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

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

Issue 2433363004: Chromad: added AD Join ui, authpolicy_client (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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4 #include "chromeos/dbus/authpolicy_client.h"
5
6 #include <map>
hashimoto 2016/10/24 03:01:18 Please remove unneeded include.
Roman Sorokin (ftl) 2016/10/24 16:50:34 Done.
7 #include <memory>
8 #include <utility>
9
10 #include "base/bind.h"
11 #include "base/location.h"
12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/message_loop/message_loop.h"
15 #include "base/stl_util.h"
16 #include "base/strings/stringprintf.h"
17 #include "base/values.h"
18 #include "dbus/bus.h"
19 #include "dbus/message.h"
20 #include "dbus/object_proxy.h"
21 #include "dbus/values_util.h"
22 #include "third_party/cros_system_api/dbus/service_constants.h"
23
24 namespace chromeos {
25
26 namespace {
27
28 // TODO(rsorokin): switch to service constants when it's landed.
hashimoto 2016/10/24 03:01:18 URL to the bug? Please follow the naming rule htt
Roman Sorokin (ftl) 2016/10/24 16:50:34 Done.
29 const char* objPath = "/org/chromium/authpolicy/Domain";
hashimoto 2016/10/24 03:01:18 This should be const char[].
Roman Sorokin (ftl) 2016/10/24 16:50:34 Done.
30 const char* authInt = "org.chromium.authpolicy";
31 const char* domainInt = "org.chromium.authpolicy.Domain";
32 const char* joinMethod = "Join";
hashimoto 2016/10/24 03:01:18 Add a blank line.
Roman Sorokin (ftl) 2016/10/24 16:50:34 Done.
33 // AuthpolicyClient is used to communicate with the org.chromium.authpolicy
34 // service.
35 class AuthpolicyClientImpl : public AuthpolicyClient {
36 public:
37 AuthpolicyClientImpl() : bus_(NULL), weak_ptr_factory_(this) {}
hashimoto 2016/10/24 03:01:18 nullptr instead of NULL.
Roman Sorokin (ftl) 2016/10/24 16:50:34 Done.
38
39 ~AuthpolicyClientImpl() override {}
40
41 void Join(const std::string& machine_name,
42 const std::string& user,
43 const std::string& password,
44 const JoinCallback& callback) override {
45 // TODO(rsorokin): make proper callbacks with errors.
46 int fd[2];
47 if (pipe(fd) < 0) {
hashimoto 2016/10/24 03:01:18 Please move this pipe creation/preparation logic o
Roman Sorokin (ftl) 2016/10/24 16:50:34 Done.
48 LOG(ERROR) << "Join: pipes fail: " << strerror(errno);
49 return;
50 }
51
52 if (write(fd[1], password.c_str(), password.size()) <= 0) {
53 LOG(ERROR) << "Join: write fail";
54 return;
55 }
56
57 if (close(fd[1])) {
hashimoto 2016/10/24 03:01:18 Use ScopedFD.
Roman Sorokin (ftl) 2016/10/24 16:50:34 Done.
58 LOG(ERROR) << "Join: close failed";
59 }
60
61 dbus::ObjectPath objectPath(objPath);
62 dbus::ObjectProxy* proxy = bus_->GetObjectProxy(authInt, objectPath);
63 dbus::MethodCall method_call(domainInt, joinMethod);
64 dbus::MessageWriter writer(&method_call);
65 writer.AppendString(machine_name);
66 writer.AppendString(user);
67 writer.AppendFileDescriptor(fd[0]);
68 proxy->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
69 base::Bind(&AuthpolicyClientImpl::HandleJoinCallback,
70 weak_ptr_factory_.GetWeakPtr(), callback));
71 if (close(fd[0])) {
72 LOG(ERROR) << "Join: close failed";
73 }
74 }
75
76 protected:
77 void Init(dbus::Bus* bus) override { bus_ = bus; }
78
79 private:
80 void HandleJoinCallback(const JoinCallback& callback,
81 dbus::Response* response) {
82 if (!response) {
83 LOG(ERROR) << "Join: Couldn't call to authpolicy";
84 callback.Run(1);
hashimoto 2016/10/24 03:01:18 What does this "1" mean?
Roman Sorokin (ftl) 2016/10/24 16:50:34 Have not defined error codes yet. For now it's jus
85 return;
86 }
87
88 dbus::MessageReader reader(response);
89 dbus::ObjectPath connection_settings_path;
hashimoto 2016/10/24 03:01:18 These variables are unused.
Roman Sorokin (ftl) 2016/10/24 16:50:34 Done.
90 dbus::ObjectPath active_connection_path;
91 int res;
92 if (!reader.PopInt32(&res)) {
93 LOG(ERROR) << "Join: Couldn't get an error from the response";
94 callback.Run(1);
95 return;
96 }
97
98 callback.Run(res);
99 }
100
101 dbus::Bus* bus_;
102
103 // Note: This should remain the last member so it'll be destroyed and
104 // invalidate its weak pointers before any other members are destroyed.
105 base::WeakPtrFactory<AuthpolicyClientImpl> weak_ptr_factory_;
106
107 DISALLOW_COPY_AND_ASSIGN(AuthpolicyClientImpl);
108 };
109
110 } // namespace
111
112 AuthpolicyClient::AuthpolicyClient() {}
113
114 AuthpolicyClient::~AuthpolicyClient() {}
115
116 // static
117 AuthpolicyClient* AuthpolicyClient::Create() {
118 return new AuthpolicyClientImpl();
119 }
120
121 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698