88 *
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/backend/libpq/auth.c,v 1.154 2007/07/23 10:16:53 mha Exp $
11+ * $PostgreSQL: pgsql/src/backend/libpq/auth.c,v 1.155 2007/07/24 09:00:27 mha Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -560,13 +560,16 @@ pg_SSPI_error(int severity, char *errmsg, SECURITY_STATUS r)
560560if (FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM ,NULL ,r ,0 ,sysmsg ,sizeof (sysmsg ),NULL )== 0 )
561561ereport (severity ,
562562 (errmsg_internal ("%s" ,errmsg ),
563- errdetail ("sspi error %x" ,r )));
563+ errdetail ("sspi error %x" ,( unsigned int ) r )));
564564else
565565ereport (severity ,
566566 (errmsg_internal ("%s" ,errmsg ),
567- errdetail ("%s (%x)" ,sysmsg ,r )));
567+ errdetail ("%s (%x)" ,sysmsg ,( unsigned int ) r )));
568568}
569569
570+ typedef SECURITY_STATUS
571+ (WINAPI * QUERY_SECURITY_CONTEXT_TOKEN_FN )(
572+ PCtxtHandle ,void * * );
570573
571574static int
572575pg_SSPI_recvauth (Port * port )
@@ -591,6 +594,8 @@ pg_SSPI_recvauth(Port *port)
591594DWORD accountnamesize = sizeof (accountname );
592595DWORD domainnamesize = sizeof (domainname );
593596SID_NAME_USE accountnameuse ;
597+ HMODULE secur32 ;
598+ QUERY_SECURITY_CONTEXT_TOKEN_FN _QuerySecurityContextToken ;
594599
595600
596601/*
@@ -726,12 +731,36 @@ pg_SSPI_recvauth(Port *port)
726731 *
727732 * Get the name of the user that authenticated, and compare it to the
728733 * pg username that was specified for the connection.
734+ *
735+ * MingW is missing the export for QuerySecurityContextToken in
736+ * the secur32 library, so we have to load it dynamically.
729737 */
730738
731- r = QuerySecurityContextToken (sspictx ,& token );
739+ secur32 = LoadLibrary ("SECUR32.DLL" );
740+ if (secur32 == NULL )
741+ ereport (ERROR ,
742+ (errmsg_internal ("could not load secur32.dll: %d" ,
743+ (int )GetLastError ())));
744+
745+ _QuerySecurityContextToken = (QUERY_SECURITY_CONTEXT_TOKEN_FN )
746+ GetProcAddress (secur32 ,"QuerySecurityContextToken" );
747+ if (_QuerySecurityContextToken == NULL )
748+ {
749+ FreeLibrary (secur32 );
750+ ereport (ERROR ,
751+ (errmsg_internal ("could not locate QuerySecurityContextToken in secur32.dll: %d" ,
752+ (int )GetLastError ())));
753+ }
754+
755+ r = (_QuerySecurityContextToken )(sspictx ,& token );
732756if (r != SEC_E_OK )
757+ {
758+ FreeLibrary (secur32 );
733759pg_SSPI_error (ERROR ,
734760gettext_noop ("could not get security token from context" ),r );
761+ }
762+
763+ FreeLibrary (secur32 );
735764
736765/*
737766 * No longer need the security context, everything from here on uses the