return num_processors;
}
-// FIXME
-OSVERSIONINFO osvi;
+
void print_system_info_os(void)
{
+ OSVERSIONINFO osvi;
LOG_INFO("* Windows\n");
LOG_INFO("* LibPNG Version : %s\n", PNG_LIBPNG_VER_STRING);
*java_path = current_java_path;
}
-bool check_integrity_level_and_respawn(void)
-{
- BOOL bResult = false;
- HANDLE hToken = NULL;
- HANDLE hNewToken = NULL;
- PSID pIntegritySid = NULL;
- TOKEN_MANDATORY_LABEL TIL = { { 0, }, };
- PTOKEN_MANDATORY_LABEL pTIL = NULL;
- PROCESS_INFORMATION ProcInfo = { 0, };
- STARTUPINFO StartupInfo = { 0, };
- SID_IDENTIFIER_AUTHORITY
- MLAuthority = { SECURITY_MANDATORY_LABEL_AUTHORITY };
- DWORD dwIntegrityLevel, dwSize = 0;
-
- if(!OpenProcessToken(GetCurrentProcess(),
- TOKEN_DUPLICATE | TOKEN_ADJUST_DEFAULT | TOKEN_QUERY |
- TOKEN_ASSIGN_PRIMARY, &hToken)) {
- LOG_WARNING("OpenProcessToken Error %lu\n", GetLastError());
- goto CleanExit;
- }
-
- if (!GetTokenInformation(hToken, TokenGroups, NULL, 0, &dwSize)) {
- DWORD dwResult = GetLastError();
- if (dwResult != ERROR_INSUFFICIENT_BUFFER) {
- LOG_WARNING("GetTokenInformation Error %lu\n", dwResult);
- goto CleanExit;
- }
- }
-
- pTIL = (PTOKEN_MANDATORY_LABEL)LocalAlloc(0, dwSize);
- if (!pTIL) {
- LOG_WARNING("LocalAlloc Error %lu\n", GetLastError());
- goto CleanExit;
- }
-
- if (!GetTokenInformation(hToken, TokenIntegrityLevel, pTIL,
- dwSize, &dwSize)) {
- LOG_WARNING("GetTokenInformation Error %lu\n", GetLastError());
- goto CleanExit;
- }
-
- dwIntegrityLevel = *GetSidSubAuthority(pTIL->Label.Sid,
- (DWORD)(UCHAR)(*GetSidSubAuthorityCount(pTIL->Label.Sid) - 1));
-
- if (dwIntegrityLevel >= SECURITY_MANDATORY_MEDIUM_RID &&
- dwIntegrityLevel < SECURITY_MANDATORY_HIGH_RID) {
- // We have medium integrity level. So keep going on.
- goto CleanExit;
- }
-
- LOG_INFO("Running with elevated integrity level. Try to respawn.\n");
-
- if (!DuplicateTokenEx(hToken, 0, NULL, SecurityImpersonation,
- TokenPrimary, &hNewToken)) {
- LOG_WARNING("DuplicateTokenEx Error %lu\n", GetLastError());
- goto CleanExit;
- }
-
- if (!AllocateAndInitializeSid(&MLAuthority, 1, SECURITY_MANDATORY_MEDIUM_RID,
- 0, 0, 0, 0, 0, 0, 0, &pIntegritySid)) {
- LOG_WARNING("AllocateAndInitializeSid Error %lu\n", GetLastError());
- goto CleanExit;
- }
-
- TIL.Label.Attributes = SE_GROUP_INTEGRITY;
- TIL.Label.Sid = pIntegritySid;
-
- if (!SetTokenInformation(hNewToken,
- TokenIntegrityLevel,
- &TIL,
- sizeof(TOKEN_MANDATORY_LABEL) + GetLengthSid(pIntegritySid))) {
- LOG_WARNING("SetTokenInformation Error %lu\n", GetLastError());
- goto CleanExit;
- }
-
- if (!CreateProcessAsUser(hNewToken, 0, GetCommandLine(),
- NULL, NULL, FALSE, 0, NULL, NULL, &StartupInfo, &ProcInfo)) {
- LOG_WARNING( "CreateProcessAsUser Error %lu\n", GetLastError());
- goto CleanExit;
- }
-
- LOG_INFO("Respawning success. Waiting for child process.\n");
- bResult = true;
- WaitForSingleObject(ProcInfo.hProcess, INFINITE);
- LOG_INFO("Respawn successfull. Elevated Process.\n");
-
-CleanExit:
- if (ProcInfo.hProcess != NULL) {
- CloseHandle(ProcInfo.hProcess);
- }
-
- if (ProcInfo.hThread != NULL) {
- CloseHandle(ProcInfo.hThread);
- }
-
- if (pIntegritySid != NULL) {
- LocalFree(pIntegritySid);
- }
-
- if (hNewToken != NULL) {
- CloseHandle(hNewToken);
- }
-
- if (hToken != NULL) {
- CloseHandle(hToken);
- }
-
- if (pTIL != NULL) {
- LocalFree(pTIL);
- }
-
- return bResult;
-}
-