/usr/share/horde/ingo/lib/Transport/Sivtest.php is in php-horde-ingo 3.2.13-1.
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 | <?php
/**
* Copyright 2003-2016 Horde LLC (http://www.horde.org/)
* Copyright 2004-2007 Liam Hoekenga <liamr@umich.edu>
*
* See the enclosed file LICENSE for license information (ASL). If you
* did not receive this file, see http://www.horde.org/licenses/apache.
*
* @author Jan Schneider <jan@horde.org>
* @author Liam Hoekenga <liamr@umich.edu>
* @category Horde
* @license http://www.horde.org/licenses/apache ASL
* @package Ingo
*/
/**
* Ingo_Transport_Sivtest implements an Ingo transport driver to allow scripts
* to be installed and set active via the Cyrus sivtest command line utility.
*
* @author Jan Schneider <jan@horde.org>
* @author Liam Hoekenga <liamr@umich.edu>
* @category Horde
* @license http://www.horde.org/licenses/apache ASL
* @package Ingo
*/
class Ingo_Transport_Sivtest extends Ingo_Transport_Timsieved
{
/**
* Constructor.
*/
public function __construct(array $params = array())
{
$default_params = array(
'hostspec' => 'localhost',
'logintype' => '',
'port' => 4190,
'scriptname' => 'ingo',
'admin' => '',
'usetls' => true,
'command' => '',
'socket' => '',
);
$this->_supportShares = false;
parent::__construct(array_merge($default_params, $params));
}
/**
* Connect to the sieve server.
*
* @throws Ingo_Exception;
*/
protected function _connect()
{
if (!empty($this->_sieve)) {
return;
}
$this->sivtestSocket(
$this->_params['username'],
$this->_params['password'],
$this->_params['hostspec']);
$this->_sieve = new Net_Sieve(
$this->_params['username'],
$this->_params['password'],
'unix://' . $this->_params['socket'],
0,
null,
null,
false,
true,
$this->_params['usetls']);
$res = $this->_sieve->getError();
if ($res instanceof PEAR_Error) {
unset($this->_sieve);
throw new Ingo_Exception($res);
}
}
/**
* Used to figure out which Sieve server the script will be run
* on, and then open a GSSAPI authenticated socket to said server.
*
* @param string $username The username.
* @param string $password The password.
* @param string $hostspec The hostspec.
*
* @return TODO
* @throws Ingo_Exception
*/
public function sivtestSocket($username, $password, $hostspec)
{
$command = '';
$error_return = '';
if (strtolower($this->_params['logintype']) == 'gssapi' &&
isset($_SERVER['KRB5CCNAME'])) {
$command .= 'KRB5CCNAME=' . $_SERVER['KRB5CCNAME'];
}
$domain_socket = 'unix://' . $this->_params['socket'];
$command .= ' ' . $this->_params['command']
. ' -m ' . $this->_params['logintype']
. ' -u ' . $username
. ' -a ' . $username
. ' -w ' . $password
. ' -p ' . $this->_params['port']
. ' -X ' . $this->_params['socket']
. ' ' . $hostspec;
$conn_attempts = 0;
while ($conn_attempts++ < 4) {
$attempts = 0;
if (!file_exists($this->_params['socket'])) {
exec($command . ' > /dev/null 2>&1');
sleep(1);
while (!file_exists($this->_params['socket'])) {
usleep(200000);
if ($attempts++ > 5) {
$error_return = ': No socket after 10 seconds of trying!';
continue 2;
}
}
}
$socket = new Net_Socket();
$error = $socket->connect($domain_socket, 0, true, 30);
if (!($error instanceof PEAR_Error)) {
break;
}
// We failed, break this connection.
unlink($this->_params['socket']);
}
if (!empty($error_return)) {
throw new Ingo_Exception($error_return);
}
$status = $socket->getStatus();
if ($status instanceof PEAR_Error || $status['eof']) {
throw new Ingo_Exception(_("Failed to write to socket: (connection lost!)"));
}
$error = $socket->writeLine("CAPABILITY");
if ($error instanceof PEAR_Error) {
throw new Ingo_Exception(_("Failed to write to socket: " . $error->getMessage()));
}
$result = $socket->readLine();
if ($result instanceof PEAR_Error) {
throw new Ingo_Exception(_("Failed to read from socket: " . $error->getMessage()));
}
if (preg_match('|^bye \(referral "(sieve://)?([^"]+)|i',
$result, $matches)) {
$socket->disconnect();
$this->sivtestSocket($username, $password, $matches[2]);
} else {
$socket->disconnect();
exec($command . ' > /dev/null 2>&1');
sleep(1);
}
}
}
|