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)
downloadpoky-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 @@
2# we need a function to reformat the params based on a static file 2# we need a function to reformat the params based on a static file
3def update_useradd_static_config(d): 3def update_useradd_static_config(d):
4 import argparse 4 import argparse
5 import itertools
5 import re 6 import re
6 7
7 class myArgumentParser( argparse.ArgumentParser ): 8 class myArgumentParser( argparse.ArgumentParser ):
@@ -16,6 +17,11 @@ def update_useradd_static_config(d):
16 def error(self, message): 17 def error(self, message):
17 raise bb.build.FuncFailed(message) 18 raise bb.build.FuncFailed(message)
18 19
20 def list_extend(iterable, length, obj = None):
21 """Ensure that iterable is the specified length by extending with obj
22 and return it as a list"""
23 return list(itertools.islice(itertools.chain(iterable, itertools.repeat(obj)), length))
24
19 # We parse and rewrite the useradd components 25 # We parse and rewrite the useradd components
20 def rewrite_useradd(params): 26 def rewrite_useradd(params):
21 # The following comes from --help on useradd from shadow 27 # The following comes from --help on useradd from shadow
@@ -84,7 +90,10 @@ def update_useradd_static_config(d):
84 for line in f: 90 for line in f:
85 if line.startswith('#'): 91 if line.startswith('#'):
86 continue 92 continue
87 field = line.rstrip().split(":") 93 # Make sure there always are at least seven elements in
94 # the field list. This allows for leaving out trailing
95 # colons in the passwd file.
96 field = list_extend(line.rstrip().split(":"), 7)
88 if field[0] == uaargs.LOGIN: 97 if field[0] == uaargs.LOGIN:
89 if uaargs.uid and field[2] and (uaargs.uid != field[2]): 98 if uaargs.uid and field[2] and (uaargs.uid != field[2]):
90 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])) 99 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):
220 for line in f: 229 for line in f:
221 if line.startswith('#'): 230 if line.startswith('#'):
222 continue 231 continue
223 field = line.rstrip().split(":") 232 # Make sure there always are at least four elements in
233 # the field list. This allows for leaving out trailing
234 # colons in the group file.
235 field = list_extend(line.rstrip().split(":"), 4)
224 if field[0] == gaargs.GROUP and field[2]: 236 if field[0] == gaargs.GROUP and field[2]:
225 if gaargs.gid and (gaargs.gid != field[2]): 237 if gaargs.gid and (gaargs.gid != field[2]):
226 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])) 238 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]))