cc[ flag... ] file... -lldap[ library... ] #include <lber.h> #include <ldap.h>int ldap_bind(LDAP *ld, char *who, char *cred, int method);
These functions provide various interfaces to the LDAP bind operation. After a connection is made to an LDAP server using ldap_open(3LDAP) , an LDAP bind operation must be performed before other operations can be attempted over the conection. Both synchronous and asynchronous versions of each variant of the bind call are provided. There are three types of calls, providing simple authentication, kerberos authentication, and general functions to do either one. All functions take ld as their first parameter, as returned from ldap_open(3LDAP) .
The simplest form of the bind call is ldap_simple_bind_s (). It takes the DN to bind as in who , and the userPassword associated with the entry in passwd . It returns an LDAP error indication (see ldap_error(3LDAP) ). The ldap_simple_bind() call is asynchronous, taking the same parameters but only initiating the bind operation and returning the message id of the request it sent. The result of the operation can be obtained by a subsequent call to ldap_result(3LDAP) .
The ldap_bind() and ldap_bind_s() functions can be used when the authentication method to use needs to be selected at runtime. They both take an extra method parameter selecting the authentication method to use. It should be set to LDAP_AUTH_SIMPLE to select simple authentication. ldap_bind() returns the message id of the request it initiates. ldap_bind_s() returns an LDAP error indication.
The ldap_sasl_bind() and ldap_sasl_bind_s() functions are used for general and extensible authentication over LDAP through the use of the Simple Authentication Security Layer. The routines both take the dn to bind as, the method to use, as a dotted-string representation of an OID identifying the method, and a struct berval holding the credentials. The special constant value LDAP_SASL_SIMPLE ("") can be passed to request simple authentication, or the simplified routines ldap_simple_bind() or ldap_simple_bind_s() can be use.
The ldap_unbind() call is used to unbind from the directory, terminate the current association, and free the resources contained in the ld structure. Once it is called, the connection to the LDAP server is closed, and the ld structure is invalid. The ldap_unbind_s() call is just another name for ldap_unbind() ; both of these calls are synchronous in nature.
The ldap_set_rebind_proc() call is used to set a function that will be called back to obtain bind credentials used when a new server is contacted during the following of an LDAP referral. Note that this function is only available when the LDAP libraries are compiled with LDAP_REFERRALS defined and is only used when the ld_options field in the LDAP structure has LDAP_OPT_REFERRALS set (this is the default). If ldap_set_rebind_proc() is never called, or if it is called with a NULL rebindproc parameter, an unauthenticated simple LDAP bind will always be done when chasing referrals.
rebindproc should be a function that is declared like this:
int rebindproc( LDAP *ld, char **whop, char **credp, int *methodp, int freeit );
The LDAP library will first call the rebindproc to obtain the referral bind credentials, and the freeit parameter will be zero. The whop , credp , and methodp should be set as appropriate. If the rebindproc returns LDAP_SUCCESS , referral processing continues, and the rebindproc will be called a second time with freeit non-zero to give your application a chance to free any memory allocated in the previous call.
If anything but LDAP_SUCCESS is returned by the first call to the rebindproc, then referral processing is stopped and that error code is returned for the original LDAP operation.
A call to ldap_result(3LDAP) , can be used to obtain the result of the bind operations.
Asynchronous functions will return -1 in case of error, setting the ld_errno parameter of the ld structure. Synchronous functions return whatever ld_errno is set to. See ldap_error(3LDAP) for more information. If no credentials are returned the result parameter is set to NULL.
See attributes(5) for a description of the following attributes:
|ATTRIBUTE TYPE||ATTRIBUTE VALUE|