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

Side by Side Diff: components/os_crypt/kwallet_dbus.cc

Issue 2150543002: OSCrypt supports encryption with KWallet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: feedback Created 4 years, 5 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 unified diff | Download patch
OLDNEW
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 4
5 #include <components/os_crypt/kwallet_dbus.h> 5 #include <components/os_crypt/kwallet_dbus.h>
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 "start_service_by_desktop_name"); 61 "start_service_by_desktop_name");
62 dbus::MessageWriter builder(&method_call); 62 dbus::MessageWriter builder(&method_call);
63 std::vector<std::string> empty; 63 std::vector<std::string> empty;
64 builder.AppendString(kwalletd_name_); // serviceName 64 builder.AppendString(kwalletd_name_); // serviceName
65 builder.AppendArrayOfStrings(empty); // urls 65 builder.AppendArrayOfStrings(empty); // urls
66 builder.AppendArrayOfStrings(empty); // envs 66 builder.AppendArrayOfStrings(empty); // envs
67 builder.AppendString(std::string()); // startup_id 67 builder.AppendString(std::string()); // startup_id
68 builder.AppendBool(false); // blind 68 builder.AppendBool(false); // blind
69 std::unique_ptr<dbus::Response> response(klauncher->CallMethodAndBlock( 69 std::unique_ptr<dbus::Response> response(klauncher->CallMethodAndBlock(
70 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); 70 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
71 if (!response.get()) { 71 if (!response) {
72 LOG(ERROR) << "Error contacting klauncher to start " << kwalletd_name_; 72 LOG(ERROR) << "Error contacting klauncher to start " << kwalletd_name_;
73 return false; 73 return false;
74 } 74 }
75 dbus::MessageReader reader(response.get()); 75 dbus::MessageReader reader(response.get());
76 int32_t ret = -1; 76 int32_t ret = -1;
77 std::string dbus_name; 77 std::string dbus_name;
78 std::string error; 78 std::string error;
79 int32_t pid = -1; 79 int32_t pid = -1;
80 if (!reader.PopInt32(&ret) || !reader.PopString(&dbus_name) || 80 if (!reader.PopInt32(&ret) || !reader.PopString(&dbus_name) ||
81 !reader.PopString(&error) || !reader.PopInt32(&pid)) { 81 !reader.PopString(&error) || !reader.PopInt32(&pid)) {
82 LOG(ERROR) << "Error reading response from klauncher to start " 82 LOG(ERROR) << "Error reading response from klauncher to start "
83 << kwalletd_name_ << ": " << response->ToString(); 83 << kwalletd_name_ << ": " << response->ToString();
84 return false; 84 return false;
85 } 85 }
86 if (!error.empty() || ret) { 86 if (!error.empty() || ret) {
87 LOG(ERROR) << "Error launching " << kwalletd_name_ << ": error '" << error 87 LOG(ERROR) << "Error launching " << kwalletd_name_ << ": error '" << error
88 << "' (code " << ret << ")"; 88 << "' (code " << ret << ")";
89 return false; 89 return false;
90 } 90 }
91 91
92 return true; 92 return true;
93 } 93 }
94 94
95 KWalletDBus::Error KWalletDBus::IsEnabled(bool* enabled) { 95 KWalletDBus::Error KWalletDBus::IsEnabled(bool* enabled) {
96 dbus::MethodCall method_call(kKWalletInterface, "isEnabled"); 96 dbus::MethodCall method_call(kKWalletInterface, "isEnabled");
97 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock( 97 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock(
98 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); 98 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
99 if (!response.get()) { 99 if (!response) {
100 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (isEnabled)"; 100 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (isEnabled)";
101 return CANNOT_CONTACT; 101 return CANNOT_CONTACT;
102 } 102 }
103 dbus::MessageReader reader(response.get()); 103 dbus::MessageReader reader(response.get());
104 if (!reader.PopBool(enabled)) { 104 if (!reader.PopBool(enabled)) {
105 LOG(ERROR) << "Error reading response from " << kwalletd_name_ 105 LOG(ERROR) << "Error reading response from " << kwalletd_name_
106 << " (isEnabled): " << response->ToString(); 106 << " (isEnabled): " << response->ToString();
107 return CANNOT_READ; 107 return CANNOT_READ;
108 } 108 }
109 // Not enabled? Don't use KWallet. But also don't warn here. 109 // Not enabled? Don't use KWallet. But also don't warn here.
110 if (!enabled) { 110 if (!enabled) {
111 VLOG(1) << kwalletd_name_ << " reports that KWallet is not enabled."; 111 VLOG(1) << kwalletd_name_ << " reports that KWallet is not enabled.";
112 } 112 }
113 113
114 return SUCCESS; 114 return SUCCESS;
115 } 115 }
116 116
117 KWalletDBus::Error KWalletDBus::NetworkWallet(std::string* wallet_name) { 117 KWalletDBus::Error KWalletDBus::NetworkWallet(std::string* wallet_name) {
118 // Get the wallet name. 118 // Get the wallet name.
119 dbus::MethodCall method_call(kKWalletInterface, "networkWallet"); 119 dbus::MethodCall method_call(kKWalletInterface, "networkWallet");
120 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock( 120 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock(
121 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); 121 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
122 if (!response.get()) { 122 if (!response) {
123 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (networkWallet)"; 123 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (networkWallet)";
124 return CANNOT_CONTACT; 124 return CANNOT_CONTACT;
125 } 125 }
126 dbus::MessageReader reader(response.get()); 126 dbus::MessageReader reader(response.get());
127 if (!reader.PopString(wallet_name)) { 127 if (!reader.PopString(wallet_name)) {
128 LOG(ERROR) << "Error reading response from " << kwalletd_name_ 128 LOG(ERROR) << "Error reading response from " << kwalletd_name_
129 << " (networkWallet): " << response->ToString(); 129 << " (networkWallet): " << response->ToString();
130 return CANNOT_READ; 130 return CANNOT_READ;
131 } 131 }
132 132
133 return SUCCESS; 133 return SUCCESS;
134 } 134 }
135 135
136 KWalletDBus::Error KWalletDBus::Open(const std::string& wallet_name, 136 KWalletDBus::Error KWalletDBus::Open(const std::string& wallet_name,
137 const std::string& app_name, 137 const std::string& app_name,
138 int* handle_ptr) { 138 int* handle_ptr) {
139 dbus::MethodCall method_call(kKWalletInterface, "open"); 139 dbus::MethodCall method_call(kKWalletInterface, "open");
140 dbus::MessageWriter builder(&method_call); 140 dbus::MessageWriter builder(&method_call);
141 builder.AppendString(wallet_name); // wallet 141 builder.AppendString(wallet_name); // wallet
142 builder.AppendInt64(0); // wid 142 builder.AppendInt64(0); // wid
143 builder.AppendString(app_name); // appid 143 builder.AppendString(app_name); // appid
144 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock( 144 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock(
145 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); 145 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
146 if (!response.get()) { 146 if (!response) {
147 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (open)"; 147 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (open)";
148 return CANNOT_CONTACT; 148 return CANNOT_CONTACT;
149 } 149 }
150 dbus::MessageReader reader(response.get()); 150 dbus::MessageReader reader(response.get());
151 if (!reader.PopInt32(handle_ptr)) { 151 if (!reader.PopInt32(handle_ptr)) {
152 LOG(ERROR) << "Error reading response from " << kwalletd_name_ 152 LOG(ERROR) << "Error reading response from " << kwalletd_name_
153 << " (open): " << response->ToString(); 153 << " (open): " << response->ToString();
154 return CANNOT_READ; 154 return CANNOT_READ;
155 } 155 }
156 return SUCCESS; 156 return SUCCESS;
157 } 157 }
158 158
159 KWalletDBus::Error KWalletDBus::HasEntry(const int wallet_handle, 159 KWalletDBus::Error KWalletDBus::HasEntry(const int wallet_handle,
160 const std::string& folder_name, 160 const std::string& folder_name,
161 const std::string& signon_realm, 161 const std::string& signon_realm,
162 const std::string& app_name, 162 const std::string& app_name,
163 bool* has_entry) { 163 bool* has_entry) {
164 dbus::MethodCall method_call(kKWalletInterface, "hasEntry"); 164 dbus::MethodCall method_call(kKWalletInterface, "hasEntry");
165 dbus::MessageWriter builder(&method_call); 165 dbus::MessageWriter builder(&method_call);
166 builder.AppendInt32(wallet_handle); // handle 166 builder.AppendInt32(wallet_handle); // handle
167 builder.AppendString(folder_name); // folder 167 builder.AppendString(folder_name); // folder
168 builder.AppendString(signon_realm); // key 168 builder.AppendString(signon_realm); // key
169 builder.AppendString(app_name); // appid 169 builder.AppendString(app_name); // appid
170 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock( 170 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock(
171 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); 171 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
172 if (!response.get()) { 172 if (!response) {
173 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (hasEntry)"; 173 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (hasEntry)";
174 return CANNOT_CONTACT; 174 return CANNOT_CONTACT;
175 } 175 }
176 dbus::MessageReader reader(response.get()); 176 dbus::MessageReader reader(response.get());
177 if (!reader.PopBool(has_entry)) { 177 if (!reader.PopBool(has_entry)) {
178 LOG(ERROR) << "Error reading response from " << kwalletd_name_ 178 LOG(ERROR) << "Error reading response from " << kwalletd_name_
179 << " (hasEntry): " << response->ToString(); 179 << " (hasEntry): " << response->ToString();
180 return CANNOT_READ; 180 return CANNOT_READ;
181 } 181 }
182 return SUCCESS; 182 return SUCCESS;
183 } 183 }
184 184
185 KWalletDBus::Error KWalletDBus::ReadEntry(const int wallet_handle, 185 KWalletDBus::Error KWalletDBus::ReadEntry(const int wallet_handle,
186 const std::string& folder_name, 186 const std::string& folder_name,
187 const std::string& signon_realm, 187 const std::string& signon_realm,
188 const std::string& app_name, 188 const std::string& app_name,
189 std::vector<uint8_t>* bytes_ptr) { 189 std::vector<uint8_t>* bytes_ptr) {
190 dbus::MethodCall method_call(kKWalletInterface, "readEntry"); 190 dbus::MethodCall method_call(kKWalletInterface, "readEntry");
191 dbus::MessageWriter builder(&method_call); 191 dbus::MessageWriter builder(&method_call);
192 builder.AppendInt32(wallet_handle); // handle 192 builder.AppendInt32(wallet_handle); // handle
193 builder.AppendString(folder_name); // folder 193 builder.AppendString(folder_name); // folder
194 builder.AppendString(signon_realm); // key 194 builder.AppendString(signon_realm); // key
195 builder.AppendString(app_name); // appid 195 builder.AppendString(app_name); // appid
196 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock( 196 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock(
197 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); 197 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
198 if (!response.get()) { 198 if (!response) {
199 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (readEntry)"; 199 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (readEntry)";
200 return CANNOT_CONTACT; 200 return CANNOT_CONTACT;
201 } 201 }
202 size_t length = 0; 202 size_t length = 0;
203 const uint8_t* bytes_temp = nullptr; 203 const uint8_t* bytes_temp = nullptr;
204 dbus::MessageReader reader(response.get()); 204 dbus::MessageReader reader(response.get());
205 if (!reader.PopArrayOfBytes(&bytes_temp, &length)) { 205 if (!reader.PopArrayOfBytes(&bytes_temp, &length)) {
206 LOG(ERROR) << "Error reading response from " << kwalletd_name_ 206 LOG(ERROR) << "Error reading response from " << kwalletd_name_
207 << " (readEntry): " << response->ToString(); 207 << " (readEntry): " << response->ToString();
208 return CANNOT_READ; 208 return CANNOT_READ;
(...skipping 11 matching lines...) Expand all
220 const std::string& folder_name, 220 const std::string& folder_name,
221 const std::string& app_name, 221 const std::string& app_name,
222 std::vector<std::string>* entry_list_ptr) { 222 std::vector<std::string>* entry_list_ptr) {
223 dbus::MethodCall method_call(kKWalletInterface, "entryList"); 223 dbus::MethodCall method_call(kKWalletInterface, "entryList");
224 dbus::MessageWriter builder(&method_call); 224 dbus::MessageWriter builder(&method_call);
225 builder.AppendInt32(wallet_handle); // handle 225 builder.AppendInt32(wallet_handle); // handle
226 builder.AppendString(folder_name); // folder 226 builder.AppendString(folder_name); // folder
227 builder.AppendString(app_name); // appid 227 builder.AppendString(app_name); // appid
228 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock( 228 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock(
229 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); 229 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
230 if (!response.get()) { 230 if (!response) {
231 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (entryList)"; 231 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (entryList)";
232 return CANNOT_CONTACT; 232 return CANNOT_CONTACT;
233 } 233 }
234 dbus::MessageReader reader(response.get()); 234 dbus::MessageReader reader(response.get());
235 if (!reader.PopArrayOfStrings(entry_list_ptr)) { 235 if (!reader.PopArrayOfStrings(entry_list_ptr)) {
236 LOG(ERROR) << "Error reading response from " << kwalletd_name_ 236 LOG(ERROR) << "Error reading response from " << kwalletd_name_
237 << "(entryList): " << response->ToString(); 237 << "(entryList): " << response->ToString();
238 return CANNOT_READ; 238 return CANNOT_READ;
239 } 239 }
240 return SUCCESS; 240 return SUCCESS;
241 } 241 }
242 242
243 KWalletDBus::Error KWalletDBus::RemoveEntry(const int wallet_handle, 243 KWalletDBus::Error KWalletDBus::RemoveEntry(const int wallet_handle,
244 const std::string& folder_name, 244 const std::string& folder_name,
245 const std::string& signon_realm, 245 const std::string& signon_realm,
246 const std::string& app_name, 246 const std::string& app_name,
247 int* return_code_ptr) { 247 int* return_code_ptr) {
248 dbus::MethodCall method_call(kKWalletInterface, "removeEntry"); 248 dbus::MethodCall method_call(kKWalletInterface, "removeEntry");
249 dbus::MessageWriter builder(&method_call); 249 dbus::MessageWriter builder(&method_call);
250 builder.AppendInt32(wallet_handle); // handle 250 builder.AppendInt32(wallet_handle); // handle
251 builder.AppendString(folder_name); // folder 251 builder.AppendString(folder_name); // folder
252 builder.AppendString(signon_realm); // key 252 builder.AppendString(signon_realm); // key
253 builder.AppendString(app_name); // appid 253 builder.AppendString(app_name); // appid
254 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock( 254 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock(
255 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); 255 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
256 if (!response.get()) { 256 if (!response) {
257 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (removeEntry)"; 257 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (removeEntry)";
258 return CANNOT_CONTACT; 258 return CANNOT_CONTACT;
259 } 259 }
260 dbus::MessageReader reader(response.get()); 260 dbus::MessageReader reader(response.get());
261 if (!reader.PopInt32(return_code_ptr)) { 261 if (!reader.PopInt32(return_code_ptr)) {
262 LOG(ERROR) << "Error reading response from " << kwalletd_name_ 262 LOG(ERROR) << "Error reading response from " << kwalletd_name_
263 << " (removeEntry): " << response->ToString(); 263 << " (removeEntry): " << response->ToString();
264 return CANNOT_READ; 264 return CANNOT_READ;
265 } 265 }
266 return SUCCESS; 266 return SUCCESS;
267 } 267 }
268 268
269 KWalletDBus::Error KWalletDBus::WriteEntry(const int wallet_handle, 269 KWalletDBus::Error KWalletDBus::WriteEntry(const int wallet_handle,
270 const std::string& folder_name, 270 const std::string& folder_name,
271 const std::string& signon_realm, 271 const std::string& signon_realm,
272 const std::string& app_name, 272 const std::string& app_name,
273 const uint8_t* data, 273 const uint8_t* data,
274 const size_t length, 274 const size_t length,
275 int* return_code_ptr) { 275 int* return_code_ptr) {
276 dbus::MethodCall method_call(kKWalletInterface, "writeEntry"); 276 dbus::MethodCall method_call(kKWalletInterface, "writeEntry");
277 dbus::MessageWriter builder(&method_call); 277 dbus::MessageWriter builder(&method_call);
278 builder.AppendInt32(wallet_handle); // handle 278 builder.AppendInt32(wallet_handle); // handle
279 builder.AppendString(folder_name); // folder 279 builder.AppendString(folder_name); // folder
280 builder.AppendString(signon_realm); // key 280 builder.AppendString(signon_realm); // key
281 builder.AppendArrayOfBytes(data, length); // value 281 builder.AppendArrayOfBytes(data, length); // value
282 builder.AppendString(app_name); // appid 282 builder.AppendString(app_name); // appid
283 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock( 283 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock(
284 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); 284 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
285 if (!response.get()) { 285 if (!response) {
286 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (writeEntry)"; 286 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (writeEntry)";
287 return CANNOT_CONTACT; 287 return CANNOT_CONTACT;
288 } 288 }
289 dbus::MessageReader reader(response.get()); 289 dbus::MessageReader reader(response.get());
290 if (!reader.PopInt32(return_code_ptr)) { 290 if (!reader.PopInt32(return_code_ptr)) {
291 LOG(ERROR) << "Error reading response from " << kwalletd_name_ 291 LOG(ERROR) << "Error reading response from " << kwalletd_name_
292 << " (writeEntry): " << response->ToString(); 292 << " (writeEntry): " << response->ToString();
293 return CANNOT_READ; 293 return CANNOT_READ;
294 } 294 }
295 return SUCCESS; 295 return SUCCESS;
296 } 296 }
297 297
298 KWalletDBus::Error KWalletDBus::HasFolder(const int handle, 298 KWalletDBus::Error KWalletDBus::HasFolder(const int handle,
299 const std::string& folder_name, 299 const std::string& folder_name,
300 const std::string& app_name, 300 const std::string& app_name,
301 bool* has_folder_ptr) { 301 bool* has_folder_ptr) {
302 dbus::MethodCall method_call(kKWalletInterface, "hasFolder"); 302 dbus::MethodCall method_call(kKWalletInterface, "hasFolder");
303 dbus::MessageWriter builder(&method_call); 303 dbus::MessageWriter builder(&method_call);
304 builder.AppendInt32(handle); // handle 304 builder.AppendInt32(handle); // handle
305 builder.AppendString(folder_name); // folder 305 builder.AppendString(folder_name); // folder
306 builder.AppendString(app_name); // appid 306 builder.AppendString(app_name); // appid
307 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock( 307 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock(
308 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); 308 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
309 if (!response.get()) { 309 if (!response) {
310 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (hasFolder)"; 310 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (hasFolder)";
311 return CANNOT_CONTACT; 311 return CANNOT_CONTACT;
312 } 312 }
313 dbus::MessageReader reader(response.get()); 313 dbus::MessageReader reader(response.get());
314 if (!reader.PopBool(has_folder_ptr)) { 314 if (!reader.PopBool(has_folder_ptr)) {
315 LOG(ERROR) << "Error reading response from " << kwalletd_name_ 315 LOG(ERROR) << "Error reading response from " << kwalletd_name_
316 << " (hasFolder): " << response->ToString(); 316 << " (hasFolder): " << response->ToString();
317 return CANNOT_READ; 317 return CANNOT_READ;
318 } 318 }
319 return SUCCESS; 319 return SUCCESS;
320 } 320 }
321 321
322 KWalletDBus::Error KWalletDBus::CreateFolder(const int handle, 322 KWalletDBus::Error KWalletDBus::CreateFolder(const int handle,
323 const std::string& folder_name, 323 const std::string& folder_name,
324 const std::string& app_name, 324 const std::string& app_name,
325 bool* success_ptr) { 325 bool* success_ptr) {
326 dbus::MethodCall method_call(kKWalletInterface, "createFolder"); 326 dbus::MethodCall method_call(kKWalletInterface, "createFolder");
327 dbus::MessageWriter builder(&method_call); 327 dbus::MessageWriter builder(&method_call);
328 builder.AppendInt32(handle); // handle 328 builder.AppendInt32(handle); // handle
329 builder.AppendString(folder_name); // folder 329 builder.AppendString(folder_name); // folder
330 builder.AppendString(app_name); // appid 330 builder.AppendString(app_name); // appid
331 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock( 331 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock(
332 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); 332 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
333 if (!response.get()) { 333 if (!response) {
334 LOG(ERROR) << "Error contacting << " << kwalletd_name_ << " (createFolder)"; 334 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (createFolder)";
335 return CANNOT_CONTACT; 335 return CANNOT_CONTACT;
336 } 336 }
337 dbus::MessageReader reader(response.get()); 337 dbus::MessageReader reader(response.get());
338 if (!reader.PopBool(success_ptr)) { 338 if (!reader.PopBool(success_ptr)) {
339 LOG(ERROR) << "Error reading response from " << kwalletd_name_ 339 LOG(ERROR) << "Error reading response from " << kwalletd_name_
340 << " (createFolder): " << response->ToString(); 340 << " (createFolder): " << response->ToString();
341 return CANNOT_READ; 341 return CANNOT_READ;
342 } 342 }
343 return SUCCESS; 343 return SUCCESS;
344 } 344 }
345
346 KWalletDBus::Error KWalletDBus::WritePassword(const int handle,
347 const std::string& folder_name,
348 const std::string& key,
349 const std::string& password,
350 const std::string& app_name,
351 bool* const write_success_ptr) {
352 dbus::MethodCall method_call(kKWalletInterface, "writePassword");
353 dbus::MessageWriter builder(&method_call);
354 builder.AppendInt32(handle);
355 builder.AppendString(folder_name);
356 builder.AppendString(key);
357 builder.AppendString(password);
358 builder.AppendString(app_name);
359 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock(
360 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
361 if (!response) {
362 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (writePassword)";
363 return CANNOT_CONTACT;
364 }
365 dbus::MessageReader reader(response.get());
366 int return_code;
367 if (!reader.PopInt32(&return_code)) {
368 LOG(ERROR) << "Error reading response from " << kwalletd_name_
369 << " (writePassword): " << response->ToString();
370 return CANNOT_READ;
371 }
372 *write_success_ptr = return_code == 0;
373 return SUCCESS;
374 }
375
376 KWalletDBus::Error KWalletDBus::ReadPassword(const int handle,
377 const std::string& folder_name,
378 const std::string& key,
379 const std::string& app_name,
380 std::string* const password_ptr) {
381 dbus::MethodCall method_call(kKWalletInterface, "readPassword");
382 dbus::MessageWriter builder(&method_call);
383 builder.AppendInt32(handle);
384 builder.AppendString(folder_name);
385 builder.AppendString(key);
386 builder.AppendString(app_name);
387 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock(
388 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
389 if (!response) {
390 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (readPassword)";
391 return CANNOT_CONTACT;
392 }
393 dbus::MessageReader reader(response.get());
394 if (!reader.PopString(password_ptr)) {
395 LOG(ERROR) << "Error reading response from " << kwalletd_name_
396 << " (readPassword): " << response->ToString();
397 return CANNOT_READ;
398 }
399 return SUCCESS;
400 }
401
402 KWalletDBus::Error KWalletDBus::Close(const int handle,
403 const bool force,
404 const std::string& app_name,
405 bool* success_ptr) {
406 dbus::MethodCall method_call(kKWalletInterface, "close");
407 dbus::MessageWriter builder(&method_call);
408 builder.AppendInt32(handle);
409 builder.AppendBool(force);
410 builder.AppendString(app_name);
411 std::unique_ptr<dbus::Response> response(kwallet_proxy_->CallMethodAndBlock(
412 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
413 if (!response) {
414 LOG(ERROR) << "Error contacting " << kwalletd_name_ << " (close)";
415 return CANNOT_CONTACT;
416 }
417 dbus::MessageReader reader(response.get());
418 int return_code = 1;
419 if (!reader.PopInt32(&return_code)) {
420 LOG(ERROR) << "Error reading response from " << kwalletd_name_
421 << " (close): " << response->ToString();
422 return CANNOT_READ;
423 }
424 *success_ptr = return_code == 0;
425 return SUCCESS;
426 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698