1<?php 2/** 3 * Copyright 2000-2017 Horde LLC (http://www.horde.org/) 4 * 5 * See the enclosed file COPYING for license information (GPL). If you 6 * did not receive this file, see http://www.horde.org/licenses/gpl. 7 * 8 * @category Horde 9 * @copyright 2000-2017 Horde LLC 10 * @license http://www.horde.org/licenses/gpl GPL 11 * @package Passwd 12 */ 13 14/** 15 * An expect implementation of the passwd system. 16 * 17 * @author Gaudenz Steinlin <gaudenz@soziologie.ch> 18 * @category Horde 19 * @copyright 2000-2017 Horde LLC 20 * @license http://www.horde.org/licenses/gpl GPL 21 * @package Passwd 22 */ 23class Passwd_Driver_Expect extends Passwd_Driver 24{ 25 /** 26 */ 27 protected function _changePassword($user, $oldpass, $newpass) 28 { 29 // Sanity checks. 30 if (!@is_executable($this->_params['program'])) { 31 throw new Passwd_Exception(sprintf(_("%s does not exist or is not executable."), $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 ' . escapeshellarg($this->_params['script']) . 40 ' -- ' . $this->_params['params'] . ' -log ' . escapeshellarg($log); 41 42 $exp = @popen($prog, 'w'); 43 @fwrite($exp, $user . "\n"); 44 @fwrite($exp, $oldpass . "\n"); 45 @fwrite($exp, $newpass . "\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} 57