From 0b3f90d60e6ade342c4733556ecbfcf8f7d8497f Mon Sep 17 00:00:00 2001 From: Chengwei Yang Date: Tue, 16 Jul 2013 12:56:12 +0800 Subject: [PATCH v2] Do not update user db cache if build with "--disable-userdb-cache" Bug: https://bugs.freedesktop.org/show_bug.cgi?id=17133 Signed-off-by: Chengwei Yang --- dbus/dbus-userdb-util.c | 91 +++++++++++++++++++++------------------------- dbus/dbus-userdb.c | 93 ++++++++++++++++++++++------------------------- 2 files changed, 85 insertions(+), 99 deletions(-) diff --git a/dbus/dbus-userdb-util.c b/dbus/dbus-userdb-util.c index 62495d8..d461322 100644 --- a/dbus/dbus-userdb-util.c +++ b/dbus/dbus-userdb-util.c @@ -273,67 +273,60 @@ _dbus_user_database_lookup_group (DBusUserDatabase *db, info->gid); return info; } + if (gid != DBUS_GID_UNSET) + _dbus_verbose ("No cache for GID "DBUS_GID_FORMAT"\n", + gid); else -#else - if (1) -#endif + _dbus_verbose ("No cache for groupname \"%s\"\n", + _dbus_string_get_const_data (groupname)); +#endif /* DBUS_ENABLE_USERDB_CACHE */ + + info = dbus_new0 (DBusGroupInfo, 1); + if (info == NULL) { - if (gid != DBUS_GID_UNSET) - _dbus_verbose ("No cache for GID "DBUS_GID_FORMAT"\n", - gid); - else - _dbus_verbose ("No cache for groupname \"%s\"\n", - _dbus_string_get_const_data (groupname)); - - info = dbus_new0 (DBusGroupInfo, 1); - if (info == NULL) - { - dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); - return NULL; - } + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + return NULL; + } - if (gid != DBUS_GID_UNSET) - { - if (!_dbus_group_info_fill_gid (info, gid, error)) - { - _DBUS_ASSERT_ERROR_IS_SET (error); - _dbus_group_info_free_allocated (info); - return NULL; - } - } - else + if (gid != DBUS_GID_UNSET) + { + if (!_dbus_group_info_fill_gid (info, gid, error)) { - if (!_dbus_group_info_fill (info, groupname, error)) - { - _DBUS_ASSERT_ERROR_IS_SET (error); - _dbus_group_info_free_allocated (info); - return NULL; - } + _DBUS_ASSERT_ERROR_IS_SET (error); + _dbus_group_info_free_allocated (info); + return NULL; } - - /* don't use these past here */ - gid = DBUS_GID_UNSET; - groupname = NULL; - - if (!_dbus_hash_table_insert_uintptr (db->groups, info->gid, info)) + } + else + { + if (!_dbus_group_info_fill (info, groupname, error)) { - dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + _DBUS_ASSERT_ERROR_IS_SET (error); _dbus_group_info_free_allocated (info); return NULL; } + } +#ifdef DBUS_ENABLE_USERDB_CACHE + if (!_dbus_hash_table_insert_uintptr (db->groups, info->gid, info)) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + _dbus_group_info_free_allocated (info); + return NULL; + } - if (!_dbus_hash_table_insert_string (db->groups_by_name, - info->groupname, - info)) - { - _dbus_hash_table_remove_uintptr (db->groups, info->gid); - dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); - return NULL; - } - - return info; + + if (!_dbus_hash_table_insert_string (db->groups_by_name, + info->groupname, + info)) + { + _dbus_hash_table_remove_uintptr (db->groups, info->gid); + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + return NULL; } +#endif /* DBUS_ENABLE_USERDB_CACHE */ + + return info; } diff --git a/dbus/dbus-userdb.c b/dbus/dbus-userdb.c index b792cbe..491aacd 100644 --- a/dbus/dbus-userdb.c +++ b/dbus/dbus-userdb.c @@ -156,67 +156,60 @@ _dbus_user_database_lookup (DBusUserDatabase *db, info->uid); return info; } + if (uid != DBUS_UID_UNSET) + _dbus_verbose ("No cache for UID "DBUS_UID_FORMAT"\n", + uid); else -#else - if (1) -#endif - { - if (uid != DBUS_UID_UNSET) - _dbus_verbose ("No cache for UID "DBUS_UID_FORMAT"\n", - uid); - else - _dbus_verbose ("No cache for user \"%s\"\n", - _dbus_string_get_const_data (username)); - - info = dbus_new0 (DBusUserInfo, 1); - if (info == NULL) - { - dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); - return NULL; - } + _dbus_verbose ("No cache for user \"%s\"\n", + _dbus_string_get_const_data (username)); +#endif /* DBUS_ENABLE_USERDB_CACHE */ - if (uid != DBUS_UID_UNSET) - { - if (!_dbus_user_info_fill_uid (info, uid, error)) - { - _DBUS_ASSERT_ERROR_IS_SET (error); - _dbus_user_info_free_allocated (info); - return NULL; - } - } - else - { - if (!_dbus_user_info_fill (info, username, error)) - { - _DBUS_ASSERT_ERROR_IS_SET (error); - _dbus_user_info_free_allocated (info); - return NULL; - } - } - - /* be sure we don't use these after here */ - uid = DBUS_UID_UNSET; - username = NULL; + info = dbus_new0 (DBusUserInfo, 1); + if (info == NULL) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + return NULL; + } - /* insert into hash */ - if (!_dbus_hash_table_insert_uintptr (db->users, info->uid, info)) + if (uid != DBUS_UID_UNSET) + { + if (!_dbus_user_info_fill_uid (info, uid, error)) { - dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + _DBUS_ASSERT_ERROR_IS_SET (error); _dbus_user_info_free_allocated (info); return NULL; } - - if (!_dbus_hash_table_insert_string (db->users_by_name, - info->username, - info)) + } + else + { + if (!_dbus_user_info_fill (info, username, error)) { - _dbus_hash_table_remove_uintptr (db->users, info->uid); - dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + _DBUS_ASSERT_ERROR_IS_SET (error); + _dbus_user_info_free_allocated (info); return NULL; } - - return info; } + +#ifdef DBUS_ENABLE_USERDB_CACHE + /* insert into hash */ + if (!_dbus_hash_table_insert_uintptr (db->users, info->uid, info)) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + _dbus_user_info_free_allocated (info); + return NULL; + } + + if (!_dbus_hash_table_insert_string (db->users_by_name, + info->username, + info)) + { + _dbus_hash_table_remove_uintptr (db->users, info->uid); + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + return NULL; + } +#endif /* DBUS_ENABLE_USERDB_CACHE */ + + return info; } static dbus_bool_t database_locked = FALSE; -- 1.7.9.5