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

Unified Diff: chromeos/dbus/auth_policy_client.cc

Issue 2433363004: Chromad: added AD Join ui, authpolicy_client (Closed)
Patch Set: Not close password_fd in AuthPolicyClient Created 4 years, 2 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
Index: chromeos/dbus/auth_policy_client.cc
diff --git a/chromeos/dbus/auth_policy_client.cc b/chromeos/dbus/auth_policy_client.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6fb68aaa8622a5eca70b0212c02762a95074c628
--- /dev/null
+++ b/chromeos/dbus/auth_policy_client.cc
@@ -0,0 +1,93 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+#include "chromeos/dbus/auth_policy_client.h"
+
+#include "base/bind.h"
+#include "base/memory/weak_ptr.h"
+#include "base/threading/worker_pool.h"
hashimoto 2016/10/27 02:26:07 nit: Please remove unused include.
Roman Sorokin (ftl) 2016/10/27 13:10:46 Done.
+#include "dbus/bus.h"
+#include "dbus/message.h"
+#include "dbus/object_proxy.h"
+#include "third_party/cros_system_api/dbus/service_constants.h"
+
+namespace chromeos {
+
+namespace {
+
+class AuthPolicyClientImpl : public AuthPolicyClient {
+ public:
+ AuthPolicyClientImpl() : bus_(nullptr), weak_ptr_factory_(this) {}
xiyuan 2016/10/26 22:03:17 nit: move |bus_| initializer to line 73 where it i
Roman Sorokin (ftl) 2016/10/27 13:10:46 Done.
+
+ ~AuthPolicyClientImpl() override {}
+
+ void JoinADDomain(const std::string& machine_name,
xiyuan 2016/10/26 22:03:16 nit: // AuthPolicyClient:
Roman Sorokin (ftl) 2016/10/27 13:10:46 Done.
+ const std::string& user,
+ int password_fd,
+ const JoinCallback& callback) override {
+ dbus::ObjectPath objectPath(authpolicy::kAuthPolicyServicePath);
+ dbus::ObjectProxy* proxy =
+ bus_->GetObjectProxy(authpolicy::kAuthPolicyServiceName, objectPath);
+ dbus::MethodCall method_call(authpolicy::kAuthPolicyInterface,
+ authpolicy::kAuthPolicyJoinADDomain);
+ dbus::MessageWriter writer(&method_call);
+ writer.AppendString(machine_name);
+ writer.AppendString(user);
+ writer.AppendFileDescriptor(password_fd);
+ proxy->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
+ base::Bind(&AuthPolicyClientImpl::HandleJoinCallback,
+ weak_ptr_factory_.GetWeakPtr(), callback));
+ }
+
+ protected:
+ void Init(dbus::Bus* bus) override { bus_ = bus; }
+
+ private:
+ void HandleJoinCallback(const JoinCallback& callback,
+ dbus::Response* response) {
+ if (!response) {
+ LOG(ERROR) << "Join: Couldn't call to authpolicy";
+ // TODO(rsorokin): make proper call, after defining possible errors codes.
+ callback.Run(authpolicy::AD_JOIN_ERROR_UNKNOWN);
+ return;
+ }
+
+ dbus::MessageReader reader(response);
+ int res = authpolicy::AD_JOIN_ERROR_UNKNOWN;
+ if (!reader.PopInt32(&res)) {
+ LOG(ERROR) << "Join: Couldn't get an error from the response";
+ // TODO(rsorokin): make proper call, after defining possible errors codes.
+ callback.Run(authpolicy::AD_JOIN_ERROR_DBUS_FAIL);
+ return;
+ }
+
+ callback.Run(res);
+ }
+
+ void OnPipeReadComplete(int error_code) {
xiyuan 2016/10/26 22:03:17 Is this used anywhere?
Roman Sorokin (ftl) 2016/10/27 13:10:46 Done.
+ if (error_code != 0) {
+ LOG(ERROR) << "Failed to stream password to AuthPolicy: " << error_code;
+ }
+ }
+
+ dbus::Bus* bus_;
+
+ // Note: This should remain the last member so it'll be destroyed and
+ // invalidate its weak pointers before any other members are destroyed.
+ base::WeakPtrFactory<AuthPolicyClientImpl> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(AuthPolicyClientImpl);
+};
+
+} // namespace
+
+AuthPolicyClient::AuthPolicyClient() {}
+
+AuthPolicyClient::~AuthPolicyClient() {}
+
+// static
+AuthPolicyClient* AuthPolicyClient::Create() {
+ return new AuthPolicyClientImpl();
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698