#!/usr/bin/perl -w
# helper program to change passwds for CGI interface
# WARNING: will run as root!!! make changes with care
# Last modified: 8.11.2000 by Thomas Bleher
#use tainting ?
use strict;
while (<>) {
	my ($user, $pw) = split / /;
	chop $pw;
	my $enc_pw = crypt $pw, join '', ('.','/',0..9,'a'..'z','A'..'Z')[rand 64, rand 64];
	system('/usr/sbin/usermod', '-p', $enc_pw, $user);
	die "Error while usermod ($!)" if ($! or $?);
	open PIPE, "|/usr/bin/smbpasswd -s $user > /dev/null" or die "Error while smbpasswd (open)";
	print PIPE $pw."\n".$pw."\n" or die "Error while smbpasswd (write)";
	close PIPE or die "Error while smbpasswd (close)";
}
system('/usr/local/sbin/generate_apache_auth');
