This question about LDAP: Answered

How to search again in results of previous LDAP-Search

How can I search inside the results of a previous ldap-search.

Example:
List all telephone-numbers and realnames of users in the LDAP-Group wikiusers
following Search
%LDAP{filter="(&(cn=wikiuser)(objectClass=myPosixGroup))" base="ou=groups,dc=mydomain,dc=com,o=myorganisation" format="$memberUid"}%

delivers the string:

user1, user2, user3

normaly the next search would be something like:

%LDAP{filter="(&(objectClass=myPosixUser)(|(uid=user1)(uid=user2)(uid=user3)))" base="ou=groups,dc=mydomain,dc=com,o=myorganisation" format="$cn $phonenumber$n"}%

How do I get the Result from the previous search "user1 user2..." in my next search inside one document?

-- UlliHochholdinger - 05 Oct 2010

This is done by nesting both expressions where the second query is build up using the results of the first:

%LDAP{
  "(&
     (objectClass=myPosixUser)
     %LDAP{
         "(&
            (cn=wikiuser)
            (objectClass=myPosixGroup)
          )" 
         base="ou=groups,dc=mydomain,dc=com,o=myorganisation" 
         header="(|"
         format="(uid=$memberUid)"
         footer=")"
     }%
   )" 
   base="ou=groups,dc=mydomain,dc=com,o=myorganisation" 
   format="$cn $phonenumber$n"
}%

-- MichaelDaum - 06 Oct 2010

Hi, Thanks for the fast response. But the nested search delivers the string:
(|(uid=user1, user2, user3))
for the second search this should be:
(|(uid=user1)(uid=user2)(uid=user3))
Is there a way to simply rewrite the result of the first search, for example with a simple perl-regex?

Cheers Ulli -- UlliHochholdinger - 07 Oct 2010

The base of the search is the same, have you tried joining the two queries together? (just thought I'd ask the obvious)

(&(objectClass=myPosixUser)(&(cn=wikiuser)(objectClass=myPosixGroup)))

-- DavidPatterson - 11 Oct 2010

Just reading my own nonsense. Nevermind, there is no JOIN in LDAP and what I put above makes no sense. Back to sleep...

You could use the %FORMATLIST macro from FilterPlugin to get the formatting you need from the inner LDAP query.

-- DavidPatterson - 11 Oct 2010

Wow, many thanks for the tip with the FilterPlugin this was exactly what I searched for. So I nested the %LDAP search for the memberUid inside %FORMATLIST and this again inside the next %LDAP search. Example:
%LDAP{
  "(&
     (objectClass=myPosixUser)
     %FORMAT{
     %LDAP{
         "(&
            (cn=wikiuser)
            (objectClass=myPosixGroup)
          )" 
         base="ou=groups,dc=mydomain,dc=com,o=myorganisation" 
         format="$memberUid"
     }%
     header="(|(uid="
     separator=")(uid=" 
     footer="))" 
     }%
   )" 
   base="ou=groups,dc=mydomain,dc=com,o=myorganisation" 
   format="$cn $phonenumber$n"
}%
-- UlliHochholdinger - 15 Oct 2010

QuestionForm edit

Subject LDAP
Extension LdapNgPlugin
Version Foswiki 1.0.9
Status Answered
Topic revision: r7 - 15 Oct 2010, UlliHochholdinger
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy