summaryrefslogtreecommitdiff
path: root/libsecret/secret-password.c
diff options
context:
space:
mode:
authorDaiki Ueno <dueno@src.gnome.org>2019-06-20 06:55:37 +0200
committerDaiki Ueno <ueno@gnu.org>2019-07-18 13:54:12 +0000
commitbac85c00fc565d0c5e8519e910225a464949698a (patch)
tree96000e09bbb9733fe6eebfef3a7b154f4096051f /libsecret/secret-password.c
parent5fedca8ffc1e57c55ee564c39d1c2d579a15f01f (diff)
downloadlibsecret-bac85c00fc565d0c5e8519e910225a464949698a.tar.gz
secret-password: Add lookup_binary functions
This adds a set of functions that return a SecretValue instead of a text password when looking up a secret. This is useful if the stored password is not null-terminated.
Diffstat (limited to 'libsecret/secret-password.c')
-rw-r--r--libsecret/secret-password.c125
1 files changed, 125 insertions, 0 deletions
diff --git a/libsecret/secret-password.c b/libsecret/secret-password.c
index fc0ea0c..1ff0e86 100644
--- a/libsecret/secret-password.c
+++ b/libsecret/secret-password.c
@@ -408,6 +408,27 @@ secret_password_lookup_nonpageable_finish (GAsyncResult *result,
}
/**
+ * secret_password_lookup_binary_finish: (skip)
+ * @result: the asynchronous result passed to the callback
+ * @error: location to place an error on failure
+ *
+ * Finish an asynchronous operation to lookup a password in the secret service.
+ *
+ * Returns: (transfer full): a newly allocated #SecretValue, which should be
+ * released with secret_value_unref(), or %NULL if no secret found
+ *
+ * Since: 0.19.0
+ */
+SecretValue *
+secret_password_lookup_binary_finish (GAsyncResult *result,
+ GError **error)
+{
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+ return secret_service_lookup_finish (NULL, result, error);
+}
+
+/**
* secret_password_lookup_finish:
* @result: the asynchronous result passed to the callback
* @error: location to place an error on failure
@@ -590,6 +611,110 @@ secret_password_lookupv_nonpageable_sync (const SecretSchema *schema,
}
/**
+ * secret_password_lookup_binary_sync: (skip)
+ * @schema: the schema for the attributes
+ * @cancellable: optional cancellation object
+ * @error: location to place an error on failure
+ * @...: the attribute keys and values, terminated with %NULL
+ *
+ * Lookup a password in the secret service.
+ *
+ * This is similar to secret_password_lookup_sync(), but returns a
+ * #SecretValue instead of a null-terminated password.
+ *
+ * This method may block indefinitely and should not be used in user interface
+ * threads.
+ *
+ * Returns: (transfer full): a newly allocated #SecretValue, which should be
+ * released with secret_value_unref(), or %NULL if no secret found
+ *
+ * Since: 0.19.0
+ */
+SecretValue *
+secret_password_lookup_binary_sync (const SecretSchema *schema,
+ GCancellable *cancellable,
+ GError **error,
+ ...)
+{
+ GHashTable *attributes;
+ SecretValue *value;
+ va_list va;
+
+ g_return_val_if_fail (schema != NULL, NULL);
+ g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+ va_start (va, error);
+ attributes = secret_attributes_buildv (schema, va);
+ va_end (va);
+
+ /* Precondition failed, already warned */
+ if (!attributes)
+ return NULL;
+
+ value = secret_password_lookupv_binary_sync (schema, attributes,
+ cancellable, error);
+
+ g_hash_table_unref (attributes);
+
+ return value;
+}
+
+/**
+ * secret_password_lookupv_binary_sync: (skip)
+ * @schema: the schema for attributes
+ * @attributes: (element-type utf8 utf8): the attribute keys and values
+ * @cancellable: optional cancellation object
+ * @error: location to place an error on failure
+ *
+ * Lookup a password in the secret service.
+ *
+ * This is similar to secret_password_lookupv_sync(), but returns a
+ * #SecretValue instead of a null-terminated password.
+ *
+ * This method may block indefinitely and should not be used in user interface
+ * threads.
+ *
+ * Returns: (transfer full): a newly allocated #SecretValue, which should be
+ * released with secret_value_unref(), or %NULL if no secret found
+ *
+ * Since: 0.19.0
+ */
+SecretValue *
+secret_password_lookupv_binary_sync (const SecretSchema *schema,
+ GHashTable *attributes,
+ GCancellable *cancellable,
+ GError **error)
+{
+ SecretSync *sync;
+ SecretValue *value;
+
+ g_return_val_if_fail (schema != NULL, NULL);
+ g_return_val_if_fail (attributes != NULL, NULL);
+ g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+ /* Warnings raised already */
+ if (!_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
+ return FALSE;
+
+ sync = _secret_sync_new ();
+ g_main_context_push_thread_default (sync->context);
+
+ secret_password_lookupv (schema, attributes, cancellable,
+ _secret_sync_on_result, sync);
+
+ g_main_loop_run (sync->loop);
+
+ value = secret_password_lookup_binary_finish (sync->result, error);
+
+ g_main_context_pop_thread_default (sync->context);
+ _secret_sync_free (sync);
+
+ return value;
+}
+
+/**
* secret_password_lookupv_sync: (rename-to secret_password_lookup_sync)
* @schema: the schema for attributes
* @attributes: (element-type utf8 utf8): the attribute keys and values