![]() |
ZenWINX Architecture - Reference Manual - Guides |
|
00001 /* 00002 * ZenWINX - WIndows Native eXtended library. 00003 * Copyright (c) 2007-2010 by Dmitri Arkhangelski (dmitriar@gmail.com). 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00027 #include "ntndk.h" 00028 #include "zenwinx.h" 00029 00041 int __stdcall winx_enable_privilege(unsigned long luid) 00042 { 00043 HANDLE hToken = NULL; 00044 NTSTATUS Status; 00045 TOKEN_PRIVILEGES tp; 00046 LUID luid_struct; 00047 00048 Status = NtOpenProcessToken(NtCurrentProcess(),MAXIMUM_ALLOWED,&hToken); 00049 if(!NT_SUCCESS(Status)){ 00050 DebugPrintEx(Status,"Cannot enable privilege %x! Open token failure",(UINT)luid); 00051 return (-1); 00052 } 00053 00054 luid_struct.HighPart = 0x0; 00055 luid_struct.LowPart = luid; 00056 tp.PrivilegeCount = 1; 00057 tp.Privileges[0].Luid = luid_struct; 00058 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 00059 Status = NtAdjustPrivilegesToken(hToken,0/*FALSE*/,&tp,sizeof(TOKEN_PRIVILEGES), 00060 (PTOKEN_PRIVILEGES)NULL,(PDWORD)NULL); 00061 NtCloseSafe(hToken); 00062 if(Status == STATUS_NOT_ALL_ASSIGNED || !NT_SUCCESS(Status)){ 00063 DebugPrintEx(Status,"Cannot enable privilege 0x%x",(UINT)luid); 00064 return (-1); 00065 } 00066 return 0; 00067 } 00068