X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=bup.git;a=blobdiff_plain;f=t%2Ftest-restore-map-owner.sh;h=84f3b08a2cc145ff6eddb0b0c556f098a62e0fd1;hp=6ebfdc550d7243396c22b9f0b3209adc8cd5594b;hb=ea0cb087050dc86bae886c0b2605b83aa819b7d3;hpb=f22c7343443d8af71dcac249cb21c7d7d2cc5686 diff --git a/t/test-restore-map-owner.sh b/t/test-restore-map-owner.sh index 6ebfdc5..84f3b08 100755 --- a/t/test-restore-map-owner.sh +++ b/t/test-restore-map-owner.sh @@ -1,7 +1,10 @@ #!/usr/bin/env bash -. ./wvtest-bup.sh +. ./wvtest-bup.sh || exit $? +. t/lib.sh || exit $? -if [ $(t/root-status) != root ]; then +root_status="$(t/root-status)" || exit $? + +if [ "$root_status" != root ]; then echo 'Not root: skipping restore --map-* tests.' exit 0 # FIXME: add WVSKIP. fi @@ -21,7 +24,7 @@ other_uinfo=$(WVPASS t/id-other-than --user "$user") || exit $? other_user="${other_uinfo%%:*}" other_uid="${other_uinfo##*:}" -other_ginfo=$(WVPASS t/id-other-than --group "$group") || exit $? +other_ginfo=$(WVPASS t/id-other-than --group "$group" 0) || exit $? other_group="${other_ginfo%%:*}" other_gid="${other_ginfo##*:}" @@ -31,6 +34,8 @@ WVPASS cd "$tmpdir" WVSTART "restore --map-user/group/uid/gid (control)" WVPASS mkdir src WVPASS touch src/foo +# Some systems assign the parent dir group to new paths. +WVPASS chgrp -R "$group" src WVPASS bup index src WVPASS bup save -n src src WVPASS bup restore -C dest "src/latest/$(pwd)/src/" @@ -77,14 +82,26 @@ WVPASS grep -qE "^uid: $other_uid\$" foo-xstat WVPASS grep -qE "^group: $other_group\$" foo-xstat WVPASS grep -qE "^gid: $other_gid\$" foo-xstat -WVSTART "restore --map-user/group/uid/gid (zero uid/gid trumps all)" -WVPASS rm -rf dest -WVPASS bup restore -C dest \ - --map-user "$user=$other_user" --map-group "$group=$other_group" \ - --map-uid "$uid=0" --map-gid "$gid=0" \ - "src/latest/$(pwd)/src/" -WVPASS bup xstat dest/foo > foo-xstat -WVPASS grep -qE "^uid: 0\$" foo-xstat -WVPASS grep -qE "^gid: 0\$" foo-xstat +has_uid_gid_0=$(WVPASS bup-python -c " +import grp, pwd +try: + pwd.getpwuid(0) + grp.getgrgid(0) + print('yes') +except KeyError as ex: + pass +") || exit $? +if [ "$has_uid_gid_0" == yes ] +then + WVSTART "restore --map-user/group/uid/gid (zero uid/gid trumps all)" + WVPASS rm -rf dest + WVPASS bup restore -C dest \ + --map-user "$user=$other_user" --map-group "$group=$other_group" \ + --map-uid "$uid=0" --map-gid "$gid=0" \ + "src/latest/$(pwd)/src/" + WVPASS bup xstat dest/foo > foo-xstat + WVPASS grep -qE "^uid: 0\$" foo-xstat + WVPASS grep -qE "^gid: 0\$" foo-xstat -WVPASS rm -rf "$tmpdir" + WVPASS rm -rf "$tmpdir" +fi