diff options
Diffstat (limited to '')
-rwxr-xr-x | tests/chgrp/basic.sh | 110 | ||||
-rwxr-xr-x | tests/chgrp/default-no-deref.sh | 34 | ||||
-rwxr-xr-x | tests/chgrp/deref.sh | 60 | ||||
-rwxr-xr-x | tests/chgrp/no-x.sh | 55 | ||||
-rwxr-xr-x | tests/chgrp/posix-H.sh | 71 | ||||
-rwxr-xr-x | tests/chgrp/recurse.sh | 54 |
6 files changed, 384 insertions, 0 deletions
diff --git a/tests/chgrp/basic.sh b/tests/chgrp/basic.sh new file mode 100755 index 0000000..c3c583a --- /dev/null +++ b/tests/chgrp/basic.sh @@ -0,0 +1,110 @@ +#!/bin/sh +# make sure chgrp is reasonable + +# Copyright (C) 2000-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ chgrp +require_membership_in_two_groups_ +require_local_dir_ + +set _ $groups; shift +g1=$1 +g2=$2 +mkdir d +touch f f2 d/f3 +chgrp $g1 f || fail=1 +chgrp $g2 f || fail=1 +chgrp $g2 f2 || fail=1 +chgrp -R $g1 d || fail=1 + +d_files='d d/f3' + +chgrp $g1 f || fail=1 ; test $(stat --p=%g f) = $g1 || fail=1 +chgrp $g2 f || fail=1 ; test $(stat --p=%g f) = $g2 || fail=1 +chgrp $g2 f || fail=1 ; test $(stat --p=%g f) = $g2 || fail=1 +chgrp '' f || fail=1 ; test $(stat --p=%g f) = $g2 || fail=1 +chgrp $g1 f || fail=1 ; test $(stat --p=%g f) = $g1 || fail=1 +chgrp $g1 f || fail=1 ; test $(stat --p=%g f) = $g1 || fail=1 +chgrp --reference=f2 f ; test $(stat --p=%g f) = $g2 || fail=1 + +chgrp -R $g2 d ||fail=1; test $(stat --p=%g: $d_files) = "$g2:$g2:" || fail=1 +chgrp -R $g1 d ||fail=1; test $(stat --p=%g: $d_files) = "$g1:$g1:" || fail=1 +chgrp -R $g2 d ||fail=1; test $(stat --p=%g: $d_files) = "$g2:$g2:" || fail=1 +chgrp -R $g1 d ||fail=1; test $(stat --p=%g: $d_files) = "$g1:$g1:" || fail=1 +chgrp $g2 d ||fail=1; test $(stat --p=%g: $d_files) = "$g2:$g1:" || fail=1 + +rm -f f +touch f +ln -s f symlink +chgrp $g1 f +test $(stat --printf=%g f) = $g1 || fail=1 + +# This should not change the group of f. +chgrp -h $g2 symlink +test $(stat --printf=%g f) = $g1 || fail=1 + +# Don't fail if chgrp failed to set the group of a symlink. +# Some systems don't support that. +test $(stat --printf=%g symlink) = $g2 || + echo 'info: failed to set group of symlink' 1>&2 + +chown --from=:$g1 :$g2 f; test $(stat --printf=%g f) = $g2 || fail=1 + +# This *should* change the group of f. +# Though note that the diagnostic is misleading in that +# it says the 'group of 'symlink'' has been changed. +chgrp $g1 symlink; test $(stat --printf=%g f) = $g1 || fail=1 +chown --from=:$g1 :$g2 f; test $(stat --printf=%g f) = $g2 || fail=1 + +# If -R is specified without -H or L, -h is assumed. +chgrp -h $g1 f symlink; test $(stat --printf=%g symlink) = $g1 || fail=1 +chgrp -R $g2 symlink +chown --from=:$g1 :$g2 f; test $(stat --printf=%g f) = $g2 || fail=1 + +# Make sure we can change the group of inaccessible files. +chmod a-r f +chown --from=:$g2 :$g1 f; test $(stat --printf=%g f) = $g1 || fail=1 +chmod 0 f +chown --from=:$g1 :$g2 f; test $(stat --printf=%g f) = $g2 || fail=1 + +# chown() must not be optimized away even when +# the file's owner and group already have the desired value. +rm -f f g +touch f g +chgrp $g1 f g +chgrp $g2 g +sleep 1 +chgrp $g1 f + +# The following no-change chgrp command is supposed to update f's ctime, +# but on OpenBSD and Darwin 7.9.0-8.11.1 (aka MacOS X 10.3.9 - 10.4.11) +# it appears to be a no-op for some file system types (at least NFS) so g's +# ctime is more recent. This is not a big deal; +# this test works fine when the files are on a local file system (/tmp). +chgrp '' f +test "$(ls -C -c -t f g)" = 'f g' || \ + { + case $host_triplet in + *openbsd*) echo ignoring known OpenBSD-specific chgrp failure 1>&2 ;; + *darwin7.9.*|*darwin8.*) + echo ignoring known MacOS X-specific chgrp failure 1>&2 ;; + *) echo $host_triplet: no-change chgrp failed to update ctime 1>&2; + fail=1 ;; + esac + } + +Exit $fail diff --git a/tests/chgrp/default-no-deref.sh b/tests/chgrp/default-no-deref.sh new file mode 100755 index 0000000..f7c4cf7 --- /dev/null +++ b/tests/chgrp/default-no-deref.sh @@ -0,0 +1,34 @@ +#!/bin/sh +# Ensure that chgrp -R does not dereference symlinks. + +# Copyright (C) 2006-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ chgrp +require_membership_in_two_groups_ +require_local_dir_ + +set _ $groups; shift +g2=$2 + +mkdir d && touch f && ln -s ../f d/s || framework_failure_ + + +g_init=$(stat --printf=%g f) +chgrp -R $g2 d || fail=1 +test $(stat --printf=%g f) = $g_init || fail=1 + +Exit $fail diff --git a/tests/chgrp/deref.sh b/tests/chgrp/deref.sh new file mode 100755 index 0000000..8398733 --- /dev/null +++ b/tests/chgrp/deref.sh @@ -0,0 +1,60 @@ +#!/bin/sh +# see if chgrp can change the group of a symlink + +# Copyright (C) 2000-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ chgrp +require_membership_in_two_groups_ + +set _ $groups; shift +g1=$1 +g2=$2 + +touch f +ln -s f symlink + +chgrp -h $g2 symlink 2> /dev/null +set _ $(ls -ln symlink) +g=$5 +test "$g" = $g2 || + skip_ "your system doesn't support changing the owner or group" \ + "of a symbolic link." + + +chgrp $g1 f +set _ $(ls -ln f); g=$5; test "$g" = $g1 || fail=1 + +chgrp -h $g2 symlink || fail=1 +set _ $(ls -ln f); g=$5; test "$g" = $g1 || fail=1 +set _ $(ls -ln symlink); g=$5; test "$g" = $g2 || fail=1 + +# This should not change the group of f. +chgrp -h $g2 symlink || fail=1 +set _ $(ls -ln f); g=$5; test "$g" = $g1 || fail=1 +set _ $(ls -ln symlink); g=$5; test "$g" = $g2 || fail=1 + +chgrp $g2 f +set _ $(ls -ln f); g=$5; test "$g" = $g2 || fail=1 + +# This *should* change the group of f. +# Though note that the diagnostic you'd get with -c is misleading in that +# it says the 'group of 'symlink'' has been changed. +chgrp --dereference $g1 symlink +set _ $(ls -ln f); g=$5; test "$g" = $g1 || fail=1 +set _ $(ls -ln symlink); g=$5; test "$g" = $g2 || fail=1 + +Exit $fail diff --git a/tests/chgrp/no-x.sh b/tests/chgrp/no-x.sh new file mode 100755 index 0000000..61888a6 --- /dev/null +++ b/tests/chgrp/no-x.sh @@ -0,0 +1,55 @@ +#!/bin/sh +# Make sure chgrp gives the right diagnostic for a readable, +# but inaccessible directory. + +# Copyright (C) 2003-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ chgrp +require_membership_in_two_groups_ +skip_if_root_ +require_local_dir_ + +set _ $groups; shift +g1=$1 +g2=$2 + +mkdir -p d/no-x/y || framework_failure_ +chmod u=rw d/no-x || framework_failure_ + + +# This must exit nonzero. +chgrp -R $g2 d >/dev/null 2>out && fail=1 + +prog=chgrp +# NOTE: this code is the same for all tests/*/no-x tests. +# Depending on whether fts is using native fdopendir, we see one +# of the following diagnostics (note also the /y suffix in one case): +# prog: 'd/no-x': Permission denied +# prog: cannot access 'd/no-x/y': Permission denied +# prog: cannot read directory 'd/no-x': Permission denied +# Convert either of the latter two to the first one. +sed "s/^$prog: cannot access /$prog: /" out > t && mv t out +sed "s/^$prog: cannot read directory /$prog: /" out > t && mv t out +sed 's,d/no-x/y,d/no-x,' out > t && mv t out + +cat <<EOF > exp +$prog: 'd/no-x': Permission denied +EOF + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/chgrp/posix-H.sh b/tests/chgrp/posix-H.sh new file mode 100755 index 0000000..42e5eef --- /dev/null +++ b/tests/chgrp/posix-H.sh @@ -0,0 +1,71 @@ +#!/bin/sh +# Test POSIX-mandated -H option. + +# Copyright (C) 2003-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ chgrp +require_membership_in_two_groups_ +require_local_dir_ + +set _ $groups; shift +g1=$1 +g2=$2 + +mkdir 1 2 3 || framework_failure_ +touch 1/1F 2/2F 3/3F || framework_failure_ +ln -s 1 1s || framework_failure_ +ln -s ../3 2/2s || framework_failure_ +chgrp -R $g1 1 2 3 || framework_failure_ + + +chgrp --preserve-root -H -R $g2 1s 2 || fail=1 + +# These must have group $g2. +# ========================= +changed=' +1 +1/1F +2 +2/2F +3 +' +for i in $changed; do + # Filter out symlinks (entries that end in 's'), since it's not + # possible to change their group/owner information on some systems. + case $i in *s) continue;; esac + set _ $(ls -dgn $i); shift + group=$3 + test $group = $g2 || fail=1 +done + +# These must have group $g1. +# ========================= +not_changed=' +1s +2/2s +3/3F +' +for i in $not_changed; do + # Filter out symlinks (entries that end in 's'), since it's not + # possible to change their group/owner information on some systems. + case $i in *s) continue;; esac + set _ $(ls -dgn $i); shift + group=$3 + test $group = $g1 || fail=1 +done + +Exit $fail diff --git a/tests/chgrp/recurse.sh b/tests/chgrp/recurse.sh new file mode 100755 index 0000000..a03b961 --- /dev/null +++ b/tests/chgrp/recurse.sh @@ -0,0 +1,54 @@ +#!/bin/sh +# ad-hoc tests of chgrp with -R and -H or -L and symlinks + +# Copyright (C) 2000-2022 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 <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ chgrp +require_membership_in_two_groups_ +require_local_dir_ + +set _ $groups; shift +g1=$1 +g2=$2 + + +# chgrp -R should not traverse a symlink to a directory. +mkdir d e +touch d/dd e/ee +ln -s ../e d/s +chgrp -R $g1 e/ee || fail=1 +# This should not should change the group of e/ee +chgrp -R $g2 d +set _ $(ls -ln e/ee); g=$5; test "$g" = $g1 || fail=1 +# This must change the group of e/ee, since -L makes +# chgrp traverse the symlink from d/s into e. +chgrp -L -R $g2 d +set _ $(ls -ln e/ee); g=$5; test "$g" = $g2 || fail=1 + +# This must *not* change the group of e/ee +chgrp -H -R $g1 d +set _ $(ls -ln e/ee); g=$5; test "$g" = $g2 || fail=1 + +ln -s d link + +# This shouldn't change the group of e/ee either. +chgrp -H -R $g1 link || fail=1 +set _ $(ls -ln e/ee); g=$5; test "$g" = $g2 || fail=1 +# But it *should* change d/dd. +set _ $(ls -ln d/dd); g=$5; test "$g" = $g1 || fail=1 + +Exit $fail |