| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/login/auth/authpolicy_login_helper.h" | 5 #include "chromeos/login/auth/authpolicy_login_helper.h" |
| 6 | 6 |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/task_scheduler/post_task.h" | 8 #include "base/task_scheduler/post_task.h" |
| 9 #include "chromeos/dbus/auth_policy_client.h" | 9 #include "chromeos/dbus/auth_policy_client.h" |
| 10 #include "chromeos/dbus/dbus_thread_manager.h" | 10 #include "chromeos/dbus/dbus_thread_manager.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 base::ScopedFD pipe_write_end(pipe_fds[1]); | 23 base::ScopedFD pipe_write_end(pipe_fds[1]); |
| 24 | 24 |
| 25 if (!base::WriteFileDescriptor(pipe_write_end.get(), data.c_str(), | 25 if (!base::WriteFileDescriptor(pipe_write_end.get(), data.c_str(), |
| 26 data.size())) { | 26 data.size())) { |
| 27 DLOG(ERROR) << "Failed to write to pipe"; | 27 DLOG(ERROR) << "Failed to write to pipe"; |
| 28 return base::ScopedFD(); | 28 return base::ScopedFD(); |
| 29 } | 29 } |
| 30 return pipe_read_end; | 30 return pipe_read_end; |
| 31 } | 31 } |
| 32 | 32 |
| 33 void AuthCallbackDoNothing( |
| 34 authpolicy::ErrorType /* error */, |
| 35 const authpolicy::ActiveDirectoryAccountData& /* account_data */) { |
| 36 // Do nothing. |
| 37 } |
| 38 |
| 33 } // namespace | 39 } // namespace |
| 34 | 40 |
| 35 AuthPolicyLoginHelper::AuthPolicyLoginHelper() : weak_factory_(this) {} | 41 AuthPolicyLoginHelper::AuthPolicyLoginHelper() : weak_factory_(this) {} |
| 36 | 42 |
| 37 void AuthPolicyLoginHelper::JoinAdDomain(const std::string& machine_name, | 43 void AuthPolicyLoginHelper::JoinAdDomain(const std::string& machine_name, |
| 38 const std::string& username, | 44 const std::string& username, |
| 39 const std::string& password, | 45 const std::string& password, |
| 40 JoinCallback callback) { | 46 JoinCallback callback) { |
| 41 DCHECK(!weak_factory_.HasWeakPtrs()) << "Another operation is in progress"; | 47 DCHECK(!weak_factory_.HasWeakPtrs()) << "Another operation is in progress"; |
| 42 chromeos::DBusThreadManager::Get()->GetAuthPolicyClient()->JoinAdDomain( | 48 chromeos::DBusThreadManager::Get()->GetAuthPolicyClient()->JoinAdDomain( |
| 43 machine_name, username, GetDataReadPipe(password).get(), | 49 machine_name, username, GetDataReadPipe(password).get(), |
| 44 base::BindOnce(&AuthPolicyLoginHelper::OnJoinCallback, | 50 base::BindOnce(&AuthPolicyLoginHelper::OnJoinCallback, |
| 45 weak_factory_.GetWeakPtr(), base::Passed(&callback))); | 51 weak_factory_.GetWeakPtr(), base::Passed(&callback))); |
| 46 } | 52 } |
| 47 | 53 |
| 48 void AuthPolicyLoginHelper::AuthenticateUser(const std::string& username, | 54 void AuthPolicyLoginHelper::AuthenticateUser(const std::string& username, |
| 55 const std::string& object_guid, |
| 49 const std::string& password, | 56 const std::string& password, |
| 50 AuthCallback callback) { | 57 AuthCallback callback) { |
| 51 DCHECK(!weak_factory_.HasWeakPtrs()) << "Another operation is in progress"; | 58 DCHECK(!weak_factory_.HasWeakPtrs()) << "Another operation is in progress"; |
| 52 chromeos::DBusThreadManager::Get()->GetAuthPolicyClient()->AuthenticateUser( | 59 chromeos::DBusThreadManager::Get()->GetAuthPolicyClient()->AuthenticateUser( |
| 53 username, GetDataReadPipe(password).get(), | 60 username, object_guid, GetDataReadPipe(password).get(), |
| 54 base::BindOnce(&AuthPolicyLoginHelper::OnAuthCallback, | 61 base::BindOnce(&AuthPolicyLoginHelper::OnAuthCallback, |
| 55 weak_factory_.GetWeakPtr(), base::Passed(&callback))); | 62 weak_factory_.GetWeakPtr(), base::Passed(&callback))); |
| 56 } | 63 } |
| 57 | 64 |
| 65 void AuthPolicyLoginHelper::TryAuthenticateUser(const std::string& username, |
| 66 const std::string& object_guid, |
| 67 const std::string& password) { |
| 68 chromeos::DBusThreadManager::Get()->GetAuthPolicyClient()->AuthenticateUser( |
| 69 username, object_guid, GetDataReadPipe(password).get(), |
| 70 base::BindOnce(&AuthCallbackDoNothing)); |
| 71 } |
| 72 |
| 58 void AuthPolicyLoginHelper::CancelRequestsAndRestart() { | 73 void AuthPolicyLoginHelper::CancelRequestsAndRestart() { |
| 59 weak_factory_.InvalidateWeakPtrs(); | 74 weak_factory_.InvalidateWeakPtrs(); |
| 60 chromeos::DBusThreadManager::Get() | 75 chromeos::DBusThreadManager::Get() |
| 61 ->GetUpstartClient() | 76 ->GetUpstartClient() |
| 62 ->RestartAuthPolicyService(); | 77 ->RestartAuthPolicyService(); |
| 63 } | 78 } |
| 64 | 79 |
| 65 void AuthPolicyLoginHelper::OnJoinCallback(JoinCallback callback, | 80 void AuthPolicyLoginHelper::OnJoinCallback(JoinCallback callback, |
| 66 authpolicy::ErrorType error) { | 81 authpolicy::ErrorType error) { |
| 67 std::move(callback).Run(error); | 82 std::move(callback).Run(error); |
| 68 } | 83 } |
| 69 | 84 |
| 70 void AuthPolicyLoginHelper::OnAuthCallback( | 85 void AuthPolicyLoginHelper::OnAuthCallback( |
| 71 AuthCallback callback, | 86 AuthCallback callback, |
| 72 authpolicy::ErrorType error, | 87 authpolicy::ErrorType error, |
| 73 const authpolicy::ActiveDirectoryAccountData& account_data) { | 88 const authpolicy::ActiveDirectoryAccountData& account_data) { |
| 74 std::move(callback).Run(error, account_data); | 89 std::move(callback).Run(error, account_data); |
| 75 } | 90 } |
| 76 | 91 |
| 77 AuthPolicyLoginHelper::~AuthPolicyLoginHelper() {} | 92 AuthPolicyLoginHelper::~AuthPolicyLoginHelper() {} |
| 78 | 93 |
| 79 } // namespace chromeos | 94 } // namespace chromeos |
| OLD | NEW |