Skip to content
Snippets Groups Projects
Commit cc28a275 authored by Bruce Momjian's avatar Bruce Momjian
Browse files

Use dynamic buffer for token buffer in win32 admin check

Magnus Hagander
parent 1c72d0de
No related branches found
No related tags found
No related merge requests found
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/port/win32/security.c,v 1.1 2004/06/24 21:02:42 tgl Exp $ * $PostgreSQL: pgsql/src/backend/port/win32/security.c,v 1.2 2004/08/28 21:00:35 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -25,8 +25,8 @@ int ...@@ -25,8 +25,8 @@ int
pgwin32_is_admin(void) pgwin32_is_admin(void)
{ {
HANDLE AccessToken; HANDLE AccessToken;
UCHAR InfoBuffer[1024]; char *InfoBuffer = NULL;
PTOKEN_GROUPS Groups = (PTOKEN_GROUPS)InfoBuffer; PTOKEN_GROUPS Groups;
DWORD InfoBufferSize; DWORD InfoBufferSize;
PSID AdministratorsSid; PSID AdministratorsSid;
PSID PowerUsersSid; PSID PowerUsersSid;
...@@ -41,8 +41,30 @@ pgwin32_is_admin(void) ...@@ -41,8 +41,30 @@ pgwin32_is_admin(void)
exit(1); exit(1);
} }
if (GetTokenInformation(AccessToken,TokenGroups,NULL,0,&InfoBufferSize))
{
write_stderr("failed to get token information - got zero size!\n");
exit(1);
}
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
{
write_stderr("failed to get token information: %d\n",
(int)GetLastError());
exit(1);
}
InfoBuffer = malloc(InfoBufferSize);
if (!InfoBuffer)
{
write_stderr("failed to allocate %i bytes for token information!\n",
(int)InfoBufferSize);
exit(1);
}
Groups = (PTOKEN_GROUPS)InfoBuffer;
if (!GetTokenInformation(AccessToken,TokenGroups,InfoBuffer, if (!GetTokenInformation(AccessToken,TokenGroups,InfoBuffer,
1024, &InfoBufferSize)) InfoBufferSize, &InfoBufferSize))
{ {
write_stderr("failed to get token information: %d\n", write_stderr("failed to get token information: %d\n",
(int)GetLastError()); (int)GetLastError());
...@@ -81,6 +103,7 @@ pgwin32_is_admin(void) ...@@ -81,6 +103,7 @@ pgwin32_is_admin(void)
} }
} }
free(InfoBuffer);
FreeSid(AdministratorsSid); FreeSid(AdministratorsSid);
FreeSid(PowerUsersSid); FreeSid(PowerUsersSid);
return success; return success;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment