diff options
Diffstat (limited to 'meta/classes/useradd.bbclass')
-rw-r--r-- | meta/classes/useradd.bbclass | 105 |
1 files changed, 70 insertions, 35 deletions
diff --git a/meta/classes/useradd.bbclass b/meta/classes/useradd.bbclass index e5f3ba24f9..16a65ac323 100644 --- a/meta/classes/useradd.bbclass +++ b/meta/classes/useradd.bbclass | |||
@@ -1,9 +1,15 @@ | |||
1 | # | ||
2 | # Copyright OpenEmbedded Contributors | ||
3 | # | ||
4 | # SPDX-License-Identifier: MIT | ||
5 | # | ||
6 | |||
1 | inherit useradd_base | 7 | inherit useradd_base |
2 | 8 | ||
3 | # base-passwd-cross provides the default passwd and group files in the | 9 | # base-passwd-cross provides the default passwd and group files in the |
4 | # target sysroot, and shadow -native and -sysroot provide the utilities | 10 | # target sysroot, and shadow -native and -sysroot provide the utilities |
5 | # and support files needed to add and modify user and group accounts | 11 | # and support files needed to add and modify user and group accounts |
6 | DEPENDS_append_class-target = " base-files shadow-native shadow-sysroot shadow base-passwd" | 12 | DEPENDS:append:class-target = " base-files shadow-native shadow-sysroot shadow base-passwd" |
7 | PACKAGE_WRITE_DEPS += "shadow-native" | 13 | PACKAGE_WRITE_DEPS += "shadow-native" |
8 | 14 | ||
9 | # This preinstall function can be run in four different contexts: | 15 | # This preinstall function can be run in four different contexts: |
@@ -97,6 +103,18 @@ fi | |||
97 | } | 103 | } |
98 | 104 | ||
99 | useradd_sysroot () { | 105 | useradd_sysroot () { |
106 | user_group_groupmems_add_sysroot user | ||
107 | } | ||
108 | |||
109 | groupadd_sysroot () { | ||
110 | user_group_groupmems_add_sysroot group | ||
111 | } | ||
112 | |||
113 | groupmemsadd_sysroot () { | ||
114 | user_group_groupmems_add_sysroot groupmems | ||
115 | } | ||
116 | |||
117 | user_group_groupmems_add_sysroot () { | ||
100 | # Pseudo may (do_prepare_recipe_sysroot) or may not (do_populate_sysroot_setscene) be running | 118 | # Pseudo may (do_prepare_recipe_sysroot) or may not (do_populate_sysroot_setscene) be running |
101 | # at this point so we're explicit about the environment so pseudo can load if | 119 | # at this point so we're explicit about the environment so pseudo can load if |
102 | # not already present. | 120 | # not already present. |
@@ -125,9 +143,15 @@ useradd_sysroot () { | |||
125 | fi | 143 | fi |
126 | 144 | ||
127 | # Add groups and users defined for all recipe packages | 145 | # Add groups and users defined for all recipe packages |
128 | GROUPADD_PARAM="${@get_all_cmd_params(d, 'groupadd')}" | 146 | if test "$1" = "group"; then |
129 | USERADD_PARAM="${@get_all_cmd_params(d, 'useradd')}" | 147 | GROUPADD_PARAM="${@get_all_cmd_params(d, 'groupadd')}" |
130 | GROUPMEMS_PARAM="${@get_all_cmd_params(d, 'groupmems')}" | 148 | elif test "$1" = "user"; then |
149 | USERADD_PARAM="${@get_all_cmd_params(d, 'useradd')}" | ||
150 | elif test "$1" = "groupmems"; then | ||
151 | GROUPMEMS_PARAM="${@get_all_cmd_params(d, 'groupmems')}" | ||
152 | elif test "x$1" = "x"; then | ||
153 | bbwarn "missing type of passwd db action" | ||
154 | fi | ||
131 | 155 | ||
132 | # Tell the system to use the environment vars | 156 | # Tell the system to use the environment vars |
133 | UA_SYSROOT=1 | 157 | UA_SYSROOT=1 |
@@ -142,38 +166,45 @@ useradd_sysroot () { | |||
142 | EXTRA_STAGING_FIXMES += "PSEUDO_SYSROOT PSEUDO_LOCALSTATEDIR LOGFIFO" | 166 | EXTRA_STAGING_FIXMES += "PSEUDO_SYSROOT PSEUDO_LOCALSTATEDIR LOGFIFO" |
143 | 167 | ||
144 | python useradd_sysroot_sstate () { | 168 | python useradd_sysroot_sstate () { |
145 | scriptfile = None | 169 | for type, sort_prefix in [("group", "01"), ("user", "02"), ("groupmems", "03")]: |
146 | task = d.getVar("BB_CURRENTTASK") | 170 | scriptfile = None |
147 | if task == "package_setscene": | 171 | task = d.getVar("BB_CURRENTTASK") |
148 | bb.build.exec_func("useradd_sysroot", d) | 172 | if task == "package_setscene": |
149 | elif task == "prepare_recipe_sysroot": | 173 | bb.build.exec_func(type + "add_sysroot", d) |
150 | # Used to update this recipe's own sysroot so the user/groups are available to do_install | 174 | elif task == "prepare_recipe_sysroot": |
151 | scriptfile = d.expand("${RECIPE_SYSROOT}${bindir}/postinst-useradd-${PN}") | 175 | # Used to update this recipe's own sysroot so the user/groups are available to do_install |
152 | bb.build.exec_func("useradd_sysroot", d) | 176 | |
153 | elif task == "populate_sysroot": | 177 | # If do_populate_sysroot is triggered and we write the file here, there would be an overlapping |
154 | # Used when installed in dependent task sysroots | 178 | # files. See usergrouptests.UserGroupTests.test_add_task_between_p_sysroot_and_package |
155 | scriptfile = d.expand("${SYSROOT_DESTDIR}${bindir}/postinst-useradd-${PN}") | 179 | scriptfile = d.expand("${RECIPE_SYSROOT}${bindir}/postinst-useradd-" + sort_prefix + type + "-${PN}-recipedebug") |
156 | 180 | ||
157 | if scriptfile: | 181 | bb.build.exec_func(type + "add_sysroot", d) |
158 | bb.utils.mkdirhier(os.path.dirname(scriptfile)) | 182 | elif task == "populate_sysroot": |
159 | with open(scriptfile, 'w') as script: | 183 | # Used when installed in dependent task sysroots |
160 | script.write("#!/bin/sh\n") | 184 | scriptfile = d.expand("${SYSROOT_DESTDIR}${bindir}/postinst-useradd-" + sort_prefix + type + "-${PN}") |
161 | bb.data.emit_func("useradd_sysroot", script, d) | 185 | |
162 | script.write("useradd_sysroot\n") | 186 | if scriptfile: |
163 | os.chmod(scriptfile, 0o755) | 187 | bb.utils.mkdirhier(os.path.dirname(scriptfile)) |
188 | with open(scriptfile, 'w') as script: | ||
189 | script.write("#!/bin/sh -e\n") | ||
190 | bb.data.emit_func(type + "add_sysroot", script, d) | ||
191 | script.write(type + "add_sysroot\n") | ||
192 | os.chmod(scriptfile, 0o755) | ||
164 | } | 193 | } |
165 | 194 | ||
166 | do_prepare_recipe_sysroot[postfuncs] += "${SYSROOTFUNC}" | 195 | do_prepare_recipe_sysroot[postfuncs] += "${SYSROOTFUNC}" |
167 | SYSROOTFUNC_class-target = "useradd_sysroot_sstate" | 196 | SYSROOTFUNC:class-target = "useradd_sysroot_sstate" |
168 | SYSROOTFUNC = "" | 197 | SYSROOTFUNC = "" |
169 | 198 | ||
170 | SYSROOT_PREPROCESS_FUNCS += "${SYSROOTFUNC}" | 199 | SYSROOT_PREPROCESS_FUNCS += "${SYSROOTFUNC}" |
171 | 200 | ||
172 | SSTATEPREINSTFUNCS_append_class-target = " useradd_sysroot_sstate" | 201 | SSTATEPREINSTFUNCS:append:class-target = " useradd_sysroot_sstate" |
173 | 202 | ||
203 | USERADD_DEPENDS ??= "" | ||
204 | DEPENDS += "${USERADD_DEPENDS}" | ||
174 | do_package_setscene[depends] += "${USERADDSETSCENEDEPS}" | 205 | do_package_setscene[depends] += "${USERADDSETSCENEDEPS}" |
175 | do_populate_sysroot_setscene[depends] += "${USERADDSETSCENEDEPS}" | 206 | do_populate_sysroot_setscene[depends] += "${USERADDSETSCENEDEPS}" |
176 | USERADDSETSCENEDEPS_class-target = "${MLPREFIX}base-passwd:do_populate_sysroot_setscene pseudo-native:do_populate_sysroot_setscene shadow-native:do_populate_sysroot_setscene ${MLPREFIX}shadow-sysroot:do_populate_sysroot_setscene" | 207 | USERADDSETSCENEDEPS:class-target = "${MLPREFIX}base-passwd:do_populate_sysroot_setscene pseudo-native:do_populate_sysroot_setscene shadow-native:do_populate_sysroot_setscene ${MLPREFIX}shadow-sysroot:do_populate_sysroot_setscene ${@' '.join(['%s:do_populate_sysroot_setscene' % pkg for pkg in d.getVar("USERADD_DEPENDS").split()])}" |
177 | USERADDSETSCENEDEPS = "" | 208 | USERADDSETSCENEDEPS = "" |
178 | 209 | ||
179 | # Recipe parse-time sanity checks | 210 | # Recipe parse-time sanity checks |
@@ -184,8 +215,8 @@ def update_useradd_after_parse(d): | |||
184 | bb.fatal("%s inherits useradd but doesn't set USERADD_PACKAGES" % d.getVar('FILE', False)) | 215 | bb.fatal("%s inherits useradd but doesn't set USERADD_PACKAGES" % d.getVar('FILE', False)) |
185 | 216 | ||
186 | for pkg in useradd_packages.split(): | 217 | for pkg in useradd_packages.split(): |
187 | d.appendVarFlag("do_populate_sysroot", "vardeps", "USERADD_PARAM_%s GROUPADD_PARAM_%s GROUPMEMS_PARAM_%s" % (pkg, pkg, pkg)) | 218 | d.appendVarFlag("do_populate_sysroot", "vardeps", " USERADD_PARAM:%s GROUPADD_PARAM:%s GROUPMEMS_PARAM:%s" % (pkg, pkg, pkg)) |
188 | if not d.getVar('USERADD_PARAM_%s' % pkg) and not d.getVar('GROUPADD_PARAM_%s' % pkg) and not d.getVar('GROUPMEMS_PARAM_%s' % pkg): | 219 | if not d.getVar('USERADD_PARAM:%s' % pkg) and not d.getVar('GROUPADD_PARAM:%s' % pkg) and not d.getVar('GROUPMEMS_PARAM:%s' % pkg): |
189 | bb.fatal("%s inherits useradd but doesn't set USERADD_PARAM, GROUPADD_PARAM or GROUPMEMS_PARAM for package %s" % (d.getVar('FILE', False), pkg)) | 220 | bb.fatal("%s inherits useradd but doesn't set USERADD_PARAM, GROUPADD_PARAM or GROUPMEMS_PARAM for package %s" % (d.getVar('FILE', False), pkg)) |
190 | 221 | ||
191 | python __anonymous() { | 222 | python __anonymous() { |
@@ -199,7 +230,7 @@ python __anonymous() { | |||
199 | def get_all_cmd_params(d, cmd_type): | 230 | def get_all_cmd_params(d, cmd_type): |
200 | import string | 231 | import string |
201 | 232 | ||
202 | param_type = cmd_type.upper() + "_PARAM_%s" | 233 | param_type = cmd_type.upper() + "_PARAM:%s" |
203 | params = [] | 234 | params = [] |
204 | 235 | ||
205 | useradd_packages = d.getVar('USERADD_PACKAGES') or "" | 236 | useradd_packages = d.getVar('USERADD_PACKAGES') or "" |
@@ -211,7 +242,7 @@ def get_all_cmd_params(d, cmd_type): | |||
211 | return "; ".join(params) | 242 | return "; ".join(params) |
212 | 243 | ||
213 | # Adds the preinst script into generated packages | 244 | # Adds the preinst script into generated packages |
214 | fakeroot python populate_packages_prepend () { | 245 | fakeroot python populate_packages:prepend () { |
215 | def update_useradd_package(pkg): | 246 | def update_useradd_package(pkg): |
216 | bb.debug(1, 'adding user/group calls to preinst for %s' % pkg) | 247 | bb.debug(1, 'adding user/group calls to preinst for %s' % pkg) |
217 | 248 | ||
@@ -220,7 +251,7 @@ fakeroot python populate_packages_prepend () { | |||
220 | required to execute on the target. Not doing so may cause | 251 | required to execute on the target. Not doing so may cause |
221 | useradd preinst to be invoked twice, causing unwanted warnings. | 252 | useradd preinst to be invoked twice, causing unwanted warnings. |
222 | """ | 253 | """ |
223 | preinst = d.getVar('pkg_preinst_%s' % pkg) or d.getVar('pkg_preinst') | 254 | preinst = d.getVar('pkg_preinst:%s' % pkg) or d.getVar('pkg_preinst') |
224 | if not preinst: | 255 | if not preinst: |
225 | preinst = '#!/bin/sh\n' | 256 | preinst = '#!/bin/sh\n' |
226 | preinst += 'bbnote () {\n\techo "NOTE: $*"\n}\n' | 257 | preinst += 'bbnote () {\n\techo "NOTE: $*"\n}\n' |
@@ -230,15 +261,19 @@ fakeroot python populate_packages_prepend () { | |||
230 | preinst += 'perform_useradd () {\n%s}\n' % d.getVar('perform_useradd') | 261 | preinst += 'perform_useradd () {\n%s}\n' % d.getVar('perform_useradd') |
231 | preinst += 'perform_groupmems () {\n%s}\n' % d.getVar('perform_groupmems') | 262 | preinst += 'perform_groupmems () {\n%s}\n' % d.getVar('perform_groupmems') |
232 | preinst += d.getVar('useradd_preinst') | 263 | preinst += d.getVar('useradd_preinst') |
233 | d.setVar('pkg_preinst_%s' % pkg, preinst) | 264 | # Expand out the *_PARAM variables to the package specific versions |
265 | for rep in ["GROUPADD_PARAM", "USERADD_PARAM", "GROUPMEMS_PARAM"]: | ||
266 | val = d.getVar(rep + ":" + pkg) or "" | ||
267 | preinst = preinst.replace("${" + rep + "}", val) | ||
268 | d.setVar('pkg_preinst:%s' % pkg, preinst) | ||
234 | 269 | ||
235 | # RDEPENDS setup | 270 | # RDEPENDS setup |
236 | rdepends = d.getVar("RDEPENDS_%s" % pkg) or "" | 271 | rdepends = d.getVar("RDEPENDS:%s" % pkg) or "" |
237 | rdepends += ' ' + d.getVar('MLPREFIX', False) + 'base-passwd' | 272 | rdepends += ' ' + d.getVar('MLPREFIX', False) + 'base-passwd' |
238 | rdepends += ' ' + d.getVar('MLPREFIX', False) + 'shadow' | 273 | rdepends += ' ' + d.getVar('MLPREFIX', False) + 'shadow' |
239 | # base-files is where the default /etc/skel is packaged | 274 | # base-files is where the default /etc/skel is packaged |
240 | rdepends += ' ' + d.getVar('MLPREFIX', False) + 'base-files' | 275 | rdepends += ' ' + d.getVar('MLPREFIX', False) + 'base-files' |
241 | d.setVar("RDEPENDS_%s" % pkg, rdepends) | 276 | d.setVar("RDEPENDS:%s" % pkg, rdepends) |
242 | 277 | ||
243 | # Add the user/group preinstall scripts and RDEPENDS requirements | 278 | # Add the user/group preinstall scripts and RDEPENDS requirements |
244 | # to packages specified by USERADD_PACKAGES | 279 | # to packages specified by USERADD_PACKAGES |
@@ -252,4 +287,4 @@ fakeroot python populate_packages_prepend () { | |||
252 | # Use the following to extend the useradd with custom functions | 287 | # Use the following to extend the useradd with custom functions |
253 | USERADDEXTENSION ?= "" | 288 | USERADDEXTENSION ?= "" |
254 | 289 | ||
255 | inherit ${USERADDEXTENSION} | 290 | inherit_defer ${USERADDEXTENSION} |