Listing 3: The client password update script
#!/bin/sh
#
# passwd-update -- update /etc/passwd from a copy of the master. Spends
# most of it's time checking to see if it succeeded.
#
SAFEPLACE=/usr/local/etc/passwd # Place where the master puts it.
SAFEMINIMUM=25 # Smallest allowable /etc/passwd file size, in lines.
if ccopy $SAFEPLACE /etc/ptmp; then
: It was ok.
else
echo "$0: /etc/ptmp exists, therefor the /etc/passwd file"
echo " is locked. Try again later, please."
exit 0
fi
# Check size didn't fall, indicating out-of-space in root.
ptmpSize=`wc -l /etc/ptmp`
if [ $ptmpSize -ne `wc -l $SAFEPLACE` ]; then
echo "$0: copy from $SAFEPLACE to /etc/ptmp failed: size changed."
echo " You may be out of space in the root partition."
rm /etc/ptmp
exit 3
fi
# Double-check that total size didn't decrease too much.
if [ `expr $ptmpSize + 1` -lt `wc -l /etc/passwd' ]; then
echo "$0: new version from $SAFEPLACE was more than one line"
echo " smaller than /etc/passwd. Please check file sizes"
echo " and free space in the root partition."
rm /etc/ptmp
exit 3
elif [ $ptmpSize -lt $SAFEMINIMUM ]; then
echo "$0: new version from $SAFEPLACE was less than $SAFEMINIMUM"
echo " lines long. This is impossible: please check file sizes"
echo " and free space in the root partition."
rm /etc/ptmp
exit 3
fi
mv /etc/ptmp /etc/passwd
# End of File
|