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

Side by Side Diff: chromeos/dbus/auth_policy_client.cc

Issue 2475343002: Add UpstartClient (Closed)
Patch Set: Created 4 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « chromeos/dbus/auth_policy_client.h ('k') | chromeos/dbus/fake_auth_policy_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 #include "chromeos/dbus/auth_policy_client.h" 4 #include "chromeos/dbus/auth_policy_client.h"
5 5
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/memory/weak_ptr.h" 7 #include "base/memory/weak_ptr.h"
8 #include "dbus/bus.h" 8 #include "dbus/bus.h"
9 #include "dbus/message.h" 9 #include "dbus/message.h"
10 #include "dbus/object_proxy.h" 10 #include "dbus/object_proxy.h"
11 #include "third_party/cros_system_api/dbus/service_constants.h" 11 #include "third_party/cros_system_api/dbus/service_constants.h"
12 12
13 namespace chromeos { 13 namespace chromeos {
14 14
15 namespace { 15 namespace {
16 16
17 const char kUpstartServiceName[] = "com.ubuntu.Upstart";
hashimoto 2016/11/08 00:12:26 AuthPolicyClient should deal only with AuthPolicy
Roman Sorokin (ftl) 2016/11/08 10:43:13 Done.
18 const char kUpstartObjectPath[] = "/com/ubuntu/Upstart/jobs/authpolicyd";
19 const char kUpstartJobInterface[] = "com.ubuntu.Upstart0_6.Job";
20 const char kUpstartStartMethod[] = "Start";
21
17 class AuthPolicyClientImpl : public AuthPolicyClient { 22 class AuthPolicyClientImpl : public AuthPolicyClient {
18 public: 23 public:
19 AuthPolicyClientImpl() : weak_ptr_factory_(this) {} 24 AuthPolicyClientImpl() : weak_ptr_factory_(this) {}
20 25
21 ~AuthPolicyClientImpl() override {} 26 ~AuthPolicyClientImpl() override {}
22 27
23 // AuthPolicyClient override. 28 // AuthPolicyClient override.
29 void StartService() override {
30 dbus::ObjectPath objectPath(kUpstartObjectPath);
31 dbus::ObjectProxy* proxy =
32 bus_->GetObjectProxy(kUpstartServiceName, objectPath);
33 dbus::MethodCall method_call(kUpstartJobInterface, kUpstartStartMethod);
34 dbus::MessageWriter writer(&method_call);
35 dbus::MessageWriter sub_writer(nullptr);
36 writer.OpenArray("s", &sub_writer);
37 writer.CloseContainer(&sub_writer);
38 writer.AppendBool(false); // No waiting for response.
39 proxy->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
40 base::Bind(&AuthPolicyClientImpl::HandleUpstartCallback,
41 weak_ptr_factory_.GetWeakPtr()));
42 }
24 void JoinAdDomain(const std::string& machine_name, 43 void JoinAdDomain(const std::string& machine_name,
25 const std::string& user, 44 const std::string& user,
26 int password_fd, 45 int password_fd,
27 const JoinCallback& callback) override { 46 const JoinCallback& callback) override {
28 dbus::ObjectPath objectPath(authpolicy::kAuthPolicyServicePath); 47 dbus::ObjectPath objectPath(authpolicy::kAuthPolicyServicePath);
29 dbus::ObjectProxy* proxy = 48 dbus::ObjectProxy* proxy =
30 bus_->GetObjectProxy(authpolicy::kAuthPolicyServiceName, objectPath); 49 bus_->GetObjectProxy(authpolicy::kAuthPolicyServiceName, objectPath);
31 dbus::MethodCall method_call(authpolicy::kAuthPolicyInterface, 50 dbus::MethodCall method_call(authpolicy::kAuthPolicyInterface,
32 authpolicy::kAuthPolicyJoinADDomain); 51 authpolicy::kAuthPolicyJoinADDomain);
33 dbus::MessageWriter writer(&method_call); 52 dbus::MessageWriter writer(&method_call);
34 writer.AppendString(machine_name); 53 writer.AppendString(machine_name);
35 writer.AppendString(user); 54 writer.AppendString(user);
36 writer.AppendFileDescriptor(password_fd); 55 writer.AppendFileDescriptor(password_fd);
37 proxy->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 56 proxy->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
38 base::Bind(&AuthPolicyClientImpl::HandleJoinCallback, 57 base::Bind(&AuthPolicyClientImpl::HandleJoinCallback,
39 weak_ptr_factory_.GetWeakPtr(), callback)); 58 weak_ptr_factory_.GetWeakPtr(), callback));
40 } 59 }
41 60
42 protected: 61 protected:
43 void Init(dbus::Bus* bus) override { bus_ = bus; } 62 void Init(dbus::Bus* bus) override { bus_ = bus; }
44 63
45 private: 64 private:
65 void HandleUpstartCallback(dbus::Response* response) {
66 if (!response) {
67 LOG(ERROR) << "Failed to start authpolicyd, response is null";
68 return;
69 }
70 }
46 void HandleJoinCallback(const JoinCallback& callback, 71 void HandleJoinCallback(const JoinCallback& callback,
47 dbus::Response* response) { 72 dbus::Response* response) {
48 if (!response) { 73 if (!response) {
49 LOG(ERROR) << "Join: Couldn't call to authpolicy"; 74 LOG(ERROR) << "Join: Couldn't call to authpolicy";
50 // TODO(rsorokin): make proper call, after defining possible errors codes. 75 // TODO(rsorokin): make proper call, after defining possible errors codes.
51 callback.Run(authpolicy::AD_JOIN_ERROR_UNKNOWN); 76 callback.Run(authpolicy::AD_JOIN_ERROR_UNKNOWN);
52 return; 77 return;
53 } 78 }
54 79
55 dbus::MessageReader reader(response); 80 dbus::MessageReader reader(response);
(...skipping 22 matching lines...) Expand all
78 AuthPolicyClient::AuthPolicyClient() {} 103 AuthPolicyClient::AuthPolicyClient() {}
79 104
80 AuthPolicyClient::~AuthPolicyClient() {} 105 AuthPolicyClient::~AuthPolicyClient() {}
81 106
82 // static 107 // static
83 AuthPolicyClient* AuthPolicyClient::Create() { 108 AuthPolicyClient* AuthPolicyClient::Create() {
84 return new AuthPolicyClientImpl(); 109 return new AuthPolicyClientImpl();
85 } 110 }
86 111
87 } // namespace chromeos 112 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/auth_policy_client.h ('k') | chromeos/dbus/fake_auth_policy_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698