mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
Replace load of functions by direct calls for some WIN32
This commit changes the following code paths to do direct system calls to some WIN32 functions rather than loading them from an external library, shaving some code in the process: - Creation of restricted tokens in pg_ctl.c, introduced bya25cd81. - QuerySecurityContextToken() in auth.c for SSPI authentication in the backend, introduced ind602592. - CreateRestrictedToken() in src/common/. This change is similar to the case of pg_ctl.c. Most of these functions were loaded rather than directly called because, as mentioned in the code comments, MinGW headers were not declaring them. I have double-checked the recent MinGW code, and all the functions changed here are declared in its headers, so this change should be safe. Note that I do not have a MinGW environment at hand so I have not tested it directly, but that MSVC was fine with the change. The buildfarm will tell soon enough if this change is appropriate or not for a much broader set of environments. A few code paths still use GetProcAddress() to load some functions: - LDAP authentication for ldap_start_tls_sA(), where I am not confident that this change would work. - win32env.c and win32ntdll.c where we have a per-MSVC version dependency for the name of the library loaded. - crashdump.c for MiniDumpWriteDump() and EnumDirTree(), where direct calls were not able to work after testing. Reported-by: Thomas Munro Reviewed-by: Justin Prysby Discussion: https://postgr.es/m/CA+hUKG+BMdcaCe=P-EjMoLTCr3zrrzqbcVE=8h5LyNsSVHKXZA@mail.gmail.com
This commit is contained in:
@@ -1201,11 +1201,8 @@ pg_SSPI_recvauth(Port *port)
|
||||
DWORD accountnamesize = sizeof(accountname);
|
||||
DWORD domainnamesize = sizeof(domainname);
|
||||
SID_NAME_USE accountnameuse;
|
||||
HMODULE secur32;
|
||||
char *authn_id;
|
||||
|
||||
QUERY_SECURITY_CONTEXT_TOKEN_FN _QuerySecurityContextToken;
|
||||
|
||||
/*
|
||||
* Acquire a handle to the server credentials.
|
||||
*/
|
||||
@@ -1358,36 +1355,12 @@ pg_SSPI_recvauth(Port *port)
|
||||
*
|
||||
* Get the name of the user that authenticated, and compare it to the pg
|
||||
* username that was specified for the connection.
|
||||
*
|
||||
* MingW is missing the export for QuerySecurityContextToken in the
|
||||
* secur32 library, so we have to load it dynamically.
|
||||
*/
|
||||
|
||||
secur32 = LoadLibrary("SECUR32.DLL");
|
||||
if (secur32 == NULL)
|
||||
ereport(ERROR,
|
||||
(errmsg("could not load library \"%s\": error code %lu",
|
||||
"SECUR32.DLL", GetLastError())));
|
||||
|
||||
_QuerySecurityContextToken = (QUERY_SECURITY_CONTEXT_TOKEN_FN) (pg_funcptr_t)
|
||||
GetProcAddress(secur32, "QuerySecurityContextToken");
|
||||
if (_QuerySecurityContextToken == NULL)
|
||||
{
|
||||
FreeLibrary(secur32);
|
||||
ereport(ERROR,
|
||||
(errmsg_internal("could not locate QuerySecurityContextToken in secur32.dll: error code %lu",
|
||||
GetLastError())));
|
||||
}
|
||||
|
||||
r = (_QuerySecurityContextToken) (sspictx, &token);
|
||||
r = QuerySecurityContextToken(sspictx, &token);
|
||||
if (r != SEC_E_OK)
|
||||
{
|
||||
FreeLibrary(secur32);
|
||||
pg_SSPI_error(ERROR,
|
||||
_("could not get token from SSPI security context"), r);
|
||||
}
|
||||
|
||||
FreeLibrary(secur32);
|
||||
|
||||
/*
|
||||
* No longer need the security context, everything from here on uses the
|
||||
|
||||
Reference in New Issue
Block a user