Blame SOURCES/0001-daemon-Fix-warnings-about-type-punning.patch

7dfda4
From dee5f443807fee3b5b279d0488df617eeed52230 Mon Sep 17 00:00:00 2001
7dfda4
From: Robert Ancell <robert.ancell@canonical.com>
7dfda4
Date: Thu, 6 Sep 2018 14:37:39 +1200
7dfda4
Subject: [PATCH] daemon: Fix warnings about type-punning
7dfda4
7dfda4
---
7dfda4
 src/daemon.c | 26 +++++++++++++++-----------
7dfda4
 1 file changed, 15 insertions(+), 11 deletions(-)
7dfda4
7dfda4
diff --git a/src/daemon.c b/src/daemon.c
7dfda4
index 2587b8a..00dff51 100644
7dfda4
--- a/src/daemon.c
7dfda4
+++ b/src/daemon.c
7dfda4
@@ -232,117 +232,118 @@ entry_generator_fgetpwent (Daemon       *daemon,
7dfda4
                 pwent = fgetpwent (generator_state->fp);
7dfda4
                 if (pwent != NULL) {
7dfda4
                         shadow_entry_buffers = g_hash_table_lookup (generator_state->users, pwent->pw_name);
7dfda4
 
7dfda4
                         if (shadow_entry_buffers != NULL) {
7dfda4
                             *spent = &shadow_entry_buffers->spbuf;
7dfda4
                         }
7dfda4
                         return pwent;
7dfda4
                 }
7dfda4
         }
7dfda4
 
7dfda4
         /* Last iteration */
7dfda4
         fclose (generator_state->fp);
7dfda4
         g_hash_table_unref (generator_state->users);
7dfda4
         g_free (generator_state);
7dfda4
         *state = NULL;
7dfda4
 
7dfda4
         return NULL;
7dfda4
 }
7dfda4
 
7dfda4
 static struct passwd *
7dfda4
 entry_generator_cachedir (Daemon       *daemon,
7dfda4
                           GHashTable   *users,
7dfda4
                           gpointer     *state,
7dfda4
                           struct spwd **shadow_entry)
7dfda4
 {
7dfda4
         struct passwd *pwent;
7dfda4
         g_autoptr(GError) error = NULL;
7dfda4
         gboolean regular;
7dfda4
         GHashTableIter iter;
7dfda4
-        const gchar *name;
7dfda4
-        User *user;
7dfda4
+        gpointer key, value;
7dfda4
         GDir *dir;
7dfda4
 
7dfda4
         /* First iteration */
7dfda4
         if (*state == NULL) {
7dfda4
                 *state = g_dir_open (USERDIR, 0, &error);
7dfda4
                 if (error != NULL) {
7dfda4
                         if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
7dfda4
                                 g_warning ("couldn't list user cache directory: %s", USERDIR);
7dfda4
                         return NULL;
7dfda4
                 }
7dfda4
         }
7dfda4
 
7dfda4
         /* Every iteration */
7dfda4
 
7dfda4
         /*
7dfda4
          * Use names of files of regular type to lookup information
7dfda4
          * about each user. Loop until we find something valid.
7dfda4
          */
7dfda4
         dir = *state;
7dfda4
         while (TRUE) {
7dfda4
                 const gchar *name;
7dfda4
                 g_autofree gchar *filename = NULL;
7dfda4
 
7dfda4
                 name = g_dir_read_name (dir);
7dfda4
                 if (name == NULL)
7dfda4
                         break;
7dfda4
 
7dfda4
                 /* Only load files in this directory */
7dfda4
                 filename = g_build_filename (USERDIR, name, NULL);
7dfda4
                 regular = g_file_test (filename, G_FILE_TEST_IS_REGULAR);
7dfda4
 
7dfda4
                 if (regular) {
7dfda4
                         errno = 0;
7dfda4
                         pwent = getpwnam (name);
7dfda4
                         if (pwent != NULL) {
7dfda4
                                 *shadow_entry = getspnam (pwent->pw_name);
7dfda4
 
7dfda4
                                 return pwent;
7dfda4
                         } else if (errno == 0) {
7dfda4
                                 g_debug ("user '%s' in cache dir but not present on system, removing", name);
7dfda4
                                 remove_cache_files (name);
7dfda4
                         }
7dfda4
                         else {
7dfda4
                                 g_warning ("failed to check if user '%s' in cache dir is present on system: %s",
7dfda4
                                   name, g_strerror (errno));
7dfda4
                         }
7dfda4
                 }
7dfda4
         }
7dfda4
 
7dfda4
         /* Last iteration */
7dfda4
         g_dir_close (dir);
7dfda4
 
7dfda4
         /* Update all the users from the files in the cache dir */
7dfda4
         g_hash_table_iter_init (&iter, users);
7dfda4
-        while (g_hash_table_iter_next (&iter, (gpointer *)&name, (gpointer *)&user)) {
7dfda4
+        while (g_hash_table_iter_next (&iter, &key, &value)) {
7dfda4
+                const gchar *name = key;
7dfda4
+                User *user = value;
7dfda4
                 g_autofree gchar *filename = NULL;
7dfda4
                 g_autoptr(GKeyFile) key_file = NULL;
7dfda4
 
7dfda4
                 filename = g_build_filename (USERDIR, name, NULL);
7dfda4
                 key_file = g_key_file_new ();
7dfda4
                 if (g_key_file_load_from_file (key_file, filename, 0, NULL))
7dfda4
                         user_update_from_keyfile (user, key_file);
7dfda4
         }
7dfda4
 
7dfda4
         *state = NULL;
7dfda4
         return NULL;
7dfda4
 }
7dfda4
 
7dfda4
 static struct passwd *
7dfda4
 entry_generator_requested_users (Daemon       *daemon,
7dfda4
                                  GHashTable   *users,
7dfda4
                                  gpointer     *state,
7dfda4
                                  struct spwd **shadow_entry)
7dfda4
 {
7dfda4
         struct passwd *pwent;
7dfda4
         GList *node;
7dfda4
 
7dfda4
         /* First iteration */
7dfda4
         if (*state == NULL) {
7dfda4
                 *state = daemon->priv->explicitly_requested_users;
7dfda4
         }
7dfda4
 
7dfda4
         /* Every iteration */
7dfda4
 
7dfda4
         if (g_hash_table_size (users) < MAX_LOCAL_USERS) {
7dfda4
@@ -423,129 +424,131 @@ load_entries (Daemon             *daemon,
7dfda4
                 }
7dfda4
 
7dfda4
                 if (!explicitly_requested) {
7dfda4
                         user_set_cached (user, TRUE);
7dfda4
                 }
7dfda4
         }
7dfda4
 
7dfda4
         /* Generator should have cleaned up */
7dfda4
         g_assert (generator_state == NULL);
7dfda4
 }
7dfda4
 
7dfda4
 static GHashTable *
7dfda4
 create_users_hash_table (void)
7dfda4
 {
7dfda4
         return g_hash_table_new_full (g_str_hash,
7dfda4
                                       g_str_equal,
7dfda4
                                       g_free,
7dfda4
                                       g_object_unref);
7dfda4
 }
7dfda4
 
7dfda4
 static void
7dfda4
 reload_users (Daemon *daemon)
7dfda4
 {
7dfda4
         AccountsAccounts *accounts = ACCOUNTS_ACCOUNTS (daemon);
7dfda4
         gboolean had_no_users, has_no_users, had_multiple_users, has_multiple_users;
7dfda4
         GHashTable *users;
7dfda4
         GHashTable *old_users;
7dfda4
         GHashTable *local;
7dfda4
         GHashTableIter iter;
7dfda4
         gsize number_of_normal_users = 0;
7dfda4
-        gpointer name;
7dfda4
-        User *user;
7dfda4
+        gpointer name, value;
7dfda4
 
7dfda4
         /* Track the users that we saw during our (re)load */
7dfda4
         users = create_users_hash_table ();
7dfda4
 
7dfda4
         /*
7dfda4
          * NOTE: As we load data from all the sources, notifies are
7dfda4
          * frozen in load_entries() and then thawed as we process
7dfda4
          * them below.
7dfda4
          */
7dfda4
 
7dfda4
         /* Load the local users into our hash table */
7dfda4
         load_entries (daemon, users, FALSE, entry_generator_fgetpwent);
7dfda4
         local = g_hash_table_new (g_str_hash, g_str_equal);
7dfda4
         g_hash_table_iter_init (&iter, users);
7dfda4
         while (g_hash_table_iter_next (&iter, &name, NULL))
7dfda4
                 g_hash_table_add (local, name);
7dfda4
 
7dfda4
         /* and add users to hash table that were explicitly requested  */
7dfda4
         load_entries (daemon, users, TRUE, entry_generator_requested_users);
7dfda4
 
7dfda4
         /* Now add/update users from other sources, possibly non-local */
7dfda4
         load_entries (daemon, users, FALSE, entry_generator_cachedir);
7dfda4
 
7dfda4
         wtmp_helper_update_login_frequencies (users);
7dfda4
 
7dfda4
         /* Count the non-system users. Mark which users are local, which are not. */
7dfda4
         g_hash_table_iter_init (&iter, users);
7dfda4
-        while (g_hash_table_iter_next (&iter, &name, (gpointer *)&user)) {
7dfda4
+        while (g_hash_table_iter_next (&iter, &name, &value)) {
7dfda4
+                User *user = value;
7dfda4
                 if (!user_get_system_account (user))
7dfda4
                         number_of_normal_users++;
7dfda4
                 user_update_local_account_property (user, g_hash_table_lookup (local, name) != NULL);
7dfda4
         }
7dfda4
         g_hash_table_destroy (local);
7dfda4
 
7dfda4
         had_no_users = accounts_accounts_get_has_no_users (accounts);
7dfda4
         has_no_users = number_of_normal_users == 0;
7dfda4
 
7dfda4
         if (had_no_users != has_no_users)
7dfda4
                 accounts_accounts_set_has_no_users (accounts, has_no_users);
7dfda4
 
7dfda4
         had_multiple_users = accounts_accounts_get_has_multiple_users (accounts);
7dfda4
         has_multiple_users = number_of_normal_users > 1;
7dfda4
 
7dfda4
         if (had_multiple_users != has_multiple_users)
7dfda4
                 accounts_accounts_set_has_multiple_users (accounts, has_multiple_users);
7dfda4
 
7dfda4
         /* Swap out the users */
7dfda4
         old_users = daemon->priv->users;
7dfda4
         daemon->priv->users = users;
7dfda4
 
7dfda4
         /* Remove all the old users */
7dfda4
         g_hash_table_iter_init (&iter, old_users);
7dfda4
-        while (g_hash_table_iter_next (&iter, &name, (gpointer *)&user)) {
7dfda4
+        while (g_hash_table_iter_next (&iter, &name, &value)) {
7dfda4
+                User *user = value;
7dfda4
                 User *refreshed_user;
7dfda4
 
7dfda4
                 refreshed_user = g_hash_table_lookup (users, name);
7dfda4
 
7dfda4
                 if (!refreshed_user || (user_get_cached (user) && !user_get_cached (refreshed_user))) {
7dfda4
                         accounts_accounts_emit_user_deleted (ACCOUNTS_ACCOUNTS (daemon),
7dfda4
                                                              user_get_object_path (user));
7dfda4
                         user_unregister (user);
7dfda4
                 }
7dfda4
         }
7dfda4
 
7dfda4
         /* Register all the new users */
7dfda4
         g_hash_table_iter_init (&iter, users);
7dfda4
-        while (g_hash_table_iter_next (&iter, &name, (gpointer *)&user)) {
7dfda4
+        while (g_hash_table_iter_next (&iter, &name, &value)) {
7dfda4
+                User *user = value;
7dfda4
                 User *stale_user;
7dfda4
 
7dfda4
                 stale_user = g_hash_table_lookup (old_users, name);
7dfda4
 
7dfda4
                 if (!stale_user || (!user_get_cached (stale_user) && user_get_cached (user))) {
7dfda4
                         user_register (user);
7dfda4
                         accounts_accounts_emit_user_added (ACCOUNTS_ACCOUNTS (daemon),
7dfda4
                                                            user_get_object_path (user));
7dfda4
                 }
7dfda4
                 g_object_thaw_notify (G_OBJECT (user));
7dfda4
         }
7dfda4
 
7dfda4
         g_hash_table_destroy (old_users);
7dfda4
 }
7dfda4
 
7dfda4
 static gboolean
7dfda4
 reload_users_timeout (Daemon *daemon)
7dfda4
 {
7dfda4
         reload_users (daemon);
7dfda4
         daemon->priv->reload_id = 0;
7dfda4
 
7dfda4
         return FALSE;
7dfda4
 }
7dfda4
 
7dfda4
 static gboolean load_autologin (Daemon    *daemon,
7dfda4
                                 gchar    **name,
7dfda4
                                 gboolean  *enabled,
7dfda4
                                 GError   **error);
7dfda4
 
7dfda4
 static gboolean
7dfda4
@@ -932,69 +935,70 @@ typedef struct {
7dfda4
 } ListUserData;
7dfda4
 
7dfda4
 
7dfda4
 static ListUserData *
7dfda4
 list_user_data_new (Daemon                *daemon,
7dfda4
                     GDBusMethodInvocation *context)
7dfda4
 {
7dfda4
         ListUserData *data;
7dfda4
 
7dfda4
         data = g_new0 (ListUserData, 1);
7dfda4
 
7dfda4
         data->daemon = g_object_ref (daemon);
7dfda4
         data->context = context;
7dfda4
 
7dfda4
         return data;
7dfda4
 }
7dfda4
 
7dfda4
 static void
7dfda4
 list_user_data_free (ListUserData *data)
7dfda4
 {
7dfda4
         g_object_unref (data->daemon);
7dfda4
         g_free (data);
7dfda4
 }
7dfda4
 
7dfda4
 static gboolean
7dfda4
 finish_list_cached_users (gpointer user_data)
7dfda4
 {
7dfda4
         ListUserData *data = user_data;
7dfda4
         g_autoptr(GPtrArray) object_paths = NULL;
7dfda4
         GHashTableIter iter;
7dfda4
-        const gchar *name;
7dfda4
-        User *user;
7dfda4
+        gpointer key, value;
7dfda4
         uid_t uid;
7dfda4
         const gchar *shell;
7dfda4
 
7dfda4
         object_paths = g_ptr_array_new ();
7dfda4
 
7dfda4
         g_hash_table_iter_init (&iter, data->daemon->priv->users);
7dfda4
-        while (g_hash_table_iter_next (&iter, (gpointer *)&name, (gpointer *)&user)) {
7dfda4
+        while (g_hash_table_iter_next (&iter, &key, &value)) {
7dfda4
+                const gchar *name = key;
7dfda4
+                User *user = value;
7dfda4
                 uid = user_get_uid (user);
7dfda4
                 shell = user_get_shell (user);
7dfda4
 
7dfda4
                 if (!user_classify_is_human (uid, name, shell, NULL)) {
7dfda4
                         g_debug ("user %s %ld excluded", name, (long) uid);
7dfda4
                         continue;
7dfda4
                 }
7dfda4
 
7dfda4
                 if (!user_get_cached (user)) {
7dfda4
                         g_debug ("user %s %ld not cached", name, (long) uid);
7dfda4
                         continue;
7dfda4
                 }
7dfda4
 
7dfda4
                 g_debug ("user %s %ld not excluded", name, (long) uid);
7dfda4
                 g_ptr_array_add (object_paths, (gpointer) user_get_object_path (user));
7dfda4
         }
7dfda4
         g_ptr_array_add (object_paths, NULL);
7dfda4
 
7dfda4
         accounts_accounts_complete_list_cached_users (NULL, data->context, (const gchar * const *) object_paths->pdata);
7dfda4
 
7dfda4
         list_user_data_free (data);
7dfda4
 
7dfda4
         return FALSE;
7dfda4
 }
7dfda4
 
7dfda4
 static gboolean
7dfda4
 daemon_list_cached_users (AccountsAccounts      *accounts,
7dfda4
                           GDBusMethodInvocation *context)
7dfda4
 {
7dfda4
         Daemon *daemon = (Daemon*)accounts;
7dfda4
-- 
7dfda4
2.17.1
7dfda4