summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-userdb.c
diff options
context:
space:
mode:
authorJohn (J5) Palmieri <johnp@redhat.com>2005-03-22 17:57:27 +0000
committerJohn (J5) Palmieri <johnp@redhat.com>2005-03-22 17:57:27 +0000
commit6eab51411982fc61c193caed388608c4f2bd25d1 (patch)
treec11efd68e12c643113d11ed0d0d605a1e01e3be8 /dbus/dbus-userdb.c
parent11519c46c42e1dc65614ad9ba214604561b9788e (diff)
* tools/Makefile.am: Patch by Colin Walters that fixes distcheck
* dbus/dbus-userdb.c, dbus/dbus-userdb-util.c: Add patch we have had in Red Hat packages for a while but for some reason never got merged upstream (_dbus_is_a_number): New checks if a string can be converted to a number and does the conversion if it can (_dbus_user_database_lookup): Add check to see if the given username is a udi. This allows udi's to be used instead of usernames in the config file. (_dbus_user_database_lookup_group): Add check to see if the given groupname is a gdi. This allows gdi's to be used instead of groupnames in the config file.
Diffstat (limited to 'dbus/dbus-userdb.c')
-rw-r--r--dbus/dbus-userdb.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/dbus/dbus-userdb.c b/dbus/dbus-userdb.c
index f1317aa9..83a5769f 100644
--- a/dbus/dbus-userdb.c
+++ b/dbus/dbus-userdb.c
@@ -66,6 +66,27 @@ _dbus_group_info_free_allocated (DBusGroupInfo *info)
}
/**
+ * Checks if a given string is actually a number
+ * and converts it if it is
+ *
+ * @param str the string to check
+ * @param num the memory location of the unsigned long to fill in
+ * @returns TRUE if str is a number and num is filled in
+ */
+dbus_bool_t
+_dbus_is_a_number (const DBusString *str,
+ unsigned long *num)
+{
+ int end;
+
+ if (_dbus_string_parse_int (str, 0, num, &end) &&
+ end == _dbus_string_get_length (str))
+ return TRUE;
+ else
+ return FALSE;
+}
+
+/**
* Looks up a uid or username in the user database. Only one of name
* or UID can be provided. There are wrapper functions for this that
* are better to use, this one does no locking or anything on the
@@ -87,7 +108,16 @@ _dbus_user_database_lookup (DBusUserDatabase *db,
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
_dbus_assert (uid != DBUS_UID_UNSET || username != NULL);
-
+
+ /* See if the username is really a number */
+ if (uid == DBUS_UID_UNSET)
+ {
+ unsigned long n;
+
+ if (_dbus_is_a_number (username, &n))
+ uid = n;
+ }
+
if (uid != DBUS_UID_UNSET)
info = _dbus_hash_table_lookup_ulong (db->users, uid);
else