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" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/chromeos/login/user.h" | 12 #include "chrome/browser/chromeos/login/user.h" |
13 #include "chrome/browser/chromeos/login/user_manager.h" | 13 #include "chrome/browser/chromeos/login/user_manager.h" |
14 #include "chrome/browser/chromeos/ui_proxy_config.h" | 14 #include "chrome/browser/chromeos/ui_proxy_config.h" |
15 #include "chrome/browser/prefs/proxy_config_dictionary.h" | 15 #include "chrome/browser/prefs/proxy_config_dictionary.h" |
16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
17 #include "chromeos/network/favorite_state.h" | 17 #include "chromeos/network/favorite_state.h" |
18 #include "chromeos/network/managed_network_configuration_handler.h" | 18 #include "chromeos/network/managed_network_configuration_handler.h" |
19 #include "chromeos/network/network_configuration_handler.h" | 19 #include "chromeos/network/network_configuration_handler.h" |
20 #include "chromeos/network/network_handler.h" | 20 #include "chromeos/network/network_handler.h" |
21 #include "chromeos/network/network_profile.h" | 21 #include "chromeos/network/network_profile.h" |
22 #include "chromeos/network/network_profile_handler.h" | 22 #include "chromeos/network/network_profile_handler.h" |
23 #include "chromeos/network/network_state.h" | 23 #include "chromeos/network/network_state.h" |
24 #include "chromeos/network/network_state_handler.h" | |
24 #include "chromeos/network/network_ui_data.h" | 25 #include "chromeos/network/network_ui_data.h" |
25 #include "chromeos/network/onc/onc_normalizer.h" | 26 #include "chromeos/network/onc/onc_normalizer.h" |
26 #include "chromeos/network/onc/onc_signature.h" | 27 #include "chromeos/network/onc/onc_signature.h" |
27 #include "chromeos/network/onc/onc_translator.h" | 28 #include "chromeos/network/onc/onc_translator.h" |
28 #include "chromeos/network/onc/onc_utils.h" | 29 #include "chromeos/network/onc/onc_utils.h" |
30 #include "chromeos/network/shill_property_util.h" | |
29 #include "net/base/host_port_pair.h" | 31 #include "net/base/host_port_pair.h" |
30 #include "net/proxy/proxy_bypass_rules.h" | 32 #include "net/proxy/proxy_bypass_rules.h" |
31 #include "net/proxy/proxy_server.h" | 33 #include "net/proxy/proxy_server.h" |
32 #include "third_party/cros_system_api/dbus/service_constants.h" | 34 #include "third_party/cros_system_api/dbus/service_constants.h" |
33 #include "url/gurl.h" | 35 #include "url/gurl.h" |
34 | 36 |
35 namespace chromeos { | 37 namespace chromeos { |
36 namespace onc { | 38 namespace onc { |
37 | 39 |
38 namespace { | 40 namespace { |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 (*it)->GetAsDictionary(&network); | 257 (*it)->GetAsDictionary(&network); |
256 std::string current_guid; | 258 std::string current_guid; |
257 network->GetStringWithoutPathExpansion(onc::network_config::kGUID, | 259 network->GetStringWithoutPathExpansion(onc::network_config::kGUID, |
258 ¤t_guid); | 260 ¤t_guid); |
259 if (current_guid == guid) | 261 if (current_guid == guid) |
260 return network; | 262 return network; |
261 } | 263 } |
262 return NULL; | 264 return NULL; |
263 } | 265 } |
264 | 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); | |
stevenjb
2013/09/17 16:22:59
if (!GetAsDictionary()) { ERROR, continue }
pneubeck (no reviews)
2013/09/30 20:08:31
Done.
| |
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); | |
stevenjb
2013/09/17 16:22:59
if (!GetDictionary...) { ERROR, continue }
pneubeck (no reviews)
2013/09/30 20:08:31
Done.
| |
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 ManagedState& network, | |
296 const std::string& network_guid) { | |
stevenjb
2013/09/17 16:22:59
I really think all of these should just take eithe
pneubeck (no reviews)
2013/09/30 20:08:31
Done.
| |
297 // In all cases except Ethernet, we use the GUID of |network|. | |
298 if (!network.Matches(NetworkTypePattern::Ethernet())) | |
299 return GetNetworkConfigByGUID(network_configs, network_guid); | |
300 | |
301 // Ethernet is always shared and thus cannot store a GUID per user. Thus we | |
302 // search for any Ethernet policy intead of a matching GUID. | |
303 // EthernetEAP service contains only the EAP parameters and stores the GUID of | |
304 // the respective ONC policy. The EthernetEAP service itself is however never | |
305 // in state "connected". An EthernetEAP policy must be applied, if an Ethernet | |
306 // service is connected using the EAP parameters. | |
307 const FavoriteState* ethernet_eap = NULL; | |
308 if (NetworkHandler::IsInitialized()) { | |
309 ethernet_eap = | |
310 NetworkHandler::Get()->network_state_handler()->GetEAPForEthernet( | |
311 network.path()); | |
312 } | |
313 | |
314 // The GUID associated with the EthernetEAP service refers to the ONC policy | |
315 // with "Authentication: 8021X". | |
316 if (ethernet_eap) | |
317 return GetNetworkConfigByGUID(network_configs, ethernet_eap->guid()); | |
318 | |
319 // Otherwise, EAP is not used and instead the Ethernet policy with | |
320 // "Authentication: None" applies. | |
321 return GetNetworkConfigForEthernetWithoutEAP(network_configs); | |
322 } | |
323 | |
265 const base::DictionaryValue* GetPolicyForNetworkFromPref( | 324 const base::DictionaryValue* GetPolicyForNetworkFromPref( |
266 const PrefService* pref_service, | 325 const PrefService* pref_service, |
267 const char* pref_name, | 326 const char* pref_name, |
327 const ManagedState& network, | |
268 const std::string& network_guid) { | 328 const std::string& network_guid) { |
269 if (!pref_service) { | 329 if (!pref_service) { |
270 VLOG(2) << "No pref service"; | 330 VLOG(2) << "No pref service"; |
271 return NULL; | 331 return NULL; |
272 } | 332 } |
273 | 333 |
274 const PrefService::Preference* preference = | 334 const PrefService::Preference* preference = |
275 pref_service->FindPreference(pref_name); | 335 pref_service->FindPreference(pref_name); |
276 if (!preference) { | 336 if (!preference) { |
277 VLOG(2) << "No preference " << pref_name; | 337 VLOG(2) << "No preference " << pref_name; |
(...skipping 14 matching lines...) Expand all Loading... | |
292 return NULL; | 352 return NULL; |
293 } | 353 } |
294 VLOG(2) << "Preference with policy found."; | 354 VLOG(2) << "Preference with policy found."; |
295 const base::Value* onc_policy_value = preference->GetValue(); | 355 const base::Value* onc_policy_value = preference->GetValue(); |
296 DCHECK(onc_policy_value); | 356 DCHECK(onc_policy_value); |
297 | 357 |
298 const base::ListValue* onc_policy = NULL; | 358 const base::ListValue* onc_policy = NULL; |
299 onc_policy_value->GetAsList(&onc_policy); | 359 onc_policy_value->GetAsList(&onc_policy); |
300 DCHECK(onc_policy); | 360 DCHECK(onc_policy); |
301 | 361 |
302 return GetNetworkConfigByGUID(*onc_policy, network_guid); | 362 return GetNetworkConfigForNetworkFromOnc(*onc_policy, network, network_guid); |
303 } | 363 } |
304 | 364 |
305 const base::DictionaryValue* GetPolicyForNetwork( | 365 const base::DictionaryValue* GetPolicyForNetwork( |
306 const PrefService* profile_prefs, | 366 const PrefService* profile_prefs, |
307 const PrefService* local_state_prefs, | 367 const PrefService* local_state_prefs, |
308 const std::string& network_path, | 368 const ManagedState& network, |
309 const std::string& network_guid, | 369 const std::string& network_guid, |
310 onc::ONCSource* onc_source) { | 370 onc::ONCSource* onc_source) { |
311 VLOG(2) << "GetPolicyForNetwork: " << network_path; | 371 VLOG(2) << "GetPolicyForNetwork: " << network.path(); |
312 *onc_source = onc::ONC_SOURCE_NONE; | 372 *onc_source = onc::ONC_SOURCE_NONE; |
313 | 373 |
314 const base::DictionaryValue* network_policy = GetPolicyForNetworkFromPref( | 374 const base::DictionaryValue* network_policy = GetPolicyForNetworkFromPref( |
315 profile_prefs, prefs::kOpenNetworkConfiguration, network_guid); | 375 profile_prefs, prefs::kOpenNetworkConfiguration, network, network_guid); |
316 if (network_policy) { | 376 if (network_policy) { |
317 VLOG(1) << "Network " << network_path << " is managed by user policy."; | 377 VLOG(1) << "Network " << network.path() << " is managed by user policy."; |
318 *onc_source = onc::ONC_SOURCE_USER_POLICY; | 378 *onc_source = onc::ONC_SOURCE_USER_POLICY; |
319 return network_policy; | 379 return network_policy; |
320 } | 380 } |
321 network_policy = GetPolicyForNetworkFromPref( | 381 network_policy = |
322 local_state_prefs, prefs::kDeviceOpenNetworkConfiguration, network_guid); | 382 GetPolicyForNetworkFromPref(local_state_prefs, |
383 prefs::kDeviceOpenNetworkConfiguration, | |
384 network, | |
385 network_guid); | |
323 if (network_policy) { | 386 if (network_policy) { |
324 VLOG(1) << "Network " << network_path << " is managed by device policy."; | 387 VLOG(1) << "Network " << network.path() << " is managed by device policy."; |
325 *onc_source = onc::ONC_SOURCE_DEVICE_POLICY; | 388 *onc_source = onc::ONC_SOURCE_DEVICE_POLICY; |
326 return network_policy; | 389 return network_policy; |
327 } | 390 } |
328 VLOG(2) << "Network " << network_path << " is unmanaged."; | 391 VLOG(2) << "Network " << network.path() << " is unmanaged."; |
329 return NULL; | 392 return NULL; |
330 } | 393 } |
331 | 394 |
332 } // namespace | 395 } // namespace |
333 | 396 |
334 const base::DictionaryValue* GetPolicyForNetwork( | 397 const base::DictionaryValue* GetPolicyForNetwork( |
335 const PrefService* profile_prefs, | 398 const PrefService* profile_prefs, |
336 const PrefService* local_state_prefs, | 399 const PrefService* local_state_prefs, |
337 const NetworkState& network, | 400 const NetworkState& network, |
338 onc::ONCSource* onc_source) { | 401 onc::ONCSource* onc_source) { |
339 return GetPolicyForNetwork(profile_prefs, | 402 return GetPolicyForNetwork( |
340 local_state_prefs, | 403 profile_prefs, local_state_prefs, network, network.guid(), onc_source); |
341 network.path(), | |
342 network.guid(), | |
343 onc_source); | |
344 } | 404 } |
345 | 405 |
346 const base::DictionaryValue* GetPolicyForNetwork( | 406 const base::DictionaryValue* GetPolicyForNetwork( |
347 const PrefService* profile_prefs, | 407 const PrefService* profile_prefs, |
348 const PrefService* local_state_prefs, | 408 const PrefService* local_state_prefs, |
349 const FavoriteState& favorite, | 409 const FavoriteState& favorite, |
350 onc::ONCSource* onc_source) { | 410 onc::ONCSource* onc_source) { |
351 return GetPolicyForNetwork(profile_prefs, | 411 return GetPolicyForNetwork( |
352 local_state_prefs, | 412 profile_prefs, local_state_prefs, favorite, favorite.guid(), onc_source); |
353 favorite.path(), | |
354 favorite.guid(), | |
355 onc_source); | |
356 } | 413 } |
357 | 414 |
358 } // namespace onc | 415 } // namespace onc |
359 } // namespace chromeos | 416 } // namespace chromeos |
OLD | NEW |