1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* This module injects itself into Drupal's Authentication stack.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Implements hook_menu().
|
10 |
|
|
*/
|
11 |
|
|
function ldap_sso_menu() {
|
12 |
|
|
$items = array();
|
13 |
|
|
|
14 |
|
|
$items['user/login/sso'] = array(
|
15 |
|
|
'title' => 'Log In',
|
16 |
|
|
'page callback' => 'ldap_sso_user_login_sso',
|
17 |
|
|
'access callback' => '_ldap_authentication_user_access',
|
18 |
|
|
'type' => MENU_NORMAL_ITEM,
|
19 |
|
|
);
|
20 |
|
|
|
21 |
|
|
return $items;
|
22 |
|
|
}
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
/**
|
26 |
|
|
* Implements hook_user_logout().
|
27 |
|
|
*
|
28 |
|
|
* The user just logged out.
|
29 |
|
|
*/
|
30 |
|
|
function ldap_sso_user_logout($account) {
|
31 |
|
|
$auth_conf = ldap_authentication_get_valid_conf();
|
32 |
|
|
if ($auth_conf->seamlessLogin == 1) {
|
33 |
|
|
$cookie_string = 'do not auto login';
|
34 |
dd54aff9
|
Assos Assos
|
$cookie_timeout = (int) $auth_conf->cookieExpire;
|
35 |
85ad3d82
|
Assos Assos
|
setcookie('seamless_login', $cookie_string, (($cookie_timeout == -1) ? 0 : $cookie_timeout + time()), base_path(), "");
|
36 |
|
|
ldap_servers_set_globals('_SESSION', 'seamless_login', $cookie_string);
|
37 |
|
|
}
|
38 |
|
|
}
|
39 |
|
|
|
40 |
|
|
/**
|
41 |
|
|
* Implements hook_boot().
|
42 |
dd54aff9
|
Assos Assos
|
*
|
43 |
|
|
* Perform setup tasks. This entry point is used because hook_user_load no
|
44 |
|
|
* longer runs on anonymous users, and hook_boot is guaranteed to run,
|
45 |
|
|
* regardless of cache.
|
46 |
85ad3d82
|
Assos Assos
|
*/
|
47 |
|
|
function ldap_sso_boot() {
|
48 |
|
|
|
49 |
|
|
if (!drupal_is_cli() && ($GLOBALS['user']->uid == 0)) {
|
50 |
|
|
|
51 |
|
|
if (ldap_sso_path_excluded_from_sso()) {
|
52 |
|
|
return;
|
53 |
|
|
}
|
54 |
|
|
module_load_include('module', 'ldap_servers');
|
55 |
|
|
|
56 |
|
|
if (!(isset($_COOKIE['seamless_login'])) || $_COOKIE['seamless_login'] == 'auto login') {
|
57 |
dd54aff9
|
Assos Assos
|
if ((arg(0) == 'user' && !(is_numeric(arg(1)))) || arg(0) == 'logout') {
|
58 |
85ad3d82
|
Assos Assos
|
return;
|
59 |
|
|
}
|
60 |
|
|
else {
|
61 |
dd54aff9
|
Assos Assos
|
if (isset($_COOKIE['seamless_login_attempted'])) {
|
62 |
85ad3d82
|
Assos Assos
|
$login_attempted = $_COOKIE['seamless_login_attempted'];
|
63 |
dd54aff9
|
Assos Assos
|
}
|
64 |
85ad3d82
|
Assos Assos
|
else {
|
65 |
|
|
$login_attempted = FALSE;
|
66 |
|
|
}
|
67 |
|
|
|
68 |
dd54aff9
|
Assos Assos
|
require_once DRUPAL_ROOT . '/includes/common.inc';
|
69 |
|
|
require_once DRUPAL_ROOT . '/includes/path.inc';
|
70 |
85ad3d82
|
Assos Assos
|
$ldap_authentication_conf = variable_get('ldap_authentication_conf', array());
|
71 |
|
|
|
72 |
|
|
if (isset($ldap_authentication_conf['seamlessLogin']) && $ldap_authentication_conf['seamlessLogin'] == 1 && ($login_attempted != 'true')) {
|
73 |
|
|
if ($ldap_authentication_conf['cookieExpire'] == 0) {
|
74 |
|
|
setcookie("seamless_login_attempted", 'true', 0, base_path(), "");
|
75 |
|
|
}
|
76 |
|
|
else {
|
77 |
dd54aff9
|
Assos Assos
|
setcookie('seamless_login_attempted', 'true', time() + (int) $ldap_authentication_conf['cookieExpire'], base_path(), "");
|
78 |
85ad3d82
|
Assos Assos
|
}
|
79 |
|
|
ldap_servers_set_globals('_SESSION', 'seamless_login_attempted', $login_attempted);
|
80 |
dd54aff9
|
Assos Assos
|
|
81 |
85ad3d82
|
Assos Assos
|
drupal_bootstrap(DRUPAL_BOOTSTRAP_LANGUAGE);
|
82 |
dd54aff9
|
Assos Assos
|
// Seems redundant, but need to check this again after additional
|
83 |
|
|
// bootstrap.
|
84 |
|
|
if (ldap_sso_path_excluded_from_sso()) {
|
85 |
85ad3d82
|
Assos Assos
|
return;
|
86 |
|
|
}
|
87 |
|
|
// Add the query key to the drupal_goto() options array only if there
|
88 |
|
|
// is a destination set. This prevents infinite redirect loops.
|
89 |
|
|
$options = array();
|
90 |
|
|
$destination = drupal_get_destination();
|
91 |
|
|
if (!empty($destination['destination'])) {
|
92 |
dd54aff9
|
Assos Assos
|
$options['query'] = $destination;
|
93 |
|
|
}
|
94 |
85ad3d82
|
Assos Assos
|
drupal_goto('user/login/sso', $options);
|
95 |
|
|
}
|
96 |
|
|
else {
|
97 |
|
|
return;
|
98 |
|
|
}
|
99 |
|
|
}
|
100 |
|
|
}
|
101 |
|
|
}
|
102 |
|
|
}
|
103 |
|
|
|
104 |
dd54aff9
|
Assos Assos
|
/**
|
105 |
|
|
* Default excluded paths.
|
106 |
|
|
*/
|
107 |
85ad3d82
|
Assos Assos
|
function ldap_sso_default_excluded_paths() {
|
108 |
|
|
return array(
|
109 |
dd54aff9
|
Assos Assos
|
'admin/config/search/clean-urls/check',
|
110 |
85ad3d82
|
Assos Assos
|
);
|
111 |
|
|
}
|
112 |
dd54aff9
|
Assos Assos
|
|
113 |
|
|
/**
|
114 |
|
|
* Paths excluded from SSO.
|
115 |
|
|
*/
|
116 |
85ad3d82
|
Assos Assos
|
function ldap_sso_path_excluded_from_sso($path = FALSE) {
|
117 |
|
|
module_load_include('module', 'ldap_servers');
|
118 |
|
|
$result = FALSE;
|
119 |
|
|
if ($path) {
|
120 |
dd54aff9
|
Assos Assos
|
// Don't derive.
|
121 |
85ad3d82
|
Assos Assos
|
}
|
122 |
|
|
elseif (ldap_servers_get_globals('_SERVER', 'PHP_SELF') == '/index.php') {
|
123 |
|
|
$path = $_GET['q'];
|
124 |
|
|
}
|
125 |
|
|
else {
|
126 |
dd54aff9
|
Assos Assos
|
// Cron.php, etc.
|
127 |
|
|
$path = ltrim(ldap_servers_get_globals('_SERVER', 'PHP_SELF'), '/');
|
128 |
85ad3d82
|
Assos Assos
|
}
|
129 |
dd54aff9
|
Assos Assos
|
|
130 |
85ad3d82
|
Assos Assos
|
if (in_array($path, ldap_sso_default_excluded_paths())) {
|
131 |
|
|
return TRUE;
|
132 |
|
|
}
|
133 |
dd54aff9
|
Assos Assos
|
|
134 |
85ad3d82
|
Assos Assos
|
$ldap_authentication_conf = variable_get('ldap_authentication_conf', array());
|
135 |
|
|
|
136 |
|
|
if (isset($ldap_authentication_conf['ssoExcludedHosts']) && is_array($ldap_authentication_conf['ssoExcludedHosts'])) {
|
137 |
|
|
$host = ldap_servers_get_globals('_SERVER', 'SERVER_NAME');
|
138 |
|
|
foreach ($ldap_authentication_conf['ssoExcludedHosts'] as $host_to_check) {
|
139 |
|
|
if ($host_to_check == $host) {
|
140 |
|
|
return TRUE;
|
141 |
|
|
}
|
142 |
|
|
}
|
143 |
|
|
}
|
144 |
|
|
|
145 |
|
|
if (isset($ldap_authentication_conf['ssoExcludedPaths'])) {
|
146 |
dd54aff9
|
Assos Assos
|
$patterns = implode("\r\n", $ldap_authentication_conf['ssoExcludedPaths']);
|
147 |
85ad3d82
|
Assos Assos
|
if ($patterns) {
|
148 |
|
|
if (function_exists('drupal_get_path_alias')) {
|
149 |
|
|
$path = drupal_get_path_alias($path);
|
150 |
|
|
}
|
151 |
|
|
$path = (function_exists('drupal_strtolower')) ? drupal_strtolower($path) : strtolower($path);
|
152 |
|
|
|
153 |
|
|
$to_replace = array(
|
154 |
dd54aff9
|
Assos Assos
|
// Newlines.
|
155 |
|
|
'/(\r\n?|\n)/',
|
156 |
|
|
// Asterisks.
|
157 |
|
|
'/\\\\\*/',
|
158 |
|
|
// <front>.
|
159 |
|
|
'/(^|\|)\\\\<front\\\\>($|\|)/',
|
160 |
85ad3d82
|
Assos Assos
|
);
|
161 |
|
|
$replacements = array(
|
162 |
|
|
'|',
|
163 |
|
|
'.*',
|
164 |
dd54aff9
|
Assos Assos
|
'\1' . preg_quote(variable_get('site_frontpage', 'node'), '/') . '\2',
|
165 |
85ad3d82
|
Assos Assos
|
);
|
166 |
|
|
$patterns_quoted = preg_quote($patterns, '/');
|
167 |
|
|
$regex = '/^(' . preg_replace($to_replace, $replacements, $patterns_quoted) . ')$/';
|
168 |
dd54aff9
|
Assos Assos
|
$result = (bool) preg_match($regex, $path);
|
169 |
85ad3d82
|
Assos Assos
|
}
|
170 |
|
|
}
|
171 |
|
|
|
172 |
|
|
return $result;
|
173 |
|
|
|
174 |
|
|
}
|
175 |
|
|
|
176 |
|
|
|
177 |
|
|
/**
|
178 |
dd54aff9
|
Assos Assos
|
* A proxy function for the actual authentication routine.
|
179 |
|
|
*
|
180 |
|
|
* This is in place so various implementations of grabbing NTLM credentials can
|
181 |
|
|
* be used and selected from an administration page. This is the real gatekeeper
|
182 |
|
|
* since this assumes that any NTLM authentication from the underlying web
|
183 |
|
|
* server is good enough, and only checks that there are values in place for the
|
184 |
85ad3d82
|
Assos Assos
|
* user name, and anything else that is set for a particular implementation. In
|
185 |
|
|
* the case that there are no credentials set by the underlying web server, the
|
186 |
|
|
* user is redirected to the normal user login form.
|
187 |
|
|
*/
|
188 |
|
|
function ldap_sso_user_login_sso() {
|
189 |
|
|
|
190 |
|
|
$detailed_watchdog_log = variable_get('ldap_help_watchdog_detail', 0);
|
191 |
|
|
$auth_conf = ldap_authentication_get_valid_conf();
|
192 |
|
|
|
193 |
|
|
if ($detailed_watchdog_log) {
|
194 |
|
|
$watchdog_tokens = array(
|
195 |
|
|
'!implementation' => $auth_conf->ldapImplementation,
|
196 |
|
|
'!enabled' => $auth_conf->ssoEnabled,
|
197 |
|
|
'!server_remote_user' => @$_SERVER['REMOTE_USER'],
|
198 |
|
|
'!server_redirect_remote_user' => @$_SERVER['REDIRECT_REMOTE_USER'],
|
199 |
|
|
'!ssoRemoteUserStripDomainName' => $auth_conf->ssoRemoteUserStripDomainName,
|
200 |
dd54aff9
|
Assos Assos
|
'!seamlessLogin' => $auth_conf->seamlessLogin,
|
201 |
85ad3d82
|
Assos Assos
|
);
|
202 |
|
|
|
203 |
|
|
watchdog(
|
204 |
|
|
'ldap_sso',
|
205 |
|
|
'ldap_sso_user_login_sso.step1: implementation: !implementation, enabled: !enabled, server_remote_user: !server_remote_user, server_redirect_remote_user: !server_redirect_remote_user, ssoRemoteUserStripDomainName: !ssoRemoteUserStripDomainName,seamlessLogin: !seamlessLogin',
|
206 |
|
|
$watchdog_tokens,
|
207 |
|
|
WATCHDOG_DEBUG
|
208 |
|
|
);
|
209 |
|
|
}
|
210 |
|
|
|
211 |
dd54aff9
|
Assos Assos
|
// Step 1. Derive $remote_user, $realm, and $domain from $_SERVER variable.
|
212 |
85ad3d82
|
Assos Assos
|
$remote_user = NULL;
|
213 |
|
|
$realm = NULL;
|
214 |
|
|
$domain = NULL;
|
215 |
|
|
|
216 |
|
|
switch ($auth_conf->ldapImplementation) {
|
217 |
dd54aff9
|
Assos Assos
|
case 'mod_auth_sspi':
|
218 |
85ad3d82
|
Assos Assos
|
$remote_user = FALSE;
|
219 |
|
|
if ($remote_user = ldap_servers_get_globals('_SERVER', 'REMOTE_USER')) {
|
220 |
|
|
}
|
221 |
|
|
else {
|
222 |
|
|
$remote_user = ldap_servers_get_globals('_SERVER', 'REDIRECT_REMOTE_USER');
|
223 |
|
|
}
|
224 |
|
|
break;
|
225 |
|
|
|
226 |
dd54aff9
|
Assos Assos
|
case 'mod_auth_kerb':
|
227 |
85ad3d82
|
Assos Assos
|
if ($remote_user = ldap_servers_get_globals('_SERVER', 'REMOTE_USER')) {
|
228 |
|
|
}
|
229 |
|
|
else {
|
230 |
|
|
$remote_user = ldap_servers_get_globals('_SERVER', 'REDIRECT_REMOTE_USER');
|
231 |
|
|
}
|
232 |
|
|
|
233 |
|
|
if ($remote_user && preg_match('/^([A-Za-z0-9_\-\.]+)@([A-Za-z0-9_\-.]+)$/', $remote_user, $matches)) {
|
234 |
|
|
$remote_user = $matches[1];
|
235 |
dd54aff9
|
Assos Assos
|
// This can be used later if realms is ever supported properly.
|
236 |
|
|
$realm = $matches[2];
|
237 |
85ad3d82
|
Assos Assos
|
}
|
238 |
|
|
break;
|
239 |
|
|
}
|
240 |
|
|
|
241 |
|
|
if ($detailed_watchdog_log) {
|
242 |
|
|
$watchdog_tokens['!remote_user'] = $remote_user;
|
243 |
|
|
$watchdog_tokens['!realm'] = $realm;
|
244 |
|
|
watchdog('ldap_authentication', 'ldap_sso_user_login_sso.implementation: username=!remote_user, (realm=!realm) found',
|
245 |
|
|
$watchdog_tokens, WATCHDOG_DEBUG);
|
246 |
|
|
}
|
247 |
|
|
|
248 |
|
|
if ($remote_user) {
|
249 |
|
|
if ($auth_conf->ssoRemoteUserStripDomainName) {
|
250 |
dd54aff9
|
Assos Assos
|
// Might be in form <remote_user>@<domain> or <domain>\<remote_user>.
|
251 |
85ad3d82
|
Assos Assos
|
$domain = NULL;
|
252 |
|
|
$exploded = preg_split('/[\@\\\\]/', $remote_user);
|
253 |
|
|
if (count($exploded) == 2) {
|
254 |
|
|
if (strpos($remote_user, '@') !== FALSE) {
|
255 |
|
|
$remote_user = $exploded[0];
|
256 |
|
|
$domain = $exploded[1];
|
257 |
|
|
}
|
258 |
|
|
else {
|
259 |
|
|
$domain = $exploded[0];
|
260 |
|
|
$remote_user = $exploded[1];
|
261 |
|
|
}
|
262 |
|
|
if ($detailed_watchdog_log) {
|
263 |
|
|
$watchdog_tokens['!remote_user'] = $remote_user;
|
264 |
|
|
$watchdog_tokens['!domain'] = $domain;
|
265 |
|
|
watchdog('ldap_authentication', 'ldap_sso_user_login_sso.stripdomain: remote_user=!remote_user, domain=!domain', $watchdog_tokens, WATCHDOG_DEBUG);
|
266 |
|
|
}
|
267 |
|
|
}
|
268 |
|
|
}
|
269 |
|
|
|
270 |
|
|
if ($detailed_watchdog_log) {
|
271 |
|
|
$watchdog_tokens['!remote_user'] = $remote_user;
|
272 |
|
|
$watchdog_tokens['!realm'] = $realm;
|
273 |
|
|
$watchdog_tokens['!domain'] = $domain;
|
274 |
|
|
watchdog('ldap_authentication', 'ldap_sso_user_login_sso.remote_user: username=!remote_user, (realm=!realm, domain=!domain) found', $watchdog_tokens, WATCHDOG_DEBUG);
|
275 |
|
|
}
|
276 |
|
|
$fake_form_state = array(
|
277 |
|
|
'values' => array(
|
278 |
|
|
'name' => check_plain($remote_user),
|
279 |
|
|
'pass' => user_password(20),
|
280 |
|
|
),
|
281 |
|
|
'sso_login' => TRUE,
|
282 |
|
|
);
|
283 |
|
|
|
284 |
dd54aff9
|
Assos Assos
|
// Make sure we're populating the global user object so that we can log this
|
285 |
|
|
// user in.
|
286 |
85ad3d82
|
Assos Assos
|
global $user;
|
287 |
|
|
$user = ldap_authentication_user_login_authenticate_validate(array(), $fake_form_state, TRUE);
|
288 |
|
|
|
289 |
|
|
// Reload the account to ensure we have a fully populated user object.
|
290 |
|
|
$user = user_load($user->uid);
|
291 |
|
|
|
292 |
|
|
if ($detailed_watchdog_log) {
|
293 |
|
|
$watchdog_tokens['!uid'] = is_object($user) ? $user->uid : NULL;
|
294 |
|
|
watchdog('ldap_authentication', 'ldap_sso_user_login_sso.remote_user: uid of user=!uid', $watchdog_tokens, WATCHDOG_DEBUG);
|
295 |
|
|
}
|
296 |
|
|
|
297 |
|
|
if ($user && $user->uid > 0) {
|
298 |
|
|
if ($auth_conf->seamlessLogin == 1) {
|
299 |
|
|
if ($detailed_watchdog_log) {
|
300 |
|
|
watchdog('ldap_authentication', 'ldap_sso_user_login_sso.remote_user.user_success.seamlessLogin', $watchdog_tokens, WATCHDOG_DEBUG);
|
301 |
|
|
}
|
302 |
|
|
setcookie("seamless_login", 'auto login', time() + $auth_conf->cookieExpire, base_path(), "");
|
303 |
|
|
ldap_servers_set_globals('_SESSION', 'seamless_login', 'auto login');
|
304 |
|
|
setcookie("seamless_login_attempted", '');
|
305 |
|
|
ldap_servers_delete_globals('_SESSION', 'seamless_login_attempted');
|
306 |
dd54aff9
|
Assos Assos
|
// Make sure we tell Drupal to create the session cookie for this
|
307 |
|
|
// authenticated user.
|
308 |
85ad3d82
|
Assos Assos
|
}
|
309 |
|
|
user_login_finalize();
|
310 |
|
|
if ($auth_conf->ssoNotifyAuthentication) {
|
311 |
|
|
drupal_set_message(theme('ldap_authentication_login_message',
|
312 |
|
|
array('message' => t('You have been successfully authenticated'))));
|
313 |
|
|
}
|
314 |
|
|
if ($detailed_watchdog_log) {
|
315 |
|
|
watchdog('ldap_authentication', 'ldap_sso_user_login_sso.remote_user.user_success.drupal_goto front', $watchdog_tokens, WATCHDOG_DEBUG);
|
316 |
|
|
}
|
317 |
|
|
drupal_goto('<front>');
|
318 |
|
|
}
|
319 |
|
|
else {
|
320 |
|
|
if ($auth_conf->seamlessLogin == 1) {
|
321 |
|
|
if ($detailed_watchdog_log) {
|
322 |
|
|
watchdog('ldap_authentication', 'ldap_sso_user_login_sso.remote_user.user_fail.seamlessLogin', $watchdog_tokens, WATCHDOG_DEBUG);
|
323 |
|
|
}
|
324 |
|
|
setcookie("seamless_login", 'do not auto login', time() + $auth_conf->cookieExpire, base_path(), "");
|
325 |
|
|
ldap_servers_set_globals('_SESSION', 'seamless_login', 'do not auto login');
|
326 |
|
|
}
|
327 |
dd54aff9
|
Assos Assos
|
drupal_set_message(theme('ldap_authentication_message_not_found', array(
|
328 |
|
|
'message' => t('Sorry, your LDAP credentials were not found, or the LDAP server is not available. You may log in with other credentials on the !user_login_form.',
|
329 |
|
|
array('!user_login_form' => l(t('user login form'), 'user/login'))))
|
330 |
85ad3d82
|
Assos Assos
|
), 'error');
|
331 |
|
|
if ($detailed_watchdog_log) {
|
332 |
|
|
watchdog('ldap_authentication', 'ldap_sso_user_login_sso.remote_user.user_fail.drupal_goto user/logint', $watchdog_tokens, WATCHDOG_DEBUG);
|
333 |
|
|
}
|
334 |
|
|
drupal_goto('user/login');
|
335 |
|
|
}
|
336 |
|
|
}
|
337 |
|
|
else {
|
338 |
dd54aff9
|
Assos Assos
|
if ($detailed_watchdog_log) {
|
339 |
|
|
watchdog('ldap_authentication', '$_SERVER[\'REMOTE_USER\'] not found', array(), WATCHDOG_DEBUG);
|
340 |
|
|
}
|
341 |
85ad3d82
|
Assos Assos
|
if ($auth_conf->seamlessLogin == 1) {
|
342 |
|
|
setcookie("seamless_login", 'do not auto login', time() + $auth_conf->cookieExpire, base_path(), "");
|
343 |
|
|
ldap_servers_set_globals('_SESSION', 'seamless_login', 'do not auto login');
|
344 |
|
|
if ($detailed_watchdog_log) {
|
345 |
|
|
watchdog('ldap_authentication', 'ldap_sso_user_login_sso.no_remote_user.seamlessLogin', $watchdog_tokens, WATCHDOG_DEBUG);
|
346 |
|
|
}
|
347 |
|
|
}
|
348 |
dd54aff9
|
Assos Assos
|
drupal_set_message(theme('ldap_authentication_message_not_authenticated', array(
|
349 |
|
|
'message' => t('You were not authenticated by the server. You may log in with your credentials below.'),
|
350 |
|
|
)), 'error');
|
351 |
85ad3d82
|
Assos Assos
|
if ($detailed_watchdog_log) {
|
352 |
|
|
watchdog('ldap_authentication', 'ldap_sso_user_login_sso.no_remote_user.drupal_goto user/login', $watchdog_tokens, WATCHDOG_DEBUG);
|
353 |
|
|
}
|
354 |
|
|
drupal_goto('user/login');
|
355 |
|
|
}
|
356 |
|
|
}
|
357 |
|
|
|
358 |
|
|
|
359 |
|
|
/**
|
360 |
dd54aff9
|
Assos Assos
|
* Used to mock $_SERVER, $_SESSION, etc globals for simpletests.
|
361 |
85ad3d82
|
Assos Assos
|
*
|
362 |
dd54aff9
|
Assos Assos
|
* @param string $global_type
|
363 |
|
|
* _SERVER, _ENV, _COOKIE, _GET, _POST, _REQUEST.
|
364 |
|
|
* @param string $key
|
365 |
|
|
* Such as 'SERVER_ADDR', 'SERVER_PROTOCOL', etc.
|
366 |
|
|
* @param bool $only_mock_values
|
367 |
|
|
* Don't get actual values when mock values don't exist.
|
368 |
85ad3d82
|
Assos Assos
|
*
|
369 |
dd54aff9
|
Assos Assos
|
* @return mixed
|
370 |
|
|
* ldap_simpletest_globals variable for global and key or $_SERVER[][],
|
371 |
|
|
* $_ENV[][], etv value if not in a simpletest or mock variable not available.
|
372 |
|
|
*/
|
373 |
85ad3d82
|
Assos Assos
|
function ldap_servers_get_globals($global_type, $key, $only_mock_values = FALSE) {
|
374 |
|
|
$simpletest_globals = variable_get('ldap_simpletest_globals', array());
|
375 |
|
|
$simpletest = variable_get('ldap_simpletest', FALSE);
|
376 |
|
|
|
377 |
|
|
if ($simpletest && (isset($simpletest_globals[$global_type][$key]) || $only_mock_values)) {
|
378 |
|
|
return ($simpletest_globals[$global_type][$key]) ? $simpletest_globals[$global_type][$key] : NULL;
|
379 |
|
|
}
|
380 |
dd54aff9
|
Assos Assos
|
else {
|
381 |
85ad3d82
|
Assos Assos
|
return (isset($GLOBALS[$global_type][$key]) && !$only_mock_values) ? $GLOBALS[$global_type][$key] : NULL;
|
382 |
|
|
}
|
383 |
|
|
|
384 |
|
|
}
|
385 |
|
|
|
386 |
dd54aff9
|
Assos Assos
|
/**
|
387 |
|
|
* Set globals.
|
388 |
|
|
*
|
389 |
|
|
* @param string $global_type
|
390 |
|
|
* _SERVER, _ENV, _COOKIE, _GET, _POST, _REQUEST.
|
391 |
|
|
* @param string $key
|
392 |
|
|
* Such as 'SERVER_ADDR', 'SERVER_PROTOCOL', etc.
|
393 |
|
|
* @param string $value
|
394 |
|
|
* The value to be set.
|
395 |
|
|
*/
|
396 |
85ad3d82
|
Assos Assos
|
function ldap_servers_set_globals($global_type, $key, $value) {
|
397 |
|
|
$simpletest_globals = variable_get('ldap_simpletest_globals', array());
|
398 |
|
|
$simpletest = variable_get('ldap_simpletest', FALSE);
|
399 |
|
|
if ($simpletest) {
|
400 |
|
|
$simpletest_globals[$global_type][$key] = $value;
|
401 |
|
|
variable_set('ldap_simpletest_globals', $simpletest_globals);
|
402 |
|
|
}
|
403 |
|
|
else {
|
404 |
|
|
$GLOBALS[$global_type][$key] = $value;
|
405 |
|
|
}
|
406 |
|
|
|
407 |
|
|
}
|
408 |
|
|
|
409 |
dd54aff9
|
Assos Assos
|
/**
|
410 |
|
|
* Delete globals.
|
411 |
|
|
*
|
412 |
|
|
* @param string $global_type
|
413 |
|
|
* _SERVER, _ENV, _COOKIE, _GET, _POST, _REQUEST.
|
414 |
|
|
* @param string $key
|
415 |
|
|
* Such as 'SERVER_ADDR', 'SERVER_PROTOCOL', etc.
|
416 |
|
|
* @param bool $only_mock_values
|
417 |
|
|
* Don't get actual values when mock values don't exist.
|
418 |
|
|
*/
|
419 |
85ad3d82
|
Assos Assos
|
function ldap_servers_delete_globals($global_type, $key, $only_mock_values = FALSE) {
|
420 |
|
|
$simpletest_globals = variable_get('ldap_simpletest_globals', array());
|
421 |
|
|
$simpletest = variable_get('ldap_simpletest', FALSE);
|
422 |
|
|
if ($simpletest && isset($simpletest_globals[$global_type][$key])) {
|
423 |
|
|
unset($simpletest_globals[$global_type][$key]);
|
424 |
|
|
variable_set('ldap_simpletest_globals', $simpletest_globals);
|
425 |
|
|
}
|
426 |
|
|
elseif (!$only_mock_values && isset($GLOBALS[$global_type][$key])) {
|
427 |
|
|
unset($GLOBALS[$global_type][$key]);
|
428 |
|
|
}
|
429 |
|
|
|
430 |
|
|
} |