diff options
author | Jonas Smedegaard <dr@jones.dk> | 2006-05-08 09:13:15 +0000 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2006-05-08 09:13:15 +0000 |
commit | e06baf0221e2e4e15fc7ece124cf8a314e6cbe89 (patch) | |
tree | 73a0e62c97e47f69844c566250a5e277dfed46d1 /localpasswdset | |
parent | edf378c3da04265f298ded1f510e0d7df04210ef (diff) |
New script to set password and temporarily shorten its lifespan.
Diffstat (limited to 'localpasswdset')
-rwxr-xr-x | localpasswdset | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/localpasswdset b/localpasswdset new file mode 100755 index 0000000..39a8d12 --- /dev/null +++ b/localpasswdset @@ -0,0 +1,79 @@ +#!/bin/sh + +# $Id: localpasswdset,v 1.1 2006-05-08 09:13:15 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 + +MAXDAYSTEMP="30" +WARNDAYSTEMP="14" + +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 + +finger -m "$user" +echo +cat <<EOF +You are about to (re)set the password of the above user. + + 1. Double-check that this is indeed the correct user + 2. Pick a new password from the list below, and spice up with a number + +To abort, type a blank password (just press enter) twice + +Suggested new passwords (random but pronouncable): +EOF +gpw +passwd "$user" +chage -M"$MAXDAYSTEMP" -W"$WARNDAYSTEMP" "$user" +echo +cat <<EOF +Password correctly (re)set! + +The new password lasts only "$WARNDAYSTEMP" days, so instruct user to +change it soon! +EOF + +exit 0 |