diff options
-rw-r--r-- | meta/classes/useradd-staticids.bbclass | 62 |
1 files changed, 29 insertions, 33 deletions
diff --git a/meta/classes/useradd-staticids.bbclass b/meta/classes/useradd-staticids.bbclass index 3d0bc09148..589a99ff45 100644 --- a/meta/classes/useradd-staticids.bbclass +++ b/meta/classes/useradd-staticids.bbclass | |||
@@ -38,10 +38,14 @@ def update_useradd_static_config(d): | |||
38 | 38 | ||
39 | return id_table | 39 | return id_table |
40 | 40 | ||
41 | def handle_missing_id(id, type, pkg): | 41 | def handle_missing_id(id, type, pkg, files, var, value): |
42 | # For backwards compatibility we accept "1" in addition to "error" | 42 | # For backwards compatibility we accept "1" in addition to "error" |
43 | error_dynamic = d.getVar('USERADD_ERROR_DYNAMIC') | 43 | error_dynamic = d.getVar('USERADD_ERROR_DYNAMIC') |
44 | msg = "%s - %s: %sname %s does not have a static ID defined." % (d.getVar('PN'), pkg, type, id) | 44 | msg = "%s - %s: %sname %s does not have a static ID defined." % (d.getVar('PN'), pkg, type, id) |
45 | if files: | ||
46 | msg += " Add %s to one of these files: %s" % (id, files) | ||
47 | else: | ||
48 | msg += " %s file(s) not found in BBPATH: %s" % (var, value) | ||
45 | if error_dynamic == 'error' or error_dynamic == '1': | 49 | if error_dynamic == 'error' or error_dynamic == '1': |
46 | raise NotImplementedError(msg) | 50 | raise NotImplementedError(msg) |
47 | elif error_dynamic == 'warn': | 51 | elif error_dynamic == 'warn': |
@@ -49,23 +53,24 @@ def update_useradd_static_config(d): | |||
49 | elif error_dynamic == 'skip': | 53 | elif error_dynamic == 'skip': |
50 | raise bb.parse.SkipRecipe(msg) | 54 | raise bb.parse.SkipRecipe(msg) |
51 | 55 | ||
56 | # Return a list of configuration files based on either the default | ||
57 | # files/group or the contents of USERADD_GID_TABLES, resp. | ||
58 | # files/passwd for USERADD_UID_TABLES. | ||
59 | # Paths are resolved via BBPATH. | ||
60 | def get_table_list(d, var, default): | ||
61 | files = [] | ||
62 | bbpath = d.getVar('BBPATH', True) | ||
63 | tables = d.getVar(var, True) | ||
64 | if not tables: | ||
65 | tables = default | ||
66 | for conf_file in tables.split(): | ||
67 | files.append(bb.utils.which(bbpath, conf_file)) | ||
68 | return (' '.join(files), var, default) | ||
69 | |||
52 | # We parse and rewrite the useradd components | 70 | # We parse and rewrite the useradd components |
53 | def rewrite_useradd(params, is_pkg): | 71 | def rewrite_useradd(params, is_pkg): |
54 | parser = oe.useradd.build_useradd_parser() | 72 | parser = oe.useradd.build_useradd_parser() |
55 | 73 | ||
56 | # Return a list of configuration files based on either the default | ||
57 | # files/passwd or the contents of USERADD_UID_TABLES | ||
58 | # paths are resolved via BBPATH | ||
59 | def get_passwd_list(d): | ||
60 | str = "" | ||
61 | bbpath = d.getVar('BBPATH') | ||
62 | passwd_tables = d.getVar('USERADD_UID_TABLES') | ||
63 | if not passwd_tables: | ||
64 | passwd_tables = 'files/passwd' | ||
65 | for conf_file in passwd_tables.split(): | ||
66 | str += " %s" % bb.utils.which(bbpath, conf_file) | ||
67 | return str | ||
68 | |||
69 | newparams = [] | 74 | newparams = [] |
70 | users = None | 75 | users = None |
71 | for param in oe.useradd.split_commands(params): | 76 | for param in oe.useradd.split_commands(params): |
@@ -86,10 +91,12 @@ def update_useradd_static_config(d): | |||
86 | # all new users get the default ('*' which prevents login) until the user is | 91 | # all new users get the default ('*' which prevents login) until the user is |
87 | # specifically configured by the system admin. | 92 | # specifically configured by the system admin. |
88 | if not users: | 93 | if not users: |
89 | users = merge_files(get_passwd_list(d), 7) | 94 | files, table_var, table_value = get_table_list(d, 'USERADD_UID_TABLES', 'files/passwd') |
95 | users = merge_files(files, 7) | ||
90 | 96 | ||
97 | type = 'system user' if uaargs.system else 'normal user' | ||
91 | if uaargs.LOGIN not in users: | 98 | if uaargs.LOGIN not in users: |
92 | handle_missing_id(uaargs.LOGIN, 'user', pkg) | 99 | handle_missing_id(uaargs.LOGIN, type, pkg, files, table_var, table_value) |
93 | newparams.append(param) | 100 | newparams.append(param) |
94 | continue | 101 | continue |
95 | 102 | ||
@@ -147,7 +154,7 @@ def update_useradd_static_config(d): | |||
147 | 154 | ||
148 | # Should be an error if a specific option is set... | 155 | # Should be an error if a specific option is set... |
149 | if not uaargs.uid or not uaargs.uid.isdigit() or not uaargs.gid: | 156 | if not uaargs.uid or not uaargs.uid.isdigit() or not uaargs.gid: |
150 | handle_missing_id(uaargs.LOGIN, 'user', pkg) | 157 | handle_missing_id(uaargs.LOGIN, type, pkg, files, table_var, table_value) |
151 | 158 | ||
152 | # Reconstruct the args... | 159 | # Reconstruct the args... |
153 | newparam = ['', ' --defaults'][uaargs.defaults] | 160 | newparam = ['', ' --defaults'][uaargs.defaults] |
@@ -184,19 +191,6 @@ def update_useradd_static_config(d): | |||
184 | def rewrite_groupadd(params, is_pkg): | 191 | def rewrite_groupadd(params, is_pkg): |
185 | parser = oe.useradd.build_groupadd_parser() | 192 | parser = oe.useradd.build_groupadd_parser() |
186 | 193 | ||
187 | # Return a list of configuration files based on either the default | ||
188 | # files/group or the contents of USERADD_GID_TABLES | ||
189 | # paths are resolved via BBPATH | ||
190 | def get_group_list(d): | ||
191 | str = "" | ||
192 | bbpath = d.getVar('BBPATH') | ||
193 | group_tables = d.getVar('USERADD_GID_TABLES') | ||
194 | if not group_tables: | ||
195 | group_tables = 'files/group' | ||
196 | for conf_file in group_tables.split(): | ||
197 | str += " %s" % bb.utils.which(bbpath, conf_file) | ||
198 | return str | ||
199 | |||
200 | newparams = [] | 194 | newparams = [] |
201 | groups = None | 195 | groups = None |
202 | for param in oe.useradd.split_commands(params): | 196 | for param in oe.useradd.split_commands(params): |
@@ -216,10 +210,12 @@ def update_useradd_static_config(d): | |||
216 | # Note: similar to the passwd file, the 'password' filed is ignored | 210 | # Note: similar to the passwd file, the 'password' filed is ignored |
217 | # Note: group_members is ignored, group members must be configured with the GROUPMEMS_PARAM | 211 | # Note: group_members is ignored, group members must be configured with the GROUPMEMS_PARAM |
218 | if not groups: | 212 | if not groups: |
219 | groups = merge_files(get_group_list(d), 4) | 213 | files, table_var, table_value = get_table_list(d, 'USERADD_GID_TABLES', 'files/group') |
214 | groups = merge_files(files, 4) | ||
220 | 215 | ||
216 | type = 'system group' if gaargs.system else 'normal group' | ||
221 | if gaargs.GROUP not in groups: | 217 | if gaargs.GROUP not in groups: |
222 | handle_missing_id(gaargs.GROUP, 'group', pkg) | 218 | handle_missing_id(gaargs.GROUP, type, pkg, files, table_var, table_value) |
223 | newparams.append(param) | 219 | newparams.append(param) |
224 | continue | 220 | continue |
225 | 221 | ||
@@ -231,7 +227,7 @@ def update_useradd_static_config(d): | |||
231 | gaargs.gid = field[2] | 227 | gaargs.gid = field[2] |
232 | 228 | ||
233 | if not gaargs.gid or not gaargs.gid.isdigit(): | 229 | if not gaargs.gid or not gaargs.gid.isdigit(): |
234 | handle_missing_id(gaargs.GROUP, 'group', pkg) | 230 | handle_missing_id(gaargs.GROUP, type, pkg, files, table_var, table_value) |
235 | 231 | ||
236 | # Reconstruct the args... | 232 | # Reconstruct the args... |
237 | newparam = ['', ' --force'][gaargs.force] | 233 | newparam = ['', ' --force'][gaargs.force] |