#!/bin/sh # # This is vipw, the password file editor. # # This version of vipw was written because the vipw on HP-SUX is broken. # No matter what you do to the file, it rejects your changes. Hence # this script. It copies /etc/passwd/ to /etc/ptmp, lets you edit it, # and then replaces /etc/passwd with the /etc/ptmp. # # If an error occurs the /etc/ptmp file may remain around, in which case # nobody else can make changes to the password file. Keep that in mind. # Eric Myers - 18 July 1996 (or so) # Department of Physics, University of Michigan, Ann Arbor # @(#) $Revision: 1.3 $ - $Date: 1996/09/03 20:57:48 $ - $Author: myers $ ####################################################################### EDITOR=${EDITOR-"/usr/ucb/vi"} PTMP=/etc/ptmp # temporary editing file is also a lock file # vipw first makes sure another vipw is not running by looking # for the file ${PTMP}. If it already exists, vipw aborts. if [ -f ${PTMP} ]; then echo "vipw: password file locked (${PTMP} exists)" exit 1 fi # Get a copy of the password file /bin/cp /etc/passwd ${PTMP} # Edit this password file if $EDITOR $PTMP then if [ -s $PTMP ]; then if /bin/cp -f ${PTMP} /etc/passwd then /bin/rm -f ${PTMP} exit 0 else echo "vipw: cannot copy $PTMP to /etc/passwd." exit 1 fi else echo "vipw: $PTMP was empty." /bin/rm -f ${PTMP} exit 2 fi else echo "vipw: $EDITOR $PTMP failed." exit 3 fi # Always remove /etc/ptmp file, except for certain errors, # as it's a lock file. /bin/rm -f ${PTMP} exit 0