From c30f5781e20342ca9f7bf3a31394a5ae17e78afa Mon Sep 17 00:00:00 2001 From: Chengwei Yang Date: Tue, 16 Jul 2013 10:21:59 +0800 Subject: [PATCH] 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 | 113 ++++++++++++++++++++++------------------------ dbus/dbus-userdb.c | 115 ++++++++++++++++++++++------------------------- 2 files changed, 107 insertions(+), 121 deletions(-) diff --git a/dbus/dbus-userdb-util.c b/dbus/dbus-userdb-util.c index 62495d8..f0ef400 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; } - else -#else - if (1) -#endif - { - 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; - } - - 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 (!_dbus_group_info_fill (info, groupname, error)) - { - _DBUS_ASSERT_ERROR_IS_SET (error); - _dbus_group_info_free_allocated (info); - return 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)); +#endif /* DBUS_ENABLE_USERDB_CACHE */ + + info = dbus_new0 (DBusGroupInfo, 1); + if (info == 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 (!_dbus_group_info_fill (info, groupname, error)) + { + _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)) - { - 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; - } +#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; + } +#endif /* DBUS_ENABLE_USERDB_CACHE */ + + return info; } diff --git a/dbus/dbus-userdb.c b/dbus/dbus-userdb.c index b792cbe..1fb043c 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; } - 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; - } - - 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; - - /* 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; - } - - return info; - } + 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)); +#endif /* DBUS_ENABLE_USERDB_CACHE */ + + info = dbus_new0 (DBusUserInfo, 1); + if (info == NULL) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + return NULL; + } + + 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; + } + } + +#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