1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-04-20 18:56:39 +02:00
Files
coreutils/tests/cp/preserve-gid
Jim Meyering 3669d2b820 Tweak new test.
* tests/cp/preserve-gid: Split some long lines.
Prepend "+" to numeric uid and gid chown arguments, on principle.
Use skip_test_.
2007-11-24 15:10:59 +01:00

97 lines
2.6 KiB
Bash
Executable File

#!/bin/sh
# Verify that cp -p preserves GID when it is possible.
# Copyright (C) 2007 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
. "$srcdir/../lang-default"
PRIV_CHECK_ARG=require-root . "$srcdir/../priv-check"
. "$srcdir/../test-lib.sh"
create() {
echo "$1" > "$1" || exit 1
chown "+$2:+$3" "$1" || exit 1
}
t0() {
f=$1; shift
u=$1; shift
g=$1; shift
rm -f b || exit 1
"$@" "$f" b || exit 1
s=`stat -c '%u %g' b`
if test "x$s" != "x$u $g"; then
echo "$0: $* $f b: $u $g != $s" 1>&2
(exit 1); exit 1
fi
}
t1() {
f=$1; shift
u=$1; shift
g=$1; shift
t0 "$f" "$u" "$g" setuidgid -g "$nameless_gid1,$nameless_gid2" \
"$nameless_uid" "$@"
}
if test "x$VERBOSE" = xyes; then
set -x
cp --version
fi
nameless_uid=`$PERL -le 'foreach my $i (1000..16*1024-1) { getpwuid $i or (print $i), exit }'`
nameless_gid1=`$PERL -le 'foreach my $i (1000..16*1024) { getgrgid $i or (print $i), exit }'`
nameless_gid2=`$PERL -le 'foreach my $i ('"$nameless_gid1"'+1..16*1024) { getgrgid $i or (print $i), exit }'`
if test -z "$nameless_uid" \
|| test -z "$nameless_gid1" \
|| test -z "$nameless_gid2"; then
skip_test_ "couldn't find a nameless UID or GID"
fi
chown "+$nameless_uid" .
create a0 0 0
create b0 "$nameless_uid" "$nameless_gid1"
create b1 "$nameless_uid" "$nameless_gid2"
create c0 0 "$nameless_gid1"
create c1 0 "$nameless_gid2"
t0 a0 0 0 cp
t0 b0 0 0 cp
t0 b1 0 0 cp
t0 c0 0 0 cp
t0 c1 0 0 cp
t0 a0 0 0 cp -p
t0 b0 "$nameless_uid" "$nameless_gid1" cp -p
t0 b1 "$nameless_uid" "$nameless_gid2" cp -p
t0 c0 0 "$nameless_gid1" cp -p
t0 c1 0 "$nameless_gid2" cp -p
t1 a0 "$nameless_uid" "$nameless_gid1" cp
t1 b0 "$nameless_uid" "$nameless_gid1" cp
t1 b1 "$nameless_uid" "$nameless_gid1" cp
t1 c0 "$nameless_uid" "$nameless_gid1" cp
t1 c1 "$nameless_uid" "$nameless_gid1" cp
t1 a0 "$nameless_uid" "$nameless_gid1" cp -p
t1 b0 "$nameless_uid" "$nameless_gid1" cp -p
t1 b1 "$nameless_uid" "$nameless_gid2" cp -p
t1 c0 "$nameless_uid" "$nameless_gid1" cp -p
t1 c1 "$nameless_uid" "$nameless_gid2" cp -p
(exit 0); exit 0