added support for new user primary group name in conf
authorImran Zaman <imran.zaman@intel.com>
Mon, 8 Sep 2014 13:14:07 +0000 (16:14 +0300)
committerImran Zaman <imran.zaman@intel.com>
Mon, 8 Sep 2014 13:14:07 +0000 (16:14 +0300)
dists/debian/changelog
dists/rpm/gum-suse.spec
dists/rpm/tizen/packaging/gumd-tizen.conf
dists/rpm/tizen/packaging/gumd.changes
dists/rpm/tizen/packaging/gumd.spec
include/gum/common/gum-config-general.h
src/common/gum-config.c
src/daemon/gumd-daemon-group.c
src/daemon/gumd-daemon-user.c
src/daemon/gumd.conf.in
test/data/gumd.conf

index ed3151d..90ff3dc 100644 (file)
@@ -1,8 +1,14 @@
+gumd (0.0.4-5) unstable; urgency=low
+
+  * Added primary group name for new user in the configuration file
+
+ -- Imran Zaman <imran.zaman@intel.com>  Mon, 08 Sep  2014 18:00:03 +0300
+
 gumd (0.0.4-4) unstable; urgency=low
 
   * Fixed bug TC-1580 which fixes user's folder and file access permissions
 
- -- Imran Zaman <imran.zaman@intel.com>  Tue, 26 Aug  2014 18:00:03 +0300
+ -- Imran Zaman <imran.zaman@intel.com>  Fri, 05 Sep  2014 18:00:03 +0300
 
 gumd (0.0.4-3) unstable; urgency=low
 
index cacccb2..acc824f 100644 (file)
@@ -8,7 +8,7 @@
 Name: gumd
 Summary: User management daemon and client library
 Version: 0.0.4
-Release: 3
+Release: 5
 Group: System/Daemons
 License: LGPL-2.1+
 Source: %{name}-%{version}.tar.gz
@@ -135,6 +135,9 @@ mkdir -p %{_sysconfdir}/%{name}/groupdel.d
 
 
 %changelog
+* Mon Sep 08 2014 Imran Zaman <imran.zaman@intel.com>
+- Added primary group name for new user in the configuration file
+
 * Fri Sep 05 2014 Imran Zaman <imran.zaman@intel.com>
 - Fixed bug TC-1580 which fixes user's folder and file access permissions
 
index 4a956c3..1022ef3 100644 (file)
@@ -7,6 +7,11 @@
 #
 [General]
 
+# Primary group name for the new user. If the primary group does not
+# exist, it will be created otherwise user gid will be set accordingly.
+# Default primary group name is same as name of the user.
+USR_PRIMARY_GRPNAME=users
+
 # Comma separate listed of groups, which every user (other than system user)
 # will be added to at the time of user account creation. Default value is:
 # ''
index ff2677b..6485c7f 100644 (file)
@@ -1,3 +1,6 @@
+* Mon Sep 08 2014 Imran Zaman <imran.zaman@intel.com>
+- Added primary group name for new user in the configuration file
+
 * Fri Sep 05 2014 Imran Zaman <imran.zaman@intel.com>
 - Fixed bug TC-1580 which fixes user's folder and file access permissions
 
index 793dcc4..163950c 100644 (file)
@@ -7,7 +7,7 @@
 Name: gumd
 Summary: User management daemon and client library
 Version: 0.0.4
-Release: 4
+Release: 5
 Group: Security/Accounts
 License: LGPL-2.1+
 Source: %{name}-%{version}.tar.gz
index 3d0d6f0..1ee49bb 100644 (file)
                                               "/DEFAULT_USR_GROUPS"
 
 /**
+ * GUM_CONFIG_GENERAL_USR_PRIMARY_GRPNAME:
+ *
+ * Primary group name for the new user. If the primary group does not
+ * exist, it will be created otherwise user gid will be set accordingly.
+ * Default primary group name is same as name of the user.
+ */
+#define GUM_CONFIG_GENERAL_USR_PRIMARY_GRPNAME   GUM_CONFIG_GENERAL \
+                                              "/USR_PRIMARY_GRPNAME"
+
+/**
  * GUM_CONFIG_GENERAL_DEF_ADMIN_GROUPS:
  *
  * Comma separate listed of groups, which admin user will be added to at the
index d4478f0..f509ebc 100644 (file)
@@ -148,8 +148,7 @@ _load_config (
     }
 
     if (!self->priv->config_file_path) {
-        gchar *filename = g_build_filename ("%s/gumd/%s", GUM_SYSCONF_DIR,
-                "gumd.conf", NULL);
+        gchar *filename = g_strdup_printf ("%s/gumd", GUM_SYSCONF_DIR);
         self->priv->config_file_path = _check_config_file (filename);
         g_free (filename);
     }
@@ -172,8 +171,7 @@ _load_config (
 #   ifndef GUM_SYSCONF_DIR
 #   error "System configuration directory not defined!"
 #   endif
-    gchar *filename = g_build_filename ("%s/gumd/%s", GUM_SYSCONF_DIR,
-            "gumd.conf", NULL);
+    gchar *filename = g_strdup_printf ("%s/gumd", GUM_SYSCONF_DIR);
     self->priv->config_file_path = _check_config_file (filename);
     g_free (filename);
 #   endif  /* ENABLE_DEBUG */
index 226a225..da4e23d 100644 (file)
@@ -527,7 +527,7 @@ _update_gshadow_entry (
                 if (g_strcmp0 (self->priv->gshadow->sg_namp,
                         entry->sg_namp) == 0) {
                     GUM_RETURN_WITH_ERROR (GUM_ERROR_GROUP_ALREADY_EXISTS,
-                            "File write failure", error, FALSE);
+                            "Group already exists", error, FALSE);
                 }
                 break;
             case GUM_OPTYPE_DELETE:
index 90b5270..d787ed3 100644 (file)
@@ -1079,9 +1079,11 @@ _set_group (
         GumdDaemonUser *self,
         GError **error)
 {
-    gboolean added = FALSE;
+    gboolean group_exists = FALSE;
     GumdDaemonGroup *group = NULL;
     gid_t gid = GUM_GROUP_INVALID_GID;
+    const gchar *primary_gname = NULL;
+    struct group *grp = NULL;
 
     group = gumd_daemon_group_new (self->priv->config);
     if (!group) {
@@ -1091,17 +1093,33 @@ _set_group (
 
     GumGroupType grp_type = self->priv->user_type == GUM_USERTYPE_SYSTEM ?
             GUM_GROUPTYPE_SYSTEM : GUM_GROUPTYPE_USER;
-    g_object_set (G_OBJECT(group), "groupname", self->priv->pw->pw_name,
-            "grouptype", grp_type, NULL);
-    if (!(added = gumd_daemon_group_add (group, (gid_t)self->priv->pw->pw_uid,
-            &gid, error))) {
-        goto _finished;
+
+    primary_gname = gum_config_get_string (self->priv->config,
+            GUM_CONFIG_GENERAL_USR_PRIMARY_GRPNAME);
+    if (primary_gname) {
+        grp = gum_file_getgrnam (primary_gname,
+                gum_config_get_string (self->priv->config,
+                        GUM_CONFIG_GENERAL_GROUP_FILE));
+    }
+
+    if (!grp) {
+        g_object_set (G_OBJECT(group), "groupname",
+                primary_gname ? primary_gname : self->priv->pw->pw_name,
+                        "grouptype", grp_type, NULL);
+        if (!(group_exists = gumd_daemon_group_add (group,
+                (gid_t)self->priv->pw->pw_uid, &gid, error))) {
+            goto _finished;
+        }
+    } else {
+        gid = grp->gr_gid;
+        group_exists = TRUE;
     }
+
     _set_gid_property (self, gid);
 
 _finished:
     g_object_unref (group);
-    return added;
+    return group_exists;
 }
 
 gboolean
index 51c1aa4..49904c9 100644 (file)
@@ -7,6 +7,11 @@
 #
 [General]
 
+# Primary group name for the new user. If the primary group does not
+# exist, it will be created otherwise user gid will be set accordingly.
+# Default primary group name is same as name of the user.
+#USR_PRIMARY_GRPNAME=users
+
 # Comma separate listed of groups, which every user (other than system user)
 # will be added to at the time of user account creation. Default value is:
 # ''
index bfe1fa8..2943890 100644 (file)
 # ''
 DEFAULT_USR_GROUPS=
 
+# Primary group name for the new user. If the primary group does not
+# exist, it will be created otherwise user gid will be set accordingly.
+# Default primary group name is same as name of the user.
+#USR_PRIMARY_GRPNAME=users
+
 # Comma separate listed of groups, which admin user will be added to at the
 # time of user account creation. Default value is: ''
 #DEFAULT_ADMIN_GROUPS=