diff --git a/windows/wincapi.c b/windows/wincapi.c index 0692f60b..b1852922 100644 --- a/windows/wincapi.c +++ b/windows/wincapi.c @@ -9,9 +9,10 @@ #include "putty.h" #include "ssh.h" -#define WINCAPI_GLOBAL #include "wincapi.h" +DEF_WINDOWS_FUNCTION(CryptProtectMemory); + bool got_crypt(void) { static bool attempted = false; diff --git a/windows/wincapi.h b/windows/wincapi.h index 3d1d31ca..732412e2 100644 --- a/windows/wincapi.h +++ b/windows/wincapi.h @@ -7,12 +7,7 @@ #if !defined NO_SECURITY -#ifndef WINCAPI_GLOBAL -#define WINCAPI_GLOBAL extern -#endif - -DECL_WINDOWS_FUNCTION(WINCAPI_GLOBAL, BOOL, CryptProtectMemory, - (LPVOID,DWORD,DWORD)); +DECL_WINDOWS_FUNCTION(extern, BOOL, CryptProtectMemory, (LPVOID,DWORD,DWORD)); bool got_crypt(void); diff --git a/windows/winnet.c b/windows/winnet.c index 1f5a8d98..558b5b3e 100644 --- a/windows/winnet.c +++ b/windows/winnet.c @@ -224,12 +224,11 @@ static bool sk_startup(int hi, int lo) return true; } -/* Actually define this function pointer, which won't have been - * defined alongside all the others by PUTTY_DO_GLOBALS because of the - * annoying winelib header-ordering issue. (See comment in winstuff.h.) */ -DECL_WINDOWS_FUNCTION(/* empty */, int, select, - (int, fd_set FAR *, fd_set FAR *, - fd_set FAR *, const struct timeval FAR *)); +DEF_WINDOWS_FUNCTION(WSAAsyncSelect); +DEF_WINDOWS_FUNCTION(WSAEventSelect); +DEF_WINDOWS_FUNCTION(WSAGetLastError); +DEF_WINDOWS_FUNCTION(WSAEnumNetworkEvents); +DEF_WINDOWS_FUNCTION(select); void sk_init(void) { diff --git a/windows/winsecur.c b/windows/winsecur.c index 190a5ee4..a1164af5 100644 --- a/windows/winsecur.c +++ b/windows/winsecur.c @@ -9,12 +9,18 @@ #if !defined NO_SECURITY -#define WINSECUR_GLOBAL #include "winsecur.h" /* Initialised once, then kept around to reuse forever */ static PSID worldsid, networksid, usersid; +DEF_WINDOWS_FUNCTION(OpenProcessToken); +DEF_WINDOWS_FUNCTION(GetTokenInformation); +DEF_WINDOWS_FUNCTION(InitializeSecurityDescriptor); +DEF_WINDOWS_FUNCTION(SetSecurityDescriptorOwner); +DEF_WINDOWS_FUNCTION(GetSecurityInfo); +DEF_WINDOWS_FUNCTION(SetSecurityInfo); +DEF_WINDOWS_FUNCTION(SetEntriesInAclA); bool got_advapi(void) { diff --git a/windows/winsecur.h b/windows/winsecur.h index d5d4cfb1..fdd39d81 100644 --- a/windows/winsecur.h +++ b/windows/winsecur.h @@ -8,30 +8,26 @@ #include -#ifndef WINSECUR_GLOBAL -#define WINSECUR_GLOBAL extern -#endif - /* * Functions loaded from advapi32.dll. */ -DECL_WINDOWS_FUNCTION(WINSECUR_GLOBAL, BOOL, OpenProcessToken, +DECL_WINDOWS_FUNCTION(extern, BOOL, OpenProcessToken, (HANDLE, DWORD, PHANDLE)); -DECL_WINDOWS_FUNCTION(WINSECUR_GLOBAL, BOOL, GetTokenInformation, +DECL_WINDOWS_FUNCTION(extern, BOOL, GetTokenInformation, (HANDLE, TOKEN_INFORMATION_CLASS, LPVOID, DWORD, PDWORD)); -DECL_WINDOWS_FUNCTION(WINSECUR_GLOBAL, BOOL, InitializeSecurityDescriptor, +DECL_WINDOWS_FUNCTION(extern, BOOL, InitializeSecurityDescriptor, (PSECURITY_DESCRIPTOR, DWORD)); -DECL_WINDOWS_FUNCTION(WINSECUR_GLOBAL, BOOL, SetSecurityDescriptorOwner, +DECL_WINDOWS_FUNCTION(extern, BOOL, SetSecurityDescriptorOwner, (PSECURITY_DESCRIPTOR, PSID, BOOL)); -DECL_WINDOWS_FUNCTION(WINSECUR_GLOBAL, DWORD, GetSecurityInfo, +DECL_WINDOWS_FUNCTION(extern, DWORD, GetSecurityInfo, (HANDLE, SE_OBJECT_TYPE, SECURITY_INFORMATION, PSID *, PSID *, PACL *, PACL *, PSECURITY_DESCRIPTOR *)); -DECL_WINDOWS_FUNCTION(WINSECUR_GLOBAL, DWORD, SetSecurityInfo, +DECL_WINDOWS_FUNCTION(extern, DWORD, SetSecurityInfo, (HANDLE, SE_OBJECT_TYPE, SECURITY_INFORMATION, PSID, PSID, PACL, PACL)); -DECL_WINDOWS_FUNCTION(WINSECUR_GLOBAL, DWORD, SetEntriesInAclA, +DECL_WINDOWS_FUNCTION(extern, DWORD, SetEntriesInAclA, (ULONG, PEXPLICIT_ACCESS, PACL, PACL *)); bool got_advapi(void); diff --git a/windows/winstuff.h b/windows/winstuff.h index bad47e3d..c2f65827 100644 --- a/windows/winstuff.h +++ b/windows/winstuff.h @@ -140,6 +140,9 @@ struct FontSpec *fontspec_new( #define DECL_WINDOWS_FUNCTION(linkage, rettype, name, params) \ typedef rettype (WINAPI *t_##name) params; \ linkage t_##name p_##name +/* If you DECL_WINDOWS_FUNCTION as extern in a header file, use this to + * define the function pointer in a source file */ +#define DEF_WINDOWS_FUNCTION(name) t_##name p_##name #define STR1(x) #x #define STR(x) STR1(x) #define GET_WINDOWS_FUNCTION_PP(module, name) \ @@ -320,12 +323,12 @@ const char *winsock_error_string(int error); * that module must be exported from it as function pointers. So * here they are. */ -DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAAsyncSelect, +DECL_WINDOWS_FUNCTION(extern, int, WSAAsyncSelect, (SOCKET, HWND, u_int, long)); -DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAEventSelect, +DECL_WINDOWS_FUNCTION(extern, int, WSAEventSelect, (SOCKET, WSAEVENT, long)); -DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAGetLastError, (void)); -DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAEnumNetworkEvents, +DECL_WINDOWS_FUNCTION(extern, int, WSAGetLastError, (void)); +DECL_WINDOWS_FUNCTION(extern, int, WSAEnumNetworkEvents, (SOCKET, WSAEVENT, LPWSANETWORKEVENTS)); #ifdef NEED_DECLARATION_OF_SELECT /* This declaration is protected by an ifdef for the sake of building @@ -335,7 +338,7 @@ DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAEnumNetworkEvents, * only a modules actually needing to use (or define, or initialise) * this function pointer will see its declaration, and _those_ modules * - which will be Windows-specific anyway - can take more care. */ -DECL_WINDOWS_FUNCTION(GLOBAL, int, select, +DECL_WINDOWS_FUNCTION(extern, int, select, (int, fd_set FAR *, fd_set FAR *, fd_set FAR *, const struct timeval FAR *)); #endif