2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 2002-2005 The OpenLDAP Foundation.
5 * Portions Copyright 1997,2002-2003 IBM Corporation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was initially developed by IBM Corporation for use in
18 * IBM products and subsequently ported to OpenLDAP Software by
19 * Steve Omrani. Additional significant contributors include:
25 #include <ac/string.h>
26 #include <ac/stdarg.h>
28 #include <ac/unistd.h>
35 * use a fake listener when faking a connection,
36 * so it can be used in ACLs
38 static struct slap_listener slap_unknown_listener = {
39 BER_BVC("unknown"), /* FIXME: use a URI form? (e.g. slapi://) */
44 slapi_int_mods_free( Modifications *ml )
48 for ( ; ml != NULL; ml = next ) {
51 /* Don't free unnormalized values */
52 if ( ml->sml_nvalues != NULL ) {
53 ber_bvarray_free( ml->sml_nvalues );
54 ml->sml_nvalues = NULL;
56 slapi_ch_free((void **)&ml->sml_values);
57 slapi_ch_free((void **)&ml);
66 LDAPControl **controls = NULL;
68 plugin_result_callback prc = NULL;
69 void *callback_data = NULL;
70 Slapi_PBlock *pb = SLAPI_OPERATION_PBLOCK( op );
74 slapi_pblock_get( pb, SLAPI_RESCONTROLS, (void **)&controls );
75 slapi_pblock_get( pb, SLAPI_X_INTOP_RESULT_CALLBACK, (void **)&prc );
76 slapi_pblock_get( pb, SLAPI_X_INTOP_CALLBACK_DATA, &callback_data );
78 assert( controls == NULL );
80 /* Copy these before they go out of scope */
81 if ( rs->sr_ctrls != NULL ) {
82 for ( i = 0; rs->sr_ctrls[i] != NULL; i++ )
85 controls = (LDAPControl **)slapi_ch_calloc( i + 1,
86 sizeof(LDAPControl ));
88 for ( i = 0; rs->sr_ctrls[i] != NULL; i++ )
89 controls[i] = slapi_dup_control( rs->sr_ctrls[i] );
94 slapi_pblock_set( pb, SLAPI_RESCONTROLS, (void *)controls );
95 slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs->sr_err );
98 (*prc)( rs->sr_err, callback_data );
105 slapi_int_search_entry(
109 plugin_search_entry_callback psec = NULL;
110 void *callback_data = NULL;
111 Slapi_PBlock *pb = SLAPI_OPERATION_PBLOCK( op );
112 int rc = SLAP_CB_CONTINUE;
114 assert( pb != NULL );
116 slapi_pblock_get( pb, SLAPI_X_INTOP_SEARCH_ENTRY_CALLBACK, (void **)&psec );
117 slapi_pblock_get( pb, SLAPI_X_INTOP_CALLBACK_DATA, &callback_data );
119 if ( psec != NULL ) {
120 rc = (*psec)( rs->sr_entry, callback_data );
127 slapi_int_search_reference(
131 int i, rc = LDAP_SUCCESS;
132 plugin_referral_entry_callback prec = NULL;
133 void *callback_data = NULL;
134 Slapi_PBlock *pb = SLAPI_OPERATION_PBLOCK( op );
136 assert( pb != NULL );
138 slapi_pblock_get( pb, SLAPI_X_INTOP_REFERRAL_ENTRY_CALLBACK, (void **)&prec );
139 slapi_pblock_get( pb, SLAPI_X_INTOP_CALLBACK_DATA, &callback_data );
141 if ( prec != NULL ) {
142 for ( i = 0; rs->sr_ref[i].bv_val != NULL; i++ ) {
143 rc = (*prec)( rs->sr_ref[i].bv_val, callback_data );
144 if ( rc != LDAP_SUCCESS ) {
154 slapi_int_response( Slapi_Operation *op, SlapReply *rs )
158 switch ( rs->sr_type ) {
160 rc = slapi_int_result( op, rs );
163 rc = slapi_int_search_entry( op, rs );
166 rc = slapi_int_search_reference( op, rs );
173 assert( rc != SLAP_CB_CONTINUE );
179 slapi_int_get_ctrls( Operation *op, LDAPControl **controls )
183 SlapReply rs = { REP_RESULT };
185 op->o_ctrls = controls;
186 if ( op->o_ctrls == NULL ) {
190 for ( c = op->o_ctrls; *c != NULL; c++ ) {
191 rc = slap_parse_ctrl( op, &rs, *c, &rs.sr_text );
192 if ( rc != LDAP_SUCCESS )
200 * To allow plugins to forward frontend requests to internal operations,
201 * the internal operation and connection structures should import as
202 * much state as practicable from the supplied parameter block.
206 * Select the backend to be used for an internal operation, either
207 * from the operation target DN or from the parameter block.
210 slapi_int_pblock_get_backend( Slapi_PBlock *pb, Operation *op )
212 int manageDsaIt = 0, isCritical;
213 LDAPControl **controls = NULL;
216 slapi_pblock_get( pb, SLAPI_REQCONTROLS, (void **)&controls );
218 slapi_pblock_get( pb, SLAPI_MANAGEDSAIT, (void **)&manageDsaIt );
219 if ( manageDsaIt != 0 )
220 manageDsaIt = SLAP_CONTROL_CRITICAL;
221 else if ( slapi_control_present( controls, SLAPI_CONTROL_MANAGEDSAIT_OID,
223 manageDsaIt = isCritical ? SLAP_CONTROL_CRITICAL : SLAP_CONTROL_NONCRITICAL;
225 /* let caller force a specific backend */
226 slapi_pblock_get( pb, SLAPI_BACKEND, (void **)&be_op );
227 if ( be_op == NULL ) {
228 be_op = select_backend( &op->o_req_ndn, 0, 0 );
229 slapi_pblock_set( pb, SLAPI_BACKEND, (void *)be_op );
232 op->o_bd = frontendDB; /* but we actually use frontend DB */
238 slapi_int_pblock_get_connection( Slapi_PBlock *pb, Operation *op )
241 Connection *conn = op->o_conn;
243 slapi_pblock_get( pb, SLAPI_X_CONN_SSF, (void **)&conn->c_ssf );
244 slapi_pblock_get( pb, SLAPI_X_CONN_SASL_CONTEXT, (void **)&conn->c_sasl_authctx );
246 if ( slapi_pblock_get( pb, SLAPI_CONN_DN, (void **)&connDn ) != 0
249 /* default to operation DN */
250 conn->c_ndn = op->o_ndn;
251 conn->c_dn = op->o_ndn;
254 /* NB: conn DN must be normalized */
255 ber_str2bv( connDn, 0, 0, &conn->c_ndn );
256 conn->c_dn = conn->c_ndn;
263 slapi_int_pblock_get_operation( Slapi_PBlock *pb, Operation *op )
267 char *requestorDn = NULL;
268 struct berval targetDn = BER_BVNULL;
269 LDAPControl **controls;
273 /* All internal operations must specify a target DN */
274 slapi_pblock_get( pb, SLAPI_TARGET_DN, (void **)&targetDn.bv_val );
275 if ( targetDn.bv_val == NULL) {
276 return LDAP_PARAM_ERROR;
278 targetDn.bv_len = strlen( targetDn.bv_val );
280 rc = dnPrettyNormal( NULL, &targetDn, &op->o_req_dn, &op->o_req_ndn, NULL );
281 if ( rc != LDAP_SUCCESS ) {
285 rc = slapi_int_pblock_get_backend( pb, op );
286 if ( rc != LDAP_SUCCESS ) {
290 slapi_pblock_get( pb, SLAPI_REQUESTOR_ISROOT, (void **)&isRoot );
291 slapi_pblock_get( pb, SLAPI_REQUESTOR_ISUPDATEDN, (void **)&isUpdateDn );
292 /* NB: requestor DN must be normalized */
293 slapi_pblock_get( pb, SLAPI_REQUESTOR_DN, (void **)&requestorDn );
294 slapi_pblock_get( pb, SLAPI_BACKEND, (void **)&be_op );
296 /* Default authorization identity for internal operations is root DN */
297 if ( isRoot || requestorDn == NULL ) {
298 assert( be_op != NULL );
299 op->o_dn = be_op->be_rootdn;
300 op->o_ndn = be_op->be_rootndn;
303 ber_str2bv( requestorDn, 0, 0, &op->o_ndn );
304 op->o_dn = op->o_ndn;
307 slapi_pblock_set( pb, SLAPI_REQUESTOR_ISROOT, (void *)isRoot );
309 rc = slapi_int_pblock_get_connection( pb, op );
310 if ( rc != LDAP_SUCCESS ) {
314 slapi_pblock_get( pb, SLAPI_REQCONTROLS, (void **)&controls );
315 rc = slapi_int_get_ctrls( op, controls );
316 if ( rc != LDAP_SUCCESS ) {
324 slapi_int_connection_init( Slapi_PBlock *pb,
330 ber_len_t max = sockbuf_max_incoming;
333 conn = (Connection *) slapi_ch_calloc( 1, sizeof(Connection) );
335 LDAP_STAILQ_INIT( &conn->c_pending_ops );
337 op = (Operation *) slapi_ch_calloc( 1, OPERATION_BUFFER_SIZE );
338 op->o_hdr = (Opheader *)(op + 1);
339 op->o_hdr->oh_extensions = NULL;
340 op->o_controls = (void **)(op->o_hdr + 1);
342 op->o_callback = (slap_callback *) slapi_ch_calloc( 1, sizeof(slap_callback) );
343 op->o_callback->sc_response = slapi_int_response;
344 op->o_callback->sc_cleanup = NULL;
345 op->o_callback->sc_private = pb;
346 op->o_callback->sc_next = NULL;
348 conn->c_pending_ops.stqh_first = op;
350 /* connection object authorization information */
351 conn->c_authtype = LDAP_AUTH_NONE;
352 BER_BVZERO( &conn->c_authmech );
353 BER_BVZERO( &conn->c_dn );
354 BER_BVZERO( &conn->c_ndn );
356 conn->c_listener = &slap_unknown_listener;
357 ber_dupbv( &conn->c_peer_domain, (struct berval *)&slap_unknown_bv );
358 ber_dupbv( &conn->c_peer_name, (struct berval *)&slap_unknown_bv );
360 LDAP_STAILQ_INIT( &conn->c_ops );
362 BER_BVZERO( &conn->c_sasl_bind_mech );
363 conn->c_sasl_authctx = NULL;
364 conn->c_sasl_sockctx = NULL;
365 conn->c_sasl_extra = NULL;
367 conn->c_sb = ber_sockbuf_alloc( );
369 ber_sockbuf_ctrl( conn->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
371 conn->c_currentber = NULL;
373 /* should check status of thread calls */
374 ldap_pvt_thread_mutex_init( &conn->c_mutex );
375 ldap_pvt_thread_mutex_init( &conn->c_write_mutex );
376 ldap_pvt_thread_cond_init( &conn->c_write_cv );
378 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
380 conn->c_n_ops_received = 0;
381 conn->c_n_ops_executing = 0;
382 conn->c_n_ops_pending = 0;
383 conn->c_n_ops_completed = 0;
389 conn->c_protocol = LDAP_VERSION3;
391 conn->c_activitytime = conn->c_starttime = slap_get_time();
394 * A real connection ID is required, because syncrepl associates
395 * pending CSNs with unique ( connection, operation ) tuples.
396 * Setting a fake connection ID will cause slap_get_commit_csn()
397 * to return a stale value.
399 connection_assign_nextid( conn );
401 conn->c_conn_state = 0x01; /* SLAP_C_ACTIVE */
402 conn->c_struct_state = 0x02; /* SLAP_C_USED */
404 conn->c_ssf = conn->c_transport_ssf = 0;
407 backend_connection_init( conn );
409 conn->c_send_ldap_result = slap_send_ldap_result;
410 conn->c_send_search_entry = slap_send_search_entry;
411 conn->c_send_ldap_extended = slap_send_ldap_extended;
412 conn->c_send_search_reference = slap_send_search_reference;
414 /* operation object */
416 op->o_protocol = LDAP_VERSION3;
417 BER_BVZERO( &op->o_authmech );
418 op->o_time = slap_get_time();
419 op->o_do_not_cache = 1;
420 op->o_threadctx = ldap_pvt_thread_pool_context();
421 op->o_tmpmemctx = NULL;
422 op->o_tmpmfuncs = &ch_mfuncs;
424 op->o_connid = conn->c_connid;
426 rc = slapi_int_pblock_get_operation( pb, op );
428 slapi_pblock_set( pb, SLAPI_OPERATION, op );
429 slapi_pblock_set( pb, SLAPI_CONNECTION, conn );
431 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
433 if ( rc != LDAP_SUCCESS ) {
434 slapi_int_connection_destroy( &conn );
443 void slapi_int_connection_destroy( Connection **pConn )
445 Connection *conn = *pConn;
449 if ( conn == NULL ) {
453 op = (Operation *)conn->c_pending_ops.stqh_first;
454 pb = SLAPI_OPERATION_PBLOCK( op );
456 slap_graduate_commit_csn( op );
458 slapi_ch_free_string( &op->o_req_dn.bv_val );
459 slapi_ch_free_string( &op->o_req_ndn.bv_val );
460 slapi_ch_free( (void **)&op->o_callback );
462 if ( conn->c_sb != NULL ) {
463 ber_sockbuf_free( conn->c_sb );
466 slapi_pblock_set( pb, SLAPI_OPERATION, NULL );
467 slapi_pblock_set( pb, SLAPI_CONNECTION, NULL );
469 slapi_ch_free( (void **)&op );
470 slapi_ch_free( (void **)pConn );
474 slapi_delete_internal_pb( Slapi_PBlock *pb )
477 Connection *conn = NULL;
478 Operation *op = NULL;
480 SlapReply rs = { REP_RESULT };
486 rs.sr_err = slapi_int_connection_init( pb, LDAP_REQ_DELETE, &conn );
487 if ( rs.sr_err != LDAP_SUCCESS ) {
488 slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
492 op = conn->c_pending_ops.stqh_first;
493 rs.sr_err = frontendDB->be_delete( op, &rs );
495 slapi_int_connection_destroy( &conn );
500 #endif /* LDAP_SLAPI */
504 slapi_add_internal_pb( Slapi_PBlock *pb )
507 Connection *conn = NULL;
508 Slapi_Entry *entry = NULL;
510 LDAPMod **mods = NULL;
511 Operation *op = NULL;
512 char textbuf[ SLAP_TEXT_BUFLEN ];
513 size_t textlen = sizeof( textbuf );
515 SlapReply rs = { REP_RESULT };
521 slapi_pblock_get( pb, SLAPI_ADD_ENTRY, (void **)&entry );
522 slapi_pblock_get( pb, SLAPI_ADD_TARGET, (void **)&dn );
523 slapi_pblock_get( pb, SLAPI_MODIFY_MODS, (void **)&mods );
525 if ( entry != NULL ) {
527 rs.sr_err = LDAP_PARAM_ERROR;
531 dn = slapi_entry_get_dn( entry );
532 slapi_pblock_set( pb, SLAPI_ADD_TARGET, dn );
533 } else if ( mods == NULL || dn == NULL ) {
534 rs.sr_err = LDAP_PARAM_ERROR;
538 rs.sr_err = slapi_int_connection_init( pb, LDAP_REQ_ADD, &conn );
539 if ( rs.sr_err != LDAP_SUCCESS ) {
543 op = (Operation *)conn->c_pending_ops.stqh_first;
545 op->ora_modlist = NULL;
548 * The caller can specify a new entry, or a target DN and set
549 * of modifications, but not both.
551 op->ora_e = (Entry *)slapi_ch_calloc( 1, sizeof(*entry) );
552 ber_dupbv( &op->ora_e->e_name, &op->o_req_dn );
553 ber_dupbv( &op->ora_e->e_nname, &op->o_req_ndn );
555 if ( mods != NULL ) {
556 /* Entry just contains name; attributes are in modlist */
557 op->ora_modlist = slapi_int_ldapmods2modifications( mods );
558 if ( op->ora_modlist == NULL ) {
559 rs.sr_err = LDAP_PROTOCOL_ERROR;
563 rs.sr_err = slap_entry2mods( entry, &op->ora_modlist,
564 &rs.sr_text, textbuf, textlen );
565 if ( rs.sr_err != LDAP_SUCCESS )
569 rs.sr_err = slap_mods_check( op->ora_modlist, &rs.sr_text,
570 textbuf, textlen, NULL );
571 if ( rs.sr_err != LDAP_SUCCESS ) {
575 rs.sr_err = frontendDB->be_add( op, &rs );
576 if ( rs.sr_err == 0 ) {
577 if ( op->ora_e != NULL && op->o_private != NULL ) {
578 BackendDB *bd = op->o_bd;
580 /* could we use SLAPI_BACKEND instead? */
581 op->o_bd = (BackendDB *)op->o_private;
582 op->o_private = NULL;
583 be_entry_release_w( op, op->ora_e );
586 op->o_private = NULL;
591 slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
593 slapi_entry_free( op->ora_e );
594 slapi_int_mods_free( op->ora_modlist );
595 slapi_int_connection_destroy( &conn );
600 #endif /* LDAP_SLAPI */
604 slapi_modrdn_internal_pb( Slapi_PBlock *pb )
607 struct berval newrdn = BER_BVNULL;
608 struct berval newsupdn = BER_BVNULL;
609 struct berval newSuperiorPretty = BER_BVNULL;
610 struct berval newSuperiorNormalized = BER_BVNULL;
611 Connection *conn = NULL;
612 Operation *op = NULL;
618 SlapReply rs = { REP_RESULT };
624 slapi_pblock_get( pb, SLAPI_MODRDN_NEWRDN, (void **)&lnewrdn );
625 slapi_pblock_get( pb, SLAPI_MODRDN_NEWSUPERIOR, (void **)&newsuperior );
626 slapi_pblock_get( pb, SLAPI_MODRDN_DELOLDRDN, (void **)&deloldrdn );
628 rs.sr_err = slapi_int_connection_init( pb, LDAP_REQ_MODRDN, &conn );
629 if ( rs.sr_err != LDAP_SUCCESS ) {
633 op = (Operation *)conn->c_pending_ops.stqh_first;
635 if ( op->o_req_dn.bv_len == 0 ) {
636 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
640 newrdn.bv_val = lnewrdn;
641 newrdn.bv_len = strlen( lnewrdn );
643 rs.sr_err = dnPrettyNormal( NULL, &newrdn, &op->orr_newrdn, &op->orr_nnewrdn, NULL );
644 if ( rs.sr_err != LDAP_SUCCESS ) {
648 if ( rdn_validate( &op->orr_nnewrdn ) != LDAP_SUCCESS ) {
652 if ( newsuperior != NULL ) {
653 newsupdn.bv_val = (char *)newsuperior;
654 newsupdn.bv_len = strlen( newsuperior );
656 rs.sr_err = dnPrettyNormal( NULL, &newsupdn, &newSuperiorPretty, &newSuperiorNormalized, NULL );
657 if ( rs.sr_err != LDAP_SUCCESS )
660 op->orr_newSup = &newSuperiorPretty;
661 op->orr_nnewSup = &newSuperiorNormalized;
663 op->orr_newSup = NULL;
664 op->orr_nnewSup = NULL;
667 op->orr_deleteoldrdn = deloldrdn;
669 rs.sr_err = frontendDB->be_modrdn( op, &rs );
672 slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
674 slapi_ch_free_string( &op->orr_newrdn.bv_val );
675 slapi_ch_free_string( &op->orr_nnewrdn.bv_val );
676 slapi_ch_free_string( &newSuperiorPretty.bv_val );
677 slapi_ch_free_string( &newSuperiorNormalized.bv_val );
679 slapi_int_connection_destroy( &conn );
684 #endif /* LDAP_SLAPI */
688 slapi_modify_internal_pb( Slapi_PBlock *pb )
691 Connection *conn = NULL;
692 Operation *op = NULL;
693 LDAPMod **mods = NULL;
694 char textbuf[ SLAP_TEXT_BUFLEN ];
695 size_t textlen = sizeof( textbuf );
697 SlapReply rs = { REP_RESULT };
703 slapi_pblock_get( pb, SLAPI_MODIFY_MODS, (void **)&mods );
705 if ( mods == NULL ) {
706 rs.sr_err = LDAP_PARAM_ERROR ;
710 rs.sr_err = slapi_int_connection_init( pb, LDAP_REQ_MODIFY, &conn );
711 if ( rs.sr_err != LDAP_SUCCESS ) {
715 op = (Operation *)conn->c_pending_ops.stqh_first;
717 if ( op->o_req_ndn.bv_len == 0 ) {
718 rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
722 op->orm_modlist = slapi_int_ldapmods2modifications( mods );
724 rs.sr_err = slap_mods_check( op->orm_modlist, &rs.sr_text,
725 textbuf, textlen, NULL );
726 if ( rs.sr_err != LDAP_SUCCESS ) {
730 rs.sr_err = frontendDB->be_modify( op, &rs );
733 slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
735 slapi_int_mods_free( op->orm_modlist );
736 slapi_int_connection_destroy( &conn );
741 #endif /* LDAP_SLAPI */
746 slapi_int_search_entry_callback( Slapi_Entry *entry, void *callback_data )
748 int nentries = 0, i = 0;
749 Slapi_Entry **head = NULL, **tp;
750 Slapi_PBlock *pb = (Slapi_PBlock *)callback_data;
752 entry = slapi_entry_dup( entry );
753 if ( entry == NULL ) {
757 slapi_pblock_get( pb, SLAPI_NENTRIES, &nentries );
758 slapi_pblock_get( pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &head );
761 if ( nentries == 0 ) {
762 tp = (Slapi_Entry **)slapi_ch_malloc( 2 * sizeof(Slapi_Entry *) );
764 slapi_entry_free( entry );
770 tp = (Slapi_Entry **)slapi_ch_realloc( (char *)head,
771 sizeof(Slapi_Entry *) * ( i + 1 ) );
773 slapi_entry_free( entry );
780 slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, (void *)tp );
781 slapi_pblock_set( pb, SLAPI_NENTRIES, (void *)i );
785 #endif /* LDAP_SLAPI */
788 slapi_search_internal_pb( Slapi_PBlock *pb )
791 return slapi_search_internal_callback_pb( pb,
794 slapi_int_search_entry_callback,
802 slapi_search_internal_callback_pb( Slapi_PBlock *pb,
804 plugin_result_callback prc,
805 plugin_search_entry_callback psec,
806 plugin_referral_entry_callback prec )
809 Connection *conn = NULL;
810 Operation *op = NULL;
811 Filter *filter = NULL;
812 struct berval fstr = BER_BVNULL;
813 AttributeName *an = NULL;
814 const char *text = NULL;
816 int scope = LDAP_SCOPE_BASE;
823 SlapReply rs = { REP_RESULT };
829 slapi_pblock_get( pb, SLAPI_SEARCH_SCOPE, (void **)&scope );
830 slapi_pblock_get( pb, SLAPI_SEARCH_FILTER, (void **)&filter );
831 slapi_pblock_get( pb, SLAPI_SEARCH_STRFILTER, (void **)&filStr );
832 slapi_pblock_get( pb, SLAPI_SEARCH_ATTRS, (void **)&attrs );
833 slapi_pblock_get( pb, SLAPI_SEARCH_ATTRSONLY, (void **)&attrsonly );
835 rs.sr_err = slapi_int_connection_init( pb, LDAP_REQ_SEARCH, &conn );
836 if ( rs.sr_err != LDAP_SUCCESS ) {
840 /* search callback and arguments */
841 slapi_pblock_set( pb, SLAPI_X_INTOP_RESULT_CALLBACK, (void *)prc );
842 slapi_pblock_set( pb, SLAPI_X_INTOP_SEARCH_ENTRY_CALLBACK, (void *)psec );
843 slapi_pblock_set( pb, SLAPI_X_INTOP_REFERRAL_ENTRY_CALLBACK, (void *)prec );
844 slapi_pblock_set( pb, SLAPI_X_INTOP_CALLBACK_DATA, (void *)callback_data );
846 op = (Operation *)conn->c_pending_ops.stqh_first;
849 case LDAP_SCOPE_BASE:
850 case LDAP_SCOPE_ONELEVEL:
851 case LDAP_SCOPE_SUBTREE:
852 #ifdef LDAP_SCOPE_SUBORDINATE
853 case LDAP_SCOPE_SUBORDINATE:
857 rs.sr_err = LDAP_PROTOCOL_ERROR;
861 if ( filter == NULL ) {
862 if ( filStr == NULL ) {
863 rs.sr_err = LDAP_PARAM_ERROR;
867 filter = slapi_str2filter( filStr );
868 if ( filter == NULL ) {
869 rs.sr_err = LDAP_PROTOCOL_ERROR;
876 filter2bv( filter, &fstr );
878 for ( i = 0; attrs != NULL && attrs[i] != NULL; i++ ) {
879 ; /* count the number of attributes */
883 an = (AttributeName *)slapi_ch_calloc( (i + 1), sizeof(AttributeName) );
884 for (i = 0; attrs[i] != 0; i++) {
885 an[i].an_desc = NULL;
887 an[i].an_oc_exclude = 0;
888 an[i].an_name.bv_val = attrs[i];
889 an[i].an_name.bv_len = strlen(attrs[i]);
890 slap_bv2ad( &an[i].an_name, &an[i].an_desc, &text );
892 an[i].an_name.bv_val = NULL;
895 rs.sr_type = REP_RESULT;
896 rs.sr_err = LDAP_SUCCESS;
897 rs.sr_entry = NULL; /* paranoia */
898 op->ors_scope = scope;
900 op->ors_slimit = SLAP_NO_LIMIT;
901 op->ors_tlimit = SLAP_NO_LIMIT;
902 op->ors_attrsonly = attrsonly;
904 op->ors_filter = filter;
905 op->ors_filterstr = fstr;
907 rs.sr_err = frontendDB->be_search( op, &rs );
910 slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );
911 slapi_pblock_set( pb, SLAPI_X_INTOP_RESULT_CALLBACK, NULL );
912 slapi_pblock_set( pb, SLAPI_X_INTOP_SEARCH_ENTRY_CALLBACK, NULL );
913 slapi_pblock_set( pb, SLAPI_X_INTOP_REFERRAL_ENTRY_CALLBACK, NULL );
914 slapi_pblock_set( pb, SLAPI_X_INTOP_CALLBACK_DATA, NULL );
916 if ( freeFilter && filter != NULL )
917 slapi_filter_free( filter, 1 );
918 slapi_ch_free_string( &fstr.bv_val );
919 slapi_ch_free( (void **)&an );
921 slapi_int_connection_destroy( &conn );
926 #endif /* LDAP_SLAPI */
929 /* Wrappers for old API */
932 slapi_search_internal_set_pb( Slapi_PBlock *pb,
938 LDAPControl **controls,
939 const char *uniqueid,
940 Slapi_ComponentId *plugin_identity,
941 int operation_flags )
944 slapi_pblock_set( pb, SLAPI_SEARCH_TARGET, (void *)base );
945 slapi_pblock_set( pb, SLAPI_SEARCH_SCOPE, (void *)scope );
946 slapi_pblock_set( pb, SLAPI_SEARCH_FILTER, NULL );
947 slapi_pblock_set( pb, SLAPI_SEARCH_STRFILTER, (void *)filter );
948 slapi_pblock_set( pb, SLAPI_SEARCH_ATTRS, (void *)attrs );
949 slapi_pblock_set( pb, SLAPI_SEARCH_ATTRSONLY, (void *)attrsonly );
950 slapi_pblock_set( pb, SLAPI_REQCONTROLS, (void *)controls );
951 slapi_pblock_set( pb, SLAPI_TARGET_UNIQUEID, (void *)uniqueid );
952 slapi_pblock_set( pb, SLAPI_PLUGIN_IDENTITY, (void *)plugin_identity );
953 slapi_pblock_set( pb, SLAPI_X_INTOP_FLAGS, (void *)operation_flags );
954 #endif /* LDAP_SLAPI */
958 slapi_search_internal(
962 LDAPControl **controls,
969 pb = slapi_pblock_new();
974 slapi_search_internal_set_pb( pb, ldn, scope, filStr, attrs, attrsonly,
975 controls, NULL, NULL, 0 );
977 slapi_search_internal_pb( pb );
982 #endif /* LDAP_SLAPI */
986 slapi_modify_internal_set_pb( Slapi_PBlock *pb,
989 LDAPControl **controls,
990 const char *uniqueid,
991 Slapi_ComponentId *plugin_identity,
992 int operation_flags )
995 slapi_pblock_set( pb, SLAPI_MODIFY_TARGET, (void *)dn );
996 slapi_pblock_set( pb, SLAPI_MODIFY_MODS, (void *)mods );
997 slapi_pblock_set( pb, SLAPI_REQCONTROLS, (void *)controls );
998 slapi_pblock_set( pb, SLAPI_TARGET_UNIQUEID, (void *)uniqueid );
999 slapi_pblock_set( pb, SLAPI_PLUGIN_IDENTITY, (void *)plugin_identity );
1000 slapi_pblock_set( pb, SLAPI_X_INTOP_FLAGS, (void *)operation_flags );
1001 #endif /* LDAP_SLAPI */
1004 /* Function : slapi_modify_internal
1006 * Description: Plugin functions call this routine to modify an entry
1007 * in the backend directly
1008 * Return values : LDAP_SUCCESS
1012 * LDAP_UNWILLING_TO_PERFORM
1015 slapi_modify_internal(
1018 LDAPControl **controls,
1024 pb = slapi_pblock_new();
1029 slapi_modify_internal_set_pb( pb, ldn, mods, controls, NULL, NULL,
1030 log_change ? SLAPI_OP_FLAG_LOG_CHANGE : 0 );
1032 slapi_modify_internal_pb( pb );
1037 #endif /* LDAP_SLAPI */
1041 slapi_add_internal_set_pb( Slapi_PBlock *pb,
1044 LDAPControl **controls,
1045 Slapi_ComponentId *plugin_identity,
1046 int operation_flags )
1049 slapi_pblock_set( pb, SLAPI_ADD_TARGET, (void *)dn );
1050 slapi_pblock_set( pb, SLAPI_MODIFY_MODS, (void *)attrs );
1051 slapi_pblock_set( pb, SLAPI_REQCONTROLS, (void *)controls );
1052 slapi_pblock_set( pb, SLAPI_PLUGIN_IDENTITY, (void *)plugin_identity );
1053 slapi_pblock_set( pb, SLAPI_X_INTOP_FLAGS, (void *)operation_flags );
1058 #endif /* LDAP_SLAPI */
1065 LDAPControl **controls,
1071 pb = slapi_pblock_new();
1075 slapi_add_internal_set_pb( pb, dn, attrs, controls, NULL,
1076 log_changes ? SLAPI_OP_FLAG_LOG_CHANGE : 0 );
1078 slapi_add_internal_pb( pb );
1083 #endif /* LDAP_SLAPI */
1087 slapi_add_entry_internal_set_pb( Slapi_PBlock *pb,
1089 LDAPControl **controls,
1090 Slapi_ComponentId *plugin_identity,
1091 int operation_flags )
1094 slapi_pblock_set( pb, SLAPI_ADD_ENTRY, (void *)e );
1095 slapi_pblock_set( pb, SLAPI_REQCONTROLS, (void *)controls );
1096 slapi_pblock_set( pb, SLAPI_PLUGIN_IDENTITY, (void *)plugin_identity );
1097 slapi_pblock_set( pb, SLAPI_X_INTOP_FLAGS, (void *)operation_flags );
1098 #endif /* LDAP_SLAPI */
1102 slapi_add_entry_internal(
1104 LDAPControl **controls,
1110 pb = slapi_pblock_new();
1114 slapi_add_entry_internal_set_pb( pb, e, controls, NULL,
1115 log_changes ? SLAPI_OP_FLAG_LOG_CHANGE : 0 );
1117 slapi_add_internal_pb( pb );
1122 #endif /* LDAP_SLAPI */
1126 slapi_rename_internal_set_pb( Slapi_PBlock *pb,
1129 const char *newsuperior,
1131 LDAPControl **controls,
1132 const char *uniqueid,
1133 Slapi_ComponentId *plugin_identity,
1134 int operation_flags )
1137 slapi_pblock_set( pb, SLAPI_MODRDN_TARGET, (void *)olddn );
1138 slapi_pblock_set( pb, SLAPI_MODRDN_NEWRDN, (void *)newrdn );
1139 slapi_pblock_set( pb, SLAPI_MODRDN_NEWSUPERIOR, (void *)newsuperior );
1140 slapi_pblock_set( pb, SLAPI_MODRDN_DELOLDRDN, (void *)deloldrdn );
1141 slapi_pblock_set( pb, SLAPI_REQCONTROLS, (void *)controls );
1142 slapi_pblock_set( pb, SLAPI_TARGET_UNIQUEID, (void *)uniqueid );
1143 slapi_pblock_set( pb, SLAPI_PLUGIN_IDENTITY, (void *)plugin_identity );
1144 slapi_pblock_set( pb, SLAPI_X_INTOP_FLAGS, (void *)operation_flags );
1145 #endif /* LDAP_SLAPI */
1148 /* Function : slapi_modrdn_internal
1150 * Description : Plugin functions call this routine to modify the rdn
1151 * of an entry in the backend directly
1152 * Return values : LDAP_SUCCESS
1156 * LDAP_UNWILLING_TO_PERFORM
1158 * NOTE: This function does not support the "newSuperior" option from LDAP V3.
1161 slapi_modrdn_internal(
1165 LDAPControl **controls,
1171 pb = slapi_pblock_new();
1176 slapi_rename_internal_set_pb( pb, olddn, lnewrdn, NULL,
1177 deloldrdn, controls, NULL, NULL,
1178 log_change ? SLAPI_OP_FLAG_LOG_CHANGE : 0 );
1180 slapi_modrdn_internal_pb( pb );
1185 #endif /* LDAP_SLAPI */
1189 slapi_delete_internal_set_pb( Slapi_PBlock *pb,
1191 LDAPControl **controls,
1192 const char *uniqueid,
1193 Slapi_ComponentId *plugin_identity,
1194 int operation_flags )
1197 slapi_pblock_set( pb, SLAPI_TARGET_DN, (void *)dn );
1198 slapi_pblock_set( pb, SLAPI_REQCONTROLS, (void *)controls );
1199 slapi_pblock_set( pb, SLAPI_TARGET_UNIQUEID, (void *)uniqueid );
1200 slapi_pblock_set( pb, SLAPI_PLUGIN_IDENTITY, (void *)plugin_identity );
1201 slapi_pblock_set( pb, SLAPI_X_INTOP_FLAGS, (void *)operation_flags );
1202 #endif /* LDAP_SLAPI */
1205 /* Function : slapi_delete_internal
1207 * Description : Plugin functions call this routine to delete an entry
1208 * in the backend directly
1209 * Return values : LDAP_SUCCESS
1213 * LDAP_UNWILLING_TO_PERFORM
1216 slapi_delete_internal(
1218 LDAPControl **controls,
1224 pb = slapi_pblock_new();
1228 slapi_delete_internal_set_pb( pb, ldn, controls, NULL, NULL,
1229 log_change ? SLAPI_OP_FLAG_LOG_CHANGE : 0 );
1231 slapi_delete_internal_pb( pb );
1236 #endif /* LDAP_SLAPI */