Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ldap authentication: add an option not to cache passwords #713

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions config_defaults_inc.php
Expand Up @@ -1968,6 +1968,14 @@
*/
$g_ldap_simulation_file_path = '';

/**
* Cache passwords in LDAP. Disabling this will mean that you cannot log into
* mantis if LDAP is down
* @global boolean $g_ldap_cache_passwords
*/

$g_ldap_cache_passwords = ON;

###################
# Status Settings #
###################
Expand Down
5 changes: 4 additions & 1 deletion core/authentication_api.php
Expand Up @@ -201,15 +201,18 @@ function auth_auto_create_user( $p_username, $p_password ) {

if( $t_login_method == BASIC_AUTH ) {
$t_auto_create = true;
$t_auto_create_password = md5( $p_password );
} else if( $t_login_method == LDAP && ldap_authenticate_by_username( $p_username, $p_password ) ) {
$t_auto_create = true;
$t_cache_password = config_get( 'ldap_cache_passwords' );
$t_auto_create_password = $t_cache_password ? md5( $p_password ) : 'external-password';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use auto-generated password (instead of 'external-password') so that the password can't be guessed if auth method is changed for example. I would use a model like random cookie generation we already do.

} else {
$t_auto_create = false;
}

if( $t_auto_create ) {
# attempt to create the user
$t_cookie_string = user_create( $p_username, md5( $p_password ) );
$t_cookie_string = user_create( $p_username, $t_auto_create_password );
if( $t_cookie_string === false ) {
# it didn't work
return false;
Expand Down
5 changes: 4 additions & 1 deletion core/ldap_api.php
Expand Up @@ -379,7 +379,10 @@ function ldap_authenticate_by_username( $p_username, $p_password ) {

if( false !== $t_user_id ) {

$t_fields_to_update = array('password' => md5( $p_password ));
$t_fields_to_update = array();
if( ON == config_get( 'ldap_cache_passwords' ) ) {
$t_fields_to_update['password'] = md5( $p_password );
}

if( ON == config_get( 'use_ldap_realname' ) ) {
$t_fields_to_update['realname'] = ldap_realname( $t_user_id );
Expand Down
10 changes: 10 additions & 0 deletions docbook/Admin_Guide/en-US/config/auth.xml
Expand Up @@ -282,6 +282,16 @@ ldaps://ldap.example.com:3269/
</listitem>
</varlistentry>

<varlistentry>
<term>$g_ldap_cache_passwords</term>

<listitem>
<para>Cache md5sums of passwords in the mantis database to
allow logins even if ldap is down. Defaults to
</para>
</listitem>
</varlistentry>

<varlistentry>
<term>$g_ldap_port</term>

Expand Down