corrected some file operations dialog msgs
[midnight-commander.git] / pc / util_winnt.c
blobcce44381035a488b580306f80aec0d5c02602c9a
1 /* Utilities - Windows NT specific utilities (not in Win95)
2 Copyright (C) 1994, 1995, 1996 the Free Software Foundation.
4 Written 1996 by Juan Grigera<grigera@isis.unlp.edu.ar>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include <config.h>
21 #include <windows.h>
22 #include "util_win32.h"
23 #include "trace_nt.h"
26 /* int winnt_IsAdministrator() - Determines whether user has Administrator (root)
27 priviledges.
28 Return: 1 if administrator
29 0 if not
31 Note: Code taken from MSKbase Number: Q118626.
33 To determine whether or not a user is an administrator, you need to examine
34 the user's access token with GetTokenInformation(). The access token
35 represents the user's privileges and the groups to which the user belongs.
38 int winnt_IsAdministrator()
40 HANDLE hAccessToken;
41 UCHAR InfoBuffer[1024];
42 PTOKEN_GROUPS ptgGroups = (PTOKEN_GROUPS)InfoBuffer;
43 DWORD dwInfoBufferSize;
44 PSID psidAdministrators;
45 SID_IDENTIFIER_AUTHORITY siaNtAuthority = SECURITY_NT_AUTHORITY;
46 UINT x;
47 BOOL bSuccess;
49 if(!OpenProcessToken(GetCurrentProcess(),TOKEN_READ,&hAccessToken))
50 return 0;
52 bSuccess = GetTokenInformation(hAccessToken,TokenGroups,InfoBuffer,
53 1024, &dwInfoBufferSize);
55 CloseHandle(hAccessToken);
57 if( !bSuccess )
58 return 0;
60 if(!AllocateAndInitializeSid(&siaNtAuthority, 2,
61 SECURITY_BUILTIN_DOMAIN_RID,
62 DOMAIN_ALIAS_RID_ADMINS,
63 0, 0, 0, 0, 0, 0,
64 &psidAdministrators))
65 return 0;
67 bSuccess = 0;
68 for(x=0;x<ptgGroups->GroupCount;x++) {
69 if( EqualSid(psidAdministrators, ptgGroups->Groups[x].Sid) ) {
70 bSuccess = 1;
71 break;
74 FreeSid(psidAdministrators);
75 return bSuccess;
79 int geteuid ()
81 if (winnt_IsAdministrator())
82 return 0;
83 return 1;