#!/bin/sh
#
# AUTHOR:  Timothy J. Luoma <luomat@nerc.com>
#
# VERSION: 1.1.0 (second public)
#
# DATE: 18 Oct 1996   
#
# WARNING: USE ENTIRELY AT YOUR OWN RISK
#	   (see the end of document for more)
#
# PURPOSE: Remove and replace password from NetInfo
#
# TESTED UNDER: NeXTStep 3.2 on my NeXTStation
#
# USAGE NOTES: 
#	fiddlepass on|off|confirm
#
# CHANGES: This version is the same as 1.0.0 except that it adds 
# 	   a check to see if there is a password for your account
#	   'fiddlepass.sh confirm' will tell you whether or not
#	   your password exists.
#
#
# LEGALIA:
# 	This program is released into the public domain and may
# be used by anyone as long as they keep my name attached to it
# and do not charge any money for it over and above the cost
# of any media cost (ie the price of a CD full of NeXTstuff).
# The author is released from any responsibility, liability, etc
# etc etc.  If you use it, then you are responsible for it.

name=`basename $0`

# This should be YOUR username
myuser=luomat

# dump the passwords but just pick out mine
pass=`nidump passwd . | grep $myuser`



# IMPORTANT: This should be identical to YOUR CURRENT ENTRY, just
# 		without the password entry
nopass="luomat::100:0:Timothy J. Luoma:/Users/luomat:/usr/local/bin/zsh:"
#       LOGIN   UID GID   NAME         HOME          LOGINSHELL




# look for arguments
case $1 in

	# Remove the Password
	off)
		# dump the other passwords, besides $myuser, into
		# a file
		nidump passwd . | grep -v $myuser > ~/.nidump.$name
		
		# send my real password to a file
		echo "$pass" > ~/.origpass.$name

		# Send the blank entry back to netinfo
		# Without this you will cease to have
		# an account!
		echo "$nopass" >> ~/.nidump.$name
		
		# reload the passwords				
		asroot niload passwd . < ~/.nidump.$name
	;;
	

	# Replace the password
	on)  
		# dump the other passwords, besides $myuser, into
		# a file
		nidump passwd . | grep -v $myuser > ~/.nidump.$name
		
		# add my old password entry back in
		cat ~/.origpass.$name >> ~/.nidump.$name

		# reload the passwords		
		asroot niload passwd . < ~/.nidump.$name && \
		/bin/rm -f ~/.origpass.$name

	;;
	
	confirm)
		pass=`nidump passwd . |grep $USER | \
		sed "s/$USER://g" | colrm 2 1000`
		
		if [ "$pass" = ":" ]
		then
			echo "$name[$$]: No password for $USER"
		else
			echo "$name[$$]: Password found for $USER"
		fi
		
		exit 0
		
	;;

	*)    echo "$name: Argument unknown, use either 'off' or 'on'"
	      exit 1
	;;
esac

# cleanup the file, just in case
/bin/rm -f ~/.nidump.$name

# Restart lookupd, to make the changes known

# make the changes known
pid=`/bin/ps -auxwww | grep -v grep |grep lookupd | awk '{print $2}'`

# restart the lookupd
asroot kill -HUP $pid


exit 0

# WARNINGS, INFO, ETC
#
# This script requires the program 'asroot' 
#
# This script leaves your encrypted password in ~/.origpass.$name
# from the time you run 'fiddlepass off' until you run 'fiddlepass
# on'.  Given that 1) this probably would only be a few minutes,
# 2) no one else has read access to your files, and 3) the password
# is still encrypted, which is how it would be if NeXT used an
# /etc/passwd file, this is not a big deal, still it should be
# mentioned.
#
# This script is designed by and intended for use by standalone
# NeXTers who would like to take advantage of the auto-login feature
# of the loginwindow.  This is set by ROOT's dwrite:
#
# dwrite loginwindow DefaultUser username
#
# I would not use this script, nor would I suggest anyone use this
# script, over a large NetInfo network.
#
# This is how I use the program:
#
# in /etc/rc.local I have:
#
#if [ -x /usr/local/bin/fiddlepass ]; then
#        (su luomat -c /usr/local/bin/fiddlepass off)    >/dev/console
#fi
# (WITHOUT THE "#" OBVIOUSLY!!!!)
#
# I then use the Workspace dwrite 'Workspace LaunchPaths' to run a
# script which invokes 'fiddlepass on'
#
# This means that when I reboot my NeXT my password will automatically
# be removed until I am logged in, at which time it will be restored.
#
# Note: this may not work under anything other than 3.2, I don't know!
#
# EOF
