Don't modify argv in dd.
[coreutils/ericb.git] / tests / cp / preserve-gid
blob516733f33ff8a1a9995561ea34ac328b5d8cbfac
1 #!/bin/sh
2 # Verify that cp -p preserves GID when it is possible.
4 # Copyright (C) 2007, 2008 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 . "$srcdir/../lang-default"
20 PRIV_CHECK_ARG=require-root . "$srcdir/../priv-check"
21 . "$srcdir/../test-lib.sh"
23 create() {
24 echo "$1" > "$1" || exit 1
25 chown "+$2:+$3" "$1" || exit 1
28 t0() {
29 f=$1; shift
30 u=$1; shift
31 g=$1; shift
32 rm -f b || exit 1
33 "$@" "$f" b || exit 1
34 s=`stat -c '%u %g' b`
35 if test "x$s" != "x$u $g"; then
36 # Allow the actual group to match that of the parent directory
37 # (it was set to 0 above).
38 if test "x$s" = "x$u 0"; then
40 else
41 echo "$0: $* $f b: $u $g != $s" 1>&2
42 (exit 1); exit 1
47 t1() {
48 f=$1; shift
49 u=$1; shift
50 g=$1; shift
51 t0 "$f" "$u" "$g" setuidgid -g "$nameless_gid1,$nameless_gid2" \
52 "$nameless_uid" "$@"
55 if test "x$VERBOSE" = xyes; then
56 set -x
57 cp --version
60 nameless_uid=`$PERL -le 'foreach my $i (1000..16*1024-1) { getpwuid $i or (print $i), exit }'`
61 nameless_gid1=`$PERL -le 'foreach my $i (1000..16*1024) { getgrgid $i or (print $i), exit }'`
62 nameless_gid2=`$PERL -le 'foreach my $i ('"$nameless_gid1"'+1..16*1024) { getgrgid $i or (print $i), exit }'`
64 if test -z "$nameless_uid" \
65 || test -z "$nameless_gid1" \
66 || test -z "$nameless_gid2"; then
67 skip_test_ "couldn't find a nameless UID or GID"
70 chown "+$nameless_uid:+0" .
72 create a0 0 0
73 create b0 "$nameless_uid" "$nameless_gid1"
74 create b1 "$nameless_uid" "$nameless_gid2"
75 create c0 0 "$nameless_gid1"
76 create c1 0 "$nameless_gid2"
78 t0 a0 0 0 cp
79 t0 b0 0 0 cp
80 t0 b1 0 0 cp
81 t0 c0 0 0 cp
82 t0 c1 0 0 cp
84 t0 a0 0 0 cp -p
85 t0 b0 "$nameless_uid" "$nameless_gid1" cp -p
86 t0 b1 "$nameless_uid" "$nameless_gid2" cp -p
87 t0 c0 0 "$nameless_gid1" cp -p
88 t0 c1 0 "$nameless_gid2" cp -p
90 t1 a0 "$nameless_uid" "$nameless_gid1" cp
91 t1 b0 "$nameless_uid" "$nameless_gid1" cp
92 t1 b1 "$nameless_uid" "$nameless_gid1" cp
93 t1 c0 "$nameless_uid" "$nameless_gid1" cp
94 t1 c1 "$nameless_uid" "$nameless_gid1" cp
96 t1 a0 "$nameless_uid" "$nameless_gid1" cp -p
97 t1 b0 "$nameless_uid" "$nameless_gid1" cp -p
98 t1 b1 "$nameless_uid" "$nameless_gid2" cp -p
99 t1 c0 "$nameless_uid" "$nameless_gid1" cp -p
100 t1 c1 "$nameless_uid" "$nameless_gid2" cp -p
102 (exit 0); exit 0