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

--- accountsservice.orig/src/daemon.c
+++ accountsservice/src/daemon.c
@@ -941,22 +941,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] = "wheel";
-                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)) {
@@ -965,6 +951,13 @@ daemon_create_user_authorized_cb (Daemon
                 return;
         }
 
+        if (cd->account_type == ACCOUNT_TYPE_ADMINISTRATOR) {
+                add_user_to_group (context, cd->user_name, "sudo");
+		 add_user_to_group (context, cd->user_name, "adm");
+		 add_user_to_group (context, cd->user_name, "lpadmin");
+		 add_user_to_group (context, cd->user_name, "sambashare");
+        }
+
         user = daemon_local_find_user_by_name (daemon, cd->user_name);
 
         accounts_accounts_complete_create_user (NULL, context, user_local_get_object_path (user));
--- accountsservice.orig/src/user.c
+++ accountsservice/src/user.c
@@ -113,7 +113,8 @@ static gint
 account_type_from_pwent (struct passwd *pwent)
 {
         struct group *grp;
-        gid_t wheel;
+        gid_t sudo;
+        gid_t admin;
         gid_t *groups;
         gint ngroups;
         gint i;
@@ -123,17 +124,26 @@ account_type_from_pwent (struct passwd *
                 return ACCOUNT_TYPE_ADMINISTRATOR;
         }
 
-        grp = getgrnam ("wheel");
+        grp = getgrnam ("sudo");
         if (grp == NULL) {
-                g_debug ("wheel group not found");
+                g_debug ("sudo group not found");
                 return ACCOUNT_TYPE_STANDARD;
         }
-        wheel = grp->gr_gid;
+        sudo = grp->gr_gid;
+
+        /* Ubuntu prior to 12.04 used "admin" */
+        grp = getgrnam ("admin");
+        if (grp == NULL) {
+                g_debug ("admin group not found");
+                admin = -1;
+        } else {
+                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] == sudo || groups[i] == admin) {
                         g_free (groups);
                         return ACCOUNT_TYPE_ADMINISTRATOR;
                 }
@@ -1250,7 +1260,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];
@@ -1260,24 +1270,24 @@ user_change_account_type_authorized_cb (
                          "change account type of user '%s' (%d) to %d",
                          user->user_name, user->uid, account_type);
 
-                grp = getgrnam ("wheel");
+                grp = getgrnam ("sudo");
                 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: sudo 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
@@ -270,3 +270,45 @@ get_caller_uid (GDBusMethodInvocation *c
 
         return TRUE;
 }
+
+void
+add_user_to_group (DBusGMethodInvocation *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 (DBusGMethodInvocation *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 (DBusGMethodInvocation *context,
+                        const char *user_name,
+                        const char *group_name);
+
+void remove_user_from_group (DBusGMethodInvocation *context,
+                             const char *user_name,
+                             const char *group_name);
+
+
 G_END_DECLS
 
 #endif /* __UTIL_H__ */
