| 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 // A helper library to keep track of a user's key by SID. | 5 // A helper library to keep track of a user's key by SID. |
| 6 // Used by RLZ libary. Also to be used by SearchWithGoogle library. | 6 // Used by RLZ libary. Also to be used by SearchWithGoogle library. |
| 7 | 7 |
| 8 #include "rlz/win/lib/registry_util.h" | 8 #include "rlz/win/lib/registry_util.h" |
| 9 | 9 |
| 10 #include "base/process/process_handle.h" | 10 #include "base/process/process_handle.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 if (key.ReadValue(name, &value_string) != ERROR_SUCCESS) { | 24 if (key.ReadValue(name, &value_string) != ERROR_SUCCESS) { |
| 25 return false; | 25 return false; |
| 26 } | 26 } |
| 27 | 27 |
| 28 if (value_string.length() > *value_size) { | 28 if (value_string.length() > *value_size) { |
| 29 *value_size = value_string.length(); | 29 *value_size = value_string.length(); |
| 30 return false; | 30 return false; |
| 31 } | 31 } |
| 32 | 32 |
| 33 // Note that RLZ string are always ASCII by design. | 33 // Note that RLZ string are always ASCII by design. |
| 34 strncpy(value, WideToUTF8(value_string).c_str(), *value_size); | 34 strncpy(value, base::WideToUTF8(value_string).c_str(), *value_size); |
| 35 value[*value_size - 1] = 0; | 35 value[*value_size - 1] = 0; |
| 36 return true; | 36 return true; |
| 37 } | 37 } |
| 38 | 38 |
| 39 bool RegKeyWriteValue(base::win::RegKey& key, const wchar_t* name, | 39 bool RegKeyWriteValue(base::win::RegKey& key, const wchar_t* name, |
| 40 const char* value) { | 40 const char* value) { |
| 41 std::wstring value_string(ASCIIToWide(value)); | 41 std::wstring value_string(base::ASCIIToWide(value)); |
| 42 return key.WriteValue(name, value_string.c_str()) == ERROR_SUCCESS; | 42 return key.WriteValue(name, value_string.c_str()) == ERROR_SUCCESS; |
| 43 } | 43 } |
| 44 | 44 |
| 45 bool HasUserKeyAccess(bool write_access) { | 45 bool HasUserKeyAccess(bool write_access) { |
| 46 // The caller is trying to access HKEY_CURRENT_USER. Test to see if we can | 46 // The caller is trying to access HKEY_CURRENT_USER. Test to see if we can |
| 47 // read from there. Don't try HKEY_CURRENT_USER because this will cause | 47 // read from there. Don't try HKEY_CURRENT_USER because this will cause |
| 48 // problems in the unit tests: if we open HKEY_CURRENT_USER directly here, | 48 // problems in the unit tests: if we open HKEY_CURRENT_USER directly here, |
| 49 // the overriding done for unit tests will no longer work. So we try subkey | 49 // the overriding done for unit tests will no longer work. So we try subkey |
| 50 // "Software" which is known to always exist. | 50 // "Software" which is known to always exist. |
| 51 base::win::RegKey key; | 51 base::win::RegKey key; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 68 } | 68 } |
| 69 if (level <= base::LOW_INTEGRITY) { | 69 if (level <= base::LOW_INTEGRITY) { |
| 70 ASSERT_STRING("UserKey::HasAccess: Cannot write from Low Integrity."); | 70 ASSERT_STRING("UserKey::HasAccess: Cannot write from Low Integrity."); |
| 71 return false; | 71 return false; |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 return true; | 74 return true; |
| 75 } | 75 } |
| 76 | 76 |
| 77 } // namespace rlz_lib | 77 } // namespace rlz_lib |
| OLD | NEW |