| 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 [email protected] so we can mail you a copy immediately. |
|---|
| 14 | * |
|---|
| 15 | * @category Authentication |
|---|
| 16 | * @package Auth |
|---|
| 17 | * @author Andrew Teixeira <[email protected]> |
|---|
| 18 | * @author Adam Ashley <[email protected]> |
|---|
| 19 | * @copyright 2001-2006 The PHP Group |
|---|
| 20 | * @license http://www.php.net/license/3_01.txt PHP License 3.01 |
|---|
| 21 | * @version CVS: $Id: KADM5.php 8713 2006-12-01 05:08:34Z kakinaka $ |
|---|
| 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 <[email protected]> |
|---|
| 48 | * @author Adam Ashley <[email protected]> |
|---|
| 49 | * @copyright 2001-2006 The PHP Group |
|---|
| 50 | * @license http://www.php.net/license/3_01.txt PHP License 3.01 |
|---|
| 51 | * @version Release: 1.4.2 File: $Revision: 8713 $ |
|---|
| 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 | } |
|---|
| 85 | |
|---|
| 86 | $this->_setDefaults(); |
|---|
| 87 | |
|---|
| 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 | } |
|---|
| 100 | |
|---|
| 101 | if ($this->options['checkServer']) { |
|---|
| 102 | $this->_checkServer(); |
|---|
| 103 | } |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | // }}} |
|---|
| 107 | // {{{ fetchData() |
|---|
| 108 | |
|---|
| 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) { |
|---|
| 117 | if ( ($username == NULL) || ($password == NULL) ) { |
|---|
| 118 | return false; |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | $server = $this->options['hostname']; |
|---|
| 122 | $realm = $this->options['realm']; |
|---|
| 123 | $check = @kadm5_init_with_password($server, $realm, $username, $password); |
|---|
| 124 | |
|---|
| 125 | if ($check == false) { |
|---|
| 126 | return false; |
|---|
| 127 | } else { |
|---|
| 128 | return true; |
|---|
| 129 | } |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | // }}} |
|---|
| 133 | // {{{ _setDefaults() |
|---|
| 134 | |
|---|
| 135 | /** |
|---|
| 136 | * Set some default options |
|---|
| 137 | * |
|---|
| 138 | * @access private |
|---|
| 139 | */ |
|---|
| 140 | function _setDefaults() { |
|---|
| 141 | $this->options['hostname'] = 'localhost'; |
|---|
| 142 | $this->options['realm'] = NULL; |
|---|
| 143 | $this->options['timeout'] = 10; |
|---|
| 144 | $this->options['checkServer'] = false; |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | // }}} |
|---|
| 148 | // {{{ _checkServer() |
|---|
| 149 | |
|---|
| 150 | /** |
|---|
| 151 | * Check if the given server and port are reachable |
|---|
| 152 | * |
|---|
| 153 | * @access private |
|---|
| 154 | */ |
|---|
| 155 | function _checkServer() { |
|---|
| 156 | $fp = @fsockopen ($this->options['host'], 88, $errno, $errstr, $this->options['timeout']); |
|---|
| 157 | if (is_resource($fp)) { |
|---|
| 158 | @fclose($fp); |
|---|
| 159 | } else { |
|---|
| 160 | $message = "Error connecting to Kerberos V server " |
|---|
| 161 | .$this->options['host'].":".$this->options['port']; |
|---|
| 162 | return PEAR::raiseError($message, 41, PEAR_ERROR_DIE); |
|---|
| 163 | } |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | // }}} |
|---|
| 167 | |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | ?> |
|---|