tests: cksum: add incorrect data to verify --check & --strict
[coreutils.git] / tests / chmod / setgid.sh
blobb8f1e4fb4f6a3f6d35799be477b5f17d21ec7e6b
1 #!/bin/sh
2 # Make sure GNU chmod works the same way as those of Solaris, HPUX, AIX
3 # on directories with the setgid bit set. Also, check that the GNU octal
4 # notations work.
6 # Copyright (C) 2001-2024 Free Software Foundation, Inc.
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <https://www.gnu.org/licenses/>.
21 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
22 print_ver_ chmod
24 umask 0
25 mkdir -m 755 d || framework_failure_
27 # "chmod g+s d" does nothing on some NFS file systems.
28 chmod g+s d 2> /dev/null && env -- test -g d ||
30 # This is required because on some systems (at least NetBSD 1.4.2A),
31 # it may happen that when you create a directory, its group isn't one
32 # to which you belong. When that happens, the above chmod fails. So
33 # here, upon failure, we try to set the group, then rerun the chmod command.
35 for id_g in $(id -g) $(id -G) ''; do
36 test -n "$id_g" || break
37 chgrp "$id_g" d && chmod g+s d && env -- test -g d && break
38 done
39 test -n "$id_g"
40 } ||
41 skip_ 'cannot create setgid directories'
43 for mode in \
44 + - g-s 00755 000755 =755 -2000 -7022 755 0755 \
45 +2000 -5022 =7777,-5022
47 chmod $mode d || fail=1
49 case $mode in
50 g-s | 00*755 | =755 | -2000 | -7022)
51 expected_mode=drwxr-xr-x ;;
52 *) expected_mode=drwxr-sr-x ;;
53 esac
54 ls_output=$(ls -ld d)
55 case $ls_output in
56 $expected_mode*) ;;
57 *) fail=1 ;;
58 esac
60 chmod =2755 d || fail=1
61 done
63 Exit $fail