Use AM_CPPFLAGS instead of INCLUDES
[platform/upstream/libsecret.git] / libsecret / secret-password.c
1 /* libsecret - GLib wrapper for Secret Service
2  *
3  * Copyright 2011 Collabora Ltd.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published
7  * by the Free Software Foundation; either version 2.1 of the licence or (at
8  * your option) any later version.
9  *
10  * See the included COPYING file for more information.
11  *
12  * Author: Stef Walter <stefw@gnome.org>
13  */
14
15 #include "config.h"
16
17 #include "secret-attributes.h"
18 #include "secret-password.h"
19 #include "secret-private.h"
20 #include "secret-value.h"
21
22 #include <egg/egg-secure-memory.h>
23
24 /**
25  * SECTION:secret-password
26  * @title: Password storage
27  * @short_description: Simple password storage and lookup
28  *
29  * This is a simple API for storing passwords and retrieving passwords in the
30  * Secret Service.
31  *
32  * Each password is associated with a set of attributes. Attribute values can
33  * be either strings, integers or booleans.
34  *
35  * The names and types of allowed attributes for a given password are defined
36  * with a schema. Certain schemas are predefined. Additional schemas can be
37  * defined via the %SecretSchema structure.
38  *
39  * Each of the functions accept a variable list of attributes names and their
40  * values. Include a %NULL to terminate the list of attributes.
41  *
42  * These functions have an unstable API and may change across versions. Use
43  * <literal>libsecret-unstable</literal> package to access them.
44  *
45  * Stability: Unstable
46  */
47
48 /**
49  * secret_password_store: (skip)
50  * @schema: the schema for attributes
51  * @collection: (allow-none): a collection alias, or D-Bus object path of the collection where to store the secret
52  * @label: label for the secret
53  * @password: the null-terminated password to store
54  * @cancellable: optional cancellation object
55  * @callback: called when the operation completes
56  * @user_data: data to be passed to the callback
57  * @...: the attribute keys and values, terminated with %NULL
58  *
59  * Store a password in the secret service.
60  *
61  * The variable argument list should contain pairs of a) The attribute name as
62  * a null-terminated string, followed by b) attribute value, either a character
63  * string, an int number, or a gboolean value, as defined in the @schema.
64  * The list of attribtues should be terminated with a %NULL.
65  *
66  * If the attributes match a secret item already stored in the collection, then
67  * the item will be updated with these new values.
68  *
69  * If @collection is %NULL, then the default collection will be
70  * used. Use #SECRET_COLLECTION_SESSION to store the password in the session
71  * collection, which doesn't get stored across login sessions.
72  *
73  * This method will return immediately and complete asynchronously.
74  */
75 void
76 secret_password_store (const SecretSchema *schema,
77                        const gchar *collection,
78                        const gchar *label,
79                        const gchar *password,
80                        GCancellable *cancellable,
81                        GAsyncReadyCallback callback,
82                        gpointer user_data,
83                        ...)
84 {
85         GHashTable *attributes;
86         va_list va;
87
88         g_return_if_fail (schema != NULL);
89         g_return_if_fail (label != NULL);
90         g_return_if_fail (password != NULL);
91         g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
92
93         va_start (va, user_data);
94         attributes = secret_attributes_buildv (schema, va);
95         va_end (va);
96
97         /* Precondition failed, already warned */
98         if (!attributes)
99                 return;
100
101         secret_password_storev (schema, attributes, collection, label, password,
102                                 cancellable, callback, user_data);
103
104         g_hash_table_unref (attributes);
105 }
106
107 /**
108  * secret_password_storev:
109  * @schema: the schema for attributes
110  * @attributes: (element-type utf8 utf8): the attribute keys and values
111  * @collection: (allow-none): a collection alias, or D-Bus object path of the collection where to store the secret
112  * @label: label for the secret
113  * @password: the null-terminated password to store
114  * @cancellable: optional cancellation object
115  * @callback: called when the operation completes
116  * @user_data: data to be passed to the callback
117  *
118  * Store a password in the secret service.
119  *
120  * The @attributes should be a set of key and value string pairs.
121  *
122  * If the attributes match a secret item already stored in the collection, then
123  * the item will be updated with these new values.
124  *
125  * If @collection is %NULL, then the default collection will be
126  * used. Use #SECRET_COLLECTION_SESSION to store the password in the session
127  * collection, which doesn't get stored across login sessions.
128  *
129  * This method will return immediately and complete asynchronously.
130  *
131  * Rename to: secret_password_store
132  */
133 void
134 secret_password_storev (const SecretSchema *schema,
135                         GHashTable *attributes,
136                         const gchar *collection,
137                         const gchar *label,
138                         const gchar *password,
139                         GCancellable *cancellable,
140                         GAsyncReadyCallback callback,
141                         gpointer user_data)
142 {
143         SecretValue *value;
144
145         g_return_if_fail (schema != NULL);
146         g_return_if_fail (label != NULL);
147         g_return_if_fail (password != NULL);
148         g_return_if_fail (attributes != NULL);
149         g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
150
151         /* Warnings raised already */
152         if (!_secret_attributes_validate (schema, attributes, G_STRFUNC, FALSE))
153                 return;
154
155         value = secret_value_new (password, -1, "text/plain");
156
157         secret_service_store (NULL, schema, attributes, collection,
158                               label, value, cancellable, callback, user_data);
159
160         secret_value_unref (value);
161 }
162
163 /**
164  * secret_password_store_finish:
165  * @result: the asynchronous result passed to the callback
166  * @error: location to place an error on failure
167  *
168  * Finish asynchronous operation to store a password in the secret service.
169  *
170  * Returns: whether the storage was successful or not
171  */
172 gboolean
173 secret_password_store_finish (GAsyncResult *result,
174                               GError **error)
175 {
176         g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
177         return secret_service_store_finish (NULL, result, error);
178 }
179
180 /**
181  * secret_password_store_sync:
182  * @schema: the schema for attributes
183  * @collection: (allow-none): a collection alias, or D-Bus object path of the collection where to store the secret
184  * @label: label for the secret
185  * @password: the null-terminated password to store
186  * @cancellable: optional cancellation object
187  * @error: location to place an error on failure
188  * @...: the attribute keys and values, terminated with %NULL
189  *
190  * Store a password in the secret service.
191  *
192  * The variable argument list should contain pairs of a) The attribute name as
193  * a null-terminated string, followed by b) attribute value, either a character
194  * string, an int number, or a gboolean value, as defined in the @schema.
195  * The list of attribtues should be terminated with a %NULL.
196  *
197  * If the attributes match a secret item already stored in the collection, then
198  * the item will be updated with these new values.
199  *
200  * If @collection is %NULL, then the default collection will be
201  * used. Use #SECRET_COLLECTION_SESSION to store the password in the session
202  * collection, which doesn't get stored across login sessions.
203  *
204  * This method may block indefinitely and should not be used in user interface
205  * threads.
206  *
207  * Returns: whether the storage was successful or not
208  */
209 gboolean
210 secret_password_store_sync (const SecretSchema *schema,
211                             const gchar *collection,
212                             const gchar *label,
213                             const gchar *password,
214                             GCancellable *cancellable,
215                             GError **error,
216                             ...)
217 {
218         GHashTable *attributes;
219         va_list va;
220         gboolean ret;
221
222         g_return_val_if_fail (schema != NULL, FALSE);
223         g_return_val_if_fail (label != NULL, FALSE);
224         g_return_val_if_fail (password != NULL, FALSE);
225         g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
226         g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
227
228         va_start (va, error);
229         attributes = secret_attributes_buildv (schema, va);
230         va_end (va);
231
232         /* Precondition failed, already warned */
233         if (!attributes)
234                 return FALSE;
235
236         ret = secret_password_storev_sync (schema, attributes, collection,
237                                            label, password, cancellable, error);
238
239         g_hash_table_unref (attributes);
240         return ret;
241 }
242
243 /**
244  * secret_password_storev_sync:
245  * @schema: the schema for attributes
246  * @attributes: (element-type utf8 utf8): the attribute keys and values
247  * @collection: (allow-none): a collection alias, or D-Bus object path of the collection where to store the secret
248  * @label: label for the secret
249  * @password: the null-terminated password to store
250  * @cancellable: optional cancellation object
251  * @error: location to place an error on failure
252  *
253  * Store a password in the secret service.
254  *
255  * The @attributes should be a set of key and value string pairs.
256  *
257  * If the attributes match a secret item already stored in the collection, then
258  * the item will be updated with these new values.
259  *
260  * If @collection is %NULL, then the default collection will be
261  * used. Use #SECRET_COLLECTION_SESSION to store the password in the session
262  * collection, which doesn't get stored across login sessions.
263  *
264  * This method may block indefinitely and should not be used in user interface
265  * threads.
266  *
267  * Returns: whether the storage was successful or not
268  *
269  * Rename to: secret_password_store_sync
270  */
271 gboolean
272 secret_password_storev_sync (const SecretSchema *schema,
273                              GHashTable *attributes,
274                              const gchar *collection,
275                              const gchar *label,
276                              const gchar *password,
277                              GCancellable *cancellable,
278                              GError **error)
279 {
280         SecretSync *sync;
281         gboolean ret;
282
283         g_return_val_if_fail (schema != NULL, FALSE);
284         g_return_val_if_fail (label != NULL, FALSE);
285         g_return_val_if_fail (password != NULL, FALSE);
286         g_return_val_if_fail (attributes != NULL, FALSE);
287         g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
288         g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
289
290         /* Warnings raised already */
291         if (!_secret_attributes_validate (schema, attributes, G_STRFUNC, FALSE))
292                 return FALSE;
293
294         sync = _secret_sync_new ();
295         g_main_context_push_thread_default (sync->context);
296
297         secret_password_storev (schema, attributes, collection, label, password,
298                                 cancellable, _secret_sync_on_result, sync);
299
300         g_main_loop_run (sync->loop);
301
302         ret = secret_password_store_finish (sync->result, error);
303
304         g_main_context_pop_thread_default (sync->context);
305         _secret_sync_free (sync);
306
307         return ret;
308 }
309
310 /**
311  * secret_password_lookup: (skip)
312  * @schema: the schema for the attributes
313  * @cancellable: optional cancellation object
314  * @callback: called when the operation completes
315  * @user_data: data to be passed to the callback
316  * @...: the attribute keys and values, terminated with %NULL
317  *
318  * Lookup a password in the secret service.
319  *
320  * The variable argument list should contain pairs of a) The attribute name as
321  * a null-terminated string, followed by b) attribute value, either a character
322  * string, an int number, or a gboolean value, as defined in the password
323  * @schema. The list of attribtues should be terminated with a %NULL.
324  *
325  * If no secret is found then %NULL is returned.
326  *
327  * This method will return immediately and complete asynchronously.
328  */
329 void
330 secret_password_lookup (const SecretSchema *schema,
331                         GCancellable *cancellable,
332                         GAsyncReadyCallback callback,
333                         gpointer user_data,
334                         ...)
335 {
336         GHashTable *attributes;
337         va_list va;
338
339         g_return_if_fail (schema != NULL);
340         g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
341
342         va_start (va, user_data);
343         attributes = secret_attributes_buildv (schema, va);
344         va_end (va);
345
346         /* Precondition failed, already warned */
347         if (!attributes)
348                 return;
349
350         secret_password_lookupv (schema, attributes, cancellable,
351                                  callback, user_data);
352
353         g_hash_table_unref (attributes);
354 }
355
356 /**
357  * secret_password_lookupv:
358  * @schema: the schema for attributes
359  * @attributes: (element-type utf8 utf8): the attribute keys and values
360  * @cancellable: optional cancellation object
361  * @callback: called when the operation completes
362  * @user_data: data to be passed to the callback
363  *
364  * Lookup a password in the secret service.
365  *
366  * The @attributes should be a set of key and value string pairs.
367  *
368  * If no secret is found then %NULL is returned.
369  *
370  * This method will return immediately and complete asynchronously.
371  *
372  * Rename to: secret_password_lookup
373  */
374 void
375 secret_password_lookupv (const SecretSchema *schema,
376                          GHashTable *attributes,
377                          GCancellable *cancellable,
378                          GAsyncReadyCallback callback,
379                          gpointer user_data)
380 {
381         g_return_if_fail (schema != NULL);
382         g_return_if_fail (attributes != NULL);
383         g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
384
385         /* Warnings raised already */
386         if (!_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
387                 return;
388
389         secret_service_lookup (NULL, schema, attributes,
390                                cancellable, callback, user_data);
391 }
392
393 /**
394  * secret_password_lookup_nonpageable_finish: (skip)
395  * @result: the asynchronous result passed to the callback
396  * @error: location to place an error on failure
397  *
398  * Finish an asynchronous operation to lookup a password in the secret service.
399  *
400  * Returns: (transfer full): a new password string stored in nonpageable memory
401  *          which must be freed with secret_password_free() when done
402  */
403 gchar *
404 secret_password_lookup_nonpageable_finish (GAsyncResult *result,
405                                            GError **error)
406 {
407         SecretValue *value;
408
409         g_return_val_if_fail (error == NULL || *error == NULL, NULL);
410
411         value = secret_service_lookup_finish (NULL, result, error);
412         if (value == NULL)
413                 return NULL;
414
415         return _secret_value_unref_to_password (value);
416 }
417
418 /**
419  * secret_password_lookup_finish:
420  * @result: the asynchronous result passed to the callback
421  * @error: location to place an error on failure
422  *
423  * Finish an asynchronous operation to lookup a password in the secret service.
424  *
425  * Returns: (transfer full): a new password string which should be freed with
426  *          secret_password_free() or may be freed with g_free() when done
427  */
428 gchar *
429 secret_password_lookup_finish (GAsyncResult *result,
430                                GError **error)
431 {
432         SecretValue *value;
433
434         g_return_val_if_fail (error == NULL || *error == NULL, NULL);
435
436         value = secret_service_lookup_finish (NULL, result, error);
437         if (value == NULL)
438                 return NULL;
439
440         return _secret_value_unref_to_string (value);
441 }
442
443 /**
444  * secret_password_lookup_sync: (skip)
445  * @schema: the schema for the attributes
446  * @cancellable: optional cancellation object
447  * @error: location to place an error on failure
448  * @...: the attribute keys and values, terminated with %NULL
449  *
450  * Lookup a password in the secret service.
451  *
452  * The variable argument list should contain pairs of a) The attribute name as
453  * a null-terminated string, followed by b) attribute value, either a character
454  * string, an int number, or a gboolean value, as defined in the password
455  * @schema. The list of attribtues should be terminated with a %NULL.
456  *
457  * If no secret is found then %NULL is returned.
458  *
459  * This method may block indefinitely and should not be used in user interface
460  * threads.
461  *
462  * Returns: (transfer full): a new password string which should be freed with
463  *          secret_password_free() or may be freed with g_free() when done
464  */
465 gchar *
466 secret_password_lookup_sync (const SecretSchema *schema,
467                              GCancellable *cancellable,
468                              GError **error,
469                              ...)
470 {
471         GHashTable *attributes;
472         gchar *password;
473         va_list va;
474
475         g_return_val_if_fail (schema != NULL, NULL);
476         g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
477         g_return_val_if_fail (error == NULL || *error == NULL, NULL);
478
479         va_start (va, error);
480         attributes = secret_attributes_buildv (schema, va);
481         va_end (va);
482
483         /* Precondition failed, already warned */
484         if (!attributes)
485                 return NULL;
486
487         password = secret_password_lookupv_sync (schema, attributes,
488                                                  cancellable, error);
489
490         g_hash_table_unref (attributes);
491
492         return password;
493 }
494
495 /**
496  * secret_password_lookup_nonpageable_sync: (skip)
497  * @schema: the schema for the attributes
498  * @cancellable: optional cancellation object
499  * @error: location to place an error on failure
500  * @...: the attribute keys and values, terminated with %NULL
501  *
502  * Lookup a password in the secret service.
503  *
504  * The variable argument list should contain pairs of a) The attribute name as
505  * a null-terminated string, followed by b) attribute value, either a character
506  * string, an int number, or a gboolean value, as defined in the password
507  * @schema. The list of attribtues should be terminated with a %NULL.
508  *
509  * If no secret is found then %NULL is returned.
510  *
511  * This method may block indefinitely and should not be used in user interface
512  * threads.
513  *
514  * Returns: (transfer full): a new password string stored in nonpageable memory
515  *          which must be freed with secret_password_free() when done
516  */
517 gchar *
518 secret_password_lookup_nonpageable_sync (const SecretSchema *schema,
519                                          GCancellable *cancellable,
520                                          GError **error,
521                                          ...)
522 {
523         GHashTable *attributes;
524         gchar *password;
525         va_list va;
526
527         g_return_val_if_fail (schema != NULL, NULL);
528         g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
529         g_return_val_if_fail (error == NULL || *error == NULL, NULL);
530
531         va_start (va, error);
532         attributes = secret_attributes_buildv (schema, va);
533         va_end (va);
534
535         /* Precondition failed, already warned */
536         if (!attributes)
537                 return NULL;
538
539         password = secret_password_lookupv_nonpageable_sync (schema, attributes,
540                                                              cancellable, error);
541
542         g_hash_table_unref (attributes);
543
544         return password;
545 }
546
547 /**
548  * secret_password_lookupv_nonpageable_sync: (skip)
549  * @schema: the schema for attributes
550  * @attributes: (element-type utf8 utf8): the attribute keys and values
551  * @cancellable: optional cancellation object
552  * @error: location to place an error on failure
553  *
554  * Lookup a password in the secret service.
555  *
556  * The @attributes should be a set of key and value string pairs.
557  *
558  * If no secret is found then %NULL is returned.
559  *
560  * This method may block indefinitely and should not be used in user interface
561  * threads.
562  *
563  * Returns: (transfer full): a new password string stored in non pageable memory
564  *          which should be freed with secret_password_free() when done
565  */
566 gchar *
567 secret_password_lookupv_nonpageable_sync (const SecretSchema *schema,
568                                           GHashTable *attributes,
569                                           GCancellable *cancellable,
570                                           GError **error)
571 {
572         SecretSync *sync;
573         gchar *password;
574
575         g_return_val_if_fail (schema != NULL, NULL);
576         g_return_val_if_fail (attributes != NULL, NULL);
577         g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
578         g_return_val_if_fail (error == NULL || *error == NULL, NULL);
579
580         /* Warnings raised already */
581         if (!_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
582                 return FALSE;
583
584         sync = _secret_sync_new ();
585         g_main_context_push_thread_default (sync->context);
586
587         secret_password_lookupv (schema, attributes, cancellable,
588                                  _secret_sync_on_result, sync);
589
590         g_main_loop_run (sync->loop);
591
592         password = secret_password_lookup_nonpageable_finish (sync->result, error);
593
594         g_main_context_pop_thread_default (sync->context);
595         _secret_sync_free (sync);
596
597         return password;
598 }
599
600 /**
601  * secret_password_lookupv_sync:
602  * @schema: the schema for attributes
603  * @attributes: (element-type utf8 utf8): the attribute keys and values
604  * @cancellable: optional cancellation object
605  * @error: location to place an error on failure
606  *
607  * Lookup a password in the secret service.
608  *
609  * The @attributes should be a set of key and value string pairs.
610  *
611  * If no secret is found then %NULL is returned.
612  *
613  * This method may block indefinitely and should not be used in user interface
614  * threads.
615  *
616  * Returns: (transfer full): a new password string which should be freed with
617  *          secret_password_free() or may be freed with g_free() when done
618  *
619  * Rename to: secret_password_lookup_sync
620  */
621 gchar *
622 secret_password_lookupv_sync (const SecretSchema *schema,
623                               GHashTable *attributes,
624                               GCancellable *cancellable,
625                               GError **error)
626 {
627         SecretSync *sync;
628         gchar *string;
629
630         g_return_val_if_fail (schema != NULL, NULL);
631         g_return_val_if_fail (attributes != NULL, NULL);
632         g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
633         g_return_val_if_fail (error == NULL || *error == NULL, NULL);
634
635         /* Warnings raised already */
636         if (!_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
637                 return FALSE;
638
639         sync = _secret_sync_new ();
640         g_main_context_push_thread_default (sync->context);
641
642         secret_password_lookupv (schema, attributes, cancellable,
643                                  _secret_sync_on_result, sync);
644
645         g_main_loop_run (sync->loop);
646
647         string = secret_password_lookup_finish (sync->result, error);
648
649         g_main_context_pop_thread_default (sync->context);
650         _secret_sync_free (sync);
651
652         return string;
653 }
654
655 /**
656  * secret_password_clear:
657  * @schema: the schema for the attributes
658  * @cancellable: optional cancellation object
659  * @callback: called when the operation completes
660  * @user_data: data to be passed to the callback
661  * @...: the attribute keys and values, terminated with %NULL
662  *
663  * Clear unlocked matching passwords from the secret service.
664  *
665  * The variable argument list should contain pairs of a) The attribute name as
666  * a null-terminated string, followed by b) attribute value, either a character
667  * string, an int number, or a gboolean value, as defined in the password
668  * @schema. The list of attribtues should be terminated with a %NULL.
669  *
670  * All unlocked items that match the attributes will be deleted.
671  *
672  * This method will return immediately and complete asynchronously.
673  */
674 void
675 secret_password_clear (const SecretSchema *schema,
676                        GCancellable *cancellable,
677                        GAsyncReadyCallback callback,
678                        gpointer user_data,
679                        ...)
680 {
681         GHashTable *attributes;
682         va_list va;
683
684         g_return_if_fail (schema != NULL);
685         g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
686
687         va_start (va, user_data);
688         attributes = secret_attributes_buildv (schema, va);
689         va_end (va);
690
691         /* Precondition failed, already warned */
692         if (!attributes)
693                 return;
694
695         secret_password_clearv (schema, attributes, cancellable,
696                                 callback, user_data);
697
698         g_hash_table_unref (attributes);
699 }
700
701
702 /**
703  * secret_password_clearv:
704  * @schema: the schema for the attributes
705  * @attributes: (element-type utf8 utf8): the attribute keys and values
706  * @cancellable: optional cancellation object
707  * @callback: called when the operation completes
708  * @user_data: data to be passed to the callback
709  *
710  * Remove unlocked matching passwords from the secret service.
711  *
712  * The @attributes should be a set of key and value string pairs.
713  *
714  * All unlocked items that match the attributes will be deleted.
715  *
716  * This method will return immediately and complete asynchronously.
717  *
718  * Rename to: secret_password_clear
719  */
720 void
721 secret_password_clearv (const SecretSchema *schema,
722                         GHashTable *attributes,
723                         GCancellable *cancellable,
724                         GAsyncReadyCallback callback,
725                         gpointer user_data)
726 {
727         g_return_if_fail (schema != NULL);
728         g_return_if_fail (attributes != NULL);
729         g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
730
731         /* Warnings raised already */
732         if (!_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
733                 return;
734
735         secret_service_clear (NULL, schema, attributes,
736                               cancellable, callback, user_data);
737 }
738
739 /**
740  * secret_password_clear_finish:
741  * @result: the asynchronous result passed to the callback
742  * @error: location to place an error on failure
743  *
744  * Finish an asynchronous operation to remove passwords from the secret
745  * service.
746  *
747  * Returns: whether any passwords were removed
748  */
749 gboolean
750 secret_password_clear_finish (GAsyncResult *result,
751                               GError **error)
752 {
753         g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
754         return secret_service_clear_finish (NULL, result, error);
755 }
756
757 /**
758  * secret_password_clear_sync:
759  * @schema: the schema for the attributes
760  * @cancellable: optional cancellation object
761  * @error: location to place an error on failure
762  * @...: the attribute keys and values, terminated with %NULL
763  *
764  * Remove unlocked matching passwords from the secret service.
765  *
766  * The variable argument list should contain pairs of a) The attribute name as
767  * a null-terminated string, followed by b) attribute value, either a character
768  * string, an int number, or a gboolean value, as defined in the password
769  * @schema. The list of attribtues should be terminated with a %NULL.
770  *
771  * All unlocked items that match the attributes will be deleted.
772  *
773  * This method may block indefinitely and should not be used in user interface
774  * threads.
775  *
776  * Returns: whether the any passwords were removed
777  */
778 gboolean
779 secret_password_clear_sync (const SecretSchema* schema,
780                             GCancellable *cancellable,
781                             GError **error,
782                             ...)
783 {
784         GHashTable *attributes;
785         gboolean result;
786         va_list va;
787
788         g_return_val_if_fail (schema != NULL, FALSE);
789         g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
790         g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
791
792         va_start (va, error);
793         attributes = secret_attributes_buildv (schema, va);
794         va_end (va);
795
796         /* Precondition failed, already warned */
797         if (!attributes)
798                 return FALSE;
799
800         result = secret_password_clearv_sync (schema, attributes,
801                                               cancellable, error);
802
803         g_hash_table_unref (attributes);
804
805         return result;
806 }
807
808 /**
809  * secret_password_clearv_sync:
810  * @schema: the schema for the attributes
811  * @attributes: (element-type utf8 utf8): the attribute keys and values
812  * @cancellable: optional cancellation object
813  * @error: location to place an error on failure
814  *
815  * Remove unlocked matching passwords from the secret service.
816  *
817  * The @attributes should be a set of key and value string pairs.
818  *
819  * All unlocked items that match the attributes will be deleted.
820  *
821  * This method may block indefinitely and should not be used in user interface
822  * threads.
823  *
824  * Returns: whether any passwords were removed
825  *
826  * Rename to: secret_password_clear_sync
827  */
828 gboolean
829 secret_password_clearv_sync (const SecretSchema *schema,
830                              GHashTable *attributes,
831                              GCancellable *cancellable,
832                              GError **error)
833 {
834         SecretSync *sync;
835         gboolean result;
836
837         g_return_val_if_fail (schema != NULL, FALSE);
838         g_return_val_if_fail (attributes != NULL, FALSE);
839         g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
840         g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
841
842         /* Warnings raised already */
843         if (!_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
844                 return FALSE;
845
846         sync = _secret_sync_new ();
847         g_main_context_push_thread_default (sync->context);
848
849         secret_password_clearv (schema, attributes, cancellable,
850                                 _secret_sync_on_result, sync);
851
852         g_main_loop_run (sync->loop);
853
854         result = secret_password_clear_finish (sync->result, error);
855
856         g_main_context_pop_thread_default (sync->context);
857         _secret_sync_free (sync);
858
859         return result;
860 }
861
862 /**
863  * secret_password_free: (skip)
864  * @password: (allow-none): password to free
865  *
866  * Clear the memory used by a password, and then free it.
867  *
868  * This function must be used to free nonpageable memory returned by
869  * secret_password_lookup_nonpageable_finish(),
870  * secret_password_lookup_nonpageable_sync() or
871  * secret_password_lookupv_nonpageable_sync().
872  */
873 void
874 secret_password_free (gchar *password)
875 {
876         if (password == NULL)
877                 return;
878
879         egg_secure_strfree (password);
880 }
881
882 /**
883  * secret_password_wipe:
884  * @password: (allow-none): password to clear
885  *
886  * Clear the memory used by a password.
887  */
888 void
889 secret_password_wipe (gchar *password)
890 {
891         if (password == NULL)
892                 return;
893
894         egg_secure_strclear (password);
895 }