From 6d76fd25fcf830dc5076770f59d31ccc67901937 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Thu, 21 Dec 2017 14:21:28 +1300 Subject: [PATCH] Support Debian based user management --- configure.ac | 18 ++++++++++++++++++ src/daemon.c | 24 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/configure.ac b/configure.ac index f25d72b..692199a 100644 --- a/configure.ac +++ b/configure.ac @@ -36,6 +36,23 @@ dnl --------------------------------------------------------------------------- dnl - Core configuration dnl --------------------------------------------------------------------------- +AC_ARG_WITH(, + [AS_HELP_STRING([--with-user-management],[Set program to use to create users (passwd or debian) @<:@default=auto@:>@])], + ,with_user_management=auto) +AS_IF([test x$with_user_management = xauto], [ + AC_CHECK_FILE(/etc/redhat-release, with_user_management=passwd) + AC_CHECK_FILE(/etc/debian_version, with_user_management=debian) + AS_IF([test x$with_user_management = xauto], [ + with_user_management=passwd + ]) +]) +if test "x$with_user_management" = "xpasswd" ; then + AC_DEFINE(WITH_USER_MANAGEMENT_PASSWD, 1, [Define to enable passwd based user management]) +fi +if test "x$with_user_management" = "xdebian" ; then + AC_DEFINE(WITH_USER_MANAGEMENT_DEBIAN, 1, [Define to enable Debian based user management]) +fi + AC_ARG_ENABLE(admin-group, [AS_HELP_STRING([--enable-admin-group],[Set group for administrative accounts @<:@default=auto@:>@])], ,enable_admin_group=auto) @@ -379,6 +396,7 @@ if test "x$enable_docbook_docs" = "xyes"; then else AC_MSG_NOTICE([** DocBook documentation build disabled]) fi + AC_MSG_NOTICE([** User management: $with_user_management]) AC_MSG_NOTICE([** Administrator group: $enable_admin_group]) AC_MSG_NOTICE([** Extra administrator groups: $with_extra_admin_groups]) AC_MSG_NOTICE([** GDM configuration: $gdmconffile]) diff --git a/src/daemon.c b/src/daemon.c index 3d588ac..c9e3280 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -1063,6 +1063,7 @@ daemon_create_user_authorized_cb (Daemon *daemon, sys_log (context, "create user '%s'", cd->user_name); +#if defined (WITH_USER_MANAGEMENT_PASSWD) argv[0] = "/usr/sbin/useradd"; argv[1] = "-m"; argv[2] = "-c"; @@ -1090,6 +1091,29 @@ daemon_create_user_authorized_cb (Daemon *daemon, throw_error (context, ERROR_FAILED, "Don't know how to add user of type %d", cd->account_type); return; } +#elif defined (WITH_USER_MANAGEMENT_DEBIAN) + argv[0] = "/usr/sbin/adduser"; + argv[1] = "--quiet"; + argv[2] = "--disabled-login"; + argv[3] = "--gecos"; + argv[4] = cd->real_name; + if (cd->account_type == ACCOUNT_TYPE_ADMINISTRATOR) { + argv[5] = "--ingroup"; + argv[6] = ADMIN_GROUP; + argv[7] = cd->user_name; + argv[8] = NULL; + } + else if (cd->account_type == ACCOUNT_TYPE_STANDARD) { + argv[5] = cd->user_name; + argv[6] = NULL; + } + else { + throw_error (context, ERROR_FAILED, "Don't know how to add user of type %d", cd->account_type); + return; + } +#else +#error "Unable to determine method to add users" +#endif if (!spawn_with_login_uid (context, argv, &error)) { throw_error (context, ERROR_FAILED, "running '%s' failed: %s", argv[0], error->message); -- 2.15.1