| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/dbus/fake_auth_policy_client.h" | 5 #include "chromeos/dbus/fake_auth_policy_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/md5.h" | 11 #include "base/md5.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/strings/string_split.h" |
| 13 #include "base/task_scheduler/post_task.h" | 14 #include "base/task_scheduler/post_task.h" |
| 14 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 15 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
| 15 #include "chromeos/chromeos_paths.h" | 16 #include "chromeos/chromeos_paths.h" |
| 16 #include "chromeos/cryptohome/cryptohome_parameters.h" | 17 #include "chromeos/cryptohome/cryptohome_parameters.h" |
| 17 #include "chromeos/dbus/cryptohome_client.h" | 18 #include "chromeos/dbus/cryptohome_client.h" |
| 18 #include "components/policy/proto/cloud_policy.pb.h" | 19 #include "components/policy/proto/cloud_policy.pb.h" |
| 19 #include "components/policy/proto/device_management_backend.pb.h" | 20 #include "components/policy/proto/device_management_backend.pb.h" |
| 20 #include "components/signin/core/account_id/account_id.h" | 21 #include "components/signin/core/account_id/account_id.h" |
| 21 #include "third_party/cros_system_api/dbus/service_constants.h" | 22 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 22 | 23 |
| 23 namespace em = enterprise_management; | 24 namespace em = enterprise_management; |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 28 const size_t kMaxMachineNameLength = 15; |
| 29 const char kInvalidMachineNameCharacters[] = "\\/:*?\"<>|"; |
| 30 |
| 27 // Drop stub policy file of |policy_type| at |policy_path| containing | 31 // Drop stub policy file of |policy_type| at |policy_path| containing |
| 28 // |serialized_payload|. | 32 // |serialized_payload|. |
| 29 bool WritePolicyFile(const base::FilePath& policy_path, | 33 bool WritePolicyFile(const base::FilePath& policy_path, |
| 30 const std::string& serialized_payload, | 34 const std::string& serialized_payload, |
| 31 const std::string& policy_type) { | 35 const std::string& policy_type) { |
| 32 em::PolicyData data; | 36 em::PolicyData data; |
| 33 data.set_policy_value(serialized_payload); | 37 data.set_policy_value(serialized_payload); |
| 34 data.set_policy_type(policy_type); | 38 data.set_policy_type(policy_type); |
| 35 | 39 |
| 36 em::PolicyFetchResponse response; | 40 em::PolicyFetchResponse response; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 58 FakeAuthPolicyClient::FakeAuthPolicyClient() {} | 62 FakeAuthPolicyClient::FakeAuthPolicyClient() {} |
| 59 | 63 |
| 60 FakeAuthPolicyClient::~FakeAuthPolicyClient() {} | 64 FakeAuthPolicyClient::~FakeAuthPolicyClient() {} |
| 61 | 65 |
| 62 void FakeAuthPolicyClient::Init(dbus::Bus* bus) {} | 66 void FakeAuthPolicyClient::Init(dbus::Bus* bus) {} |
| 63 | 67 |
| 64 void FakeAuthPolicyClient::JoinAdDomain(const std::string& machine_name, | 68 void FakeAuthPolicyClient::JoinAdDomain(const std::string& machine_name, |
| 65 const std::string& user_principal_name, | 69 const std::string& user_principal_name, |
| 66 int password_fd, | 70 int password_fd, |
| 67 const JoinCallback& callback) { | 71 const JoinCallback& callback) { |
| 72 if (machine_name.size() > kMaxMachineNameLength) { |
| 73 callback.Run(authpolicy::ERROR_MACHINE_NAME_TOO_LONG); |
| 74 return; |
| 75 } |
| 76 |
| 77 if (machine_name.empty() || |
| 78 machine_name.find_first_of(kInvalidMachineNameCharacters) != |
| 79 std::string::npos) { |
| 80 callback.Run(authpolicy::ERROR_BAD_MACHINE_NAME); |
| 81 return; |
| 82 } |
| 83 |
| 84 std::vector<std::string> parts = base::SplitString( |
| 85 user_principal_name, "@", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 86 if (parts.size() != 2 || parts[0].empty() || parts[1].empty()) { |
| 87 callback.Run(authpolicy::ERROR_PARSE_UPN_FAILED); |
| 88 return; |
| 89 } |
| 90 |
| 68 callback.Run(authpolicy::ERROR_NONE); | 91 callback.Run(authpolicy::ERROR_NONE); |
| 69 } | 92 } |
| 70 | 93 |
| 71 void FakeAuthPolicyClient::AuthenticateUser( | 94 void FakeAuthPolicyClient::AuthenticateUser( |
| 72 const std::string& user_principal_name, | 95 const std::string& user_principal_name, |
| 73 int password_fd, | 96 int password_fd, |
| 74 const AuthCallback& callback) { | 97 const AuthCallback& callback) { |
| 75 callback.Run(authpolicy::ERROR_NONE, base::MD5String(user_principal_name)); | 98 callback.Run(authpolicy::ERROR_NONE, base::MD5String(user_principal_name)); |
| 76 } | 99 } |
| 77 | 100 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 .WithShutdownBehavior( | 147 .WithShutdownBehavior( |
| 125 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) | 148 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
| 126 .WithPriority(base::TaskPriority::BACKGROUND) | 149 .WithPriority(base::TaskPriority::BACKGROUND) |
| 127 .MayBlock(), | 150 .MayBlock(), |
| 128 base::Bind(&WritePolicyFile, policy_path, payload, | 151 base::Bind(&WritePolicyFile, policy_path, payload, |
| 129 "google/chromeos/user"), | 152 "google/chromeos/user"), |
| 130 callback); | 153 callback); |
| 131 } | 154 } |
| 132 | 155 |
| 133 } // namespace chromeos | 156 } // namespace chromeos |
| OLD | NEW |