I'm designing a simplified user management interface, similar to Webmin's. Since I'm using mod_perl, I just allowed the 'apache' user to execute certain commands using sudo. I've written a command line version that works just fine:

<code>
#!/usr/bin/perl

use Expect;

my $user = shift;
my $password = shift;
print "Running 'sudo passwd ${user}'\n";
my $exp = Expect->spawn("sudo passwd ${user}") or die "Can't run 'sudo passwd 
${user}'\n";
if($exp->expect(10, -re => 'New UNIX password: $')) {
  print $exp "${password}\n";
}
if($exp->expect(10, -re => 'Retype new UNIX password: $')) {
  print $exp "${password}\n";
}
</code>

but when I change it to CGI, it doesn't:

<code>
#!/usr/bin/perl

use Expect;
use CGI;

my $cgi = new CGI;
my $p = $cgi->Vars;

print $cgi->header;
my $exp = Expect->spawn("sudo passwd $p->{user}") or die "Can't run 'sudo passwd $p->{user}'\n";
if($exp->expect(10, -re => '^New UNIX password: $')) {
print $exp "$p->{password}\n";
} else {
print "Never saw first password prompt<br>";
}
if ($exp->expect(10, -re => '^Retype new UNIX password: $')) {
print $exp "$p->{password}\n";
} else {
print "Never saw second password prompt<br>";
}
$exp->soft_close();
</code>


When I run the CGI will the same parameters as the command line version, I get:

New UNIX password: New UNIX password: New UNIX password: passwd: Conversation error Never saw first password prompt

where the command line version gives me:

Running 'sudo passwd agaffney'
New UNIX password:
BAD PASSWORD: it is too short
Retype new UNIX password:

and actually changes the password. Does anyone have any idea what's going on?

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to