From 470d743cedf6c89a8480e8387b8be1878f196494 Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Wed, 17 Apr 2013 08:48:12 +0200 Subject: [PATCH 1/2] User: hold on to our keyfile When updating a User object from keyfile, keep reference on the keyfile object passed in and modify the Daemon not to destroy it. When saving a User, instead of creating a new keyfile, reuse the one we stored on the object. We still record the properties from the User object into the keyfile in the previous way (and include a modification to clear out the 'User' group before doing this). The intention here is to allow other groups stored in the keyfile to be preserved. These other groups are likely to correspond to extension interfaces (which will be introduced in future patches). An alternative approach would have been to only preserve groups for extensions that we currently have loaded but this was abandoned as being excessively brittle since the result of a temporarily missing extension file would be the destruction of data. https://bugs.freedesktop.org/show_bug.cgi?id=63733 --- src/daemon.c | 2 +- src/user.c | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/daemon.c b/src/daemon.c index 7486b84..89ce39d 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -481,7 +481,7 @@ entry_generator_cachedir (GHashTable *users, key_file = g_key_file_new (); if (g_key_file_load_from_file (key_file, filename, 0, NULL)) user_update_from_keyfile (user, key_file); - g_key_file_free (key_file); + g_key_file_unref (key_file); g_free (filename); } diff --git a/src/user.c b/src/user.c index bf5939c..9e18b0d 100644 --- a/src/user.c +++ b/src/user.c @@ -78,6 +78,8 @@ struct User { Daemon *daemon; + GKeyFile *keyfile; + uid_t uid; gid_t gid; gchar *user_name; @@ -347,6 +349,9 @@ user_update_from_keyfile (User *user, g_object_notify (G_OBJECT (user), "icon-file"); } + g_clear_pointer (&user->keyfile, g_key_file_unref); + user->keyfile = g_key_file_ref (keyfile); + g_object_thaw_notify (G_OBJECT (user)); } @@ -364,6 +369,8 @@ static void user_save_to_keyfile (User *user, GKeyFile *keyfile) { + g_key_file_remove_group (keyfile, "User", NULL); + if (user->email) g_key_file_set_string (keyfile, "User", "Email", user->email); @@ -387,15 +394,13 @@ static void save_extra_data (User *user) { gchar *filename; - GKeyFile *keyfile; gchar *data; GError *error; - keyfile = g_key_file_new (); - user_save_to_keyfile (user, keyfile); + user_save_to_keyfile (user, user->keyfile); error = NULL; - data = g_key_file_to_data (keyfile, NULL, &error); + data = g_key_file_to_data (user->keyfile, NULL, &error); if (error == NULL) { filename = g_build_filename (USERDIR, user->user_name, @@ -408,7 +413,6 @@ save_extra_data (User *user) user->user_name, error->message); g_error_free (error); } - g_key_file_free (keyfile); } static void @@ -1752,6 +1756,8 @@ user_finalize (GObject *object) user = USER (object); + g_clear_pointer (&user->keyfile, g_key_file_unref); + g_free (user->object_path); g_free (user->user_name); g_free (user->real_name); -- 1.8.1.4