2012-02-01 12:34:08 +00:00
|
|
|
/* libsecret - GLib wrapper for Secret Service
|
2011-09-25 06:22:36 +00:00
|
|
|
*
|
2012-01-23 16:20:18 +00:00
|
|
|
* Copyright 2012 Red Hat Inc.
|
2011-09-25 06:22:36 +00:00
|
|
|
*
|
|
|
|
* 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
|
2011-09-25 06:22:36 +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>
|
2011-09-25 06:22:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
#include "secret-collection.h"
|
|
|
|
#include "secret-dbus-generated.h"
|
2012-07-05 13:38:38 +00:00
|
|
|
#include "secret-enum-types.h"
|
2012-02-01 12:34:08 +00:00
|
|
|
#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"
|
2011-09-25 06:22:36 +00:00
|
|
|
|
|
|
|
#include <glib/gi18n-lib.h>
|
|
|
|
|
2012-02-02 13:59:59 +00:00
|
|
|
/**
|
|
|
|
* SECTION:secret-item
|
|
|
|
* @title: SecretItem
|
|
|
|
* @short_description: A secret item
|
|
|
|
*
|
|
|
|
* #SecretItem represents a secret item stored in the Secret Service.
|
|
|
|
*
|
|
|
|
* Each item has a value, represented by a #SecretValue, which can be
|
2012-03-17 13:25:50 +00:00
|
|
|
* retrieved by secret_item_get_secret() or set by secret_item_set_secret().
|
2012-02-02 13:59:59 +00:00
|
|
|
* The item is only available when the item is not locked.
|
|
|
|
*
|
|
|
|
* Items can be locked or unlocked using the secret_service_lock() or
|
|
|
|
* secret_service_unlock() functions. The Secret Service may not be able to
|
|
|
|
* unlock individual items, and may unlock an entire collection when a single
|
|
|
|
* item is unlocked.
|
|
|
|
*
|
|
|
|
* Each item has a set of attributes, which are used to locate the item later.
|
|
|
|
* These are not stored or transferred in a secure manner. Each attribute has
|
|
|
|
* a string name and a string value. Use secret_service_search() to search for
|
2012-07-12 10:49:51 +00:00
|
|
|
* items based on their attributes, and secret_item_set_attributes() to change
|
2012-02-02 13:59:59 +00:00
|
|
|
* the attributes associated with an item.
|
|
|
|
*
|
|
|
|
* Items can be created with secret_item_create() or secret_service_store().
|
2012-03-24 06:52:12 +00:00
|
|
|
*
|
2012-04-27 14:57:36 +00:00
|
|
|
* Stability: Unstable
|
2012-02-02 13:59:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SecretItem:
|
|
|
|
*
|
|
|
|
* A proxy object representing a secret item in the Secret Service.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SecretItemClass:
|
|
|
|
* @parent_class: the parent class
|
|
|
|
*
|
|
|
|
* The class for #SecretItem.
|
|
|
|
*/
|
|
|
|
|
2012-07-05 13:38:38 +00:00
|
|
|
/**
|
|
|
|
* SecretItemFlags:
|
2012-07-06 08:21:04 +00:00
|
|
|
* @SECRET_ITEM_NONE: no flags
|
|
|
|
* @SECRET_ITEM_LOAD_SECRET: a secret has been (or should be) loaded for #SecretItem
|
2012-07-05 13:38:38 +00:00
|
|
|
*
|
2012-07-06 08:21:04 +00:00
|
|
|
* Flags which determine which parts of the #SecretItem proxy are initialized.
|
2012-07-05 13:38:38 +00:00
|
|
|
*/
|
|
|
|
|
2012-07-12 11:59:35 +00:00
|
|
|
/**
|
|
|
|
* SecretItemCreateFlags:
|
|
|
|
* @SECRET_ITEM_CREATE_NONE: no flags
|
|
|
|
* @SECRET_ITEM_CREATE_REPLACE: replace an item with the same attributes.
|
|
|
|
*
|
|
|
|
* Flags for secret_item_create().
|
|
|
|
*/
|
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
enum {
|
|
|
|
PROP_0,
|
2012-01-23 16:20:18 +00:00
|
|
|
PROP_SERVICE,
|
2012-07-05 13:38:38 +00:00
|
|
|
PROP_FLAGS,
|
2012-01-20 14:10:35 +00:00
|
|
|
PROP_ATTRIBUTES,
|
|
|
|
PROP_LABEL,
|
|
|
|
PROP_LOCKED,
|
|
|
|
PROP_CREATED,
|
|
|
|
PROP_MODIFIED
|
2011-09-25 06:22:36 +00:00
|
|
|
};
|
|
|
|
|
2012-03-30 11:53:44 +00:00
|
|
|
struct _SecretItemPrivate {
|
2012-07-05 13:38:38 +00:00
|
|
|
/* No changes between construct and finalize */
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *service;
|
2012-07-05 13:38:38 +00:00
|
|
|
SecretItemFlags init_flags;
|
2012-01-20 14:10:35 +00:00
|
|
|
GCancellable *cancellable;
|
2012-07-05 13:38:38 +00:00
|
|
|
|
|
|
|
/* Locked by mutex */
|
|
|
|
GMutex mutex;
|
|
|
|
SecretValue *value;
|
2012-03-30 11:53:44 +00:00
|
|
|
};
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
static GInitableIface *secret_item_initable_parent_iface = NULL;
|
2012-01-25 13:26:52 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
static GAsyncInitableIface *secret_item_async_initable_parent_iface = NULL;
|
2012-01-25 13:26:52 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
static void secret_item_initable_iface (GInitableIface *iface);
|
2012-01-25 13:26:52 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
static void secret_item_async_initable_iface (GAsyncInitableIface *iface);
|
2012-01-25 13:26:52 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (SecretItem, secret_item, G_TYPE_DBUS_PROXY,
|
|
|
|
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, secret_item_initable_iface);
|
|
|
|
G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, secret_item_async_initable_iface);
|
2012-01-25 13:26:52 +00:00
|
|
|
);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_init (SecretItem *self)
|
2011-09-25 06:22:36 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
self->pv = G_TYPE_INSTANCE_GET_PRIVATE (self, SECRET_TYPE_ITEM, SecretItemPrivate);
|
2012-01-23 16:20:18 +00:00
|
|
|
self->pv->cancellable = g_cancellable_new ();
|
2012-07-05 13:38:38 +00:00
|
|
|
g_mutex_init (&self->pv->mutex);
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_set_attributes (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *self = SECRET_ITEM (user_data);
|
2012-01-20 14:10:35 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_attributes_finish (self, result, &error);
|
2012-01-20 14:10:35 +00:00
|
|
|
if (error != NULL) {
|
2012-02-01 12:34:08 +00:00
|
|
|
g_warning ("couldn't set SecretItem Attributes: %s", error->message);
|
2012-01-20 14:10:35 +00:00
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (self);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_set_label (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *self = SECRET_ITEM (user_data);
|
2012-01-20 14:10:35 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_label_finish (self, result, &error);
|
2012-01-20 14:10:35 +00:00
|
|
|
if (error != NULL) {
|
2012-02-01 12:34:08 +00:00
|
|
|
g_warning ("couldn't set SecretItem Label: %s", error->message);
|
2012-01-20 14:10:35 +00:00
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (self);
|
|
|
|
}
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
item_take_service (SecretItem *self,
|
|
|
|
SecretService *service)
|
|
|
|
{
|
|
|
|
if (service == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_return_if_fail (self->pv->service == NULL);
|
|
|
|
|
|
|
|
self->pv->service = service;
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (self->pv->service),
|
|
|
|
(gpointer *)&self->pv->service);
|
|
|
|
|
|
|
|
/* Yes, we expect that the service will stay around */
|
|
|
|
g_object_unref (service);
|
|
|
|
}
|
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_property (GObject *obj,
|
2012-02-02 12:40:47 +00:00
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *self = SECRET_ITEM (obj);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2012-01-23 16:20:18 +00:00
|
|
|
case PROP_SERVICE:
|
2012-07-05 21:14:50 +00:00
|
|
|
item_take_service (self, g_value_dup_object (value));
|
2012-01-23 16:20:18 +00:00
|
|
|
break;
|
2012-07-05 13:38:38 +00:00
|
|
|
case PROP_FLAGS:
|
|
|
|
self->pv->init_flags = g_value_get_flags (value);
|
|
|
|
break;
|
2012-01-20 14:10:35 +00:00
|
|
|
case PROP_ATTRIBUTES:
|
2012-07-12 10:49:51 +00:00
|
|
|
secret_item_set_attributes (self, NULL, g_value_get_boxed (value),
|
2012-02-02 12:40:47 +00:00
|
|
|
self->pv->cancellable, on_set_attributes,
|
|
|
|
g_object_ref (self));
|
2012-01-20 14:10:35 +00:00
|
|
|
break;
|
|
|
|
case PROP_LABEL:
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_label (self, g_value_get_string (value),
|
2012-02-02 12:40:47 +00:00
|
|
|
self->pv->cancellable, on_set_label,
|
|
|
|
g_object_ref (self));
|
2012-01-20 14:10:35 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_get_property (GObject *obj,
|
2012-02-02 12:40:47 +00:00
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *self = SECRET_ITEM (obj);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2012-01-23 16:20:18 +00:00
|
|
|
case PROP_SERVICE:
|
|
|
|
g_value_set_object (value, self->pv->service);
|
|
|
|
break;
|
2012-07-05 13:38:38 +00:00
|
|
|
case PROP_FLAGS:
|
|
|
|
g_value_set_flags (value, secret_item_get_flags (self));
|
|
|
|
break;
|
2012-01-20 14:10:35 +00:00
|
|
|
case PROP_ATTRIBUTES:
|
2012-02-01 12:34:08 +00:00
|
|
|
g_value_take_boxed (value, secret_item_get_attributes (self));
|
2012-01-20 14:10:35 +00:00
|
|
|
break;
|
|
|
|
case PROP_LABEL:
|
2012-02-01 12:34:08 +00:00
|
|
|
g_value_take_string (value, secret_item_get_label (self));
|
2012-01-20 14:10:35 +00:00
|
|
|
break;
|
|
|
|
case PROP_LOCKED:
|
2012-02-01 12:34:08 +00:00
|
|
|
g_value_set_boolean (value, secret_item_get_locked (self));
|
2012-01-20 14:10:35 +00:00
|
|
|
break;
|
|
|
|
case PROP_CREATED:
|
2012-02-01 12:34:08 +00:00
|
|
|
g_value_set_uint64 (value, secret_item_get_created (self));
|
2012-01-20 14:10:35 +00:00
|
|
|
break;
|
|
|
|
case PROP_MODIFIED:
|
2012-02-01 12:34:08 +00:00
|
|
|
g_value_set_uint64 (value, secret_item_get_modified (self));
|
2012-01-20 14:10:35 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_dispose (GObject *obj)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *self = SECRET_ITEM (obj);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-01-23 16:20:18 +00:00
|
|
|
g_cancellable_cancel (self->pv->cancellable);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
G_OBJECT_CLASS (secret_item_parent_class)->dispose (obj);
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_finalize (GObject *obj)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *self = SECRET_ITEM (obj);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-01-23 16:20:18 +00:00
|
|
|
if (self->pv->service)
|
|
|
|
g_object_remove_weak_pointer (G_OBJECT (self->pv->service),
|
|
|
|
(gpointer *)&self->pv->service);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-01-23 16:20:18 +00:00
|
|
|
g_object_unref (self->pv->cancellable);
|
2012-07-05 13:38:38 +00:00
|
|
|
g_mutex_clear (&self->pv->mutex);
|
2012-01-23 16:20:18 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
G_OBJECT_CLASS (secret_item_parent_class)->finalize (obj);
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_property_changed (GObject *object,
|
|
|
|
const gchar *property_name)
|
|
|
|
{
|
|
|
|
if (g_str_equal (property_name, "Attributes"))
|
|
|
|
g_object_notify (object, "attributes");
|
|
|
|
|
|
|
|
else if (g_str_equal (property_name, "Label"))
|
|
|
|
g_object_notify (object, "label");
|
|
|
|
|
|
|
|
else if (g_str_equal (property_name, "Locked"))
|
|
|
|
g_object_notify (object, "locked");
|
|
|
|
|
|
|
|
else if (g_str_equal (property_name, "Created"))
|
|
|
|
g_object_notify (object, "created");
|
|
|
|
|
|
|
|
else if (g_str_equal (property_name, "Modified"))
|
|
|
|
g_object_notify (object, "modified");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_properties_changed (GDBusProxy *proxy,
|
2012-02-02 12:40:47 +00:00
|
|
|
GVariant *changed_properties,
|
|
|
|
const gchar* const *invalidated_properties)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
|
|
|
GObject *obj = G_OBJECT (proxy);
|
|
|
|
gchar *property_name;
|
|
|
|
GVariantIter iter;
|
|
|
|
GVariant *value;
|
|
|
|
|
|
|
|
g_object_freeze_notify (obj);
|
|
|
|
|
|
|
|
g_variant_iter_init (&iter, changed_properties);
|
|
|
|
while (g_variant_iter_loop (&iter, "{sv}", &property_name, &value))
|
|
|
|
handle_property_changed (obj, property_name);
|
|
|
|
|
|
|
|
g_object_thaw_notify (obj);
|
2011-09-25 06:22:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_class_init (SecretItemClass *klass)
|
2011-09-25 06:22:36 +00:00
|
|
|
{
|
2012-01-20 14:10:35 +00:00
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
GDBusProxyClass *proxy_class = G_DBUS_PROXY_CLASS (klass);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
gobject_class->get_property = secret_item_get_property;
|
|
|
|
gobject_class->set_property = secret_item_set_property;
|
|
|
|
gobject_class->dispose = secret_item_dispose;
|
|
|
|
gobject_class->finalize = secret_item_finalize;
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
proxy_class->g_properties_changed = secret_item_properties_changed;
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-02 13:59:59 +00:00
|
|
|
/**
|
|
|
|
* SecretItem:service:
|
|
|
|
*
|
|
|
|
* The #SecretService object that this item is associated with and
|
2012-03-24 12:31:14 +00:00
|
|
|
* uses to interact with the actual D-Bus Secret Service.
|
2012-02-02 13:59:59 +00:00
|
|
|
*/
|
2012-01-23 16:20:18 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_SERVICE,
|
|
|
|
g_param_spec_object ("service", "Service", "Secret Service",
|
2012-02-01 12:34:08 +00:00
|
|
|
SECRET_TYPE_SERVICE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
2012-01-23 16:20:18 +00:00
|
|
|
|
2012-07-05 13:38:38 +00:00
|
|
|
/**
|
|
|
|
* SecretService:flags:
|
|
|
|
*
|
|
|
|
* A set of flags describing which parts of the secret item have
|
|
|
|
* been initialized.
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_FLAGS,
|
|
|
|
g_param_spec_flags ("flags", "Flags", "Item flags",
|
|
|
|
secret_item_flags_get_type (), SECRET_ITEM_NONE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2012-02-02 13:59:59 +00:00
|
|
|
/**
|
|
|
|
* SecretItem:attributes:
|
|
|
|
*
|
|
|
|
* The attributes set on this item. Attributes are used to locate an
|
|
|
|
* item. They are not guaranteed to be stored or transferred securely.
|
2012-07-10 20:02:19 +00:00
|
|
|
*
|
|
|
|
* Type: GLib.HashTable(utf8,utf8)
|
|
|
|
* Transfer: full
|
2012-02-02 13:59:59 +00:00
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_ATTRIBUTES,
|
|
|
|
g_param_spec_boxed ("attributes", "Attributes", "Item attributes",
|
2012-01-23 16:20:18 +00:00
|
|
|
G_TYPE_HASH_TABLE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-02 13:59:59 +00:00
|
|
|
/**
|
|
|
|
* SecretItem:label:
|
|
|
|
*
|
|
|
|
* The human readable label for the item.
|
|
|
|
*
|
|
|
|
* Setting this property will result in the label of the item being
|
|
|
|
* set asynchronously. To properly track the changing of the label use the
|
|
|
|
* secret_item_set_label() function.
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_LABEL,
|
|
|
|
g_param_spec_string ("label", "Label", "Item label",
|
2012-01-23 16:20:18 +00:00
|
|
|
NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-02 13:59:59 +00:00
|
|
|
/**
|
|
|
|
* SecretItem:locked:
|
|
|
|
*
|
|
|
|
* Whether the item is locked or not. An item may not be independently
|
|
|
|
* lockable separate from other items in its collection.
|
|
|
|
*
|
|
|
|
* To lock or unlock a item use the secret_service_lock() or
|
|
|
|
* secret_service_unlock() functions.
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_LOCKED,
|
|
|
|
g_param_spec_boolean ("locked", "Locked", "Item locked",
|
2012-01-23 16:20:18 +00:00
|
|
|
TRUE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-02 13:59:59 +00:00
|
|
|
/**
|
|
|
|
* SecretItem:created:
|
|
|
|
*
|
|
|
|
* The date and time (in seconds since the UNIX epoch) that this
|
|
|
|
* item was created.
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_CREATED,
|
|
|
|
g_param_spec_uint64 ("created", "Created", "Item creation date",
|
2012-01-23 16:20:18 +00:00
|
|
|
0UL, G_MAXUINT64, 0UL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-02 13:59:59 +00:00
|
|
|
/**
|
|
|
|
* SecretItem:modified:
|
|
|
|
*
|
|
|
|
* The date and time (in seconds since the UNIX epoch) that this
|
|
|
|
* item was last modified.
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_MODIFIED,
|
|
|
|
g_param_spec_uint64 ("modified", "Modified", "Item modified date",
|
2012-01-23 16:20:18 +00:00
|
|
|
0UL, G_MAXUINT64, 0UL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_type_class_add_private (gobject_class, sizeof (SecretItemPrivate));
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2012-07-05 13:38:38 +00:00
|
|
|
typedef struct {
|
|
|
|
GCancellable *cancellable;
|
|
|
|
} InitClosure;
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_closure_free (gpointer data)
|
|
|
|
{
|
|
|
|
InitClosure *closure = data;
|
|
|
|
g_clear_object (&closure->cancellable);
|
|
|
|
g_slice_free (InitClosure, closure);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
item_ensure_for_flags_sync (SecretItem *self,
|
|
|
|
SecretItemFlags flags,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
if (flags & SECRET_ITEM_LOAD_SECRET && !secret_item_get_locked (self)) {
|
|
|
|
if (!secret_item_load_secret_sync (self, cancellable, error))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_init_load_secret (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
SecretItem *self = SECRET_ITEM (source);
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
if (!secret_item_load_secret_finish (self, result, &error))
|
|
|
|
g_simple_async_result_take_error (async, error);
|
|
|
|
|
|
|
|
g_simple_async_result_complete (async);
|
|
|
|
g_object_unref (async);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
item_ensure_for_flags_async (SecretItem *self,
|
|
|
|
SecretItemFlags flags,
|
|
|
|
GSimpleAsyncResult *async)
|
|
|
|
{
|
|
|
|
InitClosure *init = g_simple_async_result_get_op_res_gpointer (async);
|
|
|
|
|
|
|
|
if (flags & SECRET_ITEM_LOAD_SECRET && !secret_item_get_locked (self))
|
|
|
|
secret_item_load_secret (self, init->cancellable,
|
|
|
|
on_init_load_secret, g_object_ref (async));
|
|
|
|
|
|
|
|
else
|
|
|
|
g_simple_async_result_complete (async);
|
|
|
|
}
|
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
static gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_initable_init (GInitable *initable,
|
2012-02-02 12:40:47 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2012-01-25 13:26:52 +00:00
|
|
|
{
|
2012-07-05 13:38:38 +00:00
|
|
|
SecretItem *self;
|
2012-07-05 21:14:50 +00:00
|
|
|
SecretService *service;
|
2012-01-25 13:26:52 +00:00
|
|
|
GDBusProxy *proxy;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
if (!secret_item_initable_parent_iface->init (initable, cancellable, error))
|
2012-01-25 13:26:52 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
proxy = G_DBUS_PROXY (initable);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
if (!_secret_util_have_cached_properties (proxy)) {
|
2012-01-25 13:26:52 +00:00
|
|
|
g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD,
|
|
|
|
"No such secret item at path: %s",
|
|
|
|
g_dbus_proxy_get_object_path (proxy));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-07-05 13:38:38 +00:00
|
|
|
self = SECRET_ITEM (initable);
|
2012-07-05 21:14:50 +00:00
|
|
|
if (!self->pv->service) {
|
|
|
|
service = secret_service_get_sync (SECRET_SERVICE_NONE, cancellable, error);
|
|
|
|
if (service == NULL)
|
|
|
|
return FALSE;
|
|
|
|
else
|
|
|
|
item_take_service (self, service);
|
|
|
|
}
|
|
|
|
|
2012-07-05 13:38:38 +00:00
|
|
|
return item_ensure_for_flags_sync (self, self->pv->init_flags, cancellable, error);
|
2012-01-25 13:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_initable_iface (GInitableIface *iface)
|
2012-01-25 13:26:52 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_initable_parent_iface = g_type_interface_peek_parent (iface);
|
2012-01-25 13:26:52 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
iface->init = secret_item_initable_init;
|
2012-01-25 13:26:52 +00:00
|
|
|
}
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
static void
|
|
|
|
on_init_service (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
SecretItem *self = SECRET_ITEM (g_async_result_get_source_object (user_data));
|
|
|
|
SecretService *service;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
service = secret_service_get_finish (result, &error);
|
|
|
|
if (error == NULL) {
|
|
|
|
item_take_service (self, service);
|
|
|
|
item_ensure_for_flags_async (self, self->pv->init_flags, async);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
g_simple_async_result_take_error (async, error);
|
|
|
|
g_simple_async_result_complete (async);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (self);
|
|
|
|
g_object_unref (async);
|
|
|
|
}
|
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
static void
|
|
|
|
on_init_base (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
2012-07-05 21:14:50 +00:00
|
|
|
InitClosure *init = g_simple_async_result_get_op_res_gpointer (res);
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *self = SECRET_ITEM (source);
|
2012-01-25 13:26:52 +00:00
|
|
|
GDBusProxy *proxy = G_DBUS_PROXY (self);
|
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
if (!secret_item_async_initable_parent_iface->init_finish (G_ASYNC_INITABLE (self),
|
2012-02-02 12:40:47 +00:00
|
|
|
result, &error)) {
|
2012-01-25 13:26:52 +00:00
|
|
|
g_simple_async_result_take_error (res, error);
|
2012-07-05 13:38:38 +00:00
|
|
|
g_simple_async_result_complete (res);
|
2012-01-25 13:26:52 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
} else if (!_secret_util_have_cached_properties (proxy)) {
|
2012-01-25 13:26:52 +00:00
|
|
|
g_simple_async_result_set_error (res, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD,
|
|
|
|
"No such secret item at path: %s",
|
|
|
|
g_dbus_proxy_get_object_path (proxy));
|
2012-07-05 13:38:38 +00:00
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
} else if (self->pv->service == NULL) {
|
|
|
|
secret_service_get (SECRET_SERVICE_NONE, init->cancellable,
|
|
|
|
on_init_service, g_object_ref (res));
|
|
|
|
|
2012-07-05 13:38:38 +00:00
|
|
|
} else {
|
|
|
|
item_ensure_for_flags_async (self, self->pv->init_flags, res);
|
2012-01-25 13:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_async_initable_init_async (GAsyncInitable *initable,
|
2012-02-02 12:40:47 +00:00
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2012-01-25 13:26:52 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
2012-07-05 13:38:38 +00:00
|
|
|
InitClosure *init;
|
2012-01-25 13:26:52 +00:00
|
|
|
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (initable), callback, user_data,
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_async_initable_init_async);
|
2012-07-05 13:38:38 +00:00
|
|
|
init = g_slice_new0 (InitClosure);
|
|
|
|
init->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
|
|
|
g_simple_async_result_set_op_res_gpointer (res, init, init_closure_free);
|
2012-01-25 13:26:52 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_async_initable_parent_iface->init_async (initable, io_priority,
|
2012-02-02 12:40:47 +00:00
|
|
|
cancellable,
|
|
|
|
on_init_base,
|
|
|
|
g_object_ref (res));
|
2012-01-25 13:26:52 +00:00
|
|
|
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_async_initable_init_finish (GAsyncInitable *initable,
|
2012-02-02 12:40:47 +00:00
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
2012-01-25 13:26:52 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (initable),
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_async_initable_init_async), FALSE);
|
2012-01-25 13:26:52 +00:00
|
|
|
|
|
|
|
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-01-23 16:20:18 +00:00
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_async_initable_iface (GAsyncInitableIface *iface)
|
2012-01-23 16:20:18 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_async_initable_parent_iface = g_type_interface_peek_parent (iface);
|
2012-01-25 13:26:52 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
iface->init_async = secret_item_async_initable_init_async;
|
|
|
|
iface->init_finish = secret_item_async_initable_init_finish;
|
2012-01-23 16:20:18 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_refresh:
|
|
|
|
* @self: the collection
|
|
|
|
*
|
|
|
|
* Refresh the properties on this item. This fires off a request to
|
|
|
|
* refresh, and the properties will be updated later.
|
|
|
|
*
|
|
|
|
* Calling this method is not normally necessary, as the secret service
|
|
|
|
* will notify the client when properties change.
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_refresh (SecretItem *self)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_if_fail (SECRET_IS_ITEM (self));
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_util_get_properties (G_DBUS_PROXY (self),
|
2012-02-02 12:40:47 +00:00
|
|
|
secret_item_refresh,
|
|
|
|
NULL, NULL, NULL);
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2012-07-05 13:38:38 +00:00
|
|
|
void
|
|
|
|
_secret_item_set_cached_secret (SecretItem *self,
|
|
|
|
SecretValue *value)
|
|
|
|
{
|
|
|
|
SecretValue *other = NULL;
|
|
|
|
gboolean updated = FALSE;
|
|
|
|
|
|
|
|
g_return_if_fail (SECRET_IS_ITEM (self));
|
|
|
|
|
|
|
|
if (value != NULL)
|
|
|
|
secret_value_ref (value);
|
|
|
|
|
|
|
|
g_mutex_lock (&self->pv->mutex);
|
|
|
|
|
|
|
|
if (value != self->pv->value) {
|
|
|
|
other = self->pv->value;
|
|
|
|
self->pv->value = value;
|
|
|
|
updated = TRUE;
|
|
|
|
} else {
|
|
|
|
other = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_mutex_unlock (&self->pv->mutex);
|
|
|
|
|
|
|
|
if (other != NULL)
|
|
|
|
secret_value_unref (other);
|
|
|
|
|
|
|
|
if (updated)
|
|
|
|
g_object_notify (G_OBJECT (self), "flags");
|
|
|
|
}
|
2012-01-26 17:23:12 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
GCancellable *cancellable;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *item;
|
2012-07-05 13:38:38 +00:00
|
|
|
SecretValue *value;
|
2012-01-26 17:23:12 +00:00
|
|
|
} CreateClosure;
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_closure_free (gpointer data)
|
|
|
|
{
|
|
|
|
CreateClosure *closure = data;
|
|
|
|
g_clear_object (&closure->cancellable);
|
|
|
|
g_clear_object (&closure->item);
|
2012-07-05 13:38:38 +00:00
|
|
|
secret_value_unref (closure->value);
|
2012-01-26 17:23:12 +00:00
|
|
|
g_slice_free (CreateClosure, closure);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_create_item (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
CreateClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-07-06 07:01:20 +00:00
|
|
|
closure->item = secret_item_new_for_dbus_path_finish (result, &error);
|
2012-01-26 17:23:12 +00:00
|
|
|
if (error != NULL)
|
|
|
|
g_simple_async_result_take_error (res, error);
|
|
|
|
|
2012-07-05 13:38:38 +00:00
|
|
|
/* As a convenince mark down the SecretValue on the item */
|
|
|
|
_secret_item_set_cached_secret (closure->item, closure->value);
|
|
|
|
|
2012-01-26 17:23:12 +00:00
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_create_path (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
CreateClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *service = SECRET_SERVICE (source);
|
2012-01-26 17:23:12 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
gchar *path;
|
|
|
|
|
2012-07-06 07:01:20 +00:00
|
|
|
path = secret_service_create_item_dbus_path_finish (service, result, &error);
|
2012-01-26 17:23:12 +00:00
|
|
|
if (error == NULL) {
|
2012-07-06 07:01:20 +00:00
|
|
|
secret_item_new_for_dbus_path (service, path, SECRET_ITEM_NONE,
|
|
|
|
closure->cancellable, on_create_item,
|
|
|
|
g_object_ref (res));
|
2012-01-26 17:23:12 +00:00
|
|
|
} else {
|
|
|
|
g_simple_async_result_take_error (res, error);
|
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GHashTable *
|
2012-03-18 18:04:44 +00:00
|
|
|
item_properties_new (const gchar *label,
|
2012-07-12 10:49:51 +00:00
|
|
|
const SecretSchema *schema,
|
2012-01-26 17:23:12 +00:00
|
|
|
GHashTable *attributes)
|
|
|
|
{
|
2012-07-12 10:49:51 +00:00
|
|
|
const gchar *schema_name = NULL;
|
2012-01-26 17:23:12 +00:00
|
|
|
GHashTable *properties;
|
|
|
|
GVariant *value;
|
|
|
|
|
2012-07-12 10:49:51 +00:00
|
|
|
if (schema != NULL)
|
|
|
|
schema_name = schema->name;
|
|
|
|
|
2012-01-26 17:23:12 +00:00
|
|
|
properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
|
|
|
|
(GDestroyNotify)g_variant_unref);
|
|
|
|
|
|
|
|
value = g_variant_new_string (label);
|
|
|
|
g_hash_table_insert (properties,
|
2012-02-01 12:34:08 +00:00
|
|
|
SECRET_ITEM_INTERFACE ".Label",
|
2012-01-26 17:23:12 +00:00
|
|
|
g_variant_ref_sink (value));
|
|
|
|
|
2012-07-12 10:49:51 +00:00
|
|
|
value = _secret_attributes_to_variant (attributes, schema_name);
|
2012-01-26 17:23:12 +00:00
|
|
|
g_hash_table_insert (properties,
|
2012-02-01 12:34:08 +00:00
|
|
|
SECRET_ITEM_INTERFACE ".Attributes",
|
2012-01-26 17:23:12 +00:00
|
|
|
g_variant_ref_sink (value));
|
|
|
|
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_create:
|
|
|
|
* @collection: a secret collection to create this item in
|
2012-07-12 10:49:51 +00:00
|
|
|
* @schema: (allow-none): the schema for the attributes
|
2012-03-11 08:06:40 +00:00
|
|
|
* @attributes: (element-type utf8 utf8): attributes for the new item
|
2012-07-12 10:49:51 +00:00
|
|
|
* @label: label for the new item
|
2012-02-02 12:40:47 +00:00
|
|
|
* @value: secret value for the new item
|
2012-07-12 11:59:35 +00:00
|
|
|
* @flags: flags for the creation of the new item
|
2012-02-02 13:59:59 +00:00
|
|
|
* @cancellable: optional cancellation object
|
2012-02-02 12:40:47 +00:00
|
|
|
* @callback: called when the operation completes
|
|
|
|
* @user_data: data to pass to the callback
|
|
|
|
*
|
|
|
|
* Create a new item in the secret service.
|
|
|
|
*
|
2012-07-12 11:59:35 +00:00
|
|
|
* If the @flags contains %SECRET_ITEM_CREATE_REPLACE, then the secret
|
|
|
|
* service will search for an item matching the @attributes, and update that item
|
|
|
|
* instead of creating a new one.
|
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 are required.
|
|
|
|
*/
|
2012-01-26 17:23:12 +00:00
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_create (SecretCollection *collection,
|
2012-07-12 10:49:51 +00:00
|
|
|
const SecretSchema *schema,
|
2012-02-02 12:40:47 +00:00
|
|
|
GHashTable *attributes,
|
2012-07-12 10:49:51 +00:00
|
|
|
const gchar *label,
|
2012-02-02 12:40:47 +00:00
|
|
|
SecretValue *value,
|
2012-07-12 11:59:35 +00:00
|
|
|
SecretItemCreateFlags flags,
|
2012-02-02 12:40:47 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2012-01-26 17:23:12 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *service = NULL;
|
2012-01-26 17:23:12 +00:00
|
|
|
const gchar *collection_path;
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
CreateClosure *closure;
|
|
|
|
GHashTable *properties;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_if_fail (SECRET_IS_COLLECTION (collection));
|
2012-01-26 17:23:12 +00:00
|
|
|
g_return_if_fail (label != NULL);
|
|
|
|
g_return_if_fail (attributes != NULL);
|
|
|
|
g_return_if_fail (value != NULL);
|
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
2012-07-12 10:49:51 +00:00
|
|
|
/* Warnings raised already */
|
|
|
|
if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, FALSE))
|
|
|
|
return;
|
|
|
|
|
2012-01-26 17:23:12 +00:00
|
|
|
res = g_simple_async_result_new (NULL, callback, user_data,
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_create);
|
2012-01-26 17:23:12 +00:00
|
|
|
closure = g_slice_new0 (CreateClosure);
|
|
|
|
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
2012-07-05 13:38:38 +00:00
|
|
|
closure->value = secret_value_ref (value);
|
2012-01-26 17:23:12 +00:00
|
|
|
g_simple_async_result_set_op_res_gpointer (res, closure, create_closure_free);
|
|
|
|
|
2012-07-12 10:49:51 +00:00
|
|
|
properties = item_properties_new (label, schema, attributes);
|
2012-01-26 17:23:12 +00:00
|
|
|
g_object_get (collection, "service", &service, NULL);
|
|
|
|
|
|
|
|
collection_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection));
|
|
|
|
|
2012-07-06 07:01:20 +00:00
|
|
|
secret_service_create_item_dbus_path (service, collection_path, properties,
|
2012-07-12 11:59:35 +00:00
|
|
|
value, flags, cancellable,
|
2012-07-06 07:01:20 +00:00
|
|
|
on_create_path, g_object_ref (res));
|
2012-01-26 17:23:12 +00:00
|
|
|
|
|
|
|
g_hash_table_unref (properties);
|
|
|
|
g_object_unref (service);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_create_finish:
|
|
|
|
* @result: the asynchronous result passed to the callback
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Finish operation to create a new item in the secret service.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the new item, which should be unreferenced
|
|
|
|
* with g_object_unref()
|
|
|
|
*/
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *
|
|
|
|
secret_item_create_finish (GAsyncResult *result,
|
2012-02-02 12:40:47 +00:00
|
|
|
GError **error)
|
2012-01-26 17:23:12 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
CreateClosure *closure;
|
|
|
|
|
|
|
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, NULL,
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_create), NULL);
|
2012-01-26 17:23:12 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
|
|
|
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);
|
|
|
|
if (closure->item == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return g_object_ref (closure->item);
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_create_sync:
|
|
|
|
* @collection: a secret collection to create this item in
|
2012-07-12 10:49:51 +00:00
|
|
|
* @schema: (allow-none): the schema for the attributes
|
2012-03-11 08:06:40 +00:00
|
|
|
* @attributes: (element-type utf8 utf8): attributes for the new item
|
2012-07-12 10:49:51 +00:00
|
|
|
* @label: label for the new item
|
2012-02-02 12:40:47 +00:00
|
|
|
* @value: secret value for the new item
|
2012-07-12 11:59:35 +00:00
|
|
|
* @flags: flags for the creation of the new item
|
2012-02-02 12:40:47 +00:00
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Create a new item in the secret service.
|
|
|
|
*
|
2012-07-12 11:59:35 +00:00
|
|
|
* If the @flags contains %SECRET_ITEM_CREATE_REPLACE, then the secret
|
|
|
|
* service will search for an item matching the @attributes, and update that item
|
|
|
|
* instead of creating a new one.
|
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 are required.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the new item, which should be unreferenced
|
|
|
|
* with g_object_unref()
|
|
|
|
*/
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *
|
|
|
|
secret_item_create_sync (SecretCollection *collection,
|
2012-07-12 10:49:51 +00:00
|
|
|
const SecretSchema *schema,
|
2012-02-02 12:40:47 +00:00
|
|
|
GHashTable *attributes,
|
2012-07-12 10:49:51 +00:00
|
|
|
const gchar *label,
|
2012-02-02 12:40:47 +00:00
|
|
|
SecretValue *value,
|
2012-07-12 11:59:35 +00:00
|
|
|
SecretItemCreateFlags flags,
|
2012-02-02 12:40:47 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2012-01-26 17:23:12 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *service = NULL;
|
2012-01-26 17:23:12 +00:00
|
|
|
const gchar *collection_path;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *item = NULL;
|
2012-01-26 17:23:12 +00:00
|
|
|
GHashTable *properties;
|
|
|
|
gchar *path;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_COLLECTION (collection), NULL);
|
2012-01-26 17:23:12 +00:00
|
|
|
g_return_val_if_fail (label != NULL, NULL);
|
|
|
|
g_return_val_if_fail (attributes != NULL, NULL);
|
|
|
|
g_return_val_if_fail (value != 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-12 10:49:51 +00:00
|
|
|
/* Warnings raised already */
|
|
|
|
if (schema != NULL && !_secret_attributes_validate (schema, attributes, G_STRFUNC, FALSE))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
properties = item_properties_new (label, schema, attributes);
|
2012-01-26 17:23:12 +00:00
|
|
|
g_object_get (collection, "service", &service, NULL);
|
|
|
|
|
|
|
|
collection_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection));
|
|
|
|
|
2012-07-06 07:01:20 +00:00
|
|
|
path = secret_service_create_item_dbus_path_sync (service, collection_path, properties,
|
2012-07-12 11:59:35 +00:00
|
|
|
value, flags, cancellable, error);
|
2012-01-26 17:23:12 +00:00
|
|
|
|
|
|
|
if (path != NULL) {
|
2012-07-06 07:01:20 +00:00
|
|
|
item = secret_item_new_for_dbus_path_sync (service, path, SECRET_ITEM_NONE,
|
|
|
|
cancellable, error);
|
2012-01-26 17:23:12 +00:00
|
|
|
g_free (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hash_table_unref (properties);
|
|
|
|
g_object_unref (service);
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
static void
|
|
|
|
on_item_deleted (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *self = SECRET_ITEM (g_async_result_get_source_object (user_data));
|
2012-01-20 14:10:35 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-07-06 07:01:20 +00:00
|
|
|
if (_secret_service_delete_path_finish (SECRET_SERVICE (source), result, &error))
|
2012-01-23 16:20:18 +00:00
|
|
|
g_simple_async_result_set_op_res_gboolean (res, TRUE);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
if (error != NULL)
|
|
|
|
g_simple_async_result_take_error (res, error);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
g_object_unref (self);
|
|
|
|
g_object_unref (res);
|
2011-09-25 06:22:36 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
2012-04-27 14:57:36 +00:00
|
|
|
* secret_item_delete:
|
|
|
|
* @self: an item
|
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
|
|
|
|
*
|
2012-04-27 14:57:36 +00:00
|
|
|
* Delete this item.
|
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.
|
|
|
|
*/
|
2011-09-25 06:22:36 +00:00
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_delete (SecretItem *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2011-09-25 06:22:36 +00:00
|
|
|
{
|
2012-01-20 14:10:35 +00:00
|
|
|
GSimpleAsyncResult *res;
|
2011-09-25 06:22:36 +00:00
|
|
|
const gchar *object_path;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_if_fail (SECRET_IS_ITEM (self));
|
2011-09-25 06:22:36 +00:00
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
|
|
|
object_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (self));
|
2012-01-20 14:10:35 +00:00
|
|
|
res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_delete);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_service_delete_path (self->pv->service, object_path, TRUE,
|
2012-02-02 12:40:47 +00:00
|
|
|
cancellable, on_item_deleted, g_object_ref (res));
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
g_object_unref (res);
|
2011-09-25 06:22:36 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_delete_finish:
|
|
|
|
* @self: an item
|
|
|
|
* @result: asynchronous result passed to the callback
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Complete asynchronous operation to delete the secret item.
|
|
|
|
*
|
|
|
|
* Returns: whether the item was successfully deleted or not
|
|
|
|
*/
|
2011-09-25 06:22:36 +00:00
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_delete_finish (SecretItem *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
2011-09-25 06:22:36 +00:00
|
|
|
{
|
2012-01-23 16:20:18 +00:00
|
|
|
GSimpleAsyncResult *res;
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), FALSE);
|
2011-09-25 06:22:36 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
2012-01-23 16:20:18 +00:00
|
|
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_delete), FALSE);
|
2012-01-23 16:20:18 +00:00
|
|
|
|
|
|
|
res = G_SIMPLE_ASYNC_RESULT (result);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-01-23 16:20:18 +00:00
|
|
|
if (g_simple_async_result_propagate_error (res, error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_simple_async_result_get_op_res_gboolean (res);
|
2011-09-25 06:22:36 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_delete_sync:
|
|
|
|
* @self: an item
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Delete this secret item.
|
|
|
|
*
|
|
|
|
* 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: whether the item was successfully deleted or not
|
|
|
|
*/
|
2011-09-25 06:22:36 +00:00
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_delete_sync (SecretItem *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2011-09-25 06:22:36 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretSync *sync;
|
2012-01-20 14:10:35 +00:00
|
|
|
gboolean ret;
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), FALSE);
|
2011-09-25 06:22:36 +00:00
|
|
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
sync = _secret_sync_new ();
|
2012-01-20 14:10:35 +00:00
|
|
|
g_main_context_push_thread_default (sync->context);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_delete (self, cancellable, _secret_sync_on_result, sync);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
g_main_loop_run (sync->loop);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_item_delete_finish (self, sync->result, error);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
g_main_context_pop_thread_default (sync->context);
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_sync_free (sync);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
return ret;
|
2011-09-25 06:22:36 +00:00
|
|
|
}
|
|
|
|
|
2012-07-05 13:38:38 +00:00
|
|
|
/**
|
|
|
|
* secret_item_get_flags:
|
|
|
|
* @self: the secret item proxy
|
|
|
|
*
|
|
|
|
* Get the flags representing what features of the #SecretItem proxy
|
|
|
|
* have been initialized.
|
|
|
|
*
|
|
|
|
* Use secret_item_load_secret() to initialize further features
|
|
|
|
* and change the flags.
|
|
|
|
*
|
|
|
|
* Returns: the flags for features initialized
|
|
|
|
*/
|
|
|
|
SecretItemFlags
|
|
|
|
secret_item_get_flags (SecretItem *self)
|
|
|
|
{
|
|
|
|
SecretServiceFlags flags = 0;
|
|
|
|
|
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), SECRET_ITEM_NONE);
|
|
|
|
|
|
|
|
g_mutex_lock (&self->pv->mutex);
|
|
|
|
|
|
|
|
if (self->pv->value)
|
|
|
|
flags |= SECRET_ITEM_LOAD_SECRET;
|
|
|
|
|
|
|
|
g_mutex_unlock (&self->pv->mutex);
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-06-25 08:17:16 +00:00
|
|
|
/**
|
|
|
|
* secret_item_get_service:
|
|
|
|
* @self: an item
|
|
|
|
*
|
|
|
|
* Get the Secret Service object that this item was created with.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): the Secret Service object
|
|
|
|
*/
|
|
|
|
SecretService *
|
|
|
|
secret_item_get_service (SecretItem *self)
|
|
|
|
{
|
2012-07-05 15:11:38 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), NULL);
|
2012-06-25 08:17:16 +00:00
|
|
|
return self->pv->service;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-05 13:38:38 +00:00
|
|
|
/**
|
|
|
|
* secret_item_get_secret:
|
|
|
|
* @self: an item
|
|
|
|
*
|
|
|
|
* Get the secret value of this item. If this item is locked or the secret
|
|
|
|
* has not yet been loaded then this will return %NULL.
|
|
|
|
*
|
2012-07-06 08:21:04 +00:00
|
|
|
* To load the secret call the secret_item_load_secret() method.
|
2012-07-05 13:38:38 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer full) (allow-none): the secret value which should be
|
|
|
|
* released with secret_value_unref(), or %NULL
|
|
|
|
*/
|
|
|
|
SecretValue *
|
|
|
|
secret_item_get_secret (SecretItem *self)
|
|
|
|
{
|
|
|
|
SecretValue *value = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), NULL);
|
|
|
|
|
|
|
|
g_mutex_lock (&self->pv->mutex);
|
|
|
|
|
|
|
|
if (self->pv->value)
|
|
|
|
value = secret_value_ref (self->pv->value);
|
|
|
|
|
|
|
|
g_mutex_unlock (&self->pv->mutex);
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-23 16:20:18 +00:00
|
|
|
typedef struct {
|
|
|
|
GCancellable *cancellable;
|
2012-07-05 13:38:38 +00:00
|
|
|
} LoadClosure;
|
2012-01-23 16:20:18 +00:00
|
|
|
|
|
|
|
static void
|
2012-07-05 13:38:38 +00:00
|
|
|
load_closure_free (gpointer data)
|
2012-01-23 16:20:18 +00:00
|
|
|
{
|
2012-07-05 13:38:38 +00:00
|
|
|
LoadClosure *closure = data;
|
2012-01-23 16:20:18 +00:00
|
|
|
g_clear_object (&closure->cancellable);
|
2012-07-05 13:38:38 +00:00
|
|
|
g_slice_free (LoadClosure, closure);
|
2012-01-23 16:20:18 +00:00
|
|
|
}
|
|
|
|
|
2011-09-25 06:22:36 +00:00
|
|
|
static void
|
2012-07-05 13:38:38 +00:00
|
|
|
on_item_load_secret (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
2011-09-25 06:22:36 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *self = SECRET_ITEM (g_async_result_get_source_object (user_data));
|
|
|
|
SecretSession *session;
|
2011-09-25 06:22:36 +00:00
|
|
|
GError *error = NULL;
|
2012-07-05 13:38:38 +00:00
|
|
|
SecretValue *value;
|
2012-01-23 16:20:18 +00:00
|
|
|
GVariant *retval;
|
|
|
|
GVariant *child;
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-01-23 16:20:18 +00:00
|
|
|
retval = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), result, &error);
|
2011-09-25 06:22:36 +00:00
|
|
|
if (error == NULL) {
|
2012-01-23 16:20:18 +00:00
|
|
|
child = g_variant_get_child_value (retval, 0);
|
|
|
|
g_variant_unref (retval);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
session = _secret_service_get_session (self->pv->service);
|
2012-07-05 13:38:38 +00:00
|
|
|
value = _secret_session_decode_secret (session, child);
|
2012-01-23 16:20:18 +00:00
|
|
|
g_variant_unref (child);
|
|
|
|
|
2012-07-05 13:38:38 +00:00
|
|
|
if (value == NULL) {
|
2012-02-01 12:34:08 +00:00
|
|
|
g_set_error (&error, SECRET_ERROR, SECRET_ERROR_PROTOCOL,
|
2011-09-25 06:22:36 +00:00
|
|
|
_("Received invalid secret from the secret storage"));
|
2012-07-05 13:38:38 +00:00
|
|
|
} else {
|
|
|
|
_secret_item_set_cached_secret (self, value);
|
|
|
|
secret_value_unref (value);
|
|
|
|
}
|
2011-09-25 06:22:36 +00:00
|
|
|
}
|
|
|
|
|
2012-07-09 06:44:50 +00:00
|
|
|
if (error != NULL) {
|
|
|
|
_secret_util_strip_remote_error (&error);
|
2011-09-25 06:22:36 +00:00
|
|
|
g_simple_async_result_take_error (res, error);
|
2012-07-09 06:44:50 +00:00
|
|
|
}
|
2011-09-25 06:22:36 +00:00
|
|
|
|
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-07-05 13:38:38 +00:00
|
|
|
on_load_ensure_session (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
2011-09-25 06:22:36 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *self = SECRET_ITEM (g_async_result_get_source_object (user_data));
|
2012-07-05 13:38:38 +00:00
|
|
|
LoadClosure *load = g_simple_async_result_get_op_res_gpointer (res);
|
2011-09-25 06:22:36 +00:00
|
|
|
const gchar *session_path;
|
2012-01-23 16:20:18 +00:00
|
|
|
GError *error = NULL;
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-07-06 07:01:20 +00:00
|
|
|
secret_service_ensure_session_finish (self->pv->service, result, &error);
|
2011-09-25 06:22:36 +00:00
|
|
|
if (error != NULL) {
|
|
|
|
g_simple_async_result_take_error (res, error);
|
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
|
|
|
|
} else {
|
2012-07-06 07:01:20 +00:00
|
|
|
session_path = secret_service_get_session_dbus_path (self->pv->service);
|
2011-09-25 06:22:36 +00:00
|
|
|
g_assert (session_path != NULL && session_path[0] != '\0');
|
|
|
|
g_dbus_proxy_call (G_DBUS_PROXY (self), "GetSecret",
|
2012-01-23 16:20:18 +00:00
|
|
|
g_variant_new ("(o)", session_path),
|
2012-07-05 13:38:38 +00:00
|
|
|
G_DBUS_CALL_FLAGS_NONE, -1, load->cancellable,
|
|
|
|
on_item_load_secret, g_object_ref (res));
|
2011-09-25 06:22:36 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 17:23:12 +00:00
|
|
|
g_object_unref (self);
|
2011-09-25 06:22:36 +00:00
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
2012-07-05 13:38:38 +00:00
|
|
|
* secret_item_load_secret:
|
|
|
|
* @self: an item proxy
|
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
|
|
|
|
*
|
2012-07-05 13:38:38 +00:00
|
|
|
* Load the secret value of this item.
|
2012-02-02 12:40:47 +00:00
|
|
|
*
|
|
|
|
* Each item has a single secret which might be a password or some
|
2012-07-06 08:21:04 +00:00
|
|
|
* other secret binary value.
|
2012-07-05 13:38:38 +00:00
|
|
|
*
|
|
|
|
* This function will fail if the secret item is locked.
|
2012-02-02 12:40:47 +00:00
|
|
|
*
|
|
|
|
* This function returns immediately and completes asynchronously.
|
|
|
|
*/
|
2011-09-25 06:22:36 +00:00
|
|
|
void
|
2012-07-05 13:38:38 +00:00
|
|
|
secret_item_load_secret (SecretItem *self,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2011-09-25 06:22:36 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
2012-07-05 13:38:38 +00:00
|
|
|
LoadClosure *closure;
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_if_fail (SECRET_IS_ITEM (self));
|
2011-09-25 06:22:36 +00:00
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (self), callback,
|
2012-07-05 13:38:38 +00:00
|
|
|
user_data, secret_item_load_secret);
|
|
|
|
closure = g_slice_new0 (LoadClosure);
|
2012-01-23 16:20:18 +00:00
|
|
|
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
2012-07-05 13:38:38 +00:00
|
|
|
g_simple_async_result_set_op_res_gpointer (res, closure, load_closure_free);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_ensure_session (self->pv->service, cancellable,
|
2012-07-05 13:38:38 +00:00
|
|
|
on_load_ensure_session,
|
2012-02-02 12:40:47 +00:00
|
|
|
g_object_ref (res));
|
2011-09-25 06:22:36 +00:00
|
|
|
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
2012-07-05 13:38:38 +00:00
|
|
|
* secret_item_load_secret_finish:
|
|
|
|
* @self: an item proxy
|
2012-02-02 12:40:47 +00:00
|
|
|
* @result: asynchronous result passed to callback
|
|
|
|
* @error: location to place error on failure
|
|
|
|
*
|
2012-07-05 13:38:38 +00:00
|
|
|
* Complete asynchronous operation to load the secret value of this item.
|
2012-02-02 12:40:47 +00:00
|
|
|
*
|
2012-07-05 13:38:38 +00:00
|
|
|
* The newly loaded secret value can be accessed by calling
|
|
|
|
* secret_item_get_secret().
|
2012-02-02 12:40:47 +00:00
|
|
|
*
|
2012-07-05 13:38:38 +00:00
|
|
|
* Returns: whether the secret item succesfully loaded or not
|
2012-02-02 12:40:47 +00:00
|
|
|
*/
|
2012-07-05 13:38:38 +00:00
|
|
|
gboolean
|
|
|
|
secret_item_load_secret_finish (SecretItem *self,
|
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
2011-09-25 06:22:36 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
|
|
|
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
|
2012-07-05 13:38:38 +00:00
|
|
|
secret_item_load_secret), FALSE);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
|
|
|
res = G_SIMPLE_ASYNC_RESULT (result);
|
|
|
|
if (g_simple_async_result_propagate_error (res, error))
|
2012-07-05 13:38:38 +00:00
|
|
|
return FALSE;
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-07-05 13:38:38 +00:00
|
|
|
return TRUE;
|
2011-09-25 06:22:36 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
2012-07-05 13:38:38 +00:00
|
|
|
* secret_item_load_secret_sync:
|
2012-02-02 12:40:47 +00:00
|
|
|
* @self: an item
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @error: location to place error on failure
|
|
|
|
*
|
2012-07-05 13:38:38 +00:00
|
|
|
* Load the secret value of this item.
|
2012-02-02 12:40:47 +00:00
|
|
|
*
|
|
|
|
* Each item has a single secret which might be a password or some
|
2012-07-06 08:21:04 +00:00
|
|
|
* other secret binary value.
|
2012-02-02 12:40:47 +00:00
|
|
|
*
|
|
|
|
* This function may block indefinetely. Use the asynchronous version
|
|
|
|
* in user interface threads.
|
|
|
|
*
|
2012-07-05 13:38:38 +00:00
|
|
|
* Returns: whether the secret item succesfully loaded or not
|
2012-02-02 12:40:47 +00:00
|
|
|
*/
|
2012-07-05 13:38:38 +00:00
|
|
|
gboolean
|
|
|
|
secret_item_load_secret_sync (SecretItem *self,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2011-09-25 06:22:36 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretSync *sync;
|
2012-07-05 13:38:38 +00:00
|
|
|
gboolean result;
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), FALSE);
|
2012-01-20 14:10:35 +00:00
|
|
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
sync = _secret_sync_new ();
|
2012-01-20 14:10:35 +00:00
|
|
|
g_main_context_push_thread_default (sync->context);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-07-05 13:38:38 +00:00
|
|
|
secret_item_load_secret (self, cancellable, _secret_sync_on_result, sync);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
g_main_loop_run (sync->loop);
|
|
|
|
|
2012-07-05 13:38:38 +00:00
|
|
|
result = secret_item_load_secret_finish (self, sync->result, error);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
g_main_context_pop_thread_default (sync->context);
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_sync_free (sync);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-07-05 13:38:38 +00:00
|
|
|
return result;
|
2011-09-25 06:22:36 +00:00
|
|
|
}
|
|
|
|
|
2012-07-05 15:11:58 +00:00
|
|
|
typedef struct {
|
|
|
|
SecretService *service;
|
|
|
|
GCancellable *cancellable;
|
|
|
|
GVariant *in;
|
|
|
|
GHashTable *items;
|
|
|
|
} LoadsClosure;
|
|
|
|
|
|
|
|
static void
|
|
|
|
loads_closure_free (gpointer data)
|
|
|
|
{
|
|
|
|
LoadsClosure *loads = data;
|
|
|
|
if (loads->in)
|
|
|
|
g_variant_unref (loads->in);
|
|
|
|
if (loads->service)
|
|
|
|
g_object_unref (loads->service);
|
|
|
|
g_clear_object (&loads->cancellable);
|
|
|
|
g_slice_free (LoadsClosure, loads);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_get_secrets_complete (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
LoadsClosure *loads = g_simple_async_result_get_op_res_gpointer (async);
|
|
|
|
GHashTable *with_paths;
|
|
|
|
GError *error = NULL;
|
|
|
|
GHashTableIter iter;
|
|
|
|
const gchar *path;
|
|
|
|
SecretValue *value;
|
|
|
|
SecretItem *item;
|
|
|
|
GVariant *retval;
|
|
|
|
|
|
|
|
retval = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), result, &error);
|
|
|
|
if (retval != NULL) {
|
|
|
|
with_paths = _secret_service_decode_get_secrets_all (loads->service, retval);
|
|
|
|
g_return_if_fail (with_paths != NULL);
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, with_paths);
|
|
|
|
while (g_hash_table_iter_next (&iter, (gpointer *)&path, (gpointer *)&value)) {
|
|
|
|
item = g_hash_table_lookup (loads->items, path);
|
|
|
|
if (item != NULL)
|
|
|
|
_secret_item_set_cached_secret (item, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hash_table_unref (with_paths);
|
|
|
|
g_variant_unref (retval);
|
|
|
|
}
|
|
|
|
|
2012-07-09 06:44:50 +00:00
|
|
|
if (error != NULL) {
|
|
|
|
_secret_util_strip_remote_error (&error);
|
2012-07-05 15:11:58 +00:00
|
|
|
g_simple_async_result_take_error (async, error);
|
2012-07-09 06:44:50 +00:00
|
|
|
}
|
2012-07-05 15:11:58 +00:00
|
|
|
|
|
|
|
g_simple_async_result_complete (async);
|
|
|
|
g_object_unref (async);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_loads_secrets_session (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
LoadsClosure *loads = g_simple_async_result_get_op_res_gpointer (async);
|
|
|
|
GError *error = NULL;
|
|
|
|
const gchar *session;
|
|
|
|
|
2012-07-06 07:01:20 +00:00
|
|
|
secret_service_ensure_session_finish (SECRET_SERVICE (source), result, &error);
|
2012-07-05 15:11:58 +00:00
|
|
|
if (error != NULL) {
|
|
|
|
g_simple_async_result_take_error (async, error);
|
|
|
|
g_simple_async_result_complete (async);
|
|
|
|
|
|
|
|
} else {
|
2012-07-06 07:01:20 +00:00
|
|
|
session = secret_service_get_session_dbus_path (SECRET_SERVICE (source));
|
2012-07-05 15:11:58 +00:00
|
|
|
g_dbus_proxy_call (G_DBUS_PROXY (source), "GetSecrets",
|
|
|
|
g_variant_new ("(@aoo)", loads->in, session),
|
|
|
|
G_DBUS_CALL_FLAGS_NO_AUTO_START, -1,
|
|
|
|
loads->cancellable, on_get_secrets_complete,
|
|
|
|
g_object_ref (async));
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (async);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* secret_item_load_secrets:
|
2012-07-13 07:04:55 +00:00
|
|
|
* @items: (element-type SecretUnstable.Item): the items to retrieve secrets for
|
2012-07-05 15:11:58 +00:00
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @callback: called when the operation completes
|
|
|
|
* @user_data: data to pass to the callback
|
|
|
|
*
|
|
|
|
* Load the secret values for an secret items stored in the service.
|
|
|
|
*
|
|
|
|
* The @items must all have the same SecretItem::service property.
|
|
|
|
*
|
|
|
|
* This function returns immediately and completes asynchronously.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
secret_item_load_secrets (GList *items,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *async;
|
|
|
|
LoadsClosure *loads;
|
|
|
|
GPtrArray *paths;
|
|
|
|
const gchar *path;
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
|
|
|
for (l = items; l != NULL; l = g_list_next (l))
|
|
|
|
g_return_if_fail (SECRET_IS_ITEM (l->data));
|
|
|
|
|
|
|
|
async = g_simple_async_result_new (NULL, callback, user_data,
|
|
|
|
secret_item_load_secrets);
|
|
|
|
loads = g_slice_new0 (LoadsClosure);
|
|
|
|
loads->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
|
|
|
loads->items = g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
|
|
g_free, g_object_unref);
|
|
|
|
|
|
|
|
paths = g_ptr_array_new ();
|
|
|
|
for (l = items; l != NULL; l = g_list_next (l)) {
|
|
|
|
if (secret_item_get_locked (l->data))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (loads->service == NULL) {
|
|
|
|
loads->service = secret_item_get_service (l->data);
|
|
|
|
if (loads->service)
|
|
|
|
g_object_ref (loads->service);
|
|
|
|
}
|
|
|
|
|
|
|
|
path = g_dbus_proxy_get_object_path (l->data);
|
|
|
|
g_hash_table_insert (loads->items, g_strdup (path), g_object_ref (l->data));
|
|
|
|
g_ptr_array_add (paths, (gpointer)path);
|
|
|
|
}
|
|
|
|
|
|
|
|
loads->in = g_variant_new_objv ((const gchar * const *)paths->pdata, paths->len);
|
|
|
|
g_variant_ref_sink (loads->in);
|
|
|
|
|
|
|
|
g_ptr_array_free (paths, TRUE);
|
|
|
|
g_simple_async_result_set_op_res_gpointer (async, loads, loads_closure_free);
|
|
|
|
|
|
|
|
if (loads->service) {
|
|
|
|
secret_service_ensure_session (loads->service, cancellable,
|
|
|
|
on_loads_secrets_session,
|
|
|
|
g_object_ref (async));
|
|
|
|
} else {
|
|
|
|
g_simple_async_result_complete_in_idle (async);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (async);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* secret_item_load_secrets_finish:
|
|
|
|
* @result: asynchronous result passed to callback
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Complete asynchronous operation to load the secret values for
|
|
|
|
* secret items stored in the service.
|
|
|
|
*
|
|
|
|
* Items that are locked will not have their secrets loaded.
|
|
|
|
*
|
|
|
|
* Returns: whether the operation succeded or not
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
secret_item_load_secrets_finish (GAsyncResult *result,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *async;
|
|
|
|
|
|
|
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, NULL,
|
|
|
|
secret_item_load_secrets), FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
|
|
|
async = G_SIMPLE_ASYNC_RESULT (result);
|
|
|
|
if (g_simple_async_result_propagate_error (async, error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* secret_item_load_secrets_sync:
|
2012-07-13 07:04:55 +00:00
|
|
|
* @items: (element-type SecretUnstable.Item): the items to retrieve secrets for
|
2012-07-05 15:11:58 +00:00
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Load the secret values for an secret items stored in the service.
|
|
|
|
*
|
|
|
|
* The @items must all have the same SecretItem::service property.
|
|
|
|
*
|
|
|
|
* This method may block indefinitely and should not be used in user interface
|
|
|
|
* threads.
|
|
|
|
*
|
|
|
|
* Items that are locked will not have their secrets loaded.
|
|
|
|
*
|
|
|
|
* Returns: whether the operation succeded or not
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
secret_item_load_secrets_sync (GList *items,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
SecretSync *sync;
|
|
|
|
gboolean ret;
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
for (l = items; l != NULL; l = g_list_next (l))
|
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (l->data), 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);
|
|
|
|
|
|
|
|
secret_item_load_secrets (items, cancellable,
|
|
|
|
_secret_sync_on_result, sync);
|
|
|
|
|
|
|
|
g_main_loop_run (sync->loop);
|
|
|
|
|
|
|
|
ret = secret_item_load_secrets_finish (sync->result, error);
|
|
|
|
|
|
|
|
g_main_context_pop_thread_default (sync->context);
|
|
|
|
_secret_sync_free (sync);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-01-26 17:23:12 +00:00
|
|
|
typedef struct {
|
|
|
|
GCancellable *cancellable;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretValue *value;
|
2012-01-26 17:23:12 +00:00
|
|
|
} SetClosure;
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_closure_free (gpointer data)
|
|
|
|
{
|
2012-07-05 13:38:38 +00:00
|
|
|
SetClosure *set = data;
|
|
|
|
g_clear_object (&set->cancellable);
|
|
|
|
secret_value_unref (set->value);
|
|
|
|
g_slice_free (SetClosure, set);
|
2012-01-26 17:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_item_set_secret (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
2012-07-05 13:38:38 +00:00
|
|
|
SecretItem *self = SECRET_ITEM (g_async_result_get_source_object (user_data));
|
|
|
|
SetClosure *set = g_simple_async_result_get_op_res_gpointer (res);
|
2012-01-26 17:23:12 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
GVariant *retval;
|
|
|
|
|
|
|
|
retval = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), result, &error);
|
|
|
|
|
2012-07-09 06:44:50 +00:00
|
|
|
if (error == NULL) {
|
2012-07-05 13:38:38 +00:00
|
|
|
_secret_item_set_cached_secret (self, set->value);
|
2012-07-09 06:44:50 +00:00
|
|
|
} else {
|
|
|
|
_secret_util_strip_remote_error (&error);
|
2012-01-26 17:23:12 +00:00
|
|
|
g_simple_async_result_take_error (res, error);
|
2012-07-09 06:44:50 +00:00
|
|
|
}
|
2012-01-26 17:23:12 +00:00
|
|
|
if (retval != NULL)
|
|
|
|
g_variant_unref (retval);
|
|
|
|
|
|
|
|
g_simple_async_result_complete (res);
|
2012-07-05 13:38:38 +00:00
|
|
|
g_object_unref (self);
|
2012-01-26 17:23:12 +00:00
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_set_ensure_session (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *self = SECRET_ITEM (g_async_result_get_source_object (user_data));
|
2012-01-26 17:23:12 +00:00
|
|
|
SetClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretSession *session;
|
2012-01-26 17:23:12 +00:00
|
|
|
GVariant *encoded;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_ensure_session_finish (self->pv->service, result, &error);
|
2012-01-26 17:23:12 +00:00
|
|
|
if (error != NULL) {
|
|
|
|
g_simple_async_result_take_error (res, error);
|
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
|
|
|
|
} else {
|
2012-02-01 12:34:08 +00:00
|
|
|
session = _secret_service_get_session (self->pv->service);
|
|
|
|
encoded = _secret_session_encode_secret (session, closure->value);
|
2012-01-26 17:23:12 +00:00
|
|
|
g_dbus_proxy_call (G_DBUS_PROXY (self), "SetSecret",
|
|
|
|
g_variant_new ("(@(oayays))", encoded),
|
|
|
|
G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, closure->cancellable,
|
|
|
|
on_item_set_secret, g_object_ref (res));
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (self);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_set_secret:
|
|
|
|
* @self: an item
|
|
|
|
* @value: a new secret value
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @callback: called when the operation completes
|
|
|
|
* @user_data: data to pass to the callback
|
|
|
|
*
|
|
|
|
* Set the secret value of this item.
|
|
|
|
*
|
|
|
|
* Each item has a single secret which might be a password or some
|
|
|
|
* other secret binary value.
|
|
|
|
*
|
|
|
|
* This function returns immediately and completes asynchronously.
|
|
|
|
*/
|
2012-01-26 17:23:12 +00:00
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_secret (SecretItem *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
SecretValue *value,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2012-01-26 17:23:12 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
SetClosure *closure;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_if_fail (SECRET_IS_ITEM (self));
|
2012-01-26 17:23:12 +00:00
|
|
|
g_return_if_fail (value != NULL);
|
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (self), callback,
|
2012-02-01 12:34:08 +00:00
|
|
|
user_data, secret_item_set_secret);
|
2012-01-26 17:23:12 +00:00
|
|
|
closure = g_slice_new0 (SetClosure);
|
|
|
|
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
2012-02-01 12:34:08 +00:00
|
|
|
closure->value = secret_value_ref (value);
|
2012-01-26 17:23:12 +00:00
|
|
|
g_simple_async_result_set_op_res_gpointer (res, closure, set_closure_free);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_service_ensure_session (self->pv->service, cancellable,
|
2012-02-02 12:40:47 +00:00
|
|
|
on_set_ensure_session,
|
|
|
|
g_object_ref (res));
|
2012-01-26 17:23:12 +00:00
|
|
|
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_set_secret_finish:
|
|
|
|
* @self: an item
|
|
|
|
* @result: asynchronous result passed to callback
|
|
|
|
* @error: location to place error on failure
|
|
|
|
*
|
|
|
|
* Complete asynchronous operation to set the secret value of this item.
|
|
|
|
*
|
|
|
|
* Returns: whether the change was successful or not
|
|
|
|
*/
|
2012-01-26 17:23:12 +00:00
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_secret_finish (SecretItem *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
2012-01-26 17:23:12 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
|
|
|
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_secret), FALSE);
|
2012-01-26 17:23:12 +00:00
|
|
|
|
|
|
|
res = G_SIMPLE_ASYNC_RESULT (result);
|
|
|
|
if (g_simple_async_result_propagate_error (res, error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_set_secret_sync:
|
|
|
|
* @self: an item
|
|
|
|
* @value: a new secret value
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @error: location to place error on failure
|
|
|
|
*
|
|
|
|
* Set the secret value of this item.
|
|
|
|
*
|
|
|
|
* Each item has a single secret which might be a password or some
|
|
|
|
* other secret binary value.
|
|
|
|
*
|
|
|
|
* This function may block indefinetely. Use the asynchronous version
|
|
|
|
* in user interface threads.
|
|
|
|
*
|
|
|
|
* Returns: whether the change was successful or not
|
|
|
|
*/
|
2012-01-26 17:23:12 +00:00
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_secret_sync (SecretItem *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
SecretValue *value,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2012-01-26 17:23:12 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretSync *sync;
|
2012-01-26 17:23:12 +00:00
|
|
|
gboolean ret;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), FALSE);
|
2012-01-26 17:23:12 +00:00
|
|
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
sync = _secret_sync_new ();
|
2012-01-26 17:23:12 +00:00
|
|
|
g_main_context_push_thread_default (sync->context);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_secret (self, value, cancellable, _secret_sync_on_result, sync);
|
2012-01-26 17:23:12 +00:00
|
|
|
|
|
|
|
g_main_loop_run (sync->loop);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_item_set_secret_finish (self, 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
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-12 11:02:14 +00:00
|
|
|
/**
|
|
|
|
* secret_item_get_schema_name:
|
|
|
|
* @self: an item
|
|
|
|
*
|
|
|
|
* Gets the name of the schema that this item was stored with. This is also
|
|
|
|
* available at the <literal>xdg:schema</literal> attribute.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the schema name
|
|
|
|
*/
|
|
|
|
gchar *
|
|
|
|
secret_item_get_schema_name (SecretItem *self)
|
|
|
|
{
|
|
|
|
gchar *schema_name;
|
|
|
|
GVariant *variant;
|
|
|
|
|
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), NULL);
|
|
|
|
|
|
|
|
variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Attributes");
|
|
|
|
g_return_val_if_fail (variant != NULL, NULL);
|
|
|
|
|
|
|
|
g_variant_lookup (variant, "xdg:schema", "s", &schema_name);
|
|
|
|
g_variant_unref (variant);
|
|
|
|
|
|
|
|
return schema_name;
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_get_attributes:
|
|
|
|
* @self: an item
|
|
|
|
*
|
|
|
|
* Set the attributes of this item.
|
|
|
|
*
|
|
|
|
* The @attributes are a mapping of string keys to string values.
|
|
|
|
* Attributes are used to search for items. Attributes are not stored
|
|
|
|
* or transferred securely by the secret service.
|
|
|
|
*
|
|
|
|
* Do not modify the attributes returned by this method. Use
|
|
|
|
* secret_item_set_attributes() instead.
|
|
|
|
*
|
2012-07-10 20:02:19 +00:00
|
|
|
* Returns: (transfer full) (element-type utf8 utf8): a new reference
|
|
|
|
* to the attributes, which should not be modified, and
|
|
|
|
* released with g_hash_table_unref()
|
2012-02-02 12:40:47 +00:00
|
|
|
*/
|
2012-01-16 14:08:46 +00:00
|
|
|
GHashTable *
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_get_attributes (SecretItem *self)
|
2012-01-16 14:08:46 +00:00
|
|
|
{
|
|
|
|
GHashTable *attributes;
|
|
|
|
GVariant *variant;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), NULL);
|
2012-01-16 14:08:46 +00:00
|
|
|
|
|
|
|
variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Attributes");
|
|
|
|
g_return_val_if_fail (variant != NULL, NULL);
|
|
|
|
|
2012-06-28 11:15:06 +00:00
|
|
|
attributes = _secret_attributes_for_variant (variant);
|
2012-01-16 14:08:46 +00:00
|
|
|
g_variant_unref (variant);
|
|
|
|
|
|
|
|
return attributes;
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_set_attributes:
|
|
|
|
* @self: an item
|
2012-07-12 10:49:51 +00:00
|
|
|
* @schema: (allow-none): the schema for the attributes
|
2012-03-11 08:06:40 +00:00
|
|
|
* @attributes: (element-type utf8 utf8): a new set of attributes
|
2012-02-02 12:40:47 +00:00
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @callback: called when the asynchronous operation completes
|
|
|
|
* @user_data: data to pass to the callback
|
|
|
|
*
|
|
|
|
* Set the attributes of this item.
|
|
|
|
*
|
|
|
|
* The @attributes are a mapping of string keys to string values.
|
|
|
|
* Attributes are used to search for items. Attributes are not stored
|
|
|
|
* or transferred securely by the secret service.
|
|
|
|
*
|
|
|
|
* This function returns immediately and completes asynchronously.
|
|
|
|
*/
|
2012-01-16 14:08:46 +00:00
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_attributes (SecretItem *self,
|
2012-07-12 10:49:51 +00:00
|
|
|
const SecretSchema *schema,
|
2012-02-02 12:40:47 +00:00
|
|
|
GHashTable *attributes,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2012-01-16 14:08:46 +00:00
|
|
|
{
|
2012-07-12 11:02:14 +00:00
|
|
|
const gchar *schema_name = NULL;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_if_fail (SECRET_IS_ITEM (self));
|
2012-01-16 14:08:46 +00:00
|
|
|
g_return_if_fail (attributes != NULL);
|
|
|
|
|
2012-07-12 11:02:14 +00:00
|
|
|
if (schema != NULL) {
|
|
|
|
if (!_secret_attributes_validate (schema, attributes, G_STRFUNC, FALSE))
|
|
|
|
return; /* Warnings raised already */
|
|
|
|
schema_name = schema->name;
|
|
|
|
}
|
2012-07-12 10:49:51 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_util_set_property (G_DBUS_PROXY (self), "Attributes",
|
2012-07-12 11:02:14 +00:00
|
|
|
_secret_attributes_to_variant (attributes, schema_name),
|
2012-02-02 12:40:47 +00:00
|
|
|
secret_item_set_attributes, cancellable,
|
|
|
|
callback, user_data);
|
2012-01-16 14:08:46 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_set_attributes_finish:
|
|
|
|
* @self: an item
|
|
|
|
* @result: asynchronous result passed to the callback
|
|
|
|
* @error: location to place error on failure
|
|
|
|
*
|
|
|
|
* Complete operation to set the attributes of this item.
|
|
|
|
*
|
|
|
|
* Returns: whether the change was successful or not
|
|
|
|
*/
|
2012-01-16 14:08:46 +00:00
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_attributes_finish (SecretItem *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
2012-01-16 14:08:46 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), FALSE);
|
2012-01-16 14:08:46 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
return _secret_util_set_property_finish (G_DBUS_PROXY (self),
|
2012-02-02 12:40:47 +00:00
|
|
|
secret_item_set_attributes,
|
|
|
|
result, error);
|
2012-01-16 14:08:46 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_set_attributes_sync:
|
|
|
|
* @self: an item
|
2012-07-12 10:49:51 +00:00
|
|
|
* @schema: (allow-none): the schema for the attributes
|
2012-03-11 08:06:40 +00:00
|
|
|
* @attributes: (element-type utf8 utf8): a new set of attributes
|
2012-02-02 12:40:47 +00:00
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @error: location to place error on failure
|
|
|
|
*
|
|
|
|
* Set the attributes of this item.
|
|
|
|
*
|
|
|
|
* The @attributes are a mapping of string keys to string values.
|
|
|
|
* Attributes are used to search for items. Attributes are not stored
|
|
|
|
* or transferred securely by the secret service.
|
|
|
|
*
|
|
|
|
* This function may block indefinetely. Use the asynchronous version
|
|
|
|
* in user interface threads.
|
|
|
|
*
|
|
|
|
* Returns: whether the change was successful or not
|
|
|
|
*/
|
2012-01-16 14:08:46 +00:00
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_attributes_sync (SecretItem *self,
|
2012-07-12 10:49:51 +00:00
|
|
|
const SecretSchema *schema,
|
2012-02-02 12:40:47 +00:00
|
|
|
GHashTable *attributes,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2012-01-16 14:08:46 +00:00
|
|
|
{
|
2012-07-12 11:02:14 +00:00
|
|
|
const gchar *schema_name = NULL;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), FALSE);
|
2012-01-16 14:08:46 +00:00
|
|
|
g_return_val_if_fail (attributes != NULL, FALSE);
|
|
|
|
|
2012-07-12 11:02:14 +00:00
|
|
|
if (schema != NULL) {
|
|
|
|
if (!_secret_attributes_validate (schema, attributes, G_STRFUNC, FALSE))
|
|
|
|
return FALSE; /* Warnings raised already */
|
|
|
|
schema_name = schema->name;
|
|
|
|
}
|
2012-07-12 10:49:51 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
return _secret_util_set_property_sync (G_DBUS_PROXY (self), "Attributes",
|
2012-07-12 11:02:14 +00:00
|
|
|
_secret_attributes_to_variant (attributes, schema_name),
|
2012-02-02 12:40:47 +00:00
|
|
|
cancellable, error);
|
2012-01-16 14:08:46 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_get_label:
|
|
|
|
* @self: an item
|
|
|
|
*
|
|
|
|
* Get the label of this item.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the label, which should be freed with g_free()
|
|
|
|
*/
|
2012-01-16 14:08:46 +00:00
|
|
|
gchar *
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_get_label (SecretItem *self)
|
2012-01-16 14:08:46 +00:00
|
|
|
{
|
|
|
|
GVariant *variant;
|
|
|
|
gchar *label;
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), NULL);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-01-16 14:08:46 +00:00
|
|
|
variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Label");
|
|
|
|
g_return_val_if_fail (variant != NULL, NULL);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-01-16 14:08:46 +00:00
|
|
|
label = g_variant_dup_string (variant, NULL);
|
|
|
|
g_variant_unref (variant);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-01-16 14:08:46 +00:00
|
|
|
return label;
|
|
|
|
}
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_set_label:
|
|
|
|
* @self: an item
|
|
|
|
* @label: a new label
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @callback: called when the operation completes
|
|
|
|
* @user_data: data to pass to the callback
|
|
|
|
*
|
|
|
|
* Set the label of this item.
|
|
|
|
*
|
|
|
|
* This function returns immediately and completes asynchronously.
|
|
|
|
*/
|
2012-01-16 14:08:46 +00:00
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_label (SecretItem *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
const gchar *label,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2012-01-16 14:08:46 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_if_fail (SECRET_IS_ITEM (self));
|
2012-01-16 14:08:46 +00:00
|
|
|
g_return_if_fail (label != NULL);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_util_set_property (G_DBUS_PROXY (self), "Label",
|
2012-02-02 12:40:47 +00:00
|
|
|
g_variant_new_string (label),
|
|
|
|
secret_item_set_label,
|
|
|
|
cancellable, callback, user_data);
|
2012-01-16 14:08:46 +00:00
|
|
|
}
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_set_label_finish:
|
|
|
|
* @self: an item
|
|
|
|
* @result: asynchronous result passed to callback
|
|
|
|
* @error: location to place error on failure
|
|
|
|
*
|
|
|
|
* Complete asynchronous operation to set the label of this collection.
|
|
|
|
*
|
|
|
|
* Returns: whether the change was successful or not
|
|
|
|
*/
|
2012-01-16 14:08:46 +00:00
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_label_finish (SecretItem *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
2012-01-16 14:08:46 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), FALSE);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
return _secret_util_set_property_finish (G_DBUS_PROXY (self),
|
2012-02-02 12:40:47 +00:00
|
|
|
secret_item_set_label,
|
|
|
|
result, error);
|
2012-01-16 14:08:46 +00:00
|
|
|
}
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_set_label_sync:
|
|
|
|
* @self: an item
|
|
|
|
* @label: a new label
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @error: location to place error on failure
|
|
|
|
*
|
|
|
|
* Set the label of this item.
|
|
|
|
*
|
|
|
|
* This function may block indefinetely. Use the asynchronous version
|
|
|
|
* in user interface threads.
|
|
|
|
*
|
|
|
|
* Returns: whether the change was successful or not
|
|
|
|
*/
|
2012-01-16 14:08:46 +00:00
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_set_label_sync (SecretItem *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
const gchar *label,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2012-01-16 14:08:46 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), FALSE);
|
2012-01-16 14:08:46 +00:00
|
|
|
g_return_val_if_fail (label != NULL, FALSE);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
return _secret_util_set_property_sync (G_DBUS_PROXY (self), "Label",
|
2012-01-16 14:08:46 +00:00
|
|
|
g_variant_new_string (label),
|
|
|
|
cancellable, error);
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_get_locked:
|
|
|
|
* @self: an item
|
|
|
|
*
|
|
|
|
* Get whether the item is locked or not.
|
|
|
|
*
|
|
|
|
* Depending on the secret service an item may not be able to be locked
|
|
|
|
* independently from the collection that it is in.
|
|
|
|
*
|
|
|
|
* Returns: whether the item is locked or not
|
|
|
|
*/
|
2012-01-16 14:08:46 +00:00
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_get_locked (SecretItem *self)
|
2012-01-16 14:08:46 +00:00
|
|
|
{
|
|
|
|
GVariant *variant;
|
|
|
|
gboolean locked;
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), TRUE);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-01-16 14:08:46 +00:00
|
|
|
variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Locked");
|
|
|
|
g_return_val_if_fail (variant != NULL, TRUE);
|
2011-09-25 06:22:36 +00:00
|
|
|
|
2012-01-16 14:08:46 +00:00
|
|
|
locked = g_variant_get_boolean (variant);
|
|
|
|
g_variant_unref (variant);
|
|
|
|
|
|
|
|
return locked;
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_get_created:
|
|
|
|
* @self: an item
|
|
|
|
*
|
|
|
|
* Get the created date and time of the item. The return value is
|
|
|
|
* the number of seconds since the unix epoch, January 1st 1970.
|
|
|
|
*
|
|
|
|
* Returns: the created date and time
|
|
|
|
*/
|
2012-01-16 14:08:46 +00:00
|
|
|
guint64
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_get_created (SecretItem *self)
|
2012-01-16 14:08:46 +00:00
|
|
|
{
|
|
|
|
GVariant *variant;
|
|
|
|
guint64 created;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), TRUE);
|
2012-01-16 14:08:46 +00:00
|
|
|
|
|
|
|
variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Created");
|
|
|
|
g_return_val_if_fail (variant != NULL, 0);
|
|
|
|
|
|
|
|
created = g_variant_get_uint64 (variant);
|
|
|
|
g_variant_unref (variant);
|
|
|
|
|
|
|
|
return created;
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_item_get_modified:
|
|
|
|
* @self: an item
|
|
|
|
*
|
|
|
|
* Get the modified date and time of the item. The return value is
|
|
|
|
* the number of seconds since the unix epoch, January 1st 1970.
|
|
|
|
*
|
|
|
|
* Returns: the modified date and time
|
|
|
|
*/
|
2012-01-16 14:08:46 +00:00
|
|
|
guint64
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_item_get_modified (SecretItem *self)
|
2012-01-16 14:08:46 +00:00
|
|
|
{
|
|
|
|
GVariant *variant;
|
|
|
|
guint64 modified;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_ITEM (self), TRUE);
|
2012-01-16 14:08:46 +00:00
|
|
|
|
|
|
|
variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Modified");
|
|
|
|
g_return_val_if_fail (variant != NULL, 0);
|
|
|
|
|
|
|
|
modified = g_variant_get_uint64 (variant);
|
|
|
|
g_variant_unref (variant);
|
|
|
|
|
|
|
|
return modified;
|
|
|
|
}
|