Skip to content

Commit

Permalink
Replace direct access to $_SERVER with $INPUT->server->…
Browse files Browse the repository at this point in the history
2nd try on a separate branch
Also fixes a line that was too long

Note: As I do not use this plugin, this is completely untested.

It should fix splitbrain#3778 (unless I made a stupid mistake).

See fiwswe@ce0feb5
  • Loading branch information
fiwswe committed Sep 21, 2022
1 parent 9f48b70 commit 1d5848a
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions lib/plugins/authad/auth.php
Expand Up @@ -97,21 +97,22 @@ public function __construct()
}

// Prepare SSO
if (!empty($_SERVER['REMOTE_USER'])) {
if (!empty($INPUT->server->str('REMOTE_USER'))) {
// make sure the right encoding is used
if ($this->getConf('sso_charset')) {
$_SERVER['REMOTE_USER'] = iconv($this->getConf('sso_charset'), 'UTF-8', $_SERVER['REMOTE_USER']);
} elseif (!\dokuwiki\Utf8\Clean::isUtf8($_SERVER['REMOTE_USER'])) {
$_SERVER['REMOTE_USER'] = utf8_encode($_SERVER['REMOTE_USER']);
$INPUT->server->set('REMOTE_USER',
iconv($this->getConf('sso_charset'), 'UTF-8', $INPUT->server->str('REMOTE_USER')));
} elseif (!\dokuwiki\Utf8\Clean::isUtf8($INPUT->server->str('REMOTE_USER'))) {
$INPUT->server->set('REMOTE_USER', utf8_encode($INPUT->server->str('REMOTE_USER')));
}

// trust the incoming user
if ($this->conf['sso']) {
$_SERVER['REMOTE_USER'] = $this->cleanUser($_SERVER['REMOTE_USER']);
$INPUT->server->set('REMOTE_USER', $this->cleanUser($INPUT->server->str('REMOTE_USER')));

// we need to simulate a login
if (empty($_COOKIE[DOKU_COOKIE])) {
$INPUT->set('u', $_SERVER['REMOTE_USER']);
$INPUT->set('u', $INPUT->server->str('REMOTE_USER'));
$INPUT->set('p', 'sso_only');
}
}
Expand All @@ -131,8 +132,9 @@ public function __construct()
*/
public function canDo($cap)
{
global $INPUT;
//capabilities depend on config, which may change depending on domain
$domain = $this->getUserDomain($_SERVER['REMOTE_USER']);
$domain = $this->getUserDomain($INPUT->server->str('REMOTE_USER'));
$this->loadServerConfig($domain);
return parent::canDo($cap);
}
Expand All @@ -151,8 +153,8 @@ public function canDo($cap)
*/
public function checkPass($user, $pass)
{
if ($_SERVER['REMOTE_USER'] &&
$_SERVER['REMOTE_USER'] == $user &&
global $INPUT;
if ($INPUT->server->str('REMOTE_USER') == $user &&
$this->conf['sso']
) return true;

Expand Down Expand Up @@ -197,6 +199,7 @@ public function getUserData($user, $requireGroups = true)
global $conf;
global $lang;
global $ID;
global $INPUT;
$adldap = $this->initAdLdap($this->getUserDomain($user));
if (!$adldap) return array();

Expand Down Expand Up @@ -262,7 +265,7 @@ public function getUserData($user, $requireGroups = true)
$info['expiresin'] = round(($info['expiresat'] - time())/(24*60*60));

// if this is the current user, warn him (once per request only)
if (($_SERVER['REMOTE_USER'] == $user) &&
if (($INPUT->server->str('REMOTE_USER') == $user) &&
($info['expiresin'] <= $this->conf['expirywarn']) &&
!$this->msgshown
) {
Expand Down

0 comments on commit 1d5848a

Please sign in to comment.