| 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" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 FakeAuthPolicyClient::FakeAuthPolicyClient() {} | 69 FakeAuthPolicyClient::FakeAuthPolicyClient() {} |
| 70 | 70 |
| 71 FakeAuthPolicyClient::~FakeAuthPolicyClient() {} | 71 FakeAuthPolicyClient::~FakeAuthPolicyClient() {} |
| 72 | 72 |
| 73 void FakeAuthPolicyClient::Init(dbus::Bus* bus) {} | 73 void FakeAuthPolicyClient::Init(dbus::Bus* bus) {} |
| 74 | 74 |
| 75 void FakeAuthPolicyClient::JoinAdDomain(const std::string& machine_name, | 75 void FakeAuthPolicyClient::JoinAdDomain(const std::string& machine_name, |
| 76 const std::string& user_principal_name, | 76 const std::string& user_principal_name, |
| 77 int password_fd, | 77 int password_fd, |
| 78 const JoinCallback& callback) { | 78 const JoinCallback& callback) { |
| 79 if (!started_) { |
| 80 LOG(ERROR) << "authpolicyd not started"; |
| 81 callback.Run(authpolicy::ERROR_DBUS_FAILURE); |
| 82 return; |
| 83 } |
| 79 if (machine_name.size() > kMaxMachineNameLength) { | 84 if (machine_name.size() > kMaxMachineNameLength) { |
| 80 callback.Run(authpolicy::ERROR_MACHINE_NAME_TOO_LONG); | 85 callback.Run(authpolicy::ERROR_MACHINE_NAME_TOO_LONG); |
| 81 return; | 86 return; |
| 82 } | 87 } |
| 83 | 88 |
| 84 if (machine_name.empty() || | 89 if (machine_name.empty() || |
| 85 machine_name.find_first_of(kInvalidMachineNameCharacters) != | 90 machine_name.find_first_of(kInvalidMachineNameCharacters) != |
| 86 std::string::npos) { | 91 std::string::npos) { |
| 87 callback.Run(authpolicy::ERROR_BAD_MACHINE_NAME); | 92 callback.Run(authpolicy::ERROR_BAD_MACHINE_NAME); |
| 88 return; | 93 return; |
| 89 } | 94 } |
| 90 | 95 |
| 91 std::vector<std::string> parts = base::SplitString( | 96 std::vector<std::string> parts = base::SplitString( |
| 92 user_principal_name, "@", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 97 user_principal_name, "@", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 93 if (parts.size() != 2 || parts[0].empty() || parts[1].empty()) { | 98 if (parts.size() != 2 || parts[0].empty() || parts[1].empty()) { |
| 94 callback.Run(authpolicy::ERROR_PARSE_UPN_FAILED); | 99 callback.Run(authpolicy::ERROR_PARSE_UPN_FAILED); |
| 95 return; | 100 return; |
| 96 } | 101 } |
| 97 | 102 |
| 98 callback.Run(authpolicy::ERROR_NONE); | 103 callback.Run(authpolicy::ERROR_NONE); |
| 99 } | 104 } |
| 100 | 105 |
| 101 void FakeAuthPolicyClient::AuthenticateUser( | 106 void FakeAuthPolicyClient::AuthenticateUser( |
| 102 const std::string& user_principal_name, | 107 const std::string& user_principal_name, |
| 103 int password_fd, | 108 int password_fd, |
| 104 const AuthCallback& callback) { | 109 const AuthCallback& callback) { |
| 105 authpolicy::ActiveDirectoryAccountData account_data; | 110 authpolicy::ActiveDirectoryAccountData account_data; |
| 111 if (!started_) { |
| 112 LOG(ERROR) << "authpolicyd not started"; |
| 113 callback.Run(authpolicy::ERROR_DBUS_FAILURE, account_data); |
| 114 return; |
| 115 } |
| 106 account_data.set_account_id(base::MD5String(user_principal_name)); | 116 account_data.set_account_id(base::MD5String(user_principal_name)); |
| 107 callback.Run(authpolicy::ERROR_NONE, account_data); | 117 callback.Run(authpolicy::ERROR_NONE, account_data); |
| 108 } | 118 } |
| 109 | 119 |
| 110 void FakeAuthPolicyClient::RefreshDevicePolicy( | 120 void FakeAuthPolicyClient::RefreshDevicePolicy( |
| 111 const RefreshPolicyCallback& callback) { | 121 const RefreshPolicyCallback& callback) { |
| 122 if (!started_) { |
| 123 LOG(ERROR) << "authpolicyd not started"; |
| 124 callback.Run(false); |
| 125 return; |
| 126 } |
| 112 base::FilePath policy_path; | 127 base::FilePath policy_path; |
| 113 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &policy_path)) { | 128 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &policy_path)) { |
| 114 callback.Run(false); | 129 callback.Run(false); |
| 115 return; | 130 return; |
| 116 } | 131 } |
| 117 policy_path = policy_path.DirName().AppendASCII("stub_device_policy"); | 132 policy_path = policy_path.DirName().AppendASCII("stub_device_policy"); |
| 118 | 133 |
| 119 em::ChromeDeviceSettingsProto policy; | 134 em::ChromeDeviceSettingsProto policy; |
| 120 std::string payload; | 135 std::string payload; |
| 121 CHECK(policy.SerializeToString(&payload)); | 136 CHECK(policy.SerializeToString(&payload)); |
| 122 | 137 |
| 123 // Drop file for SessionManagerClientStubImpl to read. | 138 // Drop file for SessionManagerClientStubImpl to read. |
| 124 base::PostTaskWithTraitsAndReplyWithResult( | 139 base::PostTaskWithTraitsAndReplyWithResult( |
| 125 FROM_HERE, base::TaskTraits() | 140 FROM_HERE, base::TaskTraits() |
| 126 .WithShutdownBehavior( | 141 .WithShutdownBehavior( |
| 127 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) | 142 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
| 128 .WithPriority(base::TaskPriority::BACKGROUND) | 143 .WithPriority(base::TaskPriority::BACKGROUND) |
| 129 .MayBlock(), | 144 .MayBlock(), |
| 130 Bind(&WritePolicyFile, policy_path, payload, "google/chromeos/device"), | 145 Bind(&WritePolicyFile, policy_path, payload, "google/chromeos/device"), |
| 131 callback); | 146 callback); |
| 132 } | 147 } |
| 133 | 148 |
| 134 void FakeAuthPolicyClient::RefreshUserPolicy( | 149 void FakeAuthPolicyClient::RefreshUserPolicy( |
| 135 const AccountId& account_id, | 150 const AccountId& account_id, |
| 136 const RefreshPolicyCallback& callback) { | 151 const RefreshPolicyCallback& callback) { |
| 152 if (!started_) { |
| 153 LOG(ERROR) << "authpolicyd not started"; |
| 154 callback.Run(false); |
| 155 return; |
| 156 } |
| 137 base::FilePath policy_path; | 157 base::FilePath policy_path; |
| 138 if (!PathService::Get(chromeos::DIR_USER_POLICY_KEYS, &policy_path)) { | 158 if (!PathService::Get(chromeos::DIR_USER_POLICY_KEYS, &policy_path)) { |
| 139 callback.Run(false); | 159 callback.Run(false); |
| 140 return; | 160 return; |
| 141 } | 161 } |
| 142 const cryptohome::Identification cryptohome_identification(account_id); | 162 const cryptohome::Identification cryptohome_identification(account_id); |
| 143 const std::string sanitized_username = | 163 const std::string sanitized_username = |
| 144 chromeos::CryptohomeClient::GetStubSanitizedUsername( | 164 chromeos::CryptohomeClient::GetStubSanitizedUsername( |
| 145 cryptohome_identification); | 165 cryptohome_identification); |
| 146 policy_path = policy_path.AppendASCII(sanitized_username); | 166 policy_path = policy_path.AppendASCII(sanitized_username); |
| 147 policy_path = policy_path.AppendASCII("stub_policy"); | 167 policy_path = policy_path.AppendASCII("stub_policy"); |
| 148 | 168 |
| 149 em::CloudPolicySettings policy; | 169 em::CloudPolicySettings policy; |
| 150 std::string payload; | 170 std::string payload; |
| 151 CHECK(policy.SerializeToString(&payload)); | 171 CHECK(policy.SerializeToString(&payload)); |
| 152 | 172 |
| 153 // Drop file for SessionManagerClientStubImpl to read. | 173 // Drop file for SessionManagerClientStubImpl to read. |
| 154 base::PostTaskWithTraitsAndReplyWithResult( | 174 base::PostTaskWithTraitsAndReplyWithResult( |
| 155 FROM_HERE, base::TaskTraits() | 175 FROM_HERE, base::TaskTraits() |
| 156 .WithShutdownBehavior( | 176 .WithShutdownBehavior( |
| 157 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) | 177 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
| 158 .WithPriority(base::TaskPriority::BACKGROUND) | 178 .WithPriority(base::TaskPriority::BACKGROUND) |
| 159 .MayBlock(), | 179 .MayBlock(), |
| 160 base::Bind(&WritePolicyFile, policy_path, payload, | 180 base::Bind(&WritePolicyFile, policy_path, payload, |
| 161 "google/chromeos/user"), | 181 "google/chromeos/user"), |
| 162 callback); | 182 callback); |
| 163 } | 183 } |
| 164 | 184 |
| 165 } // namespace chromeos | 185 } // namespace chromeos |
| OLD | NEW |