OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/network_connection_handler.h" | 5 #include "chromeos/network/network_connection_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 "authentication-required"; | 108 "authentication-required"; |
109 const char NetworkConnectionHandler::kErrorConnectFailed[] = "connect-failed"; | 109 const char NetworkConnectionHandler::kErrorConnectFailed[] = "connect-failed"; |
110 const char NetworkConnectionHandler::kErrorDisconnectFailed[] = | 110 const char NetworkConnectionHandler::kErrorDisconnectFailed[] = |
111 "disconnect-failed"; | 111 "disconnect-failed"; |
112 const char NetworkConnectionHandler::kErrorConfigureFailed[] = | 112 const char NetworkConnectionHandler::kErrorConfigureFailed[] = |
113 "configure-failed"; | 113 "configure-failed"; |
114 const char NetworkConnectionHandler::kErrorConnectCanceled[] = | 114 const char NetworkConnectionHandler::kErrorConnectCanceled[] = |
115 "connect-canceled"; | 115 "connect-canceled"; |
116 const char NetworkConnectionHandler::kErrorCertLoadTimeout[] = | 116 const char NetworkConnectionHandler::kErrorCertLoadTimeout[] = |
117 "cert-load-timeout"; | 117 "cert-load-timeout"; |
| 118 const char NetworkConnectionHandler::kErrorUnmanagedNetwork[] = |
| 119 "unmanaged-network"; |
118 | 120 |
119 struct NetworkConnectionHandler::ConnectRequest { | 121 struct NetworkConnectionHandler::ConnectRequest { |
120 ConnectRequest(const std::string& service_path, | 122 ConnectRequest(const std::string& service_path, |
121 const std::string& profile_path, | 123 const std::string& profile_path, |
122 const base::Closure& success, | 124 const base::Closure& success, |
123 const network_handler::ErrorCallback& error) | 125 const network_handler::ErrorCallback& error) |
124 : service_path(service_path), | 126 : service_path(service_path), |
125 profile_path(profile_path), | 127 profile_path(profile_path), |
126 connect_state(CONNECT_REQUESTED), | 128 connect_state(CONNECT_REQUESTED), |
127 success_callback(success), | 129 success_callback(success), |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 | 280 |
279 // All synchronous checks passed, add |service_path| to connecting list. | 281 // All synchronous checks passed, add |service_path| to connecting list. |
280 pending_requests_.insert(std::make_pair( | 282 pending_requests_.insert(std::make_pair( |
281 service_path, | 283 service_path, |
282 ConnectRequest(service_path, profile_path, | 284 ConnectRequest(service_path, profile_path, |
283 success_callback, error_callback))); | 285 success_callback, error_callback))); |
284 | 286 |
285 // Connect immediately to 'connectable' networks. | 287 // Connect immediately to 'connectable' networks. |
286 // TODO(stevenjb): Shill needs to properly set Connectable for VPN. | 288 // TODO(stevenjb): Shill needs to properly set Connectable for VPN. |
287 if (network && network->connectable() && network->type() != shill::kTypeVPN) { | 289 if (network && network->connectable() && network->type() != shill::kTypeVPN) { |
| 290 if (IsNetworkProhibitedByPolicy(network->guid(), network->profile_path())) { |
| 291 ErrorCallbackForPendingRequest(service_path, kErrorUnmanagedNetwork); |
| 292 return; |
| 293 } |
| 294 |
288 CallShillConnect(service_path); | 295 CallShillConnect(service_path); |
289 return; | 296 return; |
290 } | 297 } |
291 | 298 |
292 // Request additional properties to check. VerifyConfiguredAndConnect will | 299 // Request additional properties to check. VerifyConfiguredAndConnect will |
293 // use only these properties, not cached properties, to ensure that they | 300 // use only these properties, not cached properties, to ensure that they |
294 // are up to date after any recent configuration. | 301 // are up to date after any recent configuration. |
295 configuration_handler_->GetShillProperties( | 302 configuration_handler_->GetShillProperties( |
296 service_path, | 303 service_path, |
297 base::Bind(&NetworkConnectionHandler::VerifyConfiguredAndConnect, | 304 base::Bind(&NetworkConnectionHandler::VerifyConfiguredAndConnect, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 } | 416 } |
410 | 417 |
411 std::string guid; | 418 std::string guid; |
412 service_properties.GetStringWithoutPathExpansion(shill::kGuidProperty, &guid); | 419 service_properties.GetStringWithoutPathExpansion(shill::kGuidProperty, &guid); |
413 std::string profile; | 420 std::string profile; |
414 service_properties.GetStringWithoutPathExpansion(shill::kProfileProperty, | 421 service_properties.GetStringWithoutPathExpansion(shill::kProfileProperty, |
415 &profile); | 422 &profile); |
416 const base::DictionaryValue* user_policy = | 423 const base::DictionaryValue* user_policy = |
417 managed_configuration_handler_->FindPolicyByGuidAndProfile(guid, profile); | 424 managed_configuration_handler_->FindPolicyByGuidAndProfile(guid, profile); |
418 | 425 |
| 426 if (IsNetworkProhibitedByPolicy(guid, profile)) { |
| 427 ErrorCallbackForPendingRequest(service_path, kErrorUnmanagedNetwork); |
| 428 return; |
| 429 } |
| 430 |
419 client_cert::ClientCertConfig cert_config_from_policy; | 431 client_cert::ClientCertConfig cert_config_from_policy; |
420 if (user_policy) | 432 if (user_policy) |
421 client_cert::OncToClientCertConfig(*user_policy, &cert_config_from_policy); | 433 client_cert::OncToClientCertConfig(*user_policy, &cert_config_from_policy); |
422 | 434 |
423 client_cert::ConfigType client_cert_type = client_cert::CONFIG_TYPE_NONE; | 435 client_cert::ConfigType client_cert_type = client_cert::CONFIG_TYPE_NONE; |
424 if (type == shill::kTypeVPN) { | 436 if (type == shill::kTypeVPN) { |
425 if (vpn_provider_type == shill::kProviderOpenVpn) { | 437 if (vpn_provider_type == shill::kProviderOpenVpn) { |
426 client_cert_type = client_cert::CONFIG_TYPE_OPENVPN; | 438 client_cert_type = client_cert::CONFIG_TYPE_OPENVPN; |
427 } else { | 439 } else { |
428 // L2TP/IPSec only requires a certificate if one is specified in ONC | 440 // L2TP/IPSec only requires a certificate if one is specified in ONC |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 // Otherwise, we probably still need to configure the network since | 528 // Otherwise, we probably still need to configure the network since |
517 // 'Connectable' is false. If |check_error_state| is true, signal an | 529 // 'Connectable' is false. If |check_error_state| is true, signal an |
518 // error, otherwise attempt to connect to possibly gain additional error | 530 // error, otherwise attempt to connect to possibly gain additional error |
519 // state from Shill (or in case 'Connectable' is improperly unset). | 531 // state from Shill (or in case 'Connectable' is improperly unset). |
520 if (check_error_state) | 532 if (check_error_state) |
521 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); | 533 ErrorCallbackForPendingRequest(service_path, kErrorConfigurationRequired); |
522 else | 534 else |
523 CallShillConnect(service_path); | 535 CallShillConnect(service_path); |
524 } | 536 } |
525 | 537 |
| 538 bool NetworkConnectionHandler::IsNetworkProhibitedByPolicy( |
| 539 const std::string& guid, |
| 540 const std::string& profile_path) { |
| 541 if (!logged_in_) |
| 542 return false; |
| 543 const base::DictionaryValue* global_network_config = |
| 544 managed_configuration_handler_->GetGlobalConfigFromPolicy( |
| 545 std::string() /* no username hash, device policy */); |
| 546 if (!global_network_config) |
| 547 return false; |
| 548 bool policy_prohibites = false; |
| 549 if (!global_network_config->GetBooleanWithoutPathExpansion( |
| 550 ::onc::global_network_config::kAllowOnlyPolicyNetworksToConnect, |
| 551 &policy_prohibites) || |
| 552 !policy_prohibites) { |
| 553 return false; |
| 554 } |
| 555 return !managed_configuration_handler_->FindPolicyByGuidAndProfile( |
| 556 guid, profile_path); |
| 557 } |
| 558 |
526 void NetworkConnectionHandler::QueueConnectRequest( | 559 void NetworkConnectionHandler::QueueConnectRequest( |
527 const std::string& service_path) { | 560 const std::string& service_path) { |
528 ConnectRequest* request = GetPendingRequest(service_path); | 561 ConnectRequest* request = GetPendingRequest(service_path); |
529 if (!request) { | 562 if (!request) { |
530 NET_LOG_ERROR("No pending request to queue", service_path); | 563 NET_LOG_ERROR("No pending request to queue", service_path); |
531 return; | 564 return; |
532 } | 565 } |
533 | 566 |
534 const int kMaxCertLoadTimeSeconds = 15; | 567 const int kMaxCertLoadTimeSeconds = 15; |
535 base::TimeDelta dtime = base::TimeTicks::Now() - logged_in_time_; | 568 base::TimeDelta dtime = base::TimeTicks::Now() - logged_in_time_; |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 | 805 |
773 void NetworkConnectionHandler::HandleShillDisconnectSuccess( | 806 void NetworkConnectionHandler::HandleShillDisconnectSuccess( |
774 const std::string& service_path, | 807 const std::string& service_path, |
775 const base::Closure& success_callback) { | 808 const base::Closure& success_callback) { |
776 NET_LOG_EVENT("Disconnect Request Sent", service_path); | 809 NET_LOG_EVENT("Disconnect Request Sent", service_path); |
777 if (!success_callback.is_null()) | 810 if (!success_callback.is_null()) |
778 success_callback.Run(); | 811 success_callback.Run(); |
779 } | 812 } |
780 | 813 |
781 } // namespace chromeos | 814 } // namespace chromeos |
OLD | NEW |