Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chromeos/login/auth/authpolicy_login_helper.h" | |
| 6 | |
| 7 #include "base/files/file_util.h" | |
| 8 #include "base/task_scheduler/post_task.h" | |
| 9 #include "chromeos/dbus/auth_policy_client.h" | |
| 10 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 11 #include "chromeos/dbus/upstart_client.h" | |
| 12 | |
| 13 namespace chromeos { | |
| 14 namespace { | |
| 15 | |
| 16 base::ScopedFD GetDataReadPipe(const std::string& data) { | |
| 17 int pipe_fds[2]; | |
| 18 if (!base::CreateLocalNonBlockingPipe(pipe_fds)) { | |
| 19 DLOG(ERROR) << "Failed to create pipe"; | |
| 20 return base::ScopedFD(); | |
| 21 } | |
| 22 base::ScopedFD pipe_read_end(pipe_fds[0]); | |
| 23 base::ScopedFD pipe_write_end(pipe_fds[1]); | |
| 24 | |
| 25 if (!base::WriteFileDescriptor(pipe_write_end.get(), data.c_str(), | |
| 26 data.size())) { | |
| 27 DLOG(ERROR) << "Failed to write to pipe"; | |
| 28 return base::ScopedFD(); | |
| 29 } | |
| 30 return pipe_read_end; | |
| 31 } | |
| 32 | |
| 33 } // namespace | |
| 34 | |
| 35 AuthPolicyLoginHelper::AuthPolicyLoginHelper() : weak_factory_(this) {} | |
| 36 | |
| 37 void AuthPolicyLoginHelper::JoinAdDomain(const std::string& machine_name, | |
| 38 const std::string& username, | |
| 39 const std::string& password, | |
| 40 const JoinCallback& callback) { | |
| 41 DCHECK(!weak_factory_.HasWeakPtrs()) << "Another operation is in progress"; | |
| 42 chromeos::DBusThreadManager::Get()->GetAuthPolicyClient()->JoinAdDomain( | |
| 43 machine_name, username, GetDataReadPipe(password).get(), | |
| 44 base::Bind(&AuthPolicyLoginHelper::OnJoinCallback, | |
| 45 weak_factory_.GetWeakPtr(), callback)); | |
| 46 } | |
| 47 | |
| 48 void AuthPolicyLoginHelper::AuthenticateUser(const std::string& username, | |
| 49 const std::string& password, | |
| 50 const AuthCallback& callback) { | |
| 51 DCHECK(!weak_factory_.HasWeakPtrs()) << "Another operation is in progress"; | |
| 52 chromeos::DBusThreadManager::Get()->GetAuthPolicyClient()->AuthenticateUser( | |
| 53 username, GetDataReadPipe(password).get(), | |
|
ljusten (tachyonic)
2017/04/04 12:51:32
I was a bit concerned about this, but seems like i
Roman Sorokin (ftl)
2017/04/06 15:00:32
Acknowledged.
| |
| 54 base::Bind(&AuthPolicyLoginHelper::OnAuthCallback, | |
| 55 weak_factory_.GetWeakPtr(), callback)); | |
| 56 } | |
| 57 | |
| 58 void AuthPolicyLoginHelper::CancelRequestsAndRestart() { | |
|
ljusten (tachyonic)
2017/04/04 12:51:32
Are you aware of https://cs.chromium.org/chromium/
Roman Sorokin (ftl)
2017/04/06 15:00:32
I think it would be more complicated.
| |
| 59 weak_factory_.InvalidateWeakPtrs(); | |
| 60 chromeos::DBusThreadManager::Get() | |
| 61 ->GetUpstartClient() | |
| 62 ->RestartAuthPolicyService(); | |
| 63 } | |
| 64 | |
| 65 void AuthPolicyLoginHelper::OnJoinCallback(const JoinCallback& callback, | |
| 66 authpolicy::ErrorType error) { | |
| 67 callback.Run(error); | |
| 68 } | |
| 69 | |
| 70 void AuthPolicyLoginHelper::OnAuthCallback( | |
| 71 const AuthCallback& callback, | |
| 72 authpolicy::ErrorType error, | |
| 73 const authpolicy::ActiveDirectoryAccountData& account_data) { | |
| 74 callback.Run(error, account_data); | |
| 75 } | |
| 76 | |
| 77 AuthPolicyLoginHelper::~AuthPolicyLoginHelper() {} | |
| 78 | |
| 79 } // namespace chromeos | |
| OLD | NEW |