summaryrefslogtreecommitdiff
path: root/localpasswdset
blob: 39a8d127f2cfa6689953dafa3751cad281e0c8f1 (plain)
  1. #!/bin/sh
  2. # $Id: localpasswdset,v 1.1 2006-05-08 09:13:15 jonas Exp $
  3. #
  4. # Copyright © 2006 Jonas Smedegaard <dr@jones.dk>
  5. # Description: Set or reset a user account password
  6. #
  7. # This program is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU General Public License as
  9. # published by the Free Software Foundation; either version 2, or (at
  10. # your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful, but
  13. # WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. # General Public License for more details.
  16. set -e
  17. MAXDAYSTEMP="30"
  18. WARNDAYSTEMP="14"
  19. PRG="`basename $0`"
  20. user="$1"
  21. # Reuse system defaults from adduser
  22. if [ -e /etc/adduser.conf ]; then
  23. . /etc/adduser.conf
  24. else
  25. echo 2> "Error: /etc/adduser.conf missing!"
  26. exit 1
  27. fi
  28. # Allow overriding defaults
  29. if [ -e /etc/local/users.conf ]; then
  30. . /etc/local/users.conf
  31. fi
  32. # Integrity check of user
  33. uid="`getent passwd \"$user\" | awk -F: '{print $3}'`"
  34. uidcount="`echo "$uid" | wc --word`"
  35. if [ "$uidcount" -lt "1" ]; then
  36. echo 2> "Error: User \"$user\" not found!"
  37. exit 1
  38. fi
  39. if [ "$uidcount" -gt "1" ]; then
  40. echo 2> "Error: User \"$user\" matched more than a single entry!"
  41. exit 1
  42. fi
  43. if [ "$uid" -lt "$FIRST_UID" ] || [ "$uid" -gt "$LAST_UID" ]; then
  44. echo 2> "Error: User ID ($uid) is outside the range of normal users ($FIRST_UID-$LAST_UID)!"
  45. exit 1
  46. fi
  47. finger -m "$user"
  48. echo
  49. cat <<EOF
  50. You are about to (re)set the password of the above user.
  51. 1. Double-check that this is indeed the correct user
  52. 2. Pick a new password from the list below, and spice up with a number
  53. To abort, type a blank password (just press enter) twice
  54. Suggested new passwords (random but pronouncable):
  55. EOF
  56. gpw
  57. passwd "$user"
  58. chage -M"$MAXDAYSTEMP" -W"$WARNDAYSTEMP" "$user"
  59. echo
  60. cat <<EOF
  61. Password correctly (re)set!
  62. The new password lasts only "$WARNDAYSTEMP" days, so instruct user to
  63. change it soon!
  64. EOF
  65. exit 0