1dae29784539791959480f831bb9fa1c88c8aff9
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_userauth.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2006 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 * 195: function start()
43 * 329: function checkAuthentication()
44 *
45 * SECTION: User Sessions
46 * 569: function createUserSession ($tempuser)
47 * 606: function fetchUserSession()
48 * 657: function logoff()
49 *
50 * SECTION: SQL Functions
51 * 713: function user_where_clause()
52 * 727: function ipLockClause()
53 * 745: function ipLockClause_remoteIPNumber($parts)
54 * 766: function hashLockClause()
55 * 777: function hashLockClause_getHashInt()
56 *
57 * SECTION: Session and Configuration Handling
58 * 809: function writeUC($variable='')
59 * 824: function unpack_uc($theUC='')
60 * 840: function pushModuleData($module,$data,$noSave=0)
61 * 853: function getModuleData($module,$type='')
62 * 866: function getSessionData($key)
63 * 879: function setAndSaveSessionData($key,$data)
64 *
65 * SECTION: Misc
66 * 912: function getLoginFormData()
67 * 939: function processLoginData($loginData, $security_level='')
68 * 981: function getAuthInfoArray()
69 * 1011: function compareUident($user, $loginData, $security_level='')
70 * 1050: function gc()
71 * 1064: function redirect()
72 * 1086: function writelog($type,$action,$error,$details_nr,$details,$data,$tablename,$recuid,$recpid)
73 * 1095: function checkLogFailures()
74 * 1108: function setBeUserByUid($uid)
75 * 1120: function setBeUserByName($name)
76 * 1131: function getRawUserByUid($uid)
77 * 1149: function getRawUserByName($name)
78 *
79 * SECTION: Create/update user - EXPERIMENTAL
80 * 1188: 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; // Server session lifetime. If > 0: session-timeout in seconds. If false or <0: no timeout. If string: The string is a fieldname from the usertable where the timeout can be found.
140 var $lifetime = 0; // Client session lifetime. 0 = Session-cookies. If session-cookies, the browser will stop the session when the browser is closed. Otherwise this specifies the lifetime of a cookie that keeps the session.
141 var $gc_time = 0; // GarbageCollection. Purge all server session data older than $gc_time seconds. 0 = default to $this->timeout or use 86400 seconds (1 day) if $this->lifetime is 0
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 ($TYPO3_CONF_VARS['SYS']['cookieDomain']) {
248 if ($TYPO3_CONF_VARS['SYS']['cookieDomain']{0} == '/') {
249 $matchCnt = @preg_match($TYPO3_CONF_VARS['SYS']['cookieDomain'], t3lib_div::getIndpEnv('TYPO3_HOST_ONLY'), $match);
250 if ($matchCnt === FALSE) {
251 t3lib_div::sysLog('The regular expression of $TYPO3_CONF_VARS[SYS][cookieDomain] contains errors. The session is not shared across sub-domains.', 'Core', 3);
252 } elseif ($matchCnt) {
253 $cookieDomain = $match[0];
254 }
255 } else {
256 $cookieDomain = $TYPO3_CONF_VARS['SYS']['cookieDomain'];
257 }
258 }
259
260 // If new session and the cookie is a sessioncookie, we need to set it only once!
261 if (($this->newSessionID || $this->forceSetCookie) && $this->lifetime==0 ) {
262 if (!$this->dontSetCookie) {
263 if ($cookieDomain) {
264 SetCookie($this->name, $id, 0, '/', $cookieDomain);
265 } else {
266 SetCookie($this->name, $id, 0, '/');
267 }
268 if ($this->writeDevLog) t3lib_div::devLog('Set new Cookie: '.$id.($cookieDomain ? ', '.$cookieDomain : ''), 't3lib_userAuth');
269 }
270 }
271
272 // If it is NOT a session-cookie, we need to refresh it.
273 if ($this->lifetime > 0) {
274 if (!$this->dontSetCookie) {
275 if ($cookieDomain) {
276 SetCookie($this->name, $id, time()+$this->lifetime, '/', $cookieDomain);
277 } else {
278 SetCookie($this->name, $id, time()+$this->lifetime, '/');
279 }
280 if ($this->writeDevLog) t3lib_div::devLog('Update Cookie: '.$id.($cookieDomain ? ', '.$cookieDomain : ''), 't3lib_userAuth');
281 }
282 }
283
284 // 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...
285 $this->checkAuthentication();
286
287 // 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:
288 unset($this->user);
289
290 // re-read user session
291 $this->user = $this->fetchUserSession();
292
293 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);
294 if ($this->writeDevLog AND !is_array($this->user)) t3lib_div::devLog('No user session found.', 't3lib_userAuth', 2);
295
296 // Hook for alternative ways of filling the $this->user array (is used by the "timtaw" extension)
297 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['postUserLookUp'])) {
298 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['postUserLookUp'] as $funcName) {
299 $_params = array(
300 'pObj' => &$this,
301 );
302 t3lib_div::callUserFunction($funcName,$_params,$this);
303 }
304 }
305
306 // If any redirection (inclusion of file) then it will happen in this function
307 $this->redirect();
308
309 // Set all posible headers that could ensure that the script is not cached on the client-side
310 if ($this->sendNoCacheHeaders) {
311 header('Expires: 0');
312 header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
313 header('Cache-Control: no-cache, must-revalidate');
314 header('Pragma: no-cache');
315 }
316
317 // Set $this->gc_time if not explicitely specified
318 if ($this->gc_time==0) {
319 $this->gc_time = ($this->auth_timeout_field==0 ? 86400 : $this->auth_timeout_field); // Default to 1 day if $this->auth_timeout_field is 0
320 }
321
322 // If we're lucky we'll get to clean up old sessions....
323 if ((rand()%100) <= $this->gc_probability) {
324 $this->gc();
325 }
326 }
327
328 /**
329 * Checks if a submission of username and password is present or use other authentication by auth services
330 *
331 * @return void
332 * @internal
333 */
334 function checkAuthentication() {
335
336 // No user for now - will be searched by service below
337 $tempuserArr = array();
338 $tempuser = FALSE;
339
340 // User is not authenticated by default
341 $authenticated = FALSE;
342
343 // User want to login with passed login data (name/password)
344 $activeLogin = FALSE;
345
346 // Indicates if an active authentication failed (not auto login)
347 $this->loginFailure = FALSE;
348
349 if ($this->writeDevLog) t3lib_div::devLog('Login type: '.$this->loginType, 't3lib_userAuth');
350
351 // The info array provide additional information for auth services
352 $authInfo = $this->getAuthInfoArray();
353
354 // Get Login/Logout data submitted by a form or params
355 $loginData = $this->getLoginFormData();
356
357 if ($this->writeDevLog) t3lib_div::devLog('Login data: '.t3lib_div::arrayToLogString($loginData), 't3lib_userAuth');
358
359
360 // active logout (eg. with "logout" button)
361 if ($loginData['status']=='logout') {
362 if ($this->writeStdLog) $this->writelog(255,2,0,2,'User %s logged out',Array($this->user['username'])); // Logout written to log
363 if ($this->writeDevLog) t3lib_div::devLog('User logged out. Id: '.$this->id, 't3lib_userAuth', -1);
364
365 $this->logoff();
366 }
367
368 // active login (eg. with login form)
369 if ($loginData['status']=='login') {
370 $activeLogin = TRUE;
371
372 if ($this->writeDevLog) t3lib_div::devLog('Active login (eg. with login form)', 't3lib_userAuth');
373
374 // check referer for submitted login values
375 if($this->formfield_status && $loginData['uident'] && $loginData['uname']) {
376 $httpHost = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY');
377 if (!$this->getMethodEnabled && ($httpHost!=$authInfo['refInfo']['host'] && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer'])) {
378 die('Error: This host address ("'.$httpHost.'") and the referer host ("'.$authInfo['refInfo']['host'].'") mismatches!<br />
379 It\'s possible that the environment variable HTTP_REFERER is not passed to the script because of a proxy.<br />
380 The site administrator can disable this check in the "All Configuration" section of the Install Tool (flag: TYPO3_CONF_VARS[SYS][doNotCheckReferer]).');
381 }
382
383 // delete old user session if any
384 $this->logoff();
385 }
386 }
387
388
389 // the following code makes auto-login possible (if configured). No submitted data needed
390
391 // re-read user session
392 $authInfo['userSession'] = $this->fetchUserSession();
393 $haveSession = is_array($authInfo['userSession']) ? TRUE : FALSE;
394
395 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);
396 if ($this->writeDevLog) t3lib_div::devLog('SV setup: '.t3lib_div::arrayToLogString($this->svConfig['setup']), 't3lib_userAuth', 0);
397
398
399 // fetch user if ...
400 if ( $activeLogin
401 OR (!$haveSession AND $this->svConfig['setup'][$this->loginType.'_fetchUserIfNoSession'])
402 OR $this->svConfig['setup'][$this->loginType.'_alwaysFetchUser']) {
403
404 // use 'auth' service to find the user
405 // first found user will be used
406 $serviceChain = '';
407 $subType = 'getUser'.$this->loginType;
408 while (is_object($serviceObj = t3lib_div::makeInstanceService('auth', $subType, $serviceChain))) {
409 $serviceChain.=','.$serviceObj->getServiceKey();
410 $serviceObj->initAuth($subType, $loginData, $authInfo, $this);
411 if ($row=$serviceObj->getUser()) {
412 $tempuserArr[] = $row;
413
414 if ($this->writeDevLog) t3lib_div::devLog('User found: '.t3lib_div::arrayToLogString($row, array($this->userid_column,$this->username_column)), 't3lib_userAuth', 0);
415
416 // user found, just stop to search for more if not configured to go on
417 if(!$this->svConfig['setup'][$this->loginType.'_fetchAllUsers']) {
418 break;
419 }
420 }
421 unset($serviceObj);
422 }
423 unset($serviceObj);
424
425 if ($this->writeDevLog AND $this->svConfig['setup'][$this->loginType.'_alwaysFetchUser']) t3lib_div::devLog($this->loginType.'_alwaysFetchUser option is enabled', 't3lib_userAuth');
426 if ($this->writeDevLog AND $serviceChain) t3lib_div::devLog($subType.' auth services called: '.$serviceChain, 't3lib_userAuth');
427 if ($this->writeDevLog AND !count($tempuserArr)) t3lib_div::devLog('No user found by services', 't3lib_userAuth');
428 if ($this->writeDevLog AND count($tempuserArr)) t3lib_div::devLog(count($tempuserArr).' user records found by services', 't3lib_userAuth');
429 }
430
431
432 // If no new user was set we use the already found user session
433 if (!count($tempuserArr) AND $haveSession) {
434 $tempuserArr[] = $authInfo['userSession'];
435 $tempuser = $authInfo['userSession'];
436 // User is authenticated because we found a user session
437 $authenticated = TRUE;
438
439 if ($this->writeDevLog) t3lib_div::devLog('User session used: '.t3lib_div::arrayToLogString($authInfo['userSession'], array($this->userid_column,$this->username_column)), 't3lib_userAuth');
440 }
441
442
443 // Re-auth user when 'auth'-service option is set
444 if ($this->svConfig['setup'][$this->loginType.'_alwaysAuthUser']) {
445 $authenticated = FALSE;
446 if ($this->writeDevLog) t3lib_div::devLog('alwaysAuthUser option is enabled', 't3lib_userAuth');
447 }
448
449
450 // Authenticate the user if needed
451 if(count($tempuserArr) AND !$authenticated) {
452
453 foreach($tempuserArr as $tempuser) {
454
455 // use 'auth' service to authenticate the user
456 // if one service returns FALSE then authentication failed
457 // a service might return 100 which means there's no reason to stop but the user can't be authenticated by that service
458
459 if ($this->writeDevLog) t3lib_div::devLog('Auth user: '.t3lib_div::arrayToLogString($tempuser), 't3lib_userAuth');
460
461 $serviceChain='';
462 $subType = 'authUser'.$this->loginType;
463 while (is_object($serviceObj = t3lib_div::makeInstanceService('auth', $subType, $serviceChain))) {
464 $serviceChain.=','.$serviceObj->getServiceKey();
465 $serviceObj->initAuth($subType, $loginData, $authInfo, $this);
466 if (($ret=$serviceObj->authUser($tempuser)) > 0) {
467
468 // if the service returns >=200 then no more checking is needed - useful for IP checking without password
469 if (intval($ret) >= 200) {
470 $authenticated = TRUE;
471 break;
472 } elseif (intval($ret) >= 100) {
473 // Just go on. User is still not authenticated but there's no reason to stop now.
474 } else {
475 $authenticated = TRUE;
476 }
477
478 } else {
479 $authenticated = FALSE;
480 break;
481 }
482 unset($serviceObj);
483 }
484 unset($serviceObj);
485
486 if ($this->writeDevLog AND $serviceChain) t3lib_div::devLog($subType.' auth services called: '.$serviceChain, 't3lib_userAuth');
487
488 if($authenticated) {
489 // leave foreach() because a user is authenticated
490 break;
491 }
492 }
493 }
494
495
496 // If user is authenticated a valid user is in $tempuser
497 if ($authenticated) {
498 // reset failure flag
499 $this->loginFailure = FALSE;
500
501
502 // Insert session record if needed:
503 if (!($haveSession AND (
504 $tempuser['ses_id']==$this->id OR // check if the tempuser has the current session id
505 $tempuser['uid']==$authInfo['userSession']['ses_userid'] // check if the tempuser has the uid of the fetched session user
506 ))) {
507 $this->createUserSession($tempuser);
508
509 // The login session is started.
510 $this->loginSessionStarted = TRUE;
511 }
512
513 // User logged in - write that to the log!
514 if ($this->writeStdLog && $activeLogin) {
515 $this->writelog(255,1,0,1,
516 'User %s logged in from %s (%s)',
517 Array($tempuser[$this->username_column], t3lib_div::getIndpEnv('REMOTE_ADDR'), t3lib_div::getIndpEnv('REMOTE_HOST')),
518 '','','',-1,'',$tempuser['uid']
519 );
520 }
521
522 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);
523 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);
524
525 if($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'] == 3 && $this->user_table == 'be_users') {
526 $requestStr = substr(t3lib_div::getIndpEnv('TYPO3_REQUEST_SCRIPT'), strlen(t3lib_div::getIndpEnv('TYPO3_SITE_URL').TYPO3_mainDir));
527 if($requestStr == 'alt_main.php' && t3lib_div::getIndpEnv('TYPO3_SSL')) {
528 list(,$url) = explode('://',t3lib_div::getIndpEnv('TYPO3_SITE_URL'),2);
529 header('Location: http://'.$url.TYPO3_mainDir.'alt_main.php');
530 exit;
531 }
532 }
533
534 } elseif ($activeLogin OR count($tempuserArr)) {
535 $this->loginFailure = TRUE;
536
537 if ($this->writeDevLog AND !count($tempuserArr) AND $activeLogin) t3lib_div::devLog('Login failed: '.t3lib_div::arrayToLogString($loginData), 't3lib_userAuth', 2);
538 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);
539 }
540
541
542 // If there were a login failure, check to see if a warning email should be sent:
543 if ($this->loginFailure AND $activeLogin) {
544 if ($this->writeDevLog) t3lib_div::devLog('Call checkLogFailures: '.t3lib_div::arrayToLogString(array('warningEmail'=>$this->warningEmail,'warningPeriod'=>$this->warningPeriod,'warningMax'=>$this->warningMax,)), 't3lib_userAuth', -1);
545
546 $this->checkLogFailures($this->warningEmail, $this->warningPeriod, $this->warningMax);
547 }
548 }
549
550
551
552
553
554
555
556
557
558
559
560
561 /*************************
562 *
563 * User Sessions
564 *
565 *************************/
566
567
568 /**
569 * Creates a user session record.
570 *
571 * @param array user data array
572 * @return void
573 */
574 function createUserSession ($tempuser) {
575
576 if ($this->writeDevLog) t3lib_div::devLog('Create session ses_id = '.$this->id, 't3lib_userAuth');
577
578 // delete session entry first
579 $GLOBALS['TYPO3_DB']->exec_DELETEquery(
580 $this->session_table,
581 'ses_id = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->id, $this->session_table).'
582 AND ses_name = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->name, $this->session_table)
583 );
584
585 // re-create session entry
586 $insertFields = array(
587 'ses_id' => $this->id,
588 'ses_name' => $this->name,
589 'ses_iplock' => $tempuser['disableIPlock'] ? '[DISABLED]' : $this->ipLockClause_remoteIPNumber($this->lockIP),
590 'ses_hashlock' => $this->hashLockClause_getHashInt(),
591 'ses_userid' => $tempuser[$this->userid_column],
592 'ses_tstamp' => $GLOBALS['EXEC_TIME']
593 );
594 $GLOBALS['TYPO3_DB']->exec_INSERTquery($this->session_table, $insertFields);
595
596 // Updating lastLogin_column carrying information about last login.
597 if ($this->lastLogin_column) {
598 $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
599 $this->user_table,
600 $this->userid_column.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($tempuser[$this->userid_column], $this->user_table),
601 array($this->lastLogin_column => $GLOBALS['EXEC_TIME'])
602 );
603 }
604 }
605
606 /**
607 * Read the user session from db.
608 *
609 * @return array user session data
610 */
611 function fetchUserSession() {
612
613 $user = '';
614
615 if ($this->writeDevLog) t3lib_div::devLog('Fetch session ses_id = '.$this->id, 't3lib_userAuth');
616
617 // 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
618 $dbres = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
619 '*',
620 $this->session_table.','.$this->user_table,
621 $this->session_table.'.ses_id = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->id, $this->session_table).'
622 AND '.$this->session_table.'.ses_name = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->name, $this->session_table).'
623 AND '.$this->session_table.'.ses_userid = '.$this->user_table.'.'.$this->userid_column.'
624 '.$this->ipLockClause().'
625 '.$this->hashLockClause().'
626 '.$this->user_where_clause()
627 );
628
629
630 if ($user = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($dbres)) {
631 // A user was found
632 if (is_string($this->auth_timeout_field)) {
633 $timeout = intval($user[$this->auth_timeout_field]); // Get timeout-time from usertable
634 } else {
635 $timeout = intval($this->auth_timeout_field); // Get timeout from object
636 }
637 // If timeout > 0 (true) and currenttime has not exceeded the latest sessions-time plus the timeout in seconds then accept user
638 // 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...
639 if ($timeout>0 && ($GLOBALS['EXEC_TIME'] < ($user['ses_tstamp']+$timeout))) {
640 $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
641 $this->session_table,
642 'ses_id='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->id, $this->session_table).'
643 AND ses_name='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->name, $this->session_table),
644 array('ses_tstamp' => $GLOBALS['EXEC_TIME'])
645 );
646 $user['ses_tstamp'] = $GLOBALS['EXEC_TIME']; // Make sure that the timestamp is also updated in the array
647 } else {
648 $this->logoff(); // delete any user set...
649 }
650 } else {
651 $this->logoff(); // delete any user set...
652 }
653 return $user;
654 }
655
656 /**
657 * Log out current user!
658 * Removes the current session record, sets the internal ->user array to a blank string; Thereby the current user (if any) is effectively logged out!
659 *
660 * @return void
661 */
662 function logoff() {
663 if ($this->writeDevLog) t3lib_div::devLog('logoff: ses_id = '.$this->id, 't3lib_userAuth');
664
665 // Hook for pre-processing the logoff() method, requested and implemented by andreas.otto@dkd.de:
666 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'])) {
667 $_params = array();
668 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'] as $_funcRef) {
669 if ($_funcRef) {
670 t3lib_div::callUserFunction($_funcRef,$_params,$this);
671 }
672 }
673 }
674
675 $GLOBALS['TYPO3_DB']->exec_DELETEquery(
676 $this->session_table,
677 'ses_id = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->id, $this->session_table).'
678 AND ses_name = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->name, $this->session_table)
679 );
680
681 $this->user = '';
682
683 // Hook for post-processing the logoff() method, requested and implemented by andreas.otto@dkd.de:
684 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_post_processing'])) {
685 $_params = array();
686 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_post_processing'] as $_funcRef) {
687 if ($_funcRef) {
688 t3lib_div::callUserFunction($_funcRef,$_params,$this);
689 }
690 }
691 }
692 }
693
694
695
696
697
698
699
700
701
702
703
704
705
706 /*************************
707 *
708 * SQL Functions
709 *
710 *************************/
711
712 /**
713 * This returns the where-clause needed to select the user with respect flags like deleted, hidden, starttime, endtime
714 *
715 * @return string
716 * @access private
717 */
718 function user_where_clause() {
719 return (($this->enablecolumns['rootLevel']) ? 'AND '.$this->user_table.'.pid=0 ' : '').
720 (($this->enablecolumns['disabled']) ? ' AND '.$this->user_table.'.'.$this->enablecolumns['disabled'].'=0' : '').
721 (($this->enablecolumns['deleted']) ? ' AND '.$this->user_table.'.'.$this->enablecolumns['deleted'].'=0' : '').
722 (($this->enablecolumns['starttime']) ? ' AND ('.$this->user_table.'.'.$this->enablecolumns['starttime'].'<='.time().')' : '').
723 (($this->enablecolumns['endtime']) ? ' AND ('.$this->user_table.'.'.$this->enablecolumns['endtime'].'=0 OR '.$this->user_table.'.'.$this->enablecolumns['endtime'].'>'.time().')' : '');
724 }
725
726 /**
727 * This returns the where-clause needed to lock a user to the IP address
728 *
729 * @return string
730 * @access private
731 */
732 function ipLockClause() {
733 if ($this->lockIP) {
734 $wherePart = 'AND (
735 '.$this->session_table.'.ses_iplock='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->ipLockClause_remoteIPNumber($this->lockIP),$this->session_table).'
736 OR '.$this->session_table.'.ses_iplock=\'[DISABLED]\'
737 )';
738 return $wherePart;
739 }
740 }
741
742 /**
743 * Returns the IP address to lock to.
744 * The IP address may be partial based on $parts.
745 *
746 * @param integer 1-4: Indicates how many parts of the IP address to return. 4 means all, 1 means only first number.
747 * @return string (Partial) IP address for REMOTE_ADDR
748 * @access private
749 */
750 function ipLockClause_remoteIPNumber($parts) {
751 $IP = t3lib_div::getIndpEnv('REMOTE_ADDR');
752
753 if ($parts>=4) {
754 return $IP;
755 } else {
756 $parts = t3lib_div::intInRange($parts,1,3);
757 $IPparts = explode('.',$IP);
758 for($a=4;$a>$parts;$a--) {
759 unset($IPparts[$a-1]);
760 }
761 return implode('.',$IPparts);
762 }
763 }
764
765 /**
766 * This returns the where-clause needed to lock a user to a hash integer
767 *
768 * @return string
769 * @access private
770 */
771 function hashLockClause() {
772 $wherePart = 'AND '.$this->session_table.'.ses_hashlock='.intval($this->hashLockClause_getHashInt());
773 return $wherePart;
774 }
775
776 /**
777 * Creates hash integer to lock user to. Depends on configured keywords
778 *
779 * @return integer Hash integer
780 * @access private
781 */
782 function hashLockClause_getHashInt() {
783 $hashStr = '';
784
785 if (t3lib_div::inList($this->lockHashKeyWords,'useragent')) $hashStr.=':'.t3lib_div::getIndpEnv('HTTP_USER_AGENT');
786
787 return t3lib_div::md5int($hashStr);
788 }
789
790
791
792
793
794
795
796
797
798
799
800 /*************************
801 *
802 * Session and Configuration Handling
803 *
804 *************************/
805
806 /**
807 * This writes $variable to the user-record. This is a way of providing session-data.
808 * You can fetch the data again through $this->uc in this class!
809 * If $variable is not an array, $this->uc is saved!
810 *
811 * @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
812 * @return void
813 */
814 function writeUC($variable='') {
815 if (is_array($this->user) && $this->user[$this->userid_column]) {
816 if (!is_array($variable)) { $variable = $this->uc; }
817
818 if ($this->writeDevLog) t3lib_div::devLog('writeUC: '.$this->userid_column.'='.intval($this->user[$this->userid_column]), 't3lib_userAuth');
819 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($this->user_table, $this->userid_column.'='.intval($this->user[$this->userid_column]), array('uc' => serialize($variable)));
820 }
821 }
822
823 /**
824 * 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
825 *
826 * @param mixed If an array, then set as ->uc, otherwise load from user record
827 * @return void
828 */
829 function unpack_uc($theUC='') {
830 if (!$theUC) $theUC=unserialize($this->user['uc']);
831 if (is_array($theUC)) {
832 $this->uc=$theUC;
833 }
834 }
835
836 /**
837 * Stores data for a module.
838 * 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.
839 *
840 * @param string $module is the name of the module ($MCONF['name'])
841 * @param mixed $data is the data you want to store for that module (array, string, ...)
842 * @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.
843 * @return void
844 */
845 function pushModuleData($module,$data,$noSave=0) {
846 $this->uc['moduleData'][$module] = $data;
847 $this->uc['moduleSessionID'][$module] = $this->id;
848 if (!$noSave) $this->writeUC();
849 }
850
851 /**
852 * Gets module data for a module (from a loaded ->uc array)
853 *
854 * @param string $module is the name of the module ($MCONF['name'])
855 * @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).
856 * @return mixed The module data if available: $this->uc['moduleData'][$module];
857 */
858 function getModuleData($module,$type='') {
859 if ($type!='ses' || $this->uc['moduleSessionID'][$module]==$this->id) {
860 return $this->uc['moduleData'][$module];
861 }
862 }
863
864 /**
865 * Returns the session data stored for $key.
866 * The data will last only for this login session since it is stored in the session table.
867 *
868 * @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.
869 * @return mixed
870 */
871 function getSessionData($key) {
872 $sesDat = unserialize($this->user['ses_data']);
873 return $sesDat[$key];
874 }
875
876 /**
877 * Sets the session data ($data) for $key and writes all session data (from ->user['ses_data']) to the database.
878 * The data will last only for this login session since it is stored in the session table.
879 *
880 * @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.
881 * @param mixed The variable to store in index $key
882 * @return void
883 */
884 function setAndSaveSessionData($key,$data) {
885 $sesDat = unserialize($this->user['ses_data']);
886 $sesDat[$key] = $data;
887 $this->user['ses_data'] = serialize($sesDat);
888
889 if ($this->writeDevLog) t3lib_div::devLog('setAndSaveSessionData: ses_id = '.$this->user['ses_id'], 't3lib_userAuth');
890 $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']));
891 }
892
893
894
895
896
897
898
899
900
901
902
903
904
905 /*************************
906 *
907 * Misc
908 *
909 *************************/
910
911 /**
912 * Returns an info array with Login/Logout data submitted by a form or params
913 *
914 * @return array
915 * @internal
916 */
917 function getLoginFormData() {
918 $loginData=array();
919 if ($this->getMethodEnabled) {
920 $loginData['status'] = t3lib_div::_GP($this->formfield_status);
921 $loginData['uname'] = t3lib_div::_GP($this->formfield_uname);
922 $loginData['uident'] = t3lib_div::_GP($this->formfield_uident);
923 $loginData['chalvalue'] = t3lib_div::_GP($this->formfield_chalvalue);
924 } else {
925 $loginData['status'] = t3lib_div::_POST($this->formfield_status);
926 $loginData['uname'] = t3lib_div::_POST($this->formfield_uname);
927 $loginData['uident'] = t3lib_div::_POST($this->formfield_uident);
928 $loginData['chalvalue'] = t3lib_div::_POST($this->formfield_chalvalue);
929 }
930 $loginData = $this->processLoginData($loginData);
931
932 return $loginData;
933 }
934
935 /**
936 * Processes Login data submitted by a form or params depending on the
937 * security_level
938 *
939 * @param array login data array
940 * @param string Alternative security_level. Used when authentication services wants to override the default.
941 * @return array processed login data array
942 * @internal
943 */
944 function processLoginData($loginData, $security_level='') {
945 global $TYPO3_CONF_VARS;
946
947 $loginSecurityLevel = $security_level ? $security_level : ($TYPO3_CONF_VARS[$this->loginType]['loginSecurityLevel'] ? $TYPO3_CONF_VARS[$this->loginType]['loginSecurityLevel'] : $this->security_level);
948
949 // Processing data according to the state it was submitted in.
950 // ($loginSecurityLevel should reflect the security level used on the data being submitted in the login form)
951 if ($loginSecurityLevel=='normal') {
952 $loginData['uident_text'] = $loginData['uident'];
953 $loginData['uident_challenged'] = (string)md5($loginData['uname'].':'.$loginData['uident'].':'.$loginData['chalvalue']);
954 $loginData['uident_superchallenged'] = (string)md5($loginData['uname'].':'.(md5($loginData['uident'])).':'.$loginData['chalvalue']);
955 } elseif ($loginSecurityLevel=='challenged') {
956 $loginData['uident_text'] = '';
957 $loginData['uident_challenged'] = $loginData['uident'];
958 $loginData['uident_superchallenged'] = '';
959 } elseif ($loginSecurityLevel=='superchallenged') {
960 $loginData['uident_text'] = '';
961 $loginData['uident_challenged'] = '';
962 $loginData['uident_superchallenged'] = $loginData['uident'];
963 }
964
965 // The password "uident" is set based on the internal security setting of TYPO3
966 // Example:
967 // $this->security_level for the backend must be "superchallenged" because passwords are stored as md5-hashes in the be_users table
968 // $this->security_level for the frontend must be "normal" or "challenged" because passwords are stored as clear-text in the fe_users tables
969 if ($this->security_level=='normal') {
970 $loginData['uident'] = $loginData['uident_text'];
971 } elseif ($this->security_level=='challenged') {
972 $loginData['uident'] = $loginData['uident_challenged'];
973 } elseif ($this->security_level=='superchallenged') {
974 $loginData['uident'] = $loginData['uident_superchallenged'];
975 }
976
977 return $loginData;
978 }
979
980 /**
981 * Returns an info array which provides additional information for auth services
982 *
983 * @return array
984 * @internal
985 */
986 function getAuthInfoArray() {
987 $authInfo = array();
988 $authInfo['loginType'] = $this->loginType;
989 $authInfo['refInfo'] = parse_url(t3lib_div::getIndpEnv('HTTP_REFERER'));
990 $authInfo['HTTP_HOST'] = t3lib_div::getIndpEnv('HTTP_HOST');
991 $authInfo['REMOTE_ADDR'] = t3lib_div::getIndpEnv('REMOTE_ADDR');
992 $authInfo['REMOTE_HOST'] = t3lib_div::getIndpEnv('REMOTE_HOST');
993 $authInfo['security_level'] = $this->security_level;
994 $authInfo['showHiddenRecords'] = $this->showHiddenRecords;
995 // can be overidden in localconf by SVCONF:
996 $authInfo['db_user']['table'] = $this->user_table;
997 $authInfo['db_user']['userid_column'] = $this->userid_column;
998 $authInfo['db_user']['username_column'] = $this->username_column;
999 $authInfo['db_user']['userident_column'] = $this->userident_column;
1000 $authInfo['db_user']['usergroup_column'] = $this->usergroup_column;
1001 $authInfo['db_user']['enable_clause'] = $this->user_where_clause();
1002 $authInfo['db_user']['checkPidList'] = $this->checkPid ? $this->checkPid_value : '';
1003 $authInfo['db_user']['check_pid_clause'] = $this->checkPid ? ' AND pid IN ('.$GLOBALS['TYPO3_DB']->cleanIntList($authInfo['db_user']['checkPidList']).')' : '';
1004 $authInfo['db_groups']['table'] = $this->usergroup_table;
1005 return $authInfo;
1006 }
1007
1008 /**
1009 * Check the login data with the user record data for builtin login methods
1010 *
1011 * @param array user data array
1012 * @param array login data array
1013 * @param string Alternative security_level. Used when authentication services wants to override the default.
1014 * @return boolean true if login data matched
1015 */
1016 function compareUident($user, $loginData, $security_level='') {
1017
1018 $OK = FALSE;
1019 $security_level = $security_level ? $security_level : $this->security_level;
1020
1021 switch ($security_level) {
1022 case 'superchallenged': // If superchallenged the password in the database ($user[$this->userident_column]) must be a md5-hash of the original password.
1023 case 'challenged':
1024
1025 // Check challenge stored in cookie:
1026 if ($this->challengeStoredInCookie) {
1027 session_start();
1028 if ($_SESSION['login_challenge'] !== $loginData['chalvalue']) {
1029 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);
1030 $this->logoff();
1031 return FALSE;
1032 }
1033 }
1034
1035 if ((string)$loginData['uident'] === (string)md5($user[$this->username_column].':'.$user[$this->userident_column].':'.$loginData['chalvalue'])) {
1036 $OK = TRUE;
1037 };
1038 break;
1039 default: // normal
1040 if ((string)$loginData['uident'] === (string)$user[$this->userident_column]) {
1041 $OK = TRUE;
1042 };
1043 break;
1044 }
1045
1046 return $OK;
1047 }
1048
1049 /**
1050 * Garbage collector, removing old expired sessions.
1051 *
1052 * @return void
1053 * @internal
1054 */
1055 function gc() {
1056 $GLOBALS['TYPO3_DB']->exec_DELETEquery(
1057 $this->session_table,
1058 'ses_tstamp < '.intval(time()-($this->gc_time)).'
1059 AND ses_name = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->name, $this->session_table)
1060 );
1061 }
1062
1063 /**
1064 * Redirect to somewhere. Obsolete, deprecated etc.
1065 *
1066 * @return void
1067 * @ignore
1068 */
1069 function redirect() {
1070 if (!$this->userid && $this->auth_url) { // if no userid AND an include-document for login is given
1071 include ($this->auth_include);
1072 exit;
1073 }
1074 }
1075
1076 /**
1077 * DUMMY: Writes to log database table (in some extension classes)
1078 *
1079 * @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
1080 * @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 !!)
1081 * @param integer $error: flag. 0 = message, 1 = error (user problem), 2 = System Error (which should not happen), 3 = security notice (admin)
1082 * @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
1083 * @param string $details: Default text that follows the message
1084 * @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...
1085 * @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.)
1086 * @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.)
1087 * @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.)
1088 * @return void
1089 * @see t3lib_userauthgroup::writelog()
1090 */
1091 function writelog($type,$action,$error,$details_nr,$details,$data,$tablename,$recuid,$recpid) {
1092 }
1093
1094 /**
1095 * DUMMY: Check login failures (in some extension classes)
1096 *
1097 * @return void
1098 * @ignore
1099 */
1100 function checkLogFailures() {
1101 }
1102
1103 /**
1104 * Raw initialization of the be_user with uid=$uid
1105 * 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.
1106 * Will check the users for disabled, start/endtime, etc. ($this->user_where_clause())
1107 *
1108 * @param integer The UID of the backend user to set in ->user
1109 * @return void
1110 * @internal
1111 * @see SC_mod_tools_be_user_index::compareUsers(), SC_mod_user_setup_index::simulateUser(), freesite_admin::startCreate()
1112 */
1113 function setBeUserByUid($uid) {
1114 $this->user = $this->getRawUserByUid($uid);
1115 }
1116
1117 /**
1118 * Raw initialization of the be_user with username=$name
1119 *
1120 * @param string The username to look up.
1121 * @return void
1122 * @see t3lib_userAuth::setBeUserByUid()
1123 * @internal
1124 */
1125 function setBeUserByName($name) {
1126 $this->user = $this->getRawUserByName($name);
1127 }
1128
1129 /**
1130 * Fetching raw user record with uid=$uid
1131 *
1132 * @param integer The UID of the backend user to set in ->user
1133 * @return array user record or FALSE
1134 * @internal
1135 */
1136 function getRawUserByUid($uid) {
1137 $user = FALSE;
1138 $dbres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->user_table, 'uid='.intval($uid).' '.$this->user_where_clause());
1139 if ($dbres) {
1140 $user = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($dbres);
1141 $GLOBALS['TYPO3_DB']->sql_free_result($dbres);
1142 }
1143 return $user;
1144 }
1145
1146 /**
1147 * Fetching raw user record with username=$name
1148 *
1149 * @param string The username to look up.
1150 * @return array user record or FALSE
1151 * @see t3lib_userAuth::getUserByUid()
1152 * @internal
1153 */
1154 function getRawUserByName($name) {
1155 $user = FALSE;
1156 $dbres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->user_table, 'username='.$GLOBALS['TYPO3_DB']->fullQuoteStr($name, $this->user_table).' '.$this->user_where_clause());
1157 if ($dbres) {
1158 $user = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($dbres);
1159 $GLOBALS['TYPO3_DB']->sql_free_result($dbres);
1160 }
1161 return $user;
1162 }
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178 /*************************
1179 *
1180 * Create/update user - EXPERIMENTAL
1181 *
1182 *************************/
1183
1184 /**
1185 * Get a user from DB by username
1186 * provided for usage from services
1187 *
1188 * @param array User db table definition: $this->db_user
1189 * @param string user name
1190 * @param string additional WHERE clause: " AND ...
1191 * @return mixed user array or FALSE
1192 */
1193 function fetchUserRecord($dbUser, $username, $extraWhere='' ) {
1194 $user = FALSE;
1195
1196 $usernameClause = $username ? ($dbUser['username_column'].'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($username, $dbUser['table'])) : '';
1197
1198 if ($username OR $extraWhere) {
1199
1200 // Look up the user by the username and/or extraWhere:
1201 $dbres = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
1202 '*',
1203 $dbUser['table'],
1204 $usernameClause.
1205 $dbUser['check_pid_clause'].
1206 $dbUser['enable_clause'].
1207 $extraWhere
1208 );
1209
1210 if ($dbres) {
1211 $user = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($dbres);
1212 $GLOBALS['TYPO3_DB']->sql_free_result($dbres);
1213 }
1214 }
1215 return $user;
1216 }
1217 }
1218
1219
1220
1221 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_userauth.php']) {
1222 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_userauth.php']);
1223 }
1224 ?>