Sunil Dhaka rearranged electrons thusly:

> Sorry guys, I know this post shouldn't be here (belongs to the programmiers list)
> But could some one give me a url for a cgi-perl script which can administer / allow 
>pop / system users to change passwords.
> I've done a massive search for such scripts but have only come up with
> scripts which make web users and their admin

I have posted this before ...

note - you better chroot your pop daemon before you do this ... I wont accept
responsiblity if this damages /etc/passwd :)

[it is on production use on at least two servers we run though]

#!/usr/bin/perl

if ($#ARGV < 1)
{
   print "Usage : adduser <USER> <PASSWORD> [<DOMAIN>]" . "\n";
   exit 999;
}

my $DOMAIN = "example.com";

if (@ARGV[2] ne "")
{
   $DOMAIN = @ARGV[2];
}
my $username = @ARGV[0];
my $password = @ARGV[1];
$passdir = "/home/popmail/etc/passwd";

open(PASSFILE,"$passdir") || die "Cannot Open File $passdir";
@lines = <PASSFILE>;
close(PASSFILE);

$found = 0;
        
open(PASSFILE,">$passdir");
foreach $line(@lines){
        if($line =~ /^$username/g){
                $newpass = crypt($password, substr($username,0,1) . substr($username, 
length($username) - 1,1));
                print PASSFILE "$username:$newpass\n";
                $found = 1;

        }
        else{
                print PASSFILE "$line"; 
        }
}
if ($found == 0) {
        $newpass = crypt($password, substr($username,0,1) . substr($username, 
length($username) - 1,1));

my $userID="501:501::";

        print PASSFILE "$username:$newpass:$userID\n";
}
close(PASSFILE);
exit;

-- 
Suresh Ramasubramanian  <-->  mallet <at> efn <dot> org
EMail Sturmbannfuhrer, Lower Middle Class Unix Sysadmin

----------------------------------------------
The mailing list archives are available at
http://lists.linux-india.org/cgi-bin/wilma/LIH

Reply via email to