2000-09-30 08:05:32 +00:00
|
|
|
#!/bin/sh
|
2000-09-30 08:08:21 +00:00
|
|
|
# Verify that mkdir's `-m MODE' option works properly
|
|
|
|
|
# with various umask settings.
|
2000-09-30 08:05:32 +00:00
|
|
|
|
2010-01-01 10:56:28 +01:00
|
|
|
# Copyright (C) 2000, 2002-2010 Free Software Foundation, Inc.
|
2006-08-17 19:58:17 +00:00
|
|
|
|
2007-07-23 14:35:58 +02:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2006-08-17 19:58:17 +00:00
|
|
|
# it under the terms of the GNU General Public License as published by
|
2007-07-23 14:35:58 +02:00
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
2006-08-17 19:58:17 +00:00
|
|
|
# (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
|
2007-07-23 14:35:58 +02:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-08-17 19:58:17 +00:00
|
|
|
|
2000-09-30 08:05:32 +00:00
|
|
|
if test "$VERBOSE" = yes; then
|
|
|
|
|
set -x
|
|
|
|
|
mkdir --version
|
|
|
|
|
fi
|
|
|
|
|
|
2008-05-27 13:45:44 +02:00
|
|
|
. $srcdir/test-lib.sh
|
2009-03-27 09:23:35 +01:00
|
|
|
skip_if_setgid_
|
2008-04-20 23:29:19 +02:00
|
|
|
|
|
|
|
|
working_umask_or_skip_
|
2000-12-26 08:43:03 +00:00
|
|
|
|
2000-09-30 08:05:32 +00:00
|
|
|
|
2000-10-31 10:46:24 +00:00
|
|
|
# parent parent/dir
|
|
|
|
|
# umask -m option resulting perm resulting perm
|
2000-09-30 08:05:32 +00:00
|
|
|
tests='
|
2000-11-11 13:34:51 +00:00
|
|
|
000 : empty : drwxrwxrwx : drwxrwxrwx :
|
2000-11-11 10:21:42 +00:00
|
|
|
000 : -m 016 : drwxrwxrwx : d-----xrw- :
|
2000-11-11 13:34:51 +00:00
|
|
|
077 : empty : drwx------ : drwx------ :
|
|
|
|
|
050 : empty : drwx-w-rwx : drwx-w-rwx :
|
2000-11-11 10:21:42 +00:00
|
|
|
050 : -m 312 : drwx-w-rwx : d-wx--x-w- :
|
2000-11-11 13:34:51 +00:00
|
|
|
160 : empty : drwx--xrwx : drw---xrwx :
|
2000-11-11 10:21:42 +00:00
|
|
|
160 : -m 743 : drwx--xrwx : drwxr---wx :
|
2005-04-22 23:54:05 +00:00
|
|
|
027 : -m =+x : drwxr-x--- : d--x--x--- :
|
2006-07-17 03:12:44 +00:00
|
|
|
027 : -m =+X : drwxr-x--- : d--x--x--- :
|
2000-11-11 10:21:42 +00:00
|
|
|
- : - : last : last :
|
2000-09-30 08:05:32 +00:00
|
|
|
'
|
2005-04-29 21:49:06 +00:00
|
|
|
colon_tests=`echo $tests | sed 's/^ *//; s/ *: */:/g'`
|
|
|
|
|
|
2000-10-31 07:57:29 +00:00
|
|
|
for p in empty -p; do
|
|
|
|
|
test _$p = _empty && p=
|
2000-09-30 08:05:32 +00:00
|
|
|
|
2000-10-31 07:57:29 +00:00
|
|
|
old_IFS=$IFS
|
2000-11-11 10:21:42 +00:00
|
|
|
IFS=':'
|
2005-04-29 21:49:06 +00:00
|
|
|
set $colon_tests
|
2000-10-31 07:57:29 +00:00
|
|
|
IFS=$old_IFS
|
|
|
|
|
|
|
|
|
|
while :; do
|
2000-10-31 10:46:24 +00:00
|
|
|
test "$VERBOSE" = yes && set -x
|
|
|
|
|
umask=$1 mode=$2 parent_perms=$3 sub_perms=$4
|
2000-11-11 13:34:51 +00:00
|
|
|
test "_$mode" = _empty && mode=
|
2000-10-31 10:46:24 +00:00
|
|
|
test $sub_perms = last && break
|
|
|
|
|
# echo p=$p umask=$1 mode=$2 parent_perms=$3 sub_perms=$4
|
|
|
|
|
shift; shift; shift; shift
|
2000-10-31 07:57:29 +00:00
|
|
|
umask $umask
|
|
|
|
|
|
2000-10-31 10:46:24 +00:00
|
|
|
# If we're not using -p, then create the parent manually,
|
|
|
|
|
# and adjust expectations accordingly.
|
|
|
|
|
test x$p = x && \
|
|
|
|
|
{
|
2009-08-22 18:56:06 +02:00
|
|
|
mkdir -m =,u=rwx parent || fail=1
|
|
|
|
|
parent_perms=drwx------
|
2000-10-31 10:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mkdir $p $mode parent/sub || fail=1
|
|
|
|
|
|
2009-02-27 09:16:45 +01:00
|
|
|
perms=$(stat --printf %A parent)
|
2000-10-31 10:46:24 +00:00
|
|
|
test "$parent_perms" = "$perms" \
|
|
|
|
|
|| { fail=1; echo parent: expected $parent_perms, got $perms; }
|
|
|
|
|
|
2009-02-27 09:16:45 +01:00
|
|
|
perms=$(stat --printf %A parent/sub)
|
2000-10-31 10:46:24 +00:00
|
|
|
test "$sub_perms" = "$perms" \
|
|
|
|
|
|| { fail=1; echo parent/sub: expected $sub_perms, got $perms; }
|
|
|
|
|
|
|
|
|
|
chmod -R u+rwx parent
|
|
|
|
|
rm -rf parent || fail=1
|
2000-10-31 07:57:29 +00:00
|
|
|
done
|
2000-09-30 08:05:32 +00:00
|
|
|
done
|
|
|
|
|
|
2008-09-07 10:31:27 +02:00
|
|
|
Exit $fail
|