This file is indexed.

/usr/share/horde/passwd/lib/Driver/Pine.php is in php-horde-passwd 5.0.2-3+deb8u1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<?php
/**
 * Copyright 2003-2014 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 2003-2014 Horde LLC
 * @license   http://www.horde.org/licenses/gpl GPL
 * @package   Passwd
 */

/**
 * Changes a user's password in a Pine password file.
 *
 * @author    Max Kalika <max@horde.org>
 * @category  Horde
 * @copyright 2003-2014 Horde LLC
 * @license   http://www.horde.org/licenses/gpl GPL
 * @package   Passwd
 */
class Passwd_Driver_Pine extends Passwd_Driver
{
    /** Lower boundary character. */
    const FIRSTCH = 0x20;

    /** Upper boundary character. */
    const LASTCH = 0x7e;

    /** Median character. */
    const TABSZ = 0x5f;

    /**
     * Boolean which contains state of the ftp connection.
     *
     * @var boolean
     */
    protected $_connected = false;

    /**
     * Contents array of the pine password file.
     *
     * @var array
     */
    protected $_contents = array();

    /**
     * Horde_Vfs instance.
     *
     * @var VFS
     */
    protected $_ftp;

    /**
     */
    public function __construct(array $params = array())
    {
        self::__construct(array_merge(array(
            /* We self-encrypt here, so plaintext is needed. */
            'encryption' => 'plain',
            'show_encryption' => false,

            /* Sensible FTP server parameters. */
            'host' => 'localhost',
            'port' => 21,
            'path' => '',
            'file' => '.pinepw',

            /* Connect to FTP server using just-passed-in credentials?
             * Only useful if using the composite driver and changing
             * system (FTP) password prior to this one. */
            'use_new_passwd' => false,

            /* What host to look for on each line? */
            'imaphost' => 'localhost'
        ), $params));
    }

    /**
     * Connects to the FTP server.
     *
     * @throws Passwd_Exception
     */
    protected function _connect($user, $password)
    {
        if ($this->_connected) {
            return;
        }

        $params = array(
            'username' => $user,
            'password' => $password,
            'hostspec' => $this->_params['host'],
            'port' => $this->_params['port'],
        );

        try {
            $this->_ftp = Horde_Vfs::factory('ftp', $params);
            $this->_ftp->checkCredentials();
        } catch (Horde_Vfs_Exception $e) {
            throw new Passwd_Exception($e);
        }

        $this->_connected = true;
    }

    /**
     * Disconnect from the FTP server.
     *
     * @throws Passwd_Exception
     */
    protected function _disconnect()
    {
        if ($this->_connected) {
            try {
                $this->_ftp->disconnect();
            } catch (Horde_Vfs_Exception $e) {
                throw new Passwd_Exception($e);
            }
            $this->_connected = false;
        }
    }

    /**
     * Decodes a Pine-encoded password string.
     *
     * The algorithm is borrowed from read_passfile() and xlate_out()
     * functions in pine/imap.c file distributed in the Pine source archive.
     *
     * @param string $string  The contents of a pine-encoded password file.
     *
     * @return array  List of lines of decoded elements.
     */
    protected function _decode($string)
    {
        $list = array();

        $lines = explode("\n", $string);
        for ($n = 0; $n < sizeof($lines); $n++) {
            $key = $n;
            $tmp = $lines[$n];
            for ($i = 0; $i < strlen($tmp); $i++) {
                if ((ord($tmp[$i]) >= self::FIRSTCH) &&
                    (ord($tmp[$i]) <= self::LASTCH)) {
                    $xch  = ord($tmp[$i]) - ($dti = $key);
                    $xch += ($xch < self::FIRSTCH - self::TABSZ)
                        ? 2 * self::TABSZ
                        : ($xch < self::FIRSTCH) ? self::TABSZ : 0;
                    $dti  = ($xch - self::FIRSTCH) + $dti;
                    $dti -= ($dti >= 2 * self::TABSZ)
                        ? 2 * self::TABSZ
                        : ($dti >= self::TABSZ) ? self::TABSZ : 0;
                    $key  = $dti;
                    $tmp[$i] = chr($xch);
                }
            }

            if ($i && $tmp[$i - 1] == "\n") {
                $tmp = substr($tmp, 0, -1);
            }

            $parts = explode("\t", $tmp);
            if (count($parts) >= 4) {
                $list[] = $parts;
            }
        }

        return $list;
    }

    /**
     * Encodes an array of elements into a Pine-readable password string.
     *
     * The algorithm is borrowed from write_passfile() and xlate_in()
     * functions in pine/imap.c file distributed in the Pine source archive.
     *
     * @param array  $lines  List of lines of decoded elements.
     *
     * @return array  Contents of a pine-readable password file.
     */
    protected function _encode($lines)
    {
        $string = '';
        for ($n = 0; $n < sizeof($lines); $n++) {
            if (isset($lines[$n][4])) {
                $lines[$n][4] = "\t" . $lines[$n][4];
            } else {
                $lines[$n][4] = '';
            }

            $key = $n;
            $tmp = vsprintf("%.100s\t%.100s\t%.100s\t%d%s\n", $lines[$n]);
            for ($i = 0; $i < strlen($tmp); $i++) {
                $eti = $key;
                if ((ord($tmp[$i]) >= self::FIRSTCH) &&
                    (ord($tmp[$i]) <= self::LASTCH)) {
                    $eti += ord($tmp[$i]) - self::FIRSTCH;
                    $eti -= ($eti >= 2 * self::TABSZ)
                        ? 2 * self::TABSZ
                        : ($eti >= self::TABSZ) ? self::TABSZ : 0;
                    $key  = $eti;
                    $tmp[$i] = chr($eti + self::FIRSTCH);
                 }
            }

            $string .= $tmp;
        }

        return $string;
    }

    /**
     * Finds out if a username and password is valid.
     *
     * @param string $user         The userID to check.
     * @param string $oldPassword  An old password to check.
     *
     * @throws Passwd_Exception
     */
    protected function _lookup($user, $oldPassword)
    {
        try {
            $contents = $this->_ftp->read($this->_params['path'],
                                          $this->_params['file']);
        } catch (Horde_Vfs_Exception $e) {
            throw new Passwd_Exception($e);
        }

        $this->_contents = $this->_decode($contents);
        foreach ($this->_contents as $line) {
            if ($line[1] == $user &&
                (($line[2] == $this->_params['imaphost']) ||
                 (!empty($line[4]) && $line[4] == $this->_params['imaphost']))) {
                $this->_comparePasswords($line[0], $oldPassword);
                return;
            }
        }

        throw new Passwd_Exception(_("User not found."));
    }

    /**
     * Modifies a pine password record for a user.
     *
     * @param string $user         The user whose record we will udpate.
     * @param string $newPassword  The new password value to set.
     *
     * @throws Passwd_Exception
     */
    protected function _modify($user, $newPassword)
    {
        for ($i = 0; $i < sizeof($this->_contents); $i++) {
            if ($this->_contents[$i][1] == $user &&
                (($this->_contents[$i][2] == $this->_params['imaphost']) ||
                 (!empty($this->_contents[$i][4]) &&
                  $this->_contents[$i][4] == $this->_params['imaphost']))) {
                $this->_contents[$i][0] = $newPassword;
            }
        }

        $string = $this->_encode($this->_contents);
        try {
            $this->_ftp->writeData($this->_params['path'],
                                   $this->_params['file'],
                                   $string);
        } catch (Horde_Vfs_Exception $e) {
            throw new Passwd_Exception($e);
        }
    }

    /**
     */
    protected function _changePassword($user, $oldpass, $newpass)
    {
        /* Connect to the ftp server. */
        $this->_connect($user, $this->_params['use_new_passwd'] ? $newpass : $oldpass);
        $this->_lookup($user, $oldpass);
        $this->_modify($user, $newpass);
        $this->_disconnect();
    }

}