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
|
<?php
/**
* The Net_IMSP_Auth_plaintext class for IMSP authentication.
*
* Required parameters:<pre>
* 'username' Username to logon to IMSP server as.
* 'password' Password for current user.
* 'server' The hostname of the IMSP server.
* 'port' The port of the IMSP server.</pre>
*
* $Horde: framework/Net_IMSP/IMSP/Auth/plaintext.php,v 1.7.10.15 2009/01/06 15:23:27 jan Exp $
*
* Copyright 2003-2009 The Horde Project (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @author Michael Rubinsky <mrubinsk@horde.org>
* @package Net_IMSP
*/
class Net_IMSP_Auth_plaintext extends Net_IMSP_Auth {
/**
* Private authentication function. Provides actual
* authentication code.
*
* @access private
* @param mixed $params Hash of IMSP parameters.
*
* @return mixed Net_IMSP object connected to server if successful,
* PEAR_Error on failure.
*/
function &_authenticate($params)
{
$imsp = &Net_IMSP::singleton('none', $params);
$result = $imsp->init();
if (is_a($result, 'PEAR_Error')) {
return $result;
}
$userId = $params['username'];
$credentials = $params['password'];
/* Start the command. */
$result = $imsp->imspSend('LOGIN ', true, false);
if (is_a($result, 'PEAR_Error')) {
return $result;
}
/* Username as a {}? */
if (preg_match(IMSP_MUST_USE_LITERAL, $userId)) {
$biUser = sprintf('{%d}', strlen($userId));
$result = $imsp->imspSend($biUser, false, true);
if (is_a($result, 'PEAR_Error')) {
return $result;
}
if (!preg_match("/^\+/",
$imsp->imspReceive())) {
$result = $imsp->imspError('Did not receive expected command continuation response from IMSP server.',
__FILE__, __LINE__);
return $result;
}
}
$result = $imsp->imspSend($userId . ' ', false, false);
if (is_a($result, 'PEAR_Error')) {
return $result;
}
/* Don't want to log the password! */
$logValue = $imsp->logEnabled;
$imsp->logEnabled = false;
/* Pass as {}? */
if (preg_match(IMSP_MUST_USE_LITERAL, $credentials)) {
$biPass = sprintf('{%d}', strlen($credentials));
$result = $imsp->imspSend($biPass, false, true);
if (is_a($result, 'PEAR_Error')) {
return $result;
}
if (!preg_match("/^\+/",
$imsp->imspReceive())) {
$result = $imsp->imspError('Did not receive expected command continuation response from IMSP server.',
__FILE__, __LINE__);
return $result;
}
}
$result = $imsp->imspSend($credentials, false, true);
if (is_a($result, 'PEAR_Error')) {
return $result;
}
/* Restore the logging boolean. */
$imsp->logEnabled = $logValue;
$server_response = $imsp->imspReceive();
if (is_a($server_response, 'PEAR_Error')) {
return $server_response;
}
if ($server_response != 'OK') {
$result = $imsp->imspError('Login to IMSP host failed.', __FILE__, __LINE__);
return $result;
}
return $imsp;
}
/**
* Force a logout command to the imsp stream.
*
*/
function logout()
{
$this->_imsp->logout();
}
/**
* Return the driver type
*
* @return string the type of this IMSP_Auth driver
*/
function getDriverType()
{
return 'plaintext';
}
}
|