note 58044 added to function.proc-open

From: Date: Sat, 22 Oct 2005 05:42:22 +0000
Subject: note 58044 added to function.proc-open
Groups: php.notes 
Request: Send a blank email to php-notes+get-97402@lists.php.net to get a copy of this message
Since I don't have access to PAM via Apache, suexec on, nor access to /etc/shadow I coughed up this way of authenticating users based on the system users details. It's really hairy and ugly, but it works. <? function authenticate($user,$password) { $descriptorspec = array( 0 => array("pipe", "r"), // stdin is a pipe that the child will read from 1 => array("pipe", "w"), // stdout is a pipe that the child will write to 2 => array("file","/dev/null", "w") // stderr is a file to write to ); $process = proc_open("su ".escapeshellarg($user), $descriptorspec, $pipes); if (is_resource($process)) { // $pipes now looks like this: // 0 => writeable handle connected to child stdin // 1 => readable handle connected to child stdout // Any error output will be appended to /tmp/error-output.txt fwrite($pipes[0],$password); fclose($pipes[0]); fclose($pipes[1]); // It is important that you close any pipes before calling // proc_close in order to avoid a deadlock $return_value = proc_close($process); return !$return_value; } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.proc-open.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+58044 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58044&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58044&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58044&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58044&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58044&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58044&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58044&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+58044&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#97402) next »