summaryrefslogtreecommitdiff
path: root/library
diff options
context:
space:
mode:
Diffstat (limited to 'library')
-rw-r--r--library/.gitignore8
-rw-r--r--library/Makefile.am65
-rw-r--r--library/gnome-keyring-1-uninstalled.pc.in11
-rw-r--r--library/gnome-keyring-1.pc.in11
-rw-r--r--library/gnome-keyring-memory.c280
-rw-r--r--library/gnome-keyring-memory.h66
-rw-r--r--library/gnome-keyring-opcodes.h57
-rw-r--r--library/gnome-keyring-private.h76
-rw-r--r--library/gnome-keyring-proto.c1547
-rw-r--r--library/gnome-keyring-proto.h235
-rw-r--r--library/gnome-keyring-result.h43
-rw-r--r--library/gnome-keyring-socket.c248
-rw-r--r--library/gnome-keyring-utils.c596
-rw-r--r--library/gnome-keyring.c4389
-rw-r--r--library/gnome-keyring.h523
-rw-r--r--library/tests/.gitignore4
-rw-r--r--library/tests/Makefile.am17
-rw-r--r--library/tests/unit-test-daemon-setup.c81
-rw-r--r--library/tests/unit-test-keyrings-prompt.c273
-rw-r--r--library/tests/unit-test-keyrings.c539
-rw-r--r--library/tests/unit-test-login-prompt.c104
-rw-r--r--library/tests/unit-test-memory.c128
-rw-r--r--library/tests/unit-test-other.c105
23 files changed, 0 insertions, 9406 deletions
diff --git a/library/.gitignore b/library/.gitignore
deleted file mode 100644
index c8a965ae..00000000
--- a/library/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
-/*.pc
-/.libs
-/.deps
-/Makefile.in
-/Makefile
-/test-keyring
-/test-keyring-two
-/list-keyrings
diff --git a/library/Makefile.am b/library/Makefile.am
deleted file mode 100644
index b94f64c4..00000000
--- a/library/Makefile.am
+++ /dev/null
@@ -1,65 +0,0 @@
-libgnomekeyringincludedir = $(includedir)/gnome-keyring-1/
-
-lib_LTLIBRARIES=libgnome-keyring.la
-
-noinst_LTLIBRARIES=libgnome-keyring-common.la
-
-INCLUDES= \
- -DPREFIX=\""$(prefix)"\" \
- -DBINDIR=\""$(bindir)"\" \
- -DLIBEXECDIR=\""$(libexecdir)"\" \
- -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
- -I$(top_srcdir) \
- -I$(top_builddir) \
- $(LIBRARY_CFLAGS) \
- $(GLIB_CFLAGS)
-
-libgnome_keyring_common_la_SOURCES = \
- gnome-keyring-opcodes.h \
- gnome-keyring-private.h \
- gnome-keyring-proto.c \
- gnome-keyring-proto.h \
- gnome-keyring-socket.c \
- gnome-keyring-utils.c
-
-libgnome_keyring_common_la_LIBADD = \
- $(LIBRARY_LIBS) \
- $(GLIB_LIBS)
-
-libgnome_keyring_la_SOURCES = \
- gnome-keyring.c \
- gnome-keyring.h \
- gnome-keyring-memory.h \
- gnome-keyring-memory.c \
- gnome-keyring-result.h
-
-libgnomekeyringinclude_HEADERS = \
- gnome-keyring.h \
- gnome-keyring-memory.h \
- gnome-keyring-result.h
-
-libgnome_keyring_la_LIBADD = \
- libgnome-keyring-common.la \
- $(top_builddir)/egg/libegg-buffer.la \
- $(top_builddir)/egg/libegg-secure.la \
- $(top_builddir)/egg/libegg-creds.la \
- $(GLIB_LIBS)
-
-libgnome_keyring_la_LDFLAGS = \
- -version-info $(LIB_GNOME_KEYRING_LT_VERSION) \
- -no-undefined -export-symbols-regex 'gnome_keyring_|GNOME_KEYRING_'
-
-pkgconfigdir = $(libdir)/pkgconfig
-pkgconfig_DATA = gnome-keyring-1.pc
-
-EXTRA_DIST = \
- gnome-keyring-1-uninstalled.pc.in
-
-if WITH_TESTS
-TESTS_DIR = tests
-else
-TESTS_DIR =
-endif
-
-SUBDIRS = . \
- $(TESTS_DIR)
diff --git a/library/gnome-keyring-1-uninstalled.pc.in b/library/gnome-keyring-1-uninstalled.pc.in
deleted file mode 100644
index 8e7707cd..00000000
--- a/library/gnome-keyring-1-uninstalled.pc.in
+++ /dev/null
@@ -1,11 +0,0 @@
-prefix=@prefix@
-exec_prefix=@exec_prefix@
-libdir=@libdir@
-includedir=@includedir@
-
-Name: gnome-keyring
-Description: The GNOME keyring libraries
-Version: @VERSION@
-Requires: glib-2.0
-Libs: ${pc_top_builddir}/${pcfiledir}/libgnome-keyring.la
-Cflags: -I${pc_top_builddir}/${pcfiledir}
diff --git a/library/gnome-keyring-1.pc.in b/library/gnome-keyring-1.pc.in
deleted file mode 100644
index cc053bec..00000000
--- a/library/gnome-keyring-1.pc.in
+++ /dev/null
@@ -1,11 +0,0 @@
-prefix=@prefix@
-exec_prefix=@exec_prefix@
-libdir=@libdir@
-includedir=@includedir@
-
-Name: gnome-keyring
-Description: The GNOME keyring libraries
-Version: @VERSION@
-Requires: glib-2.0
-Libs: -L${libdir} -lgnome-keyring
-Cflags: -I${includedir}/gnome-keyring-1
diff --git a/library/gnome-keyring-memory.c b/library/gnome-keyring-memory.c
deleted file mode 100644
index e135de76..00000000
--- a/library/gnome-keyring-memory.c
+++ /dev/null
@@ -1,280 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* gnome-keyring-memory.c - library for allocating memory that is non-pageable
-
- Copyright (C) 2007 Stefan Walter
-
- The Gnome Keyring Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Keyring Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-
- Author: Stef Walter <stef@memberwebs.com>
-*/
-
-#include "config.h"
-
-#include "gnome-keyring-memory.h"
-#include "gnome-keyring-private.h"
-
-#include "egg/egg-secure-memory.h"
-
-#include <glib.h>
-
-#include <string.h>
-
-/**
- * SECTION:gnome-keyring-memory
- * @title: Non-pageable Memory
- * @short_description: Secure Non-pageable Memory
- *
- * Normal allocated memory can be paged to disk at the whim of the operating system.
- * This can be a serious problem for sensitive information like passwords, keys and secrets.
- *
- * GNOME Keyring holds passwords in non-pageable, or locked memory. This happens
- * both in the daemon and in the library. This is only possible if the OS contains
- * support for it.
- *
- * These functions allow applications to use to hold passwords and other
- * sensitive information.
- */
-
-static GStaticMutex memory_mutex = G_STATIC_MUTEX_INIT;
-
-#define WARNING "couldn't allocate secure memory to keep passwords " \
- "and or keys from being written to the disk"
-
-#define ABORTMSG "The GNOME_KEYRING_PARANOID environment variable was set. " \
- "Exiting..."
-
-
-/*
- * These are called from gkr-secure-memory.c to provide appropriate
- * locking for memory between threads
- */
-
-void
-egg_memory_lock (void)
-{
- g_static_mutex_lock (&memory_mutex);
-}
-
-void
-egg_memory_unlock (void)
-{
- g_static_mutex_unlock (&memory_mutex);
-}
-
-void*
-egg_memory_fallback (void *p, size_t sz)
-{
- const gchar *env;
-
- /* We were asked to free memory */
- if (!sz) {
- g_free (p);
- return NULL;
- }
-
- /* We were asked to allocate */
- if (!p) {
- env = g_getenv ("GNOME_KEYRING_PARANOID");
- if (env && *env) {
- g_message (WARNING);
- g_error (ABORTMSG);
- }
-
- return g_malloc0 (sz);
- }
-
- /*
- * Reallocation is a bit of a gray area, as we can be asked
- * by external libraries (like libgcrypt) to reallocate a
- * non-secure block into secure memory. We cannot satisfy
- * this request (as we don't know the size of the original
- * block) so we just try our best here.
- */
-
- return g_realloc (p, sz);
-}
-
-/* -----------------------------------------------------------------------------
- * PUBLIC FUNCTIONS
- */
-
-/**
- * gnome_keyring_memory_alloc:
- * @sz: The new desired size of the memory block.
- *
- * Allocate a block of gnome-keyring non-pageable memory.
- *
- * If non-pageable memory cannot be allocated then normal memory will be
- * returned.
- *
- * Return value: The new memory block which should be freed with
- * gnome_keyring_memory_free()
- **/
-gpointer
-gnome_keyring_memory_alloc (gulong sz)
-{
- gpointer p;
-
- /* Try to allocate secure memory */
- p = egg_secure_alloc_full (sz, GKR_SECURE_USE_FALLBACK);
-
- /* Our fallback will always allocate */
- g_assert (p);
-
- return p;
-}
-
-/**
- * gnome_keyring_memory_try_alloc:
- * @sz: The new desired size of the memory block.
- *
- * Allocate a block of gnome-keyring non-pageable memory.
- *
- * If non-pageable memory cannot be allocated, then NULL is returned.
- *
- * Return value: The new block, or NULL if memory cannot be allocated.
- * The memory block should be freed with gnome_keyring_memory_free()
- */
-gpointer
-gnome_keyring_memory_try_alloc (gulong sz)
-{
- return egg_secure_alloc_full (sz, 0);
-}
-
-/**
- * gnome_keyring_memory_realloc:
- * @p: The pointer to reallocate or NULL to allocate a new block.
- * @sz: The new desired size of the memory block, or 0 to free the memory.
- *
- * Reallocate a block of gnome-keyring non-pageable memory.
- *
- * Glib memory is also reallocated correctly. If called with a null pointer,
- * then a new block of memory is allocated. If called with a zero size,
- * then the block of memory is freed.
- *
- * If non-pageable memory cannot be allocated then normal memory will be
- * returned.
- *
- * Return value: The new block, or NULL if the block was freed.
- * The memory block should be freed with gnome_keyring_memory_free()
- */
-gpointer
-gnome_keyring_memory_realloc (gpointer p, gulong sz)
-{
- gpointer n;
-
- if (!p) {
- return gnome_keyring_memory_alloc (sz);
- } else if (!sz) {
- gnome_keyring_memory_free (p);
- return NULL;
- } else if (!egg_secure_check (p)) {
- return g_realloc (p, sz);
- }
-
- /* First try and ask secure memory to reallocate */
- n = egg_secure_realloc_full (p, sz, GKR_SECURE_USE_FALLBACK);
-
- g_assert (n);
-
- return n;
-}
-
-/**
- * gnome_keyring_memory_try_realloc:
- * @p: The pointer to reallocate or NULL to allocate a new block.
- * @sz: The new desired size of the memory block.
- *
- * Reallocate a block of gnome-keyring non-pageable memory.
- *
- * Glib memory is also reallocated correctly when passed to this function.
- * If called with a null pointer, then a new block of memory is allocated.
- * If called with a zero size, then the block of memory is freed.
- *
- * If memory cannot be allocated, NULL is returned and the original block
- * of memory remains intact.
- *
- * Return value: The new block, or NULL if memory cannot be allocated.
- * The memory block should be freed with gnome_keyring_memory_free()
- */
-gpointer
-gnome_keyring_memory_try_realloc (gpointer p, gulong sz)
-{
- gpointer n;
-
- if (!p) {
- return gnome_keyring_memory_try_alloc (sz);
- } else if (!sz) {
- gnome_keyring_memory_free (p);
- return NULL;
- } else if (!egg_secure_check (p)) {
- return g_try_realloc (p, sz);
- }
-
- /* First try and ask secure memory to reallocate */
- n = egg_secure_realloc_full (p, sz, 0);
-
- g_assert (n);
-
- return n;
-}
-
-/**
- * gnome_keyring_memory_free:
- * @p: The pointer to the beginning of the block of memory to free.
- *
- * Free a block of gnome-keyring non-pageable memory.
- *
- * Glib memory is also freed correctly when passed to this function. If called
- * with a null pointer then no action is taken.
- */
-void
-gnome_keyring_memory_free (gpointer p)
-{
- if (!p)
- return;
- egg_secure_free_full (p, GKR_SECURE_USE_FALLBACK);
-}
-
-
-/**
- * gnome_keyring_memory_is_secure:
- * @p: The pointer to check
- *
- * Check if a pointer is in non-pageable memory allocated by gnome-keyring.
- *
- * Return value: Whether the memory is non-pageable or not
- */
-gboolean
-gnome_keyring_memory_is_secure (gpointer p)
-{
- return egg_secure_check (p) ? TRUE : FALSE;
-}
-
-/**
- * gnome_keyring_memory_strdup:
- * @str: The null terminated string to copy
- *
- * Copy a string into non-pageable memory. If the input string is %NULL, then
- * %NULL will be returned.
- *
- * Return value: The copied string, should be freed with gnome_keyring_memory_free()
- */
-gchar*
-gnome_keyring_memory_strdup (const gchar* str)
-{
- return egg_secure_strdup (str);
-}
diff --git a/library/gnome-keyring-memory.h b/library/gnome-keyring-memory.h
deleted file mode 100644
index 64f988b3..00000000
--- a/library/gnome-keyring-memory.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* gnome-keyring-memory.h - library for allocating memory that is non-pageable
-
- Copyright (C) 2007 Stefan Walter
-
- The Gnome Keyring Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Keyring Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-
- Author: Stef Walter <stef@memberwebs.com>
-*/
-
-#ifndef GNOME_KEYRING_MEMORY_H
-#define GNOME_KEYRING_MEMORY_H
-
-#include <glib.h>
-
-G_BEGIN_DECLS
-
-/**
- * gnome-keyring-memory:Short_Description:
- *
- * Gnome Keyring uses memory that is locked in physical RAM for secrets and
- * passwords.
- */
-
-/**
- * gnome_keyring_memory_new:
- * @type: The C type of the objects to allocate
- * @n_objects: The number of objects to allocate.
- *
- * Allocate objects in non-pageable gnome-keyring memory.
- *
- * Return value: The new block of memory.
- **/
-#define gnome_keyring_memory_new(type, n_objects) \
- ((type*)(gnome_keyring_memory_alloc (sizeof (type) * (n_objects))))
-
-gpointer gnome_keyring_memory_alloc (gulong sz);
-
-gpointer gnome_keyring_memory_try_alloc (gulong sz);
-
-gpointer gnome_keyring_memory_realloc (gpointer p, gulong sz);
-
-gpointer gnome_keyring_memory_try_realloc (gpointer p, gulong sz);
-
-void gnome_keyring_memory_free (gpointer p);
-
-gboolean gnome_keyring_memory_is_secure (gpointer p);
-
-gchar* gnome_keyring_memory_strdup (const gchar* str);
-
-G_END_DECLS
-
-#endif /* GNOME_KEYRING_MEMORY_H */
diff --git a/library/gnome-keyring-opcodes.h b/library/gnome-keyring-opcodes.h
deleted file mode 100644
index 2cbff9b0..00000000
--- a/library/gnome-keyring-opcodes.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* gnome-keyring-proto.h - helper code for the keyring daemon protocol
-
- Copyright (C) 2007 Stefan Walter
-
- The Gnome Keyring Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Keyring Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-
- Author: Stef Walter <stef@memberwebs.com>
-*/
-#ifndef GNOME_KEYRING_OPCODES_H
-#define GNOME_KEYRING_OPCODES_H
-
-typedef enum {
- GNOME_KEYRING_OP_LOCK_ALL,
- GNOME_KEYRING_OP_SET_DEFAULT_KEYRING,
- GNOME_KEYRING_OP_GET_DEFAULT_KEYRING,
- GNOME_KEYRING_OP_LIST_KEYRINGS,
- GNOME_KEYRING_OP_CREATE_KEYRING,
- GNOME_KEYRING_OP_LOCK_KEYRING,
- GNOME_KEYRING_OP_UNLOCK_KEYRING,
- GNOME_KEYRING_OP_DELETE_KEYRING,
- GNOME_KEYRING_OP_GET_KEYRING_INFO,
- GNOME_KEYRING_OP_SET_KEYRING_INFO,
- GNOME_KEYRING_OP_LIST_ITEMS,
- GNOME_KEYRING_OP_FIND,
- GNOME_KEYRING_OP_CREATE_ITEM,
- GNOME_KEYRING_OP_DELETE_ITEM,
- GNOME_KEYRING_OP_GET_ITEM_INFO,
- GNOME_KEYRING_OP_SET_ITEM_INFO,
- GNOME_KEYRING_OP_GET_ITEM_ATTRIBUTES,
- GNOME_KEYRING_OP_SET_ITEM_ATTRIBUTES,
- GNOME_KEYRING_OP_GET_ITEM_ACL,
- GNOME_KEYRING_OP_SET_ITEM_ACL,
- GNOME_KEYRING_OP_CHANGE_KEYRING_PASSWORD,
- GNOME_KEYRING_OP_SET_DAEMON_DISPLAY,
- GNOME_KEYRING_OP_GET_ITEM_INFO_FULL,
- GNOME_KEYRING_OP_PREPARE_ENVIRONMENT,
-
- /* Add new ops here */
-
- GNOME_KEYRING_NUM_OPS
-} GnomeKeyringOpCode;
-
-#endif /* GNOME_KEYRING_OPCODES_H */
diff --git a/library/gnome-keyring-private.h b/library/gnome-keyring-private.h
deleted file mode 100644
index 06b1ce9b..00000000
--- a/library/gnome-keyring-private.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* gnome-keyring-private.h - private header for keyring
-
- Copyright (C) 2003 Red Hat, Inc
-
- The Gnome Keyring Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Keyring Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-
- Author: Alexander Larsson <alexl@redhat.com>
-*/
-
-#ifndef GNOME_KEYRING_PRIVATE_H
-#define GNOME_KEYRING_PRIVATE_H
-
-#include "gnome-keyring.h"
-#include "gnome-keyring-proto.h"
-
-struct GnomeKeyringApplicationRef {
- char *display_name;
- char *pathname;
-};
-
-struct GnomeKeyringAccessControl {
- GnomeKeyringApplicationRef *application; /* null for all */
- GnomeKeyringAccessType types_allowed;
-};
-
-struct GnomeKeyringInfo {
- gboolean lock_on_idle;
- guint32 lock_timeout;
- time_t mtime;
- time_t ctime;
- gboolean is_locked;
-};
-
-struct GnomeKeyringItemInfo {
- GnomeKeyringItemType type;
- char *display_name;
- char *secret;
- time_t mtime;
- time_t ctime;
-};
-
-#define GNOME_KEYRING_DAEMON_SERVICE "org.gnome.keyring"
-#define GNOME_KEYRING_DAEMON_PATH "/org/gnome/keyring/daemon"
-#define GNOME_KEYRING_DAEMON_INTERFACE "org.gnome.keyring.Daemon"
-
-int gnome_keyring_socket_connect_daemon (gboolean non_blocking, gboolean only_running);
-int gnome_keyring_socket_read_all (int fd, guchar *buf, size_t len);
-int gnome_keyring_socket_write_all (int fd, const guchar *buf, size_t len);
-gboolean gnome_keyring_socket_read_buffer (int fd, EggBuffer *buffer);
-gboolean gnome_keyring_socket_write_buffer (int fd, EggBuffer *buffer);
-
-extern const gchar *GNOME_KEYRING_OUT_ENVIRONMENT[];
-extern const gchar *GNOME_KEYRING_IN_ENVIRONMENT[];
-
-gchar** gnome_keyring_build_environment (const gchar **names);
-void gnome_keyring_apply_environment (gchar **envp);
-
-void _gnome_keyring_memory_dump (void);
-extern gboolean gnome_keyring_memory_warning;
-
-#endif /* GNOME_KEYRING_PRIVATE_H */
-
diff --git a/library/gnome-keyring-proto.c b/library/gnome-keyring-proto.c
deleted file mode 100644
index 4f31f96a..00000000
--- a/library/gnome-keyring-proto.c
+++ /dev/null
@@ -1,1547 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* gnome-keyring-proto.c - helper code for the keyring daemon protocol
-
- Copyright (C) 2003 Red Hat, Inc
-
- The Gnome Keyring Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Keyring Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-
- Author: Alexander Larsson <alexl@redhat.com>
-*/
-#include "config.h"
-
-#include <string.h>
-#include <stdarg.h>
-
-#include "gnome-keyring-proto.h"
-#include "gnome-keyring-private.h"
-
-#include "egg/egg-buffer.h"
-#include "egg/egg-secure-memory.h"
-
-void
-gkr_proto_go_secure (EggBuffer *buffer)
-{
- egg_buffer_set_allocator (buffer, egg_secure_realloc);
-}
-
-void
-gkr_proto_add_time (EggBuffer *buffer, time_t time)
-{
- guint64 val;
-
- val = time;
- egg_buffer_add_uint32 (buffer, ((val >> 32) & 0xffffffff));
- egg_buffer_add_uint32 (buffer, (val & 0xffffffff));
-}
-
-gboolean
-gkr_proto_get_time (EggBuffer *buffer, gsize offset, gsize *next_offset,
- time_t *time)
-{
- guint32 a, b;
- guint64 val;
-
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &a)) {
- return FALSE;
- }
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &b)) {
- return FALSE;
- }
-
- val = ((guint64)a) << 32 | b;
-
- *next_offset = offset;
- *time = (time_t) val;
-
- return TRUE;
-}
-
-gboolean
-gkr_proto_add_utf8_secret (EggBuffer *buffer, const char *str)
-{
- /* Make sure this buffer is using non-pageable memory */
- gkr_proto_go_secure (buffer);
-
- return gkr_proto_add_utf8_string (buffer, str);
-}
-
-gboolean
-gkr_proto_add_utf8_string (EggBuffer *buffer, const char *str)
-{
- gsize len;
-
- if (str != NULL) {
- len = strlen (str);
-
- if (!g_utf8_validate (str, len, NULL)) {
- return FALSE;
- }
- } else {
- len = 0;
- }
-
- return egg_buffer_add_string (buffer, str);
-}
-
-gboolean
-gkr_proto_get_bytes (EggBuffer *buffer, gsize offset, gsize *next_offset,
- guchar *out, gsize n_bytes)
-{
- if (buffer->len < n_bytes ||
- offset > buffer->len - n_bytes) {
- return FALSE;
- }
-
- memcpy (out, buffer->buf + offset, n_bytes);
- *next_offset = offset + n_bytes;
-
- return TRUE;
-}
-
-gboolean
-gkr_proto_get_raw_secret (EggBuffer *buffer, gsize offset, gsize *next_offset,
- guchar **secret, gsize *n_secret)
-{
- const guchar* ptr;
- if (!egg_buffer_get_byte_array (buffer, offset, next_offset, &ptr, n_secret))
- return FALSE;
-
- if (ptr == NULL || *n_secret == 0) {
- *secret = NULL;
- *n_secret = 0;
- return TRUE;
- }
-
- *secret = egg_secure_alloc (*n_secret + 1);
- memcpy (*secret, ptr, *n_secret);
- (*secret)[*n_secret] = 0;
- return TRUE;
-}
-
-gboolean
-gkr_proto_get_utf8_string (EggBuffer *buffer, gsize offset, gsize *next_offset,
- char **str_ret)
-{
- return gkr_proto_get_utf8_full (buffer, offset, next_offset,
- str_ret, (EggBufferAllocator)g_realloc);
-}
-
-gboolean
-gkr_proto_get_utf8_secret (EggBuffer *buffer, gsize offset, gsize *next_offset,
- char **str_ret)
-{
- return gkr_proto_get_utf8_full (buffer, offset, next_offset,
- str_ret, egg_secure_realloc);
-}
-
-gboolean
-gkr_proto_get_utf8_full (EggBuffer *buffer, gsize offset, gsize *next_offset,
- char **str_ret, EggBufferAllocator allocator)
-{
- gsize len;
- char *str;
-
- if (!egg_buffer_get_string (buffer, offset, &offset, &str, allocator))
- return FALSE;
- len = str ? strlen (str) : 0;
-
- if (str != NULL) {
- if (!g_utf8_validate (str, len, NULL)) {
- (allocator) (str, 0); /* frees memory */
- return FALSE;
- }
- }
-
- if (next_offset != NULL) {
- *next_offset = offset;
- }
- if (str_ret != NULL) {
- *str_ret = str;
- } else {
- (allocator) (str, 0); /* frees memory */
- }
- return TRUE;
-}
-
-static gboolean
-gkr_proto_start_operation (EggBuffer *buffer, GnomeKeyringOpCode op,
- gsize *op_start)
-{
- gsize appname_pos;
- const char *name;
-
- appname_pos = buffer->len;
- egg_buffer_add_uint32 (buffer, 0);
-
- name = g_get_application_name ();
- if (name != NULL && !g_utf8_validate (name, -1, NULL)) {
- g_warning ("g_application_name not utf8 encoded");
- name = NULL;
- } else if (name == NULL) {
- g_warning ("g_set_application_name not set.");
- }
- if (name == NULL) {
- /* General name if none set */
- name = "Application";
- }
- if (!gkr_proto_add_utf8_string (buffer, name)) {
- return FALSE;
- }
-
- /* backpatch application name size */
- if (!egg_buffer_set_uint32 (buffer, appname_pos, buffer->len)) {
- return FALSE;
- }
-
-
- /* Make space for packet size */
- *op_start = buffer->len;
- egg_buffer_add_uint32 (buffer, 0);
- egg_buffer_add_uint32 (buffer, op);
-
- return TRUE;
-}
-
-static gboolean
-gkr_proto_end_operation (EggBuffer *buffer, gsize op_start)
-{
- if (!egg_buffer_set_uint32 (buffer, op_start, buffer->len - op_start)) {
- return FALSE;
- }
- return TRUE;
-}
-
-gboolean
-gkr_proto_decode_packet_size (EggBuffer *buffer, guint32 *size)
-{
- return egg_buffer_get_uint32 (buffer, 0, NULL, size);
-}
-
-gboolean
-gkr_proto_decode_packet_operation (EggBuffer *buffer, GnomeKeyringOpCode *op)
-{
- guint32 op_nr;
- gboolean res;
-
- res = egg_buffer_get_uint32 (buffer, 4, NULL, &op_nr);
- *op = op_nr;
- return res;
-}
-
-gboolean
-gkr_proto_encode_op_only (EggBuffer *buffer, GnomeKeyringOpCode op)
-{
- gsize op_start;
-
- if (!gkr_proto_start_operation (buffer, op, &op_start)) {
- return FALSE;
- }
- if (!gkr_proto_end_operation (buffer, op_start)) {
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
-gkr_proto_encode_op_string (EggBuffer *buffer, GnomeKeyringOpCode op,
- const char *str)
-{
- gsize op_start;
-
- if (!gkr_proto_start_operation (buffer, op, &op_start)) {
- return FALSE;
- }
- if (!gkr_proto_add_utf8_string (buffer, str)) {
- return FALSE;
- }
- if (!gkr_proto_end_operation (buffer, op_start)) {
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
-gkr_proto_encode_op_string_int (EggBuffer *buffer, GnomeKeyringOpCode op,
- const char *str, guint32 val)
-{
- gsize op_start;
-
- if (!gkr_proto_start_operation (buffer, op, &op_start)) {
- return FALSE;
- }
- if (!gkr_proto_add_utf8_string (buffer, str)) {
- return FALSE;
- }
- egg_buffer_add_uint32 (buffer, val);
- if (!gkr_proto_end_operation (buffer, op_start)) {
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
-gkr_proto_encode_op_string_int_int (EggBuffer *buffer, GnomeKeyringOpCode op,
- const char *str, guint32 integer1,
- guint32 integer2)
-{
- gsize op_start;
- if (!gkr_proto_start_operation (buffer, op, &op_start))
- return FALSE;
- if (!gkr_proto_add_utf8_string (buffer, str))
- return FALSE;
- egg_buffer_add_uint32 (buffer, integer1);
- egg_buffer_add_uint32 (buffer, integer2);
- if (!gkr_proto_end_operation (buffer, op_start))
- return FALSE;
- return TRUE;
-}
-
-gboolean
-gkr_proto_encode_op_string_secret (EggBuffer *buffer, GnomeKeyringOpCode op,
- const char *str1, const char *str2)
-{
- gsize op_start;
-
- /* Make sure we're using non-pageable memory */
- gkr_proto_go_secure (buffer);
-
- if (!gkr_proto_start_operation (buffer, op, &op_start)) {
- return FALSE;
- }
- if (!gkr_proto_add_utf8_string (buffer, str1)) {
- return FALSE;
- }
- if (!gkr_proto_add_utf8_secret (buffer, str2)) {
- return FALSE;
- }
- if (!gkr_proto_end_operation (buffer, op_start)) {
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
-gkr_proto_encode_op_string_secret_secret (EggBuffer *buffer, GnomeKeyringOpCode op,
- const char *str1, const char *str2,
- const char *str3)
-{
- gsize op_start;
-
- /* Make sure we're using non-pageable memory */
- gkr_proto_go_secure (buffer);
-
- if (!gkr_proto_start_operation (buffer, op, &op_start)) {
- return FALSE;
- }
- if (!gkr_proto_add_utf8_string (buffer, str1)) {
- return FALSE;
- }
- if (!gkr_proto_add_utf8_secret (buffer, str2)) {
- return FALSE;
- }
- if (!gkr_proto_add_utf8_secret (buffer, str3)) {
- return FALSE;
- }
- if (!gkr_proto_end_operation (buffer, op_start)) {
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
-gkr_proto_encode_find (EggBuffer *buffer, GnomeKeyringItemType type,
- GnomeKeyringAttributeList *attributes)
-{
- gsize op_start;
-
- gkr_proto_start_operation (buffer, GNOME_KEYRING_OP_FIND, &op_start);
-
- egg_buffer_add_uint32 (buffer, type);
-
- if (!gkr_proto_add_attribute_list (buffer, attributes)) {
- goto bail;
- }
-
- if (!gkr_proto_end_operation (buffer, op_start)) {
- goto bail;
- }
-
- return TRUE;
-
- bail:
- egg_buffer_resize (buffer, op_start);
- return FALSE;
-}
-
-gboolean
-gkr_proto_encode_create_item (EggBuffer *buffer, const char *keyring,
- const char *display_name,
- GnomeKeyringAttributeList *attributes,
- const char *secret, GnomeKeyringItemType type,
- gboolean update_if_exists)
-{
- gsize op_start;
-
- /* Make sure this buffer is using non-pageable memory */
- gkr_proto_go_secure (buffer);
-
- if (!gkr_proto_start_operation (buffer, GNOME_KEYRING_OP_CREATE_ITEM,
- &op_start)) {
- return FALSE;
- }
- if (!gkr_proto_add_utf8_string (buffer, keyring)) {
- return FALSE;
- }
- if (!gkr_proto_add_utf8_string (buffer, display_name)) {
- return FALSE;
- }
- if (!gkr_proto_add_utf8_secret (buffer, secret)) {
- return FALSE;
- }
- if (!gkr_proto_add_attribute_list (buffer, attributes)) {
- return FALSE;
- }
- egg_buffer_add_uint32 (buffer, type);
- egg_buffer_add_uint32 (buffer, update_if_exists);
-
- if (!gkr_proto_end_operation (buffer, op_start)) {
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
-gkr_proto_decode_create_item (EggBuffer *buffer, char **keyring, char **display_name,
- GnomeKeyringAttributeList **attributes, char **secret,
- GnomeKeyringItemType *type, gboolean *update_if_exists)
-{
- gsize offset;
- GnomeKeyringOpCode op;
- guint val;
-
- if (keyring != NULL) {
- *keyring = NULL;
- }
- if (display_name != NULL) {
- *display_name = NULL;
- }
- if (secret != NULL) {
- *secret = NULL;
- }
- if (attributes != NULL) {
- *attributes = NULL;
- }
-
- if (!gkr_proto_decode_packet_operation (buffer, &op)) {
- return FALSE;
- }
- if (op != GNOME_KEYRING_OP_CREATE_ITEM) {
- return FALSE;
- }
- offset = 8;
- if (!gkr_proto_get_utf8_string (buffer, offset, &offset, keyring)) {
- goto bail;
- }
- if (!gkr_proto_get_utf8_string (buffer, offset, &offset, display_name)) {
- goto bail;
- }
- if (!gkr_proto_get_utf8_secret (buffer, offset, &offset, secret)) {
- goto bail;
- }
-
- if (!gkr_proto_decode_attribute_list (buffer, offset, &offset, attributes)) {
- goto bail;
- }
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &val)) {
- goto bail;
- }
- if (type != NULL) {
- *type = val;
- }
-
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &val)) {
- goto bail;
- }
- if (update_if_exists != NULL) {
- *update_if_exists = val;
- }
-
- return TRUE;
-
- bail:
- if (attributes != NULL) {
- gnome_keyring_attribute_list_free (*attributes);
- }
- if (keyring != NULL) {
- g_free (*keyring);
- }
- if (display_name != NULL) {
- g_free (*display_name);
- }
- if (secret != NULL) {
- egg_secure_strfree (*secret);
- }
- return FALSE;
-
-}
-
-
-gboolean
-gkr_proto_encode_set_attributes (EggBuffer *buffer, const char *keyring,
- guint32 id, GnomeKeyringAttributeList *attributes)
-{
- gsize op_start;
-
- if (!gkr_proto_start_operation (buffer, GNOME_KEYRING_OP_SET_ITEM_ATTRIBUTES,
- &op_start)) {
- return FALSE;
- }
- if (!gkr_proto_add_utf8_string (buffer, keyring)) {
- return FALSE;
- }
- egg_buffer_add_uint32 (buffer, id);
-
- if (!gkr_proto_add_attribute_list (buffer, attributes)) {
- return FALSE;
- }
-
- if (!gkr_proto_end_operation (buffer, op_start)) {
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
-gkr_proto_encode_set_acl (EggBuffer *buffer, const char *keyring,
- guint32 id, GList *acl)
-{
- gsize op_start;
-
- if (!gkr_proto_start_operation (buffer, GNOME_KEYRING_OP_SET_ITEM_ACL,
- &op_start)) {
- return FALSE;
- }
- if (!gkr_proto_add_utf8_string (buffer, keyring)) {
- return FALSE;
- }
- egg_buffer_add_uint32 (buffer, id);
-
- if (!gkr_proto_add_acl (buffer, acl)) {
- return FALSE;
- }
-
- if (!gkr_proto_end_operation (buffer, op_start)) {
- return FALSE;
- }
-
- return TRUE;
-}
-
-
-gboolean
-gkr_proto_encode_set_item_info (EggBuffer *buffer, const char *keyring,
- guint32 id, GnomeKeyringItemInfo *info)
-{
- gsize op_start;
-
- /* Make sure this buffer is using non-pageable memory */
- gkr_proto_go_secure (buffer);
-
- if (!gkr_proto_start_operation (buffer, GNOME_KEYRING_OP_SET_ITEM_INFO,
- &op_start)) {
- return FALSE;
- }
- if (!gkr_proto_add_utf8_string (buffer, keyring)) {
- return FALSE;
- }
- egg_buffer_add_uint32 (buffer, id);
-
- egg_buffer_add_uint32 (buffer, info->type);
- if (!gkr_proto_add_utf8_string (buffer, info->display_name)) {
- return FALSE;
- }
- if (!gkr_proto_add_utf8_secret (buffer, info->secret)) {
- return FALSE;
- }
-
- if (!gkr_proto_end_operation (buffer, op_start)) {
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
-gkr_proto_encode_set_keyring_info (EggBuffer *buffer, const char *keyring,
- GnomeKeyringInfo *info)
-{
- gsize op_start;
-
- if (!gkr_proto_start_operation (buffer, GNOME_KEYRING_OP_SET_KEYRING_INFO,
- &op_start)) {
- return FALSE;
- }
- if (!gkr_proto_add_utf8_string (buffer, keyring)) {
- return FALSE;
- }
-
- egg_buffer_add_uint32 (buffer, info->lock_on_idle);
- egg_buffer_add_uint32 (buffer, info->lock_timeout);
-
- if (!gkr_proto_end_operation (buffer, op_start)) {
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
-gkr_proto_encode_prepare_environment (EggBuffer *buffer, const gchar **environment)
-{
- gsize op_start;
-
- if (!gkr_proto_start_operation (buffer, GNOME_KEYRING_OP_PREPARE_ENVIRONMENT,
- &op_start))
- return FALSE;
-
- if (!egg_buffer_add_stringv (buffer, environment))
- return FALSE;
-
- if (!gkr_proto_end_operation (buffer, op_start))
- return FALSE;
-
- return TRUE;
-}
-
-gboolean
-gkr_proto_decode_attribute_list (EggBuffer *buffer, gsize offset, gsize *next_offset,
- GnomeKeyringAttributeList **attributes_out)
-{
- guint32 list_size;
- GnomeKeyringAttributeList *attributes;
- GnomeKeyringAttribute attribute;
- char *name;
- guint32 type;
- char *str;
- guint32 val;
- int i;
-
- attributes = NULL;
-
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &list_size)) {
- goto bail;
- }
-
- attributes = gnome_keyring_attribute_list_new ();
- for (i = 0; i < list_size; i++) {
- if (!gkr_proto_get_utf8_string (buffer, offset, &offset, &name)) {
- goto bail;
- }
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &type)) {
- g_free (name);
- goto bail;
- }
- switch (type) {
- case GNOME_KEYRING_ATTRIBUTE_TYPE_STRING:
- if (!gkr_proto_get_utf8_string (buffer, offset, &offset, &str)) {
- g_free (name);
- goto bail;
- }
- attribute.name = name;
- attribute.type = type;
- attribute.value.string = str;
- g_array_append_val (attributes, attribute);
- break;
- case GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32:
- if (!egg_buffer_get_uint32 (buffer, offset,
- &offset, &val)) {
- g_free (name);
- goto bail;
- }
- attribute.name = name;
- attribute.type = type;
- attribute.value.integer = val;
- g_array_append_val (attributes, attribute);
- break;
- default:
- g_free (name);
- goto bail;
- }
- }
-
- if (attributes_out != NULL) {
- *attributes_out = attributes;
- } else {
- gnome_keyring_attribute_list_free (attributes);
- }
- *next_offset = offset;
- return TRUE;
-
- bail:
- gnome_keyring_attribute_list_free (attributes);
- return FALSE;
-}
-
-gboolean
-gkr_proto_decode_acl (EggBuffer *buffer, gsize offset, gsize *next_offset,
- GList **acl_out)
-{
- guint32 list_size;
- GList *acl;
- GnomeKeyringAccessControl *ac;
- GnomeKeyringApplicationRef *ref;
- char *display_name;
- char *pathname;
- guint32 types_allowed;
- int i;
-
- acl = NULL;
-
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &list_size)) {
- goto bail;
- }
-
- for (i = 0; i < list_size; i++) {
- if (!gkr_proto_get_utf8_string (buffer,
- offset, &offset,
- &display_name)) {
- goto bail;
- }
- if (!gkr_proto_get_utf8_string (buffer,
- offset, &offset,
- &pathname)) {
- g_free (display_name);
- goto bail;
- }
-
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &types_allowed)) {
- g_free (display_name);
- g_free (pathname);
- goto bail;
- }
- ref = g_new0 (GnomeKeyringApplicationRef, 1);
- ref->display_name = display_name;
- ref->pathname = pathname;
- ac = g_new0 (GnomeKeyringAccessControl, 1);
- ac->application = ref;
- ac->types_allowed = types_allowed;
- acl = g_list_append (acl, ac);
- }
-
- if (acl_out != NULL) {
- *acl_out = acl;
- } else {
- g_list_free (acl);
- }
- *next_offset = offset;
- return TRUE;
-
- bail:
- gnome_keyring_acl_free (acl);
- return FALSE;
-}
-
-
-gboolean
-gkr_proto_add_attribute_list (EggBuffer *buffer, GnomeKeyringAttributeList *attributes)
-{
- int i;
- GnomeKeyringAttribute *array;
-
- /* Null attributes = empty attribute array */
- if (!attributes) {
- egg_buffer_add_uint32 (buffer, 0);
- return TRUE;
- }
-
- array = (GnomeKeyringAttribute *)attributes->data;
-
- i = 0;
- egg_buffer_add_uint32 (buffer, attributes->len);
-
- for (i = 0; i < attributes->len; i++) {
- if (!gkr_proto_add_utf8_string (buffer, array[i].name)) {
- return FALSE;
- }
- egg_buffer_add_uint32 (buffer, array[i].type);
- switch (array[i].type) {
- case GNOME_KEYRING_ATTRIBUTE_TYPE_STRING:
- if (!gkr_proto_add_utf8_string (buffer, array[i].value.string)) {
- return FALSE;
- }
- break;
- case GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32:
- egg_buffer_add_uint32 (buffer, array[i].value.integer);
- break;
- default:
- g_assert_not_reached ();
- }
- }
-
- return TRUE;
-}
-
-gboolean
-gkr_proto_add_acl (EggBuffer *buffer, GList *acl)
-{
- int length;
- GnomeKeyringAccessControl *ac;
- GList *tmp;
-
- length = g_list_length (acl);
-
- egg_buffer_add_uint32 (buffer, length);
-
- for (tmp = acl; tmp != NULL; tmp = tmp->next) {
- ac = (GnomeKeyringAccessControl *)tmp->data;
- if (!gkr_proto_add_utf8_string (buffer, ac->application->display_name)) {
- return FALSE;
- }
- if (!gkr_proto_add_utf8_string (buffer, ac->application->pathname)) {
- return FALSE;
- }
- egg_buffer_add_uint32 (buffer, ac->types_allowed);
- }
-
- return TRUE;
-}
-
-
-
-gboolean
-gkr_proto_decode_result_reply (EggBuffer *buffer, GnomeKeyringResult *result)
-{
- gsize offset;
- guint32 res;
-
- offset = 4;
-
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &res)) {
- return FALSE;
- }
- *result = res;
-
- return TRUE;
-}
-
-gboolean
-gkr_proto_decode_result_string_reply (EggBuffer *buffer, GnomeKeyringResult *result,
- char **str)
-{
- gsize offset;
- guint32 res;
-
- offset = 4;
-
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &res)) {
- return FALSE;
- }
- *result = res;
- if (!gkr_proto_get_utf8_string (buffer, offset, &offset, str)) {
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
-gkr_proto_decode_result_string_list_reply (EggBuffer *buffer, GnomeKeyringResult *result,
- GList **list)
-{
- gsize offset;
- guint32 res;
- guint32 list_size, i;
- GList *names;
- char *str;
-
- offset = 4;
- names = NULL;
-
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &res)) {
- return FALSE;
- }
-
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &list_size)) {
- goto bail;
- }
-
- for (i = 0; i < list_size; i++) {
- if (!gkr_proto_get_utf8_string (buffer, offset, &offset, &str)) {
- goto bail;
- }
- names = g_list_prepend (names, str);
- }
-
- *result = res;
- *list = g_list_reverse (names);
-
- return TRUE;
-
- bail:
- g_list_foreach (names, (GFunc) g_free, NULL);
- g_list_free (names);
- return FALSE;
-}
-
-gboolean
-gkr_proto_decode_find_reply (EggBuffer *buffer, GnomeKeyringResult *result,
- GList **list_out)
-{
- GList *list;
- gsize offset;
- guint32 res;
- GnomeKeyringFound *found;
-
- offset = 4;
-
- *list_out = NULL;
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &res)) {
- return FALSE;
- }
- *result = res;
-
- if (res != GNOME_KEYRING_RESULT_OK) {
- return TRUE;
- }
-
- list = NULL;
- while (offset < buffer->len) {
- found = g_new0 (GnomeKeyringFound, 1);
- list = g_list_prepend (list, found);
- if (!gkr_proto_get_utf8_string (buffer, offset, &offset,
- &found->keyring)) {
- goto bail;
- }
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &found->item_id)) {
- goto bail;
- }
- if (!gkr_proto_get_utf8_secret (buffer, offset, &offset,
- &found->secret)) {
- goto bail;
- }
- if (!gkr_proto_decode_attribute_list (buffer, offset, &offset,
- &found->attributes)) {
- goto bail;
- }
- }
-
- *list_out = g_list_reverse (list);
- return TRUE;
-
- bail:
- g_list_foreach (list, (GFunc)gnome_keyring_found_free, NULL);
- return FALSE;
-}
-
-gboolean
-gkr_proto_decode_find (EggBuffer *buffer, GnomeKeyringItemType *type,
- GnomeKeyringAttributeList **attributes)
-{
- gsize offset;
- GnomeKeyringOpCode op;
- guint32 t;
-
- if (!gkr_proto_decode_packet_operation (buffer, &op)) {
- return FALSE;
- }
- if (op != GNOME_KEYRING_OP_FIND) {
- return FALSE;
- }
-
- offset = 8;
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &t)) {
- return FALSE;
- }
- *type = t;
- return gkr_proto_decode_attribute_list (buffer, offset, &offset, attributes);
-}
-
-gboolean
-gkr_proto_decode_op_string (EggBuffer *buffer, GnomeKeyringOpCode *op_out,
- char **str1)
-{
- gsize offset;
-
- if (str1 != NULL) {
- *str1 = NULL;
- }
- if (!gkr_proto_decode_packet_operation (buffer, op_out)) {
- return FALSE;
- }
- offset = 8;
- if (!gkr_proto_get_utf8_string (buffer, offset, &offset, str1)) {
- goto bail;
- }
-
- return TRUE;
- bail:
- if (str1 != NULL) {
- g_free (*str1);
- *str1 = NULL;
- }
- return FALSE;
-}
-
-gboolean
-gkr_proto_decode_op_string_int (EggBuffer *buffer, GnomeKeyringOpCode *op_out,
- char **str1, guint32 *val)
-{
- gsize offset;
-
- if (str1 != NULL) {
- *str1 = NULL;
- }
- if (!gkr_proto_decode_packet_operation (buffer, op_out)) {
- return FALSE;
- }
- offset = 8;
- if (!gkr_proto_get_utf8_string (buffer, offset, &offset, str1)) {
- goto bail;
- }
-
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, val)) {
- goto bail;
- }
-
- return TRUE;
- bail:
- if (str1 != NULL) {
- g_free (*str1);
- *str1 = NULL;
- }
- return FALSE;
-}
-
-gboolean
-gkr_proto_decode_get_item_info (EggBuffer *buffer, GnomeKeyringOpCode *op_out,
- char **keyring, guint32 *item_id, guint32 *flags)
-{
- gsize offset = 8;
- *keyring = NULL;
- if (!gkr_proto_decode_packet_operation (buffer, op_out))
- return FALSE;
- if (!gkr_proto_get_utf8_string (buffer, offset, &offset, keyring))
- goto bail;
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, item_id))
- goto bail;
- if (*op_out == GNOME_KEYRING_OP_GET_ITEM_INFO_FULL) {
- /* Pull in lookup flags/parts, find out which ones */
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, flags))
- goto bail;
- } else {
- /* All parts of the item by default */
- *flags = GNOME_KEYRING_ITEM_INFO_ALL;
- }
-
- return TRUE;
- bail:
- g_free (*keyring);
- *keyring = NULL;
- return FALSE;
-}
-
-gboolean
-gkr_proto_decode_op_string_secret (EggBuffer *buffer, GnomeKeyringOpCode *op_out,
- char **str1, char **str2)
-{
- gsize offset;
-
- if (str1 != NULL) {
- *str1 = NULL;
- }
- if (str2 != NULL) {
- *str2 = NULL;
- }
- if (!gkr_proto_decode_packet_operation (buffer, op_out)) {
- return FALSE;
- }
- offset = 8;
- if (!gkr_proto_get_utf8_string (buffer, offset, &offset, str1)) {
- goto bail;
- }
- if (!gkr_proto_get_utf8_secret (buffer, offset, &offset, str2)) {
- goto bail;
- }
-
- return TRUE;
- bail:
- if (str1 != NULL) {
- g_free (*str1);
- *str1 = NULL;
- }
- if (str2 != NULL) {
- g_free (*str2);
- *str2 = NULL;
- }
- return FALSE;
-}
-
-gboolean
-gkr_proto_decode_op_string_secret_secret (EggBuffer *buffer, GnomeKeyringOpCode *op_out,
- char **str1, char **str2, char **str3)
-{
- gsize offset;
-
- if (str1 != NULL) {
- *str1 = NULL;
- }
- if (str2 != NULL) {
- *str2 = NULL;
- }
- if (str3 != NULL) {
- *str3 = NULL;
- }
- if (!gkr_proto_decode_packet_operation (buffer, op_out)) {
- return FALSE;
- }
- offset = 8;
- if (!gkr_proto_get_utf8_string (buffer, offset, &offset, str1)) {
- goto bail;
- }
- if (!gkr_proto_get_utf8_secret (buffer, offset, &offset, str2)) {
- goto bail;
- }
- if (!gkr_proto_get_utf8_secret (buffer, offset, &offset, str3)) {
- goto bail;
- }
-
- return TRUE;
- bail:
- if (str1 != NULL) {
- g_free (*str1);
- *str1 = NULL;
- }
- if (str2 != NULL) {
- g_free (*str2);
- *str2 = NULL;
- }
- if (str3 != NULL) {
- g_free (*str3);
- *str3 = NULL;
- }
- return FALSE;
-}
-
-
-gboolean
-gkr_proto_decode_get_attributes_reply (EggBuffer *buffer, GnomeKeyringResult *result,
- GnomeKeyringAttributeList **attributes)
-{
- gsize offset;
- guint32 res;
-
- offset = 4;
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &res)) {
- return FALSE;
- }
- *attributes = NULL;
- *result = res;
- if (res == GNOME_KEYRING_RESULT_OK) {
- if (!gkr_proto_decode_attribute_list (buffer, offset, &offset, attributes)) {
- return FALSE;
- }
-
- }
-
- return TRUE;
-}
-
-gboolean
-gkr_proto_decode_get_acl_reply (EggBuffer *buffer, GnomeKeyringResult *result,
- GList **acl)
-{
- gsize offset;
- guint32 res;
-
- offset = 4;
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &res)) {
- return FALSE;
- }
- *acl = NULL;
- *result = res;
- if (res == GNOME_KEYRING_RESULT_OK) {
- if (!gkr_proto_decode_acl (buffer, offset, &offset, acl)) {
- return FALSE;
- }
-
- }
-
- return TRUE;
-}
-
-
-gboolean
-gkr_proto_decode_get_item_info_reply (EggBuffer *buffer, GnomeKeyringResult *result,
- GnomeKeyringItemInfo **info_out)
-{
- gsize offset;
- guint32 res, type;
- GnomeKeyringItemInfo *info;
- time_t mtime, ctime;
- char *name;
- char *secret;
-
- info = NULL;
-
- offset = 4;
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &res)) {
- return FALSE;
- }
- if (res == GNOME_KEYRING_RESULT_OK) {
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &type)) {
- return FALSE;
- }
- if (!gkr_proto_get_utf8_string (buffer, offset, &offset, &name)) {
- return FALSE;
- }
- if (!gkr_proto_get_utf8_secret (buffer, offset, &offset, &secret)) {
- g_free (name);
- return FALSE;
- }
-
- if (!gkr_proto_get_time (buffer, offset, &offset, &mtime)) {
- g_free (name);
- egg_secure_strfree (secret);
- return FALSE;
- }
- if (!gkr_proto_get_time (buffer, offset, &offset, &ctime)) {
- g_free (name);
- egg_secure_strfree (secret);
- return FALSE;
- }
-
- info = g_new (GnomeKeyringItemInfo, 1);
- info->type = type;
- info->display_name = name;
- info->secret = secret;
- info->mtime = mtime;
- info->ctime = ctime;
- }
-
- *result = res;
- *info_out = info;
-
- return TRUE;
-}
-
-gboolean
-gkr_proto_decode_get_keyring_info_reply (EggBuffer *buffer, GnomeKeyringResult *result,
- GnomeKeyringInfo **info_out)
-{
- gsize offset;
- guint32 res;
- GnomeKeyringInfo *info;
- guint32 lock_on_idle, lock_timeout, is_locked;
- time_t mtime, ctime;
-
- info = NULL;
-
- offset = 4;
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &res)) {
- return FALSE;
- }
- if (res == GNOME_KEYRING_RESULT_OK) {
- if (!egg_buffer_get_uint32 (buffer, offset, &offset,
- &lock_on_idle)) {
- return FALSE;
- }
- if (!egg_buffer_get_uint32 (buffer, offset, &offset,
- &lock_timeout)) {
- return FALSE;
- }
- if (!gkr_proto_get_time (buffer, offset, &offset, &mtime)) {
- return FALSE;
- }
- if (!gkr_proto_get_time (buffer, offset, &offset, &ctime)) {
- return FALSE;
- }
- if (!egg_buffer_get_uint32 (buffer, offset, &offset,
- &is_locked)) {
- return FALSE;
- }
- info = g_new (GnomeKeyringInfo, 1);
- info->lock_on_idle = lock_on_idle;
- info->lock_timeout = lock_timeout;
- info->mtime = mtime;
- info->ctime = ctime;
- info->is_locked = is_locked;
- }
-
- *result = res;
- *info_out = info;
-
- return TRUE;
-}
-
-gboolean
-gkr_proto_decode_set_item_info (EggBuffer *buffer, char **keyring, guint32 *item_id,
- GnomeKeyringItemType *type, char **display_name,
- char **secret)
-{
- gsize offset;
- GnomeKeyringOpCode op;
- guint32 typeint;
-
- *keyring = NULL;
- *display_name = NULL;
- *secret = NULL;
-
- if (!gkr_proto_decode_packet_operation (buffer, &op)) {
- return FALSE;
- }
- if (op != GNOME_KEYRING_OP_SET_ITEM_INFO) {
- return FALSE;
- }
- offset = 8;
- if (!gkr_proto_get_utf8_string (buffer, offset, &offset, keyring)) {
- goto bail;
- }
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, item_id)) {
- goto bail;
- }
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &typeint)) {
- goto bail;
- }
- *type = typeint;
-
- if (!gkr_proto_get_utf8_string (buffer, offset, &offset, display_name)) {
- goto bail;
- }
- if (!gkr_proto_get_utf8_secret (buffer, offset, &offset, secret)) {
- goto bail;
- }
-
- return TRUE;
-
- bail:
- g_free (*keyring);
- g_free (*display_name);
- egg_secure_strfree (*secret);
- return FALSE;
-}
-
-gboolean
-gkr_proto_decode_set_keyring_info (EggBuffer *buffer, char **keyring,
- gboolean *lock_on_idle, guint32 *lock_timeout)
-
-{
- gsize offset;
- GnomeKeyringOpCode op;
- guint32 lock_int;
-
- *keyring = NULL;
-
- if (!gkr_proto_decode_packet_operation (buffer, &op)) {
- return FALSE;
- }
- if (op != GNOME_KEYRING_OP_SET_KEYRING_INFO) {
- return FALSE;
- }
- offset = 8;
- if (!gkr_proto_get_utf8_string (buffer, offset, &offset, keyring)) {
- goto bail;
- }
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &lock_int)) {
- goto bail;
- }
- *lock_on_idle = lock_int;
-
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, lock_timeout)) {
- goto bail;
- }
-
- return TRUE;
-
- bail:
- g_free (*keyring);
- return FALSE;
-}
-
-gboolean
-gkr_proto_decode_set_attributes (EggBuffer *buffer, char **keyring,
- guint32 *item_id, GnomeKeyringAttributeList **attributes)
-{
- gsize offset;
- GnomeKeyringOpCode op;
-
- *keyring = NULL;
- *attributes = NULL;
-
- if (!gkr_proto_decode_packet_operation (buffer, &op)) {
- return FALSE;
- }
- if (op != GNOME_KEYRING_OP_SET_ITEM_ATTRIBUTES) {
- return FALSE;
- }
- offset = 8;
- if (!gkr_proto_get_utf8_string (buffer, offset, &offset, keyring)) {
- goto bail;
- }
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, item_id)) {
- goto bail;
- }
-
- if (!gkr_proto_decode_attribute_list (buffer, offset, &offset, attributes)) {
- goto bail;
- }
-
- return TRUE;
-
- bail:
- g_free (*keyring);
- return FALSE;
-}
-
-
-gboolean
-gkr_proto_decode_set_acl (EggBuffer *buffer, char **keyring, guint32 *item_id,
- GList **acl)
-{
- gsize offset;
- GnomeKeyringOpCode op;
-
- *keyring = NULL;
- *acl = NULL;
-
- if (!gkr_proto_decode_packet_operation (buffer, &op)) {
- return FALSE;
- }
- if (op != GNOME_KEYRING_OP_SET_ITEM_ACL) {
- return FALSE;
- }
- offset = 8;
- if (!gkr_proto_get_utf8_string (buffer, offset, &offset, keyring)) {
- goto bail;
- }
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, item_id)) {
- goto bail;
- }
-
- if (!gkr_proto_decode_acl (buffer, offset, &offset, acl)) {
- goto bail;
- }
-
- return TRUE;
-
- bail:
- g_free (*keyring);
- return FALSE;
-}
-
-gboolean
-gkr_proto_decode_prepare_environment (EggBuffer *buffer, gchar ***environment)
-{
- GnomeKeyringOpCode op;
- gsize offset;
-
- if (!gkr_proto_decode_packet_operation (buffer, &op))
- return FALSE;
- if (op != GNOME_KEYRING_OP_PREPARE_ENVIRONMENT)
- return FALSE;
-
- offset = 8;
-
- if (!egg_buffer_get_stringv (buffer, offset, &offset, environment, g_realloc))
- return FALSE;
-
- return TRUE;
-}
-
-gboolean
-gkr_proto_decode_prepare_environment_reply (EggBuffer *buffer, GnomeKeyringResult *result,
- char ***environment)
-{
- gsize offset;
- guint32 res;
-
- offset = 4;
-
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &res))
- return FALSE;
- *result = res;
-
- if (res == GNOME_KEYRING_RESULT_OK) {
- if (!egg_buffer_get_stringv (buffer, offset, &offset, environment, g_realloc))
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean
-gkr_proto_decode_result_int_list_reply (EggBuffer *buffer, GnomeKeyringResult *result,
- GList **list)
-{
- gsize offset;
- guint32 res, len, i, id;
-
- *list = NULL;
-
- offset = 4;
-
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &res)) {
- return FALSE;
- }
- *result = res;
-
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &len)) {
- return FALSE;
- }
-
- for (i = 0; i < len; i++) {
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &id)) {
- g_list_free (*list);
- *list = NULL;
- return FALSE;
- }
- *list = g_list_prepend (*list, GUINT_TO_POINTER (id));
-
- }
- *list = g_list_reverse (*list);
- return TRUE;
-}
-
-gboolean
-gkr_proto_decode_result_integer_reply (EggBuffer *buffer, GnomeKeyringResult *result,
- guint32 *integer)
-{
- gsize offset;
- guint32 res, val;
-
- offset = 4;
-
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &res)) {
- return FALSE;
- }
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &val)) {
- return FALSE;
- }
-
- *result = res;
- if (integer != NULL) {
- *integer = val;
- }
-
- return TRUE;
-}
-
diff --git a/library/gnome-keyring-proto.h b/library/gnome-keyring-proto.h
deleted file mode 100644
index aea9fd63..00000000
--- a/library/gnome-keyring-proto.h
+++ /dev/null
@@ -1,235 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* gnome-keyring-proto.h - helper code for the keyring daemon protocol
-
- Copyright (C) 2003 Red Hat, Inc
-
- The Gnome Keyring Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Keyring Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-
- Author: Alexander Larsson <alexl@redhat.com>
-*/
-#ifndef GNOME_KEYRING_PROTO_H
-#define GNOME_KEYRING_PROTO_H
-
-#include <stdarg.h>
-
-#include "gnome-keyring.h"
-#include "gnome-keyring-opcodes.h"
-
-#include "egg/egg-buffer.h"
-
-/* request:
- uint32 package size
- uint32 operation
- ... op data
-
- reply:
- uint32 reply size
- uint32 result
-*/
-
-void gkr_proto_go_secure (EggBuffer *buffer);
-
-/* Core buffer ops */
-gboolean gkr_proto_get_bytes (EggBuffer *buffer,
- gsize offset,
- gsize *next_offset,
- guchar *out,
- gsize n_bytes);
-void gkr_proto_add_time (EggBuffer *buffer,
- time_t val);
-gboolean gkr_proto_get_time (EggBuffer *buffer,
- gsize offset,
- gsize *next_offset,
- time_t *time);
-gboolean gkr_proto_add_utf8_string (EggBuffer *buffer,
- const char *str);
-gboolean gkr_proto_add_utf8_secret (EggBuffer *buffer,
- const char *str);
-gboolean gkr_proto_get_utf8_full (EggBuffer *buffer,
- gsize offset,
- gsize *next_offset,
- char **str_ret,
- EggBufferAllocator allocator);
-gboolean gkr_proto_get_utf8_string (EggBuffer *buffer,
- gsize offset,
- gsize *next_offset,
- char **str_ret);
-gboolean gkr_proto_get_utf8_secret (EggBuffer *buffer,
- gsize offset,
- gsize *next_offset,
- char **str_ret);
-gboolean gkr_proto_get_raw_secret (EggBuffer *buffer,
- gsize offset,
- gsize *next_offset,
- guchar **secret,
- gsize *n_secret);
-gboolean gkr_proto_add_attribute_list (EggBuffer *buffer,
- GnomeKeyringAttributeList *attributes);
-gboolean gkr_proto_add_acl (EggBuffer *buffer,
- GList *acl);
-
-
-/* marshallers */
-gboolean gkr_proto_encode_op_only (EggBuffer *buffer,
- GnomeKeyringOpCode op);
-gboolean gkr_proto_encode_op_string (EggBuffer *buffer,
- GnomeKeyringOpCode op,
- const char *str);
-gboolean gkr_proto_encode_op_string_int (EggBuffer *buffer,
- GnomeKeyringOpCode op,
- const char *str,
- guint32 integer);
-gboolean gkr_proto_encode_op_string_int_int (EggBuffer *buffer,
- GnomeKeyringOpCode op,
- const char *str,
- guint32 integer1,
- guint32 integer2);
-gboolean gkr_proto_encode_op_string_secret (EggBuffer *buffer,
- GnomeKeyringOpCode op,
- const char *str1,
- const char *str2);
-gboolean gkr_proto_encode_op_string_secret_secret (EggBuffer *buffer,
- GnomeKeyringOpCode op,
- const char *str1,
- const char *str2,
- const char *str3);
-gboolean gkr_proto_encode_find (EggBuffer *buffer,
- GnomeKeyringItemType type,
- GnomeKeyringAttributeList *attributes);
-gboolean gkr_proto_encode_create_item (EggBuffer *buffer,
- const char *keyring,
- const char *display_name,
- GnomeKeyringAttributeList *attributes,
- const char *secret,
- GnomeKeyringItemType type,
- gboolean update_if_exists);
-gboolean gkr_proto_encode_set_attributes (EggBuffer *buffer,
- const char *keyring,
- guint32 id,
- GnomeKeyringAttributeList *attributes);
-gboolean gkr_proto_encode_set_acl (EggBuffer *buffer,
- const char *keyring,
- guint32 id,
- GList *acl);
-gboolean gkr_proto_encode_set_item_info (EggBuffer *buffer,
- const char *keyring,
- guint32 id,
- GnomeKeyringItemInfo *info);
-gboolean gkr_proto_encode_set_keyring_info (EggBuffer *buffer,
- const char *keyring,
- GnomeKeyringInfo *info);
-gboolean gkr_proto_encode_prepare_environment (EggBuffer *buffer,
- const gchar **environment);
-
-
-/* demarshallers */
-gboolean gkr_proto_decode_packet_operation (EggBuffer *buffer,
- GnomeKeyringOpCode *op);
-gboolean gkr_proto_decode_packet_size (EggBuffer *buffer,
- guint32 *size);
-gboolean gkr_proto_decode_attribute_list (EggBuffer *buffer,
- gsize offset,
- gsize *next_offset,
- GnomeKeyringAttributeList **attributes_out);
-gboolean gkr_proto_decode_acl (EggBuffer *buffer,
- gsize offset,
- gsize *next_offset,
- GList **attributes_out);
-gboolean gkr_proto_decode_result_reply (EggBuffer *buffer,
- GnomeKeyringResult *result);
-gboolean gkr_proto_decode_result_string_reply (EggBuffer *buffer,
- GnomeKeyringResult *result,
- char **str);
-gboolean gkr_proto_decode_result_string_list_reply (EggBuffer *buffer,
- GnomeKeyringResult *result,
- GList **list);
-gboolean gkr_proto_decode_op_string (EggBuffer *buffer,
- GnomeKeyringOpCode *op_out,
- char **str_out);
-gboolean gkr_proto_decode_op_string_secret (EggBuffer *buffer,
- GnomeKeyringOpCode *op_out,
- char **str1_out,
- char **str2_out);
-gboolean gkr_proto_decode_op_string_secret_secret (EggBuffer *buffer,
- GnomeKeyringOpCode *op_out,
- char **str1_out,
- char **str2_out,
- char **str3_out);
-gboolean gkr_proto_decode_op_string_int (EggBuffer *buffer,
- GnomeKeyringOpCode *op_out,
- char **str1,
- guint32 *val);
-gboolean gkr_proto_decode_get_item_info (EggBuffer *buffer,
- GnomeKeyringOpCode *op_out,
- char **keyring,
- guint32 *item_id,
- guint32 *flags);
-gboolean gkr_proto_decode_find (EggBuffer *buffer,
- GnomeKeyringItemType *type,
- GnomeKeyringAttributeList **attributes);
-gboolean gkr_proto_decode_find_reply (EggBuffer *buffer,
- GnomeKeyringResult *result,
- GList **list_out);
-gboolean gkr_proto_decode_get_attributes_reply (EggBuffer *buffer,
- GnomeKeyringResult *result,
- GnomeKeyringAttributeList **attributes);
-gboolean gkr_proto_decode_get_acl_reply (EggBuffer *buffer,
- GnomeKeyringResult *result,
- GList **acl);
-gboolean gkr_proto_decode_get_item_info_reply (EggBuffer *buffer,
- GnomeKeyringResult *result,
- GnomeKeyringItemInfo **info);
-gboolean gkr_proto_decode_get_keyring_info_reply (EggBuffer *buffer,
- GnomeKeyringResult *result,
- GnomeKeyringInfo **info);
-gboolean gkr_proto_decode_result_int_list_reply (EggBuffer *buffer,
- GnomeKeyringResult *result,
- GList **list);
-gboolean gkr_proto_decode_result_integer_reply (EggBuffer *buffer,
- GnomeKeyringResult *result,
- guint32 *integer);
-gboolean gkr_proto_decode_create_item (EggBuffer *packet,
- char **keyring,
- char **display_name,
- GnomeKeyringAttributeList **attributes,
- char **secret,
- GnomeKeyringItemType *type_out,
- gboolean *update_if_exists);
-gboolean gkr_proto_decode_set_item_info (EggBuffer *buffer,
- char **keyring,
- guint32 *item_id,
- GnomeKeyringItemType *type,
- char **display_name,
- char **secret);
-gboolean gkr_proto_decode_set_keyring_info (EggBuffer *buffer,
- char **keyring,
- gboolean *lock_on_idle,
- guint32 *lock_timeout);
-gboolean gkr_proto_decode_set_attributes (EggBuffer *buffer,
- char **keyring,
- guint32 *item_id,
- GnomeKeyringAttributeList **attributes);
-gboolean gkr_proto_decode_set_acl (EggBuffer *buffer,
- char **keyring,
- guint32 *item_id,
- GList **acl);
-gboolean gkr_proto_decode_prepare_environment (EggBuffer *buffer,
- char ***environment);
-gboolean gkr_proto_decode_prepare_environment_reply (EggBuffer *buffer,
- GnomeKeyringResult *res,
- char ***environment);
-
-#endif /* GNOME_KEYRING_PROTO_H */
diff --git a/library/gnome-keyring-result.h b/library/gnome-keyring-result.h
deleted file mode 100644
index f3d8faad..00000000
--- a/library/gnome-keyring-result.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* gnome-keyring-result.h - Result codes from Gnome Keyring
-
- Copyright (C) 2007 Stefan Walter
-
- The Gnome Keyring Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Keyring Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-
- Author: Stef Walter <stef@memberwebs.com>
-*/
-
-#ifndef GNOME_KEYRING_RESULT_H
-#define GNOME_KEYRING_RESULT_H
-
-typedef enum {
- GNOME_KEYRING_RESULT_OK,
- GNOME_KEYRING_RESULT_DENIED,
- GNOME_KEYRING_RESULT_NO_KEYRING_DAEMON,
- GNOME_KEYRING_RESULT_ALREADY_UNLOCKED,
- GNOME_KEYRING_RESULT_NO_SUCH_KEYRING,
- GNOME_KEYRING_RESULT_BAD_ARGUMENTS,
- GNOME_KEYRING_RESULT_IO_ERROR,
- GNOME_KEYRING_RESULT_CANCELLED,
- GNOME_KEYRING_RESULT_KEYRING_ALREADY_EXISTS,
- GNOME_KEYRING_RESULT_NO_MATCH
-} GnomeKeyringResult;
-
-#define GNOME_KEYRING_RESULT_ALREADY_EXISTS \
- GNOME_KEYRING_RESULT_KEYRING_ALREADY_EXISTS
-
-#endif /* GNOME_KEYRING_RESULT_H */
diff --git a/library/gnome-keyring-socket.c b/library/gnome-keyring-socket.c
deleted file mode 100644
index 053f5ac4..00000000
--- a/library/gnome-keyring-socket.c
+++ /dev/null
@@ -1,248 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* gnome-keyring.c - library for talking to the keyring daemon.
-
- Copyright (C) 2003 Red Hat, Inc
- Copyright (C) 2008 Stefan Walter
-
- The Gnome Keyring Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Keyring Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-
- Author: Alexander Larsson <alexl@redhat.com>
- Author: Stef Walter <stef@memberwebs.com>
-*/
-
-#include "config.h"
-
-#include "gnome-keyring-private.h"
-
-#include <glib.h>
-
-#include <dbus/dbus.h>
-
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <sys/un.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-static gchar*
-find_daemon_via_dbus ()
-{
- DBusConnection *dconn;
- DBusMessage *reply;
- DBusMessage *msg;
- DBusMessageIter args;
- DBusError derr;
- char* socket = NULL;
-
- if (!g_getenv ("DBUS_SESSION_BUS_ADDRESS"))
- return NULL;
-
- dbus_error_init (&derr);
- dconn = dbus_bus_get (DBUS_BUS_SESSION, &derr);
- if (!dconn) {
- g_warning ("couldn't connect to dbus session bus: %s", derr.message);
- return NULL;
- }
-
- msg = dbus_message_new_method_call (GNOME_KEYRING_DAEMON_SERVICE,
- GNOME_KEYRING_DAEMON_PATH,
- GNOME_KEYRING_DAEMON_INTERFACE,
- "GetSocketPath");
- if (!msg) {
- g_warning ("couldn't create dbus message");
- dbus_connection_unref (dconn);
- return NULL;
- }
-
- /* Send message and get a handle for a reply */
- reply = dbus_connection_send_with_reply_and_block (dconn, msg, -1, &derr);
- dbus_message_unref (msg);
- if (!reply) {
- g_warning ("couldn't communicate with gnome keyring daemon via dbus: %s", derr.message);
- dbus_connection_unref (dconn);
- return NULL;
- }
-
- /* Read the return value */
- if (!dbus_message_iter_init(reply, &args) ||
- dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_STRING) {
- g_warning ("gnome-keyring-daemon sent back an invalid reply");
- } else {
- dbus_message_iter_get_basic(&args, &socket);
- socket = g_strdup (socket);
- }
-
- dbus_message_unref (reply);
- dbus_connection_unref (dconn);
-
- return socket;
-}
-
-static int
-connect_to_daemon_at (const gchar *path)
-{
- struct sockaddr_un addr;
- int sock;
-
- addr.sun_family = AF_UNIX;
- strncpy (addr.sun_path, path, sizeof (addr.sun_path));
-
- sock = socket (AF_UNIX, SOCK_STREAM, 0);
- if (sock < 0) {
- return -1;
- }
-
- /* close on exec */
- if (fcntl (sock, F_SETFD, 1) == -1) {
- close (sock);
- return -1;
- }
-
- if (connect (sock, (struct sockaddr *) &addr, sizeof (addr)) < 0) {
- close (sock);
- return -1;
- }
-
- return sock;
-}
-
-int
-gnome_keyring_socket_connect_daemon (gboolean non_blocking, gboolean only_running)
-{
- const gchar *epath = NULL;
- int sock = -1;
- int val;
-
- /* Try using the environment variable */
- epath = g_getenv ("GNOME_KEYRING_SOCKET");
- if (epath && epath[0]) {
- sock = connect_to_daemon_at (epath);
- if (sock < 0) {
- g_warning ("couldn't connect to daemon at $GNOME_KEYRING_SOCKET: %s: %s",
- epath, g_strerror (errno));
- }
- }
-
- /* Try using DBus to find daemon */
- if (sock < 0 && !only_running) {
- gchar *dpath = find_daemon_via_dbus ();
- if (dpath) {
- sock = connect_to_daemon_at (dpath);
- g_free (dpath);
- if (sock < 0) {
- g_warning ("couldn't connect to daemon at DBus discovered socket: %s: %s",
- dpath, g_strerror (errno));
- }
- }
- }
-
- if (sock < 0)
- return -1;
-
- /* Setup non blocking */
- if (non_blocking) {
- val = fcntl (sock, F_GETFL, 0);
- if (val < 0) {
- close (sock);
- return -1;
- }
-
- if (fcntl (sock, F_SETFL, val | O_NONBLOCK) < 0) {
- close (sock);
- return -1;
- }
- }
-
- return sock;
-}
-
-int
-gnome_keyring_socket_read_all (int fd, guchar *buf, size_t len)
-{
- size_t bytes;
- ssize_t res;
-
- bytes = 0;
- while (bytes < len) {
- res = read (fd, buf + bytes, len - bytes);
- if (res <= 0) {
- if (res == 0)
- res = -1;
- else if (errno == EAGAIN)
- continue;
- else
- g_warning ("couldn't read %u bytes from gnome-keyring socket: %s",
- (unsigned int)len, g_strerror (errno));
- return res;
- }
- bytes += res;
- }
- return 0;
-}
-
-
-int
-gnome_keyring_socket_write_all (int fd, const guchar *buf, size_t len)
-{
- size_t bytes;
- ssize_t res;
-
- bytes = 0;
- while (bytes < len) {
- res = write (fd, buf + bytes, len - bytes);
- if (res < 0) {
- if (errno != EINTR &&
- errno != EAGAIN) {
- g_warning ("write_all write failure: %s", g_strerror (errno));
- return -1;
- }
- } else {
- bytes += res;
- }
- }
- return 0;
-}
-
-gboolean
-gnome_keyring_socket_read_buffer (int fd, EggBuffer *buffer)
-{
- guint32 packet_size;
-
- egg_buffer_resize (buffer, 4);
- if (gnome_keyring_socket_read_all (fd, buffer->buf, 4) < 0)
- return FALSE;
-
- if (!gkr_proto_decode_packet_size (buffer, &packet_size) ||
- packet_size < 4)
- return FALSE;
-
- egg_buffer_resize (buffer, packet_size);
- if (gnome_keyring_socket_read_all (fd, buffer->buf + 4, packet_size - 4) < 0)
- return FALSE;
-
- return TRUE;
-}
-
-gboolean
-gnome_keyring_socket_write_buffer (int fd, EggBuffer *buffer)
-{
- return gnome_keyring_socket_write_all (fd, buffer->buf, buffer->len) >= 0;
-}
-
diff --git a/library/gnome-keyring-utils.c b/library/gnome-keyring-utils.c
deleted file mode 100644
index ff07ee1d..00000000
--- a/library/gnome-keyring-utils.c
+++ /dev/null
@@ -1,596 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* gnome-keyring-proto.c - shared utility functions
-
- Copyright (C) 2003 Red Hat, Inc
-
- The Gnome Keyring Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Keyring Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-
- Author: Alexander Larsson <alexl@redhat.com>
-*/
-#include "config.h"
-
-#include <string.h>
-#include <glib.h>
-#include <glib/gi18n-lib.h>
-
-#include "gnome-keyring.h"
-#include "gnome-keyring-private.h"
-#include "gnome-keyring-memory.h"
-
-#include "egg/egg-secure-memory.h"
-
-/**
- * SECTION:gnome-keyring-result
- * @title: Result Codes
- * @short_description: Gnome Keyring Result Codes
- *
- * <para>
- * Result codes used through out GNOME Keyring. Additional result codes may be
- * added from time to time and these should be handled gracefully.
- * </para>
- */
-
-/* Functions used by both the library and the daemon */
-
-/*
- * A list of all the environment variables the daemon can
- * possibly send out when it starts.
- */
-const gchar *GNOME_KEYRING_OUT_ENVIRONMENT[] = {
- "SSH_AUTH_SOCK",
- "GNOME_KEYRING_SOCKET",
- "GNOME_KEYRING_PID",
- "SSH_AGENT_PID",
- NULL
-};
-
-/*
- * A list of all the environment variables the daemon
- * is interested in from clients if it was started
- * early before these environment variables were set.
- */
-const gchar *GNOME_KEYRING_IN_ENVIRONMENT[] = {
- "DISPLAY",
- "DBUS_SESSION_BUS_ADDRESS",
- "DESKTOP_AUTOSTART_ID",
- "ICEAUTHORITY",
- "LANG",
- "XAUTHORITY",
- "XAUTHLOCALHOSTNAME",
- "XDG_SESSION_COOKIE",
- "LOGNAME",
- "USERNAME",
- NULL
-};
-
-gchar**
-gnome_keyring_build_environment (const gchar **names)
-{
- GArray *array = g_array_sized_new (TRUE, TRUE, sizeof (gchar*), 8);
- const gchar *value;
- const gchar **name;
- gchar *env;
-
- /* Transform them into NAME=VALUE pairs */
- for (name = names; *name; ++name) {
- value = g_getenv (*name);
- if (value) {
- env = g_strdup_printf ("%s=%s", *name, value);
- g_array_append_val (array, env);
- }
- }
-
- return (gchar**)g_array_free (array, FALSE);
-}
-
-void
-gnome_keyring_apply_environment (gchar **envp)
-{
- gchar **e, **parts;
-
- g_return_if_fail (envp);
-
- for (e = envp; *e; ++e) {
- parts = g_strsplit (*e, "=", 2);
- if (parts && parts[0] && parts[1])
- g_setenv (parts[0], parts[1], TRUE);
- g_strfreev (parts);
- }
-}
-
-/**
- * gnome_keyring_free_password:
- * @password: the password to be freed
- *
- * Clears the memory used by password by filling with '\0' and frees the memory
- * after doing this. You should use this function instead of g_free() for
- * secret information.
- */
-void
-gnome_keyring_free_password (gchar *password)
-{
- egg_secure_strfree (password);
-}
-
-/**
- * gnome_keyring_string_list_free:
- * @strings: A %GList of string pointers.
- *
- * Free a list of string pointers.
- */
-void
-gnome_keyring_string_list_free (GList *strings)
-{
- g_list_foreach (strings, (GFunc) g_free, NULL);
- g_list_free (strings);
-}
-
-/**
- * gnome_keyring_result_to_message:
- * @res: A #GnomeKeyringResult
- *
- * The #GNOME_KEYRING_RESULT_OK and #GNOME_KEYRING_RESULT_CANCELLED
- * codes will return an empty string.
- *
- * Note that there are some results for which the application will need to
- * take appropriate action rather than just display an error message to
- * the user.
- *
- * Return value: a string suitable for display to the user for a given
- * #GnomeKeyringResult, or an empty string if the message wouldn't make
- * sense to a user.
- **/
-const gchar*
-gnome_keyring_result_to_message (GnomeKeyringResult res)
-{
- switch (res) {
-
- /* If the caller asks for messages for these, they get what they deserve */
- case GNOME_KEYRING_RESULT_OK:
- case GNOME_KEYRING_RESULT_CANCELLED:
- return "";
-
- /* Valid displayable error messages */
- case GNOME_KEYRING_RESULT_DENIED:
- return _("Access Denied");
- case GNOME_KEYRING_RESULT_NO_KEYRING_DAEMON:
- return _("The gnome-keyring-daemon application is not running.");
- case GNOME_KEYRING_RESULT_IO_ERROR:
- return _("Error communicating with gnome-keyring-daemon");
- case GNOME_KEYRING_RESULT_ALREADY_EXISTS:
- return _("A keyring with that name already exists");
- case GNOME_KEYRING_RESULT_BAD_ARGUMENTS:
- return _("Programmer error: The application sent invalid data.");
- case GNOME_KEYRING_RESULT_NO_MATCH:
- return _("No matching results");
- case GNOME_KEYRING_RESULT_NO_SUCH_KEYRING:
- return _("A keyring with that name does not exist.");
-
- /*
- * This would be a dumb message to display to the user, we never return
- * this from the daemon, only here for compatibility
- */
- case GNOME_KEYRING_RESULT_ALREADY_UNLOCKED:
- return _("The keyring has already been unlocked.");
-
- default:
- g_return_val_if_reached (NULL);
- };
-}
-
-
-/**
- * gnome_keyring_found_free():
- * @found: a #GnomeKeyringFound
- *
- * Free the memory used by a #GnomeKeyringFound item.
- *
- * You usually want to use gnome_keyring_found_list_free() on the list of
- * results.
- */
-void
-gnome_keyring_found_free (GnomeKeyringFound *found)
-{
- g_free (found->keyring);
- gnome_keyring_free_password (found->secret);
- gnome_keyring_attribute_list_free (found->attributes);
- g_free (found);
-}
-
-/**
- * gnome_keyring_found_list_free:
- * @found_list: a #GList of #GnomeKeyringFound
- *
- * Free the memory used by the #GnomeKeyringFound items in @found_list.
- */
-void
-gnome_keyring_found_list_free (GList *found_list)
-{
- g_list_foreach (found_list, (GFunc) gnome_keyring_found_free, NULL);
- g_list_free (found_list);
-}
-
-/**
- * SECTION:gnome-keyring-attributes
- * @title: Item Attributes
- * @short_description: Attributes of individual keyring items.
- *
- * Attributes allow various other pieces of information to be associated with an item.
- * These can also be used to search for relevant items. Use gnome_keyring_item_get_attributes()
- * or gnome_keyring_item_set_attributes().
- *
- * Each attribute has either a string, or unsigned integer value.
- */
-
-/**
- * gnome_keyring_attribute_list_append_string:
- * @attributes: A #GnomeKeyringAttributeList
- * @name: The name of the new attribute
- * @value: The value to store in @attributes
- *
- * Store a key-value-pair with a string value in @attributes.
- */
-void
-gnome_keyring_attribute_list_append_string (GnomeKeyringAttributeList *attributes,
- const char *name, const char *value)
-{
- GnomeKeyringAttribute attribute;
-
- attribute.name = g_strdup (name);
- attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
- attribute.value.string = g_strdup (value);
-
- g_array_append_val (attributes, attribute);
-}
-
-/**
- * gnome_keyring_attribute_list_append_uint32:
- * @attributes: A #GnomeKeyringAttributeList
- * @name: The name of the new attribute
- * @value: The value to store in @attributes
- *
- * Store a key-value-pair with an unsigned 32bit number value in @attributes.
- */
-void
-gnome_keyring_attribute_list_append_uint32 (GnomeKeyringAttributeList *attributes,
- const char *name, guint32 value)
-{
- GnomeKeyringAttribute attribute;
-
- attribute.name = g_strdup (name);
- attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32;
- attribute.value.integer = value;
- g_array_append_val (attributes, attribute);
-}
-
-/**
- * gnome_keyring_attribute_list_free:
- * @attributes: A #GnomeKeyringAttributeList
- *
- * Free the memory used by @attributes.
- *
- * If a %NULL pointer is passed, it is ignored.
- **/
-void
-gnome_keyring_attribute_list_free (GnomeKeyringAttributeList *attributes)
-{
- GnomeKeyringAttribute *array;
- int i;
-
- if (attributes == NULL) {
- return;
- }
-
- array = (GnomeKeyringAttribute *)attributes->data;
- for (i = 0; i < attributes->len; i++) {
- g_free (array[i].name);
- if (array[i].type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING) {
- g_free (array[i].value.string);
- }
- }
-
- g_array_free (attributes, TRUE);
-}
-
-/**
- * gnome_keyring_attribute_list_copy:
- * @attributes: A #GnomeKeyringAttributeList to copy.
- *
- * Copy a list of item attributes.
- *
- * Return value: The new #GnomeKeyringAttributeList
- **/
-GnomeKeyringAttributeList *
-gnome_keyring_attribute_list_copy (GnomeKeyringAttributeList *attributes)
-{
- GnomeKeyringAttribute *array;
- GnomeKeyringAttributeList *copy;
- int i;
-
- if (attributes == NULL) {
- return NULL;
- }
-
- copy = g_array_sized_new (FALSE, FALSE, sizeof (GnomeKeyringAttribute), attributes->len);
-
- copy->len = attributes->len;
- memcpy (copy->data, attributes->data, sizeof (GnomeKeyringAttribute) * attributes->len);
-
- array = (GnomeKeyringAttribute *)copy->data;
- for (i = 0; i < copy->len; i++) {
- array[i].name = g_strdup (array[i].name);
- if (array[i].type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING) {
- array[i].value.string = g_strdup (array[i].value.string);
- }
- }
- return copy;
-}
-
-/**
- * SECTION:gnome-keyring-keyring-info
- * @title: Keyring Info
- * @short_description: Keyring Information
- *
- * Use gnome_keyring_get_info() or gnome_keyring_get_info_sync() to get a #GnomeKeyringInfo
- * pointer to use with these functions.
- */
-
-/**
- * gnome_keyring_info_free:
- * @keyring_info: The keyring info to free.
- *
- * Free a #GnomeKeyringInfo object. If a %NULL pointer is passed
- * nothing occurs.
- */
-void
-gnome_keyring_info_free (GnomeKeyringInfo *keyring_info)
-{
- g_free (keyring_info);
-}
-
-/**
- * SECTION:gnome-keyring-item-info
- * @title: Item Information
- * @short_description: Keyring Item Info
- *
- * #GnomeKeyringItemInfo represents the basic information about a keyring item.
- * Use gnome_keyring_item_get_info() or gnome_keyring_item_set_info().
- */
-
-/**
- * gnome_keyring_info_copy:
- * @keyring_info: The keyring info to copy.
- *
- * Copy a #GnomeKeyringInfo object.
- *
- * Return value: The newly allocated #GnomeKeyringInfo. This must be freed with
- * gnome_keyring_info_free()
- */
-GnomeKeyringInfo *
-gnome_keyring_info_copy (GnomeKeyringInfo *keyring_info)
-{
- GnomeKeyringInfo *copy;
-
- copy = g_new (GnomeKeyringInfo, 1);
- memcpy (copy, keyring_info, sizeof (GnomeKeyringInfo));
-
- return copy;
-}
-
-/**
- * gnome_keyring_item_info_free:
- * @item_info: The keyring item info pointer.
- *
- * Free the #GnomeKeyringItemInfo object.
- *
- * A %NULL pointer may be passed, in which case it will be ignored.
- **/
-void
-gnome_keyring_item_info_free (GnomeKeyringItemInfo *item_info)
-{
- if (item_info != NULL) {
- g_free (item_info->display_name);
- gnome_keyring_free_password (item_info->secret);
- g_free (item_info);
- }
-}
-
-/**
- * gnome_keyring_item_info_new:
- *
- * Create a new #GnomeKeyringItemInfo object.
- * Free the #GnomeKeyringItemInfo object.
- *
- * Return value: A keyring item info pointer.
- **/
-GnomeKeyringItemInfo *
-gnome_keyring_item_info_new (void)
-{
- GnomeKeyringItemInfo *info;
-
- info = g_new0 (GnomeKeyringItemInfo, 1);
-
- info->type = GNOME_KEYRING_ITEM_NO_TYPE;
-
- return info;
-}
-
-/**
- * gnome_keyring_item_info_copy:
- * @item_info: A keyring item info pointer.
- *
- * Copy a #GnomeKeyringItemInfo object.
- *
- * Return value: A keyring item info pointer.
- **/
-GnomeKeyringItemInfo *
-gnome_keyring_item_info_copy (GnomeKeyringItemInfo *item_info)
-{
- GnomeKeyringItemInfo *copy;
-
- copy = g_new (GnomeKeyringItemInfo, 1);
- memcpy (copy, item_info, sizeof (GnomeKeyringItemInfo));
-
- copy->display_name = g_strdup (copy->display_name);
- copy->secret = egg_secure_strdup (copy->secret);
-
- return copy;
-}
-
-/**
- * gnome_keyring_application_ref_new:
- *
- * Create a new application reference.
- *
- * Return value: A new #GnomeKeyringApplicationRef pointer.
- **/
-GnomeKeyringApplicationRef *
-gnome_keyring_application_ref_new (void)
-{
- GnomeKeyringApplicationRef *app_ref;
-
- app_ref = g_new0 (GnomeKeyringApplicationRef, 1);
-
- return app_ref;
-}
-
-/**
- * gnome_keyring_application_ref_free:
- * @app: A #GnomeKeyringApplicationRef pointer
- *
- * Free an application reference.
- **/
-void
-gnome_keyring_application_ref_free (GnomeKeyringApplicationRef *app)
-{
- if (app) {
- g_free (app->display_name);
- g_free (app->pathname);
- g_free (app);
- }
-}
-
-/**
- * gnome_keyring_application_ref_copy:
- * @app: A #GnomeKeyringApplicationRef pointer
- *
- * Copy an application reference.
- *
- * Return value: A new #GnomeKeyringApplicationRef pointer.
- **/
-GnomeKeyringApplicationRef *
-gnome_keyring_application_ref_copy (const GnomeKeyringApplicationRef *app)
-{
- GnomeKeyringApplicationRef *copy;
-
- copy = g_new (GnomeKeyringApplicationRef, 1);
- copy->display_name = g_strdup (app->display_name);
- copy->pathname = g_strdup (app->pathname);
-
- return copy;
-}
-
-/**
- * gnome_keyring_access_control_new:
- * @application: A #GnomeKeyringApplicationRef pointer
- * @types_allowed: Access types allowed.
- *
- * Create a new access control for an item. Combine the various access
- * rights allowed.
- *
- * Return value: The new #GnomeKeyringAccessControl pointer. Use
- * gnome_keyring_access_control_free() to free the memory.
- **/
-GnomeKeyringAccessControl *
-gnome_keyring_access_control_new (const GnomeKeyringApplicationRef *application,
- GnomeKeyringAccessType types_allowed)
-{
- GnomeKeyringAccessControl *ac;
- ac = g_new (GnomeKeyringAccessControl, 1);
-
- ac->application = gnome_keyring_application_ref_copy (application);
- ac->types_allowed = types_allowed;
-
- return ac;
-}
-
-/**
- * gnome_keyring_access_control_free:
- * @ac: A #GnomeKeyringAccessControl pointer
- *
- * Free an access control for an item.
- **/
-void
-gnome_keyring_access_control_free (GnomeKeyringAccessControl *ac)
-{
- gnome_keyring_application_ref_free (ac->application);
- g_free (ac);
-}
-
-/**
- * gnome_keyring_access_control_copy:
- * @ac: A #GnomeKeyringAcessControl pointer
- *
- * Copy an access control for an item.
- *
- * Return value: The new #GnomeKeyringAccessControl pointer. Use
- * gnome_keyring_access_control_free() to free the memory.
- **/
-GnomeKeyringAccessControl *
-gnome_keyring_access_control_copy (GnomeKeyringAccessControl *ac)
-{
- GnomeKeyringAccessControl *ret;
-
- ret = gnome_keyring_access_control_new (gnome_keyring_application_ref_copy (ac->application), ac->types_allowed);
-
- return ret;
-}
-
-/**
- * gnome_keyring_acl_copy:
- * @list: A list of #GnomeKeyringAccessControl pointers.
- *
- * Copy an access control list.
- *
- * Return value: A new list of #GnomeKeyringAccessControl items. Use
- * gnome_keyring_acl_free() to free the memory.
- */
-GList *
-gnome_keyring_acl_copy (GList *list)
-{
- GList *ret, *l;
-
- ret = g_list_copy (list);
- for (l = ret; l != NULL; l = l->next) {
- l->data = gnome_keyring_access_control_copy (l->data);
- }
-
- return ret;
-}
-
-/**
- * gnome_keyring_acl_free:
- * @acl: A list of #GnomeKeyringAccessControl pointers.
- *
- * Free an access control list.
- */
-void
-gnome_keyring_acl_free (GList *acl)
-{
- g_list_foreach (acl, (GFunc)gnome_keyring_access_control_free, NULL);
- g_list_free (acl);
-}
-
diff --git a/library/gnome-keyring.c b/library/gnome-keyring.c
deleted file mode 100644
index 38a46c57..00000000
--- a/library/gnome-keyring.c
+++ /dev/null
@@ -1,4389 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* gnome-keyring.c - library for talking to the keyring daemon.
-
- Copyright (C) 2003 Red Hat, Inc
- Copyright (C) 2007 Stefan Walter
-
- The Gnome Keyring Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Keyring Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-
- Author: Alexander Larsson <alexl@redhat.com>
- Author: Stef Walter <stef@memberwebs.com>
-*/
-
-#include "config.h"
-
-#include "gnome-keyring.h"
-#include "gnome-keyring-memory.h"
-#include "gnome-keyring-private.h"
-#include "gnome-keyring-proto.h"
-
-#include "egg/egg-buffer.h"
-#include "egg/egg-unix-credentials.h"
-
-#include <time.h>
-#include <unistd.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/uio.h>
-#include <stdarg.h>
-
-/**
- * SECTION:gnome-keyring-generic-callbacks
- * @title: Callbacks
- * @short_description: Different callbacks for retrieving async results
- */
-
-typedef enum {
- CALLBACK_DONE,
- CALLBACK_GET_STRING,
- CALLBACK_GET_INT,
- CALLBACK_GET_LIST,
- CALLBACK_GET_KEYRING_INFO,
- CALLBACK_GET_ITEM_INFO,
- CALLBACK_GET_ATTRIBUTES,
- CALLBACK_GET_ACL
-} KeyringCallbackType;
-
-typedef enum {
- STATE_FAILED,
- STATE_WRITING_CREDS,
- STATE_WRITING_PACKET,
- STATE_READING_REPLY
-} KeyringState;
-
-typedef struct GnomeKeyringOperation GnomeKeyringOperation;
-
-#define NORMAL_ALLOCATOR ((EggBufferAllocator)g_realloc)
-#define SECURE_ALLOCATOR ((EggBufferAllocator)gnome_keyring_memory_realloc)
-
-typedef gboolean (*KeyringHandleReply) (GnomeKeyringOperation *op);
-
-struct GnomeKeyringOperation {
- int socket;
-
- KeyringState state;
- GnomeKeyringResult result;
-
- guint io_watch;
- guint idle_watch;
-
- EggBuffer send_buffer;
- gsize send_pos;
-
- EggBuffer receive_buffer;
- gsize receive_pos;
-
- KeyringCallbackType user_callback_type;
- gpointer user_callback;
- gpointer user_data;
- GDestroyNotify destroy_user_data;
-
- KeyringHandleReply reply_handler;
- gpointer reply_data;
- GDestroyNotify destroy_reply_data;
-};
-
-static void
-operation_free (GnomeKeyringOperation *op)
-{
- if (op->idle_watch != 0) {
- g_source_remove (op->idle_watch);
- op->idle_watch = 0;
- }
- if (op->io_watch != 0) {
- g_source_remove (op->io_watch);
- op->io_watch = 0;
- }
- if (op->destroy_user_data != NULL && op->user_data != NULL)
- (*op->destroy_user_data) (op->user_data);
- if (op->destroy_reply_data != NULL && op->reply_data != NULL)
- (*op->destroy_reply_data) (op->reply_data);
- egg_buffer_uninit (&op->send_buffer);
- egg_buffer_uninit (&op->receive_buffer);
-
- shutdown (op->socket, SHUT_RDWR);
- close (op->socket);
- g_free (op);
-}
-
-static gboolean
-op_failed (gpointer data)
-{
- GnomeKeyringOperation *op;
-
- op = data;
- op->idle_watch = 0;
-
- switch (op->user_callback_type) {
- case CALLBACK_DONE:
- ((GnomeKeyringOperationDoneCallback)op->user_callback) (op->result, op->user_data);
- break;
- case CALLBACK_GET_STRING:
- ((GnomeKeyringOperationGetStringCallback)op->user_callback) (op->result, NULL, op->user_data);
- break;
- case CALLBACK_GET_INT:
- ((GnomeKeyringOperationGetIntCallback)op->user_callback) (op->result, 0, op->user_data);
- break;
- case CALLBACK_GET_LIST:
- ((GnomeKeyringOperationGetListCallback)op->user_callback) (op->result, NULL, op->user_data);
- break;
- case CALLBACK_GET_KEYRING_INFO:
- ((GnomeKeyringOperationGetKeyringInfoCallback)op->user_callback) (op->result, NULL, op->user_data);
- break;
- case CALLBACK_GET_ITEM_INFO:
- ((GnomeKeyringOperationGetItemInfoCallback)op->user_callback) (op->result, NULL, op->user_data);
- break;
- case CALLBACK_GET_ATTRIBUTES:
- ((GnomeKeyringOperationGetAttributesCallback)op->user_callback) (op->result, NULL, op->user_data);
- break;
- case CALLBACK_GET_ACL:
- ((GnomeKeyringOperationGetListCallback)op->user_callback) (op->result, NULL, op->user_data);
- break;
- }
-
- operation_free (op);
-
- /* Don't run idle handler again */
- return FALSE;
-}
-
-
-static void
-schedule_op_failed (GnomeKeyringOperation *op,
- GnomeKeyringResult result)
-{
- if (op->io_watch != 0) {
- g_source_remove (op->io_watch);
- op->io_watch = 0;
- }
- op->state = STATE_FAILED;
- op->result = result;
-
- if (op->idle_watch == 0)
- op->idle_watch = g_idle_add (op_failed, op);
-}
-
-static GnomeKeyringResult
-write_credentials_byte_sync (int socket)
-{
- if (egg_unix_credentials_write (socket) < 0)
- return GNOME_KEYRING_RESULT_IO_ERROR;
- return GNOME_KEYRING_RESULT_OK;
-}
-
-static void
-write_credentials_byte (GnomeKeyringOperation *op)
-{
- if (egg_unix_credentials_write (op->socket) < 0) {
- if (errno == EAGAIN)
- return;
- schedule_op_failed (op, GNOME_KEYRING_RESULT_IO_ERROR);
- return;
- }
-
- op->state = STATE_WRITING_PACKET;
-}
-
-static gboolean
-operation_io (GIOChannel *io_channel,
- GIOCondition cond,
- gpointer callback_data)
-{
- GIOChannel *channel;
- GnomeKeyringOperation *op;
- int res;
- guint32 packet_size;
-
- op = callback_data;
-
- if (cond & G_IO_HUP && !(cond & G_IO_IN)) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_IO_ERROR);
- }
-
- if (op->state == STATE_WRITING_CREDS && (cond & G_IO_OUT)) {
- write_credentials_byte (op);
- }
- if (op->state == STATE_WRITING_PACKET && (cond & G_IO_OUT)) {
- res = write (op->socket,
- op->send_buffer.buf + op->send_pos,
- op->send_buffer.len - op->send_pos);
- if (res <= 0) {
- if (errno != EAGAIN &&
- errno != EINTR) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_IO_ERROR);
- }
- } else {
- op->send_pos += res;
-
- if (op->send_pos == op->send_buffer.len) {
- op->state = STATE_READING_REPLY;
- egg_buffer_reset (&op->receive_buffer);
- op->receive_pos = 0;
-
- g_source_remove (op->io_watch);
- channel = g_io_channel_unix_new (op->socket);
- op->io_watch = g_io_add_watch (channel,
- G_IO_IN | G_IO_HUP,
- operation_io, op);
- g_io_channel_unref (channel);
- }
- }
- }
-
- if (op->state == STATE_READING_REPLY && (cond & G_IO_IN)) {
- if (op->receive_pos < 4) {
- egg_buffer_resize (&op->receive_buffer, 4);
- res = read (op->socket,
- op->receive_buffer.buf + op->receive_pos,
- 4 - op->receive_pos);
- if (res <= 0) {
- if (errno != EAGAIN &&
- errno != EINTR) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_IO_ERROR);
- }
- } else {
- op->receive_pos += res;
- }
- }
-
- if (op->receive_pos >= 4) {
- if (!gkr_proto_decode_packet_size (&op->receive_buffer, &packet_size) ||
- packet_size < 4) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_IO_ERROR);
- }
-
- g_assert (op->receive_pos <= packet_size);
- egg_buffer_resize (&op->receive_buffer, packet_size);
-
- res = read (op->socket, op->receive_buffer.buf + op->receive_pos,
- packet_size - op->receive_pos);
- if (res <= 0) {
- if (errno != EAGAIN &&
- errno != EINTR) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_IO_ERROR);
- }
- } else {
- op->receive_pos += res;
-
- if (op->receive_pos == packet_size) {
- op->result = GNOME_KEYRING_RESULT_OK;
-
- /* Only cleanup if the handler says we're done */
- if ((*op->reply_handler) (op)) {
- g_source_remove (op->io_watch);
- op->io_watch = 0;
- operation_free (op);
- }
- }
- }
- }
- }
-
-
- return TRUE;
-}
-
-
-static GnomeKeyringOperation*
-create_operation (gboolean receive_secure, gpointer callback,
- KeyringCallbackType callback_type, gpointer user_data,
- GDestroyNotify destroy_user_data)
-{
- GnomeKeyringOperation *op;
-
- op = g_new0 (GnomeKeyringOperation, 1);
-
- /* Start in failed mode */
- op->state = STATE_FAILED;
- op->result = GNOME_KEYRING_RESULT_OK;
-
- op->user_callback_type = callback_type;
- op->user_callback = callback;
- op->user_data = user_data;
- op->destroy_user_data = destroy_user_data;
- op->socket = -1;
-
- egg_buffer_init_full (&op->send_buffer, 128, NORMAL_ALLOCATOR);
- egg_buffer_init_full (&op->receive_buffer, 128,
- receive_secure ? SECURE_ALLOCATOR : NORMAL_ALLOCATOR);
-
- return op;
-}
-
-static void
-start_operation (GnomeKeyringOperation *op)
-{
- GIOChannel *channel;
-
- /* Start in failed mode */
- op->state = STATE_FAILED;
- op->result = GNOME_KEYRING_RESULT_OK;
-
- if (op->io_watch != 0) {
- g_source_remove (op->io_watch);
- op->io_watch = 0;
- }
- if (op->socket >= 0) {
- shutdown (op->socket, SHUT_RDWR);
- close (op->socket);
- }
-
- op->socket = gnome_keyring_socket_connect_daemon (TRUE, FALSE);
- if (op->socket < 0) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_NO_KEYRING_DAEMON);
- } else {
- op->state = STATE_WRITING_CREDS;
-
- egg_buffer_reset (&op->receive_buffer);
- op->send_pos = 0;
-
- channel = g_io_channel_unix_new (op->socket);
- op->io_watch = g_io_add_watch (channel,
- G_IO_OUT | G_IO_HUP,
- operation_io, op);
- g_io_channel_unref (channel);
- }
-}
-
-static GnomeKeyringResult
-run_sync_operation (EggBuffer *buffer,
- EggBuffer *receive_buffer)
-{
- GnomeKeyringResult res;
- int socket;
-
- g_assert (buffer != NULL);
- g_assert (receive_buffer != NULL);
-
- socket = gnome_keyring_socket_connect_daemon (FALSE, FALSE);
- if (socket < 0)
- return GNOME_KEYRING_RESULT_NO_KEYRING_DAEMON;
-
- res = write_credentials_byte_sync (socket);
- if (res != GNOME_KEYRING_RESULT_OK) {
- close (socket);
- return res;
- }
-
- if (!gnome_keyring_socket_write_buffer (socket, buffer) ||
- !gnome_keyring_socket_read_buffer (socket, receive_buffer)) {
- close (socket);
- return GNOME_KEYRING_RESULT_IO_ERROR;
- }
-
- close (socket);
- return GNOME_KEYRING_RESULT_OK;
-}
-
-/**
- * SECTION:gnome-keyring-misc
- * @title: Miscellaneous Functions
- * @short_description: Miscellaneous functions.
- */
-
-/**
- * gnome_keyring_is_available:
- *
- * Check whether you can communicate with a gnome-keyring-daemon.
- *
- * Return value: %FALSE if you can't communicate with the daemon (so you
- * can't load and save passwords).
- **/
-gboolean
-gnome_keyring_is_available (void)
-{
- int socket;
-
- socket = gnome_keyring_socket_connect_daemon (FALSE, FALSE);
- if (socket < 0) {
- return FALSE;
- }
- close (socket);
- return TRUE;
-}
-
-/**
- * gnome_keyring_cancel_request:
- * @request: The request returned from the asynchronous call function.
- *
- * Cancel an asynchronous request.
- *
- * If a callback was registered when making the asynchronous request, that callback
- * function will be called with a result of %GNOME_KEYRING_RESULT_CANCELLED
- **/
-void
-gnome_keyring_cancel_request (gpointer request)
-{
- GnomeKeyringOperation *op;
-
- op = request;
-
- schedule_op_failed (op, GNOME_KEYRING_RESULT_CANCELLED);
-}
-
-static gboolean
-standard_reply (GnomeKeyringOperation *op)
-{
- GnomeKeyringResult result;
- GnomeKeyringOperationDoneCallback callback;
-
- g_assert (op->user_callback_type == CALLBACK_DONE);
-
- callback = op->user_callback;
-
- if (!gkr_proto_decode_result_reply (&op->receive_buffer, &result)) {
- (*callback) (GNOME_KEYRING_RESULT_IO_ERROR, op->user_data);
- } else {
- (*callback) (result, op->user_data);
- }
-
- /* Operation is done */
- return TRUE;
-}
-
-static gboolean
-string_reply (GnomeKeyringOperation *op)
-{
- GnomeKeyringResult result;
- GnomeKeyringOperationGetStringCallback callback;
- char *string;
-
- g_assert (op->user_callback_type == CALLBACK_GET_STRING);
-
- callback = op->user_callback;
-
- if (!gkr_proto_decode_result_string_reply (&op->receive_buffer, &result, &string)) {
- (*callback) (GNOME_KEYRING_RESULT_IO_ERROR, NULL, op->user_data);
- } else {
- (*callback) (result, string, op->user_data);
- g_free (string);
- }
-
- /* Operation is done */
- return TRUE;
-}
-
-static gboolean
-int_reply (GnomeKeyringOperation *op)
-{
- GnomeKeyringResult result;
- GnomeKeyringOperationGetIntCallback callback;
- guint32 integer;
-
- g_assert (op->user_callback_type == CALLBACK_GET_INT);
-
- callback = op->user_callback;
-
- if (!gkr_proto_decode_result_integer_reply (&op->receive_buffer, &result, &integer)) {
- (*callback) (GNOME_KEYRING_RESULT_IO_ERROR, 0, op->user_data);
- } else {
- (*callback) (result, integer, op->user_data);
- }
-
- /* Operation is done */
- return TRUE;
-}
-
-/**
- * SECTION:gnome-keyring-keyrings
- * @title: Keyrings
- * @short_description: Listing and managing keyrings
- *
- * %gnome-keyring-daemon manages multiple keyrings. Each keyring can store one or more items containing secrets.
- *
- * One of the keyrings is the default keyring, which can in many cases be used by specifying %NULL for a keyring name.
- *
- * Each keyring can be in a locked or unlocked state. A password must be specified, either by the user or the calling application, to unlock the keyring.
- */
-
-/**
- * gnome_keyring_set_default_keyring:
- * @keyring: The keyring to make default
- * @callback: A callback which will be called when the request completes or fails.
- * @data: A pointer to arbitrary data that will be passed to the @callback.
- * @destroy_data: A function to free @data when it's no longer needed.
- *
- * Change the default keyring.
- *
- * For a synchronous version of this function see gnome_keyring_set_default_keyring_sync().
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- **/
-gpointer
-gnome_keyring_set_default_keyring (const gchar *keyring,
- GnomeKeyringOperationDoneCallback callback,
- gpointer data,
- GDestroyNotify destroy_data)
-{
- GnomeKeyringOperation *op;
-
- op = create_operation (FALSE, callback, CALLBACK_DONE, data, destroy_data);
- if (!gkr_proto_encode_op_string (&op->send_buffer, GNOME_KEYRING_OP_SET_DEFAULT_KEYRING,
- keyring)) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
- }
-
- op->reply_handler = standard_reply;
- start_operation (op);
- return op;
-}
-
-/**
- * gnome_keyring_set_default_keyring_sync:
- * @keyring: The keyring to make default
- *
- * Change the default keyring.
- *
- * For an asynchronous version of this function see gnome_keyring_set_default_keyring().
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- **/
-GnomeKeyringResult
-gnome_keyring_set_default_keyring_sync (const char *keyring)
-{
- EggBuffer send, receive;
- GnomeKeyringResult res;
-
- egg_buffer_init_full (&send, 128, NORMAL_ALLOCATOR);
-
- if (!gkr_proto_encode_op_string (&send, GNOME_KEYRING_OP_SET_DEFAULT_KEYRING,
- keyring)) {
- egg_buffer_uninit (&send);
- return GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
- }
-
- egg_buffer_init_full (&receive, 128, NORMAL_ALLOCATOR);
- res = run_sync_operation (&send, &receive);
- egg_buffer_uninit (&send);
- if (res != GNOME_KEYRING_RESULT_OK) {
- egg_buffer_uninit (&receive);
- return res;
- }
-
- if (!gkr_proto_decode_result_reply (&receive, &res)) {
- egg_buffer_uninit (&receive);
- return GNOME_KEYRING_RESULT_IO_ERROR;
- }
- egg_buffer_uninit (&receive);
-
- return res;
-}
-
-/**
- * gnome_keyring_get_default_keyring:
- * @callback: A callback which will be called when the request completes or fails.
- * @data: A pointer to arbitrary data that will be passed to the @callback.
- * @destroy_data: A function to free @data when it's no longer needed.
- *
- * Get the default keyring name, which will be passed to the @callback. If no
- * default keyring exists, then %NULL will be passed to the @callback. The
- * string will be freed after @callback returns.
- *
- * For a synchronous version of this function see gnome_keyring_get_default_keyring_sync().
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- **/
-gpointer
-gnome_keyring_get_default_keyring (GnomeKeyringOperationGetStringCallback callback,
- gpointer data,
- GDestroyNotify destroy_data)
-{
- GnomeKeyringOperation *op;
-
- op = create_operation (FALSE, callback, CALLBACK_GET_STRING, data, destroy_data);
- if (!gkr_proto_encode_op_only (&op->send_buffer, GNOME_KEYRING_OP_GET_DEFAULT_KEYRING)) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
- }
-
- op->reply_handler = string_reply;
- start_operation (op);
- return op;
-}
-
-/**
- * gnome_keyring_get_default_keyring_sync:
- * @keyring: Location for the default keyring name to be returned.
- *
- * Get the default keyring name.
- *
- * The string returned in @keyring must be freed with g_free().
- *
- * For an asynchronous version of this function see gnome_keyring_get_default_keyring().
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- **/
-GnomeKeyringResult
-gnome_keyring_get_default_keyring_sync (char **keyring)
-{
- EggBuffer send, receive;
- GnomeKeyringResult res;
-
- egg_buffer_init_full (&send, 128, NORMAL_ALLOCATOR);
-
- *keyring = NULL;
-
- if (!gkr_proto_encode_op_only (&send, GNOME_KEYRING_OP_GET_DEFAULT_KEYRING)) {
- egg_buffer_uninit (&send);
- return GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
- }
-
- egg_buffer_init_full (&receive, 128, NORMAL_ALLOCATOR);
-
- res = run_sync_operation (&send, &receive);
- egg_buffer_uninit (&send);
- if (res != GNOME_KEYRING_RESULT_OK) {
- egg_buffer_uninit (&receive);
- return res;
- }
-
- if (!gkr_proto_decode_result_string_reply (&receive, &res, keyring)) {
- egg_buffer_uninit (&receive);
- return GNOME_KEYRING_RESULT_IO_ERROR;
- }
- egg_buffer_uninit (&receive);
-
- return res;
-}
-
-static gboolean
-list_keyring_names_reply (GnomeKeyringOperation *op)
-{
- GnomeKeyringResult result;
- GnomeKeyringOperationGetListCallback callback;
- GList *names;
-
- callback = op->user_callback;
-
- if (!gkr_proto_decode_result_string_list_reply (&op->receive_buffer, &result, &names)) {
- (*callback) (GNOME_KEYRING_RESULT_IO_ERROR, NULL, op->user_data);
- } else {
- (*callback) (result, names, op->user_data);
- gnome_keyring_string_list_free (names);
- }
-
- /* Operation is done */
- return TRUE;
-}
-
-/**
- * gnome_keyring_list_keyring_names:
- * @callback: A callback which will be called when the request completes or fails.
- * @data: A pointer to arbitrary data that will be passed to the @callback.
- * @destroy_data: A function to free @data when it's no longer needed.
- *
- * Get a list of keyring names.
- *
- * A %GList of null terminated strings will be passed to
- * the @callback. If no keyrings exist then an empty list will be passed to the
- * @callback. The list is freed after @callback returns.
- *
- * For a synchronous version of this function see gnome_keyring_list_keyrings_sync().
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- **/
-gpointer
-gnome_keyring_list_keyring_names (GnomeKeyringOperationGetListCallback callback,
- gpointer data,
- GDestroyNotify destroy_data)
-{
- GnomeKeyringOperation *op;
-
- op = create_operation (FALSE, callback, CALLBACK_GET_LIST, data, destroy_data);
- if (!gkr_proto_encode_op_only (&op->send_buffer,
- GNOME_KEYRING_OP_LIST_KEYRINGS)) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
- }
-
- op->reply_handler = list_keyring_names_reply;
- start_operation (op);
- return op;
-}
-
-/**
- * gnome_keyring_list_keyring_names_sync:
- * @keyrings: Location for a %GList of keyring names to be returned.
- *
- * Get a list of keyring names.
- *
- * The list returned in in @keyrings must be freed using
- * gnome_keyring_string_list_free().
- *
- * For an asynchronous version of this function see gnome_keyring_list_keyring_names().
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- **/
-GnomeKeyringResult
-gnome_keyring_list_keyring_names_sync (GList **keyrings)
-{
- EggBuffer send, receive;
- GnomeKeyringResult res;
-
- egg_buffer_init_full (&send, 128, NORMAL_ALLOCATOR);
-
- *keyrings = NULL;
-
- if (!gkr_proto_encode_op_only (&send, GNOME_KEYRING_OP_LIST_KEYRINGS)) {
- egg_buffer_uninit (&send);
- return GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
- }
-
- egg_buffer_init_full (&receive, 128, NORMAL_ALLOCATOR);
-
- res = run_sync_operation (&send, &receive);
- egg_buffer_uninit (&send);
- if (res != GNOME_KEYRING_RESULT_OK) {
- egg_buffer_uninit (&receive);
- return res;
- }
-
- if (!gkr_proto_decode_result_string_list_reply (&receive, &res, keyrings)) {
- egg_buffer_uninit (&receive);
- return GNOME_KEYRING_RESULT_IO_ERROR;
- }
- egg_buffer_uninit (&receive);
-
- return res;
-}
-
-/**
- * gnome_keyring_lock_all:
- * @callback: A callback which will be called when the request completes or fails.
- * @data: A pointer to arbitrary data that will be passed to the @callback.
- * @destroy_data: A function to free @data when it's no longer needed.
- *
- * Lock all the keyrings, so that their contents may not be accessed without
- * first unlocking them with a password.
- *
- * For a synchronous version of this function see gnome_keyring_lock_all_sync().
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- **/
-gpointer
-gnome_keyring_lock_all (GnomeKeyringOperationDoneCallback callback,
- gpointer data,
- GDestroyNotify destroy_data)
-{
- GnomeKeyringOperation *op;
-
- op = create_operation (FALSE, callback, CALLBACK_DONE, data, destroy_data);
- if (!gkr_proto_encode_op_only (&op->send_buffer, GNOME_KEYRING_OP_LOCK_ALL)) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
- }
-
- op->reply_handler = standard_reply;
- start_operation (op);
- return op;
-}
-
-/**
- * gnome_keyring_lock_all_sync:
- *
- * Lock all the keyrings, so that their contents may not eb accessed without
- * first unlocking them with a password.
- *
- * For an asynchronous version of this function see gnome_keyring_lock_all().
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- **/
-GnomeKeyringResult
-gnome_keyring_lock_all_sync (void)
-{
- EggBuffer send, receive;
- GnomeKeyringResult res;
-
- egg_buffer_init_full (&send, 128, NORMAL_ALLOCATOR);
-
- if (!gkr_proto_encode_op_only (&send, GNOME_KEYRING_OP_LOCK_ALL)) {
- egg_buffer_uninit (&send);
- return GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
- }
-
- egg_buffer_init_full (&receive, 128, NORMAL_ALLOCATOR);
- res = run_sync_operation (&send, &receive);
- egg_buffer_uninit (&send);
- if (res != GNOME_KEYRING_RESULT_OK) {
- egg_buffer_uninit (&receive);
- return res;
- }
-
- if (!gkr_proto_decode_result_reply (&receive, &res)) {
- egg_buffer_uninit (&receive);
- return GNOME_KEYRING_RESULT_IO_ERROR;
- }
- egg_buffer_uninit (&receive);
-
- return res;
-}
-
-/**
- * gnome_keyring_create:
- * @keyring_name: The new keyring name. Must not be %NULL.
- * @password: The password for the new keyring. If %NULL user will be prompted.
- * @callback: A callback which will be called when the request completes or fails.
- * @data: A pointer to arbitrary data that will be passed to the @callback.
- * @destroy_data: A function to free @data when it's no longer needed.
- *
- * Create a new keyring with the specified name. In most cases %NULL will be
- * passed as the @password, which will prompt the user to enter a password
- * of their choice.
- *
- * For a synchronous version of this function see gnome_keyring_create_sync().
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- **/
-gpointer
-gnome_keyring_create (const char *keyring_name,
- const char *password,
- GnomeKeyringOperationDoneCallback callback,
- gpointer data,
- GDestroyNotify destroy_data)
-{
- GnomeKeyringOperation *op;
-
- op = create_operation (FALSE, callback, CALLBACK_DONE, data, destroy_data);
-
- /* Automatically secures buffer */
- if (!gkr_proto_encode_op_string_secret (&op->send_buffer, GNOME_KEYRING_OP_CREATE_KEYRING,
- keyring_name, password)) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
- }
-
- op->reply_handler = standard_reply;
- start_operation (op);
- return op;
-}
-
-/**
- * gnome_keyring_create_sync:
- * @keyring_name: The new keyring name. Must not be %NULL
- * @password: The password for the new keyring. If %NULL user will be prompted.
- *
- * Create a new keyring with the specified name. In most cases %NULL will be
- * passed in as the @password, which will prompt the user to enter a password
- * of their choice.
-
- * For an asynchronous version of this function see gnome_keyring_create().
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- **/
-GnomeKeyringResult
-gnome_keyring_create_sync (const char *keyring_name,
- const char *password)
-{
- EggBuffer send, receive;
- GnomeKeyringResult res;
-
- egg_buffer_init_full (&send, 128, SECURE_ALLOCATOR);
-
- if (!gkr_proto_encode_op_string_secret (&send, GNOME_KEYRING_OP_CREATE_KEYRING,
- keyring_name, password)) {
- egg_buffer_uninit (&send);
- return GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
- }
-
- egg_buffer_init_full (&receive, 128, NORMAL_ALLOCATOR);
- res = run_sync_operation (&send, &receive);
- egg_buffer_uninit (&send);
- if (res != GNOME_KEYRING_RESULT_OK) {
- egg_buffer_uninit (&receive);
- return res;
- }
-
- if (!gkr_proto_decode_result_reply (&receive, &res)) {
- egg_buffer_uninit (&receive);
- return GNOME_KEYRING_RESULT_IO_ERROR;
- }
- egg_buffer_uninit (&receive);
-
- return res;
-}
-
-/**
- * gnome_keyring_unlock:
- * @keyring: The name of the keyring to unlock, or %NULL for the default keyring.
- * @password: The password to unlock the keyring with, or %NULL to prompt the user.
- * @callback: A callback which will be called when the request completes or fails.
- * @data: A pointer to arbitrary data that will be passed to the @callback.
- * @destroy_data: A function to free @data when it's no longer needed.
- *
- * Unlock a @keyring, so that its contents may be accessed. In most cases %NULL
- * will be passed as the @password, which will prompt the user to enter the
- * correct password.
- *
- * Most keyring operations involving items require that you first unlock the
- * keyring. One exception is gnome_keyring_find_items() and related functions.
- *
- * For a synchronous version of this function see gnome_keyring_unlock_sync().
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- **/
-gpointer
-gnome_keyring_unlock (const char *keyring,
- const char *password,
- GnomeKeyringOperationDoneCallback callback,
- gpointer data,
- GDestroyNotify destroy_data)
-{
- GnomeKeyringOperation *op;
-
- op = create_operation (FALSE, callback, CALLBACK_DONE, data, destroy_data);
-
- /* Automatically secures buffer */
- if (!gkr_proto_encode_op_string_secret (&op->send_buffer, GNOME_KEYRING_OP_UNLOCK_KEYRING,
- keyring, password)) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
- }
-
- op->reply_handler = standard_reply;
- start_operation (op);
- return op;
-}
-
-/**
- * gnome_keyring_unlock_sync:
- * @keyring_name: The name of the keyring to unlock, or %NULL for the default keyring.
- * @password: The password to unlock the keyring with, or %NULL to prompt the user.
- *
- * Unlock a @keyring, so that its contents may be accessed. In most cases %NULL
- * will be passed in as the @password, which will prompt the user to enter the
- * correct password.
- *
- * Most keyring opretaions involving items require that yo ufirst unlock the
- * keyring. One exception is gnome_keyring_find_items_sync() and related functions.
- *
- * For an asynchronous version of this function see gnome_keyring_unlock().
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- **/
-GnomeKeyringResult
-gnome_keyring_unlock_sync (const char *keyring,
- const char *password)
-{
- EggBuffer send, receive;
- GnomeKeyringResult res;
-
- /* Use secure non-pageable buffer */
- egg_buffer_init_full (&send, 128, SECURE_ALLOCATOR);
-
- if (!gkr_proto_encode_op_string_secret (&send, GNOME_KEYRING_OP_UNLOCK_KEYRING,
- keyring, password)) {
- egg_buffer_uninit (&send);
- return GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
- }
-
- egg_buffer_init_full (&receive, 128, NORMAL_ALLOCATOR);
- res = run_sync_operation (&send, &receive);
- egg_buffer_uninit (&send);
- if (res != GNOME_KEYRING_RESULT_OK) {
- egg_buffer_uninit (&receive);
- return res;
- }
-
- if (!gkr_proto_decode_result_reply (&receive, &res)) {
- egg_buffer_uninit (&receive);
- return GNOME_KEYRING_RESULT_IO_ERROR;
- }
- egg_buffer_uninit (&receive);
-
- return res;
-}
-
-/**
- * gnome_keyring_lock:
- * @keyring: The name of the keyring to lock, or %NULL for the default keyring.
- * @callback: A callback which will be called when the request completes or fails.
- * @data: A pointer to arbitrary data that will be passed to the @callback.
- * @destroy_data: A function to free @data when it's no longer needed.
- *
- * Lock a @keyring, so that its contents may not be accessed without first
- * supplying a password.
- *
- * Most keyring operations involving items require that you first unlock the
- * keyring. One exception is gnome_keyring_find_items() and related functions.
- *
- * For a synchronous version of this function see gnome_keyring_lock_sync().
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- **/
-gpointer
-gnome_keyring_lock (const char *keyring,
- GnomeKeyringOperationDoneCallback callback,
- gpointer data,
- GDestroyNotify destroy_data)
-{
- GnomeKeyringOperation *op;
-
- op = create_operation (FALSE, callback, CALLBACK_DONE, data, destroy_data);
-
- if (!gkr_proto_encode_op_string (&op->send_buffer, GNOME_KEYRING_OP_LOCK_KEYRING,
- keyring)) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
- }
-
- op->reply_handler = standard_reply;
- start_operation (op);
- return op;
-}
-
-/**
- * gnome_keyring_unlock_sync:
- * @keyring: The name of the keyring to lock, or %NULL for the default keyring.
- *
- * Lock a @keyring, so that its contents may not be accessed without first
- * supplying a password.
- *
- * Most keyring opretaions involving items require that you first unlock the
- * keyring. One exception is gnome_keyring_find_items_sync() and related functions.
- *
- * For an asynchronous version of this function see gnome_keyring_lock().
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- **/
-GnomeKeyringResult
-gnome_keyring_lock_sync (const char *keyring)
-{
- EggBuffer send, receive;
- GnomeKeyringResult res;
-
- egg_buffer_init_full (&send, 128, NORMAL_ALLOCATOR);
-
- if (!gkr_proto_encode_op_string (&send, GNOME_KEYRING_OP_LOCK_KEYRING,
- keyring)) {
- egg_buffer_uninit (&send);
- return GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
- }
-
- egg_buffer_init_full (&receive, 128, NORMAL_ALLOCATOR);
- res = run_sync_operation (&send, &receive);
- egg_buffer_uninit (&send);
- if (res != GNOME_KEYRING_RESULT_OK) {
- egg_buffer_uninit (&receive);
- return res;
- }
-
- if (!gkr_proto_decode_result_reply (&receive, &res)) {
- egg_buffer_uninit (&receive);
- return GNOME_KEYRING_RESULT_IO_ERROR;
- }
- egg_buffer_uninit (&receive);
-
- return res;
-}
-
-/**
- * gnome_keyring_delete:
- * @keyring: The name of the keyring to delete. Cannot be %NULL.
- * @callback: A callback which will be called when the request completes or fails.
- * @data: A pointer to arbitrary data that will be passed to the @callback.
- * @destroy_data: A function to free @data when it's no longer needed.
- *
- * Delete @keyring. Once a keyring is deleted there is no mechanism for
- * recovery of its contents.
- *
- * For a synchronous version of this function see gnome_keyring_delete_sync().
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- **/
-gpointer
-gnome_keyring_delete (const char *keyring,
- GnomeKeyringOperationDoneCallback callback,
- gpointer data,
- GDestroyNotify destroy_data)
-{
- GnomeKeyringOperation *op;
-
- op = create_operation (FALSE, callback, CALLBACK_DONE, data, destroy_data);
-
- if (!gkr_proto_encode_op_string (&op->send_buffer, GNOME_KEYRING_OP_DELETE_KEYRING,
- keyring)) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
- }
-
- op->reply_handler = standard_reply;
- start_operation (op);
- return op;
-}
-
-/**
- * gnome_keyring_delete_sync:
- * @keyring: The name of the keyring to delete. Cannot be %NULL
- *
- * Delete @keyring. Once a keyring is deleted there is no mechanism for
- * recovery of its contents.
- *
- * For an asynchronous version of this function see gnome_keyring_delete().
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- **/
-GnomeKeyringResult
-gnome_keyring_delete_sync (const char *keyring)
-{
- EggBuffer send, receive;
- GnomeKeyringResult res;
-
- egg_buffer_init_full (&send, 128, NORMAL_ALLOCATOR);
-
- if (!gkr_proto_encode_op_string (&send, GNOME_KEYRING_OP_DELETE_KEYRING,
- keyring)) {
- egg_buffer_uninit (&send);
- return GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
- }
-
- egg_buffer_init_full (&receive, 128, NORMAL_ALLOCATOR);
- res = run_sync_operation (&send, &receive);
- egg_buffer_uninit (&send);
- if (res != GNOME_KEYRING_RESULT_OK) {
- egg_buffer_uninit (&receive);
- return res;
- }
-
- if (!gkr_proto_decode_result_reply (&receive, &res)) {
- egg_buffer_uninit (&receive);
- return GNOME_KEYRING_RESULT_IO_ERROR;
- }
- egg_buffer_uninit (&receive);
-
- return res;
-}
-
-/**
- * gnome_keyring_change_password:
- * @keyring: The name of the keyring to change the password for. Cannot be %NULL.
- * @original: The old keyring password, or %NULL to prompt the user for it.
- * @password: The new keyring password, or %NULL to prompt the user for it.
- * @callback: A callback which will be called when the request completes or fails.
- * @data: A pointer to arbitrary data that will be passed to the @callback.
- * @destroy_data: A function to free @data when it's no longer needed.
- *
- * Change the password for a @keyring. In most cases you would specify %NULL for
- * both the @original and @password arguments and allow the user to type the
- * correct passwords.
- *
- * For a synchronous version of this function see gnome_keyring_change_password_sync().
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- **/
-gpointer
-gnome_keyring_change_password (const char *keyring,
- const char *original,
- const char *password,
- GnomeKeyringOperationDoneCallback callback,
- gpointer data,
- GDestroyNotify destroy_data)
-{
- GnomeKeyringOperation *op;
-
- op = create_operation (FALSE, callback, CALLBACK_DONE, data, destroy_data);
-
- /* Automatically secures buffer */
- if (!gkr_proto_encode_op_string_secret_secret (&op->send_buffer,
- GNOME_KEYRING_OP_CHANGE_KEYRING_PASSWORD,
- keyring, original, password)) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
- }
-
- op->reply_handler = standard_reply;
- start_operation (op);
-
- return op;
-}
-
-
-/**
- * gnome_keyring_change_password_sync:
- * @keyring: The name of the keyring to change the password for. Cannot be %NULL
- * @original: The old keyring password, or %NULL to prompt the user for it.
- * @password: The new keyring password, or %NULL to prompt the user for it.
- *
- * Change the password for @keyring. In most cases you would specify %NULL for
- * both the @original and @password arguments and allow the user to type the
- * correct passwords.
- *
- * For an asynchronous version of this function see gnome_keyring_change_password().
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- **/
-GnomeKeyringResult
-gnome_keyring_change_password_sync (const char *keyring_name,
- const char *original, const char *password)
-{
- EggBuffer send, receive;
- GnomeKeyringResult res;
-
- egg_buffer_init_full (&send, 128, SECURE_ALLOCATOR);
-
- if (!gkr_proto_encode_op_string_secret_secret (&send,
- GNOME_KEYRING_OP_CHANGE_KEYRING_PASSWORD,
- keyring_name, original, password)) {
- egg_buffer_uninit (&send);
- return GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
- }
-
- egg_buffer_init_full (&receive, 128, NORMAL_ALLOCATOR);
- res = run_sync_operation (&send, &receive);
- egg_buffer_uninit (&send);
- if (res != GNOME_KEYRING_RESULT_OK) {
- egg_buffer_uninit (&receive);
- return res;
- }
-
- if (!gkr_proto_decode_result_reply (&receive, &res)) {
- egg_buffer_uninit (&receive);
- return GNOME_KEYRING_RESULT_IO_ERROR;
- }
- egg_buffer_uninit (&receive);
-
- return res;
-}
-
-static gboolean
-get_keyring_info_reply (GnomeKeyringOperation *op)
-{
- GnomeKeyringResult result;
- GnomeKeyringOperationGetKeyringInfoCallback callback;
- GnomeKeyringInfo *info;
-
- callback = op->user_callback;
-
- if (!gkr_proto_decode_get_keyring_info_reply (&op->receive_buffer, &result, &info)) {
- (*callback) (GNOME_KEYRING_RESULT_IO_ERROR, NULL, op->user_data);
- } else {
- (*callback) (result, info, op->user_data);
- gnome_keyring_info_free (info);
- }
-
- /* Operation is done */
- return TRUE;
-}
-
-/**
- * gnome_keyring_get_info:
- * @keyring: The name of the keyring, or %NULL for the default keyring.
- * @callback: A callback which will be called when the request completes or fails.
- * @data: A pointer to arbitrary data that will be passed to the @callback.
- * @destroy_data: A function to free @data when it's no longer needed.
- *
- * Get information about the @keyring. The resulting #GnomeKeyringInfo structure
- * will be passed to @callback. The structure is freed after @callback returns.
- *
- * For a synchronous version of this function see gnome_keyring_get_info_sync().
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- **/
-gpointer
-gnome_keyring_get_info (const char *keyring,
- GnomeKeyringOperationGetKeyringInfoCallback callback,
- gpointer data,
- GDestroyNotify destroy_data)
-{
- GnomeKeyringOperation *op;
-
- op = create_operation (FALSE, callback, CALLBACK_GET_KEYRING_INFO, data, destroy_data);
-
- if (!gkr_proto_encode_op_string (&op->send_buffer, GNOME_KEYRING_OP_GET_KEYRING_INFO,
- keyring)) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
- }
-
- op->reply_handler = get_keyring_info_reply;
- start_operation (op);
- return op;
-}
-
-/**
- * gnome_keyring_get_info_sync:
- * @keyring: The name of the keyring, or %NULL for the default keyring.
- * @info: Location for the information about the keyring to be returned.
- *
- * Get information about @keyring.
- *
- * The #GnomeKeyringInfo structure returned in @info must be freed with
- * gnome_keyring_info_free().
- *
- * For an asynchronous version of this function see gnome_keyring_get_info().
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- **/
-GnomeKeyringResult
-gnome_keyring_get_info_sync (const char *keyring,
- GnomeKeyringInfo **info)
-{
- EggBuffer send, receive;
- GnomeKeyringResult res;
-
- egg_buffer_init_full (&send, 128, NORMAL_ALLOCATOR);
-
- *info = NULL;
-
- if (!gkr_proto_encode_op_string (&send, GNOME_KEYRING_OP_GET_KEYRING_INFO,
- keyring)) {
- egg_buffer_uninit (&send);
- return GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
- }
-
- egg_buffer_init_full (&receive, 128, NORMAL_ALLOCATOR);
-
- res = run_sync_operation (&send, &receive);
- egg_buffer_uninit (&send);
- if (res != GNOME_KEYRING_RESULT_OK) {
- egg_buffer_uninit (&receive);
- return res;
- }
-
- if (!gkr_proto_decode_get_keyring_info_reply (&receive, &res, info)) {
- egg_buffer_uninit (&receive);
- return GNOME_KEYRING_RESULT_IO_ERROR;
- }
- egg_buffer_uninit (&receive);
-
- return res;
-}
-
-/**
- * gnome_keyring_set_info:
- * @keyring: The name of the keyring, or %NULL for the default keyring.
- * @info: A structure containing flags and info for the keyring.
- * @callback: A callback which will be called when the request completes or fails.
- * @data: A pointer to arbitrary data that will be passed to the @callback.
- * @destroy_data: A function to free @data when it's no longer needed.
- *
- * Set flags and info for the @keyring. The only fields in @info that are used
- * are %lock_on_idle and %lock_timeout.
- *
- * For a synchronous version of this function see gnome_keyring_set_info_sync().
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- **/
-gpointer
-gnome_keyring_set_info (const char *keyring,
- GnomeKeyringInfo *info,
- GnomeKeyringOperationDoneCallback callback,
- gpointer data,
- GDestroyNotify destroy_data)
-{
- GnomeKeyringOperation *op;
-
- op = create_operation (FALSE, callback, CALLBACK_DONE, data, destroy_data);
-
- if (!gkr_proto_encode_set_keyring_info (&op->send_buffer, keyring, info)) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
- }
-
- op->reply_handler = standard_reply;
- start_operation (op);
- return op;
-}
-
-/**
- * gnome_keyring_set_info_sync:
- * @keyring: The name of the keyring, or %NULL for the default keyring.
- * @info: A structure containing flags and info for the keyring.
- *
- * Set flags and info for @keyring. The only fields in @info that are used
- * are %lock_on_idle and %lock_timeout.
- *
- * For an asynchronous version of this function see gnome_keyring_set_info().
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- **/
-GnomeKeyringResult
-gnome_keyring_set_info_sync (const char *keyring,
- GnomeKeyringInfo *info)
-{
- EggBuffer send, receive;
- GnomeKeyringResult res;
-
- egg_buffer_init_full (&send, 128, NORMAL_ALLOCATOR);
-
- if (!gkr_proto_encode_set_keyring_info (&send, keyring, info)) {
- egg_buffer_uninit (&send);
- return GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
- }
-
- egg_buffer_init_full (&receive, 128, NORMAL_ALLOCATOR);
- res = run_sync_operation (&send, &receive);
- egg_buffer_uninit (&send);
- egg_buffer_uninit (&receive);
-
- return res;
-}
-
-static gboolean
-list_item_ids_reply (GnomeKeyringOperation *op)
-{
- GnomeKeyringResult result;
- GnomeKeyringOperationGetListCallback callback;
- GList *items;
-
- callback = op->user_callback;
-
- if (!gkr_proto_decode_result_int_list_reply (&op->receive_buffer, &result, &items)) {
- (*callback) (GNOME_KEYRING_RESULT_IO_ERROR, NULL, op->user_data);
- } else {
- (*callback) (result, items, op->user_data);
- g_list_free (items);
- }
-
- /* Operation is done */
- return TRUE;
-}
-
-/**
- * gnome_keyring_list_item_ids:
- * @keyring: The name of the keyring, or %NULL for the default keyring.
- * @callback: A callback which will be called when the request completes or fails.
- * @data: A pointer to arbitrary data that will be passed to the @callback.
- * @destroy_data: A function to free @data when it's no longer needed.
- *
- * Get a list of all the ids for items in @keyring. These are passed in a %GList
- * to the @callback. Use GPOINTER_TO_UINT() on the list to access the integer ids.
- * The list is freed after @callback returns.
- *
- * All items that are not flagged as %GNOME_KEYRING_ITEM_APPLICATION_SECRET are
- * included in the list. This includes items that the calling application may not
- * (yet) have access to.
- *
- * For a synchronous version of this function see gnome_keyring_list_item_ids_sync().
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- **/
-gpointer
-gnome_keyring_list_item_ids (const char *keyring,
- GnomeKeyringOperationGetListCallback callback,
- gpointer data,
- GDestroyNotify destroy_data)
-{
- GnomeKeyringOperation *op;
-
- op = create_operation (FALSE, callback, CALLBACK_GET_LIST, data, destroy_data);
-
- if (!gkr_proto_encode_op_string (&op->send_buffer, GNOME_KEYRING_OP_LIST_ITEMS,
- keyring)) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
- }
-
- op->reply_handler = list_item_ids_reply;
- start_operation (op);
- return op;
-}
-
-/**
- * gnome_keyring_list_item_ids_sync:
- * @keyring: The name of the keyring, or %NULL for the default keyring.
- * @ids: The location to store a %GList of item ids (ie: unsigned integers).
- *
- * Get a list of all the ids for items in @keyring.
- *
- * Use GPOINTER_TO_UINT() on the list to access the integer ids. The list
- * should be freed with g_list_free().
- *
- * For an asynchronous version of this function see gnome_keyring_list_item_ids().
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- **/
-GnomeKeyringResult
-gnome_keyring_list_item_ids_sync (const char *keyring,
- GList **ids)
-{
- EggBuffer send, receive;
- GnomeKeyringResult res;
-
- egg_buffer_init_full (&send, 128, NORMAL_ALLOCATOR);
-
- *ids = NULL;
-
- if (!gkr_proto_encode_op_string (&send, GNOME_KEYRING_OP_LIST_ITEMS,
- keyring)) {
- egg_buffer_uninit (&send);
- return GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
- }
-
- egg_buffer_init_full (&receive, 128, NORMAL_ALLOCATOR);
-
- res = run_sync_operation (&send, &receive);
- egg_buffer_uninit (&send);
- if (res != GNOME_KEYRING_RESULT_OK) {
- egg_buffer_uninit (&receive);
- return res;
- }
-
- if (!gkr_proto_decode_result_int_list_reply (&receive, &res, ids)) {
- egg_buffer_uninit (&receive);
- return GNOME_KEYRING_RESULT_IO_ERROR;
- }
- egg_buffer_uninit (&receive);
-
- return res;
-}
-
-/**
- * SECTION:gnome-keyring-daemon
- * @title: Daemon Management Functions
- * @short_description: Functions used by session to run the Gnome Keyring Daemon.
- *
- * These functions are not used by most applications using Gnome Keyring.
- */
-
-/**
- * gnome_keyring_daemon_set_display_sync:
- * @display: Deprecated
- *
- * Deprecated. Use gnome_keyring_daemon_prepare_environment_sync()
- **/
-GnomeKeyringResult
-gnome_keyring_daemon_set_display_sync (const char *display)
-{
- EggBuffer send, receive;
- GnomeKeyringResult res;
-
- egg_buffer_init_full (&send, 128, NORMAL_ALLOCATOR);
-
- if (!gkr_proto_encode_op_string (&send, GNOME_KEYRING_OP_SET_DAEMON_DISPLAY,
- display)) {
- egg_buffer_uninit (&send);
- return GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
- }
-
- egg_buffer_init_full (&receive, 128, NORMAL_ALLOCATOR);
- res = run_sync_operation (&send, &receive);
- egg_buffer_uninit (&send);
- if (res != GNOME_KEYRING_RESULT_OK) {
- egg_buffer_uninit (&receive);
- return res;
- }
-
- if (!gkr_proto_decode_result_reply (&receive, &res)) {
- egg_buffer_uninit (&receive);
- return GNOME_KEYRING_RESULT_IO_ERROR;
- }
- egg_buffer_uninit (&receive);
-
- return res;
-}
-
-/**
- * gnome_keyring_daemon_prepare_environment_sync:
- *
- * Used by session managers or applications that manage the gnome-keyring-daemon
- * process. Prepares the environment of both the daemon and the application
- * for successful communication.
- *
- * This includes telling the daemon the DBUS addresses, X display and related
- * information to use for communication and display. This information is only
- * used by the daemon if it does not already have it. For example the X display
- * of the daemon cannot be changed using this call.
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- **/
-GnomeKeyringResult
-gnome_keyring_daemon_prepare_environment_sync (void)
-{
- EggBuffer send, receive;
- GnomeKeyringResult res;
- gchar **envp;
- gboolean ret;
-
- egg_buffer_init_full (&send, 128, NORMAL_ALLOCATOR);
-
- /* Get all the environment names */
- envp = gnome_keyring_build_environment (GNOME_KEYRING_IN_ENVIRONMENT);
- ret = gkr_proto_encode_prepare_environment (&send, (const gchar**)envp);
- g_strfreev (envp);
-
- if (!ret) {
- egg_buffer_uninit (&send);
- return GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
- }
-
- egg_buffer_init_full (&receive, 128, NORMAL_ALLOCATOR);
- res = run_sync_operation (&send, &receive);
- egg_buffer_uninit (&send);
- if (res != GNOME_KEYRING_RESULT_OK) {
- egg_buffer_uninit (&receive);
- return res;
- }
-
- if (!gkr_proto_decode_prepare_environment_reply (&receive, &res, &envp)) {
- egg_buffer_uninit (&receive);
- return GNOME_KEYRING_RESULT_IO_ERROR;
- }
- egg_buffer_uninit (&receive);
-
- if (res == GNOME_KEYRING_RESULT_OK) {
- g_return_val_if_fail (envp, GNOME_KEYRING_RESULT_IO_ERROR);
- gnome_keyring_apply_environment (envp);
- }
-
- g_strfreev (envp);
-
- return res;
-}
-
-/**
- * gnome_keyring_info_set_lock_on_idle:
- * @keyring_info: The keyring info.
- * @value: Whether to lock or not.
- *
- * Set whether or not to lock a keyring after a certain amount of idle time.
- *
- * See also gnome_keyring_info_set_lock_timeout().
- */
-void
-gnome_keyring_info_set_lock_on_idle (GnomeKeyringInfo *keyring_info,
- gboolean value)
-{
- keyring_info->lock_on_idle = value;
-}
-
-/**
- * gnome_keyring_info_get_lock_on_idle:
- * @keyring_info: The keyring info.
- *
- * Get whether or not to lock a keyring after a certain amount of idle time.
- *
- * See also gnome_keyring_info_get_lock_timeout().
- *
- * Return value: Whether to lock or not.
- */
-gboolean
-gnome_keyring_info_get_lock_on_idle (GnomeKeyringInfo *keyring_info)
-{
- return keyring_info->lock_on_idle;
-}
-
-/**
- * gnome_keyring_info_set_lock_timeout:
- * @keyring_info: The keyring info.
- * @value: The lock timeout in seconds.
- *
- * Set the idle timeout, in seconds, after which to lock the keyring.
- *
- * See also gnome_keyring_info_set_lock_on_idle().
- */
-void
-gnome_keyring_info_set_lock_timeout (GnomeKeyringInfo *keyring_info,
- guint32 value)
-{
- keyring_info->lock_timeout = value;
-}
-
-/**
- * gnome_keyring_info_get_lock_timeout:
- * @keyring_info: The keyring info.
- *
- * Get the idle timeout, in seconds, after which to lock the keyring.
- *
- * See also gnome_keyring_info_get_lock_on_idle().
- *
- * Return value: The idle timeout, in seconds.
- */
-guint32
-gnome_keyring_info_get_lock_timeout (GnomeKeyringInfo *keyring_info)
-{
- return keyring_info->lock_timeout;
-}
-
-/**
- * gnome_keyring_info_get_mtime:
- * @keyring_info: The keyring info.
- *
- * Get the time at which the keyring was last modified.
- *
- * Return value: The last modified time.
- */
-time_t
-gnome_keyring_info_get_mtime (GnomeKeyringInfo *keyring_info)
-{
- return keyring_info->mtime;
-}
-
-/**
- * gnome_keyring_info_get_ctime:
- * @keyring_info: The keyring info.
- *
- * Get the time at which the keyring was created.
- *
- * Return value: The created time.
- */
-time_t
-gnome_keyring_info_get_ctime (GnomeKeyringInfo *keyring_info)
-{
- return keyring_info->ctime;
-}
-
-/**
- * gnome_keyring_info_get_is_locked:
- * @keyring_info: The keyring info.
- *
- * Get whether the keyring is locked or not.
- *
- * Return value: Whether the keyring is locked or not.
- */
-gboolean
-gnome_keyring_info_get_is_locked (GnomeKeyringInfo *keyring_info)
-{
- return keyring_info->is_locked;
-}
-
-static gboolean
-find_items_reply (GnomeKeyringOperation *op)
-{
- GnomeKeyringResult result;
- GnomeKeyringOperationGetListCallback callback;
- GList *found_items;
-
- callback = op->user_callback;
-
- if (!gkr_proto_decode_find_reply (&op->receive_buffer, &result, &found_items)) {
- (*callback) (GNOME_KEYRING_RESULT_IO_ERROR, NULL, op->user_data);
- } else {
- (*callback) (result, found_items, op->user_data);
- gnome_keyring_found_list_free (found_items);
- }
-
- /* Operation is done */
- return TRUE;
-}
-
-/**
- * SECTION:gnome-keyring-find
- * @title: Search Functionality
- * @short_description: Find Keyring Items
- *
- * A find operation searches through all keyrings for items that match the
- * attributes. The user may have been prompted to unlock necessary keyrings, and
- * user will have been prompted for access to the items if needed.
- *
- * A find operation may return multiple or zero results.
- */
-
-/**
- * gnome_keyring_find_items:
- * @type: The type of items to find.
- * @attributes: A list of attributes to search for. This cannot be an empty list.
- * @callback: A callback which will be called when the request completes or fails.
- * @data: A pointer to arbitrary data that will be passed to the @callback.
- * @destroy_data: A function to free @data when it's no longer needed.
- *
- * Searches through all keyrings for items that match the @attributes. The matches
- * are for exact equality.
- *
- * A %GList of GnomeKeyringFound structures are passed to the @callback. The
- * list and structures are freed after the callback returns.
- *
- * The user may have been prompted to unlock necessary keyrings, and user will
- * have been prompted for access to the items if needed.
- *
- * For a synchronous version of this function see gnome_keyring_find_items_sync().
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- **/
-gpointer
-gnome_keyring_find_items (GnomeKeyringItemType type,
- GnomeKeyringAttributeList *attributes,
- GnomeKeyringOperationGetListCallback callback,
- gpointer data,
- GDestroyNotify destroy_data)
-{
- GnomeKeyringOperation *op;
-
- /* Use a secure receive buffer */
- op = create_operation (TRUE, callback, CALLBACK_GET_LIST, data, destroy_data);
-
- if (!gkr_proto_encode_find (&op->send_buffer, type, attributes)) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
- }
-
- op->reply_handler = find_items_reply;
- start_operation (op);
- return op;
-}
-
-
-static GnomeKeyringAttributeList *
-make_attribute_list_va (va_list args)
-{
- GnomeKeyringAttributeList *attributes;
- GnomeKeyringAttribute attribute;
- char *str;
- guint32 val;
-
- attributes = g_array_new (FALSE, FALSE, sizeof (GnomeKeyringAttribute));
-
- while ((attribute.name = va_arg (args, char *)) != NULL) {
- attribute.type = va_arg (args, GnomeKeyringAttributeType);
-
- switch (attribute.type) {
- case GNOME_KEYRING_ATTRIBUTE_TYPE_STRING:
- str = va_arg (args, char *);
- attribute.value.string = str;
- g_array_append_val (attributes, attribute);
- break;
- case GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32:
- val = va_arg (args, guint32);
- attribute.value.integer = val;
- g_array_append_val (attributes, attribute);
- break;
- default:
- g_array_free (attributes, TRUE);
- return NULL;
- }
- }
- return attributes;
-}
-
-/**
- * gnome_keyring_find_itemsv:
- * @type: The type of items to find.
- * @callback: A callback which will be called when the request completes or fails.
- * @data: A pointer to arbitrary data that will be passed to the @callback.
- * @destroy_data: A function to free @data when it's no longer needed.
- *
- * Searches through all keyrings for items that match the specified attributes.
- * The matches are for exact equality.
- *
- * The variable argument list should contain a) The attribute name as a null
- * terminated string, followed by b) The attribute type, either
- * %GNOME_KEYRING_ATTRIBUTE_TYPE_STRING or %GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32
- * and then the c) attribute value, either a character string, or 32-bit
- * unsigned int. The list should be terminated with a NULL.
- *
- * A %GList of GnomeKeyringFound structures are passed to the @callback. The
- * list and structures are freed after the callback returns.
- *
- * The user may have been prompted to unlock necessary keyrings, and user will
- * have been prompted for access to the items if needed.
- *
- * For a synchronous version of this function see gnome_keyring_find_itemsv_sync().
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- **/
-gpointer
-gnome_keyring_find_itemsv (GnomeKeyringItemType type,
- GnomeKeyringOperationGetListCallback callback,
- gpointer data,
- GDestroyNotify destroy_data,
- ...)
-{
- GnomeKeyringOperation *op;
- GnomeKeyringAttributeList *attributes;
- va_list args;
-
- /* Use a secure receive buffer */
- op = create_operation (TRUE, callback, CALLBACK_GET_LIST, data, destroy_data);
-
- va_start (args, destroy_data);
- attributes = make_attribute_list_va (args);
- va_end (args);
- if (attributes == NULL) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
- return op;
- }
-
- if (!gkr_proto_encode_find (&op->send_buffer, type, attributes)) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
- }
- g_array_free (attributes, TRUE);
-
- op->reply_handler = find_items_reply;
- start_operation (op);
- return op;
-}
-
-/**
- * gnome_keyring_find_items_sync:
- * @type: The type of items to find.
- * @attributes: A list of attributes to search for. This cannot be an empty list.
- * @found: The location to return a list of #GnomeKeyringFound pointers.
- *
- * Searches through all keyrings for items that match the @attributes and @type.
- * The matches are for exact equality.
- *
- * A %GList of GnomeKeyringFound structures is returned in @found. The list may
- * have zero items if nothing matched the criteria. The list should be freed
- * using gnome_keyring_found_list_free().
- *
- * The user may have been prompted to unlock necessary keyrings, and user will
- * have been prompted for access to the items if needed.
- *
- * For an asynchronous version of this function see gnome_keyring_find_items().
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- **/
-GnomeKeyringResult
-gnome_keyring_find_items_sync (GnomeKeyringItemType type,
- GnomeKeyringAttributeList *attributes,
- GList **found)
-{
- EggBuffer send, receive;
- GnomeKeyringResult res;
-
- egg_buffer_init_full (&send, 128, NORMAL_ALLOCATOR);
-
- *found = NULL;
-
- if (!gkr_proto_encode_find (&send, type, attributes)) {
- egg_buffer_uninit (&send);
- return GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
- }
-
- /* Use a secure receive buffer */
- egg_buffer_init_full (&receive, 128, SECURE_ALLOCATOR);
-
- res = run_sync_operation (&send, &receive);
- egg_buffer_uninit (&send);
- if (res != GNOME_KEYRING_RESULT_OK) {
- egg_buffer_uninit (&receive);
- return res;
- }
-
- if (!gkr_proto_decode_find_reply (&receive, &res, found)) {
- egg_buffer_uninit (&receive);
- return GNOME_KEYRING_RESULT_IO_ERROR;
- }
- egg_buffer_uninit (&receive);
-
- return res;
-}
-
-/**
- * gnome_keyring_find_itemsv_sync:
- * @type: The type of items to find.
- * @found: The location to return a list of #GnomeKeyringFound pointers.
- *
- * Searches through all keyrings for items that match the @attributes and @type.
- * The matches are for exact equality.
- *
- * The variable argument list should contain a) The attribute name as a null
- * terminated string, followed by b) The attribute type, either
- * %GNOME_KEYRING_ATTRIBUTE_TYPE_STRING or %GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32
- * and then the c) attribute value, either a character string, or 32-bit
- * unsigned int. The list should be terminated with a NULL.
- *
- * A %GList of GnomeKeyringFound structures is returned in @found. The list may
- * have zero items if nothing matched the criteria. The list should be freed
- * using gnome_keyring_found_list_free().
- *
- * The user may have been prompted to unlock necessary keyrings, and user will
- * have been prompted for access to the items if needed.
- *
- * For an asynchronous version of this function see gnome_keyring_find_items().
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- **/
-GnomeKeyringResult
-gnome_keyring_find_itemsv_sync (GnomeKeyringItemType type,
- GList **found,
- ...)
-{
- GnomeKeyringAttributeList *attributes;
- GnomeKeyringResult res;
- va_list args;
-
- va_start (args, found);
- attributes = make_attribute_list_va (args);
- va_end (args);
- if (attributes == NULL) {
- return GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
- }
-
- res = gnome_keyring_find_items_sync (type, attributes, found);
- g_array_free (attributes, TRUE);
- return res;
-}
-
-/**
- * SECTION:gnome-keyring-items
- * @title: Keyring Items
- * @short_description: Keyring items each hold a secret and a number of attributes.
- *
- * A keyring contains multiple items. Each item has a secret, attributes and access
- * information associated with it.
- *
- * An item is identified by an unsigned integer unique to the keyring in which it
- * exists. An item's name is for displaying to the user. Each item has a single secret,
- * which is a null-terminated string. This secret is stored in non-pageable memory, and
- * encrypted on disk. All of this information is exposed via #GnomeKeyringItemInfo
- * pointers.
- *
- * Attributes allow various other pieces of information to be associated with an item.
- * These can also be used to search for relevant items. Attributes are accessed with
- * #GnomeKeyringAttribute structures and built into lists using #GnomeKeyringAttributeList.
- *
- * Each item has an access control list, which specifies the applications that
- * can read, write or delete an item. The read access applies only to reading the secret.
- * All applications can read other parts of the item. ACLs are accessed and changed
- * through #GnomeKeyringAccessControl pointers.
- */
-
-/**
- * gnome_keyring_item_create:
- * @keyring: The name of the keyring in which to create the item, or NULL for the default keyring.
- * @type: The item type.
- * @display_name: The name of the item. This will be displayed to the user where necessary.
- * @attributes: A (possibly empty) list of attributes to store with the item.
- * @secret: The password or secret of the item.
- * @update_if_exists: If true, then another item matching the type, and attributes
- * will be updated instead of creating a new item.
- * @callback: A callback which will be called when the request completes or fails.
- * @data: A pointer to arbitrary data that will be passed to the @callback.
- * @destroy_data: A function to free @data when it's no longer needed.
- *
- * Create a new item in a keyring.
- *
- * The @secret must be a null terminated string. It should be allocated using secure
- * memory whenever possible. See gnome_keyring_memory_strdup()
- *
- * The user may have been prompted to unlock necessary keyrings. If %NULL is
- * specified as the @keyring and no default keyring exists, the user will be
- * prompted to create a new keyring.
- *
- * When @update_if_exists is set to %TRUE, the user may be prompted for access
- * to the previously existing item.
- *
- * Whether a new item is created or not, id of the item will be passed to
- * the @callback.
- *
- * For a synchronous version of this function see gnome_keyring_item_create_sync().
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- **/
-gpointer
-gnome_keyring_item_create (const char *keyring,
- GnomeKeyringItemType type,
- const char *display_name,
- GnomeKeyringAttributeList *attributes,
- const char *secret,
- gboolean update_if_exists,
- GnomeKeyringOperationGetIntCallback callback,
- gpointer data,
- GDestroyNotify destroy_data)
-{
- GnomeKeyringOperation *op;
-
- op = create_operation (FALSE, callback, CALLBACK_GET_INT, data, destroy_data);
-
- /* Automatically secures buffer */
- if (!gkr_proto_encode_create_item (&op->send_buffer, keyring, display_name,
- attributes, secret, type, update_if_exists)) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
- }
-
- op->reply_handler = int_reply;
- start_operation (op);
- return op;
-}
-
-/**
- * gnome_keyring_item_create_sync():
- * @keyring: The name of the keyring in which to create the item, or NULL for the default keyring.
- * @type: The item type.
- * @display_name: The name of the item. This will be displayed to the user where necessary.
- * @attributes: A (possibly empty) list of attributes to store with the item.
- * @secret: The password or secret of the item.
- * @update_if_exists: If true, then another item matching the type, and attributes
- * will be updated instead of creating a new item.
- * @item_id: return location for the id of the created/updated keyring item.
- *
- * Create a new item in a keyring.
- *
- * The @secret must be a null terminated string. It should be allocated using secure
- * memory whenever possible. See gnome_keyring_memory_strdup()
- *
- * The user may have been prompted to unlock necessary keyrings. If %NULL is
- * specified as the @keyring and no default keyring exists, the user will be
- * prompted to create a new keyring.
- *
- * When @update_if_exists is set to %TRUE, the user may be prompted for access
- * to the previously existing item.
- *
- * For an asynchronous version of this function see gnome_keyring_create().
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- */
-GnomeKeyringResult
-gnome_keyring_item_create_sync (const char *keyring,
- GnomeKeyringItemType type,
- const char *display_name,
- GnomeKeyringAttributeList *attributes,
- const char *secret,
- gboolean update_if_exists,
- guint32 *item_id)
-{
- EggBuffer send, receive;
- GnomeKeyringResult res;
-
- /* Use a secure buffer */
- egg_buffer_init_full (&send, 128, SECURE_ALLOCATOR);
-
- *item_id = 0;
-
- if (!gkr_proto_encode_create_item (&send, keyring, display_name, attributes,
- secret, type, update_if_exists)) {
- egg_buffer_uninit (&send);
- return GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
- }
-
- egg_buffer_init_full (&receive, 128, NORMAL_ALLOCATOR);
-
- res = run_sync_operation (&send, &receive);
- egg_buffer_uninit (&send);
- if (res != GNOME_KEYRING_RESULT_OK) {
- egg_buffer_uninit (&receive);
- return res;
- }
-
- if (!gkr_proto_decode_result_integer_reply (&receive, &res, item_id)) {
- egg_buffer_uninit (&receive);
- return GNOME_KEYRING_RESULT_IO_ERROR;
- }
- egg_buffer_uninit (&receive);
-
- return res;
-}
-
-/**
- * gnome_keyring_item_delete:
- * @keyring: The name of the keyring from which to delete the item, or NULL for the default keyring.
- * @id: The id of the item
- * @callback: A callback which will be called when the request completes or fails.
- * @data: A pointer to arbitrary data that will be passed to the @callback.
- * @destroy_data: A function to free @data when it's no longer needed.
- *
- * Delete an item in a keyring.
- *
- * The user may be prompted if the calling application doesn't have necessary
- * access to delete the item.
- *
- * For an asynchronous version of this function see gnome_keyring_delete().
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- **/
-gpointer
-gnome_keyring_item_delete (const char *keyring,
- guint32 id,
- GnomeKeyringOperationDoneCallback callback,
- gpointer data,
- GDestroyNotify destroy_data)
-{
- GnomeKeyringOperation *op;
-
- op = create_operation (FALSE, callback, CALLBACK_DONE, data, destroy_data);
-
- if (!gkr_proto_encode_op_string_int (&op->send_buffer, GNOME_KEYRING_OP_DELETE_ITEM,
- keyring, id)) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
- }
-
- op->reply_handler = standard_reply;
- start_operation (op);
- return op;
-}
-
-/**
- * gnome_keyring_item_delete_sync:
- * @keyring: The name of the keyring from which to delete the item, or NULL for the default keyring.
- * @id: The id of the item
- *
- * Delete an item in a keyring.
- *
- * The user may be prompted if the calling application doesn't have necessary
- * access to delete the item.
- *
- * For an asynchronous version of this function see gnome_keyring_item_delete().
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- */
-GnomeKeyringResult
-gnome_keyring_item_delete_sync (const char *keyring,
- guint32 id)
-{
- EggBuffer send, receive;
- GnomeKeyringResult res;
-
- egg_buffer_init_full (&send, 128, NORMAL_ALLOCATOR);
-
- if (!gkr_proto_encode_op_string_int (&send, GNOME_KEYRING_OP_DELETE_ITEM,
- keyring, id)) {
- egg_buffer_uninit (&send);
- return GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
- }
-
- egg_buffer_init_full (&receive, 128, NORMAL_ALLOCATOR);
- res = run_sync_operation (&send, &receive);
- egg_buffer_uninit (&send);
- egg_buffer_uninit (&receive);
-
- return res;
-}
-
-static gboolean
-get_item_info_reply (GnomeKeyringOperation *op)
-{
- GnomeKeyringResult result;
- GnomeKeyringOperationGetItemInfoCallback callback;
- GnomeKeyringItemInfo *info;
-
- callback = op->user_callback;
-
- if (!gkr_proto_decode_get_item_info_reply (&op->receive_buffer, &result, &info)) {
- (*callback) (GNOME_KEYRING_RESULT_IO_ERROR, NULL, op->user_data);
- } else {
- (*callback) (result, info, op->user_data);
- gnome_keyring_item_info_free (info);
- }
-
- /* Operation is done */
- return TRUE;
-}
-
-/**
- * gnome_keyring_item_get_info:
- * @keyring: The name of the keyring in which the item exists, or NULL for the default keyring.
- * @id: The id of the item
- * @callback: A callback which will be called when the request completes or fails.
- * @data: A pointer to arbitrary data that will be passed to the @callback.
- * @destroy_data: A function to free @data when it's no longer needed.
- *
- * Get information about an item and its secret.
- *
- * The user may be prompted if the calling application doesn't have necessary
- * access to read the item with its secret.
- *
- * A #GnomeKeyringItemInfo structure will be passed to the @callback. This structure
- * will be freed after @callback returns.
- *
- * For a synchronous version of this function see gnome_keyring_item_get_info_sync().
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- **/
-gpointer
-gnome_keyring_item_get_info (const char *keyring,
- guint32 id,
- GnomeKeyringOperationGetItemInfoCallback callback,
- gpointer data,
- GDestroyNotify destroy_data)
-{
- GnomeKeyringOperation *op;
-
- /* Use a secure receive buffer */
- op = create_operation (TRUE, callback, CALLBACK_GET_ITEM_INFO, data, destroy_data);
-
- if (!gkr_proto_encode_op_string_int (&op->send_buffer, GNOME_KEYRING_OP_GET_ITEM_INFO,
- keyring, id)) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
- }
-
- op->reply_handler = get_item_info_reply;
- start_operation (op);
- return op;
-}
-
-/**
- * gnome_keyring_item_get_info_sync:
- * @keyring: The name of the keyring in which the item exists, or NULL for the default keyring.
- * @id: The id of the item
- * @info: The location to return a #GnomeKeyringItemInfo pointer.
- *
- * Get information about an item and its secret.
- *
- * The user may be prompted if the calling application doesn't have necessary
- * access to read the item with its secret.
- *
- * A #GnomeKeyringItemInfo structure will be returned in @info. This must be
- * freed using gnome_keyring_item_info_free().
- *
- * For an asynchronous version of this function see gnome_keyring_item_get_info().
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- */
-GnomeKeyringResult
-gnome_keyring_item_get_info_sync (const char *keyring,
- guint32 id,
- GnomeKeyringItemInfo **info)
-{
- EggBuffer send, receive;
- GnomeKeyringResult res;
-
- egg_buffer_init_full (&send, 128, NORMAL_ALLOCATOR);
-
- *info = NULL;
-
- if (!gkr_proto_encode_op_string_int (&send, GNOME_KEYRING_OP_GET_ITEM_INFO,
- keyring, id)) {
- egg_buffer_uninit (&send);
- return GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
- }
-
- /* Use a secure buffer */
- egg_buffer_init_full (&receive, 128, SECURE_ALLOCATOR);
-
- res = run_sync_operation (&send, &receive);
- egg_buffer_uninit (&send);
- if (res != GNOME_KEYRING_RESULT_OK) {
- egg_buffer_uninit (&receive);
- return res;
- }
-
- if (!gkr_proto_decode_get_item_info_reply (&receive, &res, info)) {
- egg_buffer_uninit (&receive);
- return GNOME_KEYRING_RESULT_IO_ERROR;
- }
- egg_buffer_uninit (&receive);
-
- return res;
-}
-
-/**
- * gnome_keyring_item_get_info_full:
- * @keyring: The name of the keyring in which the item exists, or NULL for the default keyring.
- * @id: The id of the item
- * @flags: The parts of the item to retrieve.
- * @callback: A callback which will be called when the request completes or fails.
- * @data: A pointer to arbitrary data that will be passed to the @callback.
- * @destroy_data: A function to free @data when it's no longer needed.
- *
- * Get information about an item, optionally retrieving its secret.
- *
- * If @flags includes %GNOME_KEYRING_ITEM_INFO_SECRET then the user may be
- * prompted if the calling application doesn't have necessary access to read
- * the item with its secret.
- *
- * A #GnomeKeyringItemInfo pointer will be passed to the @callback. Certain fields
- * of this structure may be NULL or zero if they were not specified in @flags. This
- * structure will be freed after @callback returns.
- *
- * For a synchronous version of this function see gnome_keyring_item_get_info_full_sync().
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- **/
-gpointer
-gnome_keyring_item_get_info_full (const char *keyring,
- guint32 id,
- guint32 flags,
- GnomeKeyringOperationGetItemInfoCallback callback,
- gpointer data,
- GDestroyNotify destroy_data)
-{
- GnomeKeyringOperation *op;
-
- /* Use a secure receive buffer */
- op = create_operation (TRUE, callback, CALLBACK_GET_ITEM_INFO, data, destroy_data);
-
- if (!gkr_proto_encode_op_string_int_int (&op->send_buffer,
- GNOME_KEYRING_OP_GET_ITEM_INFO_FULL,
- keyring, id, flags)) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
- }
-
- op->reply_handler = get_item_info_reply;
- start_operation (op);
- return op;
-}
-
-/**
- * gnome_keyring_item_get_info_full_sync:
- * @keyring: The name of the keyring in which the item exists, or NULL for the default keyring.
- * @id: The id of the item
- * @flags: The parts of the item to retrieve.
- * @info: The location to return a #GnomeKeyringItemInfo pointer.
- *
- * Get information about an item, optionally retrieving its secret.
- *
- * If @flags includes %GNOME_KEYRING_ITEM_INFO_SECRET then the user may be
- * prompted if the calling application doesn't have necessary access to read
- * the item with its secret.
- *
- * A #GnomeKeyringItemInfo structure will be returned in @info. Certain fields
- * of this structure may be NULL or zero if they were not specified in @flags.
- * This must be freed using gnome_keyring_item_info_free().
- *
- * For an asynchronous version of this function see gnome_keyring_item_get_info_full().
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- */
-GnomeKeyringResult
-gnome_keyring_item_get_info_full_sync (const char *keyring,
- guint32 id,
- guint32 flags,
- GnomeKeyringItemInfo **info)
-{
- EggBuffer send, receive;
- GnomeKeyringResult res;
-
- egg_buffer_init_full (&send, 128, NORMAL_ALLOCATOR);
-
- *info = NULL;
-
- if (!gkr_proto_encode_op_string_int_int (&send, GNOME_KEYRING_OP_GET_ITEM_INFO_FULL,
- keyring, id, flags)) {
- egg_buffer_uninit (&send);
- return GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
- }
-
- /* Use a secure buffer */
- egg_buffer_init_full (&receive, 128, SECURE_ALLOCATOR);
-
- res = run_sync_operation (&send, &receive);
- egg_buffer_uninit (&send);
- if (res != GNOME_KEYRING_RESULT_OK) {
- egg_buffer_uninit (&receive);
- return res;
- }
-
- if (!gkr_proto_decode_get_item_info_reply (&receive, &res, info)) {
- egg_buffer_uninit (&receive);
- return GNOME_KEYRING_RESULT_IO_ERROR;
- }
- egg_buffer_uninit (&receive);
-
- return res;
-}
-
-/**
- * gnome_keyring_item_set_info:
- * @keyring: The name of the keyring in which the item exists, or NULL for the default keyring.
- * @id: The id of the item
- * @info: The item info to save into the item.
- * @callback: A callback which will be called when the request completes or fails.
- * @data: A pointer to arbitrary data that will be passed to the @callback.
- * @destroy_data: A function to free @data when it's no longer needed.
- *
- * Set information on an item, like its display name, secret etc...
- *
- * Only the fields in the @info pointer that are non-null or non-zero will be
- * set on the item.
- *
- * For a synchronous version of this function see gnome_keyring_item_set_info_sync().
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- **/
-gpointer
-gnome_keyring_item_set_info (const char *keyring,
- guint32 id,
- GnomeKeyringItemInfo *info,
- GnomeKeyringOperationDoneCallback callback,
- gpointer data,
- GDestroyNotify destroy_data)
-{
- GnomeKeyringOperation *op;
-
- op = create_operation (FALSE, callback, CALLBACK_DONE, data, destroy_data);
-
- /* Automatically secures buffer */
- if (!gkr_proto_encode_set_item_info (&op->send_buffer, keyring, id, info)) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
- }
-
- op->reply_handler = standard_reply;
- start_operation (op);
- return op;
-}
-
-/**
- * gnome_keyring_item_set_info_sync:
- * @keyring: The name of the keyring in which the item exists, or NULL for the default keyring.
- * @id: The id of the item
- * @info: The item info to save into the item.
- *
- * Set information on an item, like its display name, secret etc...
- *
- * Only the fields in the @info pointer that are non-null or non-zero will be
- * set on the item.
- *
- * For an asynchronous version of this function see gnome_keyring_item_set_info().
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- */
-GnomeKeyringResult
-gnome_keyring_item_set_info_sync (const char *keyring,
- guint32 id,
- GnomeKeyringItemInfo *info)
-{
- EggBuffer send, receive;
- GnomeKeyringResult res;
-
- /* Use a secure memory buffer */
- egg_buffer_init_full (&send, 128, SECURE_ALLOCATOR);
-
- if (!gkr_proto_encode_set_item_info (&send, keyring, id, info)) {
- egg_buffer_uninit (&send);
- return GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
- }
-
- egg_buffer_init_full (&receive, 128, NORMAL_ALLOCATOR);
- res = run_sync_operation (&send, &receive);
- egg_buffer_uninit (&send);
- egg_buffer_uninit (&receive);
-
- return res;
-}
-
-static gboolean
-get_attributes_reply (GnomeKeyringOperation *op)
-{
- GnomeKeyringResult result;
- GnomeKeyringOperationGetAttributesCallback callback;
- GnomeKeyringAttributeList *attributes;
-
- callback = op->user_callback;
-
- if (!gkr_proto_decode_get_attributes_reply (&op->receive_buffer, &result, &attributes)) {
- (*callback) (GNOME_KEYRING_RESULT_IO_ERROR, NULL, op->user_data);
- } else {
- (*callback) (result, attributes, op->user_data);
- gnome_keyring_attribute_list_free (attributes);
- }
-
- /* Operation is done */
- return TRUE;
-}
-
-static gboolean
-get_acl_reply (GnomeKeyringOperation *op)
-{
- GnomeKeyringResult result;
- GnomeKeyringOperationGetListCallback callback;
- GList *acl;
-
- callback = op->user_callback;
-
- if (!gkr_proto_decode_get_acl_reply (&op->receive_buffer, &result, &acl)) {
- (*callback) (GNOME_KEYRING_RESULT_IO_ERROR, NULL, op->user_data);
- } else {
- (*callback) (result, acl, op->user_data);
- g_list_free (acl);
- }
-
- /* Operation is done */
- return TRUE;
-}
-
-/**
- * gnome_keyring_item_get_attributes:
- * @keyring: The name of the keyring in which the item exists, or NULL for the default keyring.
- * @id: The id of the item
- * @callback: A callback which will be called when the request completes or fails.
- * @data: A pointer to arbitrary data that will be passed to the @callback.
- * @destroy_data: A function to free @data when it's no longer needed.
- *
- * Get all the attributes for an item.
- *
- * A #GnomeKeyringAttributeList will be passed to the @callback. This list will
- * be freed after @callback returns.
- *
- * For a synchronous version of this function see gnome_keyring_item_get_attributes_sync().
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- **/
-gpointer
-gnome_keyring_item_get_attributes (const char *keyring,
- guint32 id,
- GnomeKeyringOperationGetAttributesCallback callback,
- gpointer data,
- GDestroyNotify destroy_data)
-{
- GnomeKeyringOperation *op;
-
- op = create_operation (FALSE, callback, CALLBACK_GET_ATTRIBUTES, data, destroy_data);
-
- if (!gkr_proto_encode_op_string_int (&op->send_buffer, GNOME_KEYRING_OP_GET_ITEM_ATTRIBUTES,
- keyring, id)) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
- }
-
- op->reply_handler = get_attributes_reply;
- start_operation (op);
- return op;
-}
-
-/**
- * gnome_keyring_item_get_attributes_sync:
- * @keyring: The name of the keyring in which the item exists, or NULL for the default keyring.
- * @id: The id of the item
- * @attributes: The location to return a pointer to the attribute list.
- *
- * Get all attributes for an item.
- *
- * A #GnomeKeyringAttributeList will be returned in @attributes. This should be
- * freed using gnome_keyring_attribute_list_free().
- *
- * For an asynchronous version of this function see gnome_keyring_item_get_attributes().
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- */
-GnomeKeyringResult
-gnome_keyring_item_get_attributes_sync (const char *keyring,
- guint32 id,
- GnomeKeyringAttributeList **attributes)
-{
- EggBuffer send, receive;
- GnomeKeyringResult res;
-
- egg_buffer_init_full (&send, 128, NORMAL_ALLOCATOR);
-
- *attributes = NULL;
-
- if (!gkr_proto_encode_op_string_int (&send, GNOME_KEYRING_OP_GET_ITEM_ATTRIBUTES,
- keyring, id)) {
- egg_buffer_uninit (&send);
- return GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
- }
-
- egg_buffer_init_full (&receive, 128, NORMAL_ALLOCATOR);
-
- res = run_sync_operation (&send, &receive);
- egg_buffer_uninit (&send);
- if (res != GNOME_KEYRING_RESULT_OK) {
- egg_buffer_uninit (&receive);
- return res;
- }
-
- if (!gkr_proto_decode_get_attributes_reply (&receive, &res, attributes)) {
- egg_buffer_uninit (&receive);
- return GNOME_KEYRING_RESULT_IO_ERROR;
- }
- egg_buffer_uninit (&receive);
-
- return res;
-}
-
-/**
- * gnome_keyring_item_set_attributes:
- * @keyring: The name of the keyring in which the item exists, or NULL for the default keyring.
- * @id: The id of the item
- * @attributes: The full list of attributes to set on the item.
- * @callback: A callback which will be called when the request completes or fails.
- * @data: A pointer to arbitrary data that will be passed to the @callback.
- * @destroy_data: A function to free @data when it's no longer needed.
- *
- * Set all the attributes for an item. This will replace any previous attributes
- * set on the item.
- *
- * For a synchronous version of this function see gnome_keyring_item_set_attributes_sync().
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- **/
-gpointer
-gnome_keyring_item_set_attributes (const char *keyring,
- guint32 id,
- GnomeKeyringAttributeList *attributes,
- GnomeKeyringOperationDoneCallback callback,
- gpointer data,
- GDestroyNotify destroy_data)
-{
- GnomeKeyringOperation *op;
-
- op = create_operation (FALSE, callback, CALLBACK_DONE, data, destroy_data);
-
- if (!gkr_proto_encode_set_attributes (&op->send_buffer, keyring, id,
- attributes)) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
- }
-
- op->reply_handler = standard_reply;
- start_operation (op);
- return op;
-}
-
-/**
- * gnome_keyring_item_set_attributes_sync:
- * @keyring: The name of the keyring in which the item exists, or NULL for the default keyring.
- * @id: The id of the item
- * @attributes: The full list of attributes to set on the item.
- *
- * Set all the attributes for an item. This will replace any previous attributes
- * set on the item.
- *
- * For an asynchronous version of this function see gnome_keyring_item_set_attributes().
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- */
-GnomeKeyringResult
-gnome_keyring_item_set_attributes_sync (const char *keyring,
- guint32 id,
- GnomeKeyringAttributeList *attributes)
-{
- EggBuffer send, receive;
- GnomeKeyringResult res;
-
- egg_buffer_init_full (&send, 128, NORMAL_ALLOCATOR);
-
- if (!gkr_proto_encode_set_attributes (&send, keyring, id, attributes)) {
- egg_buffer_uninit (&send);
- return GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
- }
-
- egg_buffer_init_full (&receive, 128, NORMAL_ALLOCATOR);
- res = run_sync_operation (&send, &receive);
- egg_buffer_uninit (&send);
- egg_buffer_uninit (&receive);
-
- return res;
-
-}
-
-/**
- * gnome_keyring_item_get_acl:
- * @keyring: The name of the keyring in which the item exists, or NULL for the default keyring.
- * @id: The id of the item
- * @callback: A callback which will be called when the request completes or fails.
- * @data: A pointer to arbitrary data that will be passed to the @callback.
- * @destroy_data: A function to free @data when it's no longer needed.
- *
- * Get the access control list for an item.
- *
- * A %GList of #GnomeKeyringAccessControl pointers will be passed to the @callback.
- * This list and its contents will be freed after @callback returns.
- *
- * For a synchronous version of this function see gnome_keyring_item_get_acl_sync().
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- **/
-gpointer
-gnome_keyring_item_get_acl (const char *keyring,
- guint32 id,
- GnomeKeyringOperationGetListCallback callback,
- gpointer data,
- GDestroyNotify destroy_data)
-{
- GnomeKeyringOperation *op;
-
- op = create_operation (FALSE, callback, CALLBACK_GET_ACL, data, destroy_data);
-
- if (!gkr_proto_encode_op_string_int (&op->send_buffer,
- GNOME_KEYRING_OP_GET_ITEM_ACL,
- keyring, id)) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
- }
-
- op->reply_handler = get_acl_reply;
- start_operation (op);
- return op;
-}
-
-/**
- * gnome_keyring_item_get_acl_sync:
- * @keyring: The name of the keyring in which the item exists, or NULL for the default keyring.
- * @id: The id of the item
- * @acl: The location to return a pointer to the access control list.
- *
- * Get the access control list for an item.
- *
- * A %GList of #GnomeKeyringAccessControl pointers will be passed to the @callback.
- * This list should be freed using gnome_keyring_access_control_list_free().
- *
- * For an asynchronous version of this function see gnome_keyring_item_get_acl().
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- */
-GnomeKeyringResult
-gnome_keyring_item_get_acl_sync (const char *keyring,
- guint32 id,
- GList **acl)
-{
- EggBuffer send, receive;
- GnomeKeyringResult res;
-
- egg_buffer_init_full (&send, 128, NORMAL_ALLOCATOR);
-
- *acl = NULL;
-
- if (!gkr_proto_encode_op_string_int (&send, GNOME_KEYRING_OP_GET_ITEM_ACL,
- keyring, id)) {
- egg_buffer_uninit (&send);
- return GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
- }
-
- egg_buffer_init_full (&receive, 128, NORMAL_ALLOCATOR);
-
- res = run_sync_operation (&send, &receive);
- egg_buffer_uninit (&send);
- if (res != GNOME_KEYRING_RESULT_OK) {
- egg_buffer_uninit (&receive);
- return res;
- }
-
- if (!gkr_proto_decode_get_acl_reply (&receive, &res, acl)) {
- egg_buffer_uninit (&receive);
- return GNOME_KEYRING_RESULT_IO_ERROR;
- }
- egg_buffer_uninit (&receive);
-
- return res;
-}
-
-/**
- * gnome_keyring_item_set_acl:
- * @keyring: The name of the keyring in which the item exists, or NULL for the default keyring.
- * @id: The id of the item
- * @acl: The access control list to set on the item.
- * @callback: A callback which will be called when the request completes or fails.
- * @data: A pointer to arbitrary data that will be passed to the @callback.
- * @destroy_data: A function to free @data when it's no longer needed.
- *
- * Set the full access control list on an item. This replaces any previous ACL
- * setup on the item.
- *
- * For a synchronous version of this function see gnome_keyring_item_set_acl_sync().
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- **/
-gpointer
-gnome_keyring_item_set_acl (const char *keyring,
- guint32 id,
- GList *acl,
- GnomeKeyringOperationDoneCallback callback,
- gpointer data,
- GDestroyNotify destroy_data)
-{
- GnomeKeyringOperation *op;
-
- op = create_operation (FALSE, callback, CALLBACK_DONE, data, destroy_data);
-
- if (!gkr_proto_encode_set_acl (&op->send_buffer, keyring, id, acl)) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
- }
-
- op->reply_handler = standard_reply;
- start_operation (op);
- return op;
-}
-
-/**
- * gnome_keyring_item_set_acl_sync:
- * @keyring: The name of the keyring in which the item exists, or NULL for the default keyring.
- * @id: The id of the item
- * @acl: The access control list to set on the item.
- *
- * Set the full access control list on an item. This replaces any previous
- * ACL setup on the item.
- *
- * For an asynchronous version of this function see gnome_keyring_item_set_acl().
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- */
-GnomeKeyringResult
-gnome_keyring_item_set_acl_sync (const char *keyring,
- guint32 id,
- GList *acl)
-{
- EggBuffer send, receive;
- GnomeKeyringResult res;
-
- egg_buffer_init_full (&send, 128, NORMAL_ALLOCATOR);
-
- if (!gkr_proto_encode_set_acl (&send, keyring, id, acl)) {
- egg_buffer_uninit (&send);
- return GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
- }
-
- egg_buffer_init_full (&receive, 128, NORMAL_ALLOCATOR);
- res = run_sync_operation (&send, &receive);
- egg_buffer_uninit (&send);
- egg_buffer_uninit (&receive);
-
- return res;
-}
-
-typedef struct _GrantAccessRights {
- GnomeKeyringApplicationRef app_ref;
- GnomeKeyringAccessControl acl;
- gchar *keyring_name;
- guint32 id;
-} GrantAccessRights;
-
-static void
-destroy_grant_access_rights (gpointer data)
-{
- GrantAccessRights *gar = (GrantAccessRights*)data;
- g_free (gar->app_ref.display_name);
- g_free (gar->app_ref.pathname);
- g_free (gar->keyring_name);
- g_free (gar);
-}
-
-static gboolean
-item_grant_access_rights_reply (GnomeKeyringOperation *op)
-{
- GrantAccessRights *gar;
- GnomeKeyringResult result;
- GnomeKeyringOperationDoneCallback callback;
- gboolean ret;
- GList *acl;
-
- callback = op->user_callback;
-
- /* Parse the old access rights */
- if (!gkr_proto_decode_get_acl_reply (&op->receive_buffer, &result, &acl)) {
- (*callback) (GNOME_KEYRING_RESULT_IO_ERROR, op->user_data);
- return TRUE;
- }
-
- gar = (GrantAccessRights*)op->reply_data;
- g_assert (gar);
-
- /* Send off the new access rights */
- start_operation (op);
-
- /* Append our ACL to the list */
- egg_buffer_reset (&op->send_buffer);
- acl = g_list_append (acl, &gar->acl);
- ret = gkr_proto_encode_set_acl (&op->send_buffer, gar->keyring_name,
- gar->id, acl);
-
- /* A bit of cleanup */
- acl = g_list_remove (acl, &gar->acl);
- g_list_free (acl);
-
- if (!ret) {
- (*callback) (GNOME_KEYRING_RESULT_BAD_ARGUMENTS, op->user_data);
- return TRUE;
- }
-
- op->reply_handler = standard_reply;
-
- /* Not done yet */
- return FALSE;
-}
-
-/**
- * gnome_keyring_item_grant_access_rights:
- * @keyring: The keyring name, or NULL for the default keyring.
- * @display_name: The display name for the application, as returned by g_get_application_name().
- * @full_path: The full filepath to the application.
- * @id: The id of the item to grant access to.
- * @rights: The type of rights to grant.
- * @callback: Callback which is called when the operation completes
- * @data: Data to be passed to callback
- * @destroy_data: Function to be called when data is no longer needed.
- *
- * Will grant the application access rights to the item, provided
- * callee has write access to said item.
- *
- * This is similar to calling gnome_keyring_item_get_acl() and
- * gnome_keyring_item_set_acl() with appropriate parameters.
- *
- * For a synchronous version of this function see gnome_keyring_item_grant_access_rights().
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- * Since: 2.20
- **/
-gpointer
-gnome_keyring_item_grant_access_rights (const gchar *keyring,
- const gchar *display_name,
- const gchar *full_path,
- const guint32 id,
- const GnomeKeyringAccessType rights,
- GnomeKeyringOperationDoneCallback callback,
- gpointer data,
- GDestroyNotify destroy_data)
-{
- GnomeKeyringOperation *op;
- GrantAccessRights *gar;
-
- /* First get current ACL */
- op = create_operation (FALSE, callback, CALLBACK_DONE, data, destroy_data);
-
- if (!gkr_proto_encode_op_string_int (&op->send_buffer,
- GNOME_KEYRING_OP_GET_ITEM_ACL,
- keyring, id)) {
- schedule_op_failed (op, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
- }
-
- op->reply_handler = item_grant_access_rights_reply;
-
- /* Copy information that the reply callback needs */
- gar = g_new0 (GrantAccessRights, 1);
- gar->app_ref.display_name = g_strdup (display_name);
- gar->app_ref.pathname = g_strdup (full_path);
- gar->acl.application = &gar->app_ref;
- gar->acl.types_allowed = rights;
- gar->keyring_name = g_strdup (keyring);
- gar->id = id;
-
- op->reply_data = gar;
- op->destroy_reply_data = destroy_grant_access_rights;
- start_operation (op);
-
- return op;
-}
-
-/**
- * gnome_keyring_item_grant_access_rights_sync:
- * @keyring: The keyring name, or NULL for the default keyring.
- * @display_name: The display name for the application, as returned by g_get_application_name().
- * @full_path: The full filepath to the application.
- * @id: The id of the item to grant access to.
- * @rights: The type of rights to grant.
- *
- * Will grant the application access rights to the item, provided
- * callee has write access to said item.
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- **/
-GnomeKeyringResult
-gnome_keyring_item_grant_access_rights_sync (const char *keyring,
- const char *display_name,
- const char *full_path,
- const guint32 id,
- const GnomeKeyringAccessType rights)
-{
- GList *acl_list = NULL;
- GnomeKeyringApplicationRef new_app_ref;
- GnomeKeyringAccessControl acl;
- GnomeKeyringResult res;
-
- /* setup application structure */
- new_app_ref.display_name = (char *) display_name;
- new_app_ref.pathname = (char *) full_path;
- acl.application = &new_app_ref;
- acl.types_allowed = rights;
-
- /* get the original acl list */
- res = gnome_keyring_item_get_acl_sync (keyring,
- id,
- &acl_list);
- if (GNOME_KEYRING_RESULT_OK != res)
- goto out;
-
- /* append access rights */
- acl_list = g_list_append (acl_list, (gpointer) &acl);
- res = gnome_keyring_item_set_acl_sync (keyring,
- id,
- acl_list);
-out:
- if (acl_list)
- g_list_free (acl_list);
-
- return res;
-}
-
-/**
- * gnome_keyring_item_info_get_type:
- * @item_info: A keyring item info pointer.
- *
- * Get the item type.
- *
- * Return value: The item type
- **/
-GnomeKeyringItemType
-gnome_keyring_item_info_get_type (GnomeKeyringItemInfo *item_info)
-{
- return item_info->type;
-}
-
-/**
- * gnome_keyring_item_info_set_type:
- * @item_info: A keyring item info pointer.
- * @type: The new item type
- *
- * Set the type on an item info.
- **/
-void
-gnome_keyring_item_info_set_type (GnomeKeyringItemInfo *item_info,
- GnomeKeyringItemType type)
-{
- item_info->type = type;
-}
-
-/**
- * gnome_keyring_item_info_get_secret:
- * @item_info: A keyring item info pointer.
- *
- * Get the item secret.
- *
- * Return value: The newly allocated string containing the item secret.
- **/
-char *
-gnome_keyring_item_info_get_secret (GnomeKeyringItemInfo *item_info)
-{
- /* XXXX For compatibility reasons we can't use secure memory here */
- return g_strdup (item_info->secret);
-}
-
-/**
- * gnome_keyring_item_info_set_secret:
- * @item_info: A keyring item info pointer.
- * @value: The new item secret
- *
- * Set the secret on an item info.
- **/
-void
-gnome_keyring_item_info_set_secret (GnomeKeyringItemInfo *item_info,
- const char *value)
-{
- gnome_keyring_free_password (item_info->secret);
- item_info->secret = gnome_keyring_memory_strdup (value);
-}
-
-/**
- * gnome_keyring_item_info_get_display_name:
- * @item_info: A keyring item info pointer.
- *
- * Get the item display name.
- *
- * Return value: The newly allocated string containing the item display name.
- **/
-char *
-gnome_keyring_item_info_get_display_name (GnomeKeyringItemInfo *item_info)
-{
- return g_strdup (item_info->display_name);
-}
-
-/**
- * gnome_keyring_item_info_set_display_name:
- * @item_info: A keyring item info pointer.
- * @value: The new display name.
- *
- * Set the display name on an item info.
- **/
-void
-gnome_keyring_item_info_set_display_name (GnomeKeyringItemInfo *item_info,
- const char *value)
-{
- g_free (item_info->display_name);
- item_info->display_name = g_strdup (value);
-}
-
-/**
- * gnome_keyring_item_info_get_mtime:
- * @item_info: A keyring item info pointer.
- *
- * Get the item last modified time.
- *
- * Return value: The item last modified time.
- **/
-time_t
-gnome_keyring_item_info_get_mtime (GnomeKeyringItemInfo *item_info)
-{
- return item_info->mtime;
-}
-
-/**
- * gnome_keyring_item_info_get_ctime:
- * @item_info: A keyring item info pointer.
- *
- * Get the item created time.
- *
- * Return value: The item created time.
- **/
-time_t
-gnome_keyring_item_info_get_ctime (GnomeKeyringItemInfo *item_info)
-{
- return item_info->ctime;
-}
-
-/**
- * SECTION:gnome-keyring-acl
- * @title: Item ACLs
- * @short_description: Access control lists for keyring items.
- *
- * Each item has an access control list, which specifies the applications that
- * can read, write or delete an item. The read access applies only to reading the secret.
- * All applications can read other parts of the item. ACLs are accessed and changed
- * gnome_keyring_item_get_acl() and gnome_keyring_item_set_acl().
- */
-
-/**
- * gnome_keyring_item_ac_get_display_name:
- * @ac: A #GnomeKeyringAccessControl pointer.
- *
- * Get the access control application's display name.
- *
- * Return value: A newly allocated string containing the display name.
- */
-char *
-gnome_keyring_item_ac_get_display_name (GnomeKeyringAccessControl *ac)
-{
- return g_strdup (ac->application->display_name);
-}
-
-/**
- * gnome_keyring_item_ac_set_display_name:
- * @ac: A #GnomeKeyringAcccessControl pointer.
- * @value: The new application display name.
- *
- * Set the access control application's display name.
- **/
-void
-gnome_keyring_item_ac_set_display_name (GnomeKeyringAccessControl *ac,
- const char *value)
-{
- g_free (ac->application->display_name);
- ac->application->display_name = g_strdup (value);
-}
-
-/**
- * gnome_keyring_item_ac_get_path_name:
- * @ac: A #GnomeKeyringAccessControl pointer.
- *
- * Get the access control application's full path name.
- *
- * Return value: A newly allocated string containing the display name.
- **/
-char *
-gnome_keyring_item_ac_get_path_name (GnomeKeyringAccessControl *ac)
-{
- return g_strdup (ac->application->pathname);
-}
-
-/**
- * gnome_keyring_item_ac_set_path_name:
- * @ac: A #GnomeKeyringAccessControl pointer
- * @value: The new application full path.
- *
- * Set the access control application's full path name.
- **/
-void
-gnome_keyring_item_ac_set_path_name (GnomeKeyringAccessControl *ac,
- const char *value)
-{
- g_free (ac->application->pathname);
- ac->application->pathname = g_strdup (value);
-}
-
-/**
- * gnome_keyring_item_ac_get_access_type:
- * @ac: A #GnomeKeyringAccessControl pointer.
- *
- * Get the application access rights for the access control.
- *
- * Return value: The access rights.
- */
-GnomeKeyringAccessType
-gnome_keyring_item_ac_get_access_type (GnomeKeyringAccessControl *ac)
-{
- return ac->types_allowed;
-}
-
-/**
- * gnome_keyring_item_ac_set_access_type:
- * @ac: A #GnomeKeyringAccessControl pointer.
- * @value: The new access rights.
- *
- * Set the application access rights for the access control.
- **/
-void
-gnome_keyring_item_ac_set_access_type (GnomeKeyringAccessControl *ac,
- const GnomeKeyringAccessType value)
-{
- ac->types_allowed = value;
-}
-
-/* ------------------------------------------------------------------------------
- * NETWORK PASSWORD APIS
- */
-
-/**
- * SECTION:gnome-keyring-network
- * @title: Network Passwords
- * @short_description: Saving of network passwords.
- *
- * Networks passwords are a simple way of saving passwords associated with a
- * certain user/server/protocol and other fields.
- */
-
-struct FindNetworkPasswordInfo {
- GnomeKeyringOperationGetListCallback callback;
- gpointer data;
- GDestroyNotify destroy_data;
-};
-
-static void
-free_find_network_password_info (struct FindNetworkPasswordInfo *info)
-{
- if (info->destroy_data != NULL) {
- info->destroy_data (info->data);
- }
- g_free (info);
-}
-
-static GList *
-found_list_to_nework_password_list (GList *found_list)
-{
- GnomeKeyringNetworkPasswordData *data;
- GnomeKeyringFound *found;
- GnomeKeyringAttribute *attributes;
- GList *result, *l;
- int i;
-
- result = NULL;
- for (l = found_list; l != NULL; l = l->next) {
- found = l->data;
-
- data = g_new0 (GnomeKeyringNetworkPasswordData, 1);
-
- result = g_list_prepend (result, data);
-
- data->keyring = g_strdup (found->keyring);
- data->item_id = found->item_id;
- data->password = gnome_keyring_memory_strdup (found->secret);
-
- attributes = (GnomeKeyringAttribute *) found->attributes->data;
- for (i = 0; i < found->attributes->len; i++) {
- if (strcmp (attributes[i].name, "user") == 0 &&
- attributes[i].type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING) {
- data->user = g_strdup (attributes[i].value.string);
- } else if (strcmp (attributes[i].name, "domain") == 0 &&
- attributes[i].type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING) {
- data->domain = g_strdup (attributes[i].value.string);
- } else if (strcmp (attributes[i].name, "server") == 0 &&
- attributes[i].type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING) {
- data->server = g_strdup (attributes[i].value.string);
- } else if (strcmp (attributes[i].name, "object") == 0 &&
- attributes[i].type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING) {
- data->object = g_strdup (attributes[i].value.string);
- } else if (strcmp (attributes[i].name, "protocol") == 0 &&
- attributes[i].type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING) {
- data->protocol = g_strdup (attributes[i].value.string);
- } else if (strcmp (attributes[i].name, "authtype") == 0 &&
- attributes[i].type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING) {
- data->authtype = g_strdup (attributes[i].value.string);
- } else if (strcmp (attributes[i].name, "port") == 0 &&
- attributes[i].type == GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32) {
- data->port = attributes[i].value.integer;
- }
- }
- }
-
- return g_list_reverse (result);
-}
-
-/**
- * gnome_keyring_network_password_free:
- * @data: A #GnomeKeyringNetworkPasswordData pointer.
- *
- * Free a network password data pointer. If %NULL is passed in,
- * nothing happens.
- */
-void
-gnome_keyring_network_password_free (GnomeKeyringNetworkPasswordData *data)
-{
- if (!data)
- return;
-
- g_free (data->keyring);
- g_free (data->protocol);
- g_free (data->server);
- g_free (data->object);
- g_free (data->authtype);
- g_free (data->user);
- g_free (data->domain);
- gnome_keyring_free_password (data->password);
-
- g_free (data);
-}
-
-/**
- * gnome_keyring_network_password_list_free:
- * @list: A list of #GnomeKeyringNetworkPasswordData pointers.
- *
- * Free a list of network password data.
- */
-void
-gnome_keyring_network_password_list_free (GList *list)
-{
- g_list_foreach (list, (GFunc)gnome_keyring_network_password_free, NULL);
- g_list_free (list);
-}
-
-static void
-find_network_password_callback (GnomeKeyringResult result,
- GList *list,
- gpointer data)
-{
- struct FindNetworkPasswordInfo *info;
- GList *data_list;
-
- info = data;
-
- data_list = NULL;
- if (result == GNOME_KEYRING_RESULT_OK) {
- data_list = found_list_to_nework_password_list (list);
- }
- info->callback (result, data_list, info->data);
- gnome_keyring_network_password_list_free (data_list);
- return;
-}
-
-static GnomeKeyringAttributeList *
-make_attribute_list_for_network_password (const char *user,
- const char *domain,
- const char *server,
- const char *object,
- const char *protocol,
- const char *authtype,
- guint32 port)
-{
- GnomeKeyringAttributeList *attributes;
-
- attributes = g_array_new (FALSE, FALSE, sizeof (GnomeKeyringAttribute));
-
- if (user != NULL) {
- gnome_keyring_attribute_list_append_string (attributes, "user", user);
- }
- if (domain != NULL) {
- gnome_keyring_attribute_list_append_string (attributes, "domain", domain);
- }
- if (server != NULL) {
- gnome_keyring_attribute_list_append_string (attributes, "server", server);
- }
- if (object != NULL) {
- gnome_keyring_attribute_list_append_string (attributes, "object", object);
- }
- if (protocol != NULL) {
- gnome_keyring_attribute_list_append_string (attributes, "protocol", protocol);
- }
- if (authtype != NULL) {
- gnome_keyring_attribute_list_append_string (attributes, "authtype", authtype);
- }
- if (port != 0) {
- gnome_keyring_attribute_list_append_uint32 (attributes, "port", port);
- }
- return attributes;
-}
-
-/**
- * gnome_keyring_find_network_password:
- * @user: The user name or %NULL for any user.
- * @domain: The domain name %NULL for any domain.
- * @server: The server or %NULL for any server.
- * @object: The remote object or %NULL for any object.
- * @protocol: The network protorol or %NULL for any protocol.
- * @authtype: The authentication type or %NULL for any type.
- * @port: The network port or zero for any port.
- * @callback: Callback which is called when the operation completes
- * @data: Data to be passed to callback
- * @destroy_data: Function to be called when data is no longer needed.
- *
- * Find a previously stored network password. Searches all keyrings.
- *
- * A %GList of #GnomeKeyringNetworkPasswordData structures are passed to the
- * @callback. The list and structures are freed after the callback returns.
- *
- * The user may have been prompted to unlock necessary keyrings, and user will
- * have been prompted for access to the items if needed.
- *
- * Network passwords are items with the item type %GNOME_KEYRING_ITEM_NETWORK_PASSWORD
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- */
-gpointer
-gnome_keyring_find_network_password (const char *user,
- const char *domain,
- const char *server,
- const char *object,
- const char *protocol,
- const char *authtype,
- guint32 port,
- GnomeKeyringOperationGetListCallback callback,
- gpointer user_data,
- GDestroyNotify destroy_data)
-{
- GnomeKeyringAttributeList *attributes;
- gpointer request;
- struct FindNetworkPasswordInfo *info;
-
- info = g_new0 (struct FindNetworkPasswordInfo, 1);
- info->callback = callback;
- info->data = user_data;
- info->destroy_data = destroy_data;
-
- attributes = make_attribute_list_for_network_password (user,
- domain,
- server,
- object,
- protocol,
- authtype,
- port);
-
- request = gnome_keyring_find_items (GNOME_KEYRING_ITEM_NETWORK_PASSWORD,
- attributes,
- find_network_password_callback,
- info,
- (GDestroyNotify)free_find_network_password_info);
-
- gnome_keyring_attribute_list_free (attributes);
- return request;
-}
-
-/**
- * gnome_keyring_find_network_password_sync:
- * @user: The user name or %NULL.
- * @domain: The domain name %NULL.
- * @server: The server or %NULL.
- * @object: The remote object or %NULL.
- * @protocol: The network protorol or %NULL.
- * @authtype: The authentication type or %NULL.
- * @port: The network port or zero.
- * @results: A location to return a %GList of #GnomeKeyringNetworkPasswordData pointers.
- *
- * Find a previously stored network password. Searches all keyrings.
- *
- * A %GList of #GnomeKeyringNetworkPasswordData structures are returned in the
- * @out_list argument. The list should be freed with gnome_keyring_network_password_list_free()
- *
- * The user may have been prompted to unlock necessary keyrings, and user will
- * have been prompted for access to the items if needed.
- *
- * Network passwords are items with the item type %GNOME_KEYRING_ITEM_NETWORK_PASSWORD
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- */
-GnomeKeyringResult
-gnome_keyring_find_network_password_sync (const char *user,
- const char *domain,
- const char *server,
- const char *object,
- const char *protocol,
- const char *authtype,
- guint32 port,
- GList **results)
-{
- GnomeKeyringAttributeList *attributes;
- GnomeKeyringResult result;
- GList *found;
-
- *results = NULL;
- attributes = make_attribute_list_for_network_password (user,
- domain,
- server,
- object,
- protocol,
- authtype,
- port);
-
- result = gnome_keyring_find_items_sync (GNOME_KEYRING_ITEM_NETWORK_PASSWORD,
- attributes,
- &found);
-
- gnome_keyring_attribute_list_free (attributes);
-
- if (result == GNOME_KEYRING_RESULT_OK) {
- *results = found_list_to_nework_password_list (found);
- gnome_keyring_found_list_free (found);
- }
-
- return result;
-}
-
-static char *
-get_network_password_display_name (const char *user,
- const char *server,
- const char *object,
- guint32 port)
-{
- GString *s;
- char *name;
-
- if (server != NULL) {
- s = g_string_new (NULL);
- if (user != NULL) {
- g_string_append_printf (s, "%s@", user);
- }
- g_string_append (s, server);
- if (port != 0) {
- g_string_append_printf (s, ":%d", port);
- }
- if (object != NULL) {
- g_string_append_printf (s, "/%s", object);
- }
- name = g_string_free (s, FALSE);
- } else {
- name = g_strdup ("network password");
- }
- return name;
-}
-
-
-/**
- * gnome_keyring_set_network_password:
- * @keyring: The keyring to store the password in, or %NULL for the default keyring.
- * @user: The user name or %NULL.
- * @domain: The domain name %NULL.
- * @server: The server or %NULL.
- * @object: The remote object or %NULL.
- * @protocol: The network protorol or %NULL.
- * @authtype: The authentication type or %NULL.
- * @port: The network port or zero.
- * @password: The password to store, must not be %NULL.
- * @callback: Callback which is called when the operation completes
- * @data: Data to be passed to callback
- * @destroy_data: Function to be called when data is no longer needed.
- *
- * Store a network password.
- *
- * If an item already exists for with this network info (ie: user, server etc...)
- * then it will be updated.
- *
- * Whether a new item is created or not, id of the item will be passed to
- * the @callback.
- *
- * Network passwords are items with the item type %GNOME_KEYRING_ITEM_NETWORK_PASSWORD
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- */
-gpointer
-gnome_keyring_set_network_password (const char *keyring,
- const char *user,
- const char *domain,
- const char *server,
- const char *object,
- const char *protocol,
- const char *authtype,
- guint32 port,
- const char *password,
- GnomeKeyringOperationGetIntCallback callback,
- gpointer data,
- GDestroyNotify destroy_data)
-{
- GnomeKeyringAttributeList *attributes;
- gpointer req;
- char *name;
-
- name = get_network_password_display_name (user, server, object, port);
-
- attributes = make_attribute_list_for_network_password (user,
- domain,
- server,
- object,
- protocol,
- authtype,
- port);
-
- req = gnome_keyring_item_create (keyring,
- GNOME_KEYRING_ITEM_NETWORK_PASSWORD,
- name,
- attributes,
- password,
- TRUE,
- callback, data, destroy_data);
-
- gnome_keyring_attribute_list_free (attributes);
- g_free (name);
-
- return req;
-}
-
-/**
- * gnome_keyring_set_network_password_sync:
- * @keyring: The keyring to store the password in, or %NULL for the default keyring.
- * @user: The user name or %NULL.
- * @domain: The domain name %NULL.
- * @server: The server or %NULL.
- * @object: The remote object or %NULL.
- * @protocol: The network protorol or %NULL.
- * @authtype: The authentication type or %NULL.
- * @port: The network port or zero.
- * @password: The password to store, must not be %NULL.
- * @item_id: A location to store the resulting item's id.
- *
- * Store a network password.
- *
- * If an item already exists for with this network info (ie: user, server etc...)
- * then it will be updated.
- *
- * The created or updated item id will be returned in @item_id.
- *
- * Network passwords are items with the item type %GNOME_KEYRING_ITEM_NETWORK_PASSWORD
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- */
-GnomeKeyringResult
-gnome_keyring_set_network_password_sync (const char *keyring,
- const char *user,
- const char *domain,
- const char *server,
- const char *object,
- const char *protocol,
- const char *authtype,
- guint32 port,
- const char *password,
- guint32 *item_id)
-{
- GnomeKeyringAttributeList *attributes;
- char *name;
- GnomeKeyringResult res;
-
- name = get_network_password_display_name (user, server, object, port);
- attributes = make_attribute_list_for_network_password (user,
- domain,
- server,
- object,
- protocol,
- authtype,
- port);
-
- res = gnome_keyring_item_create_sync (keyring,
- GNOME_KEYRING_ITEM_NETWORK_PASSWORD,
- name,
- attributes,
- password,
- TRUE,
- item_id);
-
- gnome_keyring_attribute_list_free (attributes);
- g_free (name);
-
- return res;
-}
-
-/* ------------------------------------------------------------------------------
- * SIMPLE PASSWORD APIS
- */
-
-/**
- * SECTION:gnome-keyring-password
- * @title: Simple Password Storage
- * @short_description: Store and lookup passwords with a set of attributes.
- *
- * This is a simple API for storing passwords and retrieving passwords in the keyring.
- *
- * Each password is associated with a set of attributes. Attribute values can be either
- * strings or unsigned integers.
- *
- * The names and types of allowed attributes for a given password are defined with a
- * schema. Certain schemas are predefined such as %GNOME_KEYRING_NETWORK_PASSWORD.
- * Additional schemas can be defined via the %GnomeKeyringPasswordSchema structure.
- *
- * Each function accepts a variable list of attributes names and their values.
- * Include a %NULL to terminate the list of attributes.
- *
- * <example>
- * <title>Passing attributes to the functions</title>
- * <programlisting>
- * res = gnome_keyring_delete_password_sync (GNOME_KEYRING_NETWORK_PASSWORD,
- * "user", "me", // A string attribute
- * "server, "example.gnome.org",
- * "port", "8080", // An integer attribute
- * NULL);
- * </programlisting></example>
- */
-
-/**
- * GnomeKeyringPasswordSchema:
- *
- * Describes a password schema. Often you'll want to use a predefined schema such
- * as %GNOME_KEYRING_NETWORK_PASSWORD.
- *
- * <para>
- * The last attribute name in a schema must be %NULL.
- *
- * <programlisting>
- * GnomeKeyringPasswordSchema my_schema = {
- * GNOME_KEYRING_ITEM_GENERIC_SECRET,
- * {
- * { "string-attr", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
- * { "uint-attr", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32 },
- * { NULL, 0 }
- * }
- * };
- * </programlisting>
- * </para>
- */
-
-static const GnomeKeyringPasswordSchema network_password_schema = {
- GNOME_KEYRING_ITEM_NETWORK_PASSWORD,
- {
- { "user", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
- { "domain", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
- { "object", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
- { "protocol", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
- { "port", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32 },
- { "server", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
- { "NULL", 0 },
- }
-};
-
-/**
- * GNOME_KEYRING_NETWORK_PASSWORD:
- *
- * <para>
- * A predefined schema for network paswsords. It contains the following attributes:
- * </para>
- * <itemizedlist>
- * <listitem>user: A string for the user login.</listitem>
- * <listitem>server: The server being connected to.</listitem>
- * <listitem>protocol: The protocol used to access the server, such as 'http' or 'smb'</listitem>
- * <listitem>domain: A realm or domain, such as a Windows login domain.</listitem>
- * <listitem>port: The network port to used to connect to the server.</listitem>
- * </itemizedlist>
- */
-
-/* Declared in gnome-keyring.h */
-const GnomeKeyringPasswordSchema *GNOME_KEYRING_NETWORK_PASSWORD = &network_password_schema;
-
-/**
- * GNOME_KEYRING_DEFAULT:
- *
- * <para>
- * The default keyring.
- * </para>
- */
-
-/**
- * GNOME_KEYRING_SESSION:
- *
- * <para>
- * A keyring only stored in memory.
- * </para>
- */
-
-static GnomeKeyringAttributeList*
-schema_attribute_list_va (const GnomeKeyringPasswordSchema *schema, va_list args)
-{
- GnomeKeyringAttributeList *attributes;
- GnomeKeyringAttributeType type;
- GnomeKeyringAttribute attribute;
- gboolean type_found;
- char *str;
- guint32 i, val;
-
- attributes = g_array_new (FALSE, FALSE, sizeof (GnomeKeyringAttribute));
-
- while ((attribute.name = va_arg (args, char *)) != NULL) {
-
- type_found = FALSE;
- for (i = 0; i < G_N_ELEMENTS (schema->attributes); ++i) {
- if (!schema->attributes[i].name)
- break;
- if (strcmp (schema->attributes[i].name, attribute.name) == 0) {
- type_found = TRUE;
- type = schema->attributes[i].type;
- break;
- }
- }
-
- if (!type_found) {
- g_warning ("The password attribute '%s' was not found in the password schema.", attribute.name);
- g_array_free (attributes, TRUE);
- return NULL;
- }
-
- attribute.type = type;
- switch (type) {
- case GNOME_KEYRING_ATTRIBUTE_TYPE_STRING:
- str = va_arg (args, char *);
- attribute.value.string = str;
- g_array_append_val (attributes, attribute);
- break;
- case GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32:
- val = va_arg (args, guint32);
- attribute.value.integer = val;
- g_array_append_val (attributes, attribute);
- break;
- default:
- g_warning ("The password attribute '%s' has an invalid type in the password schema.", attribute.name);
- g_array_free (attributes, TRUE);
- return NULL;
- }
- }
-
- return attributes;
-}
-
-/**
- * gnome_keyring_store_password:
- * @schema: The password schema.
- * @keyring: The keyring to store the password in. Specify %NULL for the default keyring.
- * Use %GNOME_KEYRING_SESSION to store the password in memory only.
- * @display_name: A human readable description of what the password is for.
- * @password: The password to store.
- * @callback: A callback which will be called when the request completes or fails.
- * @data: A pointer to arbitrary data that will be passed to the @callback.
- * @destroy_data: A function to free @data when it's no longer needed.
- * @...: The variable argument list should contain pairs of a) The attribute name as a null
- * terminated string, followed by b) attribute value, either a character string,
- * or 32-bit unsigned int, as defined in the password @schema. The list of attribtues
- * should be terminated with a %NULL.
- *
- * Store a password associated with a given set of attributes.
- *
- * Attributes which identify this password must be passed as additional
- * arguments. Attributes passed must be defined in the schema.
- *
- * If a password exists in the keyring that already has all the same arguments,
- * then the password will be updated.
- *
- * Another more complex way to create a keyring item is using gnome_keyring_item_create().
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- * Since: 2.22
- */
-gpointer
-gnome_keyring_store_password (const GnomeKeyringPasswordSchema* schema, const gchar *keyring,
- const gchar *display_name, const gchar *password,
- GnomeKeyringOperationDoneCallback callback,
- gpointer data, GDestroyNotify destroy_data, ...)
-{
- GnomeKeyringAttributeList *attributes;
- GnomeKeyringOperation *op;
- va_list args;
-
- va_start (args, destroy_data);
- attributes = schema_attribute_list_va (schema, args);
- va_end (args);
-
- op = create_operation (FALSE, callback, CALLBACK_DONE, data, destroy_data);
-
- /* Automatically secures buffer */
- if (!attributes || !attributes->len ||
- !gkr_proto_encode_create_item (&op->send_buffer, keyring, display_name,
- attributes, password, schema->item_type, TRUE))
- schedule_op_failed (op, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
-
- op->reply_handler = standard_reply;
- g_array_free (attributes, TRUE);
- start_operation (op);
- return op;
-}
-
-/**
- * gnome_keyring_store_password_sync:
- * @schema: The password schema.
- * @keyring: The keyring to store the password in. Specify %NULL for the default keyring.
- * Use %GNOME_KEYRING_SESSION to store the password in memory only.
- * @display_name: A human readable description of what the password is for.
- * @password: The password to store.
- * @...: The variable argument list should contain pairs of a) The attribute name as a null
- * terminated string, followed by b) attribute value, either a character string,
- * or 32-bit unsigned int, as defined in the password @schema. The list of attribtues
- * should be terminated with a %NULL.
- *
- * Store a password associated with a given set of attributes.
- *
- * Attributes which identify this password must be passed as additional
- * arguments. Attributes passed must be defined in the schema.
- *
- * This function may block for an unspecified period. If your application must
- * remain responsive to the user, then use gnome_keyring_store_password().
- *
- * If a password exists in the keyring that already has all the same arguments,
- * then the password will be updated.
- *
- * Another more complex way to create a keyring item is using
- * gnome_keyring_item_create_sync().
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- * Since: 2.22
- */
-GnomeKeyringResult
-gnome_keyring_store_password_sync (const GnomeKeyringPasswordSchema* schema, const gchar *keyring,
- const gchar *display_name, const gchar *password, ...)
-{
- GnomeKeyringAttributeList *attributes;
- GnomeKeyringResult res;
- guint32 item_id;
- va_list args;
-
- va_start (args, password);
- attributes = schema_attribute_list_va (schema, args);
- va_end (args);
-
- if (!attributes || !attributes->len)
- return GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
-
- res = gnome_keyring_item_create_sync (keyring, schema->item_type, display_name,
- attributes, password, TRUE, &item_id);
-
- g_array_free (attributes, TRUE);
- return res;
-}
-
-static gboolean
-find_password_reply (GnomeKeyringOperation *op)
-{
- GnomeKeyringResult result;
- GnomeKeyringOperationGetStringCallback callback;
- GList *found_items;
- const gchar *password;
-
- g_assert (op->user_callback_type == CALLBACK_GET_STRING);
- callback = op->user_callback;
-
- if (!gkr_proto_decode_find_reply (&op->receive_buffer, &result, &found_items)) {
- (*callback) (GNOME_KEYRING_RESULT_IO_ERROR, NULL, op->user_data);
- } else {
- password = NULL;
- if (found_items)
- password = ((GnomeKeyringFound*)(found_items->data))->secret;
- (*callback) (result, password, op->user_data);
- gnome_keyring_found_list_free (found_items);
- }
-
- /* Operation is done */
- return TRUE;
-}
-
-/**
- * gnome_keyring_find_password:
- * @schema: The password schema.
- * @callback: A callback which will be called when the request completes or fails.
- * @data: A pointer to arbitrary data that will be passed to the @callback.
- * @destroy_data: A function to free @data when it's no longer needed.
- * @...: The variable argument list should contain pairs of a) The attribute name as a null
- * terminated string, followed by b) attribute value, either a character string,
- * or 32-bit unsigned int, as defined in the password @schema. The list of attribtues
- * should be terminated with a %NULL.
- *
- * Find a password that matches a given set of attributes.
- *
- * Attributes which identify this password must be passed as additional
- * arguments. Attributes passed must be defined in the schema.
- *
- * The string that is passed to @callback is automatically freed when the
- * function returns.
- *
- * Another more complex way to find items in the keyrings is using
- * gnome_keyring_find_items().
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- * Since: 2.22
- */
-gpointer
-gnome_keyring_find_password (const GnomeKeyringPasswordSchema* schema,
- GnomeKeyringOperationGetStringCallback callback,
- gpointer data, GDestroyNotify destroy_data, ...)
-{
- GnomeKeyringOperation *op;
- GnomeKeyringAttributeList *attributes;
- va_list args;
-
- op = create_operation (TRUE, callback, CALLBACK_GET_STRING, data, destroy_data);
-
- va_start (args, destroy_data);
- attributes = schema_attribute_list_va (schema, args);
- va_end (args);
-
- if (!attributes || !attributes->len ||
- !gkr_proto_encode_find (&op->send_buffer, schema->item_type, attributes))
- schedule_op_failed (op, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
-
- g_array_free (attributes, TRUE);
-
- op->reply_handler = find_password_reply;
- start_operation (op);
- return op;
-
-}
-
-/**
- * gnome_keyring_find_password_sync:
- * @schema: The password schema.
- * @password: An address to store password that was found. The password must
- * be freed with gnome_keyring_free_password().
- * @...: The variable argument list should contain pairs of a) The attribute name as a null
- * terminated string, followed by b) attribute value, either a character string,
- * or 32-bit unsigned int, as defined in the password @schema. The list of attribtues
- * should be terminated with a %NULL.
- *
- * Find a password that matches a given set of attributes.
- *
- * Attributes which identify this password must be passed as additional
- * arguments. Attributes passed must be defined in the schema.
- *
- * This function may block for an unspecified period. If your application must
- * remain responsive to the user, then use gnome_keyring_find_password().
- *
- * Another more complex way to find items in the keyrings is using
- * gnome_keyring_find_items_sync().
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- * Since: 2.22
- */
-GnomeKeyringResult
-gnome_keyring_find_password_sync(const GnomeKeyringPasswordSchema* schema, gchar **password, ...)
-{
- GnomeKeyringAttributeList *attributes;
- GnomeKeyringResult res;
- GnomeKeyringFound *f;
- GList* found = NULL;
- va_list args;
-
- va_start (args, password);
- attributes = schema_attribute_list_va (schema, args);
- va_end (args);
-
- if (!attributes || !attributes->len)
- res = GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
- else
- res = gnome_keyring_find_items_sync (schema->item_type, attributes, &found);
-
- g_array_free (attributes, TRUE);
-
- if (password && res == GNOME_KEYRING_RESULT_OK) {
- *password = NULL;
- if (g_list_length (found) > 0) {
- f = (GnomeKeyringFound*)(found->data);
- *password = f->secret;
- f->secret = NULL;
- }
- }
-
- gnome_keyring_found_list_free (found);
- return res;
-}
-
-typedef struct _DeletePassword {
- GList *found;
- GList *at;
- guint non_session;
- guint deleted;
-} DeletePassword;
-
-static void
-delete_password_destroy (gpointer data)
-{
- DeletePassword *dp = (DeletePassword*)data;
- gnome_keyring_found_list_free (dp->found);
- g_free (dp);
-}
-
-static gboolean
-delete_password_reply (GnomeKeyringOperation *op)
-{
- GnomeKeyringResult result;
- GnomeKeyringOperationDoneCallback callback;
- GnomeKeyringFound *f;
- DeletePassword *dp;
-
- g_assert (op->user_callback_type == CALLBACK_DONE);
- callback = op->user_callback;
-
- dp = op->reply_data;
- g_assert (dp);
-
- /* The result of the find */
- if (!dp->found) {
- if (!gkr_proto_decode_find_reply (&op->receive_buffer, &result, &dp->found))
- result = GNOME_KEYRING_RESULT_IO_ERROR;
-
- /* On the first item */
- dp->at = dp->found;
-
- /* The result of a delete */
- } else {
- if (!gkr_proto_decode_find_reply (&op->receive_buffer, &result, &dp->found))
- result = GNOME_KEYRING_RESULT_IO_ERROR;
-
- ++dp->deleted;
- }
-
- /* Stop on any failure */
- if (result != GNOME_KEYRING_RESULT_OK) {
- (*callback) (result, op->user_data);
- return TRUE; /* Operation is done */
- }
-
- /* Iterate over list and find next item to delete */
- while (dp->at) {
- f = (GnomeKeyringFound*)(dp->at->data);
- dp->at = g_list_next (dp->at);
-
- /* If not an item in the session keyring ... */
- if (!f->keyring || strcmp (f->keyring, GNOME_KEYRING_SESSION) != 0) {
-
- ++dp->non_session;
-
- /* ... then we only delete one of those */
- if (dp->non_session > 1)
- continue;
- }
-
- /* Reset the operation into a delete */
- start_operation (op);
-
- egg_buffer_reset (&op->send_buffer);
- if (!gkr_proto_encode_op_string_int (&op->send_buffer, GNOME_KEYRING_OP_DELETE_ITEM,
- f->keyring, f->item_id)) {
- /*
- * This would happen if the server somehow sent us an invalid
- * keyring and item_id. Very unlikely, and it seems this is
- * the best error code in this case.
- */
- (*callback) (GNOME_KEYRING_RESULT_IO_ERROR, op->user_data);
- return TRUE;
- }
-
- /*
- * The delete operation is ready for processing, by returning
- * FALSE we indicate that the operation is not complete.
- */
- return FALSE;
- }
-
- /* Nothing more to find */
- g_assert (!dp->at);
-
- /* Operation is done */
- (*callback) (dp->deleted > 0 ? GNOME_KEYRING_RESULT_OK : GNOME_KEYRING_RESULT_NO_MATCH, op->user_data);
- return TRUE;
-}
-
-/**
- * gnome_keyring_delete_password:
- * @schema: The password schema.
- * @callback: A callback which will be called when the request completes or fails.
- * @data: A pointer to arbitrary data that will be passed to the @callback.
- * @destroy_data: A function to free @data when it's no longer needed.
- * @...: The variable argument list should contain pairs of a) The attribute name as a null
- * terminated string, followed by b) attribute value, either a character string,
- * or 32-bit unsigned int, as defined in the password @schema. The list of attribtues
- * should be terminated with a %NULL.
- *
- * Delete a password that matches a given set of attributes.
- *
- * Attributes which identify this password must be passed as additional
- * arguments. Attributes passed must be defined in the schema.
- *
- * Another more complex way to find items in the keyrings is using
- * gnome_keyring_item_delete().
- *
- * Return value: The asychronous request, which can be passed to gnome_keyring_cancel_request().
- * Since: 2.22
- */
-gpointer
-gnome_keyring_delete_password (const GnomeKeyringPasswordSchema* schema,
- GnomeKeyringOperationDoneCallback callback,
- gpointer data, GDestroyNotify destroy_data, ...)
-{
- GnomeKeyringOperation *op;
- GnomeKeyringAttributeList *attributes;
- va_list args;
-
- op = create_operation (TRUE, callback, CALLBACK_DONE, data, destroy_data);
-
- va_start (args, destroy_data);
- attributes = schema_attribute_list_va (schema, args);
- va_end (args);
- if (!attributes || !attributes->len ||
- !gkr_proto_encode_find (&op->send_buffer, schema->item_type, attributes))
- schedule_op_failed (op, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
-
- g_array_free (attributes, TRUE);
-
- op->reply_handler = delete_password_reply;
- op->reply_data = g_new0 (DeletePassword, 1);
- op->destroy_reply_data = delete_password_destroy;
-
- start_operation (op);
- return op;
-}
-
-/**
- * gnome_keyring_delete_password_sync:
- * @schema: The password schema.
- * @...: The variable argument list should contain pairs of a) The attribute name as a null
- * terminated string, followed by b) attribute value, either a character string,
- * or 32-bit unsigned int, as defined in the password @schema. The list of attribtues
- * should be terminated with a %NULL.
- *
- * Delete a password that matches a given set of attributes.
- *
- * Attributes which identify this password must be passed as additional
- * arguments. Attributes passed must be defined in the schema.
- *
- * This function may block for an unspecified period. If your application must
- * remain responsive to the user, then use gnome_keyring_delete_password().
- *
- * Another more complex way to find items in the keyrings is using
- * gnome_keyring_item_delete_sync().
- *
- * Return value: %GNOME_KEYRING_RESULT_OK if the operation was succcessful or
- * an error result otherwise.
- * Since: 2.22
- */
-GnomeKeyringResult
-gnome_keyring_delete_password_sync (const GnomeKeyringPasswordSchema* schema, ...)
-{
- GnomeKeyringAttributeList *attributes;
- GnomeKeyringResult res;
- GnomeKeyringFound *f;
- GList *found, *l;
- va_list args;
- guint non_session;
-
- va_start (args, schema);
- attributes = schema_attribute_list_va (schema, args);
- va_end (args);
-
- if (!attributes || !attributes->len)
- res = GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
-
- /* Find the item(s) in question */
- else
- res = gnome_keyring_find_items_sync (schema->item_type, attributes, &found);
-
- g_array_free (attributes, TRUE);
- if (res != GNOME_KEYRING_RESULT_OK)
- return res;
-
- non_session = 0;
- for (l = found; l; l = g_list_next (l)) {
- f = (GnomeKeyringFound*)(l->data);
-
- /* If not an item in the session keyring ... */
- if (!f->keyring || strcmp (f->keyring, GNOME_KEYRING_SESSION) != 0) {
-
- ++non_session;
-
- /* ... then we only delete one of those */
- if (non_session > 1)
- continue;
- }
-
- res = gnome_keyring_item_delete_sync (f->keyring, f->item_id);
- if (res != GNOME_KEYRING_RESULT_OK)
- break;
- }
-
- gnome_keyring_found_list_free (found);
- return res;
-}
diff --git a/library/gnome-keyring.h b/library/gnome-keyring.h
deleted file mode 100644
index dc19a4c1..00000000
--- a/library/gnome-keyring.h
+++ /dev/null
@@ -1,523 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* gnome-keyring.h - library for talking to the keyring daemon.
-
- Copyright (C) 2003 Red Hat, Inc
-
- The Gnome Keyring Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Keyring Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-
- Author: Alexander Larsson <alexl@redhat.com>
-*/
-
-#ifndef GNOME_KEYRING_H
-#define GNOME_KEYRING_H
-
-#include <glib.h>
-#include <time.h>
-
-#include "gnome-keyring-result.h"
-
-G_BEGIN_DECLS
-
-#define GNOME_KEYRING_SESSION "session"
-#define GNOME_KEYRING_DEFAULT NULL
-
-typedef enum {
-
- /* The item types */
- GNOME_KEYRING_ITEM_GENERIC_SECRET = 0,
- GNOME_KEYRING_ITEM_NETWORK_PASSWORD,
- GNOME_KEYRING_ITEM_NOTE,
- GNOME_KEYRING_ITEM_CHAINED_KEYRING_PASSWORD,
- GNOME_KEYRING_ITEM_ENCRYPTION_KEY_PASSWORD,
-
- GNOME_KEYRING_ITEM_PK_STORAGE = 0x100,
-
- /* Not used, remains here only for compatibility */
- GNOME_KEYRING_ITEM_LAST_TYPE,
-
-} GnomeKeyringItemType;
-
-#define GNOME_KEYRING_ITEM_TYPE_MASK 0x0000ffff
-#define GNOME_KEYRING_ITEM_NO_TYPE GNOME_KEYRING_ITEM_TYPE_MASK
-#define GNOME_KEYRING_ITEM_APPLICATION_SECRET 0x01000000
-
-typedef enum {
- GNOME_KEYRING_ACCESS_ASK,
- GNOME_KEYRING_ACCESS_DENY,
- GNOME_KEYRING_ACCESS_ALLOW
-} GnomeKeyringAccessRestriction;
-
-typedef enum {
- GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
- GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32
-} GnomeKeyringAttributeType;
-
-typedef struct GnomeKeyringAccessControl GnomeKeyringAccessControl;
-typedef struct GnomeKeyringApplicationRef GnomeKeyringApplicationRef;
-typedef GArray GnomeKeyringAttributeList;
-
-typedef enum {
- GNOME_KEYRING_ACCESS_READ = 1<<0,
- GNOME_KEYRING_ACCESS_WRITE = 1<<1,
- GNOME_KEYRING_ACCESS_REMOVE = 1<<2
-} GnomeKeyringAccessType;
-
-typedef enum {
- GNOME_KEYRING_ITEM_INFO_BASICS = 0,
- GNOME_KEYRING_ITEM_INFO_SECRET = 1<<0
-} GnomeKeyringItemInfoFlags;
-
-/* Add flags here as they are added above */
-#define GNOME_KEYRING_ITEM_INFO_ALL (GNOME_KEYRING_ITEM_INFO_BASICS | GNOME_KEYRING_ITEM_INFO_SECRET)
-
-typedef struct GnomeKeyringInfo GnomeKeyringInfo;
-typedef struct GnomeKeyringItemInfo GnomeKeyringItemInfo;
-
-typedef struct {
- char *name;
- GnomeKeyringAttributeType type;
- union {
- char *string;
- guint32 integer;
- } value;
-} GnomeKeyringAttribute;
-
-typedef struct {
- char *keyring;
- guint item_id;
- GnomeKeyringAttributeList *attributes;
- char *secret;
-} GnomeKeyringFound;
-
-void gnome_keyring_string_list_free (GList *strings);
-
-typedef void (*GnomeKeyringOperationDoneCallback) (GnomeKeyringResult result,
- gpointer data);
-typedef void (*GnomeKeyringOperationGetStringCallback) (GnomeKeyringResult result,
- const char *string,
- gpointer data);
-typedef void (*GnomeKeyringOperationGetIntCallback) (GnomeKeyringResult result,
- guint32 val,
- gpointer data);
-typedef void (*GnomeKeyringOperationGetListCallback) (GnomeKeyringResult result,
- GList *list,
- gpointer data);
-typedef void (*GnomeKeyringOperationGetKeyringInfoCallback) (GnomeKeyringResult result,
- GnomeKeyringInfo *info,
- gpointer data);
-typedef void (*GnomeKeyringOperationGetItemInfoCallback) (GnomeKeyringResult result,
- GnomeKeyringItemInfo*info,
- gpointer data);
-typedef void (*GnomeKeyringOperationGetAttributesCallback) (GnomeKeyringResult result,
- GnomeKeyringAttributeList *attributes,
- gpointer data);
-
-#define gnome_keyring_attribute_list_index(a, i) g_array_index ((a), GnomeKeyringAttribute, (i))
-#define gnome_keyring_attribute_list_new() (g_array_new (FALSE, FALSE, sizeof (GnomeKeyringAttribute)))
-void gnome_keyring_attribute_list_append_string (GnomeKeyringAttributeList *attributes,
- const char *name,
- const char *value);
-void gnome_keyring_attribute_list_append_uint32 (GnomeKeyringAttributeList *attributes,
- const char *name,
- guint32 value);
-void gnome_keyring_attribute_list_free (GnomeKeyringAttributeList *attributes);
-GnomeKeyringAttributeList *gnome_keyring_attribute_list_copy (GnomeKeyringAttributeList *attributes);
-
-
-const gchar* gnome_keyring_result_to_message (GnomeKeyringResult res);
-
-gboolean gnome_keyring_is_available (void);
-
-void gnome_keyring_found_free (GnomeKeyringFound *found);
-void gnome_keyring_found_list_free (GList *found_list);
-
-void gnome_keyring_cancel_request (gpointer request);
-
-gpointer gnome_keyring_set_default_keyring (const char *keyring,
- GnomeKeyringOperationDoneCallback callback,
- gpointer data,
- GDestroyNotify destroy_data);
-GnomeKeyringResult gnome_keyring_set_default_keyring_sync (const char *keyring);
-gpointer gnome_keyring_get_default_keyring (GnomeKeyringOperationGetStringCallback callback,
- gpointer data,
- GDestroyNotify destroy_data);
-GnomeKeyringResult gnome_keyring_get_default_keyring_sync (char **keyring);
-gpointer gnome_keyring_list_keyring_names (GnomeKeyringOperationGetListCallback callback,
- gpointer data,
- GDestroyNotify destroy_data);
-GnomeKeyringResult gnome_keyring_list_keyring_names_sync (GList **keyrings);
-gpointer gnome_keyring_lock_all (GnomeKeyringOperationDoneCallback callback,
- gpointer data,
- GDestroyNotify destroy_data);
-GnomeKeyringResult gnome_keyring_lock_all_sync (void);
-
-
-/* NULL password means ask user */
-gpointer gnome_keyring_create (const char *keyring_name,
- const char *password,
- GnomeKeyringOperationDoneCallback callback,
- gpointer data,
- GDestroyNotify destroy_data);
-GnomeKeyringResult gnome_keyring_create_sync (const char *keyring_name,
- const char *password);
-gpointer gnome_keyring_unlock (const char *keyring,
- const char *password,
- GnomeKeyringOperationDoneCallback callback,
- gpointer data,
- GDestroyNotify destroy_data);
-GnomeKeyringResult gnome_keyring_unlock_sync (const char *keyring,
- const char *password);
-gpointer gnome_keyring_lock (const char *keyring,
- GnomeKeyringOperationDoneCallback callback,
- gpointer data,
- GDestroyNotify destroy_data);
-GnomeKeyringResult gnome_keyring_lock_sync (const char *keyring);
-gpointer gnome_keyring_delete (const char *keyring,
- GnomeKeyringOperationDoneCallback callback,
- gpointer data,
- GDestroyNotify destroy_data);
-GnomeKeyringResult gnome_keyring_delete_sync (const char *keyring);
-gpointer gnome_keyring_change_password (const char *keyring,
- const char *original,
- const char *password,
- GnomeKeyringOperationDoneCallback callback,
- gpointer data,
- GDestroyNotify destroy_data);
-GnomeKeyringResult gnome_keyring_change_password_sync (const char *keyring,
- const char *original,
- const char *password);
-gpointer gnome_keyring_get_info (const char *keyring,
- GnomeKeyringOperationGetKeyringInfoCallback callback,
- gpointer data,
- GDestroyNotify destroy_data);
-GnomeKeyringResult gnome_keyring_get_info_sync (const char *keyring,
- GnomeKeyringInfo **info);
-gpointer gnome_keyring_set_info (const char *keyring,
- GnomeKeyringInfo *info,
- GnomeKeyringOperationDoneCallback callback,
- gpointer data,
- GDestroyNotify destroy_data);
-GnomeKeyringResult gnome_keyring_set_info_sync (const char *keyring,
- GnomeKeyringInfo *info);
-gpointer gnome_keyring_list_item_ids (const char *keyring,
- GnomeKeyringOperationGetListCallback callback,
- gpointer data,
- GDestroyNotify destroy_data);
-GnomeKeyringResult gnome_keyring_list_item_ids_sync (const char *keyring,
- GList **ids);
-
-void gnome_keyring_info_free (GnomeKeyringInfo *keyring_info);
-GnomeKeyringInfo *gnome_keyring_info_copy (GnomeKeyringInfo *keyring_info);
-void gnome_keyring_info_set_lock_on_idle (GnomeKeyringInfo *keyring_info,
- gboolean value);
-gboolean gnome_keyring_info_get_lock_on_idle (GnomeKeyringInfo *keyring_info);
-void gnome_keyring_info_set_lock_timeout (GnomeKeyringInfo *keyring_info,
- guint32 value);
-guint32 gnome_keyring_info_get_lock_timeout (GnomeKeyringInfo *keyring_info);
-time_t gnome_keyring_info_get_mtime (GnomeKeyringInfo *keyring_info);
-time_t gnome_keyring_info_get_ctime (GnomeKeyringInfo *keyring_info);
-gboolean gnome_keyring_info_get_is_locked (GnomeKeyringInfo *keyring_info);
-
-gpointer gnome_keyring_find_items (GnomeKeyringItemType type,
- GnomeKeyringAttributeList *attributes,
- GnomeKeyringOperationGetListCallback callback,
- gpointer data,
- GDestroyNotify destroy_data);
-gpointer gnome_keyring_find_itemsv (GnomeKeyringItemType type,
- GnomeKeyringOperationGetListCallback callback,
- gpointer data,
- GDestroyNotify destroy_data,
- ...);
-
-GnomeKeyringResult gnome_keyring_find_items_sync (GnomeKeyringItemType type,
- GnomeKeyringAttributeList *attributes,
- GList **found);
-GnomeKeyringResult gnome_keyring_find_itemsv_sync (GnomeKeyringItemType type,
- GList **found,
- ...);
-
-gpointer gnome_keyring_item_create (const char *keyring,
- GnomeKeyringItemType type,
- const char *display_name,
- GnomeKeyringAttributeList *attributes,
- const char *secret,
- gboolean update_if_exists,
- GnomeKeyringOperationGetIntCallback callback,
- gpointer data,
- GDestroyNotify destroy_data);
-GnomeKeyringResult gnome_keyring_item_create_sync (const char *keyring,
- GnomeKeyringItemType type,
- const char *display_name,
- GnomeKeyringAttributeList *attributes,
- const char *secret,
- gboolean update_if_exists,
- guint32 *item_id);
-gpointer gnome_keyring_item_delete (const char *keyring,
- guint32 id,
- GnomeKeyringOperationDoneCallback callback,
- gpointer data,
- GDestroyNotify destroy_data);
-GnomeKeyringResult gnome_keyring_item_delete_sync (const char *keyring,
- guint32 id);
-gpointer gnome_keyring_item_get_info (const char *keyring,
- guint32 id,
- GnomeKeyringOperationGetItemInfoCallback callback,
- gpointer data,
- GDestroyNotify destroy_data);
-GnomeKeyringResult gnome_keyring_item_get_info_sync (const char *keyring,
- guint32 id,
- GnomeKeyringItemInfo **info);
-gpointer gnome_keyring_item_get_info_full (const char *keyring,
- guint32 id,
- guint32 flags,
- GnomeKeyringOperationGetItemInfoCallback callback,
- gpointer data,
- GDestroyNotify destroy_data);
-GnomeKeyringResult gnome_keyring_item_get_info_full_sync (const char *keyring,
- guint32 id,
- guint32 flags,
- GnomeKeyringItemInfo **info);
-gpointer gnome_keyring_item_set_info (const char *keyring,
- guint32 id,
- GnomeKeyringItemInfo *info,
- GnomeKeyringOperationDoneCallback callback,
- gpointer data,
- GDestroyNotify destroy_data);
-GnomeKeyringResult gnome_keyring_item_set_info_sync (const char *keyring,
- guint32 id,
- GnomeKeyringItemInfo *info);
-gpointer gnome_keyring_item_get_attributes (const char *keyring,
- guint32 id,
- GnomeKeyringOperationGetAttributesCallback callback,
- gpointer data,
- GDestroyNotify destroy_data);
-GnomeKeyringResult gnome_keyring_item_get_attributes_sync (const char *keyring,
- guint32 id,
- GnomeKeyringAttributeList **attributes);
-gpointer gnome_keyring_item_set_attributes (const char *keyring,
- guint32 id,
- GnomeKeyringAttributeList *attributes,
- GnomeKeyringOperationDoneCallback callback,
- gpointer data,
- GDestroyNotify destroy_data);
-GnomeKeyringResult gnome_keyring_item_set_attributes_sync (const char *keyring,
- guint32 id,
- GnomeKeyringAttributeList *attributes);
-gpointer gnome_keyring_item_get_acl (const char *keyring,
- guint32 id,
- GnomeKeyringOperationGetListCallback callback,
- gpointer data,
- GDestroyNotify destroy_data);
-GnomeKeyringResult gnome_keyring_item_get_acl_sync (const char *keyring,
- guint32 id,
- GList **acl);
-gpointer gnome_keyring_item_set_acl (const char *keyring,
- guint32 id,
- GList *acl,
- GnomeKeyringOperationDoneCallback callback,
- gpointer data,
- GDestroyNotify destroy_data);
-GnomeKeyringResult gnome_keyring_item_set_acl_sync (const char *keyring,
- guint32 id,
- GList *acl);
-
-gpointer gnome_keyring_item_grant_access_rights (const gchar *keyring,
- const gchar *display_name,
- const gchar *full_path,
- const guint32 id,
- const GnomeKeyringAccessType rights,
- GnomeKeyringOperationDoneCallback callback,
- gpointer data,
- GDestroyNotify destroy_data);
-
-GnomeKeyringResult gnome_keyring_item_grant_access_rights_sync (const char *keyring,
- const char *display_name,
- const char *full_path,
- const guint32 id,
- const GnomeKeyringAccessType rights);
-
-void gnome_keyring_item_info_free (GnomeKeyringItemInfo *item_info);
-GnomeKeyringItemInfo *gnome_keyring_item_info_new (void);
-GnomeKeyringItemInfo *gnome_keyring_item_info_copy (GnomeKeyringItemInfo *item_info);
-GnomeKeyringItemType gnome_keyring_item_info_get_type (GnomeKeyringItemInfo *item_info);
-void gnome_keyring_item_info_set_type (GnomeKeyringItemInfo *item_info,
- GnomeKeyringItemType type);
-char * gnome_keyring_item_info_get_secret (GnomeKeyringItemInfo *item_info);
-void gnome_keyring_item_info_set_secret (GnomeKeyringItemInfo *item_info,
- const char *value);
-char * gnome_keyring_item_info_get_display_name (GnomeKeyringItemInfo *item_info);
-void gnome_keyring_item_info_set_display_name (GnomeKeyringItemInfo *item_info,
- const char *value);
-time_t gnome_keyring_item_info_get_mtime (GnomeKeyringItemInfo *item_info);
-time_t gnome_keyring_item_info_get_ctime (GnomeKeyringItemInfo *item_info);
-
-GnomeKeyringApplicationRef * gnome_keyring_application_ref_new (void);
-GnomeKeyringApplicationRef * gnome_keyring_application_ref_copy (const GnomeKeyringApplicationRef *app);
-void gnome_keyring_application_ref_free (GnomeKeyringApplicationRef *app);
-
-GnomeKeyringAccessControl * gnome_keyring_access_control_new (const GnomeKeyringApplicationRef *application,
- GnomeKeyringAccessType types_allowed);
-GnomeKeyringAccessControl * gnome_keyring_access_control_copy (GnomeKeyringAccessControl *ac);
-
-
-void gnome_keyring_access_control_free (GnomeKeyringAccessControl *ac);
-GList * gnome_keyring_acl_copy (GList *list);
-void gnome_keyring_acl_free (GList *acl);
-
-
-char * gnome_keyring_item_ac_get_display_name (GnomeKeyringAccessControl *ac);
-void gnome_keyring_item_ac_set_display_name (GnomeKeyringAccessControl *ac,
- const char *value);
-
-char * gnome_keyring_item_ac_get_path_name (GnomeKeyringAccessControl *ac);
-void gnome_keyring_item_ac_set_path_name (GnomeKeyringAccessControl *ac,
- const char *value);
-
-
-GnomeKeyringAccessType gnome_keyring_item_ac_get_access_type (GnomeKeyringAccessControl *ac);
-void gnome_keyring_item_ac_set_access_type (GnomeKeyringAccessControl *ac,
- const GnomeKeyringAccessType value);
-
-/* ------------------------------------------------------------------------------
- * A Simpler API
- */
-
-typedef struct {
- GnomeKeyringItemType item_type;
- struct {
- const gchar* name;
- GnomeKeyringAttributeType type;
- } attributes[32];
-
- /* <private> */
- gpointer reserved1;
- gpointer reserved2;
- gpointer reserved3;
-} GnomeKeyringPasswordSchema;
-
-extern const GnomeKeyringPasswordSchema* GNOME_KEYRING_NETWORK_PASSWORD;
-
-gpointer gnome_keyring_store_password (const GnomeKeyringPasswordSchema* schema,
- const gchar *keyring,
- const gchar *display_name,
- const gchar *password,
- GnomeKeyringOperationDoneCallback callback,
- gpointer data,
- GDestroyNotify destroy_data,
- ...) G_GNUC_NULL_TERMINATED;
-
-GnomeKeyringResult gnome_keyring_store_password_sync (const GnomeKeyringPasswordSchema* schema,
- const gchar *keyring,
- const gchar *display_name,
- const gchar *password,
- ...) G_GNUC_NULL_TERMINATED;
-
-gpointer gnome_keyring_find_password (const GnomeKeyringPasswordSchema* schema,
- GnomeKeyringOperationGetStringCallback callback,
- gpointer data,
- GDestroyNotify destroy_data,
- ...) G_GNUC_NULL_TERMINATED;
-
-GnomeKeyringResult gnome_keyring_find_password_sync (const GnomeKeyringPasswordSchema* schema,
- gchar **password,
- ...) G_GNUC_NULL_TERMINATED;
-
-gpointer gnome_keyring_delete_password (const GnomeKeyringPasswordSchema* schema,
- GnomeKeyringOperationDoneCallback callback,
- gpointer data,
- GDestroyNotify destroy_data,
- ...) G_GNUC_NULL_TERMINATED;
-
-GnomeKeyringResult gnome_keyring_delete_password_sync (const GnomeKeyringPasswordSchema* schema,
- ...) G_GNUC_NULL_TERMINATED;
-
-void gnome_keyring_free_password (gchar *password);
-
-/* ------------------------------------------------------------------------------
- * Special Helpers for network password items
- */
-
-typedef struct {
- char *keyring;
- guint32 item_id;
-
- char *protocol;
- char *server;
- char *object;
- char *authtype;
- guint32 port;
-
- char *user;
- char *domain;
- char *password;
-} GnomeKeyringNetworkPasswordData;
-
-void gnome_keyring_network_password_free (GnomeKeyringNetworkPasswordData *data);
-void gnome_keyring_network_password_list_free (GList *list);
-
-gpointer gnome_keyring_find_network_password (const char *user,
- const char *domain,
- const char *server,
- const char *object,
- const char *protocol,
- const char *authtype,
- guint32 port,
- GnomeKeyringOperationGetListCallback callback,
- gpointer data,
- GDestroyNotify destroy_data);
-GnomeKeyringResult gnome_keyring_find_network_password_sync (const char *user,
- const char *domain,
- const char *server,
- const char *object,
- const char *protocol,
- const char *authtype,
- guint32 port,
- GList **results);
-gpointer gnome_keyring_set_network_password (const char *keyring,
- const char *user,
- const char *domain,
- const char *server,
- const char *object,
- const char *protocol,
- const char *authtype,
- guint32 port,
- const char *password,
- GnomeKeyringOperationGetIntCallback callback,
- gpointer data,
- GDestroyNotify destroy_data);
-GnomeKeyringResult gnome_keyring_set_network_password_sync (const char *keyring,
- const char *user,
- const char *domain,
- const char *server,
- const char *object,
- const char *protocol,
- const char *authtype,
- guint32 port,
- const char *password,
- guint32 *item_id);
-
-/* -----------------------------------------------------------------------------
- * USED ONLY BY THE SESSION
- */
-
-/* Deprecated */
-GnomeKeyringResult gnome_keyring_daemon_set_display_sync (const char *display);
-
-GnomeKeyringResult gnome_keyring_daemon_prepare_environment_sync (void);
-
-G_END_DECLS
-
-#endif /* GNOME_KEYRING_H */
diff --git a/library/tests/.gitignore b/library/tests/.gitignore
deleted file mode 100644
index cdaf75f7..00000000
--- a/library/tests/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
-/run-*-test*
-/.*
-/Makefile
-/Makefile.in
diff --git a/library/tests/Makefile.am b/library/tests/Makefile.am
deleted file mode 100644
index dd26cc88..00000000
--- a/library/tests/Makefile.am
+++ /dev/null
@@ -1,17 +0,0 @@
-
-UNIT_AUTO = \
- unit-test-memory.c \
- unit-test-keyrings.c \
- unit-test-other.c \
- unit-test-daemon-setup.c
-
-UNIT_PROMPT = \
- unit-test-login-prompt.c \
- unit-test-keyrings-prompt.c \
- unit-test-daemon-setup.c
-
-UNIT_LIBS = \
- $(top_builddir)/egg/libegg.la \
- $(top_builddir)/library/libgnome-keyring.la
-
-include $(top_srcdir)/tests/gtest.make
diff --git a/library/tests/unit-test-daemon-setup.c b/library/tests/unit-test-daemon-setup.c
deleted file mode 100644
index b8d822fd..00000000
--- a/library/tests/unit-test-daemon-setup.c
+++ /dev/null
@@ -1,81 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* unit-test-daemon-setup.c: Start a gnome-keyring-daemon process for testing
-
- Copyright (C) 2007 Stefan Walter
-
- The Gnome Keyring Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Keyring Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-
- Author: Stef Walter <stef@memberwebs.com>
-*/
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <signal.h>
-#include <unistd.h>
-
-#include "run-auto-test.h"
-
-#include "library/gnome-keyring.h"
-
-static GPid daemon_pid;
-
-DEFINE_START(setup_daemon)
-{
- GError *err = NULL;
- gchar *args[3];
- const gchar *outside, *path;
- gboolean start = FALSE;
- gchar *socket;
-
- /* If already setup somewhere else, then don't start daemon here */
- outside = g_getenv ("GNOME_KEYRING_OUTSIDE_TEST");
- if (!outside || !outside[0]) {
- start = TRUE;
- }
-
- path = g_getenv ("GNOME_KEYRING_TEST_PATH");
- g_assert (path && path[0]);
-
- socket = g_strdup_printf ("%s/socket", path);
- g_setenv ("GNOME_KEYRING_SOCKET", socket, TRUE);
-
- if (!start)
- return;
-
- g_printerr ("Starting gnome-keyring-daemon...\n");
-
- args[0] = "../../daemon/gnome-keyring-daemon";
- args[1] = "-f";
- args[2] = NULL;
-
- if (!g_spawn_async (NULL, args, NULL, G_SPAWN_LEAVE_DESCRIPTORS_OPEN | G_SPAWN_DO_NOT_REAP_CHILD,
- NULL, NULL, &daemon_pid, &err)) {
- g_error ("couldn't start gnome-keyring-daemon for testing: %s",
- err && err->message ? err->message : "");
- g_assert_not_reached ();
- }
-
- /* Let it startup properly */
- sleep (2);
-}
-
-DEFINE_STOP(setup_daemon)
-{
- if (daemon_pid)
- kill (daemon_pid, SIGTERM);
- /* We're exiting soon anyway, no need to wait */
-}
diff --git a/library/tests/unit-test-keyrings-prompt.c b/library/tests/unit-test-keyrings-prompt.c
deleted file mode 100644
index 5e37c08d..00000000
--- a/library/tests/unit-test-keyrings-prompt.c
+++ /dev/null
@@ -1,273 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* unit-test-keyrings-prompt.c: Test basic prompt functionality
-
- Copyright (C) 2007 Stefan Walter
-
- The Gnome Keyring Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Keyring Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-
- Author: Stef Walter <stef@memberwebs.com>
-*/
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "run-prompt-test.h"
-
-#include "library/gnome-keyring.h"
-
-static void
-TELL(const char* what)
-{
- printf("INTERACTION: %s\n", what);
-}
-
-
-gchar* default_keyring = NULL;
-
-#define KEYRING_NAME "unit-test-keyring"
-#define DISPLAY_NAME "Item Display Name"
-#define SECRET "item-secret"
-
-DEFINE_TEST(stash_default)
-{
- GnomeKeyringResult res;
- res = gnome_keyring_get_default_keyring_sync (&default_keyring);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-}
-
-DEFINE_TEST(create_prompt_keyring)
-{
- GnomeKeyringResult res;
-
- TELL("press 'DENY'");
- res = gnome_keyring_create_sync (KEYRING_NAME, NULL);
- g_assert_cmpint (GNOME_KEYRING_RESULT_DENIED, ==, res);
-
- TELL("type in a new keyring password and click 'OK'");
-
- res = gnome_keyring_create_sync (KEYRING_NAME, NULL);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- res = gnome_keyring_create_sync (KEYRING_NAME, NULL);
- g_assert_cmpint (GNOME_KEYRING_RESULT_ALREADY_EXISTS, ==, res);
-
- res = gnome_keyring_set_default_keyring_sync (KEYRING_NAME);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-}
-
-DEFINE_TEST(change_prompt_keyring)
-{
- GnomeKeyringResult res;
-
- TELL("press 'DENY' here");
-
- res = gnome_keyring_change_password_sync (KEYRING_NAME, NULL, NULL);
- g_assert_cmpint (GNOME_KEYRING_RESULT_DENIED, ==, res);
-
- TELL("type in original password then new keyring password and click 'OK'");
-
- res = gnome_keyring_change_password_sync (KEYRING_NAME, NULL, NULL);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-}
-
-DEFINE_TEST(acls)
-{
- GnomeKeyringResult res;
- GnomeKeyringAccessControl *ac, *acl;
- GnomeKeyringItemInfo *info;
- GList *acls, *l;
- guint id;
- gchar *prog;
-
- /* Create teh item */
- res = gnome_keyring_item_create_sync (KEYRING_NAME, GNOME_KEYRING_ITEM_GENERIC_SECRET,
- "Fry", NULL, "secret", FALSE, &id);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- /* Get the ACLs */
- gnome_keyring_item_get_acl_sync (KEYRING_NAME, id, &acls);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- /* Make sure we're in the list, since we created */
- prog = g_get_prgname ();
- acl = NULL;
- for (l = acls; l; l = g_list_next (l)) {
- ac = (GnomeKeyringAccessControl*)l->data;
- if (strstr (gnome_keyring_item_ac_get_path_name (ac), prog)) {
- acl = ac;
- break;
- }
- }
-
- /* "couldn't find ACL for this process on new item" */
- g_assert (acl != NULL);
-
- /* Now remove all ACLs from the item */
- l = NULL;
- gnome_keyring_item_set_acl_sync (KEYRING_NAME, id, l);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- /* Shouldn't be prompted here, not accessing secrets */
- TELL("No prompt should show up at this point");
- res = gnome_keyring_item_get_info_full_sync (KEYRING_NAME, id, GNOME_KEYRING_ITEM_INFO_BASICS, &info);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
- /* "returned a secret when it shouldn't have" */
- g_assert (gnome_keyring_item_info_get_secret (info) == NULL);
- sleep(2);
-
- /* Now try to read the item, should be prompted */
-#ifdef ENABLE_ACL_PROMPTS
- TELL("Press 'Allow Once' to give program access to the data");
-#endif
- res = gnome_keyring_item_get_info_sync (KEYRING_NAME, id, &info);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
- /* "didn't return a secret when it should have" */
- g_assert (gnome_keyring_item_info_get_secret (info) != NULL);
-
-#ifdef ENABLE_ACL_PROMPTS
- /* Now try to read the item again, give forever access */
- TELL("Press 'Always Allow' to give program access to the data");
- res = gnome_keyring_item_get_info_sync (KEYRING_NAME, id, &info);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- /* Now try to read the item, should be prompted */
- TELL("No prompt should show up at this point");
- res = gnome_keyring_item_get_info_sync (KEYRING_NAME, id, &info);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
- sleep(2);
-#endif
-}
-
-DEFINE_TEST(application_secret)
-{
- GnomeKeyringResult res;
- GnomeKeyringItemInfo *info;
- GList *acls;
- guint id;
-
- /* Create teh item */
- res = gnome_keyring_item_create_sync (KEYRING_NAME,
- GNOME_KEYRING_ITEM_GENERIC_SECRET | GNOME_KEYRING_ITEM_APPLICATION_SECRET,
- "Fry", NULL, "secret", FALSE, &id);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- /* Remove all ACLs from the item */
- acls = NULL;
- gnome_keyring_item_set_acl_sync (KEYRING_NAME, id, acls);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- /* Shouldn't be prompted here, not accessing secrets */
- TELL("No prompt should show up at this point");
- res = gnome_keyring_item_get_info_full_sync (KEYRING_NAME, id, GNOME_KEYRING_ITEM_INFO_BASICS, &info);
- g_assert_cmpint (GNOME_KEYRING_RESULT_DENIED, ==, res);
- sleep(2);
-
- /* Now try to read the item, should be prompted */
- TELL("No prompt should show up at this point");
- res = gnome_keyring_item_get_info_sync (KEYRING_NAME, id, &info);
- g_assert_cmpint (GNOME_KEYRING_RESULT_DENIED, ==, res);
- sleep(2);
-}
-
-DEFINE_TEST(unlock_prompt)
-{
- GnomeKeyringResult res;
-
- res = gnome_keyring_lock_all_sync ();
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- TELL("press 'DENY' here");
- res = gnome_keyring_unlock_sync (KEYRING_NAME, NULL);
- g_assert_cmpint (GNOME_KEYRING_RESULT_DENIED, ==, res);
-
- TELL("type in keyring password and click 'OK'");
- res = gnome_keyring_unlock_sync (KEYRING_NAME, NULL);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-}
-
-DEFINE_TEST(find_locked)
-{
- GnomeKeyringResult res;
- GnomeKeyringAttributeList* attrs;
- guint id;
- GList *found;
-
- GTimeVal tv;
- guint32 unique;
-
- /* Make a unique value */
- g_get_current_time (&tv);
- unique = ((guint32)tv.tv_sec) ^ ((guint32)tv.tv_usec);
-
- attrs = gnome_keyring_attribute_list_new ();
- gnome_keyring_attribute_list_append_string (attrs, "dog", "barks");
- gnome_keyring_attribute_list_append_string (attrs, "bird", "tweets");
- gnome_keyring_attribute_list_append_string (attrs, "iguana", "silence");
- gnome_keyring_attribute_list_append_uint32 (attrs, "num", unique);
-
- /* Create teh item */
- res = gnome_keyring_item_create_sync (NULL, GNOME_KEYRING_ITEM_GENERIC_SECRET,
- "Yay!", attrs, SECRET, FALSE, &id);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- /* Lock the keyring ... */
- res = gnome_keyring_lock_all_sync ();
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- /* Now, try to access the item */
- TELL("type in keyring password and click 'OK'");
- res = gnome_keyring_find_items_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET, attrs, &found);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- /* "Wrong number of items found" */
- g_assert_cmpint (g_list_length (found), ==, 1);
-}
-
-DEFINE_TEST(get_info_locked)
-{
- GnomeKeyringResult res;
- GnomeKeyringItemInfo *info;
- guint id;
-
- /* Create teh item */
- res = gnome_keyring_item_create_sync (NULL, GNOME_KEYRING_ITEM_GENERIC_SECRET,
- "My test locked", NULL, SECRET, FALSE, &id);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- /* Lock the keyring ... */
- res = gnome_keyring_lock_all_sync ();
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- /* Now, try to access the item */
- TELL("type in keyring password and click 'OK'");
- res = gnome_keyring_item_get_info_sync (NULL, id, &info);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-}
-
-DEFINE_TEST(cleanup)
-{
- GnomeKeyringResult res;
-
- res = gnome_keyring_delete_sync (KEYRING_NAME);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- if (default_keyring) {
- res = gnome_keyring_set_default_keyring_sync (default_keyring);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
- }
-}
diff --git a/library/tests/unit-test-keyrings.c b/library/tests/unit-test-keyrings.c
deleted file mode 100644
index 46f2fe03..00000000
--- a/library/tests/unit-test-keyrings.c
+++ /dev/null
@@ -1,539 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* unit-test-keyrings.c: Test basic keyring functionality
-
- Copyright (C) 2007 Stefan Walter
-
- The Gnome Keyring Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Keyring Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-
- Author: Stef Walter <stef@memberwebs.com>
-*/
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "run-auto-test.h"
-
-#include "library/gnome-keyring.h"
-
-static GList* keyrings = NULL;
-
-#define PASSWORD "my-keyring-password"
-#define KEYRING_NAME "unit-test-keyring"
-#define INVALID_KEYRING_NAME "invalid-keyring-name"
-#define DISPLAY_NAME "Item Display Name"
-#define SECRET "item-secret"
-
-DEFINE_TEST(remove_incomplete)
-{
- GnomeKeyringResult res;
-
- res = gnome_keyring_delete_sync (KEYRING_NAME);
- if (res != GNOME_KEYRING_RESULT_NO_SUCH_KEYRING)
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-}
-
-DEFINE_TEST(create_keyring)
-{
- GnomeKeyringResult res;
-
- /* No default keyring */
- res = gnome_keyring_set_default_keyring_sync (NULL);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- res = gnome_keyring_create_sync (KEYRING_NAME, PASSWORD);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- res = gnome_keyring_create_sync (KEYRING_NAME, PASSWORD);
- g_assert_cmpint (GNOME_KEYRING_RESULT_ALREADY_EXISTS, ==, res);
-}
-
-DEFINE_TEST(set_default_keyring)
-{
- GnomeKeyringResult res;
- gchar* name;
-
- res = gnome_keyring_set_default_keyring_sync (KEYRING_NAME);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- res = gnome_keyring_set_default_keyring_sync (INVALID_KEYRING_NAME);
- g_assert_cmpint (GNOME_KEYRING_RESULT_NO_SUCH_KEYRING, ==, res);
-
- res = gnome_keyring_get_default_keyring_sync (&name);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
- g_assert (name != NULL);
- g_assert_cmpstr (name, ==, KEYRING_NAME);
-}
-
-DEFINE_TEST(delete_keyring)
-{
- GnomeKeyringResult res;
- gchar* name;
-
- res = gnome_keyring_delete_sync (KEYRING_NAME);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- res = gnome_keyring_delete_sync (KEYRING_NAME);
- g_assert_cmpint (GNOME_KEYRING_RESULT_NO_SUCH_KEYRING, ==, res);
-
- res = gnome_keyring_get_default_keyring_sync (&name);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
- /* "returning deleted keyring as default" */
- g_assert(name == NULL || strcmp (name, KEYRING_NAME) != 0);
-}
-
-DEFINE_TEST(recreate_keyring)
-{
- GnomeKeyringResult res;
-
- /* Create the test keyring again and set as default */
- res = gnome_keyring_create_sync (KEYRING_NAME, PASSWORD);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
- res = gnome_keyring_set_default_keyring_sync (KEYRING_NAME);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-}
-
-DEFINE_TEST(create_list_items)
-{
- GnomeKeyringResult res;
- guint id, id2, id3;
- GList *ids;
- GnomeKeyringItemInfo *info;
- GnomeKeyringAttributeList* attrs;
-
- /* Try in an invalid keyring */
- res = gnome_keyring_item_create_sync (INVALID_KEYRING_NAME, GNOME_KEYRING_ITEM_GENERIC_SECRET,
- DISPLAY_NAME, NULL, SECRET, FALSE, &id);
- g_assert_cmpint (GNOME_KEYRING_RESULT_NO_SUCH_KEYRING, ==, res);
-
- /* Create for real in valid keyring */
- res = gnome_keyring_item_create_sync (KEYRING_NAME, GNOME_KEYRING_ITEM_GENERIC_SECRET,
- DISPLAY_NAME, NULL, SECRET, FALSE, &id);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- /* Update the item, shouldn't create new */
- res = gnome_keyring_item_create_sync (KEYRING_NAME, GNOME_KEYRING_ITEM_GENERIC_SECRET,
- DISPLAY_NAME, NULL, SECRET, TRUE, &id3);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
- /* "Updated item doesn't have the same id" */
- g_assert_cmpint (id, ==, id3);
-
- /* Update in NULL keyring, should use default */
- res = gnome_keyring_item_create_sync (NULL, GNOME_KEYRING_ITEM_GENERIC_SECRET,
- DISPLAY_NAME, NULL, SECRET, TRUE, &id3);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
- /* "Updated item doesn't have the same id" */
- g_assert_cmpint (id, ==, id3);
-
- /* Create new, shouldn't update */
- res = gnome_keyring_item_create_sync (KEYRING_NAME, GNOME_KEYRING_ITEM_GENERIC_SECRET,
- "Another display name", NULL, SECRET, FALSE, &id2);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
- /* "Two items created with the same id" */
- g_assert_cmpint (id, !=, id2);
-
- /* Set some attributes, NULL keyring = default */
- attrs = gnome_keyring_attribute_list_new ();
- gnome_keyring_attribute_list_append_string (attrs, "bender", "rocks");
- res = gnome_keyring_item_set_attributes_sync (NULL, id, attrs);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- /* List ids that were created */
- res = gnome_keyring_list_item_ids_sync (KEYRING_NAME, &ids);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- /* Check that they're the same ids */
- /* "Wrong number of ids created" */
- g_assert_cmpint (g_list_length (ids), ==, 2);
- if (g_list_length (ids) == 2) {
- g_assert_cmpint (id, ==, GPOINTER_TO_UINT (ids->data));
- g_assert_cmpint (id2, ==, GPOINTER_TO_UINT (ids->next->data));
- }
-
- /* Now make sure both have that same secret */
- res = gnome_keyring_item_get_info_sync (KEYRING_NAME, id, &info);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
- if (res == GNOME_KEYRING_RESULT_OK)
- /* "Secret has changed" */
- g_assert_cmpstr (gnome_keyring_item_info_get_secret (info), ==, SECRET);
-
- /* And try it with a NULL (ie: default) keyring */
- res = gnome_keyring_item_get_info_sync (NULL, id2, &info);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
- if (res == GNOME_KEYRING_RESULT_OK)
- g_assert_cmpstr (gnome_keyring_item_info_get_secret (info), ==, SECRET);
-
- /* Set the info back, should work */
- res = gnome_keyring_item_set_info_sync (NULL, id2, info);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- /* Make sure it's still the same */
- res = gnome_keyring_item_get_info_sync (KEYRING_NAME, id, &info);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
- if (res == GNOME_KEYRING_RESULT_OK)
- g_assert_cmpstr (gnome_keyring_item_info_get_secret (info), ==, SECRET);
-
- /* Now delete the item */
- res = gnome_keyring_item_delete_sync (NULL, id);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-}
-
-DEFINE_TEST(find_keyrings)
-{
- GnomeKeyringResult res;
- GnomeKeyringAttributeList* attrs;
- GnomeKeyringAttribute *attr;
- GnomeKeyringFound* f;
- guint id, i;
- GList *found;
-
- attrs = gnome_keyring_attribute_list_new ();
- gnome_keyring_attribute_list_append_string (attrs, "dog", "woof");
- gnome_keyring_attribute_list_append_string (attrs, "bird", "cheep");
- gnome_keyring_attribute_list_append_string (attrs, "iguana", "");
- gnome_keyring_attribute_list_append_uint32 (attrs, "num", 19);
-
- /* Create the item */
- res = gnome_keyring_item_create_sync ("session", GNOME_KEYRING_ITEM_GENERIC_SECRET,
- "Barnyard", attrs, SECRET, TRUE, &id);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- /* Now try to find it */
- res = gnome_keyring_find_items_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET, attrs, &found);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
- /* "Too many items found" */
- g_assert_cmpint (g_list_length (found), ==, 1);
-
- f = (GnomeKeyringFound*)found->data;
- /* "Wrong item found" */
- g_assert (f->item_id == id);
- /* "Found in wrong keyring" */
- g_assert_cmpstr (f->keyring, ==, "session");
- /* "Wrong secret came back" */
- g_assert_cmpstr (f->secret, ==, SECRET);
-
- res = gnome_keyring_item_get_attributes_sync ("session", id, &attrs);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- /* Make sure that dog does in fact woof */
- attr = NULL;
- for(i = 0; i < attrs->len; ++i)
- {
- attr = &gnome_keyring_attribute_list_index (attrs, i);
- if (strcmp (attr->name, "dog") == 0)
- break;
- }
-
- g_assert (attr != NULL);
- if (attr) {
- /* "invalid attribute found" */
- g_assert_cmpstr (attr->name, ==, "dog");
- /* "invalid attribute type" */
- g_assert_cmpint (attr->type, ==, GNOME_KEYRING_ATTRIBUTE_TYPE_STRING);
- /* "invalid attribute value" */
- g_assert_cmpstr (attr->value.string, ==, "woof");
- }
-}
-
-/*
- * A find that does not match should return 'Not Found':
- * http://bugzilla.gnome.org/show_bug.cgi?id=476682
- */
-DEFINE_TEST(find_invalid)
-{
- GnomeKeyringResult res;
- GnomeKeyringAttributeList* attrs;
- GList *found;
-
- attrs = gnome_keyring_attribute_list_new ();
- gnome_keyring_attribute_list_append_string (attrs, "fry-unset-attribute", "rocks");
-
- /* Now try to find it */
- res = gnome_keyring_find_items_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET, attrs, &found);
- g_assert_cmpint (GNOME_KEYRING_RESULT_NO_MATCH, ==, res);
-}
-
-DEFINE_TEST(lock_keyrings)
-{
- GnomeKeyringResult res;
-
- res = gnome_keyring_lock_all_sync ();
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- res = gnome_keyring_unlock_sync (KEYRING_NAME, PASSWORD);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- /* An unlock when already unlocked is fine */
- res = gnome_keyring_unlock_sync (KEYRING_NAME, PASSWORD);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- res = gnome_keyring_unlock_sync ("boooyaaah", PASSWORD);
- g_assert_cmpint (GNOME_KEYRING_RESULT_NO_SUCH_KEYRING, ==, res);
-}
-
-DEFINE_TEST(change_password)
-{
- GnomeKeyringResult res;
-
- res = gnome_keyring_change_password_sync (KEYRING_NAME, PASSWORD, "new password");
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-}
-
-DEFINE_TEST(keyring_info)
-{
- GnomeKeyringResult res;
- GnomeKeyringInfo *info;
-
- res = gnome_keyring_get_info_sync (NULL, &info);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- res = gnome_keyring_set_info_sync (NULL, info);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-}
-
-DEFINE_TEST(list_keyrings)
-{
- GnomeKeyringResult res;
- GList *l;
-
- res = gnome_keyring_list_keyring_names_sync (&keyrings);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- printf("\t\tkeyrings:\n");
- for (l = keyrings; l; l = g_list_next (l))
- printf("\t\t %s\n", (gchar*)l->data);
-}
-
-static GnomeKeyringResult grant_access_result = GNOME_KEYRING_RESULT_CANCELLED;
-
-static void
-done_grant_access (GnomeKeyringResult res, gpointer data)
-{
- grant_access_result = res;
- test_mainloop_quit ();
-}
-
-DEFINE_TEST(keyring_grant_access)
-{
- GList *acl, *l;
- GnomeKeyringResult res;
- gpointer op;
- gboolean found;
- guint id;
-
- /* Create teh item */
- res = gnome_keyring_item_create_sync (NULL, GNOME_KEYRING_ITEM_GENERIC_SECRET,
- "Barnyard", NULL, SECRET, FALSE, &id);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- /* Grant strange program access (async) */
- grant_access_result = GNOME_KEYRING_RESULT_CANCELLED;
- op = gnome_keyring_item_grant_access_rights (NULL, "Strange Application",
- "/usr/bin/strangeness", id,
- GNOME_KEYRING_ACCESS_READ,
- done_grant_access, NULL, NULL);
- /* "return null op" */
- g_assert (op != NULL);
- /* "callback already called" */
- g_assert_cmpint (grant_access_result, ==, GNOME_KEYRING_RESULT_CANCELLED);
-
- test_mainloop_run (2000);
-
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, grant_access_result);
-
- /* Now list the stuff */
- res = gnome_keyring_item_get_acl_sync (NULL, id, &acl);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- /* Make sure it's in the list */
- found = FALSE;
- for (l = acl; l; l = g_list_next (l)) {
- GnomeKeyringAccessControl *ac = (GnomeKeyringAccessControl*)l->data;
- /* "null access control" */
- g_assert (ac != NULL);
- /* "null access control pathname" */
- g_assert (gnome_keyring_item_ac_get_path_name (ac) != NULL);
-
- if (strcmp (gnome_keyring_item_ac_get_path_name (ac), "/usr/bin/strangeness") == 0)
- found = TRUE;
- }
-
- /* "couldn't find acces granted" */
- g_assert (found == TRUE);
-
- gnome_keyring_acl_free (acl);
-}
-
-/* -----------------------------------------------------------------------------
- * SIMPLE PASSWORD API
- */
-
-static GnomeKeyringPasswordSchema our_schema = {
- GNOME_KEYRING_ITEM_GENERIC_SECRET,
- {
- { "dog", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
- { "legs", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32 },
- { NULL, 0 }
- },
-};
-
-static void
-done_store_password (GnomeKeyringResult res, gpointer data)
-{
- *((GnomeKeyringResult*)data) = res;
- test_mainloop_quit ();
-}
-
-DEFINE_TEST(store_password)
-{
- GnomeKeyringResult res;
- gpointer op;
-
- /* Synchronous, bad arguments */
- res = gnome_keyring_store_password_sync (&our_schema, NULL,
- "Display name", "password",
- NULL);
- g_assert_cmpint (GNOME_KEYRING_RESULT_BAD_ARGUMENTS, ==, res);
-
- /* Synchronous, save to default keyring */
- res = gnome_keyring_store_password_sync (&our_schema, NULL,
- "Display name", "password",
- "dog", "woof",
- "legs", 4,
- NULL);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- /* Asynchronous, save to session */
- res = GNOME_KEYRING_RESULT_CANCELLED;
- op = gnome_keyring_store_password (&our_schema, GNOME_KEYRING_SESSION,
- "Display name", "password",
- done_store_password, &res, NULL,
- "dog", "woof",
- "legs", 4,
- NULL);
- /* "async operation is NULL" */
- g_assert (op != NULL);
- /* "callback already called" */
- g_assert_cmpint (res, ==, GNOME_KEYRING_RESULT_CANCELLED);
-
- test_mainloop_run (2000);
-
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-}
-
-static GnomeKeyringResult find_password_result;
-
-static void
-done_find_password (GnomeKeyringResult res, const gchar* password, gpointer unused)
-{
- find_password_result = res;
-
- if(res == GNOME_KEYRING_RESULT_OK) {
- /* "Null password returned" */
- g_assert (password != NULL);
- /* "Wrong returned from find" */
- g_assert_cmpstr (password, ==, "password");
- }
-
- test_mainloop_quit ();
-}
-
-DEFINE_TEST(find_password)
-{
- GnomeKeyringResult res;
- gchar *password;
- gpointer op;
-
- /* Synchronous, bad arguments */
- res = gnome_keyring_find_password_sync (&our_schema, &password,
- NULL);
- g_assert_cmpint (GNOME_KEYRING_RESULT_BAD_ARGUMENTS, ==, res);
-
- /* Synchronous, valid*/
- res = gnome_keyring_find_password_sync (&our_schema, &password,
- "dog", "woof",
- "legs", 4,
- NULL);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
- /* "Null password returned" */
- g_assert (password != NULL);
- /* "Wrong returned from find" */
- g_assert_cmpstr (password, ==, "password");
- gnome_keyring_free_password (password);
-
- /* Asynchronous, less arguments */
- find_password_result = GNOME_KEYRING_RESULT_CANCELLED;
- op = gnome_keyring_find_password (&our_schema,
- done_find_password, NULL, NULL,
- "legs", 4,
- NULL);
- /* "async operation is NULL" */
- g_assert (op != NULL);
- /* "callback already called" */
- g_assert (find_password_result == GNOME_KEYRING_RESULT_CANCELLED);
-
- test_mainloop_run (2000);
-
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, find_password_result);
-}
-
-static void
-done_delete_password (GnomeKeyringResult res, gpointer data)
-{
- *((GnomeKeyringResult*)data) = res;
- test_mainloop_quit ();
-}
-
-DEFINE_TEST(delete_password)
-{
- GnomeKeyringResult res;
- gpointer op;
-
- /* Synchronous, bad arguments */
- res = gnome_keyring_delete_password_sync (&our_schema, NULL);
- g_assert_cmpint (GNOME_KEYRING_RESULT_BAD_ARGUMENTS, ==, res);
-
- /* Synchronous, no match */
- res = gnome_keyring_delete_password_sync (&our_schema,
- "dog", "waoof",
- "legs", 5,
- NULL);
- g_assert_cmpint (GNOME_KEYRING_RESULT_NO_MATCH, ==, res);
-
- /* Asynchronous, less arguments */
- res = GNOME_KEYRING_RESULT_CANCELLED;
- op = gnome_keyring_delete_password (&our_schema,
- done_delete_password, &res, NULL,
- "legs", 4,
- NULL);
- /* "async operation is NULL" */
- g_assert (op != NULL);
- /* "callback already called" */
- g_assert (res == GNOME_KEYRING_RESULT_CANCELLED);
-
- test_mainloop_run (2000);
-
- /* Should have already been deleted by the second call above */
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-}
-
-DEFINE_TEST(cleanup)
-{
- GnomeKeyringResult res;
-
- res = gnome_keyring_delete_sync (KEYRING_NAME);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-}
diff --git a/library/tests/unit-test-login-prompt.c b/library/tests/unit-test-login-prompt.c
deleted file mode 100644
index 9f1bc835..00000000
--- a/library/tests/unit-test-login-prompt.c
+++ /dev/null
@@ -1,104 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* unit-test-keyrings-prompt.c: Test basic prompt functionality
-
- Copyright (C) 2007 Stefan Walter
-
- The Gnome Keyring Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Keyring Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-
- Author: Stef Walter <stef@memberwebs.com>
-*/
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "run-prompt-test.h"
-
-#include "library/gnome-keyring.h"
-
-static void
-TELL(const char* what)
-{
- printf("INTERACTION: %s\n", what);
-}
-
-
-#define THE_PASSWORD "test"
-#define OTHER_PASSWORD "other"
-#define KEYRING_LOGIN "login"
-#define KEYRING_NAME "auto-unlock-keyring"
-#define DISPLAY_NAME "Item Display Name"
-#define SECRET "item-secret"
-
-DEFINE_TEST(create_unlock_login)
-{
- GnomeKeyringResult res;
-
- /* Remove the login keyring */
- res = gnome_keyring_delete_sync (KEYRING_LOGIN);
- if (res != GNOME_KEYRING_RESULT_NO_SUCH_KEYRING)
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- /* Now create it with our password */
- res = gnome_keyring_create_sync (KEYRING_LOGIN, THE_PASSWORD);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-}
-
-DEFINE_TEST(auto_keyring)
-{
- GnomeKeyringResult res;
-
- /* Remove the auto unlock keyring */
- res = gnome_keyring_delete_sync (KEYRING_NAME);
- if (res != GNOME_KEYRING_RESULT_NO_SUCH_KEYRING)
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- res = gnome_keyring_create_sync (KEYRING_NAME, THE_PASSWORD);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- res = gnome_keyring_lock_sync (KEYRING_NAME);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- /* Prompt the user to unlock, and check the option */
- TELL("type 'test' as the password and check the 'Automatically unlock' option");
- res = gnome_keyring_unlock_sync (KEYRING_NAME, NULL);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- res = gnome_keyring_lock_sync (KEYRING_NAME);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- TELL("No prompt should show up at this point");
- res = gnome_keyring_unlock_sync (KEYRING_NAME, NULL);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
- sleep(2);
-}
-
-DEFINE_TEST(auto_keyring_stale)
-{
- GnomeKeyringResult res;
-
- /* Remove the auto unlock keyring */
- res = gnome_keyring_change_password_sync (KEYRING_NAME, THE_PASSWORD, OTHER_PASSWORD);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- res = gnome_keyring_lock_sync (KEYRING_NAME);
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-
- TELL("Press 'deny' here");
- res = gnome_keyring_unlock_sync (KEYRING_NAME, NULL);
- g_assert_cmpint (GNOME_KEYRING_RESULT_DENIED, ==, res);
-}
diff --git a/library/tests/unit-test-memory.c b/library/tests/unit-test-memory.c
deleted file mode 100644
index c7dcacbe..00000000
--- a/library/tests/unit-test-memory.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* unit-test-memory.c: Test memory allocation functionality
-
- Copyright (C) 2007 Stefan Walter
-
- The Gnome Keyring Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Keyring Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-
- Author: Stef Walter <stef@memberwebs.com>
-*/
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "run-auto-test.h"
-
-#include "library/gnome-keyring-memory.h"
-
-#define IS_ZERO ~0
-
-static gsize
-find_non_zero (gpointer mem, gsize len)
-{
- guchar *b, *e;
- gsize sz = 0;
- for (b = (guchar*)mem, e = ((guchar*)mem) + len; b != e; ++b, ++sz) {
- if (*b != 0x00)
- return sz;
- }
-
- return IS_ZERO;
-}
-
-DEFINE_TEST(alloc_free)
-{
- gpointer p;
- gboolean ret;
-
- p = gnome_keyring_memory_alloc (512);
- g_assert (p != NULL);
- g_assert_cmpint (IS_ZERO, ==, find_non_zero (p, 512));
-
- memset (p, 0x67, 512);
-
- ret = gnome_keyring_memory_is_secure (p);
- g_assert (ret == TRUE);
-
- gnome_keyring_memory_free (p);
-}
-
-DEFINE_TEST(alloc_two)
-{
- gpointer p, p2;
- gboolean ret;
-
- p2 = gnome_keyring_memory_alloc (4);
- g_assert(p2 != NULL);
- g_assert_cmpint (IS_ZERO, ==, find_non_zero (p2, 4));
-
- memset (p2, 0x67, 4);
-
- p = gnome_keyring_memory_alloc (16200);
- g_assert (p != NULL);
- g_assert_cmpint (IS_ZERO, ==, find_non_zero (p, 16200));
-
- memset (p, 0x67, 16200);
-
- ret = gnome_keyring_memory_is_secure (p);
- g_assert (ret == TRUE);
-
- gnome_keyring_memory_free (p2);
- gnome_keyring_memory_free (p);
-}
-
-DEFINE_TEST(realloc)
-{
- gchar *str = "a test string to see if realloc works properly";
- gpointer p, p2;
- gsize len;
-
- len = strlen (str) + 1;
-
- p = gnome_keyring_memory_realloc (NULL, len);
- g_assert (p != NULL);
- g_assert_cmpint (IS_ZERO, ==, find_non_zero (p, len));
-
- strcpy ((gchar*)p, str);
-
- p2 = gnome_keyring_memory_realloc (p, 512);
- g_assert (p2 != NULL);
-
- /* "strings not equal after realloc" */
- g_assert_cmpstr (p2, ==, str);
-
- p = gnome_keyring_memory_realloc (p2, 0);
- /* "should have freed memory" */
- g_assert (p == NULL);
-}
-
-DEFINE_TEST(realloc_across)
-{
- gpointer p, p2;
-
- /* Tiny allocation */
- p = gnome_keyring_memory_realloc (NULL, 1088);
- g_assert (p != NULL);
- g_assert_cmpint (IS_ZERO, ==, find_non_zero (p, 1088));
-
- /* Reallocate to a large one, will have to have changed blocks */
- p2 = gnome_keyring_memory_realloc (p, 16200);
- g_assert (p2 != NULL);
- g_assert_cmpint (IS_ZERO, ==, find_non_zero (p2, 16200));
-
- gnome_keyring_memory_free (p2);
-}
diff --git a/library/tests/unit-test-other.c b/library/tests/unit-test-other.c
deleted file mode 100644
index a61cdd5a..00000000
--- a/library/tests/unit-test-other.c
+++ /dev/null
@@ -1,105 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* unit-test-other.c: Test miscellaneous functionality
-
- Copyright (C) 2007 Stefan Walter
-
- The Gnome Keyring Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Keyring Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-
- Author: Stef Walter <stef@memberwebs.com>
-*/
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "run-auto-test.h"
-
-#include "library/gnome-keyring.h"
-
-/*
- * Each test looks like (on one line):
- * void unit_test_xxxxx (CuTest* cu)
- *
- * Each setup looks like (on one line):
- * void unit_setup_xxxxx (void);
- *
- * Each teardown looks like (on one line):
- * void unit_teardown_xxxxx (void);
- *
- * Tests be run in the order specified here.
- */
-
-DEFINE_TEST(set_display)
-{
- GnomeKeyringResult res;
-
- res = gnome_keyring_daemon_set_display_sync (":0.0");
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-}
-
-DEFINE_TEST(setup_environment)
-{
- GnomeKeyringResult res;
-
- res = gnome_keyring_daemon_prepare_environment_sync ();
- g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
-}
-
-DEFINE_TEST(result_string)
-{
- const gchar *msg;
-
- msg = gnome_keyring_result_to_message (GNOME_KEYRING_RESULT_OK);
- /* "should return an empty string" */
- g_assert (msg && !msg[0]);
-
- msg = gnome_keyring_result_to_message (GNOME_KEYRING_RESULT_CANCELLED);
- /* "should return an empty string" */
- g_assert (msg && !msg[0]);
-
- msg = gnome_keyring_result_to_message (GNOME_KEYRING_RESULT_DENIED);
- /* "should return an valid message" */
- g_assert (msg && msg[0]);
-
- msg = gnome_keyring_result_to_message (GNOME_KEYRING_RESULT_NO_KEYRING_DAEMON);
- /* "should return an valid message" */
- g_assert (msg && msg[0]);
-
- msg = gnome_keyring_result_to_message (GNOME_KEYRING_RESULT_NO_SUCH_KEYRING);
- /* "should return an valid message" */
- g_assert (msg && msg[0]);
-
- msg = gnome_keyring_result_to_message (GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
- /* "should return an valid message" */
- g_assert (msg && msg[0]);
-
- msg = gnome_keyring_result_to_message (GNOME_KEYRING_RESULT_IO_ERROR);
- /* "should return an valid message" */
- g_assert (msg && msg[0]);
-
- msg = gnome_keyring_result_to_message (GNOME_KEYRING_RESULT_KEYRING_ALREADY_EXISTS);
- /* "should return an valid message" */
- g_assert (msg && msg[0]);
-}
-
-DEFINE_TEST(is_available)
-{
- gboolean ret;
-
- ret = gnome_keyring_is_available ();
- /* "gnome_keyring_is_available returned false" */
- g_assert (ret == TRUE);
-}