6
6
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
7
7
*
8
8
* 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 $
10
10
*
11
11
*-------------------------------------------------------------------------
12
12
*/
25
25
pgwin32_is_admin (void )
26
26
{
27
27
HANDLE AccessToken ;
28
- UCHAR InfoBuffer [ 1024 ] ;
29
- PTOKEN_GROUPS Groups = ( PTOKEN_GROUPS ) InfoBuffer ;
28
+ char * InfoBuffer = NULL ;
29
+ PTOKEN_GROUPS Groups ;
30
30
DWORD InfoBufferSize ;
31
31
PSID AdministratorsSid ;
32
32
PSID PowerUsersSid ;
@@ -41,8 +41,30 @@ pgwin32_is_admin(void)
41
41
exit (1 );
42
42
}
43
43
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
+
44
66
if (!GetTokenInformation (AccessToken ,TokenGroups ,InfoBuffer ,
45
- 1024 , & InfoBufferSize ))
67
+ InfoBufferSize , & InfoBufferSize ))
46
68
{
47
69
write_stderr ("failed to get token information: %d\n" ,
48
70
(int )GetLastError ());
@@ -81,6 +103,7 @@ pgwin32_is_admin(void)
81
103
}
82
104
}
83
105
106
+ free (InfoBuffer );
84
107
FreeSid (AdministratorsSid );
85
108
FreeSid (PowerUsersSid );
86
109
return success ;
0 commit comments