Index: src/backend/port/win32/security.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/port/win32/security.c,v retrieving revision 1.1 diff -c -r1.1 security.c *** src/backend/port/win32/security.c 24 Jun 2004 21:02:42 -0000 1.1 --- src/backend/port/win32/security.c 23 Aug 2004 18:13:27 -0000 *************** *** 25,32 **** pgwin32_is_admin(void) { HANDLE AccessToken; ! UCHAR InfoBuffer[1024]; ! PTOKEN_GROUPS Groups = (PTOKEN_GROUPS)InfoBuffer; DWORD InfoBufferSize; PSID AdministratorsSid; PSID PowerUsersSid; --- 25,32 ---- pgwin32_is_admin(void) { HANDLE AccessToken; ! char *InfoBuffer = NULL; ! PTOKEN_GROUPS Groups; DWORD InfoBufferSize; PSID AdministratorsSid; PSID PowerUsersSid; *************** *** 41,48 **** exit(1); } if (!GetTokenInformation(AccessToken,TokenGroups,InfoBuffer, ! 1024, &InfoBufferSize)) { write_stderr("failed to get token information: %d\n", (int)GetLastError()); --- 41,70 ---- 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, ! InfoBufferSize, &InfoBufferSize)) { write_stderr("failed to get token information: %d\n", (int)GetLastError()); *************** *** 81,86 **** --- 103,109 ---- } } + free(InfoBuffer); FreeSid(AdministratorsSid); FreeSid(PowerUsersSid); return success;