24 #define DBUS_USERDB_INCLUDES_PRIVATE 1
25 #include "dbus-userdb.h"
26 #include "dbus-test.h"
27 #include "dbus-internals.h"
28 #include "dbus-protocol.h"
32 #include <systemd/sd-daemon.h>
33 #include <systemd/sd-login.h>
64 r = sd_uid_get_seats (uid, 0,
NULL);
78 #ifdef HAVE_CONSOLE_OWNER_FILE
85 _DBUS_SET_OOM (error);
92 _DBUS_SET_OOM (error);
158 DBusUserDatabase *db;
195 DBusUserDatabase *db;
242 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
253 #ifdef DBUS_ENABLE_USERDB_CACHE
274 _dbus_verbose (
"No cache for groupname \"%s\"\n",
288 _DBUS_ASSERT_ERROR_IS_SET (error);
297 _DBUS_ASSERT_ERROR_IS_SET (error);
346 return *info !=
NULL;
366 return *info !=
NULL;
385 DBusUserDatabase *db;
411 if (*group_ids ==
NULL)
427 #ifdef DBUS_BUILD_TESTS
436 _dbus_userdb_test (
const char *test_data_dir)
441 unsigned long *group_ids;
457 printf (
" Current user: %s homedir: %s gids:",
461 for (i=0; i<n_group_ids; i++)
462 printf(
" %ld", group_ids[i]);
467 printf (
"Is Console user: %i\n",
469 printf (
"Invocation was OK: %s\n", error.
message ? error.
message :
"yes");
471 printf (
"Is Console user 4711: %i\n",
473 printf (
"Invocation was OK: %s\n", error.
message ? error.
message :
"yes");
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 _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().
Portable struct with stat() results.
#define dbus_new(type, count)
Safe macro for using dbus_malloc().
#define DBUS_GID_FORMAT
an appropriate printf format for dbus_gid_t
dbus_bool_t _dbus_groups_from_uid(dbus_uid_t uid, dbus_gid_t **group_ids, int *n_group_ids)
Gets all groups corresponding to the given UID.
dbus_bool_t _dbus_is_console_user(dbus_uid_t uid, DBusError *error)
Checks to see if the UID sent in is the console user.
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
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_gid_t primary_gid
GID.
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.
char * groupname
Group name.
#define DBUS_UID_UNSET
an invalid UID used to represent an uninitialized dbus_uid_t field
dbus_bool_t _dbus_user_database_get_groupname(DBusUserDatabase *db, const DBusString *groupname, const DBusGroupInfo **info, DBusError *error)
Gets the user information for the given group name, returned group info should not be freed...
const char * _dbus_error_from_errno(int error_number)
Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.
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_get_user_id_and_primary_group(const DBusString *username, dbus_uid_t *uid_p, dbus_gid_t *gid_p)
Gets user ID and primary group given username.
dbus_gid_t * group_ids
Groups IDs, including above primary group.
dbus_bool_t _dbus_user_database_get_gid(DBusUserDatabase *db, dbus_gid_t gid, const DBusGroupInfo **info, DBusError *error)
Gets the user information for the given GID, returned group info should not be freed.
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...
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
int n_group_ids
Size of group IDs array.
dbus_bool_t _dbus_group_info_fill_gid(DBusGroupInfo *info, dbus_gid_t gid, DBusError *error)
Initializes the given DBusGroupInfo struct with information about the given group ID...
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. ...
DBusGroupInfo * _dbus_user_database_lookup_group(DBusUserDatabase *db, dbus_gid_t gid, const DBusString *groupname, DBusError *error)
Looks up a gid or group name in the user database.
dbus_bool_t _dbus_get_group_id(const DBusString *groupname, dbus_gid_t *gid)
Gets group ID given groupname.
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.
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init().
#define DBUS_GID_UNSET
an invalid GID used to represent an uninitialized dbus_gid_t field
#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_assert_not_reached(explanation)
Aborts with an error message if called.
dbus_bool_t _dbus_group_info_fill(DBusGroupInfo *info, const DBusString *groupname, DBusError *error)
Initializes the given DBusGroupInfo struct with information about the given group name...
dbus_uid_t uid
User owning file.
#define DBUS_ERROR_FAILED
A generic error; "something went wrong" - see the error message for more.
#define DBUS_UID_FORMAT
an appropriate printf format for dbus_uid_t
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_stat(const DBusString *filename, DBusStat *statbuf, DBusError *error)
stat() wrapper.
dbus_bool_t _dbus_get_user_id(const DBusString *username, dbus_uid_t *uid)
Gets user ID given username.
void dbus_error_init(DBusError *error)
Initializes a DBusError structure.
dbus_bool_t _dbus_user_at_console(const char *username, DBusError *error)
Checks if user is at the console.
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation.
#define FALSE
Expands to "0".
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_user_database_get_username(DBusUserDatabase *db, const DBusString *username, const DBusUserInfo **info, DBusError *error)
Gets the user information for the given username.
unsigned long dbus_gid_t
A group ID.
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.