#/usr/local/bin/perl

$PIPE = "|/usr/lib/sendmail -oi -t"; 
#$PIPE = "|/bin/cat";

$SIG{'PIPE'} = 'plumber';
sub plumber { die "$0: broken PIPE talking to sendmail!\n"; } 


while (<>) {
    next unless /^Problem/;
    chop;
    split;
    for ( @_ ) { s/.*://; } 

    $nullpw =  /null passwd/;

    ($user,$host,$passwd) = 
	$nullpw ? ($_[2], $_[3], ' ')
		: ($_[1], $_[2], $_[3]);

    printf "user %-8s has passwd %-8s on host %s\n",
	$user, $passwd, $host;

    next if $user =~ /uucp/;

    open PIPE || die "$0: couldn't open $PIPE: $!\n";

    printf PIPE "From: Security Auditor <daemon>\n";
    printf PIPE "To: %s\n",  $user;

    if ($nullpw) {
	printf PIPE "Subject: Your missing passwd on %s\n\n", $host;

	printf PIPE "On the machine named \"%s\", your password has not\n",
		$host;
	printf PIPE "yet been set.  This lets anyone login as you without\n";
	printf PIPE "having to present  password, so please try to\n";
    } else {
	printf PIPE "Subject: Your trivial passwd on %s\n\n", $host;

	printf PIPE "On the machine named \"%s\", your passwd is \"%s\".\n",
	    $host, $passwd;
	printf PIPE "This is considered very easy to guess, so please\n";
    }
    printf PIPE "fix it at your earliest possible convenience.\n";
    printf PIPE "\nOtherwise your account may soon be de-activated!\n";
    printf PIPE "\nThanks,\n\n--daemon\n";
    close PIPE;
}