script to change samba users password
hello,
I want to create a webpage where users can change their samba password and before I jump to PHP code i want to write perl code that can be called in php code.
I have created two file
1. main.pl - this script actually switch user and call passwd.pl
2. passwd.pl - this is actually changes the password
{main.pl}
#!/usr/bin/perl
my $username = $ARGV[0];
my $oldpass = $ARGV[1];
my $newpass1 = $ARGV[2];
my $newpass2 = $ARGV[3];
open(USER, "|su - $username -c /script/passwd.pl \" $oldpass $newpass1 $newpass2\" ");
close(USER);
{passwd.pl}
#!/usr/bin/perl
my $oldpw = $ARG[0];
my $newpw_1 = $ARG[1];
my $newpw_2 = $ARG[2];
my $smbpasswd = "/usr/bin/smbpasswd";
&pw_change($smbpasswd,$username,$oldpw,$newpw_1,$newpw_2);
sub pw_change(){
my ($smbpasswd,$username,$oldpw,$newpw_1,$newpw_2) = @_;
if ( "$newpw_1" eq "$newpw_2" ) {
open (FILE, "|$smbpasswd -s") or die("cannot pipe into $smbpasswd: $!");
print FILE qq|$oldpw\n|;
print FILE qq|$newpw_1\n|;
print FILE qq|$newpw_1\n|;
close (FILE);
}
}
if I switch to user whom i want to change the password passwd.pl allows me the change the password but when i call this script from my main.pl, the arguments doesn't passes to passwd.pl
e.g. I call it as
./main.pl <user name> <old_pass> <new_pass_1> <new_pass_2>
Hope this make sense
Saif
Last edited by saifurab; 02-04-2010 at 04:49 AM.
|