Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit 533022c

Browse files
committed
Add a getOptionAsBool() function abstractAuthDriver and use everywhere we use TRANSMIT_CLEAR_PASS. Handle all possible values (true, "true", 1, etc...).
1 parent c227ae4 commit 533022c

File tree

7 files changed

+26
-14
lines changed

7 files changed

+26
-14
lines changed

core/src/core/classes/class.AuthService.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ public static function bootSequence(&$START_PARAMETERS)
517517
if ($adminCount == 0) {
518518
$authDriver = ConfService::getAuthDriverImpl();
519519
$adminPass = ADMIN_PASSWORD;
520-
if ($authDriver->getOption("TRANSMIT_CLEAR_PASS") !== true) {
520+
if (!$authDriver->getOptionAsBool("TRANSMIT_CLEAR_PASS")) {
521521
$adminPass = md5(ADMIN_PASSWORD);
522522
}
523523
self::createUser("admin", $adminPass, true);
@@ -730,7 +730,7 @@ public static function checkPassword($userId, $userPass, $cookieString = false,
730730
$res = $userObject->checkCookieString($userPass);
731731
return $res;
732732
}
733-
if($authDriver->getOption("TRANSMIT_CLEAR_PASS") !== true){
733+
if(!$authDriver->getOptionAsBool("TRANSMIT_CLEAR_PASS")){
734734
if($authDriver->getSeed(false) != $returnSeed) return false;
735735
}
736736
return $authDriver->checkPassword($userId, $userPass, $returnSeed);
@@ -754,7 +754,7 @@ public static function updatePassword($userId, $userPass)
754754
AJXP_Controller::applyHook("user.before_password_change", array($userId));
755755
$authDriver->changePassword($userId, $userPass);
756756
AJXP_Controller::applyHook("user.after_password_change", array($userId));
757-
if ($authDriver->getOption("TRANSMIT_CLEAR_PASS") === true) {
757+
if ($authDriver->getOptionAsBool("TRANSMIT_CLEAR_PASS")) {
758758
// We can directly update the HA1 version of the WEBDAV Digest
759759
$realm = ConfService::getCoreConf("WEBDAV_DIGESTREALM");
760760
$ha1 = md5("{$userId}:{$realm}:{$userPass}");
@@ -800,7 +800,7 @@ public static function createUser($userId, $userPass, $isAdmin=false)
800800
$user->setAdmin(true);
801801
$user->save("superuser");
802802
}
803-
if ($authDriver->getOption("TRANSMIT_CLEAR_PASS") === true) {
803+
if ($authDriver->getOptionAsBool("TRANSMIT_CLEAR_PASS")) {
804804
$realm = ConfService::getCoreConf("WEBDAV_DIGESTREALM");
805805
$ha1 = md5("{$userId}:{$realm}:{$userPass}");
806806
if (!isSet($user)) {

core/src/dav.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function AJXP_Sabre_autoload($className)
103103
}
104104

105105
if((AJXP_Sabre_AuthBackendBasic::detectBasicHeader() || ConfService::getCoreConf("WEBDAV_FORCE_BASIC"))
106-
&& ConfService::getAuthDriverImpl()->getOption("TRANSMIT_CLEAR_PASS")){
106+
&& ConfService::getAuthDriverImpl()->getOptionAsBool("TRANSMIT_CLEAR_PASS")){
107107
$authBackend = new AJXP_Sabre_AuthBackendBasic($rId);
108108
} else {
109109
$authBackend = new AJXP_Sabre_AuthBackendDigest($rId);

core/src/plugins/action.share/class.ShareCenter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1909,7 +1909,7 @@ public function createSharedRepository($httpVars, $repository, $accessDriver, $u
19091909
// check that it's a child user
19101910
$userObject = $confDriver->createUserObject($userName);
19111911
} else {
1912-
if (ConfService::getAuthDriverImpl()->getOption("TRANSMIT_CLEAR_PASS")) {
1912+
if (ConfService::getAuthDriverImpl()->getOptionAsBool("TRANSMIT_CLEAR_PASS")) {
19131913
$pass = $uPasses[$userName];
19141914
} else {
19151915
$pass = md5($uPasses[$userName]);

core/src/plugins/auth.remote/class.remoteAuthDriver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public function createUser($login, $passwd)
250250
$users = $this->listUsers();
251251
if(!is_array($users)) $users = array();
252252
if(array_key_exists($login, $users)) return "exists";
253-
if ($this->getOption("TRANSMIT_CLEAR_PASS") === true) {
253+
if ($this->getOptionAsBool("TRANSMIT_CLEAR_PASS")) {
254254
$users[$login] = AJXP_Utils::pbkdf2_create_hash($passwd);
255255
} else {
256256
$users[$login] = $passwd;
@@ -262,7 +262,7 @@ public function changePassword($login, $newPass)
262262
if(AuthService::ignoreUserCase()) $login = strtolower($login);
263263
$users = $this->listUsers();
264264
if(!is_array($users) || !array_key_exists($login, $users)) return ;
265-
if ($this->getOption("TRANSMIT_CLEAR_PASS") === true) {
265+
if ($this->getOptionAsBool("TRANSMIT_CLEAR_PASS")) {
266266
$users[$login] = AJXP_Utils::pbkdf2_create_hash($newPass);
267267
} else {
268268
$users[$login] = $newPass;

core/src/plugins/auth.serial/class.serialAuthDriver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function createUser($login, $passwd)
138138
$users = $this->_listAllUsers();
139139
if(!is_array($users)) $users = array();
140140
if(array_key_exists($login, $users)) return "exists";
141-
if ($this->getOption("TRANSMIT_CLEAR_PASS") === true) {
141+
if ($this->getOptionAsBool("TRANSMIT_CLEAR_PASS")) {
142142
$users[$login] = AJXP_Utils::pbkdf2_create_hash($passwd);//md5($passwd);
143143
} else {
144144
$users[$login] = $passwd;
@@ -150,7 +150,7 @@ public function changePassword($login, $newPass)
150150
if(AuthService::ignoreUserCase()) $login = strtolower($login);
151151
$users = $this->_listAllUsers();
152152
if(!is_array($users) || !array_key_exists($login, $users)) return ;
153-
if ($this->getOption("TRANSMIT_CLEAR_PASS") === true) {
153+
if ($this->getOptionAsBool("TRANSMIT_CLEAR_PASS")) {
154154
$users[$login] = AJXP_Utils::pbkdf2_create_hash($newPass);//md5($newPass);
155155
} else {
156156
$users[$login] = $newPass;

core/src/plugins/auth.sql/class.sqlAuthDriver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public function checkPassword($login, $pass, $seed)
154154
$userStoredPass = $this->getUserPass($login);
155155
if(!$userStoredPass) return false;
156156

157-
if ($this->getOption("TRANSMIT_CLEAR_PASS") === true) { // Seed = -1 means that password is not encoded.
157+
if ($this->getOptionAsBool("TRANSMIT_CLEAR_PASS")) { // Seed = -1 means that password is not encoded.
158158
return AJXP_Utils::pbkdf2_validate_password($pass, $userStoredPass); //($userStoredPass == md5($pass));
159159
} else {
160160
return (md5($userStoredPass.$seed) == $pass);
@@ -174,7 +174,7 @@ public function createUser($login, $passwd)
174174
{
175175
if($this->userExists($login)) return "exists";
176176
$userData = array("login" => $login);
177-
if ($this->getOption("TRANSMIT_CLEAR_PASS") === true) {
177+
if ($this->getOptionAsBool("TRANSMIT_CLEAR_PASS")) {
178178
$userData["password"] = AJXP_Utils::pbkdf2_create_hash($passwd); //md5($passwd);
179179
} else {
180180
$userData["password"] = $passwd;
@@ -186,7 +186,7 @@ public function changePassword($login, $newPass)
186186
{
187187
if(!$this->userExists($login)) throw new Exception("User does not exists!");
188188
$userData = array("login" => $login);
189-
if ($this->getOption("TRANSMIT_CLEAR_PASS") === true) {
189+
if ($this->getOptionAsBool("TRANSMIT_CLEAR_PASS")) {
190190
$userData["password"] = AJXP_Utils::pbkdf2_create_hash($newPass); //md5($newPass);
191191
} else {
192192
$userData["password"] = $newPass;

core/src/plugins/core.auth/class.AbstractAuthDriver.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,18 @@ public function getOption($optionName)
268268
return (isSet($this->options[$optionName])?$this->options[$optionName]:"");
269269
}
270270

271+
/**
272+
* @param $optionName
273+
* @return bool
274+
*/
275+
public function getOptionAsBool($optionName)
276+
{
277+
return (isSet($this->options[$optionName]) &&
278+
($this->options[$optionName] === true || $this->options[$optionName] === 1
279+
|| $this->options[$optionName] === "true" || $this->options[$optionName] === "1")
280+
);
281+
}
282+
271283
public function isAjxpAdmin($login)
272284
{
273285
return ($this->getOption("AJXP_ADMIN_LOGIN") === $login);
@@ -282,7 +294,7 @@ public function autoCreateUser()
282294

283295
public function getSeed($new=true)
284296
{
285-
if($this->getOption("TRANSMIT_CLEAR_PASS") === true) return -1;
297+
if($this->getOptionAsBool("TRANSMIT_CLEAR_PASS")) return -1;
286298
if ($new) {
287299
$seed = md5(time());
288300
$_SESSION["AJXP_CURRENT_SEED"] = $seed;

0 commit comments

Comments
 (0)