2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 #include <afs/param.h>
16 #include <WINNT/TaLocale.h>
20 * ISWINNT ____________________________________________________________________
24 BOOL IsWindowsNT (void)
26 static BOOL fChecked = FALSE;
27 static BOOL fIsWinNT = FALSE;
33 OSVERSIONINFO Version;
34 memset (&Version, 0x00, sizeof(Version));
35 Version.dwOSVersionInfoSize = sizeof(Version);
37 if (GetVersionEx (&Version))
39 if (Version.dwPlatformId == VER_PLATFORM_WIN32_NT)
49 * ISADMIN ____________________________________________________________________
55 static BOOL fAdmin = FALSE;
56 static BOOL fTested = FALSE;
61 // Obtain the SID for BUILTIN\Administrators. If this is Windows NT,
62 // expect this call to succeed; if it does not, we can presume that
63 // it's not NT and therefore the user always has administrative
66 PSID psidAdmin = NULL;
67 SID_IDENTIFIER_AUTHORITY auth = SECURITY_NT_AUTHORITY;
68 if (!AllocateAndInitializeSid (&auth, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &psidAdmin))
73 // Then open our current ProcessToken
76 if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken))
79 // We'll have to allocate a chunk of memory to store the list of
80 // groups to which this user belongs; find out how much memory
84 GetTokenInformation (hToken, TokenGroups, NULL, dwSize, &dwSize);
86 // Allocate that buffer, and read in the list of groups.
88 PTOKEN_GROUPS pGroups = (PTOKEN_GROUPS)Allocate (dwSize);
89 if (GetTokenInformation (hToken, TokenGroups, pGroups, dwSize, &dwSize))
91 // Look through the list of group SIDs and see if any of them
92 // matches the Administrator group SID.
94 for (size_t iGroup = 0; (!fAdmin) && (iGroup < pGroups->GroupCount); ++iGroup)
96 if (EqualSid (psidAdmin, pGroups->Groups[ iGroup ].Sid))