OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 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/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "components/signin/core/account_id/account_id.h" | 9 #include "components/signin/core/account_id/account_id.h" |
10 #include "dbus/bus.h" | 10 #include "dbus/bus.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 int32_t int_error; | 26 int32_t int_error; |
27 if (!reader->PopInt32(&int_error)) { | 27 if (!reader->PopInt32(&int_error)) { |
28 DLOG(ERROR) << "AuthPolicyClient: Failed to get an error from the response"; | 28 DLOG(ERROR) << "AuthPolicyClient: Failed to get an error from the response"; |
29 return authpolicy::ERROR_DBUS_FAILURE; | 29 return authpolicy::ERROR_DBUS_FAILURE; |
30 } | 30 } |
31 if (int_error < 0 || int_error >= authpolicy::ERROR_COUNT) | 31 if (int_error < 0 || int_error >= authpolicy::ERROR_COUNT) |
32 return authpolicy::ERROR_UNKNOWN; | 32 return authpolicy::ERROR_UNKNOWN; |
33 return static_cast<authpolicy::ErrorType>(int_error); | 33 return static_cast<authpolicy::ErrorType>(int_error); |
34 } | 34 } |
35 | 35 |
| 36 authpolicy::ErrorType GetErrorAndProto( |
| 37 dbus::Response* response, |
| 38 google::protobuf::MessageLite* protobuf) { |
| 39 if (!response) { |
| 40 DLOG(ERROR) << "Auth: Failed to call to authpolicy"; |
| 41 return authpolicy::ERROR_DBUS_FAILURE; |
| 42 } |
| 43 dbus::MessageReader reader(response); |
| 44 const authpolicy::ErrorType error(GetErrorFromReader(&reader)); |
| 45 |
| 46 if (error != authpolicy::ERROR_NONE) |
| 47 return error; |
| 48 |
| 49 if (!reader.PopArrayOfBytesAsProto(protobuf)) { |
| 50 DLOG(ERROR) << "Failed to parse protobuf."; |
| 51 return authpolicy::ERROR_DBUS_FAILURE; |
| 52 } |
| 53 return authpolicy::ERROR_NONE; |
| 54 } |
| 55 |
36 class AuthPolicyClientImpl : public AuthPolicyClient { | 56 class AuthPolicyClientImpl : public AuthPolicyClient { |
37 public: | 57 public: |
38 AuthPolicyClientImpl() : weak_ptr_factory_(this) {} | 58 AuthPolicyClientImpl() : weak_ptr_factory_(this) {} |
39 | 59 |
40 ~AuthPolicyClientImpl() override {} | 60 ~AuthPolicyClientImpl() override {} |
41 | 61 |
42 // AuthPolicyClient override. | 62 // AuthPolicyClient override. |
43 void JoinAdDomain(const std::string& machine_name, | 63 void JoinAdDomain(const std::string& machine_name, |
44 const std::string& user_principal_name, | 64 const std::string& user_principal_name, |
45 int password_fd, | 65 int password_fd, |
(...skipping 19 matching lines...) Expand all Loading... |
65 dbus::MessageWriter writer(&method_call); | 85 dbus::MessageWriter writer(&method_call); |
66 writer.AppendString(user_principal_name); | 86 writer.AppendString(user_principal_name); |
67 writer.AppendString(object_guid); | 87 writer.AppendString(object_guid); |
68 writer.AppendFileDescriptor(password_fd); | 88 writer.AppendFileDescriptor(password_fd); |
69 proxy_->CallMethod( | 89 proxy_->CallMethod( |
70 &method_call, kSlowDbusTimeoutMilliseconds, | 90 &method_call, kSlowDbusTimeoutMilliseconds, |
71 base::Bind(&AuthPolicyClientImpl::HandleAuthCallback, | 91 base::Bind(&AuthPolicyClientImpl::HandleAuthCallback, |
72 weak_ptr_factory_.GetWeakPtr(), base::Passed(&callback))); | 92 weak_ptr_factory_.GetWeakPtr(), base::Passed(&callback))); |
73 } | 93 } |
74 | 94 |
| 95 void GetUserStatus(const std::string& object_guid, |
| 96 GetUserStatusCallback callback) override { |
| 97 dbus::MethodCall method_call(authpolicy::kAuthPolicyInterface, |
| 98 authpolicy::kAuthPolicyGetUserStatus); |
| 99 dbus::MessageWriter writer(&method_call); |
| 100 writer.AppendString(object_guid); |
| 101 proxy_->CallMethod( |
| 102 &method_call, kSlowDbusTimeoutMilliseconds, |
| 103 base::Bind(&AuthPolicyClientImpl::HandleGetUserStatusCallback, |
| 104 weak_ptr_factory_.GetWeakPtr(), base::Passed(&callback))); |
| 105 } |
| 106 |
75 void RefreshDevicePolicy(RefreshPolicyCallback callback) override { | 107 void RefreshDevicePolicy(RefreshPolicyCallback callback) override { |
76 dbus::MethodCall method_call(authpolicy::kAuthPolicyInterface, | 108 dbus::MethodCall method_call(authpolicy::kAuthPolicyInterface, |
77 authpolicy::kAuthPolicyRefreshDevicePolicy); | 109 authpolicy::kAuthPolicyRefreshDevicePolicy); |
78 proxy_->CallMethod( | 110 proxy_->CallMethod( |
79 &method_call, kSlowDbusTimeoutMilliseconds, | 111 &method_call, kSlowDbusTimeoutMilliseconds, |
80 base::Bind(&AuthPolicyClientImpl::HandleRefreshPolicyCallback, | 112 base::Bind(&AuthPolicyClientImpl::HandleRefreshPolicyCallback, |
81 weak_ptr_factory_.GetWeakPtr(), base::Passed(&callback))); | 113 weak_ptr_factory_.GetWeakPtr(), base::Passed(&callback))); |
82 } | 114 } |
83 | 115 |
84 void RefreshUserPolicy(const AccountId& account_id, | 116 void RefreshUserPolicy(const AccountId& account_id, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 DLOG(ERROR) << "Join: Couldn't call to authpolicy"; | 152 DLOG(ERROR) << "Join: Couldn't call to authpolicy"; |
121 std::move(callback).Run(authpolicy::ERROR_DBUS_FAILURE); | 153 std::move(callback).Run(authpolicy::ERROR_DBUS_FAILURE); |
122 return; | 154 return; |
123 } | 155 } |
124 | 156 |
125 dbus::MessageReader reader(response); | 157 dbus::MessageReader reader(response); |
126 std::move(callback).Run(GetErrorFromReader(&reader)); | 158 std::move(callback).Run(GetErrorFromReader(&reader)); |
127 } | 159 } |
128 | 160 |
129 void HandleAuthCallback(AuthCallback callback, dbus::Response* response) { | 161 void HandleAuthCallback(AuthCallback callback, dbus::Response* response) { |
130 authpolicy::ActiveDirectoryAccountData account_data; | 162 authpolicy::ActiveDirectoryAccountInfo account_info; |
131 if (!response) { | 163 authpolicy::ErrorType error(GetErrorAndProto(response, &account_info)); |
132 DLOG(ERROR) << "Auth: Failed to call to authpolicy"; | 164 std::move(callback).Run(error, account_info); |
133 std::move(callback).Run(authpolicy::ERROR_DBUS_FAILURE, account_data); | 165 } |
134 return; | 166 |
135 } | 167 void HandleGetUserStatusCallback(GetUserStatusCallback callback, |
136 dbus::MessageReader reader(response); | 168 dbus::Response* response) { |
137 const authpolicy::ErrorType error(GetErrorFromReader(&reader)); | 169 authpolicy::ActiveDirectoryUserStatus user_status; |
138 if (!reader.PopArrayOfBytesAsProto(&account_data)) { | 170 authpolicy::ErrorType error(GetErrorAndProto(response, &user_status)); |
139 DLOG(ERROR) << "Failed to parse protobuf."; | 171 std::move(callback).Run(error, user_status); |
140 std::move(callback).Run(authpolicy::ErrorType::ERROR_DBUS_FAILURE, | |
141 account_data); | |
142 return; | |
143 } | |
144 std::move(callback).Run(error, account_data); | |
145 } | 172 } |
146 | 173 |
147 dbus::Bus* bus_ = nullptr; | 174 dbus::Bus* bus_ = nullptr; |
148 dbus::ObjectProxy* proxy_ = nullptr; | 175 dbus::ObjectProxy* proxy_ = nullptr; |
149 | 176 |
150 // Note: This should remain the last member so it'll be destroyed and | 177 // Note: This should remain the last member so it'll be destroyed and |
151 // invalidate its weak pointers before any other members are destroyed. | 178 // invalidate its weak pointers before any other members are destroyed. |
152 base::WeakPtrFactory<AuthPolicyClientImpl> weak_ptr_factory_; | 179 base::WeakPtrFactory<AuthPolicyClientImpl> weak_ptr_factory_; |
153 | 180 |
154 DISALLOW_COPY_AND_ASSIGN(AuthPolicyClientImpl); | 181 DISALLOW_COPY_AND_ASSIGN(AuthPolicyClientImpl); |
155 }; | 182 }; |
156 | 183 |
157 } // namespace | 184 } // namespace |
158 | 185 |
159 AuthPolicyClient::AuthPolicyClient() {} | 186 AuthPolicyClient::AuthPolicyClient() {} |
160 | 187 |
161 AuthPolicyClient::~AuthPolicyClient() {} | 188 AuthPolicyClient::~AuthPolicyClient() {} |
162 | 189 |
163 // static | 190 // static |
164 AuthPolicyClient* AuthPolicyClient::Create() { | 191 AuthPolicyClient* AuthPolicyClient::Create() { |
165 return new AuthPolicyClientImpl(); | 192 return new AuthPolicyClientImpl(); |
166 } | 193 } |
167 | 194 |
168 } // namespace chromeos | 195 } // namespace chromeos |
OLD | NEW |