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 "chromeos/network/onc/onc_utils.h" | 5 #include "chromeos/network/onc/onc_utils.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_util.h" |
10 #include "base/values.h" | 11 #include "base/values.h" |
11 #include "chromeos/network/network_event_log.h" | 12 #include "chromeos/network/network_event_log.h" |
12 #include "chromeos/network/onc/onc_constants.h" | |
13 #include "crypto/encryptor.h" | 13 #include "crypto/encryptor.h" |
14 #include "crypto/hmac.h" | 14 #include "crypto/hmac.h" |
15 #include "crypto/symmetric_key.h" | 15 #include "crypto/symmetric_key.h" |
16 | 16 |
17 #define ONC_LOG_WARNING(message) NET_LOG_WARNING("ONC", message) | 17 #define ONC_LOG_WARNING(message) NET_LOG_WARNING("ONC", message) |
18 #define ONC_LOG_ERROR(message) NET_LOG_ERROR("ONC", message) | 18 #define ONC_LOG_ERROR(message) NET_LOG_ERROR("ONC", message) |
19 | 19 |
20 namespace chromeos { | 20 namespace chromeos { |
21 namespace onc { | 21 namespace onc { |
22 | 22 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 return "user policy"; | 157 return "user policy"; |
158 case ONC_SOURCE_NONE: | 158 case ONC_SOURCE_NONE: |
159 return "none"; | 159 return "none"; |
160 case ONC_SOURCE_USER_IMPORT: | 160 case ONC_SOURCE_USER_IMPORT: |
161 return "user import"; | 161 return "user import"; |
162 } | 162 } |
163 NOTREACHED() << "unknown ONC source " << source; | 163 NOTREACHED() << "unknown ONC source " << source; |
164 return "unknown"; | 164 return "unknown"; |
165 } | 165 } |
166 | 166 |
167 } // chromeos | 167 void ExpandField(const std::string fieldname, |
168 } // onc | 168 const StringSubstitution& substitution, |
| 169 base::DictionaryValue* onc_object) { |
| 170 std::string user_string; |
| 171 if (!onc_object->GetStringWithoutPathExpansion(fieldname, &user_string)) |
| 172 return; |
| 173 |
| 174 std::string login_id; |
| 175 if (substitution.GetSubstitute(substitutes::kLoginIDField, &login_id)) { |
| 176 ReplaceSubstringsAfterOffset(&user_string, 0, |
| 177 onc::substitutes::kLoginIDField, |
| 178 login_id); |
| 179 } |
| 180 |
| 181 std::string email; |
| 182 if (substitution.GetSubstitute(substitutes::kEmailField, &email)) { |
| 183 ReplaceSubstringsAfterOffset(&user_string, 0, |
| 184 onc::substitutes::kEmailField, |
| 185 email); |
| 186 } |
| 187 |
| 188 onc_object->SetStringWithoutPathExpansion(fieldname, user_string); |
| 189 } |
| 190 |
| 191 void ExpandStringsInOncObject( |
| 192 const OncValueSignature& signature, |
| 193 const StringSubstitution& substitution, |
| 194 base::DictionaryValue* onc_object) { |
| 195 if (&signature == &kEAPSignature) { |
| 196 ExpandField(eap::kAnonymousIdentity, substitution, onc_object); |
| 197 ExpandField(eap::kIdentity, substitution, onc_object); |
| 198 } else if (&signature == &kL2TPSignature || |
| 199 &signature == &kOpenVPNSignature) { |
| 200 ExpandField(vpn::kUsername, substitution, onc_object); |
| 201 } |
| 202 |
| 203 // Recurse into nested objects. |
| 204 for (base::DictionaryValue::key_iterator it = onc_object->begin_keys(); |
| 205 it != onc_object->end_keys(); ++it) { |
| 206 base::DictionaryValue* inner_object; |
| 207 if (!onc_object->GetDictionaryWithoutPathExpansion(*it, &inner_object)) |
| 208 continue; |
| 209 |
| 210 const OncFieldSignature* field_signature = |
| 211 GetFieldSignature(signature, *it); |
| 212 |
| 213 ExpandStringsInOncObject(*field_signature->value_signature, |
| 214 substitution, inner_object); |
| 215 } |
| 216 } |
| 217 |
| 218 } // namespace onc |
| 219 } // namespace chromeos |
OLD | NEW |