zoneadmin/chpass

51 lines
1.1 KiB
Plaintext
Raw Normal View History

2017-09-20 23:16:30 +02:00
PATH=/bin:/usr/bin:/usr/sbin:/usr/sfw/bin:/opt/csw/bin
export PATH
if [ $# -lt 2 ]
then
echo "Usage:"
echo " chpass <usermane> <password>"
echo ""
exit 1
fi
mmuser=$1
mmpass=$2
# Solaris has no tool to set a password non-interactively.
# Using "expect" has many risks. So we directly edit /etc/shadow.
sol_pwd()
{
ETCSHADOW=/etc/shadow
DATECHG=`perl -e 'print int time/86400'`
# Backup with owner/permission
if
cp -p ${ETCSHADOW} ${ETCSHADOW}- &&
cp -p ${ETCSHADOW} ${ETCSHADOW}.aux &&
# Overwrite the files; owner/permission and line order remains
awk '
BEGIN { FS=OFS=":" }
($1==user) { $2=hash; $3=datechg }
{ print }
' user="$ID" hash="$HASH" datechg="$DATECHG" < ${ETCSHADOW} > ${ETCSHADOW}.aux
then
# *LK* in pw-hash and 0 in lastchg was overwritten. passwd -u is not necessary
mv -f ${ETCSHADOW}.aux ${ETCSHADOW}
fi
} # sol_pwd
# main
#echo "Enter user:"
#read ID
ID=${mmuser}
#echo "Enter pw:"
#read PASS
PASS=${mmpass}
if [ -z "$ID" ] || [ ${#PASS} -lt 3 ]
then
exit
fi
HASH=`echo "${PASS}" | openssl passwd -stdin` || exit
sol_pwd