mirror of
https://github.com/systemd/systemd.git
synced 2025-06-11 23:17:08 +03:00
test: use setpriv instead of su for user switch from root
systemd-repart needs to find mkfs.ext4 for the test. This is located in the directory /usr/sbin on openSUSE Tumbleweed. But since the variable ALWAYS_SET_PATH in /etc/login.defs is set to yes, su re-initializes the $PATH variable and removes /usr/sbin. Hence, mkfs.ext4 is not found and the test fails. Using setpriv instead of su fixes this issue and is more appropriate to do the switch user task from root. [zjs: move setpriv to $BASICTOOLS and force-push to retrigger CI]
This commit is contained in:
parent
6f1fe575f0
commit
c7bf1959d7
@ -214,6 +214,7 @@ BASICTOOLS=(
|
|||||||
seq
|
seq
|
||||||
setfattr
|
setfattr
|
||||||
setfont
|
setfont
|
||||||
|
setpriv
|
||||||
setsid
|
setsid
|
||||||
sfdisk
|
sfdisk
|
||||||
sh
|
sh
|
||||||
@ -2651,12 +2652,12 @@ inst_binary() {
|
|||||||
# Same as above, but we need to wrap certain libraries unconditionally
|
# Same as above, but we need to wrap certain libraries unconditionally
|
||||||
#
|
#
|
||||||
# chown, getent, login, su, useradd, userdel - dlopen() (not only) systemd's PAM modules
|
# chown, getent, login, su, useradd, userdel - dlopen() (not only) systemd's PAM modules
|
||||||
# ls, mkfs.*, mksquashfs, mkswap, stat
|
# ls, mkfs.*, mksquashfs, mkswap, setpriv, stat
|
||||||
# - pull in nss_systemd with certain options (like ls -l) when
|
# - pull in nss_systemd with certain options (like ls -l) when
|
||||||
# nsswitch.conf uses [SUCCESS=merge] (like on Arch Linux)
|
# nsswitch.conf uses [SUCCESS=merge] (like on Arch Linux)
|
||||||
# delv, dig - pull in nss_resolve if `resolve` is in nsswitch.conf
|
# delv, dig - pull in nss_resolve if `resolve` is in nsswitch.conf
|
||||||
# tar - called by machinectl in TEST-25
|
# tar - called by machinectl in TEST-25
|
||||||
bin_rx='/(chown|delv|dig|getent|login|ls|mkfs\.[a-z0-9]+|mksquashfs|mkswap|stat|su|tar|useradd|userdel)$'
|
bin_rx='/(chown|delv|dig|getent|login|ls|mkfs\.[a-z0-9]+|mksquashfs|mkswap|setpriv|stat|su|tar|useradd|userdel)$'
|
||||||
if get_bool "$IS_BUILT_WITH_ASAN" && [[ "$bin" =~ $bin_rx ]]; then
|
if get_bool "$IS_BUILT_WITH_ASAN" && [[ "$bin" =~ $bin_rx ]]; then
|
||||||
wrap_binary=1
|
wrap_binary=1
|
||||||
fi
|
fi
|
||||||
|
@ -151,8 +151,7 @@ test "$(systemctl show -P Result test20-true.scope)" = success
|
|||||||
runas() {
|
runas() {
|
||||||
declare userid=$1
|
declare userid=$1
|
||||||
shift
|
shift
|
||||||
# shellcheck disable=SC2016
|
XDG_RUNTIME_DIR=/run/user/"$(id -u "$userid")" setpriv --reuid="$userid" --init-groups "$@"
|
||||||
su "$userid" -s /bin/sh -c 'XDG_RUNTIME_DIR=/run/user/$UID exec "$@"' -- sh "$@"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
systemctl start user@4711.service
|
systemctl start user@4711.service
|
||||||
|
@ -8,8 +8,7 @@ systemd-analyze log-level debug
|
|||||||
runas() {
|
runas() {
|
||||||
declare userid=$1
|
declare userid=$1
|
||||||
shift
|
shift
|
||||||
# shellcheck disable=SC2016
|
XDG_RUNTIME_DIR=/run/user/"$(id -u "$userid")" setpriv --reuid="$userid" --init-groups "$@"
|
||||||
su "$userid" -s /bin/sh -c 'XDG_RUNTIME_DIR=/run/user/$UID exec "$@"' -- sh "$@"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
runas testuser systemd-run --wait --user --unit=test-private-users \
|
runas testuser systemd-run --wait --user --unit=test-private-users \
|
||||||
|
@ -6,8 +6,7 @@ set -o pipefail
|
|||||||
runas() {
|
runas() {
|
||||||
declare userid=$1
|
declare userid=$1
|
||||||
shift
|
shift
|
||||||
# shellcheck disable=SC2016
|
XDG_RUNTIME_DIR=/run/user/"$(id -u "$userid")" setpriv --reuid="$userid" --init-groups "$@"
|
||||||
su "$userid" -s /bin/sh -c 'XDG_RUNTIME_DIR=/run/user/$UID exec "$@"' -- sh "$@"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ! command -v systemd-repart &>/dev/null; then
|
if ! command -v systemd-repart &>/dev/null; then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user