| 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 // Library functions related to the OEM Deal Confirmation Code. | 5 // Library functions related to the OEM Deal Confirmation Code. |
| 6 | 6 |
| 7 #include "rlz/win/lib/machine_deal.h" | 7 #include "rlz/win/lib/machine_deal.h" |
| 8 | 8 |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 17 #include "base/win/registry.h" | 17 #include "base/win/registry.h" |
| 18 #include "rlz/lib/assert.h" | 18 #include "rlz/lib/assert.h" |
| 19 #include "rlz/lib/lib_values.h" | 19 #include "rlz/lib/lib_values.h" |
| 20 #include "rlz/win/lib/lib_mutex.h" | 20 #include "rlz/win/lib/lib_mutex.h" |
| 21 #include "rlz/win/lib/registry_util.h" | 21 #include "rlz/win/lib/registry_util.h" |
| 22 #include "rlz/win/lib/rlz_value_store_registry.h" | 22 #include "rlz/win/lib/rlz_value_store_registry.h" |
| 23 | 23 |
| 24 namespace { |
| 25 |
| 24 const wchar_t kDccValueName[] = L"DCC"; | 26 const wchar_t kDccValueName[] = L"DCC"; |
| 25 | 27 |
| 26 namespace { | |
| 27 | |
| 28 // Current DCC can only uses [a-zA-Z0-9_-!@$*();.<>,:] | 28 // Current DCC can only uses [a-zA-Z0-9_-!@$*();.<>,:] |
| 29 // We will be more liberal and allow some additional chars, but not url meta | 29 // We will be more liberal and allow some additional chars, but not url meta |
| 30 // chars. | 30 // chars. |
| 31 bool IsGoodDccChar(char ch) { | 31 bool IsGoodDccChar(char ch) { |
| 32 if (IsAsciiAlpha(ch) || IsAsciiDigit(ch)) | 32 if (IsAsciiAlpha(ch) || IsAsciiDigit(ch)) |
| 33 return true; | 33 return true; |
| 34 | 34 |
| 35 switch (ch) { | 35 switch (ch) { |
| 36 case '_': | 36 case '_': |
| 37 case '-': | 37 case '-': |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 base::SplitString(response_line, ':', &tokens); | 110 base::SplitString(response_line, ':', &tokens); |
| 111 if (tokens.size() != 2) | 111 if (tokens.size() != 2) |
| 112 return false; | 112 return false; |
| 113 | 113 |
| 114 // The first token is the key, the second is the value. The value is already | 114 // The first token is the key, the second is the value. The value is already |
| 115 // trimmed for whitespace. | 115 // trimmed for whitespace. |
| 116 *value = tokens[1]; | 116 *value = tokens[1]; |
| 117 return true; | 117 return true; |
| 118 } | 118 } |
| 119 | 119 |
| 120 } // namespace anonymous | 120 } // namespace |
| 121 | 121 |
| 122 namespace rlz_lib { | 122 namespace rlz_lib { |
| 123 | 123 |
| 124 bool MachineDealCode::Set(const char* dcc) { | 124 bool MachineDealCode::Set(const char* dcc) { |
| 125 LibMutex lock; | 125 LibMutex lock; |
| 126 if (lock.failed()) | 126 if (lock.failed()) |
| 127 return false; | 127 return false; |
| 128 | 128 |
| 129 // TODO: if (!ProcessInfo::CanWriteMachineKey()) return false; | 129 // TODO: if (!ProcessInfo::CanWriteMachineKey()) return false; |
| 130 | 130 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 143 " Did you call rlz_lib::CreateMachineState()?"); | 143 " Did you call rlz_lib::CreateMachineState()?"); |
| 144 return false; | 144 return false; |
| 145 } | 145 } |
| 146 | 146 |
| 147 char normalized_dcc[kMaxDccLength + 1]; | 147 char normalized_dcc[kMaxDccLength + 1]; |
| 148 NormalizeDcc(dcc, normalized_dcc); | 148 NormalizeDcc(dcc, normalized_dcc); |
| 149 VERIFY(length == strlen(normalized_dcc)); | 149 VERIFY(length == strlen(normalized_dcc)); |
| 150 | 150 |
| 151 // Write the DCC to HKLM. Note that we need to include the null character | 151 // Write the DCC to HKLM. Note that we need to include the null character |
| 152 // when writing the string. | 152 // when writing the string. |
| 153 if (!RegKeyWriteValue(hklm_key, kDccValueName, normalized_dcc)) { | 153 if (!RegKeyWriteValue(&hklm_key, kDccValueName, normalized_dcc)) { |
| 154 ASSERT_STRING("MachineDealCode::Set: Could not write the DCC value"); | 154 ASSERT_STRING("MachineDealCode::Set: Could not write the DCC value"); |
| 155 return false; | 155 return false; |
| 156 } | 156 } |
| 157 | 157 |
| 158 return true; | 158 return true; |
| 159 } | 159 } |
| 160 | 160 |
| 161 bool MachineDealCode::GetNewCodeFromPingResponse(const char* response, | 161 bool MachineDealCode::GetNewCodeFromPingResponse(const char* response, |
| 162 bool* has_new_dcc, char* new_dcc, int new_dcc_size) { | 162 bool* has_new_dcc, char* new_dcc, int new_dcc_size) { |
| 163 if (!has_new_dcc || !new_dcc || !new_dcc_size) | 163 if (!has_new_dcc || !new_dcc || !new_dcc_size) |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 DWORD dcc_size = arraysize(dcc); | 291 DWORD dcc_size = arraysize(dcc); |
| 292 if (dcc_key.ReadValue(kDccValueName, dcc, &dcc_size, NULL) == ERROR_SUCCESS) { | 292 if (dcc_key.ReadValue(kDccValueName, dcc, &dcc_size, NULL) == ERROR_SUCCESS) { |
| 293 ASSERT_STRING("MachineDealCode::Clear: Could not delete the DCC value."); | 293 ASSERT_STRING("MachineDealCode::Clear: Could not delete the DCC value."); |
| 294 return false; | 294 return false; |
| 295 } | 295 } |
| 296 | 296 |
| 297 return true; | 297 return true; |
| 298 } | 298 } |
| 299 | 299 |
| 300 } // namespace rlz_lib | 300 } // namespace rlz_lib |
| OLD | NEW |