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 // Information about the current process. | 5 // Information about the current process. |
6 | 6 |
7 #include "rlz/win/lib/process_info.h" | 7 #include "rlz/win/lib/process_info.h" |
8 | 8 |
9 #include <windows.h> | 9 #include <windows.h> |
10 #include <Sddl.h> // For ConvertSidToStringSid. | 10 #include <Sddl.h> // For ConvertSidToStringSid. |
(...skipping 22 matching lines...) Expand all Loading... |
33 // In which case, search for and use the process handle of a running | 33 // In which case, search for and use the process handle of a running |
34 // Explorer.exe.) | 34 // Explorer.exe.) |
35 HANDLE token; | 35 HANDLE token; |
36 if (!::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY, &token)) | 36 if (!::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY, &token)) |
37 return E_FAIL; | 37 return E_FAIL; |
38 | 38 |
39 base::win::ScopedHandle scoped_process_token(token); | 39 base::win::ScopedHandle scoped_process_token(token); |
40 | 40 |
41 // (Following call will fail with ERROR_INSUFFICIENT_BUFFER and give us the | 41 // (Following call will fail with ERROR_INSUFFICIENT_BUFFER and give us the |
42 // required size.) | 42 // required size.) |
43 scoped_array<char> token_user_bytes; | 43 scoped_ptr<char[]> token_user_bytes; |
44 DWORD token_user_size; | 44 DWORD token_user_size; |
45 DWORD token_user_size2; | 45 DWORD token_user_size2; |
46 BOOL result = ::GetTokenInformation(token, TokenUser, NULL, 0, | 46 BOOL result = ::GetTokenInformation(token, TokenUser, NULL, 0, |
47 &token_user_size); | 47 &token_user_size); |
48 err = ::GetLastError(); | 48 err = ::GetLastError(); |
49 CHECK(!result && err == ERROR_INSUFFICIENT_BUFFER); | 49 CHECK(!result && err == ERROR_INSUFFICIENT_BUFFER); |
50 | 50 |
51 token_user_bytes.reset(new char[token_user_size]); | 51 token_user_bytes.reset(new char[token_user_size]); |
52 if (!token_user_bytes.get()) | 52 if (!token_user_bytes.get()) |
53 return E_OUTOFMEMORY; | 53 return E_OUTOFMEMORY; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } | 186 } |
187 | 187 |
188 evaluated = true; | 188 evaluated = true; |
189 if (!has_rights) | 189 if (!has_rights) |
190 ASSERT_STRING("ProcessInfo::HasAdminRights: Does not have admin rights."); | 190 ASSERT_STRING("ProcessInfo::HasAdminRights: Does not have admin rights."); |
191 | 191 |
192 return has_rights; | 192 return has_rights; |
193 } | 193 } |
194 | 194 |
195 }; // namespace | 195 }; // namespace |
OLD | NEW |