[accountsservice/f15/master] Keep excluded users off the user list

Matthias Clasen mclasen at fedoraproject.org
Thu Feb 24 22:54:13 UTC 2011


commit 99ef539c50416b423f0f726d2fc54d23f0786a35
Author: Matthias Clasen <mclasen at redhat.com>
Date:   Thu Feb 24 17:54:06 2011 -0500

    Keep excluded users off the user list

 0001-Add-a-debug-commandline-option.patch          |   57 ++++++++++
 0002-Add-a-function-to-get-the-uid-of-a-user.patch |   44 ++++++++
 0003-Keep-excluded-users-off-the-cached-list.patch |  113 ++++++++++++++++++++
 accountsservice.spec                               |   14 +++-
 4 files changed, 227 insertions(+), 1 deletions(-)
---
diff --git a/0001-Add-a-debug-commandline-option.patch b/0001-Add-a-debug-commandline-option.patch
new file mode 100644
index 0000000..a875e46
--- /dev/null
+++ b/0001-Add-a-debug-commandline-option.patch
@@ -0,0 +1,57 @@
+From e3c58ec8361fdabd01947803688ccc519475dab0 Mon Sep 17 00:00:00 2001
+From: Matthias Clasen <mclasen at redhat.com>
+Date: Thu, 24 Feb 2011 17:48:09 -0500
+Subject: [PATCH 1/3] Add a --debug commandline option
+
+Having this makes g_debug() a lot more useful.
+---
+ src/main.c |   19 +++++++++++++++++++
+ 1 files changed, 19 insertions(+), 0 deletions(-)
+
+diff --git a/src/main.c b/src/main.c
+index 6953de4..ad00910 100644
+--- a/src/main.c
++++ b/src/main.c
+@@ -111,6 +111,21 @@ acquire_name_on_proxy (DBusGProxy *system_bus_proxy,
+         return ret;
+ }
+ 
++static gboolean debug;
++
++static void
++log_handler (const gchar   *domain,
++             GLogLevelFlags level,
++             const gchar   *message,
++             gpointer       data)
++{
++        /* filter out DEBUG messages if debug isn't set */
++        if ((level & G_LOG_LEVEL_MASK) == G_LOG_LEVEL_DEBUG && !debug)
++                return;
++
++        g_log_default_handler (domain, level, message, data);
++}
++
+ int
+ main (int argc, char *argv[])
+ {
+@@ -125,6 +140,8 @@ main (int argc, char *argv[])
+         static GOptionEntry entries[] = {
+                 { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Output version information and exit"), NULL },
+                 { "replace", 0, 0, G_OPTION_ARG_NONE, &replace, N_("Replace existing instance"), NULL },
++                { "debug", 0, 0, G_OPTION_ARG_NONE, &debug, N_("Enable debugging code"), NULL },
++
+                 { NULL }
+         };
+ 
+@@ -159,6 +176,8 @@ main (int argc, char *argv[])
+                 goto out;
+         }
+ 
++        g_log_set_default_handler (log_handler, NULL);
++
+         bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+         if (bus == NULL) {
+                 g_warning ("Could not connect to system bus: %s", error->message);
+-- 
+1.7.4.1
+
diff --git a/0002-Add-a-function-to-get-the-uid-of-a-user.patch b/0002-Add-a-function-to-get-the-uid-of-a-user.patch
new file mode 100644
index 0000000..f41deae
--- /dev/null
+++ b/0002-Add-a-function-to-get-the-uid-of-a-user.patch
@@ -0,0 +1,44 @@
+From eda6544a12c13711c6a81f944f56de92391c0854 Mon Sep 17 00:00:00 2001
+From: Matthias Clasen <mclasen at redhat.com>
+Date: Thu, 24 Feb 2011 17:48:53 -0500
+Subject: [PATCH 2/3] Add a function to get the uid of a user
+
+---
+ src/user.c |    6 ++++++
+ src/user.h |    3 ++-
+ 2 files changed, 8 insertions(+), 1 deletions(-)
+
+diff --git a/src/user.c b/src/user.c
+index d60257a..b7acb6c 100644
+--- a/src/user.c
++++ b/src/user.c
+@@ -773,6 +773,12 @@ user_local_get_object_path (User *user)
+         return user->object_path;
+ }
+ 
++uid_t
++user_local_get_uid (User *user)
++{
++        return user->uid;
++}
++
+ static void
+ throw_error (DBusGMethodInvocation *context,
+              gint                   error_code,
+diff --git a/src/user.h b/src/user.h
+index 2c3d047..a30be89 100644
+--- a/src/user.h
++++ b/src/user.h
+@@ -63,7 +63,8 @@ void         user_local_register            (User          *user);
+ void         user_local_unregister          (User          *user);
+ 
+ const gchar *user_local_get_user_name       (User          *user);
+-const gchar *user_local_get_object_path     (User          *user);
++const gchar *user_local_get_user_name       (User          *user);
++uid_t        user_local_get_uid             (User          *user);
+ 
+ /* exported methods */
+ 
+-- 
+1.7.4.1
+
diff --git a/0003-Keep-excluded-users-off-the-cached-list.patch b/0003-Keep-excluded-users-off-the-cached-list.patch
new file mode 100644
index 0000000..ab99c5b
--- /dev/null
+++ b/0003-Keep-excluded-users-off-the-cached-list.patch
@@ -0,0 +1,113 @@
+From a9699746f5b5e6c3a6ea3e3509df0a21a67e4eaf Mon Sep 17 00:00:00 2001
+From: Matthias Clasen <mclasen at redhat.com>
+Date: Thu, 24 Feb 2011 17:49:11 -0500
+Subject: [PATCH 3/3] Keep excluded users off the cached list
+
+Previously, calling FindUserByName would create a user object
+and then it would be included in ListCachedUsers return  values
+even though it has e.g. a low uid.
+
+This was causing both the root and gdm users to show up in
+the user account panel.
+---
+ src/daemon.c |   49 ++++++++++++++++++++++++++++++-------------------
+ 1 files changed, 30 insertions(+), 19 deletions(-)
+
+diff --git a/src/daemon.c b/src/daemon.c
+index 3b021ad..4e0b935 100644
+--- a/src/daemon.c
++++ b/src/daemon.c
+@@ -213,6 +213,18 @@ daemon_class_init (DaemonClass *klass)
+                                                               G_PARAM_READABLE));
+ }
+ 
++static gboolean
++user_is_excluded (Daemon *daemon, const gchar *username, uid_t uid)
++{
++        if (uid < MINIMAL_UID) {
++                return TRUE;
++        }
++        if (g_hash_table_lookup (daemon->priv->exclusions, username)) {
++                return TRUE;
++        }
++
++        return FALSE;
++}
+ 
+ static void
+ listify_hash_values_hfunc (gpointer key,
+@@ -325,7 +337,8 @@ process_ck_history_line (Daemon      *daemon,
+                 return;
+         }
+ 
+-        if (g_hash_table_lookup (daemon->priv->exclusions, username)) {
++        /* pass MINIMAL_UID to just check the name here */
++        if (user_is_excluded (daemon, username, MINIMAL_UID)) {
+                 g_debug ("excluding user '%s'", username);
+                 g_free (username);
+                 return;
+@@ -474,13 +487,8 @@ reload_passwd (Daemon *daemon)
+ 
+         for (pwent = fgetpwent (fp); pwent != NULL; pwent = fgetpwent (fp)) {
+                 /* Skip users below MINIMAL_UID... */
+-                if (pwent->pw_uid < MINIMAL_UID) {
+-                        continue;
+-                }
+-
+-                /* ...and explicitly excluded users */
+-                if (g_hash_table_lookup (daemon->priv->exclusions, pwent->pw_name)) {
+-                        g_debug ("explicitly skipping user: %s", pwent->pw_name);
++                if (user_is_excluded (daemon, pwent->pw_name, pwent->pw_uid)) {
++                        g_debug ("skipping user: %s", pwent->pw_name);
+                         continue;
+                 }
+ 
+@@ -919,21 +927,12 @@ daemon_find_user_by_name (Daemon                *daemon,
+         return TRUE;
+ }
+ 
+-static void
+-enumerate_cb (gpointer key,
+-              gpointer value,
+-              gpointer user_data)
+-{
+-        User *user = USER (value);
+-        GPtrArray *object_paths = user_data;
+-        g_ptr_array_add (object_paths, g_strdup (user_local_get_object_path (user)));
+-}
+-
+ typedef struct {
+         Daemon *daemon;
+         DBusGMethodInvocation *context;
+ } ListUserData;
+ 
++
+ static ListUserData *
+ list_user_data_new (Daemon                *daemon,
+                     DBusGMethodInvocation *context)
+@@ -960,9 +959,21 @@ finish_list_cached_users (gpointer user_data)
+ {
+         ListUserData *data = user_data;
+         GPtrArray *object_paths;
++        GHashTableIter iter;
++        const gchar *name;
++        User *user;
++        uid_t uid;
+ 
+         object_paths = g_ptr_array_new ();
+-        g_hash_table_foreach (data->daemon->priv->users, enumerate_cb, object_paths);
++
++        g_hash_table_iter_init (&iter, data->daemon->priv->users);
++        while (g_hash_table_iter_next (&iter, (gpointer *)&name, (gpointer *)&user)) {
++                uid = user_local_get_uid (user);
++                if (!user_is_excluded (data->daemon, name, uid)) {
++                        g_debug ("user %s %ld not excluded\n", name, uid);
++                        g_ptr_array_add (object_paths, g_strdup (user_local_get_object_path (user)));
++                }
++        }
+ 
+         dbus_g_method_return (data->context, object_paths);
+ 
+-- 
+1.7.4.1
+
diff --git a/accountsservice.spec b/accountsservice.spec
index 29dd20d..fa6b7a4 100644
--- a/accountsservice.spec
+++ b/accountsservice.spec
@@ -1,7 +1,7 @@
 
 Name:           accountsservice
 Version:        0.6.4
-Release:        1%{?dist}
+Release:        2%{?dist}
 Summary:        D-Bus interfaces for querying and manipulating user account information
 
 Group:          System Environment/Daemons
@@ -10,6 +10,12 @@ URL:            http://www.fedoraproject.org/wiki/Features/UserAccountDialog
 #VCS: git:git://git.freedesktop.org/accountsservice
 Source0:        http://mclasen.fedorapeople.org/accounts/accountsservice-%{version}.tar.bz2
 
+# upstream patches
+Patch0: 0001-Add-a-debug-commandline-option.patch
+Patch1: 0002-Add-a-function-to-get-the-uid-of-a-user.patch
+Patch2: 0003-Keep-excluded-users-off-the-cached-list.patch
+
+
 BuildRequires:  glib2-devel
 BuildRequires:  dbus-glib-devel
 BuildRequires:  polkit-devel
@@ -50,6 +56,9 @@ of these interfaces, based on the useradd, usermod and userdel commands.
 
 %prep
 %setup -q
+%patch0 -p1 -b .debug
+%patch1 -p1 -b .get-uid
+%patch2 -p1 -b .keep-excluded
 
 %build
 %configure
@@ -88,6 +97,9 @@ rm $RPM_BUILD_ROOT%{_libdir}/*.a
 %{_datadir}/gir-1.0/AccountsService-1.0.gir
 
 %changelog
+* Thu Feb 24 2011 Matthias Clasen <mclasen at redha.com> - 0.6.4-2
+- Keep excluded users off the user list
+
 * Wed Feb 23 2011 Ray Strode <rstrode at redhat.com> 0.6.4-1
 - Update to latest release
 


More information about the scm-commits mailing list