File: plaintext.php

package info (click to toggle)
horde3 3.0.4-4sarge7
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 15,980 kB
  • ctags: 16,295
  • sloc: php: 68,726; xml: 2,382; sql: 498; makefile: 74; sh: 63; pascal: 6
file content (129 lines) | stat: -rw-r--r-- 3,849 bytes parent folder | download
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
<?php
/**
 * The Net_IMSP_Auth_plaintext class for IMSP authentication.
 *
 * Required parameters:
 * ====================
 * '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.
 *
 * $Horde: framework/Net_IMSP/IMSP/Auth/plaintext.php,v 1.7.10.4 2005/03/09 18:26:56 mrubinsk Exp $
 *
 * Copyright 2003-2005 Michael Rubinsky <mrubinsk@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_COMMAND_CONTINUATION_RESPONSE,
                            $imsp->imspReceive())) {

                return $imsp->imspError(IMSP_NO_CONTINUATION_RESPONSE,
                                        __FILE__, __LINE__);
            }
        }

        $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_COMMAND_CONTINUATION_RESPONSE,
                            $imsp->imspReceive())) {
                return $imsp->imspError(IMSP_NO_CONTINUATION_RESPONSE,
                                        __FILE__, __LINE__);
            }
        }

        $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') {
            return $imsp->imspError(IMSP_EXIT_LOGIN_FAILED, __FILE__, __LINE__);
        }

        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';
     }

}