Subversion Repositories Applications.papyrus

Rev

Rev 1713 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1173 jp_milcent 1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
3
 
4
/**
5
 * Storage driver for Authentication on a Kerberos V server.
6
 *
7
 * PHP versions 4 and 5
8
 *
9
 * LICENSE: This source file is subject to version 3.01 of the PHP license
10
 * that is available through the world-wide-web at the following URI:
11
 * http://www.php.net/license/3_01.txt.  If you did not receive a copy of
12
 * the PHP License and are unable to obtain it through the web, please
13
 * send a note to license@php.net so we can mail you a copy immediately.
14
 *
15
 * @category   Authentication
16
 * @package    Auth
17
 * @author     Andrew Teixeira <ateixeira@gmail.com>
18
 * @author     Adam Ashley <aashley@php.net>
19
 * @copyright  2001-2006 The PHP Group
20
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
2150 mathias 21
 * @version    CVS: $Id: KADM5.php,v 1.6 2007/06/12 03:11:26 aashley Exp $
1173 jp_milcent 22
 * @link       http://pear.php.net/package/Auth
23
 * @since      File available since Release 1.4.0
24
 */
25
 
26
/**
27
 * Include Auth_Container base class
28
 */
29
require_once 'Auth/Container.php';
30
/**
31
 * Include PEAR for error handling
32
 */
33
require_once 'PEAR.php';
34
 
35
/**
36
 * Storage driver for Authentication on a Kerberos V server.
37
 *
38
 * Available options:
39
 * hostname:        The hostname of the kerberos server
40
 * realm:           The Kerberos V realm
41
 * timeout:         The timeout for checking the server
42
 * checkServer:     Set to true to check if the server is running when
43
 *                  constructing the object
44
 *
45
 * @category   Authentication
46
 * @package    Auth
47
 * @author     Andrew Teixeira <ateixeira@gmail.com>
48
 * @author     Adam Ashley <aashley@php.net>
49
 * @copyright  2001-2006 The PHP Group
50
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
2150 mathias 51
 * @version    Release: 1.5.4  File: $Revision: 1.6 $
1173 jp_milcent 52
 * @link       http://pear.php.net/package/Auth
53
 * @since      Class available since Release 1.4.0
54
 */
55
class Auth_Container_KADM5 extends Auth_Container {
56
 
57
    // {{{ properties
58
 
59
    /**
60
     * Options for the class
61
     * @var string
62
     */
63
    var $options = array();
64
 
65
    // }}}
66
    // {{{ Auth_Container_KADM5()
67
 
68
    /**
69
     * Constructor of the container class
70
     *
71
     * $options can have these keys:
72
     * 'hostname'    The hostname of the kerberos server
73
     * 'realm'       The Kerberos V realm
74
     * 'timeout'     The timeout for checking the server
75
     * 'checkServer' Set to true to check if the server is running when
76
     *               constructing the object
77
     *
78
     * @param  $options associative array
79
     * @return object Returns an error object if something went wrong
80
     */
81
    function Auth_Container_KADM5($options) {
82
        if (!extension_loaded('kadm5')) {
83
            return PEAR::raiseError("Cannot use Kerberos V authentication, KADM5 extension not loaded!", 41, PEAR_ERROR_DIE);
84
        }
1713 jp_milcent 85
 
1173 jp_milcent 86
        $this->_setDefaults();
1713 jp_milcent 87
 
1173 jp_milcent 88
        if (isset($options['hostname'])) {
89
            $this->options['hostname'] = $options['hostname'];
90
        }
91
        if (isset($options['realm'])) {
92
            $this->options['realm'] = $options['realm'];
93
        }
94
        if (isset($options['timeout'])) {
95
            $this->options['timeout'] = $options['timeout'];
96
        }
97
        if (isset($options['checkServer'])) {
98
            $this->options['checkServer'] = $options['checkServer'];
99
        }
1713 jp_milcent 100
 
1173 jp_milcent 101
        if ($this->options['checkServer']) {
102
            $this->_checkServer();
103
        }
104
    }
105
 
106
    // }}}
107
    // {{{ fetchData()
1713 jp_milcent 108
 
1173 jp_milcent 109
    /**
110
     * Try to login to the KADM5 server
111
     *
112
     * @param   string Username
113
     * @param   string Password
114
     * @return  boolean
115
     */
116
    function fetchData($username, $password) {
1713 jp_milcent 117
        $this->log('Auth_Container_KADM5::fetchData() called.', AUTH_LOG_DEBUG);
1173 jp_milcent 118
        if ( ($username == NULL) || ($password == NULL) ) {
119
            return false;
120
        }
1713 jp_milcent 121
 
1173 jp_milcent 122
        $server = $this->options['hostname'];
123
        $realm = $this->options['realm'];
124
        $check = @kadm5_init_with_password($server, $realm, $username, $password);
1713 jp_milcent 125
 
1173 jp_milcent 126
        if ($check == false) {
127
            return false;
128
        } else {
129
            return true;
130
        }
131
    }
1713 jp_milcent 132
 
1173 jp_milcent 133
    // }}}
134
    // {{{ _setDefaults()
1713 jp_milcent 135
 
1173 jp_milcent 136
    /**
137
     * Set some default options
138
     *
139
     * @access private
140
     */
141
    function _setDefaults() {
142
        $this->options['hostname'] = 'localhost';
143
        $this->options['realm'] = NULL;
144
        $this->options['timeout'] = 10;
145
        $this->options['checkServer'] = false;
146
    }
1713 jp_milcent 147
 
1173 jp_milcent 148
    // }}}
149
    // {{{ _checkServer()
1713 jp_milcent 150
 
1173 jp_milcent 151
    /**
152
     * Check if the given server and port are reachable
153
     *
154
     * @access private
155
     */
156
    function _checkServer() {
157
        $fp = @fsockopen ($this->options['hostname'], 88, $errno, $errstr, $this->options['timeout']);
158
        if (is_resource($fp)) {
159
            @fclose($fp);
160
        } else {
161
            $message = "Error connecting to Kerberos V server "
162
                .$this->options['hostname'].":".$this->options['port'];
163
            return PEAR::raiseError($message, 41, PEAR_ERROR_DIE);
164
        }
165
    }
1713 jp_milcent 166
 
1173 jp_milcent 167
    // }}}
168
 
169
}
170
 
171
?>