OLD | NEW |
| (Empty) |
1 // Copyright 2016 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. | |
4 | |
5 #include "remoting/host/win/elevation_helpers.h" | |
6 | |
7 #include <windows.h> | |
8 | |
9 #include "base/logging.h" | |
10 #include "base/win/scoped_handle.h" | |
11 | |
12 namespace { | |
13 | |
14 void GetCurrentProcessToken(base::win::ScopedHandle* scoped_handle) { | |
15 DCHECK(scoped_handle); | |
16 | |
17 HANDLE process_token; | |
18 OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &process_token); | |
19 scoped_handle->Set(process_token); | |
20 DCHECK(scoped_handle->IsValid()); | |
21 } | |
22 | |
23 } // namespace | |
24 | |
25 namespace remoting { | |
26 | |
27 bool IsProcessElevated() { | |
28 base::win::ScopedHandle scoped_process_token; | |
29 GetCurrentProcessToken(&scoped_process_token); | |
30 | |
31 // Unlike TOKEN_ELEVATION_TYPE which returns TokenElevationTypeDefault when | |
32 // UAC is turned off, TOKEN_ELEVATION returns whether the process is elevated. | |
33 DWORD size; | |
34 TOKEN_ELEVATION elevation; | |
35 if (!GetTokenInformation(scoped_process_token.Get(), TokenElevation, | |
36 &elevation, sizeof(elevation), &size)) { | |
37 PLOG(ERROR) << "GetTokenInformation() failed"; | |
38 return false; | |
39 } | |
40 return elevation.TokenIsElevated != 0; | |
41 } | |
42 | |
43 bool CurrentProcessHasUiAccess() { | |
44 base::win::ScopedHandle scoped_process_token; | |
45 GetCurrentProcessToken(&scoped_process_token); | |
46 | |
47 DWORD size; | |
48 DWORD uiaccess_value = 0; | |
49 if (!GetTokenInformation(scoped_process_token.Get(), TokenUIAccess, | |
50 &uiaccess_value, sizeof(uiaccess_value), &size)) { | |
51 PLOG(ERROR) << "GetTokenInformation() failed"; | |
52 return false; | |
53 } | |
54 return uiaccess_value != 0; | |
55 } | |
56 | |
57 } // namespace remoting | |
OLD | NEW |