]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #3032 from annando/1612-auth-ejabber
authorTobias Diekershoff <tobias.diekershoff@gmx.net>
Tue, 20 Dec 2016 14:45:18 +0000 (15:45 +0100)
committerGitHub <noreply@github.com>
Tue, 20 Dec 2016 14:45:18 +0000 (15:45 +0100)
Workaround for vanished database connections while authentication

1  2 
include/auth_ejabberd.php

index e12da35ef1755057b37e78e26e2069ba50fa7035,01e3389427cf69ef4d8e48ba23dc05a06bdde529..8ee3af8e2be23148342d2eb84bcffb6707ba8da4
@@@ -146,7 -146,7 +146,7 @@@ class exAuth 
         * @param array $aCommand The command array
         */
        private function isuser($aCommand) {
 -              global $a;
 +              $a = get_app();
  
                // Check if there is a username
                if (!isset($aCommand[1])) {
                $sUser = str_replace(array("%20", "(a)"), array(" ", "@"), $aCommand[1]);
                $this->writeDebugLog("[debug] checking isuser for ". $sUser."@".$aCommand[2]);
  
-               // If the hostnames doesn't match, we try to check remotely
-               if ($a->get_hostname() != $aCommand[2])
-                       $found = $this->check_user($aCommand[2], $aCommand[1], true);
-               else {
+               // Does the hostname match? So we try directly
+               if ($a->get_hostname() == $aCommand[2]) {
                        $sQuery = "SELECT `uid` FROM `user` WHERE `nickname`='".dbesc($sUser)."'";
                        $this->writeDebugLog("[debug] using query ". $sQuery);
                        $r = q($sQuery);
                        $found = dbm::is_result($r);
+               } else {
+                       $found = false;
+               }
+               // If the hostnames doesn't match or there is some failure, we try to check remotely
+               if (!$found) {
+                       $found = $this->check_user($aCommand[2], $aCommand[1], true);
                }
  
                if ($found) {
         * @param array $aCommand The command array
         */
        private function auth($aCommand) {
 -              global $a;
 +              $a = get_app();
  
                // check user authentication
                if (sizeof($aCommand) != 4) {
                $sUser = str_replace(array("%20", "(a)"), array(" ", "@"), $aCommand[1]);
                $this->writeDebugLog("[debug] doing auth for ".$sUser."@".$aCommand[2]);
  
-               // If the hostnames doesn't match, we try to authenticate remotely
-               if ($a->get_hostname() != $aCommand[2])
-                       $Error = !$this->check_credentials($aCommand[2], $aCommand[1], $aCommand[3], true);
-               else {
+               // Does the hostname match? So we try directly
+               if ($a->get_hostname() == $aCommand[2]) {
                        $sQuery = "SELECT `uid`, `password` FROM `user` WHERE `nickname`='".dbesc($sUser)."'";
                        $this->writeDebugLog("[debug] using query ". $sQuery);
                        if ($oResult = q($sQuery)) {
                                $this->writeLog("[exAuth] got password ".$oConfig[0]["v"]);
                                $Error = ($aCommand[3] != $oConfig[0]["v"]);
                        }
+               } else {
+                       $Error = true;
+               }
+               // If the hostnames doesn't match or there is some failure, we try to check remotely
+               if ($Error) {
+                       $Error = !$this->check_credentials($aCommand[2], $aCommand[1], $aCommand[3], true);
                }
  
                if ($Error) {