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

Unified Diff: chromeos/dbus/fake_auth_policy_client.cc

Issue 2653913002: Check username validity in the FakeAuthPolicyClient (Closed)
Patch Set: Comments Created 3 years, 11 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
« no previous file with comments | « chromeos/chromeos.gyp ('k') | chromeos/dbus/fake_auth_policy_client_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/dbus/fake_auth_policy_client.cc
diff --git a/chromeos/dbus/fake_auth_policy_client.cc b/chromeos/dbus/fake_auth_policy_client.cc
index f37f1ea53bc88d6aa576485db9d67fb310e6978b..4f3a35ded30f6a9d54b64ba1d7c329a6f8eebb20 100644
--- a/chromeos/dbus/fake_auth_policy_client.cc
+++ b/chromeos/dbus/fake_auth_policy_client.cc
@@ -10,6 +10,7 @@
#include "base/location.h"
#include "base/md5.h"
#include "base/path_service.h"
+#include "base/strings/string_split.h"
#include "base/task_scheduler/post_task.h"
#include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
#include "chromeos/chromeos_paths.h"
@@ -24,6 +25,9 @@ namespace em = enterprise_management;
namespace {
+const size_t kMaxMachineNameLength = 15;
+const char kInvalidMachineNameCharacters[] = "\\/:*?\"<>|";
+
// Drop stub policy file of |policy_type| at |policy_path| containing
// |serialized_payload|.
bool WritePolicyFile(const base::FilePath& policy_path,
@@ -65,6 +69,25 @@ void FakeAuthPolicyClient::JoinAdDomain(const std::string& machine_name,
const std::string& user_principal_name,
int password_fd,
const JoinCallback& callback) {
+ if (machine_name.size() > kMaxMachineNameLength) {
+ callback.Run(authpolicy::ERROR_MACHINE_NAME_TOO_LONG);
+ return;
+ }
+
+ if (machine_name.empty() ||
+ machine_name.find_first_of(kInvalidMachineNameCharacters) !=
+ std::string::npos) {
+ callback.Run(authpolicy::ERROR_BAD_MACHINE_NAME);
+ return;
+ }
+
+ std::vector<std::string> parts = base::SplitString(
+ user_principal_name, "@", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
+ if (parts.size() != 2 || parts[0].empty() || parts[1].empty()) {
+ callback.Run(authpolicy::ERROR_PARSE_UPN_FAILED);
+ return;
+ }
+
callback.Run(authpolicy::ERROR_NONE);
}
« no previous file with comments | « chromeos/chromeos.gyp ('k') | chromeos/dbus/fake_auth_policy_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698