2 # Verify that mkdir's `-m MODE' option works properly
3 # with various umask settings.
5 # Copyright (C) 2000, 2002, 2003, 2004, 2005, 2006 Free Software
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 2 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, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 if test "$VERBOSE" = yes; then
29 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
30 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
31 trap '(exit $?); exit' 1 2 13 15
35 # Record absolute path of srcdir and cd back to current dir.
36 cd $srcdir || framework_failure=1
38 cd $pwd || framework_failure=1
40 mkdir -p $tmp || framework_failure=1
41 cd $tmp || framework_failure=1
43 if test $framework_failure = 1; then
44 echo 'failure in testing framework'
48 . $abs_srcdir/../setgid-check
49 . $abs_srcdir/../umask-check
54 # umask -m option resulting perm resulting perm
56 000 : empty : drwxrwxrwx : drwxrwxrwx :
57 000 : -m 016 : drwxrwxrwx : d-----xrw- :
58 077 : empty : drwx------ : drwx------ :
59 050 : empty : drwx-w-rwx : drwx-w-rwx :
60 050 : -m 312 : drwx-w-rwx : d-wx--x-w- :
61 160 : empty : drwx--xrwx : drw---xrwx :
62 160 : -m 743 : drwx--xrwx : drwxr---wx :
63 027 : -m =+x : drwxr-x--- : d--x--x--- :
64 027 : -m =+X : drwxr-x--- : d--x--x--- :
67 colon_tests=`echo $tests | sed 's/^ *//; s/ *: */:/g'`
70 test _$p = _empty && p=
78 test "$VERBOSE" = yes && set -x
79 umask=$1 mode=$2 parent_perms=$3 sub_perms=$4
80 test "_$mode" = _empty && mode=
81 test $sub_perms = last && break
82 # echo p=$p umask=$1 mode=$2 parent_perms=$3 sub_perms=$4
83 shift; shift; shift; shift
86 # If we're not using -p, then create the parent manually,
87 # and adjust expectations accordingly.
90 mkdir -m =,u=rwx parent || fail=1
91 parent_perms=drwx------
94 mkdir $p $mode parent/sub || fail=1
96 perms=`ls -ld parent | sed 's/ .*//; s/+$//'`
97 test "$parent_perms" = "$perms" \
98 || { fail=1; echo parent: expected $parent_perms, got $perms; }
100 perms=`ls -ld parent/sub | sed 's/ .*//; s/+$//'`
101 test "$sub_perms" = "$perms" \
102 || { fail=1; echo parent/sub: expected $sub_perms, got $perms; }
104 chmod -R u+rwx parent
105 rm -rf parent || fail=1
109 (exit $fail); exit $fail