From 342ab2170ce5a09fd665db70b4d2c5a6be75ca60 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Thu, 13 Aug 2015 02:56:58 +0000 Subject: [PATCH] fixed a bug in post-commit of not handling ldap_auth_mode 2 properly --- codepot/etc/post-commit.in | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/codepot/etc/post-commit.in b/codepot/etc/post-commit.in index 89085e01..d7257b41 100644 --- a/codepot/etc/post-commit.in +++ b/codepot/etc/post-commit.in @@ -205,8 +205,37 @@ sub get_author_email_ldap return (-1, undef); } - my $f_basedn = format_string ($cfg->{ldap_userid_format}, $userid, ''); - my $f_filter = '(' . $cfg->{ldap_mail_attribute_name} . '=*)'; + + my $f_basedn = ''; + my $f_filter = ''; + + if ($cfg->{ldap_auth_mode} == 2) + { + $f_basedn = format_string ($cfg->{ldap_userid_search_base}, $userid, ''); + $f_filter = format_string ($cfg->{ldap_userid_search_filter}, $userid, ''); + + $res = $ldap->search (base => $f_basedn, scope => 'sub', filter => $f_filter); + if ($res->code != LDAP_SUCCESS) + { + $ldap->unbind(); + return (-1, undef); + } + + my $entry = $res->entry(0); # get the first entry only + if (!defined($entry)) + { + $ldap->unbind(); + return (0, undef); + } + + $f_basedn = $entry->dn (); + } + else + { + $f_basedn = format_string ($cfg->{ldap_userid_format}, $userid, ''); + } + + $f_filter = '(' . $cfg->{ldap_mail_attribute_name} . '=*)'; $res = $ldap->search (base => $f_basedn, scope => 'sub', filter => $f_filter); if ($res->code != LDAP_SUCCESS)