Skip to content

Commit

Permalink
MDL-9399 auth/ldap: NTLM SSO - lots of fixes from Iñaki
Browse files Browse the repository at this point in the history
Lots of typos and minor errors fixed by Iñaki. Thanks!
  • Loading branch information
martinlanghoff committed Nov 14, 2007
1 parent 3357a50 commit 02c7f3d
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions auth/ldap/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,28 @@ function user_login($username, $password) {
//
// Before we connect to LDAP, check if this is an AD SSO login
//
if (!empty($this->ntlmsso_enabled)) {
if (!empty($this->config->ntlmsso_enabled)) {
$key = $_SERVER['REMOTE_ADDR'];
if ($cookie = get_config('auth/ldap/ntlmsess', $key)) {
// These checks match the work done
if (preg_match('/^(\d+):.{10}:(.+)$/',$cookie,$matches)) {
if (preg_match('/^(\d+):(.{10}):(.+)$/',$cookie,$matches)) {
// $matches[0] is the whole matched string...
$time = $matches[1];
$sesskey = $matches[2];
$sessusername = $matches[3];
if (((int)$time < now() - 6) // timewindow for the process, in secs...
if (((time() - ((int)$time)) < 6) // timewindow for the process, in secs...
&& $sesskey === sesskey()
&& $sesskey === $password
&& $sessusername === $username) {

unset($cookie);
unset($key);
unset($time);
unset($sessusername);
return true;
}
}
}
unset($cookie);
unset($key);
unset($time);
unset($sessusername);
}


Expand Down Expand Up @@ -1742,6 +1743,8 @@ function change_password_url() {
*
*/
function loginpage_hook() {
global $CFG;

if (!empty($this->config->ntlmsso_enabled) // SSO enabled
&& !empty($this->config->ntlmsso_subnet)// have a subnet to test for
&& empty($_GET['authldap_skipntlmsso']) // haven't failed it yet
Expand Down Expand Up @@ -1774,7 +1777,7 @@ function ntlmsso_magic($sesskey) {
$username = substr(strrchr($username, '\\'), 1); //strip domain info
$username = strtolower($username); //compatibility hack
$key = $_SERVER['REMOTE_ADDR']; // add sesskey?
$value = now() . ':' . $sesskey . ':' . $username;
$value = time() . ':' . $sesskey . ':' . $username;
return set_config($key, $value, 'auth/ldap/ntlmsess');
}
return false;
Expand All @@ -1791,14 +1794,16 @@ function ntlmsso_magic($sesskey) {
*
*/
function ntlmsso_finish() {
global $CFG;

$key = $_SERVER['REMOTE_ADDR']; // add sesskey?
if ($cookie = get_config('auth/ldap/ntlmsess', $key)) {
if (preg_match('/^(\d+):.{10}:(.+)$/',$cookie,$matches)) {
if (preg_match('/^(\d+):(.{10}):(.+)$/',$cookie,$matches)) {
// $matches[0] is the whole matched string...
$time = $matches[1];
$sesskey = $matches[2];
$username = $matches[3];
if (((int)$time < now() - 6) // timewindow for the process, in secs...
if (((time() - ((int)$time)) < 6) // timewindow for the process, in secs...
&& $sesskey === sesskey()) {
// Here we want to trigger the whole authentication machinery
// to make sure no step is bypassed...
Expand Down

0 comments on commit 02c7f3d

Please sign in to comment.