#
#korn shell script that calls perl script
#
#----------------------------------------------------
# create the user
#----------------------------------------------------
NEWLOGIN=try1
mkuser pgrp=staff groups=staff gecos="user name" home=/home/$NEWLOGIN login=true shell=/usr/bin/ksh $NEWLOGIN
if [ $? -ne 0 ]
then
echo "login $NEWLOGIN not created "
exit 1
fi
#----------------------------------------------------
# crypt the password for newlogin and add the stanza
# in /etc/security/passwd for AIX
#----------------------------------------------------
PASSWORD_FILE=/etc/security/passwd
PASSWORD=$NEWLOGIN # assign the login to the password
type perl 1>/dev/null 2>&1
if [ $? -ne 0 ]
then
echo "perl not available in your PATH, please type in password"
pwdadm $NEWLOGIN
else
perl generate_crypted_pass.pl $PASSWORD_FILE $NEWLOGIN $PASSWORD
if [ $? -ne 0 ]
then
echo "error in generating crypted password"
echo "please type in password for $NEWLOGIN"
pwdadm $NEWLOGIN
fi
# clear the flags for newlogin, so it is not prompted to
# change the password at first telnet connection
pwdadm -c $NEWLOGIN
fi
exit 0
#
#end of korn shell script that calls perl script
#
#
# begin of perl script named "generate_crypted_pass.pl "
# for generating crypted password
#
#-------------------------------------------------------------
# perl script for crypting readable password and writing
# the stanza in file passed as first parameter
#-------------------------------------------------------------
#!/usr/bin/perl
if ( $#ARGV < 2 ){
print "Usage : $0 <password file> <login> <readable password>\n";
die;
}
use POSIX;
$ENV{'TZ'} = "GMT";
#-------------------------------------------------------------
# get parameters
#-------------------------------------------------------------
$password_file=@ARGV[0];
$login=@ARGV[1];
$readable_password=@ARGV[2];
#-------------------------------------------------------------
# generate 2 chars ASCII for salt randomly in the set
# [./0-9A-Za-z]
#-------------------------------------------------------------
# generate first char
$hazard= int(rand()*100) + 26;
$c1=chr($hazard);
while ( $c1 !~ "[./0-9A-Za-z]" ) {
$hazard= int(rand()*100) + 26;
$c1=chr($hazard);
}
# generate 2nd char
$hazard= int(rand()*100) + 26;
$c2=chr($hazard);
while ( $c2 !~ "[./0-9A-Za-z]" ) {
$hazard= int(rand()*100) + 26;
$c2=chr($hazard);
}
# concatenate the 2 chars to make salt
$salt="$c1$c2";
# crypt the readable password
$crypted_password = crypt($readable_password,$salt) ;
# generate last modification time of password since epoch
$last_pass_change = POSIX::time() ;
#-------------------------------------------
# write the stanza in the password file
#-------------------------------------------
open (OUT, ">>$password_file"

|| die "cannot open $password_file: $!.\n";
print OUT<<EOF;
$login:
password = $crypted_password
lastupdate = $last_pass_change
flags =
EOF
exit 0
#
#end of perl script for generating crypted password
#