]> arthur.barton.de Git - bup.git/commitdiff
Avoid uid/gid 0 metadata tests when ids don't exist 0.26-rc2
authorPatrick Rouleau <prouleau72@gmail.com>
Thu, 3 Jul 2014 00:58:39 +0000 (20:58 -0400)
committerRob Browning <rlb@defaultvalue.org>
Thu, 3 Jul 2014 18:09:10 +0000 (13:09 -0500)
Cygwin may not have a 0 uid/gid, so skip the relevant tests whenever
it doesn't.

We have to explicitly exclude the gid 0 from other_group, because
/etc/group may define a group named root with the same id as
Administrators. We cannot use "root" instead of 0, because root may
not be defined.

Cygwin users: If you want to define the root group, add this line
at the begining of /etc/group:
  root:S-1-5-32-544:0:

Signed-off-by: Patrick Rouleau <prouleau72@gmail.com>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
t/test-restore-map-owner.sh

index 05c3d41eb24693f7545e70d242d1e1a99651cbb7..090aef1746f8f3a4887fb803fcd76f6fc01574cf 100755 (executable)
@@ -21,7 +21,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##*:}"
 
@@ -79,14 +79,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 python -c "
+import grp, pwd
+try:
+  pwd.getpwuid(0)
+  grp.getgrgid(0)
+  print 'yes'
+except KeyError, ex:
+  pass
+" 2>/dev/null) || 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