66 * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
77 *
88 * IDENTIFICATION
9- * $PostgreSQL: pgsql/src/backend/port/win32/security.c,v 1.1 2004/06/24 21:02:42 tgl Exp $
9+ * $PostgreSQL: pgsql/src/backend/port/win32/security.c,v 1.2 2004/08/28 21:00:35 momjian Exp $
1010 *
1111 *-------------------------------------------------------------------------
1212 */
2525pgwin32_is_admin (void )
2626{
2727HANDLE AccessToken ;
28- UCHAR InfoBuffer [ 1024 ] ;
29- PTOKEN_GROUPS Groups = ( PTOKEN_GROUPS ) InfoBuffer ;
28+ char * InfoBuffer = NULL ;
29+ PTOKEN_GROUPS Groups ;
3030DWORD InfoBufferSize ;
3131PSID AdministratorsSid ;
3232PSID PowerUsersSid ;
@@ -41,8 +41,30 @@ pgwin32_is_admin(void)
4141exit (1 );
4242}
4343
44+ if (GetTokenInformation (AccessToken ,TokenGroups ,NULL ,0 ,& InfoBufferSize ))
45+ {
46+ write_stderr ("failed to get token information - got zero size!\n" );
47+ exit (1 );
48+ }
49+
50+ if (GetLastError ()!= ERROR_INSUFFICIENT_BUFFER )
51+ {
52+ write_stderr ("failed to get token information: %d\n" ,
53+ (int )GetLastError ());
54+ exit (1 );
55+ }
56+
57+ InfoBuffer = malloc (InfoBufferSize );
58+ if (!InfoBuffer )
59+ {
60+ write_stderr ("failed to allocate %i bytes for token information!\n" ,
61+ (int )InfoBufferSize );
62+ exit (1 );
63+ }
64+ Groups = (PTOKEN_GROUPS )InfoBuffer ;
65+
4466if (!GetTokenInformation (AccessToken ,TokenGroups ,InfoBuffer ,
45- 1024 ,& InfoBufferSize ))
67+ InfoBufferSize ,& InfoBufferSize ))
4668{
4769write_stderr ("failed to get token information: %d\n" ,
4870 (int )GetLastError ());
@@ -81,6 +103,7 @@ pgwin32_is_admin(void)
81103}
82104}
83105
106+ free (InfoBuffer );
84107FreeSid (AdministratorsSid );
85108FreeSid (PowerUsersSid );
86109return success ;