26#define DBUS_USERDB_INCLUDES_PRIVATE 1
27#include "dbus-userdb.h"
30#include "dbus-internals.h"
31#include "dbus-protocol.h"
32#include "dbus-credentials.h"
38#if defined(DBUS_WIN) || !defined(DBUS_UNIX)
39#error "This file only makes sense on Unix OSs"
141 end == _dbus_string_get_length (str))
167 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
196 _dbus_verbose (
"No cache for user \"%s\"\n",
197 _dbus_string_get_const_data (username));
211 _DBUS_ASSERT_ERROR_IS_SET (error);
220 _DBUS_ASSERT_ERROR_IS_SET (error);
233 _dbus_user_info_ref (info);
246 _dbus_user_info_ref (info);
265static dbus_bool_t database_locked =
FALSE;
266static DBusUserDatabase *system_db =
NULL;
271shutdown_system_db (
void *data)
273 if (system_db !=
NULL)
285 if (system_db ==
NULL)
291 if (system_db ==
NULL)
310 _dbus_warn (
"Could not get password database information for UID of current process: %s",
357 database_locked =
TRUE;
372 database_locked =
FALSE;
404 if (system_db !=
NULL)
423 if (!init_system_db ())
428 *username = &process_username;
447 if (!init_system_db ())
452 *homedir = &process_homedir;
469 DBusUserDatabase *db;
474 const char *from_environment;
478 if (from_environment !=
NULL)
527 DBusCredentialsAddFlags flags,
530 DBusUserDatabase *db;
539 _DBUS_STATIC_ASSERT (
sizeof (uid) ==
sizeof (
dbus_uid_t));
547 _DBUS_SET_OOM (error);
553 if (!(flags & DBUS_CREDENTIALS_ADD_FLAGS_USER_DATABASE))
556 "Expected a numeric Unix uid");
562 _DBUS_SET_OOM (error);
570 _DBUS_SET_OOM (error);
584 _DBUS_SET_OOM (error);
600 DBusUserDatabase *db;
611 if (db->users ==
NULL)
617 if (db->groups ==
NULL)
622 if (db->users_by_name ==
NULL)
627 if (db->groups_by_name ==
NULL)
649#ifdef DBUS_ENABLE_EMBEDDED_TESTS
656_dbus_user_database_ref (DBusUserDatabase *db)
676 if (db->refcount == 0)
684 if (db->users_by_name)
687 if (db->groups_by_name)
711 return *info !=
NULL;
730 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_IN...
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
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.