Fix removal of user/group.

This commit is contained in:
ajacoutot 2012-05-11 18:19:10 +00:00
parent 29fce94f67
commit 2ccc6edecc
2 changed files with 52 additions and 19 deletions

View File

@ -1,9 +1,10 @@
# $OpenBSD: Makefile,v 1.25 2012/05/11 15:32:46 ajacoutot Exp $
# $OpenBSD: Makefile,v 1.26 2012/05/11 18:19:10 ajacoutot Exp $
COMMENT= D-Bus interface for user account query and manipulation
DISTNAME= accountsservice-0.6.20
EXTRACT_SUFX= .tar.xz
REVISION= 0
SHARED_LIBS += accountsservice 0.0 # 0.0

View File

@ -1,7 +1,18 @@
$OpenBSD: patch-src_daemon_c,v 1.15 2012/05/11 15:32:46 ajacoutot Exp $
$OpenBSD: patch-src_daemon_c,v 1.16 2012/05/11 18:19:10 ajacoutot Exp $
--- src/daemon.c.orig Fri May 4 15:52:03 2012
+++ src/daemon.c Fri May 11 16:16:02 2012
@@ -52,7 +52,7 @@
+++ src/daemon.c Fri May 11 20:16:23 2012
@@ -36,6 +36,10 @@
#include <utmpx.h>
#endif
+#ifdef __OpenBSD__
+#include <grp.h> /* getgrnam */
+#endif
+
#include <glib.h>
#include <glib/gi18n.h>
#include <glib-object.h>
@@ -52,7 +56,7 @@
#define PATH_FALSE "/bin/false"
#define PATH_GDM_CUSTOM "/etc/gdm/custom.conf"
@ -10,7 +21,7 @@ $OpenBSD: patch-src_daemon_c,v 1.15 2012/05/11 15:32:46 ajacoutot Exp $
static const char *default_excludes[] = {
"bin",
@@ -909,7 +909,11 @@ daemon_create_user_authorized_cb (Daemon
@@ -909,7 +913,11 @@ daemon_create_user_authorized_cb (Daemon
CreateUserData *cd = data;
User *user;
GError *error;
@ -22,7 +33,7 @@ $OpenBSD: patch-src_daemon_c,v 1.15 2012/05/11 15:32:46 ajacoutot Exp $
if (getpwnam (cd->user_name) != NULL) {
throw_error (context, ERROR_USER_EXISTS, "A user with name '%s' already exists", cd->user_name);
@@ -926,14 +930,31 @@ daemon_create_user_authorized_cb (Daemon
@@ -926,14 +934,31 @@ daemon_create_user_authorized_cb (Daemon
if (cd->account_type == ACCOUNT_TYPE_ADMINISTRATOR) {
argv[4] = "-G";
argv[5] = "wheel";
@ -54,32 +65,53 @@ $OpenBSD: patch-src_daemon_c,v 1.15 2012/05/11 15:32:46 ajacoutot Exp $
}
else {
throw_error (context, ERROR_FAILED, "Don't know how to add user of type %d", cd->account_type);
@@ -1004,6 +1025,28 @@ daemon_delete_user_authorized_cb (Daemon
@@ -1005,15 +1030,49 @@ daemon_delete_user_authorized_cb (Daemon
return;
}
+
+/*
+ * Under OpenBSD there is no /etc/login.defs (for USERGROUPS_ENAB), so
+ * we need to explicitely remove the user's group if it contains no more
+ * members.
+ * members and matches the username.
+ */
+#ifdef __OpenBSD__
+ struct group *grp;
+ GError *grperror;
+ gchar *grpargv[2];
+
+ sys_log (context, "delete group '%d'", pwent->pw_gid);
+ grp = getgrnam (pwent->pw_name);
+
+ grpargv[0] = "/usr/sbin/groupdel";
+ grpargv[1] = pwent->pw_name;
+ if ((grp != NULL) && (*grp->gr_name == *pwent->pw_name) && (*grp->gr_mem == NULL)) {
+ sys_log (context, "delete group '%d'", pwent->pw_gid);
+
+ grperror = NULL;
+ if (!spawn_with_login_uid (context, grpargv, &grperror)) {
+ throw_error (context, ERROR_FAILED, "running '%s' failed: %s", grpargv[0], grperror->message);
+ g_error_free (grperror);
+ return;
+ grpargv[0] = "/usr/sbin/groupdel";
+ grpargv[1] = pwent->pw_name;
+
+ grperror = NULL;
+ if (!spawn_with_login_uid (context, grpargv, &grperror)) {
+ throw_error (context, ERROR_FAILED, "running '%s' failed: %s", grpargv[0], grperror->message);
+ g_error_free (grperror);
+ return;
+ }
+ }
+#endif
+
sys_log (context, "delete user '%s' (%d)", pwent->pw_name, ud->uid);
argv[0] = "/usr/sbin/userdel";
if (ud->remove_files) {
+#ifdef __OpenBSD__
+ argv[1] = "-r";
+ argv[2] = "--";
+ argv[3] = pwent->pw_name;
+ argv[4] = NULL;
+#else
argv[1] = "-f";
argv[2] = "-r";
argv[3] = "--";
argv[4] = pwent->pw_name;
argv[5] = NULL;
+#endif
}
else {
argv[1] = "--";