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