Commit 3ba59e98 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

Small fixes for sonarqube

Showing with 40 additions and 61 deletions
+40 -61
...@@ -20,20 +20,20 @@ ...@@ -20,20 +20,20 @@
*/ */
function smarty_function_msgPool($params, &$smarty) function smarty_function_msgPool($params, &$smarty)
{ {
if(class_available("msgPool") && isset($params['type'])){ if (class_available('msgPool') && isset($params['type'])) {
$parameter = array(); $parameter = array();
foreach($params as $para => $value){ foreach ($params as $para => $value) {
if(!preg_match("/^type$/i",$para)){ if (!preg_match('/^type$/i', $para)) {
$parameter[$para] = $value; $parameter[$para] = $value;
} }
} }
if(is_callable("msgPool::".$params['type'])){ if (is_callable('msgPool::'.$params['type'])) {
echo call_user_func_array(array("msgPool",$params['type']), $parameter); echo call_user_func_array(array('msgPool',$params['type']), $parameter);
}else{ } else {
trigger_error("Unknown msgPool function ".$params['type']); trigger_error('Unknown msgPool function '.$params['type']);
} }
}else{ } else {
trigger_error("Unknown class msgPool."); trigger_error('Unknown class msgPool.');
} }
} }
?> ?>
...@@ -45,13 +45,7 @@ class passwordMethodsha extends passwordMethod ...@@ -45,13 +45,7 @@ class passwordMethodsha extends passwordMethod
*/ */
function is_available() function is_available()
{ {
if (function_exists('sha1')) { return (function_exists('sha1') || function_exists('mhash'));
return TRUE;
} elseif (function_exists('mhash')) {
return TRUE;
} else {
return FALSE;
}
} }
/*! /*!
...@@ -62,11 +56,11 @@ class passwordMethodsha extends passwordMethod ...@@ -62,11 +56,11 @@ class passwordMethodsha extends passwordMethod
function generate_hash($password) function generate_hash($password)
{ {
if (function_exists('sha1')) { if (function_exists('sha1')) {
$hash = "{SHA}" . base64_encode(pack("H*", sha1($password))); $hash = '{SHA}' . base64_encode(pack('H*', sha1($password)));
} elseif (function_exists('mhash')) { } elseif (function_exists('mhash')) {
$hash = "{SHA}" . base64_encode(mHash(MHASH_SHA1, $password)); $hash = '{SHA}' . base64_encode(mHash(MHASH_SHA1, $password));
} else { } else {
msg_dialog::display(_("Configuration error"), msgPool::missingext("mhash"), ERROR_DIALOG); msg_dialog::display(_('Configuration error'), msgPool::missingext('mhash'), ERROR_DIALOG);
return FALSE; return FALSE;
} }
...@@ -78,7 +72,7 @@ class passwordMethodsha extends passwordMethod ...@@ -78,7 +72,7 @@ class passwordMethodsha extends passwordMethod
*/ */
static function get_hash_name() static function get_hash_name()
{ {
return "sha"; return 'sha';
} }
} }
?> ?>
...@@ -45,13 +45,7 @@ class passwordMethodssha extends passwordMethod ...@@ -45,13 +45,7 @@ class passwordMethodssha extends passwordMethod
*/ */
function is_available() function is_available()
{ {
if (function_exists("sha1")) { return (function_exists('sha1') || function_exists('mhash'));
return TRUE;
} elseif (function_exists("mhash")) {
return TRUE;
} else {
return FALSE;
}
} }
/*! /*!
...@@ -61,16 +55,16 @@ class passwordMethodssha extends passwordMethod ...@@ -61,16 +55,16 @@ class passwordMethodssha extends passwordMethod
*/ */
function generate_hash($pwd) function generate_hash($pwd)
{ {
if (function_exists("sha1")) { if (function_exists('sha1')) {
$salt = substr(pack("h*", md5(mt_rand())), 0, 8); $salt = substr(pack('h*', md5(mt_rand())), 0, 8);
$salt = substr(pack("H*", sha1($salt.$pwd)), 0, 4); $salt = substr(pack('H*', sha1($salt.$pwd)), 0, 4);
$pwd = "{SSHA}".base64_encode(pack("H*", sha1($pwd.$salt)).$salt); $pwd = '{SSHA}'.base64_encode(pack('H*', sha1($pwd.$salt)).$salt);
return $pwd; return $pwd;
} elseif (function_exists("mhash")) { } elseif (function_exists('mhash')) {
$salt = mhash_keygen_s2k(MHASH_SHA1, $pwd, substr(pack("h*", md5(mt_rand())), 0, 8), 4); $salt = mhash_keygen_s2k(MHASH_SHA1, $pwd, substr(pack('h*', md5(mt_rand())), 0, 8), 4);
$pwd = "{SSHA}".base64_encode(mhash(MHASH_SHA1, $pwd.$salt).$salt); $pwd = '{SSHA}'.base64_encode(mhash(MHASH_SHA1, $pwd.$salt).$salt);
} else { } else {
msg_dialog::display(_("Configuration error"), msgPool::missingext("mhash"), ERROR_DIALOG); msg_dialog::display(_('Configuration error'), msgPool::missingext('mhash'), ERROR_DIALOG);
return FALSE; return FALSE;
} }
return $pwd; return $pwd;
...@@ -81,12 +75,12 @@ class passwordMethodssha extends passwordMethod ...@@ -81,12 +75,12 @@ class passwordMethodssha extends passwordMethod
$hash = base64_decode(substr($hash, 6)); $hash = base64_decode(substr($hash, 6));
$salt = substr($hash, 20); $salt = substr($hash, 20);
$hash = substr($hash, 0, 20); $hash = substr($hash, 0, 20);
if (function_exists("sha1")) { if (function_exists('sha1')) {
$nhash = pack("H*", sha1($pwd . $salt)); $nhash = pack('H*', sha1($pwd . $salt));
} elseif (function_exists("mhash")) { } elseif (function_exists('mhash')) {
$nhash = mhash(MHASH_SHA1, $pwd.$salt); $nhash = mhash(MHASH_SHA1, $pwd.$salt);
} else { } else {
msg_dialog::display(_("Configuration error"), msgPool::missingext("mhash"), ERROR_DIALOG); msg_dialog::display(_('Configuration error'), msgPool::missingext('mhash'), ERROR_DIALOG);
return FALSE; return FALSE;
} }
return ($nhash == $hash); return ($nhash == $hash);
...@@ -97,7 +91,7 @@ class passwordMethodssha extends passwordMethod ...@@ -97,7 +91,7 @@ class passwordMethodssha extends passwordMethod
*/ */
static function get_hash_name() static function get_hash_name()
{ {
return "ssha"; return 'ssha';
} }
} }
?> ?>
...@@ -920,21 +920,12 @@ class simplePlugin extends plugin ...@@ -920,21 +920,12 @@ class simplePlugin extends plugin
$infos = pluglist::pluginInfos($tabclass); $infos = pluglist::pluginInfos($tabclass);
foreach ($infos['plForeignRefs'] as $field => $refs) { foreach ($infos['plForeignRefs'] as $field => $refs) {
if (preg_match('/^handle_/', $mode)) { if (preg_match('/^handle_/', $mode)) {
if ($newdn !== NULL) { if (($newdn !== NULL) && ($field != 'dn') && ($mode == 'handle_move')) {
// Move action // Move action, ignore other fields than dn
if (($field != 'dn') && ($mode == 'handle_move')) { continue;
// We only change dn } elseif (($newdn === NULL) && ($olddn === NULL) && (($field == 'dn') || (!$this->attributeHaveChanged($field)))) {
continue; // Edit action, ignore dn changes or attributes which did not change
} continue;
} elseif ($olddn === NULL) {
// Edit action
if ($field == 'dn') {
// dn did not change
continue;
} elseif (!$this->attributeHaveChanged($field)) {
// only look at changed attributes
continue;
}
} }
// else = delete action, all fields are concerned, nothing to do here // else = delete action, all fields are concerned, nothing to do here
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment