dbus/dbus dbus-userdb-util.c, 1.7, 1.8 dbus-userdb.c, 1.20,
1.21 dbus-userdb.h, 1.11, 1.12
Tim Dijkstra
tdykstra at kemper.freedesktop.org
Tue Dec 12 13:24:09 PST 2006
- Previous message: dbus/bus bus.c, 1.72, 1.73 bus.h, 1.27, 1.28 connection.c, 1.65,
1.66 policy.c, 1.23, 1.24 policy.h, 1.16, 1.17
- Next message: dbus ChangeLog,1.1210,1.1211 configure.in,1.199,1.200
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvs/dbus/dbus/dbus
In directory kemper:/tmp/cvs-serv8740/dbus
Modified Files:
dbus-userdb-util.c dbus-userdb.c dbus-userdb.h
Log Message:
commit.msg
Index: dbus-userdb-util.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-userdb-util.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- dbus-userdb-util.c 7 Jun 2006 19:59:11 -0000 1.7
+++ dbus-userdb-util.c 12 Dec 2006 21:24:07 -0000 1.8
@@ -86,6 +86,8 @@
return FALSE;
}
+ /* TPTD: this should be cache-safe, we've locked the DB and
+ _dbus_user_at_console doesn't pass it on. */
info = _dbus_user_database_lookup (db, uid, NULL, error);
if (info == NULL)
@@ -347,45 +349,49 @@
/**
- * Gets all groups for a particular user. Returns #FALSE
+ * Gets all groups corresponding to the given UID. Returns #FALSE
* if no memory, or user isn't known, but always initializes
- * group_ids to a NULL array. Sets error to the reason
- * for returning #FALSE.
+ * group_ids to a NULL array.
*
- * @param db the user database object
- * @param uid the user ID
+ * @param uid the UID
* @param group_ids return location for array of group IDs
* @param n_group_ids return location for length of returned array
- * @param error return location for error
- * @returns #TRUE on success
+ * @returns #TRUE if the UID existed and we got some credentials
*/
dbus_bool_t
-_dbus_user_database_get_groups (DBusUserDatabase *db,
- dbus_uid_t uid,
- dbus_gid_t **group_ids,
- int *n_group_ids,
- DBusError *error)
+_dbus_groups_from_uid (dbus_uid_t uid,
+ dbus_gid_t **group_ids,
+ int *n_group_ids)
{
- DBusUserInfo *info;
-
- _DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
+ DBusUserDatabase *db;
+ const DBusUserInfo *info;
*group_ids = NULL;
*n_group_ids = 0;
-
- info = _dbus_user_database_lookup (db, uid, NULL, error);
- if (info == NULL)
+
+ _dbus_user_database_lock_system ();
+
+ db = _dbus_user_database_get_system ();
+ if (db == NULL)
{
- _DBUS_ASSERT_ERROR_IS_SET (error);
+ _dbus_user_database_unlock_system ();
return FALSE;
}
+ if (!_dbus_user_database_get_uid (db, uid,
+ &info, NULL))
+ {
+ _dbus_user_database_unlock_system ();
+ return FALSE;
+ }
+
+ _dbus_assert (info->uid == uid);
+
if (info->n_group_ids > 0)
{
*group_ids = dbus_new (dbus_gid_t, info->n_group_ids);
if (*group_ids == NULL)
{
- dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ _dbus_user_database_unlock_system ();
return FALSE;
}
@@ -394,9 +400,9 @@
memcpy (*group_ids, info->group_ids, info->n_group_ids * sizeof (dbus_gid_t));
}
+ _dbus_user_database_unlock_system ();
return TRUE;
}
-
/** @} */
#ifdef DBUS_BUILD_TESTS
@@ -412,6 +418,9 @@
{
const DBusString *username;
const DBusString *homedir;
+ dbus_uid_t uid;
+ unsigned long *group_ids;
+ int n_group_ids, i;
if (!_dbus_username_from_current_process (&username))
_dbus_assert_not_reached ("didn't get username");
@@ -419,10 +428,24 @@
if (!_dbus_homedir_from_current_process (&homedir))
_dbus_assert_not_reached ("didn't get homedir");
- printf (" Current user: %s homedir: %s\n",
+ 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");
+
+ printf (" Current user: %s homedir: %s gids:",
_dbus_string_get_const_data (username),
_dbus_string_get_const_data (homedir));
-
+
+ for (i=0; i<n_group_ids; i++)
+ printf(" %ld", group_ids[i]);
+
+ printf ("\n");
+
+ dbus_free (group_ids);
+
return TRUE;
}
#endif /* DBUS_BUILD_TESTS */
Index: dbus-userdb.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-userdb.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- dbus-userdb.c 10 Sep 2006 21:37:10 -0000 1.20
+++ dbus-userdb.c 12 Dec 2006 21:24:07 -0000 1.21
@@ -79,7 +79,7 @@
{
int end;
- if (_dbus_string_parse_int (str, 0, num, &end) &&
+ if (_dbus_string_parse_uint (str, 0, num, &end) &&
end == _dbus_string_get_length (str))
return TRUE;
else
@@ -312,6 +312,19 @@
}
/**
+ * Flushes the system global user database;
+ */
+void
+_dbus_user_database_flush_system (void)
+{
+ _dbus_user_database_lock_system ();
+
+ _dbus_user_database_flush (system_db);
+
+ _dbus_user_database_unlock_system ();
+}
+
+/**
* Gets username of user owning current process. The returned string
* is valid until dbus_shutdown() is called.
*
Index: dbus-userdb.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-userdb.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- dbus-userdb.h 6 Mar 2006 19:06:45 -0000 1.11
+++ dbus-userdb.h 12 Dec 2006 21:24:07 -0000 1.12
@@ -47,17 +47,11 @@
};
-#endif /* DBUS_USERDB_INCLUDES_PRIVATE */
DBusUserDatabase* _dbus_user_database_new (void);
DBusUserDatabase* _dbus_user_database_ref (DBusUserDatabase *db);
void _dbus_user_database_flush (DBusUserDatabase *db);
void _dbus_user_database_unref (DBusUserDatabase *db);
-dbus_bool_t _dbus_user_database_get_groups (DBusUserDatabase *db,
- dbus_uid_t uid,
- dbus_gid_t **group_ids,
- int *n_group_ids,
- DBusError *error);
dbus_bool_t _dbus_user_database_get_uid (DBusUserDatabase *db,
dbus_uid_t uid,
const DBusUserInfo **info,
@@ -75,7 +69,6 @@
const DBusGroupInfo **info,
DBusError *error);
-#ifdef DBUS_USERDB_INCLUDES_PRIVATE
DBusUserInfo* _dbus_user_database_lookup (DBusUserDatabase *db,
dbus_uid_t uid,
const DBusString *username,
@@ -91,6 +84,7 @@
DBusUserDatabase* _dbus_user_database_get_system (void);
void _dbus_user_database_lock_system (void);
void _dbus_user_database_unlock_system (void);
+void _dbus_user_database_flush_system (void);
dbus_bool_t _dbus_username_from_current_process (const DBusString **username);
dbus_bool_t _dbus_homedir_from_current_process (const DBusString **homedir);
@@ -104,6 +98,9 @@
DBusCredentials *credentials);
dbus_bool_t _dbus_credentials_from_uid (dbus_uid_t user_id,
DBusCredentials *credentials);
+dbus_bool_t _dbus_groups_from_uid (dbus_uid_t uid,
+ dbus_gid_t **group_ids,
+ int *n_group_ids);
dbus_bool_t _dbus_is_console_user (dbus_uid_t uid,
DBusError *error);
- Previous message: dbus/bus bus.c, 1.72, 1.73 bus.h, 1.27, 1.28 connection.c, 1.65,
1.66 policy.c, 1.23, 1.24 policy.h, 1.16, 1.17
- Next message: dbus ChangeLog,1.1210,1.1211 configure.in,1.199,1.200
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the dbus-commit
mailing list