Here is the script:
#!/usr/bin/perl
#Adduser - add a user to the xxxdomain NIS domain
# also, creates a home directory and establishes an alias
# emails notification to <username>@xxx.com automatically, so
# usage: Adduser <username> <homedir node> <uid> "<User Full Name">
#Valid nodes
undef %is_node;
grep($is_node{$_}++, ('filer','topone','aixserver'));
#Main program
#Untaint the variables
$ENV{PATH} = "/bin:/usr/bin:/usr/sbin:/usr/local/bin";
I've tried this several ways:
$ENV{SHELL} = "/usr/local/bin/bash";
$shell = $ENV{'SHELL'};
($ARGV[0]) || die 'Account name not specified (Adduser user node uid "User Name")';
($ARGV[1]) || die 'Node name not specified (Adduser user node uid "User Name")';
($ARGV[2]) || die 'Employee ID / User ID not specified (Adduser user node uid "User Name")';
($ARGV[3]) || die 'User name not specified (Adduser user node uid "User name")';
$ARGV[0] =~ /(\w+)/;
$ARGV[0] = $1;
$ARGV[1] =~ /(\w+)/;
$ARGV[1] = $1;
$ARGV[2] =~ /(\w+)/;
$ARGV[2] = $1;
$ARGV[3] =~ /(.+)/;
$ARGV[3] = $1;
#Check arguments
if (`/usr/bin/grep ^$ARGV[0]: /var/yp/etc/passwd`) {die "User $ARGV[0] already exists"};
if (`/usr/bin/grep ^.*:$ARGV[2]: /var/yp/etc/passwd`) {die "UID $ARGV[2] already exists"};
$is_node{$ARGV[1]} || die "$ARGV[1] -- Invalid node name";
if($ARGV[0] =~ /[A-Z]/) {die "$ARGV[0] -- Caps not allowed in usernames"};
#Create the user
print "\n\nMaking the user ...\n\n";
$homed = "/usr1"; # aixserver
if ($ARGV[1] eq "topone") { $homed = "/home3"};
if ($ARGV[1] eq "filer") { $homed = "/vol/vol0/home"};
#
print `echo "$ARGV[0]:*:$ARGV[2]:1::0:0:$ARGV[3],,,,$ARGV[2]:/net/$ARGV[1]$homed/$ARGV[0]:/bin/ksh" | cat >> /var/yp/etc/passwd`;
print "\n";
# Add an alias..
print "\n\nMaking the alias ...\n\n";
print `echo "$ARGV[0]: $ARGV[0]\@xxx.com" >> /var/yp/etc/aliases`;
# Push NIS maps
print `cd /var/yp ; /usr/ccs/bin/make`;
print "\n";
# Give the user a random password, with a safety backup
# -x = length, -x = alt. right and left hand when typing
# uppercase converted to lowercase, and print it out
$ipassword=`/usr/local/bin/mkpasswd -x x -x x -x x -x -x /usr/bin/passwd $ARGV[0]`;
if ( ! $ipassword ) { print ">>> mkpasswd failed! fix me! <<<...\n"; }
# Notify
chomp($ipassword);
print "$ARGV[0]'s initial password = \"$ipassword\" --- user should change it immediately!!!...\n";
#Make home & populate
print "\n\nMaking the home directory on $ARGV[1]...\n";
#must change uid to do remsh saving the original name
$logname = (getpwuid($<))[0];
if($ENV{REMOTE_USER}) {$logname = $ENV{REMOTE_USER};} #Running from Web
$< = $>;
print `mkdir -m 755 /net/$ARGV[1]/$homed/$ARGV[0]`;
print `cd /usr/local/share/skel ; cp * .[^.]* /net/$ARGV[1]/$homed/$ARGV[0]`;
print `chown -R $ARGV[0] /net/$ARGV[1]/$homed/$ARGV[0]`;
#Send a message to admins
print `echo $ARGV[0], uid $ARGV[2], added on $ARGV[1] | mail -s "New user added by $logname" admin\@xxx.com`;
#Send a message to user
I cut out a long section that notifies me of the account creation as well as a welcome email to the user.
#End of program