Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: base/process/process_handle_win.cc

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/process/process_handle_posix.cc ('k') | base/process/process_info.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/process/process_handle.h" 5 #include "base/process/process_handle.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/win/scoped_handle.h" 10 #include "base/win/scoped_handle.h"
11 #include "base/win/windows_version.h" 11 #include "base/win/windows_version.h"
12 12
13 namespace base { 13 namespace base {
14 14
15 ProcessId GetCurrentProcId() { 15 ProcessId GetCurrentProcId() {
16 return ::GetCurrentProcessId(); 16 return ::GetCurrentProcessId();
17 } 17 }
18 18
19 ProcessHandle GetCurrentProcessHandle() { 19 ProcessHandle GetCurrentProcessHandle() {
20 return ::GetCurrentProcess(); 20 return ::GetCurrentProcess();
21 } 21 }
22 22
23 void CloseProcessHandle(ProcessHandle process) {
24 CloseHandle(process);
25 }
26
27 ProcessId GetProcId(ProcessHandle process) { 23 ProcessId GetProcId(ProcessHandle process) {
28 // This returns 0 if we have insufficient rights to query the process handle. 24 // This returns 0 if we have insufficient rights to query the process handle.
29 return GetProcessId(process); 25 return GetProcessId(process);
30 } 26 }
31 27
32 bool GetProcessIntegrityLevel(ProcessHandle process, IntegrityLevel *level) {
33 if (!level)
34 return false;
35
36 if (win::GetVersion() < base::win::VERSION_VISTA)
37 return false;
38
39 HANDLE process_token;
40 if (!OpenProcessToken(process, TOKEN_QUERY | TOKEN_QUERY_SOURCE,
41 &process_token))
42 return false;
43
44 win::ScopedHandle scoped_process_token(process_token);
45
46 DWORD token_info_length = 0;
47 if (GetTokenInformation(process_token, TokenIntegrityLevel, NULL, 0,
48 &token_info_length) ||
49 GetLastError() != ERROR_INSUFFICIENT_BUFFER)
50 return false;
51
52 scoped_ptr<char[]> token_label_bytes(new char[token_info_length]);
53 if (!token_label_bytes.get())
54 return false;
55
56 TOKEN_MANDATORY_LABEL* token_label =
57 reinterpret_cast<TOKEN_MANDATORY_LABEL*>(token_label_bytes.get());
58 if (!token_label)
59 return false;
60
61 if (!GetTokenInformation(process_token, TokenIntegrityLevel, token_label,
62 token_info_length, &token_info_length))
63 return false;
64
65 DWORD integrity_level = *GetSidSubAuthority(token_label->Label.Sid,
66 (DWORD)(UCHAR)(*GetSidSubAuthorityCount(token_label->Label.Sid)-1));
67
68 if (integrity_level < SECURITY_MANDATORY_MEDIUM_RID) {
69 *level = LOW_INTEGRITY;
70 } else if (integrity_level >= SECURITY_MANDATORY_MEDIUM_RID &&
71 integrity_level < SECURITY_MANDATORY_HIGH_RID) {
72 *level = MEDIUM_INTEGRITY;
73 } else if (integrity_level >= SECURITY_MANDATORY_HIGH_RID) {
74 *level = HIGH_INTEGRITY;
75 } else {
76 NOTREACHED();
77 return false;
78 }
79
80 return true;
81 }
82
83 } // namespace base 28 } // namespace base
OLDNEW
« no previous file with comments | « base/process/process_handle_posix.cc ('k') | base/process/process_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698