From 9181aa17e2658a6155227581b7938f9c42439390 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Wed, 13 Jun 2012 16:02:29 +0200 Subject: [PATCH] Don't use userdel for deletion of remote users https://bugs.freedesktop.org/show_bug.cgi?id=51037 --- src/daemon.c | 54 ++++++++++++++++++++++++++++++++++++------------------ src/user.c | 5 ++++- 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/daemon.c b/src/daemon.c index 0467bc4..fbc1bdd 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -1178,6 +1178,7 @@ daemon_delete_user_authorized_cb (Daemon *daemon, gchar *filename; struct passwd *pwent; const gchar *argv[6]; + User *user; pwent = getpwuid (ud->uid); @@ -1189,25 +1190,30 @@ daemon_delete_user_authorized_cb (Daemon *daemon, sys_log (context, "delete user '%s' (%d)", pwent->pw_name, ud->uid); - argv[0] = "/usr/sbin/userdel"; - if (ud->remove_files) { - argv[1] = "-f"; - argv[2] = "-r"; - argv[3] = "--"; - argv[4] = pwent->pw_name; - argv[5] = NULL; - } - else { - argv[1] = "--"; - argv[2] = pwent->pw_name; - argv[3] = NULL; - } + user = g_hash_table_lookup (daemon->priv->users, pwent->pw_name); - error = NULL; - if (!spawn_with_login_uid (context, argv, &error)) { - throw_error (context, ERROR_FAILED, "running '%s' failed: %s", argv[0], error->message); - g_error_free (error); - return; + /* Delete a local user */ + if (!user || user_get_local_account (user)) { + argv[0] = "/usr/sbin/userdel"; + if (ud->remove_files) { + argv[1] = "-f"; + argv[2] = "-r"; + argv[3] = "--"; + argv[4] = pwent->pw_name; + argv[5] = NULL; + } else { + argv[1] = "--"; + argv[2] = pwent->pw_name; + argv[3] = NULL; + } + + error = NULL; + if (!spawn_with_login_uid (context, argv, &error)) { + throw_error (context, ERROR_FAILED, "running '%s' failed: %s", + argv[0], error->message); + g_error_free (error); + return; + } } filename = g_build_filename (USERDIR, pwent->pw_name, NULL); @@ -1218,6 +1224,18 @@ daemon_delete_user_authorized_cb (Daemon *daemon, g_remove (filename); g_free (filename); + /* Remove the user from our lists */ + if (user) { + g_object_ref (user); + + user_unregister (user); + g_hash_table_remove (daemon->priv->users, pwent->pw_name); + accounts_accounts_emit_user_deleted (ACCOUNTS_ACCOUNTS (daemon), + user_get_object_path (user)); + + g_object_unref (user); + } + accounts_accounts_complete_delete_user (NULL, context); } diff --git a/src/user.c b/src/user.c index 59b86fb..074243d 100644 --- a/src/user.c +++ b/src/user.c @@ -444,13 +444,16 @@ user_register (User *user) } user->object_path = compute_object_path (user); + g_debug ("registering user %s at %s", user->user_name, user->object_path); if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (user), user->system_bus_connection, user->object_path, &error)) { if (error != NULL) { - g_critical ("error exporting user object: %s", error->message); + g_critical ("error exporting user '%s' object at '%s': %s", + user->user_name, user->object_path, + error->message); g_error_free (error); } return; -- 1.7.10.2