Article

jimc's picture
article
Reads:

6251

Score:
0
0
 
Comments:

2

Reading Operational Attributes with LDAP/PHP

Author Info

20 May 2009 - 12:15pm
Submitted by: jimc

(View Disclaimer)

How to read Operational Attributes with PHP and LDAP.

By default operational attributes (most notably object creation time, creator etc) are not exposed by LDAP. TID 1007418 How to query operational attributes with LDAP http://www.novell.com/support/php/search.do?cmd=displayKC&externalId=10070418 covers the fundamentals. This note demonstrates how to code in PHP using LDAP Calls.

I've got a demonstration script downloadable at http://www.champwilde.f9.co.uk/idmphp/readopatt/index.html, but this note covers the fundamental points.

An LDAP query of eDirectory (or any other directory) typically starts with ldap_connect and ldap_bind commands to set up the server connection, then an ldap_search command to control what is being searched for, and finally ldap entry and ldap attribute commands to extract the output. In order to return the operational attributes its necessary to add some options to the ldap_search command.

A simple LDAP search command in php will look like this:

$sr=@ldap_search($ds, $ldap_root, $ldap_sr );  

You will find that this returns all the standard attributes, and none of the operational attributes. As well as the lack of operational attributes, you are also searching and returning more data than you really need, so its not good practice anyway. What you should do is to specify each attribute that you wish to search for in an array in the LDAP call, and you must do this if you need to return the Operational Attributes. Thus the search command should look something like this:

$sr=@ldap_search($ds, $ldap_root, $ldap_sr, array ("givenName", "sn", "createTimestamp") ); 

In this command the search will return Given Name, Surname and the Object creation timestamp.

There are, of course, other options for ldap_search: see http://www.php.net/manual/en/function.ldap-search.php for full documentation.


Disclaimer: As with everything else at Cool Solutions, this content is definitely not supported by Novell (so don't even think of calling Support if you try something and it blows up).

It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test, test, test before you do anything drastic with it.




User Comments

jwilleke's picture

You might want to try

Submitted by jwilleke on 23 May 2009 - 4:56am.

Several LDAP server providers, including eDirectory, support using +* as a methodology to return all attributes including operational attributes.

ldapsearch -b "uid=isACTIVE,o=test,dc=com" -s base -D cn=admin,ou=administration,dc=willeke,dc=com "(objectclass=*)" + *

-jim

TudorBran's picture

I've tested Jim's idea and it

Submitted by TudorBran on 20 September 2010 - 5:44am.

I've tested Jim's idea and it seems to work just fine for me. Thanks a lot for sharing this info with us.

Tudor Bran

© 2013 Novell