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
3 // found in the LICENSE file.
5 #include "base/process/process_info.h"
9 #include "base/basictypes.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/time/time.h"
12 #include "base/win/scoped_handle.h"
13 #include "base/win/windows_version.h"
18 const Time
CurrentProcessInfo::CreationTime() {
19 FILETIME creation_time
= {};
21 if (::GetProcessTimes(::GetCurrentProcess(), &creation_time
, &ignore
,
22 &ignore
, &ignore
) == false)
25 return Time::FromFileTime(creation_time
);
28 IntegrityLevel
GetCurrentProcessIntegrityLevel() {
29 if (win::GetVersion() < base::win::VERSION_VISTA
)
30 return INTEGRITY_UNKNOWN
;
33 if (!::OpenProcessToken(::GetCurrentProcess(),
34 TOKEN_QUERY
| TOKEN_QUERY_SOURCE
, &process_token
)) {
35 return INTEGRITY_UNKNOWN
;
37 win::ScopedHandle
scoped_process_token(process_token
);
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
;
46 scoped_ptr
<char[]> token_label_bytes(new char[token_info_length
]);
47 if (!token_label_bytes
.get())
48 return INTEGRITY_UNKNOWN
;
50 TOKEN_MANDATORY_LABEL
* token_label
=
51 reinterpret_cast<TOKEN_MANDATORY_LABEL
*>(token_label_bytes
.get());
53 return INTEGRITY_UNKNOWN
;
55 if (!::GetTokenInformation(process_token
, TokenIntegrityLevel
, token_label
,
56 token_info_length
, &token_info_length
)) {
57 return INTEGRITY_UNKNOWN
;
60 DWORD integrity_level
= *::GetSidSubAuthority(
61 token_label
->Label
.Sid
,
62 static_cast<DWORD
>(*::GetSidSubAuthorityCount(token_label
->Label
.Sid
)-1));
64 if (integrity_level
< SECURITY_MANDATORY_MEDIUM_RID
)
67 if (integrity_level
>= SECURITY_MANDATORY_MEDIUM_RID
&&
68 integrity_level
< SECURITY_MANDATORY_HIGH_RID
) {
69 return MEDIUM_INTEGRITY
;
72 if (integrity_level
>= SECURITY_MANDATORY_HIGH_RID
)
73 return HIGH_INTEGRITY
;
76 return INTEGRITY_UNKNOWN
;