Foxxie
01-04-03, 07:19 PM
Hello developers,
I'm currently working on making a php script that interacts with the passwd binary to change user passwords rather then going in and manually editing the /etc/group, /etc/passwd, and /etc/shadow files with php. For some reason the script isn't working correctly and the error output I get is the following:
New password:
New password:
New password:
passwd: Conversation error
Here is the code:
#!/usr/bin/php -f
<?php
$structure = array
(
"0" => array("pipe", "r"),
"1" => array("pipe", "w"),
"2" => array("file", "/tmp/error-output.txt", "a")
);
$proc = proc_open("passwd $argv[1]", $structure, $pipes);
if(is_resource($proc))
{
$r = fread($pipes[0], 1024);
if(strstr($r, "New password:"))
{
fwrite($pipes[1], $argv[2]);
}
$r = fread($pipes[0], 1024);
if(strstr($r, "Retype new password:"))
{
fwrite($pipes[1], $argv[2]);
}
$r = fread($pipes[0], 1024);
if(strstr($r, "passwd: all authentication tokens updated successfully."))
{
print "The user $argv[1]'s password has sucessfully been changed.\n";
}
else
{
print "The user $argv[1]'s password change has failed.\n";
}
fclose($pipes[0]);
fclose($pipes[1]);
proc_close($proc);
}
?>
Does anyone have any idea why it's not working correctly? If so thanks, and your help is greatly appreciated :).
I'm currently working on making a php script that interacts with the passwd binary to change user passwords rather then going in and manually editing the /etc/group, /etc/passwd, and /etc/shadow files with php. For some reason the script isn't working correctly and the error output I get is the following:
New password:
New password:
New password:
passwd: Conversation error
Here is the code:
#!/usr/bin/php -f
<?php
$structure = array
(
"0" => array("pipe", "r"),
"1" => array("pipe", "w"),
"2" => array("file", "/tmp/error-output.txt", "a")
);
$proc = proc_open("passwd $argv[1]", $structure, $pipes);
if(is_resource($proc))
{
$r = fread($pipes[0], 1024);
if(strstr($r, "New password:"))
{
fwrite($pipes[1], $argv[2]);
}
$r = fread($pipes[0], 1024);
if(strstr($r, "Retype new password:"))
{
fwrite($pipes[1], $argv[2]);
}
$r = fread($pipes[0], 1024);
if(strstr($r, "passwd: all authentication tokens updated successfully."))
{
print "The user $argv[1]'s password has sucessfully been changed.\n";
}
else
{
print "The user $argv[1]'s password change has failed.\n";
}
fclose($pipes[0]);
fclose($pipes[1]);
proc_close($proc);
}
?>
Does anyone have any idea why it's not working correctly? If so thanks, and your help is greatly appreciated :).