From: Frederic Peters <fpeters@debian.org>
Bug-Debian: http://bugs.debian.org/618764
Forwarded: not-needed
Description: Create and manage groups like on a debian system.
---
 src/daemon.c |   22 ++++++----------------
 src/user.c   |   16 ++++++++--------
 src/util.c   |   42 ++++++++++++++++++++++++++++++++++++++++++
 src/util.h   |    9 +++++++++
 4 files changed, 65 insertions(+), 24 deletions(-)

--- accountsservice.orig/src/daemon.c
+++ accountsservice/src/daemon.c
@@ -1187,22 +1187,8 @@ daemon_create_user_authorized_cb (Daemon
         argv[1] = "-m";
         argv[2] = "-c";
         argv[3] = cd->real_name;
-        if (cd->account_type == ACCOUNT_TYPE_ADMINISTRATOR) {
-                argv[4] = "-G";
-                argv[5] = ADMIN_GROUP;
-                argv[6] = "--";
-                argv[7] = cd->user_name;
-                argv[8] = NULL;
-        }
-        else if (cd->account_type == ACCOUNT_TYPE_STANDARD) {
-                argv[4] = "--";
-                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;
-        }
+        argv[4] = cd->user_name;
+        argv[5] = NULL;
 
         error = NULL;
         if (!spawn_with_login_uid (context, argv, &error)) {
@@ -1211,6 +1197,10 @@ daemon_create_user_authorized_cb (Daemon
                 return;
         }
 
+        if (cd->account_type == ACCOUNT_TYPE_ADMINISTRATOR) {
+                add_user_to_group (context, cd->user_name, "sudo");
+        }
+
         user = daemon_local_find_user_by_name (daemon, cd->user_name);
         user_update_local_account_property (user, TRUE);
         user_update_system_account_property (user, FALSE);
--- accountsservice.orig/src/user.c
+++ accountsservice/src/user.c
@@ -115,7 +115,7 @@ static gint
 account_type_from_pwent (struct passwd *pwent)
 {
         struct group *grp;
-        gid_t wheel;
+        gid_t admin;
         gid_t *groups;
         gint ngroups;
         gint i;
@@ -130,12 +130,12 @@ account_type_from_pwent (struct passwd *
                 g_debug (ADMIN_GROUP " group not found");
                 return ACCOUNT_TYPE_STANDARD;
         }
-        wheel = grp->gr_gid;
+        admin = grp->gr_gid;
 
         ngroups = get_user_groups (pwent->pw_name, pwent->pw_gid, &groups);
 
         for (i = 0; i < ngroups; i++) {
-                if (groups[i] == wheel) {
+                if (groups[i] == admin) {
                         g_free (groups);
                         return ACCOUNT_TYPE_ADMINISTRATOR;
                 }
@@ -1347,7 +1347,7 @@ user_change_account_type_authorized_cb (
         gid_t *groups;
         gint ngroups;
         GString *str;
-        gid_t wheel;
+        gid_t admin;
         struct group *grp;
         gint i;
         const gchar *argv[6];
@@ -1359,22 +1359,22 @@ user_change_account_type_authorized_cb (
 
                 grp = getgrnam (ADMIN_GROUP);
                 if (grp == NULL) {
-                        throw_error (context, ERROR_FAILED, "failed to set account type: wheel group not found");
+                        throw_error (context, ERROR_FAILED, "failed to set account type: admin group not found");
                         return;
                 }
-                wheel = grp->gr_gid;
+                admin = grp->gr_gid;
 
                 ngroups = get_user_groups (user->user_name, user->gid, &groups);
 
                 str = g_string_new ("");
                 for (i = 0; i < ngroups; i++) {
-                        if (groups[i] == wheel)
+                        if (groups[i] == admin)
                                 continue;
                         g_string_append_printf (str, "%d,", groups[i]);
                 }
                 switch (account_type) {
                 case ACCOUNT_TYPE_ADMINISTRATOR:
-                        g_string_append_printf (str, "%d", wheel);
+                        g_string_append_printf (str, "%d", admin);
                         break;
                 case ACCOUNT_TYPE_STANDARD:
                 default:
--- accountsservice.orig/src/util.c
+++ accountsservice/src/util.c
@@ -313,3 +313,45 @@ get_caller_uid (GDBusMethodInvocation *c
 
         return TRUE;
 }
+
+void
+add_user_to_group (GDBusMethodInvocation *context,
+                  const char *user_name,
+                  const char *group_name)
+{
+        GError *error;
+        gchar *argv[4];
+
+        argv[0] = (gchar*) "/usr/sbin/adduser";
+        argv[1] = (gchar*) user_name;
+        argv[2] = (gchar*) group_name;
+        argv[3] = NULL;
+
+        error = NULL;
+        if (!spawn_with_login_uid (context, argv, &error)) {
+                g_warning ("failed to add user %s to group %s", user_name, group_name);
+                g_error_free (error);
+                return;
+        }
+}
+
+void
+remove_user_from_group (GDBusMethodInvocation *context,
+                        const char *user_name,
+                        const char *group_name)
+{
+        GError *error;
+        gchar *argv[4];
+
+        argv[0] = (gchar*) "/usr/sbin/deluser";
+        argv[1] = (gchar*) user_name;
+        argv[2] = (gchar*) group_name;
+        argv[3] = NULL;
+
+        error = NULL;
+        if (!spawn_with_login_uid (context, argv, &error)) {
+                g_warning ("failed to remove user %s from group %s", user_name, group_name);
+                g_error_free (error);
+                return;
+        }
+}
--- accountsservice.orig/src/util.h
+++ accountsservice/src/util.h
@@ -40,6 +40,15 @@ gint get_user_groups (const gchar  *user
                       gid_t         group,
                       gid_t       **groups);
 
+void add_user_to_group (GDBusMethodInvocation *context,
+                        const char *user_name,
+                        const char *group_name);
+
+void remove_user_from_group (GDBusMethodInvocation *context,
+                             const char *user_name,
+                             const char *group_name);
+
+
 G_END_DECLS
 
 #endif /* __UTIL_H__ */
