24#define DBUS_USERDB_INCLUDES_PRIVATE 1
25#include "dbus-userdb.h"
28#include "dbus-internals.h"
29#include "dbus-protocol.h"
30#include "dbus-credentials.h"
36#if defined(DBUS_WIN) || !defined(DBUS_UNIX)
37#error "This file only makes sense on Unix OSs"
139 end == _dbus_string_get_length (str))
165 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
194 _dbus_verbose (
"No cache for user \"%s\"\n",
195 _dbus_string_get_const_data (username));
209 _DBUS_ASSERT_ERROR_IS_SET (error);
218 _DBUS_ASSERT_ERROR_IS_SET (error);
231 _dbus_user_info_ref (info);
244 _dbus_user_info_ref (info);
264static DBusUserDatabase *system_db =
NULL;
269shutdown_system_db (
void *data)
271 if (system_db !=
NULL)
283 if (system_db ==
NULL)
289 if (system_db ==
NULL)
308 _dbus_warn (
"Could not get password database information for UID of current process: %s",
355 database_locked =
TRUE;
370 database_locked =
FALSE;
402 if (system_db !=
NULL)
421 if (!init_system_db ())
426 *username = &process_username;
445 if (!init_system_db ())
450 *homedir = &process_homedir;
467 DBusUserDatabase *db;
472 const char *from_environment;
476 if (from_environment !=
NULL)
525 DBusCredentialsAddFlags flags,
528 DBusUserDatabase *db;
537 _DBUS_STATIC_ASSERT (
sizeof (uid) ==
sizeof (
dbus_uid_t));
545 _DBUS_SET_OOM (error);
551 if (!(flags & DBUS_CREDENTIALS_ADD_FLAGS_USER_DATABASE))
554 "Expected a numeric Unix uid");
560 _DBUS_SET_OOM (error);
568 _DBUS_SET_OOM (error);
582 _DBUS_SET_OOM (error);
598 DBusUserDatabase *db;
609 if (db->users ==
NULL)
615 if (db->groups ==
NULL)
620 if (db->users_by_name ==
NULL)
625 if (db->groups_by_name ==
NULL)
647#ifdef DBUS_ENABLE_EMBEDDED_TESTS
654_dbus_user_database_ref (DBusUserDatabase *db)
674 if (db->refcount == 0)
682 if (db->users_by_name)
685 if (db->groups_by_name)
709 return *info !=
NULL;
728 return *info !=
NULL;
dbus_bool_t _dbus_credentials_add_unix_uid(DBusCredentials *credentials, dbus_uid_t uid)
Add a UNIX user ID to the credentials.
#define DBUS_ERROR_INIT
Expands to a suitable initializer for a DBusError on the stack.
dbus_bool_t dbus_error_has_name(const DBusError *error, const char *name)
Checks whether the error is set and has the given name.
void dbus_set_error(DBusError *error, const char *name, const char *format,...)
Assigns an error name and message to a DBusError.
void dbus_error_free(DBusError *error)
Frees an error that's been set (or just initialized), then reinitializes the error as in dbus_error_i...
dbus_bool_t _dbus_hash_table_remove_uintptr(DBusHashTable *table, uintptr_t key)
Removes the hash entry for the given key.
dbus_bool_t _dbus_hash_table_insert_string(DBusHashTable *table, char *key, void *value)
Creates a hash entry with the given key and value.
void * _dbus_hash_table_lookup_uintptr(DBusHashTable *table, uintptr_t key)
Looks up the value for a given integer in a hash table of type DBUS_HASH_UINTPTR.
void _dbus_hash_table_unref(DBusHashTable *table)
Decrements the reference count for a hash table, freeing the hash table if the count reaches zero.
DBusHashTable * _dbus_hash_table_new(DBusHashType type, DBusFreeFunction key_free_function, DBusFreeFunction value_free_function)
Constructs a new hash table.
void * _dbus_hash_table_lookup_string(DBusHashTable *table, const char *key)
Looks up the value for a given string in a hash table of type DBUS_HASH_STRING.
void _dbus_hash_table_remove_all(DBusHashTable *table)
Removed all entries from a hash table.
dbus_bool_t _dbus_hash_table_insert_uintptr(DBusHashTable *table, uintptr_t key, void *value)
Creates a hash entry with the given key and value.
@ DBUS_HASH_UINTPTR
Hash keys are integer capable to hold a pointer.
@ DBUS_HASH_STRING
Hash keys are strings.
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
dbus_bool_t _dbus_user_database_lock_system(void)
Locks global system user database.
dbus_bool_t _dbus_homedir_from_current_process(const DBusString **homedir)
Gets homedir of user owning current process.
#define _DBUS_UNLOCK(name)
Unlocks a global lock.
DBusUserDatabase * _dbus_user_database_new(void)
Creates a new user database object used to look up and cache user information.
#define _DBUS_LOCK(name)
Locks a global lock, initializing it first if necessary.
void _dbus_user_database_unlock_system(void)
Unlocks global system user database.
void _dbus_user_database_unref(DBusUserDatabase *db)
Decrements refcount of user database.
dbus_bool_t _dbus_credentials_add_from_user(DBusCredentials *credentials, const DBusString *username, DBusCredentialsAddFlags flags, DBusError *error)
Adds the credentials corresponding to the given username.
dbus_bool_t _dbus_user_database_get_uid(DBusUserDatabase *db, dbus_uid_t uid, const DBusUserInfo **info, DBusError *error)
Gets the user information for the given UID, returned user info should not be freed.
void _dbus_user_database_flush_system(void)
Flushes the system global user database;.
void _dbus_group_info_unref(DBusGroupInfo *info)
Decrements the reference count.
const DBusUserInfo * _dbus_user_database_lookup(DBusUserDatabase *db, dbus_uid_t uid, const DBusString *username, DBusError *error)
Looks up a uid or username in the user database.
void _dbus_user_info_unref(DBusUserInfo *info)
Decrements the reference count.
dbus_bool_t _dbus_username_from_current_process(const DBusString **username)
Gets username of user owning current process.
void _dbus_user_info_free(DBusUserInfo *info)
Frees the members of info (but not info itself)
void _dbus_user_database_flush(DBusUserDatabase *db)
Flush all information out of the user database.
dbus_bool_t _dbus_homedir_from_uid(dbus_uid_t uid, DBusString *homedir)
Gets the home directory for the given user.
void _dbus_warn(const char *format,...)
Prints a warning message to stderr.
void _dbus_group_info_free(DBusGroupInfo *info)
Frees the members of info (but not info itself).
dbus_bool_t _dbus_user_database_get_username(DBusUserDatabase *db, const DBusString *username, const DBusUserInfo **info, DBusError *error)
Gets the user information for the given username.
dbus_bool_t _dbus_is_a_number(const DBusString *str, unsigned long *num)
Checks if a given string is actually a number and converts it if it is.
DBusUserDatabase * _dbus_user_database_get_system(void)
Gets the system global user database; must be called with lock held (_dbus_user_database_lock_system(...
#define NULL
A null pointer, defined appropriately for C or C++.
#define TRUE
Expands to "1".
#define FALSE
Expands to "0".
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_register_shutdown_func(DBusShutdownFunction function, void *data)
Register a cleanup function to be called exactly once the next time dbus_shutdown() is called.
void(* DBusFreeFunction)(void *memory)
The type of a function which frees a block of memory.
void dbus_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation.
#define DBUS_ERROR_INVALID_ARGS
Invalid arguments passed to a method call.
dbus_bool_t _dbus_string_append(DBusString *str, const char *buffer)
Appends a nul-terminated C-style string to a DBusString.
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init(), and fills it with the same contents as #_DBUS_STRING_I...
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_string_parse_uint(const DBusString *str, int start, unsigned long *value_return, int *end_return)
Parses an unsigned integer contained in a DBusString.
dbus_bool_t _dbus_user_info_fill(DBusUserInfo *info, const DBusString *username, DBusError *error)
Gets user info for the given username.
dbus_uid_t _dbus_geteuid(void)
Gets our effective UID.
dbus_bool_t _dbus_user_info_fill_uid(DBusUserInfo *info, dbus_uid_t uid, DBusError *error)
Gets user info for the given user ID.
unsigned long dbus_uid_t
A user ID.
#define DBUS_UID_UNSET
an invalid UID used to represent an uninitialized dbus_uid_t field
const char * _dbus_getenv(const char *varname)
Wrapper for getenv().
dbus_uid_t _dbus_getuid(void)
Gets our UID.
#define DBUS_UID_FORMAT
an appropriate printf format for dbus_uid_t
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Object representing an exception.
const char * message
public error message field
Information about a UNIX group.
char * groupname
Group name.
size_t refcount
Reference count.
Information about a UNIX user.
char * homedir
Home directory.
dbus_gid_t * group_ids
Groups IDs, including above primary group.
size_t refcount
Reference count.