-#if defined( LDAP_SLAPI )
- slapi_x_backend_set_pb( pb, op->o_bd );
- slapi_x_connection_set_pb( pb, op->o_conn );
- slapi_x_operation_set_pb( pb, op );
- slapi_pblock_set( pb, SLAPI_BIND_TARGET, (void *)dn.bv_val );
- slapi_pblock_set( pb, SLAPI_BIND_METHOD, (void *)method );
- slapi_pblock_set( pb, SLAPI_BIND_CREDENTIALS, (void *)&op->oq_bind.rb_cred );
- slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)(0) );
-
- rs->sr_err = doPluginFNs( op->o_bd, SLAPI_PLUGIN_PRE_BIND_FN, pb );
- if ( rs->sr_err != SLAPI_BIND_SUCCESS ) {
- /*
- * Binding is a special case for SLAPI plugins. It is
- * possible for a bind plugin to be successful *and*
- * abort further processing; this means it has handled
- * a bind request authoritatively. If we have reached
- * here, a result has been sent to the client (XXX
- * need to check with Sun whether SLAPI_BIND_ANONYMOUS
- * means a result has been sent).
- */
- int ldapRc;
-
- if ( slapi_pblock_get( pb, SLAPI_RESULT_CODE, (void *)&ldapRc ) != 0 )
- ldapRc = LDAP_OTHER;
-
- op->oq_bind.rb_edn.bv_val = NULL;
- op->oq_bind.rb_edn.bv_len = 0;
- if ( rs->sr_err != SLAPI_BIND_FAIL && ldapRc == LDAP_SUCCESS ) {
- /* Set the new connection DN. */
- if ( rs->sr_err != SLAPI_BIND_ANONYMOUS ) {
- slapi_pblock_get( pb, SLAPI_CONN_DN, (void *)&op->oq_bind.rb_edn.bv_val );
+#ifdef LDAP_SLAPI
+ if ( pb ) {
+ int rc;
+ slapi_int_pblock_set_operation( pb, op );
+ slapi_pblock_set( pb, SLAPI_BIND_TARGET, (void *)op->o_req_dn.bv_val );
+ slapi_pblock_set( pb, SLAPI_BIND_METHOD, (void *)op->orb_method );
+ slapi_pblock_set( pb, SLAPI_BIND_CREDENTIALS, (void *)&op->orb_cred );
+ slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)(0) );
+ slapi_pblock_set( pb, SLAPI_CONN_DN, (void *)(0) );
+
+ rc = slapi_int_call_plugins( op->o_bd, SLAPI_PLUGIN_PRE_BIND_FN, pb );
+
+ Debug(LDAP_DEBUG_TRACE,
+ "do_bind: Bind preoperation plugin returned %d.\n",
+ rs->sr_err, 0, 0);
+
+ switch ( rc ) {
+ case SLAPI_BIND_SUCCESS:
+ /* Continue with backend processing */
+ break;
+ case SLAPI_BIND_FAIL:
+ /* Failure, server sends result */
+ rs->sr_err = LDAP_INVALID_CREDENTIALS;
+ send_ldap_result( op, rs );
+ goto cleanup;
+ break;
+ case SLAPI_BIND_ANONYMOUS:
+ /* SLAPI_BIND_ANONYMOUS is undocumented XXX */
+ default:
+ /* Authoritative, plugin sent result, or no plugins called. */
+ if ( slapi_pblock_get( op->o_pb, SLAPI_RESULT_CODE,
+ (void *)&rs->sr_err) != 0 )
+ {
+ rs->sr_err = LDAP_OTHER;