* Maximum number of keys in the keyring before
* we just ignore the rest
*/
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#define MAX_KEYS_IN_FILE 10
#else
#define MAX_KEYS_IN_FILE 256
return keyring;
- /* out_4: */
- _dbus_string_free (&keyring->filename_lock);
out_3:
_dbus_string_free (&keyring->filename);
out_2:
if (!_dbus_delete_file (&keyring->filename_lock, &error))
{
- _dbus_warn ("Failed to delete lock file: %s\n",
+ _dbus_warn ("Failed to delete lock file: %s",
error.message);
dbus_error_free (&error);
}
/* Generate an integer ID and then the actual key. */
retry:
- if (!_dbus_generate_random_bytes (&bytes, 4))
- {
- dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
- goto out;
- }
+ if (!_dbus_generate_random_bytes (&bytes, 4, error))
+ goto out;
s = (const unsigned char*) _dbus_string_get_const_data (&bytes);
#define KEY_LENGTH_BYTES 24
_dbus_string_set_length (&bytes, 0);
- if (!_dbus_generate_random_bytes (&bytes, KEY_LENGTH_BYTES))
+ if (!_dbus_generate_random_bytes (&bytes, KEY_LENGTH_BYTES, error))
{
- dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
goto out;
}
goto out;
}
- _dbus_get_current_time (×tamp, NULL);
+ _dbus_get_real_time (×tamp, NULL);
keys[n_keys-1].id = id;
keys[n_keys-1].creation_time = timestamp;
retval = FALSE;
have_lock = FALSE;
- _dbus_get_current_time (&now, NULL);
+ _dbus_get_real_time (&now, NULL);
if (add_new)
{
if (!_dbus_string_validate_ascii (&contents, 0,
_dbus_string_get_length (&contents)))
{
- _dbus_warn ("Secret keyring file contains non-ASCII! Ignoring existing contents\n");
+ _dbus_warn ("Secret keyring file contains non-ASCII! Ignoring existing contents");
_dbus_string_set_length (&contents, 0);
}
}
if (!_dbus_string_save_to_file (&contents, &keyring->filename,
- error))
+ FALSE, error))
goto out;
}
{
if (error && error->name)
_dbus_verbose ("error is %s: %s\n", error->name, error->message);
- _dbus_warn ("returning %d but error pointer %p name %s\n",
+ _dbus_warn ("returning %d but error pointer %p name %s",
retval, error, error->name ? error->name : "(none)");
_dbus_assert_not_reached ("didn't handle errors properly");
}
/**
* Creates a new keyring that lives in the ~/.dbus-keyrings directory
- * of the given user credentials. If the credentials are #NULL or
- * empty, uses those of the current process.
+ * of the user represented by @p credentials. If the @p credentials are
+ * #NULL or empty, uses those of the current process.
*
- * @param username username to get keyring for, or #NULL
+ * @param credentials a set of credentials representing a user or #NULL
* @param context which keyring to get
* @param error return location for errors
* @returns the keyring or #NULL on error
DBusCredentials *our_credentials;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
+
+ if (_dbus_check_setuid ())
+ {
+ dbus_set_error_const (error, DBUS_ERROR_NOT_SUPPORTED,
+ "Unable to create DBus keyring when setuid");
+ return NULL;
+ }
keyring = NULL;
error_set = FALSE;
* unless someone else manages to create it
*/
dbus_error_init (&tmp_error);
- if (!_dbus_create_directory (&keyring->directory,
+ if (!_dbus_ensure_directory (&keyring->directory,
&tmp_error))
{
_dbus_verbose ("Creating keyring directory: %s\n",
int i;
long tv_sec, tv_usec;
- _dbus_get_current_time (&tv_sec, &tv_usec);
+ _dbus_get_real_time (&tv_sec, &tv_usec);
i = 0;
while (i < keyring->n_keys)
/** @} */ /* end of exposed API */
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include "dbus-test.h"
#include <stdio.h>
return FALSE;
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */