Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / openldap / dist / servers / slapd / slapi / slapi_ops.c
blob761012514239ba5c8b51f73024f9e338c24ffbe2
1 /* $OpenLDAP: pkg/ldap/servers/slapd/slapi/slapi_ops.c,v 1.111.2.4 2008/03/21 01:01:07 hyc Exp $ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 2002-2008 The OpenLDAP Foundation.
5 * Portions Copyright 1997,2002-2003 IBM Corporation.
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
10 * Public License.
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>.
16 /* ACKNOWLEDGEMENTS:
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:
20 * Luke Howard
23 #include "portable.h"
25 #include <ac/string.h>
26 #include <ac/stdarg.h>
27 #include <ac/ctype.h>
28 #include <ac/unistd.h>
30 #include <slap.h>
31 #include <lber_pvt.h>
32 #include <slapi.h>
34 #ifdef LDAP_SLAPI
36 static struct slap_listener slapi_listener = {
37 BER_BVC("slapi://"),
38 BER_BVC("slapi://")
41 static LDAPControl **
42 slapi_int_dup_controls( LDAPControl **controls )
44 LDAPControl **c;
45 size_t i;
47 if ( controls == NULL )
48 return NULL;
50 for ( i = 0; controls[i] != NULL; i++ )
53 c = (LDAPControl **) slapi_ch_calloc( i + 1, sizeof(LDAPControl *) );
55 for ( i = 0; controls[i] != NULL; i++ ) {
56 c[i] = slapi_dup_control( controls[i] );
59 return c;
62 static int
63 slapi_int_result(
64 Operation *op,
65 SlapReply *rs )
67 Slapi_PBlock *pb = SLAPI_OPERATION_PBLOCK( op );
68 plugin_result_callback prc = NULL;
69 void *callback_data = NULL;
70 LDAPControl **ctrls = NULL;
72 assert( pb != NULL );
74 slapi_pblock_get( pb, SLAPI_X_INTOP_RESULT_CALLBACK, (void **)&prc );
75 slapi_pblock_get( pb, SLAPI_X_INTOP_CALLBACK_DATA, &callback_data );
77 /* we need to duplicate controls because they might go out of scope */
78 ctrls = slapi_int_dup_controls( rs->sr_ctrls );
79 slapi_pblock_set( pb, SLAPI_RESCONTROLS, ctrls );
81 if ( prc != NULL ) {
82 (*prc)( rs->sr_err, callback_data );
85 return rs->sr_err;
88 static int
89 slapi_int_search_entry(
90 Operation *op,
91 SlapReply *rs )
93 Slapi_PBlock *pb = SLAPI_OPERATION_PBLOCK( op );
94 plugin_search_entry_callback psec = NULL;
95 void *callback_data = NULL;
96 int rc = LDAP_SUCCESS;
98 assert( pb != NULL );
100 slapi_pblock_get( pb, SLAPI_X_INTOP_SEARCH_ENTRY_CALLBACK, (void **)&psec );
101 slapi_pblock_get( pb, SLAPI_X_INTOP_CALLBACK_DATA, &callback_data );
103 if ( psec != NULL ) {
104 rc = (*psec)( rs->sr_entry, callback_data );
107 return rc;
110 static int
111 slapi_int_search_reference(
112 Operation *op,
113 SlapReply *rs )
115 int i, rc = LDAP_SUCCESS;
116 plugin_referral_entry_callback prec = NULL;
117 void *callback_data = NULL;
118 Slapi_PBlock *pb = SLAPI_OPERATION_PBLOCK( op );
120 assert( pb != NULL );
122 slapi_pblock_get( pb, SLAPI_X_INTOP_REFERRAL_ENTRY_CALLBACK, (void **)&prec );
123 slapi_pblock_get( pb, SLAPI_X_INTOP_CALLBACK_DATA, &callback_data );
125 if ( prec != NULL ) {
126 for ( i = 0; rs->sr_ref[i].bv_val != NULL; i++ ) {
127 rc = (*prec)( rs->sr_ref[i].bv_val, callback_data );
128 if ( rc != LDAP_SUCCESS ) {
129 break;
134 return rc;
138 slapi_int_response( Slapi_Operation *op, SlapReply *rs )
140 int rc;
142 switch ( rs->sr_type ) {
143 case REP_RESULT:
144 rc = slapi_int_result( op, rs );
145 break;
146 case REP_SEARCH:
147 rc = slapi_int_search_entry( op, rs );
148 break;
149 case REP_SEARCHREF:
150 rc = slapi_int_search_reference( op, rs );
151 break;
152 default:
153 rc = LDAP_OTHER;
154 break;
157 assert( rc != SLAP_CB_CONTINUE ); /* never try to send a wire response */
159 return rc;
162 static int
163 slapi_int_get_ctrls( Slapi_PBlock *pb )
165 LDAPControl **c;
166 int rc = LDAP_SUCCESS;
168 if ( pb->pb_op->o_ctrls != NULL ) {
169 for ( c = pb->pb_op->o_ctrls; *c != NULL; c++ ) {
170 rc = slap_parse_ctrl( pb->pb_op, pb->pb_rs, *c, &pb->pb_rs->sr_text );
171 if ( rc != LDAP_SUCCESS )
172 break;
176 return rc;
179 void
180 slapi_int_connection_init_pb( Slapi_PBlock *pb, ber_tag_t tag )
182 Connection *conn;
183 Operation *op;
184 ber_len_t max = sockbuf_max_incoming;
186 conn = (Connection *) slapi_ch_calloc( 1, sizeof(Connection) );
188 LDAP_STAILQ_INIT( &conn->c_pending_ops );
190 op = (Operation *) slapi_ch_calloc( 1, sizeof(OperationBuffer) );
191 op->o_hdr = &((OperationBuffer *) op)->ob_hdr;
192 op->o_controls = ((OperationBuffer *) op)->ob_controls;
194 op->o_callback = (slap_callback *) slapi_ch_calloc( 1, sizeof(slap_callback) );
195 op->o_callback->sc_response = slapi_int_response;
196 op->o_callback->sc_cleanup = NULL;
197 op->o_callback->sc_private = pb;
198 op->o_callback->sc_next = NULL;
200 conn->c_pending_ops.stqh_first = op;
202 /* connection object authorization information */
203 conn->c_authtype = LDAP_AUTH_NONE;
204 BER_BVZERO( &conn->c_authmech );
205 BER_BVZERO( &conn->c_dn );
206 BER_BVZERO( &conn->c_ndn );
208 conn->c_listener = &slapi_listener;
209 ber_dupbv( &conn->c_peer_domain, (struct berval *)&slap_unknown_bv );
210 ber_dupbv( &conn->c_peer_name, (struct berval *)&slap_unknown_bv );
212 LDAP_STAILQ_INIT( &conn->c_ops );
214 BER_BVZERO( &conn->c_sasl_bind_mech );
215 conn->c_sasl_authctx = NULL;
216 conn->c_sasl_sockctx = NULL;
217 conn->c_sasl_extra = NULL;
219 conn->c_sb = ber_sockbuf_alloc();
221 ber_sockbuf_ctrl( conn->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
223 conn->c_currentber = NULL;
225 /* should check status of thread calls */
226 ldap_pvt_thread_mutex_init( &conn->c_mutex );
227 ldap_pvt_thread_mutex_init( &conn->c_write_mutex );
228 ldap_pvt_thread_cond_init( &conn->c_write_cv );
230 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
232 conn->c_n_ops_received = 0;
233 conn->c_n_ops_executing = 0;
234 conn->c_n_ops_pending = 0;
235 conn->c_n_ops_completed = 0;
237 conn->c_n_get = 0;
238 conn->c_n_read = 0;
239 conn->c_n_write = 0;
241 conn->c_protocol = LDAP_VERSION3;
243 conn->c_activitytime = conn->c_starttime = slap_get_time();
246 * A real connection ID is required, because syncrepl associates
247 * pending CSNs with unique ( connection, operation ) tuples.
248 * Setting a fake connection ID will cause slap_get_commit_csn()
249 * to return a stale value.
251 connection_assign_nextid( conn );
253 conn->c_conn_state = 0x01; /* SLAP_C_ACTIVE */
254 conn->c_struct_state = 0x02; /* SLAP_C_USED */
256 conn->c_ssf = conn->c_transport_ssf = local_ssf;
257 conn->c_tls_ssf = 0;
259 backend_connection_init( conn );
261 conn->c_send_ldap_result = slap_send_ldap_result;
262 conn->c_send_search_entry = slap_send_search_entry;
263 conn->c_send_ldap_extended = slap_send_ldap_extended;
264 conn->c_send_search_reference = slap_send_search_reference;
266 /* operation object */
267 op->o_tag = tag;
268 op->o_protocol = LDAP_VERSION3;
269 BER_BVZERO( &op->o_authmech );
270 op->o_time = slap_get_time();
271 op->o_do_not_cache = 1;
272 op->o_threadctx = ldap_pvt_thread_pool_context();
273 op->o_tmpmemctx = NULL;
274 op->o_tmpmfuncs = &ch_mfuncs;
275 op->o_conn = conn;
276 op->o_connid = conn->c_connid;
277 op->o_bd = frontendDB;
279 /* extensions */
280 slapi_int_create_object_extensions( SLAPI_X_EXT_OPERATION, op );
281 slapi_int_create_object_extensions( SLAPI_X_EXT_CONNECTION, conn );
283 pb->pb_rs = (SlapReply *)slapi_ch_calloc( 1, sizeof(SlapReply) );
284 pb->pb_op = op;
285 pb->pb_conn = conn;
286 pb->pb_intop = 1;
288 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
291 static void
292 slapi_int_set_operation_dn( Slapi_PBlock *pb )
294 Backend *be;
295 Operation *op = pb->pb_op;
297 if ( BER_BVISNULL( &op->o_ndn ) ) {
298 /* set to root DN */
299 be = select_backend( &op->o_req_ndn, 1 );
300 if ( be != NULL ) {
301 ber_dupbv( &op->o_dn, &be->be_rootdn );
302 ber_dupbv( &op->o_ndn, &be->be_rootndn );
307 void
308 slapi_int_connection_done_pb( Slapi_PBlock *pb )
310 Connection *conn;
311 Operation *op;
313 PBLOCK_ASSERT_INTOP( pb, 0 );
315 conn = pb->pb_conn;
316 op = pb->pb_op;
318 /* free allocated DNs */
319 if ( !BER_BVISNULL( &op->o_dn ) )
320 op->o_tmpfree( op->o_dn.bv_val, op->o_tmpmemctx );
321 if ( !BER_BVISNULL( &op->o_ndn ) )
322 op->o_tmpfree( op->o_ndn.bv_val, op->o_tmpmemctx );
324 if ( !BER_BVISNULL( &op->o_req_dn ) )
325 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
326 if ( !BER_BVISNULL( &op->o_req_ndn ) )
327 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
329 switch ( op->o_tag ) {
330 case LDAP_REQ_MODRDN:
331 if ( !BER_BVISNULL( &op->orr_newrdn ))
332 op->o_tmpfree( op->orr_newrdn.bv_val, op->o_tmpmemctx );
333 if ( !BER_BVISNULL( &op->orr_nnewrdn ))
334 op->o_tmpfree( op->orr_nnewrdn.bv_val, op->o_tmpmemctx );
335 if ( op->orr_newSup != NULL ) {
336 assert( !BER_BVISNULL( op->orr_newSup ) );
337 op->o_tmpfree( op->orr_newSup->bv_val, op->o_tmpmemctx );
338 op->o_tmpfree( op->orr_newSup, op->o_tmpmemctx );
340 if ( op->orr_nnewSup != NULL ) {
341 assert( !BER_BVISNULL( op->orr_nnewSup ) );
342 op->o_tmpfree( op->orr_nnewSup->bv_val, op->o_tmpmemctx );
343 op->o_tmpfree( op->orr_nnewSup, op->o_tmpmemctx );
345 slap_mods_free( op->orr_modlist, 1 );
346 break;
347 case LDAP_REQ_ADD:
348 slap_mods_free( op->ora_modlist, 0 );
349 break;
350 case LDAP_REQ_MODIFY:
351 slap_mods_free( op->orm_modlist, 1 );
352 break;
353 case LDAP_REQ_SEARCH:
354 if ( op->ors_attrs != NULL ) {
355 op->o_tmpfree( op->ors_attrs, op->o_tmpmemctx );
356 op->ors_attrs = NULL;
358 break;
359 default:
360 break;
363 slapi_ch_free_string( &conn->c_authmech.bv_val );
364 slapi_ch_free_string( &conn->c_dn.bv_val );
365 slapi_ch_free_string( &conn->c_ndn.bv_val );
366 slapi_ch_free_string( &conn->c_peer_domain.bv_val );
367 slapi_ch_free_string( &conn->c_peer_name.bv_val );
369 if ( conn->c_sb != NULL ) {
370 ber_sockbuf_free( conn->c_sb );
373 slapi_int_free_object_extensions( SLAPI_X_EXT_OPERATION, op );
374 slapi_int_free_object_extensions( SLAPI_X_EXT_CONNECTION, conn );
376 slapi_ch_free( (void **)&pb->pb_op->o_callback );
377 slapi_ch_free( (void **)&pb->pb_op );
378 slapi_ch_free( (void **)&pb->pb_conn );
379 slapi_ch_free( (void **)&pb->pb_rs );
382 static int
383 slapi_int_func_internal_pb( Slapi_PBlock *pb, slap_operation_t which )
385 BI_op_bind **func;
386 SlapReply *rs = pb->pb_rs;
387 int rc;
389 PBLOCK_ASSERT_INTOP( pb, 0 );
391 rc = slapi_int_get_ctrls( pb );
392 if ( rc != LDAP_SUCCESS ) {
393 rs->sr_err = rc;
394 return rc;
397 pb->pb_op->o_bd = frontendDB;
398 func = &frontendDB->be_bind;
400 return func[which]( pb->pb_op, pb->pb_rs );
404 slapi_delete_internal_pb( Slapi_PBlock *pb )
406 if ( pb == NULL ) {
407 return -1;
410 PBLOCK_ASSERT_INTOP( pb, LDAP_REQ_DELETE );
412 slapi_int_func_internal_pb( pb, op_delete );
414 return 0;
418 slapi_add_internal_pb( Slapi_PBlock *pb )
420 SlapReply *rs;
421 Slapi_Entry *entry_orig = NULL;
422 OpExtraDB oex;
423 int rc;
425 if ( pb == NULL ) {
426 return -1;
429 PBLOCK_ASSERT_INTOP( pb, LDAP_REQ_ADD );
431 rs = pb->pb_rs;
433 entry_orig = pb->pb_op->ora_e;
434 pb->pb_op->ora_e = NULL;
437 * The caller can specify a new entry, or a target DN and set
438 * of modifications, but not both.
440 if ( entry_orig != NULL ) {
441 if ( pb->pb_op->ora_modlist != NULL || !BER_BVISNULL( &pb->pb_op->o_req_ndn )) {
442 rs->sr_err = LDAP_PARAM_ERROR;
443 goto cleanup;
446 assert( BER_BVISNULL( &pb->pb_op->o_req_dn ) ); /* shouldn't get set */
447 ber_dupbv( &pb->pb_op->o_req_dn, &entry_orig->e_name );
448 ber_dupbv( &pb->pb_op->o_req_ndn, &entry_orig->e_nname );
449 } else if ( pb->pb_op->ora_modlist == NULL || BER_BVISNULL( &pb->pb_op->o_req_ndn )) {
450 rs->sr_err = LDAP_PARAM_ERROR;
451 goto cleanup;
454 pb->pb_op->ora_e = (Entry *)slapi_ch_calloc( 1, sizeof(Entry) );
455 ber_dupbv( &pb->pb_op->ora_e->e_name, &pb->pb_op->o_req_dn );
456 ber_dupbv( &pb->pb_op->ora_e->e_nname, &pb->pb_op->o_req_ndn );
458 if ( entry_orig != NULL ) {
459 assert( pb->pb_op->ora_modlist == NULL );
461 rs->sr_err = slap_entry2mods( entry_orig, &pb->pb_op->ora_modlist,
462 &rs->sr_text, pb->pb_textbuf, sizeof( pb->pb_textbuf ) );
463 if ( rs->sr_err != LDAP_SUCCESS ) {
464 goto cleanup;
466 } else {
467 assert( pb->pb_op->ora_modlist != NULL );
470 rs->sr_err = slap_mods_check( pb->pb_op, pb->pb_op->ora_modlist, &rs->sr_text,
471 pb->pb_textbuf, sizeof( pb->pb_textbuf ), NULL );
472 if ( rs->sr_err != LDAP_SUCCESS ) {
473 goto cleanup;
476 /* Duplicate the values, because we may call slapi_entry_free() */
477 rs->sr_err = slap_mods2entry( pb->pb_op->ora_modlist, &pb->pb_op->ora_e,
478 1, 0, &rs->sr_text, pb->pb_textbuf, sizeof( pb->pb_textbuf ) );
479 if ( rs->sr_err != LDAP_SUCCESS ) {
480 goto cleanup;
483 oex.oe.oe_key = (void *)do_add;
484 oex.oe_db = NULL;
485 LDAP_SLIST_INSERT_HEAD(&pb->pb_op->o_extra, &oex.oe, oe_next);
486 rc = slapi_int_func_internal_pb( pb, op_add );
487 LDAP_SLIST_REMOVE(&pb->pb_op->o_extra, &oex.oe, OpExtra, oe_next);
489 if ( !rc ) {
490 if ( pb->pb_op->ora_e != NULL && oex.oe_db != NULL ) {
491 BackendDB *bd = pb->pb_op->o_bd;
493 pb->pb_op->o_bd = oex.oe_db;
494 be_entry_release_w( pb->pb_op, pb->pb_op->ora_e );
495 pb->pb_op->ora_e = NULL;
496 pb->pb_op->o_bd = bd;
500 cleanup:
502 if ( pb->pb_op->ora_e != NULL ) {
503 slapi_entry_free( pb->pb_op->ora_e );
504 pb->pb_op->ora_e = NULL;
506 if ( entry_orig != NULL ) {
507 pb->pb_op->ora_e = entry_orig;
508 slap_mods_free( pb->pb_op->ora_modlist, 1 );
509 pb->pb_op->ora_modlist = NULL;
512 return 0;
516 slapi_modrdn_internal_pb( Slapi_PBlock *pb )
518 if ( pb == NULL ) {
519 return -1;
522 PBLOCK_ASSERT_INTOP( pb, LDAP_REQ_MODRDN );
524 if ( BER_BVISEMPTY( &pb->pb_op->o_req_ndn ) ) {
525 pb->pb_rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
526 goto cleanup;
529 slapi_int_func_internal_pb( pb, op_modrdn );
531 cleanup:
533 return 0;
537 slapi_modify_internal_pb( Slapi_PBlock *pb )
539 SlapReply *rs;
541 if ( pb == NULL ) {
542 return -1;
545 PBLOCK_ASSERT_INTOP( pb, LDAP_REQ_MODIFY );
547 rs = pb->pb_rs;
549 if ( pb->pb_op->orm_modlist == NULL ) {
550 rs->sr_err = LDAP_PARAM_ERROR;
551 goto cleanup;
554 if ( BER_BVISEMPTY( &pb->pb_op->o_req_ndn ) ) {
555 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
556 goto cleanup;
559 rs->sr_err = slap_mods_check( pb->pb_op, pb->pb_op->orm_modlist,
560 &rs->sr_text, pb->pb_textbuf, sizeof( pb->pb_textbuf ), NULL );
561 if ( rs->sr_err != LDAP_SUCCESS ) {
562 goto cleanup;
565 slapi_int_func_internal_pb( pb, op_modify );
567 cleanup:
569 return 0;
572 static int
573 slapi_int_search_entry_callback( Slapi_Entry *entry, void *callback_data )
575 int nentries = 0, i = 0;
576 Slapi_Entry **head = NULL, **tp;
577 Slapi_PBlock *pb = (Slapi_PBlock *)callback_data;
579 PBLOCK_ASSERT_INTOP( pb, LDAP_REQ_SEARCH );
581 entry = slapi_entry_dup( entry );
582 if ( entry == NULL ) {
583 return LDAP_NO_MEMORY;
586 slapi_pblock_get( pb, SLAPI_NENTRIES, &nentries );
587 slapi_pblock_get( pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &head );
589 i = nentries + 1;
590 if ( nentries == 0 ) {
591 tp = (Slapi_Entry **)slapi_ch_malloc( 2 * sizeof(Slapi_Entry *) );
592 if ( tp == NULL ) {
593 slapi_entry_free( entry );
594 return LDAP_NO_MEMORY;
597 tp[0] = entry;
598 } else {
599 tp = (Slapi_Entry **)slapi_ch_realloc( (char *)head,
600 sizeof(Slapi_Entry *) * ( i + 1 ) );
601 if ( tp == NULL ) {
602 slapi_entry_free( entry );
603 return LDAP_NO_MEMORY;
605 tp[i - 1] = entry;
607 tp[i] = NULL;
609 slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, (void *)tp );
610 slapi_pblock_set( pb, SLAPI_NENTRIES, (void *)&i );
612 return LDAP_SUCCESS;
616 slapi_search_internal_pb( Slapi_PBlock *pb )
618 return slapi_search_internal_callback_pb( pb,
619 (void *)pb,
620 NULL,
621 slapi_int_search_entry_callback,
622 NULL );
626 slapi_search_internal_callback_pb( Slapi_PBlock *pb,
627 void *callback_data,
628 plugin_result_callback prc,
629 plugin_search_entry_callback psec,
630 plugin_referral_entry_callback prec )
632 int free_filter = 0;
633 SlapReply *rs;
635 if ( pb == NULL ) {
636 return -1;
639 PBLOCK_ASSERT_INTOP( pb, LDAP_REQ_SEARCH );
641 rs = pb->pb_rs;
643 /* search callback and arguments */
644 slapi_pblock_set( pb, SLAPI_X_INTOP_RESULT_CALLBACK, (void *)prc );
645 slapi_pblock_set( pb, SLAPI_X_INTOP_SEARCH_ENTRY_CALLBACK, (void *)psec );
646 slapi_pblock_set( pb, SLAPI_X_INTOP_REFERRAL_ENTRY_CALLBACK, (void *)prec );
647 slapi_pblock_set( pb, SLAPI_X_INTOP_CALLBACK_DATA, (void *)callback_data );
649 if ( BER_BVISEMPTY( &pb->pb_op->ors_filterstr )) {
650 rs->sr_err = LDAP_PARAM_ERROR;
651 goto cleanup;
654 if ( pb->pb_op->ors_filter == NULL ) {
655 pb->pb_op->ors_filter = slapi_str2filter( pb->pb_op->ors_filterstr.bv_val );
656 if ( pb->pb_op->ors_filter == NULL ) {
657 rs->sr_err = LDAP_PROTOCOL_ERROR;
658 goto cleanup;
661 free_filter = 1;
664 slapi_int_func_internal_pb( pb, op_search );
666 cleanup:
667 if ( free_filter ) {
668 slapi_filter_free( pb->pb_op->ors_filter, 1 );
669 pb->pb_op->ors_filter = NULL;
672 slapi_pblock_delete_param( pb, SLAPI_X_INTOP_RESULT_CALLBACK );
673 slapi_pblock_delete_param( pb, SLAPI_X_INTOP_SEARCH_ENTRY_CALLBACK );
674 slapi_pblock_delete_param( pb, SLAPI_X_INTOP_REFERRAL_ENTRY_CALLBACK );
675 slapi_pblock_delete_param( pb, SLAPI_X_INTOP_CALLBACK_DATA );
677 return 0;
680 /* Wrappers for old API */
682 void
683 slapi_search_internal_set_pb( Slapi_PBlock *pb,
684 const char *base,
685 int scope,
686 const char *filter,
687 char **attrs,
688 int attrsonly,
689 LDAPControl **controls,
690 const char *uniqueid,
691 Slapi_ComponentId *plugin_identity,
692 int operation_flags )
694 int no_limit = SLAP_NO_LIMIT;
695 int deref = LDAP_DEREF_NEVER;
697 slapi_int_connection_init_pb( pb, LDAP_REQ_SEARCH );
698 slapi_pblock_set( pb, SLAPI_SEARCH_TARGET, (void *)base );
699 slapi_pblock_set( pb, SLAPI_SEARCH_SCOPE, (void *)&scope );
700 slapi_pblock_set( pb, SLAPI_SEARCH_FILTER, (void *)0 );
701 slapi_pblock_set( pb, SLAPI_SEARCH_STRFILTER, (void *)filter );
702 slapi_pblock_set( pb, SLAPI_SEARCH_ATTRS, (void *)attrs );
703 slapi_pblock_set( pb, SLAPI_SEARCH_ATTRSONLY, (void *)&attrsonly );
704 slapi_pblock_set( pb, SLAPI_REQCONTROLS, (void *)controls );
705 slapi_pblock_set( pb, SLAPI_TARGET_UNIQUEID, (void *)uniqueid );
706 slapi_pblock_set( pb, SLAPI_PLUGIN_IDENTITY, (void *)plugin_identity );
707 slapi_pblock_set( pb, SLAPI_X_INTOP_FLAGS, (void *)&operation_flags );
708 slapi_pblock_set( pb, SLAPI_SEARCH_DEREF, (void *)&deref );
709 slapi_pblock_set( pb, SLAPI_SEARCH_SIZELIMIT, (void *)&no_limit );
710 slapi_pblock_set( pb, SLAPI_SEARCH_TIMELIMIT, (void *)&no_limit );
712 slapi_int_set_operation_dn( pb );
715 Slapi_PBlock *
716 slapi_search_internal(
717 char *ldn,
718 int scope,
719 char *filStr,
720 LDAPControl **controls,
721 char **attrs,
722 int attrsonly )
724 Slapi_PBlock *pb;
726 pb = slapi_pblock_new();
728 slapi_search_internal_set_pb( pb, ldn, scope, filStr,
729 attrs, attrsonly,
730 controls, NULL, NULL, 0 );
732 slapi_search_internal_pb( pb );
734 return pb;
737 void
738 slapi_modify_internal_set_pb( Slapi_PBlock *pb,
739 const char *dn,
740 LDAPMod **mods,
741 LDAPControl **controls,
742 const char *uniqueid,
743 Slapi_ComponentId *plugin_identity,
744 int operation_flags )
746 slapi_int_connection_init_pb( pb, LDAP_REQ_MODIFY );
747 slapi_pblock_set( pb, SLAPI_MODIFY_TARGET, (void *)dn );
748 slapi_pblock_set( pb, SLAPI_MODIFY_MODS, (void *)mods );
749 slapi_pblock_set( pb, SLAPI_REQCONTROLS, (void *)controls );
750 slapi_pblock_set( pb, SLAPI_TARGET_UNIQUEID, (void *)uniqueid );
751 slapi_pblock_set( pb, SLAPI_PLUGIN_IDENTITY, (void *)plugin_identity );
752 slapi_pblock_set( pb, SLAPI_X_INTOP_FLAGS, (void *)&operation_flags );
753 slapi_int_set_operation_dn( pb );
756 /* Function : slapi_modify_internal
758 * Description: Plugin functions call this routine to modify an entry
759 * in the backend directly
760 * Return values : LDAP_SUCCESS
761 * LDAP_PARAM_ERROR
762 * LDAP_NO_MEMORY
763 * LDAP_OTHER
764 * LDAP_UNWILLING_TO_PERFORM
766 Slapi_PBlock *
767 slapi_modify_internal(
768 char *ldn,
769 LDAPMod **mods,
770 LDAPControl **controls,
771 int log_change )
773 Slapi_PBlock *pb;
775 pb = slapi_pblock_new();
777 slapi_modify_internal_set_pb( pb, ldn, mods, controls, NULL, NULL, 0 );
778 slapi_pblock_set( pb, SLAPI_LOG_OPERATION, (void *)&log_change );
779 slapi_modify_internal_pb( pb );
781 return pb;
785 slapi_add_internal_set_pb( Slapi_PBlock *pb,
786 const char *dn,
787 LDAPMod **attrs,
788 LDAPControl **controls,
789 Slapi_ComponentId *plugin_identity,
790 int operation_flags )
792 slapi_int_connection_init_pb( pb, LDAP_REQ_ADD );
793 slapi_pblock_set( pb, SLAPI_ADD_TARGET, (void *)dn );
794 slapi_pblock_set( pb, SLAPI_MODIFY_MODS, (void *)attrs );
795 slapi_pblock_set( pb, SLAPI_REQCONTROLS, (void *)controls );
796 slapi_pblock_set( pb, SLAPI_PLUGIN_IDENTITY, (void *)plugin_identity );
797 slapi_pblock_set( pb, SLAPI_X_INTOP_FLAGS, (void *)&operation_flags );
798 slapi_int_set_operation_dn( pb );
800 return 0;
803 Slapi_PBlock *
804 slapi_add_internal(
805 char * dn,
806 LDAPMod **attrs,
807 LDAPControl **controls,
808 int log_change )
810 Slapi_PBlock *pb;
812 pb = slapi_pblock_new();
814 slapi_add_internal_set_pb( pb, dn, attrs, controls, NULL, 0);
815 slapi_pblock_set( pb, SLAPI_LOG_OPERATION, (void *)&log_change );
816 slapi_add_internal_pb( pb );
818 return pb;
821 void
822 slapi_add_entry_internal_set_pb( Slapi_PBlock *pb,
823 Slapi_Entry *e,
824 LDAPControl **controls,
825 Slapi_ComponentId *plugin_identity,
826 int operation_flags )
828 slapi_int_connection_init_pb( pb, LDAP_REQ_ADD );
829 slapi_pblock_set( pb, SLAPI_ADD_ENTRY, (void *)e );
830 slapi_pblock_set( pb, SLAPI_REQCONTROLS, (void *)controls );
831 slapi_pblock_set( pb, SLAPI_PLUGIN_IDENTITY, (void *)plugin_identity );
832 slapi_pblock_set( pb, SLAPI_X_INTOP_FLAGS, (void *)&operation_flags );
833 slapi_int_set_operation_dn( pb );
836 Slapi_PBlock *
837 slapi_add_entry_internal(
838 Slapi_Entry *e,
839 LDAPControl **controls,
840 int log_change )
842 Slapi_PBlock *pb;
844 pb = slapi_pblock_new();
846 slapi_add_entry_internal_set_pb( pb, e, controls, NULL, 0 );
847 slapi_pblock_set( pb, SLAPI_LOG_OPERATION, (void *)&log_change );
848 slapi_add_internal_pb( pb );
850 return pb;
853 void
854 slapi_rename_internal_set_pb( Slapi_PBlock *pb,
855 const char *olddn,
856 const char *newrdn,
857 const char *newsuperior,
858 int deloldrdn,
859 LDAPControl **controls,
860 const char *uniqueid,
861 Slapi_ComponentId *plugin_identity,
862 int operation_flags )
864 slapi_int_connection_init_pb( pb, LDAP_REQ_MODRDN );
865 slapi_pblock_set( pb, SLAPI_MODRDN_TARGET, (void *)olddn );
866 slapi_pblock_set( pb, SLAPI_MODRDN_NEWRDN, (void *)newrdn );
867 slapi_pblock_set( pb, SLAPI_MODRDN_NEWSUPERIOR, (void *)newsuperior );
868 slapi_pblock_set( pb, SLAPI_MODRDN_DELOLDRDN, (void *)&deloldrdn );
869 slapi_pblock_set( pb, SLAPI_REQCONTROLS, (void *)controls );
870 slapi_pblock_set( pb, SLAPI_TARGET_UNIQUEID, (void *)uniqueid );
871 slapi_pblock_set( pb, SLAPI_PLUGIN_IDENTITY, (void *)plugin_identity );
872 slapi_pblock_set( pb, SLAPI_X_INTOP_FLAGS, (void *)&operation_flags );
873 slap_modrdn2mods( pb->pb_op, pb->pb_rs );
874 slapi_int_set_operation_dn( pb );
877 /* Function : slapi_modrdn_internal
879 * Description : Plugin functions call this routine to modify the rdn
880 * of an entry in the backend directly
881 * Return values : LDAP_SUCCESS
882 * LDAP_PARAM_ERROR
883 * LDAP_NO_MEMORY
884 * LDAP_OTHER
885 * LDAP_UNWILLING_TO_PERFORM
887 * NOTE: This function does not support the "newSuperior" option from LDAP V3.
889 Slapi_PBlock *
890 slapi_modrdn_internal(
891 char *olddn,
892 char *lnewrdn,
893 int deloldrdn,
894 LDAPControl **controls,
895 int log_change )
897 Slapi_PBlock *pb;
899 pb = slapi_pblock_new ();
901 slapi_rename_internal_set_pb( pb, olddn, lnewrdn, NULL,
902 deloldrdn, controls, NULL, NULL, 0 );
903 slapi_pblock_set( pb, SLAPI_LOG_OPERATION, (void *)&log_change );
904 slapi_modrdn_internal_pb( pb );
906 return pb;
909 void
910 slapi_delete_internal_set_pb( Slapi_PBlock *pb,
911 const char *dn,
912 LDAPControl **controls,
913 const char *uniqueid,
914 Slapi_ComponentId *plugin_identity,
915 int operation_flags )
917 slapi_int_connection_init_pb( pb, LDAP_REQ_DELETE );
918 slapi_pblock_set( pb, SLAPI_TARGET_DN, (void *)dn );
919 slapi_pblock_set( pb, SLAPI_REQCONTROLS, (void *)controls );
920 slapi_pblock_set( pb, SLAPI_TARGET_UNIQUEID, (void *)uniqueid );
921 slapi_pblock_set( pb, SLAPI_PLUGIN_IDENTITY, (void *)plugin_identity );
922 slapi_pblock_set( pb, SLAPI_X_INTOP_FLAGS, (void *)&operation_flags );
923 slapi_int_set_operation_dn( pb );
926 /* Function : slapi_delete_internal
928 * Description : Plugin functions call this routine to delete an entry
929 * in the backend directly
930 * Return values : LDAP_SUCCESS
931 * LDAP_PARAM_ERROR
932 * LDAP_NO_MEMORY
933 * LDAP_OTHER
934 * LDAP_UNWILLING_TO_PERFORM
936 Slapi_PBlock *
937 slapi_delete_internal(
938 char *ldn,
939 LDAPControl **controls,
940 int log_change )
942 Slapi_PBlock *pb;
944 pb = slapi_pblock_new();
946 slapi_delete_internal_set_pb( pb, ldn, controls, NULL, NULL, 0 );
947 slapi_pblock_set( pb, SLAPI_LOG_OPERATION, (void *)&log_change );
948 slapi_delete_internal_pb( pb );
950 return pb;
953 #endif /* LDAP_SLAPI */