]> git.sur5r.net Git - openldap/blob - servers/slapd/slapi/slapi_ops.c
use slapi_pblock_delete_param()
[openldap] / servers / slapd / slapi / slapi_ops.c
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 2002-2005 The OpenLDAP Foundation.
5  * Portions Copyright 1997,2002-2003 IBM Corporation.
6  * All rights reserved.
7  *
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.
11  *
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>.
15  */
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
21  */
22
23 #include "portable.h"
24
25 #include <ac/string.h>
26 #include <ac/stdarg.h>
27 #include <ac/ctype.h>
28 #include <ac/unistd.h>
29
30 #include <slap.h>
31 #include <lber_pvt.h>
32 #include <slapi.h>
33
34 #ifdef LDAP_SLAPI
35
36 static struct slap_listener slapi_listener = {
37         BER_BVC("slapi://"),
38         BER_BVC("slapi://")
39 };
40
41 static LDAPControl **
42 slapi_int_dup_controls( LDAPControl **controls )
43 {
44         LDAPControl **c;
45         size_t i;
46
47         if ( controls == NULL )
48                 return NULL;
49
50         for ( i = 0; controls[i] != NULL; i++ )
51                 ;
52
53         c = (LDAPControl **) slapi_ch_calloc( i + 1, sizeof(LDAPControl *) );
54
55         for ( i = 0; controls[i] != NULL; i++ ) {
56                 c[i] = slapi_dup_control( controls[i] );
57         }
58
59         return c;
60 }
61
62 static int
63 slapi_int_result(
64         Operation       *op, 
65         SlapReply       *rs )
66 {
67         Slapi_PBlock            *pb = SLAPI_OPERATION_PBLOCK( op );
68         plugin_result_callback  prc = NULL;
69         void                    *callback_data = NULL;
70         LDAPControl             **ctrls = NULL;
71
72         assert( pb != NULL );   
73
74         slapi_pblock_get( pb, SLAPI_X_INTOP_RESULT_CALLBACK, (void **)&prc );
75         slapi_pblock_get( pb, SLAPI_X_INTOP_CALLBACK_DATA,   &callback_data );
76
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 );
80
81         if ( prc != NULL ) {
82                 (*prc)( rs->sr_err, callback_data );
83         }
84
85         return rs->sr_err;
86 }
87
88 static int
89 slapi_int_search_entry(
90         Operation       *op,
91         SlapReply       *rs )
92 {
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;
97
98         assert( pb != NULL );
99
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 );
102
103         if ( psec != NULL ) {
104                 rc = (*psec)( rs->sr_entry, callback_data );
105         }
106
107         return rc;
108 }
109
110 static int
111 slapi_int_search_reference(
112         Operation       *op,    
113         SlapReply       *rs )
114 {
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 );
119
120         assert( pb != NULL );
121
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 );
124
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;
130                         }
131                 }
132         }
133
134         return rc;
135 }
136
137 int
138 slapi_int_response( Slapi_Operation *op, SlapReply *rs )
139 {
140         int                             rc;
141
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;
155         }
156
157         assert( rc != SLAP_CB_CONTINUE ); /* never try to send a wire response */
158
159         return rc;
160 }
161
162 static int
163 slapi_int_get_ctrls( Slapi_PBlock *pb )
164 {
165         LDAPControl             **c;
166         int                     rc = LDAP_SUCCESS;
167
168         if ( pb->pop->o_ctrls != NULL ) {
169                 for ( c = pb->pop->o_ctrls; *c != NULL; c++ ) {
170                         rc = slap_parse_ctrl( pb->pop, &pb->rs, *c, &pb->rs.sr_text );
171                         if ( rc != LDAP_SUCCESS )
172                                 break;
173                 }
174         }
175
176         return rc;
177 }
178
179 void
180 slapi_int_connection_init_pb( Slapi_PBlock *pb, ber_tag_t tag )
181 {
182         Connection              *conn;
183         Operation               *op;
184         ber_len_t               max = sockbuf_max_incoming;
185
186         conn = (Connection *) slapi_ch_calloc( 1, sizeof(Connection) );
187
188         LDAP_STAILQ_INIT( &conn->c_pending_ops );
189
190         op = (Operation *) slapi_ch_calloc( 1, OPERATION_BUFFER_SIZE );
191         op->o_hdr = (Opheader *)(op + 1);
192         op->o_hdr->oh_extensions = NULL;
193         op->o_controls = (void **)(op->o_hdr + 1);
194
195         op->o_callback = (slap_callback *) slapi_ch_calloc( 1, sizeof(slap_callback) );
196         op->o_callback->sc_response = slapi_int_response;
197         op->o_callback->sc_cleanup = NULL;
198         op->o_callback->sc_private = pb;
199         op->o_callback->sc_next = NULL;
200
201         conn->c_pending_ops.stqh_first = op;
202
203         /* connection object authorization information */
204         conn->c_authtype = LDAP_AUTH_NONE;
205         BER_BVZERO( &conn->c_authmech );
206         BER_BVZERO( &conn->c_dn );
207         BER_BVZERO( &conn->c_ndn );
208
209         conn->c_listener = &slapi_listener;
210         ber_dupbv( &conn->c_peer_domain, (struct berval *)&slap_unknown_bv );
211         ber_dupbv( &conn->c_peer_name, (struct berval *)&slap_unknown_bv );
212
213         LDAP_STAILQ_INIT( &conn->c_ops );
214
215         BER_BVZERO( &conn->c_sasl_bind_mech );
216         conn->c_sasl_authctx = NULL;
217         conn->c_sasl_sockctx = NULL;
218         conn->c_sasl_extra = NULL;
219
220         conn->c_sb = ber_sockbuf_alloc();
221
222         ber_sockbuf_ctrl( conn->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
223
224         conn->c_currentber = NULL;
225
226         /* should check status of thread calls */
227         ldap_pvt_thread_mutex_init( &conn->c_mutex );
228         ldap_pvt_thread_mutex_init( &conn->c_write_mutex );
229         ldap_pvt_thread_cond_init( &conn->c_write_cv );
230
231         ldap_pvt_thread_mutex_lock( &conn->c_mutex );
232
233         conn->c_n_ops_received = 0;
234         conn->c_n_ops_executing = 0;
235         conn->c_n_ops_pending = 0;
236         conn->c_n_ops_completed = 0;
237
238         conn->c_n_get = 0;
239         conn->c_n_read = 0;
240         conn->c_n_write = 0;
241
242         conn->c_protocol = LDAP_VERSION3; 
243
244         conn->c_activitytime = conn->c_starttime = slap_get_time();
245
246         /*
247          * A real connection ID is required, because syncrepl associates
248          * pending CSNs with unique ( connection, operation ) tuples.
249          * Setting a fake connection ID will cause slap_get_commit_csn()
250          * to return a stale value.
251          */
252         connection_assign_nextid( conn );
253
254         conn->c_conn_state  = 0x01;     /* SLAP_C_ACTIVE */
255         conn->c_struct_state = 0x02;    /* SLAP_C_USED */
256
257         conn->c_ssf = conn->c_transport_ssf = 0;
258         conn->c_tls_ssf = 0;
259
260         backend_connection_init( conn );
261
262         conn->c_send_ldap_result = slap_send_ldap_result;
263         conn->c_send_search_entry = slap_send_search_entry;
264         conn->c_send_ldap_extended = slap_send_ldap_extended;
265         conn->c_send_search_reference = slap_send_search_reference;
266
267         /* operation object */
268         op->o_tag = tag;
269         op->o_protocol = LDAP_VERSION3; 
270         BER_BVZERO( &op->o_authmech );
271         op->o_time = slap_get_time();
272         op->o_do_not_cache = 1;
273         op->o_threadctx = ldap_pvt_thread_pool_context();
274         op->o_tmpmemctx = NULL;
275         op->o_tmpmfuncs = &ch_mfuncs;
276         op->o_conn = conn;
277         op->o_connid = conn->c_connid;
278         op->o_bd = frontendDB;
279
280         pb->pop = op;
281         pb->pconn = conn;
282         pb->internal_op = 1;
283
284         ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
285 }
286
287 static void
288 slapi_int_set_operation_dn( Slapi_PBlock *pb )
289 {
290         Backend                 *be;
291         Operation               *op = pb->pop;
292
293         if ( BER_BVISNULL( &op->o_ndn ) ) {
294                 /* set to root DN */
295                 be = select_backend( &op->o_req_ndn, 0, 0 );
296                 assert( be != NULL );
297                 ber_dupbv( &op->o_dn, &be->be_rootdn );
298                 ber_dupbv( &op->o_ndn, &be->be_rootndn );
299         }
300 }
301
302 void
303 slapi_int_connection_done_pb( Slapi_PBlock *pb )
304 {
305         Connection              *conn;
306         Operation               *op;
307
308         PBLOCK_ASSERT_INTOP( pb, 0 );
309
310         conn = pb->pconn;
311         op = pb->pop;
312
313         /* free allocated DNs */
314         if ( !BER_BVISNULL( &op->o_dn ) )
315                 op->o_tmpfree( op->o_dn.bv_val, op->o_tmpmemctx );
316         if ( !BER_BVISNULL( &op->o_ndn ) )
317                 op->o_tmpfree( op->o_ndn.bv_val, op->o_tmpmemctx );
318
319         if ( !BER_BVISNULL( &op->o_req_dn ) )
320                 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
321         if ( !BER_BVISNULL( &op->o_req_ndn ) )
322                 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
323
324         switch ( op->o_tag ) {
325         case LDAP_REQ_MODRDN:
326                 if ( !BER_BVISNULL( &op->orr_newrdn ))
327                         op->o_tmpfree( op->orr_newrdn.bv_val, op->o_tmpmemctx );
328                 if ( !BER_BVISNULL( &op->orr_nnewrdn ))
329                         op->o_tmpfree( op->orr_nnewrdn.bv_val, op->o_tmpmemctx );
330                 if ( op->orr_newSup != NULL ) {
331                         assert( !BER_BVISNULL( op->orr_newSup ) );
332                         op->o_tmpfree( op->orr_newSup->bv_val, op->o_tmpmemctx );
333                         op->o_tmpfree( op->orr_newSup, op->o_tmpmemctx );
334                 }
335                 if ( op->orr_nnewSup != NULL ) {
336                         assert( !BER_BVISNULL( op->orr_nnewSup ) );
337                         op->o_tmpfree( op->orr_nnewSup->bv_val, op->o_tmpmemctx );
338                         op->o_tmpfree( op->orr_nnewSup, op->o_tmpmemctx );
339                 }
340                 break;
341         case LDAP_REQ_ADD:
342                 slapi_int_mods_free( op->ora_modlist );
343                 break;
344         case LDAP_REQ_MODIFY:
345                 slapi_int_mods_free( op->orm_modlist );
346                 break;
347         case LDAP_REQ_SEARCH:
348                 if ( op->ors_attrs != NULL ) {
349                         op->o_tmpfree( op->ors_attrs, op->o_tmpmemctx );
350                         op->ors_attrs = NULL;
351                 }
352                 break;
353         default:
354                 break;
355         }
356
357         slapi_ch_free_string( &conn->c_authmech.bv_val );
358         slapi_ch_free_string( &conn->c_dn.bv_val );
359         slapi_ch_free_string( &conn->c_ndn.bv_val );
360
361         if ( conn->c_sb != NULL ) {
362                 ber_sockbuf_free( conn->c_sb );
363         }
364
365         slapi_ch_free( (void **)&pb->pop->o_callback );
366         slapi_ch_free( (void **)&pb->pop );
367         slapi_ch_free( (void **)&pb->pconn );
368 }
369
370 static int
371 slapi_int_func_internal_pb( Slapi_PBlock *pb, slap_operation_t which )
372 {
373         BI_op_bind              **func;
374         SlapReply               *rs = &pb->rs;
375         int                     rc;
376
377         PBLOCK_ASSERT_INTOP( pb, 0 );
378
379         rc = slapi_int_get_ctrls( pb );
380         if ( rc != LDAP_SUCCESS ) {
381                 rs->sr_err = rc;
382                 return rc;
383         }
384
385         func = &pb->pop->o_bd->be_bind;
386
387         rc = func[which]( pb->pop, &pb->rs );
388
389         return rc;
390 }
391
392 int
393 slapi_delete_internal_pb( Slapi_PBlock *pb )
394 {
395         if ( pb == NULL ) {
396                 return -1;
397         }
398
399         PBLOCK_ASSERT_INTOP( pb, LDAP_REQ_DELETE );
400
401         slapi_int_func_internal_pb( pb, op_delete );
402         slap_graduate_commit_csn( pb->pop );
403
404         return 0;
405 }
406
407 int
408 slapi_add_internal_pb( Slapi_PBlock *pb )
409 {
410         SlapReply               *rs;
411         Slapi_Entry             *entry_orig = NULL;
412
413         if ( pb == NULL ) {
414                 return -1;
415         }
416
417         PBLOCK_ASSERT_INTOP( pb, LDAP_REQ_ADD );
418
419         rs = &pb->rs;
420
421         entry_orig = pb->pop->ora_e;
422         pb->pop->ora_e = NULL;
423
424         if ( entry_orig != NULL ) {
425                 if ( pb->pop->ora_modlist != NULL || !BER_BVISNULL( &pb->pop->o_req_ndn )) {
426                         rs->sr_err = LDAP_PARAM_ERROR;
427                         goto cleanup;
428                 }
429
430                 assert( BER_BVISNULL( &pb->pop->o_req_dn ) ); /* shouldn't get set */
431                 ber_dupbv( &pb->pop->o_req_dn, &entry_orig->e_name );
432                 ber_dupbv( &pb->pop->o_req_ndn, &entry_orig->e_nname );
433         } else if ( pb->pop->ora_modlist == NULL || BER_BVISNULL( &pb->pop->o_req_ndn )) {
434                 rs->sr_err = LDAP_PARAM_ERROR;
435                 goto cleanup;
436         }
437
438         /*
439          * The caller can specify a new entry, or a target DN and set
440          * of modifications, but not both.
441          */
442         pb->pop->ora_e = (Entry *)slapi_ch_calloc( 1, sizeof(Entry) );
443         ber_dupbv( &pb->pop->ora_e->e_name,  &pb->pop->o_req_dn );
444         ber_dupbv( &pb->pop->ora_e->e_nname, &pb->pop->o_req_ndn );
445
446         if ( entry_orig != NULL ) {
447                 assert( pb->pop->ora_modlist == NULL );
448
449                 rs->sr_err = slap_entry2mods( entry_orig, &pb->pop->ora_modlist,
450                         &rs->sr_text, pb->textbuf, sizeof( pb->textbuf ) );
451                 if ( rs->sr_err != LDAP_SUCCESS ) {
452                         goto cleanup;
453                 }
454         } else {
455                 assert( pb->pop->ora_modlist != NULL );
456         }
457
458         rs->sr_err = slap_mods_check( pb->pop->ora_modlist, &rs->sr_text,
459                 pb->textbuf, sizeof( pb->textbuf ), NULL );
460         if ( rs->sr_err != LDAP_SUCCESS ) {
461                 goto cleanup;
462         }
463
464         if ( slapi_int_func_internal_pb( pb, op_add ) == 0 ) {
465                 if ( pb->pop->ora_e != NULL && pb->pop->o_private != NULL ) {
466                         BackendDB       *bd = pb->pop->o_bd;
467
468                         /* could we use SLAPI_BACKEND instead? */
469                         pb->pop->o_bd = (BackendDB *)pb->pop->o_private;
470                         pb->pop->o_private = NULL;
471                         be_entry_release_w( pb->pop, pb->pop->ora_e );
472                         pb->pop->ora_e = NULL;
473                         pb->pop->o_bd = bd;
474                         pb->pop->o_private = NULL;
475                 }
476         }
477
478 cleanup:
479         slap_graduate_commit_csn( pb->pop );
480
481         if ( pb->pop->ora_e != NULL ) {
482                 slapi_entry_free( pb->pop->ora_e );
483                 pb->pop->ora_e = NULL;
484         }
485         if ( entry_orig != NULL ) {
486                 pb->pop->ora_e = entry_orig;
487                 slapi_int_mods_free( pb->pop->ora_modlist );
488                 pb->pop->ora_modlist = NULL;
489         }
490
491         return 0;
492 }
493
494 int
495 slapi_modrdn_internal_pb( Slapi_PBlock *pb )
496 {
497         if ( pb == NULL ) {
498                 return -1;
499         }
500
501         PBLOCK_ASSERT_INTOP( pb, LDAP_REQ_MODRDN );
502
503         if ( BER_BVISEMPTY( &pb->pop->o_req_ndn ) ) {
504                 pb->rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
505                 goto cleanup;
506         }
507
508         slapi_int_func_internal_pb( pb, op_modrdn );
509
510 cleanup:
511         slap_graduate_commit_csn( pb->pop );
512
513         return 0;
514 }
515
516 int
517 slapi_modify_internal_pb( Slapi_PBlock *pb )
518 {
519         SlapReply               *rs;
520
521         if ( pb == NULL ) {
522                 return -1;
523         }
524
525         PBLOCK_ASSERT_INTOP( pb, LDAP_REQ_MODIFY );
526
527         rs = &pb->rs;
528
529         if ( pb->pop->orm_modlist == NULL ) {
530                 rs->sr_err = LDAP_PARAM_ERROR;
531                 goto cleanup;
532         }
533
534         if ( BER_BVISEMPTY( &pb->pop->o_req_ndn ) ) {
535                 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
536                 goto cleanup;
537         }
538
539         rs->sr_err = slap_mods_check( pb->pop->orm_modlist,
540                 &rs->sr_text, pb->textbuf, sizeof( pb->textbuf ), NULL );
541         if ( rs->sr_err != LDAP_SUCCESS ) {
542                 goto cleanup;
543         }
544
545         slapi_int_func_internal_pb( pb, op_modify );
546
547 cleanup:
548         slap_graduate_commit_csn( pb->pop );
549
550         return 0;
551 }
552
553 static int
554 slapi_int_search_entry_callback( Slapi_Entry *entry, void *callback_data )
555 {
556         int             nentries = 0, i = 0;
557         Slapi_Entry     **head = NULL, **tp;
558         Slapi_PBlock    *pb = (Slapi_PBlock *)callback_data;
559
560         PBLOCK_ASSERT_INTOP( pb, LDAP_REQ_SEARCH );
561
562         entry = slapi_entry_dup( entry );
563         if ( entry == NULL ) {
564                 return LDAP_NO_MEMORY;
565         }
566
567         slapi_pblock_get( pb, SLAPI_NENTRIES, &nentries );
568         slapi_pblock_get( pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &head );
569         
570         i = nentries + 1;
571         if ( nentries == 0 ) {
572                 tp = (Slapi_Entry **)slapi_ch_malloc( 2 * sizeof(Slapi_Entry *) );
573                 if ( tp == NULL ) {
574                         slapi_entry_free( entry );
575                         return LDAP_NO_MEMORY;
576                 }
577
578                 tp[0] = entry;
579         } else {
580                 tp = (Slapi_Entry **)slapi_ch_realloc( (char *)head,
581                                 sizeof(Slapi_Entry *) * ( i + 1 ) );
582                 if ( tp == NULL ) {
583                         slapi_entry_free( entry );
584                         return LDAP_NO_MEMORY;
585                 }
586                 tp[i - 1] = entry;
587         }
588         tp[i] = NULL;
589                   
590         slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, (void *)tp );
591         slapi_pblock_set( pb, SLAPI_NENTRIES, (void *)i );
592
593         return LDAP_SUCCESS;
594 }
595
596 int
597 slapi_search_internal_pb( Slapi_PBlock *pb )
598 {
599         return slapi_search_internal_callback_pb( pb,
600                 (void *)pb,
601                 NULL,
602                 slapi_int_search_entry_callback,
603                 NULL );
604 }
605
606 int
607 slapi_search_internal_callback_pb( Slapi_PBlock *pb,
608         void *callback_data,
609         plugin_result_callback prc,
610         plugin_search_entry_callback psec,
611         plugin_referral_entry_callback prec )
612 {
613         int                     free_filter = 0;
614         SlapReply               *rs;
615
616         if ( pb == NULL ) {
617                 return -1;
618         }
619
620         PBLOCK_ASSERT_INTOP( pb, LDAP_REQ_SEARCH );
621
622         rs = &pb->rs;
623
624         /* search callback and arguments */
625         slapi_pblock_set( pb, SLAPI_X_INTOP_RESULT_CALLBACK,         (void *)prc );
626         slapi_pblock_set( pb, SLAPI_X_INTOP_SEARCH_ENTRY_CALLBACK,   (void *)psec );
627         slapi_pblock_set( pb, SLAPI_X_INTOP_REFERRAL_ENTRY_CALLBACK, (void *)prec );
628         slapi_pblock_set( pb, SLAPI_X_INTOP_CALLBACK_DATA,           (void *)callback_data );
629
630         if ( BER_BVISEMPTY( &pb->pop->ors_filterstr )) {
631                 rs->sr_err = LDAP_PARAM_ERROR;
632                 goto cleanup;
633         }
634
635         if ( pb->pop->ors_filter == NULL ) {
636                 pb->pop->ors_filter = slapi_str2filter( pb->pop->ors_filterstr.bv_val );
637                 if ( pb->pop->ors_filter == NULL ) {
638                         rs->sr_err = LDAP_PROTOCOL_ERROR;
639                         goto cleanup;
640                 }
641
642                 free_filter = 1;
643         }
644
645         slapi_int_func_internal_pb( pb, op_search );
646
647 cleanup:
648         if ( free_filter ) {
649                 slapi_filter_free( pb->pop->ors_filter, 1 );
650                 pb->pop->ors_filter = NULL;
651         }
652
653         slapi_pblock_delete_param( pb, SLAPI_X_INTOP_RESULT_CALLBACK );
654         slapi_pblock_delete_param( pb, SLAPI_X_INTOP_SEARCH_ENTRY_CALLBACK );
655         slapi_pblock_delete_param( pb, SLAPI_X_INTOP_REFERRAL_ENTRY_CALLBACK );
656         slapi_pblock_delete_param( pb, SLAPI_X_INTOP_CALLBACK_DATA );
657
658         return 0;
659 }
660
661 /* Wrappers for old API */
662
663 void
664 slapi_search_internal_set_pb( Slapi_PBlock *pb,
665         const char *base,
666         int scope,
667         const char *filter,
668         char **attrs,
669         int attrsonly,
670         LDAPControl **controls,
671         const char *uniqueid,
672         Slapi_ComponentId *plugin_identity,
673         int operation_flags )
674 {
675         slapi_int_connection_init_pb( pb, LDAP_REQ_SEARCH );
676         slapi_pblock_set( pb, SLAPI_SEARCH_TARGET,    (void *)base );
677         slapi_pblock_set( pb, SLAPI_SEARCH_SCOPE,     (void *)scope );
678         slapi_pblock_set( pb, SLAPI_SEARCH_FILTER,    NULL );
679         slapi_pblock_set( pb, SLAPI_SEARCH_STRFILTER, (void *)filter );
680         slapi_pblock_set( pb, SLAPI_SEARCH_ATTRS,     (void *)attrs );
681         slapi_pblock_set( pb, SLAPI_SEARCH_ATTRSONLY, (void *)attrsonly );
682         slapi_pblock_set( pb, SLAPI_REQCONTROLS,      (void *)controls );
683         slapi_pblock_set( pb, SLAPI_TARGET_UNIQUEID,  (void *)uniqueid );
684         slapi_pblock_set( pb, SLAPI_PLUGIN_IDENTITY,  (void *)plugin_identity );
685         slapi_pblock_set( pb, SLAPI_X_INTOP_FLAGS,    (void *)operation_flags );
686         slapi_pblock_set( pb, SLAPI_SEARCH_DEREF,     (void *)0 );
687         slapi_pblock_set( pb, SLAPI_SEARCH_SIZELIMIT, (void *)SLAP_NO_LIMIT );
688         slapi_pblock_set( pb, SLAPI_SEARCH_TIMELIMIT, (void *)SLAP_NO_LIMIT );
689
690         slapi_int_set_operation_dn( pb );
691 }
692
693 Slapi_PBlock *
694 slapi_search_internal(
695         char *ldn, 
696         int scope, 
697         char *filStr, 
698         LDAPControl **controls, 
699         char **attrs, 
700         int attrsonly ) 
701 {
702         Slapi_PBlock *pb;
703
704         pb = slapi_pblock_new();
705
706         slapi_search_internal_set_pb( pb, ldn, scope, filStr,
707                 attrs, attrsonly,
708                 controls, NULL, NULL, 0 );
709
710         slapi_search_internal_pb( pb );
711
712         return pb;
713 }
714
715 void
716 slapi_modify_internal_set_pb( Slapi_PBlock *pb,
717         const char *dn,
718         LDAPMod **mods,
719         LDAPControl **controls,
720         const char *uniqueid,
721         Slapi_ComponentId *plugin_identity,
722         int operation_flags )
723 {
724         slapi_int_connection_init_pb( pb, LDAP_REQ_MODIFY );
725         slapi_pblock_set( pb, SLAPI_MODIFY_TARGET,   (void *)dn );
726         slapi_pblock_set( pb, SLAPI_MODIFY_MODS,     (void *)mods );
727         slapi_pblock_set( pb, SLAPI_REQCONTROLS,     (void *)controls );
728         slapi_pblock_set( pb, SLAPI_TARGET_UNIQUEID, (void *)uniqueid );
729         slapi_pblock_set( pb, SLAPI_PLUGIN_IDENTITY, (void *)plugin_identity );
730         slapi_pblock_set( pb, SLAPI_X_INTOP_FLAGS,   (void *)operation_flags );
731         slapi_int_set_operation_dn( pb );
732 }
733
734 /* Function : slapi_modify_internal
735  *
736  * Description: Plugin functions call this routine to modify an entry 
737  *                              in the backend directly
738  * Return values : LDAP_SUCCESS
739  *                 LDAP_PARAM_ERROR
740  *                 LDAP_NO_MEMORY
741  *                 LDAP_OTHER
742  *                 LDAP_UNWILLING_TO_PERFORM
743 */
744 Slapi_PBlock *
745 slapi_modify_internal(
746         char *ldn,      
747         LDAPMod **mods, 
748         LDAPControl **controls, 
749         int log_change )
750 {
751         Slapi_PBlock *pb;
752
753         pb = slapi_pblock_new();
754
755         slapi_modify_internal_set_pb( pb, ldn, mods, controls, NULL, NULL,
756                 log_change ? SLAPI_OP_FLAG_LOG_CHANGE : 0 );
757
758         slapi_modify_internal_pb( pb );
759
760         return pb;
761 }
762
763 int
764 slapi_add_internal_set_pb( Slapi_PBlock *pb,
765         const char *dn,
766         LDAPMod **attrs,
767         LDAPControl **controls,
768         Slapi_ComponentId *plugin_identity,
769         int operation_flags )
770 {
771         slapi_int_connection_init_pb( pb, LDAP_REQ_ADD );
772         slapi_pblock_set( pb, SLAPI_ADD_TARGET,      (void *)dn );
773         slapi_pblock_set( pb, SLAPI_MODIFY_MODS,     (void *)attrs );
774         slapi_pblock_set( pb, SLAPI_REQCONTROLS,     (void *)controls );
775         slapi_pblock_set( pb, SLAPI_PLUGIN_IDENTITY, (void *)plugin_identity );
776         slapi_pblock_set( pb, SLAPI_X_INTOP_FLAGS,   (void *)operation_flags );
777         slapi_int_set_operation_dn( pb );
778
779         return 0;
780 }
781
782 Slapi_PBlock *
783 slapi_add_internal(
784         char * dn,
785         LDAPMod **attrs,
786         LDAPControl **controls,
787         int log_changes )
788 {
789         Slapi_PBlock *pb;
790
791         pb = slapi_pblock_new();
792
793         slapi_add_internal_set_pb( pb, dn, attrs, controls, NULL,
794                 log_changes ? SLAPI_OP_FLAG_LOG_CHANGE : 0 );
795         
796         slapi_add_internal_pb( pb );
797
798         return pb;
799 }
800
801 void
802 slapi_add_entry_internal_set_pb( Slapi_PBlock *pb,
803         Slapi_Entry *e,
804         LDAPControl **controls,
805         Slapi_ComponentId *plugin_identity,
806         int operation_flags )
807 {
808         slapi_int_connection_init_pb( pb, LDAP_REQ_ADD );
809         slapi_pblock_set( pb, SLAPI_ADD_ENTRY,       (void *)e );
810         slapi_pblock_set( pb, SLAPI_REQCONTROLS,     (void *)controls );
811         slapi_pblock_set( pb, SLAPI_PLUGIN_IDENTITY, (void *)plugin_identity );
812         slapi_pblock_set( pb, SLAPI_X_INTOP_FLAGS,   (void *)operation_flags );
813         slapi_int_set_operation_dn( pb );
814 }
815
816 Slapi_PBlock * 
817 slapi_add_entry_internal(
818         Slapi_Entry *e, 
819         LDAPControl **controls, 
820         int log_changes )
821 {
822         Slapi_PBlock *pb;
823
824         pb = slapi_pblock_new();
825
826         slapi_add_entry_internal_set_pb( pb, e, controls, NULL,
827                 log_changes ? SLAPI_OP_FLAG_LOG_CHANGE : 0 );
828         
829         slapi_add_internal_pb( pb );
830
831         return pb;
832 }
833
834 void
835 slapi_rename_internal_set_pb( Slapi_PBlock *pb,
836         const char *olddn,
837         const char *newrdn,
838         const char *newsuperior,
839         int deloldrdn,
840         LDAPControl **controls,
841         const char *uniqueid,
842         Slapi_ComponentId *plugin_identity,
843         int operation_flags )
844 {
845         slapi_int_connection_init_pb( pb, LDAP_REQ_MODRDN );
846         slapi_pblock_set( pb, SLAPI_MODRDN_TARGET,      (void *)olddn );
847         slapi_pblock_set( pb, SLAPI_MODRDN_NEWRDN,      (void *)newrdn );
848         slapi_pblock_set( pb, SLAPI_MODRDN_NEWSUPERIOR, (void *)newsuperior );
849         slapi_pblock_set( pb, SLAPI_MODRDN_DELOLDRDN,   (void *)deloldrdn );
850         slapi_pblock_set( pb, SLAPI_REQCONTROLS,        (void *)controls );
851         slapi_pblock_set( pb, SLAPI_TARGET_UNIQUEID,    (void *)uniqueid );
852         slapi_pblock_set( pb, SLAPI_PLUGIN_IDENTITY,    (void *)plugin_identity );
853         slapi_pblock_set( pb, SLAPI_X_INTOP_FLAGS,      (void *)operation_flags );
854         slapi_int_set_operation_dn( pb );
855 }
856
857 /* Function : slapi_modrdn_internal
858  *
859  * Description : Plugin functions call this routine to modify the rdn 
860  *                               of an entry in the backend directly
861  * Return values : LDAP_SUCCESS
862  *                 LDAP_PARAM_ERROR
863  *                 LDAP_NO_MEMORY
864  *                 LDAP_OTHER
865  *                 LDAP_UNWILLING_TO_PERFORM
866  *
867  * NOTE: This function does not support the "newSuperior" option from LDAP V3.
868  */
869 Slapi_PBlock *
870 slapi_modrdn_internal(
871         char *olddn, 
872         char *lnewrdn, 
873         int deloldrdn, 
874         LDAPControl **controls, 
875         int log_change )
876 {
877         Slapi_PBlock *pb;
878
879         pb = slapi_pblock_new ();
880
881         slapi_rename_internal_set_pb( pb, olddn, lnewrdn, NULL,
882                 deloldrdn, controls, NULL, NULL,
883                 log_change ? SLAPI_OP_FLAG_LOG_CHANGE : 0 );
884
885         slapi_modrdn_internal_pb( pb );
886
887         return pb;
888 }
889
890 void
891 slapi_delete_internal_set_pb( Slapi_PBlock *pb,
892         const char *dn,
893         LDAPControl **controls,
894         const char *uniqueid,
895         Slapi_ComponentId *plugin_identity,
896         int operation_flags )
897 {
898         slapi_int_connection_init_pb( pb, LDAP_REQ_DELETE );
899         slapi_pblock_set( pb, SLAPI_TARGET_DN,       (void *)dn );
900         slapi_pblock_set( pb, SLAPI_REQCONTROLS,     (void *)controls );
901         slapi_pblock_set( pb, SLAPI_TARGET_UNIQUEID, (void *)uniqueid );
902         slapi_pblock_set( pb, SLAPI_PLUGIN_IDENTITY, (void *)plugin_identity );
903         slapi_pblock_set( pb, SLAPI_X_INTOP_FLAGS,   (void *)operation_flags );
904         slapi_int_set_operation_dn( pb );
905 }
906
907 /* Function : slapi_delete_internal
908  *
909  * Description : Plugin functions call this routine to delete an entry 
910  *               in the backend directly
911  * Return values : LDAP_SUCCESS
912  *                 LDAP_PARAM_ERROR
913  *                 LDAP_NO_MEMORY
914  *                 LDAP_OTHER
915  *                 LDAP_UNWILLING_TO_PERFORM
916 */
917 Slapi_PBlock *
918 slapi_delete_internal(
919         char *ldn, 
920         LDAPControl **controls, 
921         int log_change )
922 {
923         Slapi_PBlock *pb;
924
925         pb = slapi_pblock_new();
926
927         slapi_delete_internal_set_pb( pb, ldn, controls, NULL, NULL,
928                 log_change ? SLAPI_OP_FLAG_LOG_CHANGE : 0 );
929
930         slapi_delete_internal_pb( pb );
931
932         return pb;
933 }
934
935 #endif /* LDAP_SLAPI */
936