24 #define DBUS_USERDB_INCLUDES_PRIVATE 1
25 #include "dbus-userdb.h"
26 #include "dbus-hash.h"
27 #include "dbus-test.h"
28 #include "dbus-internals.h"
29 #include "dbus-protocol.h"
30 #include "dbus-credentials.h"
135 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
147 #ifdef DBUS_ENABLE_USERDB_CACHE
168 _dbus_verbose (
"No cache for user \"%s\"\n",
182 _DBUS_ASSERT_ERROR_IS_SET (error);
191 _DBUS_ASSERT_ERROR_IS_SET (error);
223 static DBusUserDatabase *system_db =
NULL;
228 shutdown_system_db (
void *data)
230 if (system_db !=
NULL)
238 init_system_db (
void)
242 if (system_db ==
NULL)
248 if (system_db ==
NULL)
267 _dbus_warn (
"Could not get password database information for UID of current process: %s\n",
313 database_locked =
TRUE;
322 database_locked =
FALSE;
350 if (system_db !=
NULL)
367 if (!init_system_db ())
372 *username = &process_username;
389 if (!init_system_db ())
394 *homedir = &process_homedir;
411 DBusUserDatabase *db;
450 DBusUserDatabase *db;
496 DBusUserDatabase *db;
533 DBusUserDatabase *db;
544 if (db->users ==
NULL)
550 if (db->groups ==
NULL)
555 if (db->users_by_name ==
NULL)
560 if (db->groups_by_name ==
NULL)
582 #ifdef DBUS_BUILD_TESTS
589 _dbus_user_database_ref (DBusUserDatabase *db)
609 if (db->refcount == 0)
617 if (db->users_by_name)
620 if (db->groups_by_name)
644 return *info !=
NULL;
663 return *info !=
NULL;
dbus_bool_t dbus_error_has_name(const DBusError *error, const char *name)
Checks whether the error is set and has the given name.
dbus_bool_t _dbus_string_append(DBusString *str, const char *buffer)
Appends a nul-terminated C-style string to a DBusString.
const char * message
public error message field
#define NULL
A null pointer, defined appropriately for C or C++.
void(* DBusFreeFunction)(void *memory)
The type of a function which frees a block of memory.
void _dbus_user_database_lock_system(void)
Locks global system user database.
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_free(void *memory)
Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
#define DBUS_ERROR_INIT
Expands to a suitable initializer for a DBusError on the stack.
void _dbus_user_database_flush_system(void)
Flushes the system global user database;.
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_homedir_from_username(const DBusString *username, DBusString *homedir)
Gets the home directory for the given user.
void _dbus_user_database_flush(DBusUserDatabase *db)
Flush all information out of the user database.
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_unlock_system(void)
Unlocks global system user database.
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
void _dbus_hash_table_unref(DBusHashTable *table)
Decrements the reference count for a hash table, freeing the hash table if the count reaches zero...
Hash keys are integer capable to hold a pointer.
void _dbus_hash_table_remove_all(DBusHashTable *table)
Removed all entries from a hash table.
char * groupname
Group name.
#define DBUS_UID_UNSET
an invalid UID used to represent an uninitialized dbus_uid_t field
void _dbus_user_info_free_allocated(DBusUserInfo *info)
Frees the given DBusUserInfo's members with _dbus_user_info_free() and also calls dbus_free() on the ...
dbus_bool_t _dbus_user_info_fill(DBusUserInfo *info, const DBusString *username, DBusError *error)
Gets user info for the given username.
DBusUserDatabase * _dbus_user_database_get_system(void)
Gets the system global user database; must be called with lock held (_dbus_user_database_lock_system(...
dbus_bool_t _dbus_homedir_from_uid(dbus_uid_t uid, DBusString *homedir)
Gets the home directory for the given user.
dbus_gid_t * group_ids
Groups IDs, including above primary group.
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.
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
void _dbus_group_info_free_allocated(DBusGroupInfo *info)
Frees the given DBusGroupInfo's members with _dbus_group_info_free() and also calls dbus_free() on th...
DBusHashTable * _dbus_hash_table_new(DBusHashType type, DBusFreeFunction key_free_function, DBusFreeFunction value_free_function)
Constructs a new hash table.
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
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).
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_user_info_free(DBusUserInfo *info)
Frees the members of info (but not info itself)
int _dbus_string_get_length(const DBusString *str)
Gets the length of a string (not including nul termination).
Object representing an exception.
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_set_error(DBusError *error, const char *name, const char *format,...)
Assigns an error name and message to a DBusError.
DBusUserDatabase * _dbus_user_database_new(void)
Creates a new user database object used to look up and cache user information.
#define _DBUS_UNLOCK(name)
Unlocks a global lock.
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init().
#define TRUE
Expands to "1".
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.
#define DBUS_UID_FORMAT
an appropriate printf format for dbus_uid_t
char * homedir
Home directory.
dbus_uid_t _dbus_getuid(void)
Gets our UID.
dbus_bool_t _dbus_homedir_from_current_process(const DBusString **homedir)
Gets homedir of user owning current process.
Information about a UNIX group.
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_uid(DBusUserInfo *info, dbus_uid_t uid, DBusError *error)
Gets user info for the given user ID.
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation.
#define FALSE
Expands to "0".
DBusCredentials * credentials
Credentials of other end read from the socket.
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_register_shutdown_func(DBusShutdownFunction function, void *data)
Register a cleanup function to be called exactly once the next time dbus_shutdown() is called...
#define _DBUS_LOCK(name)
Locks a global lock.
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_credentials_add_unix_uid(DBusCredentials *credentials, dbus_uid_t uid)
Add a UNIX user ID to the credentials.
void _dbus_user_database_unref(DBusUserDatabase *db)
Decrements refcount of user database.
unsigned long dbus_uid_t
A user ID.
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.
const char * _dbus_string_get_const_data(const DBusString *str)
Gets the raw character buffer from a const string.
dbus_bool_t _dbus_username_from_current_process(const DBusString **username)
Gets username of user owning current process.
Information about a UNIX user.
dbus_bool_t _dbus_credentials_add_from_user(DBusCredentials *credentials, const DBusString *username)
Adds the credentials corresponding to the given username.