#!/usr/athena/bin/perl

require 'sys/file.ph';

open(MSTRPWD, ">>/etc/master.passwd") || die "Can't open master.passwd file.. are you root?\n";
flock(MSTRPWD, &LOCK_EX);
while ($name = shift){
    if (getpwnam($name)) {
	print STDERR "Did not add $name: Already on your machine\n";
    }
    elsif (&add_name($name)){
	print STDERR "Did not add $name: Hesiod is not aware of this person.. he is not Athena!!\n";
    }
    else{
	print STDERR "Added $name\n";
    }
}
flock(MSTRPWD, &LOCK_UN);
close(MSTRPWD);
system("/usr/sbin/pwd_mkdb -p /etc/master.passwd");
exit(0);



sub add_name {

    $name = shift(@_);
    $result = `/bin/athena/hesinfo $name passwd` || return 1;
    ($username, $passwd, $uid, $gid, $gecos,$home,$shell) = split(':',$result);
    print MSTRPWD $username,':',$passwd,':',$uid,':', $gid,'::0:0:', $gecos,':',$home,':',$shell;
    return 0;
}
