Some additional beautification

This commit is contained in:
Michael Vogel 2016-09-22 18:18:26 +00:00
parent abbf501602
commit 6fd54df940

View file

@ -152,29 +152,31 @@ class exAuth {
if (!isset($aCommand[1])) { if (!isset($aCommand[1])) {
$this->writeLog("[exAuth] invalid isuser command, no username given"); $this->writeLog("[exAuth] invalid isuser command, no username given");
fwrite(STDOUT, pack("nn", 2, 0)); fwrite(STDOUT, pack("nn", 2, 0));
} else { return;
// Now we check if the given user is valid }
$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 // Now we check if the given user is valid
if ($a->get_hostname() != $aCommand[2]) $sUser = str_replace(array("%20", "(a)"), array(" ", "@"), $aCommand[1]);
$found = $this->check_user($aCommand[2], $aCommand[1], true); $this->writeDebugLog("[debug] checking isuser for ". $sUser."@".$aCommand[2]);
else {
$sQuery = "SELECT `uid` FROM `user` WHERE `nickname`='".dbesc($sUser)."'"; // If the hostnames doesn't match, we try to check remotely
$this->writeDebugLog("[debug] using query ". $sQuery); if ($a->get_hostname() != $aCommand[2])
$r = q($sQuery); $found = $this->check_user($aCommand[2], $aCommand[1], true);
$found = dbm::is_result($r); else {
} $sQuery = "SELECT `uid` FROM `user` WHERE `nickname`='".dbesc($sUser)."'";
if ($found) { $this->writeDebugLog("[debug] using query ". $sQuery);
// The user is okay $r = q($sQuery);
$this->writeLog("[exAuth] valid user: ". $sUser); $found = dbm::is_result($r);
fwrite(STDOUT, pack("nn", 2, 1)); }
} else {
// The user isn't okay if ($found) {
$this->writeLog("[exAuth] invalid user: ". $sUser); // The user is okay
fwrite(STDOUT, pack("nn", 2, 0)); $this->writeLog("[exAuth] valid user: ". $sUser);
} fwrite(STDOUT, pack("nn", 2, 1));
} else {
// The user isn't okay
$this->writeLog("[exAuth] invalid user: ". $sUser);
fwrite(STDOUT, pack("nn", 2, 0));
} }
} }
@ -218,39 +220,41 @@ class exAuth {
if (sizeof($aCommand) != 4) { if (sizeof($aCommand) != 4) {
$this->writeLog("[exAuth] invalid auth command, data missing"); $this->writeLog("[exAuth] invalid auth command, data missing");
fwrite(STDOUT, pack("nn", 2, 0)); fwrite(STDOUT, pack("nn", 2, 0));
} else { return;
// We now check if the password match }
$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 // We now check if the password match
if ($a->get_hostname() != $aCommand[2]) $sUser = str_replace(array("%20", "(a)"), array(" ", "@"), $aCommand[1]);
$Error = !$this->check_credentials($aCommand[2], $aCommand[1], $aCommand[3], true); $this->writeDebugLog("[debug] doing auth for ".$sUser."@".$aCommand[2]);
else {
$sQuery = "SELECT `uid`, `password` FROM `user` WHERE `nickname`='".dbesc($sUser)."'"; // If the hostnames doesn't match, we try to authenticate remotely
$this->writeDebugLog("[debug] using query ". $sQuery); if ($a->get_hostname() != $aCommand[2])
if ($oResult = q($sQuery)) { $Error = !$this->check_credentials($aCommand[2], $aCommand[1], $aCommand[3], true);
$uid = $oResult[0]["uid"]; else {
$Error = ($oResult[0]["password"] != hash('whirlpool',$aCommand[3])); $sQuery = "SELECT `uid`, `password` FROM `user` WHERE `nickname`='".dbesc($sUser)."'";
} else { $this->writeDebugLog("[debug] using query ". $sQuery);
$this->writeLog("[MySQL] invalid query: ". $sQuery); if ($oResult = q($sQuery)) {
$Error = true; $uid = $oResult[0]["uid"];
$uid = -1; $Error = ($oResult[0]["password"] != hash('whirlpool',$aCommand[3]));
} } else {
if ($Error) { $this->writeLog("[MySQL] invalid query: ". $sQuery);
$oConfig = q("SELECT `v` FROM `pconfig` WHERE `uid` = %d AND `cat` = 'xmpp' AND `k`='password' LIMIT 1;", intval($uid)); $Error = true;
$this->writeLog("[exAuth] got password ".$oConfig[0]["v"]); $uid = -1;
$Error = ($aCommand[3] != $oConfig[0]["v"]);
}
} }
if ($Error) { if ($Error) {
$this->writeLog("[exAuth] authentification failed for user ".$sUser."@". $aCommand[2]); $oConfig = q("SELECT `v` FROM `pconfig` WHERE `uid` = %d AND `cat` = 'xmpp' AND `k`='password' LIMIT 1;", intval($uid));
fwrite(STDOUT, pack("nn", 2, 0)); $this->writeLog("[exAuth] got password ".$oConfig[0]["v"]);
} else { $Error = ($aCommand[3] != $oConfig[0]["v"]);
$this->writeLog("[exAuth] authentificated user ".$sUser."@".$aCommand[2]);
fwrite(STDOUT, pack("nn", 2, 1));
} }
} }
if ($Error) {
$this->writeLog("[exAuth] authentification failed for user ".$sUser."@". $aCommand[2]);
fwrite(STDOUT, pack("nn", 2, 0));
} else {
$this->writeLog("[exAuth] authentificated user ".$sUser."@".$aCommand[2]);
fwrite(STDOUT, pack("nn", 2, 1));
}
} }
/** /**