2 # Verify that cp -p preserves GID when it is possible.
4 # Copyright (C) 2007-2010 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/>.
20 test "$VERBOSE" = yes && cp --version
24 # Some of the tests expect a umask that grants group and/or world read access.
25 working_umask_or_skip_
27 # Record primary group number, usually 0.
28 # This is the group ID used when cp (without -p) creates a new file.
29 primary_group_num
=$
(id
-g)
32 echo "$1" > "$1" ||
exit 1
33 chown
"+$2:+$3" "$1" ||
exit 1
43 if test "x$s" != "x$u $g"; then
44 # Allow the actual group to match that of the parent directory
45 # (it was set to 0 above).
46 if test "x$s" = "x$u $primary_group_num"; then
49 echo "$0: $* $f b: $u $g != $s" 1>&2
59 t0
"$f" "$u" "$g" setuidgid
-g "$nameless_gid1,$nameless_gid2" \
63 nameless_uid
=`$PERL -le 'foreach my $i (1000..16*1024-1) { getpwuid $i or (print $i), exit }'`
64 nameless_gid1
=`$PERL -le 'foreach my $i (1000..16*1024) { getgrgid $i or (print $i), exit }'`
65 nameless_gid2
=`$PERL -le 'foreach my $i ('"$nameless_gid1"'+1..16*1024) { getgrgid $i or (print $i), exit }'`
67 if test -z "$nameless_uid" \
68 ||
test -z "$nameless_gid1" \
69 ||
test -z "$nameless_gid2"; then
70 skip_test_
"couldn't find a nameless UID or GID"
73 chown
"+$nameless_uid:+0" .
76 create b0
"$nameless_uid" "$nameless_gid1"
77 create b1
"$nameless_uid" "$nameless_gid2"
78 create c0
0 "$nameless_gid1"
79 create c1
0 "$nameless_gid2"
88 t0 b0
"$nameless_uid" "$nameless_gid1" cp -p
89 t0 b1
"$nameless_uid" "$nameless_gid2" cp -p
90 t0 c0
0 "$nameless_gid1" cp -p
91 t0 c1
0 "$nameless_gid2" cp -p
93 t1 a0
"$nameless_uid" "$nameless_gid1" cp
94 t1 b0
"$nameless_uid" "$nameless_gid1" cp
95 t1 b1
"$nameless_uid" "$nameless_gid1" cp
96 t1 c0
"$nameless_uid" "$nameless_gid1" cp
97 t1 c1
"$nameless_uid" "$nameless_gid1" cp
99 t1 a0
"$nameless_uid" "$nameless_gid1" cp -p
100 t1 b0
"$nameless_uid" "$nameless_gid1" cp -p
101 t1 b1
"$nameless_uid" "$nameless_gid2" cp -p
102 t1 c0
"$nameless_uid" "$nameless_gid1" cp -p
103 t1 c1
"$nameless_uid" "$nameless_gid2" cp -p