diff options
author | Havoc Pennington <hp@redhat.com> | 2007-06-09 21:53:20 +0000 |
---|---|---|
committer | Havoc Pennington <hp@redhat.com> | 2007-06-09 21:53:20 +0000 |
commit | 23832672266bb4ff23b66247c0cfa1a2ed0cc97b (patch) | |
tree | 119e37411f14923780de3ca7a759707508f1ec63 /dbus/dbus-userdb-util.c | |
parent | b80a8fe6b364543aa4b32a02a5ad913faf97173b (diff) |
2007-06-09 Havoc Pennington <hp@redhat.com>
* bus/dispatch.c (check_get_connection_unix_process_id): adapt
since sysdeps-unix.h stuff isn't included anymore
* bus/bus.c (bus_context_new): use more abstract functions to
change user, so they can be no-ops on Windows
* dbus/dbus-credentials.c, dbus/dbus-credentials.h,
dbus/dbus-credentials-util.c: new files containing a fully opaque
DBusCredentials data type to replace the old not opaque one.
* configure.in (DBUS_UNIX): define DBUS_UNIX to match DBUS_WIN on
windows
* dbus/dbus-userdb.h: prohibit on Windows, next step is to clean
up the uses of it in bus/*.c and factor out the parts of
cookie auth that depend on it
Diffstat (limited to 'dbus/dbus-userdb-util.c')
-rw-r--r-- | dbus/dbus-userdb-util.c | 86 |
1 files changed, 37 insertions, 49 deletions
diff --git a/dbus/dbus-userdb-util.c b/dbus/dbus-userdb-util.c index 7b12de50..6e1653e6 100644 --- a/dbus/dbus-userdb-util.c +++ b/dbus/dbus-userdb-util.c @@ -103,20 +103,33 @@ _dbus_is_console_user (dbus_uid_t uid, return result; } +/** + * Gets user ID given username + * + * @param username the username + * @param uid return location for UID + * @returns #TRUE if username existed and we got the UID + */ +dbus_bool_t +_dbus_get_user_id (const DBusString *username, + dbus_uid_t *uid) +{ + return _dbus_get_user_id_and_primary_group (username, uid, NULL); +} /** - * Gets the credentials corresponding to the given UID. + * Gets group ID given groupname * - * @param uid the UID - * @param credentials credentials to fill in - * @returns #TRUE if the UID existed and we got some credentials + * @param groupname the groupname + * @param gid return location for GID + * @returns #TRUE if group name existed and we got the GID */ dbus_bool_t -_dbus_credentials_from_uid (dbus_uid_t uid, - DBusCredentials *credentials) +_dbus_get_group_id (const DBusString *groupname, + dbus_gid_t *gid) { DBusUserDatabase *db; - const DBusUserInfo *info; + const DBusGroupInfo *info; _dbus_user_database_lock_system (); db = _dbus_user_database_get_system (); @@ -126,61 +139,34 @@ _dbus_credentials_from_uid (dbus_uid_t uid, return FALSE; } - if (!_dbus_user_database_get_uid (db, uid, - &info, NULL)) + if (!_dbus_user_database_get_groupname (db, groupname, + &info, NULL)) { _dbus_user_database_unlock_system (); return FALSE; } - _dbus_assert (info->uid == uid); - - credentials->pid = DBUS_PID_UNSET; - credentials->uid = info->uid; - credentials->gid = info->primary_gid; + *gid = info->gid; _dbus_user_database_unlock_system (); return TRUE; } - /** - * Gets user ID given username + * Gets user ID and primary group given username * * @param username the username - * @param uid return location for UID - * @returns #TRUE if username existed and we got the UID + * @param uid_p return location for UID + * @param gid_p return location for GID + * @returns #TRUE if username existed and we got the UID and GID */ dbus_bool_t -_dbus_get_user_id (const DBusString *username, - dbus_uid_t *uid) -{ - DBusCredentials creds; - - if (!_dbus_credentials_from_username (username, &creds)) - return FALSE; - - if (creds.uid == DBUS_UID_UNSET) - return FALSE; - - *uid = creds.uid; - - return TRUE; -} - -/** - * Gets group ID given groupname - * - * @param groupname the groupname - * @param gid return location for GID - * @returns #TRUE if group name existed and we got the GID - */ -dbus_bool_t -_dbus_get_group_id (const DBusString *groupname, - dbus_gid_t *gid) +_dbus_get_user_id_and_primary_group (const DBusString *username, + dbus_uid_t *uid_p, + dbus_gid_t *gid_p) { DBusUserDatabase *db; - const DBusGroupInfo *info; + const DBusUserInfo *info; _dbus_user_database_lock_system (); db = _dbus_user_database_get_system (); @@ -190,14 +176,17 @@ _dbus_get_group_id (const DBusString *groupname, return FALSE; } - if (!_dbus_user_database_get_groupname (db, groupname, - &info, NULL)) + if (!_dbus_user_database_get_username (db, username, + &info, NULL)) { _dbus_user_database_unlock_system (); return FALSE; } - *gid = info->gid; + if (uid_p) + *uid_p = info->uid; + if (gid_p) + *gid_p = info->primary_gid; _dbus_user_database_unlock_system (); return TRUE; @@ -434,7 +423,6 @@ _dbus_userdb_test (const char *test_data_dir) if (!_dbus_get_user_id (username, &uid)) _dbus_assert_not_reached ("didn't get uid"); - if (!_dbus_groups_from_uid (uid, &group_ids, &n_group_ids)) _dbus_assert_not_reached ("didn't get groups"); |