setgid.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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.
  5. # Copyright (C) 2001-2018 Free Software Foundation, Inc.
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
  17. print_ver_ chmod
  18. umask 0
  19. mkdir -m 755 d || framework_failure_
  20. chmod g+s d 2> /dev/null && env -- test -g d ||
  21. {
  22. # This is required because on some systems (at least NetBSD 1.4.2A),
  23. # it may happen that when you create a directory, its group isn't one
  24. # to which you belong. When that happens, the above chmod fails. So
  25. # here, upon failure, we try to set the group, then rerun the chmod command.
  26. id_g=$(id -g) &&
  27. test -n "$id_g" &&
  28. chgrp "$id_g" d &&
  29. chmod g+s d || framework_failure_
  30. }
  31. # "chmod g+s d" does nothing on some NFS file systems.
  32. env -- test -g d ||
  33. skip_ 'cannot create setgid directories'
  34. for mode in \
  35. + - g-s 00755 000755 =755 -2000 -7022 755 0755 \
  36. +2000 -5022 =7777,-5022
  37. do
  38. chmod $mode d || fail=1
  39. case $mode in
  40. g-s | 00*755 | =755 | -2000 | -7022)
  41. expected_mode=drwxr-xr-x ;;
  42. *) expected_mode=drwxr-sr-x ;;
  43. esac
  44. ls_output=$(ls -ld d)
  45. case $ls_output in
  46. $expected_mode*) ;;
  47. *) fail=1 ;;
  48. esac
  49. chmod =2755 d || fail=1
  50. done
  51. Exit $fail