[Patch] Flush the userdb cache on config reload
Sjoerd Simons
sjoerd at luon.net
Sun Mar 5 12:16:26 PST 2006
Hi,
Attached patch flushed the userdb cache when a config reload is requested.
This resolves the issue of having to restart dbus fully when a user is added
or removed from various groups.
As dbus ``caches'' the policy per connection it's still necessary to restart
the users applications before the new permissions take effect. But i doubt
that's a big problem as it's quite normal for unix users that they need to
restart their session before new permissions come into effect.
Please review.
Sjoerd
--
The root of all superstition is that men observe when a thing hits,
but not when it misses.
-- Francis Bacon
-------------- next part --------------
Index: bus/bus.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/bus.c,v
retrieving revision 1.65
diff -u -r1.65 bus.c
--- bus/bus.c 14 Nov 2005 20:51:25 -0000 1.65
+++ bus/bus.c 5 Mar 2006 17:08:15 -0000
@@ -790,6 +790,9 @@
DBusString config_file;
dbus_bool_t ret;
+ /* Flush the user database cache */
+ _dbus_user_database_flush(context->user_database);
+
ret = FALSE;
_dbus_string_init_const (&config_file, context->config_file);
parser = bus_config_load (&config_file, TRUE, NULL, error);
Index: dbus/dbus-hash.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-hash.c,v
retrieving revision 1.19
diff -u -r1.19 dbus-hash.c
--- dbus/dbus-hash.c 17 Jan 2005 03:53:40 -0000 1.19
+++ dbus/dbus-hash.c 5 Mar 2006 17:08:15 -0000
@@ -422,6 +422,22 @@
}
}
+/**
+ * Removes all entries from a hash table.
+ *
+ * @param table the hash table to remove all entries from.
+ */
+void
+_dbus_hash_table_remove_all (DBusHashTable *table)
+{
+ DBusHashIter iter;
+ _dbus_hash_iter_init (table, &iter);
+ while (_dbus_hash_iter_next (&iter))
+ {
+ _dbus_hash_iter_remove_entry(&iter);
+ }
+}
+
static DBusHashEntry*
alloc_entry (DBusHashTable *table)
{
Index: dbus/dbus-hash.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-hash.h,v
retrieving revision 1.14
diff -u -r1.14 dbus-hash.h
--- dbus/dbus-hash.h 9 Sep 2004 10:20:17 -0000 1.14
+++ dbus/dbus-hash.h 5 Mar 2006 17:08:15 -0000
@@ -63,6 +63,7 @@
DBusFreeFunction value_free_function);
DBusHashTable* _dbus_hash_table_ref (DBusHashTable *table);
void _dbus_hash_table_unref (DBusHashTable *table);
+void _dbus_hash_table_remove_all (DBusHashTable *table);
void _dbus_hash_iter_init (DBusHashTable *table,
DBusHashIter *iter);
dbus_bool_t _dbus_hash_iter_next (DBusHashIter *iter);
Index: dbus/dbus-userdb.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-userdb.c,v
retrieving revision 1.18
diff -u -r1.18 dbus-userdb.c
--- dbus/dbus-userdb.c 24 Feb 2006 16:13:08 -0000 1.18
+++ dbus/dbus-userdb.c 5 Mar 2006 17:08:15 -0000
@@ -476,6 +476,18 @@
return NULL;
}
+/**
+ * Flush all information out of the user database.
+ */
+void
+_dbus_user_database_flush (DBusUserDatabase *db)
+{
+ _dbus_hash_table_remove_all(db->users_by_name);
+ _dbus_hash_table_remove_all(db->groups_by_name);
+ _dbus_hash_table_remove_all(db->users);
+ _dbus_hash_table_remove_all(db->groups);
+}
+
#ifdef DBUS_BUILD_TESTS
/**
* Increments refcount of user database.
Index: dbus/dbus-userdb.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-userdb.h,v
retrieving revision 1.10
diff -u -r1.10 dbus-userdb.h
--- dbus/dbus-userdb.h 22 Mar 2005 17:57:27 -0000 1.10
+++ dbus/dbus-userdb.h 5 Mar 2006 17:08:15 -0000
@@ -51,6 +51,7 @@
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,
More information about the dbus
mailing list