From 0df96d5ecaafea4b6d1c271ef5efdce77ef77f1c Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Tue, 21 Aug 2007 20:51:46 +0000 Subject: [PATCH] increase process visibility --- src/os/win32/win32_sigar.c | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/os/win32/win32_sigar.c b/src/os/win32/win32_sigar.c index 10ff71ec..3e1bebdc 100644 --- a/src/os/win32/win32_sigar.c +++ b/src/os/win32/win32_sigar.c @@ -407,6 +407,43 @@ int sigar_wsa_init(sigar_t *sigar) return SIGAR_OK; } +static int sigar_enable_privilege(char *name) +{ + int status; + HANDLE handle; + TOKEN_PRIVILEGES tok; + + SIGAR_ZERO(&tok); + + if (!OpenProcessToken(GetCurrentProcess(), + TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, + &handle)) + { + return GetLastError(); + } + + if (LookupPrivilegeValue(NULL, name, + &tok.Privileges[0].Luid)) + { + tok.PrivilegeCount = 1; + tok.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; + + if (AdjustTokenPrivileges(handle, FALSE, &tok, 0, NULL, 0)) { + status = SIGAR_OK; + } + else { + status = GetLastError(); + } + } + else { + status = GetLastError(); + } + + CloseHandle(handle); + + return status; +} + int sigar_os_open(sigar_t **sigar_ptr) { LONG result; @@ -469,6 +506,9 @@ int sigar_os_open(sigar_t **sigar_ptr) sigar->ws_version = 0; sigar->ncpu = 0; + /* increase process visibility */ + sigar_enable_privilege(SE_DEBUG_NAME); + return result; }