HP-UX Directory Server 8.1 plug-in reference

Table Of Contents
Slapi_Entry **entries = NULL;
Slapi_Attr *attr = NULL;
/* Log a message to the server error log. */
slapi_log_error( SLAPI_LOG_PLUGIN, "test_bind" ,"Preoperation bind
function called.\n" );
/* Gets parameters available when processing an LDAP bind operation. */
if ( slapi_pblock_get( pb, SLAPI_BIND_TARGET, &dn ) != 0 ||
slapi_pblock_get( pb, SLAPI_BIND_METHOD, &method ) != 0 ||
slapi_pblock_get( pb, SLAPI_BIND_CREDENTIALS, &credentials ) != 0 )
{
slapi_log_error( SLAPI_LOG_PLUGIN, "test_bind" ,"Could not get para\
meters for bind operation\n" );
slapi_send_ldap_result( pb, LDAP_OPERATIONS_ERROR,
NULL, NULL, 0, NULL );
return( 1 );
}
/* Check the authentication method */
switch( method ) {
case LDAP_AUTH_SIMPLE:
/* First, get the entry specified by the DN. */
searchpb = slapi_search_internal( dn,LDAP_SCOPE_BASE,"
(objectclass=*)" , NULL, NULL, 0 );
if ( searchpb != NULL ) {
slapi_pblock_get( pb, SLAPI_PLUGIN_INTOP_RESULT, &rc );
if ( rc == LDAP_SUCCESS ) {
slapi_pblock_get( searchpb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES,
&entries );
if ( entries != NULL && entries[0] != NULL ) {
e = entries[0];
} else {
slapi_log_error( SLAPI_LOG_PLUGIN, "test_bind" ,"Could not
find entry for %s\n" , dn );
rc = LDAP_NO_SUCH_OBJECT;
break;
}
} else {
slapi_log_error( SLAPI_LOG_PLUGIN, "test_bind" ,
"Could not find entry for %s (error %d)\n" , dn, rc );
break;
}
} else {
slapi_log_error( SLAPI_LOG_PLUGIN, "test_bind" ,"Could not
search for entry\n" );
rc = LDAP_OPERATIONS_ERROR;
break;
}
/* Next, check the credentials against the userpassword attribute
* of that entry. */
if ( e != NULL ) {
if ( slapi_entry_attr_find( e, "userpassword" , &attr ) != 0 ) {
slapi_log_error( SLAPI_LOG_PLUGIN, "test_bind" ,"Entry has no
userpassword attribute\n" );
rc = LDAP_INAPPROPRIATE_AUTH;
break;
}
slapi_attr_get_values( attr,&pwvals );
if ( slapi_pw_find( pwvals, credentials ) != 0 ) {
slapi_log_error( SLAPI_LOG_PLUGIN, "test_bind" ,
"Credentials are not correct for the entry\n" );
rc = LDAP_INVALID_CREDENTIALS;
break;
}
} else {
/* This should not happen. The previous section of code
* already checks for this case. */
slapi_log_error( SLAPI_LOG_PLUGIN, "test_bind" ,"Could find
entry for %s\n" , dn );
rc = LDAP_NO_SUCH_OBJECT;
break;
}
76 Defining functions for authentication