Browse Source

Workaround for vanished database connections while authentication

tags/3.5.1
Michael 2 years ago
parent
commit
75711a947e
1 changed files with 18 additions and 8 deletions
  1. 18
    8
      include/auth_ejabberd.php

+ 18
- 8
include/auth_ejabberd.php View File

@@ -159,14 +159,19 @@ class exAuth {
159 159
 		$sUser = str_replace(array("%20", "(a)"), array(" ", "@"), $aCommand[1]);
160 160
 		$this->writeDebugLog("[debug] checking isuser for ". $sUser."@".$aCommand[2]);
161 161
 
162
-		// If the hostnames doesn't match, we try to check remotely
163
-		if ($a->get_hostname() != $aCommand[2])
164
-			$found = $this->check_user($aCommand[2], $aCommand[1], true);
165
-		else {
162
+		// Does the hostname match? So we try directly
163
+		if ($a->get_hostname() == $aCommand[2]) {
166 164
 			$sQuery = "SELECT `uid` FROM `user` WHERE `nickname`='".dbesc($sUser)."'";
167 165
 			$this->writeDebugLog("[debug] using query ". $sQuery);
168 166
 			$r = q($sQuery);
169 167
 			$found = dbm::is_result($r);
168
+		} else {
169
+			$found = false;
170
+		}
171
+
172
+		// If the hostnames doesn't match or there is some failure, we try to check remotely
173
+		if (!$found) {
174
+			$found = $this->check_user($aCommand[2], $aCommand[1], true);
170 175
 		}
171 176
 
172 177
 		if ($found) {
@@ -227,10 +232,8 @@ class exAuth {
227 232
 		$sUser = str_replace(array("%20", "(a)"), array(" ", "@"), $aCommand[1]);
228 233
 		$this->writeDebugLog("[debug] doing auth for ".$sUser."@".$aCommand[2]);
229 234
 
230
-		// If the hostnames doesn't match, we try to authenticate remotely
231
-		if ($a->get_hostname() != $aCommand[2])
232
-			$Error = !$this->check_credentials($aCommand[2], $aCommand[1], $aCommand[3], true);
233
-		else {
235
+		// Does the hostname match? So we try directly
236
+		if ($a->get_hostname() == $aCommand[2]) {
234 237
 			$sQuery = "SELECT `uid`, `password` FROM `user` WHERE `nickname`='".dbesc($sUser)."'";
235 238
 			$this->writeDebugLog("[debug] using query ". $sQuery);
236 239
 			if ($oResult = q($sQuery)) {
@@ -246,6 +249,13 @@ class exAuth {
246 249
 				$this->writeLog("[exAuth] got password ".$oConfig[0]["v"]);
247 250
 				$Error = ($aCommand[3] != $oConfig[0]["v"]);
248 251
 			}
252
+		} else {
253
+			$Error = true;
254
+		}
255
+
256
+		// If the hostnames doesn't match or there is some failure, we try to check remotely
257
+		if ($Error) {
258
+			$Error = !$this->check_credentials($aCommand[2], $aCommand[1], $aCommand[3], true);
249 259
 		}
250 260
 
251 261
 		if ($Error) {

Loading…
Cancel
Save