File: Expect.php

package info (click to toggle)
php-horde-passwd 5.0.7-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 3,412 kB
  • sloc: php: 2,017; xml: 1,136; javascript: 29; makefile: 18; sh: 3
file content (56 lines) | stat: -rw-r--r-- 1,670 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
 * Copyright 2000-2017 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (GPL). If you
 * did not receive this file, see http://www.horde.org/licenses/gpl.
 *
 * @category  Horde
 * @copyright 2000-2017 Horde LLC
 * @license   http://www.horde.org/licenses/gpl GPL
 * @package   Passwd
 */

/**
 * An expect implementation of the passwd system.
 *
 * @author    Gaudenz Steinlin <gaudenz@soziologie.ch>
 * @category  Horde
 * @copyright 2000-2017 Horde LLC
 * @license   http://www.horde.org/licenses/gpl GPL
 * @package   Passwd
 */
class Passwd_Driver_Expect extends Passwd_Driver
{
    /**
     */
    protected function _changePassword($user, $oldpass, $newpass)
    {
        // Sanity checks.
        if (!@is_executable($this->_params['program'])) {
            throw new Passwd_Exception(sprintf(_("%s does not exist or is not executable."), $this->_params['program']));
        }

        // Temporary logfile for error messages.
        $log = Horde::getTempFile('passwd');

        // Open expect script for writing.
        $prog = 'LANG=C LC_ALL=C ' . $this->_params['program'] .
            ' -f ' . escapeshellarg($this->_params['script']) .
            ' -- ' . $this->_params['params'] . ' -log ' . escapeshellarg($log);

        $exp = @popen($prog, 'w');
        @fwrite($exp, $user . "\n");
        @fwrite($exp, $oldpass . "\n");
        @fwrite($exp, $newpass . "\n");

        if (@pclose($exp)) {
            $errormsg = implode(' ', @file($log));
            @unlink($log);
            if ($errormsg) {
                throw new Passwd_Exception($errormsg);
            }
        }
    }

}