diff options
| author | alec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2011-02-10 14:42:18 +0000 |
|---|---|---|
| committer | alec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2011-02-10 14:42:18 +0000 |
| commit | b5a41f433545a91ab821ca3044cc41548db61344 (patch) | |
| tree | 963aa06e240b88cf4a23da71099553537b89690d /plugins/password | |
| parent | aab4abc3012a65213981d98c90edefbcc5f672e8 (diff) | |
- ldap/ldap_simple drivers: use password_ldap_samba_pwattr/password_ldap_samba_lchattr
instead of password_ldap_samba option
git-svn-id: https://svn.roundcube.net/trunk@4529 208e9e7b-5314-0410-a742-e7e81cd9613c
Diffstat (limited to 'plugins/password')
| -rw-r--r-- | plugins/password/config.inc.php.dist | 11 | ||||
| -rw-r--r-- | plugins/password/drivers/ldap.php | 57 | ||||
| -rw-r--r-- | plugins/password/drivers/ldap_simple.php | 70 | ||||
| -rw-r--r-- | plugins/password/package.xml | 2 |
4 files changed, 101 insertions, 39 deletions
diff --git a/plugins/password/config.inc.php.dist b/plugins/password/config.inc.php.dist index 54e9e51c6..086fc502f 100644 --- a/plugins/password/config.inc.php.dist +++ b/plugins/password/config.inc.php.dist @@ -195,8 +195,15 @@ $rcmail_config['password_ldap_force_replace'] = true; // Whenever the password is changed, the attribute will be updated if set (e.g. shadowLastChange) $rcmail_config['password_ldap_lchattr'] = ''; -// Also try to update Samba password attributes: sambaNTPassword and sambaPwdLastSet -$rcmail_config['password_ldap_samba'] = false; +// LDAP Samba password attribute, e.g. sambaNTPassword +// Name of the LDAP's Samba attribute used for storing user password +$rcmail_config['password_ldap_samba_pwattr'] = ''; + +// LDAP Samba Password Last Change Date attribute, e.g. sambaPwdLastSet +// Some places use an attribute to store the date of the last password change +// The date is meassured in "seconds since epoch" (an integer value) +// Whenever the password is changed, the attribute will be updated if set +$rcmail_config['password_ldap_samba_lchattr'] = ''; // DirectAdmin Driver options diff --git a/plugins/password/drivers/ldap.php b/plugins/password/drivers/ldap.php index e4d91fe1b..a18f349d7 100644 --- a/plugins/password/drivers/ldap.php +++ b/plugins/password/drivers/ldap.php @@ -62,43 +62,59 @@ function password_save($curpass, $passwd) return PASSWORD_CONNECT_ERROR; } - // Crypting new password - $newCryptedPassword = hashPassword($passwd, $rcmail->config->get('password_ldap_encodage')); - if (!$newCryptedPassword) { + $crypted_pass = hashPassword($passwd, $rcmail->config->get('password_ldap_encodage')); + $force = $rcmail->config->get('password_ldap_force_replace'); + $pwattr = $rcmail->config->get('password_ldap_pwattr'); + $lchattr = $rcmail->config->get('password_ldap_lchattr'); + $smbpwattr = $rcmail->config->get('password_ldap_samba_pwattr'); + $smblchattr = $rcmail->config->get('password_ldap_samba_lchattr'); + $samba = $rcmail->config->get('password_ldap_samba'); + + // Support password_ldap_samba option for backward compat. + if ($samba && !$smbpwattr) { + $smbpwattr = 'sambaNTPassword'; + $smblchattr = 'sambaPwdLastSet'; + } + + // Crypt new password + if (!$crypted_pass) { return PASSWORD_CRYPT_ERROR; } + // Crypt new samba password + if ($smbpwattr && !($samba_pass = hashPassword($passwd, 'samba'))) { + return PASSWORD_CRYPT_ERROR; + } + // Writing new crypted password to LDAP $userEntry = $ldap->getEntry($userDN); if (Net_LDAP2::isError($userEntry)) { return PASSWORD_CONNECT_ERROR; } - $pwattr = $rcmail->config->get('password_ldap_pwattr'); - $force = $rcmail->config->get('password_ldap_force_replace'); - - if (!$userEntry->replace(array($pwattr => $newCryptedPassword), $force)) { + if (!$userEntry->replace(array($pwattr => $crypted_pass), $force)) { return PASSWORD_CONNECT_ERROR; } // Updating PasswordLastChange Attribute if desired - if ($lchattr = $rcmail->config->get('password_ldap_lchattr')) { + if ($lchattr) { $current_day = (int)(time() / 86400); if (!$userEntry->replace(array($lchattr => $current_day), $force)) { return PASSWORD_CONNECT_ERROR; } } - if (Net_LDAP2::isError($userEntry->update())) { - return PASSWORD_CONNECT_ERROR; + // Update Samba password and last change fields + if ($smbpwattr) { + $userEntry->replace(array($smbpwattr => $samba_pass), $force); + } + // Update Samba password last change field + if ($smblchattr) { + $userEntry->replace(array($smblchattr => time()), $force); } - // Update Samba password fields, ignore errors if attributes are not found - if ($rcmail->config->get('password_ldap_samba')) { - $sambaNTPassword = hash('md4', rcube_charset_convert($passwd, RCMAIL_CHARSET, 'UTF-16LE')); - $userEntry->replace(array('sambaNTPassword' => $sambaNTPassword), $force); - $userEntry->replace(array('sambaPwdLastSet' => time()), $force); - $userEntry->update(); + if (Net_LDAP2::isError($userEntry->update())) { + return PASSWORD_CONNECT_ERROR; } // All done, no error @@ -253,6 +269,15 @@ function hashPassword( $passwordClear, $encodageType ) } break; + case 'samba': + if (function_exists('hash')) { + $cryptedPassword = hash('md4', rcube_charset_convert($password_clear, RCMAIL_CHARSET, 'UTF-16LE')); + } else { + /* Your PHP install does not have the hash() function */ + return false; + } + break; + case 'clear': default: $cryptedPassword = $passwordClear; diff --git a/plugins/password/drivers/ldap_simple.php b/plugins/password/drivers/ldap_simple.php index 67f53d091..482b7e56f 100644 --- a/plugins/password/drivers/ldap_simple.php +++ b/plugins/password/drivers/ldap_simple.php @@ -14,19 +14,19 @@ function password_save($curpass, $passwd) { $rcmail = rcmail::get_instance(); - /* Connect */ + // Connect if (!$ds = ldap_connect($rcmail->config->get('password_ldap_host'), $rcmail->config->get('password_ldap_port'))) { ldap_unbind($ds); return PASSWORD_CONNECT_ERROR; } - /* Set protocol version */ + // Set protocol version if (!ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, $rcmail->config->get('password_ldap_version'))) { ldap_unbind($ds); return PASSWORD_CONNECT_ERROR; } - /* Start TLS */ + // Start TLS if ($rcmail->config->get('password_ldap_starttls')) { if (!ldap_start_tls($ds)) { ldap_unbind($ds); @@ -34,7 +34,7 @@ function password_save($curpass, $passwd) } } - /* Build user DN */ + // Build user DN if ($user_dn = $rcmail->config->get('password_ldap_userDN_mask')) { $user_dn = ldap_simple_substitute_vars($user_dn); } else { @@ -46,7 +46,7 @@ function password_save($curpass, $passwd) return PASSWORD_CONNECT_ERROR; } - /* Connection method */ + // Connection method switch ($rcmail->config->get('password_ldap_method')) { case 'admin': $binddn = $rcmail->config->get('password_ldap_adminDN'); @@ -59,31 +59,51 @@ function password_save($curpass, $passwd) break; } - /* Bind */ - if (!ldap_bind($ds, $binddn, $bindpw)) { - ldap_unbind($ds); - return PASSWORD_CONNECT_ERROR; - } - /* Crypting new password */ $crypted_pass = ldap_simple_hash_password($passwd, $rcmail->config->get('password_ldap_encodage')); + $lchattr = $rcmail->config->get('password_ldap_lchattr'); + $pwattr = $rcmail->config->get('password_ldap_pwattr'); + $smbpwattr = $rcmail->config->get('password_ldap_samba_pwattr'); + $smblchattr = $rcmail->config->get('password_ldap_samba_lchattr'); + $samba = $rcmail->config->get('password_ldap_samba'); + + // Support password_ldap_samba option for backward compat. + if ($samba && !$smbpwattr) { + $smbpwattr = 'sambaNTPassword'; + $smblchattr = 'sambaPwdLastSet'; + } + + // Crypt new password if (!$crypted_pass) { - ldap_unbind($ds); return PASSWORD_CRYPT_ERROR; } - $entree[$rcmail->config->get('password_ldap_pwattr')] = $crypted_pass; + // Crypt new Samba password + if ($smbpwattr && !($samba_pass = ldap_simple_hash_password($passwd, 'samba'))) { + return PASSWORD_CRYPT_ERROR; + } - /* Updating PasswordLastChange Attribute if desired */ - if ($lchattr = $rcmail->config->get('password_ldap_lchattr')) { + // Bind + if (!ldap_bind($ds, $binddn, $bindpw)) { + ldap_unbind($ds); + return PASSWORD_CONNECT_ERROR; + } + + $entree[$pwattr] = $crypted_pass; + + // Update PasswordLastChange Attribute if desired + if ($lchattr) { $entree[$lchattr] = (int)(time() / 86400); } - /* Update Samba password fields */ - if ($smbattr = $rcmail->config->get('password_ldap_samba')) { - $sambaNTPassword = hash('md4', rcube_charset_convert($passwd, RCMAIL_CHARSET, 'UTF-16LE')); - $entree['sambaNTPassword'] = $sambaNTPassword; - $entree['sambaPwdLastSet'] = time(); + // Update Samba password + if ($smbpwattr) { + $entree[$smbpwattr] = $samba_pass; + } + + // Update Samba password last change + if ($smblchattr) { + $entree[$smblchattr] = time(); } if (!ldap_modify($ds, $user_dn, $entree)) { @@ -91,7 +111,7 @@ function password_save($curpass, $passwd) return PASSWORD_CONNECT_ERROR; } - /* All done, no error */ + // All done, no error ldap_unbind($ds); return PASSWORD_SUCCESS; } @@ -215,6 +235,14 @@ function ldap_simple_hash_password($password_clear, $encodage_type) return false; } break; + case 'samba': + if (function_exists('hash')) { + $crypted_password = hash('md4', rcube_charset_convert($password_clear, RCMAIL_CHARSET, 'UTF-16LE')); + } else { + /* Your PHP install does not have the hash() function */ + return false; + } + break; case 'clear': default: $crypted_password = $password_clear; diff --git a/plugins/password/package.xml b/plugins/password/package.xml index 2d5aaf2c0..dab44457d 100644 --- a/plugins/password/package.xml +++ b/plugins/password/package.xml @@ -37,6 +37,8 @@ - Fix extended error messages handling (#1487676) - Fix double request when clicking on Password tab in Firefox - Fix deprecated split() usage in xmail and directadmin drivers (#1487769) +- ldap/ldap_simple drivers: use password_ldap_samba_pwattr/password_ldap_samba_lchattr + instead of password_ldap_samba option </notes> <contents> <dir baseinstalldir="/" name="/"> |
