summaryrefslogtreecommitdiff
path: root/localaccountlock
blob: 5523181b76687190f121af6f7ab4611912b7e2c4 (plain)
  1. #!/bin/sh
  2. # $Id: localaccountlock,v 1.1 2007-05-30 19:02:50 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. PRG="`basename $0`"
  18. user="$1"
  19. # Reuse system defaults from adduser
  20. if [ -e /etc/adduser.conf ]; then
  21. . /etc/adduser.conf
  22. else
  23. echo 2> "Error: /etc/adduser.conf missing!"
  24. exit 1
  25. fi
  26. # Allow overriding defaults
  27. if [ -e /etc/local/users.conf ]; then
  28. . /etc/local/users.conf
  29. fi
  30. # Integrity check of user
  31. uid="`getent passwd \"$user\" | awk -F: '{print $3}'`"
  32. uidcount="`echo "$uid" | wc --word`"
  33. if [ "$uidcount" -lt "1" ]; then
  34. echo 2> "Error: User \"$user\" not found!"
  35. exit 1
  36. fi
  37. if [ "$uidcount" -gt "1" ]; then
  38. echo 2> "Error: User \"$user\" matched more than a single entry!"
  39. exit 1
  40. fi
  41. if [ "$uid" -lt "$FIRST_UID" ] || [ "$uid" -gt "$LAST_UID" ]; then
  42. echo 2> "Error: User ID ($uid) is outside the range of normal users ($FIRST_UID-$LAST_UID)!"
  43. exit 1
  44. fi
  45. passwd -l "$user"
  46. # Samba password
  47. #FIXME: Check if enabled in samba.conf (or included files!)
  48. if [ -x /usr/bin/pdbedit ]; then
  49. pdbedit -c "[D ]" -u "$user"
  50. elif [ -x /usr/bin/smbpasswd ] && [ -f /etc/samba/smbpasswd ]; then
  51. /usr/bin/smbpasswd -d "$user"
  52. fi
  53. echo 2> "Account $user is now locked!"
  54. exit 0