| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # 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 | 
|  | 3 | def update_useradd_static_config(d): | 
| Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 4 | import itertools | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5 | import re | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 6 | import errno | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 7 | import oe.useradd | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8 |  | 
| Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 9 | def list_extend(iterable, length, obj = None): | 
|  | 10 | """Ensure that iterable is the specified length by extending with obj | 
|  | 11 | and return it as a list""" | 
|  | 12 | return list(itertools.islice(itertools.chain(iterable, itertools.repeat(obj)), length)) | 
|  | 13 |  | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 14 | def merge_files(file_list, exp_fields): | 
|  | 15 | """Read each passwd/group file in file_list, split each line and create | 
|  | 16 | a dictionary with the user/group names as keys and the split lines as | 
|  | 17 | values. If the user/group name already exists in the dictionary, then | 
|  | 18 | update any fields in the list with the values from the new list (if they | 
|  | 19 | are set).""" | 
|  | 20 | id_table = dict() | 
|  | 21 | for conf in file_list.split(): | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 22 | try: | 
|  | 23 | with open(conf, "r") as f: | 
|  | 24 | for line in f: | 
|  | 25 | if line.startswith('#'): | 
|  | 26 | continue | 
|  | 27 | # Make sure there always are at least exp_fields | 
|  | 28 | # elements in the field list. This allows for leaving | 
|  | 29 | # out trailing colons in the files. | 
|  | 30 | fields = list_extend(line.rstrip().split(":"), exp_fields) | 
|  | 31 | if fields[0] not in id_table: | 
|  | 32 | id_table[fields[0]] = fields | 
|  | 33 | else: | 
|  | 34 | id_table[fields[0]] = list(map(lambda x, y: x or y, fields, id_table[fields[0]])) | 
|  | 35 | except IOError as e: | 
|  | 36 | if e.errno == errno.ENOENT: | 
|  | 37 | pass | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 38 |  | 
|  | 39 | return id_table | 
|  | 40 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 41 | def handle_missing_id(id, type, pkg, files, var, value): | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 42 | # For backwards compatibility we accept "1" in addition to "error" | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 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) | 
|  | 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) | 
|  | 49 | if error_dynamic == 'error' or error_dynamic == '1': | 
|  | 50 | raise NotImplementedError(msg) | 
|  | 51 | elif error_dynamic == 'warn': | 
|  | 52 | bb.warn(msg) | 
|  | 53 | elif error_dynamic == 'skip': | 
|  | 54 | raise bb.parse.SkipRecipe(msg) | 
|  | 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 = [] | 
| Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 62 | bbpath = d.getVar('BBPATH') | 
|  | 63 | tables = d.getVar(var) | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 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) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 69 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 70 | # We parse and rewrite the useradd components | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 71 | def rewrite_useradd(params, is_pkg): | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 72 | parser = oe.useradd.build_useradd_parser() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 73 |  | 
|  | 74 | newparams = [] | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 75 | users = None | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 76 | for param in oe.useradd.split_commands(params): | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 77 | try: | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 78 | uaargs = parser.parse_args(oe.useradd.split_args(param)) | 
| Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 79 | except Exception as e: | 
| Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 80 | bb.fatal("%s: Unable to parse arguments for USERADD_PARAM:%s '%s': %s" % (d.getVar('PN'), pkg, param, e)) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 81 |  | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 82 | # Read all passwd files specified in USERADD_UID_TABLES or files/passwd | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 83 | # Use the standard passwd layout: | 
|  | 84 | #  username:password:user_id:group_id:comment:home_directory:login_shell | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 85 | # | 
|  | 86 | # If a field is left blank, the original value will be used.  The 'username' | 
|  | 87 | # field is required. | 
|  | 88 | # | 
|  | 89 | # Note: we ignore the password field, as including even the hashed password | 
|  | 90 | # in the useradd command may introduce a security hole.  It's assumed that | 
|  | 91 | # all new users get the default ('*' which prevents login) until the user is | 
|  | 92 | # specifically configured by the system admin. | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 93 | if not users: | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 94 | files, table_var, table_value = get_table_list(d, 'USERADD_UID_TABLES', 'files/passwd') | 
|  | 95 | users = merge_files(files, 7) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 96 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 97 | type = 'system user' if uaargs.system else 'normal user' | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 98 | if uaargs.LOGIN not in users: | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 99 | handle_missing_id(uaargs.LOGIN, type, pkg, files, table_var, table_value) | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 100 | newparams.append(param) | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 101 | continue | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 102 |  | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 103 | field = users[uaargs.LOGIN] | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 104 |  | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 105 | if uaargs.uid and field[2] and (uaargs.uid != field[2]): | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 106 | 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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 107 | uaargs.uid = field[2] or uaargs.uid | 
|  | 108 |  | 
|  | 109 | # Determine the possible groupname | 
|  | 110 | # Unless the group name (or gid) is specified, we assume that the LOGIN is the groupname | 
|  | 111 | # | 
|  | 112 | # By default the system has creation of the matching groups enabled | 
|  | 113 | # So if the implicit username-group creation is on, then the implicit groupname (LOGIN) | 
|  | 114 | # is used, and we disable the user_group option. | 
|  | 115 | # | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 116 | if uaargs.gid: | 
|  | 117 | uaargs.groupname = uaargs.gid | 
|  | 118 | elif uaargs.user_group is not False: | 
|  | 119 | uaargs.groupname = uaargs.LOGIN | 
|  | 120 | else: | 
|  | 121 | uaargs.groupname = 'users' | 
|  | 122 | uaargs.groupid = field[3] or uaargs.groupname | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 123 |  | 
|  | 124 | if uaargs.groupid and uaargs.gid != uaargs.groupid: | 
|  | 125 | newgroup = None | 
|  | 126 | if not uaargs.groupid.isdigit(): | 
|  | 127 | # We don't have a group number, so we have to add a name | 
|  | 128 | bb.debug(1, "Adding group %s!" % uaargs.groupid) | 
|  | 129 | newgroup = "%s %s" % (' --system' if uaargs.system else '', uaargs.groupid) | 
|  | 130 | elif uaargs.groupname and not uaargs.groupname.isdigit(): | 
|  | 131 | # We have a group name and a group number to assign it to | 
|  | 132 | bb.debug(1, "Adding group %s (gid %s)!" % (uaargs.groupname, uaargs.groupid)) | 
|  | 133 | newgroup = "-g %s %s" % (uaargs.groupid, uaargs.groupname) | 
|  | 134 | else: | 
|  | 135 | # We want to add a group, but we don't know it's name... so we can't add the group... | 
|  | 136 | # We have to assume the group has previously been added or we'll fail on the adduser... | 
|  | 137 | # Note: specifying the actual gid is very rare in OE, usually the group name is specified. | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 138 | bb.warn("%s: Changing gid for login %s to %s, verify configuration files!" % (d.getVar('PN'), uaargs.LOGIN, uaargs.groupid)) | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 139 |  | 
|  | 140 | uaargs.gid = uaargs.groupid | 
|  | 141 | uaargs.user_group = None | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 142 | if newgroup and is_pkg: | 
| Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 143 | groupadd = d.getVar("GROUPADD_PARAM:%s" % pkg) | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 144 | if groupadd: | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 145 | # Only add the group if not already specified | 
|  | 146 | if not uaargs.groupname in groupadd: | 
| Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 147 | d.setVar("GROUPADD_PARAM:%s" % pkg, "%s; %s" % (groupadd, newgroup)) | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 148 | else: | 
| Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 149 | d.setVar("GROUPADD_PARAM:%s" % pkg, newgroup) | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 150 |  | 
|  | 151 | uaargs.comment = "'%s'" % field[4] if field[4] else uaargs.comment | 
|  | 152 | uaargs.home_dir = field[5] or uaargs.home_dir | 
|  | 153 | uaargs.shell = field[6] or uaargs.shell | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 154 |  | 
|  | 155 | # Should be an error if a specific option is set... | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 156 | if not uaargs.uid or not uaargs.uid.isdigit() or not uaargs.gid: | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 157 | handle_missing_id(uaargs.LOGIN, type, pkg, files, table_var, table_value) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 158 |  | 
|  | 159 | # Reconstruct the args... | 
|  | 160 | newparam  = ['', ' --defaults'][uaargs.defaults] | 
|  | 161 | newparam += ['', ' --base-dir %s' % uaargs.base_dir][uaargs.base_dir != None] | 
|  | 162 | newparam += ['', ' --comment %s' % uaargs.comment][uaargs.comment != None] | 
|  | 163 | newparam += ['', ' --home-dir %s' % uaargs.home_dir][uaargs.home_dir != None] | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 164 | newparam += ['', ' --expiredate %s' % uaargs.expiredate][uaargs.expiredate != None] | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 165 | newparam += ['', ' --inactive %s' % uaargs.inactive][uaargs.inactive != None] | 
|  | 166 | newparam += ['', ' --gid %s' % uaargs.gid][uaargs.gid != None] | 
|  | 167 | newparam += ['', ' --groups %s' % uaargs.groups][uaargs.groups != None] | 
|  | 168 | newparam += ['', ' --skel %s' % uaargs.skel][uaargs.skel != None] | 
|  | 169 | newparam += ['', ' --key %s' % uaargs.key][uaargs.key != None] | 
|  | 170 | newparam += ['', ' --no-log-init'][uaargs.no_log_init] | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 171 | newparam += ['', ' --create-home'][uaargs.create_home is True] | 
|  | 172 | newparam += ['', ' --no-create-home'][uaargs.create_home is False] | 
|  | 173 | newparam += ['', ' --no-user-group'][uaargs.user_group is False] | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 174 | newparam += ['', ' --non-unique'][uaargs.non_unique] | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 175 | if uaargs.password != None: | 
|  | 176 | newparam += ['', ' --password %s' % uaargs.password][uaargs.password != None] | 
|  | 177 | elif uaargs.clear_password: | 
|  | 178 | newparam += ['', ' --clear-password %s' % uaargs.clear_password][uaargs.clear_password != None] | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 179 | newparam += ['', ' --root %s' % uaargs.root][uaargs.root != None] | 
|  | 180 | newparam += ['', ' --system'][uaargs.system] | 
|  | 181 | newparam += ['', ' --shell %s' % uaargs.shell][uaargs.shell != None] | 
|  | 182 | newparam += ['', ' --uid %s' % uaargs.uid][uaargs.uid != None] | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 183 | newparam += ['', ' --user-group'][uaargs.user_group is True] | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 184 | newparam += ' %s' % uaargs.LOGIN | 
|  | 185 |  | 
|  | 186 | newparams.append(newparam) | 
|  | 187 |  | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 188 | return ";".join(newparams).strip() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 189 |  | 
|  | 190 | # We parse and rewrite the groupadd components | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 191 | def rewrite_groupadd(params, is_pkg): | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 192 | parser = oe.useradd.build_groupadd_parser() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 193 |  | 
|  | 194 | newparams = [] | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 195 | groups = None | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 196 | for param in oe.useradd.split_commands(params): | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 197 | try: | 
|  | 198 | # If we're processing multiple lines, we could have left over values here... | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 199 | gaargs = parser.parse_args(oe.useradd.split_args(param)) | 
| Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 200 | except Exception as e: | 
| Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 201 | bb.fatal("%s: Unable to parse arguments for GROUPADD_PARAM:%s '%s': %s" % (d.getVar('PN'), pkg, param, e)) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 202 |  | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 203 | # Read all group files specified in USERADD_GID_TABLES or files/group | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 204 | # Use the standard group layout: | 
|  | 205 | #  groupname:password:group_id:group_members | 
|  | 206 | # | 
|  | 207 | # If a field is left blank, the original value will be used. The 'groupname' field | 
|  | 208 | # is required. | 
|  | 209 | # | 
|  | 210 | # Note: similar to the passwd file, the 'password' filed is ignored | 
|  | 211 | # Note: group_members is ignored, group members must be configured with the GROUPMEMS_PARAM | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 212 | if not groups: | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 213 | files, table_var, table_value = get_table_list(d, 'USERADD_GID_TABLES', 'files/group') | 
|  | 214 | groups = merge_files(files, 4) | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 215 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 216 | type = 'system group' if gaargs.system else 'normal group' | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 217 | if gaargs.GROUP not in groups: | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 218 | handle_missing_id(gaargs.GROUP, type, pkg, files, table_var, table_value) | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 219 | newparams.append(param) | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 220 | continue | 
|  | 221 |  | 
|  | 222 | field = groups[gaargs.GROUP] | 
|  | 223 |  | 
|  | 224 | if field[2]: | 
|  | 225 | if gaargs.gid and (gaargs.gid != field[2]): | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 226 | 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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 227 | gaargs.gid = field[2] | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 228 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 229 | if not gaargs.gid or not gaargs.gid.isdigit(): | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 230 | handle_missing_id(gaargs.GROUP, type, pkg, files, table_var, table_value) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 231 |  | 
|  | 232 | # Reconstruct the args... | 
|  | 233 | newparam  = ['', ' --force'][gaargs.force] | 
|  | 234 | newparam += ['', ' --gid %s' % gaargs.gid][gaargs.gid != None] | 
|  | 235 | newparam += ['', ' --key %s' % gaargs.key][gaargs.key != None] | 
|  | 236 | newparam += ['', ' --non-unique'][gaargs.non_unique] | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 237 | if gaargs.password != None: | 
|  | 238 | newparam += ['', ' --password %s' % gaargs.password][gaargs.password != None] | 
|  | 239 | elif gaargs.clear_password: | 
|  | 240 | newparam += ['', ' --clear-password %s' % gaargs.clear_password][gaargs.clear_password != None] | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 241 | newparam += ['', ' --root %s' % gaargs.root][gaargs.root != None] | 
|  | 242 | newparam += ['', ' --system'][gaargs.system] | 
|  | 243 | newparam += ' %s' % gaargs.GROUP | 
|  | 244 |  | 
|  | 245 | newparams.append(newparam) | 
|  | 246 |  | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 247 | return ";".join(newparams).strip() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 248 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 249 | # The parsing of the current recipe depends on the content of | 
|  | 250 | # the files listed in USERADD_UID/GID_TABLES. We need to tell bitbake | 
|  | 251 | # about that explicitly to trigger re-parsing and thus re-execution of | 
|  | 252 | # this code when the files change. | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 253 | bbpath = d.getVar('BBPATH') | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 254 | for varname, default in (('USERADD_UID_TABLES', 'files/passwd'), | 
|  | 255 | ('USERADD_GID_TABLES', 'files/group')): | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 256 | tables = d.getVar(varname) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 257 | if not tables: | 
|  | 258 | tables = default | 
|  | 259 | for conf_file in tables.split(): | 
|  | 260 | bb.parse.mark_dependency(d, bb.utils.which(bbpath, conf_file)) | 
|  | 261 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 262 | # Load and process the users and groups, rewriting the adduser/addgroup params | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 263 | useradd_packages = d.getVar('USERADD_PACKAGES') or "" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 264 |  | 
|  | 265 | for pkg in useradd_packages.split(): | 
|  | 266 | # Groupmems doesn't have anything we might want to change, so simply validating | 
|  | 267 | # is a bit of a waste -- only process useradd/groupadd | 
| Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 268 | useradd_param = d.getVar('USERADD_PARAM:%s' % pkg) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 269 | if useradd_param: | 
| Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 270 | #bb.warn("Before: 'USERADD_PARAM:%s' - '%s'" % (pkg, useradd_param)) | 
|  | 271 | d.setVar('USERADD_PARAM:%s' % pkg, rewrite_useradd(useradd_param, True)) | 
|  | 272 | #bb.warn("After:  'USERADD_PARAM:%s' - '%s'" % (pkg, d.getVar('USERADD_PARAM:%s' % pkg))) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 273 |  | 
| Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 274 | groupadd_param = d.getVar('GROUPADD_PARAM:%s' % pkg) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 275 | if groupadd_param: | 
| Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 276 | #bb.warn("Before: 'GROUPADD_PARAM:%s' - '%s'" % (pkg, groupadd_param)) | 
|  | 277 | d.setVar('GROUPADD_PARAM:%s' % pkg, rewrite_groupadd(groupadd_param, True)) | 
|  | 278 | #bb.warn("After:  'GROUPADD_PARAM:%s' - '%s'" % (pkg, d.getVar('GROUPADD_PARAM:%s' % pkg))) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 279 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 280 | # Load and process extra users and groups, rewriting only adduser/addgroup params | 
|  | 281 | pkg = d.getVar('PN') | 
|  | 282 | extrausers = d.getVar('EXTRA_USERS_PARAMS') or "" | 
|  | 283 |  | 
|  | 284 | #bb.warn("Before:  'EXTRA_USERS_PARAMS' - '%s'" % (d.getVar('EXTRA_USERS_PARAMS'))) | 
|  | 285 | new_extrausers = [] | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 286 | for cmd in oe.useradd.split_commands(extrausers): | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 287 | if re.match('''useradd (.*)''', cmd): | 
|  | 288 | useradd_param = re.match('''useradd (.*)''', cmd).group(1) | 
|  | 289 | useradd_param = rewrite_useradd(useradd_param, False) | 
|  | 290 | cmd = 'useradd %s' % useradd_param | 
|  | 291 | elif re.match('''groupadd (.*)''', cmd): | 
|  | 292 | groupadd_param = re.match('''groupadd (.*)''', cmd).group(1) | 
|  | 293 | groupadd_param = rewrite_groupadd(groupadd_param, False) | 
|  | 294 | cmd = 'groupadd %s' % groupadd_param | 
|  | 295 |  | 
|  | 296 | new_extrausers.append(cmd) | 
|  | 297 |  | 
|  | 298 | new_extrausers.append('') | 
|  | 299 | d.setVar('EXTRA_USERS_PARAMS', ';'.join(new_extrausers)) | 
|  | 300 | #bb.warn("After:  'EXTRA_USERS_PARAMS' - '%s'" % (d.getVar('EXTRA_USERS_PARAMS'))) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 301 |  | 
|  | 302 |  | 
|  | 303 | python __anonymous() { | 
|  | 304 | if not bb.data.inherits_class('nativesdk', d) \ | 
|  | 305 | and not bb.data.inherits_class('native', d): | 
|  | 306 | try: | 
|  | 307 | update_useradd_static_config(d) | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 308 | except NotImplementedError as f: | 
|  | 309 | bb.debug(1, "Skipping recipe %s: %s" % (d.getVar('PN'), f)) | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 310 | raise bb.parse.SkipRecipe(f) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 311 | } |