LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 01-30-2015, 02:48 AM   #1
Ramurd
Member
 
Registered: Mar 2009
Location: Rotterdam, the Netherlands
Distribution: Slackwarelinux
Posts: 703

Rep: Reputation: 111Reputation: 111
Question (open)Ldap query for dn of inetOrgPerson containing an alias


G'day y'all,

Hoping someone can help me get the correct search/filter setup for this situation; been searching the interwebs for a while now, and still cannot even find if someone has asked this one before.

The setup is as follows:
I have an ou, called contacts. The ou contains inetOrgPerson objects. The purpose is to have a single object containing the contactinformation of a set of users that are referenced as aliases; those users are setup below:
I have another ou, called users. This ou contains the actual user.

So, now I have to find the 'contact' that has the aliasedObjectName <dn of the user>.
For simplicity let's have this 'user' object: 'cn=Ramurd,ou=users,dc=environment,o=org"
It is referenced in one of the contact-objects, and I'd like to know which one.

So I tried a few filters:
(&(objectClass=inetOrgPerson)(aliasedObjectName=cn=Ramurd,ou=users,dc=environment,o=org))
But it returns the alias (=user) not the contact.
'(objectClass=*)' '(aliasedObjectname=cn=Ramurd,ou=users,dc=environment,o=org)' (with ldapsearch) returns all contacts, not only the one that has the given alias...

Tried a few more, but got either the above results or none at all. (and for the test I know I should get exactly one result)
 
Old 02-02-2015, 09:22 AM   #2
Ramurd
Member
 
Registered: Mar 2009
Location: Rotterdam, the Netherlands
Distribution: Slackwarelinux
Posts: 703

Original Poster
Rep: Reputation: 111Reputation: 111
For now, until I know of a better solution, I have created this solution (in php style)

First I search the existing inetOrgPersons, I iterate over each to see if they have an 'aliasedObjectName' and then test if one of those is the dn of the user I'm searching for.
If so, I know I found the dn.

Codewise, it goes like this (and it is a style I was hoping to avoid):

Code:
$contactsr=ldap_search($ds,$contactbase,$contactfilter,$contactattr,0,0,0,LDAP_DEREF_NEVER);

if($contactsr)
{   
     $contactinfo=ldap_get_entries($ds,$contactsr);
     for($i=0;$i<$contactinfo['count'];$i++)
     {   
          $aliasfilter=("(objectClass=*)");
          $aliasbase=sprintf("%s",$contactinfo[$i]['dn']);
          $aliasattr=array('dn','aliasedObjectName');
          $aliassr=ldap_search($ds,$aliasbase,$aliasfilter,$aliasattr,0,0,0,LDAP_DEREF_NEVER);
          $aliasinfo=ldap_get_entries($ds,$aliassr);
          for($j=0;$j<$aliasinfo['count'];$j++)
          {   
               if(isset($aliasinfo[$j]['aliasedobjectname']))
               {   
                    for($k=0;$k<$aliasinfo[$j]['aliasedobjectname']['count'];$k++)
                    {   
                         if($aliasinfo[$j]['aliasedobjectname'][$k] == $userdn)
                         {
                              printf("Alias found: %s contains: %s [dn: %s]\n", $contactinfo[i]['dn'], $aliasinfo[$j]['aliasedobjectname'][$k], $aliasinfo[$j]['dn']);
                         }   
                    }   
               }   
          }   
     }   
}

Last edited by Ramurd; 02-02-2015 at 09:26 AM. Reason: abundance of spaces removed
 
  


Reply

Tags
ldap openldap filter


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
phpldapadmin - create inetOrgPerson, posixAccount and posixGroup at the same time lqmp Linux - Newbie 1 11-06-2013 11:51 AM
Query about LDAP, WINBIND aayash Linux - Newbie 3 05-09-2013 03:06 AM
[SOLVED] LDAP Query (ssl) elalexluna83 Linux - Networking 3 10-22-2012 11:46 AM
query related to alias IP Neelabha Banerjee Linux - Networking 1 11-07-2011 11:40 AM
LDAP Query cjagdish69 Linux - Server 0 11-18-2006 01:16 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 01:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration