2012-02-01 12:34:08 +00:00
|
|
|
/* libsecret - GLib wrapper for Secret Service
|
2012-01-26 14:34:26 +00:00
|
|
|
*
|
|
|
|
* Copyright 2011 Collabora Ltd.
|
|
|
|
* Copyright 2012 Red Hat Inc.
|
|
|
|
*
|
|
|
|
* 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
|
2012-03-31 13:32:43 +00:00
|
|
|
* by the Free Software Foundation; either version 2.1 of the licence or (at
|
2012-01-26 14:34:26 +00:00
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* See the included COPYING file for more information.
|
2012-03-31 13:32:43 +00:00
|
|
|
*
|
|
|
|
* Author: Stef Walter <stefw@gnome.org>
|
2012-01-26 14:34:26 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
#include "secret-collection.h"
|
|
|
|
#include "secret-dbus-generated.h"
|
|
|
|
#include "secret-item.h"
|
2012-07-05 14:41:28 +00:00
|
|
|
#include "secret-paths.h"
|
2012-02-01 12:34:08 +00:00
|
|
|
#include "secret-private.h"
|
|
|
|
#include "secret-service.h"
|
|
|
|
#include "secret-types.h"
|
|
|
|
#include "secret-value.h"
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-07-06 08:21:04 +00:00
|
|
|
/**
|
|
|
|
* SecretSearchFlags:
|
|
|
|
* @SECRET_SEARCH_NONE: no flags
|
|
|
|
* @SECRET_SEARCH_ALL: all the items matching the search will be returned, instead of just the first one
|
|
|
|
* @SECRET_SEARCH_UNLOCK: unlock locked items while searching
|
|
|
|
* @SECRET_SEARCH_LOAD_SECRETS: while searching load secrets for items that are not locked
|
|
|
|
*
|
|
|
|
* Various flags to be used with secret_service_search() and secret_service_search_sync().
|
|
|
|
*/
|
|
|
|
|
2012-01-26 14:34:26 +00:00
|
|
|
typedef struct {
|
2012-07-05 17:08:09 +00:00
|
|
|
SecretService *service;
|
2012-01-26 14:34:26 +00:00
|
|
|
GCancellable *cancellable;
|
|
|
|
GHashTable *items;
|
|
|
|
gchar **unlocked;
|
|
|
|
gchar **locked;
|
|
|
|
guint loading;
|
2012-07-05 17:08:09 +00:00
|
|
|
SecretSearchFlags flags;
|
2012-07-05 21:14:50 +00:00
|
|
|
GVariant *attributes;
|
2012-01-26 14:34:26 +00:00
|
|
|
} SearchClosure;
|
|
|
|
|
|
|
|
static void
|
|
|
|
search_closure_free (gpointer data)
|
|
|
|
{
|
|
|
|
SearchClosure *closure = data;
|
2012-07-05 17:08:09 +00:00
|
|
|
g_object_unref (closure->service);
|
2012-01-26 14:34:26 +00:00
|
|
|
g_clear_object (&closure->cancellable);
|
|
|
|
g_hash_table_unref (closure->items);
|
2012-07-05 21:14:50 +00:00
|
|
|
g_variant_unref (closure->attributes);
|
2012-01-26 14:34:26 +00:00
|
|
|
g_strfreev (closure->unlocked);
|
|
|
|
g_strfreev (closure->locked);
|
|
|
|
g_slice_free (SearchClosure, closure);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
search_closure_take_item (SearchClosure *closure,
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *item)
|
2012-01-26 14:34:26 +00:00
|
|
|
{
|
|
|
|
const gchar *path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (item));
|
|
|
|
g_hash_table_insert (closure->items, (gpointer)path, item);
|
|
|
|
}
|
|
|
|
|
2012-07-05 17:08:09 +00:00
|
|
|
static GList *
|
|
|
|
search_closure_build_items (SearchClosure *closure,
|
|
|
|
gchar **paths)
|
|
|
|
{
|
|
|
|
GList *results = NULL;
|
|
|
|
SecretItem *item;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; paths[i]; i++) {
|
|
|
|
item = g_hash_table_lookup (closure->items, paths[i]);
|
|
|
|
if (item != NULL)
|
|
|
|
results = g_list_prepend (results, g_object_ref (item));
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_list_reverse (results);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_search_secrets (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
|
|
|
|
/* Note that we ignore any unlock failure */
|
|
|
|
secret_item_load_secrets_finish (result, NULL);
|
|
|
|
|
|
|
|
g_simple_async_result_complete (async);
|
|
|
|
g_object_unref (async);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_search_unlocked (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
SearchClosure *search = g_simple_async_result_get_op_res_gpointer (async);
|
|
|
|
GList *items;
|
|
|
|
|
|
|
|
/* Note that we ignore any unlock failure */
|
|
|
|
secret_service_unlock_finish (search->service, result, NULL, NULL);
|
|
|
|
|
|
|
|
/* If loading secrets ... locked items automatically ignored */
|
|
|
|
if (search->flags & SECRET_SEARCH_LOAD_SECRETS) {
|
|
|
|
items = g_hash_table_get_values (search->items);
|
|
|
|
secret_item_load_secrets (items, search->cancellable,
|
|
|
|
on_search_secrets, g_object_ref (async));
|
|
|
|
g_list_free (items);
|
|
|
|
|
|
|
|
/* No additional options, just complete */
|
|
|
|
} else {
|
|
|
|
g_simple_async_result_complete (async);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (async);
|
|
|
|
}
|
|
|
|
|
2012-07-09 06:46:11 +00:00
|
|
|
static void
|
|
|
|
secret_search_unlock_load_or_complete (GSimpleAsyncResult *async,
|
|
|
|
SearchClosure *search)
|
|
|
|
{
|
|
|
|
GList *items;
|
|
|
|
|
|
|
|
/* If unlocking then unlock all the locked items */
|
|
|
|
if (search->flags & SECRET_SEARCH_UNLOCK) {
|
|
|
|
items = search_closure_build_items (search, search->locked);
|
|
|
|
secret_service_unlock (search->service, items, search->cancellable,
|
|
|
|
on_search_unlocked, g_object_ref (async));
|
|
|
|
g_list_free_full (items, g_object_unref);
|
|
|
|
|
|
|
|
/* If loading secrets ... locked items automatically ignored */
|
|
|
|
} else if (search->flags & SECRET_SEARCH_LOAD_SECRETS) {
|
|
|
|
items = g_hash_table_get_values (search->items);
|
|
|
|
secret_item_load_secrets (items, search->cancellable,
|
|
|
|
on_search_secrets, g_object_ref (async));
|
|
|
|
g_list_free (items);
|
|
|
|
|
|
|
|
/* No additional options, just complete */
|
|
|
|
} else {
|
|
|
|
g_simple_async_result_complete (async);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-26 14:34:26 +00:00
|
|
|
static void
|
|
|
|
on_search_loaded (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
SearchClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
|
|
|
GError *error = NULL;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *item;
|
2012-01-26 14:34:26 +00:00
|
|
|
|
|
|
|
closure->loading--;
|
|
|
|
|
2012-07-06 07:01:20 +00:00
|
|
|
item = secret_item_new_for_dbus_path_finish (result, &error);
|
2012-01-26 14:34:26 +00:00
|
|
|
if (error != NULL)
|
|
|
|
g_simple_async_result_take_error (res, error);
|
|
|
|
|
|
|
|
if (item != NULL)
|
|
|
|
search_closure_take_item (closure, item);
|
2012-07-05 17:08:09 +00:00
|
|
|
|
|
|
|
/* We're done loading, lets go to the next step */
|
2012-07-09 06:46:11 +00:00
|
|
|
if (closure->loading == 0)
|
|
|
|
secret_search_unlock_load_or_complete (res, closure);
|
2012-01-26 14:34:26 +00:00
|
|
|
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
search_load_item_async (SecretService *self,
|
2012-01-26 14:34:26 +00:00
|
|
|
GSimpleAsyncResult *res,
|
|
|
|
SearchClosure *closure,
|
|
|
|
const gchar *path)
|
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *item;
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
item = _secret_service_find_item_instance (self, path);
|
2012-01-26 14:34:26 +00:00
|
|
|
if (item == NULL) {
|
2012-07-06 07:01:20 +00:00
|
|
|
secret_item_new_for_dbus_path (self, path, SECRET_ITEM_NONE, closure->cancellable,
|
|
|
|
on_search_loaded, g_object_ref (res));
|
2012-01-26 14:34:26 +00:00
|
|
|
closure->loading++;
|
|
|
|
} else {
|
|
|
|
search_closure_take_item (closure, item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_search_paths (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
SearchClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
2012-07-05 17:08:09 +00:00
|
|
|
SecretService *self = closure->service;
|
2012-01-26 14:34:26 +00:00
|
|
|
GError *error = NULL;
|
2012-07-05 17:08:09 +00:00
|
|
|
gint want = 1;
|
2012-07-09 06:46:11 +00:00
|
|
|
gint count;
|
|
|
|
gint i;
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-07-06 07:01:20 +00:00
|
|
|
secret_service_search_for_dbus_paths_finish (self, result, &closure->unlocked,
|
|
|
|
&closure->locked, &error);
|
2012-07-05 17:08:09 +00:00
|
|
|
if (error == NULL) {
|
|
|
|
want = 1;
|
|
|
|
if (closure->flags & SECRET_SEARCH_ALL)
|
|
|
|
want = G_MAXINT;
|
2012-07-09 06:46:11 +00:00
|
|
|
count = 0;
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-07-09 06:46:11 +00:00
|
|
|
for (i = 0; count < want && closure->unlocked[i] != NULL; i++, count++)
|
2012-07-05 17:08:09 +00:00
|
|
|
search_load_item_async (self, res, closure, closure->unlocked[i]);
|
2012-07-09 06:46:11 +00:00
|
|
|
for (i = 0; count < want && closure->locked[i] != NULL; i++, count++)
|
2012-07-05 17:08:09 +00:00
|
|
|
search_load_item_async (self, res, closure, closure->locked[i]);
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-07-05 17:08:09 +00:00
|
|
|
/* No items loading, complete operation now */
|
|
|
|
if (closure->loading == 0)
|
2012-07-09 06:46:11 +00:00
|
|
|
secret_search_unlock_load_or_complete (res, closure);
|
2012-07-05 17:08:09 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
g_simple_async_result_take_error (res, error);
|
2012-01-26 14:34:26 +00:00
|
|
|
g_simple_async_result_complete (res);
|
2012-07-05 17:08:09 +00:00
|
|
|
}
|
2012-01-26 14:34:26 +00:00
|
|
|
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
static void
|
|
|
|
on_search_service (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
SearchClosure *search = g_simple_async_result_get_op_res_gpointer (async);
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
search->service = secret_service_get_finish (result, &error);
|
|
|
|
if (error == NULL) {
|
|
|
|
_secret_service_search_for_paths_variant (search->service, search->attributes,
|
|
|
|
search->cancellable, on_search_paths,
|
|
|
|
g_object_ref (async));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
g_simple_async_result_take_error (async, error);
|
|
|
|
g_simple_async_result_complete (async);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (async);
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_service_search:
|
2012-07-05 21:14:50 +00:00
|
|
|
* @service: (allow-none): the secret service
|
2012-07-05 18:29:28 +00:00
|
|
|
* @schema: (allow-none): the schema for the attributes
|
2012-03-11 08:06:40 +00:00
|
|
|
* @attributes: (element-type utf8 utf8): search for items matching these attributes
|
2012-07-05 17:08:09 +00:00
|
|
|
* @flags: search option flags
|
2012-02-02 12:40:47 +00:00
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @callback: called when the operation completes
|
|
|
|
* @user_data: data to pass to the callback
|
|
|
|
*
|
|
|
|
* Search for items matching the @attributes. All collections are searched.
|
|
|
|
* The @attributes should be a table of string keys and string values.
|
|
|
|
*
|
2012-07-05 21:14:50 +00:00
|
|
|
* If @service is NULL, then secret_service_get() will be called to get
|
|
|
|
* the default #SecretService proxy.
|
|
|
|
*
|
2012-07-05 17:08:09 +00:00
|
|
|
* If %SECRET_SEARCH_ALL is set in @flags, then all the items matching the
|
|
|
|
* search will be returned. Otherwise only the first item will be returned.
|
|
|
|
* This is almost always the unlocked item that was most recently stored.
|
2012-03-24 12:31:14 +00:00
|
|
|
*
|
2012-07-05 17:08:09 +00:00
|
|
|
* If %SECRET_SEARCH_UNLOCK is set in @flags, then items will be unlocked
|
|
|
|
* if necessary. In either case, locked and unlocked items will match the
|
|
|
|
* search and be returned. If the unlock fails, the search does not fail.
|
|
|
|
*
|
|
|
|
* If %SECRET_SEARCH_LOAD_SECRETS is set in @flags, then the items will have
|
|
|
|
* their secret values loaded and available via secret_item_get_secret().
|
|
|
|
*
|
|
|
|
* This function returns immediately and completes asynchronously.
|
2012-02-02 12:40:47 +00:00
|
|
|
*/
|
2012-01-26 14:34:26 +00:00
|
|
|
void
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_search (SecretService *service,
|
2012-07-05 18:29:28 +00:00
|
|
|
const SecretSchema *schema,
|
2012-02-02 12:40:47 +00:00
|
|
|
GHashTable *attributes,
|
2012-07-05 17:08:09 +00:00
|
|
|
SecretSearchFlags flags,
|
2012-02-02 12:40:47 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2012-01-26 14:34:26 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
SearchClosure *closure;
|
2012-07-05 21:14:50 +00:00
|
|
|
const gchar *schema_name = NULL;
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_if_fail (service == NULL || SECRET_IS_SERVICE (service));
|
2012-01-26 14:34:26 +00:00
|
|
|
g_return_if_fail (attributes != NULL);
|
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
2012-07-05 18:29:28 +00:00
|
|
|
/* Warnings raised already */
|
2012-07-10 19:37:20 +00:00
|
|
|
if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
|
2012-07-05 18:29:28 +00:00
|
|
|
return;
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
if (schema != NULL && !(schema->flags & SECRET_SCHEMA_DONT_MATCH_NAME))
|
|
|
|
schema_name = schema->name;
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (service), callback, user_data,
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_search);
|
2012-01-26 14:34:26 +00:00
|
|
|
closure = g_slice_new0 (SearchClosure);
|
|
|
|
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
|
|
|
closure->items = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref);
|
2012-07-05 17:08:09 +00:00
|
|
|
closure->flags = flags;
|
2012-07-05 21:14:50 +00:00
|
|
|
closure->attributes = _secret_attributes_to_variant (attributes, schema_name);
|
|
|
|
g_variant_ref_sink (closure->attributes);
|
2012-01-26 14:34:26 +00:00
|
|
|
g_simple_async_result_set_op_res_gpointer (res, closure, search_closure_free);
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
if (service) {
|
|
|
|
closure->service = g_object_ref (service);
|
|
|
|
_secret_service_search_for_paths_variant (closure->service, closure->attributes,
|
|
|
|
closure->cancellable, on_search_paths,
|
|
|
|
g_object_ref (res));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
secret_service_get (SECRET_SERVICE_NONE, cancellable,
|
|
|
|
on_search_service, g_object_ref (res));
|
|
|
|
}
|
2012-01-26 14:34:26 +00:00
|
|
|
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_service_search_finish:
|
2012-07-05 21:14:50 +00:00
|
|
|
* @service: (allow-none): the secret service
|
2012-02-02 12:40:47 +00:00
|
|
|
* @result: asynchronous result passed to callback
|
|
|
|
* @error: location to place error on failure
|
|
|
|
*
|
|
|
|
* Complete asynchronous operation to search for items.
|
|
|
|
*
|
2012-07-05 17:08:09 +00:00
|
|
|
* Returns: (transfer full) (element-type Secret.Item):
|
|
|
|
* a list of items that matched the search
|
2012-02-02 12:40:47 +00:00
|
|
|
*/
|
2012-07-05 17:08:09 +00:00
|
|
|
GList *
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_search_finish (SecretService *service,
|
2012-02-02 12:40:47 +00:00
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
2012-01-26 14:34:26 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
SearchClosure *closure;
|
2012-07-05 17:08:09 +00:00
|
|
|
GList *items;
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_val_if_fail (service == NULL || SECRET_IS_SERVICE (service), FALSE);
|
2012-01-26 14:34:26 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (service),
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_search), FALSE);
|
2012-01-26 14:34:26 +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);
|
2012-07-05 17:08:09 +00:00
|
|
|
if (closure->unlocked)
|
|
|
|
items = search_closure_build_items (closure, closure->unlocked);
|
|
|
|
if (closure->locked)
|
|
|
|
items = g_list_concat (items, search_closure_build_items (closure, closure->locked));
|
|
|
|
return items;
|
2012-01-26 14:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-07-05 21:14:50 +00:00
|
|
|
service_load_items_sync (SecretService *service,
|
2012-01-26 14:34:26 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
gchar **paths,
|
|
|
|
GList **items,
|
2012-07-05 17:08:09 +00:00
|
|
|
gint want,
|
|
|
|
gint *have,
|
2012-01-26 14:34:26 +00:00
|
|
|
GError **error)
|
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *item;
|
2012-01-26 14:34:26 +00:00
|
|
|
guint i;
|
|
|
|
|
2012-07-05 17:08:09 +00:00
|
|
|
for (i = 0; *have < want && paths[i] != NULL; i++) {
|
2012-07-05 21:14:50 +00:00
|
|
|
item = _secret_service_find_item_instance (service, paths[i]);
|
2012-01-26 14:34:26 +00:00
|
|
|
if (item == NULL)
|
2012-07-06 07:01:20 +00:00
|
|
|
item = secret_item_new_for_dbus_path_sync (service, paths[i], SECRET_ITEM_NONE,
|
|
|
|
cancellable, error);
|
2012-01-26 14:34:26 +00:00
|
|
|
if (item == NULL) {
|
|
|
|
return FALSE;
|
2012-07-05 17:08:09 +00:00
|
|
|
|
2012-01-26 14:34:26 +00:00
|
|
|
} else {
|
2012-07-05 17:08:09 +00:00
|
|
|
*items = g_list_prepend (*items, item);
|
|
|
|
(*have)++;
|
2012-01-26 14:34:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_service_search_sync:
|
2012-07-05 21:14:50 +00:00
|
|
|
* @service: (allow-none): the secret service
|
2012-07-05 18:29:28 +00:00
|
|
|
* @schema: (allow-none): the schema for the attributes
|
2012-03-11 08:06:40 +00:00
|
|
|
* @attributes: (element-type utf8 utf8): search for items matching these attributes
|
2012-07-05 17:08:09 +00:00
|
|
|
* @flags: search option flags
|
2012-02-02 12:40:47 +00:00
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @error: location to place error on failure
|
|
|
|
*
|
|
|
|
* Search for items matching the @attributes. All collections are searched.
|
|
|
|
* The @attributes should be a table of string keys and string values.
|
|
|
|
*
|
2012-07-05 21:14:50 +00:00
|
|
|
* If @service is NULL, then secret_service_get_sync() will be called to get
|
|
|
|
* the default #SecretService proxy.
|
|
|
|
*
|
2012-07-05 17:08:09 +00:00
|
|
|
* If %SECRET_SEARCH_ALL is set in @flags, then all the items matching the
|
|
|
|
* search will be returned. Otherwise only the first item will be returned.
|
|
|
|
* This is almost always the unlocked item that was most recently stored.
|
2012-02-02 12:40:47 +00:00
|
|
|
*
|
2012-07-05 17:08:09 +00:00
|
|
|
* If %SECRET_SEARCH_UNLOCK is set in @flags, then items will be unlocked
|
|
|
|
* if necessary. In either case, locked and unlocked items will match the
|
|
|
|
* search and be returned. If the unlock fails, the search does not fail.
|
2012-02-02 12:40:47 +00:00
|
|
|
*
|
2012-07-05 17:08:09 +00:00
|
|
|
* If %SECRET_SEARCH_LOAD_SECRETS is set in @flags, then the items' secret
|
|
|
|
* values will be loaded for any unlocked items. Loaded item secret values
|
|
|
|
* are available via secret_item_get_secret(). If the load of a secret values
|
|
|
|
* fail, then the
|
2012-03-24 12:31:14 +00:00
|
|
|
*
|
2012-07-05 17:08:09 +00:00
|
|
|
* This function may block indefinetely. Use the asynchronous version
|
|
|
|
* in user interface threads.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full) (element-type Secret.Item):
|
|
|
|
* a list of items that matched the search
|
2012-02-02 12:40:47 +00:00
|
|
|
*/
|
2012-07-05 17:08:09 +00:00
|
|
|
GList *
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_search_sync (SecretService *service,
|
2012-07-05 18:29:28 +00:00
|
|
|
const SecretSchema *schema,
|
2012-02-02 12:40:47 +00:00
|
|
|
GHashTable *attributes,
|
2012-07-05 17:08:09 +00:00
|
|
|
SecretSearchFlags flags,
|
2012-02-02 12:40:47 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2012-01-26 14:34:26 +00:00
|
|
|
{
|
|
|
|
gchar **unlocked_paths = NULL;
|
|
|
|
gchar **locked_paths = NULL;
|
2012-07-05 17:08:09 +00:00
|
|
|
GList *items = NULL;
|
|
|
|
GList *locked = NULL;
|
|
|
|
GList *unlocked = NULL;
|
2012-01-26 14:34:26 +00:00
|
|
|
gboolean ret;
|
2012-07-05 17:08:09 +00:00
|
|
|
gint want;
|
|
|
|
gint have;
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_val_if_fail (service == NULL || SECRET_IS_SERVICE (service), NULL);
|
2012-07-05 17:08:09 +00:00
|
|
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-07-05 18:29:28 +00:00
|
|
|
/* Warnings raised already */
|
2012-07-10 19:37:20 +00:00
|
|
|
if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
|
2012-07-05 18:29:28 +00:00
|
|
|
return NULL;
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
if (service == NULL) {
|
|
|
|
service = secret_service_get_sync (SECRET_SERVICE_NONE, cancellable, error);
|
|
|
|
if (service == NULL)
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
g_object_ref (service);
|
|
|
|
}
|
|
|
|
|
2012-07-06 07:01:20 +00:00
|
|
|
if (!secret_service_search_for_dbus_paths_sync (service, schema, attributes, cancellable,
|
|
|
|
&unlocked_paths, &locked_paths, error)) {
|
2012-07-05 21:14:50 +00:00
|
|
|
g_object_unref (service);
|
2012-07-05 17:08:09 +00:00
|
|
|
return NULL;
|
2012-07-05 21:14:50 +00:00
|
|
|
}
|
2012-01-26 14:34:26 +00:00
|
|
|
|
|
|
|
ret = TRUE;
|
|
|
|
|
2012-07-05 17:08:09 +00:00
|
|
|
want = 1;
|
|
|
|
if (flags & SECRET_SEARCH_ALL)
|
|
|
|
want = G_MAXINT;
|
|
|
|
have = 0;
|
|
|
|
|
|
|
|
/* Remember, we're adding to the list backwards */
|
|
|
|
|
|
|
|
if (unlocked_paths) {
|
2012-07-05 21:14:50 +00:00
|
|
|
ret = service_load_items_sync (service, cancellable, unlocked_paths,
|
2012-07-05 17:08:09 +00:00
|
|
|
&unlocked, want, &have, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret && locked_paths) {
|
2012-07-05 21:14:50 +00:00
|
|
|
ret = service_load_items_sync (service, cancellable, locked_paths,
|
2012-07-05 17:08:09 +00:00
|
|
|
&locked, want, &have, error);
|
|
|
|
}
|
2012-01-26 14:34:26 +00:00
|
|
|
|
|
|
|
g_strfreev (unlocked_paths);
|
|
|
|
g_strfreev (locked_paths);
|
|
|
|
|
2012-07-05 17:08:09 +00:00
|
|
|
if (!ret) {
|
|
|
|
g_list_free_full (unlocked, g_object_unref);
|
|
|
|
g_list_free_full (locked, g_object_unref);
|
2012-07-05 21:14:50 +00:00
|
|
|
g_object_unref (service);
|
2012-07-05 17:08:09 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The lists are backwards at this point ... */
|
|
|
|
items = g_list_concat (items, g_list_copy (locked));
|
|
|
|
items = g_list_concat (items, g_list_copy (unlocked));
|
|
|
|
items = g_list_reverse (items);
|
|
|
|
|
|
|
|
if (flags & SECRET_SEARCH_UNLOCK)
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_unlock_sync (service, locked, cancellable, NULL, NULL);
|
2012-07-05 17:08:09 +00:00
|
|
|
|
|
|
|
if (flags & SECRET_SEARCH_LOAD_SECRETS)
|
|
|
|
secret_item_load_secrets_sync (items, NULL, NULL);
|
|
|
|
|
|
|
|
g_list_free (locked);
|
|
|
|
g_list_free (unlocked);
|
2012-07-05 21:14:50 +00:00
|
|
|
g_object_unref (service);
|
2012-07-05 17:08:09 +00:00
|
|
|
return items;
|
2012-01-26 14:34:26 +00:00
|
|
|
}
|
|
|
|
|
2012-07-05 14:41:28 +00:00
|
|
|
SecretValue *
|
|
|
|
_secret_service_decode_get_secrets_first (SecretService *self,
|
|
|
|
GVariant *out)
|
2012-01-26 14:34:26 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretSession *session;
|
|
|
|
SecretValue *value = NULL;
|
2012-01-26 14:34:26 +00:00
|
|
|
GVariantIter *iter;
|
|
|
|
GVariant *variant;
|
|
|
|
const gchar *path;
|
|
|
|
|
|
|
|
g_variant_get (out, "(a{o(oayays)})", &iter);
|
|
|
|
while (g_variant_iter_next (iter, "{&o@(oayays)}", &path, &variant)) {
|
2012-02-01 12:34:08 +00:00
|
|
|
session = _secret_service_get_session (self);
|
|
|
|
value = _secret_session_decode_secret (session, variant);
|
2012-01-26 14:34:26 +00:00
|
|
|
g_variant_unref (variant);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_variant_iter_free (iter);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2012-07-05 14:41:28 +00:00
|
|
|
GHashTable *
|
|
|
|
_secret_service_decode_get_secrets_all (SecretService *self,
|
|
|
|
GVariant *out)
|
2012-01-26 14:34:26 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretSession *session;
|
2012-01-26 14:34:26 +00:00
|
|
|
GVariantIter *iter;
|
|
|
|
GVariant *variant;
|
|
|
|
GHashTable *values;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretValue *value;
|
2012-01-26 14:34:26 +00:00
|
|
|
gchar *path;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
session = _secret_service_get_session (self);
|
2012-01-26 14:34:26 +00:00
|
|
|
values = g_hash_table_new_full (g_str_hash, g_str_equal,
|
2012-02-01 12:34:08 +00:00
|
|
|
g_free, secret_value_unref);
|
2012-01-26 14:34:26 +00:00
|
|
|
g_variant_get (out, "(a{o(oayays)})", &iter);
|
|
|
|
while (g_variant_iter_loop (iter, "{o@(oayays)}", &path, &variant)) {
|
2012-02-01 12:34:08 +00:00
|
|
|
value = _secret_session_decode_secret (session, variant);
|
2012-01-26 14:34:26 +00:00
|
|
|
if (value && path)
|
|
|
|
g_hash_table_insert (values, g_strdup (path), value);
|
|
|
|
}
|
|
|
|
g_variant_iter_free (iter);
|
|
|
|
return values;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
2012-07-05 21:14:50 +00:00
|
|
|
GCancellable *cancellable;
|
|
|
|
GPtrArray *paths;
|
2012-01-26 14:34:26 +00:00
|
|
|
GHashTable *objects;
|
2012-07-05 17:03:37 +00:00
|
|
|
gchar **xlocked;
|
|
|
|
guint count;
|
|
|
|
gboolean locking;
|
2012-01-26 14:34:26 +00:00
|
|
|
} XlockClosure;
|
|
|
|
|
|
|
|
static void
|
|
|
|
xlock_closure_free (gpointer data)
|
|
|
|
{
|
|
|
|
XlockClosure *closure = data;
|
2012-07-05 21:14:50 +00:00
|
|
|
if (closure->cancellable)
|
|
|
|
g_object_unref (closure->cancellable);
|
|
|
|
g_ptr_array_free (closure->paths, TRUE);
|
2012-07-05 17:03:37 +00:00
|
|
|
g_strfreev (closure->xlocked);
|
|
|
|
g_hash_table_unref (closure->objects);
|
2012-01-26 14:34:26 +00:00
|
|
|
g_slice_free (XlockClosure, closure);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-07-05 17:03:37 +00:00
|
|
|
on_xlock_paths (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
2012-01-26 14:34:26 +00:00
|
|
|
{
|
2012-07-05 17:03:37 +00:00
|
|
|
GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
XlockClosure *xlock = g_simple_async_result_get_op_res_gpointer (async);
|
|
|
|
GVariant *lockval;
|
|
|
|
GDBusProxy *object;
|
2012-01-26 14:34:26 +00:00
|
|
|
GError *error = NULL;
|
2012-07-05 17:03:37 +00:00
|
|
|
gint i;
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-07-05 17:03:37 +00:00
|
|
|
xlock->count = _secret_service_xlock_paths_finish (SECRET_SERVICE (source), result,
|
|
|
|
&xlock->xlocked, &error);
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-07-05 17:03:37 +00:00
|
|
|
if (error == NULL) {
|
|
|
|
/*
|
|
|
|
* After a lock or unlock we want the Locked property to immediately
|
|
|
|
* reflect the new state, and not have to wait for a PropertiesChanged
|
|
|
|
* signal to be processed later.
|
|
|
|
*/
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-07-05 17:03:37 +00:00
|
|
|
lockval = g_variant_ref_sink (g_variant_new_boolean (xlock->locking));
|
|
|
|
for (i = 0; xlock->xlocked[i] != NULL; i++) {
|
|
|
|
object = g_hash_table_lookup (xlock->objects, xlock->xlocked[i]);
|
|
|
|
if (object != NULL)
|
|
|
|
g_dbus_proxy_set_cached_property (object, "Locked", lockval);
|
2012-01-26 14:34:26 +00:00
|
|
|
}
|
2012-07-05 17:03:37 +00:00
|
|
|
g_variant_unref (lockval);
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-07-05 17:03:37 +00:00
|
|
|
} else {
|
|
|
|
g_simple_async_result_take_error (async, error);
|
2012-01-26 14:34:26 +00:00
|
|
|
}
|
|
|
|
|
2012-07-05 17:03:37 +00:00
|
|
|
g_simple_async_result_complete (async);
|
|
|
|
g_object_unref (async);
|
2012-01-26 14:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-07-05 21:14:50 +00:00
|
|
|
on_xlock_service (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
XlockClosure *xlock = g_simple_async_result_get_op_res_gpointer (async);
|
|
|
|
GError *error = NULL;
|
|
|
|
SecretService *service;
|
|
|
|
|
|
|
|
service = secret_service_get_finish (result, &error);
|
|
|
|
if (error == NULL) {
|
|
|
|
_secret_service_xlock_paths_async (service, xlock->locking ? "Lock" : "Unlock",
|
|
|
|
(const gchar **)xlock->paths->pdata,
|
|
|
|
xlock->cancellable, on_xlock_paths,
|
|
|
|
g_object_ref (async));
|
|
|
|
g_object_unref (service);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
g_simple_async_result_take_error (async, error);
|
|
|
|
g_simple_async_result_complete (async);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (async);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
service_xlock_async (SecretService *service,
|
2012-07-05 17:03:37 +00:00
|
|
|
gboolean locking,
|
2012-01-26 14:34:26 +00:00
|
|
|
GList *objects,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2012-07-05 17:03:37 +00:00
|
|
|
GSimpleAsyncResult *async;
|
|
|
|
XlockClosure *xlock;
|
2012-01-26 14:34:26 +00:00
|
|
|
const gchar *path;
|
|
|
|
GList *l;
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
async = g_simple_async_result_new (G_OBJECT (service), callback, user_data,
|
2012-07-05 17:03:37 +00:00
|
|
|
service_xlock_async);
|
|
|
|
xlock = g_slice_new0 (XlockClosure);
|
|
|
|
xlock->objects = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
|
|
|
|
xlock->locking = locking;
|
2012-07-05 21:14:50 +00:00
|
|
|
xlock->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
|
|
|
xlock->paths = g_ptr_array_new ();
|
2012-01-26 14:34:26 +00:00
|
|
|
|
|
|
|
for (l = objects; l != NULL; l = g_list_next (l)) {
|
|
|
|
path = g_dbus_proxy_get_object_path (l->data);
|
2012-07-05 21:14:50 +00:00
|
|
|
g_ptr_array_add (xlock->paths, (gpointer)path);
|
2012-07-05 17:03:37 +00:00
|
|
|
g_hash_table_insert (xlock->objects, g_strdup (path), g_object_ref (l->data));
|
2012-01-26 14:34:26 +00:00
|
|
|
}
|
2012-07-05 21:14:50 +00:00
|
|
|
g_ptr_array_add (xlock->paths, NULL);
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-07-05 17:03:37 +00:00
|
|
|
g_simple_async_result_set_op_res_gpointer (async, xlock, xlock_closure_free);
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
if (service == NULL) {
|
|
|
|
secret_service_get (SECRET_SERVICE_NONE, cancellable,
|
|
|
|
on_xlock_service, g_object_ref (async));
|
|
|
|
} else {
|
|
|
|
_secret_service_xlock_paths_async (service, xlock->locking ? "Lock" : "Unlock",
|
|
|
|
(const gchar **)xlock->paths->pdata,
|
|
|
|
xlock->cancellable, on_xlock_paths,
|
|
|
|
g_object_ref (async));
|
|
|
|
}
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-07-05 17:03:37 +00:00
|
|
|
g_object_unref (async);
|
2012-01-26 14:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2012-07-05 21:14:50 +00:00
|
|
|
service_xlock_finish (SecretService *service,
|
2012-01-26 14:34:26 +00:00
|
|
|
GAsyncResult *result,
|
|
|
|
GList **xlocked,
|
|
|
|
GError **error)
|
|
|
|
{
|
2012-07-05 17:03:37 +00:00
|
|
|
GSimpleAsyncResult *async;
|
|
|
|
XlockClosure *xlock;
|
|
|
|
GDBusProxy *object;
|
|
|
|
gint i;
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (service),
|
|
|
|
service_xlock_async), -1);
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-07-05 17:03:37 +00:00
|
|
|
async = G_SIMPLE_ASYNC_RESULT (result);
|
|
|
|
if (g_simple_async_result_propagate_error (async, error))
|
|
|
|
return -1;
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-07-05 17:03:37 +00:00
|
|
|
xlock = g_simple_async_result_get_op_res_gpointer (async);
|
|
|
|
if (xlocked) {
|
|
|
|
*xlocked = NULL;
|
|
|
|
for (i = 0; xlock->xlocked[i] != NULL; i++) {
|
|
|
|
object = g_hash_table_lookup (xlock->objects, xlock->xlocked[i]);
|
2012-01-26 14:34:26 +00:00
|
|
|
if (object != NULL)
|
|
|
|
*xlocked = g_list_prepend (*xlocked, g_object_ref (object));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-05 17:03:37 +00:00
|
|
|
return xlock->count;
|
2012-01-26 14:34:26 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_service_lock:
|
2012-07-05 21:14:50 +00:00
|
|
|
* @service: (allow-none): the secret service
|
2012-02-02 12:40:47 +00:00
|
|
|
* @objects: (element-type GLib.DBusProxy): the items or collections to lock
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @callback: called when the operation completes
|
|
|
|
* @user_data: data to pass to the callback
|
|
|
|
*
|
|
|
|
* Lock items or collections in the secret service.
|
|
|
|
*
|
|
|
|
* The secret service may not be able to lock items individually, and may
|
|
|
|
* lock an entire collection instead.
|
|
|
|
*
|
2012-07-05 21:14:50 +00:00
|
|
|
* If @service is NULL, then secret_service_get() will be called to get
|
|
|
|
* the default #SecretService proxy.
|
|
|
|
*
|
2012-02-02 12:40:47 +00:00
|
|
|
* This method returns immediately and completes asynchronously. The secret
|
|
|
|
* service may prompt the user. secret_service_prompt() will be used to handle
|
|
|
|
* any prompts that show up.
|
|
|
|
*/
|
2012-01-26 14:34:26 +00:00
|
|
|
void
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_lock (SecretService *service,
|
2012-02-02 12:40:47 +00:00
|
|
|
GList *objects,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2012-01-26 14:34:26 +00:00
|
|
|
{
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_if_fail (service == NULL || SECRET_IS_SERVICE (service));
|
2012-01-26 14:34:26 +00:00
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
service_xlock_async (service, TRUE, objects, cancellable, callback, user_data);
|
2012-01-26 14:34:26 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_service_lock_finish:
|
2012-07-05 21:14:50 +00:00
|
|
|
* @service: (allow-none): the secret service
|
2012-02-02 12:40:47 +00:00
|
|
|
* @result: asynchronous result passed to the callback
|
|
|
|
* @locked: (out) (element-type GLib.DBusProxy) (transfer full) (allow-none):
|
|
|
|
* location to place list of items or collections that were locked
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Complete asynchronous operation to lock items or collections in the secret
|
|
|
|
* service.
|
|
|
|
*
|
|
|
|
* The secret service may not be able to lock items individually, and may
|
|
|
|
* lock an entire collection instead.
|
|
|
|
*
|
|
|
|
* Returns: the number of items or collections that were locked
|
|
|
|
*/
|
2012-01-26 14:34:26 +00:00
|
|
|
gint
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_lock_finish (SecretService *service,
|
2012-02-02 12:40:47 +00:00
|
|
|
GAsyncResult *result,
|
|
|
|
GList **locked,
|
|
|
|
GError **error)
|
2012-01-26 14:34:26 +00:00
|
|
|
{
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_val_if_fail (service == NULL || SECRET_IS_SERVICE (service), -1);
|
2012-07-05 17:03:37 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, -1);
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
return service_xlock_finish (service, result, locked, error);
|
2012-01-26 14:34:26 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_service_lock_sync:
|
2012-07-05 21:14:50 +00:00
|
|
|
* @service: (allow-none): the secret service
|
2012-02-02 12:40:47 +00:00
|
|
|
* @objects: (element-type GLib.DBusProxy): the items or collections to lock
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @locked: (out) (element-type GLib.DBusProxy) (transfer full) (allow-none):
|
|
|
|
* location to place list of items or collections that were locked
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Lock items or collections in the secret service.
|
|
|
|
*
|
|
|
|
* The secret service may not be able to lock items individually, and may
|
|
|
|
* lock an entire collection instead.
|
|
|
|
*
|
2012-07-05 21:14:50 +00:00
|
|
|
* If @service is NULL, then secret_service_get_sync() will be called to get
|
|
|
|
* the default #SecretService proxy.
|
|
|
|
*
|
2012-02-02 12:40:47 +00:00
|
|
|
* This method may block indefinitely and should not be used in user
|
|
|
|
* interface threads. The secret service may prompt the user.
|
|
|
|
* secret_service_prompt() will be used to handle any prompts that show up.
|
|
|
|
*
|
|
|
|
* Returns: the number of items or collections that were locked
|
|
|
|
*/
|
2012-01-26 14:34:26 +00:00
|
|
|
gint
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_lock_sync (SecretService *service,
|
2012-02-02 12:40:47 +00:00
|
|
|
GList *objects,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GList **locked,
|
|
|
|
GError **error)
|
2012-01-26 14:34:26 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretSync *sync;
|
2012-01-26 14:34:26 +00:00
|
|
|
gint count;
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_val_if_fail (service == NULL || SECRET_IS_SERVICE (service), -1);
|
2012-01-26 14:34:26 +00:00
|
|
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), -1);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, -1);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
sync = _secret_sync_new ();
|
2012-01-26 14:34:26 +00:00
|
|
|
g_main_context_push_thread_default (sync->context);
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_lock (service, objects, cancellable,
|
|
|
|
_secret_sync_on_result, sync);
|
2012-01-26 14:34:26 +00:00
|
|
|
|
|
|
|
g_main_loop_run (sync->loop);
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
count = secret_service_lock_finish (service, sync->result, locked, error);
|
2012-01-26 14:34:26 +00:00
|
|
|
|
|
|
|
g_main_context_pop_thread_default (sync->context);
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_sync_free (sync);
|
2012-01-26 14:34:26 +00:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
2012-07-05 14:41:28 +00:00
|
|
|
* secret_service_unlock:
|
2012-07-05 21:14:50 +00:00
|
|
|
* @service: (allow-none): the secret service
|
2012-07-05 14:41:28 +00:00
|
|
|
* @objects: (element-type GLib.DBusProxy): the items or collections to unlock
|
2012-02-02 12:40:47 +00:00
|
|
|
* @cancellable: optional cancellation object
|
2012-07-05 14:41:28 +00:00
|
|
|
* @callback: called when the operation completes
|
|
|
|
* @user_data: data to pass to the callback
|
2012-02-02 12:40:47 +00:00
|
|
|
*
|
2012-07-05 14:41:28 +00:00
|
|
|
* Unlock items or collections in the secret service.
|
2012-02-02 12:40:47 +00:00
|
|
|
*
|
2012-07-05 14:41:28 +00:00
|
|
|
* The secret service may not be able to unlock items individually, and may
|
|
|
|
* unlock an entire collection instead.
|
2012-02-02 12:40:47 +00:00
|
|
|
*
|
2012-07-05 21:14:50 +00:00
|
|
|
* If @service is NULL, then secret_service_get() will be called to get
|
|
|
|
* the default #SecretService proxy.
|
|
|
|
*
|
2012-02-02 12:40:47 +00:00
|
|
|
* This method may block indefinitely and should not be used in user
|
|
|
|
* interface threads. The secret service may prompt the user.
|
|
|
|
* secret_service_prompt() will be used to handle any prompts that show up.
|
|
|
|
*/
|
2012-01-26 14:34:26 +00:00
|
|
|
void
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_unlock (SecretService *service,
|
2012-07-05 14:41:28 +00:00
|
|
|
GList *objects,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2012-01-26 14:34:26 +00:00
|
|
|
{
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_if_fail (service == NULL || SECRET_IS_SERVICE (service));
|
2012-01-26 14:34:26 +00:00
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
service_xlock_async (service, FALSE, objects, cancellable, callback, user_data);
|
2012-01-26 14:34:26 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
2012-07-05 14:41:28 +00:00
|
|
|
* secret_service_unlock_finish:
|
2012-07-05 21:14:50 +00:00
|
|
|
* @service: (allow-none): the secret service
|
2012-02-02 12:40:47 +00:00
|
|
|
* @result: asynchronous result passed to the callback
|
2012-07-05 14:41:28 +00:00
|
|
|
* @unlocked: (out) (element-type GLib.DBusProxy) (transfer full) (allow-none):
|
|
|
|
* location to place list of items or collections that were unlocked
|
2012-02-02 12:40:47 +00:00
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
2012-07-05 14:41:28 +00:00
|
|
|
* Complete asynchronous operation to unlock items or collections in the secret
|
2012-02-02 12:40:47 +00:00
|
|
|
* service.
|
|
|
|
*
|
2012-07-05 14:41:28 +00:00
|
|
|
* The secret service may not be able to unlock items individually, and may
|
|
|
|
* unlock an entire collection instead.
|
2012-02-02 12:40:47 +00:00
|
|
|
*
|
2012-07-05 14:41:28 +00:00
|
|
|
* Returns: the number of items or collections that were unlocked
|
2012-02-02 12:40:47 +00:00
|
|
|
*/
|
2012-01-26 14:34:26 +00:00
|
|
|
gint
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_unlock_finish (SecretService *service,
|
2012-07-05 14:41:28 +00:00
|
|
|
GAsyncResult *result,
|
|
|
|
GList **unlocked,
|
|
|
|
GError **error)
|
2012-01-26 14:34:26 +00:00
|
|
|
{
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_val_if_fail (service == NULL || SECRET_IS_SERVICE (service), -1);
|
2012-01-26 14:34:26 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, -1);
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
return service_xlock_finish (service, result, unlocked, error);
|
2012-01-26 14:34:26 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
2012-07-05 14:41:28 +00:00
|
|
|
* secret_service_unlock_sync:
|
2012-07-05 21:14:50 +00:00
|
|
|
* @service: (allow-none): the secret service
|
2012-07-05 14:41:28 +00:00
|
|
|
* @objects: (element-type GLib.DBusProxy): the items or collections to unlock
|
2012-02-02 12:40:47 +00:00
|
|
|
* @cancellable: optional cancellation object
|
2012-07-05 14:41:28 +00:00
|
|
|
* @unlocked: (out) (element-type GLib.DBusProxy) (transfer full) (allow-none):
|
|
|
|
* location to place list of items or collections that were unlocked
|
2012-02-02 12:40:47 +00:00
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Unlock items or collections in the secret service.
|
|
|
|
*
|
|
|
|
* The secret service may not be able to unlock items individually, and may
|
|
|
|
* unlock an entire collection instead.
|
|
|
|
*
|
2012-07-05 21:14:50 +00:00
|
|
|
* If @service is NULL, then secret_service_get_sync() will be called to get
|
|
|
|
* the default #SecretService proxy.
|
|
|
|
*
|
2012-02-02 12:40:47 +00:00
|
|
|
* This method may block indefinitely and should not be used in user
|
|
|
|
* interface threads. The secret service may prompt the user.
|
|
|
|
* secret_service_prompt() will be used to handle any prompts that show up.
|
|
|
|
*
|
|
|
|
* Returns: the number of items or collections that were unlocked
|
|
|
|
*/
|
2012-01-26 14:34:26 +00:00
|
|
|
gint
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_unlock_sync (SecretService *service,
|
2012-02-02 12:40:47 +00:00
|
|
|
GList *objects,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GList **unlocked,
|
|
|
|
GError **error)
|
2012-01-26 14:34:26 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretSync *sync;
|
2012-01-26 14:34:26 +00:00
|
|
|
gint count;
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_val_if_fail (service == NULL || SECRET_IS_SERVICE (service), -1);
|
2012-01-26 14:34:26 +00:00
|
|
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), -1);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, -1);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
sync = _secret_sync_new ();
|
2012-01-26 14:34:26 +00:00
|
|
|
g_main_context_push_thread_default (sync->context);
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_unlock (service, objects, cancellable,
|
|
|
|
_secret_sync_on_result, sync);
|
2012-01-26 14:34:26 +00:00
|
|
|
|
|
|
|
g_main_loop_run (sync->loop);
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
count = secret_service_unlock_finish (service, sync->result, unlocked, error);
|
2012-01-26 14:34:26 +00:00
|
|
|
|
|
|
|
g_main_context_pop_thread_default (sync->context);
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_sync_free (sync);
|
2012-01-26 14:34:26 +00:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
typedef struct {
|
|
|
|
GCancellable *cancellable;
|
|
|
|
gchar *collection_path;
|
|
|
|
SecretValue *value;
|
|
|
|
GHashTable *properties;
|
|
|
|
} StoreClosure;
|
|
|
|
|
|
|
|
static void
|
|
|
|
store_closure_free (gpointer data)
|
|
|
|
{
|
|
|
|
StoreClosure *store = data;
|
|
|
|
if (store->cancellable)
|
|
|
|
g_object_unref (store->cancellable);
|
|
|
|
g_free (store->collection_path);
|
|
|
|
secret_value_unref (store->value);
|
|
|
|
g_hash_table_unref (store->properties);
|
|
|
|
g_slice_free (StoreClosure, store);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_store_create (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
GError *error = NULL;
|
|
|
|
gchar *path;
|
|
|
|
|
2012-07-06 07:01:20 +00:00
|
|
|
path = secret_service_create_item_dbus_path_finish (SECRET_SERVICE (source), result, &error);
|
2012-07-05 21:14:50 +00:00
|
|
|
if (error != NULL)
|
|
|
|
g_simple_async_result_take_error (async, error);
|
|
|
|
g_free (path);
|
|
|
|
|
|
|
|
g_simple_async_result_complete (async);
|
|
|
|
g_object_unref (async);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_store_service (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
StoreClosure *store = g_simple_async_result_get_op_res_gpointer (async);
|
|
|
|
SecretService *service;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
service = secret_service_get_finish (result, &error);
|
|
|
|
if (error == NULL) {
|
2012-07-06 07:01:20 +00:00
|
|
|
secret_service_create_item_dbus_path (service, store->collection_path,
|
|
|
|
store->properties, store->value,
|
|
|
|
TRUE, store->cancellable,
|
|
|
|
on_store_create, g_object_ref (async));
|
2012-07-05 21:14:50 +00:00
|
|
|
g_object_unref (service);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
g_simple_async_result_take_error (async, error);
|
|
|
|
g_simple_async_result_complete (async);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (async);
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_service_store:
|
2012-07-05 21:14:50 +00:00
|
|
|
* @service: (allow-none): the secret service
|
2012-06-28 11:15:06 +00:00
|
|
|
* @schema: (allow-none): the schema to use to check attributes
|
|
|
|
* @attributes: (element-type utf8 utf8): the attribute keys and values
|
2012-07-06 07:42:08 +00:00
|
|
|
* @collection: (allow-none): a collection alias, or D-Bus object path of the collection where to store the secret
|
2012-02-02 12:40:47 +00:00
|
|
|
* @label: label for the secret
|
|
|
|
* @value: the secret value
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @callback: called when the operation completes
|
|
|
|
* @user_data: data to be passed to the callback
|
|
|
|
*
|
|
|
|
* Store a secret value in the secret service.
|
|
|
|
*
|
2012-06-28 11:15:06 +00:00
|
|
|
* The @attributes should be a set of key and value string pairs.
|
2012-02-02 12:40:47 +00:00
|
|
|
*
|
|
|
|
* If the attributes match a secret item already stored in the collection, then
|
|
|
|
* the item will be updated with these new values.
|
|
|
|
*
|
2012-07-05 21:14:50 +00:00
|
|
|
* If @service is NULL, then secret_service_get() will be called to get
|
|
|
|
* the default #SecretService proxy.
|
|
|
|
*
|
2012-07-06 07:42:08 +00:00
|
|
|
* If @collection is not specified, then the default collection will be
|
2012-03-11 12:35:43 +00:00
|
|
|
* used. Use #SECRET_COLLECTION_SESSION to store the password in the session
|
|
|
|
* collection, which doesn't get stored across login sessions.
|
|
|
|
*
|
2012-02-02 12:40:47 +00:00
|
|
|
* This method will return immediately and complete asynchronously.
|
|
|
|
*/
|
2012-01-26 14:34:26 +00:00
|
|
|
void
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_store (SecretService *service,
|
2012-02-02 12:40:47 +00:00
|
|
|
const SecretSchema *schema,
|
2012-06-28 11:15:06 +00:00
|
|
|
GHashTable *attributes,
|
2012-07-06 07:42:08 +00:00
|
|
|
const gchar *collection,
|
2012-02-02 12:40:47 +00:00
|
|
|
const gchar *label,
|
|
|
|
SecretValue *value,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
2012-06-28 11:15:06 +00:00
|
|
|
gpointer user_data)
|
2012-01-26 14:34:26 +00:00
|
|
|
{
|
2012-07-05 21:14:50 +00:00
|
|
|
GSimpleAsyncResult *async;
|
|
|
|
StoreClosure *store;
|
2012-03-25 10:22:10 +00:00
|
|
|
const gchar *schema_name;
|
2012-01-30 13:14:39 +00:00
|
|
|
GVariant *propval;
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_if_fail (service == NULL || SECRET_IS_SERVICE (service));
|
2012-01-26 14:34:26 +00:00
|
|
|
g_return_if_fail (attributes != NULL);
|
|
|
|
g_return_if_fail (label != NULL);
|
|
|
|
g_return_if_fail (value != NULL);
|
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
2012-03-11 08:06:40 +00:00
|
|
|
/* Warnings raised already */
|
2012-07-10 19:37:20 +00:00
|
|
|
if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, FALSE))
|
2012-03-11 08:06:40 +00:00
|
|
|
return;
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
async = g_simple_async_result_new (G_OBJECT (service), callback, user_data,
|
|
|
|
secret_service_store);
|
|
|
|
store = g_slice_new0 (StoreClosure);
|
2012-07-06 07:42:08 +00:00
|
|
|
store->collection_path = _secret_util_collection_to_path (collection);
|
2012-07-05 21:14:50 +00:00
|
|
|
store->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
|
|
|
store->value = secret_value_ref (value);
|
|
|
|
store->properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
|
|
|
|
(GDestroyNotify)g_variant_unref);
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-01-30 13:14:39 +00:00
|
|
|
propval = g_variant_new_string (label);
|
2012-07-05 21:14:50 +00:00
|
|
|
g_hash_table_insert (store->properties,
|
2012-02-01 12:34:08 +00:00
|
|
|
SECRET_ITEM_INTERFACE ".Label",
|
2012-01-30 13:14:39 +00:00
|
|
|
g_variant_ref_sink (propval));
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-03-18 18:04:44 +00:00
|
|
|
/* Always store the schema name in the attributes */
|
2012-03-25 10:22:10 +00:00
|
|
|
schema_name = (schema == NULL) ? NULL : schema->name;
|
2012-06-28 11:15:06 +00:00
|
|
|
propval = _secret_attributes_to_variant (attributes, schema_name);
|
2012-07-05 21:14:50 +00:00
|
|
|
g_hash_table_insert (store->properties,
|
2012-02-01 12:34:08 +00:00
|
|
|
SECRET_ITEM_INTERFACE ".Attributes",
|
2012-01-30 13:14:39 +00:00
|
|
|
g_variant_ref_sink (propval));
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
g_simple_async_result_set_op_res_gpointer (async, store, store_closure_free);
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
if (service == NULL) {
|
|
|
|
secret_service_get (SECRET_SERVICE_OPEN_SESSION, cancellable,
|
|
|
|
on_store_service, g_object_ref (async));
|
|
|
|
|
|
|
|
} else {
|
2012-07-06 07:01:20 +00:00
|
|
|
secret_service_create_item_dbus_path (service, store->collection_path,
|
|
|
|
store->properties, store->value,
|
|
|
|
TRUE, store->cancellable,
|
|
|
|
on_store_create, g_object_ref (async));
|
2012-07-05 21:14:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (async);
|
2012-01-26 14:34:26 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_service_store_finish:
|
2012-07-05 21:14:50 +00:00
|
|
|
* @service: (allow-none): the secret service
|
2012-02-02 12:40:47 +00:00
|
|
|
* @result: the asynchronous result passed to the callback
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Finish asynchronous operation to store a secret value in the secret service.
|
|
|
|
*
|
|
|
|
* Returns: whether the storage was successful or not
|
|
|
|
*/
|
2012-01-26 14:34:26 +00:00
|
|
|
gboolean
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_store_finish (SecretService *service,
|
2012-02-02 12:40:47 +00:00
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
2012-01-26 14:34:26 +00:00
|
|
|
{
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_val_if_fail (service == NULL || SECRET_IS_SERVICE (service), FALSE);
|
|
|
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (service),
|
|
|
|
secret_service_store), FALSE);
|
2012-01-26 14:34:26 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
|
|
|
|
return FALSE;
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
return TRUE;
|
2012-01-26 14:34:26 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_service_store_sync:
|
2012-07-05 21:14:50 +00:00
|
|
|
* @service: (allow-none): the secret service
|
2012-06-28 11:15:06 +00:00
|
|
|
* @schema: (allow-none): the schema for the attributes
|
|
|
|
* @attributes: (element-type utf8 utf8): the attribute keys and values
|
2012-07-06 07:42:08 +00:00
|
|
|
* @collection: (allow-none): a collection alias, or D-Bus object path of the collection where to store the secret
|
2012-02-02 12:40:47 +00:00
|
|
|
* @label: label for the secret
|
|
|
|
* @value: the secret value
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Store a secret value in the secret service.
|
|
|
|
*
|
2012-06-28 11:15:06 +00:00
|
|
|
* The @attributes should be a set of key and value string pairs.
|
2012-02-02 12:40:47 +00:00
|
|
|
*
|
|
|
|
* If the attributes match a secret item already stored in the collection, then
|
|
|
|
* the item will be updated with these new values.
|
|
|
|
*
|
2012-07-06 07:42:08 +00:00
|
|
|
* If @collection is %NULL, then the default collection will be
|
2012-03-11 12:35:43 +00:00
|
|
|
* used. Use #SECRET_COLLECTION_SESSION to store the password in the session
|
|
|
|
* collection, which doesn't get stored across login sessions.
|
|
|
|
*
|
2012-07-05 21:14:50 +00:00
|
|
|
* If @service is NULL, then secret_service_get_sync() will be called to get
|
|
|
|
* the default #SecretService proxy.
|
|
|
|
*
|
2012-02-02 12:40:47 +00:00
|
|
|
* This method may block indefinitely and should not be used in user interface
|
|
|
|
* threads.
|
|
|
|
*
|
|
|
|
* Returns: whether the storage was successful or not
|
|
|
|
*/
|
2012-01-26 14:34:26 +00:00
|
|
|
gboolean
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_store_sync (SecretService *service,
|
2012-02-02 12:40:47 +00:00
|
|
|
const SecretSchema *schema,
|
2012-06-28 11:15:06 +00:00
|
|
|
GHashTable *attributes,
|
2012-07-06 07:42:08 +00:00
|
|
|
const gchar *collection,
|
2012-02-02 12:40:47 +00:00
|
|
|
const gchar *label,
|
|
|
|
SecretValue *value,
|
|
|
|
GCancellable *cancellable,
|
2012-06-28 11:15:06 +00:00
|
|
|
GError **error)
|
2012-01-26 14:34:26 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretSync *sync;
|
2012-01-26 14:34:26 +00:00
|
|
|
gboolean ret;
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_val_if_fail (service == NULL || SECRET_IS_SERVICE (service), FALSE);
|
2012-01-26 14:34:26 +00:00
|
|
|
g_return_val_if_fail (attributes != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (label != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (value != 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-03-11 08:06:40 +00:00
|
|
|
/* Warnings raised already */
|
2012-07-10 19:37:20 +00:00
|
|
|
if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, FALSE))
|
2012-03-11 08:06:40 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
sync = _secret_sync_new ();
|
2012-01-26 14:34:26 +00:00
|
|
|
g_main_context_push_thread_default (sync->context);
|
|
|
|
|
2012-07-06 07:42:08 +00:00
|
|
|
secret_service_store (service, schema, attributes, collection,
|
2012-07-05 21:14:50 +00:00
|
|
|
label, value, cancellable, _secret_sync_on_result, sync);
|
2012-01-26 14:34:26 +00:00
|
|
|
|
|
|
|
g_main_loop_run (sync->loop);
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
ret = secret_service_store_finish (service, sync->result, error);
|
2012-01-26 14:34:26 +00:00
|
|
|
|
|
|
|
g_main_context_pop_thread_default (sync->context);
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_sync_free (sync);
|
2012-01-26 14:34:26 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
2012-07-05 21:14:50 +00:00
|
|
|
GVariant *attributes;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretValue *value;
|
2012-01-26 14:34:26 +00:00
|
|
|
GCancellable *cancellable;
|
|
|
|
} LookupClosure;
|
|
|
|
|
|
|
|
static void
|
|
|
|
lookup_closure_free (gpointer data)
|
|
|
|
{
|
|
|
|
LookupClosure *closure = data;
|
2012-07-05 21:14:50 +00:00
|
|
|
g_variant_unref (closure->attributes);
|
2012-01-26 14:34:26 +00:00
|
|
|
if (closure->value)
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_value_unref (closure->value);
|
2012-01-26 14:34:26 +00:00
|
|
|
g_clear_object (&closure->cancellable);
|
|
|
|
g_slice_free (LookupClosure, closure);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_lookup_get_secret (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 *self = SECRET_SERVICE (source);
|
2012-01-26 14:34:26 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-07-06 07:01:20 +00:00
|
|
|
closure->value = secret_service_get_secret_for_dbus_path_finish (self, result, &error);
|
2012-01-26 14:34:26 +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_unlocked (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 *self = SECRET_SERVICE (source);
|
2012-01-26 14:34:26 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
gchar **unlocked = NULL;
|
|
|
|
|
2012-07-06 07:01:20 +00:00
|
|
|
secret_service_unlock_dbus_paths_finish (SECRET_SERVICE (source),
|
|
|
|
result, &unlocked, &error);
|
2012-01-26 14:34:26 +00:00
|
|
|
if (error != NULL) {
|
|
|
|
g_simple_async_result_take_error (res, error);
|
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
|
|
|
|
} else if (unlocked && unlocked[0]) {
|
2012-07-06 07:01:20 +00:00
|
|
|
secret_service_get_secret_for_dbus_path (self, unlocked[0],
|
|
|
|
closure->cancellable,
|
|
|
|
on_lookup_get_secret,
|
|
|
|
g_object_ref (res));
|
2012-01-26 14:34:26 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_strfreev (unlocked);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_lookup_searched (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 *self = SECRET_SERVICE (source);
|
2012-01-26 14:34:26 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
gchar **unlocked = NULL;
|
|
|
|
gchar **locked = NULL;
|
|
|
|
|
2012-07-06 07:01:20 +00:00
|
|
|
secret_service_search_for_dbus_paths_finish (self, result, &unlocked, &locked, &error);
|
2012-01-26 14:34:26 +00:00
|
|
|
if (error != NULL) {
|
|
|
|
g_simple_async_result_take_error (res, error);
|
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
|
|
|
|
} else if (unlocked && unlocked[0]) {
|
2012-07-06 07:01:20 +00:00
|
|
|
secret_service_get_secret_for_dbus_path (self, unlocked[0],
|
|
|
|
closure->cancellable,
|
|
|
|
on_lookup_get_secret,
|
|
|
|
g_object_ref (res));
|
2012-01-26 14:34:26 +00:00
|
|
|
|
|
|
|
} else if (locked && locked[0]) {
|
|
|
|
const gchar *paths[] = { locked[0], NULL };
|
2012-07-06 07:01:20 +00:00
|
|
|
secret_service_unlock_dbus_paths (self, paths,
|
|
|
|
closure->cancellable,
|
|
|
|
on_lookup_unlocked,
|
|
|
|
g_object_ref (res));
|
2012-01-26 14:34:26 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_strfreev (unlocked);
|
|
|
|
g_strfreev (locked);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
static void
|
|
|
|
on_lookup_service (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
LookupClosure *lookup = g_simple_async_result_get_op_res_gpointer (async);
|
|
|
|
SecretService *service;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
service = secret_service_get_finish (result, &error);
|
|
|
|
if (error == NULL) {
|
|
|
|
_secret_service_search_for_paths_variant (service, lookup->attributes,
|
|
|
|
lookup->cancellable,
|
|
|
|
on_lookup_searched, g_object_ref (async));
|
|
|
|
g_object_unref (service);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
g_simple_async_result_take_error (async, error);
|
|
|
|
g_simple_async_result_complete (async);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (async);
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
2012-06-28 11:15:06 +00:00
|
|
|
* secret_service_lookup:
|
2012-07-05 21:14:50 +00:00
|
|
|
* @service: (allow-none): the secret service
|
2012-03-25 10:22:10 +00:00
|
|
|
* @schema: (allow-none): the schema for the attributes
|
2012-03-11 08:06:40 +00:00
|
|
|
* @attributes: (element-type utf8 utf8): the attribute keys and values
|
2012-02-02 12:40:47 +00:00
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @callback: called when the operation completes
|
|
|
|
* @user_data: data to be passed to the callback
|
|
|
|
*
|
|
|
|
* Lookup a secret value in the secret service.
|
|
|
|
*
|
|
|
|
* The @attributes should be a set of key and value string pairs.
|
|
|
|
*
|
2012-07-05 21:14:50 +00:00
|
|
|
* If @service is NULL, then secret_service_get() will be called to get
|
|
|
|
* the default #SecretService proxy.
|
|
|
|
*
|
2012-02-02 12:40:47 +00:00
|
|
|
* This method will return immediately and complete asynchronously.
|
|
|
|
*/
|
2012-01-26 14:34:26 +00:00
|
|
|
void
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_lookup (SecretService *service,
|
2012-06-28 11:15:06 +00:00
|
|
|
const SecretSchema *schema,
|
|
|
|
GHashTable *attributes,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2012-01-26 14:34:26 +00:00
|
|
|
{
|
2012-03-25 10:22:10 +00:00
|
|
|
const gchar *schema_name = NULL;
|
2012-01-26 14:34:26 +00:00
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
LookupClosure *closure;
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_if_fail (service == NULL || SECRET_IS_SERVICE (service));
|
2012-01-26 14:34:26 +00:00
|
|
|
g_return_if_fail (attributes != NULL);
|
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
2012-03-11 08:06:40 +00:00
|
|
|
/* Warnings raised already */
|
2012-07-10 19:37:20 +00:00
|
|
|
if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
|
2012-03-11 08:06:40 +00:00
|
|
|
return;
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
if (schema != NULL && !(schema->flags & SECRET_SCHEMA_DONT_MATCH_NAME))
|
|
|
|
schema_name = schema->name;
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (service), callback, user_data,
|
2012-06-28 11:15:06 +00:00
|
|
|
secret_service_lookup);
|
2012-01-26 14:34:26 +00:00
|
|
|
closure = g_slice_new0 (LookupClosure);
|
|
|
|
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
2012-07-05 21:14:50 +00:00
|
|
|
closure->attributes = _secret_attributes_to_variant (attributes, schema_name);
|
|
|
|
g_variant_ref_sink (closure->attributes);
|
2012-01-26 14:34:26 +00:00
|
|
|
g_simple_async_result_set_op_res_gpointer (res, closure, lookup_closure_free);
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
if (service == NULL) {
|
|
|
|
secret_service_get (SECRET_SERVICE_OPEN_SESSION, cancellable,
|
|
|
|
on_lookup_service, g_object_ref (res));
|
|
|
|
} else {
|
|
|
|
_secret_service_search_for_paths_variant (service, closure->attributes,
|
|
|
|
closure->cancellable,
|
|
|
|
on_lookup_searched, g_object_ref (res));
|
|
|
|
}
|
2012-01-26 14:34:26 +00:00
|
|
|
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_service_lookup_finish:
|
2012-07-05 21:14:50 +00:00
|
|
|
* @service: (allow-none): the secret service
|
2012-02-02 12:40:47 +00:00
|
|
|
* @result: the asynchronous result passed to the callback
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Finish asynchronous operation to lookup a secret value in the secret service.
|
|
|
|
*
|
|
|
|
* If no secret is found then %NULL is returned.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): a newly allocated #SecretValue, which should be
|
|
|
|
* released with secret_value_unref(), or %NULL if no secret found
|
|
|
|
*/
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretValue *
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_lookup_finish (SecretService *service,
|
2012-02-02 12:40:47 +00:00
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
2012-01-26 14:34:26 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
LookupClosure *closure;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretValue *value;
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_val_if_fail (service == NULL || SECRET_IS_SERVICE (service), NULL);
|
2012-01-26 14:34:26 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (service),
|
2012-06-28 11:15:06 +00:00
|
|
|
secret_service_lookup), NULL);
|
2012-01-26 14:34:26 +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);
|
|
|
|
value = closure->value;
|
|
|
|
closure->value = NULL;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_service_lookup_sync:
|
2012-07-05 21:14:50 +00:00
|
|
|
* @service: (allow-none): the secret service
|
2012-03-25 10:22:10 +00:00
|
|
|
* @schema: (allow-none): the schema for the attributes
|
2012-03-11 08:06:40 +00:00
|
|
|
* @attributes: (element-type utf8 utf8): the attribute keys and values
|
2012-02-02 12:40:47 +00:00
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Lookup a secret value in the secret service.
|
|
|
|
*
|
|
|
|
* The @attributes should be a set of key and value string pairs.
|
|
|
|
*
|
2012-07-05 21:14:50 +00:00
|
|
|
* If @service is NULL, then secret_service_get_sync() will be called to get
|
|
|
|
* the default #SecretService proxy.
|
|
|
|
*
|
2012-02-02 12:40:47 +00:00
|
|
|
* 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
|
|
|
|
*/
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretValue *
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_lookup_sync (SecretService *service,
|
2012-06-28 11:15:06 +00:00
|
|
|
const SecretSchema *schema,
|
|
|
|
GHashTable *attributes,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2012-01-26 14:34:26 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretSync *sync;
|
|
|
|
SecretValue *value;
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_val_if_fail (service == NULL || SECRET_IS_SERVICE (service), NULL);
|
2012-01-26 14:34:26 +00:00
|
|
|
g_return_val_if_fail (attributes != NULL, NULL);
|
|
|
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
|
|
|
|
|
2012-03-11 08:06:40 +00:00
|
|
|
/* Warnings raised already */
|
2012-07-10 19:37:20 +00:00
|
|
|
if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
|
2012-03-11 08:06:40 +00:00
|
|
|
return NULL;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
sync = _secret_sync_new ();
|
2012-01-26 14:34:26 +00:00
|
|
|
g_main_context_push_thread_default (sync->context);
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_lookup (service, schema, attributes, cancellable,
|
2012-06-28 11:15:06 +00:00
|
|
|
_secret_sync_on_result, sync);
|
2012-01-26 14:34:26 +00:00
|
|
|
|
|
|
|
g_main_loop_run (sync->loop);
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
value = secret_service_lookup_finish (service, sync->result, error);
|
2012-01-26 14:34:26 +00:00
|
|
|
|
|
|
|
g_main_context_pop_thread_default (sync->context);
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_sync_free (sync);
|
2012-01-26 14:34:26 +00:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
GCancellable *cancellable;
|
2012-07-05 21:14:50 +00:00
|
|
|
SecretService *service;
|
|
|
|
GVariant *attributes;
|
2012-07-10 19:38:48 +00:00
|
|
|
gint deleted;
|
|
|
|
gint deleting;
|
2012-01-26 14:34:26 +00:00
|
|
|
} DeleteClosure;
|
|
|
|
|
|
|
|
static void
|
|
|
|
delete_closure_free (gpointer data)
|
|
|
|
{
|
|
|
|
DeleteClosure *closure = data;
|
2012-07-05 21:14:50 +00:00
|
|
|
if (closure->service)
|
|
|
|
g_object_unref (closure->service);
|
|
|
|
g_variant_unref (closure->attributes);
|
2012-01-26 14:34:26 +00:00
|
|
|
g_clear_object (&closure->cancellable);
|
|
|
|
g_slice_free (DeleteClosure, closure);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-07-05 14:41:28 +00:00
|
|
|
on_delete_password_complete (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
2012-01-26 14:34:26 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
DeleteClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
|
|
|
GError *error = NULL;
|
2012-07-10 19:38:48 +00:00
|
|
|
gboolean deleted;
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-07-10 19:38:48 +00:00
|
|
|
closure->deleting--;
|
|
|
|
|
|
|
|
deleted = _secret_service_delete_path_finish (SECRET_SERVICE (source), result, &error);
|
2012-07-05 14:41:28 +00:00
|
|
|
if (error != NULL)
|
2012-01-26 14:34:26 +00:00
|
|
|
g_simple_async_result_take_error (res, error);
|
2012-07-10 19:38:48 +00:00
|
|
|
if (deleted)
|
|
|
|
closure->deleted++;
|
2012-07-05 14:41:28 +00:00
|
|
|
|
2012-07-10 19:38:48 +00:00
|
|
|
if (closure->deleting <= 0)
|
|
|
|
g_simple_async_result_complete (res);
|
2012-07-05 14:41:28 +00:00
|
|
|
|
2012-01-26 14:34:26 +00:00
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-07-05 21:14:50 +00:00
|
|
|
on_delete_searched (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
2012-01-26 14:34:26 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
DeleteClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
|
|
|
GError *error = NULL;
|
2012-07-10 19:38:48 +00:00
|
|
|
gchar **unlocked = NULL;
|
|
|
|
gint i;
|
2012-01-26 14:34:26 +00:00
|
|
|
|
2012-07-10 19:38:48 +00:00
|
|
|
secret_service_search_for_dbus_paths_finish (SECRET_SERVICE (source), result, &unlocked, NULL, &error);
|
|
|
|
if (error == NULL) {
|
|
|
|
for (i = 0; unlocked[i] != NULL; i++) {
|
|
|
|
_secret_service_delete_path (closure->service, unlocked[i], TRUE,
|
2012-07-05 14:41:28 +00:00
|
|
|
closure->cancellable,
|
|
|
|
on_delete_password_complete,
|
|
|
|
g_object_ref (res));
|
2012-07-10 19:38:48 +00:00
|
|
|
closure->deleting++;
|
2012-01-26 14:34:26 +00:00
|
|
|
}
|
2012-07-10 19:38:48 +00:00
|
|
|
|
|
|
|
if (closure->deleting == 0)
|
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
} else {
|
|
|
|
g_simple_async_result_take_error (res, error);
|
|
|
|
g_simple_async_result_complete (res);
|
2012-01-26 14:34:26 +00:00
|
|
|
}
|
|
|
|
|
2012-07-05 14:41:28 +00:00
|
|
|
g_strfreev (unlocked);
|
2012-01-26 14:34:26 +00:00
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
static void
|
|
|
|
on_delete_service (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
DeleteClosure *closure = g_simple_async_result_get_op_res_gpointer (async);
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
closure->service = secret_service_get_finish (result, &error);
|
|
|
|
if (error == NULL) {
|
|
|
|
_secret_service_search_for_paths_variant (closure->service, closure->attributes,
|
|
|
|
closure->cancellable,
|
|
|
|
on_delete_searched, g_object_ref (async));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
g_simple_async_result_take_error (async, error);
|
|
|
|
g_simple_async_result_complete (async);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (async);
|
|
|
|
}
|
|
|
|
|
2012-07-05 14:41:28 +00:00
|
|
|
/**
|
|
|
|
* secret_service_remove:
|
2012-07-05 21:14:50 +00:00
|
|
|
* @service: (allow-none): the secret service
|
2012-07-05 14:41:28 +00:00
|
|
|
* @schema: (allow-none): the schema for the attributes
|
|
|
|
* @attributes: (element-type utf8 utf8): the attribute keys and values
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @callback: called when the operation completes
|
|
|
|
* @user_data: data to be passed to the callback
|
|
|
|
*
|
|
|
|
* Remove a secret value from the secret service.
|
|
|
|
*
|
|
|
|
* The @attributes should be a set of key and value string pairs.
|
|
|
|
*
|
|
|
|
* If multiple items match the attributes, then only one will be deleted.
|
|
|
|
*
|
2012-07-05 21:14:50 +00:00
|
|
|
* If @service is NULL, then secret_service_get() will be called to get
|
|
|
|
* the default #SecretService proxy.
|
|
|
|
*
|
2012-07-05 14:41:28 +00:00
|
|
|
* This method will return immediately and complete asynchronously.
|
|
|
|
*/
|
2012-01-26 14:34:26 +00:00
|
|
|
void
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_remove (SecretService *service,
|
2012-07-05 14:41:28 +00:00
|
|
|
const SecretSchema *schema,
|
|
|
|
GHashTable *attributes,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2012-01-26 14:34:26 +00:00
|
|
|
{
|
2012-07-05 14:41:28 +00:00
|
|
|
const gchar *schema_name = NULL;
|
2012-01-26 14:34:26 +00:00
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
DeleteClosure *closure;
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_if_fail (service == NULL || SECRET_SERVICE (service));
|
2012-07-05 14:41:28 +00:00
|
|
|
g_return_if_fail (attributes != NULL);
|
2012-01-26 14:34:26 +00:00
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
2012-07-05 14:41:28 +00:00
|
|
|
/* Warnings raised already */
|
2012-07-10 19:37:20 +00:00
|
|
|
if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
|
2012-07-05 14:41:28 +00:00
|
|
|
return;
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
if (schema != NULL && !(schema->flags & SECRET_SCHEMA_DONT_MATCH_NAME))
|
|
|
|
schema_name = schema->name;
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (service), callback, user_data,
|
2012-07-05 14:41:28 +00:00
|
|
|
secret_service_remove);
|
2012-01-26 14:34:26 +00:00
|
|
|
closure = g_slice_new0 (DeleteClosure);
|
|
|
|
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
2012-07-05 21:14:50 +00:00
|
|
|
closure->attributes = _secret_attributes_to_variant (attributes, schema_name);
|
|
|
|
g_variant_ref_sink (closure->attributes);
|
2012-01-26 14:34:26 +00:00
|
|
|
g_simple_async_result_set_op_res_gpointer (res, closure, delete_closure_free);
|
|
|
|
|
2012-07-10 19:38:48 +00:00
|
|
|
/* A double check to make sure we don't delete everything, should have been checked earlier */
|
|
|
|
g_assert (g_variant_n_children (closure->attributes) > 0);
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
if (service == NULL) {
|
|
|
|
secret_service_get (SECRET_SERVICE_NONE, cancellable,
|
|
|
|
on_delete_service, g_object_ref (res));
|
|
|
|
} else {
|
|
|
|
closure->service = g_object_ref (service);
|
|
|
|
_secret_service_search_for_paths_variant (closure->service, closure->attributes,
|
|
|
|
closure->cancellable,
|
|
|
|
on_delete_searched, g_object_ref (res));
|
|
|
|
}
|
2012-01-26 14:34:26 +00:00
|
|
|
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
2012-07-05 14:41:28 +00:00
|
|
|
* secret_service_remove_finish:
|
2012-07-05 21:14:50 +00:00
|
|
|
* @service: (allow-none): the secret service
|
2012-07-05 14:41:28 +00:00
|
|
|
* @result: the asynchronous result passed to the callback
|
|
|
|
* @error: location to place an error on failure
|
2012-02-02 12:40:47 +00:00
|
|
|
*
|
2012-07-05 14:41:28 +00:00
|
|
|
* Finish asynchronous operation to remove a secret value from the secret
|
|
|
|
* service.
|
2012-02-02 12:40:47 +00:00
|
|
|
*
|
2012-07-05 14:41:28 +00:00
|
|
|
* Returns: whether the removal was successful or not
|
2012-02-02 12:40:47 +00:00
|
|
|
*/
|
2012-07-05 14:41:28 +00:00
|
|
|
gboolean
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_remove_finish (SecretService *service,
|
2012-07-05 14:41:28 +00:00
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
2012-01-26 17:23:12 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
2012-07-05 14:41:28 +00:00
|
|
|
DeleteClosure *closure;
|
2012-01-26 17:23:12 +00:00
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_val_if_fail (service == NULL || SECRET_IS_SERVICE (service), FALSE);
|
2012-07-05 14:41:28 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (service),
|
2012-07-05 14:41:28 +00:00
|
|
|
secret_service_remove), FALSE);
|
2012-01-26 17:23:12 +00:00
|
|
|
|
|
|
|
res = G_SIMPLE_ASYNC_RESULT (result);
|
|
|
|
if (g_simple_async_result_propagate_error (res, error))
|
2012-07-05 14:41:28 +00:00
|
|
|
return FALSE;
|
2012-01-26 17:23:12 +00:00
|
|
|
|
|
|
|
closure = g_simple_async_result_get_op_res_gpointer (res);
|
2012-07-10 19:38:48 +00:00
|
|
|
return closure->deleted > 0;
|
2012-01-26 17:23:12 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
2012-07-05 14:41:28 +00:00
|
|
|
* secret_service_remove_sync:
|
2012-07-05 21:14:50 +00:00
|
|
|
* @service: (allow-none): the secret service
|
2012-07-05 14:41:28 +00:00
|
|
|
* @schema: (allow-none): the schema for the attributes
|
|
|
|
* @attributes: (element-type utf8 utf8): the attribute keys and values
|
2012-02-02 12:40:47 +00:00
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
2012-07-05 14:41:28 +00:00
|
|
|
* Remove a secret value from the secret service.
|
2012-02-02 12:40:47 +00:00
|
|
|
*
|
2012-07-05 14:41:28 +00:00
|
|
|
* The @attributes should be a set of key and value string pairs.
|
2012-02-02 12:40:47 +00:00
|
|
|
*
|
2012-07-05 14:41:28 +00:00
|
|
|
* If multiple items match the attributes, then only one will be deleted.
|
2012-02-02 12:40:47 +00:00
|
|
|
*
|
2012-07-05 21:14:50 +00:00
|
|
|
* If @service is NULL, then secret_service_get_sync() will be called to get
|
|
|
|
* the default #SecretService proxy.
|
|
|
|
*
|
2012-02-02 12:40:47 +00:00
|
|
|
* This method may block indefinitely and should not be used in user interface
|
2012-07-05 14:41:28 +00:00
|
|
|
* threads.
|
2012-02-02 12:40:47 +00:00
|
|
|
*
|
2012-07-05 14:41:28 +00:00
|
|
|
* Returns: whether the removal was successful or not
|
2012-02-02 12:40:47 +00:00
|
|
|
*/
|
2012-07-05 14:41:28 +00:00
|
|
|
gboolean
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_remove_sync (SecretService *service,
|
2012-07-05 14:41:28 +00:00
|
|
|
const SecretSchema *schema,
|
|
|
|
GHashTable *attributes,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2012-01-26 17:23:12 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretSync *sync;
|
2012-07-05 14:41:28 +00:00
|
|
|
gboolean result;
|
2012-01-26 17:23:12 +00:00
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_val_if_fail (service == NULL || SECRET_IS_SERVICE (service), FALSE);
|
2012-07-05 14:41:28 +00:00
|
|
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
|
|
|
/* Warnings raised already */
|
2012-07-10 19:37:20 +00:00
|
|
|
if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, TRUE))
|
2012-07-05 14:41:28 +00:00
|
|
|
return FALSE;
|
2012-01-26 17:23:12 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
sync = _secret_sync_new ();
|
2012-01-26 17:23:12 +00:00
|
|
|
g_main_context_push_thread_default (sync->context);
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_remove (service, schema, attributes, cancellable,
|
2012-07-05 14:41:28 +00:00
|
|
|
_secret_sync_on_result, sync);
|
2012-01-26 17:23:12 +00:00
|
|
|
|
|
|
|
g_main_loop_run (sync->loop);
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
result = secret_service_remove_finish (service, sync->result, error);
|
2012-01-26 17:23:12 +00:00
|
|
|
|
|
|
|
g_main_context_pop_thread_default (sync->context);
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_sync_free (sync);
|
2012-01-26 17:23:12 +00:00
|
|
|
|
2012-07-05 14:41:28 +00:00
|
|
|
return result;
|
2012-01-26 17:23:12 +00:00
|
|
|
}
|
2012-06-23 12:09:50 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
GCancellable *cancellable;
|
2012-07-05 21:14:50 +00:00
|
|
|
gchar *alias;
|
2012-06-23 12:09:50 +00:00
|
|
|
SecretCollection *collection;
|
|
|
|
} ReadClosure;
|
|
|
|
|
|
|
|
static void
|
|
|
|
read_closure_free (gpointer data)
|
|
|
|
{
|
|
|
|
ReadClosure *read = data;
|
2012-07-05 21:14:50 +00:00
|
|
|
g_free (read->alias);
|
2012-06-23 12:09:50 +00:00
|
|
|
if (read->collection)
|
|
|
|
g_object_unref (read->collection);
|
|
|
|
if (read->cancellable)
|
|
|
|
g_object_unref (read->cancellable);
|
|
|
|
g_slice_free (ReadClosure, read);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_read_alias_collection (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
ReadClosure *read = g_simple_async_result_get_op_res_gpointer (async);
|
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-07-06 07:01:20 +00:00
|
|
|
read->collection = secret_collection_new_for_dbus_path_finish (result, &error);
|
2012-06-23 12:09:50 +00:00
|
|
|
if (error != NULL)
|
|
|
|
g_simple_async_result_take_error (async, error);
|
|
|
|
|
|
|
|
g_simple_async_result_complete (async);
|
|
|
|
g_object_unref (async);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_read_alias_path (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
ReadClosure *read = g_simple_async_result_get_op_res_gpointer (async);
|
|
|
|
SecretService *self = SECRET_SERVICE (source);
|
|
|
|
GError *error = NULL;
|
|
|
|
gchar *collection_path;
|
|
|
|
|
2012-07-06 07:01:20 +00:00
|
|
|
collection_path = secret_service_read_alias_dbus_path_finish (self, result, &error);
|
2012-06-23 12:09:50 +00:00
|
|
|
if (error == NULL) {
|
|
|
|
|
|
|
|
/* No collection for this alias */
|
|
|
|
if (collection_path == NULL) {
|
|
|
|
g_simple_async_result_complete (async);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
read->collection = _secret_service_find_collection_instance (self,
|
|
|
|
collection_path);
|
|
|
|
if (read->collection != NULL) {
|
|
|
|
g_simple_async_result_complete (async);
|
|
|
|
|
|
|
|
/* No collection loaded, but valid path, load */
|
|
|
|
} else {
|
2012-07-06 07:01:20 +00:00
|
|
|
secret_collection_new_for_dbus_path (self, collection_path,
|
|
|
|
SECRET_COLLECTION_NONE,
|
|
|
|
read->cancellable,
|
|
|
|
on_read_alias_collection,
|
|
|
|
g_object_ref (async));
|
2012-06-23 12:09:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
g_simple_async_result_take_error (async, error);
|
|
|
|
g_simple_async_result_complete (async);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (collection_path);
|
|
|
|
g_object_unref (async);
|
|
|
|
}
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
static void
|
|
|
|
on_read_alias_service (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
ReadClosure *read = g_simple_async_result_get_op_res_gpointer (async);
|
|
|
|
SecretService *service;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
service = secret_service_get_finish (result, &error);
|
|
|
|
if (error == NULL) {
|
2012-07-06 07:01:20 +00:00
|
|
|
secret_service_read_alias_dbus_path (service, read->alias, read->cancellable,
|
|
|
|
on_read_alias_path, g_object_ref (async));
|
2012-07-05 21:14:50 +00:00
|
|
|
g_object_unref (service);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
g_simple_async_result_take_error (async, error);
|
|
|
|
g_simple_async_result_complete (async);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (async);
|
|
|
|
}
|
|
|
|
|
2012-06-23 12:09:50 +00:00
|
|
|
/**
|
|
|
|
* secret_service_read_alias:
|
2012-07-05 21:14:50 +00:00
|
|
|
* @service: (allow-none): a secret service object
|
2012-06-23 12:09:50 +00:00
|
|
|
* @alias: the alias to lookup
|
|
|
|
* @cancellable: (allow-none): optional cancellation object
|
|
|
|
* @callback: called when the operation completes
|
|
|
|
* @user_data: data to pass to the callback
|
|
|
|
*
|
|
|
|
* Lookup which collection is assigned to this alias. Aliases help determine
|
|
|
|
* well known collections, such as 'default'.
|
|
|
|
*
|
2012-07-05 21:14:50 +00:00
|
|
|
* If @service is NULL, then secret_service_get() will be called to get
|
|
|
|
* the default #SecretService proxy.
|
|
|
|
*
|
2012-06-23 12:09:50 +00:00
|
|
|
* This method will return immediately and complete asynchronously.
|
|
|
|
*/
|
|
|
|
void
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_read_alias (SecretService *service,
|
2012-06-23 12:09:50 +00:00
|
|
|
const gchar *alias,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *async;
|
|
|
|
ReadClosure *read;
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_if_fail (service == NULL || SECRET_IS_SERVICE (service));
|
2012-06-23 12:09:50 +00:00
|
|
|
g_return_if_fail (alias != NULL);
|
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
async = g_simple_async_result_new (G_OBJECT (service), callback, user_data,
|
2012-06-23 12:09:50 +00:00
|
|
|
secret_service_read_alias);
|
|
|
|
read = g_slice_new0 (ReadClosure);
|
|
|
|
read->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
2012-07-05 21:14:50 +00:00
|
|
|
read->alias = g_strdup (alias);
|
2012-06-23 12:09:50 +00:00
|
|
|
g_simple_async_result_set_op_res_gpointer (async, read, read_closure_free);
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
if (service == NULL) {
|
|
|
|
secret_service_get (SECRET_SERVICE_NONE, cancellable,
|
|
|
|
on_read_alias_service, g_object_ref (async));
|
|
|
|
} else {
|
2012-07-06 07:01:20 +00:00
|
|
|
secret_service_read_alias_dbus_path (service, read->alias, read->cancellable,
|
|
|
|
on_read_alias_path, g_object_ref (async));
|
2012-07-05 21:14:50 +00:00
|
|
|
}
|
2012-06-23 12:09:50 +00:00
|
|
|
|
|
|
|
g_object_unref (async);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* secret_service_read_alias_finish:
|
2012-07-05 21:14:50 +00:00
|
|
|
* @service: (allow-none): a secret service object
|
2012-06-23 12:09:50 +00:00
|
|
|
* @result: asynchronous result passed to callback
|
|
|
|
* @error: location to place error on failure
|
|
|
|
*
|
|
|
|
* Finish an asynchronous operation to lookup which collection is assigned
|
|
|
|
* to an alias.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the collection, or %NULL if none assigned to the alias
|
|
|
|
*/
|
|
|
|
SecretCollection *
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_read_alias_finish (SecretService *service,
|
2012-06-23 12:09:50 +00:00
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *async;
|
|
|
|
ReadClosure *read;
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_val_if_fail (service == NULL || SECRET_IS_SERVICE (service), NULL);
|
|
|
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (service),
|
2012-06-23 12:09:50 +00:00
|
|
|
secret_service_read_alias), NULL);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
|
|
|
async = G_SIMPLE_ASYNC_RESULT (result);
|
|
|
|
if (g_simple_async_result_propagate_error (async, error))
|
|
|
|
return NULL;
|
|
|
|
read = g_simple_async_result_get_op_res_gpointer (async);
|
|
|
|
if (read->collection)
|
|
|
|
g_object_ref (read->collection);
|
|
|
|
return read->collection;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* secret_service_read_alias_sync:
|
2012-07-05 21:14:50 +00:00
|
|
|
* @service: (allow-none): a secret service object
|
2012-06-23 12:09:50 +00:00
|
|
|
* @alias: the alias to lookup
|
|
|
|
* @cancellable: (allow-none): optional cancellation object
|
|
|
|
* @error: location to place error on failure
|
|
|
|
*
|
|
|
|
* Lookup which collection is assigned to this alias. Aliases help determine
|
|
|
|
* well known collections, such as 'default'.
|
|
|
|
*
|
2012-07-05 21:14:50 +00:00
|
|
|
* If @service is NULL, then secret_service_get_sync() will be called to get
|
|
|
|
* the default #SecretService proxy.
|
|
|
|
*
|
2012-06-23 12:09:50 +00:00
|
|
|
* This method may block and should not be used in user interface threads.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the collection, or %NULL if none assigned to the alias
|
|
|
|
*/
|
|
|
|
SecretCollection *
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_read_alias_sync (SecretService *service,
|
2012-06-23 12:09:50 +00:00
|
|
|
const gchar *alias,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
SecretCollection *collection;
|
|
|
|
gchar *collection_path;
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_val_if_fail (service == NULL || SECRET_IS_SERVICE (service), NULL);
|
2012-06-23 12:09:50 +00:00
|
|
|
g_return_val_if_fail (alias != 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-07-06 07:01:20 +00:00
|
|
|
collection_path = secret_service_read_alias_dbus_path_sync (service, alias,
|
|
|
|
cancellable, error);
|
2012-06-23 12:09:50 +00:00
|
|
|
if (collection_path == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* No collection for this alias */
|
|
|
|
if (collection_path == NULL) {
|
|
|
|
collection = NULL;
|
|
|
|
|
|
|
|
} else {
|
2012-07-05 21:14:50 +00:00
|
|
|
collection = _secret_service_find_collection_instance (service,
|
2012-06-23 12:09:50 +00:00
|
|
|
collection_path);
|
|
|
|
|
|
|
|
/* No collection loaded, but valid path, load */
|
|
|
|
if (collection == NULL) {
|
2012-07-06 07:01:20 +00:00
|
|
|
collection = secret_collection_new_for_dbus_path_sync (service, collection_path,
|
|
|
|
SECRET_COLLECTION_LOAD_ITEMS,
|
|
|
|
cancellable, error);
|
2012-06-23 12:09:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (collection_path);
|
|
|
|
return collection;
|
|
|
|
}
|
|
|
|
|
2012-07-06 08:40:22 +00:00
|
|
|
typedef struct {
|
|
|
|
GCancellable *cancellable;
|
|
|
|
gchar *alias;
|
|
|
|
gchar *collection_path;
|
|
|
|
} SetClosure;
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_closure_free (gpointer data)
|
|
|
|
{
|
|
|
|
SetClosure *set = data;
|
|
|
|
if (set->cancellable)
|
|
|
|
g_object_unref (set->cancellable);
|
|
|
|
g_free (set->alias);
|
|
|
|
g_free (set->collection_path);
|
|
|
|
g_slice_free (SetClosure, set);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_set_alias_done (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
secret_service_set_alias_to_dbus_path_finish (SECRET_SERVICE (source), result, &error);
|
|
|
|
if (error != NULL)
|
|
|
|
g_simple_async_result_take_error (async, error);
|
|
|
|
|
|
|
|
g_simple_async_result_complete (async);
|
|
|
|
g_object_unref (async);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_set_alias_service (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
SetClosure *set = g_simple_async_result_get_op_res_gpointer (async);
|
|
|
|
SecretService *service;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
service = secret_service_get_finish (result, &error);
|
|
|
|
if (error == NULL) {
|
|
|
|
secret_service_set_alias_to_dbus_path (service, set->alias,
|
|
|
|
set->collection_path,
|
|
|
|
set->cancellable,
|
|
|
|
on_set_alias_done,
|
|
|
|
g_object_ref (async));
|
|
|
|
g_object_unref (service);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
g_simple_async_result_take_error (async, error);
|
|
|
|
g_simple_async_result_complete (async);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (async);
|
|
|
|
}
|
|
|
|
|
2012-06-23 12:09:50 +00:00
|
|
|
/**
|
|
|
|
* secret_service_set_alias:
|
2012-07-05 21:14:50 +00:00
|
|
|
* @service: (allow-none): a secret service object
|
2012-06-23 12:09:50 +00:00
|
|
|
* @alias: the alias to assign the collection to
|
|
|
|
* @collection: (allow-none): the collection to assign to the alias
|
|
|
|
* @cancellable: (allow-none): optional cancellation object
|
|
|
|
* @callback: called when the operation completes
|
|
|
|
* @user_data: data to pass to the callback
|
|
|
|
*
|
|
|
|
* Assign a collection to this alias. Aliases help determine
|
|
|
|
* well known collections, such as 'default'.
|
|
|
|
*
|
2012-07-06 08:40:22 +00:00
|
|
|
* If @service is NULL, then secret_service_get() will be called to get
|
|
|
|
* the default #SecretService proxy.
|
2012-07-05 21:14:50 +00:00
|
|
|
*
|
2012-06-23 12:09:50 +00:00
|
|
|
* This method will return immediately and complete asynchronously.
|
|
|
|
*/
|
|
|
|
void
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_set_alias (SecretService *service,
|
2012-06-23 12:09:50 +00:00
|
|
|
const gchar *alias,
|
|
|
|
SecretCollection *collection,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2012-07-06 08:40:22 +00:00
|
|
|
GSimpleAsyncResult *async;
|
|
|
|
SetClosure *set;
|
|
|
|
const gchar *path;
|
2012-06-23 12:09:50 +00:00
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_if_fail (service == NULL || SECRET_IS_SERVICE (service));
|
2012-06-23 12:09:50 +00:00
|
|
|
g_return_if_fail (alias != NULL);
|
|
|
|
g_return_if_fail (collection == NULL || SECRET_IS_COLLECTION (collection));
|
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
2012-07-06 08:40:22 +00:00
|
|
|
async = g_simple_async_result_new (G_OBJECT (service), callback, user_data,
|
|
|
|
secret_service_set_alias);
|
|
|
|
set = g_slice_new0 (SetClosure);
|
|
|
|
set->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
|
|
|
set->alias = g_strdup (alias);
|
|
|
|
|
2012-06-23 12:09:50 +00:00
|
|
|
if (collection) {
|
2012-07-06 08:40:22 +00:00
|
|
|
path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection));
|
|
|
|
g_return_if_fail (path != NULL);
|
2012-06-23 12:09:50 +00:00
|
|
|
} else {
|
2012-07-06 08:40:22 +00:00
|
|
|
path = NULL;
|
2012-06-23 12:09:50 +00:00
|
|
|
}
|
|
|
|
|
2012-07-06 08:40:22 +00:00
|
|
|
set->collection_path = g_strdup (path);
|
|
|
|
g_simple_async_result_set_op_res_gpointer (async, set, set_closure_free);
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
if (service == NULL) {
|
2012-07-06 08:40:22 +00:00
|
|
|
secret_service_get (SECRET_SERVICE_NONE, cancellable,
|
|
|
|
on_set_alias_service, g_object_ref (async));
|
2012-07-05 21:14:50 +00:00
|
|
|
} else {
|
2012-07-06 08:40:22 +00:00
|
|
|
secret_service_set_alias_to_dbus_path (service, set->alias,
|
|
|
|
set->collection_path,
|
|
|
|
set->cancellable,
|
|
|
|
on_set_alias_done,
|
|
|
|
g_object_ref (async));
|
2012-07-05 21:14:50 +00:00
|
|
|
}
|
|
|
|
|
2012-07-06 08:40:22 +00:00
|
|
|
g_object_unref (async);
|
2012-06-23 12:09:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* secret_service_set_alias_finish:
|
2012-07-05 21:14:50 +00:00
|
|
|
* @service: (allow-none): a secret service object
|
2012-06-23 12:09:50 +00:00
|
|
|
* @result: asynchronous result passed to callback
|
|
|
|
* @error: location to place error on failure
|
|
|
|
*
|
|
|
|
* Finish an asynchronous operation to assign a collection to an alias.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if successful
|
|
|
|
*/
|
|
|
|
gboolean
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_set_alias_finish (SecretService *service,
|
2012-06-23 12:09:50 +00:00
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
|
|
|
{
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_val_if_fail (service == NULL || SECRET_IS_SERVICE (service), FALSE);
|
2012-07-06 08:40:22 +00:00
|
|
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (service),
|
|
|
|
secret_service_set_alias), FALSE);
|
2012-06-23 12:09:50 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
2012-07-06 08:40:22 +00:00
|
|
|
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
|
|
|
|
return FALSE;
|
2012-07-05 21:14:50 +00:00
|
|
|
|
2012-07-06 08:40:22 +00:00
|
|
|
return TRUE;
|
2012-06-23 12:09:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* secret_service_set_alias_sync:
|
2012-07-05 21:14:50 +00:00
|
|
|
* @service: (allow-none): a secret service object
|
2012-06-23 12:09:50 +00:00
|
|
|
* @alias: the alias to assign the collection to
|
|
|
|
* @collection: (allow-none): the collection to assign to the alias
|
|
|
|
* @cancellable: (allow-none): optional cancellation object
|
|
|
|
* @error: location to place error on failure
|
|
|
|
*
|
|
|
|
* Assign a collection to this alias. Aliases help determine
|
|
|
|
* well known collections, such as 'default'.
|
|
|
|
*
|
2012-07-05 21:14:50 +00:00
|
|
|
* If @service is NULL, then secret_service_get_sync() will be called to get
|
|
|
|
* the default #SecretService proxy.
|
|
|
|
*
|
2012-06-23 12:09:50 +00:00
|
|
|
* This method may block and should not be used in user interface threads.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if successful
|
|
|
|
*/
|
|
|
|
gboolean
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_set_alias_sync (SecretService *service,
|
2012-06-23 12:09:50 +00:00
|
|
|
const gchar *alias,
|
|
|
|
SecretCollection *collection,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
SecretSync *sync;
|
|
|
|
gboolean ret;
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_val_if_fail (service == NULL || SECRET_IS_SERVICE (service), FALSE);
|
2012-06-23 12:09:50 +00:00
|
|
|
g_return_val_if_fail (alias != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
|
|
|
sync = _secret_sync_new ();
|
|
|
|
g_main_context_push_thread_default (sync->context);
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
secret_service_set_alias (service, alias, collection, cancellable,
|
2012-06-23 12:09:50 +00:00
|
|
|
_secret_sync_on_result, sync);
|
|
|
|
|
|
|
|
g_main_loop_run (sync->loop);
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
ret = secret_service_set_alias_finish (service, sync->result, error);
|
2012-06-23 12:09:50 +00:00
|
|
|
|
|
|
|
g_main_context_pop_thread_default (sync->context);
|
|
|
|
_secret_sync_free (sync);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|