2012-02-01 12:34:08 +00:00
|
|
|
/* libsecret - GLib wrapper for Secret Service
|
2012-01-11 06:44:32 +00:00
|
|
|
*
|
|
|
|
* Copyright 2011 Collabora Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published
|
|
|
|
* by the Free Software Foundation; either version 2 of the licence or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* See the included COPYING file for more information.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
#include "secret-password.h"
|
|
|
|
#include "secret-private.h"
|
|
|
|
#include "secret-value.h"
|
2012-01-11 06:44:32 +00:00
|
|
|
|
|
|
|
#include <egg/egg-secure-memory.h>
|
|
|
|
|
|
|
|
typedef struct {
|
2012-02-01 12:34:08 +00:00
|
|
|
const SecretSchema *schema;
|
2012-01-16 14:08:29 +00:00
|
|
|
GHashTable *attributes;
|
2012-01-11 06:44:32 +00:00
|
|
|
gchar *collection_path;
|
2012-01-16 14:08:29 +00:00
|
|
|
gchar *label;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretValue *value;
|
2012-01-11 06:44:32 +00:00
|
|
|
GCancellable *cancellable;
|
2012-01-16 14:08:29 +00:00
|
|
|
gboolean created;
|
2012-01-11 06:44:32 +00:00
|
|
|
} StoreClosure;
|
|
|
|
|
|
|
|
static void
|
|
|
|
store_closure_free (gpointer data)
|
|
|
|
{
|
|
|
|
StoreClosure *closure = data;
|
2012-01-16 14:08:29 +00:00
|
|
|
g_hash_table_unref (closure->attributes);
|
2012-01-11 06:44:32 +00:00
|
|
|
g_free (closure->collection_path);
|
2012-01-16 14:08:29 +00:00
|
|
|
g_free (closure->label);
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_value_unref (closure->value);
|
2012-01-16 14:08:29 +00:00
|
|
|
g_clear_object (&closure->cancellable);
|
|
|
|
g_slice_free (StoreClosure, closure);
|
2012-01-11 06:44:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-01-16 14:08:29 +00:00
|
|
|
on_store_complete (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
2012-01-11 06:44:32 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
2012-01-16 14:08:29 +00:00
|
|
|
StoreClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
2012-01-11 06:44:32 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
closure->created = secret_service_store_finish (SECRET_SERVICE (source),
|
2012-01-20 14:10:35 +00:00
|
|
|
result, &error);
|
2012-01-16 14:08:29 +00:00
|
|
|
if (error != NULL)
|
|
|
|
g_simple_async_result_take_error (res, error);
|
2012-01-11 06:44:32 +00:00
|
|
|
|
2012-01-16 14:08:29 +00:00
|
|
|
g_simple_async_result_complete (res);
|
2012-01-11 06:44:32 +00:00
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-01-16 14:08:29 +00:00
|
|
|
on_store_connected (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
2012-01-11 06:44:32 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
StoreClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *service;
|
2012-01-11 06:44:32 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
service = secret_service_get_finish (result, &error);
|
2012-01-11 06:44:32 +00:00
|
|
|
if (error == NULL) {
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_storev (service, closure->schema,
|
2012-01-20 14:10:35 +00:00
|
|
|
closure->attributes,
|
|
|
|
closure->collection_path,
|
|
|
|
closure->label, closure->value,
|
|
|
|
closure->cancellable,
|
|
|
|
on_store_complete,
|
|
|
|
g_object_ref (res));
|
2012-01-16 14:08:29 +00:00
|
|
|
g_object_unref (service);
|
|
|
|
|
2012-01-11 06:44:32 +00:00
|
|
|
} else {
|
|
|
|
g_simple_async_result_take_error (res, error);
|
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_password_store (const SecretSchema *schema,
|
2012-01-11 06:44:32 +00:00
|
|
|
const gchar *collection_path,
|
|
|
|
const gchar *label,
|
|
|
|
const gchar *password,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data,
|
|
|
|
...)
|
|
|
|
{
|
2012-01-16 14:08:29 +00:00
|
|
|
GHashTable *attributes;
|
2012-01-11 06:44:32 +00:00
|
|
|
va_list va;
|
|
|
|
|
|
|
|
g_return_if_fail (schema != NULL);
|
2012-01-16 14:08:29 +00:00
|
|
|
g_return_if_fail (collection_path != NULL);
|
2012-01-11 06:44:32 +00:00
|
|
|
g_return_if_fail (label != NULL);
|
|
|
|
g_return_if_fail (password != NULL);
|
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
|
|
|
va_start (va, user_data);
|
2012-02-01 12:34:08 +00:00
|
|
|
attributes = _secret_util_attributes_for_varargs (schema, va);
|
2012-01-11 06:44:32 +00:00
|
|
|
va_end (va);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_password_storev (schema, collection_path, label, password, attributes,
|
2012-01-16 14:08:29 +00:00
|
|
|
cancellable, callback, user_data);
|
|
|
|
|
|
|
|
g_hash_table_unref (attributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_password_storev (const SecretSchema *schema,
|
2012-01-16 14:08:29 +00:00
|
|
|
const gchar *collection_path,
|
|
|
|
const gchar *label,
|
|
|
|
const gchar *password,
|
|
|
|
GHashTable *attributes,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
StoreClosure *closure;
|
|
|
|
|
|
|
|
g_return_if_fail (schema != NULL);
|
|
|
|
g_return_if_fail (collection_path != NULL);
|
|
|
|
g_return_if_fail (label != NULL);
|
|
|
|
g_return_if_fail (password != NULL);
|
|
|
|
g_return_if_fail (attributes != NULL);
|
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
2012-01-11 06:44:32 +00:00
|
|
|
|
|
|
|
res = g_simple_async_result_new (NULL, callback, user_data,
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_password_storev);
|
2012-01-16 14:08:29 +00:00
|
|
|
closure = g_slice_new0 (StoreClosure);
|
|
|
|
closure->schema = schema;
|
2012-01-11 06:44:32 +00:00
|
|
|
closure->collection_path = g_strdup (collection_path);
|
2012-01-16 14:08:29 +00:00
|
|
|
closure->label = g_strdup (label);
|
2012-02-01 12:34:08 +00:00
|
|
|
closure->value = secret_value_new (password, -1, "text/plain");
|
2012-01-16 14:08:29 +00:00
|
|
|
closure->attributes = g_hash_table_ref (attributes);
|
2012-01-11 06:44:32 +00:00
|
|
|
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
|
|
|
g_simple_async_result_set_op_res_gpointer (res, closure, store_closure_free);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_get (SECRET_SERVICE_OPEN_SESSION, cancellable,
|
2012-01-25 13:26:52 +00:00
|
|
|
on_store_connected, g_object_ref (res));
|
2012-01-11 06:44:32 +00:00
|
|
|
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_password_store_finish (GAsyncResult *result,
|
2012-01-11 06:44:32 +00:00
|
|
|
GError **error)
|
|
|
|
{
|
2012-01-16 14:08:29 +00:00
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
StoreClosure *closure;
|
|
|
|
|
2012-01-11 06:44:32 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
2012-01-16 14:08:29 +00:00
|
|
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, NULL,
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_password_storev), FALSE);
|
2012-01-11 06:44:32 +00:00
|
|
|
|
2012-01-16 14:08:29 +00:00
|
|
|
res = G_SIMPLE_ASYNC_RESULT (result);
|
|
|
|
if (g_simple_async_result_propagate_error (res, error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
closure = g_simple_async_result_get_op_res_gpointer (res);
|
|
|
|
return closure->created;
|
2012-01-11 06:44:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_password_store_sync (const SecretSchema *schema,
|
2012-01-16 14:08:29 +00:00
|
|
|
const gchar *collection_path,
|
2012-01-11 06:44:32 +00:00
|
|
|
const gchar *label,
|
|
|
|
const gchar *password,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error,
|
|
|
|
...)
|
|
|
|
{
|
2012-01-16 14:08:29 +00:00
|
|
|
GHashTable *attributes;
|
|
|
|
va_list va;
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail (schema != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (label != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (password != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
|
|
|
va_start (va, error);
|
2012-02-01 12:34:08 +00:00
|
|
|
attributes = _secret_util_attributes_for_varargs (schema, va);
|
2012-01-16 14:08:29 +00:00
|
|
|
va_end (va);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_password_storev_sync (schema, collection_path, label, password,
|
2012-01-16 14:08:29 +00:00
|
|
|
attributes, cancellable, error);
|
|
|
|
|
|
|
|
g_hash_table_unref (attributes);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_password_storev_sync (const SecretSchema *schema,
|
2012-01-16 14:08:29 +00:00
|
|
|
const gchar *collection_path,
|
|
|
|
const gchar *label,
|
|
|
|
const gchar *password,
|
|
|
|
GHashTable *attributes,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretSync *sync;
|
2012-01-16 14:08:29 +00:00
|
|
|
gboolean ret;
|
|
|
|
|
2012-01-11 06:44:32 +00:00
|
|
|
g_return_val_if_fail (schema != NULL, FALSE);
|
2012-01-16 14:08:29 +00:00
|
|
|
g_return_val_if_fail (collection_path != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (label != NULL, FALSE);
|
2012-01-11 06:44:32 +00:00
|
|
|
g_return_val_if_fail (password != NULL, FALSE);
|
2012-01-16 14:08:29 +00:00
|
|
|
g_return_val_if_fail (attributes != NULL, FALSE);
|
2012-01-11 06:44:32 +00:00
|
|
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
sync = _secret_sync_new ();
|
2012-01-20 14:10:35 +00:00
|
|
|
g_main_context_push_thread_default (sync->context);
|
2012-01-16 14:08:29 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_password_storev (schema, collection_path, label, password, attributes,
|
|
|
|
cancellable, _secret_sync_on_result, sync);
|
2012-01-16 14:08:29 +00:00
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
g_main_loop_run (sync->loop);
|
2012-01-16 14:08:29 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_password_store_finish (sync->result, error);
|
2012-01-16 14:08:29 +00:00
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
g_main_context_pop_thread_default (sync->context);
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_sync_free (sync);
|
2012-01-16 14:08:29 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
GCancellable *cancellable;
|
|
|
|
GHashTable *attributes;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretValue *value;
|
2012-01-16 14:08:29 +00:00
|
|
|
} LookupClosure;
|
|
|
|
|
|
|
|
static void
|
|
|
|
lookup_closure_free (gpointer data)
|
|
|
|
{
|
|
|
|
LookupClosure *closure = data;
|
|
|
|
g_clear_object (&closure->cancellable);
|
|
|
|
g_hash_table_unref (closure->attributes);
|
|
|
|
if (closure->value)
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_value_unref (closure->value);
|
2012-01-16 14:08:29 +00:00
|
|
|
g_slice_free (LookupClosure, closure);
|
2012-01-11 06:44:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_password_lookup (const SecretSchema *schema,
|
2012-01-11 06:44:32 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data,
|
|
|
|
...)
|
|
|
|
{
|
2012-01-16 14:08:29 +00:00
|
|
|
GHashTable *attributes;
|
|
|
|
va_list va;
|
|
|
|
|
2012-01-11 06:44:32 +00:00
|
|
|
g_return_if_fail (schema != NULL);
|
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
2012-01-16 14:08:29 +00:00
|
|
|
va_start (va, user_data);
|
2012-02-01 12:34:08 +00:00
|
|
|
attributes = _secret_util_attributes_for_varargs (schema, va);
|
2012-01-16 14:08:29 +00:00
|
|
|
va_end (va);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_password_lookupv (attributes, cancellable, callback, user_data);
|
2012-01-16 14:08:29 +00:00
|
|
|
|
|
|
|
g_hash_table_unref (attributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_lookup_complete (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
LookupClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
closure->value = secret_service_lookup_finish (SECRET_SERVICE (source),
|
2012-01-20 14:10:35 +00:00
|
|
|
result, &error);
|
2012-01-16 14:08:29 +00:00
|
|
|
|
|
|
|
if (error != NULL)
|
|
|
|
g_simple_async_result_take_error (res, error);
|
|
|
|
|
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_lookup_connected (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
LookupClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *service;
|
2012-01-16 14:08:29 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
service = secret_service_get_finish (result, &error);
|
2012-01-16 14:08:29 +00:00
|
|
|
if (error != NULL) {
|
|
|
|
g_simple_async_result_take_error (res, error);
|
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
|
|
|
|
} else {
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_lookupv (service, closure->attributes, closure->cancellable,
|
2012-01-20 14:10:35 +00:00
|
|
|
on_lookup_complete, g_object_ref (res));
|
2012-01-16 14:08:29 +00:00
|
|
|
g_object_unref (service);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_password_lookupv (GHashTable *attributes,
|
2012-01-16 14:08:29 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
LookupClosure *closure;
|
|
|
|
|
|
|
|
g_return_if_fail (attributes != NULL);
|
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (NULL, callback, user_data,
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_password_lookupv);
|
2012-01-16 14:08:29 +00:00
|
|
|
closure = g_slice_new0 (LookupClosure);
|
|
|
|
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
2012-01-30 17:11:53 +00:00
|
|
|
closure->attributes = g_hash_table_ref (attributes);
|
2012-01-16 14:08:29 +00:00
|
|
|
g_simple_async_result_set_op_res_gpointer (res, closure, lookup_closure_free);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_get (SECRET_SERVICE_OPEN_SESSION, cancellable,
|
2012-01-25 13:26:52 +00:00
|
|
|
on_lookup_connected, g_object_ref (res));
|
2012-01-16 14:08:29 +00:00
|
|
|
|
|
|
|
g_object_unref (res);
|
2012-01-11 06:44:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gchar *
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_password_lookup_finish (GAsyncResult *result,
|
2012-01-11 06:44:32 +00:00
|
|
|
GError **error)
|
|
|
|
{
|
2012-01-16 14:08:29 +00:00
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
LookupClosure *closure;
|
|
|
|
const gchar *content_type;
|
|
|
|
gchar *password = NULL;
|
|
|
|
|
2012-01-11 06:44:32 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2012-01-16 14:08:29 +00:00
|
|
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, NULL,
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_password_lookupv), NULL);
|
2012-01-16 14:08:29 +00:00
|
|
|
|
|
|
|
res = G_SIMPLE_ASYNC_RESULT (result);
|
|
|
|
if (g_simple_async_result_propagate_error (res, error))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
closure = g_simple_async_result_get_op_res_gpointer (res);
|
2012-02-01 12:34:08 +00:00
|
|
|
content_type = secret_value_get_content_type (closure->value);
|
2012-01-16 14:08:29 +00:00
|
|
|
if (content_type && g_str_equal (content_type, "text/plain")) {
|
2012-02-01 12:34:08 +00:00
|
|
|
password = _secret_value_unref_to_password (closure->value);
|
2012-01-16 14:08:29 +00:00
|
|
|
closure->value = NULL;
|
|
|
|
}
|
2012-01-11 06:44:32 +00:00
|
|
|
|
2012-01-16 14:08:29 +00:00
|
|
|
return password;
|
2012-01-11 06:44:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gchar *
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_password_lookup_sync (const SecretSchema *schema,
|
2012-01-11 06:44:32 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error,
|
|
|
|
...)
|
|
|
|
{
|
2012-01-16 14:08:29 +00:00
|
|
|
GHashTable *attributes;
|
|
|
|
gchar *password;
|
|
|
|
va_list va;
|
|
|
|
|
2012-01-11 06:44:32 +00:00
|
|
|
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);
|
|
|
|
|
2012-01-16 14:08:29 +00:00
|
|
|
va_start (va, error);
|
2012-02-01 12:34:08 +00:00
|
|
|
attributes = _secret_util_attributes_for_varargs (schema, va);
|
2012-01-16 14:08:29 +00:00
|
|
|
va_end (va);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
password = secret_password_lookupv_sync (attributes, cancellable, error);
|
2012-01-16 14:08:29 +00:00
|
|
|
|
|
|
|
g_hash_table_unref (attributes);
|
|
|
|
|
|
|
|
return password;
|
2012-01-11 06:44:32 +00:00
|
|
|
}
|
|
|
|
|
2012-01-16 14:08:29 +00:00
|
|
|
gchar *
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_password_lookupv_sync (GHashTable *attributes,
|
2012-01-16 14:08:29 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretSync *sync;
|
2012-01-16 14:08:29 +00:00
|
|
|
gchar *password;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
sync = _secret_sync_new ();
|
2012-01-20 14:10:35 +00:00
|
|
|
g_main_context_push_thread_default (sync->context);
|
2012-01-16 14:08:29 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_password_lookupv (attributes, cancellable,
|
|
|
|
_secret_sync_on_result, sync);
|
2012-01-16 14:08:29 +00:00
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
g_main_loop_run (sync->loop);
|
2012-01-16 14:08:29 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
password = secret_password_lookup_finish (sync->result, error);
|
2012-01-16 14:08:29 +00:00
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
g_main_context_pop_thread_default (sync->context);
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_sync_free (sync);
|
2012-01-16 14:08:29 +00:00
|
|
|
|
|
|
|
return password;
|
|
|
|
}
|
2012-01-11 06:44:32 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
GCancellable *cancellable;
|
|
|
|
GHashTable *attributes;
|
|
|
|
gboolean deleted;
|
|
|
|
} DeleteClosure;
|
|
|
|
|
|
|
|
static void
|
|
|
|
delete_closure_free (gpointer data)
|
|
|
|
{
|
|
|
|
DeleteClosure *closure = data;
|
|
|
|
g_clear_object (&closure->cancellable);
|
|
|
|
g_hash_table_unref (closure->attributes);
|
|
|
|
g_slice_free (DeleteClosure, closure);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_password_remove (const SecretSchema *schema,
|
2012-01-11 06:44:32 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
GHashTable *attributes;
|
|
|
|
va_list va;
|
|
|
|
|
|
|
|
g_return_if_fail (schema != NULL);
|
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
|
|
|
va_start (va, user_data);
|
2012-02-01 12:34:08 +00:00
|
|
|
attributes = _secret_util_attributes_for_varargs (schema, va);
|
2012-01-11 06:44:32 +00:00
|
|
|
va_end (va);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_password_removev (attributes, cancellable,
|
2012-01-11 06:44:32 +00:00
|
|
|
callback, user_data);
|
|
|
|
|
|
|
|
g_hash_table_unref (attributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_delete_complete (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
DeleteClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
closure->deleted = secret_service_remove_finish (SECRET_SERVICE (source),
|
2012-01-20 14:10:35 +00:00
|
|
|
result, &error);
|
2012-01-11 06:44:32 +00:00
|
|
|
if (error != NULL)
|
|
|
|
g_simple_async_result_take_error (res, error);
|
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_delete_connect (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
DeleteClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *service;
|
2012-01-11 06:44:32 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
service = secret_service_get_finish (result, &error);
|
2012-01-11 06:44:32 +00:00
|
|
|
if (error == NULL) {
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_removev (service, closure->attributes,
|
2012-01-20 14:10:35 +00:00
|
|
|
closure->cancellable, on_delete_complete,
|
|
|
|
g_object_ref (res));
|
2012-01-11 06:44:32 +00:00
|
|
|
g_object_unref (service);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
g_simple_async_result_take_error (res, error);
|
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_password_removev (GHashTable *attributes,
|
2012-01-11 06:44:32 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
DeleteClosure *closure;
|
|
|
|
|
|
|
|
g_return_if_fail (attributes != NULL);
|
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (NULL, callback, user_data,
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_password_removev);
|
2012-01-11 06:44:32 +00:00
|
|
|
closure = g_slice_new0 (DeleteClosure);
|
|
|
|
closure->attributes = g_hash_table_ref (attributes);
|
|
|
|
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
|
|
|
g_simple_async_result_set_op_res_gpointer (res, closure, delete_closure_free);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_get (SECRET_SERVICE_NONE, cancellable,
|
2012-01-25 13:26:52 +00:00
|
|
|
on_delete_connect, g_object_ref (res));
|
2012-01-11 06:44:32 +00:00
|
|
|
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_password_remove_finish (GAsyncResult *result,
|
2012-01-11 06:44:32 +00:00
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
DeleteClosure *closure;
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, NULL,
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_password_removev), FALSE);
|
2012-01-11 06:44:32 +00:00
|
|
|
|
|
|
|
res = G_SIMPLE_ASYNC_RESULT (result);
|
|
|
|
if (g_simple_async_result_propagate_error (res, error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
closure = g_simple_async_result_get_op_res_gpointer (res);
|
|
|
|
return closure->deleted;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_password_remove_sync (const SecretSchema* schema,
|
2012-01-11 06:44:32 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
GHashTable *attributes;
|
|
|
|
gboolean result;
|
|
|
|
va_list va;
|
|
|
|
|
|
|
|
g_return_val_if_fail (schema != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
|
|
|
va_start (va, error);
|
2012-02-01 12:34:08 +00:00
|
|
|
attributes = _secret_util_attributes_for_varargs (schema, va);
|
2012-01-11 06:44:32 +00:00
|
|
|
va_end (va);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
result = secret_password_removev_sync (attributes, cancellable, error);
|
2012-01-11 06:44:32 +00:00
|
|
|
|
|
|
|
g_hash_table_unref (attributes);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_password_removev_sync (GHashTable *attributes,
|
2012-01-11 06:44:32 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretSync *sync;
|
2012-01-11 06:44:32 +00:00
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (attributes != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
sync = _secret_sync_new ();
|
2012-01-20 14:10:35 +00:00
|
|
|
g_main_context_push_thread_default (sync->context);
|
2012-01-11 06:44:32 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_password_removev (attributes, cancellable,
|
|
|
|
_secret_sync_on_result, sync);
|
2012-01-11 06:44:32 +00:00
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
g_main_loop_run (sync->loop);
|
2012-01-11 06:44:32 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
result = secret_password_remove_finish (sync->result, error);
|
2012-01-11 06:44:32 +00:00
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
g_main_context_pop_thread_default (sync->context);
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_sync_free (sync);
|
2012-01-11 06:44:32 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_password_free (gpointer password)
|
2012-01-11 06:44:32 +00:00
|
|
|
{
|
|
|
|
if (password == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
egg_secure_strfree (password);
|
|
|
|
}
|