summaryrefslogtreecommitdiffstats
path: root/meta/classes/useradd-staticids.bbclass
diff options
context:
space:
mode:
authorPeter Kjellerstedt <peter.kjellerstedt@axis.com>2015-10-24 11:50:17 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-10-29 07:31:16 +0000
commit1c3c76d78fd6261ef1919e87e5b19b0410ee976a (patch)
treef15b37ccfe5bee6b18f2587504972a676aca9fe7 /meta/classes/useradd-staticids.bbclass
parent8a0d8eee432924433c3e70198aaeab3161476c5f (diff)
downloadopenembedded-core-contrib-1c3c76d78fd6261ef1919e87e5b19b0410ee976a.tar.gz
useradd-staticids.bbclass: Do not require trailing colons
Before, the users and groups specified in the passwd file and the groups file had to have trailing colons to make sure there were enough elements in the definitions, or bitbake would throw a Python exception. After this change one can omit the trailing colons, which especially simplifies passwd files used only to specify static UIDs. (From OE-Core rev: 7754e0f71eb794f0e06a1b005e3824fac4cdac6c) Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/useradd-staticids.bbclass')
-rw-r--r--meta/classes/useradd-staticids.bbclass16
1 files changed, 14 insertions, 2 deletions
diff --git a/meta/classes/useradd-staticids.bbclass b/meta/classes/useradd-staticids.bbclass
index 421a70a6ab..924d6eae60 100644
--- a/meta/classes/useradd-staticids.bbclass
+++ b/meta/classes/useradd-staticids.bbclass
@@ -2,6 +2,7 @@
# we need a function to reformat the params based on a static file
def update_useradd_static_config(d):
import argparse
+ import itertools
import re
class myArgumentParser( argparse.ArgumentParser ):
@@ -16,6 +17,11 @@ def update_useradd_static_config(d):
def error(self, message):
raise bb.build.FuncFailed(message)
+ def list_extend(iterable, length, obj = None):
+ """Ensure that iterable is the specified length by extending with obj
+ and return it as a list"""
+ return list(itertools.islice(itertools.chain(iterable, itertools.repeat(obj)), length))
+
# We parse and rewrite the useradd components
def rewrite_useradd(params):
# The following comes from --help on useradd from shadow
@@ -84,7 +90,10 @@ def update_useradd_static_config(d):
for line in f:
if line.startswith('#'):
continue
- field = line.rstrip().split(":")
+ # Make sure there always are at least seven elements in
+ # the field list. This allows for leaving out trailing
+ # colons in the passwd file.
+ field = list_extend(line.rstrip().split(":"), 7)
if field[0] == uaargs.LOGIN:
if uaargs.uid and field[2] and (uaargs.uid != field[2]):
bb.warn("%s: Changing username %s's uid from (%s) to (%s), verify configuration files!" % (d.getVar('PN', True), uaargs.LOGIN, uaargs.uid, field[2]))
@@ -220,7 +229,10 @@ def update_useradd_static_config(d):
for line in f:
if line.startswith('#'):
continue
- field = line.rstrip().split(":")
+ # Make sure there always are at least four elements in
+ # the field list. This allows for leaving out trailing
+ # colons in the group file.
+ field = list_extend(line.rstrip().split(":"), 4)
if field[0] == gaargs.GROUP and field[2]:
if gaargs.gid and (gaargs.gid != field[2]):
bb.warn("%s: Changing groupname %s's gid from (%s) to (%s), verify configuration files!" % (d.getVar('PN', True), gaargs.GROUP, gaargs.gid, field[2]))