shadowconfig 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #! /bin/sh -
  2. #
  3. # Turn shadow passwords on or off (based on Debian's shadowconfig.sh)
  4. #
  5. # Copyright (c) 2018 Matias Fonzo, <selk@dragora.org>.
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License");
  8. # you may not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. umask 022
  19. IFS='
  20. '
  21. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin
  22. usage()
  23. {
  24. echo "Usage: ${0##*/} [on|off]"
  25. echo "Turn shadow passwords ON or OFF."
  26. }
  27. # Exit immediately on any error
  28. set -e
  29. # Be immune to the following signals
  30. trap "" HUP INT QUIT ABRT TERM
  31. # Parse options
  32. case $1 in
  33. on | ON )
  34. pwck -q -r
  35. grpck -r
  36. pwconv
  37. grpconv
  38. chown root:root /etc/passwd /etc/group
  39. chmod 644 /etc/passwd /etc/group
  40. chown root:shadow /etc/shadow /etc/gshadow
  41. chmod 640 /etc/shadow /etc/gshadow
  42. echo "Shadow passwords are now on."
  43. ;;
  44. off | OFF )
  45. pwck -q -r
  46. grpck -r
  47. pwunconv
  48. grpunconv
  49. # sometimes the passwd perms get munged
  50. chown root:root /etc/passwd /etc/group
  51. chmod 644 /etc/passwd /etc/group
  52. echo "Shadow passwords are now off."
  53. ;;
  54. --help | -h )
  55. usage
  56. exit 0
  57. ;;
  58. -*)
  59. echo "Unrecognized option: $1" 1>&2
  60. usage
  61. exit 1
  62. ;;
  63. *)
  64. usage
  65. ;;
  66. esac