3
* Apache auth plug-in for phpBB3
5
* Authentication plug-ins is largely down to Sergey Kanareykin, our thanks to him.
8
* @version $Id: auth_apache.php,v 1.18 2007/10/05 12:42:06 acydburn Exp $
9
* @copyright (c) 2005 phpBB Group
10
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
17
if (!defined('IN_PHPBB'))
23
* Checks whether the user is identified to apache
24
* Only allow changing authentication to apache if the user is identified
25
* Called in acp_board while setting authentication plugins
27
* @return boolean|string false if the user is identified and else an error message
29
function init_apache()
33
if (!isset($_SERVER['PHP_AUTH_USER']) || $user->data['username'] !== $_SERVER['PHP_AUTH_USER'])
35
return $user->lang['APACHE_SETUP_BEFORE_USE'];
43
function login_apache(&$username, &$password)
47
// do not allow empty password
51
'status' => LOGIN_BREAK,
52
'error_msg' => 'NO_PASSWORD_SUPPLIED',
56
if (!isset($_SERVER['PHP_AUTH_USER']))
59
'status' => LOGIN_ERROR_EXTERNAL_AUTH,
60
'error_msg' => 'LOGIN_ERROR_EXTERNAL_AUTH_APACHE',
61
'user_row' => array('user_id' => ANONYMOUS),
65
$php_auth_user = $_SERVER['PHP_AUTH_USER'];
66
$php_auth_pw = $_SERVER['PHP_AUTH_PW'];
68
if (!empty($php_auth_user) && !empty($php_auth_pw))
70
if ($php_auth_user !== $username)
73
'status' => LOGIN_ERROR_USERNAME,
74
'error_msg' => 'LOGIN_ERROR_USERNAME',
75
'user_row' => array('user_id' => ANONYMOUS),
79
$sql = 'SELECT user_id, username, user_password, user_passchg, user_email, user_type
80
FROM ' . USERS_TABLE . "
81
WHERE username = '" . $db->sql_escape($php_auth_user) . "'";
82
$result = $db->sql_query($sql);
83
$row = $db->sql_fetchrow($result);
84
$db->sql_freeresult($result);
89
if ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE)
92
'status' => LOGIN_ERROR_ACTIVE,
93
'error_msg' => 'ACTIVE_ERROR',
98
// Successful login...
100
'status' => LOGIN_SUCCESS,
101
'error_msg' => false,
106
// this is the user's first login so create an empty profile
108
'status' => LOGIN_SUCCESS_CREATE_PROFILE,
109
'error_msg' => false,
110
'user_row' => user_row_apache($php_auth_user, $php_auth_pw),
114
// Not logged into apache
116
'status' => LOGIN_ERROR_EXTERNAL_AUTH,
117
'error_msg' => 'LOGIN_ERROR_EXTERNAL_AUTH_APACHE',
118
'user_row' => array('user_id' => ANONYMOUS),
125
* @return array containing the user row or empty if no auto login should take place
127
function autologin_apache()
131
if (!isset($_SERVER['PHP_AUTH_USER']))
136
$php_auth_user = $_SERVER['PHP_AUTH_USER'];
137
$php_auth_pw = $_SERVER['PHP_AUTH_PW'];
139
if (!empty($php_auth_user) && !empty($php_auth_pw))
141
set_var($php_auth_user, $php_auth_user, 'string');
142
set_var($php_auth_pw, $php_auth_pw, 'string');
145
FROM ' . USERS_TABLE . "
146
WHERE username = '" . $db->sql_escape($php_auth_user) . "'";
147
$result = $db->sql_query($sql);
148
$row = $db->sql_fetchrow($result);
149
$db->sql_freeresult($result);
153
return ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE) ? array() : $row;
156
if (!function_exists('user_add'))
158
global $phpbb_root_path, $phpEx;
160
include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
163
// create the user if he does not exist yet
164
user_add(user_row_apache($php_auth_user, $php_auth_pw));
167
FROM ' . USERS_TABLE . "
168
WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($php_auth_user)) . "'";
169
$result = $db->sql_query($sql);
170
$row = $db->sql_fetchrow($result);
171
$db->sql_freeresult($result);
183
* This function generates an array which can be passed to the user_add function in order to create a user
185
function user_row_apache($username, $password)
187
global $db, $config, $user;
188
// first retrieve default group id
189
$sql = 'SELECT group_id
190
FROM ' . GROUPS_TABLE . "
191
WHERE group_name = '" . $db->sql_escape('REGISTERED') . "'
192
AND group_type = " . GROUP_SPECIAL;
193
$result = $db->sql_query($sql);
194
$row = $db->sql_fetchrow($result);
195
$db->sql_freeresult($result);
199
trigger_error('NO_GROUP');
202
// generate user account data
204
'username' => $username,
205
'user_password' => phpbb_hash($password),
207
'group_id' => (int) $row['group_id'],
208
'user_type' => USER_NORMAL,
209
'user_ip' => $user->ip,
214
* The session validation function checks whether the user is still logged in
216
* @return boolean true if the given user is authenticated or false if the session should be closed
218
function validate_session_apache(&$user)
220
if (!isset($_SERVER['PHP_AUTH_USER']))
226
set_var($php_auth_user, $_SERVER['PHP_AUTH_USER'], 'string');
228
return ($php_auth_user === $user['username']) ? true : false;
b'\\ No newline at end of file'