This chapter gives a brief description of what is involved to connect to an LDAP server and return a result. An assumption is made that you have a working LDAP server and that you are familiar with the LDAP language. For a detailed description of the supported LDAP methods please read the chapter External Component Reference. The LDAP example library implements a functional interface for connecting to an LDAP server and searching and manipulating entries in an LDAP database. It uses an instance variable to host the non-visual object called ivLDAP.
WARNING: In the example, the instance variable is of type Object reference and the $construct and $destruct method call $newref() and $deleteref() to create and destroy the object instance. When using the non-visual LDAP object in your own library and you find you have to pass it as a parameter to Omnis methods, make sure you also use an Object reference variable to host the non-visual object.
Converting the old external commands
When converting your old library code, we recommend you use Studio 6 or older on the Macintosh or convert your library’s methods on Windows, so you may have loaded both the old external commands DLL and the new non-visual object DLL. If you do not load the old external, the external commands will be displayed as unrecognisable numbers.
Please also note:
In this section we show you how to connect to an LDAP server and complete a search.
Before you can connect to your server you must make sure that your LDAP middle ware is functioning correctly. To do this you execute the ivLDAP.$available() method.
Do ivLDAP.$available() Returns #F If flag true ;; LDAP is available Else ;; LDAP is not available - Check the installation End If |
Example:
Connecting to an LDAP server requires the execution of the two methods ivLDAP.$init(...) and ivLDAP.$simple_bind_s(...). ivLDAP.$init(...) connects to the actual server using the given host name and port, and ivLDAP.$simple_bind_s(...) will establish your access rights using the given DN (Distinguished Name) and password.
When connecting to an LDAP version 3 compliant server you should tell the external to use UTF8 characters for communications by assigning the ivLDAP.$use_utf8 property.
The following example connects to a server and then disconnects using ivLDAP.$unbind_s().
Do ivLDAP.$use_utf8.$assign(kTrue) Do ivLDAP.$init(”10.0.0.2”,389) Returns err If not(err) Do ivLDAP.$simple_bind_s(”cn=root,dc=brainydata,dc=com”,”Password”) Returns err End If If not(err) ;; Connection test completed! Else ;; Connection failed! End If Do ivLDAP.$unbind_s() |
Example:
Searching an LDAP database and dissecting the result involves a series of commands. First you call ivLDAP.$search_ext_s(...) with a scope and a filter. Then you use ivLDAP.$first_attribute(...) and ivLDAP$next_attribute(...) together with ivLDAP$get_values(...).
Do ivLDAP.$search_ext_s(”dc=brainydata,dc=com”,kLDAP_SCOPE_BASE,“(objectclass=*)”) Returns search_result Do ivLDAP.$first_entry(search_result) Returns result_entry While len(result_entry) Do ivLDAP.$first_attribute(result_entry,ber) Returns attribute While len(attribute) Do ivLDAP.$get_values(result_entry,attribute) Returns values ;; do something with the values Do ivLDAP.$next_attribute(result_entry,ber) Returns attribute End While Do ivLDAP.$free(ber) Do ivLDAP.$next_entry(result_entry) Returns result_entry End While Do ivLDAP.$free(search_result) |
Example:
The Omnis LDAP external is build against traditional LDAP client software. When connecting to a Microsoft Active Directory server some searches may not work correctly, in particular when searching root level directories using kLDAP_SCOPE_ONELEVEL or kLDAP_SCOPE_SUBTREE.
Connecting via the Global Catalog port 3268 usually resolves this issue. Please see the following Microsoft Technical article for full details http://technet.microsoft.com/en-gb/library/cc978012.aspx