]> code.ossystems Code Review - openembedded-core.git/commitdiff
useradd-staticids: Fix groupadd when --user-group is selected
authorMark Hatle <mark.hatle@windriver.com>
Mon, 10 Feb 2014 19:28:25 +0000 (13:28 -0600)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Tue, 11 Feb 2014 12:03:31 +0000 (12:03 +0000)
When --user-group is selected (it's on by default as well) we want
to translate that to a groupname and disable the --user-group.  Before
we just disabled --user-group, but didn't always add the group to the
system.

This change ensures that we add the group (as long as we have enough
information to actually add the group), and we disable --user-group
in that case.  If a static groupid is not specified we continue to
use the groupname, but via an explicit groupadd.

Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes/useradd-staticids.bbclass

index 689c29c53f9a0c6d4cb1b8d8b92b91352d7cf33b..5897fed20d58fb53e82550ffbf078f8270e25590 100644 (file)
@@ -96,27 +96,37 @@ def update_useradd_static_config(d):
                             # is used, and we disable the user_group option.
                             #
                             uaargs.groupname = [uaargs.gid, uaargs.LOGIN][not uaargs.gid or uaargs.user_group]
-                            uaargs.user_group = False
+                            uaargs.groupid = [uaargs.gid, uaargs.groupname][not uaargs.gid]
+                            uaargs.groupid = [field[3], uaargs.groupid][not field[3]]
 
-                            uaargs.gid = [uaargs.gid, uaargs.groupname][not uaargs.gid]
-                            uaargs.gid = [field[3], uaargs.gid][not field[3]]
-
-                            if uaargs.groupname == uaargs.gid:
-                                # Nothing to do...
-                                pass
-                            elif (uaargs.groupname and uaargs.groupname.isdigit()) and (uaargs.gid and uaargs.gid.isdigit()) and (uaargs.groupname != uaargs.gid):
-                                # We want to add a group, but we don't know it's name... so we can't add the group...
-                                # We have to assume the group has previously been added or we'll fail on the adduser...
-                                # Note: specifying the actual gid is very rare in OE, usually the group name is specified.
-                                bb.warn("%s: Changing gid for login %s from (%s) to (%s), verify configuration files!" % (d.getVar('PN', True), uaargs.LOGIN, uaargs.groupname, uaargs.gid))
-                            elif uaargs.groupname and (uaargs.gid and uaargs.gid.isdigit()):
-                               bb.debug(1, "Adding group %s  gid (%s)!" % (uaargs.groupname, uaargs.gid))
-                               groupadd = d.getVar("GROUPADD_PARAM_%s" % pkg, True)
-                               newgroup = "-g %s %s" % (uaargs.gid, uaargs.groupname)
-                               if groupadd:
-                                   d.setVar("GROUPADD_PARAM_%s" % pkg, "%s ; %s" % (groupadd, newgroup))
-                               else:
-                                   d.setVar("GROUPADD_PARAM_%s" % pkg, newgroup)
+                            if not uaargs.gid or uaargs.gid != uaargs.groupid:
+                                if (uaargs.groupid and uaargs.groupid.isdigit()) and (uaargs.groupname and uaargs.groupname.isdigit()) and (uaargs.groupid != uaargs.groupname):
+                                    # We want to add a group, but we don't know it's name... so we can't add the group...
+                                    # We have to assume the group has previously been added or we'll fail on the adduser...
+                                    # Note: specifying the actual gid is very rare in OE, usually the group name is specified.
+                                    bb.warn("%s: Changing gid for login %s from (%s) to (%s), verify configuration files!" % (d.getVar('PN', True), uaargs.LOGIN, uaargs.groupname, uaargs.gid))
+                                elif (uaargs.groupid and not uaargs.groupid.isdigit()) and uaargs.groupid == uaargs.groupname:
+                                    # We don't have a number, so we have to add a name
+                                    bb.debug(1, "Adding group %s!" % (uaargs.groupname))
+                                    uaargs.gid = uaargs.groupid
+                                    uaargs.user_group = False
+                                    groupadd = d.getVar("GROUPADD_PARAM_%s" % pkg, True)
+                                    newgroup = "%s %s" % (['', ' --system'][uaargs.system], uaargs.groupname)
+                                    if groupadd:
+                                        d.setVar("GROUPADD_PARAM_%s" % pkg, "%s ; %s" % (groupadd, newgroup))
+                                    else:
+                                        d.setVar("GROUPADD_PARAM_%s" % pkg, newgroup)
+                                elif uaargs.groupname and (uaargs.groupid and uaargs.groupid.isdigit()):
+                                    # We have a group name and a group number to assign it to
+                                    bb.debug(1, "Adding group %s  gid (%s)!" % (uaargs.groupname, uaargs.groupid))
+                                    uaargs.gid = uaargs.groupid
+                                    uaargs.user_group = False
+                                    groupadd = d.getVar("GROUPADD_PARAM_%s" % pkg, True)
+                                    newgroup = "-g %s %s" % (uaargs.gid, uaargs.groupname)
+                                    if groupadd:
+                                        d.setVar("GROUPADD_PARAM_%s" % pkg, "%s ; %s" % (groupadd, newgroup))
+                                    else:
+                                        d.setVar("GROUPADD_PARAM_%s" % pkg, newgroup)
 
                             uaargs.comment = ["'%s'" % field[4], uaargs.comment][not field[4]]
                             uaargs.home_dir = [field[5], uaargs.home_dir][not field[5]]