Overview

Packages

  • None
  • Passwd

Classes

  • Passwd
  • Passwd_Driver
  • Passwd_Driver_Adsi
  • Passwd_Driver_Composite
  • Passwd_Driver_Expect
  • Passwd_Driver_Expectpecl
  • Passwd_Driver_Horde
  • Passwd_Driver_Http
  • Passwd_Driver_Kolab
  • Passwd_Driver_Ldap
  • Passwd_Driver_Pine
  • Passwd_Driver_Poppassd
  • Passwd_Driver_Procopen
  • Passwd_Driver_Pspasswd
  • Passwd_Driver_Servuftp
  • Passwd_Driver_Smbldap
  • Passwd_Driver_Smbpasswd
  • Passwd_Driver_Soap
  • Passwd_Driver_Sql
  • Passwd_Driver_Vmailmgr
  • Passwd_Driver_Vpopmail
  • Passwd_Exception
  • Passwd_Factory_Driver
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * The Passwd_Driver_Procopen class provides a procopen implementation of
 4:  * the passwd system.
 5:  *
 6:  * Any script or program can be supplied as the 'program' attribute value of
 7:  * the params argument.  The username, old password and new password are
 8:  * written to the stdin of the process and then the stdout and stderr of the
 9:  * process are read and combined with the exit status value and returned to
10:  * the caller if the status code is not 0.
11:  *
12:  * Copyright 2004-2012 Horde LLC (http://www.horde.org/)
13:  *
14:  * See the enclosed file COPYING for license information (GPL). If you
15:  * did not receive this file, see http://www.horde.org/licenses/gpl.php.
16:  *
17:  * @author  Samuel Nicolary <sam@nicolary.org>
18:  * @package Passwd
19:  */
20: class Passwd_Driver_Procopen extends Passwd_Driver
21: {
22:     /**
23:      * Changes the user's password.
24:      *
25:      * @param string $user     The user for which to change the password.
26:      * @param string $oldpass  The old (current) user password.
27:      * @param string $newpass  The new user password to set.
28:      *
29:      * @throws Passwd_Exception
30:      */
31:     public function changePassword($user, $oldpass, $newpass)
32:     {
33:         $descriptorspec = array(
34:             0 => array('pipe', 'r'),
35:             1 => array('pipe', 'w'),
36:             2 => array('pipe', 'w'));
37: 
38:         $output = '';
39: 
40:         $process = @proc_open($this->_params['program'], $descriptorspec, $pipes);
41:         if (is_resource($process)) {
42:             fwrite($pipes[0], "$user\n");
43:             fwrite($pipes[0], "$oldpass\n");
44:             fwrite($pipes[0], "$newpass\n");
45:             fclose($pipes[0]);
46:             while (!feof($pipes[1])) {
47:                 $output .= fgets($pipes[1], 1024);
48:             }
49:             fclose($pipes[1]);
50:             while (!feof($pipes[2])) {
51:                 $output .= fgets($pipes[2], 1024);
52:             }
53:             fclose($pipes[2]);
54:             $return_value = proc_close($process);
55:         } else {
56:             $return_value = -1;
57:         }
58: 
59:         $output .= " (Exit Status: $return_value)";
60: 
61:         if ($return_value != 0) {
62:             throw new Passwd_Exception($output);
63:         }
64:     }
65: }
66: 
API documentation generated by ApiGen