LCOV - code coverage report
Current view: top level - libsecret - secret-password.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 427 482 88.6 %
Date: 2024-02-08 14:44:34 Functions: 43 45 95.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 179 528 33.9 %

           Branch data     Line data    Source code
       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-retrievable.h"
      21                 :            : #include "secret-backend.h"
      22                 :            : #include "secret-value.h"
      23                 :            : 
      24                 :            : #include <egg/egg-secure-memory.h>
      25                 :            : 
      26                 :            : /**
      27                 :            :  * secret_password_store: (skip)
      28                 :            :  * @schema: the schema for attributes
      29                 :            :  * @collection: (nullable): a collection alias, or D-Bus object path of the
      30                 :            :  *   collection where to store the secret
      31                 :            :  * @label: label for the secret
      32                 :            :  * @password: the null-terminated password to store
      33                 :            :  * @cancellable: (nullable): optional cancellation object
      34                 :            :  * @callback: called when the operation completes
      35                 :            :  * @user_data: data to be passed to the callback
      36                 :            :  * @...: the attribute keys and values, terminated with %NULL
      37                 :            :  *
      38                 :            :  * Store a password in the secret service.
      39                 :            :  *
      40                 :            :  * The variable argument list should contain pairs of a) The attribute name as
      41                 :            :  * a null-terminated string, followed by b) attribute value, either a character
      42                 :            :  * string, an int number, or a gboolean value, as defined in the @schema.
      43                 :            :  * The list of attributes should be terminated with a %NULL.
      44                 :            :  *
      45                 :            :  * If the attributes match a secret item already stored in the collection, then
      46                 :            :  * the item will be updated with these new values.
      47                 :            :  *
      48                 :            :  * If @collection is %NULL, then the default collection will be
      49                 :            :  * used. Use [const@COLLECTION_SESSION] to store the password in the session
      50                 :            :  * collection, which doesn't get stored across login sessions.
      51                 :            :  *
      52                 :            :  * This method will return immediately and complete asynchronously.
      53                 :            :  */
      54                 :            : void
      55                 :          2 : secret_password_store (const SecretSchema *schema,
      56                 :            :                        const gchar *collection,
      57                 :            :                        const gchar *label,
      58                 :            :                        const gchar *password,
      59                 :            :                        GCancellable *cancellable,
      60                 :            :                        GAsyncReadyCallback callback,
      61                 :            :                        gpointer user_data,
      62                 :            :                        ...)
      63                 :            : {
      64                 :            :         GHashTable *attributes;
      65                 :            :         va_list va;
      66                 :            : 
      67         [ -  + ]:          2 :         g_return_if_fail (schema != NULL);
      68         [ -  + ]:          2 :         g_return_if_fail (label != NULL);
      69         [ -  + ]:          2 :         g_return_if_fail (password != NULL);
      70   [ -  +  -  -  :          2 :         g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
          -  -  -  -  -  
                      - ]
      71                 :            : 
      72                 :          2 :         va_start (va, user_data);
      73                 :          2 :         attributes = secret_attributes_buildv (schema, va);
      74                 :          2 :         va_end (va);
      75                 :            : 
      76                 :            :         /* Precondition failed, already warned */
      77         [ -  + ]:          2 :         if (!attributes)
      78                 :          0 :                 return;
      79                 :            : 
      80                 :          2 :         secret_password_storev (schema, attributes, collection, label, password,
      81                 :            :                                 cancellable, callback, user_data);
      82                 :            : 
      83                 :          2 :         g_hash_table_unref (attributes);
      84                 :            : }
      85                 :            : 
      86                 :            : typedef struct {
      87                 :            :         const SecretSchema *schema;
      88                 :            :         GHashTable *attributes;
      89                 :            :         gchar *collection;
      90                 :            :         gchar *label;
      91                 :            :         SecretValue *value;
      92                 :            : } StoreClosure;
      93                 :            : 
      94                 :            : static void
      95                 :         11 : store_closure_free (gpointer data)
      96                 :            : {
      97                 :         11 :         StoreClosure *store = data;
      98                 :         11 :         _secret_schema_unref_if_nonstatic (store->schema);
      99                 :         11 :         g_hash_table_unref (store->attributes);
     100                 :         11 :         g_free (store->collection);
     101                 :         11 :         g_free (store->label);
     102                 :         11 :         secret_value_unref (store->value);
     103                 :         11 :         g_free (store);
     104                 :         11 : }
     105                 :            : 
     106                 :            : static void
     107                 :         11 : on_store (GObject *source,
     108                 :            :           GAsyncResult *result,
     109                 :            :           gpointer user_data)
     110                 :            : {
     111                 :         11 :         GTask *task = G_TASK (user_data);
     112                 :         11 :         SecretBackend *backend = SECRET_BACKEND (source);
     113                 :            :         SecretBackendInterface *iface;
     114                 :         11 :         GError *error = NULL;
     115                 :            : 
     116                 :         11 :         iface = SECRET_BACKEND_GET_IFACE (backend);
     117         [ -  + ]:         11 :         g_return_if_fail (iface->store_finish != NULL);
     118                 :            : 
     119         [ -  + ]:         11 :         if (!iface->store_finish (backend, result, &error)) {
     120                 :          0 :                 g_task_return_error (task, error);
     121                 :          0 :                 g_object_unref (task);
     122                 :          0 :                 return;
     123                 :            :         }
     124                 :            : 
     125                 :         11 :         g_task_return_boolean (task, TRUE);
     126                 :         11 :         g_object_unref (task);
     127                 :            : }
     128                 :            : 
     129                 :            : static void
     130                 :         11 : on_store_backend (GObject *source,
     131                 :            :                   GAsyncResult *result,
     132                 :            :                   gpointer user_data)
     133                 :            : {
     134                 :         11 :         GTask *task = G_TASK (user_data);
     135                 :         11 :         StoreClosure *store = g_task_get_task_data (task);
     136                 :            :         SecretBackend *backend;
     137                 :            :         SecretBackendInterface *iface;
     138                 :         11 :         GError *error = NULL;
     139                 :            : 
     140                 :         11 :         backend = secret_backend_get_finish (result, &error);
     141         [ -  + ]:         11 :         if (backend == NULL) {
     142                 :          0 :                 g_task_return_error (task, error);
     143                 :          0 :                 g_object_unref (task);
     144                 :          0 :                 return;
     145                 :            :         }
     146                 :            : 
     147                 :         11 :         iface = SECRET_BACKEND_GET_IFACE (backend);
     148         [ -  + ]:         11 :         g_return_if_fail (iface->store != NULL);
     149                 :            : 
     150                 :         11 :         iface->store (backend, store->schema, store->attributes,
     151                 :         11 :                       store->collection, store->label, store->value,
     152                 :            :                       g_task_get_cancellable (task),
     153                 :            :                       on_store,
     154                 :            :                       task);
     155                 :            : }
     156                 :            : 
     157                 :            : /**
     158                 :            :  * secret_password_storev: (rename-to secret_password_store)
     159                 :            :  * @schema: (nullable): the schema for attributes
     160                 :            :  * @attributes: (element-type utf8 utf8) (transfer full): the attribute keys and values
     161                 :            :  * @collection: (nullable): a collection alias, or D-Bus object path of the
     162                 :            :  *   collection where to store the secret
     163                 :            :  * @label: label for the secret
     164                 :            :  * @password: the null-terminated password to store
     165                 :            :  * @cancellable: (nullable): optional cancellation object
     166                 :            :  * @callback: (scope async): called when the operation completes
     167                 :            :  * @user_data: data to be passed to the callback
     168                 :            :  *
     169                 :            :  * Store a password in the secret service.
     170                 :            :  *
     171                 :            :  * The @attributes should be a set of key and value string pairs.
     172                 :            :  *
     173                 :            :  * If the attributes match a secret item already stored in the collection, then
     174                 :            :  * the item will be updated with these new values.
     175                 :            :  *
     176                 :            :  * If @collection is %NULL, then the default collection will be
     177                 :            :  * used. Use [const@COLLECTION_SESSION] to store the password in the session
     178                 :            :  * collection, which doesn't get stored across login sessions.
     179                 :            :  *
     180                 :            :  * This method will return immediately and complete asynchronously.
     181                 :            :  */
     182                 :            : void
     183                 :          5 : secret_password_storev (const SecretSchema *schema,
     184                 :            :                         GHashTable *attributes,
     185                 :            :                         const gchar *collection,
     186                 :            :                         const gchar *label,
     187                 :            :                         const gchar *password,
     188                 :            :                         GCancellable *cancellable,
     189                 :            :                         GAsyncReadyCallback callback,
     190                 :            :                         gpointer user_data)
     191                 :            : {
     192                 :            :         StoreClosure *store;
     193                 :            :         GTask *task;
     194                 :            : 
     195         [ -  + ]:          5 :         g_return_if_fail (label != NULL);
     196         [ -  + ]:          5 :         g_return_if_fail (password != NULL);
     197         [ -  + ]:          5 :         g_return_if_fail (attributes != NULL);
     198   [ -  +  -  -  :          5 :         g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
          -  -  -  -  -  
                      - ]
     199                 :            : 
     200                 :            :         /* Warnings raised already */
     201   [ +  -  -  + ]:          5 :         if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, FALSE))
     202                 :          0 :                 return;
     203                 :            : 
     204                 :          5 :         task = g_task_new (NULL, cancellable, callback, user_data);
     205                 :          5 :         store = g_new0 (StoreClosure, 1);
     206                 :          5 :         store->schema = _secret_schema_ref_if_nonstatic (schema);
     207                 :          5 :         store->attributes = g_hash_table_ref (attributes);
     208                 :          5 :         store->collection = g_strdup (collection);
     209                 :          5 :         store->label = g_strdup (label);
     210                 :          5 :         store->value = secret_value_new (password, -1, "text/plain");
     211                 :          5 :         g_task_set_task_data (task, store, store_closure_free);
     212                 :            : 
     213                 :          5 :         secret_backend_get (SECRET_BACKEND_OPEN_SESSION,
     214                 :            :                             cancellable,
     215                 :            :                             on_store_backend, task);
     216                 :            : }
     217                 :            : 
     218                 :            : /**
     219                 :            :  * secret_password_store_binary: (skip)
     220                 :            :  * @schema: the schema for attributes
     221                 :            :  * @collection: (nullable): a collection alias, or D-Bus object path of the
     222                 :            :  *    collection where to store the secret
     223                 :            :  * @label: label for the secret
     224                 :            :  * @value: a [struct@Value]
     225                 :            :  * @cancellable: (nullable): optional cancellation object
     226                 :            :  * @callback: called when the operation completes
     227                 :            :  * @user_data: data to be passed to the callback
     228                 :            :  * @...: the attribute keys and values, terminated with %NULL
     229                 :            :  *
     230                 :            :  * Store a password in the secret service.
     231                 :            :  *
     232                 :            :  * This is similar to [func@password_store], but takes a
     233                 :            :  * [struct@Value] as the argument instead of a null-terminated password.
     234                 :            :  *
     235                 :            :  * This method will return immediately and complete asynchronously.
     236                 :            :  *
     237                 :            :  * Since: 0.19.0
     238                 :            :  */
     239                 :            : void
     240                 :          1 : secret_password_store_binary (const SecretSchema *schema,
     241                 :            :                               const gchar *collection,
     242                 :            :                               const gchar *label,
     243                 :            :                               SecretValue *value,
     244                 :            :                               GCancellable *cancellable,
     245                 :            :                               GAsyncReadyCallback callback,
     246                 :            :                               gpointer user_data,
     247                 :            :                               ...)
     248                 :            : {
     249                 :            :         GHashTable *attributes;
     250                 :            :         va_list va;
     251                 :            : 
     252         [ -  + ]:          1 :         g_return_if_fail (schema != NULL);
     253         [ -  + ]:          1 :         g_return_if_fail (label != NULL);
     254         [ -  + ]:          1 :         g_return_if_fail (value != NULL);
     255   [ -  +  -  -  :          1 :         g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
          -  -  -  -  -  
                      - ]
     256                 :            : 
     257                 :          1 :         va_start (va, user_data);
     258                 :          1 :         attributes = secret_attributes_buildv (schema, va);
     259                 :          1 :         va_end (va);
     260                 :            : 
     261                 :            :         /* Precondition failed, already warned */
     262         [ -  + ]:          1 :         if (!attributes)
     263                 :          0 :                 return;
     264                 :            : 
     265                 :          1 :         secret_password_storev_binary (schema, attributes, collection, label, value,
     266                 :            :                                        cancellable, callback, user_data);
     267                 :            : 
     268                 :          1 :         g_hash_table_unref (attributes);
     269                 :            : }
     270                 :            : 
     271                 :            : /**
     272                 :            :  * secret_password_storev_binary: (rename-to secret_password_store_binary)
     273                 :            :  * @schema: (nullable): the schema for attributes
     274                 :            :  * @attributes: (element-type utf8 utf8) (transfer full): the attribute keys and values
     275                 :            :  * @collection: (nullable): a collection alias, or D-Bus object path of the
     276                 :            :  *   collection where to store the secret
     277                 :            :  * @label: label for the secret
     278                 :            :  * @value: a [struct@Value]
     279                 :            :  * @cancellable: (nullable): optional cancellation object
     280                 :            :  * @callback: (scope async): called when the operation completes
     281                 :            :  * @user_data: data to be passed to the callback
     282                 :            :  *
     283                 :            :  * Store a password in the secret service.
     284                 :            :  *
     285                 :            :  * This is similar to [func@password_storev], but takes a
     286                 :            :  * [struct@Value] as the argument instead of a null-terminated password.
     287                 :            :  *
     288                 :            :  * This method will return immediately and complete asynchronously.
     289                 :            :  *
     290                 :            :  * Since: 0.19.0
     291                 :            :  */
     292                 :            : void
     293                 :          6 : secret_password_storev_binary (const SecretSchema *schema,
     294                 :            :                                GHashTable *attributes,
     295                 :            :                                const gchar *collection,
     296                 :            :                                const gchar *label,
     297                 :            :                                SecretValue *value,
     298                 :            :                                GCancellable *cancellable,
     299                 :            :                                GAsyncReadyCallback callback,
     300                 :            :                                gpointer user_data)
     301                 :            : {
     302                 :            :         StoreClosure *store;
     303                 :            :         GTask *task;
     304                 :            : 
     305         [ -  + ]:          6 :         g_return_if_fail (label != NULL);
     306         [ -  + ]:          6 :         g_return_if_fail (value != NULL);
     307         [ -  + ]:          6 :         g_return_if_fail (attributes != NULL);
     308   [ -  +  -  -  :          6 :         g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
          -  -  -  -  -  
                      - ]
     309                 :            : 
     310                 :            :         /* Warnings raised already */
     311   [ +  +  -  + ]:          6 :         if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, FALSE))
     312                 :          0 :                 return;
     313                 :            : 
     314                 :          6 :         task = g_task_new (NULL, cancellable, callback, user_data);
     315                 :          6 :         store = g_new0 (StoreClosure, 1);
     316                 :          6 :         store->schema = _secret_schema_ref_if_nonstatic (schema);
     317                 :          6 :         store->attributes = g_hash_table_ref (attributes);
     318                 :          6 :         store->collection = g_strdup (collection);
     319                 :          6 :         store->label = g_strdup (label);
     320                 :          6 :         store->value = secret_value_ref (value);
     321                 :          6 :         g_task_set_task_data (task, store, store_closure_free);
     322                 :            : 
     323                 :          6 :         secret_backend_get (SECRET_BACKEND_OPEN_SESSION,
     324                 :            :                             cancellable,
     325                 :            :                             on_store_backend, task);
     326                 :            : }
     327                 :            : 
     328                 :            : /**
     329                 :            :  * secret_password_store_finish:
     330                 :            :  * @result: the asynchronous result passed to the callback
     331                 :            :  * @error: location to place an error on failure
     332                 :            :  *
     333                 :            :  * Finish asynchronous operation to store a password in the secret service.
     334                 :            :  *
     335                 :            :  * Returns: whether the storage was successful or not
     336                 :            :  */
     337                 :            : gboolean
     338                 :         11 : secret_password_store_finish (GAsyncResult *result,
     339                 :            :                               GError **error)
     340                 :            : {
     341   [ +  -  -  + ]:         11 :         g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
     342         [ -  + ]:         11 :         g_return_val_if_fail (g_task_is_valid (result, NULL), FALSE);
     343                 :            : 
     344                 :         11 :         return g_task_propagate_boolean (G_TASK (result), error);
     345                 :            : }
     346                 :            : 
     347                 :            : /**
     348                 :            :  * secret_password_store_sync:
     349                 :            :  * @schema: the schema for attributes
     350                 :            :  * @collection: (nullable): a collection alias, or D-Bus object path of the
     351                 :            :  *   collection where to store the secret
     352                 :            :  * @label: label for the secret
     353                 :            :  * @password: the null-terminated password to store
     354                 :            :  * @cancellable: (nullable): optional cancellation object
     355                 :            :  * @error: location to place an error on failure
     356                 :            :  * @...: the attribute keys and values, terminated with %NULL
     357                 :            :  *
     358                 :            :  * Store a password in the secret service.
     359                 :            :  *
     360                 :            :  * The variable argument list should contain pairs of a) The attribute name as
     361                 :            :  * a null-terminated string, followed by b) attribute value, either a character
     362                 :            :  * string, an int number, or a gboolean value, as defined in the @schema.
     363                 :            :  * The list of attributes should be terminated with a %NULL.
     364                 :            :  *
     365                 :            :  * If the attributes match a secret item already stored in the collection, then
     366                 :            :  * the item will be updated with these new values.
     367                 :            :  *
     368                 :            :  * If @collection is %NULL, then the default collection will be
     369                 :            :  * used. Use [const@COLLECTION_SESSION] to store the password in the session
     370                 :            :  * collection, which doesn't get stored across login sessions.
     371                 :            :  *
     372                 :            :  * This method may block indefinitely and should not be used in user interface
     373                 :            :  * threads.
     374                 :            :  *
     375                 :            :  * Returns: whether the storage was successful or not
     376                 :            :  */
     377                 :            : gboolean
     378                 :          1 : secret_password_store_sync (const SecretSchema *schema,
     379                 :            :                             const gchar *collection,
     380                 :            :                             const gchar *label,
     381                 :            :                             const gchar *password,
     382                 :            :                             GCancellable *cancellable,
     383                 :            :                             GError **error,
     384                 :            :                             ...)
     385                 :            : {
     386                 :            :         GHashTable *attributes;
     387                 :            :         va_list va;
     388                 :            :         gboolean ret;
     389                 :            : 
     390         [ -  + ]:          1 :         g_return_val_if_fail (schema != NULL, FALSE);
     391         [ -  + ]:          1 :         g_return_val_if_fail (label != NULL, FALSE);
     392         [ -  + ]:          1 :         g_return_val_if_fail (password != NULL, FALSE);
     393   [ -  +  -  -  :          1 :         g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
          -  -  -  -  -  
                      - ]
     394   [ +  -  -  + ]:          1 :         g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
     395                 :            : 
     396                 :          1 :         va_start (va, error);
     397                 :          1 :         attributes = secret_attributes_buildv (schema, va);
     398                 :          1 :         va_end (va);
     399                 :            : 
     400                 :            :         /* Precondition failed, already warned */
     401         [ -  + ]:          1 :         if (!attributes)
     402                 :          0 :                 return FALSE;
     403                 :            : 
     404                 :          1 :         ret = secret_password_storev_sync (schema, attributes, collection,
     405                 :            :                                            label, password, cancellable, error);
     406                 :            : 
     407                 :          1 :         g_hash_table_unref (attributes);
     408                 :          1 :         return ret;
     409                 :            : }
     410                 :            : 
     411                 :            : /**
     412                 :            :  * secret_password_storev_sync: (rename-to secret_password_store_sync)
     413                 :            :  * @schema: (nullable): the schema for attributes
     414                 :            :  * @attributes: (element-type utf8 utf8): the attribute keys and values
     415                 :            :  * @collection: (nullable): a collection alias, or D-Bus object path of the
     416                 :            :  *   collection where to store the secret
     417                 :            :  * @label: label for the secret
     418                 :            :  * @password: the null-terminated password to store
     419                 :            :  * @cancellable: (nullable): optional cancellation object
     420                 :            :  * @error: location to place an error on failure
     421                 :            :  *
     422                 :            :  * Store a password in the secret service.
     423                 :            :  *
     424                 :            :  * The @attributes should be a set of key and value string pairs.
     425                 :            :  *
     426                 :            :  * If the attributes match a secret item already stored in the collection, then
     427                 :            :  * the item will be updated with these new values.
     428                 :            :  *
     429                 :            :  * If @collection is %NULL, then the default collection will be
     430                 :            :  * used. Use [const@COLLECTION_SESSION] to store the password in the session
     431                 :            :  * collection, which doesn't get stored across login sessions.
     432                 :            :  *
     433                 :            :  * This method may block indefinitely and should not be used in user interface
     434                 :            :  * threads.
     435                 :            :  *
     436                 :            :  * Returns: whether the storage was successful or not
     437                 :            :  */
     438                 :            : gboolean
     439                 :          2 : secret_password_storev_sync (const SecretSchema *schema,
     440                 :            :                              GHashTable *attributes,
     441                 :            :                              const gchar *collection,
     442                 :            :                              const gchar *label,
     443                 :            :                              const gchar *password,
     444                 :            :                              GCancellable *cancellable,
     445                 :            :                              GError **error)
     446                 :            : {
     447                 :            :         SecretSync *sync;
     448                 :            :         gboolean ret;
     449                 :            : 
     450         [ -  + ]:          2 :         g_return_val_if_fail (label != NULL, FALSE);
     451         [ -  + ]:          2 :         g_return_val_if_fail (password != NULL, FALSE);
     452         [ -  + ]:          2 :         g_return_val_if_fail (attributes != NULL, FALSE);
     453   [ -  +  -  -  :          2 :         g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
          -  -  -  -  -  
                      - ]
     454   [ +  -  -  + ]:          2 :         g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
     455                 :            : 
     456                 :            :         /* Warnings raised already */
     457   [ +  -  -  + ]:          2 :         if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, FALSE))
     458                 :          0 :                 return FALSE;
     459                 :            : 
     460                 :          2 :         sync = _secret_sync_new ();
     461                 :          2 :         g_main_context_push_thread_default (sync->context);
     462                 :            : 
     463                 :          2 :         secret_password_storev (schema, attributes, collection, label, password,
     464                 :            :                                 cancellable, _secret_sync_on_result, sync);
     465                 :            : 
     466                 :          2 :         g_main_loop_run (sync->loop);
     467                 :            : 
     468                 :          2 :         ret = secret_password_store_finish (sync->result, error);
     469                 :            : 
     470                 :          2 :         g_main_context_pop_thread_default (sync->context);
     471                 :          2 :         _secret_sync_free (sync);
     472                 :            : 
     473                 :          2 :         return ret;
     474                 :            : }
     475                 :            : 
     476                 :            : /**
     477                 :            :  * secret_password_store_binary_sync:
     478                 :            :  * @schema: the schema for attributes
     479                 :            :  * @collection: (nullable): a collection alias, or D-Bus object path of the
     480                 :            :  *   collection where to store the secret
     481                 :            :  * @label: label for the secret
     482                 :            :  * @value: a [struct@Value]
     483                 :            :  * @cancellable: (nullable): optional cancellation object
     484                 :            :  * @error: location to place an error on failure
     485                 :            :  * @...: the attribute keys and values, terminated with %NULL
     486                 :            :  *
     487                 :            :  * Store a password in the secret service.
     488                 :            :  *
     489                 :            :  * This is similar to [func@password_store_sync], but takes a
     490                 :            :  * [struct@Value] as the argument instead of a null terminated password.
     491                 :            :  *
     492                 :            :  * This method may block indefinitely and should not be used in user interface
     493                 :            :  * threads.
     494                 :            :  *
     495                 :            :  * Returns: whether the storage was successful or not
     496                 :            :  *
     497                 :            :  * Since: 0.19.0
     498                 :            :  */
     499                 :            : gboolean
     500                 :          1 : secret_password_store_binary_sync (const SecretSchema *schema,
     501                 :            :                                    const gchar *collection,
     502                 :            :                                    const gchar *label,
     503                 :            :                                    SecretValue *value,
     504                 :            :                                    GCancellable *cancellable,
     505                 :            :                                    GError **error,
     506                 :            :                                    ...)
     507                 :            : {
     508                 :            :         GHashTable *attributes;
     509                 :            :         va_list va;
     510                 :            :         gboolean ret;
     511                 :            : 
     512         [ -  + ]:          1 :         g_return_val_if_fail (schema != NULL, FALSE);
     513         [ -  + ]:          1 :         g_return_val_if_fail (label != NULL, FALSE);
     514         [ -  + ]:          1 :         g_return_val_if_fail (value != NULL, FALSE);
     515   [ -  +  -  -  :          1 :         g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
          -  -  -  -  -  
                      - ]
     516   [ +  -  -  + ]:          1 :         g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
     517                 :            : 
     518                 :          1 :         va_start (va, error);
     519                 :          1 :         attributes = secret_attributes_buildv (schema, va);
     520                 :          1 :         va_end (va);
     521                 :            : 
     522                 :            :         /* Precondition failed, already warned */
     523         [ -  + ]:          1 :         if (!attributes)
     524                 :          0 :                 return FALSE;
     525                 :            : 
     526                 :          1 :         ret = secret_password_storev_binary_sync (schema, attributes, collection,
     527                 :            :                                                   label, value, cancellable, error);
     528                 :            : 
     529                 :          1 :         g_hash_table_unref (attributes);
     530                 :          1 :         return ret;
     531                 :            : }
     532                 :            : 
     533                 :            : /**
     534                 :            :  * secret_password_storev_binary_sync: (rename-to secret_password_store_binary_sync)
     535                 :            :  * @schema: (nullable): the schema for attributes
     536                 :            :  * @attributes: (element-type utf8 utf8): the attribute keys and values
     537                 :            :  * @collection: (nullable): a collection alias, or D-Bus object path of the
     538                 :            :  *   collection where to store the secret
     539                 :            :  * @label: label for the secret
     540                 :            :  * @value: a [struct@Value]
     541                 :            :  * @cancellable: (nullable): optional cancellation object
     542                 :            :  * @error: location to place an error on failure
     543                 :            :  *
     544                 :            :  * Store a password in the secret service.
     545                 :            :  *
     546                 :            :  * This is similar to [func@password_storev_sync], but takes a [struct@Value] as
     547                 :            :  * the argument instead of a null-terminated passwords.
     548                 :            :  *
     549                 :            :  * This method may block indefinitely and should not be used in user interface
     550                 :            :  * threads.
     551                 :            :  *
     552                 :            :  * Returns: whether the storage was successful or not
     553                 :            :  *
     554                 :            :  * Since: 0.19.0
     555                 :            :  */
     556                 :            : gboolean
     557                 :          5 : secret_password_storev_binary_sync (const SecretSchema *schema,
     558                 :            :                                     GHashTable *attributes,
     559                 :            :                                     const gchar *collection,
     560                 :            :                                     const gchar *label,
     561                 :            :                                     SecretValue *value,
     562                 :            :                                     GCancellable *cancellable,
     563                 :            :                                     GError **error)
     564                 :            : {
     565                 :            :         SecretSync *sync;
     566                 :            :         gboolean ret;
     567                 :            : 
     568         [ -  + ]:          5 :         g_return_val_if_fail (label != NULL, FALSE);
     569         [ -  + ]:          5 :         g_return_val_if_fail (value != NULL, FALSE);
     570         [ -  + ]:          5 :         g_return_val_if_fail (attributes != NULL, FALSE);
     571   [ -  +  -  -  :          5 :         g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
          -  -  -  -  -  
                      - ]
     572   [ +  -  -  + ]:          5 :         g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
     573                 :            : 
     574                 :            :         /* Warnings raised already */
     575   [ +  +  -  + ]:          5 :         if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, FALSE))
     576                 :          0 :                 return FALSE;
     577                 :            : 
     578                 :          5 :         sync = _secret_sync_new ();
     579                 :          5 :         g_main_context_push_thread_default (sync->context);
     580                 :            : 
     581                 :          5 :         secret_password_storev_binary (schema, attributes, collection, label, value,
     582                 :            :                                        cancellable, _secret_sync_on_result, sync);
     583                 :            : 
     584                 :          5 :         g_main_loop_run (sync->loop);
     585                 :            : 
     586                 :          5 :         ret = secret_password_store_finish (sync->result, error);
     587                 :            : 
     588                 :          5 :         g_main_context_pop_thread_default (sync->context);
     589                 :          5 :         _secret_sync_free (sync);
     590                 :            : 
     591                 :          5 :         return ret;
     592                 :            : }
     593                 :            : 
     594                 :            : /**
     595                 :            :  * secret_password_lookup: (skip)
     596                 :            :  * @schema: the schema for the attributes
     597                 :            :  * @cancellable: (nullable): optional cancellation object
     598                 :            :  * @callback: called when the operation completes
     599                 :            :  * @user_data: data to be passed to the callback
     600                 :            :  * @...: the attribute keys and values, terminated with %NULL
     601                 :            :  *
     602                 :            :  * Lookup a password in the secret service.
     603                 :            :  *
     604                 :            :  * The variable argument list should contain pairs of a) The attribute name as
     605                 :            :  * a null-terminated string, followed by b) attribute value, either a character
     606                 :            :  * string, an int number, or a gboolean value, as defined in the password
     607                 :            :  * @schema. The list of attributes should be terminated with a %NULL.
     608                 :            :  *
     609                 :            :  * If no secret is found then %NULL is returned.
     610                 :            :  *
     611                 :            :  * This method will return immediately and complete asynchronously.
     612                 :            :  */
     613                 :            : void
     614                 :          1 : secret_password_lookup (const SecretSchema *schema,
     615                 :            :                         GCancellable *cancellable,
     616                 :            :                         GAsyncReadyCallback callback,
     617                 :            :                         gpointer user_data,
     618                 :            :                         ...)
     619                 :            : {
     620                 :            :         GHashTable *attributes;
     621                 :            :         va_list va;
     622                 :            : 
     623         [ -  + ]:          1 :         g_return_if_fail (schema != NULL);
     624   [ -  +  -  -  :          1 :         g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
          -  -  -  -  -  
                      - ]
     625                 :            : 
     626                 :          1 :         va_start (va, user_data);
     627                 :          1 :         attributes = secret_attributes_buildv (schema, va);
     628                 :          1 :         va_end (va);
     629                 :            : 
     630                 :            :         /* Precondition failed, already warned */
     631         [ -  + ]:          1 :         if (!attributes)
     632                 :          0 :                 return;
     633                 :            : 
     634                 :          1 :         secret_password_lookupv (schema, attributes, cancellable,
     635                 :            :                                  callback, user_data);
     636                 :            : 
     637                 :          1 :         g_hash_table_unref (attributes);
     638                 :            : }
     639                 :            : 
     640                 :            : typedef struct {
     641                 :            :         const SecretSchema *schema;
     642                 :            :         GHashTable *attributes;
     643                 :            : } LookupClosure;
     644                 :            : 
     645                 :            : static void
     646                 :         21 : lookup_closure_free (gpointer data)
     647                 :            : {
     648                 :         21 :         LookupClosure *closure = data;
     649                 :         21 :         _secret_schema_unref_if_nonstatic (closure->schema);
     650                 :         21 :         g_hash_table_unref (closure->attributes);
     651                 :         21 :         g_free (closure);
     652                 :         21 : }
     653                 :            : 
     654                 :            : static void
     655                 :         21 : on_lookup (GObject *source,
     656                 :            :            GAsyncResult *result,
     657                 :            :            gpointer user_data)
     658                 :            : {
     659                 :         21 :         GTask *task = G_TASK (user_data);
     660                 :         21 :         SecretBackend *backend = SECRET_BACKEND (source);
     661                 :            :         SecretBackendInterface *iface;
     662                 :            :         SecretValue *value;
     663                 :         21 :         GError *error = NULL;
     664                 :            : 
     665                 :         21 :         iface = SECRET_BACKEND_GET_IFACE (backend);
     666         [ -  + ]:         21 :         g_return_if_fail (iface->store_finish != NULL);
     667                 :            : 
     668                 :         21 :         value = iface->lookup_finish (backend, result, &error);
     669         [ -  + ]:         21 :         if (error) {
     670                 :          0 :                 g_task_return_error (task, error);
     671                 :          0 :                 g_object_unref (task);
     672                 :          0 :                 return;
     673                 :            :         }
     674                 :            : 
     675         [ +  + ]:         21 :         if (value)
     676                 :         15 :                 g_task_return_pointer (task, value, secret_value_unref);
     677                 :            :         else
     678                 :          6 :                 g_task_return_pointer (task, NULL, NULL);
     679                 :         21 :         g_object_unref (task);
     680                 :            : }
     681                 :            : 
     682                 :            : static void
     683                 :         21 : on_lookup_backend (GObject *source,
     684                 :            :                    GAsyncResult *result,
     685                 :            :                    gpointer user_data)
     686                 :            : {
     687                 :         21 :         GTask *task = G_TASK (user_data);
     688                 :         21 :         LookupClosure *lookup = g_task_get_task_data (task);
     689                 :            :         SecretBackend *backend;
     690                 :            :         SecretBackendInterface *iface;
     691                 :         21 :         GError *error = NULL;
     692                 :            : 
     693                 :         21 :         backend = secret_backend_get_finish (result, &error);
     694         [ -  + ]:         21 :         if (backend == NULL) {
     695                 :          0 :                 g_task_return_error (task, error);
     696                 :          0 :                 g_object_unref (task);
     697                 :          0 :                 return;
     698                 :            :         }
     699                 :            : 
     700                 :         21 :         iface = SECRET_BACKEND_GET_IFACE (backend);
     701         [ -  + ]:         21 :         g_return_if_fail (iface->store != NULL);
     702                 :            : 
     703                 :         21 :         iface->lookup (backend, lookup->schema, lookup->attributes,
     704                 :            :                        g_task_get_cancellable (task),
     705                 :            :                        on_lookup,
     706                 :            :                        task);
     707                 :            : }
     708                 :            : 
     709                 :            : /**
     710                 :            :  * secret_password_lookupv: (rename-to secret_password_lookup)
     711                 :            :  * @schema: (nullable): the schema for attributes
     712                 :            :  * @attributes: (element-type utf8 utf8) (transfer full): the attribute keys and values
     713                 :            :  * @cancellable: (nullable): optional cancellation object
     714                 :            :  * @callback: (scope async): called when the operation completes
     715                 :            :  * @user_data: data to be passed to the callback
     716                 :            :  *
     717                 :            :  * Lookup a password in the secret service.
     718                 :            :  *
     719                 :            :  * The @attributes should be a set of key and value string pairs.
     720                 :            :  *
     721                 :            :  * If no secret is found then %NULL is returned.
     722                 :            :  *
     723                 :            :  * This method will return immediately and complete asynchronously.
     724                 :            :  */
     725                 :            : void
     726                 :         21 : secret_password_lookupv (const SecretSchema *schema,
     727                 :            :                          GHashTable *attributes,
     728                 :            :                          GCancellable *cancellable,
     729                 :            :                          GAsyncReadyCallback callback,
     730                 :            :                          gpointer user_data)
     731                 :            : {
     732                 :            :         LookupClosure *lookup;
     733                 :            :         GTask *task;
     734                 :            : 
     735         [ -  + ]:         21 :         g_return_if_fail (attributes != NULL);
     736   [ -  +  -  -  :         21 :         g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
          -  -  -  -  -  
                      - ]
     737                 :            : 
     738                 :            :         /* Warnings raised already */
     739   [ +  +  -  + ]:         21 :         if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
     740                 :          0 :                 return;
     741                 :            : 
     742                 :         21 :         task = g_task_new (NULL, cancellable, callback, user_data);
     743                 :         21 :         lookup = g_new0 (LookupClosure, 1);
     744                 :         21 :         lookup->schema = _secret_schema_ref_if_nonstatic (schema);
     745                 :         21 :         lookup->attributes = g_hash_table_ref (attributes);
     746                 :         21 :         g_task_set_task_data (task, lookup, lookup_closure_free);
     747                 :            : 
     748                 :         21 :         secret_backend_get (SECRET_BACKEND_OPEN_SESSION,
     749                 :            :                             cancellable,
     750                 :            :                             on_lookup_backend, task);
     751                 :            : }
     752                 :            : 
     753                 :            : /**
     754                 :            :  * secret_password_lookup_nonpageable_finish: (skip)
     755                 :            :  * @result: the asynchronous result passed to the callback
     756                 :            :  * @error: location to place an error on failure
     757                 :            :  *
     758                 :            :  * Finish an asynchronous operation to lookup a password in the secret service.
     759                 :            :  *
     760                 :            :  * Returns: (transfer full): a new password string stored in nonpageable memory
     761                 :            :  *   which must be freed with [func@password_free] when done
     762                 :            :  */
     763                 :            : gchar *
     764                 :          5 : secret_password_lookup_nonpageable_finish (GAsyncResult *result,
     765                 :            :                                            GError **error)
     766                 :            : {
     767                 :            :         SecretValue *value;
     768                 :            : 
     769   [ +  -  -  + ]:          5 :         g_return_val_if_fail (error == NULL || *error == NULL, NULL);
     770         [ -  + ]:          5 :         g_return_val_if_fail (g_task_is_valid (result, NULL), NULL);
     771                 :            : 
     772                 :          5 :         value = g_task_propagate_pointer (G_TASK (result), error);
     773         [ -  + ]:          5 :         if (value == NULL)
     774                 :          0 :                 return NULL;
     775                 :            : 
     776                 :          5 :         return _secret_value_unref_to_password (value);
     777                 :            : }
     778                 :            : 
     779                 :            : /**
     780                 :            :  * secret_password_lookup_binary_finish: (skip)
     781                 :            :  * @result: the asynchronous result passed to the callback
     782                 :            :  * @error: location to place an error on failure
     783                 :            :  *
     784                 :            :  * Finish an asynchronous operation to lookup a password in the secret service.
     785                 :            :  *
     786                 :            :  * Returns: (transfer full): a newly allocated [struct@Value], which should be
     787                 :            :  *   released with [method@Value.unref], or %NULL if no secret found
     788                 :            :  *
     789                 :            :  * Since: 0.19.0
     790                 :            :  */
     791                 :            : SecretValue *
     792                 :          4 : secret_password_lookup_binary_finish (GAsyncResult *result,
     793                 :            :                                       GError **error)
     794                 :            : {
     795   [ +  -  -  + ]:          4 :         g_return_val_if_fail (error == NULL || *error == NULL, NULL);
     796         [ -  + ]:          4 :         g_return_val_if_fail (g_task_is_valid (result, NULL), NULL);
     797                 :            : 
     798                 :          4 :         return g_task_propagate_pointer (G_TASK (result), error);
     799                 :            : }
     800                 :            : 
     801                 :            : /**
     802                 :            :  * secret_password_lookup_finish:
     803                 :            :  * @result: the asynchronous result passed to the callback
     804                 :            :  * @error: location to place an error on failure
     805                 :            :  *
     806                 :            :  * Finish an asynchronous operation to lookup a password in the secret service.
     807                 :            :  *
     808                 :            :  * Returns: (transfer full): a new password string which should be freed with
     809                 :            :  *   [func@password_free] or may be freed with [func@GLib.free] when done
     810                 :            :  */
     811                 :            : gchar *
     812                 :         12 : secret_password_lookup_finish (GAsyncResult *result,
     813                 :            :                                GError **error)
     814                 :            : {
     815                 :            :         SecretValue *value;
     816                 :            : 
     817   [ +  -  -  + ]:         12 :         g_return_val_if_fail (error == NULL || *error == NULL, NULL);
     818         [ -  + ]:         12 :         g_return_val_if_fail (g_task_is_valid (result, NULL), NULL);
     819                 :            : 
     820                 :         12 :         value = g_task_propagate_pointer (G_TASK (result), error);
     821         [ +  + ]:         12 :         if (value == NULL)
     822                 :          6 :                 return NULL;
     823                 :            : 
     824                 :          6 :         return _secret_value_unref_to_string (value);
     825                 :            : }
     826                 :            : 
     827                 :            : /**
     828                 :            :  * secret_password_lookup_sync: (skip)
     829                 :            :  * @schema: the schema for the attributes
     830                 :            :  * @cancellable: (nullable): optional cancellation object
     831                 :            :  * @error: location to place an error on failure
     832                 :            :  * @...: the attribute keys and values, terminated with %NULL
     833                 :            :  *
     834                 :            :  * Lookup a password in the secret service.
     835                 :            :  *
     836                 :            :  * The variable argument list should contain pairs of a) The attribute name as
     837                 :            :  * a null-terminated string, followed by b) attribute value, either a character
     838                 :            :  * string, an int number, or a gboolean value, as defined in the password
     839                 :            :  * @schema. The list of attributes should be terminated with a %NULL.
     840                 :            :  *
     841                 :            :  * If no secret is found then %NULL is returned.
     842                 :            :  *
     843                 :            :  * This method may block indefinitely and should not be used in user interface
     844                 :            :  * threads.
     845                 :            :  *
     846                 :            :  * Returns: (transfer full): a new password string which should be freed with
     847                 :            :  *   [func@password_free] or may be freed with [func@GLib.free] when done
     848                 :            :  */
     849                 :            : gchar *
     850                 :          2 : secret_password_lookup_sync (const SecretSchema *schema,
     851                 :            :                              GCancellable *cancellable,
     852                 :            :                              GError **error,
     853                 :            :                              ...)
     854                 :            : {
     855                 :            :         GHashTable *attributes;
     856                 :            :         gchar *password;
     857                 :            :         va_list va;
     858                 :            : 
     859         [ -  + ]:          2 :         g_return_val_if_fail (schema != NULL, NULL);
     860   [ -  +  -  -  :          2 :         g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
          -  -  -  -  -  
                      - ]
     861   [ +  -  -  + ]:          2 :         g_return_val_if_fail (error == NULL || *error == NULL, NULL);
     862                 :            : 
     863                 :          2 :         va_start (va, error);
     864                 :          2 :         attributes = secret_attributes_buildv (schema, va);
     865                 :          2 :         va_end (va);
     866                 :            : 
     867                 :            :         /* Precondition failed, already warned */
     868         [ -  + ]:          2 :         if (!attributes)
     869                 :          0 :                 return NULL;
     870                 :            : 
     871                 :          2 :         password = secret_password_lookupv_sync (schema, attributes,
     872                 :            :                                                  cancellable, error);
     873                 :            : 
     874                 :          2 :         g_hash_table_unref (attributes);
     875                 :            : 
     876                 :          2 :         return password;
     877                 :            : }
     878                 :            : 
     879                 :            : /**
     880                 :            :  * secret_password_lookup_nonpageable_sync: (skip)
     881                 :            :  * @schema: the schema for the attributes
     882                 :            :  * @cancellable: (nullable): optional cancellation object
     883                 :            :  * @error: location to place an error on failure
     884                 :            :  * @...: the attribute keys and values, terminated with %NULL
     885                 :            :  *
     886                 :            :  * Lookup a password in the secret service.
     887                 :            :  *
     888                 :            :  * The variable argument list should contain pairs of a) The attribute name as
     889                 :            :  * a null-terminated string, followed by b) attribute value, either a character
     890                 :            :  * string, an int number, or a gboolean value, as defined in the password
     891                 :            :  * @schema. The list of attributes should be terminated with a %NULL.
     892                 :            :  *
     893                 :            :  * If no secret is found then %NULL is returned.
     894                 :            :  *
     895                 :            :  * This method may block indefinitely and should not be used in user interface
     896                 :            :  * threads.
     897                 :            :  *
     898                 :            :  * Returns: (transfer full): a new password string stored in nonpageable memory
     899                 :            :  *   which must be freed with [func@password_free] when done
     900                 :            :  */
     901                 :            : gchar *
     902                 :          4 : secret_password_lookup_nonpageable_sync (const SecretSchema *schema,
     903                 :            :                                          GCancellable *cancellable,
     904                 :            :                                          GError **error,
     905                 :            :                                          ...)
     906                 :            : {
     907                 :            :         GHashTable *attributes;
     908                 :            :         gchar *password;
     909                 :            :         va_list va;
     910                 :            : 
     911         [ -  + ]:          4 :         g_return_val_if_fail (schema != NULL, NULL);
     912   [ -  +  -  -  :          4 :         g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
          -  -  -  -  -  
                      - ]
     913   [ +  -  -  + ]:          4 :         g_return_val_if_fail (error == NULL || *error == NULL, NULL);
     914                 :            : 
     915                 :          4 :         va_start (va, error);
     916                 :          4 :         attributes = secret_attributes_buildv (schema, va);
     917                 :          4 :         va_end (va);
     918                 :            : 
     919                 :            :         /* Precondition failed, already warned */
     920         [ -  + ]:          4 :         if (!attributes)
     921                 :          0 :                 return NULL;
     922                 :            : 
     923                 :          4 :         password = secret_password_lookupv_nonpageable_sync (schema, attributes,
     924                 :            :                                                              cancellable, error);
     925                 :            : 
     926                 :          4 :         g_hash_table_unref (attributes);
     927                 :            : 
     928                 :          4 :         return password;
     929                 :            : }
     930                 :            : 
     931                 :            : /**
     932                 :            :  * secret_password_lookupv_nonpageable_sync: (skip)
     933                 :            :  * @schema: (nullable): the schema for attributes
     934                 :            :  * @attributes: (element-type utf8 utf8): the attribute keys and values
     935                 :            :  * @cancellable: (nullable): optional cancellation object
     936                 :            :  * @error: location to place an error on failure
     937                 :            :  *
     938                 :            :  * Lookup a password in the secret service.
     939                 :            :  *
     940                 :            :  * The @attributes should be a set of key and value string pairs.
     941                 :            :  *
     942                 :            :  * If no secret is found then %NULL is returned.
     943                 :            :  *
     944                 :            :  * This method may block indefinitely and should not be used in user interface
     945                 :            :  * threads.
     946                 :            :  *
     947                 :            :  * Returns: (transfer full): a new password string stored in non pageable memory
     948                 :            :  *   which should be freed with [func@password_free] when done
     949                 :            :  */
     950                 :            : gchar *
     951                 :          4 : secret_password_lookupv_nonpageable_sync (const SecretSchema *schema,
     952                 :            :                                           GHashTable *attributes,
     953                 :            :                                           GCancellable *cancellable,
     954                 :            :                                           GError **error)
     955                 :            : {
     956                 :            :         SecretSync *sync;
     957                 :            :         gchar *password;
     958                 :            : 
     959         [ -  + ]:          4 :         g_return_val_if_fail (attributes != NULL, NULL);
     960   [ -  +  -  -  :          4 :         g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
          -  -  -  -  -  
                      - ]
     961   [ +  -  -  + ]:          4 :         g_return_val_if_fail (error == NULL || *error == NULL, NULL);
     962                 :            : 
     963                 :            :         /* Warnings raised already */
     964   [ +  -  -  + ]:          4 :         if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
     965                 :          0 :                 return FALSE;
     966                 :            : 
     967                 :          4 :         sync = _secret_sync_new ();
     968                 :          4 :         g_main_context_push_thread_default (sync->context);
     969                 :            : 
     970                 :          4 :         secret_password_lookupv (schema, attributes, cancellable,
     971                 :            :                                  _secret_sync_on_result, sync);
     972                 :            : 
     973                 :          4 :         g_main_loop_run (sync->loop);
     974                 :            : 
     975                 :          4 :         password = secret_password_lookup_nonpageable_finish (sync->result, error);
     976                 :            : 
     977                 :          4 :         g_main_context_pop_thread_default (sync->context);
     978                 :          4 :         _secret_sync_free (sync);
     979                 :            : 
     980                 :          4 :         return password;
     981                 :            : }
     982                 :            : 
     983                 :            : /**
     984                 :            :  * secret_password_lookup_binary_sync: (skip)
     985                 :            :  * @schema: the schema for the attributes
     986                 :            :  * @cancellable: (nullable): optional cancellation object
     987                 :            :  * @error: location to place an error on failure
     988                 :            :  * @...: the attribute keys and values, terminated with %NULL
     989                 :            :  *
     990                 :            :  * Lookup a password in the secret service.
     991                 :            :  *
     992                 :            :  * This is similar to [func@password_lookup_sync], but returns a
     993                 :            :  * [struct@Value] instead of a null-terminated password.
     994                 :            :  *
     995                 :            :  * This method may block indefinitely and should not be used in user interface
     996                 :            :  * threads.
     997                 :            :  *
     998                 :            :  * Returns: (transfer full): a newly allocated [struct@Value], which should be
     999                 :            :  *   released with [method@Value.unref], or %NULL if no secret found
    1000                 :            :  *
    1001                 :            :  * Since: 0.19.0
    1002                 :            :  */
    1003                 :            : SecretValue *
    1004                 :          2 : secret_password_lookup_binary_sync (const SecretSchema *schema,
    1005                 :            :                                     GCancellable *cancellable,
    1006                 :            :                                     GError **error,
    1007                 :            :                                     ...)
    1008                 :            : {
    1009                 :            :         GHashTable *attributes;
    1010                 :            :         SecretValue *value;
    1011                 :            :         va_list va;
    1012                 :            : 
    1013         [ -  + ]:          2 :         g_return_val_if_fail (schema != NULL, NULL);
    1014   [ -  +  -  -  :          2 :         g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
          -  -  -  -  -  
                      - ]
    1015   [ +  -  -  + ]:          2 :         g_return_val_if_fail (error == NULL || *error == NULL, NULL);
    1016                 :            : 
    1017                 :          2 :         va_start (va, error);
    1018                 :          2 :         attributes = secret_attributes_buildv (schema, va);
    1019                 :          2 :         va_end (va);
    1020                 :            : 
    1021                 :            :         /* Precondition failed, already warned */
    1022         [ -  + ]:          2 :         if (!attributes)
    1023                 :          0 :                 return NULL;
    1024                 :            : 
    1025                 :          2 :         value = secret_password_lookupv_binary_sync (schema, attributes,
    1026                 :            :                                                      cancellable, error);
    1027                 :            : 
    1028                 :          2 :         g_hash_table_unref (attributes);
    1029                 :            : 
    1030                 :          2 :         return value;
    1031                 :            : }
    1032                 :            : 
    1033                 :            : /**
    1034                 :            :  * secret_password_lookupv_binary_sync: (skip)
    1035                 :            :  * @schema: (nullable): the schema for attributes
    1036                 :            :  * @attributes: (element-type utf8 utf8): the attribute keys and values
    1037                 :            :  * @cancellable: (nullable): optional cancellation object
    1038                 :            :  * @error: location to place an error on failure
    1039                 :            :  *
    1040                 :            :  * Lookup a password in the secret service.
    1041                 :            :  *
    1042                 :            :  * This is similar to [func@password_lookupv_sync], but returns a
    1043                 :            :  * [struct@Value] instead of a null-terminated password.
    1044                 :            :  *
    1045                 :            :  * This method may block indefinitely and should not be used in user interface
    1046                 :            :  * threads.
    1047                 :            :  *
    1048                 :            :  * Returns: (transfer full): a newly allocated [struct@Value], which should be
    1049                 :            :  *   released with [method@Value.unref], or %NULL if no secret found
    1050                 :            :  *
    1051                 :            :  * Since: 0.19.0
    1052                 :            :  */
    1053                 :            : SecretValue *
    1054                 :          4 : secret_password_lookupv_binary_sync (const SecretSchema *schema,
    1055                 :            :                                      GHashTable *attributes,
    1056                 :            :                                      GCancellable *cancellable,
    1057                 :            :                                      GError **error)
    1058                 :            : {
    1059                 :            :         SecretSync *sync;
    1060                 :            :         SecretValue *value;
    1061                 :            : 
    1062         [ -  + ]:          4 :         g_return_val_if_fail (attributes != NULL, NULL);
    1063   [ -  +  -  -  :          4 :         g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
          -  -  -  -  -  
                      - ]
    1064   [ +  -  -  + ]:          4 :         g_return_val_if_fail (error == NULL || *error == NULL, NULL);
    1065                 :            : 
    1066                 :            :         /* Warnings raised already */
    1067   [ +  +  -  + ]:          4 :         if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
    1068                 :          0 :                 return FALSE;
    1069                 :            : 
    1070                 :          4 :         sync = _secret_sync_new ();
    1071                 :          4 :         g_main_context_push_thread_default (sync->context);
    1072                 :            : 
    1073                 :          4 :         secret_password_lookupv (schema, attributes, cancellable,
    1074                 :            :                                  _secret_sync_on_result, sync);
    1075                 :            : 
    1076                 :          4 :         g_main_loop_run (sync->loop);
    1077                 :            : 
    1078                 :          4 :         value = secret_password_lookup_binary_finish (sync->result, error);
    1079                 :            : 
    1080                 :          4 :         g_main_context_pop_thread_default (sync->context);
    1081                 :          4 :         _secret_sync_free (sync);
    1082                 :            : 
    1083                 :          4 :         return value;
    1084                 :            : }
    1085                 :            : 
    1086                 :            : /**
    1087                 :            :  * secret_password_lookupv_sync: (rename-to secret_password_lookup_sync)
    1088                 :            :  * @schema: (nullable): the schema for attributes
    1089                 :            :  * @attributes: (element-type utf8 utf8): the attribute keys and values
    1090                 :            :  * @cancellable: (nullable): optional cancellation object
    1091                 :            :  * @error: location to place an error on failure
    1092                 :            :  *
    1093                 :            :  * Lookup a password in the secret service.
    1094                 :            :  *
    1095                 :            :  * The @attributes should be a set of key and value string pairs.
    1096                 :            :  *
    1097                 :            :  * If no secret is found then %NULL is returned.
    1098                 :            :  *
    1099                 :            :  * This method may block indefinitely and should not be used in user interface
    1100                 :            :  * threads.
    1101                 :            :  *
    1102                 :            :  * Returns: (transfer full): a new password string which should be freed with
    1103                 :            :  *   [func@password_free] or may be freed with [func@GLib.free] when done
    1104                 :            :  */
    1105                 :            : gchar *
    1106                 :         10 : secret_password_lookupv_sync (const SecretSchema *schema,
    1107                 :            :                               GHashTable *attributes,
    1108                 :            :                               GCancellable *cancellable,
    1109                 :            :                               GError **error)
    1110                 :            : {
    1111                 :            :         SecretSync *sync;
    1112                 :            :         gchar *string;
    1113                 :            : 
    1114         [ -  + ]:         10 :         g_return_val_if_fail (attributes != NULL, NULL);
    1115   [ -  +  -  -  :         10 :         g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
          -  -  -  -  -  
                      - ]
    1116   [ +  -  -  + ]:         10 :         g_return_val_if_fail (error == NULL || *error == NULL, NULL);
    1117                 :            : 
    1118                 :            :         /* Warnings raised already */
    1119   [ +  -  -  + ]:         10 :         if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
    1120                 :          0 :                 return FALSE;
    1121                 :            : 
    1122                 :         10 :         sync = _secret_sync_new ();
    1123                 :         10 :         g_main_context_push_thread_default (sync->context);
    1124                 :            : 
    1125                 :         10 :         secret_password_lookupv (schema, attributes, cancellable,
    1126                 :            :                                  _secret_sync_on_result, sync);
    1127                 :            : 
    1128                 :         10 :         g_main_loop_run (sync->loop);
    1129                 :            : 
    1130                 :         10 :         string = secret_password_lookup_finish (sync->result, error);
    1131                 :            : 
    1132                 :         10 :         g_main_context_pop_thread_default (sync->context);
    1133                 :         10 :         _secret_sync_free (sync);
    1134                 :            : 
    1135                 :         10 :         return string;
    1136                 :            : }
    1137                 :            : 
    1138                 :            : /**
    1139                 :            :  * secret_password_clear:
    1140                 :            :  * @schema: the schema for the attributes
    1141                 :            :  * @cancellable: (nullable): optional cancellation object
    1142                 :            :  * @callback: called when the operation completes
    1143                 :            :  * @user_data: data to be passed to the callback
    1144                 :            :  * @...: the attribute keys and values, terminated with %NULL
    1145                 :            :  *
    1146                 :            :  * Clear unlocked matching passwords from the secret service.
    1147                 :            :  *
    1148                 :            :  * The variable argument list should contain pairs of a) The attribute name as
    1149                 :            :  * a null-terminated string, followed by b) attribute value, either a character
    1150                 :            :  * string, an int number, or a gboolean value, as defined in the password
    1151                 :            :  * @schema. The list of attributes should be terminated with a %NULL.
    1152                 :            :  *
    1153                 :            :  * All unlocked items that match the attributes will be deleted.
    1154                 :            :  *
    1155                 :            :  * This method will return immediately and complete asynchronously.
    1156                 :            :  */
    1157                 :            : void
    1158                 :          1 : secret_password_clear (const SecretSchema *schema,
    1159                 :            :                        GCancellable *cancellable,
    1160                 :            :                        GAsyncReadyCallback callback,
    1161                 :            :                        gpointer user_data,
    1162                 :            :                        ...)
    1163                 :            : {
    1164                 :            :         GHashTable *attributes;
    1165                 :            :         va_list va;
    1166                 :            : 
    1167         [ -  + ]:          1 :         g_return_if_fail (schema != NULL);
    1168   [ -  +  -  -  :          1 :         g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
          -  -  -  -  -  
                      - ]
    1169                 :            : 
    1170                 :          1 :         va_start (va, user_data);
    1171                 :          1 :         attributes = secret_attributes_buildv (schema, va);
    1172                 :          1 :         va_end (va);
    1173                 :            : 
    1174                 :            :         /* Precondition failed, already warned */
    1175         [ -  + ]:          1 :         if (!attributes)
    1176                 :          0 :                 return;
    1177                 :            : 
    1178                 :          1 :         secret_password_clearv (schema, attributes, cancellable,
    1179                 :            :                                 callback, user_data);
    1180                 :            : 
    1181                 :          1 :         g_hash_table_unref (attributes);
    1182                 :            : }
    1183                 :            : 
    1184                 :            : typedef struct {
    1185                 :            :         const SecretSchema *schema;
    1186                 :            :         GHashTable *attributes;
    1187                 :            : } ClearClosure;
    1188                 :            : 
    1189                 :            : static void
    1190                 :         10 : clear_closure_free (gpointer data)
    1191                 :            : {
    1192                 :         10 :         ClearClosure *closure = data;
    1193                 :         10 :         _secret_schema_unref_if_nonstatic (closure->schema);
    1194                 :         10 :         g_hash_table_unref (closure->attributes);
    1195                 :         10 :         g_free (closure);
    1196                 :         10 : }
    1197                 :            : 
    1198                 :            : static void
    1199                 :         10 : on_clear (GObject *source,
    1200                 :            :           GAsyncResult *result,
    1201                 :            :           gpointer user_data)
    1202                 :            : {
    1203                 :         10 :         GTask *task = G_TASK (user_data);
    1204                 :         10 :         SecretBackend *backend = SECRET_BACKEND (source);
    1205                 :            :         SecretBackendInterface *iface;
    1206                 :         10 :         GError *error = NULL;
    1207                 :            : 
    1208                 :         10 :         iface = SECRET_BACKEND_GET_IFACE (backend);
    1209         [ -  + ]:         13 :         g_return_if_fail (iface->clear_finish != NULL);
    1210                 :            : 
    1211         [ +  + ]:         10 :         if (!iface->clear_finish (backend, result, &error)) {
    1212         [ -  + ]:          3 :                 if (error)
    1213                 :          0 :                         g_task_return_error (task, error);
    1214                 :            :                 else
    1215                 :          3 :                         g_task_return_boolean (task, FALSE);
    1216                 :          3 :                 g_object_unref (task);
    1217                 :          3 :                 return;
    1218                 :            :         }
    1219                 :            : 
    1220                 :          7 :         g_task_return_boolean (task, TRUE);
    1221                 :          7 :         g_object_unref (task);
    1222                 :            : }
    1223                 :            : 
    1224                 :            : static void
    1225                 :         10 : on_clear_backend (GObject *source,
    1226                 :            :                   GAsyncResult *result,
    1227                 :            :                   gpointer user_data)
    1228                 :            : {
    1229                 :         10 :         GTask *task = G_TASK (user_data);
    1230                 :         10 :         ClearClosure *clear = g_task_get_task_data (task);
    1231                 :            :         SecretBackend *backend;
    1232                 :            :         SecretBackendInterface *iface;
    1233                 :         10 :         GError *error = NULL;
    1234                 :            : 
    1235                 :         10 :         backend = secret_backend_get_finish (result, &error);
    1236         [ -  + ]:         10 :         if (backend == NULL) {
    1237                 :          0 :                 g_task_return_error (task, error);
    1238                 :          0 :                 g_object_unref (task);
    1239                 :          0 :                 return;
    1240                 :            :         }
    1241                 :            : 
    1242                 :         10 :         iface = SECRET_BACKEND_GET_IFACE (backend);
    1243         [ -  + ]:         10 :         g_return_if_fail (iface->clear != NULL);
    1244                 :            : 
    1245                 :         10 :         iface->clear (backend, clear->schema, clear->attributes,
    1246                 :            :                       g_task_get_cancellable (task),
    1247                 :            :                       on_clear,
    1248                 :            :                       task);
    1249                 :            : }
    1250                 :            : 
    1251                 :            : /**
    1252                 :            :  * secret_password_clearv: (rename-to secret_password_clear)
    1253                 :            :  * @schema: (nullable): the schema for the attributes
    1254                 :            :  * @attributes: (element-type utf8 utf8) (transfer full): the attribute keys and values
    1255                 :            :  * @cancellable: (nullable): optional cancellation object
    1256                 :            :  * @callback: (scope async): called when the operation completes
    1257                 :            :  * @user_data: data to be passed to the callback
    1258                 :            :  *
    1259                 :            :  * Remove unlocked matching passwords from the secret service.
    1260                 :            :  *
    1261                 :            :  * The @attributes should be a set of key and value string pairs.
    1262                 :            :  *
    1263                 :            :  * All unlocked items that match the attributes will be deleted.
    1264                 :            :  *
    1265                 :            :  * This method will return immediately and complete asynchronously.
    1266                 :            :  */
    1267                 :            : void
    1268                 :         10 : secret_password_clearv (const SecretSchema *schema,
    1269                 :            :                         GHashTable *attributes,
    1270                 :            :                         GCancellable *cancellable,
    1271                 :            :                         GAsyncReadyCallback callback,
    1272                 :            :                         gpointer user_data)
    1273                 :            : {
    1274                 :            :         ClearClosure *clear;
    1275                 :            :         GTask *task;
    1276                 :            : 
    1277         [ -  + ]:         10 :         g_return_if_fail (attributes != NULL);
    1278   [ -  +  -  -  :         10 :         g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
          -  -  -  -  -  
                      - ]
    1279                 :            : 
    1280                 :            :         /* Warnings raised already */
    1281   [ +  +  -  + ]:         10 :         if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
    1282                 :          0 :                 return;
    1283                 :            : 
    1284                 :         10 :         task = g_task_new (NULL, cancellable, callback, user_data);
    1285                 :         10 :         clear = g_new0 (ClearClosure, 1);
    1286                 :         10 :         clear->schema = _secret_schema_ref_if_nonstatic (schema);
    1287                 :         10 :         clear->attributes = g_hash_table_ref (attributes);
    1288                 :         10 :         g_task_set_task_data (task, clear, clear_closure_free);
    1289                 :            : 
    1290                 :         10 :         secret_backend_get (SECRET_SERVICE_NONE,
    1291                 :            :                             cancellable,
    1292                 :            :                             on_clear_backend, task);
    1293                 :            : }
    1294                 :            : 
    1295                 :            : /**
    1296                 :            :  * secret_password_clear_finish:
    1297                 :            :  * @result: the asynchronous result passed to the callback
    1298                 :            :  * @error: location to place an error on failure
    1299                 :            :  *
    1300                 :            :  * Finish an asynchronous operation to remove passwords from the secret
    1301                 :            :  * service.
    1302                 :            :  *
    1303                 :            :  * Returns: whether any passwords were removed
    1304                 :            :  */
    1305                 :            : gboolean
    1306                 :         10 : secret_password_clear_finish (GAsyncResult *result,
    1307                 :            :                               GError **error)
    1308                 :            : {
    1309   [ +  -  -  + ]:         10 :         g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
    1310         [ -  + ]:         10 :         g_return_val_if_fail (g_task_is_valid (result, NULL), FALSE);
    1311                 :            : 
    1312                 :         10 :         return g_task_propagate_boolean (G_TASK (result), error);
    1313                 :            : }
    1314                 :            : 
    1315                 :            : /**
    1316                 :            :  * secret_password_clear_sync:
    1317                 :            :  * @schema: the schema for the attributes
    1318                 :            :  * @cancellable: (nullable): optional cancellation object
    1319                 :            :  * @error: location to place an error on failure
    1320                 :            :  * @...: the attribute keys and values, terminated with %NULL
    1321                 :            :  *
    1322                 :            :  * Remove unlocked matching passwords from the secret service.
    1323                 :            :  *
    1324                 :            :  * The variable argument list should contain pairs of a) The attribute name as
    1325                 :            :  * a null-terminated string, followed by b) attribute value, either a character
    1326                 :            :  * string, an int number, or a gboolean value, as defined in the password
    1327                 :            :  * @schema. The list of attributes should be terminated with a %NULL.
    1328                 :            :  *
    1329                 :            :  * All unlocked items that match the attributes will be deleted.
    1330                 :            :  *
    1331                 :            :  * This method may block indefinitely and should not be used in user interface
    1332                 :            :  * threads.
    1333                 :            :  *
    1334                 :            :  * Returns: whether the any passwords were removed
    1335                 :            :  */
    1336                 :            : gboolean
    1337                 :          3 : secret_password_clear_sync (const SecretSchema* schema,
    1338                 :            :                             GCancellable *cancellable,
    1339                 :            :                             GError **error,
    1340                 :            :                             ...)
    1341                 :            : {
    1342                 :            :         GHashTable *attributes;
    1343                 :            :         gboolean result;
    1344                 :            :         va_list va;
    1345                 :            : 
    1346         [ -  + ]:          3 :         g_return_val_if_fail (schema != NULL, FALSE);
    1347   [ -  +  -  -  :          3 :         g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
          -  -  -  -  -  
                      - ]
    1348   [ +  -  -  + ]:          3 :         g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
    1349                 :            : 
    1350                 :          3 :         va_start (va, error);
    1351                 :          3 :         attributes = secret_attributes_buildv (schema, va);
    1352                 :          3 :         va_end (va);
    1353                 :            : 
    1354                 :            :         /* Precondition failed, already warned */
    1355         [ -  + ]:          3 :         if (!attributes)
    1356                 :          0 :                 return FALSE;
    1357                 :            : 
    1358                 :          3 :         result = secret_password_clearv_sync (schema, attributes,
    1359                 :            :                                               cancellable, error);
    1360                 :            : 
    1361                 :          3 :         g_hash_table_unref (attributes);
    1362                 :            : 
    1363                 :          3 :         return result;
    1364                 :            : }
    1365                 :            : 
    1366                 :            : /**
    1367                 :            :  * secret_password_clearv_sync: (rename-to secret_password_clear_sync)
    1368                 :            :  * @schema: (nullable): the schema for the attributes
    1369                 :            :  * @attributes: (element-type utf8 utf8): the attribute keys and values
    1370                 :            :  * @cancellable: (nullable): optional cancellation object
    1371                 :            :  * @error: location to place an error on failure
    1372                 :            :  *
    1373                 :            :  * Remove unlocked matching passwords from the secret service.
    1374                 :            :  *
    1375                 :            :  * The @attributes should be a set of key and value string pairs.
    1376                 :            :  *
    1377                 :            :  * All unlocked items that match the attributes will be deleted.
    1378                 :            :  *
    1379                 :            :  * This method may block indefinitely and should not be used in user interface
    1380                 :            :  * threads.
    1381                 :            :  *
    1382                 :            :  * Returns: whether any passwords were removed
    1383                 :            :  */
    1384                 :            : gboolean
    1385                 :          7 : secret_password_clearv_sync (const SecretSchema *schema,
    1386                 :            :                              GHashTable *attributes,
    1387                 :            :                              GCancellable *cancellable,
    1388                 :            :                              GError **error)
    1389                 :            : {
    1390                 :            :         SecretSync *sync;
    1391                 :            :         gboolean result;
    1392                 :            : 
    1393         [ -  + ]:          7 :         g_return_val_if_fail (attributes != NULL, FALSE);
    1394   [ -  +  -  -  :          7 :         g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
          -  -  -  -  -  
                      - ]
    1395   [ +  -  -  + ]:          7 :         g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
    1396                 :            : 
    1397                 :            :         /* Warnings raised already */
    1398   [ +  +  -  + ]:          7 :         if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
    1399                 :          0 :                 return FALSE;
    1400                 :            : 
    1401                 :          7 :         sync = _secret_sync_new ();
    1402                 :          7 :         g_main_context_push_thread_default (sync->context);
    1403                 :            : 
    1404                 :          7 :         secret_password_clearv (schema, attributes, cancellable,
    1405                 :            :                                 _secret_sync_on_result, sync);
    1406                 :            : 
    1407                 :          7 :         g_main_loop_run (sync->loop);
    1408                 :            : 
    1409                 :          7 :         result = secret_password_clear_finish (sync->result, error);
    1410                 :            : 
    1411                 :          7 :         g_main_context_pop_thread_default (sync->context);
    1412                 :          7 :         _secret_sync_free (sync);
    1413                 :            : 
    1414                 :          7 :         return result;
    1415                 :            : }
    1416                 :            : 
    1417                 :            : /**
    1418                 :            :  * secret_password_search: (skip)
    1419                 :            :  * @schema: the schema for the attributes
    1420                 :            :  * @flags: search option flags
    1421                 :            :  * @cancellable: (nullable): optional cancellation object
    1422                 :            :  * @callback: called when the operation completes
    1423                 :            :  * @user_data: data to be passed to the callback
    1424                 :            :  * @...: the attribute keys and values, terminated with %NULL
    1425                 :            :  *
    1426                 :            :  * Search for items in the secret service.
    1427                 :            :  *
    1428                 :            :  * The variable argument list should contain pairs of a) The attribute name as
    1429                 :            :  * a null-terminated string, followed by b) attribute value, either a character
    1430                 :            :  * string, an int number, or a gboolean value, as defined in the password
    1431                 :            :  * @schema. The list of attributes should be terminated with a %NULL.
    1432                 :            :  *
    1433                 :            :  * This method will return immediately and complete asynchronously.
    1434                 :            :  *
    1435                 :            :  * Since: 0.19.0
    1436                 :            :  */
    1437                 :            : void
    1438                 :          1 : secret_password_search (const SecretSchema *schema,
    1439                 :            :                         SecretSearchFlags flags,
    1440                 :            :                         GCancellable *cancellable,
    1441                 :            :                         GAsyncReadyCallback callback,
    1442                 :            :                         gpointer user_data,
    1443                 :            :                         ...)
    1444                 :            : {
    1445                 :            :         GHashTable *attributes;
    1446                 :            :         va_list va;
    1447                 :            : 
    1448         [ -  + ]:          1 :         g_return_if_fail (schema != NULL);
    1449   [ -  +  -  -  :          1 :         g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
          -  -  -  -  -  
                      - ]
    1450                 :            : 
    1451                 :          1 :         va_start (va, user_data);
    1452                 :          1 :         attributes = secret_attributes_buildv (schema, va);
    1453                 :          1 :         va_end (va);
    1454                 :            : 
    1455                 :            :         /* Precondition failed, already warned */
    1456         [ -  + ]:          1 :         if (!attributes)
    1457                 :          0 :                 return;
    1458                 :            : 
    1459                 :          1 :         secret_password_searchv (schema, attributes, flags, cancellable,
    1460                 :            :                                  callback, user_data);
    1461                 :            : 
    1462                 :          1 :         g_hash_table_unref (attributes);
    1463                 :            : }
    1464                 :            : 
    1465                 :            : typedef struct {
    1466                 :            :         const SecretSchema *schema;
    1467                 :            :         GHashTable *attributes;
    1468                 :            :         SecretSearchFlags flags;
    1469                 :            : } SearchClosure;
    1470                 :            : 
    1471                 :            : static void
    1472                 :          8 : search_closure_free (gpointer data)
    1473                 :            : {
    1474                 :          8 :         SearchClosure *closure = data;
    1475                 :          8 :         _secret_schema_unref_if_nonstatic (closure->schema);
    1476                 :          8 :         g_hash_table_unref (closure->attributes);
    1477                 :          8 :         g_free (closure);
    1478                 :          8 : }
    1479                 :            : 
    1480                 :            : static void
    1481                 :          0 : object_list_free (gpointer data)
    1482                 :            : {
    1483                 :          0 :         GList *list = data;
    1484                 :          0 :         g_list_free_full (list, g_object_unref);
    1485                 :          0 : }
    1486                 :            : 
    1487                 :            : static void
    1488                 :          8 : on_search (GObject *source,
    1489                 :            :            GAsyncResult *result,
    1490                 :            :            gpointer user_data)
    1491                 :            : {
    1492                 :          8 :         GTask *task = G_TASK (user_data);
    1493                 :          8 :         SecretBackend *backend = SECRET_BACKEND (source);
    1494                 :            :         SecretBackendInterface *iface;
    1495                 :          8 :         GError *error = NULL;
    1496                 :            :         GList *items;
    1497                 :            : 
    1498                 :          8 :         iface = SECRET_BACKEND_GET_IFACE (backend);
    1499         [ -  + ]:          8 :         g_return_if_fail (iface->search_finish != NULL);
    1500                 :            : 
    1501                 :          8 :         items = iface->search_finish (backend, result, &error);
    1502         [ -  + ]:          8 :         if (error) {
    1503                 :          0 :                 g_task_return_error (task, error);
    1504                 :          0 :                 g_object_unref (task);
    1505                 :          0 :                 return;
    1506                 :            :         }
    1507                 :            : 
    1508                 :          8 :         g_task_return_pointer (task, items, object_list_free);
    1509                 :          8 :         g_object_unref (task);
    1510                 :            : }
    1511                 :            : 
    1512                 :            : static void
    1513                 :          8 : on_search_backend (GObject *source,
    1514                 :            :                    GAsyncResult *result,
    1515                 :            :                    gpointer user_data)
    1516                 :            : {
    1517                 :          8 :         GTask *task = G_TASK (user_data);
    1518                 :          8 :         SearchClosure *search = g_task_get_task_data (task);
    1519                 :            :         SecretBackend *backend;
    1520                 :            :         SecretBackendInterface *iface;
    1521                 :          8 :         GError *error = NULL;
    1522                 :            : 
    1523                 :          8 :         backend = secret_backend_get_finish (result, &error);
    1524         [ -  + ]:          8 :         if (backend == NULL) {
    1525                 :          0 :                 g_task_return_error (task, error);
    1526                 :          0 :                 g_object_unref (task);
    1527                 :          0 :                 return;
    1528                 :            :         }
    1529                 :            : 
    1530                 :          8 :         iface = SECRET_BACKEND_GET_IFACE (backend);
    1531         [ -  + ]:          8 :         g_return_if_fail (iface->search != NULL);
    1532                 :            : 
    1533                 :          8 :         iface->search (backend,
    1534                 :            :                        search->schema, search->attributes, search->flags,
    1535                 :            :                        g_task_get_cancellable (task),
    1536                 :            :                        on_search,
    1537                 :            :                        task);
    1538                 :            : }
    1539                 :            : 
    1540                 :            : /**
    1541                 :            :  * secret_password_searchv: (rename-to secret_password_search)
    1542                 :            :  * @schema: (nullable): the schema for attributes
    1543                 :            :  * @attributes: (element-type utf8 utf8) (transfer full): the attribute keys and values
    1544                 :            :  * @flags: search option flags
    1545                 :            :  * @cancellable: (nullable): optional cancellation object
    1546                 :            :  * @callback: (scope async): called when the operation completes
    1547                 :            :  * @user_data: data to be passed to the callback
    1548                 :            :  *
    1549                 :            :  * Search for items in the secret service.
    1550                 :            :  *
    1551                 :            :  * The @attributes should be a set of key and value string pairs.
    1552                 :            :  *
    1553                 :            :  * This method will return immediately and complete asynchronously.
    1554                 :            :  *
    1555                 :            :  * Since: 0.19.0
    1556                 :            :  */
    1557                 :            : void
    1558                 :          8 : secret_password_searchv (const SecretSchema *schema,
    1559                 :            :                          GHashTable *attributes,
    1560                 :            :                          SecretSearchFlags flags,
    1561                 :            :                          GCancellable *cancellable,
    1562                 :            :                          GAsyncReadyCallback callback,
    1563                 :            :                          gpointer user_data)
    1564                 :            : {
    1565                 :            :         SearchClosure *search;
    1566                 :            :         GTask *task;
    1567                 :            : 
    1568         [ -  + ]:          8 :         g_return_if_fail (attributes != NULL);
    1569   [ -  +  -  -  :          8 :         g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
          -  -  -  -  -  
                      - ]
    1570                 :            : 
    1571                 :            :         /* Warnings raised already */
    1572   [ +  +  -  + ]:          8 :         if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
    1573                 :          0 :                 return;
    1574                 :            : 
    1575                 :          8 :         task = g_task_new (NULL, cancellable, callback, user_data);
    1576                 :          8 :         search = g_new0 (SearchClosure, 1);
    1577                 :          8 :         search->schema = _secret_schema_ref_if_nonstatic (schema);
    1578                 :          8 :         search->attributes = g_hash_table_ref (attributes);
    1579                 :          8 :         search->flags = flags;
    1580                 :          8 :         g_task_set_task_data (task, search, search_closure_free);
    1581                 :            : 
    1582                 :          8 :         secret_backend_get (SECRET_SERVICE_NONE,
    1583                 :            :                             cancellable,
    1584                 :            :                             on_search_backend, task);
    1585                 :            : }
    1586                 :            : 
    1587                 :            : /**
    1588                 :            :  * secret_password_search_finish:
    1589                 :            :  * @result: the asynchronous result passed to the callback
    1590                 :            :  * @error: location to place an error on failure
    1591                 :            :  *
    1592                 :            :  * Finish an asynchronous operation to search for items in the secret service.
    1593                 :            :  *
    1594                 :            :  * Returns: (transfer full) (element-type Secret.Retrievable): a list of
    1595                 :            :  *   [iface@Retrievable] containing attributes of the matched items
    1596                 :            :  *
    1597                 :            :  * Since: 0.19.0
    1598                 :            :  */
    1599                 :            : GList *
    1600                 :          8 : secret_password_search_finish (GAsyncResult *result,
    1601                 :            :                                GError **error)
    1602                 :            : {
    1603   [ +  -  -  + ]:          8 :         g_return_val_if_fail (error == NULL || *error == NULL, NULL);
    1604         [ -  + ]:          8 :         g_return_val_if_fail (g_task_is_valid (result, NULL), NULL);
    1605                 :            : 
    1606                 :          8 :         return g_task_propagate_pointer (G_TASK (result), error);
    1607                 :            : }
    1608                 :            : 
    1609                 :            : /**
    1610                 :            :  * secret_password_search_sync: (skip)
    1611                 :            :  * @schema: the schema for the attributes
    1612                 :            :  * @flags: search option flags
    1613                 :            :  * @cancellable: (nullable): optional cancellation object
    1614                 :            :  * @error: location to place an error on failure
    1615                 :            :  * @...: the attribute keys and values, terminated with %NULL
    1616                 :            :  *
    1617                 :            :  * Search for items in the secret service.
    1618                 :            :  *
    1619                 :            :  * The variable argument list should contain pairs of a) The attribute name as
    1620                 :            :  * a null-terminated string, followed by b) attribute value, either a character
    1621                 :            :  * string, an int number, or a gboolean value, as defined in the password
    1622                 :            :  * @schema. The list of attributes should be terminated with a %NULL.
    1623                 :            :  *
    1624                 :            :  * If no secret is found then %NULL is returned.
    1625                 :            :  *
    1626                 :            :  * This method may block indefinitely and should not be used in user interface
    1627                 :            :  * threads.
    1628                 :            :  *
    1629                 :            :  * Returns: (transfer full) (element-type Secret.Retrievable): a list of
    1630                 :            :  *   [iface@Retrievable] containing attributes of the matched items
    1631                 :            :  *
    1632                 :            :  * Since: 0.19.0
    1633                 :            :  */
    1634                 :            : GList *
    1635                 :          3 : secret_password_search_sync (const SecretSchema *schema,
    1636                 :            :                              SecretSearchFlags flags,
    1637                 :            :                              GCancellable *cancellable,
    1638                 :            :                              GError **error,
    1639                 :            :                              ...)
    1640                 :            : {
    1641                 :            :         GHashTable *attributes;
    1642                 :            :         GList *items;
    1643                 :            :         va_list va;
    1644                 :            : 
    1645         [ -  + ]:          3 :         g_return_val_if_fail (schema != NULL, NULL);
    1646   [ -  +  -  -  :          3 :         g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
          -  -  -  -  -  
                      - ]
    1647   [ +  -  -  + ]:          3 :         g_return_val_if_fail (error == NULL || *error == NULL, NULL);
    1648                 :            : 
    1649                 :          3 :         va_start (va, error);
    1650                 :          3 :         attributes = secret_attributes_buildv (schema, va);
    1651                 :          3 :         va_end (va);
    1652                 :            : 
    1653                 :            :         /* Precondition failed, already warned */
    1654         [ -  + ]:          3 :         if (!attributes)
    1655                 :          0 :                 return NULL;
    1656                 :            : 
    1657                 :          3 :         items = secret_password_searchv_sync (schema, attributes, flags,
    1658                 :            :                                               cancellable, error);
    1659                 :            : 
    1660                 :          3 :         g_hash_table_unref (attributes);
    1661                 :            : 
    1662                 :          3 :         return items;
    1663                 :            : }
    1664                 :            : 
    1665                 :            : /**
    1666                 :            :  * secret_password_searchv_sync: (rename-to secret_password_search_sync)
    1667                 :            :  * @schema: (nullable): the schema for attributes
    1668                 :            :  * @attributes: (element-type utf8 utf8): the attribute keys and values
    1669                 :            :  * @flags: search option flags
    1670                 :            :  * @cancellable: (nullable): optional cancellation object
    1671                 :            :  * @error: location to place an error on failure
    1672                 :            :  *
    1673                 :            :  * Search for items in the secret service.
    1674                 :            :  *
    1675                 :            :  * The @attributes should be a set of key and value string pairs.
    1676                 :            :  *
    1677                 :            :  * If no secret is found then %NULL is returned.
    1678                 :            :  *
    1679                 :            :  * This method may block indefinitely and should not be used in user interface
    1680                 :            :  * threads.
    1681                 :            :  *
    1682                 :            :  * Returns: (transfer full) (element-type Secret.Retrievable): a list of
    1683                 :            :  *   [iface@Retrievable] containing attributes of the matched items
    1684                 :            :  *
    1685                 :            :  * Since: 0.19.0
    1686                 :            :  */
    1687                 :            : GList *
    1688                 :          7 : secret_password_searchv_sync (const SecretSchema *schema,
    1689                 :            :                               GHashTable *attributes,
    1690                 :            :                               SecretSearchFlags flags,
    1691                 :            :                               GCancellable *cancellable,
    1692                 :            :                               GError **error)
    1693                 :            : {
    1694                 :            :         SecretSync *sync;
    1695                 :            :         GList *items;
    1696                 :            : 
    1697         [ -  + ]:          7 :         g_return_val_if_fail (attributes != NULL, NULL);
    1698   [ -  +  -  -  :          7 :         g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
          -  -  -  -  -  
                      - ]
    1699   [ +  -  -  + ]:          7 :         g_return_val_if_fail (error == NULL || *error == NULL, NULL);
    1700                 :            : 
    1701                 :            :         /* Warnings raised already */
    1702   [ +  +  -  + ]:          7 :         if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
    1703                 :          0 :                 return NULL;
    1704                 :            : 
    1705                 :          7 :         sync = _secret_sync_new ();
    1706                 :          7 :         g_main_context_push_thread_default (sync->context);
    1707                 :            : 
    1708                 :          7 :         secret_password_searchv (schema, attributes, flags, cancellable,
    1709                 :            :                                  _secret_sync_on_result, sync);
    1710                 :            : 
    1711                 :          7 :         g_main_loop_run (sync->loop);
    1712                 :            : 
    1713                 :          7 :         items = secret_password_search_finish (sync->result, error);
    1714                 :            : 
    1715                 :          7 :         g_main_context_pop_thread_default (sync->context);
    1716                 :          7 :         _secret_sync_free (sync);
    1717                 :            : 
    1718                 :          7 :         return items;
    1719                 :            : }
    1720                 :            : 
    1721                 :            : /**
    1722                 :            :  * secret_password_free: (skip)
    1723                 :            :  * @password: (nullable): password to free
    1724                 :            :  *
    1725                 :            :  * Clear the memory used by a password, and then free it.
    1726                 :            :  *
    1727                 :            :  * This function must be used to free nonpageable memory returned by
    1728                 :            :  * [func@password_lookup_nonpageable_finish],
    1729                 :            :  * [func@password_lookup_nonpageable_sync] or
    1730                 :            :  * [func@password_lookupv_nonpageable_sync].
    1731                 :            :  */
    1732                 :            : void
    1733                 :         11 : secret_password_free (gchar *password)
    1734                 :            : {
    1735         [ +  + ]:         11 :         if (password == NULL)
    1736                 :          1 :                 return;
    1737                 :            : 
    1738                 :         10 :         egg_secure_strfree (password);
    1739                 :            : }
    1740                 :            : 
    1741                 :            : /**
    1742                 :            :  * secret_password_wipe:
    1743                 :            :  * @password: (nullable): password to clear
    1744                 :            :  *
    1745                 :            :  * Clear the memory used by a password.
    1746                 :            :  */
    1747                 :            : void
    1748                 :          0 : secret_password_wipe (gchar *password)
    1749                 :            : {
    1750         [ #  # ]:          0 :         if (password == NULL)
    1751                 :          0 :                 return;
    1752                 :            : 
    1753                 :          0 :         egg_secure_strclear (password);
    1754                 :            : }

Generated by: LCOV version 1.14