diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 16:11:47 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 16:11:47 +0000 |
commit | 758f820bcc0f68aeebac1717e537ca13a320b909 (patch) | |
tree | 48111ece75cf4f98316848b37a7e26356e00669e /tests/chmod | |
parent | Initial commit. (diff) | |
download | coreutils-758f820bcc0f68aeebac1717e537ca13a320b909.tar.xz coreutils-758f820bcc0f68aeebac1717e537ca13a320b909.zip |
Adding upstream version 9.1.upstream/9.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/chmod')
-rwxr-xr-x | tests/chmod/c-option.sh | 51 | ||||
-rwxr-xr-x | tests/chmod/equal-x.sh | 34 | ||||
-rwxr-xr-x | tests/chmod/equals.sh | 46 | ||||
-rwxr-xr-x | tests/chmod/ignore-symlink.sh | 31 | ||||
-rwxr-xr-x | tests/chmod/inaccessible.sh | 28 | ||||
-rwxr-xr-x | tests/chmod/no-x.sh | 56 | ||||
-rwxr-xr-x | tests/chmod/octal.sh | 29 | ||||
-rwxr-xr-x | tests/chmod/setgid.sh | 64 | ||||
-rwxr-xr-x | tests/chmod/silent.sh | 29 | ||||
-rwxr-xr-x | tests/chmod/thru-dangling.sh | 31 | ||||
-rwxr-xr-x | tests/chmod/umask-x.sh | 26 | ||||
-rwxr-xr-x | tests/chmod/usage.sh | 86 |
12 files changed, 511 insertions, 0 deletions
diff --git a/tests/chmod/c-option.sh b/tests/chmod/c-option.sh new file mode 100755 index 0000000..f9deeb2 --- /dev/null +++ b/tests/chmod/c-option.sh @@ -0,0 +1,51 @@ +#!/bin/sh +# Verify that chmod's --changes (-c) option works. + +# 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_ chmod + +umask 0 +file=f +touch $file || framework_failure_ +chmod 444 $file || framework_failure_ + +skip_if_setgid_ + + +chmod u=rwx $file || fail=1 +chmod -c g=rwx $file > out || fail=1 +chmod -c g=rwx $file > empty || fail=1 + +compare /dev/null empty || fail=1 +case "$(cat out)" in + "mode of 'f' changed from 0744 "?rwxr--r--?" to 0774 "?rwxrwxr--?) ;; + *) cat out; fail=1 ;; +esac + +# From V5.1.0 to 8.22 this would stat the wrong file and +# give an erroneous ENOENT diagnostic +mkdir -p a/b || framework_failure_ +# chmod g+s might fail as detailed in setgid.sh +# but we don't care about those edge cases here +chmod g+s a/b +# This should never warn, but it did when special +# bits are set on b (the common case under test) +chmod -c -R g+w a 2>err +compare /dev/null err || fail=1 + +Exit $fail diff --git a/tests/chmod/equal-x.sh b/tests/chmod/equal-x.sh new file mode 100755 index 0000000..0e4f236 --- /dev/null +++ b/tests/chmod/equal-x.sh @@ -0,0 +1,34 @@ +#!/bin/sh +# Test "chmod =x" and the like. + +# Copyright (C) 1999-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_ chmod + +file=f +touch $file || framework_failure_ + +umask 005 +for mode in =x =xX =Xx =x,=X =X,=x; do + chmod a=r,$mode $file || fail=1 + case "$(ls -l $file)" in + ---x--x---*) ;; + *) fail=1; echo "after 'chmod $mode $file':"; ls -l $file ;; + esac +done + +Exit $fail diff --git a/tests/chmod/equals.sh b/tests/chmod/equals.sh new file mode 100755 index 0000000..182474a --- /dev/null +++ b/tests/chmod/equals.sh @@ -0,0 +1,46 @@ +#!/bin/sh +# Make sure chmod mode arguments of the form A=B work properly. +# Before fileutils-4.1.2, some of them didn't. +# Also, before coreutils-5.3.1, =[ugo] sometimes didn't work. + +# Copyright (C) 2001-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_ chmod + +touch f || framework_failure_ + + +expected_u=-rwx------ +expected_g=----rwx--- +expected_o=-------rwx + +for src in u g o; do + for dest in u g o; do + test $dest = $src && continue + chmod a=,$src=rwx,$dest=$src,$src= f || fail=1 + actual_perms=$(ls -l f|cut -b-10) + expected_perms=$(eval 'echo $expected_'$dest) + test "$actual_perms" = "$expected_perms" || fail=1 + done +done + +umask 027 +chmod a=,u=rwx,=u f || fail=1 +actual_perms=$(ls -l f|cut -b-10) +test "$actual_perms" = "-rwxr-x---" || fail=1 + +Exit $fail diff --git a/tests/chmod/ignore-symlink.sh b/tests/chmod/ignore-symlink.sh new file mode 100755 index 0000000..9bc03e8 --- /dev/null +++ b/tests/chmod/ignore-symlink.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# Test for proper exit code of chmod on a processed symlink. + +# Copyright (C) 2021-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_ chmod + +mkdir dir || framework_failure_ +touch dir/f || framework_failure_ +ln -s f dir/l || framework_failure_ + +# This operation ignores symlinks but should succeed. +chmod u+w -R dir 2> out || fail=1 + +compare /dev/null out || fail=1 + +Exit $fail diff --git a/tests/chmod/inaccessible.sh b/tests/chmod/inaccessible.sh new file mode 100755 index 0000000..70ed53b --- /dev/null +++ b/tests/chmod/inaccessible.sh @@ -0,0 +1,28 @@ +#!/bin/sh +# Test for the bug fixed on 2006-09-20. + +# 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_ chmod + +mkdir -p d/e || framework_failure_ +chmod 0 d/e d || framework_failure_ + + +chmod u+rwx d d/e || fail=1 + +Exit $fail diff --git a/tests/chmod/no-x.sh b/tests/chmod/no-x.sh new file mode 100755 index 0000000..052634d --- /dev/null +++ b/tests/chmod/no-x.sh @@ -0,0 +1,56 @@ +#!/bin/sh +# Make sure chmod 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_ chmod +skip_if_root_ + +mkdir -p d/no-x/y a/b || framework_failure_ +chmod u=rw d/no-x || framework_failure_ + + +# This must exit nonzero. +chmod -R o=r d >/dev/null 2>out && fail=1 + +prog=chmod +# 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 + +cd a +# This will fail with ''chmod: fts_read failed: Permission denied'' +# chmod must exit with status 1. +# Due to a bug in coreutils-5.93's fts.c, chmod would provoke +# an abort (exit with status 134) on recent glibc-based systems. +returns_ 1 chmod a-x . b 2> /dev/null || fail=1 + +Exit $fail diff --git a/tests/chmod/octal.sh b/tests/chmod/octal.sh new file mode 100755 index 0000000..4d4e6a1 --- /dev/null +++ b/tests/chmod/octal.sh @@ -0,0 +1,29 @@ +#!/bin/sh +# ensure that chmod diagnoses a certain type of invalid mode string + +# Copyright (C) 2005-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_ chmod + + +# Before coreutils-5.92, this would mistakenly succeed, +# and act like 'chmod 0 .'. +for mode in '0-anything' '7-anything' '8'; do + returns_ 1 chmod "$mode" . 2>/dev/null || fail=1 +done + +Exit $fail diff --git a/tests/chmod/setgid.sh b/tests/chmod/setgid.sh new file mode 100755 index 0000000..fdeb343 --- /dev/null +++ b/tests/chmod/setgid.sh @@ -0,0 +1,64 @@ +#!/bin/sh +# Make sure GNU chmod works the same way as those of Solaris, HPUX, AIX +# on directories with the setgid bit set. Also, check that the GNU octal +# notations work. + +# Copyright (C) 2001-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_ chmod + +umask 0 +mkdir -m 755 d || framework_failure_ + +chmod g+s d 2> /dev/null && env -- test -g d || + { + # This is required because on some systems (at least NetBSD 1.4.2A), + # it may happen that when you create a directory, its group isn't one + # to which you belong. When that happens, the above chmod fails. So + # here, upon failure, we try to set the group, then rerun the chmod command. + + id_g=$(id -g) && + test -n "$id_g" && + chgrp "$id_g" d && + chmod g+s d || framework_failure_ + } + +# "chmod g+s d" does nothing on some NFS file systems. +env -- test -g d || + skip_ 'cannot create setgid directories' + +for mode in \ + + - g-s 00755 000755 =755 -2000 -7022 755 0755 \ + +2000 -5022 =7777,-5022 +do + chmod $mode d || fail=1 + + case $mode in + g-s | 00*755 | =755 | -2000 | -7022) + expected_mode=drwxr-xr-x ;; + *) expected_mode=drwxr-sr-x ;; + esac + ls_output=$(ls -ld d) + case $ls_output in + $expected_mode*) ;; + *) fail=1 ;; + esac + + chmod =2755 d || fail=1 +done + +Exit $fail diff --git a/tests/chmod/silent.sh b/tests/chmod/silent.sh new file mode 100755 index 0000000..c47fae2 --- /dev/null +++ b/tests/chmod/silent.sh @@ -0,0 +1,29 @@ +#!/bin/sh +# ensure that chgrp, chmod, chown -f don't print some diagnostics + +# Copyright (C) 2008-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 chmod chown + +chmod -f 0 no-such 2> out && fail=1 +chgrp -f 0 no-such 2>> out && fail=1 +chown -f 0:0 no-such 2>> out && fail=1 +touch exp || fail=1 + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/chmod/thru-dangling.sh b/tests/chmod/thru-dangling.sh new file mode 100755 index 0000000..9953816 --- /dev/null +++ b/tests/chmod/thru-dangling.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# Test for proper error and exit code of chmod on a dangling symlink. + +# Copyright (C) 2007-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_ chmod + +ln -s non-existent dangle || framework_failure_ + + +# This operation cannot succeed since the symbolic link dangles. +chmod 644 dangle 2> out && fail=1 + +echo "chmod: cannot operate on dangling symlink 'dangle'" > exp +compare exp out || fail=1 + +Exit $fail diff --git a/tests/chmod/umask-x.sh b/tests/chmod/umask-x.sh new file mode 100755 index 0000000..85c53a5 --- /dev/null +++ b/tests/chmod/umask-x.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# Test that chmod -x file reports an error if the result is executable. + +# Copyright (C) 2005-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_ chmod + +touch file +chmod 755 file +(umask 77 && returns_ 1 chmod -x file) 2>/dev/null || fail=1 + +Exit $fail diff --git a/tests/chmod/usage.sh b/tests/chmod/usage.sh new file mode 100755 index 0000000..2144230 --- /dev/null +++ b/tests/chmod/usage.sh @@ -0,0 +1,86 @@ +#!/bin/sh +# Verify that chmod works correctly with odd option combinations. + +# Copyright (C) 2004-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_ chmod + + +# Each line in this list is a set of arguments, followed by :, +# followed by the set of files it will attempt to chmod, +# or empty if the usage is erroneous. +# Many of these test cases are due to Glenn Fowler. +# These test cases assume GNU behavior for "options" like -w. +cases=' + -- : + -- -- : + -- -- -- f : -- f + -- -- -w f : -w f + -- -- f : f + -- -w : + -- -w -- f : -- f + -- -w -w f : -w f + -- -w f : f + -- f : + -w : + -w -- : + -w -- -- f : -- f + -w -- -w f : -w f + -w -- f : f + -w -w : + -w -w -- f : f + -w -w -w f : f + -w -w f : f + -w f : f + f : + f -- : + f -w : f + f f : + u+gr f : + ug,+x f : +' + +all_files=$(echo "$cases" | sed 's/.*://'|sort -u) + +old_IFS=$IFS +IFS=' +' +for case in $cases; do + IFS=$old_IFS + args=$(expr "$case" : ' *\(.*[^ ]\) *:') + files=$(expr "$case" : '.*: *\(.*\)') + + case $files in + '') + touch -- $all_files || framework_failure_ + returns_ 1 chmod $args 2>/dev/null || fail=1 + ;; + ?*) + touch -- $files || framework_failure_ + chmod $args || fail=1 + for file in $files; do + # Test for misparsing args by creating all $files but $file. + # chmod has a bug if it succeeds even though $file is absent. + rm -f -- $all_files && touch -- $files && rm -- $file \ + || framework_failure_ + returns_ 1 chmod $args 2>/dev/null || fail=1 + done + ;; + esac +done + +Exit $fail |