Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: extensions/browser/api/networking_private/networking_private_chromeos.cc

Issue 2754903002: Prevent networkingPrivate.forgetNetwork from removing shared configs (Closed)
Patch Set: . Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/browser/api/networking_private/networking_private_chromeos. h" 5 #include "extensions/browser/api/networking_private/networking_private_chromeos. h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 } 437 }
438 438
439 GetManagedConfigurationHandler()->CreateConfiguration( 439 GetManagedConfigurationHandler()->CreateConfiguration(
440 user_id_hash, *properties, 440 user_id_hash, *properties,
441 base::Bind(&NetworkHandlerCreateCallback, success_callback), 441 base::Bind(&NetworkHandlerCreateCallback, success_callback),
442 base::Bind(&NetworkHandlerFailureCallback, failure_callback)); 442 base::Bind(&NetworkHandlerFailureCallback, failure_callback));
443 } 443 }
444 444
445 void NetworkingPrivateChromeOS::ForgetNetwork( 445 void NetworkingPrivateChromeOS::ForgetNetwork(
446 const std::string& guid, 446 const std::string& guid,
447 bool allow_forget_shared_config,
447 const VoidCallback& success_callback, 448 const VoidCallback& success_callback,
448 const FailureCallback& failure_callback) { 449 const FailureCallback& failure_callback) {
449 std::string service_path, error; 450 std::string service_path, error;
450 if (!GetServicePathFromGuid(guid, &service_path, &error)) { 451 if (!GetServicePathFromGuid(guid, &service_path, &error)) {
451 failure_callback.Run(error); 452 failure_callback.Run(error);
452 return; 453 return;
453 } 454 }
454 455
455 GetManagedConfigurationHandler()->RemoveConfiguration( 456 const chromeos::NetworkState* network =
456 service_path, success_callback, 457 GetStateHandler()->GetNetworkStateFromServicePath(
457 base::Bind(&NetworkHandlerFailureCallback, failure_callback)); 458 service_path, true /* configured only */);
459 if (!network) {
460 failure_callback.Run(networking_private::kErrorNetworkUnavailable);
461 return;
462 }
463
464 std::string user_id_hash;
465 // Don't allow non-primary user to remove private configs - the private
466 // configs belong to the primary user (non-primary users' network configs
467 // never get loaded by shill).
468 if (!GetPrimaryUserIdHash(browser_context_, &user_id_hash, &error) &&
469 network->IsPrivate()) {
470 failure_callback.Run(error);
471 return;
472 }
473
474 if (!allow_forget_shared_config && !network->IsPrivate()) {
475 failure_callback.Run(networking_private::kErrorAccessToSharedConfig);
476 return;
477 }
478
479 onc::ONCSource onc_source = onc::ONC_SOURCE_UNKNOWN;
480 if (GetManagedConfigurationHandler()->FindPolicyByGUID(user_id_hash, guid,
481 &onc_source)) {
482 // Fail if requested configuration removal includes a policy controlled
483 // network configuration.
484 if (allow_forget_shared_config ||
485 onc_source == onc::ONC_SOURCE_USER_POLICY) {
stevenjb 2017/03/30 17:33:13 This logic is confusing to follow. I guess it is s
tbarzic 2017/03/30 18:00:05 yeah, good point. Done.
486 failure_callback.Run(networking_private::kErrorPolicyControlled);
487 return;
488 }
489 }
490
491 if (allow_forget_shared_config) {
492 GetManagedConfigurationHandler()->RemoveConfiguration(
493 service_path, success_callback,
494 base::Bind(&NetworkHandlerFailureCallback, failure_callback));
495 } else {
496 GetManagedConfigurationHandler()->RemoveConfigurationFromCurrentProfile(
497 service_path, success_callback,
498 base::Bind(&NetworkHandlerFailureCallback, failure_callback));
499 }
458 } 500 }
459 501
460 void NetworkingPrivateChromeOS::GetNetworks( 502 void NetworkingPrivateChromeOS::GetNetworks(
461 const std::string& network_type, 503 const std::string& network_type,
462 bool configured_only, 504 bool configured_only,
463 bool visible_only, 505 bool visible_only,
464 int limit, 506 int limit,
465 const NetworkListCallback& success_callback, 507 const NetworkListCallback& success_callback,
466 const FailureCallback& failure_callback) { 508 const FailureCallback& failure_callback) {
467 NetworkTypePattern pattern = 509 NetworkTypePattern pattern =
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 // Eventually the caller (e.g. Settings) should handle any failures and 894 // Eventually the caller (e.g. Settings) should handle any failures and
853 // show its own configuration UI. crbug.com/380937. 895 // show its own configuration UI. crbug.com/380937.
854 if (ui_delegate()->HandleConnectFailed(guid, error_name)) { 896 if (ui_delegate()->HandleConnectFailed(guid, error_name)) {
855 success_callback.Run(); 897 success_callback.Run();
856 return; 898 return;
857 } 899 }
858 failure_callback.Run(error_name); 900 failure_callback.Run(error_name);
859 } 901 }
860 902
861 } // namespace extensions 903 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698