Lines Matching refs:keyring

2 /* dbus-keyring.c Store secret cookies in your homedir
25 #include "dbus-keyring.h"
32 * @defgroup DBusKeyring keyring class
80 * Maximum number of keys in the keyring before
119 DBusCredentials *credentials; /**< Credentials containing user the keyring is for */
125 DBusKeyring *keyring;
127 keyring = dbus_new0 (DBusKeyring, 1);
128 if (keyring == NULL)
131 if (!_dbus_string_init (&keyring->directory))
134 if (!_dbus_string_init (&keyring->filename))
137 if (!_dbus_string_init (&keyring->filename_lock))
140 keyring->refcount = 1;
141 keyring->keys = NULL;
142 keyring->n_keys = 0;
144 return keyring;
147 _dbus_string_free (&keyring->filename_lock);
149 _dbus_string_free (&keyring->filename);
151 _dbus_string_free (&keyring->directory);
153 dbus_free (keyring);
198 _dbus_keyring_lock (DBusKeyring *keyring)
207 if (_dbus_create_file_exclusively (&keyring->filename_lock,
227 if (!_dbus_delete_file (&keyring->filename_lock, &error))
235 if (!_dbus_create_file_exclusively (&keyring->filename_lock,
249 _dbus_keyring_unlock (DBusKeyring *keyring)
253 if (!_dbus_delete_file (&keyring->filename_lock, &error))
382 * Reloads the keyring file, optionally adds one new key to the file,
384 * resaves the file. Stores the keys from the file in keyring->keys.
390 * @param keyring the keyring
396 _dbus_keyring_reload (DBusKeyring *keyring,
412 if (!_dbus_check_dir_is_private_to_user (&keyring->directory, error))
437 if (!_dbus_keyring_lock (keyring))
440 "Could not lock keyring file to add to it");
449 &keyring->filename,
452 _dbus_verbose ("Failed to load keyring file: %s\n",
454 /* continue with empty keyring file, so we recreate it */
461 _dbus_warn ("Secret keyring file contains non-ASCII! Ignoring existing contents\n");
465 /* FIXME this is badly inefficient for large keyring files
466 * (not that large keyring files exist outside of test suites)
553 _dbus_verbose ("invalid hex encoding in keyring file\n");
607 if (!_dbus_string_save_to_file (&contents, &keyring->filename,
612 if (keyring->keys)
613 free_keys (keyring->keys, keyring->n_keys);
614 keyring->keys = keys;
615 keyring->n_keys = n_keys;
623 _dbus_keyring_unlock (keyring);
663 * Increments reference count of the keyring
665 * @param keyring the keyring
666 * @returns the keyring
669 _dbus_keyring_ref (DBusKeyring *keyring)
671 keyring->refcount += 1;
673 return keyring;
680 * @param keyring the keyring
683 _dbus_keyring_unref (DBusKeyring *keyring)
685 keyring->refcount -= 1;
687 if (keyring->refcount == 0)
689 if (keyring->credentials)
690 _dbus_credentials_unref (keyring->credentials);
692 _dbus_string_free (&keyring->filename);
693 _dbus_string_free (&keyring->filename_lock);
694 _dbus_string_free (&keyring->directory);
695 free_keys (keyring->keys, keyring->n_keys);
696 dbus_free (keyring);
701 * Creates a new keyring that lives in the ~/.dbus-keyrings directory
705 * @param username username to get keyring for, or #NULL
706 * @param context which keyring to get
708 * @returns the keyring or #NULL on error
716 DBusKeyring *keyring;
723 keyring = NULL;
755 keyring = _dbus_keyring_new ();
756 if (keyring == NULL)
759 _dbus_assert (keyring->credentials == NULL);
760 keyring->credentials = our_credentials;
769 "Invalid context in keyring creation");
773 /* Save keyring dir in the keyring object */
775 &keyring->directory, 0))
778 /* Create keyring->filename based on keyring dir and context */
779 if (!_dbus_string_copy (&keyring->directory, 0,
780 &keyring->filename, 0))
783 if (!_dbus_concat_dir_and_file (&keyring->filename,
788 if (!_dbus_string_copy (&keyring->filename, 0,
789 &keyring->filename_lock, 0))
792 if (!_dbus_string_append (&keyring->filename_lock, ".lock"))
795 /* Reload keyring */
797 if (!_dbus_keyring_reload (keyring, FALSE, &tmp_error))
799 _dbus_verbose ("didn't load an existing keyring: %s\n",
805 * but the keyring will probably always be empty
809 if (!_dbus_create_directory (&keyring->directory,
812 _dbus_verbose ("Creating keyring directory: %s\n",
819 return keyring;
828 if (keyring)
829 _dbus_keyring_unref (keyring);
908 find_recent_key (DBusKeyring *keyring)
916 while (i < keyring->n_keys)
918 DBusKey *key = &keyring->keys[i];
935 * the key ID. If a key can't be written to the keyring
939 * @param keyring the keyring
944 _dbus_keyring_get_best_key (DBusKeyring *keyring,
951 key = find_recent_key (keyring);
956 * keyring. Create a new one.
958 if (!_dbus_keyring_reload (keyring, TRUE,
962 key = find_recent_key (keyring);
969 "No recent-enough key found in keyring, and unable to create a new key");
975 * Checks whether the keyring is for the same user as the given credentials.
977 * @param keyring the keyring
980 * @returns #TRUE if the keyring belongs to the given user
983 _dbus_keyring_is_for_credentials (DBusKeyring *keyring,
986 return _dbus_credentials_same_user (keyring->credentials,
996 * @param keyring the keyring
1002 _dbus_keyring_get_hex_key (DBusKeyring *keyring,
1008 key = find_key_by_id (keyring->keys,
1009 keyring->n_keys,
1071 /* Now verify that if we create a key in keyring 1,
1072 * it is properly loaded in keyring 2
1085 fprintf (stderr, "Could not load keyring: %s\n", error.message);
1108 fprintf (stderr, "Keyring 1 has first key ID %d and keyring 2 has %d\n",
1115 fprintf (stderr, "Keyring 1 has first key time %ld and keyring 2 has %ld\n",