1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-keyring.c Store secret cookies in your homedir
4 * Copyright (C) 2003 Red Hat Inc.
6 * Licensed under the Academic Free License version 1.2
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "dbus-keyring.h"
25 #include <dbus/dbus-string.h>
26 #include <dbus/dbus-list.h>
27 #include <dbus/dbus-sysdeps.h>
30 * @defgroup DBusKeyring keyring class
31 * @ingroup DBusInternals
32 * @brief DBusKeyring data structure
34 * Types and functions related to DBusKeyring. DBusKeyring is intended
35 * to manage cookies used to authenticate clients to servers. This is
36 * essentially the "verify that client can read the user's homedir"
37 * authentication mechanism. Both client and server must have access
40 * The secret keys are not kept in locked memory, and are written to a
41 * file in the user's homedir. However they are transient (only used
42 * by a single server instance for a fixed period of time, then
43 * discarded). Also, the keys are not sent over the wire.
45 * @todo there's a memory leak on some codepath in here, I saw it once
46 * when running make check - probably some specific initial cookies
47 * present in the cookie file, then depending on what we do with them.
51 * @defgroup DBusKeyringInternals DBusKeyring implementation details
52 * @ingroup DBusInternals
53 * @brief DBusKeyring implementation details
55 * The guts of DBusKeyring.
60 /** The maximum age of a key before we create a new key to use in
61 * challenges. This isn't super-reliably enforced, since system
62 * clocks can change or be wrong, but we make a best effort to only
63 * use keys for a short time.
65 #define NEW_KEY_TIMEOUT_SECONDS (60*5)
67 * The time after which we drop a key from the secrets file.
68 * The EXPIRE_KEYS_TIMEOUT_SECONDS - NEW_KEY_TIMEOUT_SECONDS is the minimum
69 * time window a client has to complete authentication.
71 #define EXPIRE_KEYS_TIMEOUT_SECONDS (NEW_KEY_TIMEOUT_SECONDS + (60*2))
73 * The maximum amount of time a key can be in the future.
75 #define MAX_TIME_TRAVEL_SECONDS (60*5)
79 dbus_int32_t id; /**< identifier used to refer to the key */
81 long creation_time; /**< when the key was generated,
82 * as unix timestamp. signed long
83 * matches struct timeval.
86 DBusString secret; /**< the actual key */
91 * @brief Internals of DBusKeyring.
93 * DBusKeyring internals. DBusKeyring is an opaque object, it must be
94 * used via accessor functions.
98 int refcount; /**< Reference count */
99 DBusString username; /**< Username keyring is for */
100 DBusString directory; /**< Directory the below two items are inside */
101 DBusString filename; /**< Keyring filename */
102 DBusString filename_lock; /**< Name of lockfile */
103 DBusKey *keys; /**< Keys loaded from the file */
104 int n_keys; /**< Number of keys */
108 _dbus_keyring_new (void)
110 DBusKeyring *keyring;
112 keyring = dbus_new0 (DBusKeyring, 1);
116 if (!_dbus_string_init (&keyring->directory))
119 if (!_dbus_string_init (&keyring->filename))
122 if (!_dbus_string_init (&keyring->filename_lock))
125 if (!_dbus_string_init (&keyring->username))
128 keyring->refcount = 1;
129 keyring->keys = NULL;
135 _dbus_string_free (&keyring->username);
137 _dbus_string_free (&keyring->filename);
139 _dbus_string_free (&keyring->directory);
147 free_keys (DBusKey *keys,
152 /* should be safe for args NULL, 0 */
157 _dbus_string_free (&keys[i].secret);
164 /* Our locking scheme is highly unreliable. However, there is
165 * unfortunately no reliable locking scheme in user home directories;
166 * between bugs in Linux NFS, people using Tru64 or other total crap
167 * NFS, AFS, random-file-system-of-the-week, and so forth, fcntl() in
168 * homedirs simply generates tons of bug reports. This has been
169 * learned through hard experience with GConf, unfortunately.
171 * This bad hack might work better for the kind of lock we have here,
172 * which we don't expect to hold for any length of time. Crashing
173 * while we hold it should be unlikely, and timing out such that we
174 * delete a stale lock should also be unlikely except when the
175 * filesystem is running really slowly. Stuff might break in corner
176 * cases but as long as it's not a security-level breakage it should
180 /** Maximum number of timeouts waiting for lock before we decide it's stale */
181 #define MAX_LOCK_TIMEOUTS 32
182 /** Length of each timeout while waiting for a lock */
183 #define LOCK_TIMEOUT_MILLISECONDS 250
186 _dbus_keyring_lock (DBusKeyring *keyring)
191 while (n_timeouts < MAX_LOCK_TIMEOUTS)
195 dbus_error_init (&error);
196 if (_dbus_create_file_exclusively (&keyring->filename_lock,
200 _dbus_verbose ("Did not get lock file, sleeping %d milliseconds (%s)\n",
201 LOCK_TIMEOUT_MILLISECONDS, error.message);
202 dbus_error_free (&error);
204 _dbus_sleep_milliseconds (LOCK_TIMEOUT_MILLISECONDS);
209 if (n_timeouts == MAX_LOCK_TIMEOUTS)
213 _dbus_verbose ("Lock file timed out %d times, assuming stale\n",
216 dbus_error_init (&error);
218 if (!_dbus_delete_file (&keyring->filename_lock, &error))
220 _dbus_verbose ("Couldn't delete old lock file: %s\n",
222 dbus_error_free (&error);
226 if (!_dbus_create_file_exclusively (&keyring->filename_lock,
229 _dbus_verbose ("Couldn't create lock file after deleting stale one: %s\n",
231 dbus_error_free (&error);
240 _dbus_keyring_unlock (DBusKeyring *keyring)
243 dbus_error_init (&error);
244 if (!_dbus_delete_file (&keyring->filename_lock, &error))
246 _dbus_warn ("Failed to delete lock file: %s\n",
248 dbus_error_free (&error);
253 find_key_by_id (DBusKey *keys,
262 if (keys[i].id == id)
272 add_new_key (DBusKey **keys_p,
279 unsigned long timestamp;
280 const unsigned char *s;
285 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
287 if (!_dbus_string_init (&bytes))
289 dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
297 /* Generate an integer ID and then the actual key. */
300 if (!_dbus_generate_random_bytes (&bytes, 4))
302 dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
306 s = (const unsigned char*) _dbus_string_get_const_data (&bytes);
308 id = s[0] | (s[1] << 8) | (s[2] << 16) | (s[3] << 24);
311 _dbus_assert (id >= 0);
313 if (find_key_by_id (keys, n_keys, id) != NULL)
315 _dbus_string_set_length (&bytes, 0);
316 _dbus_verbose ("Key ID %d already existed, trying another one\n",
321 _dbus_verbose ("Creating key with ID %d\n", id);
323 #define KEY_LENGTH_BYTES 24
324 _dbus_string_set_length (&bytes, 0);
325 if (!_dbus_generate_random_bytes (&bytes, KEY_LENGTH_BYTES))
327 dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
331 new = dbus_realloc (keys, sizeof (DBusKey) * (n_keys + 1));
334 dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
341 if (!_dbus_string_init (&keys[n_keys-1].secret))
343 n_keys -= 1; /* we don't want to free the one we didn't init */
344 dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
348 _dbus_get_current_time (×tamp, NULL);
350 keys[n_keys-1].id = id;
351 keys[n_keys-1].creation_time = timestamp;
352 if (!_dbus_string_move (&bytes, 0,
353 &keys[n_keys-1].secret,
356 dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
369 _dbus_string_free (&bytes);
374 * Reloads the keyring file, optionally adds one new key to the file,
375 * removes all expired keys from the file iff a key was added, then
376 * resaves the file. Stores the keys from the file in keyring->keys.
377 * Note that the file is only resaved (written to) if a key is added,
378 * this means that only servers ever write to the file and need to
379 * lock it, which avoids a lot of lock contention at login time and
382 * @param keyring the keyring
383 * @param add_new #TRUE to add a new key to the file, expire keys, and resave
384 * @param error return location for errors
385 * @returns #FALSE on failure
388 _dbus_keyring_reload (DBusKeyring *keyring,
395 dbus_bool_t have_lock;
402 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
404 if (!_dbus_string_init (&contents))
406 dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
410 if (!_dbus_string_init (&line))
412 dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
413 _dbus_string_free (&contents);
422 _dbus_get_current_time (&now, NULL);
426 if (!_dbus_keyring_lock (keyring))
428 dbus_set_error (error, DBUS_ERROR_FAILED,
429 "Could not lock keyring file to add to it");
436 dbus_error_init (&tmp_error);
437 if (!_dbus_file_get_contents (&contents,
441 _dbus_verbose ("Failed to load keyring file: %s\n",
443 /* continue with empty keyring file, so we recreate it */
444 dbus_error_free (&tmp_error);
447 if (!_dbus_string_validate_ascii (&contents, 0,
448 _dbus_string_get_length (&contents)))
450 _dbus_warn ("Secret keyring file contains non-ASCII! Ignoring existing contents\n");
451 _dbus_string_set_length (&contents, 0);
454 while (_dbus_string_pop_line (&contents, &line))
464 if (!_dbus_string_parse_int (&line, 0, &val, &next))
466 _dbus_verbose ("could not parse secret key ID at start of line\n");
470 if (val > _DBUS_INT_MAX || val < 0)
472 _dbus_verbose ("invalid secret key ID at start of line\n");
478 _dbus_string_skip_blank (&line, next, &next);
480 if (!_dbus_string_parse_int (&line, next, ×tamp, &next))
482 _dbus_verbose ("could not parse secret key timestamp\n");
487 (now + MAX_TIME_TRAVEL_SECONDS) < timestamp ||
488 (now - EXPIRE_KEYS_TIMEOUT_SECONDS) > timestamp)
490 _dbus_verbose ("dropping/ignoring %ld-seconds old key with timestamp %ld as current time is %ld\n",
491 now - timestamp, timestamp, now);
495 _dbus_string_skip_blank (&line, next, &next);
497 len = _dbus_string_get_length (&line);
499 if ((len - next) == 0)
501 _dbus_verbose ("no secret key after ID and timestamp\n");
505 /* We have all three parts */
506 new = dbus_realloc (keys, sizeof (DBusKey) * (n_keys + 1));
509 dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
516 if (!_dbus_string_init (&keys[n_keys-1].secret))
518 n_keys -= 1; /* we don't want to free the one we didn't init */
519 dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
523 keys[n_keys-1].id = id;
524 keys[n_keys-1].creation_time = timestamp;
525 if (!_dbus_string_hex_decode (&line, next,
526 &keys[n_keys-1].secret,
529 dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
534 _dbus_verbose ("Successfully loaded %d existing keys\n",
539 if (!add_new_key (&keys, &n_keys, error))
541 _dbus_verbose ("Failed to generate new key: %s\n",
542 error ? "(unknown)" : error->message);
546 _dbus_string_set_length (&contents, 0);
551 if (!_dbus_string_append_int (&contents,
555 if (!_dbus_string_append_byte (&contents, ' '))
558 if (!_dbus_string_append_int (&contents,
559 keys[i].creation_time))
562 if (!_dbus_string_append_byte (&contents, ' '))
565 if (!_dbus_string_hex_encode (&keys[i].secret, 0,
567 _dbus_string_get_length (&contents)))
570 if (!_dbus_string_append_byte (&contents, '\n'))
577 dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
581 if (!_dbus_string_save_to_file (&contents, &keyring->filename,
586 dbus_free (keyring->keys);
587 keyring->keys = keys;
588 keyring->n_keys = n_keys;
596 _dbus_keyring_unlock (keyring);
598 if (! ((retval == TRUE && (error == NULL || error->name == NULL)) ||
599 (retval == FALSE && (error == NULL || error->name != NULL))))
601 if (error && error->name)
602 _dbus_verbose ("error is %s: %s\n", error->name, error->message);
603 _dbus_warn ("returning %d but error pointer %p name %s\n",
604 retval, error, error->name ? error->name : "(none)");
605 _dbus_assert_not_reached ("didn't handle errors properly");
613 _dbus_string_zero (&keys[i].secret);
614 _dbus_string_free (&keys[i].secret);
621 _dbus_string_free (&contents);
622 _dbus_string_free (&line);
627 /** @} */ /* end of internals */
630 * @addtogroup DBusKeyring
636 * Increments reference count of the keyring
638 * @param keyring the keyring
641 _dbus_keyring_ref (DBusKeyring *keyring)
643 keyring->refcount += 1;
647 * Decrements refcount and finalizes if it reaches
650 * @param keyring the keyring
653 _dbus_keyring_unref (DBusKeyring *keyring)
655 keyring->refcount -= 1;
657 if (keyring->refcount == 0)
659 _dbus_string_free (&keyring->username);
660 _dbus_string_free (&keyring->filename);
661 _dbus_string_free (&keyring->filename_lock);
662 _dbus_string_free (&keyring->directory);
663 free_keys (keyring->keys, keyring->n_keys);
669 * Creates a new keyring that lives in the ~/.dbus-keyrings
670 * directory of the given user. If the username is #NULL,
671 * uses the user owning the current process.
673 * @param username username to get keyring for, or #NULL
674 * @param context which keyring to get
675 * @param error return location for errors
676 * @returns the keyring or #NULL on error
679 _dbus_keyring_new_homedir (const DBusString *username,
680 const DBusString *context,
684 DBusKeyring *keyring;
685 dbus_bool_t error_set;
689 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
694 if (!_dbus_string_init (&homedir))
697 _dbus_string_init_const (&dotdir, ".dbus-keyrings");
699 if (username == NULL)
701 const DBusString *const_homedir;
703 if (!_dbus_user_info_from_current_process (&username,
708 if (!_dbus_string_copy (const_homedir, 0,
714 if (!_dbus_homedir_from_username (username, &homedir))
718 #ifdef DBUS_BUILD_TESTS
720 const char *override;
722 override = _dbus_getenv ("DBUS_TEST_HOMEDIR");
723 if (override != NULL && *override != '\0')
725 _dbus_string_set_length (&homedir, 0);
726 if (!_dbus_string_append (&homedir, override))
727 _dbus_assert_not_reached ("no memory");
729 _dbus_verbose ("Using fake homedir for testing: %s\n",
730 _dbus_string_get_const_data (&homedir));
734 _dbus_warn ("Using your real home directory for testing, set DBUS_TEST_HOMEDIR to avoid\n");
739 _dbus_assert (username != NULL);
741 keyring = _dbus_keyring_new ();
745 /* should have been validated already, but paranoia check here */
746 if (!_dbus_keyring_validate_context (context))
749 dbus_set_error_const (error,
751 "Invalid context in keyring creation");
755 if (!_dbus_string_copy (username, 0,
756 &keyring->username, 0))
759 if (!_dbus_string_copy (&homedir, 0,
760 &keyring->directory, 0))
763 _dbus_string_free (&homedir);
765 if (!_dbus_concat_dir_and_file (&keyring->directory,
769 if (!_dbus_string_copy (&keyring->directory, 0,
770 &keyring->filename, 0))
773 if (!_dbus_concat_dir_and_file (&keyring->filename,
777 if (!_dbus_string_copy (&keyring->filename, 0,
778 &keyring->filename_lock, 0))
781 if (!_dbus_string_append (&keyring->filename_lock, ".lock"))
784 dbus_error_init (&tmp_error);
785 if (!_dbus_keyring_reload (keyring, FALSE, &tmp_error))
787 _dbus_verbose ("didn't load an existing keyring: %s\n",
789 dbus_error_free (&tmp_error);
792 /* We don't fail fatally if we can't create the directory,
793 * but the keyring will probably always be empty
794 * unless someone else manages to create it
796 dbus_error_init (&tmp_error);
797 if (!_dbus_create_directory (&keyring->directory,
800 _dbus_verbose ("Creating keyring directory: %s\n",
802 dbus_error_free (&tmp_error);
809 dbus_set_error_const (error,
810 DBUS_ERROR_NO_MEMORY,
811 "No memory to create keyring");
813 _dbus_keyring_unref (keyring);
814 _dbus_string_free (&homedir);
820 * Checks whether the context is a valid context.
821 * Contexts that might cause confusion when used
822 * in filenames are not allowed (contexts can't
823 * start with a dot or contain dir separators).
825 * @todo this is the most inefficient implementation
828 * @param context the context
829 * @returns #TRUE if valid
832 _dbus_keyring_validate_context (const DBusString *context)
834 if (_dbus_string_get_length (context) == 0)
836 _dbus_verbose ("context is zero-length\n");
840 if (!_dbus_string_validate_ascii (context, 0,
841 _dbus_string_get_length (context)))
843 _dbus_verbose ("context not valid ascii\n");
847 /* no directory separators */
848 if (_dbus_string_find (context, 0, "/", NULL))
850 _dbus_verbose ("context contains a slash\n");
854 if (_dbus_string_find (context, 0, "\\", NULL))
856 _dbus_verbose ("context contains a backslash\n");
860 /* prevent attempts to use dotfiles or ".." or ".lock"
861 * all of which might allow some kind of attack
863 if (_dbus_string_find (context, 0, ".", NULL))
865 _dbus_verbose ("context contains a dot\n");
869 /* no spaces/tabs, those are used for separators in the protocol */
870 if (_dbus_string_find_blank (context, 0, NULL))
872 _dbus_verbose ("context contains a blank\n");
876 if (_dbus_string_find (context, 0, "\n", NULL))
878 _dbus_verbose ("context contains a newline\n");
882 if (_dbus_string_find (context, 0, "\r", NULL))
884 _dbus_verbose ("context contains a carriage return\n");
892 find_recent_key (DBusKeyring *keyring)
895 long tv_sec, tv_usec;
897 _dbus_get_current_time (&tv_sec, &tv_usec);
900 while (i < keyring->n_keys)
902 DBusKey *key = &keyring->keys[i];
904 _dbus_verbose ("Key %d is %ld seconds old\n",
905 i, tv_sec - key->creation_time);
907 if ((tv_sec - NEW_KEY_TIMEOUT_SECONDS) < key->creation_time)
917 * Gets a recent key to use for authentication.
918 * If no recent key exists, creates one. Returns
919 * the key ID. If a key can't be written to the keyring
920 * file so no recent key can be created, returns -1.
921 * All valid keys are > 0.
923 * @param keyring the keyring
924 * @param error error on failure
925 * @returns key ID to use for auth, or -1 on failure
928 _dbus_keyring_get_best_key (DBusKeyring *keyring,
933 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
935 key = find_recent_key (keyring);
939 /* All our keys are too old, or we've never loaded the
940 * keyring. Create a new one.
942 if (!_dbus_keyring_reload (keyring, TRUE,
946 key = find_recent_key (keyring);
951 dbus_set_error_const (error,
953 "No recent-enough key found in keyring, and unable to create a new key");
959 * Checks whether the keyring is for the given username.
961 * @param keyring the keyring
962 * @param username the username to check
964 * @returns #TRUE if the keyring belongs to the given user
967 _dbus_keyring_is_for_user (DBusKeyring *keyring,
968 const DBusString *username)
970 return _dbus_string_equal (&keyring->username,
975 * Gets the hex-encoded secret key for the given ID.
976 * Returns #FALSE if not enough memory. Returns #TRUE
977 * but empty key on any other error such as unknown
980 * @param keyring the keyring
981 * @param key_id the key ID
982 * @param hex_key string to append hex-encoded key to
983 * @returns #TRUE if we had enough memory
986 _dbus_keyring_get_hex_key (DBusKeyring *keyring,
992 key = find_key_by_id (keyring->keys,
996 return TRUE; /* had enough memory, so TRUE */
998 return _dbus_string_hex_encode (&key->secret, 0,
1000 _dbus_string_get_length (hex_key));
1003 /** @} */ /* end of exposed API */
1005 #ifdef DBUS_BUILD_TESTS
1006 #include "dbus-test.h"
1010 _dbus_keyring_test (void)
1022 /* Context validation */
1024 _dbus_string_init_const (&context, "foo");
1025 _dbus_assert (_dbus_keyring_validate_context (&context));
1026 _dbus_string_init_const (&context, "org_freedesktop_blah");
1027 _dbus_assert (_dbus_keyring_validate_context (&context));
1029 _dbus_string_init_const (&context, "");
1030 _dbus_assert (!_dbus_keyring_validate_context (&context));
1031 _dbus_string_init_const (&context, ".foo");
1032 _dbus_assert (!_dbus_keyring_validate_context (&context));
1033 _dbus_string_init_const (&context, "bar.foo");
1034 _dbus_assert (!_dbus_keyring_validate_context (&context));
1035 _dbus_string_init_const (&context, "bar/foo");
1036 _dbus_assert (!_dbus_keyring_validate_context (&context));
1037 _dbus_string_init_const (&context, "bar\\foo");
1038 _dbus_assert (!_dbus_keyring_validate_context (&context));
1039 _dbus_string_init_const (&context, "foo\xfa\xf0");
1040 _dbus_assert (!_dbus_keyring_validate_context (&context));
1041 _dbus_string_init_const (&context, "foo\x80");
1042 _dbus_assert (!_dbus_keyring_validate_context (&context));
1043 _dbus_string_init_const (&context, "foo\x7f");
1044 _dbus_assert (_dbus_keyring_validate_context (&context));
1045 _dbus_string_init_const (&context, "foo bar");
1046 _dbus_assert (!_dbus_keyring_validate_context (&context));
1048 if (!_dbus_string_init (&context))
1049 _dbus_assert_not_reached ("no memory");
1050 if (!_dbus_string_append_byte (&context, '\0'))
1051 _dbus_assert_not_reached ("no memory");
1052 _dbus_assert (!_dbus_keyring_validate_context (&context));
1053 _dbus_string_free (&context);
1055 /* Now verify that if we create a key in keyring 1,
1056 * it is properly loaded in keyring 2
1059 _dbus_string_init_const (&context, "org_freedesktop_dbus_testsuite");
1060 dbus_error_init (&error);
1061 ring1 = _dbus_keyring_new_homedir (NULL, &context,
1063 _dbus_assert (ring1);
1064 _dbus_assert (error.name == NULL);
1066 id = _dbus_keyring_get_best_key (ring1, &error);
1069 fprintf (stderr, "Could not load keyring: %s\n", error.message);
1070 dbus_error_free (&error);
1074 ring2 = _dbus_keyring_new_homedir (NULL, &context, &error);
1075 _dbus_assert (ring2);
1076 _dbus_assert (error.name == NULL);
1078 if (ring1->n_keys != ring2->n_keys)
1080 fprintf (stderr, "Different number of keys in keyrings\n");
1084 /* We guarantee we load and save keeping keys in a fixed
1088 while (i < ring1->n_keys)
1090 if (ring1->keys[i].id != ring2->keys[i].id)
1092 fprintf (stderr, "Keyring 1 has first key ID %d and keyring 2 has %d\n",
1093 ring1->keys[i].id, ring2->keys[i].id);
1097 if (ring1->keys[i].creation_time != ring2->keys[i].creation_time)
1099 fprintf (stderr, "Keyring 1 has first key time %ld and keyring 2 has %ld\n",
1100 ring1->keys[i].creation_time, ring2->keys[i].creation_time);
1104 if (!_dbus_string_equal (&ring1->keys[i].secret,
1105 &ring2->keys[i].secret))
1107 fprintf (stderr, "Keyrings 1 and 2 have different secrets for same ID/timestamp\n");
1114 printf (" %d keys in test\n", ring1->n_keys);
1116 _dbus_keyring_unref (ring1);
1117 _dbus_keyring_unref (ring2);
1123 _dbus_keyring_unref (ring1);
1125 _dbus_keyring_unref (ring2);
1130 #endif /* DBUS_BUILD_TESTS */