Ray Strode cc3cb7
From 815c43087926eb22f37fed6f501a3e9291edf564 Mon Sep 17 00:00:00 2001
Ray Strode cc3cb7
From: Ray Strode <rstrode@redhat.com>
Ray Strode cc3cb7
Date: Wed, 9 May 2018 09:26:57 -0400
Ray Strode cc3cb7
Subject: [PATCH 2/2] daemon: don't emit user-deleted for uncached users
Ray Strode cc3cb7
Ray Strode cc3cb7
Right now we emit spurious user-deleted signals for
Ray Strode cc3cb7
all uncached users anytime a reload occurs.
Ray Strode cc3cb7
Uncached users are users explicitly requested by a client,
Ray Strode cc3cb7
but not part of the results returned from ListCachedUsers.
Ray Strode cc3cb7
Ray Strode cc3cb7
We should only be emitting user-deleted it they were initially
Ray Strode cc3cb7
cached and transitioned to uncached, not if they're still
Ray Strode cc3cb7
hanging around in an uncached state.
Ray Strode cc3cb7
Ray Strode cc3cb7
This commit fixes the code to do that.
Ray Strode cc3cb7
---
Ray Strode cc3cb7
 src/daemon.c | 2 +-
Ray Strode cc3cb7
 1 file changed, 1 insertion(+), 1 deletion(-)
Ray Strode cc3cb7
Ray Strode cc3cb7
diff --git a/src/daemon.c b/src/daemon.c
Ray Strode cc3cb7
index d3fa971..a12b71b 100644
Ray Strode cc3cb7
--- a/src/daemon.c
Ray Strode cc3cb7
+++ b/src/daemon.c
Ray Strode cc3cb7
@@ -482,61 +482,61 @@ reload_users (Daemon *daemon)
Ray Strode cc3cb7
         while (g_hash_table_iter_next (&iter, &name, (gpointer *)&user)) {
Ray Strode cc3cb7
                 if (!user_get_system_account (user))
Ray Strode cc3cb7
                         number_of_normal_users++;
Ray Strode cc3cb7
                 user_update_local_account_property (user, g_hash_table_lookup (local, name) != NULL);
Ray Strode cc3cb7
         }
Ray Strode cc3cb7
         g_hash_table_destroy (local);
Ray Strode cc3cb7
 
Ray Strode cc3cb7
         had_no_users = accounts_accounts_get_has_no_users (accounts);
Ray Strode cc3cb7
         has_no_users = number_of_normal_users == 0;
Ray Strode cc3cb7
 
Ray Strode cc3cb7
         if (had_no_users != has_no_users)
Ray Strode cc3cb7
                 accounts_accounts_set_has_no_users (accounts, has_no_users);
Ray Strode cc3cb7
 
Ray Strode cc3cb7
         had_multiple_users = accounts_accounts_get_has_multiple_users (accounts);
Ray Strode cc3cb7
         has_multiple_users = number_of_normal_users > 1;
Ray Strode cc3cb7
 
Ray Strode cc3cb7
         if (had_multiple_users != has_multiple_users)
Ray Strode cc3cb7
                 accounts_accounts_set_has_multiple_users (accounts, has_multiple_users);
Ray Strode cc3cb7
 
Ray Strode cc3cb7
         /* Swap out the users */
Ray Strode cc3cb7
         old_users = daemon->priv->users;
Ray Strode cc3cb7
         daemon->priv->users = users;
Ray Strode cc3cb7
 
Ray Strode cc3cb7
         /* Remove all the old users */
Ray Strode cc3cb7
         g_hash_table_iter_init (&iter, old_users);
Ray Strode cc3cb7
         while (g_hash_table_iter_next (&iter, &name, (gpointer *)&user)) {
Ray Strode cc3cb7
                 User *refreshed_user;
Ray Strode cc3cb7
 
Ray Strode cc3cb7
                 refreshed_user = g_hash_table_lookup (users, name);
Ray Strode cc3cb7
 
Ray Strode cc3cb7
-                if (!refreshed_user || !user_get_cached (refreshed_user)) {
Ray Strode cc3cb7
+                if (!refreshed_user || user_get_cached (user) && !user_get_cached (refreshed_user)) {
Ray Strode cc3cb7
                         accounts_accounts_emit_user_deleted (ACCOUNTS_ACCOUNTS (daemon),
Ray Strode cc3cb7
                                                              user_get_object_path (user));
Ray Strode cc3cb7
                         user_unregister (user);
Ray Strode cc3cb7
                 }
Ray Strode cc3cb7
         }
Ray Strode cc3cb7
 
Ray Strode cc3cb7
         /* Register all the new users */
Ray Strode cc3cb7
         g_hash_table_iter_init (&iter, users);
Ray Strode cc3cb7
         while (g_hash_table_iter_next (&iter, &name, (gpointer *)&user)) {
Ray Strode cc3cb7
                 User *stale_user;
Ray Strode cc3cb7
 
Ray Strode cc3cb7
                 stale_user = g_hash_table_lookup (old_users, name);
Ray Strode cc3cb7
 
Ray Strode cc3cb7
                 if (!stale_user || !user_get_cached (stale_user) && user_get_cached (user)) {
Ray Strode cc3cb7
                         user_register (user);
Ray Strode cc3cb7
                         accounts_accounts_emit_user_added (ACCOUNTS_ACCOUNTS (daemon),
Ray Strode cc3cb7
                                                            user_get_object_path (user));
Ray Strode cc3cb7
                 }
Ray Strode cc3cb7
                 g_object_thaw_notify (G_OBJECT (user));
Ray Strode cc3cb7
         }
Ray Strode cc3cb7
 
Ray Strode cc3cb7
         g_hash_table_destroy (old_users);
Ray Strode cc3cb7
 }
Ray Strode cc3cb7
 
Ray Strode cc3cb7
 static gboolean
Ray Strode cc3cb7
 reload_users_timeout (Daemon *daemon)
Ray Strode cc3cb7
 {
Ray Strode cc3cb7
         reload_users (daemon);
Ray Strode cc3cb7
         daemon->priv->reload_id = 0;
Ray Strode cc3cb7
 
Ray Strode cc3cb7
-- 
Ray Strode cc3cb7
2.17.0
Ray Strode cc3cb7