Commit 6ee66ff7 authored by Simon McVittie's avatar Simon McVittie
Browse files

userdb: Make lookups return a const pointer



This makes it more obvious that the returned pointer points to a
struct owned by the userdb, which must not be freed or have its
contents modified, and is only valid to dereference until the next
modification to the userdb's underlying hash tables (which in practice
means until the lock is released, because after that we have no
guarantees about what might be going on in another thread).
Signed-off-by: Simon McVittie's avatarSimon McVittie <smcv@collabora.com>
parent ce9682ec
......@@ -249,9 +249,9 @@ _dbus_get_user_id_and_primary_group (const DBusString *username,
* @param gid the group ID or #DBUS_GID_UNSET
* @param groupname group name or #NULL
* @param error error to fill in
* @returns the entry in the database
* @returns the entry in the database (borrowed, do not free)
*/
DBusGroupInfo*
const DBusGroupInfo *
_dbus_user_database_lookup_group (DBusUserDatabase *db,
dbus_gid_t gid,
const DBusString *groupname,
......@@ -337,6 +337,8 @@ _dbus_user_database_lookup_group (DBusUserDatabase *db,
return NULL;
}
/* Return a borrowed reference to the DBusGroupInfo owned by the
* two hash tables */
return info;
}
}
......
......@@ -129,9 +129,9 @@ _dbus_is_a_number (const DBusString *str,
* @param uid the user ID or #DBUS_UID_UNSET
* @param username username or #NULL
* @param error error to fill in
* @returns the entry in the database
* @returns the entry in the database (borrowed, do not free)
*/
DBusUserInfo*
const DBusUserInfo *
_dbus_user_database_lookup (DBusUserDatabase *db,
dbus_uid_t uid,
const DBusString *username,
......@@ -218,6 +218,8 @@ _dbus_user_database_lookup (DBusUserDatabase *db,
return NULL;
}
/* Return a borrowed pointer to the DBusUserInfo owned by the
* hash tables */
return info;
}
}
......
......@@ -67,15 +67,15 @@ dbus_bool_t _dbus_user_database_get_username (DBusUserDatabase *db,
const DBusUserInfo **info,
DBusError *error);
DBUS_PRIVATE_EXPORT
DBusUserInfo* _dbus_user_database_lookup (DBusUserDatabase *db,
const DBusUserInfo *_dbus_user_database_lookup (DBusUserDatabase *db,
dbus_uid_t uid,
const DBusString *username,
DBusError *error);
DBUS_PRIVATE_EXPORT
DBusGroupInfo* _dbus_user_database_lookup_group (DBusUserDatabase *db,
dbus_gid_t gid,
const DBusString *groupname,
DBusError *error);
const DBusGroupInfo* _dbus_user_database_lookup_group (DBusUserDatabase *db,
dbus_gid_t gid,
const DBusString *groupname,
DBusError *error);
DBUS_PRIVATE_EXPORT
void _dbus_user_info_free_allocated (DBusUserInfo *info);
DBUS_PRIVATE_EXPORT
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment