Bug 323272 - Querying a Microsoft Exchange's Active Directory via LDAP is extremely slow
Summary: Querying a Microsoft Exchange's Active Directory via LDAP is extremely slow
Status: RESOLVED FIXED
Alias: None
Product: kmail2
Classification: Unclassified
Component: composer (show other bugs)
Version: Git (master)
Platform: Compiled Sources Linux
: NOR normal (vote)
Target Milestone: ---
Assignee: kdepim bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-07 22:32 UTC by Thiago Macieira
Modified: 2013-08-08 10:49 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 4.11.1


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thiago Macieira 2013-08-07 22:32:50 UTC
Whenever an LDAP query is sent to a Microsoft Exchange's Active Directory via LDAP, the results are extremely slow to come. This is definitely an Exchange bug -- it appears to timeout in searching and then replies after 120 seconds. However, there's a specific field of the LDAP query that triggers it and it can be worked around.

In (kdepim) libkdepim/ldap/ldapclientsearch.cpp, we have:
  const QString filter = QString( "&(|(objectclass=person)(objectclass=groupOfNames)(mail=*))"
                                  "(|(cn=%1*)(mail=%2*)(mail=*@%3*)(givenName=%4*)(sn=%5*))" )
                                .arg( d->mSearchText ).arg( d->mSearchText )
                                .arg( d->mSearchText ).arg( d->mSearchText ).arg( d->mSearchText );

The field that causes the slowdown is the (mail=*@%3*) part. In fact, it appears that Exchange is slow for any query that starts with * in the field. If that part of the query is removed, the server replies in reasonable time.

Reproducible: Always

Steps to Reproduce:
1. Set up LDAP to an Exchange AD server
2. Open a KMail Composer window
3. Start typing someone's name, surname or email address
Actual Results:  
No search results are shown for 2 minutes. That's because no network traffic occurs for those 2 minutes: the server does not reply.

Expected Results:  
Search results come quickly.

PS: it's not necessary to have 4 .arg() calls with the same value. Replacing all of the fields with %1 and using one .arg() call is enough.
Comment 1 Laurent Montel 2013-08-08 07:04:55 UTC
Problem if I remove "(mail=*@%3*)" we will not able to search address as "*@mandriva*"
Will investigate if there is another method to do it.
Comment 2 Thiago Macieira 2013-08-08 07:28:32 UTC
(In reply to comment #1)
> Problem if I remove "(mail=*@%3*)" we will not able to search address as
> "*@mandriva*"

I know. The thing is that Exchange is often used in corporate environments, which means that search will either have no results, or it'll match *everyone* (Intel's servers only have @intel.com people listed).

Anyway, looks like Exchange doesn't like any queries beginning with *.
Comment 3 Laurent Montel 2013-08-08 09:06:09 UTC
Yes it's right by default a ldap will search in one server so search for *@intel.com or other  is not useful.
Ok will remove it.
Will do soon.
Comment 4 Laurent Montel 2013-08-08 10:49:12 UTC
Git commit aea27876c7f3a7232727204b053a8953d5f67c81 by Montel Laurent.
Committed on 08/08/2013 at 10:48.
Pushed by mlaurent into branch 'KDE/4.11'.

Fix Bug 323272 - Querying a Microsoft Exchange's Active Directory via LDAP is extremely slow

FIXED-IN: 4.11.1

M  +6    -0    libkdepim/ldap/ldapclientsearch.cpp

http://commits.kde.org/kdepim/aea27876c7f3a7232727204b053a8953d5f67c81