View Issue Details

IDProjectCategoryView StatusLast Update
0010230mantisbtldappublic2011-08-05 02:45
Reportertk Assigned Torombert  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionduplicate 
Product Version1.2.0a3 
Summary0010230: LDAP: ldap_email_from_username( $p_username ) cannot handle undefined email
Description

If e-mail is to be obtained from LDAP and for a user in LDAP e-mail is not defined submit issue will inidcate error since function ldap_email_from_username( $p_username ) in core/ldap_api.php does not handle this case correctly.

Problem is due to


$t_info = ldap_get_entries( $t_ds, $t_sr );
ldap_free_result( $t_sr );
ldap_unbind( $t_ds );

return $t_info[0]['mail'][0];


where the return value accesses an undefined array element. According to php error message we have in this case

t_info
Variable Value Type
count 0 integer

TagsNo tags attached.

Relationships

duplicate of 0012960 closedrombert Email / Realname lookups against LDAP spew warning when account is not in LDAP 
related to 0010944 closeddregad ldap_get_field_from_username does not properly check return value from ldap_get_entries 

Activities

tk

tk

2009-03-23 03:11

reporter   ~0021146

to consider: http://de3.php.net/manual/de/function.ldap-get-entries.php


Note: ldap_get_entries returns true even if no results are found, like this:

echo $entries=ldap_get_entries(...);

will print Array.

You have to check for number of row in the Array like this:

if($entries["count"]==0) return false;

Hope this helped someone...

tk

tk

2009-03-24 03:37

reporter   ~0021171

Last edited: 2009-03-24 03:37

I've worked out a solution now. I have


function ldap_email_from_username( $p_username ) {
$t_ldap_organization = config_get( 'ldap_organization' );
$t_ldap_root_dn = config_get( 'ldap_root_dn' );

$t_ldap_uid_field = config_get( 'ldap_uid_field', 'uid' );
$t_search_filter = "(&$t_ldap_organization($t_ldap_uid_field=$p_username))";
$t_search_attrs = array(
    $t_ldap_uid_field,
    'mail',
    'dn',
);

$t_ldap_mail ='';
$t_ds = ldap_connect_bind();

if( $t_ds ) {
    $t_sr = ldap_search( $t_ds, $t_ldap_root_dn, $t_search_filter, $t_search_attrs );

    if( $t_sr ) {
        $t_info = ldap_get_entries( $t_ds, $t_sr );
        if( ( $t_info ) && ( $t_info['count'] > 0) && ( array_key_exists( 'mail', $t_info[0] ) ) ) {
             $t_ldap_mail = $t_info[0]['mail'][0];
        }
    }
    ldap_free_result( $t_sr );
}
ldap_unbind( $t_ds );

return $t_ldap_mail;

}

The most important point is the sequence


array_key_exists( 'mail', $t_info[0] )

which masks off user accounts that have no mail attached.

tk

tk

2009-10-19 04:44

reporter   ~0023234

Last edited: 2009-11-02 02:12

Regrettably the problem still exists (I admit I have the error switches set to halt in case of php-problems).
As far as I can see the code has not been changed with respect to my findings -- please consider my proposal in the previous note.

I.e., I mean the sequence


$t_info = ldap_get_entries( $t_ds, $t_sr );
if( ( $t_info ) && ( $t_info['count'] > 0) && ( array_key_exists( 'mail',
$t_info[0] ) ) ) {
$t_ldap_mail = $t_info[0]['mail'][0];
}

tk

tk

2011-07-07 05:44

reporter   ~0029121

I've seen that the ldap.api code in my freshly installed mantis 1.2.5 has been greatly enhanced.
Yet I still see the problem.

In my setting, I query the users' email adresses via the LDAP api from our AD-server. I suppose that in case of a nonexisting data element the AD server returns someting like a void container, so that the error handlings rules in core/ldap.api, lines 259 and 265 are too weak:


258 # If no matches, return null.
259 if ( count( $t_info ) == 0 ) {
260 log_event( LOG_LDAP, "No matches found." );
261 return null;
262 }
263
264 # Make sure the requested field exists
265 if( array_key_exists( $p_field, $t_info[0] ) ) {

In debug mode I get for problematic the message that the second agument of the array_key_exists expression, i.e., $t_info[0], is NULL.
The following patch fixes the problem in my case:


265 if( ( array_key_exists( 0, $t_info ) ) && ( array_key_exists( $p_field, $t_info[0] ) ) ) {

i.e., checking that $t_info[0] actually exists.

dregad

dregad

2011-07-07 11:10

developer   ~0029125

Hi tk,

Did you have a look at 0012960 ? That issue was recently fixed (although after the release of 1.2.5) and seems quite similar to the problem you reported. If that's the case, you may want to download a nightly build of 1.2.x to test and confirm.

tk

tk

2011-07-08 02:09

reporter   ~0029127

Hi dregard,

yes, this is exactly what I've seen. I directly applied the patch attached to 0012960 and confirmed that this patch also works.
So anyone with higher access rights may mark this issue as a duplicate of 0012960 and close it as fixed in 1.2.5+

Thank you!

rombert

rombert

2011-07-08 07:57

reporter   ~0029133

Thanks for taking the time to look for duplicates and confirming that it works. Closing as requested.

Related Changesets

MantisBT: master-1.2.x d58b9ccf

2009-07-19 21:00

vboctor


Details Diff
Fixes 0010230: LDAP: ldap_email_from_username( ) cannot handle undefined email. Affected Issues
0010230
mod - core/ldap_api.php Diff File

MantisBT: master 0f11c6f3

2009-07-19 21:00

vboctor


Details Diff
Fixes 0010230: LDAP: ldap_email_from_username( ) cannot handle undefined email. Affected Issues
0010230
mod - core/ldap_api.php Diff File