| #include "os.h" | |
| #ifdef _WIN32 | |
| #include <windows.h> | |
| #endif /* _WIN32 */ | |
| #ifndef NO_SystemReboot | |
| JNIEXPORT jboolean JNICALL OS_NATIVE(SystemReboot) | |
| (JNIEnv *env, jclass that ) | |
| { | |
| #ifdef _WIN32 | |
| HANDLE hToken; | |
| TOKEN_PRIVILEGES tkp; | |
| if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) | |
| return FALSE; | |
| LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid); | |
| tkp.PrivilegeCount = 1; // one privilege to set | |
| tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; | |
| AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0); | |
| // Cannot test the return value of AdjustTokenPrivileges. | |
| if (GetLastError() != ERROR_SUCCESS) | |
| return FALSE; | |
| SetProcessShutdownParameters(0x100/*Application reserved last shutdown range*/,0); | |
| return ExitWindowsEx(EWX_REBOOT | EWX_FORCE, 0); | |
| #else /* _WIN32 */ | |
| return FALSE; | |
| #endif /* _WIN32 */ | |
| } | |
| #endif | |
| JNIEXPORT jboolean JNICALL OS_NATIVE(IsUserAdmin) | |
| (JNIEnv *env, jclass that ) | |
| { | |
| #ifdef _WIN32 | |
| /*++ | |
| Routine Description: This routine returns TRUE if the caller's process | |
| is a member of the Administrators local group. Caller is NOT expected | |
| to be impersonating anyone and is expected to be able to open its own | |
| process and process token. | |
| Arguments: None. | |
| Return Value: | |
| TRUE - Caller has Administrators local group. | |
| FALSE - Caller does not have Administrators local group. -- | |
| */ | |
| BOOL b; | |
| SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY; | |
| PSID AdministratorsGroup; | |
| b = AllocateAndInitializeSid( | |
| &NtAuthority, | |
| 2, | |
| SECURITY_BUILTIN_DOMAIN_RID, | |
| DOMAIN_ALIAS_RID_ADMINS, | |
| 0, 0, 0, 0, 0, 0, | |
| &AdministratorsGroup); | |
| if(b) | |
| { | |
| if (!CheckTokenMembership( NULL, AdministratorsGroup, &b)) | |
| { | |
| b = FALSE; | |
| } | |
| FreeSid(AdministratorsGroup); | |
| } | |
| return b; | |
| #else | |
| return TRUE; | |
| #endif | |
| } |