summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Kjellerstedt <peter.kjellerstedt@axis.com>2015-12-19 00:53:50 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-01-17 11:32:20 +0000
commite98e98ce65cf9ffdef29462310a622ffddd1412b (patch)
treecab81d054bec23cce1c25a19c52227df48f9fcd3
parent274d38a6e2183ec88335a08b963f26c34b328558 (diff)
downloadopenembedded-core-e98e98ce65cf9ffdef29462310a622ffddd1412b.tar.gz
openembedded-core-e98e98ce65cf9ffdef29462310a622ffddd1412b.tar.bz2
openembedded-core-e98e98ce65cf9ffdef29462310a622ffddd1412b.zip
useradd-staticids.bbclass: Simplify the logic for when to add groups
The original code was near impossible to follow, and missed a couple of cases. For example, if one added the following line to the passwd file specified in USERADD_UID_TABLES: foobar:x:12345:nogroup::/:/bin/sh and then specified the user as: USERADD_PARAM_${PN} = "--system foobar" one would then assume that the foobar user would be created with the primary group set to nogroup. However, it was not (the primary group would be foobar), and the only way to get it correct was to explicitly add --gid nogroup to the USERADD_PARAM_${PN}. Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/classes/useradd-staticids.bbclass36
1 files changed, 16 insertions, 20 deletions
diff --git a/meta/classes/useradd-staticids.bbclass b/meta/classes/useradd-staticids.bbclass
index 0e855e91c7..df4902ee9a 100644
--- a/meta/classes/useradd-staticids.bbclass
+++ b/meta/classes/useradd-staticids.bbclass
@@ -110,30 +110,26 @@ def update_useradd_static_config(d):
uaargs.groupname = uaargs.LOGIN if user_group else uaargs.gid
uaargs.groupid = field[3] or uaargs.gid or uaargs.groupname
- 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):
+ if uaargs.groupid and uaargs.gid != uaargs.groupid:
+ newgroup = None
+ if not uaargs.groupid.isdigit():
+ # We don't have a group number, so we have to add a name
+ bb.debug(1, "Adding group %s!" % uaargs.groupid)
+ newgroup = "%s %s" % (' --system' if uaargs.system else '', uaargs.groupid)
+ elif uaargs.groupname and not uaargs.groupname.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))
+ newgroup = "-g %s %s" % (uaargs.groupid, uaargs.groupname)
+ else:
# 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 = None
- groupadd = d.getVar("GROUPADD_PARAM_%s" % pkg, True)
- newgroup = "%s %s" % (' --system' if uaargs.system else '', 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 = None
+ bb.warn("%s: Changing gid for login %s to %s, verify configuration files!" % (d.getVar('PN', True), uaargs.LOGIN, uaargs.groupid))
+
+ uaargs.gid = uaargs.groupid
+ uaargs.user_group = None
+ if newgroup:
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: