From c04a8cc42ec311586c51b09c5bfeab32f80ed52d Mon Sep 17 00:00:00 2001 From: Imran Zaman Date: Mon, 8 Sep 2014 16:14:07 +0300 Subject: [PATCH] added support for new user primary group name in conf --- dists/debian/changelog | 8 +++++++- dists/rpm/gum-suse.spec | 5 ++++- dists/rpm/tizen/packaging/gumd-tizen.conf | 5 +++++ dists/rpm/tizen/packaging/gumd.changes | 3 +++ dists/rpm/tizen/packaging/gumd.spec | 2 +- include/gum/common/gum-config-general.h | 10 ++++++++++ src/common/gum-config.c | 6 ++---- src/daemon/gumd-daemon-group.c | 2 +- src/daemon/gumd-daemon-user.c | 32 ++++++++++++++++++++++++------- src/daemon/gumd.conf.in | 5 +++++ test/data/gumd.conf | 5 +++++ 11 files changed, 68 insertions(+), 15 deletions(-) diff --git a/dists/debian/changelog b/dists/debian/changelog index ed3151d..90ff3dc 100644 --- a/dists/debian/changelog +++ b/dists/debian/changelog @@ -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 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 Tue, 26 Aug 2014 18:00:03 +0300 + -- Imran Zaman Fri, 05 Sep 2014 18:00:03 +0300 gumd (0.0.4-3) unstable; urgency=low diff --git a/dists/rpm/gum-suse.spec b/dists/rpm/gum-suse.spec index cacccb2..acc824f 100644 --- a/dists/rpm/gum-suse.spec +++ b/dists/rpm/gum-suse.spec @@ -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 +- Added primary group name for new user in the configuration file + * Fri Sep 05 2014 Imran Zaman - Fixed bug TC-1580 which fixes user's folder and file access permissions diff --git a/dists/rpm/tizen/packaging/gumd-tizen.conf b/dists/rpm/tizen/packaging/gumd-tizen.conf index 4a956c3..1022ef3 100644 --- a/dists/rpm/tizen/packaging/gumd-tizen.conf +++ b/dists/rpm/tizen/packaging/gumd-tizen.conf @@ -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: # '' diff --git a/dists/rpm/tizen/packaging/gumd.changes b/dists/rpm/tizen/packaging/gumd.changes index ff2677b..6485c7f 100644 --- a/dists/rpm/tizen/packaging/gumd.changes +++ b/dists/rpm/tizen/packaging/gumd.changes @@ -1,3 +1,6 @@ +* Mon Sep 08 2014 Imran Zaman +- Added primary group name for new user in the configuration file + * Fri Sep 05 2014 Imran Zaman - Fixed bug TC-1580 which fixes user's folder and file access permissions diff --git a/dists/rpm/tizen/packaging/gumd.spec b/dists/rpm/tizen/packaging/gumd.spec index 793dcc4..163950c 100644 --- a/dists/rpm/tizen/packaging/gumd.spec +++ b/dists/rpm/tizen/packaging/gumd.spec @@ -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 diff --git a/include/gum/common/gum-config-general.h b/include/gum/common/gum-config-general.h index 3d0d6f0..1ee49bb 100644 --- a/include/gum/common/gum-config-general.h +++ b/include/gum/common/gum-config-general.h @@ -54,6 +54,16 @@ "/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 diff --git a/src/common/gum-config.c b/src/common/gum-config.c index d4478f0..f509ebc 100644 --- a/src/common/gum-config.c +++ b/src/common/gum-config.c @@ -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 */ diff --git a/src/daemon/gumd-daemon-group.c b/src/daemon/gumd-daemon-group.c index 226a225..da4e23d 100644 --- a/src/daemon/gumd-daemon-group.c +++ b/src/daemon/gumd-daemon-group.c @@ -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: diff --git a/src/daemon/gumd-daemon-user.c b/src/daemon/gumd-daemon-user.c index 90b5270..d787ed3 100644 --- a/src/daemon/gumd-daemon-user.c +++ b/src/daemon/gumd-daemon-user.c @@ -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 diff --git a/src/daemon/gumd.conf.in b/src/daemon/gumd.conf.in index 51c1aa4..49904c9 100644 --- a/src/daemon/gumd.conf.in +++ b/src/daemon/gumd.conf.in @@ -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: # '' diff --git a/test/data/gumd.conf b/test/data/gumd.conf index bfe1fa8..2943890 100644 --- a/test/data/gumd.conf +++ b/test/data/gumd.conf @@ -12,6 +12,11 @@ # '' 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= -- 2.7.4