Commit 913a0a3f authored by Côme Bernigaud's avatar Côme Bernigaud Committed by Benoit Mortier
Browse files

Fixes: #2595 The code should follow code guidelines

parent b6b41003
......@@ -613,7 +613,6 @@ function ldap_login_user ($username, $password)
{
global $config;
/* look through the entire ldap */
$ldap = $config->get_ldap_link();
if (!$ldap->success()) {
......@@ -647,25 +646,22 @@ function ldap_login_user ($username, $password)
$filter = "(&(|".$filter.")(objectClass=gosaAccount))";
$ldap->search($filter, $tmp);
/* get results, only a count of 1 is valid */
switch ($ldap->count()) {
/* user not found */
case 0:
return NULL;
/* valid uniq user */
/* valid uniq user */
case 1:
break;
/* found more than one matching id */
/* found more than one matching id */
default:
msg_dialog::display(_("Internal error"), _("Username / UID is not unique inside the LDAP tree. Please contact your Administrator."), FATAL_ERROR_DIALOG);
return NULL;
}
/* LDAP schema is not case sensitive. Perform additional check. */
$attrs = $ldap->fetch();
$success = FALSE;
......@@ -678,7 +674,6 @@ function ldap_login_user ($username, $password)
return FALSE;
}
/* got user dn, fill acl's */
$ui = new userinfo($config, $ldap->getDN());
$ui->username = $attrs['uid'][0];
......@@ -689,7 +684,6 @@ function ldap_login_user ($username, $password)
return NULL;
}
/* password check, bind as user with supplied password */
$ldap->disconnect();
$ldap = new LDAP($ui->dn, $password, $config->current['SERVER'],
......@@ -701,11 +695,9 @@ function ldap_login_user ($username, $password)
return NULL;
}
/* Username is set, load subtreeACL's now */
$ui->loadACL();
return $ui;
}
......
......@@ -38,7 +38,7 @@ class passwordMethodClear extends passwordMethod
*
* \param string $config
*/
function passwordMethodClear($config)
function __construct($config)
{
}
......@@ -49,7 +49,7 @@ class passwordMethodClear extends passwordMethod
*/
function is_available()
{
return true;
return TRUE;
}
/*!
......@@ -71,6 +71,4 @@ class passwordMethodClear extends passwordMethod
}
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>
......@@ -37,7 +37,7 @@ class passwordMethodCrypt extends passwordMethod
*
* \param string $config
*/
function passwordMethodCrypt($config)
function __construct($config)
{
}
......@@ -48,10 +48,10 @@ class passwordMethodCrypt extends passwordMethod
*/
function is_available()
{
if(function_exists("crypt")){
return true;
}else{
return false;
if (function_exists("crypt")) {
return TRUE;
} else {
return FALSE;
}
}
......@@ -62,7 +62,7 @@ class passwordMethodCrypt extends passwordMethod
*/
function create_template_hash($attrs)
{
return($this->generate_hash('N0T$3T4N0W').'N0T$3T4N0W');
return $this->generate_hash('N0T$3T4N0W').'N0T$3T4N0W';
}
/*!
......@@ -72,21 +72,21 @@ class passwordMethodCrypt extends passwordMethod
*/
function generate_hash($pwd)
{
if ($this->hash == "crypt/standard-des"){
if ($this->hash == "crypt/standard-des") {
$salt = "";
for ($i = 0; $i < 2; $i++) {
$salt .= get_random_char();
}
}
if ($this->hash == "crypt/enhanced-des"){
if ($this->hash == "crypt/enhanced-des") {
$salt = "_";
for ($i = 0; $i < 8; $i++) {
$salt .= get_random_char();
}
}
if ($this->hash == "crypt/md5"){
if ($this->hash == "crypt/md5") {
$salt = "\$1\$";
for ($i = 0; $i < 8; $i++) {
$salt .= get_random_char();
......@@ -94,7 +94,7 @@ class passwordMethodCrypt extends passwordMethod
$salt .= "\$";
}
if ($this->hash == "crypt/blowfish"){
if ($this->hash == "crypt/blowfish") {
$salt = "\$2a\$07\$";
for ($i = 0; $i < CRYPT_SALT_LENGTH; $i++) {
$salt .= get_random_char();
......@@ -102,7 +102,7 @@ class passwordMethodCrypt extends passwordMethod
$salt .= "\$";
}
if ($this->hash == "crypt/sha-256"){
if ($this->hash == "crypt/sha-256") {
$salt = "\$5\$";
for ($i = 0; $i < 16; $i++) {
$salt .= get_random_char();
......@@ -110,7 +110,7 @@ class passwordMethodCrypt extends passwordMethod
$salt .= "\$";
}
if ($this->hash == "crypt/sha-512"){
if ($this->hash == "crypt/sha-512") {
$salt = "\$6\$";
for ($i = 0; $i < 16; $i++) {
$salt .= get_random_char();
......@@ -126,29 +126,29 @@ class passwordMethodCrypt extends passwordMethod
*/
static function get_hash_name()
{
$hashes= array();
$hashes = array();
if (CRYPT_STD_DES == 1) {
$hashes[]= "crypt/standard-des";
$hashes[] = "crypt/standard-des";
}
if (CRYPT_EXT_DES == 1) {
$hashes[]= "crypt/enhanced-des";
$hashes[] = "crypt/enhanced-des";
}
if (CRYPT_MD5 == 1) {
$hashes[]= "crypt/md5";
$hashes[] = "crypt/md5";
}
if (CRYPT_BLOWFISH == 1) {
$hashes[]= "crypt/blowfish";
$hashes[] = "crypt/blowfish";
}
if (CRYPT_SHA256 == 1) {
$hashes[]= "crypt/sha-256";
$hashes[] = "crypt/sha-256";
}
if (CRYPT_SHA512 == 1) {
$hashes[]= "crypt/sha-512";
$hashes[] = "crypt/sha-512";
}
return $hashes;
......@@ -193,8 +193,5 @@ class passwordMethodCrypt extends passwordMethod
return "";
}
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>
......@@ -37,7 +37,7 @@ class passwordMethodMd5 extends passwordMethod
*
* \param string $config
*/
function passwordMethodMd5($config)
function __construct($config)
{
}
......@@ -48,10 +48,10 @@ class passwordMethodMd5 extends passwordMethod
*/
function is_available()
{
if (function_exists('md5')){
return(true);
}else{
return false;
if (function_exists('md5')) {
return TRUE;
} else {
return FALSE;
}
}
......@@ -72,8 +72,5 @@ class passwordMethodMd5 extends passwordMethod
{
return "md5";
}
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>
......@@ -39,14 +39,14 @@ class passwordMethodsasl extends passwordMethod {
*
* \param string $dn The DN
*/
function __construct($config, $dn="")
function __construct($config, $dn = "")
{
if ($dn == "" || $dn == "new") {
return;
}
$this->realm = trim($config->get_cfg_value('saslRealm',""));
$this->exop = trim($config->get_cfg_value('saslExop',""));
$this->realm = trim($config->get_cfg_value('saslRealm', ""));
$this->exop = trim($config->get_cfg_value('saslExop', ""));
if (empty($this->realm) && empty($this->exop)) {
msg_dialog::display(_("Error"), msgPool::cmdnotfound("saslRealm or saslExop", _("SASL")), ERROR_DIALOG);
}
......@@ -60,7 +60,7 @@ class passwordMethodsasl extends passwordMethod {
$attrs = $ldap->fetch();
$this->uid = $attrs[$attr][0];
} else {
msg_dialog::display(_("Error"), sprintf(_("Cannot change password, unknown user '%s'"),$dn), ERROR_DIALOG);
msg_dialog::display(_("Error"), sprintf(_("Cannot change password, unknown user '%s'"), $dn), ERROR_DIALOG);
}
}
......@@ -106,6 +106,4 @@ class passwordMethodsasl extends passwordMethod {
return FALSE;
}
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>
......@@ -36,7 +36,7 @@ class passwordMethodsha extends passwordMethod
*
* \param string $config
*/
function passwordMethodsha($config)
function __construct($config)
{
}
......@@ -47,12 +47,12 @@ class passwordMethodsha extends passwordMethod
*/
function is_available()
{
if (function_exists('sha1')){
return(true);
}elseif(function_exists('mhash')){
return true;
}else{
return false;
if (function_exists('sha1')) {
return TRUE;
} elseif (function_exists('mhash')) {
return TRUE;
} else {
return FALSE;
}
}
......@@ -64,12 +64,12 @@ class passwordMethodsha extends passwordMethod
function generate_hash($password)
{
if (function_exists('sha1')) {
$hash = "{SHA}" . base64_encode(pack("H*",sha1($password)));
}elseif (function_exists('mhash')) {
$hash = "{SHA}" . base64_encode(pack("H*", sha1($password)));
} elseif (function_exists('mhash')) {
$hash = "{SHA}" . base64_encode(mHash(MHASH_SHA1, $password));
}else{
} else {
msg_dialog::display(_("Configuration error"), msgPool::missingext("mhash"), ERROR_DIALOG);
return false;
return FALSE;
}
return $hash;
......@@ -82,8 +82,5 @@ class passwordMethodsha extends passwordMethod
{
return "sha";
}
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>
......@@ -36,7 +36,7 @@ class passwordMethodsmd5 extends passwordMethod
*
* \param string $config
*/
function passwordMethodsmd5($config)
function __construct($config)
{
}
......@@ -47,10 +47,10 @@ class passwordMethodsmd5 extends passwordMethod
*/
function is_available()
{
if ((!function_exists('md5'))){
return false;
}else{
return true;
if ((!function_exists('md5'))) {
return FALSE;
} else {
return TRUE;
}
}
......@@ -61,10 +61,10 @@ class passwordMethodsmd5 extends passwordMethod
*/
function generate_hash($pwd)
{
mt_srand(microtime()* 10000000);
$salt0= substr(pack("h*", md5(mt_rand())), 0, 8);
$salt = substr(pack("H*", md5($salt0 . $pwd)), 0, 4);
$hash = "{SMD5}".base64_encode(pack("H*",md5($pwd . $salt)) . $salt);
mt_srand(microtime() * 10000000);
$salt0 = substr(pack("h*", md5(mt_rand())), 0, 8);
$salt = substr(pack("H*", md5($salt0 . $pwd)), 0, 4);
$hash = "{SMD5}".base64_encode(pack("H*", md5($pwd . $salt)) . $salt);
return $hash;
}
......@@ -75,8 +75,5 @@ class passwordMethodsmd5 extends passwordMethod
{
return "smd5";
}
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>
......@@ -36,7 +36,7 @@ class passwordMethodssha extends passwordMethod
*
* \param string $config
*/
function passwordMethodssha($config)
function __construct($config)
{
}
......@@ -47,12 +47,12 @@ class passwordMethodssha extends passwordMethod
*/
function is_available()
{
if(function_exists("sha1")){
return true;
}elseif(function_exists("mhash")){
return true;
}else{
return false;
if (function_exists("sha1")) {
return TRUE;
} elseif (function_exists("mhash")) {
return TRUE;
} else {
return FALSE;
}
}
......@@ -64,16 +64,16 @@ class passwordMethodssha extends passwordMethod
function generate_hash($pwd)
{
if (function_exists("sha1")) {
$salt= substr(pack("h*", md5(mt_rand())), 0, 8);
$salt= substr(pack("H*", sha1($salt.$pwd)), 0, 4);
$pwd= "{SSHA}".base64_encode(pack("H*", sha1($pwd.$salt)).$salt);
$salt = substr(pack("h*", md5(mt_rand())), 0, 8);
$salt = substr(pack("H*", sha1($salt.$pwd)), 0, 4);
$pwd = "{SSHA}".base64_encode(pack("H*", sha1($pwd.$salt)).$salt);
return $pwd;
} elseif(function_exists("mhash")) {
$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);
} elseif (function_exists("mhash")) {
$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);
} else {
msg_dialog::display(_("Configuration error"), msgPool::missingext("mhash"), ERROR_DIALOG);
return(false);
return FALSE;
}
return $pwd;
}
......@@ -85,8 +85,5 @@ class passwordMethodssha extends passwordMethod
{
return "ssha";
}
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>
......@@ -43,7 +43,7 @@ class passwordMethod
*
* \param string $dn The DN
*/
function passwordMethod($config, $dn = "")
function __construct($config, $dn = "")
{
}
......
Markdown is supported
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