blob: 6ebf7600f611803f05412bca4220b40463ba30e8 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# In order to support a deterministic set of 'dynamic' users/groups,
2# we need a function to reformat the params based on a static file
3def update_useradd_static_config(d):
4 import argparse
Patrick Williamsf1e5d692016-03-30 15:21:19 -05005 import itertools
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006 import re
Patrick Williamsc0f7c042017-02-23 20:41:17 -06007 import errno
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008
9 class myArgumentParser( argparse.ArgumentParser ):
10 def _print_message(self, message, file=None):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011 bb.warn("%s - %s: %s" % (d.getVar('PN'), pkg, message))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012
13 # This should never be called...
14 def exit(self, status=0, message=None):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050015 message = message or ("%s - %s: useradd.bbclass: Argument parsing exited" % (d.getVar('PN'), pkg))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050016 error(message)
17
18 def error(self, message):
Patrick Williamsc0f7c042017-02-23 20:41:17 -060019 bb.fatal(message)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050020
Patrick Williamsf1e5d692016-03-30 15:21:19 -050021 def list_extend(iterable, length, obj = None):
22 """Ensure that iterable is the specified length by extending with obj
23 and return it as a list"""
24 return list(itertools.islice(itertools.chain(iterable, itertools.repeat(obj)), length))
25
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050026 def merge_files(file_list, exp_fields):
27 """Read each passwd/group file in file_list, split each line and create
28 a dictionary with the user/group names as keys and the split lines as
29 values. If the user/group name already exists in the dictionary, then
30 update any fields in the list with the values from the new list (if they
31 are set)."""
32 id_table = dict()
33 for conf in file_list.split():
Patrick Williamsc0f7c042017-02-23 20:41:17 -060034 try:
35 with open(conf, "r") as f:
36 for line in f:
37 if line.startswith('#'):
38 continue
39 # Make sure there always are at least exp_fields
40 # elements in the field list. This allows for leaving
41 # out trailing colons in the files.
42 fields = list_extend(line.rstrip().split(":"), exp_fields)
43 if fields[0] not in id_table:
44 id_table[fields[0]] = fields
45 else:
46 id_table[fields[0]] = list(map(lambda x, y: x or y, fields, id_table[fields[0]]))
47 except IOError as e:
48 if e.errno == errno.ENOENT:
49 pass
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050050
51 return id_table
52
Patrick Williamsc0f7c042017-02-23 20:41:17 -060053 def handle_missing_id(id, type, pkg):
54 # For backwards compatibility we accept "1" in addition to "error"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050055 if d.getVar('USERADD_ERROR_DYNAMIC') == 'error' or d.getVar('USERADD_ERROR_DYNAMIC') == '1':
56 raise NotImplementedError("%s - %s: %sname %s does not have a static ID defined. Skipping it." % (d.getVar('PN'), pkg, type, id))
57 elif d.getVar('USERADD_ERROR_DYNAMIC') == 'warn':
58 bb.warn("%s - %s: %sname %s does not have a static ID defined." % (d.getVar('PN'), pkg, type, id))
Patrick Williamsc0f7c042017-02-23 20:41:17 -060059
Patrick Williamsc124f4f2015-09-15 14:41:29 -050060 # We parse and rewrite the useradd components
Brad Bishop6e60e8b2018-02-01 10:27:11 -050061 def rewrite_useradd(params, is_pkg):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050062 # The following comes from --help on useradd from shadow
63 parser = myArgumentParser(prog='useradd')
64 parser.add_argument("-b", "--base-dir", metavar="BASE_DIR", help="base directory for the home directory of the new account")
65 parser.add_argument("-c", "--comment", metavar="COMMENT", help="GECOS field of the new account")
66 parser.add_argument("-d", "--home-dir", metavar="HOME_DIR", help="home directory of the new account")
67 parser.add_argument("-D", "--defaults", help="print or change default useradd configuration", action="store_true")
68 parser.add_argument("-e", "--expiredate", metavar="EXPIRE_DATE", help="expiration date of the new account")
69 parser.add_argument("-f", "--inactive", metavar="INACTIVE", help="password inactivity period of the new account")
70 parser.add_argument("-g", "--gid", metavar="GROUP", help="name or ID of the primary group of the new account")
71 parser.add_argument("-G", "--groups", metavar="GROUPS", help="list of supplementary groups of the new account")
72 parser.add_argument("-k", "--skel", metavar="SKEL_DIR", help="use this alternative skeleton directory")
73 parser.add_argument("-K", "--key", metavar="KEY=VALUE", help="override /etc/login.defs defaults")
74 parser.add_argument("-l", "--no-log-init", help="do not add the user to the lastlog and faillog databases", action="store_true")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050075 parser.add_argument("-m", "--create-home", help="create the user's home directory", action="store_const", const=True)
76 parser.add_argument("-M", "--no-create-home", dest="create_home", help="do not create the user's home directory", action="store_const", const=False)
77 parser.add_argument("-N", "--no-user-group", dest="user_group", help="do not create a group with the same name as the user", action="store_const", const=False)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050078 parser.add_argument("-o", "--non-unique", help="allow to create users with duplicate (non-unique UID)", action="store_true")
79 parser.add_argument("-p", "--password", metavar="PASSWORD", help="encrypted password of the new account")
Brad Bishop6e60e8b2018-02-01 10:27:11 -050080 parser.add_argument("-P", "--clear-password", metavar="CLEAR_PASSWORD", help="use this clear password for the new account")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050081 parser.add_argument("-R", "--root", metavar="CHROOT_DIR", help="directory to chroot into")
82 parser.add_argument("-r", "--system", help="create a system account", action="store_true")
83 parser.add_argument("-s", "--shell", metavar="SHELL", help="login shell of the new account")
84 parser.add_argument("-u", "--uid", metavar="UID", help="user ID of the new account")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050085 parser.add_argument("-U", "--user-group", help="create a group with the same name as the user", action="store_const", const=True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050086 parser.add_argument("LOGIN", help="Login name of the new user")
87
88 # Return a list of configuration files based on either the default
89 # files/passwd or the contents of USERADD_UID_TABLES
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050090 # paths are resolved via BBPATH
Patrick Williamsc124f4f2015-09-15 14:41:29 -050091 def get_passwd_list(d):
92 str = ""
Brad Bishop6e60e8b2018-02-01 10:27:11 -050093 bbpath = d.getVar('BBPATH')
94 passwd_tables = d.getVar('USERADD_UID_TABLES')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050095 if not passwd_tables:
96 passwd_tables = 'files/passwd'
97 for conf_file in passwd_tables.split():
98 str += " %s" % bb.utils.which(bbpath, conf_file)
99 return str
100
101 newparams = []
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500102 users = None
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500103 for param in re.split('''[ \t]*;[ \t]*(?=(?:[^'"]|'[^']*'|"[^"]*")*$)''', params):
104 param = param.strip()
105 if not param:
106 continue
107 try:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600108 uaargs = parser.parse_args(re.split('''[ \t]+(?=(?:[^'"]|'[^']*'|"[^"]*")*$)''', param))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500109 except:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500110 bb.fatal("%s: Unable to parse arguments for USERADD_PARAM_%s: '%s'" % (d.getVar('PN'), pkg, param))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500111
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500112 # Read all passwd files specified in USERADD_UID_TABLES or files/passwd
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500113 # Use the standard passwd layout:
114 # username:password:user_id:group_id:comment:home_directory:login_shell
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500115 #
116 # If a field is left blank, the original value will be used. The 'username'
117 # field is required.
118 #
119 # Note: we ignore the password field, as including even the hashed password
120 # in the useradd command may introduce a security hole. It's assumed that
121 # all new users get the default ('*' which prevents login) until the user is
122 # specifically configured by the system admin.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500123 if not users:
124 users = merge_files(get_passwd_list(d), 7)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500125
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500126 if uaargs.LOGIN not in users:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500127 handle_missing_id(uaargs.LOGIN, 'user', pkg)
128 newparams.append(param)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500129 continue
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500130
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500131 field = users[uaargs.LOGIN]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500132
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500133 if uaargs.uid and field[2] and (uaargs.uid != field[2]):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500134 bb.warn("%s: Changing username %s's uid from (%s) to (%s), verify configuration files!" % (d.getVar('PN'), uaargs.LOGIN, uaargs.uid, field[2]))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500135 uaargs.uid = field[2] or uaargs.uid
136
137 # Determine the possible groupname
138 # Unless the group name (or gid) is specified, we assume that the LOGIN is the groupname
139 #
140 # By default the system has creation of the matching groups enabled
141 # So if the implicit username-group creation is on, then the implicit groupname (LOGIN)
142 # is used, and we disable the user_group option.
143 #
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500144 if uaargs.gid:
145 uaargs.groupname = uaargs.gid
146 elif uaargs.user_group is not False:
147 uaargs.groupname = uaargs.LOGIN
148 else:
149 uaargs.groupname = 'users'
150 uaargs.groupid = field[3] or uaargs.groupname
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500151
152 if uaargs.groupid and uaargs.gid != uaargs.groupid:
153 newgroup = None
154 if not uaargs.groupid.isdigit():
155 # We don't have a group number, so we have to add a name
156 bb.debug(1, "Adding group %s!" % uaargs.groupid)
157 newgroup = "%s %s" % (' --system' if uaargs.system else '', uaargs.groupid)
158 elif uaargs.groupname and not uaargs.groupname.isdigit():
159 # We have a group name and a group number to assign it to
160 bb.debug(1, "Adding group %s (gid %s)!" % (uaargs.groupname, uaargs.groupid))
161 newgroup = "-g %s %s" % (uaargs.groupid, uaargs.groupname)
162 else:
163 # We want to add a group, but we don't know it's name... so we can't add the group...
164 # We have to assume the group has previously been added or we'll fail on the adduser...
165 # Note: specifying the actual gid is very rare in OE, usually the group name is specified.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500166 bb.warn("%s: Changing gid for login %s to %s, verify configuration files!" % (d.getVar('PN'), uaargs.LOGIN, uaargs.groupid))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500167
168 uaargs.gid = uaargs.groupid
169 uaargs.user_group = None
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500170 if newgroup and is_pkg:
171 groupadd = d.getVar("GROUPADD_PARAM_%s" % pkg)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500172 if groupadd:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500173 # Only add the group if not already specified
174 if not uaargs.groupname in groupadd:
175 d.setVar("GROUPADD_PARAM_%s" % pkg, "%s; %s" % (groupadd, newgroup))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500176 else:
177 d.setVar("GROUPADD_PARAM_%s" % pkg, newgroup)
178
179 uaargs.comment = "'%s'" % field[4] if field[4] else uaargs.comment
180 uaargs.home_dir = field[5] or uaargs.home_dir
181 uaargs.shell = field[6] or uaargs.shell
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500182
183 # Should be an error if a specific option is set...
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600184 if not uaargs.uid or not uaargs.uid.isdigit() or not uaargs.gid:
185 handle_missing_id(uaargs.LOGIN, 'user', pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500186
187 # Reconstruct the args...
188 newparam = ['', ' --defaults'][uaargs.defaults]
189 newparam += ['', ' --base-dir %s' % uaargs.base_dir][uaargs.base_dir != None]
190 newparam += ['', ' --comment %s' % uaargs.comment][uaargs.comment != None]
191 newparam += ['', ' --home-dir %s' % uaargs.home_dir][uaargs.home_dir != None]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500192 newparam += ['', ' --expiredate %s' % uaargs.expiredate][uaargs.expiredate != None]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500193 newparam += ['', ' --inactive %s' % uaargs.inactive][uaargs.inactive != None]
194 newparam += ['', ' --gid %s' % uaargs.gid][uaargs.gid != None]
195 newparam += ['', ' --groups %s' % uaargs.groups][uaargs.groups != None]
196 newparam += ['', ' --skel %s' % uaargs.skel][uaargs.skel != None]
197 newparam += ['', ' --key %s' % uaargs.key][uaargs.key != None]
198 newparam += ['', ' --no-log-init'][uaargs.no_log_init]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500199 newparam += ['', ' --create-home'][uaargs.create_home is True]
200 newparam += ['', ' --no-create-home'][uaargs.create_home is False]
201 newparam += ['', ' --no-user-group'][uaargs.user_group is False]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500202 newparam += ['', ' --non-unique'][uaargs.non_unique]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500203 if uaargs.password != None:
204 newparam += ['', ' --password %s' % uaargs.password][uaargs.password != None]
205 elif uaargs.clear_password:
206 newparam += ['', ' --clear-password %s' % uaargs.clear_password][uaargs.clear_password != None]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500207 newparam += ['', ' --root %s' % uaargs.root][uaargs.root != None]
208 newparam += ['', ' --system'][uaargs.system]
209 newparam += ['', ' --shell %s' % uaargs.shell][uaargs.shell != None]
210 newparam += ['', ' --uid %s' % uaargs.uid][uaargs.uid != None]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500211 newparam += ['', ' --user-group'][uaargs.user_group is True]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500212 newparam += ' %s' % uaargs.LOGIN
213
214 newparams.append(newparam)
215
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500216 return ";".join(newparams).strip()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500217
218 # We parse and rewrite the groupadd components
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500219 def rewrite_groupadd(params, is_pkg):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500220 # The following comes from --help on groupadd from shadow
221 parser = myArgumentParser(prog='groupadd')
222 parser.add_argument("-f", "--force", help="exit successfully if the group already exists, and cancel -g if the GID is already used", action="store_true")
223 parser.add_argument("-g", "--gid", metavar="GID", help="use GID for the new group")
224 parser.add_argument("-K", "--key", metavar="KEY=VALUE", help="override /etc/login.defs defaults")
225 parser.add_argument("-o", "--non-unique", help="allow to create groups with duplicate (non-unique) GID", action="store_true")
226 parser.add_argument("-p", "--password", metavar="PASSWORD", help="use this encrypted password for the new group")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500227 parser.add_argument("-P", "--clear-password", metavar="CLEAR_PASSWORD", help="use this clear password for the new group")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500228 parser.add_argument("-R", "--root", metavar="CHROOT_DIR", help="directory to chroot into")
229 parser.add_argument("-r", "--system", help="create a system account", action="store_true")
230 parser.add_argument("GROUP", help="Group name of the new group")
231
232 # Return a list of configuration files based on either the default
233 # files/group or the contents of USERADD_GID_TABLES
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500234 # paths are resolved via BBPATH
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500235 def get_group_list(d):
236 str = ""
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500237 bbpath = d.getVar('BBPATH')
238 group_tables = d.getVar('USERADD_GID_TABLES')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500239 if not group_tables:
240 group_tables = 'files/group'
241 for conf_file in group_tables.split():
242 str += " %s" % bb.utils.which(bbpath, conf_file)
243 return str
244
245 newparams = []
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500246 groups = None
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500247 for param in re.split('''[ \t]*;[ \t]*(?=(?:[^'"]|'[^']*'|"[^"]*")*$)''', params):
248 param = param.strip()
249 if not param:
250 continue
251 try:
252 # If we're processing multiple lines, we could have left over values here...
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600253 gaargs = parser.parse_args(re.split('''[ \t]+(?=(?:[^'"]|'[^']*'|"[^"]*")*$)''', param))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500254 except:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500255 bb.fatal("%s: Unable to parse arguments for GROUPADD_PARAM_%s: '%s'" % (d.getVar('PN'), pkg, param))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500256
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500257 # Read all group files specified in USERADD_GID_TABLES or files/group
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500258 # Use the standard group layout:
259 # groupname:password:group_id:group_members
260 #
261 # If a field is left blank, the original value will be used. The 'groupname' field
262 # is required.
263 #
264 # Note: similar to the passwd file, the 'password' filed is ignored
265 # Note: group_members is ignored, group members must be configured with the GROUPMEMS_PARAM
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500266 if not groups:
267 groups = merge_files(get_group_list(d), 4)
268
269 if gaargs.GROUP not in groups:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500270 handle_missing_id(gaargs.GROUP, 'group', pkg)
271 newparams.append(param)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500272 continue
273
274 field = groups[gaargs.GROUP]
275
276 if field[2]:
277 if gaargs.gid and (gaargs.gid != field[2]):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500278 bb.warn("%s: Changing groupname %s's gid from (%s) to (%s), verify configuration files!" % (d.getVar('PN'), gaargs.GROUP, gaargs.gid, field[2]))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500279 gaargs.gid = field[2]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500280
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600281 if not gaargs.gid or not gaargs.gid.isdigit():
282 handle_missing_id(gaargs.GROUP, 'group', pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500283
284 # Reconstruct the args...
285 newparam = ['', ' --force'][gaargs.force]
286 newparam += ['', ' --gid %s' % gaargs.gid][gaargs.gid != None]
287 newparam += ['', ' --key %s' % gaargs.key][gaargs.key != None]
288 newparam += ['', ' --non-unique'][gaargs.non_unique]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500289 if gaargs.password != None:
290 newparam += ['', ' --password %s' % gaargs.password][gaargs.password != None]
291 elif gaargs.clear_password:
292 newparam += ['', ' --clear-password %s' % gaargs.clear_password][gaargs.clear_password != None]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500293 newparam += ['', ' --root %s' % gaargs.root][gaargs.root != None]
294 newparam += ['', ' --system'][gaargs.system]
295 newparam += ' %s' % gaargs.GROUP
296
297 newparams.append(newparam)
298
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500299 return ";".join(newparams).strip()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500300
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600301 # The parsing of the current recipe depends on the content of
302 # the files listed in USERADD_UID/GID_TABLES. We need to tell bitbake
303 # about that explicitly to trigger re-parsing and thus re-execution of
304 # this code when the files change.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500305 bbpath = d.getVar('BBPATH')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600306 for varname, default in (('USERADD_UID_TABLES', 'files/passwd'),
307 ('USERADD_GID_TABLES', 'files/group')):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500308 tables = d.getVar(varname)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600309 if not tables:
310 tables = default
311 for conf_file in tables.split():
312 bb.parse.mark_dependency(d, bb.utils.which(bbpath, conf_file))
313
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500314 # Load and process the users and groups, rewriting the adduser/addgroup params
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500315 useradd_packages = d.getVar('USERADD_PACKAGES') or ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500316
317 for pkg in useradd_packages.split():
318 # Groupmems doesn't have anything we might want to change, so simply validating
319 # is a bit of a waste -- only process useradd/groupadd
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500320 useradd_param = d.getVar('USERADD_PARAM_%s' % pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500321 if useradd_param:
322 #bb.warn("Before: 'USERADD_PARAM_%s' - '%s'" % (pkg, useradd_param))
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500323 d.setVar('USERADD_PARAM_%s' % pkg, rewrite_useradd(useradd_param, True))
324 #bb.warn("After: 'USERADD_PARAM_%s' - '%s'" % (pkg, d.getVar('USERADD_PARAM_%s' % pkg)))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500325
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500326 groupadd_param = d.getVar('GROUPADD_PARAM_%s' % pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500327 if groupadd_param:
328 #bb.warn("Before: 'GROUPADD_PARAM_%s' - '%s'" % (pkg, groupadd_param))
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500329 d.setVar('GROUPADD_PARAM_%s' % pkg, rewrite_groupadd(groupadd_param, True))
330 #bb.warn("After: 'GROUPADD_PARAM_%s' - '%s'" % (pkg, d.getVar('GROUPADD_PARAM_%s' % pkg)))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500331
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500332 # Load and process extra users and groups, rewriting only adduser/addgroup params
333 pkg = d.getVar('PN')
334 extrausers = d.getVar('EXTRA_USERS_PARAMS') or ""
335
336 #bb.warn("Before: 'EXTRA_USERS_PARAMS' - '%s'" % (d.getVar('EXTRA_USERS_PARAMS')))
337 new_extrausers = []
338 for cmd in re.split('''[ \t]*;[ \t]*(?=(?:[^'"]|'[^']*'|"[^"]*")*$)''', extrausers):
339 cmd = cmd.strip()
340 if not cmd:
341 continue
342
343 if re.match('''useradd (.*)''', cmd):
344 useradd_param = re.match('''useradd (.*)''', cmd).group(1)
345 useradd_param = rewrite_useradd(useradd_param, False)
346 cmd = 'useradd %s' % useradd_param
347 elif re.match('''groupadd (.*)''', cmd):
348 groupadd_param = re.match('''groupadd (.*)''', cmd).group(1)
349 groupadd_param = rewrite_groupadd(groupadd_param, False)
350 cmd = 'groupadd %s' % groupadd_param
351
352 new_extrausers.append(cmd)
353
354 new_extrausers.append('')
355 d.setVar('EXTRA_USERS_PARAMS', ';'.join(new_extrausers))
356 #bb.warn("After: 'EXTRA_USERS_PARAMS' - '%s'" % (d.getVar('EXTRA_USERS_PARAMS')))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500357
358
359python __anonymous() {
360 if not bb.data.inherits_class('nativesdk', d) \
361 and not bb.data.inherits_class('native', d):
362 try:
363 update_useradd_static_config(d)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500364 except NotImplementedError as f:
365 bb.debug(1, "Skipping recipe %s: %s" % (d.getVar('PN'), f))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500366 raise bb.parse.SkipPackage(f)
367}