summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2009-12-17 03:57:11 +0000
committerStef Walter <stef@memberwebs.com>2009-12-17 05:32:49 +0000
commitda22a40250da283a502ecb35add5e6548c654c6b (patch)
treeff12702373bc3ab4891be99137617f2dcad1c9c3
parente206707ce7d57ee60cd950e2e667bbb0ec2064ed (diff)
downloadgnome-keyring-da22a40250da283a502ecb35add5e6548c654c6b.tar.gz
Remove old keyring socket, library and code support.
After this commit, all callers must use the libgnome-keyring module to access secrets. The old socket method and included library no longer work.
-rw-r--r--HACKING13
-rw-r--r--Makefile.am2
-rw-r--r--TODO18
-rw-r--r--configure.in9
-rw-r--r--daemon/Makefile.am7
-rw-r--r--daemon/control/Makefile.am3
-rw-r--r--daemon/control/gkd-control-client.c2
-rw-r--r--daemon/control/gkd-control-codes.h (renamed from daemon/control/gkd-control-private.h)0
-rw-r--r--daemon/control/gkd-control-server.c2
-rwxr-xr-xdaemon/control/tests/test-control-changebin96222 -> 96222 bytes
-rwxr-xr-xdaemon/control/tests/test-control-unlockbin96149 -> 96149 bytes
-rw-r--r--daemon/dbus/gkd-dbus-service.c19
-rw-r--r--daemon/gkd-main.c9
-rw-r--r--daemon/gkd-util.c1
-rw-r--r--daemon/gkr-daemon-io.c441
-rw-r--r--daemon/gkr-daemon-ops.c1779
-rw-r--r--daemon/gkr-daemon.h52
-rw-r--r--daemon/keyrings/.gitignore6
-rw-r--r--daemon/keyrings/Makefile.am36
-rw-r--r--daemon/keyrings/gkr-keyring-binary.c676
-rw-r--r--daemon/keyrings/gkr-keyring-item.c412
-rw-r--r--daemon/keyrings/gkr-keyring-item.h111
-rw-r--r--daemon/keyrings/gkr-keyring-login.c325
-rw-r--r--daemon/keyrings/gkr-keyring-login.h50
-rw-r--r--daemon/keyrings/gkr-keyring-textual.c453
-rw-r--r--daemon/keyrings/gkr-keyring.c624
-rw-r--r--daemon/keyrings/gkr-keyring.h145
-rw-r--r--daemon/keyrings/gkr-keyrings.c406
-rw-r--r--daemon/keyrings/gkr-keyrings.h53
-rw-r--r--daemon/keyrings/tests/.gitignore5
-rw-r--r--daemon/keyrings/tests/Makefile.am19
-rw-r--r--daemon/keyrings/tests/test-data/encrypted.keyringbin733 -> 0 bytes
-rw-r--r--daemon/keyrings/tests/test-data/plain.keyring55
-rw-r--r--daemon/keyrings/tests/unit-test-keyring-file.c248
-rw-r--r--daemon/keyrings/tests/unit-test-keyring-login.c157
-rw-r--r--daemon/keyrings/tests/unit-test-login-prompt.c128
-rw-r--r--daemon/ui/gkr-ask-request.c5
-rw-r--r--daemon/util/Makefile.am5
-rw-r--r--daemon/util/gkr-location-watch.c365
-rw-r--r--daemon/util/gkr-location-watch.h70
-rw-r--r--daemon/util/tests/Makefile.am3
-rw-r--r--daemon/util/tests/unit-test-location-watch.c245
-rw-r--r--docs/reference/Makefile.am2
-rw-r--r--docs/reference/gnome-keyring/.gitignore10
-rw-r--r--docs/reference/gnome-keyring/Makefile.am99
-rw-r--r--docs/reference/gnome-keyring/gnome-keyring-docs.sgml26
-rw-r--r--docs/reference/gnome-keyring/gnome-keyring-sections.txt183
-rw-r--r--docs/reference/gnome-keyring/gnome-keyring.types0
-rw-r--r--keyring-intro.txt154
-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
-rw-r--r--pam/gkr-pam-client.c17
-rw-r--r--pam/gkr-pam-module.c11
-rw-r--r--pam/gkr-pam.h7
-rw-r--r--pkcs11/secret-store/file-format.txt (renamed from daemon/keyrings/file-format.txt)7
-rw-r--r--po/POTFILES.in4
-rw-r--r--po/POTFILES.skip6
-rw-r--r--tests/Makefile.am29
-rw-r--r--tests/list-keyrings.c225
-rw-r--r--tests/test-keyrings.c524
81 files changed, 33 insertions, 17636 deletions
diff --git a/HACKING b/HACKING
index ea3e156c..c48e5e4f 100644
--- a/HACKING
+++ b/HACKING
@@ -14,18 +14,8 @@ http://live.gnome.org/GnomeKeyring/Architecture
Gnome Keyring is made up of several distinct parts working on concert with
each other. These parts generally live in different directories:
-common
- Deprecated. This code will shortly live elsewhere. Daemon code will be moved
- into daemon/ some code may move into egg/ etc...
-
daemon
The main daemon startup code and gnome-keyring password protocol operations.
-
-daemon/keyrings
- Code that manages the user's password keyrings
-
-daemon/pk
- Old code, disappearing presently, not in use.
daemon/pkcs11
The various hooks that connect the PKCS#11 modules and code into the daemon.
@@ -43,9 +33,6 @@ gcr
gp11
A public library for accessing PKCS#11 modules.
-library
- The gnome-keyring library for accessing passwords and secrets.
-
pam
The PAM module that unlocks the login keyring when the user logs in.
diff --git a/Makefile.am b/Makefile.am
index 8c4e10a7..08c82ba0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -15,7 +15,6 @@ SUBDIRS = \
gp11 \
egg \
gcr \
- library \
pkcs11 \
daemon \
tool \
@@ -28,7 +27,6 @@ EXTRA_DIST = \
intltool-extract.in \
intltool-merge.in \
intltool-update.in \
- keyring-intro.txt \
ChangeLog.old \
HACKING
diff --git a/TODO b/TODO
deleted file mode 100644
index b132aab9..00000000
--- a/TODO
+++ /dev/null
@@ -1,18 +0,0 @@
-file format fix:
- hash whole attibname + value
- don't store hash to verify decrypt. Instead check attribute hashes.
-
-set daemon chmod a-r or similar (pctrl)
-
-keyring acls?
-
-keep track of denied_keyrings in ask to avoid asking multiple times
-
-make ask UI nicer
-
-verify acls work
-
-missing ops:
- delete keyring
- set keyring info
-
diff --git a/configure.in b/configure.in
index afaa4029..81c1c0d4 100644
--- a/configure.in
+++ b/configure.in
@@ -1,4 +1,4 @@
-AC_INIT(library/gnome-keyring.h)
+AC_INIT(daemon/gkd-main.c)
AM_INIT_AUTOMAKE(gnome-keyring, 2.29.4)
AM_CONFIG_HEADER(config.h)
@@ -554,8 +554,6 @@ daemon/control/Makefile
daemon/control/tests/Makefile
daemon/data/Makefile
daemon/dbus/Makefile
-daemon/keyrings/Makefile
-daemon/keyrings/tests/Makefile
daemon/login/Makefile
daemon/pkcs11/Makefile
daemon/prompt/Makefile
@@ -566,7 +564,6 @@ daemon/util/tests/Makefile
docs/Makefile
docs/reference/Makefile
docs/reference/gcr/Makefile
-docs/reference/gnome-keyring/Makefile
docs/reference/gp11/Makefile
egg/Makefile
egg/tests/Makefile
@@ -576,8 +573,6 @@ gcr/tests/Makefile
gp11/gp11.pc
gp11/Makefile
gp11/tests/Makefile
-library/Makefile
-library/tests/Makefile
pam/Makefile
pam/tests/Makefile
pkcs11/Makefile
@@ -597,8 +592,6 @@ pkcs11/user-store/tests/Makefile
po/Makefile.in
tests/Makefile
tool/Makefile
-library/gnome-keyring-1.pc
-library/gnome-keyring-1-uninstalled.pc
])
# ------------------------------------------------------------------------------
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index a0ce816b..5e3143f7 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -2,7 +2,6 @@ SUBDIRS = \
util \
ui \
prompt \
- keyrings \
login \
control \
pkcs11 \
@@ -28,20 +27,16 @@ INCLUDES= \
gnome_keyring_daemon_SOURCES = \
gkd-main.c gkd-main.h \
- gkd-util.c gkd-util.h \
- gkr-daemon-io.c \
- gkr-daemon-ops.c
+ gkd-util.c gkd-util.h
gnome_keyring_daemon_LDADD = \
$(top_builddir)/daemon/pkcs11/libgkr-pkcs11.la \
$(top_builddir)/daemon/dbus/libgkr-dbus.la \
- $(top_builddir)/daemon/keyrings/libgkr-keyrings.la \
$(top_builddir)/daemon/login/libgkd-login.la \
$(top_builddir)/daemon/ui/libgkr-ui.la \
$(top_builddir)/daemon/control/libgkd-control.la \
$(top_builddir)/daemon/prompt/libgkd-prompt.la \
$(top_builddir)/daemon/util/libgkr-daemon-util.la \
- $(top_builddir)/library/libgnome-keyring-common.la \
$(top_builddir)/pkcs11/plex-layer/libgck-plex-layer.la \
$(top_builddir)/pkcs11/roots-store/libgck-roots-store.la \
$(top_builddir)/pkcs11/rpc-layer/libgck-rpc-layer.la \
diff --git a/daemon/control/Makefile.am b/daemon/control/Makefile.am
index 2fdcf788..79b2c0fb 100644
--- a/daemon/control/Makefile.am
+++ b/daemon/control/Makefile.am
@@ -24,7 +24,8 @@ noinst_LTLIBRARIES = \
libgkd-control-client.la
libgkd_control_la_SOURCES = \
- gkd-control-server.c gkd-control-client.c gkd-control.h
+ gkd-control-server.c gkd-control-client.c \
+ gkd-control.h gkd-control-codes.h
libgkd_control_client_la_SOURCES = \
gkd-control-client.c gkd-control.h
diff --git a/daemon/control/gkd-control-client.c b/daemon/control/gkd-control-client.c
index dedf6e0a..43a7cc42 100644
--- a/daemon/control/gkd-control-client.c
+++ b/daemon/control/gkd-control-client.c
@@ -22,7 +22,7 @@
#include "config.h"
#include "gkd-control.h"
-#include "gkd-control-private.h"
+#include "gkd-control-codes.h"
#include "egg/egg-buffer.h"
#include "egg/egg-secure-memory.h"
diff --git a/daemon/control/gkd-control-private.h b/daemon/control/gkd-control-codes.h
index a982c14c..a982c14c 100644
--- a/daemon/control/gkd-control-private.h
+++ b/daemon/control/gkd-control-codes.h
diff --git a/daemon/control/gkd-control-server.c b/daemon/control/gkd-control-server.c
index 87a50d73..fcb4daaf 100644
--- a/daemon/control/gkd-control-server.c
+++ b/daemon/control/gkd-control-server.c
@@ -22,7 +22,7 @@
#include "config.h"
#include "gkd-control.h"
-#include "gkd-control-private.h"
+#include "gkd-control-codes.h"
#include "gkd-main.h"
#include "gkd-util.h"
diff --git a/daemon/control/tests/test-control-change b/daemon/control/tests/test-control-change
index e2236f4e..1c781233 100755
--- a/daemon/control/tests/test-control-change
+++ b/daemon/control/tests/test-control-change
Binary files differ
diff --git a/daemon/control/tests/test-control-unlock b/daemon/control/tests/test-control-unlock
index d71dd094..90767609 100755
--- a/daemon/control/tests/test-control-unlock
+++ b/daemon/control/tests/test-control-unlock
Binary files differ
diff --git a/daemon/dbus/gkd-dbus-service.c b/daemon/dbus/gkd-dbus-service.c
index c0761528..0455bbba 100644
--- a/daemon/dbus/gkd-dbus-service.c
+++ b/daemon/dbus/gkd-dbus-service.c
@@ -25,7 +25,6 @@
#include "gkd-dbus-private.h"
#include "gkd-util.h"
-#include "gkr-daemon.h"
#include <dbus/dbus.h>
@@ -47,25 +46,11 @@ message_handler_cb (DBusConnection *conn, DBusMessage *message, void *user_data)
DBusMessageIter args;
DBusMessage *reply = NULL;
- /* GetSocketPath */
+ /* GetEnvironment */
if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_CALL &&
- dbus_message_is_method_call (message, GNOME_KEYRING_DAEMON_INTERFACE, "GetSocketPath") &&
+ dbus_message_is_method_call (message, GNOME_KEYRING_DAEMON_INTERFACE, "GetEnvironment") &&
g_str_equal (dbus_message_get_signature (message), "")) {
- const gchar *socket_path = gkr_daemon_io_get_socket_path ();
- g_return_val_if_fail (socket_path, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
-
- /* Setup the result */
- reply = dbus_message_new_method_return (message);
- dbus_message_iter_init_append (reply, &args);
- if (!dbus_message_iter_append_basic (&args, DBUS_TYPE_STRING, &socket_path))
- g_return_val_if_reached (DBUS_HANDLER_RESULT_NEED_MEMORY);
-
- /* GetEnvironment */
- } else if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_CALL &&
- dbus_message_is_method_call (message, GNOME_KEYRING_DAEMON_INTERFACE, "GetEnvironment") &&
- g_str_equal (dbus_message_get_signature (message), "")) {
-
const gchar **env;
DBusMessageIter items, entry;
gchar **parts;
diff --git a/daemon/gkd-main.c b/daemon/gkd-main.c
index b7d56b10..01d297b8 100644
--- a/daemon/gkd-main.c
+++ b/daemon/gkd-main.c
@@ -25,7 +25,6 @@
#include "gkd-main.h"
#include "gkd-util.h"
-#include "gkr-daemon.h"
#include "control/gkd-control.h"
@@ -633,14 +632,6 @@ fork_and_print_environment (void)
static gboolean
gkr_daemon_startup_steps (void)
{
- /*
- * Always initialize the keyring subsystem. This is a necessary
- * component that everything else depends on in one way or
- * another.
- */
- if (!gkr_daemon_io_create_master_socket ())
- return FALSE;
-
/* Startup the appropriate components, creates sockets etc.. */
#ifdef WITH_SSH
if (check_run_component ("ssh")) {
diff --git a/daemon/gkd-util.c b/daemon/gkd-util.c
index 16a0730b..23e61440 100644
--- a/daemon/gkd-util.c
+++ b/daemon/gkd-util.c
@@ -44,7 +44,6 @@
*/
const gchar *GKD_UTIL_OUT_ENVIRONMENT[] = {
"SSH_AUTH_SOCK",
- "GNOME_KEYRING_SOCKET",
"GNOME_KEYRING_CONTROL",
"GNOME_KEYRING_PID",
"SSH_AGENT_PID",
diff --git a/daemon/gkr-daemon-io.c b/daemon/gkr-daemon-io.c
deleted file mode 100644
index af126344..00000000
--- a/daemon/gkr-daemon-io.c
+++ /dev/null
@@ -1,441 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* gnome-keyring-daemon-io.c - handles i/o from the clients
-
- Copyright (C) 2003 Red Hat, Inc
-
- Gnome keyring is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- Gnome keyring 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
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- Author: Alexander Larsson <alexl@redhat.com>
-*/
-
-#include "config.h"
-
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-
-#include "gkd-util.h"
-#include "gkr-daemon.h"
-
-#include "egg/egg-buffer.h"
-#include "egg/egg-cleanup.h"
-#include "egg/egg-secure-memory.h"
-#include "egg/egg-unix-credentials.h"
-
-#include "keyrings/gkr-keyrings.h"
-
-#include "library/gnome-keyring.h"
-#include "library/gnome-keyring-private.h"
-#include "library/gnome-keyring-proto.h"
-
-#include "ui/gkr-ask-daemon.h"
-
-#include "util/gkr-daemon-async.h"
-#include "util/gkr-daemon-util.h"
-
-#ifndef HAVE_SOCKLEN_T
-#define socklen_t int
-#endif
-
-typedef enum {
- GNOME_CLIENT_STATE_CREDENTIALS,
- GNOME_CLIENT_STATE_READ_DISPLAYNAME,
- GNOME_CLIENT_STATE_READ_PACKET,
- GNOME_CLIENT_STATE_COLLECT_INFO,
- GNOME_CLIENT_STATE_REQUEST_ACCESS,
- GNOME_CLIENT_STATE_EXECUTE_OP,
- GNOME_CLIENT_STATE_WRITE_REPLY
-} GnomeKeyringClientStates;
-
-typedef struct {
- GkrDaemonAsyncWorker *worker;
- int sock;
-
- GnomeKeyringApplicationRef *app_ref;
-
- EggBuffer input_buffer;
- EggBuffer output_buffer;
-} GnomeKeyringClient;
-
-static char socket_path[1024] = { 0, };
-
-#if 0
-#define debug_print(x) g_print x
-#else
-#define debug_print(x)
-#endif
-
-static gboolean
-set_local_creds (int fd, gboolean on)
-{
- gboolean retval = TRUE;
-
-#if defined(LOCAL_CREDS) && !defined(HAVE_CMSGCRED)
- int val = on ? 1 : 0;
- if (setsockopt (fd, 0, LOCAL_CREDS, &val, sizeof (val)) < 0)
- {
- g_warning ("Unable to set LOCAL_CREDS socket option on fd %d\n", fd);
- retval = FALSE;
- }
-#endif
-
- return retval;
-}
-
-static GnomeKeyringApplicationRef*
-application_ref_new_from_client ()
-{
- GnomeKeyringApplicationRef *app_ref;
-
- app_ref = g_new0 (GnomeKeyringApplicationRef, 1);
- app_ref->pathname = g_strdup (gkr_daemon_client_get_app_path (NULL));
- app_ref->display_name = g_strdup (gkr_daemon_client_get_app_display (NULL));
-
- return app_ref;
-}
-
-static gboolean
-yield_and_read_all (int fd, guchar *buf, int len)
-{
- int all = len;
- int res;
-
- while (len > 0) {
-
- /* Is this worker stopping? */
- if (gkr_daemon_async_is_stopping ())
- return FALSE;
-
- /* Don't block other threads during the read */
- gkr_daemon_async_begin_concurrent ();
-
- res = read (fd, buf, len);
-
- gkr_daemon_async_end_concurrent ();
-
- if (res <= 0) {
- if (errno == EAGAIN || errno == EINTR)
- continue;
-
- g_warning ("couldn't read %u bytes from client: %s", all,
- res < 0 ? g_strerror (errno) : "");
- return FALSE;
- } else {
- len -= res;
- buf += res;
- }
- }
-
- return TRUE;
-}
-
-static gboolean
-yield_and_write_all (int fd, const guchar *buf, int len)
-{
- int all = len;
- int res;
-
- while (len > 0) {
-
- /* Is this worker stopping? */
- if (gkr_daemon_async_is_stopping ())
- return FALSE;
-
- /* Don't block other threads during the read */
- gkr_daemon_async_begin_concurrent ();
-
- res = write (fd, buf, len);
-
- gkr_daemon_async_end_concurrent ();
-
- if (res <= 0) {
- if (errno == EAGAIN || errno == EINTR)
- continue;
-
- g_warning ("couldn't write %u bytes to client: %s", all,
- res < 0 ? g_strerror (errno) : "");
- return FALSE;
- } else {
- len -= res;
- buf += res;
- }
- }
-
- return TRUE;
-}
-
-static gboolean
-read_packet_with_size (GnomeKeyringClient *client)
-{
- int fd;
- guint32 packet_size;
-
- fd = client->sock;
-
- egg_buffer_resize (&client->input_buffer, 4);
- if (!yield_and_read_all (fd, client->input_buffer.buf, 4))
- return FALSE;
-
- if (!gkr_proto_decode_packet_size (&client->input_buffer, &packet_size) ||
- packet_size < 4) {
- g_warning ("invalid packet size from client");
- return FALSE;
- }
-
- egg_buffer_resize (&client->input_buffer, packet_size + 4);
- if (!yield_and_read_all (fd, client->input_buffer.buf + 4, packet_size - 4))
- return FALSE;
-
- return TRUE;
-}
-
-static gboolean
-yield_and_read_credentials (int sock, pid_t *pid, uid_t *uid)
-{
- gboolean ret;
-
- gkr_daemon_async_begin_concurrent ();
-
- ret = egg_unix_credentials_read (sock, pid, uid) >= 0;
-
- gkr_daemon_async_end_concurrent ();
-
- return ret;
-}
-
-static void
-close_fd (gpointer data)
-{
- int *fd = (int*)data;
- g_assert (fd);
-
- /* If we're waiting anywhere this makes the thread stop */
- shutdown (*fd, SHUT_RDWR);
-}
-
-static gpointer
-client_worker_main (gpointer user_data)
-{
- GnomeKeyringClient *client = (GnomeKeyringClient*)user_data;
- GnomeKeyringOpCode op;
- GkrKeyringRequest req;
- pid_t pid;
- uid_t uid;
- char *str;
-
- /* This helps any reads wakeup when this worker is stopping */
- gkr_daemon_async_register_cancel (close_fd, &client->sock);
-
- /* 1. First we read and verify the client's user credentials */
- debug_print (("GNOME_CLIENT_STATE_CREDENTIALS %p\n", client));
- if (!yield_and_read_credentials (client->sock, &pid, &uid))
- return NULL;
- if (getuid() != uid) {
- g_warning ("uid mismatch: %u, should be %u\n", (guint)uid, (guint)getuid());
- return NULL;
- }
-
- gkr_daemon_client_set_current (pid, NULL, NULL);
- client->app_ref = application_ref_new_from_client ();
-
-
- /* 2. Read the connecting application display name */
- debug_print (("GNOME_CLIENT_STATE_READ_DISPLAYNAME %p\n", client));
- if (!read_packet_with_size (client))
- return NULL;
- debug_print (("read packet\n"));
- if (!gkr_proto_get_utf8_string (&client->input_buffer, 4, NULL, &str))
- return NULL;
- if (!str)
- return NULL;
- debug_print (("got name: %s\n", str));
- g_free (client->app_ref->display_name);
- client->app_ref->display_name = str;
-
-
- /* 3. Now read the actual packet of the operation */
- debug_print (("GNOME_CLIENT_STATE_READ_PACKET %p\n", client));
- if (!read_packet_with_size (client))
- return NULL;
- debug_print (("read packet, size: %d\n", client->input_buffer.len));
-
-
- /* 4. Next decode the operation, and execute the operation */
- debug_print (("GNOME_CLIENT_STATE_EXECUTE_OP %p\n", client));
- if (!gkr_proto_decode_packet_operation (&client->input_buffer, &op))
- return NULL;
- if (op < 0 || op >= GNOME_KEYRING_NUM_OPS)
- return NULL;
- g_assert (keyring_ops[op]);
-
- /* Make sure keyrings in memory are up to date before doing anything */
- gkr_keyrings_update ();
-
- egg_buffer_init_full (&client->output_buffer, 128, g_realloc);
-
- /* Add empty size */
- egg_buffer_add_uint32 (&client->output_buffer, 0);
-
- memset (&req, 0, sizeof (req));
- req.app_ref = client->app_ref;
-
- if (!(keyring_ops[op])(&client->input_buffer, &client->output_buffer, &req))
- return NULL;
-
- if (!egg_buffer_set_uint32 (&client->output_buffer, 0,
- client->output_buffer.len))
- return NULL;
-
-
- /* 5. Write the reply back out */
- debug_print (("GNOME_CLIENT_STATE_WRITE_REPLY %p\n", client));
- debug_print (("writing %d bytes\n", client->output_buffer.len));
- if (!yield_and_write_all (client->sock, client->output_buffer.buf,
- client->output_buffer.len))
- return NULL;
-
- /* All done */
- return NULL;
-}
-
-static void
-client_worker_done (GkrDaemonAsyncWorker *worker, gpointer result, gpointer user_data)
-{
- GnomeKeyringClient *client = (GnomeKeyringClient*)user_data;
-
- egg_buffer_uninit (&client->input_buffer);
- egg_buffer_uninit (&client->output_buffer);
-
- if (client->app_ref != NULL) {
- gnome_keyring_application_ref_free (client->app_ref);
- }
-
- shutdown (client->sock, SHUT_RDWR);
- close (client->sock);
- g_free (client);
-}
-
-static void
-client_new (int fd)
-{
- GnomeKeyringClient *client;
-
- debug_print (("client_new(fd:%d) -> %p\n", fd, client));
-
- client = g_new0 (GnomeKeyringClient, 1);
- client->sock = fd;
-
- /*
- * We really have no idea what operation the client will send,
- * so we err on the side of caution and use secure memory in case
- * passwords or secrets are involved.
- */
- egg_buffer_init_full (&client->input_buffer, 128, egg_secure_realloc);
-
- client->worker = gkr_daemon_async_worker_start (client_worker_main,
- client_worker_done, client);
- g_assert (client->worker);
-
- /*
- * The worker thread is tracked in a global list, and is guaranteed to
- * be cleaned up, either when it exits, or when the application closes.
- */
-}
-
-static gboolean
-accept_client (GIOChannel *channel, GIOCondition cond,
- gpointer callback_data)
-{
- int fd;
- int new_fd;
- struct sockaddr_un addr;
- socklen_t addrlen;
-
- fd = g_io_channel_unix_get_fd (channel);
-
- addrlen = sizeof (addr);
- new_fd = accept(fd, (struct sockaddr *) &addr, &addrlen);
-
- if (new_fd >= 0)
- client_new (new_fd);
- return TRUE;
-}
-
-static void
-cleanup_socket_dir (gpointer data)
-{
- if(*socket_path)
- unlink (socket_path);
-}
-
-const gchar*
-gkr_daemon_io_get_socket_path (void)
-{
- return socket_path[0] ? socket_path : NULL;
-}
-
-gboolean
-gkr_daemon_io_create_master_socket (void)
-{
- const gchar *tmp_dir;
- int sock;
- struct sockaddr_un addr;
- GIOChannel *channel;
-
- tmp_dir = gkd_util_get_master_directory ();
- g_return_val_if_fail (tmp_dir, FALSE);
-
- snprintf (socket_path, sizeof (socket_path), "%s/socket", tmp_dir);
-
- unlink (socket_path);
-
- egg_cleanup_register (cleanup_socket_dir, NULL);
-
- sock = socket(AF_UNIX, SOCK_STREAM, 0);
- if (sock < 0) {
- perror("socket");
- return FALSE;
- }
- memset(&addr, 0, sizeof(addr));
- addr.sun_family = AF_UNIX;
- strncpy (addr.sun_path, socket_path, sizeof (addr.sun_path));
- if (bind (sock, (struct sockaddr *) & addr, sizeof (addr)) < 0) {
- perror ("bind");
- return FALSE;
- }
-
- if (listen (sock, 128) < 0) {
- perror ("listen");
- return FALSE;
- }
-
- if (!set_local_creds (sock, TRUE)) {
- close (sock);
- return FALSE;
- }
-
- channel = g_io_channel_unix_new (sock);
- g_io_add_watch (channel, G_IO_IN | G_IO_HUP, accept_client, NULL);
- g_io_channel_unref (channel);
-
- gkd_util_push_environment ("GNOME_KEYRING_SOCKET", socket_path);
- return TRUE;
-}
diff --git a/daemon/gkr-daemon-ops.c b/daemon/gkr-daemon-ops.c
deleted file mode 100644
index b12967f9..00000000
--- a/daemon/gkr-daemon-ops.c
+++ /dev/null
@@ -1,1779 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* gnome-keyring-daemon.c - main keyring daemon code.
-
- Copyright (C) 2003 Red Hat, Inc
-
- Gnome keyring is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- Gnome keyring 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
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- Author: Alexander Larsson <alexl@redhat.com>
-*/
-
-#include "config.h"
-
-#include "gkd-main.h"
-#include "gkd-util.h"
-#include "gkr-daemon.h"
-
-#include "egg/egg-buffer.h"
-#include "egg/egg-secure-memory.h"
-
-#include "keyrings/gkr-keyring.h"
-#include "keyrings/gkr-keyring-item.h"
-#include "keyrings/gkr-keyrings.h"
-#include "keyrings/gkr-keyring-login.h"
-
-#include "library/gnome-keyring.h"
-#include "library/gnome-keyring-private.h"
-#include "library/gnome-keyring-proto.h"
-
-#include "ui/gkr-ask-request.h"
-#include "ui/gkr-ask-daemon.h"
-
-#include "util/gkr-location.h"
-
-#include <unistd.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <signal.h>
-#include <locale.h>
-#include <sys/types.h>
-
-#include <glib.h>
-#include <glib/gi18n.h>
-
-#include <gcrypt.h>
-
-/* for requesting list access to items */
-#define GNOME_KEYRING_ACCESS_LIST 0
-
-static gboolean
-app_ref_match (GnomeKeyringApplicationRef *app1,
- GnomeKeyringApplicationRef *app2)
-{
- if ((app1->display_name != NULL && app2->display_name != NULL) &&
- strcmp (app1->display_name, app2->display_name) != 0) {
- return FALSE;
- }
- if ((app1->display_name == NULL && app2->display_name != NULL) ||
- (app1->display_name != NULL && app2->display_name == NULL)) {
- return FALSE;
- }
-
- if ((app1->pathname != NULL && app2->pathname != NULL) &&
- strcmp (app1->pathname, app2->pathname) != 0) {
- return FALSE;
- }
- if ((app1->pathname == NULL && app2->pathname != NULL) ||
- (app1->pathname != NULL && app2->pathname == NULL)) {
- return FALSE;
- }
- return TRUE;
-}
-
-static GnomeKeyringAccessControl *
-acl_find_app (GList *acl, GnomeKeyringApplicationRef *app)
-{
- GnomeKeyringAccessControl *ac;
-
- for (; acl != NULL; acl = acl->next) {
- ac = acl->data;
-
- if (app_ref_match (app, ac->application)) {
- return ac;
- }
- }
-
- return NULL;
-}
-
-static gboolean
-acl_check_access (GkrKeyringItem* item, GnomeKeyringApplicationRef *app,
- GnomeKeyringAccessType access_type, gboolean secret)
-{
- GnomeKeyringAccessControl *ac;
- GList *l;
-
- /* Any app can list non application-secret items */
- if (access_type == GNOME_KEYRING_ACCESS_LIST) {
- if((item->type & GNOME_KEYRING_ITEM_APPLICATION_SECRET) == 0)
- return TRUE;
- }
-
- /* Any app is allowed to read non-secrets of non application-secret items */
- if (access_type == GNOME_KEYRING_ACCESS_READ && !secret) {
- if ((item->type & GNOME_KEYRING_ITEM_APPLICATION_SECRET) == 0)
- return TRUE;
- }
-
- /* Otherwise look through ACLs */
- for (l = item->acl; l != NULL; l = l->next) {
- ac = l->data;
- if (app_ref_match (app, ac->application) &&
- (ac->types_allowed & access_type) == access_type) {
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-static void
-add_item_acl (GkrKeyringItem *item,
- GnomeKeyringApplicationRef *app_ref,
- GnomeKeyringAccessType types_allowed)
-{
- GnomeKeyringAccessControl *ac;
-
- ac = acl_find_app (item->acl, app_ref);
- if (ac != NULL) {
- ac->types_allowed |= types_allowed;
- } else {
- ac = gnome_keyring_access_control_new (app_ref,
- types_allowed);
- item->acl = g_list_prepend (item->acl, ac);
- }
-}
-
-static guint
-check_acl_ask_request (GkrAskRequest* ask, GnomeKeyringApplicationRef *app)
-{
- GkrKeyringItem *item;
- gboolean secret;
- GnomeKeyringAccessType access_type;
-
- /* Pull out information from the ask request */
- item = GKR_KEYRING_ITEM (gkr_ask_request_get_object (ask));
- g_assert (GKR_IS_KEYRING_ITEM (item));
- secret = g_object_get_data (G_OBJECT (ask), "access-secret") ? TRUE : FALSE;
- access_type = (GnomeKeyringAccessType)GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (ask), "access-type"));
-
- /* Don't deal with straglers */
- if (!item->keyring) {
- ask->response = GKR_ASK_RESPONSE_FAILURE;
- return GKR_ASK_STOP_REQUEST;
- }
-
- /* Don't deal with locked keyrings */
- if (item->locked) {
- ask->response = GKR_ASK_RESPONSE_DENY;
- return GKR_ASK_STOP_REQUEST;
- }
-
- /* See if this application already has access to this item */
- if (acl_check_access (item, app, access_type, secret)) {
- ask->response = GKR_ASK_RESPONSE_ALLOW;
- return GKR_ASK_STOP_REQUEST;
- }
-
- /* We don't prompt for application secrets at all */
- if (item->type & GNOME_KEYRING_ITEM_APPLICATION_SECRET) {
- ask->response = GKR_ASK_RESPONSE_DENY;
- return GKR_ASK_STOP_REQUEST;
- }
-
-#ifdef ENABLE_ACL_PROMPTS
- /* Did prompting already occur? */
- if (ask->response) {
-
- /* Mark it down if the user gave eternal access */
- if (ask->response == GKR_ASK_RESPONSE_ALLOW_FOREVER) {
- add_item_acl (item, app,
- GNOME_KEYRING_ACCESS_READ |
- GNOME_KEYRING_ACCESS_WRITE |
- GNOME_KEYRING_ACCESS_REMOVE);
- gkr_keyring_save_to_disk (item->keyring);
- }
- }
-
- /* Continue with prompting */
- return GKR_ASK_DONT_CARE;
-#else /* !ENABLE_ACL_PROMPTS */
- ask->response = GKR_ASK_RESPONSE_ALLOW;
- return GKR_ASK_STOP_REQUEST;
-#endif /* ENABLE_ACL_PROMPTS */
-}
-
-static gboolean
-request_item_access (GkrKeyringRequest *req, GkrKeyringItem *item,
- GnomeKeyringAccessType access_type, gboolean secret)
-{
- GnomeKeyringApplicationRef *app = req->app_ref;
- const gchar *keyring_name = NULL;
- GkrAskRequest *ask;
- gboolean is_default, ret;
- gchar *secondary;
-
- /* Simpler messages for the default keyring */
- is_default = !item->keyring || (item->keyring == gkr_keyrings_get_default ());
-
- /* An item with no keyring can happen in certain cases, let's not crash */
- if (!is_default)
- keyring_name = item->keyring->keyring_name;
-
- if (app->display_name && app->pathname) {
- if (is_default) {
- /* TRANSLATORS: Don't translate text in markup (ie: HTML or XML tags) */
- secondary = g_markup_printf_escaped (_("The application '%s' (%s) wants to access the password for '<object prop='name'/>' in the default keyring."),
- app->display_name, app->pathname);
- } else {
- /* TRANSLATORS: Don't translate text in markup (ie: HTML or XML tags) */
- secondary = g_markup_printf_escaped (_("The application '%s' (%s) wants to access the password for '<object prop='name'/>' in %s."),
- app->display_name, app->pathname, keyring_name);
- }
- } else if (app->display_name) {
- if (is_default) {
- /* TRANSLATORS: Don't translate text in markup (ie: HTML or XML tags) */
- secondary = g_markup_printf_escaped (_("The application '%s' wants to access the password for '<object prop='name'/>' in the default keyring."),
- app->display_name);
- } else {
- /* TRANSLATORS: Don't translate text in markup (ie: HTML or XML tags) */
- secondary = g_markup_printf_escaped (_("The application '%s' wants to access the password for '<object prop='name'/>' in %s."),
- app->display_name, keyring_name);
- }
- } else if (app->pathname) {
- if (is_default) {
- /* TRANSLATORS: Don't translate text in markup (ie: HTML or XML tags) */
- secondary = g_markup_printf_escaped (_("The application '%s' wants to access the password for '<object prop='name'/>' in the default keyring."),
- app->pathname);
- } else {
- /* TRANSLATORS: Don't translate text in markup (ie: HTML or XML tags) */
- secondary = g_markup_printf_escaped (_("The application '%s' wants to access the password for '<object prop='name'/>' in %s."),
- app->pathname, keyring_name);
- }
- } else {
- if (is_default) {
- /* TRANSLATORS: Don't translate text in markup (ie: HTML or XML tags) */
- secondary = g_strdup (_("An unknown application wants to access the password for '<object prop='name'/>' in the default keyring."));
- } else {
- /* TRANSLATORS: Don't translate text in markup (ie: HTML or XML tags) */
- secondary = g_markup_printf_escaped (_("An unknown application wants to access the password for '<object prop='name'/>' in %s."),
- keyring_name);
- }
- }
-
- /* And put together the ask request */
- ask = gkr_ask_request_new (_("Allow access"), _("Allow application access to keyring?"),
- GKR_ASK_REQUEST_ACCESS_SOMETHING);
-
- gkr_ask_request_set_secondary (ask, secondary);
- g_free (secondary);
-
- /* Save data away for our handlers to use */
- gkr_ask_request_set_object (ask, G_OBJECT (item));
- g_object_set_data (G_OBJECT (ask), "access-secret", GUINT_TO_POINTER (secret));
- g_object_set_data (G_OBJECT (ask), "access-type", GUINT_TO_POINTER (access_type));
-
- g_signal_connect_data (ask, "check-request", G_CALLBACK (check_acl_ask_request),
- gnome_keyring_application_ref_copy (app),
- (GClosureNotify)gnome_keyring_application_ref_free, 0);
-
- gkr_ask_daemon_process (ask);
-
- ret = ask->response >= GKR_ASK_RESPONSE_ALLOW;
- g_object_unref (ask);
-
- return ret;
-}
-
-static gboolean
-request_keyring_access (GkrKeyringRequest *req, GkrKeyring *keyring)
-{
- GnomeKeyringApplicationRef *app = req->app_ref;
- GkrAskRequest *ask;
- const gchar *keyring_name;
- gboolean is_default, ret;
- gchar *message, *primary;
- GkrKeyring *login;
-
- keyring_name = keyring->keyring_name;
- g_assert (keyring_name);
-
- /* Simpler messages for the default keyring */
- is_default = (keyring == gkr_keyrings_get_default ());
-
- if (app->display_name && app->pathname) {
- if (is_default) {
- /* TRANSLATORS: The default keyring is locked */
- message = g_markup_printf_escaped (_("The application '%s' (%s) wants access to "
- "the default keyring, but it is locked"),
- app->display_name, app->pathname);
- } else {
- /* TRANSLATORS: The keyring '%s' is locked */
- message = g_markup_printf_escaped (_("The application '%s' (%s) wants access to "
- "the keyring '%s', but it is locked"),
- app->display_name, app->pathname, keyring_name);
- }
- } else if (app->display_name) {
- if (is_default) {
- /* TRANSLATORS: The default keyring is locked */
- message = g_markup_printf_escaped (_("The application '%s' wants access to the "
- "default keyring, but it is locked"),
- app->display_name);
- } else {
- /* TRANSLATORS: The keyring '%s' is locked */
- message = g_markup_printf_escaped (_("The application '%s' wants access to the "
- "keyring '%s', but it is locked"),
- app->display_name, keyring_name);
- }
- } else if (app->pathname) {
- if (is_default) {
- /* TRANSLATORS: The default keyring is locked */
- message = g_markup_printf_escaped (_("The application '%s' wants access to the "
- "default keyring, but it is locked"),
- app->pathname);
- }
- else {
- /* TRANSLATORS: The keyring '%s' is locked */
- message = g_markup_printf_escaped (_("The application '%s' wants access to the "
- "keyring '%s', but it is locked"),
- app->pathname, keyring_name);
- }
- } else {
- if (is_default) {
- /* TRANSLATORS: The default keyring is locked */
- message = g_markup_printf_escaped (_("An unknown application wants access to the "
- "default keyring, but it is locked"));
- }
- else {
- /* TRANSLATORS: The keyring '%s' is locked */
- message = g_markup_printf_escaped (_("An unknown application wants access to the "
- "keyring '%s', but it is locked"),
- keyring_name);
- }
- }
-
- if (is_default) {
- primary = g_strdup (_("Enter password for default keyring to unlock"));
- } else {
- primary = g_markup_printf_escaped (_("Enter password for keyring '%s' to unlock"), keyring_name);
- }
-
- /* And put together the ask request */
- ask = gkr_ask_request_new (_("Unlock Keyring"), primary,
- GKR_ASK_REQUEST_PROMPT_PASSWORD);
-
- gkr_ask_request_set_secondary (ask, message);
- gkr_ask_request_set_object (ask, G_OBJECT (keyring));
-
- /*
- * If it's not the login keyring, and we have a login keyring, we can offer
- * to unlock automatically next time.
- */
- login = gkr_keyrings_get_login ();
- if (login != keyring && gkr_keyring_login_is_usable ())
- gkr_ask_request_set_check_option (ask, _("Automatically unlock this keyring when I log in."));
-
- /* Intercept item access requests to see if we still need to prompt */
- g_signal_connect (ask, "check-request", G_CALLBACK (gkr_keyring_ask_check_unlock), NULL);
-
- g_free (primary);
- g_free (message);
-
- gkr_ask_daemon_process (ask);
-
- ret = ask->response >= GKR_ASK_RESPONSE_ALLOW;
- g_object_unref (ask);
-
- return ret;
-}
-
-static gboolean
-request_new_keyring_password (GkrKeyringRequest *req, const char *keyring_name,
- gchar **password, GQuark *volume)
-{
- GnomeKeyringApplicationRef *app = req->app_ref;
- GkrAskRequest* ask;
- gboolean is_default, ret;
- gchar* message;
-
- g_assert (password);
-
- /* If we already have a password then don't prompt */
- if (*password)
- return TRUE;
-
- /* Simpler messages for the default keyring */
- is_default = !keyring_name || (strcmp (keyring_name, "default") == 0);
-
- if (app->display_name && app->pathname) {
- if (!is_default) {
- /* TRANSLATORS: The password is for the new keyring */
- message = g_markup_printf_escaped (_("The application '%s' (%s) wants to create a new keyring called '%s'. "
- "You have to choose the password you want to use for it."),
- app->display_name, app->pathname, keyring_name);
- } else {
- /* TRANSLATORS: The password is for the new keyring */
- message = g_markup_printf_escaped (_("The application '%s' (%s) wants to create a new default keyring. "
- "You have to choose the password you want to use for it."),
- app->display_name, app->pathname);
- }
- } else if (app->display_name) {
- if (!is_default) {
- /* TRANSLATORS: The password is for the new keyring */
- message = g_markup_printf_escaped (_("The application '%s' wants to create a new keyring called '%s'. "
- "You have to choose the password you want to use for it."),
- app->display_name, keyring_name);
- } else {
- /* TRANSLATORS: The password is for the new keyring */
- message = g_markup_printf_escaped (_("The application '%s' wants to create a new default keyring. "
- "You have to choose the password you want to use for it."),
- app->display_name);
- }
- } else if (app->pathname) {
- if (!is_default) {
- /* TRANSLATORS: The password is for the new keyring */
- message = g_markup_printf_escaped (_("The application '%s' wants to create a new keyring called '%s'. "
- "You have to choose the password you want to use for it."),
- app->pathname, keyring_name);
- } else {
- /* TRANSLATORS: The password is for the new keyring */
- message = g_markup_printf_escaped (_("The application '%s' wants to create a new default keyring. "
- "You have to choose the password you want to use for it."),
- app->pathname);
- }
- } else {
- if (!is_default) {
- /* TRANSLATORS: The password is for the new keyring */
- message = g_markup_printf_escaped (_("An unknown application wants to create a new keyring called '%s'. "
- "You have to choose the password you want to use for it."),
- keyring_name);
- } else {
- /* TRANSLATORS: The password is for the new keyring */
- message = g_markup_printf_escaped (_("An unknown application wants to create a new default keyring. "
- "You have to choose the password you want to use for it."));
- }
- }
-
- /* And put together the ask request */
- ask = gkr_ask_request_new (_("New Keyring Password"),
- _("Choose password for new keyring"),
- GKR_ASK_REQUEST_NEW_PASSWORD);
-
- gkr_ask_request_set_secondary (ask, message);
- g_free (message);
-
- gkr_ask_request_set_location_selector (ask, TRUE);
-
- gkr_ask_daemon_process (ask);
-
- ret = ask->response >= GKR_ASK_RESPONSE_ALLOW;
- if (ret) {
- g_free (*password);
- *password = egg_secure_strdup (ask->typed_password);
- *volume = ask->location_selected;
- }
-
- g_object_unref (ask);
-
- return ret;
-}
-
-static gboolean
-request_change_keyring_password (GkrKeyringRequest *req, GkrKeyring* keyring,
- gchar **original, gchar **password)
-{
- GnomeKeyringApplicationRef *app = req->app_ref;
- GkrAskRequest *ask;
- const gchar *keyring_name;
- gboolean is_default, ret;
- gchar *message, *primary;
- guint flags;
-
- g_assert (original && password);
-
- /* Already have passwords no need to prompt */
- if (*original && *password)
- return TRUE;
-
- keyring_name = keyring->keyring_name;
- g_assert (keyring_name);
-
- /* Simpler messages for the default keyring */
- is_default = (keyring == gkr_keyrings_get_default ());
-
- if (app->display_name && app->pathname) {
- if (!is_default) {
- message = g_markup_printf_escaped (_("The application '%s' (%s) wants to change the password for the '%s' keyring. "
- "You have to choose the password you want to use for it."),
- app->display_name, app->pathname, keyring_name);
- } else {
- message = g_markup_printf_escaped (_("The application '%s' (%s) wants to change the password for the default keyring. "
- "You have to choose the password you want to use for it."),
- app->display_name, app->pathname);
- }
- } else if (app->display_name) {
- if (!is_default) {
- message = g_markup_printf_escaped (_("The application '%s' wants to change the password for the '%s' keyring. "
- "You have to choose the password you want to use for it."),
- app->display_name, keyring_name);
- } else {
- message = g_markup_printf_escaped (_("The application '%s' wants to change the password for the default keyring. "
- "You have to choose the password you want to use for it."),
- app->display_name);
- }
- } else if (app->pathname) {
- if (!is_default) {
- message = g_markup_printf_escaped (_("The application '%s' wants to change the password for the '%s' keyring. "
- "You have to choose the password you want to use for it."),
- app->pathname, keyring_name);
- } else {
- message = g_markup_printf_escaped (_("The application '%s' wants to change the password for the default keyring. "
- "You have to choose the password you want to use for it."),
- app->pathname);
- }
- } else {
- if (!is_default) {
- message = g_markup_printf_escaped (_("An unknown application wants to change the password for the '%s' keyring. "
- "You have to choose the password you want to use for it."),
- keyring_name);
- } else {
- message = g_markup_printf_escaped (_("An unknown application wants to change the password for the default keyring. "
- "You have to choose the password you want to use for it."));
- }
- }
-
- flags = GKR_ASK_REQUEST_CHANGE_PASSWORD;
- if (!*original)
- flags |= GKR_ASK_REQUEST_ORIGINAL_PASSWORD;
-
- if (is_default) {
- primary = g_markup_printf_escaped (_("Choose a new password for the '%s' keyring."), keyring_name);
- } else {
- primary = g_markup_printf_escaped (_("Choose a new password for the default keyring."));
- }
-
- /* And put together the ask request */
- ask = gkr_ask_request_new (_("Change Keyring Password"), primary, flags);
- gkr_ask_request_set_secondary (ask, message);
- gkr_ask_request_set_object (ask, G_OBJECT (keyring));
-
- g_free (primary);
- g_free (message);
-
- gkr_ask_daemon_process (ask);
-
- ret = ask->response >= GKR_ASK_RESPONSE_ALLOW;
- if (ret) {
- g_free (*password);
- *password = egg_secure_strdup (ask->typed_password);
-
- g_free (*original);
- *original = egg_secure_strdup (ask->original_password);
- }
-
- g_object_unref (ask);
-
- return ret;
-}
-
-static gboolean
-check_keyring_default_request (GkrAskRequest* ask)
-{
- GkrKeyring *keyring;
-
- /* If another default keyring has been created in the meantime, ignore */
- if (gkr_keyrings_get_default ()) {
- ask->response = GKR_ASK_RESPONSE_ALLOW;
- return GKR_ASK_STOP_REQUEST;
- }
-
- /* If a password was typed use it */
- if (ask->response >= GKR_ASK_RESPONSE_ALLOW) {
- g_assert (ask->typed_password);
-
- /* Create the new keyring */
- keyring = gkr_keyring_create (GKR_LOCATION_VOLUME_LOCAL, "default",
- ask->typed_password);
- if (keyring == NULL) {
- g_warning ("couldn't create default keyring");
- ask->response = GKR_ASK_RESPONSE_FAILURE;
- } else {
- /* Add to our main list */
- gkr_keyrings_add (keyring);
-
- /* Set our newly created keyring as the default */
- gkr_keyrings_set_default (keyring);
-
- /* Let go of the initial reference to this object */
- g_object_unref (keyring);
- }
- }
-
- return GKR_ASK_DONT_CARE;
-}
-
-static GkrKeyring*
-create_default_keyring (GkrKeyringRequest *req)
-{
- GnomeKeyringApplicationRef *app = req->app_ref;
- GkrAskRequest* ask;
- gchar* message;
- GkrKeyring *keyring;
-
- keyring = gkr_keyrings_get_default ();
- if (keyring)
- return keyring;
-
- /* Build an appropriate message */
- if (app->display_name && app->pathname) {
- message = g_markup_printf_escaped (_("The application '%s' (%s) wants to store a password, but there is no default keyring. "
- "To create one, you need to choose the password you wish to use for it."),
- app->display_name, app->pathname);
- } else if (app->display_name) {
- message = g_markup_printf_escaped (_("The application '%s' wants to store a password, but there is no default keyring. "
- "To create one, you need to choose the password you wish to use for it."),
- app->display_name);
- } else if (app->pathname) {
- message = g_markup_printf_escaped (_("The application '%s' wants to store a password, but there is no default keyring. "
- "To create one, you need to choose the password you wish to use for it."),
- app->pathname);
- } else {
- message = g_markup_printf_escaped (_("An unknown application wants to store a password, but there is no default keyring. "
- "To create one, you need to choose the password you wish to use for it."));
- }
-
- /* And put together the ask request */
- ask = gkr_ask_request_new (_("Create Default Keyring"), _("Choose password for default keyring"),
- GKR_ASK_REQUEST_NEW_PASSWORD);
-
- gkr_ask_request_set_secondary (ask, message);
-
- /* Intercept request, and actually create the keyring after prompt */
- g_signal_connect (ask, "check-request", G_CALLBACK (check_keyring_default_request), NULL);
-
- gkr_ask_daemon_process (ask);
-
- if (ask->response >= GKR_ASK_RESPONSE_ALLOW)
- keyring = gkr_keyrings_get_default ();
-
- g_object_unref (ask);
-
- return keyring;
-}
-
-static GnomeKeyringResult
-lookup_and_request_item_access (GkrKeyringRequest *req, gchar *keyring_name,
- int item_id, GnomeKeyringAccessType access_type,
- gboolean access_secret, GkrKeyringItem **ret_item)
-{
- GkrKeyring *keyring;
- GkrKeyringItem *item;
-
- g_assert (ret_item);
- *ret_item = NULL;
-
- keyring = gkr_keyrings_find (keyring_name);
- if (keyring == NULL)
- return GNOME_KEYRING_RESULT_NO_SUCH_KEYRING;
-
- g_object_ref (keyring);
-
- item = gkr_keyring_get_item (keyring, item_id);
- if (item != NULL) {
-
- g_object_ref (item);
-
- if (request_keyring_access (req, keyring) &&
- request_item_access (req, item, access_type, access_secret))
- *ret_item = item;
-
- g_object_unref (item);
- }
-
- g_object_unref (keyring);
-
- return *ret_item == NULL ? GNOME_KEYRING_RESULT_DENIED : GNOME_KEYRING_RESULT_OK;
-}
-
-static GnomeKeyringResult
-change_keyring_password (GkrKeyring *keyring, const char *password)
-{
- if (keyring->locked) {
- return GNOME_KEYRING_RESULT_DENIED;
- } else {
- keyring->password = egg_secure_strdup (password);
- gkr_keyring_save_to_disk (keyring);
- return GNOME_KEYRING_RESULT_OK;
- }
-}
-
-static gboolean
-op_lock_keyring (EggBuffer *packet, EggBuffer *result,
- GkrKeyringRequest *req)
-{
- char *keyring_name;
- GnomeKeyringOpCode opcode;
- GkrKeyring *keyring;
-
- if (!gkr_proto_decode_op_string (packet, &opcode, &keyring_name))
- return FALSE;
-
- keyring = gkr_keyrings_find (keyring_name);
- if (keyring == NULL) {
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_NO_SUCH_KEYRING);
- } else {
- gkr_keyring_lock (keyring);
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_OK);
- }
-
- g_free (keyring_name);
-
- return TRUE;
-}
-
-static gboolean
-lock_each_keyring (GkrKeyring* keyring, gpointer unused)
-{
- gkr_keyring_lock (keyring);
- return TRUE;
-}
-
-static gboolean
-op_lock_all (EggBuffer *packet, EggBuffer *result,
- GkrKeyringRequest *req)
-{
- gkr_keyrings_foreach (lock_each_keyring, NULL);
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_OK);
- return TRUE;
-}
-
-static gboolean
-op_set_default_keyring (EggBuffer *packet, EggBuffer *result,
- GkrKeyringRequest *req)
-{
- char *keyring_name;
- GnomeKeyringOpCode opcode;
- GkrKeyring *keyring;
-
- if (!gkr_proto_decode_op_string (packet, &opcode, &keyring_name))
- return FALSE;
-
- if (keyring_name == NULL) {
- gkr_keyrings_set_default (NULL);
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_OK);
- } else {
- keyring = gkr_keyrings_find (keyring_name);
- if (keyring == NULL) {
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_NO_SUCH_KEYRING);
- } else {
- gkr_keyrings_set_default (keyring);
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_OK);
- }
- }
-
- g_free (keyring_name);
-
- return TRUE;
-}
-
-static gboolean
-op_get_default_keyring (EggBuffer *packet, EggBuffer *result,
- GkrKeyringRequest *req)
-{
- GkrKeyring* keyring;
- char *name;
-
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_OK);
-
- name = NULL;
-
- keyring = gkr_keyrings_get_default ();
- if (keyring)
- name = keyring->keyring_name;
-
- if (!gkr_proto_add_utf8_string (result, name))
- return FALSE;
-
- return TRUE;
-}
-
-static gboolean
-add_name_to_result (GkrKeyring* keyring, gpointer result)
-{
- return gkr_proto_add_utf8_string ((EggBuffer*)result,
- keyring->keyring_name);
-}
-
-static gboolean
-op_list_keyrings (EggBuffer *packet, EggBuffer *result,
- GkrKeyringRequest *req)
-{
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_OK);
-
- egg_buffer_add_uint32 (result, gkr_keyrings_get_count ());
- if (!gkr_keyrings_foreach (add_name_to_result, result))
- return FALSE;
-
- return TRUE;
-}
-
-
-static gboolean
-op_set_keyring_info (EggBuffer *packet, EggBuffer *result,
- GkrKeyringRequest *req)
-{
- char *keyring_name;
- gboolean lock_on_idle;
- guint32 lock_timeout;
- GkrKeyring *keyring;
-
- if (!gkr_proto_decode_set_keyring_info (packet,
- &keyring_name,
- &lock_on_idle,
- &lock_timeout)) {
- return FALSE;
- }
-
- keyring = gkr_keyrings_find (keyring_name);
- if (keyring == NULL) {
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_NO_SUCH_KEYRING);
- } else {
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_OK);
-
- keyring->lock_on_idle = lock_on_idle;
- keyring->lock_timeout = lock_timeout;
- }
-
- g_free (keyring_name);
-
- return TRUE;
-}
-
-static gboolean
-op_get_keyring_info (EggBuffer *packet, EggBuffer *result,
- GkrKeyringRequest *req)
-{
- char *keyring_name;
- GkrKeyring *keyring;
- GnomeKeyringOpCode opcode;
-
- if (!gkr_proto_decode_op_string (packet, &opcode, &keyring_name))
- return FALSE;
-
- keyring = gkr_keyrings_find (keyring_name);
- if (keyring == NULL) {
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_NO_SUCH_KEYRING);
- } else {
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_OK);
-
- egg_buffer_add_uint32 (result, keyring->lock_on_idle);
- egg_buffer_add_uint32 (result, keyring->lock_timeout);
- gkr_proto_add_time (result, keyring->mtime);
- gkr_proto_add_time (result, keyring->ctime);
- egg_buffer_add_uint32 (result, keyring->locked);
- }
-
- g_free (keyring_name);
-
- return TRUE;
-}
-
-static gboolean
-op_create_keyring (EggBuffer *packet, EggBuffer *result,
- GkrKeyringRequest *req)
-{
- GQuark volume = GKR_LOCATION_VOLUME_LOCAL;
- char *keyring_name, *password;
- GkrKeyring *keyring;
- GnomeKeyringOpCode opcode;
-
- if (!gkr_proto_decode_op_string_secret (packet,
- &opcode,
- &keyring_name,
- &password)) {
- return FALSE;
- }
- g_assert (opcode == GNOME_KEYRING_OP_CREATE_KEYRING);
-
- if (keyring_name == NULL) {
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
- goto out;
- }
-
- keyring = gkr_keyrings_find (keyring_name);
- if (keyring != NULL) {
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_ALREADY_EXISTS);
- goto out;
- }
-
- /* Let user pick password if necessary*/
- if (!request_new_keyring_password (req, keyring_name, &password, &volume)) {
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_DENIED);
- goto out;
- }
-
- keyring = gkr_keyring_create (volume, keyring_name, password);
- if (keyring == NULL) {
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_DENIED);
- goto out;
- }
-
- /* Add to our main list */
- gkr_keyrings_add (keyring);
-
- /* Let go of the initial reference to this object */
- g_object_unref (keyring);
- g_assert (GKR_IS_KEYRING (keyring));
-
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_OK);
-
- out:
- g_free (keyring_name);
- egg_secure_strfree (password);
-
- return TRUE;
-}
-
-static gboolean
-op_unlock_keyring (EggBuffer *packet, EggBuffer *result,
- GkrKeyringRequest *req)
-{
- char *keyring_name, *password;
- GkrKeyring *keyring;
- GnomeKeyringOpCode opcode;
- GnomeKeyringResult res;
-
- if (!gkr_proto_decode_op_string_secret (packet,
- &opcode,
- &keyring_name,
- &password)) {
- return FALSE;
- }
- g_assert (opcode == GNOME_KEYRING_OP_UNLOCK_KEYRING);
-
- keyring = gkr_keyrings_find (keyring_name);
- if (!keyring) {
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_NO_SUCH_KEYRING);
- goto out;
-
- }
-
- /* User types password */
- if (password == NULL) {
- if (request_keyring_access (req, keyring))
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_OK);
- else
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_DENIED);
-
- /* Password specified */
- } else {
- if (gkr_keyring_unlock (keyring, password))
- res = GNOME_KEYRING_RESULT_OK;
- else
- res = GNOME_KEYRING_RESULT_DENIED;
- egg_buffer_add_uint32 (result, res);
- }
-
- out:
- g_free (keyring_name);
- egg_secure_strfree (password);
-
- return TRUE;
-}
-
-
-static gboolean
-op_delete_keyring (EggBuffer *packet, EggBuffer *result,
- GkrKeyringRequest *req)
-{
- char *keyring_name;
- GkrKeyring *keyring = NULL;
- GnomeKeyringOpCode opcode;
- GnomeKeyringResult res;
-
- if (!gkr_proto_decode_op_string (packet, &opcode, &keyring_name))
- return FALSE;
-
- g_assert (opcode == GNOME_KEYRING_OP_DELETE_KEYRING);
-
- if (keyring_name == NULL) {
- res = GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
- } else {
- keyring = gkr_keyrings_find (keyring_name);
- if (keyring == NULL) {
- res = GNOME_KEYRING_RESULT_NO_SUCH_KEYRING;
- } else {
- if (!gkr_keyring_remove_from_disk (keyring))
- res = GNOME_KEYRING_RESULT_DENIED;
- else
- res = GNOME_KEYRING_RESULT_OK;
- }
- }
-
- egg_buffer_add_uint32 (result, res);
- g_free (keyring_name);
-
- if (res == GNOME_KEYRING_RESULT_OK)
- gkr_keyrings_remove (keyring);
-
- return TRUE;
-}
-
-static gboolean
-op_change_keyring_password (EggBuffer *packet, EggBuffer *result,
- GkrKeyringRequest *req)
-{
- char *keyring_name, *original, *password;
- GkrKeyring *keyring;
- GnomeKeyringOpCode opcode;
-
- if (!gkr_proto_decode_op_string_secret_secret (packet,
- &opcode,
- &keyring_name,
- &original,
- &password)) {
- return FALSE;
- }
- g_assert (opcode == GNOME_KEYRING_OP_CHANGE_KEYRING_PASSWORD);
-
- if (keyring_name == NULL) {
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_BAD_ARGUMENTS);
- goto out;
- }
-
- keyring = gkr_keyrings_find (keyring_name);
- if (keyring == NULL) {
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_NO_SUCH_KEYRING);
- goto out;
- }
-
- /* Prompt for any missing passwords */
- if (!request_change_keyring_password (req, keyring, &original, &password)) {
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_DENIED);
- goto out;
- }
-
- gkr_keyring_lock (keyring);
-
- if (!gkr_keyring_unlock (keyring, original)) {
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_DENIED);
- goto out;
- }
-
- egg_buffer_add_uint32 (result, change_keyring_password (keyring, password));
-
- out:
- g_free (keyring_name);
- egg_secure_strfree (original);
- egg_secure_strfree (password);
-
- return TRUE;
-}
-
-static gboolean
-op_list_items (EggBuffer *packet, EggBuffer *result,
- GkrKeyringRequest *req)
-{
- GkrKeyring *keyring;
- char *keyring_name;
- GnomeKeyringOpCode opcode;
- GkrKeyringItem *item;
- GList *l, *items;
-
- if (!gkr_proto_decode_op_string (packet, &opcode, &keyring_name))
- return FALSE;
-
- keyring = gkr_keyrings_find (keyring_name);
- if (keyring == NULL) {
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_NO_SUCH_KEYRING);
- egg_buffer_add_uint32 (result, 0);
-
- } else if (!request_keyring_access (req, keyring)) {
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_DENIED);
- egg_buffer_add_uint32 (result, 0);
-
- } else {
-
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_OK);
-
- items = NULL;
- for (l = keyring->items; l != NULL; l = l->next) {
- if (acl_check_access (l->data, req->app_ref, GNOME_KEYRING_ACCESS_LIST, FALSE))
- items = g_list_prepend (items, l->data);
- }
- items = g_list_reverse (items);
-
- /* Send the results */
- egg_buffer_add_uint32 (result, g_list_length (items));
- for (l = items; l != NULL; l = l->next) {
- item = l->data;
- egg_buffer_add_uint32 (result, item->id);
- }
-
- g_list_free (items);
- }
-
- g_free (keyring_name);
-
- return TRUE;
-}
-
-static gboolean
-op_create_item (EggBuffer *packet, EggBuffer *result,
- GkrKeyringRequest *req)
-{
- char *keyring_name, *display_name, *secret;
- GnomeKeyringAttributeList *attributes, *hashed;
- GkrKeyringItem *item;
- GkrKeyring *keyring;
- guint32 type;
- GnomeKeyringResult res;
- guint32 id;
- gboolean update_if_exists;
-
- keyring_name = display_name = secret = NULL;
- item = NULL;
- attributes = hashed = NULL;
-
- res = GNOME_KEYRING_RESULT_OK;
- id = 0;
-
- if (!gkr_proto_decode_create_item (packet,
- &keyring_name,
- &display_name,
- &attributes,
- &secret,
- (GnomeKeyringItemType*)&type,
- &update_if_exists)) {
- return FALSE;
- }
-
- if (display_name == NULL || secret == NULL) {
- res = GNOME_KEYRING_RESULT_BAD_ARGUMENTS;
- goto out;
- }
-
- keyring = gkr_keyrings_find (keyring_name);
-
- /* Prompt user to create a new keyring if none exists */
- if (keyring == NULL && keyring_name == NULL) {
- keyring = create_default_keyring (req);
- if (keyring == NULL) {
- res = GNOME_KEYRING_RESULT_DENIED;
- goto out;
- }
- }
-
- /* Make sure we have access to the keyring */
- if (keyring != NULL) {
- if (!request_keyring_access (req, keyring)) {
- res = GNOME_KEYRING_RESULT_DENIED;
- goto out;
- }
-
- /* No such keyring found */
- } else {
- res = GNOME_KEYRING_RESULT_NO_SUCH_KEYRING;
- goto out;
- }
-
- if (update_if_exists) {
- item = gkr_keyring_find_item (keyring, type, keyring->locked ? hashed : attributes, TRUE);
- if (item) {
- /* Make sure we have access to the previous item */
- if (!request_item_access (req, item, GNOME_KEYRING_ACCESS_WRITE, TRUE))
- item = NULL;
- }
- }
-
- if (!item) {
- item = gkr_keyring_item_create (keyring, type);
- gkr_keyring_add_item (keyring, item);
- g_object_unref (item);
- }
-
- /* Copy in item type flags */
- item->type |= (type & ~GNOME_KEYRING_ITEM_TYPE_MASK);
-
- g_free (item->display_name);
- item->display_name = g_strdup (display_name);
- egg_secure_strfree (item->secret);
- item->secret = egg_secure_strdup (secret);
- gnome_keyring_attribute_list_free (item->attributes);
- item->attributes = gnome_keyring_attribute_list_copy (attributes);
-
- add_item_acl (item, req->app_ref,
- GNOME_KEYRING_ACCESS_READ |
- GNOME_KEYRING_ACCESS_WRITE |
- GNOME_KEYRING_ACCESS_REMOVE);
-
- id = item->id;
- gkr_keyring_save_to_disk (keyring);
-
- out:
- g_free (keyring_name);
- g_free (display_name);
- egg_secure_strfree (secret);
- gnome_keyring_attribute_list_free (hashed);
- gnome_keyring_attribute_list_free (attributes);
-
- egg_buffer_add_uint32 (result, res);
- egg_buffer_add_uint32 (result, id);
- return TRUE;
-}
-
-static gboolean
-op_delete_item (EggBuffer *packet, EggBuffer *result,
- GkrKeyringRequest *req)
-{
- char *keyring_name;
- GkrKeyring *keyring;
- GkrKeyringItem *item;
- GnomeKeyringOpCode opcode;
- guint32 item_id;
- GnomeKeyringResult res;
-
- if (!gkr_proto_decode_op_string_int (packet,
- &opcode,
- &keyring_name,
- &item_id)) {
- return FALSE;
- }
-
- /* Request access based on what parts were desired */
- res = lookup_and_request_item_access (req,
- keyring_name,
- item_id,
- GNOME_KEYRING_ACCESS_REMOVE,
- TRUE,
- &item);
-
- egg_buffer_add_uint32 (result, res);
- if (res == GNOME_KEYRING_RESULT_OK) {
- if (item->keyring) {
- keyring = item->keyring;
- gkr_keyring_remove_item (keyring, item);
- gkr_keyring_save_to_disk (keyring);
- }
- }
-
- g_free (keyring_name);
- return TRUE;
-}
-
-static gboolean
-op_get_item_info (EggBuffer *packet, EggBuffer *result,
- GkrKeyringRequest *req)
-{
- char *keyring_name, *secret;
- GkrKeyringItem *item;
- GnomeKeyringOpCode opcode;
- guint32 item_id, flags;
- gboolean ret = TRUE;
- GnomeKeyringResult res;
-
- if (!gkr_proto_decode_get_item_info (packet, &opcode, &keyring_name,
- &item_id, &flags)) {
- return FALSE;
- }
-
- /* Request access based on what parts were desired */
- res = lookup_and_request_item_access (req,
- keyring_name,
- item_id,
- GNOME_KEYRING_ACCESS_READ,
- (flags & GNOME_KEYRING_ITEM_INFO_SECRET) == GNOME_KEYRING_ITEM_INFO_SECRET,
- &item);
-
- egg_buffer_add_uint32 (result, res);
- if (res == GNOME_KEYRING_RESULT_OK) {
- egg_buffer_add_uint32 (result, item->type);
- if (!gkr_proto_add_utf8_string (result, item->display_name))
- ret = FALSE;
-
- /* Only return the secret if it was requested */
- secret = NULL;
- if ((flags & GNOME_KEYRING_ITEM_INFO_SECRET) == GNOME_KEYRING_ITEM_INFO_SECRET)
- secret = item->secret;
-
- /* Always put the secret string or NULL in the results for compatibility */
- if (!gkr_proto_add_utf8_secret (result, secret))
- ret = FALSE;
-
- gkr_proto_add_time (result, item->mtime);
- gkr_proto_add_time (result, item->ctime);
- }
-
- g_free (keyring_name);
- return ret;
-}
-
-static gboolean
-op_get_item_attributes (EggBuffer *packet, EggBuffer *result,
- GkrKeyringRequest *req)
-{
- char *keyring_name;
- GkrKeyringItem *item;
- GnomeKeyringOpCode opcode;
- guint32 item_id;
- gboolean ret = TRUE;
- GnomeKeyringResult res;
-
- if (!gkr_proto_decode_op_string_int (packet,
- &opcode,
- &keyring_name,
- &item_id)) {
- return FALSE;
- }
-
- res = lookup_and_request_item_access (req,
- keyring_name,
- item_id,
- GNOME_KEYRING_ACCESS_READ,
- FALSE,
- &item);
-
- egg_buffer_add_uint32 (result, res);
- if (res == GNOME_KEYRING_RESULT_OK) {
- if (!gkr_proto_add_attribute_list (result, item->attributes))
- ret = FALSE;
- }
-
- g_free (keyring_name);
- return ret;
-}
-
-static gboolean
-op_get_item_acl (EggBuffer *packet, EggBuffer *result,
- GkrKeyringRequest *req)
-{
- char *keyring_name;
- GkrKeyringItem *item;
- GnomeKeyringOpCode opcode;
- guint32 item_id;
- gboolean ret = TRUE;
- GnomeKeyringResult res;
-
- if (!gkr_proto_decode_op_string_int (packet,
- &opcode,
- &keyring_name,
- &item_id)) {
- return FALSE;
- }
-
- res = lookup_and_request_item_access (req,
- keyring_name,
- item_id,
- GNOME_KEYRING_ACCESS_READ,
- FALSE,
- &item);
-
- egg_buffer_add_uint32 (result, res);
- if (res == GNOME_KEYRING_RESULT_OK) {
- if (!gkr_proto_add_acl (result, item->acl))
- ret = FALSE;
- }
-
- g_free (keyring_name);
- return ret;
-}
-
-static gboolean
-op_set_item_acl (EggBuffer *packet, EggBuffer *result,
- GkrKeyringRequest *req)
-{
- char *keyring_name;
- GkrKeyringItem *item;
- guint32 item_id;
- GList *acl;
- GnomeKeyringResult res;
-
- if (!gkr_proto_decode_set_acl (packet,
- &keyring_name,
- &item_id,
- &acl)) {
- return FALSE;
- }
-
- res = lookup_and_request_item_access (req,
- keyring_name,
- item_id,
- GNOME_KEYRING_ACCESS_WRITE,
- TRUE,
- &item);
-
- if (res == GNOME_KEYRING_RESULT_OK) {
- gnome_keyring_acl_free (item->acl);
- item->acl = gnome_keyring_acl_copy (acl);
-
- if (item->keyring)
- gkr_keyring_save_to_disk (item->keyring);
- }
-
- egg_buffer_add_uint32 (result, res);
-
- gnome_keyring_acl_free (acl);
- g_free (keyring_name);
- return TRUE;
-}
-
-static gboolean
-op_set_item_info (EggBuffer *packet, EggBuffer *result,
- GkrKeyringRequest *req)
-{
- char *keyring_name;
- GkrKeyringItem *item;
- guint32 item_id, type;
- char *item_name, *secret;
- GnomeKeyringResult res;
-
- if (!gkr_proto_decode_set_item_info (packet,
- &keyring_name,
- &item_id,
- (GnomeKeyringItemType*)&type,
- &item_name,
- &secret)) {
- return FALSE;
- }
-
- res = lookup_and_request_item_access (req,
- keyring_name,
- item_id,
- GNOME_KEYRING_ACCESS_WRITE,
- TRUE,
- &item);
-
- egg_buffer_add_uint32 (result, res);
- if (res == GNOME_KEYRING_RESULT_OK) {
- if ((type & GNOME_KEYRING_ITEM_TYPE_MASK) != GNOME_KEYRING_ITEM_NO_TYPE) {
- item->type = type;
- }
- if (item_name != NULL) {
- g_free (item->display_name);
- item->display_name = g_strdup (item_name);
- }
- if (secret != NULL) {
- egg_secure_strfree (item->secret);
- item->secret = egg_secure_strdup (secret);
- }
-
- if (item->keyring)
- gkr_keyring_save_to_disk (item->keyring);
- }
-
- g_free (keyring_name);
- g_free (item_name);
- egg_secure_strfree (secret);
- return TRUE;
-}
-
-static gboolean
-op_set_daemon_display (EggBuffer *packet, EggBuffer *result,
- GkrKeyringRequest *req)
-{
- char *display;
- GnomeKeyringOpCode opcode;
-
- if (!gkr_proto_decode_op_string (packet, &opcode, &display))
- return FALSE;
-
- if (display == NULL) {
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_DENIED);
- } else {
- g_setenv ("DISPLAY", display, FALSE);
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_OK);
- }
-
- g_free (display);
- return TRUE;
-}
-
-static gboolean
-op_set_item_attributes (EggBuffer *packet, EggBuffer *result,
- GkrKeyringRequest *req)
-{
- char *keyring_name;
- GkrKeyringItem *item;
- guint32 item_id;
- GnomeKeyringResult res;
- GnomeKeyringAttributeList *attributes;
-
- if (!gkr_proto_decode_set_attributes (packet,
- &keyring_name,
- &item_id,
- &attributes)) {
- return FALSE;
- }
-
- res = lookup_and_request_item_access (req,
- keyring_name,
- item_id,
- GNOME_KEYRING_ACCESS_WRITE,
- TRUE,
- &item);
-
- egg_buffer_add_uint32 (result, res);
- if (res == GNOME_KEYRING_RESULT_OK) {
- gnome_keyring_attribute_list_free (item->attributes);
- item->attributes = gnome_keyring_attribute_list_copy (attributes);
-
- if (item->keyring)
- gkr_keyring_save_to_disk (item->keyring);
- }
-
- g_free (keyring_name);
- gnome_keyring_attribute_list_free (attributes);
- return TRUE;
-}
-
-static int
-unmatched_attributes (GnomeKeyringAttributeList *attributes,
- GnomeKeyringAttributeList *matching)
-{
- int i, j;
- GnomeKeyringAttribute *matching_attribute;
- GnomeKeyringAttribute *attribute;
- gboolean found;
- int unmatching;
-
- unmatching = 0;
- for (i = 0; i < attributes->len; i++) {
- found = FALSE;
- attribute = &g_array_index (attributes,
- GnomeKeyringAttribute,
- i);
- for (j = 0; j < matching->len; j++) {
- matching_attribute = &g_array_index (matching,
- GnomeKeyringAttribute,
- j);
- if (strcmp (attribute->name, matching_attribute->name) == 0 &&
- attribute->type == matching_attribute->type) {
- found = TRUE;
- break;
- }
- }
- if (!found) {
- unmatching++;
- }
- }
-
- return unmatching;;
-}
-
-static gint
-sort_found (gconstpointer a, gconstpointer b, gpointer user_data)
-{
- GnomeKeyringAttributeList *matching;
- int a_unmatched, b_unmatched;
- GkrKeyringItem *item;
-
- matching = user_data;
-
- item = GKR_KEYRING_ITEM (a);
- g_assert (GKR_IS_KEYRING_ITEM (item));
- a_unmatched = unmatched_attributes (item->attributes, matching);
-
- item = GKR_KEYRING_ITEM (b);
- g_assert (GKR_IS_KEYRING_ITEM (item));
- b_unmatched = unmatched_attributes (item->attributes, matching);
-
- if (a_unmatched < b_unmatched)
- return -1;
- else if (a_unmatched == b_unmatched)
- return 0;
- else
- return 1;
-}
-
-typedef struct _FindContext {
- GnomeKeyringAttributeList *attributes;
- GnomeKeyringAttributeList *hashed;
- GnomeKeyringItemType type;
- GkrKeyringRequest *req;
- guint nfound;
- GList *items;
-} FindContext;
-
-static gboolean
-find_in_each_keyring (GkrKeyring* keyring, gpointer data)
-{
- FindContext* ctx = (FindContext*)data;
- GkrKeyringItem *item;
- GList *ilist;
-
- g_object_ref (keyring);
-
- for (ilist = keyring->items; ilist != NULL; ilist = ilist->next) {
- item = ilist->data;
- if (!gkr_keyring_item_match (item, ctx->type, keyring->locked ? ctx->hashed : ctx->attributes, FALSE))
- continue;
-
- ++ctx->nfound;
-
- if (keyring->locked) {
- if (!request_keyring_access (ctx->req, keyring))
- break;
- }
-
- if (request_item_access (ctx->req, item, GNOME_KEYRING_ACCESS_READ, TRUE)) {
- g_object_ref (item);
- ctx->items = g_list_prepend (ctx->items, item);
- }
- }
-
- g_object_unref (keyring);
-
- return TRUE;
-}
-
-static void
-unref_object (gpointer obj, gpointer data)
-{
- g_object_unref (obj);
-}
-
-static gboolean
-op_find (EggBuffer *packet, EggBuffer *result, GkrKeyringRequest *req)
-{
- FindContext ctx;
- GList *l;
- gboolean return_val;
-
- memset (&ctx, 0, sizeof (ctx));
-
- if (!gkr_proto_decode_find (packet,
- &ctx.type,
- &ctx.attributes)) {
- return FALSE;
- }
-
- /* Need at least one attribute to match on */
- if (ctx.attributes->len > 0) {
- ctx.hashed = gkr_attribute_list_hash (ctx.attributes);
- ctx.nfound = 0;
- ctx.req = req;
- ctx.items = NULL;
- gkr_keyrings_foreach (find_in_each_keyring, &ctx);
- }
-
- /* No items given access to */
- if (ctx.nfound > 0 && ctx.items == NULL)
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_DENIED);
-
- /* Zero items matched */
- else if (ctx.nfound == 0)
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_NO_MATCH);
-
- /* More than one item found and given access to */
- else
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_OK);
-
- ctx.items = g_list_sort_with_data (ctx.items, sort_found, ctx.attributes);
-
- /* The attributes might have changed since we matched them, rematch */
- return_val = TRUE;
- for (l = ctx.items; l; l = g_list_next (l)) {
- GkrKeyringItem *item = GKR_KEYRING_ITEM (l->data);
-
- if (!item->locked && gkr_keyring_item_match (item, ctx.type, ctx.attributes, FALSE)) {
-
- /* Add it to the output */
- if (!gkr_proto_add_utf8_string (result, item->keyring->keyring_name)) {
- return_val = FALSE;
- break;
- }
-
- egg_buffer_add_uint32 (result, item->id);
-
- if (!gkr_proto_add_utf8_secret (result, item->secret) ||
- !gkr_proto_add_attribute_list (result, item->attributes)) {
- return_val = FALSE;
- break;
- }
- }
- }
-
- g_list_foreach (ctx.items, unref_object, NULL);
- g_list_free (ctx.items);
-
- gnome_keyring_attribute_list_free (ctx.attributes);
- gnome_keyring_attribute_list_free (ctx.hashed);
-
- return return_val;
-}
-
-static gboolean
-op_prepare_daemon_environment (EggBuffer *packet, EggBuffer *result, GkrKeyringRequest *req)
-{
- const gchar **daemonenv;
- gchar **environment, **e;
- gchar *x;
- gint i;
-
- if (!gkr_proto_decode_prepare_environment (packet, &environment))
- return FALSE;
-
- /* Accept environment from outside */
- for (e = environment; *e; ++e) {
- x = strchr (*e, '=');
- if (x) {
- *(x++) = 0;
-
- /* We're only interested in these environment variables */
- for (i = 0; GNOME_KEYRING_IN_ENVIRONMENT[i] != NULL; ++i) {
- if (g_str_equal (*e, GNOME_KEYRING_IN_ENVIRONMENT[i]))
- {
- g_setenv (*e, x, FALSE);
- break;
- }
- }
- }
- }
-
- g_strfreev (environment);
-
- /*
- * We've now definitely received everything we need to run. Ask
- * the daemon to complete the initialization.
- */
- gkd_main_complete_initialization();
-
- egg_buffer_add_uint32 (result, GNOME_KEYRING_RESULT_OK);
-
- /* These are the environment variables that the daemon setup */
- daemonenv = gkd_util_get_environment ();
- g_return_val_if_fail (daemonenv, FALSE);
-
- egg_buffer_add_stringv (result, daemonenv);
- return TRUE;
-}
-
-GkrDaemonOperation keyring_ops[] = {
- op_lock_all, /* LOCK_ALL */
- op_set_default_keyring, /* SET_DEFAULT_KEYRING */
- op_get_default_keyring, /* GET_DEFAULT_KEYRING */
- op_list_keyrings, /* LIST_KEYRINGS */
- op_create_keyring, /* CREATE_KEYRING */
- op_lock_keyring, /* LOCK_KEYRING */
- op_unlock_keyring, /* UNLOCK_KEYRING */
- op_delete_keyring, /* DELETE_KEYRING */
- op_get_keyring_info, /* GET_KEYRING_INFO */
- op_set_keyring_info, /* SET_KEYRING_INFO */
- op_list_items, /* LIST_ITEMS */
- op_find, /* FIND */
- op_create_item, /* CREATE_ITEM */
- op_delete_item, /* DELETE_ITEM */
- op_get_item_info, /* GET_ITEM_INFO */
- op_set_item_info, /* SET_ITEM_INFO */
- op_get_item_attributes, /* GET_ITEM_ATTRIBUTES */
- op_set_item_attributes, /* SET_ITEM_ATTRIBUTES */
- op_get_item_acl, /* GET_ITEM_ACL */
- op_set_item_acl, /* SET_ITEM_ACL */
- op_change_keyring_password, /* CHANGE_KEYRING_PASSWORD */
- op_set_daemon_display, /* SET_DAEMON_DISPLAY */
- op_get_item_info, /* GET_ITEM_INFO_PARTIAL */
- op_prepare_daemon_environment, /* PREPARE_DAEMON_ENVIRONMENT */
-};
diff --git a/daemon/gkr-daemon.h b/daemon/gkr-daemon.h
deleted file mode 100644
index b843f24d..00000000
--- a/daemon/gkr-daemon.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* gnome-keyring-daemon.h - common includes for the keyring daemon code
-
- Copyright (C) 2003 Red Hat, Inc
-
- Gnome keyring is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- Gnome keyring 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
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- Author: Alexander Larsson <alexl@redhat.com>
-*/
-
-#ifndef GNOME_KEYRING_DAEMON_H
-#define GNOME_KEYRING_DAEMON_H
-
-#include <time.h>
-#include <sys/types.h>
-#include <glib.h>
-
-#include "egg/egg-buffer.h"
-
-#include "keyrings/gkr-keyring.h"
-#include "keyrings/gkr-keyring-item.h"
-
-#include "library/gnome-keyring.h"
-#include "library/gnome-keyring-private.h"
-
-
-typedef struct {
- GnomeKeyringApplicationRef *app_ref;
-} GkrKeyringRequest;
-
-typedef gboolean (*GkrDaemonOperation) (EggBuffer *packet, EggBuffer *result,
- GkrKeyringRequest *req);
-
-extern GkrDaemonOperation keyring_ops[];
-
-gboolean gkr_daemon_io_create_master_socket (void);
-
-const gchar* gkr_daemon_io_get_socket_path (void);
-
-#endif /* GNOME_KEYRING_DAEMON_H */
diff --git a/daemon/keyrings/.gitignore b/daemon/keyrings/.gitignore
deleted file mode 100644
index 76e62b4c..00000000
--- a/daemon/keyrings/.gitignore
+++ /dev/null
@@ -1,6 +0,0 @@
-/Makefile.in
-/Makefile
-/.*
-/.deps
-/.libs
-/*.loT
diff --git a/daemon/keyrings/Makefile.am b/daemon/keyrings/Makefile.am
deleted file mode 100644
index 259ae54e..00000000
--- a/daemon/keyrings/Makefile.am
+++ /dev/null
@@ -1,36 +0,0 @@
-noinst_LTLIBRARIES=libgkr-keyrings.la
-
-INCLUDES= \
- -DPREFIX=\""$(prefix)"\" \
- -DBINDIR=\""$(bindir)"\" \
- -DLIBEXECDIR=\""$(libexecdir)"\" \
- -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
- -I$(top_srcdir) \
- -I$(top_srcdir)/daemon \
- -I$(top_builddir) \
- $(DAEMON_CFLAGS) \
- $(GOBJECT_CFLAGS) \
- $(GLIB_CFLAGS)
-
-libgkr_keyrings_la_SOURCES = \
- gkr-keyring.c gkr-keyring.h \
- gkr-keyring-binary.c gkr-keyring-textual.c \
- gkr-keyring-item.c gkr-keyring-item.h \
- gkr-keyrings.c gkr-keyrings.h \
- gkr-keyring-login.c gkr-keyring-login.h
-
-libgkr_keyrings_la_LIBADD = \
- $(GLIB_LIBS) \
- $(GOBJECT_LIBS)
-
-EXTRA_DIST = \
- file-format.txt
-
-if WITH_TESTS
-TESTS_DIR = tests
-else
-TESTS_DIR =
-endif
-
-SUBDIRS = . $(TESTS_DIR)
-
diff --git a/daemon/keyrings/gkr-keyring-binary.c b/daemon/keyrings/gkr-keyring-binary.c
deleted file mode 100644
index 7d12e8a4..00000000
--- a/daemon/keyrings/gkr-keyring-binary.c
+++ /dev/null
@@ -1,676 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* gkr-keyring-binary.c - The binary encrypted format of a keyring
-
- Copyright (C) 2003 Red Hat, Inc
- Copyright (C) 2007 Stefan Walter
-
- Gnome keyring is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- Gnome keyring 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
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- Author: Alexander Larsson <alexl@redhat.com>
- Author: Stef Walter <stef@memberwebs.com>
-*/
-
-#include "config.h"
-
-#include "gkr-keyring.h"
-#include "gkr-keyring-item.h"
-
-#include "egg/egg-buffer.h"
-#include "egg/egg-symkey.h"
-#include "egg/egg-secure-memory.h"
-
-#include "library/gnome-keyring-private.h"
-#include "library/gnome-keyring-proto.h"
-
-#include <glib.h>
-
-#include <gcrypt.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-/* -----------------------------------------------------------------------------
- * DECLARATIONS
- */
-
-#define LOCK_ON_IDLE_FLAG (1<<0)
-
-typedef struct {
- /* unencrypted: */
- guint32 id;
- guint32 type;
- GnomeKeyringAttributeList *hashed_attributes;
-
- /* encrypted: */
- char *display_name;
- char *secret;
- time_t ctime;
- time_t mtime;
- GnomeKeyringAttributeList *attributes;
- GList *acl;
-} ItemInfo;
-
-#define KEYRING_FILE_HEADER "GnomeKeyring\n\r\0\n"
-#define KEYRING_FILE_HEADER_LEN 16
-
-/* -----------------------------------------------------------------------------
- * BINARY ENCRYPTED FILE FORMAT
- */
-
-static gboolean
-encrypt_buffer (EggBuffer *buffer,
- const char *password,
- guchar salt[8],
- int iterations)
-{
- gcry_cipher_hd_t cih;
- gcry_error_t gerr;
- guchar *key, *iv;
- size_t pos;
-
- g_assert (buffer->len % 16 == 0);
- g_assert (16 == gcry_cipher_get_algo_blklen (GCRY_CIPHER_AES128));
- g_assert (16 == gcry_cipher_get_algo_keylen (GCRY_CIPHER_AES128));
-
- if (!egg_symkey_generate_simple (GCRY_CIPHER_AES128, GCRY_MD_SHA256,
- password, -1, salt, 8, iterations, &key, &iv))
- return FALSE;
-
- gerr = gcry_cipher_open (&cih, GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CBC, 0);
- if (gerr) {
- g_warning ("couldn't create aes cipher context: %s",
- gcry_strerror (gerr));
- egg_secure_free (key);
- g_free (iv);
- return FALSE;
- }
-
- /* 16 = 128 bits */
- gerr = gcry_cipher_setkey (cih, key, 16);
- g_return_val_if_fail (!gerr, FALSE);
- egg_secure_free (key);
-
- /* 16 = 128 bits */
- gerr = gcry_cipher_setiv (cih, iv, 16);
- g_return_val_if_fail (!gerr, FALSE);
- g_free (iv);
-
- for (pos = 0; pos < buffer->len; pos += 16) {
- /* In place encryption */
- gerr = gcry_cipher_encrypt (cih, buffer->buf + pos, 16, NULL, 0);
- g_return_val_if_fail (!gerr, FALSE);
- }
-
- gcry_cipher_close (cih);
-
- return TRUE;
-}
-
-static gboolean
-decrypt_buffer (EggBuffer *buffer,
- const char *password,
- guchar salt[8],
- int iterations)
-{
- gcry_cipher_hd_t cih;
- gcry_error_t gerr;
- guchar *key, *iv;
- size_t pos;
-
- g_assert (buffer->len % 16 == 0);
- g_assert (16 == gcry_cipher_get_algo_blklen (GCRY_CIPHER_AES128));
- g_assert (16 == gcry_cipher_get_algo_keylen (GCRY_CIPHER_AES128));
-
- if (!egg_symkey_generate_simple (GCRY_CIPHER_AES128, GCRY_MD_SHA256,
- password, -1, salt, 8, iterations, &key, &iv))
- return FALSE;
-
- gerr = gcry_cipher_open (&cih, GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CBC, 0);
- if (gerr) {
- g_warning ("couldn't create aes cipher context: %s",
- gcry_strerror (gerr));
- egg_secure_free (key);
- g_free (iv);
- return FALSE;
- }
-
- /* 16 = 128 bits */
- gerr = gcry_cipher_setkey (cih, key, 16);
- g_return_val_if_fail (!gerr, FALSE);
- egg_secure_free (key);
-
- /* 16 = 128 bits */
- gerr = gcry_cipher_setiv (cih, iv, 16);
- g_return_val_if_fail (!gerr, FALSE);
- g_free (iv);
-
- for (pos = 0; pos < buffer->len; pos += 16) {
- /* In place encryption */
- gerr = gcry_cipher_decrypt (cih, buffer->buf + pos, 16, NULL, 0);
- g_return_val_if_fail (!gerr, FALSE);
- }
-
- gcry_cipher_close (cih);
-
- return TRUE;
-}
-
-static gboolean
-verify_decrypted_buffer (EggBuffer *buffer)
-{
- guchar digest[16];
-
- /* In case the world changes on us... */
- g_return_val_if_fail (gcry_md_get_algo_dlen (GCRY_MD_MD5) == sizeof (digest), 0);
-
- gcry_md_hash_buffer (GCRY_MD_MD5, (void*)digest,
- (guchar*)buffer->buf + 16, buffer->len - 16);
-
- return memcmp (buffer->buf, digest, 16) == 0;
-}
-
-static gboolean
-generate_acl_data (EggBuffer *buffer, GList *acl)
-{
- GList *l;
- GnomeKeyringAccessControl *ac;
-
- egg_buffer_add_uint32 (buffer, g_list_length (acl));
-
- for (l = acl; l != NULL; l = l->next) {
- ac = l->data;
-
- egg_buffer_add_uint32 (buffer, ac->types_allowed);
- 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;
- }
- /* Reserved: */
- if (!gkr_proto_add_utf8_string (buffer, NULL)) {
- return FALSE;
- }
- egg_buffer_add_uint32 (buffer, 0);
- }
-
- return TRUE;
-}
-
-static gboolean
-generate_encrypted_data (EggBuffer *buffer, GkrKeyring *keyring)
-{
- GList *l;
- int i;
- GkrKeyringItem *item;
-
- /* Make sure we're using non-pageable memory */
- gkr_proto_go_secure (buffer);
-
- for (l = keyring->items; l != NULL; l = l->next) {
- item = l->data;
- if (!gkr_proto_add_utf8_string (buffer, item->display_name)) {
- return FALSE;
- }
- if (!gkr_proto_add_utf8_secret (buffer, item->secret)) {
- return FALSE;
- }
- gkr_proto_add_time (buffer, item->ctime);
- gkr_proto_add_time (buffer, item->mtime);
-
- /* reserved: */
- if (!gkr_proto_add_utf8_string (buffer, NULL)) {
- return FALSE;
- }
- for (i = 0; i < 4; i++) {
- egg_buffer_add_uint32 (buffer, 0);
- }
-
- if (!gkr_proto_add_attribute_list (buffer, item->attributes)) {
- return FALSE;
- }
- if (!generate_acl_data (buffer, item->acl)) {
- return FALSE;
- }
- }
- return TRUE;
-}
-
-gboolean
-gkr_keyring_binary_generate (GkrKeyring *keyring, EggBuffer *buffer)
-{
- guint flags;
- GList *l;
- GkrKeyringItem *item;
- GnomeKeyringAttributeList *hashed;
- EggBuffer to_encrypt;
- guchar digest[16];
- int i;
-
- /* In case the world changes on us... */
- g_return_val_if_fail (gcry_md_get_algo_dlen (GCRY_MD_MD5) == sizeof (digest), FALSE);
-
- g_assert (!keyring->locked);
-
- /* Prepare the keyring for encryption */
- if (!keyring->salt_valid) {
- keyring->hash_iterations = 1000 + (int) (1000.0 * rand() / (RAND_MAX + 1.0));
- gcry_create_nonce (keyring->salt, sizeof (keyring->salt));
- keyring->salt_valid = TRUE;
- }
-
- egg_buffer_append (buffer, (guchar*)KEYRING_FILE_HEADER, KEYRING_FILE_HEADER_LEN);
- egg_buffer_add_byte (buffer, 0); /* Major version */
- egg_buffer_add_byte (buffer, 0); /* Minor version */
- egg_buffer_add_byte (buffer, 0); /* crypto (0 == AEL) */
- egg_buffer_add_byte (buffer, 0); /* hash (0 == MD5) */
-
- if (!gkr_proto_add_utf8_string (buffer, keyring->keyring_name)) {
- return FALSE;
- }
-
- gkr_proto_add_time (buffer, keyring->mtime);
- gkr_proto_add_time (buffer, keyring->ctime);
-
- flags = 0;
- if (keyring->lock_on_idle) {
- flags |= 1;
- }
- egg_buffer_add_uint32 (buffer, flags);
- egg_buffer_add_uint32 (buffer, keyring->lock_timeout);
- egg_buffer_add_uint32 (buffer, keyring->hash_iterations);
- egg_buffer_append (buffer, (guchar*)keyring->salt, 8);
-
- /* Reserved: */
- for (i = 0; i < 4; i++) {
- egg_buffer_add_uint32 (buffer, 0);
- }
-
- /* Hashed items: */
- egg_buffer_add_uint32 (buffer, g_list_length (keyring->items));
-
- for (l = keyring->items; l != NULL; l = l->next) {
- item = l->data;
- egg_buffer_add_uint32 (buffer, item->id);
- egg_buffer_add_uint32 (buffer, item->type);
-
- hashed = gkr_attribute_list_hash (item->attributes);
-
- if (!gkr_proto_add_attribute_list (buffer, hashed)) {
- gnome_keyring_attribute_list_free (hashed);
- return FALSE;
- }
- gnome_keyring_attribute_list_free (hashed);
- }
-
- /* Encrypted data. Use non-pageable memory */
- egg_buffer_init_full (&to_encrypt, 4096, egg_secure_realloc);
-
- egg_buffer_append (&to_encrypt, (guchar*)digest, 16); /* Space for hash */
-
- if (!generate_encrypted_data (&to_encrypt, keyring)) {
- egg_buffer_uninit (&to_encrypt);
- return FALSE;
- }
-
- /* Pad with zeros to multiple of 16 bytes */
- while (to_encrypt.len % 16 != 0) {
- egg_buffer_add_byte (&to_encrypt, 0);
- }
-
- gcry_md_hash_buffer (GCRY_MD_MD5, (void*)digest,
- (guchar*)to_encrypt.buf + 16, to_encrypt.len - 16);
- memcpy (to_encrypt.buf, digest, 16);
-
- /* This is either set by gnome_keyring_create, or when reading from disk */
- g_assert (keyring->hash_iterations);
-
- if (!encrypt_buffer (&to_encrypt, keyring->password, keyring->salt, keyring->hash_iterations)) {
- egg_buffer_uninit (&to_encrypt);
- return FALSE;
- }
- egg_buffer_add_uint32 (buffer, to_encrypt.len);
- egg_buffer_append (buffer, to_encrypt.buf, to_encrypt.len);
- egg_buffer_uninit (&to_encrypt);
-
- return TRUE;
-}
-
-static gboolean
-decode_acl (EggBuffer *buffer, gsize offset, gsize *offset_out, GList **out)
-{
- GList *acl;
- guint32 num_acs;
- guint32 x, y;
- int i;
- char *name, *path, *reserved;
- GnomeKeyringApplicationRef *app;
-
- acl = NULL;
-
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &num_acs)) {
- return FALSE;
- }
- for (i = 0; i < num_acs; i++) {
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &x)) {
- goto bail;
- }
- if (!gkr_proto_get_utf8_string (buffer, offset, &offset, &name)) {
- goto bail;
- }
- if (!gkr_proto_get_utf8_string (buffer, offset, &offset, &path)) {
- g_free (name);
- goto bail;
- }
- reserved = NULL;
- if (!gkr_proto_get_utf8_string (buffer, offset, &offset, &reserved)) {
- g_free (name);
- g_free (path);
- goto bail;
- }
- g_free (reserved);
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &y)) {
- g_free (name);
- g_free (path);
- goto bail;
- }
-
- app = g_new0 (GnomeKeyringApplicationRef, 1);
- app->display_name = name;
- app->pathname = path;
-
- acl = g_list_prepend (acl,
- gnome_keyring_access_control_new (app, x));
- }
-
- *offset_out = offset;
- *out = g_list_reverse (acl);
- return TRUE;
-
- bail:
- gnome_keyring_acl_free (acl);
- return FALSE;
-}
-
-static void
-remove_unavailable_item (gpointer key, gpointer dummy, GkrKeyring *keyring)
-{
- /* Called to remove items from a keyring that no longer exist */
-
- GkrKeyringItem *item;
- guint id = GPOINTER_TO_UINT (key);
-
- g_assert (GKR_IS_KEYRING (keyring));
-
- item = gkr_keyring_get_item (keyring, id);
- if (item)
- gkr_keyring_remove_item (keyring, item);
-}
-
-gint
-gkr_keyring_binary_parse (GkrKeyring *keyring, EggBuffer *buffer)
-{
- gsize offset;
- guchar major, minor, crypto, hash;
- guint32 flags;
- guint32 lock_timeout;
- time_t mtime, ctime;
- char *display_name;
- gsize n_secret;
- int i, j;
- guint32 tmp;
- guint32 num_items;
- guint32 crypto_size;
- guint32 hash_iterations;
- guchar salt[8];
- ItemInfo *items;
- EggBuffer to_decrypt = EGG_BUFFER_EMPTY;
- gboolean locked;
- GList *l;
- GHashTable *checks = NULL;
- GkrKeyringItem *item;
- char *reserved;
-
- display_name = NULL;
- items = 0;
-
- /* We're decrypting this, so use secure memory */
- egg_buffer_set_allocator (&to_decrypt, egg_secure_realloc);
-
- if (buffer->len < KEYRING_FILE_HEADER_LEN) {
- return 0;
- }
- if (memcmp (buffer->buf, KEYRING_FILE_HEADER, KEYRING_FILE_HEADER_LEN) != 0) {
- return 0;
- }
- offset = KEYRING_FILE_HEADER_LEN;
-
- major = buffer->buf[offset++];
- minor = buffer->buf[offset++];
- crypto = buffer->buf[offset++];
- hash = buffer->buf[offset++];
-
- if (major != 0 || minor != 0 ||
- crypto != 0 || hash != 0) {
- return -1;
- }
-
- if (!gkr_proto_get_utf8_string (buffer, offset, &offset, &display_name)) {
- goto bail;
- }
- if (!gkr_proto_get_time (buffer, offset, &offset, &ctime)) {
- goto bail;
- }
- if (!gkr_proto_get_time (buffer, offset, &offset, &mtime)) {
- goto bail;
- }
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &flags)) {
- goto bail;
- }
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &lock_timeout)) {
- goto bail;
- }
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &hash_iterations)) {
- goto bail;
- }
- if (!gkr_proto_get_bytes (buffer, offset, &offset, salt, 8)) {
- goto bail;
- }
-
- for (i = 0; i < 4; i++) {
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &tmp))
- goto bail;
- }
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &num_items)) {
- goto bail;
- }
-
- items = g_new0 (ItemInfo, num_items);
-
- for (i = 0; i < num_items; i++) {
- if (!egg_buffer_get_uint32 (buffer, offset, &offset,
- &items[i].id)) {
- goto bail;
- }
- if (!egg_buffer_get_uint32 (buffer, offset, &offset,
- &items[i].type)) {
- goto bail;
- }
- if (!gkr_proto_decode_attribute_list (buffer, offset, &offset,
- &items[i].hashed_attributes)) {
- goto bail;
- }
- }
-
- if (!egg_buffer_get_uint32 (buffer, offset, &offset,
- &crypto_size)) {
- goto bail;
- }
- /* Make the crypted part is the right size */
- if (crypto_size % 16 != 0)
- goto bail;
-
- /* Copy the data into to_decrypt into non-pageable memory */
- egg_buffer_init_static (&to_decrypt, buffer->buf + offset, crypto_size);
-
- locked = TRUE;
- if (keyring->password != NULL) {
-
- if (!decrypt_buffer (&to_decrypt, keyring->password, salt, hash_iterations)) {
- goto bail;
- }
- if (!verify_decrypted_buffer (&to_decrypt)) {
- egg_secure_strfree (keyring->password);
- keyring->password = NULL;
- } else {
- locked = FALSE;
- offset += 16; /* Skip hash */
- for (i = 0; i < num_items; i++) {
- if (!gkr_proto_get_utf8_string (buffer, offset, &offset,
- &items[i].display_name)) {
- goto bail;
- }
- if (!gkr_proto_get_raw_secret (buffer, offset, &offset,
- (guchar**)(&items[i].secret), &n_secret)) {
- goto bail;
- }
- /* We don't support binary secrets yet, skip */
- if (!g_utf8_validate ((gchar*)items[i].secret, n_secret, NULL)) {
- g_message ("discarding item with unsupported non-textual secret: %s",
- items[i].display_name);
- free (items[i].display_name);
- free (items[i].secret);
- continue;
- }
- if (!gkr_proto_get_time (buffer, offset, &offset,
- &items[i].ctime)) {
- goto bail;
- }
- if (!gkr_proto_get_time (buffer, offset, &offset,
- &items[i].mtime)) {
- goto bail;
- }
- reserved = NULL;
- if (!gkr_proto_get_utf8_string (buffer, offset, &offset, &reserved))
- goto bail;
- g_free (reserved);
- for (j = 0; j < 4; j++) {
- guint32 tmp;
- if (!egg_buffer_get_uint32 (buffer, offset, &offset, &tmp))
- goto bail;
- }
- if (!gkr_proto_decode_attribute_list (buffer, offset, &offset,
- &items[i].attributes)) {
- goto bail;
- }
-
- if (!decode_acl (buffer, offset, &offset, &items[i].acl)) {
- goto bail;
- }
- }
- }
- }
-
- /* Correctly read all data, possibly including the decrypted data.
- * Now update the keyring and items: */
-
- keyring->locked = locked;
- g_free (keyring->keyring_name);
- keyring->keyring_name = display_name;
- keyring->mtime = mtime;
- keyring->ctime = ctime;
- keyring->lock_on_idle = !!(flags & LOCK_ON_IDLE_FLAG);
- keyring->lock_timeout = lock_timeout;
- keyring->hash_iterations = hash_iterations;
- memcpy (keyring->salt, salt, 8);
- keyring->salt_valid = TRUE;
-
- /* Build a Hash table where we can track ids we haven't yet seen */
- checks = g_hash_table_new (g_direct_hash, g_direct_equal);
- for (l = keyring->items; l; l = g_list_next (l)) {
- item = GKR_KEYRING_ITEM (l->data);
- g_hash_table_insert (checks, GUINT_TO_POINTER (item->id), GINT_TO_POINTER (TRUE));
- }
-
- for (i = 0; i < num_items; i++) {
-
- /* We've seen this id */
- g_hash_table_remove (checks, GUINT_TO_POINTER (items[i].id));
-
- item = gkr_keyring_get_item (keyring, items[i].id);
- if (item == NULL) {
- item = gkr_keyring_item_new (keyring, items[i].id, items[i].type);
- gkr_keyring_add_item (keyring, item);
- g_object_unref (item);
- }
-
- item->locked = locked;
- item->type = items[i].type;
-
- g_free (item->display_name);
- item->display_name = NULL;
- egg_secure_strfree (item->secret);
- item->secret = NULL;
- if (item->acl) {
- gnome_keyring_acl_free (item->acl);
- item->acl = NULL;
- }
- gnome_keyring_attribute_list_free (item->attributes);
- item->attributes = NULL;
-
- if (locked) {
- item->attributes = items[i].hashed_attributes;
- item->mtime = 0;
- item->ctime = 0;
- } else {
- item->attributes = items[i].attributes;
- gnome_keyring_attribute_list_free (items[i].hashed_attributes);
- item->display_name = items[i].display_name;
- item->secret = items[i].secret;
- item->acl = items[i].acl;
- item->mtime = items[i].mtime;
- item->ctime = items[i].ctime;
- }
- }
-
- g_hash_table_foreach (checks, (GHFunc)remove_unavailable_item, keyring);
- g_hash_table_destroy (checks);
-
- return 1;
- bail:
- egg_buffer_uninit (&to_decrypt);
- if (checks)
- g_hash_table_destroy (checks);
- g_free (display_name);
-
- if (items != NULL) {
- for (i = 0; i < num_items; i++) {
- g_free (items[i].display_name);
- egg_secure_strfree (items[i].secret);
- gnome_keyring_attribute_list_free (items[i].hashed_attributes);
- gnome_keyring_attribute_list_free (items[i].attributes);
- gnome_keyring_acl_free (items[i].acl);
- }
- g_free (items);
- }
-
- return -1;
-}
diff --git a/daemon/keyrings/gkr-keyring-item.c b/daemon/keyrings/gkr-keyring-item.c
deleted file mode 100644
index 60fac3dd..00000000
--- a/daemon/keyrings/gkr-keyring-item.c
+++ /dev/null
@@ -1,412 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* gkr-keyring-item.c - represents an item in a 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>
-*/
-
-#include "config.h"
-
-#include "gkr-keyring-item.h"
-#include "gkr-keyring.h"
-
-#include "egg/egg-secure-memory.h"
-
-#include <gcrypt.h>
-
-#include <glib.h>
-
-#include <string.h>
-
-enum {
- PROP_0,
- PROP_NAME
-};
-
-G_DEFINE_TYPE (GkrKeyringItem, gkr_keyring_item, G_TYPE_OBJECT);
-
-/* -----------------------------------------------------------------------------
- * HELPERS
- */
-
-static guint32
-hash_int (guint32 x)
-{
- /* Just random 32bit hash. Security here is not very important */
- return 0x18273645 ^ x ^ (x << 16 | x >> 16);
-}
-
-static char*
-md5_digest_to_ascii (unsigned char digest[16])
-{
- static char hex_digits[] = "0123456789abcdef";
- char *res;
- int i;
-
- res = g_malloc (33);
-
- for (i = 0; i < 16; i++) {
- res[2*i] = hex_digits[digest[i] >> 4];
- res[2*i+1] = hex_digits[digest[i] & 0xf];
- }
-
- res[32] = 0;
- return res;
-}
-
-static char *
-hash_string (const char *str)
-{
- guchar digest[16];
-
- if (str == NULL)
- return NULL;
-
- /* In case the world changes on us... */
- g_return_val_if_fail (gcry_md_get_algo_dlen (GCRY_MD_MD5) == sizeof (digest), NULL);
-
- gcry_md_hash_buffer (GCRY_MD_MD5, (void*)digest, str, strlen (str));
- return md5_digest_to_ascii (digest);
-}
-
-/* -----------------------------------------------------------------------------
- * OBJECT
- */
-
-static void
-gkr_keyring_item_init (GkrKeyringItem *item)
-{
-
-}
-
-static void
-gkr_keyring_item_get_property (GObject *obj, guint prop_id, GValue *value,
- GParamSpec *pspec)
-{
- GkrKeyringItem *item = GKR_KEYRING_ITEM (obj);
-
- switch (prop_id) {
- case PROP_NAME:
- g_value_set_string (value, item->display_name ? item->display_name : "");
- break;
- }
-}
-
-static void
-gkr_keyring_item_dispose (GObject *obj)
-{
- GkrKeyringItem *item = GKR_KEYRING_ITEM (obj);
-
- if (item->keyring) {
- g_object_remove_weak_pointer (G_OBJECT (item->keyring),
- (gpointer*)&(item->keyring));
- item->keyring = NULL;
- }
-
- G_OBJECT_CLASS (gkr_keyring_item_parent_class)->dispose (obj);
-}
-
-static void
-gkr_keyring_item_finalize (GObject *obj)
-{
- GkrKeyringItem *item = GKR_KEYRING_ITEM (obj);
-
- gnome_keyring_attribute_list_free (item->attributes);
- if (item->acl != NULL)
- gnome_keyring_acl_free (item->acl);
- g_free (item->display_name);
- egg_secure_strfree (item->secret);
-
- G_OBJECT_CLASS (gkr_keyring_item_parent_class)->finalize (obj);
-}
-
-static void
-gkr_keyring_item_class_init (GkrKeyringItemClass *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-
- gkr_keyring_item_parent_class = g_type_class_peek_parent (klass);
-
- gobject_class->get_property = gkr_keyring_item_get_property;
- gobject_class->dispose = gkr_keyring_item_dispose;
- gobject_class->finalize = gkr_keyring_item_finalize;
-
- g_object_class_install_property (gobject_class, PROP_NAME,
- g_param_spec_string ("name", "Name", "Item Name",
- NULL, G_PARAM_READABLE));
-}
-
-/* -----------------------------------------------------------------------------
- * PUBLIC
- */
-
-GkrKeyringItem*
-gkr_keyring_item_new (GkrKeyring* keyring, guint id, GnomeKeyringItemType type)
-{
- GkrKeyringItem *item = g_object_new (GKR_TYPE_KEYRING_ITEM, NULL);
-
- /* TODO: These should move into properties */
-
- g_assert (GKR_IS_KEYRING (keyring));
-
- item->keyring = keyring;
- item->id = id;
- item->type = type;
- item->attributes = gnome_keyring_attribute_list_new ();
-
- /* Make sure we get disconnected when keyring goes away */
- g_object_add_weak_pointer (G_OBJECT (item->keyring), (gpointer*)&(item->keyring));
-
- return item;
-}
-
-GkrKeyringItem*
-gkr_keyring_item_create (GkrKeyring* keyring, GnomeKeyringItemType type)
-{
- GkrKeyringItem *item;
- guint id;
-
- g_assert (!keyring->locked);
-
- id = gkr_keyring_get_new_id (keyring);
- g_return_val_if_fail (id != 0, NULL);
-
- item = gkr_keyring_item_new (keyring, id, type);
- item->locked = keyring->locked;
- item->ctime = item->mtime = time (NULL);
- item->type = type;
-
- return item;
-}
-
-GkrKeyringItem*
-gkr_keyring_item_clone (GkrKeyring* new_keyring, GkrKeyringItem *item)
-{
- GkrKeyringItem *nitem = g_object_new (GKR_TYPE_KEYRING_ITEM, NULL);
-
- g_return_val_if_fail (GKR_IS_KEYRING (new_keyring), NULL);
- g_return_val_if_fail (GKR_IS_KEYRING_ITEM (item), NULL);
-
- nitem->keyring = new_keyring;
- nitem->id = gkr_keyring_get_new_id (new_keyring);
- nitem->locked = item->locked;
-
- nitem->type = item->type;
- nitem->secret = egg_secure_strdup (item->secret);
- nitem->display_name = g_strdup (item->display_name);
-
- nitem->attributes = gnome_keyring_attribute_list_copy (item->attributes);
- nitem->acl = gnome_keyring_acl_copy (item->acl);
-
- nitem->ctime = item->ctime;
- nitem->mtime = item->mtime;
-
- /* Make sure we get disconnected when keyring goes away */
- g_object_add_weak_pointer (G_OBJECT (item->keyring), (gpointer*)&(item->keyring));
-
- return nitem;
-}
-
-void
-gkr_keyring_item_merge (GkrKeyringItem* merged, GkrKeyringItem* item)
-{
- GnomeKeyringAttributeList *attributes;
- GnomeKeyringAttribute *attribute;
- gint i;
-
- attributes = item->attributes;
- for (i = 0; i < attributes->len; i++) {
- attribute = &gnome_keyring_attribute_list_index (attributes, i);
- gkr_attribute_list_set (merged->attributes, attribute);
- }
-}
-
-gboolean
-gkr_keyring_item_match (GkrKeyringItem *item, GnomeKeyringItemType type,
- GnomeKeyringAttributeList *attributes, gboolean match_all)
-{
- int i, j;
- GnomeKeyringAttribute *item_attribute;
- GnomeKeyringAttribute *attribute;
- gboolean found;
- int attributes_matching;
-
- if ((item->type & GNOME_KEYRING_ITEM_TYPE_MASK) != (type & GNOME_KEYRING_ITEM_TYPE_MASK))
- return FALSE;
-
- attributes_matching = 0;
- for (i = 0; i < attributes->len; i++) {
- found = FALSE;
- attribute = &g_array_index (attributes,
- GnomeKeyringAttribute,
- i);
- for (j = 0; j < item->attributes->len; j++) {
- item_attribute = &g_array_index (item->attributes,
- GnomeKeyringAttribute,
- j);
- if (strcmp (attribute->name, item_attribute->name) == 0) {
- found = TRUE;
- attributes_matching++;
- if (attribute->type != item_attribute->type) {
- return FALSE;
- }
- switch (attribute->type) {
- case GNOME_KEYRING_ATTRIBUTE_TYPE_STRING:
- if (attribute->value.string != item_attribute->value.string) {
- if (attribute->value.string == NULL || item_attribute->value.string == NULL)
- return FALSE;
- if (strcmp (attribute->value.string, item_attribute->value.string) != 0)
- return FALSE;
- }
- break;
- case GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32:
- if (attribute->value.integer != item_attribute->value.integer) {
- return FALSE;
- }
- break;
- default:
- g_assert_not_reached ();
- }
- }
- }
- if (!found) {
- return FALSE;
- }
- }
- if (match_all) {
- return attributes_matching == attributes->len;
- }
-
- return TRUE;
-}
-
-/* -----------------------------------------------------------------------------
- * ATTRIBUTE LIST FUNCTIONS
- */
-
-void
-gkr_attribute_list_set (GnomeKeyringAttributeList *attrs, GnomeKeyringAttribute *attr)
-{
- GnomeKeyringAttribute *set;
- GnomeKeyringAttribute last;
- gchar *tofree = NULL;
-
- g_return_if_fail (attrs);
- g_return_if_fail (attr);
- g_return_if_fail (attr->name);
-
- set = gkr_attribute_list_find (attrs, attr->name);
-
- /* Found, appropriate for our own uses */
- if (set) {
- if (set->type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING) {
- tofree = set->value.string;
- set->value.string = NULL;
- }
-
- /* Not found, add a new one to the end */
- } else {
- memset (&last, 0, sizeof (last));
- g_array_append_val (attrs, last);
- set = &g_array_index (attrs, GnomeKeyringAttribute, attrs->len - 1);
- set->name = g_strdup (attr->name);
- }
-
- /* Set the actual value */
- set->type = attr->type;
- switch (attr->type) {
- case GNOME_KEYRING_ATTRIBUTE_TYPE_STRING:
- set->value.string = g_strdup (attr->value.string);
- break;
- case GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32:
- set->value.integer = attr->value.integer;
- break;
- default:
- g_assert_not_reached ();
- }
-
- g_free (tofree);
-}
-
-GnomeKeyringAttribute*
-gkr_attribute_list_find (GnomeKeyringAttributeList *attrs, const gchar *name)
-{
- GnomeKeyringAttribute *attr;
- int i;
-
- g_return_val_if_fail (attrs, NULL);
- g_return_val_if_fail (name, NULL);
-
- for (i = 0; i < attrs->len; i++) {
- attr = &gnome_keyring_attribute_list_index (attrs, i);
- g_return_val_if_fail (attr->name, NULL);
- if (strcmp (attr->name, name) == 0)
- return attr;
- }
-
- return NULL;
-}
-
-void
-gkr_attribute_list_delete (GnomeKeyringAttributeList *attrs, const gchar *name)
-{
- GnomeKeyringAttribute *attr;
- int i;
-
- g_return_if_fail (attrs);
- g_return_if_fail (name);
-
- for (i = 0; i < attrs->len; i++) {
- attr = &gnome_keyring_attribute_list_index (attrs, i);
- g_return_if_fail (attr->name);
- if (strcmp (attr->name, name) == 0) {
- g_array_remove_index_fast (attrs, i);
- return;
- }
- }
-}
-
-GnomeKeyringAttributeList *
-gkr_attribute_list_hash (GnomeKeyringAttributeList *attributes)
-{
- GnomeKeyringAttributeList *hashed;
- GnomeKeyringAttribute *orig_attribute;
- GnomeKeyringAttribute attribute;
- int i;
-
- hashed = g_array_new (FALSE, FALSE, sizeof (GnomeKeyringAttribute));
- for (i = 0; i < attributes->len; i++) {
- orig_attribute = &gnome_keyring_attribute_list_index (attributes, i);
- attribute.name = g_strdup (orig_attribute->name);
- attribute.type = orig_attribute->type;
- switch (attribute.type) {
- case GNOME_KEYRING_ATTRIBUTE_TYPE_STRING:
- attribute.value.string = hash_string (orig_attribute->value.string);
- break;
- case GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32:
- attribute.value.integer = hash_int (orig_attribute->value.integer);
- break;
- default:
- g_assert_not_reached ();
- }
- g_array_append_val (hashed, attribute);
- }
-
- return hashed;
-}
diff --git a/daemon/keyrings/gkr-keyring-item.h b/daemon/keyrings/gkr-keyring-item.h
deleted file mode 100644
index 05bf7928..00000000
--- a/daemon/keyrings/gkr-keyring-item.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* gkr-keyring-item.h - represents an item in a 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 __GKR_KEYRING_ITEM_H__
-#define __GKR_KEYRING_ITEM_H__
-
-/*
- * TODO: The internals of a GkrKeyringItem should probably be further
- * abstracted away and accessed via accessor methods and properties.
- */
-
-#include <glib-object.h>
-#include "library/gnome-keyring.h"
-
-G_BEGIN_DECLS
-
-#define GKR_TYPE_KEYRING_ITEM (gkr_keyring_item_get_type())
-#define GKR_KEYRING_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GKR_TYPE_KEYRING_ITEM, GkrKeyringItem))
-#define GKR_KEYRING_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GKR_TYPE_KEYRING_ITEM, GObject))
-#define GKR_IS_KEYRING_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GKR_TYPE_KEYRING_ITEM))
-#define GKR_IS_KEYRING_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GKR_TYPE_KEYRING_ITEM))
-#define GKR_KEYRING_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GKR_TYPE_KEYRING_ITEM, GkrKeyringItemClass))
-
-struct _GkrKeyring;
-typedef struct _GkrKeyring GkrKeyring;
-typedef struct _GkrKeyringItem GkrKeyringItem;
-typedef struct _GkrKeyringItemClass GkrKeyringItemClass;
-
-struct _GkrKeyringItem {
- GObject parent;
-
- /*
- * Can be null if the keyring goes away, and this object
- * was referenced
- */
- GkrKeyring *keyring;
-
- guint32 id;
- GnomeKeyringItemType type;
-
- gboolean locked;
-
- /* These are hashed if locked, normal if unlocked, encrypted on file: */
- GArray *attributes;
-
- /* Below is encrypted in file, invalid in memory if locked: */
- char *display_name;
- char *secret;
- GList *acl;
- time_t ctime;
- time_t mtime;
-};
-
-struct _GkrKeyringItemClass {
- GObjectClass parent_class;
-};
-
-GType gkr_keyring_item_get_type (void) G_GNUC_CONST;
-
-GkrKeyringItem* gkr_keyring_item_new (GkrKeyring* keyring, guint id,
- GnomeKeyringItemType type);
-
-GkrKeyringItem* gkr_keyring_item_create (GkrKeyring* keyring,
- GnomeKeyringItemType type);
-
-GkrKeyringItem* gkr_keyring_item_clone (GkrKeyring* new_keyring,
- GkrKeyringItem *item);
-
-void gkr_keyring_item_merge (GkrKeyringItem* merged,
- GkrKeyringItem* item);
-
-gboolean gkr_keyring_item_match (GkrKeyringItem *item,
- GnomeKeyringItemType type,
- GnomeKeyringAttributeList *attributes,
- gboolean match_all);
-
-void gkr_attribute_list_set (GnomeKeyringAttributeList *attrs,
- GnomeKeyringAttribute *attr);
-
-GnomeKeyringAttribute* gkr_attribute_list_find (GnomeKeyringAttributeList *attrs,
- const gchar *name);
-
-void gkr_attribute_list_delete (GnomeKeyringAttributeList *attrs,
- const gchar *name);
-
-GnomeKeyringAttributeList* gkr_attribute_list_hash (GnomeKeyringAttributeList *attrs);
-
-G_END_DECLS
-
-#endif /* __GKR_KEYRING_ITEM_H__ */
-
diff --git a/daemon/keyrings/gkr-keyring-login.c b/daemon/keyrings/gkr-keyring-login.c
deleted file mode 100644
index 4c912def..00000000
--- a/daemon/keyrings/gkr-keyring-login.c
+++ /dev/null
@@ -1,325 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* gkr-keyrings-login.c - get secrets to automatically unlock keyrings or keys
-
- 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 "gkr-keyring-login.h"
-
-#include "gkr-keyring.h"
-#include "gkr-keyring-item.h"
-#include "gkr-keyrings.h"
-
-#include "egg/egg-secure-memory.h"
-
-#include "library/gnome-keyring.h"
-
-#include "ui/gkr-ask-daemon.h"
-#include "ui/gkr-ask-request.h"
-
-#include "util/gkr-location.h"
-
-#include <glib.h>
-#include <glib/gi18n.h>
-
-#include <stdarg.h>
-#include <unistd.h>
-
-gboolean
-gkr_keyring_login_is_unlocked (void)
-{
- GkrKeyring *login = gkr_keyrings_get_login ();
- return (login && !login->locked);
-}
-
-gboolean
-gkr_keyring_login_is_usable (void)
-{
- /*
- * We only flag this as usable by our internals if the keyring will
- * be encrypted when on disk.
- */
- GkrKeyring *login = gkr_keyrings_get_login ();
- return (login && !login->locked && !gkr_keyring_is_insecure (login));
-}
-
-static gboolean
-check_ask_request (GkrAskRequest* ask)
-{
- GkrKeyring *keyring;
-
- keyring = GKR_KEYRING (gkr_ask_request_get_object (ask));
- g_assert (GKR_IS_KEYRING (keyring));
-
- if (!keyring->locked) {
- ask->response = GKR_ASK_RESPONSE_ALLOW;
- return GKR_ASK_STOP_REQUEST;
- }
-
- /* If they typed a password, try it out */
- if (ask->response >= GKR_ASK_RESPONSE_ALLOW) {
-
- g_assert (ask->typed_password);
- if (!gkr_keyring_unlock (keyring, ask->typed_password)) {
- /* Bad password, try again */
- ask->response = GKR_ASK_RESPONSE_NONE;
- return GKR_ASK_CONTINUE_REQUEST;
- }
- }
-
- return GKR_ASK_DONT_CARE;
-}
-
-static gboolean
-request_login_access (GkrKeyring* keyring)
-{
- GkrAskRequest *ask;
- gboolean ret;
-
- /* And put together the ask request */
- ask = gkr_ask_request_new (_("Unlock Login Keyring"), _("Enter login password to unlock keyring"),
- GKR_ASK_REQUEST_PROMPT_PASSWORD);
- gkr_ask_request_set_secondary (ask, _("Your login keyring was not automatically unlocked when you logged into this computer."));
- gkr_ask_request_set_object (ask, G_OBJECT (keyring));
-
- /* Intercept item access requests to see if we still need to prompt */
- g_signal_connect (ask, "check-request", G_CALLBACK (check_ask_request), NULL);
-
- /* And do the prompt */
- gkr_ask_daemon_process (ask);
- ret = ask->response >= GKR_ASK_RESPONSE_ALLOW;
- g_object_unref (ask);
-
- return ret;
-}
-
-static gboolean
-request_login_new (gchar **password)
-{
- GkrAskRequest* ask;
- gboolean ret;
-
- g_assert (password);
- g_assert (!*password);
-
- /* And put together the ask request */
- ask = gkr_ask_request_new (_("Create Login Keyring"), _("Enter your login password"),
- GKR_ASK_REQUEST_NEW_PASSWORD);
- gkr_ask_request_set_secondary (ask, _("Your login keyring was not automatically created when you logged "
- "into this computer. It will now be created."));
-
- /* And do the prompt */
- gkr_ask_daemon_process (ask);
- ret = ask->response >= GKR_ASK_RESPONSE_ALLOW;
- if (ret)
- *password = egg_secure_strdup (ask->typed_password);
- g_object_unref (ask);
- return ret;
-}
-
-gboolean
-gkr_keyring_login_unlock (const gchar *password)
-{
- GkrKeyring *login = gkr_keyrings_get_login ();
- gchar *new_password = NULL;
-
- /* Make sure its loaded */
- if (!login) {
- gkr_keyrings_update ();
- login = gkr_keyrings_get_login ();
- }
-
- if (login && !login->locked)
- return TRUE;
-
- /* Try to unlock the keyring that exists */
- if (login) {
- if (!password)
- return request_login_access (login);
-
- if (!gkr_keyring_unlock (login, password)) {
- g_message ("Couldn't unlock login keyring with provided password");
- return FALSE;
- }
-
- return TRUE;
- }
-
- /* No such keyring exists, and we don't have a password. */
- if (!password) {
- if (!request_login_new (&new_password))
- return FALSE;
- g_return_val_if_fail (new_password, FALSE);
- password = new_password;
- }
-
- /* No such keyring exists, so create one */
- login = gkr_keyring_create (GKR_LOCATION_VOLUME_LOCAL, "login", password);
- egg_secure_strfree (new_password);
-
- if (!login) {
- g_warning ("Failed to create login keyring");
- return FALSE;
- }
-
- g_assert (!login->locked);
-
- gkr_keyrings_add (login);
- g_return_val_if_fail (gkr_keyrings_get_login () == login, FALSE);
-
- g_object_unref (login);
- return TRUE;
-}
-
-void
-gkr_keyring_login_lock (void)
-{
- GkrKeyring *login = gkr_keyrings_get_login ();
- if (login)
- gkr_keyring_lock (login);
-}
-
-static GnomeKeyringAttributeList*
-string_attribute_list_va (va_list args)
-{
- GnomeKeyringAttributeList *attributes;
- GnomeKeyringAttribute attribute;
-
- attributes = g_array_new (FALSE, FALSE, sizeof (GnomeKeyringAttribute));
-
- while ((attribute.name = va_arg (args, char *)) != NULL) {
- attribute.name = g_strdup (attribute.name);
- attribute.value.string = g_strdup (va_arg (args, char *));
- attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
- g_array_append_val (attributes, attribute);
- }
-
- return attributes;
-}
-
-const gchar*
-gkr_keyring_login_master (void)
-{
- GkrKeyring *login;
-
- login = gkr_keyrings_get_login ();
- if (!login || login->locked)
- return NULL;
-
- if (gkr_keyring_is_insecure (login))
- return NULL;
-
- return login->password;
-}
-
-void
-gkr_keyring_login_attach_secret (GnomeKeyringItemType type, const gchar *display_name,
- const gchar *secret, ...)
-{
- GkrKeyring *login;
- GnomeKeyringAttributeList *attrs;
- GkrKeyringItem *item;
- va_list args;
-
- login = gkr_keyrings_get_login ();
- if (!login || login->locked)
- return;
-
- va_start (args, secret);
- attrs = string_attribute_list_va (args);
- va_end (args);
-
- item = gkr_keyring_find_item (login, type, attrs, TRUE);
-
- if (!item) {
- item = gkr_keyring_item_create (login, type);
- gkr_keyring_add_item (login, item);
- g_object_unref (item);
- }
-
- g_free (item->display_name);
- item->display_name = g_strdup (display_name);
-
- egg_secure_strfree (item->secret);
- item->secret = egg_secure_strdup (secret);
-
- gnome_keyring_attribute_list_free (item->attributes);
- item->attributes = attrs;
-
- gkr_keyring_save_to_disk (login);
-}
-
-const gchar*
-gkr_keyring_login_lookup_secret (GnomeKeyringItemType type, ...)
-{
- GkrKeyring *login;
- GkrKeyringItem *item;
- GnomeKeyringAttributeList *attrs;
- va_list args;
-
- login = gkr_keyrings_get_login ();
- if (!login || login->locked)
- return NULL;
-
- if (!login->location)
- return NULL;
-
- va_start (args, type);
- attrs = string_attribute_list_va (args);
- va_end (args);
-
- item = gkr_keyring_find_item (login, type, attrs, TRUE);
- gnome_keyring_attribute_list_free (attrs);
-
- if (item)
- return item->secret;
-
- return NULL;
-}
-
-void
-gkr_keyring_login_remove_secret (GnomeKeyringItemType type, ...)
-{
- GkrKeyring *login;
- GkrKeyringItem *item;
- GnomeKeyringAttributeList *attrs;
- va_list args;
-
- login = gkr_keyrings_get_login ();
- if (!login || login->locked)
- return;
-
- if (!login->location)
- return;
-
- va_start (args, type);
- attrs = string_attribute_list_va (args);
- va_end (args);
-
- item = gkr_keyring_find_item (login, type, attrs, TRUE);
- gnome_keyring_attribute_list_free (attrs);
-
- if (item) {
- gkr_keyring_remove_item (login, item);
- gkr_keyring_save_to_disk (login);
- }
-}
diff --git a/daemon/keyrings/gkr-keyring-login.h b/daemon/keyrings/gkr-keyring-login.h
deleted file mode 100644
index 8fbbcccf..00000000
--- a/daemon/keyrings/gkr-keyring-login.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* gkr-keyrings-login.h - get secrets to automatically unlock keyrings or keys
-
- 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 GKRKEYRINGSAUTOUNLOCK_H_
-#define GKRKEYRINGSAUTOUNLOCK_H_
-
-#include "library/gnome-keyring.h"
-
-gboolean gkr_keyring_login_is_unlocked (void);
-
-gboolean gkr_keyring_login_is_usable (void);
-
-gboolean gkr_keyring_login_unlock (const gchar *secret);
-
-void gkr_keyring_login_lock (void);
-
-const gchar* gkr_keyring_login_master (void);
-
-void gkr_keyring_login_attach_secret (GnomeKeyringItemType type,
- const gchar *display_name,
- const gchar *secret,
- ...);
-
-const gchar* gkr_keyring_login_lookup_secret (GnomeKeyringItemType type,
- ...);
-
-void gkr_keyring_login_remove_secret (GnomeKeyringItemType type,
- ...);
-
-#endif /*GKRKEYRINGSAUTOUNLOCK_H_*/
diff --git a/daemon/keyrings/gkr-keyring-textual.c b/daemon/keyrings/gkr-keyring-textual.c
deleted file mode 100644
index 62bb9e6b..00000000
--- a/daemon/keyrings/gkr-keyring-textual.c
+++ /dev/null
@@ -1,453 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* gkr-keyring-textual.c - Textual non-encrypted format for the 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>
-*/
-
-#include "config.h"
-
-#include "gkr-keyring.h"
-#include "gkr-keyring-item.h"
-
-#include "egg/egg-secure-memory.h"
-
-#include "library/gnome-keyring.h"
-#include "library/gnome-keyring-private.h"
-
-#include <glib.h>
-
-#include <sys/types.h>
-#include <stdlib.h>
-#include <string.h>
-
-static void
-key_file_set_uint64 (GKeyFile *file, const gchar *group,
- const gchar *key, guint64 value)
-{
- gchar buffer[64];
- g_snprintf (buffer, sizeof (buffer), "%llu",
- (long long unsigned int)value);
- g_key_file_set_value (file, group, key, buffer);
-}
-
-static gboolean
-key_file_get_uint64 (GKeyFile *file, const gchar *group,
- const gchar *key, guint64 *value)
-{
- gchar *str, *end;
-
- str = g_key_file_get_value (file, group, key, NULL);
- if (!str)
- return FALSE;
-
- *value = g_ascii_strtoull (str, &end, 10);
- if (end[0]) {
- g_free (str);
- return FALSE;
- }
-
- g_free (str);
- return TRUE;
-}
-
-static void
-generate_attributes (GKeyFile *file, GkrKeyringItem *item)
-{
- GnomeKeyringAttribute *attr;
- gchar *groupname;
- gint i;
-
- g_return_if_fail (item->attributes);
-
- for (i = 0; i < item->attributes->len; ++i) {
-
- /* Build a group name */
- groupname = g_strdup_printf ("%d:attribute%d", item->id, i);
-
- attr = &gnome_keyring_attribute_list_index (item->attributes, i);
-
- g_key_file_set_string (file, groupname, "name", attr->name);
-
- switch (attr->type) {
- case GNOME_KEYRING_ATTRIBUTE_TYPE_STRING:
- g_key_file_set_string (file, groupname, "type", "string");
- if (attr->value.string)
- g_key_file_set_string (file, groupname, "value", attr->value.string);
- break;
- case GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32:
- g_key_file_set_string (file, groupname, "type", "uint32");
- key_file_set_uint64 (file, groupname, "value", attr->value.integer);
- break;
- default:
- g_return_if_reached ();
- break;
- };
-
- g_free (groupname);
- }
-}
-
-static void
-parse_attributes (GKeyFile *file, GkrKeyringItem *item, const gchar **groups)
-{
- const gchar **g;
- gchar *prefix;
- gchar *name, *type;
- gchar *strval;
- guint64 intval;
-
- /* Now do the attributes */
-
- prefix = g_strdup_printf ("%u:attribute", item->id);
-
- gnome_keyring_attribute_list_free (item->attributes);
- item->attributes = gnome_keyring_attribute_list_new ();
-
- for (g = groups; *g; ++g) {
- if (!g_str_has_prefix (*g, prefix))
- continue;
-
- name = g_key_file_get_string (file, *g, "name", NULL);
- type = g_key_file_get_string (file, *g, "type", NULL);
-
- if (name && type && g_key_file_has_key (file, *g, "value", NULL)) {
- if (g_str_equal (type, "uint32")) {
- if (key_file_get_uint64 (file, *g, "value", &intval))
- gnome_keyring_attribute_list_append_uint32 (item->attributes,
- name, intval);
- } else {
- strval = g_key_file_get_string (file, *g, "value", NULL);
- gnome_keyring_attribute_list_append_string (item->attributes,
- name, strval);
- g_free (strval);
- }
- }
-
- g_free (name);
- g_free (type);
- }
-
- g_free (prefix);
-}
-
-static void
-generate_acl (GKeyFile *file, GkrKeyringItem *item)
-{
- GnomeKeyringAccessControl *ac;
- gchar *groupname;
- GList *l;
- gint i;
-
- for (l = item->acl, i = 0; l != NULL; l = l->next, ++i) {
- ac = l->data;
-
- /* Build a group name */
- groupname = g_strdup_printf ("%d:acl%d", item->id, i);
-
- if (ac->application->display_name)
- g_key_file_set_string (file, groupname, "display-name",
- ac->application->display_name);
- if (ac->application->pathname)
- g_key_file_set_string (file, groupname, "path",
- ac->application->pathname);
-
- g_key_file_set_boolean (file, groupname, "read-access",
- ac->types_allowed & GNOME_KEYRING_ACCESS_READ);
- g_key_file_set_boolean (file, groupname, "write-access",
- ac->types_allowed & GNOME_KEYRING_ACCESS_WRITE);
- g_key_file_set_boolean (file, groupname, "remove-access",
- ac->types_allowed & GNOME_KEYRING_ACCESS_REMOVE);
-
- g_free (groupname);
- }
-}
-
-static void
-parse_acl (GKeyFile *file, GkrKeyringItem *item, const gchar **groups)
-{
- GnomeKeyringAccessType access_type;
- GnomeKeyringApplicationRef *app;
- const gchar **g;
- gchar *prefix;
- gchar *path, *display;
- GError *err = NULL;
-
- /* Now do the attributes */
-
- prefix = g_strdup_printf ("%u:acl", item->id);
-
- gnome_keyring_acl_free (item->acl);
- item->acl = NULL;
-
- for (g = groups; *g; ++g) {
- if (!g_str_has_prefix (*g, prefix))
- continue;
- path = g_key_file_get_string (file, *g, "path", NULL);
- if (!path)
- continue;
-
- display = g_key_file_get_string (file, *g, "display-name", NULL);
-
- access_type = 0;
-
- if (g_key_file_get_boolean (file, *g, "read-access", &err) && !err)
- access_type |= GNOME_KEYRING_ACCESS_READ;
- g_clear_error (&err);
-
- if (g_key_file_get_boolean (file, *g, "write-access", &err) && !err)
- access_type |= GNOME_KEYRING_ACCESS_WRITE;
- g_clear_error (&err);
-
- if (g_key_file_get_boolean (file, *g, "remove-access", &err) && !err)
- access_type |= GNOME_KEYRING_ACCESS_REMOVE;
- g_clear_error (&err);
-
- app = g_new0 (GnomeKeyringApplicationRef, 1);
- app->display_name = display;
- app->pathname = path;
-
- item->acl = g_list_prepend (item->acl, gnome_keyring_access_control_new (app, access_type));
- }
-
- g_free (prefix);
-}
-
-static void
-generate_item (GKeyFile *file, GkrKeyringItem *item)
-{
- gchar *groupname;
-
- groupname = g_strdup_printf ("%u", item->id);
-
- g_key_file_set_integer (file, groupname, "item-type", item->type);
-
- if (item->display_name)
- g_key_file_set_string (file, groupname, "display-name", item->display_name);
-
- if (item->secret)
- g_key_file_set_value (file, groupname, "secret", item->secret);
-
- key_file_set_uint64 (file, groupname, "mtime", item->mtime);
- key_file_set_uint64 (file, groupname, "ctime", item->ctime);
-
- g_free (groupname);
-
- generate_attributes (file, item);
- generate_acl (file, item);
-}
-
-static void
-parse_item (GKeyFile *file, GkrKeyringItem *item, const gchar **groups)
-{
- gchar *groupname, *val;
- GError *err = NULL;
- guint64 num;
-
- /* First the main item data */
-
- groupname = g_strdup_printf ("%u", item->id);
-
- /* Never encrypted */
- item->locked = FALSE;
-
- item->type = g_key_file_get_integer (file, groupname, "item-type", &err);
- if (err) {
- g_clear_error (&err);
- item->type = 0;
- }
-
- g_free (item->display_name);
- item->display_name = g_key_file_get_string (file, groupname, "display-name", NULL);
-
- /* Even though this is from disk, use secure memory just to be consistent */
- egg_secure_free (item->secret);
- val = g_key_file_get_string (file, groupname, "secret", NULL);
- item->secret = egg_secure_strdup (val);
- g_free (val);
-
- item->mtime = 0;
- if (key_file_get_uint64 (file, groupname, "mtime", &num))
- item->mtime = num;
- item->ctime = 0;
- if (key_file_get_uint64 (file, groupname, "ctime", &num))
- item->ctime = num;
-
- g_free (groupname);
-
- /* Now the other stuff */
- parse_attributes (file, item, groups);
- parse_acl (file, item, groups);
-}
-
-gboolean
-gkr_keyring_textual_generate (GkrKeyring *keyring, EggBuffer *buffer)
-{
- GkrKeyringItem *item;
- GKeyFile *file;
- gchar *data;
- GError *err = NULL;
- GList *l;
- gsize n_data;
-
- g_return_val_if_fail (!keyring->locked, FALSE);
-
- file = g_key_file_new ();
-
- if (keyring->keyring_name)
- g_key_file_set_string (file, "keyring", "display-name", keyring->keyring_name);
-
- key_file_set_uint64 (file, "keyring", "ctime", keyring->ctime);
- key_file_set_uint64 (file, "keyring", "mtime", keyring->mtime);
-
- g_key_file_set_boolean (file, "keyring", "lock-on-idle", keyring->lock_on_idle);
- g_key_file_set_integer (file, "keyring", "lock-timeout", keyring->lock_timeout);
-
- for (l = keyring->items; l; l = g_list_next (l)) {
- item = GKR_KEYRING_ITEM (l->data);
- generate_item (file, item);
- }
-
- data = g_key_file_to_data (file, &n_data, &err);
- g_key_file_free (file);
-
- if (!data) {
- g_warning ("couldn't generate textual keyring file: %s", err->message);
- return FALSE;
- }
-
- egg_buffer_uninit (buffer);
- egg_buffer_init_allocated (buffer, (guchar*)data, n_data, NULL);
- return TRUE;
-}
-
-static void
-remove_unavailable_item (gpointer key, gpointer dummy, GkrKeyring *keyring)
-{
- /* Called to remove items from a keyring that no longer exist */
-
- GkrKeyringItem *item;
- guint id = GPOINTER_TO_UINT (key);
-
- g_assert (GKR_IS_KEYRING (keyring));
-
- item = gkr_keyring_get_item (keyring, id);
- if (item)
- gkr_keyring_remove_item (keyring, item);
-}
-
-gint
-gkr_keyring_textual_parse (GkrKeyring *keyring, EggBuffer *buffer)
-{
- GkrKeyringItem *item;
- GError *err = NULL;
- GKeyFile *file = NULL;
- gchar **groups = NULL;
- gint ret = -1;
- gchar *start = NULL;
- GHashTable *checks = NULL;
- guint64 num;
- gint integer;
- GList *l;
- gchar **g;
- gchar *end;
- guint32 id;
-
- file = g_key_file_new ();
-
- if (!g_key_file_load_from_data (file, (const gchar*)buffer->buf,
- buffer->len, G_KEY_FILE_NONE, &err)) {
- if (g_error_matches (err, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_PARSE))
- ret = 0;
- goto done;
- }
-
- start = g_key_file_get_start_group (file);
- if (!start || !g_str_equal (start, "keyring")) {
- g_message ("invalid keyring file: wrong header group");
- goto done;
- }
-
- g_free (keyring->keyring_name);
- keyring->keyring_name = g_key_file_get_string (file, "keyring", "display-name", NULL);
-
- keyring->ctime = 0;
- if (key_file_get_uint64 (file, "keyring", "ctime", &num))
- keyring->ctime = num;
- keyring->mtime = 0;
- if (key_file_get_uint64 (file, "keyring", "mtime", &num))
- keyring->mtime = num;
-
- keyring->lock_on_idle = FALSE;
- if (g_key_file_get_boolean (file, "keyring", "lock-on-idle", &err) && !err)
- keyring->lock_on_idle = TRUE;
- g_clear_error (&err);
-
- integer = g_key_file_get_integer (file, "keyring", "lock-timeout", &err);
- if (!err)
- keyring->lock_timeout = integer;
- g_clear_error (&err);
-
- /* No encryption context for use when reencrypting */
- keyring->salt_valid = FALSE;
- memset (keyring->salt, 0, sizeof (keyring->salt));
- keyring->hash_iterations = 0;
-
- /* Build a Hash table where we can track ids we haven't yet seen */
- checks = g_hash_table_new (g_direct_hash, g_direct_equal);
- for (l = keyring->items; l; l = g_list_next (l)) {
- item = GKR_KEYRING_ITEM (l->data);
- g_hash_table_insert (checks, GUINT_TO_POINTER (item->id), "DUMMY");
- }
-
- groups = g_key_file_get_groups (file, NULL);
- for (g = groups; *g; ++g) {
- id = strtoul (*g, &end, 10);
-
- /* Wasn't a complete number */
- if (end[0])
- continue;
-
- /* We've seen this id */
- g_hash_table_remove (checks, GUINT_TO_POINTER (id));
-
- item = gkr_keyring_get_item (keyring, id);
- if (item == NULL) {
- item = gkr_keyring_item_new (keyring, id, 0);
- gkr_keyring_add_item (keyring, item);
- g_object_unref (item);
- }
-
- parse_item (file, item, (const gchar**)groups);
- }
-
- g_hash_table_foreach (checks, (GHFunc)remove_unavailable_item, keyring);
- ret = 1;
-
-done:
- if (checks)
- g_hash_table_destroy (checks);
- if (file)
- g_key_file_free (file);
- g_strfreev (groups);
- g_free (start);
- g_clear_error (&err);
-
- return ret;
-}
diff --git a/daemon/keyrings/gkr-keyring.c b/daemon/keyrings/gkr-keyring.c
deleted file mode 100644
index 977937d8..00000000
--- a/daemon/keyrings/gkr-keyring.c
+++ /dev/null
@@ -1,624 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* gkr-keyring.c - represents a keyring in memory, and functionality save/load
-
- Copyright (C) 2003 Red Hat, Inc
- Copyright (C) 2007 Stefan Walter
-
- Gnome keyring is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- Gnome keyring 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
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- Author: Alexander Larsson <alexl@redhat.com>
- Author: Stef Walter <stef@memberwebs.com>
-*/
-
-#include "config.h"
-
-#include "gkr-keyring.h"
-#include "gkr-keyring-item.h"
-#include "gkr-keyring-login.h"
-#include "gkr-keyrings.h"
-
-#include "egg/egg-buffer.h"
-#include "egg/egg-secure-memory.h"
-
-#include "library/gnome-keyring-private.h"
-#include "library/gnome-keyring-proto.h"
-
-#include "util/gkr-location.h"
-
-#include <glib.h>
-#include <glib/gi18n.h>
-
-#include <gcrypt.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-/* -----------------------------------------------------------------------------
- * DECLARATIONS
- */
-
-enum {
- ITEM_ADDED,
- ITEM_REMOVED,
- LAST_SIGNAL
-};
-
-enum {
- PROP_0,
- PROP_NAME,
- PROP_LOCATION
-};
-
-static guint signals[LAST_SIGNAL] = { 0 };
-
-G_DEFINE_TYPE (GkrKeyring, gkr_keyring, G_TYPE_OBJECT);
-
-/* -----------------------------------------------------------------------------
- * HELPERS
- */
-
-static int
-write_all (int fd, const guchar *buf, size_t len)
-{
- size_t bytes;
- int res;
-
- bytes = 0;
- while (bytes < len) {
- res = write (fd, buf + bytes, len - bytes);
- if (res < 0) {
- if (errno != EINTR && errno != EAGAIN) {
- perror ("write_all write failure:");
- return -1;
- }
- } else {
- bytes += res;
- }
- }
- return 0;
-}
-
-static GQuark
-get_default_location_for_name (GQuark volume, const char *keyring_name)
-{
- gchar *path = NULL;
- gchar *base, *filename;
- int version;
- GQuark loc;
-
- g_assert (volume);
- g_assert (keyring_name && keyring_name[0]);
-
- base = g_filename_from_utf8 (keyring_name, -1, NULL, NULL, NULL);
- if (base == NULL)
- base = g_strdup ("keyring");
-
- version = 0;
- do {
- g_free (path);
-
- if (version == 0)
- filename = g_strdup_printf ("%s/keyrings/%s.keyring",
- g_quark_to_string (volume), base);
- else
- filename = g_strdup_printf ("%s/keyrings/%s%d.keyring",
- g_quark_to_string (volume), base, version);
-
- loc = gkr_location_from_string (filename);
- g_free (filename);
-
- path = gkr_location_to_path (loc);
- g_return_val_if_fail (path, 0);
-
- version++;
- } while (g_file_test (path, G_FILE_TEST_EXISTS));
-
- g_free (base);
-
- loc = gkr_location_from_path (path);
- g_free (path);
- return loc;
-}
-
-/* -----------------------------------------------------------------------------
- * OBJECT
- */
-
-static void
-gkr_keyring_init (GkrKeyring *keyring)
-{
- keyring->ctime = keyring->mtime = time (NULL);
-
- /* Default values: */
- keyring->lock_on_idle = FALSE;
- keyring->lock_timeout = 0;
-}
-
-static void
-gkr_keyring_get_property (GObject *obj, guint prop_id, GValue *value,
- GParamSpec *pspec)
-{
- GkrKeyring *keyring = GKR_KEYRING (obj);
-
- switch (prop_id) {
- case PROP_NAME:
- g_value_set_string (value, keyring->keyring_name);
- break;
- case PROP_LOCATION:
- g_value_set_uint (value, keyring->location);
- break;
- }
-}
-
-static void
-gkr_keyring_dispose (GObject *obj)
-{
- GkrKeyring *keyring = GKR_KEYRING (obj);
- GkrKeyringItem *item;
- GList *l;
-
- /* Remove all references to items */
- for (l = keyring->items; l; l = g_list_next (l)) {
- item = GKR_KEYRING_ITEM (l->data);
- g_object_unref (item);
- }
-
- g_list_free (keyring->items);
- keyring->items = NULL;
-
- egg_secure_strfree (keyring->password);
- keyring->password = NULL;
-
- G_OBJECT_CLASS (gkr_keyring_parent_class)->dispose (obj);
-}
-
-static void
-gkr_keyring_finalize (GObject *obj)
-{
- GkrKeyring *keyring = GKR_KEYRING (obj);
-
- g_free (keyring->keyring_name);
- g_assert (keyring->password == NULL);
-
- G_OBJECT_CLASS (gkr_keyring_parent_class)->finalize (obj);
-}
-
-static void
-gkr_keyring_class_init (GkrKeyringClass *klass)
-{
- GObjectClass *gobject_class = (GObjectClass*)klass;
-
- gkr_keyring_parent_class = g_type_class_peek_parent (klass);
-
- gobject_class->get_property = gkr_keyring_get_property;
- gobject_class->dispose = gkr_keyring_dispose;
- gobject_class->finalize = gkr_keyring_finalize;
-
- g_object_class_install_property (gobject_class, PROP_NAME,
- g_param_spec_string ("name", "Name", "Keyring Name",
- NULL, G_PARAM_READABLE));
-
- g_object_class_install_property (gobject_class, PROP_LOCATION,
- g_param_spec_uint ("location", "Location", "File Location",
- 0, G_MAXUINT, 0, G_PARAM_READABLE));
-
- signals[ITEM_ADDED] = g_signal_new ("item-added", GKR_TYPE_KEYRING,
- G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GkrKeyringClass, item_added),
- NULL, NULL, g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE, 1, GKR_TYPE_KEYRING_ITEM);
-
- signals[ITEM_REMOVED] = g_signal_new ("item-removed", GKR_TYPE_KEYRING,
- G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GkrKeyringClass, item_removed),
- NULL, NULL, g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE, 1, GKR_TYPE_KEYRING_ITEM);
-}
-
-/* -----------------------------------------------------------------------------
- * PUBLIC
- */
-
-GkrKeyring*
-gkr_keyring_new (const char *name, GQuark location)
-{
- GkrKeyring *keyring;
-
- /* TODO: This should be done using properties */
-
- keyring = g_object_new (GKR_TYPE_KEYRING, NULL);
-
- keyring->keyring_name = g_strdup (name);
- keyring->location = location;
-
- return keyring;
-}
-
-GkrKeyring*
-gkr_keyring_create (GQuark location, const gchar *keyring_name, const gchar *password)
-{
- GkrKeyring *keyring;
-
- if (!location)
- location = GKR_LOCATION_VOLUME_LOCAL;
- if (gkr_location_is_volume (location))
- location = get_default_location_for_name (location, keyring_name);
-
- keyring = gkr_keyring_new (keyring_name, 0);
- if (keyring != NULL) {
- keyring->location = location;
- keyring->locked = FALSE;
- keyring->password = egg_secure_strdup (password);
- keyring->salt_valid = FALSE;
- gkr_keyring_save_to_disk (keyring);
- }
- return keyring;
-}
-
-guint
-gkr_keyring_get_new_id (GkrKeyring *keyring)
-{
- GkrKeyringItem *item;
- GList *l;
- guint max;
-
- g_assert (GKR_IS_KEYRING (keyring));
-
- max = 0;
- for (l = keyring->items; l ; l = g_list_next (l)) {
- item = l->data;
- if (item->id >= max)
- max = item->id;
- }
- /* Naive unique id lookup, but avoid rollaround at lest: */
-
- if (max == 0xffffffff)
- return 0;
-
- return max + 1;
-}
-
-GkrKeyringItem*
-gkr_keyring_get_item (GkrKeyring *keyring, guint id)
-{
- GkrKeyringItem *item;
- GList *l;
-
- for (l = keyring->items; l; l = g_list_next (l)) {
- item = GKR_KEYRING_ITEM (l->data);
- if (item->id == id)
- return item;
- }
-
- return NULL;
-}
-
-GkrKeyringItem*
-gkr_keyring_find_item (GkrKeyring *keyring, GnomeKeyringItemType type,
- GnomeKeyringAttributeList *attrs, gboolean match_all)
-{
- GkrKeyringItem *item;
- GList *l;
-
- for (l = keyring->items; l; l = g_list_next (l)) {
- item = GKR_KEYRING_ITEM (l->data);
- if (gkr_keyring_item_match (item, type, attrs, match_all))
- return item;
- }
-
- return NULL;
-}
-
-void
-gkr_keyring_add_item (GkrKeyring* keyring, GkrKeyringItem* item)
-{
- g_assert (GKR_IS_KEYRING (keyring));
- g_assert (GKR_IS_KEYRING_ITEM (item));
-
- /* Must not be added twice */
- g_assert (g_list_find (keyring->items, item) == NULL);
-
- keyring->items = g_list_append (keyring->items, item);
- g_object_ref (item);
-
- g_signal_emit (keyring, signals[ITEM_ADDED], 0, item);
-
-}
-
-void
-gkr_keyring_remove_item (GkrKeyring* keyring, GkrKeyringItem* item)
-{
- g_assert (GKR_IS_KEYRING (keyring));
- g_assert (GKR_IS_KEYRING_ITEM (item));
-
- if (g_list_find (keyring->items, item)) {
- keyring->items = g_list_remove (keyring->items, item);
-
- /* Must not be added twice */
- g_assert (g_list_find (keyring->items, item) == NULL);
-
- /* Keep the reference until after the signal */
- g_signal_emit (keyring, signals[ITEM_REMOVED], 0, item);
-
- g_object_unref (item);
- }
-}
-
-gboolean
-gkr_keyring_update_from_disk (GkrKeyring *keyring)
-{
- EggBuffer buffer;
- GError *err = NULL;
- guchar *contents = NULL;
- gsize len;
- gint result;
-
- if (!keyring->location)
- return TRUE;
-
- if (!gkr_location_read_file (keyring->location, &contents, &len, &err)) {
- g_warning ("couldn't read keyring: %s", err && err->message ? err->message : "");
- g_clear_error (&err);
- return FALSE;
- }
-
- egg_buffer_init_static (&buffer, contents, len);
-
- result = gkr_keyring_binary_parse (keyring, &buffer);
- if (result == 0)
- result = gkr_keyring_textual_parse (keyring, &buffer);
-
- egg_buffer_uninit (&buffer);
- g_free (contents);
-
- if (result > 0)
- return TRUE;
-
- if (result == 0)
- g_warning ("keyring has unknown format");
- else if (result < 0)
- g_warning ("error parsing keyring");
-
- return FALSE;
-}
-
-gboolean
-gkr_keyring_remove_from_disk (GkrKeyring *keyring)
-{
- gchar *file;
- int res;
-
- /* Cannot remove session or memory based keyring */
- if (!keyring->location)
- return FALSE;
-
- file = gkr_location_to_path (keyring->location);
- if (!file)
- return FALSE;
-
- res = unlink (file);
- g_free (file);
-
- return (res == 0);
-}
-
-gboolean
-gkr_keyring_save_to_disk (GkrKeyring *keyring)
-{
- struct stat statbuf;
- EggBuffer out;
- int fd;
- char *dirname;
- char *template;
- gboolean result;
- gboolean ret = TRUE;
- gchar *file = NULL;
-
- /* Can't save locked keyrings */
- if (keyring->locked)
- return FALSE;
-
- /* Not file backed */
- if (!keyring->location)
- return TRUE;
-
- file = gkr_location_to_path (keyring->location);
- if (!file)
- return FALSE;
-
- egg_buffer_init_full (&out, 4096, g_realloc);
-
- /* Generate it */
- if (!keyring->password || !keyring->password[0])
- result = gkr_keyring_textual_generate (keyring, &out);
- else
- result = gkr_keyring_binary_generate (keyring, &out);
-
- /* And write it to disk */
- if (result) {
- dirname = g_path_get_dirname (file);
- if (g_mkdir_with_parents (dirname, S_IRWXU) < 0)
- g_warning ("unable to create keyring dir");
- template = g_build_filename (dirname, ".keyringXXXXXX", NULL);
-
- fd = g_mkstemp (template);
- if (fd != -1) {
- fchmod (fd, S_IRUSR | S_IWUSR);
- if (write_all (fd, out.buf, out.len) == 0) {
-#ifdef HAVE_FSYNC
- fsync (fd);
-#endif
- close (fd);
- if (rename (template, file) == 0) {
- if (stat (file, &statbuf) == 0)
- gkr_location_manager_note_mtime (NULL,
- keyring->location, statbuf.st_mtime);
- } else {
- unlink (template);
- }
- } else {
- close (fd);
- }
- } else {
- g_warning ("Can't open keyring save file %s", template);
- perror ("mkstemp error: ");
- ret = FALSE;
- }
- g_free (template);
- g_free (dirname);
- } else {
- g_warning ("Internal error: Unable to generate data for keyring %s\n", keyring->keyring_name);
- ret = FALSE;
- }
-
- egg_buffer_uninit (&out);
- g_free (file);
- return ret;
-}
-
-gboolean
-gkr_keyring_lock (GkrKeyring *keyring)
-{
- if (keyring->locked)
- return TRUE;
-
- /* Never lock the session keyring */
- if (!keyring->location)
- return TRUE;
-
- /* Password will be null for textual keyrings */
- if (keyring->password != NULL) {
- egg_secure_strfree (keyring->password);
- keyring->password = NULL;
- }
-
- if (!gkr_keyring_update_from_disk (keyring)) {
- /* Failed to re-read, remove the keyring */
- g_warning ("Couldn't re-read keyring %s\n", keyring->keyring_name);
- gkr_keyrings_remove (keyring);
- }
-
- return TRUE;
-}
-
-gboolean
-gkr_keyring_unlock (GkrKeyring *keyring, const gchar *password)
-{
- if (!keyring->locked)
- return TRUE;
-
- g_return_val_if_fail (keyring->password == NULL, FALSE);
-
- keyring->password = egg_secure_strdup (password);
- if (!gkr_keyring_update_from_disk (keyring)) {
- egg_secure_strfree (keyring->password);
- keyring->password = NULL;
- }
- if (keyring->locked) {
- g_assert (keyring->password == NULL);
- return FALSE;
- } else {
- g_assert (keyring->password != NULL);
- return TRUE;
- }
-}
-
-gboolean
-gkr_keyring_is_insecure (GkrKeyring *keyring)
-{
- /* It's locked, must have encryption */
- if (keyring->locked)
- return FALSE;
-
- /* Only in memory == secure */
- if (!keyring->location)
- return FALSE;
-
- /* No or empty password == insecure */
- if (!keyring->password || !keyring->password[0])
- return TRUE;
-
- return FALSE;
-}
-
-gboolean
-gkr_keyring_ask_check_unlock (GkrAskRequest* ask)
-{
- GkrKeyring *keyring;
- const gchar *password;
- gchar *display;
-
- keyring = GKR_KEYRING (gkr_ask_request_get_object (ask));
- g_assert (GKR_IS_KEYRING (keyring));
-
- if (!keyring->locked) {
- ask->response = GKR_ASK_RESPONSE_ALLOW;
- return GKR_ASK_STOP_REQUEST;
- }
-
- /* If they typed a password, try it out */
- if (ask->response >= GKR_ASK_RESPONSE_ALLOW) {
-
- g_assert (ask->typed_password);
- if (!gkr_keyring_unlock (keyring, ask->typed_password)) {
- /* Bad password, try again */
- ask->response = GKR_ASK_RESPONSE_NONE;
- return GKR_ASK_CONTINUE_REQUEST;
- }
-
- /* Did they ask us to remember the password? */
- if (ask->checked) {
- display = g_strdup_printf (_("Unlock password for %s keyring"),
- keyring->keyring_name);
- gkr_keyring_login_attach_secret (GNOME_KEYRING_ITEM_CHAINED_KEYRING_PASSWORD,
- display, ask->typed_password,
- "keyring", gkr_location_to_string (keyring->location), NULL);
- g_free (display);
- }
- }
-
- /*
- * We can automatically unlock keyrings that have their password
- * stored in the 'login' keyring.
- */
- password = gkr_keyring_login_lookup_secret (GNOME_KEYRING_ITEM_CHAINED_KEYRING_PASSWORD,
- "keyring", gkr_location_to_string (keyring->location), NULL);
- if (password) {
- if (gkr_keyring_unlock (keyring, password)) {
-
- /* A good password, unlocked, all done */
- ask->response = GKR_ASK_RESPONSE_ALLOW;
- return GKR_ASK_STOP_REQUEST;
-
- } else {
-
- /* A bad internal password */
- gkr_keyring_login_remove_secret (GNOME_KEYRING_ITEM_CHAINED_KEYRING_PASSWORD,
- "keyring", gkr_location_to_string (keyring->location), NULL);
- }
- }
-
- /* If the keyring is unlocked then no need to continue */
- if (!keyring->locked) {
- ask->response = GKR_ASK_RESPONSE_ALLOW;
- return GKR_ASK_STOP_REQUEST;
- }
-
- return GKR_ASK_DONT_CARE;
-}
diff --git a/daemon/keyrings/gkr-keyring.h b/daemon/keyrings/gkr-keyring.h
deleted file mode 100644
index 26425ab3..00000000
--- a/daemon/keyrings/gkr-keyring.h
+++ /dev/null
@@ -1,145 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* gkr-keyring.h - represents a keyring in memory, and functionality save/load
-
- 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 __GKR_KEYRING_H__
-#define __GKR_KEYRING_H__
-
-/*
- * TODO: The internals of a GkrKeyring should probably be further
- * abstracted away and accessed via accessor methods and properties.
- */
-
-#include <glib-object.h>
-
-#include "gkr-keyring-item.h"
-
-#include "egg/egg-buffer.h"
-
-#include "library/gnome-keyring.h"
-
-#include "ui/gkr-ask-request.h"
-
-G_BEGIN_DECLS
-
-#define GKR_TYPE_KEYRING (gkr_keyring_get_type())
-#define GKR_KEYRING(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GKR_TYPE_KEYRING, GkrKeyring))
-#define GKR_KEYRING_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GKR_TYPE_KEYRING, GObject))
-#define GKR_IS_KEYRING(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GKR_TYPE_KEYRING))
-#define GKR_IS_KEYRING_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GKR_TYPE_KEYRING))
-#define GKR_KEYRING_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GKR_TYPE_KEYRING, GkrKeyringClass))
-
-typedef struct _GkrKeyringClass GkrKeyringClass;
-
-struct _GkrKeyring {
- GObject parent;
-
- /* NULL if memory only */
- GQuark location;
-
- /* If known: */
- char *password;
- gboolean locked;
- gboolean asking_password;
-
- /* Whether the salt and hash_iterations members are populated */
- gboolean salt_valid;
-
- /* On disk data: */
- guchar salt[8];
- guint32 hash_iterations;
-
- char *keyring_name;
- GList *items;
-
- time_t ctime;
- time_t mtime;
-
- gboolean lock_on_idle;
- guint lock_timeout;
-};
-
-struct _GkrKeyringClass {
- GObjectClass parent_class;
-
- void (*item_added) (GkrKeyring* keyring, GkrKeyringItem* item);
-
- void (*item_removed) (GkrKeyring* keyring, GkrKeyringItem* item);
-};
-
-GType gkr_keyring_get_type (void) G_GNUC_CONST;
-
-GkrKeyring* gkr_keyring_new (const gchar* name, GQuark location);
-
-GkrKeyring* gkr_keyring_create (GQuark volume, const gchar* name, const gchar* password);
-
-guint gkr_keyring_get_new_id (GkrKeyring *keyring);
-
-GkrKeyringItem* gkr_keyring_get_item (GkrKeyring *keyring, guint id);
-
-GkrKeyringItem* gkr_keyring_find_item (GkrKeyring *keyring, GnomeKeyringItemType type,
- GnomeKeyringAttributeList *attrs, gboolean match_all);
-
-void gkr_keyring_add_item (GkrKeyring* keyring, GkrKeyringItem* item);
-
-void gkr_keyring_remove_item (GkrKeyring* keyring, GkrKeyringItem* item);
-
-gboolean gkr_keyring_update_from_disk (GkrKeyring *keyring);
-
-gboolean gkr_keyring_remove_from_disk (GkrKeyring *keyring);
-
-gboolean gkr_keyring_save_to_disk (GkrKeyring *keyring);
-
-gboolean gkr_keyring_lock (GkrKeyring *keyring);
-
-gboolean gkr_keyring_unlock (GkrKeyring *keyring, const gchar *password);
-
-void gkr_keyrings_set_item (GkrKeyring *keyring, GnomeKeyringItemType type,
- const gchar *display_name, const gchar *secret,
- GnomeKeyringAttributeList *attrs);
-
-gboolean gkr_keyring_is_insecure (GkrKeyring *keyring);
-
-/* Used with the check-request signal on GkrAskRequest to unlock a keyring */
-gboolean gkr_keyring_ask_check_unlock (GkrAskRequest* ask);
-
-/* -----------------------------------------------------------------------------
- * FILE FORMATS
- *
- * gint return value:
- * -1 : error
- * 0 : unrecognized
- * 1 : successful
- */
-
-gboolean gkr_keyring_textual_generate (GkrKeyring *keyring, EggBuffer *buffer);
-
-gboolean gkr_keyring_binary_generate (GkrKeyring *keyring, EggBuffer *buffer);
-
-gint gkr_keyring_textual_parse (GkrKeyring *keyring, EggBuffer *buffer);
-
-gint gkr_keyring_binary_parse (GkrKeyring *keyring, EggBuffer *buffer);
-
-G_END_DECLS
-
-#endif /* __GKR_KEYRING_H__ */
-
diff --git a/daemon/keyrings/gkr-keyrings.c b/daemon/keyrings/gkr-keyrings.c
deleted file mode 100644
index a8ad4d20..00000000
--- a/daemon/keyrings/gkr-keyrings.c
+++ /dev/null
@@ -1,406 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* gkr-keyrings.c - the global list of keyrings
-
- Copyright (C) 2003 Red Hat, Inc
- Copyright (C) 2007 Stefan Walter
-
- Gnome keyring is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- Gnome keyring 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
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- Author: Alexander Larsson <alexl@redhat.com>
- Author: Stef Walter <stef@memberwebs.com>
-*/
-
-#include "config.h"
-
-#include "gkr-keyrings.h"
-
-#include "egg/egg-cleanup.h"
-
-#include "library/gnome-keyring-proto.h"
-
-#include "util/gkr-location.h"
-#include "util/gkr-location-watch.h"
-
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <sys/stat.h>
-#include <glib.h>
-#include <strings.h>
-
-#define LOC_DEFAULT_FILE (gkr_location_from_string ("LOCAL:/keyrings/default"))
-
-static gboolean keyrings_inited = FALSE;
-static gboolean keyrings_loaded = FALSE;
-
-static GList *keyrings = NULL;
-
-static GkrKeyring *session_keyring = NULL;
-static gchar *default_keyring = NULL;
-
-static GkrLocationWatch *location_watch = NULL;
-
-/* -----------------------------------------------------------------------------
- * HELPERS
- */
-
-static int
-write_all (int fd, const char *buf, size_t len)
-{
- size_t bytes;
- int res;
-
- bytes = 0;
- while (bytes < len) {
- res = write (fd, buf + bytes, len - bytes);
- if (res < 0) {
- if (errno != EINTR &&
- errno != EAGAIN) {
- perror ("write_all write failure:");
- return -1;
- }
- } else {
- bytes += res;
- }
- }
- return 0;
-}
-
-static void
-update_default (void)
-{
- gchar *contents;
-
- if (gkr_location_read_file (LOC_DEFAULT_FILE, (guchar**)&contents, NULL, NULL)) {
- g_strstrip (contents);
- if (!contents[0]) {
- g_free (contents);
- contents = NULL;
- }
- g_free (default_keyring);
- default_keyring = contents;
- }
-}
-
-static void
-load_keyring (GkrLocationWatch *watch, GQuark loc, gpointer unused)
-{
- GkrKeyring *keyring;
- gboolean updated = FALSE;
- GList *l;
-
- /* Still need to check for file updates */
- for (l = keyrings; l != NULL; l = l->next) {
- keyring = GKR_KEYRING (l->data);
- if (keyring->location && keyring->location == loc) {
- gkr_keyring_update_from_disk (keyring);
- updated = TRUE;
- }
- }
-
- if (updated)
- return;
-
- /* Make a new blank keyring and add it */
- keyring = gkr_keyring_new ("", loc);
- gkr_keyrings_add (keyring);
- g_object_unref (keyring);
-
- /* Try and update/load it */
- if (!gkr_keyring_update_from_disk (keyring) ||
- !keyring->keyring_name || !keyring->keyring_name[0])
- gkr_keyrings_remove (keyring);
-}
-
-static void
-remove_keyring (GkrLocationWatch *watch, GQuark loc, gpointer unused)
-{
- GkrKeyring *keyring;
- GList *l;
-
- g_return_if_fail (loc);
-
- /* Find the keyring that dissappeared, and remove it from our list */
- for (l = keyrings; l; l = g_list_next (l)) {
- keyring = GKR_KEYRING (l->data);
- if (keyring->location && keyring->location == loc)
- gkr_keyrings_remove (keyring);
- }
-}
-
-static void
-keyrings_cleanup (gpointer unused)
-{
- GkrKeyring *keyring;
-
- g_assert (keyrings_inited);
-
- g_assert (location_watch);
- g_object_unref (location_watch);
- location_watch = NULL;
-
- while (keyrings) {
- keyring = GKR_KEYRING (keyrings->data);
- if (keyring == session_keyring)
- session_keyring = NULL;
- keyrings = g_list_remove (keyrings, keyring);
- g_object_unref (keyring);
- }
-
- g_free (default_keyring);
- default_keyring = NULL;
-
- g_assert (session_keyring == NULL);
- keyrings_inited = FALSE;
-}
-
-static void
-keyrings_init (void)
-{
- GQuark loc;
- gchar *path;
-
- if (keyrings_inited)
- return;
- keyrings_inited = TRUE;
-
- /* Make the local keyrings directory */
- loc = gkr_location_from_string ("LOCAL:/keyrings");
- g_assert (loc);
- path = gkr_location_to_path (loc);
- if (g_mkdir_with_parents (path, S_IRWXU) < 0)
- g_warning ("unable to create keyring dir");
- g_free (path);
-
- /* Create the session keyring */
- g_assert (!session_keyring);
- session_keyring = gkr_keyring_new ("session", 0);
- gkr_keyrings_add (session_keyring);
- g_object_unref (session_keyring);
-
- g_assert (!location_watch);
- location_watch = gkr_location_watch_new (NULL, 0, "keyrings", "*.keyring", NULL);
- g_signal_connect (location_watch, "location-added", G_CALLBACK (load_keyring), NULL);
- g_signal_connect (location_watch, "location-changed", G_CALLBACK (load_keyring), NULL);
- g_signal_connect (location_watch, "location-removed", G_CALLBACK (remove_keyring), NULL);
-
- egg_cleanup_register (keyrings_cleanup, NULL);
-}
-
-/* -----------------------------------------------------------------------------
- * PUBLIC
- */
-
-GkrKeyring*
-gkr_keyrings_get_default (void)
-{
- GkrKeyring *keyring = NULL;
-
- keyrings_init ();
- if (!default_keyring)
- update_default ();
-
- if (default_keyring != NULL)
- keyring = gkr_keyrings_find (default_keyring);
-
- /*
- * We prefer to make the 'login' keyring the default
- * keyring when nothing else is setup.
- */
- if (keyring == NULL)
- keyring = gkr_keyrings_get_login ();
-
- /*
- * Otherwise fall back to the 'default' keyring setup
- * if PAM integration is borked, and the user had to
- * create a new keyring.
- */
- if (keyring == NULL)
- keyring = gkr_keyrings_find ("default");
-
- return keyring;
-}
-
-void
-gkr_keyrings_set_default (GkrKeyring *keyring)
-{
- char *path;
- const gchar *data;
- int fd;
-
- keyrings_init ();
-
- path = gkr_location_to_path (LOC_DEFAULT_FILE);
- fd = open (path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
- if (fd != -1) {
- data = (keyring && keyring->keyring_name) ? keyring->keyring_name : "";
- write_all (fd, data, strlen (data));
-#ifdef HAVE_FSYNC
- fsync (fd);
-#endif
- close (fd);
- }
-
- g_free (path);
-
- g_free (default_keyring);
- default_keyring = keyring ? g_strdup (keyring->keyring_name) : NULL;
-}
-
-GkrKeyring*
-gkr_keyrings_get_login (void)
-{
- return gkr_keyrings_find ("login");
-}
-
-void
-gkr_keyrings_update (void)
-{
- keyrings_init ();
- gkr_location_watch_refresh (location_watch, FALSE);
- update_default ();
- keyrings_loaded = TRUE;
-}
-
-void
-gkr_keyrings_add (GkrKeyring *keyring)
-{
- GList *l;
-
- keyrings_init ();
-
- g_assert (GKR_IS_KEYRING (keyring));
-
- /* Can't add the same keyring twice */
- g_assert (g_list_find (keyrings, keyring) == NULL);
-
- /* Can't add two keyrings for the same location */
- for (l = keyrings; l; l = g_list_next (l)) {
- if (((GkrKeyring*)l->data)->location == keyring->location) {
- g_warning ("two keyrings added for the same location: %s",
- gkr_location_to_string (keyring->location));
- }
- }
-
- keyrings = g_list_prepend (keyrings, keyring);
- g_object_ref (keyring);
-}
-
-void
-gkr_keyrings_remove (GkrKeyring *keyring)
-{
- keyrings_init ();
-
- g_assert (GKR_IS_KEYRING (keyring));
-
- if (g_list_find (keyrings, keyring)) {
-
- if (default_keyring &&
- strcmp (keyring->keyring_name, default_keyring) == 0)
- gkr_keyrings_set_default (NULL);
-
- keyrings = g_list_remove (keyrings, keyring);
-
- g_object_unref (keyring);
- }
-}
-
-GkrKeyring*
-gkr_keyrings_get_session (void)
-{
- keyrings_init ();
- g_assert (session_keyring);
- return session_keyring;
-}
-
-GkrKeyring*
-gkr_keyrings_find (const gchar *name)
-{
- GkrKeyring *keyring;
- GList *l;
-
- keyrings_init ();
-
- if (!keyrings_loaded)
- gkr_keyrings_update ();
-
- if (name == NULL)
- return gkr_keyrings_get_default ();
-
- for (l = keyrings; l != NULL; l = l->next) {
- keyring = GKR_KEYRING (l->data);
- if (strcmp (keyring->keyring_name, name) == 0) {
- return keyring;
- }
- }
-
- return NULL;
-}
-
-GkrKeyring*
-gkr_keyrings_for_location (GQuark location)
-{
- GkrKeyring *keyring;
- GList *l;
-
- keyrings_init ();
-
- for (l = keyrings; l != NULL; l = l->next) {
- keyring = GKR_KEYRING (l->data);
- if (keyring->location == location)
- return keyring;
- }
-
- /* Try and load the keyring */
- if (gkr_location_test_file (location, G_FILE_TEST_IS_REGULAR)) {
- keyring = gkr_keyring_new ("", location);
- if (gkr_keyring_update_from_disk (keyring)) {
- gkr_keyrings_add (keyring);
- g_object_unref (keyring);
- return keyring;
- }
-
- g_object_unref (keyring);
- }
-
- return NULL;
-}
-
-gboolean
-gkr_keyrings_foreach (GkrKeyringEnumFunc func, gpointer data)
-{
- GList *l;
-
- keyrings_init ();
-
- for (l = keyrings; l != NULL; l = l->next) {
- if (!(func) (GKR_KEYRING (l->data), data))
- return FALSE;
- }
-
- return TRUE;
-}
-
-guint
-gkr_keyrings_get_count (void)
-{
- keyrings_init ();
- return g_list_length (keyrings);
-}
diff --git a/daemon/keyrings/gkr-keyrings.h b/daemon/keyrings/gkr-keyrings.h
deleted file mode 100644
index dac44858..00000000
--- a/daemon/keyrings/gkr-keyrings.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* gkr-keyrings.h - the global list of keyrings
-
- 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 __GKR_KEYRINGS_H__
-#define __GKR_KEYRINGS_H__
-
-#include "gkr-keyring.h"
-
-void gkr_keyrings_update (void);
-
-GkrKeyring* gkr_keyrings_get_default (void);
-
-void gkr_keyrings_set_default (GkrKeyring *keyring);
-
-GkrKeyring* gkr_keyrings_get_login (void);
-
-void gkr_keyrings_add (GkrKeyring *keyring);
-
-void gkr_keyrings_remove (GkrKeyring *keyring);
-
-GkrKeyring* gkr_keyrings_find (const gchar *name);
-
-GkrKeyring* gkr_keyrings_for_location (GQuark location);
-
-GkrKeyring* gkr_keyrings_get_session (void);
-
-guint gkr_keyrings_get_count (void);
-
-typedef gboolean (*GkrKeyringEnumFunc) (GkrKeyring* keyring, gpointer data);
-gboolean gkr_keyrings_foreach (GkrKeyringEnumFunc func, gpointer data);
-
-#endif /* __GKR_KEYRINGS_H__ */
-
diff --git a/daemon/keyrings/tests/.gitignore b/daemon/keyrings/tests/.gitignore
deleted file mode 100644
index cb6e6dfb..00000000
--- a/daemon/keyrings/tests/.gitignore
+++ /dev/null
@@ -1,5 +0,0 @@
-/run-keyrings-test.*
-/run-*-test*
-/.*
-/Makefile
-/Makefile.in
diff --git a/daemon/keyrings/tests/Makefile.am b/daemon/keyrings/tests/Makefile.am
deleted file mode 100644
index a24f5358..00000000
--- a/daemon/keyrings/tests/Makefile.am
+++ /dev/null
@@ -1,19 +0,0 @@
-
-UNIT_AUTO = \
- unit-test-keyring-login.c \
- unit-test-keyring-file.c
-
-UNIT_PROMPT = \
- unit-test-login-prompt.c
-
-UNIT_LIBS = \
- $(top_builddir)/daemon/keyrings/libgkr-keyrings.la \
- $(top_builddir)/daemon/ui/libgkr-ui.la \
- $(top_builddir)/daemon/util/libgkr-daemon-util.la \
- $(top_builddir)/library/libgnome-keyring-common.la \
- $(top_builddir)/egg/libegg-dbus.la \
- $(top_builddir)/egg/libegg.la
-
-EXTRA_DIST = test-data
-
-include $(top_srcdir)/tests/gtest.make
diff --git a/daemon/keyrings/tests/test-data/encrypted.keyring b/daemon/keyrings/tests/test-data/encrypted.keyring
deleted file mode 100644
index 742aecc3..00000000
--- a/daemon/keyrings/tests/test-data/encrypted.keyring
+++ /dev/null
Binary files differ
diff --git a/daemon/keyrings/tests/test-data/plain.keyring b/daemon/keyrings/tests/test-data/plain.keyring
deleted file mode 100644
index c048aa10..00000000
--- a/daemon/keyrings/tests/test-data/plain.keyring
+++ /dev/null
@@ -1,55 +0,0 @@
-
-[keyring]
-display-name=unit-test-keyring
-ctime=1198027852
-mtime=1198027852
-lock-on-idle=false
-lock-timeout=0
-
-[2]
-item-type=0
-display-name=Another display name
-secret=item-secret
-mtime=1198027852
-ctime=1198027852
-
-[2:acl0]
-display-name=run-auto-test
-path=/data/projects/gnome-keyring/library/tests/.libs/run-auto-test
-read-access=true
-write-access=true
-remove-access=true
-
-[3]
-item-type=0
-display-name=Barnyard
-secret=item-secret
-mtime=1198027852
-ctime=1198027852
-
-[3:attribute0]
-name=dog
-type=string
-value=woof
-
-[3:attribute1]
-name=bird
-type=string
-value=cheep
-
-[3:attribute2]
-name=iguana
-type=string
-value=
-
-[3:attribute3]
-name=num
-type=uint32
-value=3
-
-[3:acl0]
-display-name=run-auto-test
-path=/data/projects/gnome-keyring/library/tests/.libs/run-auto-test
-read-access=true
-write-access=true
-remove-access=true
diff --git a/daemon/keyrings/tests/unit-test-keyring-file.c b/daemon/keyrings/tests/unit-test-keyring-file.c
deleted file mode 100644
index 7d36da87..00000000
--- a/daemon/keyrings/tests/unit-test-keyring-file.c
+++ /dev/null
@@ -1,248 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* unit-test-keyrings-file.c: Test Keyring file formats
-
- 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 "run-auto-test.h"
-
-#include "egg/egg-secure-memory.h"
-
-#include "keyrings/gkr-keyring.h"
-
-#include "library/gnome-keyring-private.h"
-
-#include "util/gkr-location.h"
-
-#include <glib.h>
-#include <string.h>
-
-static GQuark
-location_for_test_data (const gchar *filename)
-{
- GQuark quark;
- gchar *path;
-
- path = test_data_filename (filename);
- quark = gkr_location_from_path (path);
- g_free (path);
-
- return quark;
-}
-
-static void
-validate_keyring_contents (GkrKeyring *keyring)
-{
- GnomeKeyringAccessControl *ac;
- GkrKeyringItem* item;
- GArray *attrs;
-
- /* The keyring itself */
- /* "Missing keyring name" */
- g_assert (keyring->keyring_name != NULL);
- /* "Invalid keyring name" */
- g_assert_cmpstr (keyring->keyring_name, ==, "unit-test-keyring");
- /* "Bad lock settings" */
- g_assert (!keyring->lock_on_idle && keyring->lock_timeout == 0);
- /* "Bad Creation Time" */
- g_assert_cmpint (keyring->ctime, ==, 1198027852);
- /* "Bad Modification Time" */
- g_assert_cmpint (keyring->mtime, ==, 1198027852);
- /* "Wrong number of items" */
- g_assert_cmpint (g_list_length (keyring->items), ==, 2);
-
- /* Item #2 */
- item = gkr_keyring_get_item (keyring, 2);
- /* "Couldn't find item" */
- g_assert (item != NULL);
- /* "Invalid item type" */
- g_assert_cmpint (item->type, ==, GNOME_KEYRING_ITEM_GENERIC_SECRET);
- /* "Missing secret" */
- g_assert (item->secret != NULL);
- /* "Wrong secret" */
- g_assert_cmpstr (item->secret, ==, "item-secret");
- /* "Bad Creation Time" */
- g_assert_cmpint (item->ctime, ==, 1198027852);
-
- /* Item #2 ACL */
- /* "Bad ACLs" */
- g_assert_cmpint (g_list_length (item->acl), ==, 1);
- ac = (GnomeKeyringAccessControl*)item->acl->data;
- /* "Invalid ACL" */
- g_assert (ac && ac->application);
- /* "Invalid ACL Path" */
- g_assert (ac->application->pathname && strstr (ac->application->pathname, "run-auto-test"));
- /* "Invalid ACL Display Name" */
- g_assert (ac->application->display_name);
- g_assert_cmpstr (ac->application->display_name, ==, "run-auto-test");
- /* "Invalid ACL Access Type" */
- g_assert_cmpint (ac->types_allowed, ==, (GNOME_KEYRING_ACCESS_READ | GNOME_KEYRING_ACCESS_WRITE | GNOME_KEYRING_ACCESS_REMOVE));
-
- /* Item #3 */
- 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", 3);
- item = gkr_keyring_find_item (keyring, GNOME_KEYRING_ITEM_GENERIC_SECRET, attrs, TRUE);
- gnome_keyring_attribute_list_free (attrs);
- /* "Couldn't find item #3" */
- g_assert (item != NULL);
- /* "Invalid item found" */
- g_assert_cmpint (item->id, ==, 3);
- /* "Invalid item type" */
- g_assert_cmpint (item->type, ==, GNOME_KEYRING_ITEM_GENERIC_SECRET);
- /* "Missing secret" */
- g_assert (item->secret != NULL);
- /* "Wrong secret" */
- g_assert_cmpstr (item->secret, ==, "item-secret");
-}
-
-DEFINE_TEST(keyring_parse_encrypted)
-{
- GkrKeyring *encrypted, *plain;
- EggBuffer buffer, output;
- guchar *data;
- gsize n_data;
- gint ret;
- gboolean success;
-
- encrypted = gkr_keyring_new ("encrypted", 0);
- encrypted->password = "my-keyring-password";
- plain = gkr_keyring_new ("plain", 0);
-
- data = test_data_read ("encrypted.keyring", &n_data);
-
- /* Parse it */
- egg_buffer_init_allocated (&buffer, data, n_data, NULL);
- data = g_memdup (data, n_data); /* Make a copy for double parse */
- ret = gkr_keyring_binary_parse (encrypted, &buffer);
- egg_buffer_uninit (&buffer);
- /* "couldn't parse encrypted keyring" */
- g_assert (ret == 1);
- /* "didn't unlock encrypted keyring" */
- g_assert (!encrypted->locked);
-
- validate_keyring_contents (encrypted);
-
- /* Double parse shouldn't change it */
- egg_buffer_init_allocated (&buffer, (guchar*)data, n_data, NULL);
- ret = gkr_keyring_binary_parse (encrypted, &buffer);
- egg_buffer_uninit (&buffer);
- /* "couldn't parse encrypted keyring" */
- g_assert (ret == 1);
- /* "didn't unlock encrypted keyring" */
- g_assert (!encrypted->locked);
-
- validate_keyring_contents (encrypted);
-
- /* Output same data in the cleartext format */
- egg_buffer_init (&output, 128);
- success = gkr_keyring_textual_generate (encrypted, &output);
- /* "couldn't generate textual data" */
- g_assert (success);
-
- /* Make sure it parses */
- ret = gkr_keyring_textual_parse (plain, &output);
- /* "couldn't parse generated textual data" */
- g_assert (ret == 1);
- /* "keyring should not be locked" */
- g_assert (!plain->locked);
-
- validate_keyring_contents (plain);
-}
-
-DEFINE_TEST(keyring_parse_plain)
-{
- GkrKeyring *keyring;
- EggBuffer buffer;
- guchar *data;
- gsize n_data;
- gint ret;
-
- keyring = gkr_keyring_new ("plain", 0);
-
- data = test_data_read ("plain.keyring", &n_data);
-
- /* Parse it */
- egg_buffer_init_static (&buffer, (guchar*)data, n_data);
- ret = gkr_keyring_textual_parse (keyring, &buffer);
- /* "couldn't parse generated textual data" */
- g_assert (ret == 1);
- /* "keyring should not be locked" */
- g_assert (!keyring->locked);
-
- validate_keyring_contents (keyring);
-
- /* Double parse shouldn't change it */
- egg_buffer_init_static (&buffer, (guchar*)data, n_data);
- ret = gkr_keyring_textual_parse (keyring, &buffer);
- /* "couldn't parse generated textual data" */
- g_assert (ret == 1);
- /* "keyring should not be locked" */
- g_assert (!keyring->locked);
-
- validate_keyring_contents (keyring);
-}
-
-DEFINE_TEST(keyring_double_lock_encrypted)
-{
- GkrKeyring *encrypted;
- gboolean ret;
-
- encrypted = gkr_keyring_new ("encrypted", location_for_test_data ("encrypted.keyring"));
- encrypted->password = egg_secure_strdup ("my-keyring-password");
- ret = gkr_keyring_update_from_disk (encrypted);
- /* "couldn't parse generated textual data" */
- g_assert (ret == TRUE);
-
- /* Lock it */
- gkr_keyring_lock (encrypted);
- g_assert (encrypted->locked);
-
- /* Should succeed */
- gkr_keyring_lock (encrypted);
- g_assert (encrypted->locked);
-
- g_object_unref (encrypted);
-}
-
-DEFINE_TEST(keyring_double_lock_plain)
-{
- GkrKeyring *keyring;
- gboolean ret;
-
- keyring = gkr_keyring_new ("plain", location_for_test_data ("plain.keyring"));
- ret = gkr_keyring_update_from_disk (keyring);
- /* "couldn't parse generated textual data" */
- g_assert (ret == TRUE);
-
- /* Lock it, shouldn't actually work, no way to lock */
- gkr_keyring_lock (keyring);
- g_assert (!keyring->locked);
-
- /* Shouldn't crash */
- gkr_keyring_lock (keyring);
- g_assert (!keyring->locked);
-
- g_object_unref (keyring);
-}
diff --git a/daemon/keyrings/tests/unit-test-keyring-login.c b/daemon/keyrings/tests/unit-test-keyring-login.c
deleted file mode 100644
index d6f236c8..00000000
--- a/daemon/keyrings/tests/unit-test-keyring-login.c
+++ /dev/null
@@ -1,157 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* unit-test-keyrings-login.c: Test Login 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>
-*/
-
-#include "config.h"
-
-#include "run-auto-test.h"
-
-#include "keyrings/gkr-keyrings.h"
-#include "keyrings/gkr-keyring-login.h"
-
-#include "ui/gkr-ask-daemon.h"
-
-#include "util/gkr-location.h"
-
-#include <glib.h>
-#include <memory.h>
-
-DEFINE_SETUP(keyrings_login)
-{
- gkr_keyrings_update();
-
- /* Remove the current login keyring */
- GkrKeyring *login = gkr_keyrings_get_login ();
- if (login) {
- gkr_keyring_remove_from_disk (login);
- gkr_keyrings_remove (login);
- }
-}
-
-static void
-verify_no_ask (GkrAskRequest *req, gpointer unused)
-{
- /* "should not have prompted" */
- g_assert_not_reached ();
-}
-
-DEFINE_TEST(keyrings_login)
-{
- GkrKeyring *login;
- gboolean ret;
-
- gkr_ask_daemon_set_hook (verify_no_ask, NULL);
-
- /* Unlock and create a new login keyring */
- ret = gkr_keyring_login_unlock ("blah");
- /* "gkr_keyring_login_unlock() return FALSE" */
- g_assert (ret);
- /* "login not marked unlocked" */
- g_assert (gkr_keyring_login_is_unlocked ());
-
- /* Make sure it worked */
- login = gkr_keyrings_get_login ();
- /* "invalid keyring created by gkr_keyring_login_unlock()" */
- g_assert (login != NULL);
-
- /* Now lock it */
- gkr_keyring_login_lock ();
- /* "didn't lock right keyring" */
- g_assert (login->locked);
- /* "login not marked locked" */
- g_assert (!gkr_keyring_login_is_unlocked ());
-
- /* And unlock it again */
- ret = gkr_keyring_login_unlock ("blah");
- /* "gkr_keyring_login_unlock() returned FALSE" */
- g_assert (ret);
-
- /* Make sure it didn't create a new keyring */
- /* "gkr_keyring_login_unlock() created a second keyring" */
- g_assert (login == gkr_keyrings_get_login());
-}
-
-DEFINE_TEST(keyrings_login_master)
-{
- const gchar *master;
- gboolean ret;
-
- /* Unlock and create a new login keyring */
- ret = gkr_keyring_login_unlock ("blah");
- g_assert (ret);
-
- master = gkr_keyring_login_master();
- /* "no master password in login keyring" */
- g_assert (master != NULL);
- /* "wrong master password in login keyring" */
- g_assert_cmpstr (master, ==, "blah");
-}
-
-DEFINE_TEST(keyrings_login_secrets)
-{
- const gchar *password;
-
- /* Unlock and create a new login keyring */
- gkr_keyring_login_unlock ("blah");
-
- /* Save a password away */
- gkr_keyring_login_attach_secret (GNOME_KEYRING_ITEM_GENERIC_SECRET,
- "Display Name", "secret",
- "attr-string", "string",
- NULL);
-
- /* Look it up */
- password = gkr_keyring_login_lookup_secret (GNOME_KEYRING_ITEM_GENERIC_SECRET,
- "attr-string", "string",
- NULL);
- /* "no secret found in login keyring */
- g_assert (password != NULL);
- /* "wrong secret found in login keyring" */
- g_assert_cmpstr (password, ==, "secret");
-
- /* Change it to a different password */
- gkr_keyring_login_attach_secret (GNOME_KEYRING_ITEM_GENERIC_SECRET,
- "Display Name", "other",
- "attr-string", "string",
- NULL);
-
- /* Look it up */
- password = gkr_keyring_login_lookup_secret (GNOME_KEYRING_ITEM_GENERIC_SECRET,
- "attr-string", "string",
- NULL);
- /* "no secret found in login keyring" */
- g_assert (password != NULL);
- /* "wrong secret found in login keyring" */
- g_assert_cmpstr (password, ==, "other");
-
- /* Remove it */
- gkr_keyring_login_remove_secret (GNOME_KEYRING_ITEM_GENERIC_SECRET,
- "attr-string", "string",
- NULL);
-
- /* Look it up */
- password = gkr_keyring_login_lookup_secret (GNOME_KEYRING_ITEM_GENERIC_SECRET,
- "attr-string", "string",
- NULL);
- /* "secret wasn't deleted properly" */
- g_assert (password == NULL);
-}
diff --git a/daemon/keyrings/tests/unit-test-login-prompt.c b/daemon/keyrings/tests/unit-test-login-prompt.c
deleted file mode 100644
index b0f957db..00000000
--- a/daemon/keyrings/tests/unit-test-login-prompt.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* unit-test-keyrings-login.c: Test Login 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>
-*/
-
-#include "config.h"
-
-#include "run-prompt-test.h"
-
-#include "keyrings/gkr-keyrings.h"
-#include "keyrings/gkr-keyring-login.h"
-
-#include "ui/gkr-ask-daemon.h"
-
-#include <glib.h>
-#include <memory.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.
- */
-
-static void
-TELL(const char* what)
- { printf("INTERACTION: %s\n", what); }
-
-DEFINE_START(keyrings_login)
-{
- /* Remove the current login keyring */
- GkrKeyring *login = gkr_keyrings_get_login ();
- if (login)
- gkr_keyrings_remove (login);
-}
-
-static gboolean had_prompt = FALSE;
-
-static void
-verify_ask (GkrAskRequest *req, gpointer unused)
-{
- /* "should only have one prompt" */
- g_assert (!had_prompt);
- had_prompt = TRUE;
-}
-
-DEFINE_TEST(keyrings_login)
-{
- gboolean ret;
-
- gkr_ask_daemon_set_hook (verify_ask, NULL);
-
- /* "login not marked locked" */
- g_assert (!gkr_keyring_login_is_unlocked ());
-
- /* cancel the prompt */
- TELL("Press 'DENY'");
- had_prompt = FALSE;
- ret = gkr_keyring_login_unlock (NULL);
- /* "no prompt appeared" */
- g_assert (had_prompt);
- /* "gkr_keyring_login_unlock() return TRUE" */
- g_assert (!ret);
- /* "login not marked locked" */
- g_assert (!gkr_keyring_login_is_unlocked ());
-
- /* Now create a keyring */
- TELL("Type 'blah' and press 'OK'");
- had_prompt = FALSE;
- ret = gkr_keyring_login_unlock (NULL);
- /* "no prompt appeared" */
- g_assert (had_prompt);
- /* "gkr_keyring_login_unlock() return FALSE" */
- g_assert (ret);
- /* "login not marked unlocked" */
- g_assert (gkr_keyring_login_is_unlocked ());
-
- /* Now lock it */
- gkr_keyring_login_lock ();
- /* "didn't lock right keyring" */
- g_assert (!gkr_keyring_login_is_unlocked ());
-
- /* cancel the prompt */
- TELL("Press 'DENY'");
- had_prompt = FALSE;
- ret = gkr_keyring_login_unlock (NULL);
- /* "no prompt appeared" */
- g_assert (had_prompt);
- /* "gkr_keyring_login_unlock() return TRUE" */
- g_assert (!ret);
- /* "login not marked locked" */
- g_assert (!gkr_keyring_login_is_unlocked ());
-
- /* Now create a keyring */
- TELL("Type 'blah' and press 'OK'");
- had_prompt = FALSE;
- ret = gkr_keyring_login_unlock (NULL);
- /* "no prompt appeared" */
- g_assert (had_prompt);
- /* "gkr_keyring_login_unlock() return FALSE" */
- g_assert (ret);
- /* "login not marked unlocked" */
- g_assert (gkr_keyring_login_is_unlocked ());
-}
diff --git a/daemon/ui/gkr-ask-request.c b/daemon/ui/gkr-ask-request.c
index 4f952dca..da4a0d3b 100644
--- a/daemon/ui/gkr-ask-request.c
+++ b/daemon/ui/gkr-ask-request.c
@@ -30,12 +30,9 @@
#include "daemon/util/gkr-daemon-async.h"
+#include "egg/egg-buffer.h"
#include "egg/egg-secure-memory.h"
-#include "library/gnome-keyring.h"
-#include "library/gnome-keyring-private.h"
-#include "library/gnome-keyring-proto.h"
-
#include "util/gkr-location.h"
#include <unistd.h>
diff --git a/daemon/util/Makefile.am b/daemon/util/Makefile.am
index e69ec160..af3a588c 100644
--- a/daemon/util/Makefile.am
+++ b/daemon/util/Makefile.am
@@ -16,9 +16,8 @@ INCLUDES= \
libgkr_daemon_util_la_SOURCES = \
gkr-daemon-async.c gkr-daemon-async.h \
gkr-daemon-util.c gkr-daemon-util.h \
- gkr-location.c gkr-location.h \
- gkr-location-watch.c gkr-location-watch.h
-
+ gkr-location.c gkr-location.h
+
libgkr_daemon_util_la_LIBADD = \
$(GLIB_LIBS) \
$(GOBJECT_LIBS)
diff --git a/daemon/util/gkr-location-watch.c b/daemon/util/gkr-location-watch.c
deleted file mode 100644
index 3fb6543b..00000000
--- a/daemon/util/gkr-location-watch.c
+++ /dev/null
@@ -1,365 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* gkr-location-watch.c - Watch for changes in all base locations
-
- 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 "gkr-location-watch.h"
-
-#include <glib.h>
-#include <glib/gstdio.h>
-
-#include <sys/stat.h>
-#include <errno.h>
-#include <unistd.h>
-
-enum {
- LOCATION_ADDED,
- LOCATION_REMOVED,
- LOCATION_CHANGED,
- LAST_SIGNAL
-};
-
-typedef struct {
- GQuark parent;
- GkrLocationWatch *watch;
- GHashTable *checks;
-} UpdateDescendants;
-
-typedef struct _GkrLocationWatchPrivate GkrLocationWatchPrivate;
-struct _GkrLocationWatchPrivate {
- /* Specification */
- GPatternSpec *include;
- GPatternSpec *exclude;
- gchar *subdir;
- GQuark only_volume;
-
- /* Matched Locations */
- GHashTable *locations;
-};
-
-#define GKR_LOCATION_WATCH_GET_PRIVATE(o) \
- (G_TYPE_INSTANCE_GET_PRIVATE((o), GKR_TYPE_LOCATION_WATCH, GkrLocationWatchPrivate))
-
-G_DEFINE_TYPE (GkrLocationWatch, gkr_location_watch, G_TYPE_OBJECT);
-
-static guint signals[LAST_SIGNAL] = { 0 };
-
-/* -----------------------------------------------------------------------------
- * HELPERS
- */
-
-static void
-copy_key_value (gpointer key, gpointer value, gpointer data)
-{
- GHashTable *dest = (GHashTable*)data;
- g_hash_table_replace (dest, key, value);
-}
-
-static void
-remove_locations (gpointer key, gpointer value, gpointer data)
-{
- GkrLocationWatch *watch = GKR_LOCATION_WATCH (data);
- GkrLocationWatchPrivate *pv = GKR_LOCATION_WATCH_GET_PRIVATE (watch);
-
- g_hash_table_remove (pv->locations, key);
- g_signal_emit (watch, signals[LOCATION_REMOVED], 0, GPOINTER_TO_UINT(key));
-}
-
-static gboolean
-update_location (GkrLocationWatch *watch, gboolean force_all, GQuark location)
-{
- GkrLocationWatchPrivate *pv = GKR_LOCATION_WATCH_GET_PRIVATE (watch);
- struct stat sb;
- gchar *path;
-
- /* TODO: Allocating and freeing this all the time is braindead */
- path = gkr_location_to_path (location);
- if (!path)
- return FALSE;
-
- if (stat (path, &sb) < 0) {
- if (errno != ENOENT && errno != ENOTDIR && errno != EPERM)
- g_warning ("couldn't stat file: %s: %s", path, g_strerror (errno));
- g_free (path);
- return FALSE;
- }
-
- g_free (path);
-
-
- /* See if it has actually changed */
- if (gkr_location_manager_note_mtime (watch->manager, location, sb.st_mtime) ||
- force_all) {
- g_assert (g_hash_table_lookup (pv->locations, GUINT_TO_POINTER (location)));
- g_signal_emit (watch, signals[LOCATION_CHANGED], 0, location);
- }
-
- return TRUE;
-}
-
-static void
-update_each_descendant (gpointer key, gpointer unused, gpointer data)
-{
- UpdateDescendants *ctx = (UpdateDescendants*)data;
- GQuark location = GPOINTER_TO_UINT (key);
-
- if (!gkr_location_is_descendant (ctx->parent, location))
- return;
-
- if (update_location (ctx->watch, FALSE, location))
- g_hash_table_remove (ctx->checks, GUINT_TO_POINTER (location));
-}
-
-static void
-update_volume (GkrLocationWatch *watch, GQuark volume, gboolean force_all,
- GHashTable *checks)
-{
- GkrLocationWatchPrivate *pv = GKR_LOCATION_WATCH_GET_PRIVATE (watch);
- UpdateDescendants uctx;
- struct stat sb;
- GQuark dirloc;
- GError *err = NULL;
- const char *filename;
- gpointer key;
- gchar *path;
- gchar *file;
- GDir *dir;
- GQuark loc;
- int ret, lasterr;
-
- g_assert (volume);
- g_assert (checks);
- g_assert (GKR_IS_LOCATION_WATCH (watch));
-
- dirloc = pv->subdir ? gkr_location_from_child (volume, pv->subdir) : volume;
- path = gkr_location_to_path (dirloc);
-
- /* Can't resolve the location? Skip. */
- if (!path)
- return;
-
- if (stat (path, &sb) < 0) {
- if (errno != ENOENT && errno != ENOTDIR && errno != EPERM)
- g_message ("couldn't stat directory: %s: %s", path, g_strerror (errno));
- g_free (path);
- return;
- }
-
- /* See if it was updated since last seen or not */
- if (!gkr_location_manager_note_mtime (watch->manager, dirloc, sb.st_mtime) &&
- !force_all) {
-
- uctx.parent = dirloc;
- uctx.watch = watch;
- uctx.checks = checks;
-
- /* Still need to check for individual file updates */
- g_hash_table_foreach (pv->locations, update_each_descendant, &uctx);
-
- g_free (path);
- return;
- }
-
- /* Actually list the directory */
- dir = g_dir_open (path, 0, &err);
- if (dir == NULL) {
- if (errno != ENOENT && errno != ENOTDIR && errno != EPERM)
- g_message ("couldn't list keyrings at: %s: %s", path,
- err && err->message ? err->message : "");
- g_error_free (err);
- g_free (path);
- return;
- }
-
- while ((filename = g_dir_read_name (dir)) != NULL) {
- if (filename[0] == '.')
- continue;
- if (pv->include && !g_pattern_match_string (pv->include, filename))
- continue;
- if (pv->exclude && g_pattern_match_string (pv->exclude, filename))
- continue;
-
- loc = gkr_location_from_child (dirloc, filename);
- g_assert (loc);
-
- /* If we hadn't yet seen this, then add it */
- key = GUINT_TO_POINTER (loc);
- if (!g_hash_table_remove (checks, key)) {
-
- /* Get the last modified time for this one */
- file = gkr_location_to_path (loc);
- g_assert (file);
- ret = g_stat (file, &sb);
- lasterr = errno;
-
- /* Couldn't access the file */
- if (ret < 0) {
- g_message ("couldn't stat file: %s: %s", file, g_strerror (lasterr));
- g_free (file);
- continue;
- }
-
- g_free (file);
-
- /* We don't do directories */
- if (sb.st_mode & S_IFDIR)
- continue;
-
- g_hash_table_replace (pv->locations, key, key);
- gkr_location_manager_note_mtime (watch->manager, loc, sb.st_mtime);
- g_signal_emit (watch, signals[LOCATION_ADDED], 0, loc);
-
- /* Otherwise we already had it, see if it needs updating */
- } else {
- update_location (watch, force_all, loc);
- }
- }
-
- g_dir_close (dir);
- g_free (path);
-}
-
-/* -----------------------------------------------------------------------------
- * OBJECT
- */
-
-static void
-gkr_location_watch_init (GkrLocationWatch *obj)
-{
- GkrLocationWatchPrivate *pv = GKR_LOCATION_WATCH_GET_PRIVATE (obj);
- pv->locations = g_hash_table_new (g_direct_hash, g_direct_equal);
-}
-
-static void
-gkr_location_watch_dispose (GObject *obj)
-{
- GkrLocationWatch *watch = GKR_LOCATION_WATCH (obj);
-
- if (watch->manager)
- g_object_unref (watch->manager);
- watch->manager = NULL;
-
- G_OBJECT_CLASS (gkr_location_watch_parent_class)->dispose (obj);
-}
-
-static void
-gkr_location_watch_finalize (GObject *obj)
-{
- GkrLocationWatch *watch = GKR_LOCATION_WATCH (obj);
- GkrLocationWatchPrivate *pv = GKR_LOCATION_WATCH_GET_PRIVATE (watch);
-
- if (pv->include)
- g_pattern_spec_free (pv->include);
- if (pv->exclude)
- g_pattern_spec_free (pv->exclude);
- g_free (pv->subdir);
-
- g_hash_table_destroy (pv->locations);
-
- G_OBJECT_CLASS (gkr_location_watch_parent_class)->finalize (obj);
-}
-
-static void
-gkr_location_watch_class_init (GkrLocationWatchClass *klass)
-{
- GObjectClass *gobject_class;
- gobject_class = (GObjectClass*) klass;
-
- gkr_location_watch_parent_class = g_type_class_peek_parent (klass);
- gobject_class->dispose = gkr_location_watch_dispose;
- gobject_class->finalize = gkr_location_watch_finalize;
-
- g_type_class_add_private (gobject_class, sizeof (GkrLocationWatchPrivate));
-
- signals[LOCATION_ADDED] = g_signal_new ("location-added", GKR_TYPE_LOCATION_WATCH,
- G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GkrLocationWatchClass, location_added),
- NULL, NULL, g_cclosure_marshal_VOID__UINT,
- G_TYPE_NONE, 1, G_TYPE_UINT);
-
- signals[LOCATION_CHANGED] = g_signal_new ("location-changed", GKR_TYPE_LOCATION_WATCH,
- G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GkrLocationWatchClass, location_changed),
- NULL, NULL, g_cclosure_marshal_VOID__UINT,
- G_TYPE_NONE, 1, G_TYPE_UINT);
-
- signals[LOCATION_REMOVED] = g_signal_new ("location-removed", GKR_TYPE_LOCATION_WATCH,
- G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GkrLocationWatchClass, location_removed),
- NULL, NULL, g_cclosure_marshal_VOID__UINT,
- G_TYPE_NONE, 1, G_TYPE_UINT);
-}
-
-GkrLocationWatch*
-gkr_location_watch_new (GkrLocationManager *locmgr, GQuark only_volume,
- const gchar *subdir, const gchar *include, const gchar *exclude)
-{
- GkrLocationWatch *watch = g_object_new (GKR_TYPE_LOCATION_WATCH, NULL);
- GkrLocationWatchPrivate *pv = GKR_LOCATION_WATCH_GET_PRIVATE (watch);
-
- if (!locmgr)
- locmgr = gkr_location_manager_get ();
-
- g_return_val_if_fail (GKR_IS_LOCATION_MANAGER (locmgr), NULL);
-
- /* TODO: Use properties */
- pv->include = include ? g_pattern_spec_new (include) : NULL;
- pv->exclude = exclude ? g_pattern_spec_new (exclude) : NULL;
- pv->subdir = g_strdup (subdir);
- pv->only_volume = only_volume;
-
- watch->manager = locmgr;
- g_object_ref (locmgr);
-
- return watch;
-}
-
-void
-gkr_location_watch_refresh (GkrLocationWatch *watch, gboolean force_all)
-{
- GkrLocationWatchPrivate *pv = GKR_LOCATION_WATCH_GET_PRIVATE (watch);
- GHashTable *checks;
- GSList *l, *volumes;
- GQuark volume;
-
- g_return_if_fail (GKR_IS_LOCATION_WATCH (watch));
-
- /* Copy into our check set */
- checks = g_hash_table_new (g_direct_hash, g_direct_equal);
- g_hash_table_foreach (pv->locations, copy_key_value, checks);
-
- /* If only one volume, then just try and access it directly */
- if (pv->only_volume) {
- if (gkr_location_manager_has_volume (watch->manager, pv->only_volume))
- update_volume (watch, pv->only_volume, force_all, checks);
-
- /* Go through each base location and update */
- } else {
- volumes = gkr_location_manager_get_volumes (watch->manager);
- for (l = volumes; l; l = g_slist_next (l)) {
- volume = GPOINTER_TO_UINT (l->data);
- update_volume (watch, volume, force_all, checks);
- }
- }
-
- /* Find any keyrings whose paths we didn't see */
- g_hash_table_foreach (checks, remove_locations, watch);
- g_hash_table_destroy (checks);
-}
diff --git a/daemon/util/gkr-location-watch.h b/daemon/util/gkr-location-watch.h
deleted file mode 100644
index dd87d32b..00000000
--- a/daemon/util/gkr-location-watch.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* gkr-location-watch.h - Watch for changes in all base locations
-
- 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 __GKR_LOCATION_WATCH_H__
-#define __GKR_LOCATION_WATCH_H__
-
-#include <glib-object.h>
-
-#include "gkr-location.h"
-
-G_BEGIN_DECLS
-
-#define GKR_TYPE_LOCATION_WATCH (gkr_location_watch_get_type ())
-#define GKR_LOCATION_WATCH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GKR_TYPE_LOCATION_WATCH, GkrLocationWatch))
-#define GKR_LOCATION_WATCH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GKR_TYPE_LOCATION_WATCH, GObject))
-#define GKR_IS_LOCATION_WATCH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GKR_TYPE_LOCATION_WATCH))
-#define GKR_IS_LOCATION_WATCH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GKR_TYPE_LOCATION_WATCH))
-#define GKR_LOCATION_WATCH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GKR_TYPE_LOCATION_WATCH, GkrLocationWatchClass))
-
-typedef struct _GkrLocationWatch GkrLocationWatch;
-typedef struct _GkrLocationWatchClass GkrLocationWatchClass;
-
-struct _GkrLocationWatch {
- GObject parent;
- GkrLocationManager *manager;
-};
-
-struct _GkrLocationWatchClass {
- GObjectClass parent_class;
-
- void (*location_added) (GkrLocationManager *locmgr, GQuark location);
- void (*location_changed) (GkrLocationManager *locmgr, GQuark location);
- void (*location_removed) (GkrLocationManager *locmgr, GQuark location);
-};
-
-GType gkr_location_watch_get_type (void) G_GNUC_CONST;
-
-GkrLocationWatch* gkr_location_watch_new (GkrLocationManager *locmgr,
- GQuark only_volume,
- const gchar *subdir,
- const gchar *include_pattern,
- const gchar *exclude_pattern);
-
-void gkr_location_watch_refresh (GkrLocationWatch *watch,
- gboolean force_all);
-
-G_END_DECLS
-
-#endif /* __GKR_LOCATION_WATCH_H__ */
-
diff --git a/daemon/util/tests/Makefile.am b/daemon/util/tests/Makefile.am
index 250fbb17..ec80c74c 100644
--- a/daemon/util/tests/Makefile.am
+++ b/daemon/util/tests/Makefile.am
@@ -1,7 +1,6 @@
UNIT_AUTO = \
unit-test-async.c \
- unit-test-location.c \
- unit-test-location-watch.c
+ unit-test-location.c
UNIT_PROMPT =
diff --git a/daemon/util/tests/unit-test-location-watch.c b/daemon/util/tests/unit-test-location-watch.c
deleted file mode 100644
index adb130c5..00000000
--- a/daemon/util/tests/unit-test-location-watch.c
+++ /dev/null
@@ -1,245 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* unit-test-location.c: Test location 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-auto-test.h"
-
-#include "util/gkr-location-watch.h"
-
-#include <glib/gstdio.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 DATA "test-data"
-#define SUBDIR "test-subdir"
-#define WILDCARD "*.woo?"
-
-static GkrLocationWatch *the_watch = NULL;
-static gchar *test_dir = NULL;
-static gchar *test_file = NULL;
-
-static guint n_locations_added = 0;
-static GQuark last_location_added = 0;
-
-static guint n_locations_changed = 0;
-static GQuark last_location_changed = 0;
-
-static guint n_locations_removed = 0;
-static GQuark last_location_removed = 0;
-
-static void
-location_added (GkrLocationWatch *watch, GQuark loc, gpointer unused)
-{
- /* "should be a non-null quark" */
- g_assert_cmpint (loc, !=, 0);
- /* "should be a valid quark" */
- g_assert (g_quark_to_string (loc) != NULL);
-
- ++n_locations_added;
- last_location_added = loc;
-}
-
-static void
-location_changed (GkrLocationWatch *watch, GQuark loc, gpointer unused)
-{
- /* "should be a non-null quark" */
- g_assert_cmpint (loc, !=, 0);
- /* "should be a valid quark" */
- g_assert (g_quark_to_string (loc) != NULL);
-
- ++n_locations_changed;
- last_location_changed = loc;
-}
-
-static void
-location_removed (GkrLocationWatch *watch, GQuark loc, gpointer unused)
-{
- /* "should be a non-null quark" */
- g_assert_cmpint (loc, !=, 0);
- /* "should be a valid quark" */
- g_assert (g_quark_to_string (loc) != NULL);
-
- ++n_locations_removed;
- last_location_removed = loc;
-}
-
-DEFINE_TEST(location_watch)
-{
- GQuark loc;
-
- /* Mtime must change so wait between tests */
- sleep (1);
-
- the_watch = gkr_location_watch_new (NULL, 0, SUBDIR, WILDCARD, NULL);
- g_signal_connect (the_watch, "location-added", G_CALLBACK (location_added), NULL);
- g_signal_connect (the_watch, "location-removed", G_CALLBACK (location_removed), NULL);
- g_signal_connect (the_watch, "location-changed", G_CALLBACK (location_changed), NULL);
-
- /* Make a test directory */
- loc = gkr_location_from_child (GKR_LOCATION_VOLUME_LOCAL, SUBDIR);
- test_dir = gkr_location_to_path (loc);
-
- test_file = g_build_filename (test_dir, "my-file.woof", NULL);
- g_unlink (test_file);
-
- /* A watch for an empty directory, should have no responses */
- gkr_location_watch_refresh (the_watch, FALSE);
-
- g_assert_cmpint (0, ==, n_locations_added);
- g_assert_cmpint (0, ==, n_locations_changed);
- g_assert_cmpint (0, ==, n_locations_removed);
-
- g_mkdir_with_parents (test_dir, 0700);
-
- /* Should still have no responses even though it exists */
- gkr_location_watch_refresh (the_watch, FALSE);
-
- g_assert_cmpint (0, ==, n_locations_added);
- g_assert_cmpint (0, ==, n_locations_changed);
- g_assert_cmpint (0, ==, n_locations_removed);
-}
-
-DEFINE_TEST(location_file)
-{
- gboolean ret;
- GQuark loc;
-
- /* Mtime must change so wait between tests */
- sleep (1);
-
- /* Make sure things are clean */
- g_unlink (test_file);
- gkr_location_watch_refresh (the_watch, FALSE);
-
- n_locations_added = n_locations_changed = n_locations_removed = 0;
- last_location_added = last_location_changed = last_location_removed = 0;
-
- ret = g_file_set_contents (test_file, DATA, strlen (DATA), NULL);
- g_assert (ret == TRUE);
-
- /* Now make sure that file is located */
- gkr_location_watch_refresh (the_watch, FALSE);
-
- g_assert_cmpint (1, ==, n_locations_added);
- g_assert_cmpint (0, ==, n_locations_changed);
- g_assert_cmpint (0, ==, n_locations_removed);
-
- /* The added one should match our file */
- loc = gkr_location_from_path (test_file);
- /* "returned zero location" */
- g_assert_cmpint (loc, !=, 0);
- /* "wrong location was signalled" */
- g_assert (loc == last_location_added);
-
-
-
- n_locations_added = n_locations_changed = n_locations_removed = 0;
- last_location_added = last_location_changed = last_location_removed = 0;
-
- sleep (1);
-
- /* Shouldn't find the file again */
- gkr_location_watch_refresh (the_watch, FALSE);
- g_assert_cmpint (0, ==, n_locations_added);
- g_assert_cmpint (0, ==, n_locations_changed);
- g_assert_cmpint (0, ==, n_locations_removed);
-
- /* But we should find the file if forced to */
- gkr_location_watch_refresh (the_watch, TRUE);
- g_assert_cmpint (0, ==, n_locations_added);
- g_assert_cmpint (1, ==, n_locations_changed);
- g_assert_cmpint (0, ==, n_locations_removed);
- /* "wrong location was signalled" */
- g_assert (loc == last_location_changed);
-
-
-
- n_locations_added = n_locations_changed = n_locations_removed = 0;
- last_location_added = last_location_changed = last_location_removed = 0;
-
- ret = g_file_set_contents (test_file, DATA, strlen (DATA), NULL);
- g_assert (ret == TRUE);
-
- /* File was updated */
- gkr_location_watch_refresh (the_watch, FALSE);
- g_assert_cmpint (0, ==, n_locations_added);
- g_assert_cmpint (1, ==, n_locations_changed);
- g_assert_cmpint (0, ==, n_locations_removed);
- /* "wrong location was signalled" */
- g_assert (loc == last_location_changed);
-
-
-
- n_locations_added = n_locations_changed = n_locations_removed = 0;
- last_location_added = last_location_changed = last_location_removed = 0;
-
- g_unlink (test_file);
-
- /* Now file should be removed */
- gkr_location_watch_refresh (the_watch, FALSE);
-
- g_assert_cmpint (0, ==, n_locations_added);
- g_assert_cmpint (0, ==, n_locations_changed);
- g_assert_cmpint (1, ==, n_locations_removed);
- /* "wrong location was signalled" */
- g_assert (loc == last_location_removed);
-}
-
-DEFINE_TEST(location_nomatch)
-{
- gchar *file = g_build_filename (test_dir, "my-file.toot", NULL);
- gboolean ret;
-
- /* Mtime must change so wait between tests */
- sleep (1);
-
- ret = g_file_set_contents (file, DATA, strlen (DATA), NULL);
- g_assert (ret == TRUE);
-
- n_locations_added = n_locations_changed = n_locations_removed = 0;
- last_location_added = last_location_changed = last_location_removed = 0;
-
- /* Now make sure that file is not located */
- gkr_location_watch_refresh (the_watch, FALSE);
-
- g_assert_cmpint (0, ==, n_locations_added);
- g_assert_cmpint (0, ==, n_locations_changed);
- g_assert_cmpint (0, ==, n_locations_removed);
-
- g_unlink (file);
-}
diff --git a/docs/reference/Makefile.am b/docs/reference/Makefile.am
index bcf78307..ad8f278f 100644
--- a/docs/reference/Makefile.am
+++ b/docs/reference/Makefile.am
@@ -1,2 +1,2 @@
-SUBDIRS = gcr gnome-keyring gp11
+SUBDIRS = gcr gp11
diff --git a/docs/reference/gnome-keyring/.gitignore b/docs/reference/gnome-keyring/.gitignore
deleted file mode 100644
index d4bd33bf..00000000
--- a/docs/reference/gnome-keyring/.gitignore
+++ /dev/null
@@ -1,10 +0,0 @@
-# Commit these files if you edit them
-*-decl-list.txt
-*-decl.txt
-*-overrides.txt
-*.args
-*.hierarchy
-*.interfaces
-*.prerequisites
-*.signals
-
diff --git a/docs/reference/gnome-keyring/Makefile.am b/docs/reference/gnome-keyring/Makefile.am
deleted file mode 100644
index 2b171527..00000000
--- a/docs/reference/gnome-keyring/Makefile.am
+++ /dev/null
@@ -1,99 +0,0 @@
-## Process this file with automake to produce Makefile.in
-
-# We require automake 1.6 at least.
-AUTOMAKE_OPTIONS = 1.6
-
-# This is a blank Makefile.am for using gtk-doc.
-# Copy this to your project's API docs directory and modify the variables to
-# suit your project. See the GTK+ Makefiles in gtk+/docs/reference for examples
-# of using the various options.
-
-# The name of the module, e.g. 'glib'.
-DOC_MODULE=gnome-keyring
-
-# Uncomment for versioned docs and specify the version of the module, e.g. '2'.
-#DOC_MODULE_VERSION=2
-
-
-# The top-level SGML file. You can change this if you want to.
-DOC_MAIN_SGML_FILE=$(DOC_MODULE)-docs.sgml
-
-# The directory containing the source code. Relative to $(srcdir).
-# gtk-doc will search all .c & .h files beneath here for inline comments
-# documenting the functions and macros.
-# e.g. DOC_SOURCE_DIR=../../../gtk
-DOC_SOURCE_DIR=../../../library
-
-# Extra options to pass to gtkdoc-scangobj. Not normally needed.
-SCANGOBJ_OPTIONS=
-
-# Extra options to supply to gtkdoc-scan.
-# e.g. SCAN_OPTIONS=--deprecated-guards="GTK_DISABLE_DEPRECATED"
-SCAN_OPTIONS=
-
-# Extra options to supply to gtkdoc-mkdb.
-# e.g. MKDB_OPTIONS=--sgml-mode --output-format=xml
-MKDB_OPTIONS=--sgml-mode --output-format=xml
-
-# Extra options to supply to gtkdoc-mktmpl
-# e.g. MKTMPL_OPTIONS=--only-section-tmpl
-MKTMPL_OPTIONS=
-
-# Extra options to supply to gtkdoc-mkhtml
-MKHTML_OPTIONS=
-
-# Extra options to supply to gtkdoc-fixref. Not normally needed.
-# e.g. FIXXREF_OPTIONS=--extra-dir=../gdk-pixbuf/html --extra-dir=../gdk/html
-FIXXREF_OPTIONS=
-
-# Used for dependencies. The docs will be rebuilt if any of these change.
-# e.g. HFILE_GLOB=$(top_srcdir)/gtk/*.h
-# e.g. CFILE_GLOB=$(top_srcdir)/gtk/*.c
-HFILE_GLOB=$(top_srcdir)/library/*.h
-CFILE_GLOB=$(top_srcdir)/library/*.c
-
-# Extra header to include when scanning, which are not under DOC_SOURCE_DIR
-# e.g. EXTRA_HFILES=$(top_srcdir}/contrib/extra.h
-EXTRA_HFILES=
-
-# Header files to ignore when scanning. Use base file name, no paths
-# e.g. IGNORE_HFILES=gtkdebug.h gtkintl.h
-IGNORE_HFILES=
-
-# Images to copy into HTML directory.
-# e.g. HTML_IMAGES=$(top_srcdir)/gtk/stock-icons/stock_about_24.png
-HTML_IMAGES=
-
-# Extra SGML files that are included by $(DOC_MAIN_SGML_FILE).
-# e.g. content_files=running.sgml building.sgml changes-2.0.sgml
-content_files=
-
-# SGML files where gtk-doc abbrevations (#GtkWidget) are expanded
-# These files must be listed here *and* in content_files
-# e.g. expand_content_files=running.sgml
-expand_content_files=
-
-# CFLAGS and LDFLAGS for compiling gtkdoc-scangobj with your library.
-# Only needed if you are using gtkdoc-scangobj to dynamically query widget
-# signals and properties.
-# e.g. GTKDOC_CFLAGS=-I$(top_srcdir) -I$(top_builddir) $(GTK_DEBUG_FLAGS)
-# e.g. GTKDOC_LIBS=$(top_builddir)/gtk/$(gtktargetlib)
-GTKDOC_CFLAGS= -I$(top_srcdir) -I$(top_builddir) $(GOBJECT_CFLAGS) -Wno-error
-GTKDOC_LIBS= $(GOBJECT_LIBS) $(top_builddir)/library/libgnome-keyring.la
-
-# This includes the standard gtk-doc make rules, copied by gtkdocize.
-include $(top_srcdir)/gtk-doc.make
-
-# Other files to distribute
-# e.g. EXTRA_DIST += version.xml.in
-EXTRA_DIST +=
-
-# Files not to distribute
-# for --rebuild-types in $(SCAN_OPTIONS), e.g. $(DOC_MODULE).types
-# for --rebuild-sections in $(SCAN_OPTIONS) e.g. $(DOC_MODULE)-sections.txt
-#DISTCLEANFILES +=
-
-# Comment this out if you want your docs-status tested during 'make check'
-#TESTS_ENVIRONMENT = cd $(srcsrc)
-#TESTS = $(GTKDOC_CHECK)
-
diff --git a/docs/reference/gnome-keyring/gnome-keyring-docs.sgml b/docs/reference/gnome-keyring/gnome-keyring-docs.sgml
deleted file mode 100644
index 309308a7..00000000
--- a/docs/reference/gnome-keyring/gnome-keyring-docs.sgml
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0"?>
-<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
- "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
-<book id="index" xmlns:xi="http://www.w3.org/2003/XInclude">
- <bookinfo>
- <title>gnome-keyring Reference Manual</title>
- </bookinfo>
-
- <chapter>
- <title>gnome-keyring API Reference</title>
- <xi:include href="xml/gnome-keyring-password.xml"/>
- <xi:include href="xml/gnome-keyring-keyrings.xml"/>
- <xi:include href="xml/gnome-keyring-keyring-info.xml"/>
- <xi:include href="xml/gnome-keyring-items.xml"/>
- <xi:include href="xml/gnome-keyring-item-info.xml"/>
- <xi:include href="xml/gnome-keyring-attributes.xml"/>
- <xi:include href="xml/gnome-keyring-acl.xml"/>
- <xi:include href="xml/gnome-keyring-find.xml"/>
- <xi:include href="xml/gnome-keyring-network.xml"/>
- <xi:include href="xml/gnome-keyring-memory.xml"/>
- <xi:include href="xml/gnome-keyring-result.xml"/>
- <xi:include href="xml/gnome-keyring-misc.xml"/>
- <xi:include href="xml/gnome-keyring-daemon.xml"/>
- <xi:include href="xml/gnome-keyring-generic-callbacks.xml"/>
- </chapter>
-</book>
diff --git a/docs/reference/gnome-keyring/gnome-keyring-sections.txt b/docs/reference/gnome-keyring/gnome-keyring-sections.txt
deleted file mode 100644
index e8e4977e..00000000
--- a/docs/reference/gnome-keyring/gnome-keyring-sections.txt
+++ /dev/null
@@ -1,183 +0,0 @@
-<SECTION>
-<FILE>gnome-keyring-password</FILE>
-GnomeKeyringPasswordSchema
-GNOME_KEYRING_NETWORK_PASSWORD
-GNOME_KEYRING_DEFAULT
-GNOME_KEYRING_SESSION
-gnome_keyring_store_password
-gnome_keyring_store_password_sync
-gnome_keyring_find_password
-gnome_keyring_find_password_sync
-gnome_keyring_delete_password
-gnome_keyring_delete_password_sync
-gnome_keyring_free_password
-</SECTION>
-<SECTION>
-<FILE>gnome-keyring-keyrings</FILE>
-GnomeKeyringOperationGetKeyringInfoCallback
-gnome_keyring_set_default_keyring
-gnome_keyring_set_default_keyring_sync
-gnome_keyring_get_default_keyring
-gnome_keyring_get_default_keyring_sync
-gnome_keyring_list_keyring_names
-gnome_keyring_list_keyring_names_sync
-gnome_keyring_lock_all
-gnome_keyring_lock_all_sync
-gnome_keyring_create
-gnome_keyring_create_sync
-gnome_keyring_unlock
-gnome_keyring_unlock_sync
-gnome_keyring_lock
-gnome_keyring_lock_sync
-gnome_keyring_delete
-gnome_keyring_delete_sync
-gnome_keyring_get_info
-gnome_keyring_get_info_sync
-gnome_keyring_set_info
-gnome_keyring_set_info_sync
-gnome_keyring_change_password
-gnome_keyring_change_password_sync
-gnome_keyring_list_item_ids
-gnome_keyring_list_item_ids_sync
-</SECTION>
-<SECTION>
-<FILE>gnome-keyring-keyring-info</FILE>
-GnomeKeyringInfo
-gnome_keyring_info_free
-gnome_keyring_info_copy
-gnome_keyring_info_set_lock_on_idle
-gnome_keyring_info_get_lock_on_idle
-gnome_keyring_info_set_lock_timeout
-gnome_keyring_info_get_lock_timeout
-gnome_keyring_info_get_mtime
-gnome_keyring_info_get_ctime
-gnome_keyring_info_get_is_locked
-</SECTION>
-<SECTION>
-<FILE>gnome-keyring-items</FILE>
-GnomeKeyringItemInfoFlags
-GnomeKeyringOperationGetItemInfoCallback
-GnomeKeyringOperationGetAttributesCallback
-gnome_keyring_item_create
-gnome_keyring_item_create_sync
-gnome_keyring_item_delete
-gnome_keyring_item_delete_sync
-gnome_keyring_item_get_info
-gnome_keyring_item_get_info_full
-gnome_keyring_item_get_info_full_sync
-gnome_keyring_item_get_info_sync
-gnome_keyring_item_set_info
-gnome_keyring_item_set_info_sync
-gnome_keyring_item_get_attributes
-gnome_keyring_item_get_attributes_sync
-gnome_keyring_item_set_attributes
-gnome_keyring_item_set_attributes_sync
-gnome_keyring_item_get_acl
-gnome_keyring_item_get_acl_sync
-gnome_keyring_item_set_acl
-gnome_keyring_item_set_acl_sync
-gnome_keyring_item_grant_access_rights
-gnome_keyring_item_grant_access_rights_sync
-</SECTION>
-<SECTION>
-<FILE>gnome-keyring-item-info</FILE>
-GnomeKeyringItemType
-GnomeKeyringItemInfo
-gnome_keyring_item_info_free
-gnome_keyring_item_info_new
-gnome_keyring_item_info_copy
-gnome_keyring_item_info_get_type
-gnome_keyring_item_info_set_type
-gnome_keyring_item_info_get_secret
-gnome_keyring_item_info_set_secret
-gnome_keyring_item_info_get_display_name
-gnome_keyring_item_info_set_display_name
-gnome_keyring_item_info_get_mtime
-gnome_keyring_item_info_get_ctime
-</SECTION>
-<SECTION>
-<FILE>gnome-keyring-find</FILE>
-GnomeKeyringFound
-gnome_keyring_found_free
-gnome_keyring_found_list_free
-gnome_keyring_find_items
-gnome_keyring_find_itemsv
-gnome_keyring_find_items_sync
-gnome_keyring_find_itemsv_sync
-</SECTION>
-<SECTION>
-<FILE>gnome-keyring-attributes</FILE>
-GnomeKeyringAttributeType
-GnomeKeyringAttributeList
-GnomeKeyringAttribute
-gnome_keyring_attribute_list_index
-gnome_keyring_attribute_list_new
-gnome_keyring_attribute_list_append_string
-gnome_keyring_attribute_list_append_uint32
-gnome_keyring_attribute_list_free
-gnome_keyring_attribute_list_copy
-</SECTION>
-<SECTION>
-<FILE>gnome-keyring-acl</FILE>
-GnomeKeyringAccessControl
-GnomeKeyringApplicationRef
-GnomeKeyringAccessType
-gnome_keyring_application_ref_new
-gnome_keyring_application_ref_copy
-gnome_keyring_application_ref_free
-gnome_keyring_access_control_new
-gnome_keyring_access_control_copy
-gnome_keyring_access_control_free
-gnome_keyring_acl_copy
-gnome_keyring_acl_free
-gnome_keyring_item_ac_get_display_name
-gnome_keyring_item_ac_set_display_name
-gnome_keyring_item_ac_get_path_name
-gnome_keyring_item_ac_set_path_name
-gnome_keyring_item_ac_get_access_type
-gnome_keyring_item_ac_set_access_type
-</SECTION>
-<SECTION>
-<FILE>gnome-keyring-network</FILE>
-GnomeKeyringNetworkPasswordData
-gnome_keyring_network_password_free
-gnome_keyring_network_password_list_free
-gnome_keyring_find_network_password
-gnome_keyring_find_network_password_sync
-gnome_keyring_set_network_password
-gnome_keyring_set_network_password_sync
-</SECTION>
-<SECTION>
-<FILE>gnome-keyring-misc</FILE>
-gnome_keyring_is_available
-gnome_keyring_cancel_request
-gnome_keyring_string_list_free
-</SECTION>
-<SECTION>
-<FILE>gnome-keyring-daemon</FILE>
-gnome_keyring_daemon_set_display_sync
-gnome_keyring_daemon_prepare_environment_sync
-</SECTION>
-<SECTION>
-<FILE>gnome-keyring-memory</FILE>
-gnome_keyring_memory_new
-gnome_keyring_memory_alloc
-gnome_keyring_memory_try_alloc
-gnome_keyring_memory_realloc
-gnome_keyring_memory_try_realloc
-gnome_keyring_memory_free
-gnome_keyring_memory_is_secure
-gnome_keyring_memory_strdup
-</SECTION>
-<SECTION>
-<FILE>gnome-keyring-result</FILE>
-gnome_keyring_result_to_message
-GnomeKeyringResult
-</SECTION>
-<SECTION>
-<FILE>gnome-keyring-generic-callbacks</FILE>
-GnomeKeyringOperationDoneCallback
-GnomeKeyringOperationGetIntCallback
-GnomeKeyringOperationGetListCallback
-GnomeKeyringOperationGetStringCallback
-</SECTION>
diff --git a/docs/reference/gnome-keyring/gnome-keyring.types b/docs/reference/gnome-keyring/gnome-keyring.types
deleted file mode 100644
index e69de29b..00000000
--- a/docs/reference/gnome-keyring/gnome-keyring.types
+++ /dev/null
diff --git a/keyring-intro.txt b/keyring-intro.txt
deleted file mode 100644
index 5c1859e5..00000000
--- a/keyring-intro.txt
+++ /dev/null
@@ -1,154 +0,0 @@
-GNOME Keyring is a system to store passwords and other sensitive data in a
-standardized way across all GNOME applications.
-
-A keyring stores a collection of encrypted passwords and encrypted information
-about those passwords. A user can have multiple keyrings, each for a different
-use, but there is a default one, called 'login'. There is also a special "session"
-keyring which is not stored on disk and goes away when you log out.
-
-When a user logs into GNOME, the keyrings are locked and a master keyring
-password has to be provided in order to unlock each of them. A keyring can be
-configured to be locked automatically after a period of inactivity (This isn't
-actually implemented yet but is coming soon)
-
-The data inside a keyring is stored in "items". An item can be of these types:
-
- GNOME_KEYRING_ITEM_GENERIC_SECRET
- GNOME_KEYRING_ITEM_NETWORK_PASSWORD
- GNOME_KEYRING_ITEM_NOTE
-
-Notice that we might extend the set of types as necessary.
-
-Each item has a name, such as "university proxy password" or "example.org SSH
-private key password", a secret, and an unlimited list of attributes. Each
-attribute consists of a name-value pair that is intended to serve as a hint for
-the applications (e.g., "user=fer", or "server=example.org"). This enables
-applications to find the relevant item in the keyring. All strings are UTF-8.
-Attributes can be integers or strings.
-
-
-Storing a password in a keyring
--------------------------------
-
-The example code below demonstrates how to add the new password (and associated
-data) into the selected keyring:
-
-
- GnomeKeyringAttributeList *attributes;
- GnomeKeyringAttribute attribute;
-
- attributes = gnome_keyring_attribute_list_new ();
-
- attribute.name = g_strdup ("user");
- attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
- attribute.value.string = g_strdup ("gnomer");
- g_array_append_val (attributes, attribute);
-
- attribute.name = g_strdup ("server");
- attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
- attribute.value.string = g_strdup ("master.gnome.org");
- g_array_append_val (attributes, attribute);
-
- attribute.name = g_strdup ("protocol");
- attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
- attribute.value.string = g_strdup ("ssh");
- g_array_append_val (attributes, attribute);
-
- gnome_keyring_item_create (NULL, /* Use default keyring */
- GNOME_KEYRING_ITEM_NETWORK_PASSWORD, /* type */
- "master.gnome.org SSH password", /* name */
- attributes, /* attribute list */
- "mypassword", /* password */
- TRUE, /* Update if already exists */
- create_item_cb, NULL, NULL);
- gnome_keyring_attribute_list_free (attributes);
-
-
-In most cases, applications must use standard attributes. There is a convenience
-function in gnome-keyring to aid in setting these attributes:
-
- gnome_keyring_set_network_password (NULL /* default keyring */,
- "gnomer" /* user */
- NULL, /* domain */
- "master.gnome.org", /* server */
- NULL, /* object */
- "ssh", /* protocol */
- NULL, /* authtype */
- 0, /* port, default */
- "mypassword", /* password */
- set_network_cb, NULL, NULL);
-
-
-Retrieving a password in a keyring
-----------------------------------
-
-Typically, applications will search for a password that matches certain
-criteria. This is done by providing a list of specific attributes to the
-
- gnome_keyring_find_items
-
-function. In the common case that an application is searching for a network
-password, however, there is a convenience function that can be used instead:
-
-
- gnome_keyring_find_network_password_sync ("gnomer", /* user */
- NULL, /* domain */
- "master.gnome.org", /* server */
- NULL, /* object */
- "ssh", /* protocol */
- NULL, /* authtype */
- 0, /* port */
- &list);
-
-
-In this example, list is a GList containing GnomeKeyringNetworkPasswordData
-entries.
-
-The search is performed by the GNOME Keyring daemon, which looks through the
-passwords on every keyring. The daemon gathers a list of all of the items
-(passwords) that match the specified criteria. The returned list can contain
-several matches, for instance {server=foo, user=bar} and {server=foo}. The
-daemon always orders these such that the ones that match the least of the
-query are returned first.
-
-This is so that you can for instance have two passwords on the same
-machine, but say on different ports, and one is the default port (not
-set). Then just querying for the server will give you the one without
-the additional port.
-
-For each item, it then asks the user whether to allow the application that
-requested the item to receive it. Only the items allowed by the user are
-given to the application.
-
-Note that multiple ways of approving key usage are provided to the user, such
-as "Deny", "Allow this time", "Allow always".
-
-Using multiple keyrings
------------------------
-
-Applications should provide the user an opportunity to select the keyring in
-which to store the password. The default keyring can be obtained by calling
-
- gnome_keyring_get_default_keyring
-
-while a list of all available keyrings can be obtained by calling the
-
- gnome_keyring_list_keyring_names
-
-function. Passing NULL for keyring parameter in any gnome-keyring function
-will use the default one.
-
-Some notes about gnome-keyring API
-----------------------------------
-
-Most GNOME Keyring functions are asynchronous. Because of this, callback
-functions should be provided that will be executed when the required operation
-has finished. For those that prefer synchronous operation, there are
-synchronous variants of common gnome-keyring functions:
-
- gnome_keyring_find_items_sync
- gnome_keyring_find_itemsv_sync
- gnome_keyring_item_create_sync
- gnome_keyring_find_network_password_sync
- gnome_keyring_set_network_password_sync
-
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);
-}
diff --git a/pam/gkr-pam-client.c b/pam/gkr-pam-client.c
index 88a2382d..0d441aec 100644
--- a/pam/gkr-pam-client.c
+++ b/pam/gkr-pam-client.c
@@ -28,6 +28,8 @@
#include "egg/egg-buffer.h"
#include "egg/egg-unix-credentials.h"
+#include "daemon/control/gkd-control-codes.h"
+
#include <sys/types.h>
#include <sys/param.h>
#include <sys/socket.h>
@@ -214,7 +216,7 @@ connect_to_daemon (const char *control)
}
static void
-write_part (int fd, const unsigned char *data, int len, GnomeKeyringResult *res)
+write_part (int fd, const unsigned char *data, int len, int *res)
{
assert (res);
@@ -267,11 +269,10 @@ read_part (int fd, unsigned char *data, int len)
return all;
}
-static GnomeKeyringResult
-keyring_daemon_op (const char *control, GnomeKeyringOpCode op, int argc,
- const char* argv[])
+static int
+keyring_daemon_op (const char *control, int op, int argc, const char* argv[])
{
- GnomeKeyringResult ret = GNOME_KEYRING_RESULT_OK;
+ int ret = GNOME_KEYRING_RESULT_OK;
unsigned char buf[4];
int i, sock = -1;
uint oplen, l;
@@ -346,12 +347,12 @@ done:
return ret;
}
-GnomeKeyringResult
+int
gkr_pam_client_run_operation (struct passwd *pwd, const char *control,
- GnomeKeyringOpCode op, int argc, const char* argv[])
+ int op, int argc, const char* argv[])
{
struct sigaction ignpipe, oldpipe, defchld, oldchld;
- GnomeKeyringResult res;
+ int res;
pid_t pid;
int status;
diff --git a/pam/gkr-pam-module.c b/pam/gkr-pam-module.c
index 98e4ea7b..4e561fd9 100644
--- a/pam/gkr-pam-module.c
+++ b/pam/gkr-pam-module.c
@@ -31,8 +31,7 @@
#include "gkr-pam.h"
-#include "library/gnome-keyring-result.h"
-#include "library/gnome-keyring-opcodes.h"
+#include "daemon/control/gkd-control-codes.h"
#include <security/pam_appl.h>
#include <security/pam_modules.h>
@@ -648,7 +647,7 @@ static int
create_keyring (pam_handle_t *ph, struct passwd *pwd, const char *password)
{
const char *control;
- GnomeKeyringResult res;
+ int res;
const char *argv[2];
assert (pwd);
@@ -679,7 +678,7 @@ static int
unlock_keyring (pam_handle_t *ph, struct passwd *pwd, const char *password)
{
const char *control;
- GnomeKeyringResult res;
+ int res;
const char *argv[2];
assert (pwd);
@@ -716,9 +715,9 @@ change_keyring_password (pam_handle_t *ph, struct passwd *pwd,
const char *password, const char *original)
{
const char *control;
- GnomeKeyringResult res;
const char *argv[3];
-
+ int res;
+
assert (pwd);
assert (password);
assert (original);
diff --git a/pam/gkr-pam.h b/pam/gkr-pam.h
index 0a988fe6..9d4a9b71 100644
--- a/pam/gkr-pam.h
+++ b/pam/gkr-pam.h
@@ -26,9 +26,6 @@
#include <pwd.h>
-#include "library/gnome-keyring-opcodes.h"
-#include "library/gnome-keyring-result.h"
-
#ifndef LOG_AUTHPRIV
#define LOG_AUTHPRIV LOG_AUTH
#endif
@@ -38,7 +35,7 @@
#define GKR_LOG_NOTICE (LOG_NOTICE | LOG_AUTHPRIV)
#define GKR_LOG_INFO (LOG_INFO | LOG_AUTHPRIV)
-GnomeKeyringResult gkr_pam_client_run_operation (struct passwd *pwd, const char *socket,
- GnomeKeyringOpCode op, int argc, const char* argv[]);
+int gkr_pam_client_run_operation (struct passwd *pwd, const char *socket,
+ int op, int argc, const char* argv[]);
#endif /*GKRPAM_H_*/
diff --git a/daemon/keyrings/file-format.txt b/pkcs11/secret-store/file-format.txt
index e3c36a2b..4d7b491b 100644
--- a/daemon/keyrings/file-format.txt
+++ b/pkcs11/secret-store/file-format.txt
@@ -41,13 +41,13 @@ num_items *
guin32 num_encrypted bytes
encrypted data:
bytes[16] encryted hash, (for decrypt ok verify)
-
+
num_items *
string display_name
string secret
time_t ctime
time_t mtime
-
+
string reserved_str
guint[4] reserved_int2
@@ -65,5 +65,4 @@ guin32 num_encrypted bytes
string reserved_str
guint32 reserved_uint
- zero padding to make even multiple of 16
-
+ zero padding to make even multiple of 16
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 3b5a7353..0fe92eb3 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,11 +1,8 @@
# List of source files containing translatable strings.
# Please keep this file sorted alphabetically.
-daemon/gkr-daemon-ops.c
daemon/data/gnome-keyring.schemas.in
daemon/gnome-keyring-daemon.desktop.in.in
daemon/org.gnome.keyring.service.in
-daemon/keyrings/gkr-keyring-login.c
-daemon/keyrings/gkr-keyring.c
daemon/pkcs11/gkr-pkcs11-auth.c
daemon/ui/gkr-ask-tool.c
daemon/util/gkr-location.c
@@ -18,6 +15,5 @@ gcr/gcr-certificate-details-widget.c
gcr/gcr-importer.c
gcr/gcr-parser.c
gp11/gp11-misc.c
-library/gnome-keyring-utils.c
pkcs11/gck/gck-certificate.c
pkcs11/ssh-store/gck-ssh-private-key.c
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index acda45c2..fcfbed80 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -1,9 +1,3 @@
daemon/gnome-keyring-daemon.desktop.in
-daemon/pk/gkr-pk-import.c
-daemon/pk/gkr-pk-index.c
-daemon/pk/gkr-pk-object.c
-daemon/pk/gkr-pk-storage.c
-daemon/pkix/gkr-pkix-parser.c
-daemon/pkix/gkr-pkix-serialize.c
gcr/gcr-import-dialog.ui
gcr/gcr-certificate-basics-widget.ui
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6cb78085..bfd49678 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -15,32 +15,5 @@ LIBS = \
$(GTK_LIBS) \
$(GLIB_LIBS) \
$(GTHREAD_LIBS)
-
-noinst_PROGRAMS= \
- list-keyrings \
- test-keyring \
- test-keyring-two
-
-# ------------------------------------------------------------------------------
-# Simply list all the keyrings and whatever they have access to
-
-list_keyrings_SOURCES = \
- list-keyrings.c
-
-list_keyrings_LDADD = \
- $(top_builddir)/library/libgnome-keyring.la
-
-# ------------------------------------------------------------------------------
-# A generic testing program
-
-test_keyring_SOURCES = \
- test-keyrings.c
-
-test_keyring_LDADD = \
- $(top_builddir)/library/libgnome-keyring.la
-
-test_keyring_two_SOURCES = \
- test-keyrings.c
-test_keyring_two_LDADD = \
- $(top_builddir)/library/libgnome-keyring.la
+noinst_PROGRAMS =
diff --git a/tests/list-keyrings.c b/tests/list-keyrings.c
deleted file mode 100644
index adbdb5bf..00000000
--- a/tests/list-keyrings.c
+++ /dev/null
@@ -1,225 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* list-keyrings.c - test app to list keyrings
-
- Copyright (C) 2003 Red Hat, Inc
-
- The Gnome 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 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 "library/gnome-keyring.h"
-
-static GMainLoop *loop = NULL;
-
-
-static void
-string_callback (GnomeKeyringResult result,
- const char *str,
- gpointer data)
-{
- char **out;
-
- out = data;
-
- if (result != GNOME_KEYRING_RESULT_OK) {
- g_print ("string op failed: %d\n", result);
- *out = NULL;
- } else {
- *out = g_strdup (str);
- }
- g_main_loop_quit (loop);
-}
-
-
-static void
-print_keyring_info (GnomeKeyringResult result,
- GnomeKeyringInfo *info,
- gpointer data)
-{
- gboolean *locked;
- locked = data;
-
- *locked = TRUE;
- if (result != GNOME_KEYRING_RESULT_OK) {
- g_print ("error getting keyring info: %d\n", result);
- } else {
- g_print ("lock_on_idle: %d\n", gnome_keyring_info_get_lock_on_idle (info));
- g_print ("lock timeout: %d\n", gnome_keyring_info_get_lock_timeout (info));
- g_print ("mtime: %lu\n", (unsigned long)gnome_keyring_info_get_mtime (info));
- g_print ("ctime: %lu\n", (unsigned long)gnome_keyring_info_get_ctime (info));
- g_print ("locked: %d\n", gnome_keyring_info_get_is_locked (info));
- *locked = gnome_keyring_info_get_is_locked (info);
- }
-
- g_main_loop_quit (loop);
-}
-
-static void
-print_item_info (GnomeKeyringResult result,
- GnomeKeyringItemInfo *info,
- gpointer data)
-{
- char *secret;
- char *name;
- if (result != GNOME_KEYRING_RESULT_OK) {
- g_print ("error getting item info: %d\n", result);
- } else {
- name = gnome_keyring_item_info_get_display_name (info);
- secret = gnome_keyring_item_info_get_secret (info);
- g_print (" type: %u\n", gnome_keyring_item_info_get_type (info));
- g_print (" name: %s\n", name);
- g_print (" secret: %s\n", secret);
- g_print (" mtime: %lu\n", (unsigned long)gnome_keyring_item_info_get_mtime (info));
- g_print (" ctime: %lu\n", (unsigned long)gnome_keyring_item_info_get_ctime (info));
- gnome_keyring_free_password (secret);
- g_free (name);
- }
-
- g_main_loop_quit (loop);
-}
-
-static void
-print_attributes (GnomeKeyringResult result,
- GnomeKeyringAttributeList *attributes,
- gpointer data)
-{
- GnomeKeyringAttribute *array;
- int i;
-
- if (result != GNOME_KEYRING_RESULT_OK) {
- g_print ("error getting item attributes: %d\n", result);
- } else {
- array = (GnomeKeyringAttribute *)attributes->data;
- g_print (" Attributes:\n");
- for (i = 0; i < attributes->len; i++) {
- if (array[i].type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING) {
- g_print (" %s = '%s'\n", array[i].name, array[i].value.string);
- } else if (array[i].type == GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32) {
- g_print (" %s = %u\n", array[i].name, array[i].value.integer);
- } else {
- g_print (" %s = ** unsupported attribute type **\n", array[i].name);
- }
- }
- }
-
- g_main_loop_quit (loop);
-}
-
-static void
-get_items_callback (GnomeKeyringResult result,
- GList *list,
- gpointer data)
-{
- GList **out;
-
- out = data;
- *out = NULL;
-
- if (result != GNOME_KEYRING_RESULT_OK) {
- g_print ("error getting item list: %d\n", result);
- } else {
- *out = g_list_copy (list);
- }
-
- g_main_loop_quit (loop);
-}
-
-static void
-string_list_callback (GnomeKeyringResult result,
- GList *list,
- gpointer data)
-{
- GList *l;
- char *name;
- GList **out;
-
- out = data;
-
- *out = NULL;
-
- if (result != GNOME_KEYRING_RESULT_OK) {
- g_print ("error getting keyring list: %d\n", result);
- } else {
- for (l = list; l != NULL; l = l->next) {
- name = l->data;
- *out = g_list_append (*out, g_strdup (name));
- }
- }
-
- g_main_loop_quit (loop);
-}
-
-
-int
-main (int argc, char *argv[])
-{
- GList *keyrings, *l, *items, *ll;
- char *keyring;
- gboolean locked;
- guint32 item_id;
-
- g_set_application_name("list-keyrings");
- loop = g_main_loop_new (NULL, FALSE);
-
- g_print ("Keyrings:\n");
- gnome_keyring_list_keyring_names (string_list_callback, &keyrings, NULL);
- g_main_loop_run (loop);
- for (l = keyrings; l != NULL; l = l->next) {
- keyring = l->data;
- g_print ("\nkeyring: %s\n", keyring);
-
- gnome_keyring_get_info (keyring, print_keyring_info, &locked, NULL);
- g_main_loop_run (loop);
-
- if (1 || !locked) {
- gnome_keyring_list_item_ids (keyring, get_items_callback, &items, NULL);
- g_main_loop_run (loop);
-
- if (items != NULL) {
- g_print ("Items: \n");
- }
- for (ll = items; ll != NULL; ll = ll->next) {
- item_id = GPOINTER_TO_UINT(ll->data);
-
- g_print ("\n");
- g_print (" id: %u\n", item_id);
- gnome_keyring_item_get_info (keyring,
- item_id,
- print_item_info, NULL, NULL);
- g_main_loop_run (loop);
- gnome_keyring_item_get_attributes (keyring,
- item_id,
- print_attributes, NULL, NULL);
- g_main_loop_run (loop);
- }
- g_list_free (items);
- }
-
- g_free (keyring);
- }
- g_list_free (keyrings);
-
- gnome_keyring_get_default_keyring (string_callback, &keyring, NULL);
- g_main_loop_run (loop);
- g_print ("\n");
- if (keyring != NULL) {
- g_print ("The default keyring for storage is '%s'\n", keyring);
- } else {
- g_print ("No default keyring defined\n");
- }
-
- return 0;
-}
diff --git a/tests/test-keyrings.c b/tests/test-keyrings.c
deleted file mode 100644
index 750e92a2..00000000
--- a/tests/test-keyrings.c
+++ /dev/null
@@ -1,524 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* test-keyrings.c - test app
-
- Copyright (C) 2003 Red Hat, Inc
-
- The Gnome 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 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 <stdlib.h>
-
-#include "library/gnome-keyring.h"
-
-static GMainLoop *loop = NULL;
-
-static void
-print_attributes (GnomeKeyringAttributeList *attributes)
-{
- GnomeKeyringAttribute *array;
- int i;
-
- array = (GnomeKeyringAttribute *)attributes->data;
- g_print (" Attributes:\n");
- for (i = 0; i < attributes->len; i++) {
- if (array[i].type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING) {
- g_print (" %s = '%s'\n", array[i].name, array[i].value.string);
- } else if (array[i].type == GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32) {
- g_print (" %s = %u\n", array[i].name, array[i].value.integer);
- } else {
- g_print (" %s = ** unsupported attribute type **\n", array[i].name);
- }
- }
-}
-
-static const gchar* result_msg[] = {
- "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_ALREADY_EXISTS"
-};
-
-static const gchar*
-get_msg_for_keyring_result (GnomeKeyringResult result)
-{
- if (result<=GNOME_KEYRING_RESULT_ALREADY_EXISTS) {
- return result_msg[result];
- } else {
- return "Unknown GnomeKeyringResult";
- }
-}
-
-static void
-ok_cb (GnomeKeyringResult result,
- gpointer data)
-{
- g_print ("%s: %d (%s)\n", (char *)data, result, get_msg_for_keyring_result (result));
- g_main_loop_quit (loop);
-}
-
-static void
-lock_all (void)
-{
- gnome_keyring_lock_all (ok_cb, "lock all", NULL);
- g_main_loop_run (loop);
-}
-
-static void
-lock (char *keyring)
-{
- gnome_keyring_lock (keyring,
- ok_cb, "lock", NULL);
- g_main_loop_run (loop);
-}
-
-static void
-unlock (char *keyring, char *password)
-{
- gnome_keyring_unlock (keyring, password,
- ok_cb, "unlock", NULL);
- g_main_loop_run (loop);
-}
-
-static void
-find_items_cb (GnomeKeyringResult result,
- GList *found_items,
- gpointer data)
-{
- g_print ("found items: res: %d (%s) nr items: %d\n", result, get_msg_for_keyring_result (result), g_list_length (found_items));
-
- if (found_items != NULL) {
- GnomeKeyringFound *found = found_items->data;
-
- g_print ("Found item: keyring=%s, id=%d, secret='%s'\n", found->keyring, found->item_id, found->secret);
- print_attributes (found->attributes);
- }
-
- g_main_loop_quit (loop);
-}
-
-static void
-find_items (char *attr_val)
-{
- gnome_keyring_find_itemsv (GNOME_KEYRING_ITEM_NOTE,
- find_items_cb, NULL, NULL,
- "testattribute", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING, attr_val,
- NULL);
- g_main_loop_run (loop);
-}
-
-static void
-creat_item_cb (GnomeKeyringResult result,
- guint32 id,
- gpointer data)
-{
- g_print ("created item: res: %d (%s) id: %d\n", result, get_msg_for_keyring_result (result), id);
- g_main_loop_quit (loop);
-}
-
-static void
-create_item (char *name, char *attr_name, gboolean update_if_exists)
-{
- GnomeKeyringAttributeList *attributes;
- GnomeKeyringAttribute attribute;
-
- attribute.name = g_strdup ("testattribute");
- attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
- attribute.value.string = g_strdup (attr_name);
-
- attributes = gnome_keyring_attribute_list_new ();
- g_array_append_val (attributes, attribute);
-
- gnome_keyring_item_create (NULL,
- GNOME_KEYRING_ITEM_NOTE,
- name,
- attributes,
- "secret text",
- update_if_exists,
- creat_item_cb, NULL, NULL);
- gnome_keyring_attribute_list_free (attributes);
- g_main_loop_run (loop);
-}
-
-static void
-creat_application_item_cb (GnomeKeyringResult result,
- guint32 id,
- gpointer data)
-{
- g_print ("created application item: res: %d (%s) id: %d\n", result, get_msg_for_keyring_result (result), id);
- g_main_loop_quit (loop);
-}
-
-static void
-create_application_item (char *name, char *attr_name, gboolean update_if_exists)
-{
- GnomeKeyringAttributeList *attributes;
- GnomeKeyringAttribute attribute;
-
- attribute.name = g_strdup ("testattribute");
- attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
- attribute.value.string = g_strdup (attr_name);
-
- attributes = gnome_keyring_attribute_list_new ();
- g_array_append_val (attributes, attribute);
-
- gnome_keyring_item_create (NULL,
- GNOME_KEYRING_ITEM_NOTE | GNOME_KEYRING_ITEM_APPLICATION_SECRET,
- name,
- attributes,
- "application secret text",
- update_if_exists,
- creat_application_item_cb, NULL, NULL);
- gnome_keyring_attribute_list_free (attributes);
- g_main_loop_run (loop);
-}
-
-static void
-show_item_cb (GnomeKeyringResult result,
- GnomeKeyringItemInfo *info,
- gpointer data)
-{
- char *secret;
- char *name;
- if (result != GNOME_KEYRING_RESULT_OK) {
- g_print ("error getting item info: %d (%s)\n", result, get_msg_for_keyring_result (result));
- } else {
- name = gnome_keyring_item_info_get_display_name (info);
- secret = gnome_keyring_item_info_get_secret (info);
- g_print (" type: %u\n", gnome_keyring_item_info_get_type (info));
- g_print (" name: %s\n", name);
- g_print (" secret: %s\n", secret);
- g_print (" mtime: %lu\n", (unsigned long)gnome_keyring_item_info_get_mtime (info));
- g_print (" ctime: %lu\n", (unsigned long)gnome_keyring_item_info_get_ctime (info));
- gnome_keyring_free_password (secret);
- g_free (name);
- }
-
- g_main_loop_quit (loop);
-}
-
-static void
-print_attributes_cb (GnomeKeyringResult result,
- GnomeKeyringAttributeList *attributes,
- gpointer data)
-{
- if (result != GNOME_KEYRING_RESULT_OK) {
- g_print ("error getting item attributes: %d (%s)\n", result, get_msg_for_keyring_result (result));
- } else {
- print_attributes (attributes);
- }
-
- g_main_loop_quit (loop);
-}
-
-static void
-show_item (char *keyring, guint32 item_id, guint32 parts)
-{
- gnome_keyring_item_get_info_full (keyring, item_id, parts,
- show_item_cb, NULL, NULL);
- g_main_loop_run (loop);
- gnome_keyring_item_get_attributes (keyring, item_id,
- print_attributes_cb, NULL, NULL);
- g_main_loop_run (loop);
-}
-
-static void
-delete_item (char *keyring, guint32 item_id)
-{
- gnome_keyring_item_delete (keyring, item_id,
- ok_cb, "delete item", NULL);
- g_main_loop_run (loop);
-}
-
-static void
-set_item_secret (char *keyring, guint32 item_id, char *secret)
-{
- GnomeKeyringItemInfo *info;
-
- info = gnome_keyring_item_info_new ();
- gnome_keyring_item_info_set_secret (info, secret);
- gnome_keyring_item_set_info (keyring, item_id, info,
- ok_cb, "set item", NULL);
- gnome_keyring_item_info_free (info);
- g_main_loop_run (loop);
-}
-
-static void
-set_item_attribute (char *keyring, guint32 item_id, char *value)
-{
- GnomeKeyringAttributeList *attributes;
- GnomeKeyringAttribute attribute;
-
- attribute.name = g_strdup ("testattribute");
- attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
- attribute.value.string = g_strdup (value);
-
- attributes = gnome_keyring_attribute_list_new ();
- g_array_append_val (attributes, attribute);
-
- gnome_keyring_item_set_attributes (keyring, item_id, attributes,
- ok_cb, "set attributes", NULL);
- gnome_keyring_attribute_list_free (attributes);
- g_main_loop_run (loop);
-}
-
-static void
-create_keyring (char *name, char *password)
-{
- gnome_keyring_create (name, password,
- ok_cb, "create keyring", NULL);
- g_main_loop_run (loop);
-}
-
-static void
-set_default (char *name)
-{
- gnome_keyring_set_default_keyring (name,
- ok_cb, "set default", NULL);
- g_main_loop_run (loop);
-}
-
-static void
-set_network_cb (GnomeKeyringResult result,
- guint32 id,
- gpointer data)
-{
- g_print ("set network password: res: %d id: %d\n", result, id);
- g_main_loop_quit (loop);
-}
-
-
-static void
-set_network (char *server, char *password)
-{
- gnome_keyring_set_network_password (NULL /* default keyring */,
- NULL,
- NULL,
- server,
- NULL,
- "smb",
- NULL,
- 0,
- password,
- set_network_cb, NULL, NULL);
- g_main_loop_run (loop);
-}
-
-static void
-set_network_sync (char *server, char *password)
-{
- guint32 id;
- GnomeKeyringResult res;
- res = gnome_keyring_set_network_password_sync (NULL /* default keyring */,
- NULL,
- NULL,
- server,
- NULL,
- "smb",
- NULL,
- 0,
- password,
- &id);
- g_print ("set network password: res: %d id: %d\n", res, id);
-}
-
-static void
-find_network (char *server)
-{
- GnomeKeyringResult res;
- GList *list, *l;
-
- list = NULL;
- res = gnome_keyring_find_network_password_sync (NULL, NULL,
- server, NULL,
- "smb",
- NULL,
- 0,
- &list);
- g_print ("find network password, res: %d, len: %d\n", res, g_list_length (list));
- for (l = list; l != NULL; l = l->next) {
- GnomeKeyringNetworkPasswordData *data;
- data = l->data;
-
- g_print ("%s:%d - proto: %s, server: %s, object: %s, authtype: %s, port: %d, user: %s, domain: %s, password: %s\n",
- data->keyring,
- data->item_id,
- data->protocol,
- data->server,
- data->object,
- data->authtype,
- data->port,
- data->user,
- data->domain,
- data->password);
- }
-}
-
-static void
-list_items_cb (GnomeKeyringResult result, GList *list, gpointer data)
-{
- g_print ("list items: res: %d (%s)\n", result, get_msg_for_keyring_result (result));
- for ( ; list; list = list->next)
- g_print (" id: %d\n", GPOINTER_TO_UINT (list->data));
- g_main_loop_quit (loop);
-}
-
-static void
-list_items (const char *keyring)
-{
- gnome_keyring_list_item_ids (keyring, list_items_cb, NULL, NULL);
- g_main_loop_run (loop);
-}
-
-int
-main (int argc, char *argv[])
-{
- char arg;
-
- g_set_application_name("test-keyring");
- loop = g_main_loop_new (NULL, FALSE);
-
- arg = 0;
- if (argc >= 2) {
- arg = argv[1][0];
- }
-
- if (arg == 'L') {
- lock_all ();
- } else if (arg == 'l') {
- if (argc >= 3) {
- lock (argv[2]);
- } else {
- lock (NULL);
- }
- } else if (arg == 'u') {
- if (argc >= 4) {
- unlock (argv[2], argv[3]);
- } else {
- g_print ("unlock requires keyring and password\n");
- }
- } else if (arg == 'c') {
- if (argc >= 4) {
- create_item (argv[2], argv[3], FALSE);
- } else {
- g_print ("create item requires item name and attr value\n");
- }
- } else if (arg == 'C') {
- if (argc >= 4) {
- create_item (argv[2], argv[3], TRUE);
- } else {
- g_print ("create item requires item name and attr value\n");
- }
-
- } else if (arg == 'A') {
- if (argc >= 4) {
- create_application_item (argv[2], argv[3], FALSE);
- } else {
- g_print ("create application item requires item name and attr value\n");
- }
-
- /* Show complete item information */
- } else if (arg == 'i') {
- if (argc >= 4) {
- show_item (argv[2], atoi(argv[3]), GNOME_KEYRING_ITEM_INFO_SECRET);
- } else {
- g_print ("must give keyring & item id to show\n");
- }
-
- /* Show basic item information */
- } else if (arg == 'b') {
- if (argc >= 4) {
- show_item (argv[2], atoi(argv[3]), GNOME_KEYRING_ITEM_INFO_BASICS);
- } else {
- g_print ("must give keyring & item id to show\n");
- }
- } else if (arg == 'd') {
- if (argc >= 4) {
- delete_item (argv[2] ,atoi (argv[3]));
- } else {
- g_print ("must give keyring & item id to delete\n");
- }
- } else if (arg == 's') {
- if (argc >= 5) {
- set_item_secret (argv[2] ,atoi (argv[3]), argv[4]);
- } else {
- g_print ("must give keyring & item id & secret\n");
- }
- } else if (arg == 'a') {
- if (argc >= 5) {
- set_item_attribute (argv[2] ,atoi (argv[3]), argv[4]);
- } else {
- g_print ("must give keyring & item id & attribute value\n");
- }
- } else if (arg == 'f') {
- if (argc >= 3) {
- find_items (argv[2]);
- } else {
- g_print ("must give testattribute value\n");
- }
- } else if (arg == 'k') {
- if (argc >= 4) {
- create_keyring (argv[2], argv[3]);
- } else if (argc >= 3) {
- create_keyring (argv[2], NULL);
- } else {
- g_print ("create keyring requires keyring name\n");
- }
- } else if (arg == 'D') {
- if (argc >= 3) {
- set_default (argv[2]);
- } else {
- set_default (NULL);
- }
- } else if (arg == 'n') {
- if (argc >= 4) {
- set_network (argv[2], argv[3]);
- } else {
- g_print ("need server & password\n");
- }
- } else if (arg == 'N') {
- if (argc >= 4) {
- set_network_sync (argv[2], argv[3]);
- } else {
- g_print ("need server & password\n");
- }
- } else if (arg == 'p') {
- if (argc >= 3) {
- find_network (argv[2]);
- } else {
- g_print ("need server\n");
- }
- } else if (arg == 't') {
- g_print ("gnome keyring is: %s\n",
- gnome_keyring_is_available ()?"available":"not available");
- } else if (arg == 'I') {
- if (argc >= 3) {
- list_items(argv[2]);
- } else {
- g_print ("need keyring\n");
- }
- } else {
- g_print ("unsupported test\n");
- }
-
-
- return 0;
-}