OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_info.h" | 5 #include "base/process/process_info.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/memory/scoped_ptr.h" | |
10 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "base/win/scoped_handle.h" | |
13 #include "base/win/windows_version.h" | |
11 | 14 |
12 namespace base { | 15 namespace base { |
13 | 16 |
14 //static | 17 // static |
15 const Time CurrentProcessInfo::CreationTime() { | 18 const Time CurrentProcessInfo::CreationTime() { |
16 FILETIME creation_time = {}; | 19 FILETIME creation_time = {}; |
17 FILETIME ignore = {}; | 20 FILETIME ignore = {}; |
18 if (::GetProcessTimes(::GetCurrentProcess(), &creation_time, &ignore, | 21 if (::GetProcessTimes(::GetCurrentProcess(), &creation_time, &ignore, |
19 &ignore, &ignore) == false) | 22 &ignore, &ignore) == false) |
20 return Time(); | 23 return Time(); |
21 | 24 |
22 return Time::FromFileTime(creation_time); | 25 return Time::FromFileTime(creation_time); |
23 } | 26 } |
24 | 27 |
28 IntegrityLevel GetCurrentProcessIntegrityLevel() { | |
29 if (win::GetVersion() < base::win::VERSION_VISTA) | |
30 return INTEGRITY_UNKNOWN; | |
31 | |
32 HANDLE process_token; | |
33 if (!::OpenProcessToken(::GetCurrentProcess(), | |
34 TOKEN_QUERY | TOKEN_QUERY_SOURCE, &process_token)) { | |
35 return INTEGRITY_UNKNOWN; | |
36 } | |
37 win::ScopedHandle scoped_process_token(process_token); | |
38 | |
39 DWORD token_info_length = 0; | |
40 if (::GetTokenInformation(process_token, TokenIntegrityLevel, NULL, 0, | |
41 &token_info_length) || | |
42 ::GetLastError() != ERROR_INSUFFICIENT_BUFFER) { | |
43 return INTEGRITY_UNKNOWN; | |
44 } | |
45 | |
46 scoped_ptr<char[]> token_label_bytes(new char[token_info_length]); | |
47 if (!token_label_bytes.get()) | |
48 return INTEGRITY_UNKNOWN; | |
49 | |
50 TOKEN_MANDATORY_LABEL* token_label = | |
51 reinterpret_cast<TOKEN_MANDATORY_LABEL*>(token_label_bytes.get()); | |
52 if (!token_label) | |
53 return INTEGRITY_UNKNOWN; | |
54 | |
55 if (!::GetTokenInformation(process_token, TokenIntegrityLevel, token_label, | |
56 token_info_length, &token_info_length)) { | |
57 return INTEGRITY_UNKNOWN; | |
58 } | |
59 | |
60 DWORD integrity_level = *::GetSidSubAuthority( | |
61 token_label->Label.Sid, | |
62 (DWORD)(UCHAR)(*::GetSidSubAuthorityCount(token_label->Label.Sid)-1)); | |
63 | |
cpu_(ooo_6.6-7.5)
2015/02/13 02:39:46
use c++ style casts.
rvargas (doing something else)
2015/02/13 02:49:08
arrggg. Sorry about that, I meant to fix it but fo
| |
64 if (integrity_level < SECURITY_MANDATORY_MEDIUM_RID) | |
65 return LOW_INTEGRITY; | |
66 | |
67 if (integrity_level >= SECURITY_MANDATORY_MEDIUM_RID && | |
68 integrity_level < SECURITY_MANDATORY_HIGH_RID) { | |
69 return MEDIUM_INTEGRITY; | |
70 } | |
71 | |
72 if (integrity_level >= SECURITY_MANDATORY_HIGH_RID) | |
73 return HIGH_INTEGRITY; | |
74 | |
75 NOTREACHED(); | |
76 return INTEGRITY_UNKNOWN; | |
77 } | |
78 | |
25 } // namespace base | 79 } // namespace base |
OLD | NEW |