diff options
Diffstat (limited to 'base')
-rw-r--r-- | base/process_util.h | 6 | ||||
-rw-r--r-- | base/process_util_posix.cc | 6 | ||||
-rw-r--r-- | base/process_util_win.cc | 16 |
3 files changed, 28 insertions, 0 deletions
diff --git a/base/process_util.h b/base/process_util.h index a692870..a459ed4 100644 --- a/base/process_util.h +++ b/base/process_util.h @@ -71,6 +71,12 @@ ProcessHandle GetCurrentProcessHandle(); // CloseProcessHandle when you are done with it. Returns true on success. bool OpenProcessHandle(ProcessId pid, ProcessHandle* handle); +// Converts a PID to a process handle. On Windows the handle is opened +// with more access rights and must only be used by trusted code. +// You have to close returned handle using CloseProcessHandle. Returns true +// on success. +bool OpenPrivilegedProcessHandle(ProcessId pid, ProcessHandle* handle); + // Closes the process handle opened by OpenProcessHandle. void CloseProcessHandle(ProcessHandle process); diff --git a/base/process_util_posix.cc b/base/process_util_posix.cc index efe7442..859dfc3 100644 --- a/base/process_util_posix.cc +++ b/base/process_util_posix.cc @@ -43,6 +43,12 @@ bool OpenProcessHandle(ProcessId pid, ProcessHandle* handle) { return true; } +bool OpenPrivilegedProcessHandle(ProcessId pid, ProcessHandle* handle) { + // On POSIX permissions are checked for each operation on process, + // not when opening a "handle". + return OpenProcessHandle(pid, handle); +} + void CloseProcessHandle(ProcessHandle process) { // See OpenProcessHandle, nothing to do. return; diff --git a/base/process_util_win.cc b/base/process_util_win.cc index 45a23e8..265c26f 100644 --- a/base/process_util_win.cc +++ b/base/process_util_win.cc @@ -34,6 +34,7 @@ ProcessHandle GetCurrentProcessHandle() { } bool OpenProcessHandle(ProcessId pid, ProcessHandle* handle) { + // TODO(phajdan.jr): Take even more permissions out of this list. ProcessHandle result = OpenProcess(PROCESS_DUP_HANDLE | PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION | @@ -47,6 +48,21 @@ bool OpenProcessHandle(ProcessId pid, ProcessHandle* handle) { return true; } +bool OpenPrivilegedProcessHandle(ProcessId pid, ProcessHandle* handle) { + ProcessHandle result = OpenProcess(PROCESS_DUP_HANDLE | + PROCESS_TERMINATE | + PROCESS_QUERY_INFORMATION | + PROCESS_VM_READ | + SYNCHRONIZE, + FALSE, pid); + + if (result == INVALID_HANDLE_VALUE) + return false; + + *handle = result; + return true; +} + void CloseProcessHandle(ProcessHandle process) { CloseHandle(process); } |