Skip to content
This repository has been archived by the owner on Oct 26, 2019. It is now read-only.

Commit

Permalink
Double verify the SMB response
Browse files Browse the repository at this point in the history
In case anonymous auth is allowed this can otherwise lead to unexpected actions.
  • Loading branch information
LukasReschke committed Sep 9, 2016
1 parent f101d84 commit decb91f
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions user_external/lib/smb.php
Expand Up @@ -32,18 +32,14 @@ public function __construct($host) {
}

/**
* Check if the password is correct without logging in the user
*
* @param string $uid The username
* @param string $password The password
*
* @return true/false
* @param string $uid
* @param string $password
* @return bool
*/
public function checkPassword($uid, $password) {
$uidEscaped=escapeshellarg($uid);
$password=escapeshellarg($password);
$result=array();
$command=self::SMBCLIENT.' //'.$this->host.'/dummy -U'.$uidEscaped.'%'.$password;
private function tryAuthentication($uid, $password) {
$uidEscaped = escapeshellarg($uid);
$password = escapeshellarg($password);
$command = self::SMBCLIENT.' '.escapeshellarg('//' . $this->host . '/dummy').' -U'.$uidEscaped.'%'.$password;
$lastline = exec($command, $output, $retval);
if ($retval === 127) {
OCP\Util::writeLog(
Expand All @@ -66,8 +62,32 @@ public function checkPassword($uid, $password) {
return false;
} else {
login:
return $uid;
}
}

/**
* Check if the password is correct without logging in the user
*
* @param string $uid The username
* @param string $password The password
*
* @return true/false
*/
public function checkPassword($uid, $password) {
// Check with an invalid password, if the user authenticates then fail
$attemptWithInvalidPassword = $this->tryAuthentication($uid, base64_encode($password));
if(is_string($attemptWithInvalidPassword)) {
return false;
}

// Check with valid password
$attemptWithValidPassword = $this->tryAuthentication($uid, $password);
if(is_string($attemptWithValidPassword)) {
$this->storeUser($uid);
return $uid;
}

return false;
}
}

0 comments on commit decb91f

Please sign in to comment.