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 "remoting/host/sas_injector.h" | 5 #include "remoting/host/sas_injector.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/native_library.h" | 12 #include "base/native_library.h" |
13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/stringize_macros.h" |
15 #include "base/win/registry.h" | 15 #include "base/win/registry.h" |
16 #include "base/win/windows_version.h" | 16 #include "base/win/windows_version.h" |
17 | 17 |
18 namespace remoting { | 18 namespace remoting { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // Names of the API and library implementing software SAS generation. | 22 // Names of the API and library implementing software SAS generation. |
23 const FilePath::CharType kSasDllFileName[] = | 23 const FilePath::CharType kSasDllFileName[] = |
24 FILE_PATH_LITERAL("sas.dll"); | 24 FILE_PATH_LITERAL("sas.dll"); |
25 const char kSendSasName[] = "SendSAS"; | 25 const char kSendSasName[] = "SendSAS"; |
26 | 26 |
27 // The prototype of SendSAS(). | 27 // The prototype of SendSAS(). |
28 typedef VOID (WINAPI *SendSasFunc)(BOOL); | 28 typedef VOID (WINAPI *SendSasFunc)(BOOL); |
29 | 29 |
30 // The registry key and value holding the policy controlling software SAS | 30 // The registry key and value holding the policy controlling software SAS |
31 // generation. | 31 // generation. |
32 const char kSystemPolicyKeyName[] = | 32 const char16 kSystemPolicyKeyName[] = |
33 "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"; | 33 TO_L_STRING("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\") |
34 const char kSoftwareSasValueName[] = "SoftwareSASGeneration"; | 34 TO_L_STRING("System"); |
| 35 const char16 kSoftwareSasValueName[] = TO_L_STRING("SoftwareSASGeneration"); |
35 | 36 |
36 const DWORD kEnableSoftwareSasByServices = 1; | 37 const DWORD kEnableSoftwareSasByServices = 1; |
37 | 38 |
38 // Toggles the default software SAS generation policy to enable SAS generation | 39 // Toggles the default software SAS generation policy to enable SAS generation |
39 // by services. Non-default policy is not changed. | 40 // by services. Non-default policy is not changed. |
40 class ScopedSoftwareSasPolicy { | 41 class ScopedSoftwareSasPolicy { |
41 public: | 42 public: |
42 ScopedSoftwareSasPolicy(); | 43 ScopedSoftwareSasPolicy(); |
43 ~ScopedSoftwareSasPolicy(); | 44 ~ScopedSoftwareSasPolicy(); |
44 | 45 |
45 bool Apply(); | 46 bool Apply(); |
46 | 47 |
47 private: | 48 private: |
48 // The handle of the registry key were SoftwareSASGeneration policy is stored. | 49 // The handle of the registry key were SoftwareSASGeneration policy is stored. |
49 base::win::RegKey system_policy_; | 50 base::win::RegKey system_policy_; |
50 | 51 |
51 // Name of the registry value holding the policy. | |
52 string16 value_name_; | |
53 | |
54 // True if the policy needs to be restored. | 52 // True if the policy needs to be restored. |
55 bool restore_policy_; | 53 bool restore_policy_; |
56 | 54 |
57 DISALLOW_COPY_AND_ASSIGN(ScopedSoftwareSasPolicy); | 55 DISALLOW_COPY_AND_ASSIGN(ScopedSoftwareSasPolicy); |
58 }; | 56 }; |
59 | 57 |
60 ScopedSoftwareSasPolicy::ScopedSoftwareSasPolicy() | 58 ScopedSoftwareSasPolicy::ScopedSoftwareSasPolicy() |
61 : restore_policy_(false) { | 59 : restore_policy_(false) { |
62 } | 60 } |
63 | 61 |
64 ScopedSoftwareSasPolicy::~ScopedSoftwareSasPolicy() { | 62 ScopedSoftwareSasPolicy::~ScopedSoftwareSasPolicy() { |
65 // Restore the default policy by deleting the value that we have set. | 63 // Restore the default policy by deleting the value that we have set. |
66 if (restore_policy_) { | 64 if (restore_policy_) { |
67 LONG result = system_policy_.DeleteValue(value_name_.c_str()); | 65 LONG result = system_policy_.DeleteValue(kSoftwareSasValueName); |
68 if (result != ERROR_SUCCESS) { | 66 if (result != ERROR_SUCCESS) { |
69 SetLastError(result); | 67 SetLastError(result); |
70 LOG_GETLASTERROR(ERROR) | 68 LOG_GETLASTERROR(ERROR) |
71 << "Failed to restore the software SAS generation policy"; | 69 << "Failed to restore the software SAS generation policy"; |
72 } | 70 } |
73 } | 71 } |
74 } | 72 } |
75 | 73 |
76 bool ScopedSoftwareSasPolicy::Apply() { | 74 bool ScopedSoftwareSasPolicy::Apply() { |
77 // Query the currently set SoftwareSASGeneration policy. | 75 // Query the currently set SoftwareSASGeneration policy. |
78 LONG result = system_policy_.Open(HKEY_LOCAL_MACHINE, | 76 LONG result = system_policy_.Open(HKEY_LOCAL_MACHINE, |
79 ASCIIToUTF16(kSystemPolicyKeyName).c_str(), | 77 kSystemPolicyKeyName, |
80 KEY_QUERY_VALUE | KEY_SET_VALUE | | 78 KEY_QUERY_VALUE | KEY_SET_VALUE | |
81 KEY_WOW64_64KEY); | 79 KEY_WOW64_64KEY); |
82 if (result != ERROR_SUCCESS) { | 80 if (result != ERROR_SUCCESS) { |
83 SetLastError(result); | 81 SetLastError(result); |
84 LOG_GETLASTERROR(ERROR) << "Failed to open 'HKLM\\" | 82 LOG_GETLASTERROR(ERROR) << "Failed to open 'HKLM\\" |
85 << kSystemPolicyKeyName << "'"; | 83 << kSystemPolicyKeyName << "'"; |
86 return false; | 84 return false; |
87 } | 85 } |
88 | 86 |
89 value_name_ = ASCIIToUTF16(kSoftwareSasValueName); | 87 bool custom_policy = system_policy_.HasValue(kSoftwareSasValueName); |
90 bool custom_policy = system_policy_.HasValue(value_name_.c_str()); | |
91 | 88 |
92 // Override the default policy (i.e. there is no value in the registry) only. | 89 // Override the default policy (i.e. there is no value in the registry) only. |
93 if (!custom_policy) { | 90 if (!custom_policy) { |
94 result = system_policy_.WriteValue(value_name_.c_str(), | 91 result = system_policy_.WriteValue(kSoftwareSasValueName, |
95 kEnableSoftwareSasByServices); | 92 kEnableSoftwareSasByServices); |
96 if (result != ERROR_SUCCESS) { | 93 if (result != ERROR_SUCCESS) { |
97 SetLastError(result); | 94 SetLastError(result); |
98 LOG_GETLASTERROR(ERROR) | 95 LOG_GETLASTERROR(ERROR) |
99 << "Failed to enable software SAS generation by services"; | 96 << "Failed to enable software SAS generation by services"; |
100 return false; | 97 return false; |
101 } else { | 98 } else { |
102 restore_policy_ = true; | 99 restore_policy_ = true; |
103 } | 100 } |
104 } | 101 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 174 |
178 scoped_ptr<SasInjector> SasInjector::Create() { | 175 scoped_ptr<SasInjector> SasInjector::Create() { |
179 if (base::win::OSInfo::GetInstance()->version() >= base::win::VERSION_VISTA) { | 176 if (base::win::OSInfo::GetInstance()->version() >= base::win::VERSION_VISTA) { |
180 return scoped_ptr<SasInjector>(new SasInjectorWin()); | 177 return scoped_ptr<SasInjector>(new SasInjectorWin()); |
181 } | 178 } |
182 | 179 |
183 return scoped_ptr<SasInjector>(); | 180 return scoped_ptr<SasInjector>(); |
184 } | 181 } |
185 | 182 |
186 } // namespace remoting | 183 } // namespace remoting |
OLD | NEW |