summaryrefslogtreecommitdiff
path: root/localaccountunlock
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2007-05-30 19:02:50 +0000
committerJonas Smedegaard <dr@jones.dk>2007-05-30 19:02:50 +0000
commitfcd748c2a54d7ca165ee4c1cc98844e6eb814e64 (patch)
tree3da1d92ffdc6f161c15a5ddcbad94f10b481c2a7 /localaccountunlock
parentebf4465f22cbb7c59377f855f96a6561ed99870a (diff)
Add new commands localaccountlock localaccountunlock .
Diffstat (limited to 'localaccountunlock')
-rwxr-xr-xlocalaccountunlock65
1 files changed, 65 insertions, 0 deletions
diff --git a/localaccountunlock b/localaccountunlock
new file mode 100755
index 0000000..15877c9
--- /dev/null
+++ b/localaccountunlock
@@ -0,0 +1,65 @@
+#!/bin/sh
+
+# $Id: localaccountunlock,v 1.1 2007-05-30 19:02:50 jonas Exp $
+#
+# Copyright © 2006 Jonas Smedegaard <dr@jones.dk>
+# Description: Set or reset a user account password
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2, or (at
+# your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+set -e
+
+PRG="`basename $0`"
+
+user="$1"
+
+# Reuse system defaults from adduser
+if [ -e /etc/adduser.conf ]; then
+ . /etc/adduser.conf
+else
+ echo 2> "Error: /etc/adduser.conf missing!"
+ exit 1
+fi
+
+# Allow overriding defaults
+if [ -e /etc/local/users.conf ]; then
+ . /etc/local/users.conf
+fi
+
+# Integrity check of user
+uid="`getent passwd \"$user\" | awk -F: '{print $3}'`"
+uidcount="`echo "$uid" | wc --word`"
+if [ "$uidcount" -lt "1" ]; then
+ echo 2> "Error: User \"$user\" not found!"
+ exit 1
+fi
+if [ "$uidcount" -gt "1" ]; then
+ echo 2> "Error: User \"$user\" matched more than a single entry!"
+ exit 1
+fi
+if [ "$uid" -lt "$FIRST_UID" ] || [ "$uid" -gt "$LAST_UID" ]; then
+ echo 2> "Error: User ID ($uid) is outside the range of normal users ($FIRST_UID-$LAST_UID)!"
+ exit 1
+fi
+
+passwd -u "$user"
+
+# Samba password
+#FIXME: Check if enabled in samba.conf (or included files!)
+if [ -x /usr/bin/pdbedit ]; then
+ pdbedit -c "[ ]" -u "$user"
+elif [ -x /usr/bin/smbpasswd ] && [ -f /etc/samba/smbpasswd ]; then
+ /usr/bin/smbpasswd -e "$user"
+fi
+
+echo 2> "Account $user is now unlocked!"
+
+exit 0