2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Set of functions used to run http authentication.
5 * NOTE: Requires PHP loaded as a Apache module.
7 * @package phpMyAdmin-Auth-HTTP
13 * Displays authentication form
15 * @global string the font face to use in case of failure
16 * @global string the default font size to use in case of failure
17 * @global string the big font size to use in case of failure
19 * @return boolean always true (no return indeed)
25 /* Perform logout to custom URL */
26 if (!empty($_REQUEST['old_usr']) && !empty($GLOBALS['cfg']['Server']['LogoutURL'])) {
27 PMA_sendHeaderLocation($GLOBALS['cfg']['Server']['LogoutURL']);
31 if (empty($GLOBALS['cfg']['Server']['auth_http_realm'])) {
32 if (empty($GLOBALS['cfg']['Server']['verbose'])) {
33 $server_message = $GLOBALS['cfg']['Server']['host'];
35 $server_message = $GLOBALS['cfg']['Server']['verbose'];
37 $realm_message = 'phpMyAdmin ' . $server_message;
39 $realm_message = $GLOBALS['cfg']['Server']['auth_http_realm'];
41 // remove non US-ASCII to respect RFC2616
42 $realm_message = preg_replace('/[^\x20-\x7e]/i', '', $realm_message);
43 header('WWW-Authenticate: Basic realm="' . $realm_message . '"');
44 header('HTTP/1.0 401 Unauthorized');
45 if (php_sapi_name() !== 'cgi-fcgi') {
46 header('status: 401 Unauthorized');
49 // Defines the charset to be used
50 header('Content-Type: text/html; charset=' . $GLOBALS['charset']);
52 $page_title = __('Access denied');
53 require './libraries/header_meta_style.inc.php';
58 if (file_exists(CUSTOM_HEADER_FILE
)) {
59 require CUSTOM_HEADER_FILE
;
65 <h1
><?php
echo sprintf(__('Welcome to %s'), ' phpMyAdmin'); ?
></h1
>
70 PMA_Message
::error(__('Wrong username/password. Access denied.'))->display();
72 if (file_exists(CUSTOM_FOOTER_FILE
)) {
73 require CUSTOM_FOOTER_FILE
;
81 } // end of the 'PMA_auth()' function
85 * Gets advanced authentication settings
87 * @global string the username if register_globals is on
88 * @global string the password if register_globals is on
89 * @global array the array of server variables if register_globals is
91 * @global array the array of environment variables if register_globals
93 * @global string the username for the ? server
94 * @global string the password for the ? server
95 * @global string the username for the WebSite Professional server
96 * @global string the password for the WebSite Professional server
97 * @global string the username of the user who logs out
99 * @return boolean whether we get authentication settings or not
103 function PMA_auth_check()
105 global $PHP_AUTH_USER, $PHP_AUTH_PW;
108 // Grabs the $PHP_AUTH_USER variable whatever are the values of the
109 // 'register_globals' and the 'variables_order' directives
110 if (empty($PHP_AUTH_USER)) {
111 if (PMA_getenv('PHP_AUTH_USER')) {
112 $PHP_AUTH_USER = PMA_getenv('PHP_AUTH_USER');
113 } elseif (PMA_getenv('REMOTE_USER')) {
114 // CGI, might be encoded, see below
115 $PHP_AUTH_USER = PMA_getenv('REMOTE_USER');
116 } elseif (PMA_getenv('REDIRECT_REMOTE_USER')) {
117 // CGI, might be encoded, see below
118 $PHP_AUTH_USER = PMA_getenv('REDIRECT_REMOTE_USER');
119 } elseif (PMA_getenv('AUTH_USER')) {
120 // WebSite Professional
121 $PHP_AUTH_USER = PMA_getenv('AUTH_USER');
122 } elseif (PMA_getenv('HTTP_AUTHORIZATION')) {
123 // IIS, might be encoded, see below
124 $PHP_AUTH_USER = PMA_getenv('HTTP_AUTHORIZATION');
125 } elseif (PMA_getenv('Authorization')) {
126 // FastCGI, might be encoded, see below
127 $PHP_AUTH_USER = PMA_getenv('Authorization');
130 // Grabs the $PHP_AUTH_PW variable whatever are the values of the
131 // 'register_globals' and the 'variables_order' directives
132 if (empty($PHP_AUTH_PW)) {
133 if (PMA_getenv('PHP_AUTH_PW')) {
134 $PHP_AUTH_PW = PMA_getenv('PHP_AUTH_PW');
135 } elseif (PMA_getenv('REMOTE_PASSWORD')) {
137 $PHP_AUTH_PW = PMA_getenv('REMOTE_PASSWORD');
138 } elseif (PMA_getenv('AUTH_PASSWORD')) {
139 // WebSite Professional
140 $PHP_AUTH_PW = PMA_getenv('AUTH_PASSWORD');
144 // Decode possibly encoded information (used by IIS/CGI/FastCGI)
145 // (do not use explode() because a user might have a colon in his password
146 if (strcmp(substr($PHP_AUTH_USER, 0, 6), 'Basic ') == 0) {
147 $usr_pass = base64_decode(substr($PHP_AUTH_USER, 6));
148 if (! empty($usr_pass)) {
149 $colon = strpos($usr_pass, ':');
151 $PHP_AUTH_USER = substr($usr_pass, 0, $colon);
152 $PHP_AUTH_PW = substr($usr_pass, $colon +
1);
159 // User logged out -> ensure the new username is not the same
161 && (isset($PHP_AUTH_USER) && $old_usr == $PHP_AUTH_USER)) {
163 // -> delete user's choices that were stored in session
167 // Returns whether we get authentication settings or not
168 if (empty($PHP_AUTH_USER)) {
173 } // end of the 'PMA_auth_check()' function
177 * Set the user and password after last checkings if required
179 * @global array the valid servers settings
180 * @global integer the id of the current server
181 * @global array the current server settings
182 * @global string the current username
183 * @global string the current password
185 * @return boolean always true
189 function PMA_auth_set_user()
191 global $cfg, $server;
192 global $PHP_AUTH_USER, $PHP_AUTH_PW;
194 // Ensures valid authentication mode, 'only_db', bookmark database and
195 // table names and relation table name are used
196 if ($cfg['Server']['user'] != $PHP_AUTH_USER) {
197 $servers_cnt = count($cfg['Servers']);
198 for ($i = 1; $i <= $servers_cnt; $i++
) {
199 if (isset($cfg['Servers'][$i])
200 && ($cfg['Servers'][$i]['host'] == $cfg['Server']['host'] && $cfg['Servers'][$i]['user'] == $PHP_AUTH_USER)) {
202 $cfg['Server'] = $cfg['Servers'][$i];
208 $cfg['Server']['user'] = $PHP_AUTH_USER;
209 $cfg['Server']['password'] = $PHP_AUTH_PW;
212 } // end of the 'PMA_auth_set_user()' function
216 * User is not allowed to login to MySQL -> authentication failed
218 * @return boolean always true (no return indeed)
222 function PMA_auth_fails()
224 $error = PMA_DBI_getError();
225 if ($error && $GLOBALS['errno'] != 1045) {
226 PMA_fatalError($error);
232 } // end of the 'PMA_auth_fails()' function