*** empty log message ***
[coreutils.git] / tests / chmod / setgid
blobb7f9ad14c57c9cca360fd117c498a27f340d4f33
1 #!/bin/sh
2 # Make sure GNU chmod works the same way as those of Solaris, HPUX, AIX
3 # wrt directories with the setgid bit set.
5 if test "$VERBOSE" = yes; then
6 set -x
7 chmod --version
8 fi
10 . $srcdir/../envvar-check
11 . $srcdir/../lang-default
13 pwd=`pwd`
14 tmp=setgid.$$
15 trap 'status=$?; cd $pwd; rm -rf $tmp && exit $status' 0
16 trap '(exit $?); exit' 1 2 13 15
18 framework_failure=0
20 # Record absolute path of srcdir and cd back to current dir.
21 cd $srcdir || framework_failure=1
22 abs_srcdir=`pwd`
23 cd $pwd || framework_failure=1
25 mkdir $tmp || framework_failure=1
26 cd $tmp || framework_failure=1
28 . $abs_srcdir/../setgid-check
30 umask 0
31 mkdir d || framework_failure=1
33 chmod g+s d 2> /dev/null ||
35 # This is required because on some systems (at least NetBSD 1.4.2A),
36 # it may happen that when you create a directory, its group isn't one
37 # to which you belong. When that happens, the above chmod fails. So
38 # here, upon failure, we try to set the group, then rerun the chmod command.
39 group=${FETISH_GROUP-`(id -ng || /usr/xpg4/bin/id -ng) 2>/dev/null`}
40 if test "$group"; then
41 chgrp "$group" d || framework_failure=1
42 chmod g+s d || framework_failure=1
43 else
44 framework_failure=1
48 if test $framework_failure = 1; then
49 echo 'failure in testing framework' 1>&2
50 (exit 1); exit
53 fail=0
55 chmod 755 d
57 # To be compatible with chmod from other vendors,
58 # GNU chmod must not reset a directory's setgid bit.
59 # The latest POSIX draft (d5) allows either behavior. It says:
61 # For regular files, for each bit set in the octal number
62 # corresponding to the set-user-ID-on-execution or the
63 # set-group-ID-on-execution, bits shown in the following table shall
64 # be set; if these bits are not set in the octal number, they are
65 # cleared. For other file types, it is implementation-defined whether
66 # or not requests to set or clear the set-user-ID-on-execution or
67 # set-group-ID-on-execution bits are honored.
69 # FIXME: consider changing GNU chmod to work like other versions of chmod.
70 # For now, this test simply confirms the existing behavior.
71 p=`ls -ld d|sed 's/ .*//'`; case $p in drwxr-xr-x);; *) fail=1;; esac
73 (exit $fail); exit