summaryrefslogtreecommitdiff
path: root/localresetpasswd
diff options
context:
space:
mode:
Diffstat (limited to 'localresetpasswd')
-rwxr-xr-xlocalresetpasswd48
1 files changed, 48 insertions, 0 deletions
diff --git a/localresetpasswd b/localresetpasswd
new file mode 100755
index 0000000..17f41fe
--- /dev/null
+++ b/localresetpasswd
@@ -0,0 +1,48 @@
+#!/bin/sh
+#
+# /usr/local/bin/localresetpasswd
+# Copyright 2006 Jonas Smedegaard <dr@jones.dk>
+#
+# $Id: localresetpasswd,v 1.1 2006-08-31 22:51:03 jonas Exp $
+#
+# Generate random password and apply to account through sudo
+#
+# TODO: Check for bad arguments
+# TODO: Use getopts to offer help
+# TODO: Support overriding options in /etc/local file
+#
+
+set -e
+
+pass_len=11
+
+verbose=1
+#simulate=true
+interactive=0
+
+# echo something, but only if in verbose mode
+vecho() {
+ test -n "$verbose" && echo "$@" >&2
+}
+
+randompass() {
+ gpw 1 $pass_len 2>&- ||
+ pwgen $pass_len 1 2>&- ||
+ tr -d '[\000-\057][\072-\100][\133-\140][\173-\377]' < /dev/urandom |
+ dd bs=$pass_len count=1 2>&-
+}
+
+u=$1
+shift
+
+vecho -n "Generating random password..."
+pass=$(randompass)
+vecho " Done!"
+
+vecho -n "Applying new password to account $u..."
+echo "$u:$pass" | eval $simulate sudo "/usr/sbin/chpasswd"
+vecho " Done!"
+
+eval $simulate localresetpasswdexpiry "$u"
+
+vecho "New password is $pass"