summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-userdb-util.c
diff options
context:
space:
mode:
Diffstat (limited to 'dbus/dbus-userdb-util.c')
-rw-r--r--dbus/dbus-userdb-util.c86
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");