00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00088 require_once(t3lib_extMgm::extPath('sv').'class.tx_sv_authbase.php');
00089
00090
00091
00092
00093
00094
00095
00096
00097
00111 class t3lib_userAuth {
00112 var $global_database = '';
00113 var $session_table = '';
00114 var $name = '';
00115 var $get_name = '';
00116
00117 var $user_table = '';
00118 var $username_column = '';
00119 var $userident_column = '';
00120 var $userid_column = '';
00121 var $lastLogin_column = '';
00122
00123 var $enablecolumns = Array (
00124 'rootLevel' => '',
00125 'disabled' => '',
00126 'starttime' => '',
00127 'endtime' => '',
00128 'deleted' => ''
00129 );
00130
00131 var $formfield_uname = '';
00132 var $formfield_uident = '';
00133 var $formfield_chalvalue = '';
00134 var $formfield_status = '';
00135 var $security_level = 'normal';
00136
00137 var $auth_include = '';
00138
00139 var $auth_timeout_field = 0;
00140 var $lifetime = 0;
00141 var $gc_time = 24;
00142 var $gc_probability = 1;
00143 var $writeStdLog = FALSE;
00144 var $writeAttemptLog = FALSE;
00145 var $sendNoCacheHeaders = TRUE;
00146 var $getFallBack = FALSE;
00147 var $hash_length = 32;
00148 var $getMethodEnabled = FALSE;
00149 var $lockIP = 4;
00150 var $lockHashKeyWords = 'useragent';
00151
00152 var $warningEmail = '';
00153 var $warningPeriod = 3600;
00154 var $warningMax = 3;
00155 var $checkPid = TRUE;
00156 var $checkPid_value=0;
00157
00158
00159 var $id;
00160 var $cookieId;
00161 var $loginFailure = FALSE;
00162 var $loginSessionStarted = FALSE;
00163
00164 var $user;
00165 var $get_URL_ID = '';
00166
00167 var $newSessionID = FALSE;
00168 var $forceSetCookie = FALSE;
00169 var $dontSetCookie = FALSE;
00170 var $challengeStoredInCookie = FALSE;
00171 var $loginType = '';
00172
00173 var $svConfig = array();
00174 var $writeDevLog = FALSE;
00175
00176
00177
00178
00179
00180
00181
00182
00183
00195 function start() {
00196 global $TYPO3_CONF_VARS;
00197
00198
00199 $this->loginType = ($this->name=='fe_typo_user') ? 'FE' : 'BE';
00200
00201
00202 $this->security_level = $this->security_level ? $this->security_level : 'normal';
00203
00204
00205 if ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['writeDevLog']) $this->writeDevLog = TRUE;
00206 if ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['writeDevLog'.$this->loginType]) $this->writeDevLog = TRUE;
00207 if (TYPO3_DLOG) $this->writeDevLog = TRUE;
00208
00209 if ($this->writeDevLog) t3lib_div::devLog('## Beginning of auth logging.', 't3lib_userAuth');
00210
00211
00212 $mode = '';
00213 $this->newSessionID = FALSE;
00214
00215 $id = isset($_COOKIE[$this->name]) ? stripslashes($_COOKIE[$this->name]) : '';
00216 $this->hash_length = t3lib_div::intInRange($this->hash_length,6,32);
00217 $this->svConfig = $TYPO3_CONF_VARS['SVCONF']['auth'];
00218
00219
00220
00221 if (!$id && $this->getFallBack && $this->get_name) {
00222 $id = isset($_GET[$this->get_name]) ? t3lib_div::_GET($this->get_name) : '';
00223 if (strlen($id)!=$this->hash_length) $id='';
00224 $mode='get';
00225 }
00226 $this->cookieId = $id;
00227
00228
00229 if (!$id) {
00230
00231 $id = substr(md5(uniqid('').getmypid()),0,$this->hash_length);
00232
00233 $this->newSessionID = TRUE;
00234 }
00235
00236
00237 $this->id = $id;
00238
00239
00240 if ($mode=='get' && $this->getFallBack && $this->get_name) {
00241 $this->get_URL_ID = '&'.$this->get_name.'='.$id;
00242 }
00243
00244 $this->user = '';
00245
00246
00247 if ($TYPO3_CONF_VARS['SYS']['cookieDomain']) {
00248 if ($TYPO3_CONF_VARS['SYS']['cookieDomain']{0} == '/') {
00249 $matchCnt = @preg_match($TYPO3_CONF_VARS['SYS']['cookieDomain'], t3lib_div::getIndpEnv('TYPO3_HOST_ONLY'), $match);
00250 if ($matchCnt === FALSE) {
00251 t3lib_div::sysLog('The regular expression of $TYPO3_CONF_VARS[SYS][cookieDomain] contains errors. The session is not shared across sub-domains.', 'Core', 3);
00252 } elseif ($matchCnt) {
00253 $cookieDomain = $match[0];
00254 }
00255 } else {
00256 $cookieDomain = $TYPO3_CONF_VARS['SYS']['cookieDomain'];
00257 }
00258 }
00259
00260
00261 if (($this->newSessionID || $this->forceSetCookie) && $this->lifetime==0 ) {
00262 if (!$this->dontSetCookie) {
00263 if ($cookieDomain) {
00264 SetCookie($this->name, $id, 0, '/', $cookieDomain);
00265 } else {
00266 SetCookie($this->name, $id, 0, '/');
00267 }
00268 if ($this->writeDevLog) t3lib_div::devLog('Set new Cookie: '.$id.($cookieDomain ? ', '.$cookieDomain : ''), 't3lib_userAuth');
00269 }
00270 }
00271
00272
00273 if ($this->lifetime > 0) {
00274 if (!$this->dontSetCookie) {
00275 if ($cookieDomain) {
00276 SetCookie($this->name, $id, time()+$this->lifetime, '/', $cookieDomain);
00277 } else {
00278 SetCookie($this->name, $id, time()+$this->lifetime, '/');
00279 }
00280 if ($this->writeDevLog) t3lib_div::devLog('Update Cookie: '.$id.($cookieDomain ? ', '.$cookieDomain : ''), 't3lib_userAuth');
00281 }
00282 }
00283
00284
00285 $this->checkAuthentication();
00286
00287
00288 unset($this->user);
00289
00290
00291 $this->user = $this->fetchUserSession();
00292
00293 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);
00294 if ($this->writeDevLog AND !is_array($this->user)) t3lib_div::devLog('No user session found.', 't3lib_userAuth', 2);
00295
00296
00297 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['postUserLookUp'])) {
00298 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['postUserLookUp'] as $funcName) {
00299 $_params = array(
00300 'pObj' => &$this,
00301 );
00302 t3lib_div::callUserFunction($funcName,$_params,$this);
00303 }
00304 }
00305
00306
00307 $this->redirect();
00308
00309
00310 if ($this->sendNoCacheHeaders) {
00311 header('Expires: 0');
00312 header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
00313 header('Cache-Control: no-cache, must-revalidate');
00314 header('Pragma: no-cache');
00315 }
00316
00317
00318 if ((rand()%100) <= $this->gc_probability) {
00319 $this->gc();
00320 }
00321 }
00322
00329 function checkAuthentication() {
00330
00331
00332 $tempuserArr = array();
00333 $tempuser = FALSE;
00334
00335
00336 $authenticated = FALSE;
00337
00338
00339 $activeLogin = FALSE;
00340
00341
00342 $this->loginFailure = FALSE;
00343
00344 if ($this->writeDevLog) t3lib_div::devLog('Login type: '.$this->loginType, 't3lib_userAuth');
00345
00346
00347 $authInfo = $this->getAuthInfoArray();
00348
00349
00350 $loginData = $this->getLoginFormData();
00351
00352 if ($this->writeDevLog) t3lib_div::devLog('Login data: '.t3lib_div::arrayToLogString($loginData), 't3lib_userAuth');
00353
00354
00355
00356 if ($loginData['status']=='logout') {
00357 if ($this->writeStdLog) $this->writelog(255,2,0,2,'User %s logged out',Array($this->user['username']));
00358 if ($this->writeDevLog) t3lib_div::devLog('User logged out. Id: '.$this->id, 't3lib_userAuth', -1);
00359
00360 $this->logoff();
00361 }
00362
00363
00364 if ($loginData['status']=='login') {
00365 $activeLogin = TRUE;
00366
00367 if ($this->writeDevLog) t3lib_div::devLog('Active login (eg. with login form)', 't3lib_userAuth');
00368
00369
00370 if($this->formfield_status && $loginData['uident'] && $loginData['uname']) {
00371 $httpHost = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY');
00372 if (!$this->getMethodEnabled && ($httpHost!=$authInfo['refInfo']['host'] && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer'])) {
00373 die('Error: This host address ("'.$httpHost.'") and the referer host ("'.$authInfo['refInfo']['host'].'") mismatches!<br />
00374 It\'s possible that the environment variable HTTP_REFERER is not passed to the script because of a proxy.<br />
00375 The site administrator can disable this check in the "All Configuration" section of the Install Tool (flag: TYPO3_CONF_VARS[SYS][doNotCheckReferer]).');
00376 }
00377
00378
00379 $this->logoff();
00380 }
00381 }
00382
00383
00384
00385
00386
00387 $authInfo['userSession'] = $this->fetchUserSession();
00388 $haveSession = is_array($authInfo['userSession']) ? TRUE : FALSE;
00389
00390 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);
00391 if ($this->writeDevLog) t3lib_div::devLog('SV setup: '.t3lib_div::arrayToLogString($this->svConfig['setup']), 't3lib_userAuth', 0);
00392
00393
00394
00395 if ( $activeLogin
00396 OR (!$haveSession AND $this->svConfig['setup'][$this->loginType.'_fetchUserIfNoSession'])
00397 OR $this->svConfig['setup'][$this->loginType.'_alwaysFetchUser']) {
00398
00399
00400
00401 $serviceChain = '';
00402 $subType = 'getUser'.$this->loginType;
00403 while (is_object($serviceObj = t3lib_div::makeInstanceService('auth', $subType, $serviceChain))) {
00404 $serviceChain.=','.$serviceObj->getServiceKey();
00405 $serviceObj->initAuth($subType, $loginData, $authInfo, $this);
00406 if ($row=$serviceObj->getUser()) {
00407 $tempuserArr[] = $row;
00408
00409 if ($this->writeDevLog) t3lib_div::devLog('User found: '.t3lib_div::arrayToLogString($row, array($this->userid_column,$this->username_column)), 't3lib_userAuth', 0);
00410
00411
00412 if(!$this->svConfig['setup'][$this->loginType.'_fetchAllUsers']) {
00413 break;
00414 }
00415 }
00416 unset($serviceObj);
00417 }
00418 unset($serviceObj);
00419
00420 if ($this->writeDevLog AND $this->svConfig['setup'][$this->loginType.'_alwaysFetchUser']) t3lib_div::devLog($this->loginType.'_alwaysFetchUser option is enabled', 't3lib_userAuth');
00421 if ($this->writeDevLog AND $serviceChain) t3lib_div::devLog($subType.' auth services called: '.$serviceChain, 't3lib_userAuth');
00422 if ($this->writeDevLog AND !count($tempuserArr)) t3lib_div::devLog('No user found by services', 't3lib_userAuth');
00423 if ($this->writeDevLog AND count($tempuserArr)) t3lib_div::devLog(count($tempuserArr).' user records found by services', 't3lib_userAuth');
00424 }
00425
00426
00427
00428 if (!count($tempuserArr) AND $haveSession) {
00429 $tempuserArr[] = $authInfo['userSession'];
00430 $tempuser = $authInfo['userSession'];
00431
00432 $authenticated = TRUE;
00433
00434 if ($this->writeDevLog) t3lib_div::devLog('User session used: '.t3lib_div::arrayToLogString($authInfo['userSession'], array($this->userid_column,$this->username_column)), 't3lib_userAuth');
00435 }
00436
00437
00438
00439 if ($this->svConfig['setup'][$this->loginType.'_alwaysAuthUser']) {
00440 $authenticated = FALSE;
00441 if ($this->writeDevLog) t3lib_div::devLog('alwaysAuthUser option is enabled', 't3lib_userAuth');
00442 }
00443
00444
00445
00446 if(count($tempuserArr) AND !$authenticated) {
00447
00448 foreach($tempuserArr as $tempuser) {
00449
00450
00451
00452
00453
00454 if ($this->writeDevLog) t3lib_div::devLog('Auth user: '.t3lib_div::arrayToLogString($tempuser), 't3lib_userAuth');
00455
00456 $serviceChain='';
00457 $subType = 'authUser'.$this->loginType;
00458 while (is_object($serviceObj = t3lib_div::makeInstanceService('auth', $subType, $serviceChain))) {
00459 $serviceChain.=','.$serviceObj->getServiceKey();
00460 $serviceObj->initAuth($subType, $loginData, $authInfo, $this);
00461 if (($ret=$serviceObj->authUser($tempuser)) > 0) {
00462
00463
00464 if (intval($ret) >= 200) {
00465 $authenticated = TRUE;
00466 break;
00467 } elseif (intval($ret) >= 100) {
00468
00469 } else {
00470 $authenticated = TRUE;
00471 }
00472
00473 } else {
00474 $authenticated = FALSE;
00475 break;
00476 }
00477 unset($serviceObj);
00478 }
00479 unset($serviceObj);
00480
00481 if ($this->writeDevLog AND $serviceChain) t3lib_div::devLog($subType.' auth services called: '.$serviceChain, 't3lib_userAuth');
00482
00483 if($authenticated) {
00484
00485 break;
00486 }
00487 }
00488 }
00489
00490
00491
00492 if ($authenticated) {
00493
00494 $this->loginFailure = FALSE;
00495
00496
00497
00498 if (!($haveSession AND (
00499 $tempuser['ses_id']==$this->id OR
00500 $tempuser['uid']==$authInfo['userSession']['ses_userid']
00501 ))) {
00502 $this->createUserSession($tempuser);
00503
00504
00505 $this->loginSessionStarted = TRUE;
00506 }
00507
00508
00509 if ($this->writeStdLog && $activeLogin) {
00510 $this->writelog(255,1,0,1,
00511 'User %s logged in from %s (%s)',
00512 Array($tempuser[$this->username_column], t3lib_div::getIndpEnv('REMOTE_ADDR'), t3lib_div::getIndpEnv('REMOTE_HOST')),
00513 '','','',-1,'',$tempuser['uid']
00514 );
00515 }
00516
00517 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);
00518 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);
00519
00520 if($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'] == 3 && $this->user_table == 'be_users') {
00521 $requestStr = substr(t3lib_div::getIndpEnv('TYPO3_REQUEST_SCRIPT'), strlen(t3lib_div::getIndpEnv('TYPO3_SITE_URL').TYPO3_mainDir));
00522 if($requestStr == 'alt_main.php' && t3lib_div::getIndpEnv('TYPO3_SSL')) {
00523 list(,$url) = explode(':
00524 header('Location: http:
00525 exit;
00526 }
00527 }
00528
00529 } elseif ($activeLogin OR count($tempuserArr)) {
00530 $this->loginFailure = TRUE;
00531
00532 if ($this->writeDevLog AND !count($tempuserArr) AND $activeLogin) t3lib_div::devLog('Login failed: '.t3lib_div::arrayToLogString($loginData), 't3lib_userAuth', 2);
00533 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);
00534 }
00535
00536
00537
00538 if ($this->loginFailure AND $activeLogin) {
00539 if ($this->writeDevLog) t3lib_div::devLog('Call checkLogFailures: '.t3lib_div::arrayToLogString(array('warningEmail'=>$this->warningEmail,'warningPeriod'=>$this->warningPeriod,'warningMax'=>$this->warningMax,)), 't3lib_userAuth', -1);
00540
00541 $this->checkLogFailures($this->warningEmail, $this->warningPeriod, $this->warningMax);
00542 }
00543 }
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00569 function createUserSession ($tempuser) {
00570
00571 if ($this->writeDevLog) t3lib_div::devLog('Create session ses_id = '.$this->id, 't3lib_userAuth');
00572
00573
00574 $GLOBALS['TYPO3_DB']->exec_DELETEquery(
00575 $this->session_table,
00576 'ses_id = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->id, $this->session_table).'
00577 AND ses_name = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->name, $this->session_table)
00578 );
00579
00580
00581 $insertFields = array(
00582 'ses_id' => $this->id,
00583 'ses_name' => $this->name,
00584 'ses_iplock' => $tempuser['disableIPlock'] ? '[DISABLED]' : $this->ipLockClause_remoteIPNumber($this->lockIP),
00585 'ses_hashlock' => $this->hashLockClause_getHashInt(),
00586 'ses_userid' => $tempuser[$this->userid_column],
00587 'ses_tstamp' => $GLOBALS['EXEC_TIME']
00588 );
00589 $GLOBALS['TYPO3_DB']->exec_INSERTquery($this->session_table, $insertFields);
00590
00591
00592 if ($this->lastLogin_column) {
00593 $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
00594 $this->user_table,
00595 $this->userid_column.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($tempuser[$this->userid_column], $this->user_table),
00596 array($this->lastLogin_column => $GLOBALS['EXEC_TIME'])
00597 );
00598 }
00599 }
00600
00606 function fetchUserSession() {
00607
00608 $user = '';
00609
00610 if ($this->writeDevLog) t3lib_div::devLog('Fetch session ses_id = '.$this->id, 't3lib_userAuth');
00611
00612
00613 $dbres = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00614 '*',
00615 $this->session_table.','.$this->user_table,
00616 $this->session_table.'.ses_id = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->id, $this->session_table).'
00617 AND '.$this->session_table.'.ses_name = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->name, $this->session_table).'
00618 AND '.$this->session_table.'.ses_userid = '.$this->user_table.'.'.$this->userid_column.'
00619 '.$this->ipLockClause().'
00620 '.$this->hashLockClause().'
00621 '.$this->user_where_clause()
00622 );
00623
00624
00625 if ($user = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($dbres)) {
00626
00627 if (is_string($this->auth_timeout_field)) {
00628 $timeout = intval($user[$this->auth_timeout_field]);
00629 } else {
00630 $timeout = intval($this->auth_timeout_field);
00631 }
00632
00633
00634 if ($timeout>0 && ($GLOBALS['EXEC_TIME'] < ($user['ses_tstamp']+$timeout))) {
00635 $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
00636 $this->session_table,
00637 'ses_id='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->id, $this->session_table).'
00638 AND ses_name='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->name, $this->session_table),
00639 array('ses_tstamp' => $GLOBALS['EXEC_TIME'])
00640 );
00641 $user['ses_tstamp'] = $GLOBALS['EXEC_TIME'];
00642 } else {
00643 $this->logoff();
00644 }
00645 } else {
00646 $this->logoff();
00647 }
00648 return $user;
00649 }
00650
00657 function logoff() {
00658 if ($this->writeDevLog) t3lib_div::devLog('logoff: ses_id = '.$this->id, 't3lib_userAuth');
00659
00660
00661 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'])) {
00662 $_params = array();
00663 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'] as $_funcRef) {
00664 if ($_funcRef) {
00665 t3lib_div::callUserFunction($_funcRef,$_params,$this);
00666 }
00667 }
00668 }
00669
00670 $GLOBALS['TYPO3_DB']->exec_DELETEquery(
00671 $this->session_table,
00672 'ses_id = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->id, $this->session_table).'
00673 AND ses_name = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->name, $this->session_table)
00674 );
00675
00676 $this->user = '';
00677
00678
00679 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_post_processing'])) {
00680 $_params = array();
00681 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_post_processing'] as $_funcRef) {
00682 if ($_funcRef) {
00683 t3lib_div::callUserFunction($_funcRef,$_params,$this);
00684 }
00685 }
00686 }
00687 }
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00713 function user_where_clause() {
00714 return (($this->enablecolumns['rootLevel']) ? 'AND '.$this->user_table.'.pid=0 ' : '').
00715 (($this->enablecolumns['disabled']) ? ' AND '.$this->user_table.'.'.$this->enablecolumns['disabled'].'=0' : '').
00716 (($this->enablecolumns['deleted']) ? ' AND '.$this->user_table.'.'.$this->enablecolumns['deleted'].'=0' : '').
00717 (($this->enablecolumns['starttime']) ? ' AND ('.$this->user_table.'.'.$this->enablecolumns['starttime'].'<='.time().')' : '').
00718 (($this->enablecolumns['endtime']) ? ' AND ('.$this->user_table.'.'.$this->enablecolumns['endtime'].'=0 OR '.$this->user_table.'.'.$this->enablecolumns['endtime'].'>'.time().')' : '');
00719 }
00720
00727 function ipLockClause() {
00728 if ($this->lockIP) {
00729 $wherePart = 'AND (
00730 '.$this->session_table.'.ses_iplock='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->ipLockClause_remoteIPNumber($this->lockIP),$this->session_table).'
00731 OR '.$this->session_table.'.ses_iplock=\'[DISABLED]\'
00732 )';
00733 return $wherePart;
00734 }
00735 }
00736
00745 function ipLockClause_remoteIPNumber($parts) {
00746 $IP = t3lib_div::getIndpEnv('REMOTE_ADDR');
00747
00748 if ($parts>=4) {
00749 return $IP;
00750 } else {
00751 $parts = t3lib_div::intInRange($parts,1,3);
00752 $IPparts = explode('.',$IP);
00753 for($a=4;$a>$parts;$a--) {
00754 unset($IPparts[$a-1]);
00755 }
00756 return implode('.',$IPparts);
00757 }
00758 }
00759
00766 function hashLockClause() {
00767 $wherePart = 'AND '.$this->session_table.'.ses_hashlock='.intval($this->hashLockClause_getHashInt());
00768 return $wherePart;
00769 }
00770
00777 function hashLockClause_getHashInt() {
00778 $hashStr = '';
00779
00780 if (t3lib_div::inList($this->lockHashKeyWords,'useragent')) $hashStr.=':'.t3lib_div::getIndpEnv('HTTP_USER_AGENT');
00781
00782 return t3lib_div::md5int($hashStr);
00783 }
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00809 function writeUC($variable='') {
00810 if (is_array($this->user) && $this->user[$this->userid_column]) {
00811 if (!is_array($variable)) { $variable = $this->uc; }
00812
00813 if ($this->writeDevLog) t3lib_div::devLog('writeUC: '.$this->userid_column.'='.intval($this->user[$this->userid_column]), 't3lib_userAuth');
00814 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($this->user_table, $this->userid_column.'='.intval($this->user[$this->userid_column]), array('uc' => serialize($variable)));
00815 }
00816 }
00817
00824 function unpack_uc($theUC='') {
00825 if (!$theUC) $theUC=unserialize($this->user['uc']);
00826 if (is_array($theUC)) {
00827 $this->uc=$theUC;
00828 }
00829 }
00830
00840 function pushModuleData($module,$data,$noSave=0) {
00841 $this->uc['moduleData'][$module] = $data;
00842 $this->uc['moduleSessionID'][$module] = $this->id;
00843 if (!$noSave) $this->writeUC();
00844 }
00845
00853 function getModuleData($module,$type='') {
00854 if ($type!='ses' || $this->uc['moduleSessionID'][$module]==$this->id) {
00855 return $this->uc['moduleData'][$module];
00856 }
00857 }
00858
00866 function getSessionData($key) {
00867 $sesDat = unserialize($this->user['ses_data']);
00868 return $sesDat[$key];
00869 }
00870
00879 function setAndSaveSessionData($key,$data) {
00880 $sesDat = unserialize($this->user['ses_data']);
00881 $sesDat[$key] = $data;
00882 $this->user['ses_data'] = serialize($sesDat);
00883
00884 if ($this->writeDevLog) t3lib_div::devLog('setAndSaveSessionData: ses_id = '.$this->user['ses_id'], 't3lib_userAuth');
00885 $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']));
00886 }
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00912 function getLoginFormData() {
00913 $loginData=array();
00914 if ($this->getMethodEnabled) {
00915 $loginData['status'] = t3lib_div::_GP($this->formfield_status);
00916 $loginData['uname'] = t3lib_div::_GP($this->formfield_uname);
00917 $loginData['uident'] = t3lib_div::_GP($this->formfield_uident);
00918 $loginData['chalvalue'] = t3lib_div::_GP($this->formfield_chalvalue);
00919 } else {
00920 $loginData['status'] = t3lib_div::_POST($this->formfield_status);
00921 $loginData['uname'] = t3lib_div::_POST($this->formfield_uname);
00922 $loginData['uident'] = t3lib_div::_POST($this->formfield_uident);
00923 $loginData['chalvalue'] = t3lib_div::_POST($this->formfield_chalvalue);
00924 }
00925 $loginData = $this->processLoginData($loginData);
00926
00927 return $loginData;
00928 }
00929
00939 function processLoginData($loginData, $security_level='') {
00940 global $TYPO3_CONF_VARS;
00941
00942 $loginSecurityLevel = $security_level ? $security_level : ($TYPO3_CONF_VARS[$this->loginType]['loginSecurityLevel'] ? $TYPO3_CONF_VARS[$this->loginType]['loginSecurityLevel'] : $this->security_level);
00943
00944
00945
00946 if ($loginSecurityLevel=='normal') {
00947 $loginData['uident_text'] = $loginData['uident'];
00948 $loginData['uident_challenged'] = (string)md5($loginData['uname'].':'.$loginData['uident'].':'.$loginData['chalvalue']);
00949 $loginData['uident_superchallenged'] = (string)md5($loginData['uname'].':'.(md5($loginData['uident'])).':'.$loginData['chalvalue']);
00950 } elseif ($loginSecurityLevel=='challenged') {
00951 $loginData['uident_text'] = '';
00952 $loginData['uident_challenged'] = $loginData['uident'];
00953 $loginData['uident_superchallenged'] = '';
00954 } elseif ($loginSecurityLevel=='superchallenged') {
00955 $loginData['uident_text'] = '';
00956 $loginData['uident_challenged'] = '';
00957 $loginData['uident_superchallenged'] = $loginData['uident'];
00958 }
00959
00960
00961
00962
00963
00964 if ($this->security_level=='normal') {
00965 $loginData['uident'] = $loginData['uident_text'];
00966 } elseif ($this->security_level=='challenged') {
00967 $loginData['uident'] = $loginData['uident_challenged'];
00968 } elseif ($this->security_level=='superchallenged') {
00969 $loginData['uident'] = $loginData['uident_superchallenged'];
00970 }
00971
00972 return $loginData;
00973 }
00974
00981 function getAuthInfoArray() {
00982 $authInfo = array();
00983 $authInfo['loginType'] = $this->loginType;
00984 $authInfo['refInfo'] = parse_url(t3lib_div::getIndpEnv('HTTP_REFERER'));
00985 $authInfo['HTTP_HOST'] = t3lib_div::getIndpEnv('HTTP_HOST');
00986 $authInfo['REMOTE_ADDR'] = t3lib_div::getIndpEnv('REMOTE_ADDR');
00987 $authInfo['REMOTE_HOST'] = t3lib_div::getIndpEnv('REMOTE_HOST');
00988 $authInfo['security_level'] = $this->security_level;
00989 $authInfo['showHiddenRecords'] = $this->showHiddenRecords;
00990
00991 $authInfo['db_user']['table'] = $this->user_table;
00992 $authInfo['db_user']['userid_column'] = $this->userid_column;
00993 $authInfo['db_user']['username_column'] = $this->username_column;
00994 $authInfo['db_user']['userident_column'] = $this->userident_column;
00995 $authInfo['db_user']['usergroup_column'] = $this->usergroup_column;
00996 $authInfo['db_user']['enable_clause'] = $this->user_where_clause();
00997 $authInfo['db_user']['checkPidList'] = $this->checkPid ? $this->checkPid_value : '';
00998 $authInfo['db_user']['check_pid_clause'] = $this->checkPid ? ' AND pid IN ('.$GLOBALS['TYPO3_DB']->cleanIntList($authInfo['db_user']['checkPidList']).')' : '';
00999 $authInfo['db_groups']['table'] = $this->usergroup_table;
01000 return $authInfo;
01001 }
01002
01011 function compareUident($user, $loginData, $security_level='') {
01012
01013 $OK = FALSE;
01014 $security_level = $security_level ? $security_level : $this->security_level;
01015
01016 switch ($security_level) {
01017 case 'superchallenged':
01018 case 'challenged':
01019
01020
01021 if ($this->challengeStoredInCookie) {
01022 session_start();
01023 if ($_SESSION['login_challenge'] !== $loginData['chalvalue']) {
01024 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);
01025 $this->logoff();
01026 return FALSE;
01027 }
01028 }
01029
01030 if ((string)$loginData['uident'] === (string)md5($user[$this->username_column].':'.$user[$this->userident_column].':'.$loginData['chalvalue'])) {
01031 $OK = TRUE;
01032 };
01033 break;
01034 default:
01035 if ((string)$loginData['uident'] === (string)$user[$this->userident_column]) {
01036 $OK = TRUE;
01037 };
01038 break;
01039 }
01040
01041 return $OK;
01042 }
01043
01050 function gc() {
01051 $GLOBALS['TYPO3_DB']->exec_DELETEquery(
01052 $this->session_table,
01053 'ses_tstamp < '.intval(time()-($this->gc_time*60*60)).'
01054 AND ses_name = '.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->name, $this->session_table)
01055 );
01056 }
01057
01064 function redirect() {
01065 if (!$this->userid && $this->auth_url) {
01066 include ($this->auth_include);
01067 exit;
01068 }
01069 }
01070
01086 function writelog($type,$action,$error,$details_nr,$details,$data,$tablename,$recuid,$recpid) {
01087 }
01088
01095 function checkLogFailures() {
01096 }
01097
01108 function setBeUserByUid($uid) {
01109 $this->user = $this->getRawUserByUid($uid);
01110 }
01111
01120 function setBeUserByName($name) {
01121 $this->user = $this->getRawUserByName($name);
01122 }
01123
01131 function getRawUserByUid($uid) {
01132 $user = FALSE;
01133 $dbres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->user_table, 'uid='.intval($uid).' '.$this->user_where_clause());
01134 if ($dbres) {
01135 $user = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($dbres);
01136 $GLOBALS['TYPO3_DB']->sql_free_result($dbres);
01137 }
01138 return $user;
01139 }
01140
01149 function getRawUserByName($name) {
01150 $user = FALSE;
01151 $dbres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->user_table, 'username='.$GLOBALS['TYPO3_DB']->fullQuoteStr($name, $this->user_table).' '.$this->user_where_clause());
01152 if ($dbres) {
01153 $user = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($dbres);
01154 $GLOBALS['TYPO3_DB']->sql_free_result($dbres);
01155 }
01156 return $user;
01157 }
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01188 function fetchUserRecord($dbUser, $username, $extraWhere='' ) {
01189 $user = FALSE;
01190
01191 $usernameClause = $username ? ($dbUser['username_column'].'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($username, $dbUser['table'])) : '';
01192
01193 if ($username OR $extraWhere) {
01194
01195
01196 $dbres = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
01197 '*',
01198 $dbUser['table'],
01199 $usernameClause.
01200 $dbUser['check_pid_clause'].
01201 $dbUser['enable_clause'].
01202 $extraWhere
01203 );
01204
01205 if ($dbres) {
01206 $user = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($dbres);
01207 $GLOBALS['TYPO3_DB']->sql_free_result($dbres);
01208 }
01209 }
01210 return $user;
01211 }
01212 }
01213
01214
01215
01216 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_userauth.php']) {
01217 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_userauth.php']);
01218 }
01219 ?>