LDAP SCL Interface |
Opens a connection to an LDAP server.
_OPEN(ldapServerName, port, base, bindDN, password, <session_options>);
ldapServerName
parameter is left blank, the default server name is that of the host that is
running the application that called this method. Otherwise, the value of the
ldapServerName
parameter must be the DNS name or IP address of a
host on which an LDAP server is running.LDAP_BASE
is used for the definition of the
base object.LDAP_BINDDN
is used as the bind distinguished name. If a
value of "" is specified and the LDAP_BINDDN
variable has not been set,
an unauthorized bind is performed.
LDAP_BINDPW
is used as the bind password. If the value of
this attribute is specified as ""
and the
LDAP_BINDPW
variable has not been set, an unauthenticated
bind is performed.Note: Specify only one search scope option. If multiple search scope options are specified, the one that appears last is used. If none of the search scope options are specified, the default value of SUBTREE_SEARCH_SCOPE is used.
When invoked on an LDAPSERVICES instance, the _OPEN method initializes the connection to the specified LDAP server.
The %SYSRC macro can be used to check for errors returned from the _OPEN method. Possible error return codes include:
If the return code is not one of these pre-defined system return codes, use SYSMSG() to determine the exact error message. See the examples section for a sample code snippet that shows how to check for these return codes.
The following example opens a connection to an LDAP server using an anonymous bind and the default session options. It also shows how to check for error conditions from the _OPEN method.
dclass = loadclass('sashelp.base.ldapservices.class'); ds = instance(dclass); server = "myhost.net.com"; base = "Alpine Airways,c=US"; bindDn=""; pw=""; rc = ds._open(server,8001,base,bindDn,pw); if rc ne 0 then do; if (rc = %sysrc(_SELDBOS)) then put 'Bind outside of scope.'; else if (rc = %sysrc(_SELDNSO)) then put 'No such object.'; else if (rc = %sysrc(_SELDICR)) then put 'Invalid credentials.'; else if (rc = %sysrc(_SELDDWN)) then put 'Unable to contact LDAP server.'; else do; msg = sysmsg(); put msg; end; end;
The following example opens a connection to an LDAP server, binding as user John Doe. It passes in a session option of OPT_REFERRALS_OFF; this instructs the LDAP server not to chase referrals.
server = "myhost.net.com"; base = "Alpine Airways,c=US"; bindDN ="cn=John Doe,ou=People,o=Alpine Airways,c=us"; pw="myPass1"; referral= "OPT_REFERRALS_OFF"; rc = ds._OPEN(server,8001,base,bindDn,pw,referral);
LDAP SCL Interface |