perm.sh 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/sh
  2. # Verify that mkdir's '-m MODE' option works properly
  3. # with various umask settings.
  4. # Copyright (C) 2000-2018 Free Software Foundation, Inc.
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
  16. print_ver_ mkdir
  17. skip_if_setgid_
  18. require_no_default_acl_ .
  19. working_umask_or_skip_
  20. # parent parent/dir
  21. # umask -m option resulting perm resulting perm
  22. tests='
  23. 000 : empty : drwxrwxrwx : drwxrwxrwx :
  24. 000 : -m 016 : drwxrwxrwx : d-----xrw- :
  25. 077 : empty : drwx------ : drwx------ :
  26. 050 : empty : drwx-w-rwx : drwx-w-rwx :
  27. 050 : -m 312 : drwx-w-rwx : d-wx--x-w- :
  28. 160 : empty : drwx--xrwx : drw---xrwx :
  29. 160 : -m 743 : drwx--xrwx : drwxr---wx :
  30. 027 : -m =+x : drwxr-x--- : d--x--x--- :
  31. 027 : -m =+X : drwxr-x--- : d--x--x--- :
  32. - : - : last : last :
  33. '
  34. colon_tests=$(echo $tests | sed 's/^ *//; s/ *: */:/g')
  35. for p in empty -p; do
  36. test _$p = _empty && p=
  37. old_IFS=$IFS
  38. IFS=':'
  39. set $colon_tests
  40. IFS=$old_IFS
  41. while :; do
  42. test "$VERBOSE" = yes && set -x
  43. umask=$1 mode=$2 parent_perms=$3 sub_perms=$4
  44. test "_$mode" = _empty && mode=
  45. test $sub_perms = last && break
  46. # echo p=$p umask=$1 mode=$2 parent_perms=$3 sub_perms=$4
  47. shift; shift; shift; shift
  48. umask $umask
  49. # If we're not using -p, then create the parent manually,
  50. # and adjust expectations accordingly.
  51. test x$p = x &&
  52. {
  53. mkdir -m =,u=rwx parent || fail=1
  54. parent_perms=drwx------
  55. }
  56. mkdir $p $mode parent/sub || fail=1
  57. perms=$(stat --printf %A parent)
  58. test "$parent_perms" = "$perms" \
  59. || { fail=1; echo parent: expected $parent_perms, got $perms; }
  60. perms=$(stat --printf %A parent/sub)
  61. test "$sub_perms" = "$perms" \
  62. || { fail=1; echo parent/sub: expected $sub_perms, got $perms; }
  63. chmod -R u+rwx parent
  64. rm -rf parent || fail=1
  65. done
  66. done
  67. Exit $fail