. "$BST_LIB" # base-passwd ships no binary in the image: its main package is empty and, via a # preinst, installs the master /etc/passwd and /etc/group. (update-passwd builds # into a separate subpackage this image does not install.) Coverage is the two # database files, the root entry in each, and that the database is functionally # consumed for name resolution. # # Name resolution on the static wasm32-hwjs glibc image reaches the database two # ways, both asserted below: # - file-reading tools (busybox id/ls, and su/login/dpkg's useradd) parse # /etc/passwd + /etc/group directly. # - glibc getpwnam/getpwuid (GNU coreutils id/ls/chown by name) resolves via # the builtin 'files' NSS service — the image nsswitch.conf uses 'files' # (not the dlopen'd 'compat', which cannot load on the static image). check base-passwd/passwd test -f /etc/passwd check base-passwd/group test -f /etc/group check_out base-passwd/root-user ":0:0:root:" cat /etc/passwd check_out base-passwd/root-grp "root:*:0:" cat /etc/group # The by-name listing cases assert against a file this suite owns end to end: # created on tmpfs and chowned to uid 0 here, so the uid ls(1) has to resolve is # one we set rather than one the backing filesystem supplied. Listing the rootfs # itself cannot carry the assertion — see the rootdir cases below. bp_owned=/tmp/.bst-base-passwd-owner rm -f "$bp_owned"; : > "$bp_owned" && chown 0:0 "$bp_owned" 2>/dev/null # name resolution via the file-reading consumers base-passwd actually feeds: check_out base-passwd/id-root "uid=0(root)" busybox id root check_out base-passwd/ls-names "root" busybox ls -l "$bp_owned" # glibc getpwnam/getpwuid path (GNU coreutils by-name/by-id resolution): check_out base-passwd/nss-getpwnam "uid=0(root)" id root check_out base-passwd/nss-ls-names "root" ls -l "$bp_owned" check base-passwd/nss-chown sh -c "touch /tmp/.bst-chown && chown root:root /tmp/.bst-chown && rm -f /tmp/.bst-chown" rm -f "$bp_owned" # The rootfs's ownership is supplied by whatever backs the mount, not by this # image, so it is evidence about base-passwd only when the mount reports uid 0. # A deployed machine's cloud FS does; the local virtiofs proxy reports the build # host's uid while the process is uid 0. Asserting there would score the host's # directory, so the cases say which environment they are in instead. # # BRINTOS-WORKAROUND: linux-in-the-browser#139 remove -- virtiofs reports the # host's uid for every file on the rootfs while the process is uid 0, so / has no # root owner for ls(1) to name. When #139 closes the guard is dead code and both # cases should assert unconditionally. # read(1) is a shell builtin and busybox is already the shell's own binary, so the # owner is extracted without staging a large exec image the way awk would. bp_rootuid=$(busybox ls -ldn / 2>/dev/null | { read -r _bp_p _bp_l _bp_u _bp_rest; echo "$_bp_u"; }) if [ "$bp_rootuid" = 0 ]; then check_out base-passwd/rootdir-names "root" busybox ls -ld / check_out base-passwd/nss-rootdir-names "root" ls -ld / else bp_why="/ is owned by uid ${bp_rootuid:-?} on this mount, not 0 (brintos/linux-in-the-browser#139) -- the backing FS supplies it, so ls(1) has no root-owned rootfs to name" bst_skip base-passwd/rootdir-names "$bp_why" bst_skip base-passwd/nss-rootdir-names "$bp_why" fi