2022-05-25 14:02:09 +00:00
|
|
|
#!/bin/sh
|
|
|
|
set -eu
|
|
|
|
export LC_ALL=C.UTF-8
|
|
|
|
if [ ! -e /mmdebstrap-testenv ]; then
|
|
|
|
echo "this test modifies the system and should only be run inside a container" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
trap "rm -f /tmp/debian-chroot.tar /tmp/debian-chroot-shifted.tar /tmp/debian-chroot.txt /tmp/debian-chroot-shiftedback.tar /tmp/expected; rm -rf /tmp/debian-chroot" EXIT INT TERM
|
2023-02-01 09:36:16 +00:00
|
|
|
useradd --home-dir /home/user --create-home user
|
2022-05-25 14:02:09 +00:00
|
|
|
echo user:100000:65536 | cmp /etc/subuid -
|
|
|
|
echo user:100000:65536 | cmp /etc/subgid -
|
2022-08-31 03:35:40 +00:00
|
|
|
# include iputils-ping so that we can verify that tarfilter does not remove
|
2022-05-25 14:02:09 +00:00
|
|
|
# extended attributes
|
|
|
|
# run through tarshift no-op to create a tarball that should be bit-by-bit
|
2022-08-31 03:35:40 +00:00
|
|
|
# identical to a round trip through "tarfilter --idshift X" and "tarfilter --idshift -X"
|
2022-05-25 14:02:09 +00:00
|
|
|
runuser -u user -- {{ CMD }} --mode=unshare --variant=apt --include=iputils-ping {{ DIST }} - {{ MIRROR }} \
|
2022-08-31 03:35:40 +00:00
|
|
|
| ./tarfilter --idshift 0 > /tmp/debian-chroot.tar
|
2022-05-25 14:02:09 +00:00
|
|
|
# make sure that xattrs are set in the original tarball
|
|
|
|
mkdir /tmp/debian-chroot
|
2022-10-18 08:32:03 +00:00
|
|
|
tar --xattrs --xattrs-include='*' --directory /tmp/debian-chroot -xf /tmp/debian-chroot.tar ./usr/bin/ping
|
|
|
|
echo "/tmp/debian-chroot/usr/bin/ping cap_net_raw=ep" > /tmp/expected
|
|
|
|
getcap /tmp/debian-chroot/usr/bin/ping | diff -u /tmp/expected - >&2
|
|
|
|
rm /tmp/debian-chroot/usr/bin/ping
|
|
|
|
rmdir /tmp/debian-chroot/usr/bin
|
|
|
|
rmdir /tmp/debian-chroot/usr
|
2022-05-25 14:02:09 +00:00
|
|
|
rmdir /tmp/debian-chroot
|
|
|
|
# shift the uid/gid forward by 100000 and backward by 100000
|
2022-08-31 03:35:40 +00:00
|
|
|
./tarfilter --idshift 100000 < /tmp/debian-chroot.tar > /tmp/debian-chroot-shifted.tar
|
|
|
|
./tarfilter --idshift -100000 < /tmp/debian-chroot-shifted.tar > /tmp/debian-chroot-shiftedback.tar
|
|
|
|
# the tarball before and after the roundtrip through tarfilter should be bit
|
2022-05-25 14:02:09 +00:00
|
|
|
# by bit identical
|
|
|
|
cmp /tmp/debian-chroot.tar /tmp/debian-chroot-shiftedback.tar
|
|
|
|
# manually adjust uid/gid and compare "tar -t" output
|
|
|
|
tar --numeric-owner -tvf /tmp/debian-chroot.tar \
|
2022-10-18 08:42:09 +00:00
|
|
|
| sed 's# 42/0 # 100042/100000 #' \
|
2022-05-25 14:02:09 +00:00
|
|
|
| sed 's# 0/0 # 100000/100000 #' \
|
|
|
|
| sed 's# 0/5 # 100000/100005 #' \
|
|
|
|
| sed 's# 0/8 # 100000/100008 #' \
|
|
|
|
| sed 's# 0/42 # 100000/100042 #' \
|
|
|
|
| sed 's# 0/43 # 100000/100043 #' \
|
|
|
|
| sed 's# 0/50 # 100000/100050 #' \
|
|
|
|
| sed 's/ \+/ /g' \
|
|
|
|
> /tmp/debian-chroot.txt
|
|
|
|
tar --numeric-owner -tvf /tmp/debian-chroot-shifted.tar \
|
|
|
|
| sed 's/ \+/ /g' \
|
2022-10-16 20:32:46 +00:00
|
|
|
| diff -u /tmp/debian-chroot.txt - >&2
|
2022-05-25 14:02:09 +00:00
|
|
|
mkdir /tmp/debian-chroot
|
|
|
|
tar --xattrs --xattrs-include='*' --directory /tmp/debian-chroot -xf /tmp/debian-chroot-shifted.tar
|
|
|
|
echo "100000 100000" > /tmp/expected
|
2022-10-18 08:32:03 +00:00
|
|
|
stat --format="%u %g" /tmp/debian-chroot/usr/bin/ping | diff -u /tmp/expected - >&2
|
|
|
|
echo "/tmp/debian-chroot/usr/bin/ping cap_net_raw=ep" > /tmp/expected
|
|
|
|
getcap /tmp/debian-chroot/usr/bin/ping | diff -u /tmp/expected - >&2
|
2022-05-25 14:02:09 +00:00
|
|
|
echo "0 0" > /tmp/expected
|
2022-10-18 08:32:03 +00:00
|
|
|
runuser -u user -- {{ CMD }} --unshare-helper /usr/sbin/chroot /tmp/debian-chroot stat --format="%u %g" /usr/bin/ping \
|
2022-10-16 20:32:46 +00:00
|
|
|
| diff -u /tmp/expected - >&2
|
2022-10-18 08:32:03 +00:00
|
|
|
echo "/usr/bin/ping cap_net_raw=ep" > /tmp/expected
|
|
|
|
runuser -u user -- {{ CMD }} --unshare-helper /usr/sbin/chroot /tmp/debian-chroot getcap /usr/bin/ping \
|
2022-10-16 20:32:46 +00:00
|
|
|
| diff -u /tmp/expected - >&2
|