This chapter explains how to write a plug-in function to bypass or replace the standard function for authentication with your own function.
Information on authentication with the Netscape Directory Server (Directory Server) is organized in the following sections:
Authentication methods for LDAP is described in RFC 2829, which you can find at http://www.ietf.org/rfc/rfc2829.txt
Two methods that you can use to authenticate clients are simple authentication and SASL authentication:
The server keeps track of the identity of the LDAP client through the SLAPI_CONN_DN and SLAPI_CONN_AUTHTYPE parameters.
During an LDAP bind operation, the server authenticates the user and puts the DN and authenticated method in the SLAPI_CONN_DN and SLAPI_CONN_AUTHTYPE parameters.
When an authenticated client requests the server to perform an LDAP operation, the server checks the DN in the SLAPI_CONN_DN parameter to determine if the client has the appropriate access rights.
When the Directory Server receives an LDAP bind request from a client, it processes the request in the following steps:
A situation may arise in which you may want to write and implement your own function for authentication; that is, replace the standard means of authentication with your own function. You can write a pre-operation bind plug-in function (a function that the server calls before processing an LDAP bind request) that performs the authentication and bypasses the default bind functionality. For details, see the next section, Writing a Pre-Operation Bind Plug-in.
You can define your own pre-operation bind plug-in function to authenticate LDAP clients. The server will call your function during the authentication process (in Step 9). Your function should return a non-zero value to bypass the default backend bind function and the post-operation bind functions.
Note that this means that Step 10 through Step 12 are skipped. Your pre-operation plug-in function is responsible for sending the result code to the client and for setting the DN and authentication method for the connection.
Figure 8-1 summarizes the process of using a pre-operation bind plug-in function to authenticate LDAP clients to the Directory Server.

Figure 8-2 illustrates the steps that your pre-operation bind plug-in function must take to authenticate LDAP clients to the Directory Server.
The following sections cover guidelines that you can follow when defining your authentication function:
|
|
|
|
Be sure to check this source file for an example of a pre-operation plug-in function that handles authentication: <server_root>/plugins/slapd/slapi/examples/testbind.c
|
|
|
|
|
Call the slapi_pblock_get() function to get the values of the following parameters:
If you plan to support authentication through SASL mechanisms, you should also get the value of the SLAPI_BIND_SASLMECHANISM parameter (a string value specifying the name of the SASL mechanism to use for authentication).
Make sure to check the following:
In both cases, return a non-zero value to prevent the server from calling the default backend function for authentication.
Get the entry for the DN specified by the SLAPI_BIND_TARGET parameter, and compare the credentials in the SLAPI_BIND_CREDENTIALS parameter against the known credentials for that entry.
By default, Directory Server 4.x uses the userpassword attribute to store the credentials for an entry. The server encodes the password using the scheme specified in the passwdhash directive of the slapd.conf configuration file. The scheme can be crypt, sha, or "." (for cleartext).
By default, Directory Server 7.x uses the userpassword attribute to store the credentials for an entry. The server encodes the password using the scheme specified in the nsslapd-rootpwstoragescheme or passwordStorageScheme attributes of the cn=config entry contained in the dse.ldif file. The scheme can be any of the following:
If you need to
compare the client's
credentials against the value of the userpassword
attribute, you can call the slapi_pw_find_sv()
function. This function determines which password scheme was used to
store the password and uses the appropriate comparison function to
compare a given value against the encrypted value of the userpassword
attribute.
If authentication fails, send one of the following result codes back to the client:
If the authentication is successful, your authentication function should do the following:
Make sure that your
function returns a
non-zero value to bypass the default backend bind function and any
post-operation plug-in functions.
If you are using SASL as the authentication method, you need to register the SASL mechanisms that you plan to use.
In your initialization function (see Writing Plug-in Initialization Functions), call the Functions for Syntax Plug-in function and specify the name of the SASL mechanism. For example:
slapi_register_supported_saslmechanism( "babsmechanism" );
If you do
not register your SASL
mechanism, the Directory Server will send an
LDAP_AUTH_METHOD_NOT_SUPPORTED
result code back to the client and will not call your pre-operation
bind function.
|
|
|
|
Be sure to check this source file for an example of a pre-operation plug-in function for SASL authentication with LDAP bind operations: <server_root>/plugins/slapd/slapi/examples/testsaslbind.c
|
|
|
|
|
The following sections document an example of a pre-operation bind plug-in that handles authentication:
|
|
|
|
Be sure to check this source file for an updated example of a pre-operation plug-in function that handles authentication: <server_root>/plugins/slapd/slapi/examples/testbind.c |
|
|
|
|
The following is an
example of a
pre-operation bind function that authenticates clients and bypasses the
default backend bind function. In this example, the function just
compares the client's credentials against the value of the userpassword
attribute for the entry.
Code Example 8-1 Sample pre-Operation Bind Function
To initialize your plug-in, write an initialization function to do the following:
The following is an example of an initialization function that registers the pre-operation bind function.
To register the plug-in, follow the instructions appropriate for the Directory Server you're using:
Check this source file for an example of a pre-operation plug-in function that handles authentication: <server_root>/plugins/slapd/slapi/examples/testbind.c
If you intend to use SASL as the method for authenticating clients, you need to enable your LDAP clients to use SASL.
In your client, call the ldap_sasl_bind() or ldap_sasl_bind_s() function to request authentication using SASL. To parse credentials from an asynchronous SASL bind operation, call ldap_parse_sasl_bind_result(). These functions are part of the Netscape LDAP C SDK 3.0.
The syntax for these functions are listed below:
LDAP_API(int)
LDAP_CALL ldap_sasl_bind(
LDAP
*ld, const char *dn,
const char
*mechanism, struct berval *cred,
LDAPControl
**serverctrls, LDAPControl **clientctrls, int *msgidp );
LDAP_API(int)
LDAP_CALL ldap_sasl_bind_s(
LDAP *ld, const char *dn,
const char *mechanism, struct berval *cred,
LDAPControl **serverctrls, LDAPControl **clientctrls,
struct berval **servercredp );
The parameters are described below:
If you are call the ldap_sasl_bind() function, you need to call the ldap_result() function to get the result of the authentication attempt:
LDAP_API(int)
LDAP_CALL ldap_result( LDAP
*ld, int msgid, \
int all,
struct timeval *timeout, LDAPMessage **result );
The parameters are described below:
After callingldap_result(), you need to call the ldap_parse_sasl_bind_result() function to parse the results and retrieve the LDAP result code and any credentials returned by the server:
LDAP_API(int)
LDAP_CALL
ldap_parse_sasl_bind_result( LDAP *ld, \
LDAPMessage
*res, struct berval **servercredp, int freeit);
The parameters are described below:
The following example is an LDAP client that authenticates using the SASL method named babsmechanism.
| Previous |
Contents |
Index |
DocHome | Next |