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

Unified Diff: chrome/browser/extensions/api/networking_private/networking_private_api_chromeos.cc

Issue 242983004: Disable some API calls in networkingPrivate for non-primary user (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fail to configure networks from non-primary user Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/networking_private/networking_private_api_chromeos.cc
diff --git a/chrome/browser/extensions/api/networking_private/networking_private_api_chromeos.cc b/chrome/browser/extensions/api/networking_private/networking_private_api_chromeos.cc
index 81bda9eec2e36073a7b70b72fede42f2283161c2..56c6284e53be1e9373c4938b43ec9da29ce9d11a 100644
--- a/chrome/browser/extensions/api/networking_private/networking_private_api_chromeos.cc
+++ b/chrome/browser/extensions/api/networking_private/networking_private_api_chromeos.cc
@@ -7,17 +7,16 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/callback.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/browser/browser_process_platform_part_chromeos.h"
#include "chrome/browser/chromeos/net/network_portal_detector.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
-#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/common/extensions/api/networking_private.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/shill_manager_client.h"
+#include "chromeos/login/login_state.h"
#include "chromeos/network/managed_network_configuration_handler.h"
#include "chromeos/network/network_connection_handler.h"
#include "chromeos/network/network_device_handler.h"
+#include "chromeos/network/network_event_log.h"
#include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
#include "chromeos/network/network_util.h"
@@ -25,6 +24,7 @@
#include "chromeos/network/onc/onc_translator.h"
#include "chromeos/network/onc/onc_utils.h"
#include "components/onc/onc_constants.h"
+#include "content/public/browser/browser_context.h"
#include "extensions/browser/extension_function_registry.h"
namespace api = extensions::api::networking_private;
@@ -62,9 +62,20 @@ ShillManagerClient::VerificationProperties ConvertVerificationProperties(
return output;
}
-std::string GetUserIdHash(Profile* profile) {
- return g_browser_process->platform_part()->
- profile_helper()->GetUserIdHashFromProfile(profile);
+bool GetUserIdHash(content::BrowserContext* browser_context,
+ std::string* user_hash) {
+ // Currently Chrome OS only configures networks for the primary user.
+ // Configuration attempts from other profiles should fail. TODO(stevenjb):
+ // use an ExtensionsBrowserClient method to access ProfileHelper when moving
+ // this to src/extensions.
+ std::string current_user_hash =
+ chromeos::ProfileHelper::GetUserIdHashFromProfile(
+ static_cast<Profile*>(browser_context));
+
+ if (current_user_hash != chromeos::LoginState::Get()->primary_user_hash())
+ return false;
+ *user_hash = current_user_hash;
+ return true;
}
bool GetServicePathFromGuid(const std::string& guid,
@@ -137,7 +148,15 @@ bool NetworkingPrivateGetManagedPropertiesFunction::RunAsync() {
return false;
std::string user_id_hash;
- GetUserIdHash(GetProfile());
+ if (!GetUserIdHash(browser_context(), &user_id_hash)) {
+ // It is OK to call getManagedProperties from a non-primary user context
+ // for the purposes of displaying network properites. |user_id_hash| will
pneubeck (no reviews) 2014/06/12 09:51:00 typo: properites -> properties
stevenjb 2014/06/12 20:27:51 Done.
+ // be empty, so no properties from the profile (e.g. proxy config) will be
pneubeck (no reviews) 2014/06/12 18:26:18 this comment is still wrong / misleading and bring
stevenjb 2014/06/12 20:27:51 Disallowing for now to simplify.
+ // included.
pneubeck (no reviews) 2014/06/12 09:51:00 the MNCH wasn't written with empty user hashes in
pneubeck (no reviews) 2014/06/12 10:17:47 Thinking more about it, MNCH shouldn't ever get an
stevenjb 2014/06/12 20:27:51 For now I am only disallowing calls that require a
+ NET_LOG_DEBUG("getManagedProperties called from non primary user context",
+ browser_context()->GetPath().value());
+ }
+
NetworkHandler::Get()->managed_network_configuration_handler()->
GetManagedProperties(
user_id_hash,
@@ -249,8 +268,15 @@ bool NetworkingPrivateCreateNetworkFunction::RunAsync() {
EXTENSION_FUNCTION_VALIDATE(params);
std::string user_id_hash;
stevenjb 2014/06/12 20:27:51 We are already currently passing an empty user_id_
pneubeck (no reviews) 2014/06/13 08:51:12 Whether empty user_id_hash is the right way to com
- if (!params->shared)
- user_id_hash = GetUserIdHash(GetProfile());
+ if (!params->shared &&
+ !GetUserIdHash(browser_context(), &user_id_hash)) {
+ // Do not allow configuring a non-shared network from a non-primary user
+ // context.
+ NET_LOG_ERROR("createNetwork called from non primary user.",
+ browser_context()->GetPath().value());
+ error_ = "Error.NonPrimaryUser";
+ return false;
+ }
scoped_ptr<base::DictionaryValue> properties_dict(
params->properties.ToValue());

Powered by Google App Engine
This is Rietveld 408576698