* Force TCEform reload if the plugin is changed
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_userauth.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Contains a base class for authentication of users in TYPO3, both frontend and backend.
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
32 *
33 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
34 * @author René Fritz <r.fritz@colorcube.de>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 111: class t3lib_userAuth
42 * 187: function start()
43 * 300: function checkAuthentication()
44 *
45 * SECTION: User Sessions
46 * 531: function createUserSession ($tempuser)
47 * 568: function fetchUserSession()
48 * 619: function logoff()
49 *
50 * SECTION: SQL Functions
51 * 655: function user_where_clause()
52 * 669: function ipLockClause()
53 * 687: function ipLockClause_remoteIPNumber($parts)
54 * 708: function hashLockClause()
55 * 719: function hashLockClause_getHashInt()
56 *
57 * SECTION: Session and Configuration Handling
58 * 751: function writeUC($variable='')
59 * 766: function unpack_uc($theUC='')
60 * 782: function pushModuleData($module,$data,$noSave=0)
61 * 795: function getModuleData($module,$type='')
62 * 808: function getSessionData($key)
63 * 821: function setAndSaveSessionData($key,$data)
64 *
65 * SECTION: Misc
66 * 854: function getLoginFormData()
67 * 881: function processLoginData($loginData, $security_level='')
68 * 915: function getAuthInfoArray()
69 * 945: function compareUident($user, $loginData, $security_level='')
70 * 983: function gc()
71 * 997: function redirect()
72 * 1019: function writelog($type,$action,$error,$details_nr,$details,$data,$tablename,$recuid,$recpid)
73 * 1028: function checkLogFailures()
74 * 1041: function setBeUserByUid($uid)
75 * 1053: function setBeUserByName($name)
76 * 1064: function getRawUserByUid($uid)
77 * 1082: function getRawUserByName($name)
78 *
79 * SECTION: Create/update user - EXPERIMENTAL
80 * 1121: function fetchUserRecord($dbUser, $username, $extraWhere='' )
81 *
82 * TOTAL FUNCTIONS: 29
83 * (This index is automatically created/updated by the extension "extdeveval")
84 *
85 */
86
87
88 require_once(t3lib_extMgm::extPath('sv').'class.tx_sv_authbase.php');
89
90
91
92
93
94
95
96
97
98 /**
99 * Authentication of users in TYPO3
100 *
101 * This class is used to authenticate a login user.
102 * The class is used by both the frontend and backend. In both cases this class is a parent class to beuserauth and feuserauth
103 *
104 * See Inside TYPO3 for more information about the API of the class and internal variables.
105 *
106 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
107 * @author René Fritz <r.fritz@colorcube.de>
108 * @package TYPO3
109 * @subpackage t3lib
110 */
111 class t3lib_userAuth {
112 var $global_database = ''; // Which global database to connect to
113 var $session_table = ''; // Table to use for session data.
114 var $name = ''; // Session/Cookie name
115 var $get_name = ''; // Session/GET-var name
116
117 var $user_table = ''; // Table in database with userdata
118 var $username_column = ''; // Column for login-name
119 var $userident_column = ''; // Column for password
120 var $userid_column = ''; // Column for user-id
121 var $lastLogin_column = '';
122
123 var $enablecolumns = Array (
124 'rootLevel' => '', // Boolean: If true, 'AND pid=0' will be a part of the query...
125 'disabled' => '',
126 'starttime' => '',
127 'endtime' => '',
128 'deleted' => ''
129 );
130
131 var $formfield_uname = ''; // formfield with login-name
132 var $formfield_uident = ''; // formfield with password
133 var $formfield_chalvalue = ''; // formfield with a unique value which is used to encrypt the password and username
134 var $formfield_status = ''; // formfield with status: *'login', 'logout'. If empty login is not verified.
135 var $security_level = 'normal'; // sets the level of security. *'normal' = clear-text. 'challenged' = hashed password/username from form in $formfield_uident. 'superchallenged' = hashed password hashed again with username.
136
137 var $auth_include = ''; // this is the name of the include-file containing the login form. If not set, login CAN be anonymous. If set login IS needed.
138
139 var $auth_timeout_field = 0; // if > 0 : session-timeout in seconds. if string: The string is fieldname from the usertable where the timeout can be found.
140 var $lifetime = 0; // 0 = Session-cookies. If session-cookies, the browser will stop session when the browser is closed. Else it keeps the session for $lifetime seconds.
141 var $gc_time = 24; // GarbageCollection. Purge all session data older than $gc_time hours.
142 var $gc_probability = 1; // Possibility (in percent) for GarbageCollection to be run.
143 var $writeStdLog = FALSE; // Decides if the writelog() function is called at login and logout
144 var $writeAttemptLog = FALSE; // If the writelog() functions is called if a login-attempt has be tried without success
145 var $sendNoCacheHeaders = TRUE; // If this is set, headers is sent to assure, caching is NOT done
146 var $getFallBack = FALSE; // If this is set, authentication is also accepted by the $_GET. Notice that the identification is NOT 128bit MD5 hash but reduced. This is done in order to minimize the size for mobile-devices, such as WAP-phones
147 var $hash_length = 32; // The ident-hash is normally 32 characters and should be! But if you are making sites for WAP-devices og other lowbandwidth stuff, you may shorten the length. Never let this value drop below 6. A length of 6 would give you more than 16 mio possibilities.
148 var $getMethodEnabled = FALSE; // Setting this flag true lets user-authetication happen from GET_VARS if POST_VARS are not set. Thus you may supply username/password from the URL.
149 var $lockIP = 4; // If set, will lock the session to the users IP address (all four numbers. Reducing to 1-3 means that only first, second or third part of the IP address is used).
150 var $lockHashKeyWords = 'useragent'; // Keyword list (commalist with no spaces!): "useragent". Each keyword indicates some information that can be included in a integer hash made to lock down usersessions.
151
152 var $warningEmail = ''; // warning -emailaddress:
153 var $warningPeriod = 3600; // Period back in time (in seconds) in which number of failed logins are collected
154 var $warningMax = 3; // The maximum accepted number of warnings before an email is sent
155 var $checkPid = TRUE; // If set, the user-record must $checkPid_value as pid
156 var $checkPid_value=0; // The pid, the user-record must have as page-id
157
158 // Internals
159 var $id; // Internal: Will contain session_id (MD5-hash)
160 var $cookieId; // Internal: Will contain the session_id gotten from cookie or GET method. This is used in statistics as a reliable cookie (one which is known to come from $_COOKIE).
161 var $loginFailure = FALSE; // Indicates if an authentication was started but failed
162 var $loginSessionStarted = FALSE; // Will be set to true if the login session is actually written during auth-check.
163
164 var $user; // Internal: Will contain user- AND session-data from database (joined tables)
165 var $get_URL_ID = ''; // Internal: Will will be set to the url--ready (eg. '&login=ab7ef8d...') GET-auth-var if getFallBack is true. Should be inserted in links!
166
167 var $newSessionID = FALSE; // Will be set to true if a new session ID was created
168 var $forceSetCookie = FALSE; // Will force the session cookie to be set everytime (lifetime must be 0)
169 var $dontSetCookie = FALSE; // Will prevent the setting of the session cookie (takes precedence over forceSetCookie)
170 var $challengeStoredInCookie = FALSE; // If set, the challenge value will be stored in a session as well so the server can check that is was not forged.
171 var $loginType = ''; // Login type, used for services.
172
173 var $svConfig = array(); // "auth" services configuration array from $TYPO3_CONF_VARS['SVCONF']['auth']
174 var $writeDevLog = FALSE; // write messages into the devlog?
175
176
177
178
179
180
181
182
183
184 /**
185 * Starts a user session
186 * Typical configurations will:
187 * a) check if session cookie was set and if not, set one,
188 * b) check if a password/username was sent and if so, try to authenticate the user
189 * c) Lookup a session attached to a user and check timeout etc.
190 * d) Garbage collection, setting of no-cache headers.
191 * If a user is authenticated the database record of the user (array) will be set in the ->user internal variable.
192 *
193 * @return void
194 */
195 function start() {
196 global $TYPO3_CONF_VARS;
197
198 // backend or frontend login - used for auth services
199 $this->loginType = ($this->name=='fe_typo_user') ? 'FE' : 'BE';
200
201 // set level to normal if not already set
202 $this->security_level = $this->security_level ? $this->security_level : 'normal';
203
204 // enable dev logging if set
205 if ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['writeDevLog']) $this->writeDevLog = TRUE;
206 if ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['writeDevLog'.$this->loginType]) $this->writeDevLog = TRUE;
207 if (TYPO3_DLOG) $this->writeDevLog = TRUE;
208
209 if ($this->writeDevLog) t3lib_div::devLog('## Beginning of auth logging.', 't3lib_userAuth');
210
211 // Init vars.
212 $mode = '';
213 $this->newSessionID = FALSE;
214 // $id is set to ses_id if cookie is present. Else set to false, which will start a new session
215 $id = isset($_COOKIE[$this->name]) ? stripslashes($_COOKIE[$this->name]) : '';
216 $this->hash_length = t3lib_div::intInRange($this->hash_length,6,32);
217 $this->svConfig = $TYPO3_CONF_VARS['SVCONF']['auth'];
218
219
220 // If fallback to get mode....
221 if (!$id && $this->getFallBack && $this->get_name) {
222 $id = isset($_GET[$this->get_name]) ? t3lib_div::_GET($this->get_name) : '';
223 if (strlen($id)!=$this->hash_length) $id='';
224 $mode='get';
225 }
226 $this->cookieId = $id;
227
228 // If new session...
229 if (!$id) {
230 // New random session-$id is made
231 $id = substr(md5(uniqid('').getmypid()),0,$this->hash_length);
232 // New session
233 $this->newSessionID = TRUE;
234 }
235
236 // Internal var 'id' is set
237 $this->id = $id;
238
239 // If fallback to get mode....
240 if ($mode=='get' && $this->getFallBack && $this->get_name) {
241 $this->get_URL_ID = '&'.$this->get_name.'='.$id;
242 }
243 // Make certain that NO user is set initially
244 $this->user = '';
245
246 // Setting cookies
247 // If new session and the cookie is a sessioncookie, we need to set it only once!
248 if (($this->newSessionID || $this->forceSetCookie) && $this->lifetime==0 ) {
249 if (!$this->dontSetCookie) {
250 SetCookie($this->name, $id, 0, '/');
251 if ($this->writeDevLog) t3lib_div::devLog('Set new Cookie: '.$id, 't3lib_userAuth');
252 }
253 }
254
255 // If it is NOT a session-cookie, we need to refresh it.
256 if ($this->lifetime > 0) {
257 if (!$this->dontSetCookie) {
258 SetCookie($this->name, $id, time()+$this->lifetime, '/');
259 if ($this->writeDevLog) t3lib_div::devLog('Update Cookie: '.$id, 't3lib_userAuth');
260 }
261 }
262
263 // Check to see if anyone has submitted login-information and if so register the user with the session. $this->user[uid] may be used to write log...
264 $this->checkAuthentication();
265
266 // Make certain that NO user is set initially. ->check_authentication may have set a session-record which will provide us with a user record in the next section:
267 unset($this->user);
268
269 // re-read user session
270 $this->user = $this->fetchUserSession();
271
272 if ($this->writeDevLog AND is_array($this->user)) t3lib_div::devLog('User session finally read: '.t3lib_div::arrayToLogString($this->user, array($this->userid_column,$this->username_column)), 't3lib_userAuth', -1);
273 if ($this->writeDevLog AND !is_array($this->user)) t3lib_div::devLog('No user session found.', 't3lib_userAuth', 2);
274
275 // Hook for alternative ways of filling the $this->user array (is used by TIMTAW extension)
276 if(is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['postUserLookUp'])) {
277 foreach($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['postUserLookUp'] as $funcName) {
278 $_params = array(
279 'pObj' => &$this,
280 );
281 t3lib_div::callUserFunction($funcName,$_params,$this);
282 }
283 }
284
285 // If any redirection (inclusion of file) then it will happen in this function
286 $this->redirect();
287
288 // Set all posible headers that could ensure that the script is not cached on the client-side
289 if ($this->sendNoCacheHeaders) {
290 header('Expires: 0');
291 header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
292 header('Cache-Control: no-cache, must-revalidate');
293 header('Pragma: no-cache');
294 }
295
296 // If we're lucky we'll get to clean up old sessions....
297 if ((rand()%100) <= $this->gc_probability) {
298 $this->gc();
299 }
300 }
301
302 /**
303 * Checks if a submission of username and password is present or use other authentication by auth services
304 *
305 * @return void
306 * @internal
307 */
308 function checkAuthentication() {
309
310 // No user for now - will be searched by service below
311 $tempuserArr = array();
312 $tempuser = FALSE;
313
314 // User is not authenticated by default
315 $authenticated = FALSE;
316
317 // User want to login with passed login data (name/password)
318 $activeLogin = FALSE;
319
320 // Indicates if an active authentication failed (not auto login)
321 $this->loginFailure = FALSE;
322
323 if ($this->writeDevLog) t3lib_div::devLog('Login type: '.$this->loginType, 't3lib_userAuth');
324
325 // The info array provide additional information for auth services
326 $authInfo = $this->getAuthInfoArray();
327
328 // Get Login/Logout data submitted by a form or params
329 $loginData = $this->getLoginFormData();
330
331 if ($this->writeDevLog) t3lib_div::devLog('Login data: '.t3lib_div::arrayToLogString($loginData), 't3lib_userAuth');
332
333
334 // active logout (eg. with "logout" button)
335 if ($loginData['status']=='logout') {
336 if ($this->writeStdLog) $this->writelog(255,2,0,2,'User %s logged out',Array($this->user['username'])); // Logout written to log
337 if ($this->writeDevLog) t3lib_div::devLog('User logged out. Id: '.$this->id, 't3lib_userAuth', -1);
338
339 $this->logoff();
340 }
341
342 // active login (eg. with login form)
343 if ($loginData['status']=='login') {
344 $activeLogin = TRUE;
345
346 if ($this->writeDevLog) t3lib_div::devLog('Active login (eg. with login form)', 't3lib_userAuth');
347
348 // check referer for submitted login values
349 if($this->formfield_status && $loginData['uident'] && $loginData['uname']) {
350 $httpHost = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY');
351 if (!$this->getMethodEnabled && ($httpHost!=$authInfo['refInfo']['host'] && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer'])) {
352 die('Error: This host address ("'.$httpHost.'") and the referer host ("'.$authInfo['refInfo']['host'].'") mismatches!<br />
353 It\'s possible that the environment variable HTTP_REFERER is not passed to the script because of a proxy.<br />
354 The site administrator can disable this check in the "All Configuration" section of the Install Tool (flag: TYPO3_CONF_VARS[SYS][doNotCheckReferer]).');
355 }
356
357 // delete old user session if any
358 $this->logoff();
359 }
360 }
361
362
363 // the following code makes auto-login possible (if configured). No submitted data needed
364
365 // re-read user session
366 $authInfo['userSession'] = $this->fetchUserSession();
367 $haveSession = is_array($authInfo['userSession']) ? TRUE : FALSE;
368
369 if ($this->writeDevLog AND $haveSession) t3lib_div::devLog('User session found: '.t3lib_div::arrayToLogString($authInfo['userSession'], array($this->userid_column,$this->username_column)), 't3lib_userAuth', 0);
370 if ($this->writeDevLog) t3lib_div::devLog('SV setup: '.t3lib_div::arrayToLogString($this->svConfig['setup']), 't3lib_userAuth', 0);
371
372
373 // fetch user if ...
374 if ( $activeLogin
375 OR (!$haveSession AND $this->svConfig['setup'][$this->loginType.'_fetchUserIfNoSession'])
376 OR $this->svConfig['setup'][$this->loginType.'_alwaysFetchUser']) {
377
378 // use 'auth' service to find the user
379 // first found user will be used
380 $serviceChain = '';
381 $subType = 'getUser'.$this->loginType;
382 while (is_object($serviceObj = t3lib_div::makeInstanceService('auth', $subType, $serviceChain))) {
383 $serviceChain.=','.$serviceObj->getServiceKey();
384 $serviceObj->initAuth($subType, $loginData, $authInfo, $this);
385 if ($row=$serviceObj->getUser()) {
386 $tempuserArr[] = $row;
387
388 if ($this->writeDevLog) t3lib_div::devLog('User found: '.t3lib_div::arrayToLogString($row, array($this->userid_column,$this->username_column)), 't3lib_userAuth', 0);
389
390 // user found, just stop to search for more if not configured to go on
391 if(!$this->svConfig['setup'][$this->loginType.'_fetchAllUsers']) {
392 break;
393 }
394 }
395 unset($serviceObj);
396 }
397 unset($serviceObj);
398
399 if ($this->writeDevLog AND $this->svConfig['setup'][$this->loginType.'_alwaysFetchUser']) t3lib_div::devLog($this->loginType.'_alwaysFetchUser option is enabled', 't3lib_userAuth');
400 if ($this->writeDevLog AND $serviceChain) t3lib_div::devLog($subType.' auth services called: '.$serviceChain, 't3lib_userAuth');
401 if ($this->writeDevLog AND !count($tempuserArr)) t3lib_div::devLog('No user found by services', 't3lib_userAuth');
402 if ($this->writeDevLog AND count($tempuserArr)) t3lib_div::devLog(count($tempuserArr).' user records found by services', 't3lib_userAuth');
403 }
404
405
406 // If no new user was set we use the already found user session
407 if (!count($tempuserArr) AND $haveSession) {
408 $tempuserArr[] = $authInfo['userSession'];
409 $tempuser = $authInfo['userSession'];
410 // User is authenticated because we found a user session
411 $authenticated = TRUE;
412
413 if ($this->writeDevLog) t3lib_div::devLog('User session used: '.t3lib_div::arrayToLogString($authInfo['userSession'], array($this->userid_column,$this->username_column)), 't3lib_userAuth');
414 }
415
416
417 // Re-auth user when 'auth'-service option is set
418 if ($this->svConfig['setup'][$this->loginType.'_alwaysAuthUser']) {
419 $authenticated = FALSE;
420 if ($this->writeDevLog) t3lib_div::devLog('alwaysAuthUser option is enabled', 't3lib_userAuth');
421 }
422
423
424 // Authenticate the user if needed
425 if(count($tempuserArr) AND !$authenticated) {
426
427 foreach($tempuserArr as $tempuser) {
428
429 // use 'auth' service to authenticate the user
430 // if one service returns FALSE then authentication failed
431 // a service might return 100 which means there's no reason to stop but the user can't be authenticated by that service
432
433 if ($this->writeDevLog) t3lib_div::devLog('Auth user: '.t3lib_div::arrayToLogString($tempuser), 't3lib_userAuth');
434
435 $serviceChain='';
436 $subType = 'authUser'.$this->loginType;
437 while (is_object($serviceObj = t3lib_div::makeInstanceService('auth', $subType, $serviceChain))) {
438 $serviceChain.=','.$serviceObj->getServiceKey();
439 $serviceObj->initAuth($subType, $loginData, $authInfo, $this);
440 if (($ret=$serviceObj->authUser($tempuser)) > 0) {
441
442 // if the service returns >=200 then no more checking is needed - useful for IP checking without password
443 if (intval($ret) >= 200) {
444 $authenticated = TRUE;
445 break;
446 } elseif (intval($ret) >= 100) {
447 // Just go on. User is still not authenticated but there's no reason to stop now.
448 } else {
449 $authenticated = TRUE;
450 }
451
452 } else {
453 $authenticated = FALSE;
454 break;
455 }
456 unset($serviceObj);
457 }
458 unset($serviceObj);
459
460 if ($this->writeDevLog AND $serviceChain) t3lib_div::devLog($subType.' auth services called: '.$serviceChain, 't3lib_userAuth');
461
462 if($authenticated) {
463 // leave foreach() because a user is authenticated
464 break;
465 }
466 }
467 }
468
469
470 // If user is authenticated a valid user is in $tempuser
471 if ($authenticated) {
472 // reset failure flag
473 $this->loginFailure = FALSE;
474
475
476 // Insert session record if needed:
477 if (!($haveSession AND (
478 $tempuser['ses_id']==$this->id OR // check if the tempuser has the current session id
479 $tempuser['uid']==$authInfo['userSession']['ses_userid'] // check if the tempuser has the uid of the fetched session user
480 ))) {
481 $this->createUserSession($tempuser);
482
483 // The login session is started.
484 $this->loginSessionStarted = TRUE;
485 }
486
487 // User logged in - write that to the log!
488 if ($this->writeStdLog && $activeLogin) {
489 $this->writelog(255,1,0,1,
490 'User %s logged in from %s (%s)',
491 Array($tempuser[$this->username_column], t3lib_div::getIndpEnv('REMOTE_ADDR'), t3lib_div::getIndpEnv('REMOTE_HOST')));
492 }
493
494 if ($this->writeDevLog && $activeLogin) t3lib_div::devLog('User '.$tempuser[$this->username_column].' logged in from '.t3lib_div::getIndpEnv('REMOTE_ADDR').' ('.t3lib_div::getIndpEnv('REMOTE_HOST').')', 't3lib_userAuth', -1);
495 if ($this->writeDevLog && !$activeLogin) t3lib_div::devLog('User '.$tempuser[$this->username_column].' authenticated from '.t3lib_div::getIndpEnv('REMOTE_ADDR').' ('.t3lib_div::getIndpEnv('REMOTE_HOST').')', 't3lib_userAuth', -1);
496
497
498 } elseif ($activeLogin OR count($tempuserArr)) {
499 $this->loginFailure = TRUE;
500
501 if ($this->writeDevLog AND !count($tempuserArr) AND $activeLogin) t3lib_div::devLog('Login failed: '.t3lib_div::arrayToLogString($loginData), 't3lib_userAuth', 2);
502 if ($this->writeDevLog AND count($tempuserArr)) t3lib_div::devLog('Login failed: '.t3lib_div::arrayToLogString($tempuser, array($this->userid_column,$this->username_column)), 't3lib_userAuth', 2);
503 }
504
505
506 // If there were a login failure, check to see if a warning email should be sent:
507 if ($this->loginFailure AND $activeLogin) {
508 if ($this->writeDevLog) t3lib_div::devLog('Call checkLogFailures: '.t3lib_div::arrayToLogString(array('warningEmail'=>$this->warningEmail,'warningPeriod'=>$this->warningPeriod,'warningMax'=>$this->warningMax,)), 't3lib_userAuth', -1);
509
510 $this->checkLogFailures($this->warningEmail, $this->warningPeriod, $this->warningMax);
511 }
512 }
513
514
515
516
517
518
519
520
521
522
523
524
525 /*************************
526 *
527 * User Sessions
528 *
529 *************************/
530
531
532 /**
533 * Creates a user session record.
534 *
535 * @param array user data array
536 * @return void
537 */
538 function createUserSession ($tempuser) {
539
540 if ($this->writeDevLog) t3lib_div::devLog('Create session ses_id = '.$this->id, 't3lib_userAuth');
541
542 // delete session entry first
543 $GLOBALS['TYPO3_DB']->exec_DELETEquery(
544 $this->session_table,
545 'ses_id = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->id, $this->session_table).'
546 AND ses_name = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->name, $this->session_table)
547 );
548
549 // re-create session entry
550 $insertFields = array(
551 'ses_id' => $this->id,
552 'ses_name' => $this->name,
553 'ses_iplock' => $tempuser['disableIPlock'] ? '[DISABLED]' : $this->ipLockClause_remoteIPNumber($this->lockIP),
554 'ses_hashlock' => $this->hashLockClause_getHashInt(),
555 'ses_userid' => $tempuser[$this->userid_column],
556 'ses_tstamp' => $GLOBALS['EXEC_TIME']
557 );
558 $GLOBALS['TYPO3_DB']->exec_INSERTquery($this->session_table, $insertFields);
559
560 // Updating lastLogin_column carrying information about last login.
561 if ($this->lastLogin_column) {
562 $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
563 $this->user_table,
564 $this->userid_column.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($tempuser[$this->userid_column], $this->user_table),
565 array($this->lastLogin_column => $GLOBALS['EXEC_TIME'])
566 );
567 }
568 }
569
570 /**
571 * Read the user session from db.
572 *
573 * @return array user session data
574 */
575 function fetchUserSession() {
576
577 $user = '';
578
579 if ($this->writeDevLog) t3lib_div::devLog('Fetch session ses_id = '.$this->id, 't3lib_userAuth');
580
581 // The session_id is used to find user in the database. Two tables are joined: The session-table with user_id of the session and the usertable with its primary key
582 $dbres = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
583 '*',
584 $this->session_table.','.$this->user_table,
585 $this->session_table.'.ses_id = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->id, $this->session_table).'
586 AND '.$this->session_table.'.ses_name = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->name, $this->session_table).'
587 AND '.$this->session_table.'.ses_userid = '.$this->user_table.'.'.$this->userid_column.'
588 '.$this->ipLockClause().'
589 '.$this->hashLockClause().'
590 '.$this->user_where_clause()
591 );
592
593
594 if ($user = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($dbres)) {
595 // A user was found
596 if (is_string($this->auth_timeout_field)) {
597 $timeout = intval($user[$this->auth_timeout_field]); // Get timeout-time from usertable
598 } else {
599 $timeout = intval($this->auth_timeout_field); // Get timeout from object
600 }
601 // If timeout > 0 (true) and currenttime has not exceeded the latest sessions-time plus the timeout in seconds then accept user
602 // Option later on: We could check that last update was at least x seconds ago in order not to update twice in a row if one script redirects to another...
603 if ($timeout>0 && ($GLOBALS['EXEC_TIME'] < ($user['ses_tstamp']+$timeout))) {
604 $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
605 $this->session_table,
606 'ses_id='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->id, $this->session_table).'
607 AND ses_name='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->name, $this->session_table),
608 array('ses_tstamp' => $GLOBALS['EXEC_TIME'])
609 );
610 $user['ses_tstamp'] = $GLOBALS['EXEC_TIME']; // Make sure that the timestamp is also updated in the array
611 } else {
612 $this->logoff(); // delete any user set...
613 }
614 } else {
615 $this->logoff(); // delete any user set...
616 }
617 return $user;
618 }
619
620 /**
621 * Log out current user!
622 * Removes the current session record, sets the internal ->user array to a blank string; Thereby the current user (if any) is effectively logged out!
623 *
624 * @return void
625 */
626 function logoff() {
627 if ($this->writeDevLog) t3lib_div::devLog('logoff: ses_id = '.$this->id, 't3lib_userAuth');
628
629 $GLOBALS['TYPO3_DB']->exec_DELETEquery(
630 $this->session_table,
631 'ses_id = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->id, $this->session_table).'
632 AND ses_name = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->name, $this->session_table)
633 );
634
635 $this->user = '';
636 }
637
638
639
640
641
642
643
644
645
646
647
648
649
650 /*************************
651 *
652 * SQL Functions
653 *
654 *************************/
655
656 /**
657 * This returns the where-clause needed to select the user with respect flags like deleted, hidden, starttime, endtime
658 *
659 * @return string
660 * @access private
661 */
662 function user_where_clause() {
663 return (($this->enablecolumns['rootLevel']) ? 'AND '.$this->user_table.'.pid=0 ' : '').
664 (($this->enablecolumns['disabled']) ? ' AND '.$this->user_table.'.'.$this->enablecolumns['disabled'].'=0' : '').
665 (($this->enablecolumns['deleted']) ? ' AND '.$this->user_table.'.'.$this->enablecolumns['deleted'].'=0' : '').
666 (($this->enablecolumns['starttime']) ? ' AND ('.$this->user_table.'.'.$this->enablecolumns['starttime'].'<='.time().')' : '').
667 (($this->enablecolumns['endtime']) ? ' AND ('.$this->user_table.'.'.$this->enablecolumns['endtime'].'=0 OR '.$this->user_table.'.'.$this->enablecolumns['endtime'].'>'.time().')' : '');
668 }
669
670 /**
671 * This returns the where-clause needed to lock a user to the IP address
672 *
673 * @return string
674 * @access private
675 */
676 function ipLockClause() {
677 if ($this->lockIP) {
678 $wherePart = 'AND (
679 '.$this->session_table.'.ses_iplock='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->ipLockClause_remoteIPNumber($this->lockIP),$this->session_table).'
680 OR '.$this->session_table.'.ses_iplock=\'[DISABLED]\'
681 )';
682 return $wherePart;
683 }
684 }
685
686 /**
687 * Returns the IP address to lock to.
688 * The IP address may be partial based on $parts.
689 *
690 * @param integer 1-4: Indicates how many parts of the IP address to return. 4 means all, 1 means only first number.
691 * @return string (Partial) IP address for REMOTE_ADDR
692 * @access private
693 */
694 function ipLockClause_remoteIPNumber($parts) {
695 $IP = t3lib_div::getIndpEnv('REMOTE_ADDR');
696
697 if ($parts>=4) {
698 return $IP;
699 } else {
700 $parts = t3lib_div::intInRange($parts,1,3);
701 $IPparts = explode('.',$IP);
702 for($a=4;$a>$parts;$a--) {
703 unset($IPparts[$a-1]);
704 }
705 return implode('.',$IPparts);
706 }
707 }
708
709 /**
710 * This returns the where-clause needed to lock a user to a hash integer
711 *
712 * @return string
713 * @access private
714 */
715 function hashLockClause() {
716 $wherePart = 'AND '.$this->session_table.'.ses_hashlock='.intval($this->hashLockClause_getHashInt());
717 return $wherePart;
718 }
719
720 /**
721 * Creates hash integer to lock user to. Depends on configured keywords
722 *
723 * @return integer Hash integer
724 * @access private
725 */
726 function hashLockClause_getHashInt() {
727 $hashStr = '';
728
729 if (t3lib_div::inList($this->lockHashKeyWords,'useragent')) $hashStr.=':'.t3lib_div::getIndpEnv('HTTP_USER_AGENT');
730
731 return t3lib_div::md5int($hashStr);
732 }
733
734
735
736
737
738
739
740
741
742
743
744 /*************************
745 *
746 * Session and Configuration Handling
747 *
748 *************************/
749
750 /**
751 * This writes $variable to the user-record. This is a way of providing session-data.
752 * You can fetch the data again through $this->uc in this class!
753 * If $variable is not an array, $this->uc is saved!
754 *
755 * @param array An array you want to store for the user as session data. If $variable is not supplied (is blank string), the internal variable, ->uc, is stored by default
756 * @return void
757 */
758 function writeUC($variable='') {
759 if (is_array($this->user) && $this->user[$this->userid_column]) {
760 if (!is_array($variable)) { $variable = $this->uc; }
761
762 if ($this->writeDevLog) t3lib_div::devLog('writeUC: '.$this->userid_column.'='.intval($this->user[$this->userid_column]), 't3lib_userAuth');
763 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($this->user_table, $this->userid_column.'='.intval($this->user[$this->userid_column]), array('uc' => serialize($variable)));
764 }
765 }
766
767 /**
768 * Sets $theUC as the internal variable ->uc IF $theUC is an array. If $theUC is false, the 'uc' content from the ->user array will be unserialized and restored in ->uc
769 *
770 * @param mixed If an array, then set as ->uc, otherwise load from user record
771 * @return void
772 */
773 function unpack_uc($theUC='') {
774 if (!$theUC) $theUC=unserialize($this->user['uc']);
775 if (is_array($theUC)) {
776 $this->uc=$theUC;
777 }
778 }
779
780 /**
781 * Stores data for a module.
782 * The data is stored with the session id so you can even check upon retrieval if the module data is from a previous session or from the current session.
783 *
784 * @param string $module is the name of the module ($MCONF['name'])
785 * @param mixed $data is the data you want to store for that module (array, string, ...)
786 * @param boolean If $noSave is set, then the ->uc array (which carries all kinds of user data) is NOT written immediately, but must be written by some subsequent call.
787 * @return void
788 */
789 function pushModuleData($module,$data,$noSave=0) {
790 $this->uc['moduleData'][$module] = $data;
791 $this->uc['moduleSessionID'][$module] = $this->id;
792 if (!$noSave) $this->writeUC();
793 }
794
795 /**
796 * Gets module data for a module (from a loaded ->uc array)
797 *
798 * @param string $module is the name of the module ($MCONF['name'])
799 * @param string If $type = 'ses' then module data is returned only if it was stored in the current session, otherwise data from a previous session will be returned (if available).
800 * @return mixed The module data if available: $this->uc['moduleData'][$module];
801 */
802 function getModuleData($module,$type='') {
803 if ($type!='ses' || $this->uc['moduleSessionID'][$module]==$this->id) {
804 return $this->uc['moduleData'][$module];
805 }
806 }
807
808 /**
809 * Returns the session data stored for $key.
810 * The data will last only for this login session since it is stored in the session table.
811 *
812 * @param string Pointer to an associative key in the session data array which is stored serialized in the field "ses_data" of the session table.
813 * @return mixed
814 */
815 function getSessionData($key) {
816 $sesDat = unserialize($this->user['ses_data']);
817 return $sesDat[$key];
818 }
819
820 /**
821 * Sets the session data ($data) for $key and writes all session data (from ->user['ses_data']) to the database.
822 * The data will last only for this login session since it is stored in the session table.
823 *
824 * @param string Pointer to an associative key in the session data array which is stored serialized in the field "ses_data" of the session table.
825 * @param mixed The variable to store in index $key
826 * @return void
827 */
828 function setAndSaveSessionData($key,$data) {
829 $sesDat = unserialize($this->user['ses_data']);
830 $sesDat[$key] = $data;
831 $this->user['ses_data'] = serialize($sesDat);
832
833 if ($this->writeDevLog) t3lib_div::devLog('setAndSaveSessionData: ses_id = '.$this->user['ses_id'], 't3lib_userAuth');
834 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($this->session_table, 'ses_id='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->user['ses_id'], $this->session_table), array('ses_data' => $this->user['ses_data']));
835 }
836
837
838
839
840
841
842
843
844
845
846
847
848
849 /*************************
850 *
851 * Misc
852 *
853 *************************/
854
855 /**
856 * Returns an info array with Login/Logout data submitted by a form or params
857 *
858 * @return array
859 * @internal
860 */
861 function getLoginFormData() {
862 $loginData=array();
863 if ($this->getMethodEnabled) {
864 $loginData['status'] = t3lib_div::_GP($this->formfield_status);
865 $loginData['uname'] = t3lib_div::_GP($this->formfield_uname);
866 $loginData['uident'] = t3lib_div::_GP($this->formfield_uident);
867 $loginData['chalvalue'] = t3lib_div::_GP($this->formfield_chalvalue);
868 } else {
869 $loginData['status'] = t3lib_div::_POST($this->formfield_status);
870 $loginData['uname'] = t3lib_div::_POST($this->formfield_uname);
871 $loginData['uident'] = t3lib_div::_POST($this->formfield_uident);
872 $loginData['chalvalue'] = t3lib_div::_POST($this->formfield_chalvalue);
873 }
874 $loginData = $this->processLoginData($loginData);
875
876 return $loginData;
877 }
878
879 /**
880 * Processes Login data submitted by a form or params depending on the
881 * security_level
882 *
883 * @param array login data array
884 * @param string Alternative security_level. Used when authentication services wants to override the default.
885 * @return array processed login data array
886 * @internal
887 */
888 function processLoginData($loginData, $security_level='') {
889 global $TYPO3_CONF_VARS;
890
891 $loginSecurityLevel = $security_level ? $security_level : ($TYPO3_CONF_VARS[$this->loginType]['loginSecurityLevel'] ? $TYPO3_CONF_VARS[$this->loginType]['loginSecurityLevel'] : $this->security_level);
892
893 // Processing data according to the state it was submitted in.
894 // ($loginSecurityLevel should reflect the security level used on the data being submitted in the login form)
895 if ($loginSecurityLevel=='normal') {
896 $loginData['uident_text'] = $loginData['uident'];
897 $loginData['uident_challenged'] = (string)md5($loginData['uname'].':'.$loginData['uident'].':'.$loginData['chalvalue']);
898 $loginData['uident_superchallenged'] = (string)md5($loginData['uname'].':'.(md5($loginData['uident'])).':'.$loginData['chalvalue']);
899 } elseif ($loginSecurityLevel=='challenged') {
900 $loginData['uident_text'] = '';
901 $loginData['uident_challenged'] = $loginData['uident'];
902 $loginData['uident_superchallenged'] = '';
903 } elseif ($loginSecurityLevel=='superchallenged') {
904 $loginData['uident_text'] = '';
905 $loginData['uident_challenged'] = '';
906 $loginData['uident_superchallenged'] = $loginData['uident'];
907 }
908
909 // The password "uident" is set based on the internal security setting of TYPO3
910 // Example:
911 // $this->security_level for the backend must be "superchallenged" because passwords are stored as md5-hashes in the be_users table
912 // $this->security_level for the frontend must be "normal" or "challenged" because passwords are stored as clear-text in the fe_users tables
913 if ($this->security_level=='normal') {
914 $loginData['uident'] = $loginData['uident_text'];
915 } elseif ($this->security_level=='challenged') {
916 $loginData['uident'] = $loginData['uident_challenged'];
917 } elseif ($this->security_level=='superchallenged') {
918 $loginData['uident'] = $loginData['uident_superchallenged'];
919 }
920
921 return $loginData;
922 }
923
924 /**
925 * Returns an info array which provides additional information for auth services
926 *
927 * @return array
928 * @internal
929 */
930 function getAuthInfoArray() {
931 $authInfo = array();
932 $authInfo['loginType'] = $this->loginType;
933 $authInfo['refInfo'] = parse_url(t3lib_div::getIndpEnv('HTTP_REFERER'));
934 $authInfo['HTTP_HOST'] = t3lib_div::getIndpEnv('HTTP_HOST');
935 $authInfo['REMOTE_ADDR'] = t3lib_div::getIndpEnv('REMOTE_ADDR');
936 $authInfo['REMOTE_HOST'] = t3lib_div::getIndpEnv('REMOTE_HOST');
937 $authInfo['security_level'] = $this->security_level;
938 $authInfo['showHiddenRecords'] = $this->showHiddenRecords;
939 // can be overidden in localconf by SVCONF:
940 $authInfo['db_user']['table'] = $this->user_table;
941 $authInfo['db_user']['userid_column'] = $this->userid_column;
942 $authInfo['db_user']['username_column'] = $this->username_column;
943 $authInfo['db_user']['userident_column'] = $this->userident_column;
944 $authInfo['db_user']['usergroup_column'] = $this->usergroup_column;
945 $authInfo['db_user']['enable_clause'] = $this->user_where_clause();
946 $authInfo['db_user']['checkPidList'] = $this->checkPid ? $this->checkPid_value : '';
947 $authInfo['db_user']['check_pid_clause'] = $this->checkPid ? ' AND pid IN ('.$GLOBALS['TYPO3_DB']->cleanIntList($authInfo['db_user']['checkPidList']).')' : '';
948 $authInfo['db_groups']['table'] = $this->usergroup_table;
949 return $authInfo;
950 }
951
952 /**
953 * Check the login data with the user record data for builtin login methods
954 *
955 * @param array user data array
956 * @param array login data array
957 * @param string Alternative security_level. Used when authentication services wants to override the default.
958 * @return boolean true if login data matched
959 */
960 function compareUident($user, $loginData, $security_level='') {
961
962 $OK = FALSE;
963 $security_level = $security_level ? $security_level : $this->security_level;
964
965 switch ($security_level) {
966 case 'superchallenged': // If superchallenged the password in the database ($user[$this->userident_column]) must be a md5-hash of the original password.
967 case 'challenged':
968
969 // Check challenge stored in cookie:
970 if ($this->challengeStoredInCookie) {
971 session_start();
972 if ($_SESSION['login_challenge'] !== $loginData['chalvalue']) {
973 if ($this->writeDevLog) t3lib_div::devLog('PHP Session stored challenge "'.$_SESSION['login_challenge'].'" and submitted challenge "'.$loginData['chalvalue'].'" did not match, so authentication failed!', 't3lib_userAuth', 2);
974 $this->logoff();
975 return FALSE;
976 }
977 }
978
979 if ((string)$loginData['uident'] === (string)md5($user[$this->username_column].':'.$user[$this->userident_column].':'.$loginData['chalvalue'])) {
980 $OK = TRUE;
981 };
982 break;
983 default: // normal
984 if ((string)$loginData['uident'] === (string)$user[$this->userident_column]) {
985 $OK = TRUE;
986 };
987 break;
988 }
989
990 return $OK;
991 }
992
993 /**
994 * Garbage collector, removing old expired sessions.
995 *
996 * @return void
997 * @internal
998 */
999 function gc() {
1000 $GLOBALS['TYPO3_DB']->exec_DELETEquery(
1001 $this->session_table,
1002 'ses_tstamp < '.intval(time()-($this->gc_time*60*60)).'
1003 AND ses_name = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->name, $this->session_table)
1004 );
1005 }
1006
1007 /**
1008 * Redirect to somewhere. Obsolete, depreciated etc.
1009 *
1010 * @return void
1011 * @ignore
1012 */
1013 function redirect() {
1014 if (!$this->userid && $this->auth_url) { // if no userid AND an include-document for login is given
1015 include ($this->auth_include);
1016 exit;
1017 }
1018 }
1019
1020 /**
1021 * DUMMY: Writes to log database table (in some extension classes)
1022 *
1023 * @param integer $type: denotes which module that has submitted the entry. This is the current list: 1=tce_db; 2=tce_file; 3=system (eg. sys_history save); 4=modules; 254=Personal settings changed; 255=login / out action: 1=login, 2=logout, 3=failed login (+ errorcode 3), 4=failure_warning_email sent
1024 * @param integer $action: denotes which specific operation that wrote the entry (eg. 'delete', 'upload', 'update' and so on...). Specific for each $type. Also used to trigger update of the interface. (see the log-module for the meaning of each number !!)
1025 * @param integer $error: flag. 0 = message, 1 = error (user problem), 2 = System Error (which should not happen), 3 = security notice (admin)
1026 * @param integer $details_nr: The message number. Specific for each $type and $action. in the future this will make it possible to translate errormessages to other languages
1027 * @param string $details: Default text that follows the message
1028 * @param array $data: Data that follows the log. Might be used to carry special information. If an array the first 5 entries (0-4) will be sprintf'ed the details-text...
1029 * @param string $tablename: Special field used by tce_main.php. These ($tablename, $recuid, $recpid) holds the reference to the record which the log-entry is about. (Was used in attic status.php to update the interface.)
1030 * @param integer $recuid: Special field used by tce_main.php. These ($tablename, $recuid, $recpid) holds the reference to the record which the log-entry is about. (Was used in attic status.php to update the interface.)
1031 * @param integer $recpid: Special field used by tce_main.php. These ($tablename, $recuid, $recpid) holds the reference to the record which the log-entry is about. (Was used in attic status.php to update the interface.)
1032 * @return void
1033 * @see t3lib_userauthgroup::writelog()
1034 */
1035 function writelog($type,$action,$error,$details_nr,$details,$data,$tablename,$recuid,$recpid) {
1036 }
1037
1038 /**
1039 * DUMMY: Check login failures (in some extension classes)
1040 *
1041 * @return void
1042 * @ignore
1043 */
1044 function checkLogFailures() {
1045 }
1046
1047 /**
1048 * Raw initialization of the be_user with uid=$uid
1049 * This will circumvent all login procedures and select a be_users record from the database and set the content of ->user to the record selected. Thus the BE_USER object will appear like if a user was authenticated - however without a session id and the fields from the session table of course.
1050 * Will check the users for disabled, start/endtime, etc. ($this->user_where_clause())
1051 *
1052 * @param integer The UID of the backend user to set in ->user
1053 * @return void
1054 * @internal
1055 * @see SC_mod_tools_be_user_index::compareUsers(), SC_mod_user_setup_index::simulateUser(), freesite_admin::startCreate()
1056 */
1057 function setBeUserByUid($uid) {
1058 $this->user = $this->getRawUserByUid($uid);
1059 }
1060
1061 /**
1062 * Raw initialization of the be_user with username=$name
1063 *
1064 * @param string The username to look up.
1065 * @return void
1066 * @see t3lib_userAuth::setBeUserByUid()
1067 * @internal
1068 */
1069 function setBeUserByName($name) {
1070 $this->user = $this->getRawUserByName($name);
1071 }
1072
1073 /**
1074 * Fetching raw user record with uid=$uid
1075 *
1076 * @param integer The UID of the backend user to set in ->user
1077 * @return array user record or FALSE
1078 * @internal
1079 */
1080 function getRawUserByUid($uid) {
1081 $user = FALSE;
1082 $dbres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->user_table, 'uid='.intval($uid).' '.$this->user_where_clause());
1083 if ($dbres) {
1084 $user = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($dbres);
1085 $GLOBALS['TYPO3_DB']->sql_free_result($dbres);
1086 }
1087 return $user;
1088 }
1089
1090 /**
1091 * Fetching raw user record with username=$name
1092 *
1093 * @param string The username to look up.
1094 * @return array user record or FALSE
1095 * @see t3lib_userAuth::getUserByUid()
1096 * @internal
1097 */
1098 function getRawUserByName($name) {
1099 $user = FALSE;
1100 $dbres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->user_table, 'username='.$GLOBALS['TYPO3_DB']->fullQuoteStr($name, $this->user_table).' '.$this->user_where_clause());
1101 if ($dbres) {
1102 $user = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($dbres);
1103 $GLOBALS['TYPO3_DB']->sql_free_result($dbres);
1104 }
1105 return $user;
1106 }
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122 /*************************
1123 *
1124 * Create/update user - EXPERIMENTAL
1125 *
1126 *************************/
1127
1128 /**
1129 * Get a user from DB by username
1130 * provided for usage from services
1131 *
1132 * @param array User db table definition: $this->db_user
1133 * @param string user name
1134 * @param string additional WHERE clause: " AND ...
1135 * @return mixed user array or FALSE
1136 */
1137 function fetchUserRecord($dbUser, $username, $extraWhere='' ) {
1138 $user = FALSE;
1139
1140 $usernameClause = $username ? ($dbUser['username_column'].'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($username, $dbUser['table'])) : '';
1141
1142 if ($username OR $extraWhere) {
1143
1144 // Look up the user by the username and/or extraWhere:
1145 $dbres = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
1146 '*',
1147 $dbUser['table'],
1148 $usernameClause.
1149 $dbUser['check_pid_clause'].
1150 $dbUser['enable_clause'].
1151 $extraWhere
1152 );
1153
1154 if ($dbres) {
1155 $user = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($dbres);
1156 $GLOBALS['TYPO3_DB']->sql_free_result($dbres);
1157 }
1158 }
1159 return $user;
1160 }
1161 }
1162
1163
1164
1165 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_userauth.php']) {
1166 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_userauth.php']);
1167 }
1168 ?>