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 "chrome/browser/chromeos/net/onc_utils.h" | 5 #include "chrome/browser/chromeos/net/onc_utils.h" |
6 | 6 |
7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 (*it)->GetAsDictionary(&network); | 257 (*it)->GetAsDictionary(&network); |
258 std::string current_guid; | 258 std::string current_guid; |
259 network->GetStringWithoutPathExpansion(onc::network_config::kGUID, | 259 network->GetStringWithoutPathExpansion(onc::network_config::kGUID, |
260 ¤t_guid); | 260 ¤t_guid); |
261 if (current_guid == guid) | 261 if (current_guid == guid) |
262 return network; | 262 return network; |
263 } | 263 } |
264 return NULL; | 264 return NULL; |
265 } | 265 } |
266 | 266 |
| 267 const base::DictionaryValue* GetNetworkConfigForEthernetWithoutEAP( |
| 268 const base::ListValue& network_configs) { |
| 269 VLOG(2) << "Search for ethernet policy without EAP."; |
| 270 for (base::ListValue::const_iterator it = network_configs.begin(); |
| 271 it != network_configs.end(); ++it) { |
| 272 const base::DictionaryValue* network = NULL; |
| 273 (*it)->GetAsDictionary(&network); |
| 274 |
| 275 std::string type; |
| 276 network->GetStringWithoutPathExpansion(onc::network_config::kType, &type); |
| 277 if (type != onc::network_type::kEthernet) |
| 278 continue; |
| 279 |
| 280 const base::DictionaryValue* ethernet = NULL; |
| 281 network->GetDictionaryWithoutPathExpansion(onc::network_config::kEthernet, |
| 282 ðernet); |
| 283 |
| 284 std::string auth; |
| 285 ethernet->GetStringWithoutPathExpansion(onc::ethernet::kAuthentication, |
| 286 &auth); |
| 287 if (auth == onc::ethernet::kNone) |
| 288 return network; |
| 289 } |
| 290 return NULL; |
| 291 } |
| 292 |
| 293 const base::DictionaryValue* GetNetworkConfigForNetworkFromOnc( |
| 294 const base::ListValue& network_configs, |
| 295 const NetworkStateBase& network) { |
| 296 // In all cases except Ethernet, we use the GUID of |network|. |
| 297 if (!network.Matches(NetworkTypePattern::Ethernet())) |
| 298 return GetNetworkConfigByGUID(network_configs, network.guid()); |
| 299 |
| 300 // Ethernet is always shared and thus cannot store a GUID per user. Thus we |
| 301 // search for any Ethernet policy intead of a matching GUID. |
| 302 // EthernetEAP service contains only the EAP parameters and stores the GUID of |
| 303 // the respective ONC policy. The EthernetEAP service itself is however never |
| 304 // in state "connected". An EthernetEAP policy must be applied, if an Ethernet |
| 305 // service is connected using the EAP parameters. |
| 306 const FavoriteState* ethernet_eap = NULL; |
| 307 if (NetworkHandler::IsInitialized()) { |
| 308 ethernet_eap = |
| 309 NetworkHandler::Get()->network_state_handler()->GetEAPForEthernet( |
| 310 &network); |
| 311 } |
| 312 |
| 313 // The GUID associated with the EthernetEAP service refers to the ONC policy |
| 314 // with "Authentication: 8021X". |
| 315 if (ethernet_eap) |
| 316 return GetNetworkConfigByGUID(network_configs, ethernet_eap->guid()); |
| 317 |
| 318 // Otherwise, EAP is not used and instead the Ethernet policy with |
| 319 // "Authentication: None" applies. |
| 320 return GetNetworkConfigForEthernetWithoutEAP(network_configs); |
| 321 } |
| 322 |
267 const base::DictionaryValue* GetPolicyForNetworkFromPref( | 323 const base::DictionaryValue* GetPolicyForNetworkFromPref( |
268 const PrefService* pref_service, | 324 const PrefService* pref_service, |
269 const char* pref_name, | 325 const char* pref_name, |
270 const NetworkStateBase& network) { | 326 const NetworkStateBase& network) { |
271 if (!pref_service) { | 327 if (!pref_service) { |
272 VLOG(2) << "No pref service"; | 328 VLOG(2) << "No pref service"; |
273 return NULL; | 329 return NULL; |
274 } | 330 } |
275 | 331 |
276 const PrefService::Preference* preference = | 332 const PrefService::Preference* preference = |
(...skipping 17 matching lines...) Expand all Loading... |
294 return NULL; | 350 return NULL; |
295 } | 351 } |
296 VLOG(2) << "Preference with policy found."; | 352 VLOG(2) << "Preference with policy found."; |
297 const base::Value* onc_policy_value = preference->GetValue(); | 353 const base::Value* onc_policy_value = preference->GetValue(); |
298 DCHECK(onc_policy_value); | 354 DCHECK(onc_policy_value); |
299 | 355 |
300 const base::ListValue* onc_policy = NULL; | 356 const base::ListValue* onc_policy = NULL; |
301 onc_policy_value->GetAsList(&onc_policy); | 357 onc_policy_value->GetAsList(&onc_policy); |
302 DCHECK(onc_policy); | 358 DCHECK(onc_policy); |
303 | 359 |
304 return GetNetworkConfigByGUID(*onc_policy, network.guid()); | 360 return GetNetworkConfigForNetworkFromOnc(*onc_policy, network); |
305 } | 361 } |
306 | 362 |
307 } // namespace | 363 } // namespace |
308 | 364 |
309 const base::DictionaryValue* GetPolicyForNetwork( | 365 const base::DictionaryValue* GetPolicyForNetwork( |
310 const PrefService* profile_prefs, | 366 const PrefService* profile_prefs, |
311 const PrefService* local_state_prefs, | 367 const PrefService* local_state_prefs, |
312 const NetworkStateBase& network, | 368 const NetworkStateBase& network, |
313 onc::ONCSource* onc_source) { | 369 onc::ONCSource* onc_source) { |
314 VLOG(2) << "GetPolicyForNetwork: " << network.path(); | 370 VLOG(2) << "GetPolicyForNetwork: " << network.path(); |
(...skipping 12 matching lines...) Expand all Loading... |
327 VLOG(1) << "Network " << network.path() << " is managed by device policy."; | 383 VLOG(1) << "Network " << network.path() << " is managed by device policy."; |
328 *onc_source = onc::ONC_SOURCE_DEVICE_POLICY; | 384 *onc_source = onc::ONC_SOURCE_DEVICE_POLICY; |
329 return network_policy; | 385 return network_policy; |
330 } | 386 } |
331 VLOG(2) << "Network " << network.path() << " is unmanaged."; | 387 VLOG(2) << "Network " << network.path() << " is unmanaged."; |
332 return NULL; | 388 return NULL; |
333 } | 389 } |
334 | 390 |
335 } // namespace onc | 391 } // namespace onc |
336 } // namespace chromeos | 392 } // namespace chromeos |
OLD | NEW |