mc/nt/util.WinNT.c
Miguel de Icaza 74c6330a30 Sat Mar 7 14:43:27 1998 Pavel Roskin <pavel@absolute.spb.su>
* nt/Makefile.NT, nt/Makefile.VC4: rewritten for GNU make.
        Use gmake -f Makefile.VC4 to compile.

        * nt/*.c: config.h is included before all other code.

        * nt/config.h: added some definitions, because some
        compilers don't accept long command lines.

        * nt/Makefile.VC1: removed :-( It didn't work anyways.

        * nt/slint.nt.c: can be compiled under OS/2 too

        * nt/key.nt.c: correct_key_code was called twice. Shifted
        functional keys supported. Alt-F1 and Alt-F2 work as F11 and F12.
        Alt-F7 works as Shift-Alt-? (used for find file). Function
        alt_pressed() and ctrl_pressed() introduced.
1998-03-07 20:36:45 +00:00

86 lines
2.4 KiB
C

/* Utilities - Windows NT specific utilities (not in Win95)
Copyright (C) 1994, 1995, 1996 the Free Software Foundation.
Written 1996 by Juan Grigera<grigera@isis.unlp.edu.ar>
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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <config.h>
#include <windows.h>
#include "util.win32.h"
#include "util.debug.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;
}