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_expect class provides an expect implementation of the passwd
 4:  * system.
 5:  *
 6:  * Copyright 2000-2012 Horde LLC (http://www.horde.org/)
 7:  *
 8:  * See the enclosed file COPYING for license information (GPL). If you
 9:  * did not receive this file, see http://www.horde.org/licenses/gpl.php.
10:  *
11:  * @author  Gaudenz Steinlin <gaudenz@soziologie.ch>
12:  * @package Passwd
13:  */
14: class Passwd_Driver_Expect extends Passwd_Driver
15: {
16:     /**
17:      * Changes the user's password.
18:      *
19:      * @param string $user          The user for which to change the password.
20:      * @param string $old_password  The old (current) user password.
21:      * @param string $new_password  The new user password to set.
22:      *
23:      * @throws Passwd_Exception
24:      */
25:     public function changePassword($user, $old_password, $new_password)
26:     {
27:         // Sanity checks.
28:         if (!@is_executable($this->_params['program'])) {
29:             throw new Passwd_Exception(
30:                 sprintf(_("%s does not exist or is not executable."),
31:                         $this->_params['program']));
32:         }
33: 
34:         // Temporary logfile for error messages.
35:         $log = Horde::getTempFile('passwd');
36: 
37:         // Open expect script for writing.
38:         $prog = 'LANG=C LC_ALL=C ' . $this->_params['program']
39:             . ' -f ' . $this->_params['script']
40:             . ' -- ' . $this->_params['params'] . ' -log ' . $log;
41: 
42:         $exp = @popen($prog, 'w');
43:         @fwrite($exp, "$user\n");
44:         @fwrite($exp, "$old_password\n");
45:         @fwrite($exp, "$new_password\n");
46: 
47:         if (@pclose($exp)) {
48:             $errormsg = implode(' ', @file($log));
49:             @unlink($log);
50:             if ($errormsg) {
51:                 throw new Passwd_Exception($errormsg);
52:             }
53:         }
54:     }
55: }
56: 
API documentation generated by ApiGen