]> git.sur5r.net Git - openldap/blob - servers/slapd/slapi/slapi_ops.c
Make slapi_pblock directly overlaid on operation/connection/slapreply
[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 OpType )
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 = OpType;
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         if ( conn->c_sb != NULL ) {
358                 ber_sockbuf_free( conn->c_sb );
359         }
360
361         slapi_ch_free( (void **)&pb->pop->o_callback );
362         slapi_ch_free( (void **)&pb->pop );
363         slapi_ch_free( (void **)&pb->pconn );
364 }
365
366 static int
367 slapi_int_func_internal_pb( Slapi_PBlock *pb, slap_operation_t which )
368 {
369         BI_op_bind              **func;
370         SlapReply               *rs = &pb->rs;
371
372         PBLOCK_ASSERT_INTOP( pb, 0 );
373
374         rs->sr_err = slapi_int_get_ctrls( pb );
375         if ( rs->sr_err != LDAP_SUCCESS ) {
376                 return rs->sr_err;
377         }
378
379         func = &pb->pop->o_bd->be_bind;
380
381         rs->sr_err = func[which]( pb->pop, &pb->rs );
382
383         return rs->sr_err;
384 }
385
386 int
387 slapi_delete_internal_pb( Slapi_PBlock *pb )
388 {
389         if ( pb == NULL ) {
390                 return -1;
391         }
392
393         PBLOCK_ASSERT_INTOP( pb, LDAP_REQ_DELETE );
394
395         slapi_int_func_internal_pb( pb, op_delete );
396         slap_graduate_commit_csn( pb->pop );
397
398         return 0;
399 }
400
401 int
402 slapi_add_internal_pb( Slapi_PBlock *pb )
403 {
404         SlapReply               *rs;
405         Slapi_Entry             *entry_orig = NULL;
406
407         if ( pb == NULL ) {
408                 return -1;
409         }
410
411         PBLOCK_ASSERT_INTOP( pb, LDAP_REQ_ADD );
412
413         rs = &pb->rs;
414
415         entry_orig = pb->pop->ora_e;
416         pb->pop->ora_e = NULL;
417
418         if ( entry_orig != NULL ) {
419                 if ( pb->pop->ora_modlist != NULL || !BER_BVISNULL( &pb->pop->o_req_ndn )) {
420                         rs->sr_err = LDAP_PARAM_ERROR;
421                         goto cleanup;
422                 }
423
424                 assert( BER_BVISNULL( &pb->pop->o_req_dn ) ); /* shouldn't get set */
425                 ber_dupbv( &pb->pop->o_req_dn, &entry_orig->e_name );
426                 ber_dupbv( &pb->pop->o_req_ndn, &entry_orig->e_nname );
427         } else if ( pb->pop->ora_modlist == NULL || BER_BVISNULL( &pb->pop->o_req_ndn )) {
428                 rs->sr_err = LDAP_PARAM_ERROR;
429                 goto cleanup;
430         }
431
432         /*
433          * The caller can specify a new entry, or a target DN and set
434          * of modifications, but not both.
435          */
436         pb->pop->ora_e = (Entry *)slapi_ch_calloc( 1, sizeof(Entry) );
437         ber_dupbv( &pb->pop->ora_e->e_name,  &pb->pop->o_req_dn );
438         ber_dupbv( &pb->pop->ora_e->e_nname, &pb->pop->o_req_ndn );
439
440         if ( entry_orig != NULL ) {
441                 assert( pb->pop->ora_modlist == NULL );
442
443                 rs->sr_err = slap_entry2mods( entry_orig, &pb->pop->ora_modlist,
444                         &rs->sr_text, pb->textbuf, sizeof( pb->textbuf ) );
445                 if ( rs->sr_err != LDAP_SUCCESS ) {
446                         goto cleanup;
447                 }
448         } else {
449                 assert( pb->pop->ora_modlist != NULL );
450         }
451
452         rs->sr_err = slap_mods_check( pb->pop->ora_modlist, &rs->sr_text,
453                 pb->textbuf, sizeof( pb->textbuf ), NULL );
454         if ( rs->sr_err != LDAP_SUCCESS ) {
455                 goto cleanup;
456         }
457
458         if ( slapi_int_func_internal_pb( pb, op_add ) == 0 ) {
459                 if ( pb->pop->ora_e != NULL && pb->pop->o_private != NULL ) {
460                         BackendDB       *bd = pb->pop->o_bd;
461
462                         /* could we use SLAPI_BACKEND instead? */
463                         pb->pop->o_bd = (BackendDB *)pb->pop->o_private;
464                         pb->pop->o_private = NULL;
465                         be_entry_release_w( pb->pop, pb->pop->ora_e );
466                         pb->pop->ora_e = NULL;
467                         pb->pop->o_bd = bd;
468                         pb->pop->o_private = NULL;
469                 }
470         }
471
472 cleanup:
473         slap_graduate_commit_csn( pb->pop );
474
475         if ( pb->pop->ora_e != NULL ) {
476                 slapi_entry_free( pb->pop->ora_e );
477                 pb->pop->ora_e = NULL;
478         }
479         if ( entry_orig != NULL ) {
480                 pb->pop->ora_e = entry_orig;
481                 slapi_int_mods_free( pb->pop->ora_modlist );
482                 pb->pop->ora_modlist = NULL;
483         }
484
485         return 0;
486 }
487
488 int
489 slapi_modrdn_internal_pb( Slapi_PBlock *pb )
490 {
491         if ( pb == NULL ) {
492                 return -1;
493         }
494
495         PBLOCK_ASSERT_INTOP( pb, LDAP_REQ_MODRDN );
496
497         if ( BER_BVISEMPTY( &pb->pop->o_req_ndn ) ) {
498                 pb->rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
499                 goto cleanup;
500         }
501
502         slapi_int_func_internal_pb( pb, op_modrdn );
503
504 cleanup:
505         slap_graduate_commit_csn( pb->pop );
506
507         return 0;
508 }
509
510 int
511 slapi_modify_internal_pb( Slapi_PBlock *pb )
512 {
513         SlapReply               *rs;
514
515         if ( pb == NULL ) {
516                 return -1;
517         }
518
519         PBLOCK_ASSERT_INTOP( pb, LDAP_REQ_MODIFY );
520
521         rs = &pb->rs;
522
523         if ( pb->pop->orm_modlist == NULL ) {
524                 rs->sr_err = LDAP_PARAM_ERROR;
525                 goto cleanup;
526         }
527
528         if ( BER_BVISEMPTY( &pb->pop->o_req_ndn ) ) {
529                 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
530                 goto cleanup;
531         }
532
533         rs->sr_err = slap_mods_check( pb->pop->orm_modlist,
534                 &rs->sr_text, pb->textbuf, sizeof( pb->textbuf ), NULL );
535         if ( rs->sr_err != LDAP_SUCCESS ) {
536                 goto cleanup;
537         }
538
539         slapi_int_func_internal_pb( pb, op_modify );
540
541 cleanup:
542         slap_graduate_commit_csn( pb->pop );
543
544         return 0;
545 }
546
547 static int
548 slapi_int_search_entry_callback( Slapi_Entry *entry, void *callback_data )
549 {
550         int             nentries = 0, i = 0;
551         Slapi_Entry     **head = NULL, **tp;
552         Slapi_PBlock    *pb = (Slapi_PBlock *)callback_data;
553
554         PBLOCK_ASSERT_INTOP( pb, LDAP_REQ_SEARCH );
555
556         entry = slapi_entry_dup( entry );
557         if ( entry == NULL ) {
558                 return LDAP_NO_MEMORY;
559         }
560
561         slapi_pblock_get( pb, SLAPI_NENTRIES, &nentries );
562         slapi_pblock_get( pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &head );
563         
564         i = nentries + 1;
565         if ( nentries == 0 ) {
566                 tp = (Slapi_Entry **)slapi_ch_malloc( 2 * sizeof(Slapi_Entry *) );
567                 if ( tp == NULL ) {
568                         slapi_entry_free( entry );
569                         return LDAP_NO_MEMORY;
570                 }
571
572                 tp[0] = entry;
573         } else {
574                 tp = (Slapi_Entry **)slapi_ch_realloc( (char *)head,
575                                 sizeof(Slapi_Entry *) * ( i + 1 ) );
576                 if ( tp == NULL ) {
577                         slapi_entry_free( entry );
578                         return LDAP_NO_MEMORY;
579                 }
580                 tp[i - 1] = entry;
581         }
582         tp[i] = NULL;
583                   
584         slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, (void *)tp );
585         slapi_pblock_set( pb, SLAPI_NENTRIES, (void *)i );
586
587         return LDAP_SUCCESS;
588 }
589
590 int
591 slapi_search_internal_pb( Slapi_PBlock *pb )
592 {
593         return slapi_search_internal_callback_pb( pb,
594                 (void *)pb,
595                 NULL,
596                 slapi_int_search_entry_callback,
597                 NULL );
598 }
599
600 int
601 slapi_search_internal_callback_pb( Slapi_PBlock *pb,
602         void *callback_data,
603         plugin_result_callback prc,
604         plugin_search_entry_callback psec,
605         plugin_referral_entry_callback prec )
606 {
607         int                     free_filter = 0;
608         SlapReply               *rs;
609
610         if ( pb == NULL ) {
611                 return -1;
612         }
613
614         PBLOCK_ASSERT_INTOP( pb, LDAP_REQ_SEARCH );
615
616         rs = &pb->rs;
617
618         /* search callback and arguments */
619         slapi_pblock_set( pb, SLAPI_X_INTOP_RESULT_CALLBACK,         (void *)prc );
620         slapi_pblock_set( pb, SLAPI_X_INTOP_SEARCH_ENTRY_CALLBACK,   (void *)psec );
621         slapi_pblock_set( pb, SLAPI_X_INTOP_REFERRAL_ENTRY_CALLBACK, (void *)prec );
622         slapi_pblock_set( pb, SLAPI_X_INTOP_CALLBACK_DATA,           (void *)callback_data );
623
624         if ( BER_BVISEMPTY( &pb->pop->ors_filterstr )) {
625                 rs->sr_err = LDAP_PARAM_ERROR;
626                 goto cleanup;
627         }
628
629         if ( pb->pop->ors_filter == NULL ) {
630                 pb->pop->ors_filter = slapi_str2filter( pb->pop->ors_filterstr.bv_val );
631                 if ( pb->pop->ors_filter == NULL ) {
632                         rs->sr_err = LDAP_PROTOCOL_ERROR;
633                         goto cleanup;
634                 }
635
636                 free_filter = 1;
637         }
638
639         slapi_int_func_internal_pb( pb, op_search );
640
641 cleanup:
642         if ( free_filter ) {
643                 slapi_filter_free( pb->pop->ors_filter, 1 );
644                 pb->pop->ors_filter = NULL;
645         }
646
647         slapi_pblock_set( pb, SLAPI_X_INTOP_RESULT_CALLBACK,         NULL );
648         slapi_pblock_set( pb, SLAPI_X_INTOP_SEARCH_ENTRY_CALLBACK,   NULL );
649         slapi_pblock_set( pb, SLAPI_X_INTOP_REFERRAL_ENTRY_CALLBACK, NULL );
650         slapi_pblock_set( pb, SLAPI_X_INTOP_CALLBACK_DATA,           NULL );
651
652         return 0;
653 }
654
655 /* Wrappers for old API */
656
657 void
658 slapi_search_internal_set_pb( Slapi_PBlock *pb,
659         const char *base,
660         int scope,
661         const char *filter,
662         char **attrs,
663         int attrsonly,
664         LDAPControl **controls,
665         const char *uniqueid,
666         Slapi_ComponentId *plugin_identity,
667         int operation_flags )
668 {
669         slapi_int_connection_init_pb( pb, LDAP_REQ_SEARCH );
670         slapi_pblock_set( pb, SLAPI_SEARCH_TARGET,    (void *)base );
671         slapi_pblock_set( pb, SLAPI_SEARCH_SCOPE,     (void *)scope );
672         slapi_pblock_set( pb, SLAPI_SEARCH_FILTER,    NULL );
673         slapi_pblock_set( pb, SLAPI_SEARCH_STRFILTER, (void *)filter );
674         slapi_pblock_set( pb, SLAPI_SEARCH_ATTRS,     (void *)attrs );
675         slapi_pblock_set( pb, SLAPI_SEARCH_ATTRSONLY, (void *)attrsonly );
676         slapi_pblock_set( pb, SLAPI_REQCONTROLS,      (void *)controls );
677         slapi_pblock_set( pb, SLAPI_TARGET_UNIQUEID,  (void *)uniqueid );
678         slapi_pblock_set( pb, SLAPI_PLUGIN_IDENTITY,  (void *)plugin_identity );
679         slapi_pblock_set( pb, SLAPI_X_INTOP_FLAGS,    (void *)operation_flags );
680         slapi_pblock_set( pb, SLAPI_SEARCH_DEREF,     (void *)0 );
681         slapi_pblock_set( pb, SLAPI_SEARCH_SIZELIMIT, (void *)SLAP_NO_LIMIT );
682         slapi_pblock_set( pb, SLAPI_SEARCH_TIMELIMIT, (void *)SLAP_NO_LIMIT );
683
684         slapi_int_set_operation_dn( pb );
685 }
686
687 Slapi_PBlock *
688 slapi_search_internal(
689         char *ldn, 
690         int scope, 
691         char *filStr, 
692         LDAPControl **controls, 
693         char **attrs, 
694         int attrsonly ) 
695 {
696         Slapi_PBlock *pb;
697
698         pb = slapi_pblock_new();
699
700         slapi_search_internal_set_pb( pb, ldn, scope, filStr,
701                 attrs, attrsonly,
702                 controls, NULL, NULL, 0 );
703
704         slapi_search_internal_pb( pb );
705
706         return pb;
707 }
708
709 void
710 slapi_modify_internal_set_pb( Slapi_PBlock *pb,
711         const char *dn,
712         LDAPMod **mods,
713         LDAPControl **controls,
714         const char *uniqueid,
715         Slapi_ComponentId *plugin_identity,
716         int operation_flags )
717 {
718         slapi_int_connection_init_pb( pb, LDAP_REQ_MODIFY );
719         slapi_pblock_set( pb, SLAPI_MODIFY_TARGET,   (void *)dn );
720         slapi_pblock_set( pb, SLAPI_MODIFY_MODS,     (void *)mods );
721         slapi_pblock_set( pb, SLAPI_REQCONTROLS,     (void *)controls );
722         slapi_pblock_set( pb, SLAPI_TARGET_UNIQUEID, (void *)uniqueid );
723         slapi_pblock_set( pb, SLAPI_PLUGIN_IDENTITY, (void *)plugin_identity );
724         slapi_pblock_set( pb, SLAPI_X_INTOP_FLAGS,   (void *)operation_flags );
725         slapi_int_set_operation_dn( pb );
726 }
727
728 /* Function : slapi_modify_internal
729  *
730  * Description: Plugin functions call this routine to modify an entry 
731  *                              in the backend directly
732  * Return values : LDAP_SUCCESS
733  *                 LDAP_PARAM_ERROR
734  *                 LDAP_NO_MEMORY
735  *                 LDAP_OTHER
736  *                 LDAP_UNWILLING_TO_PERFORM
737 */
738 Slapi_PBlock *
739 slapi_modify_internal(
740         char *ldn,      
741         LDAPMod **mods, 
742         LDAPControl **controls, 
743         int log_change )
744 {
745         Slapi_PBlock *pb;
746
747         pb = slapi_pblock_new();
748
749         slapi_modify_internal_set_pb( pb, ldn, mods, controls, NULL, NULL,
750                 log_change ? SLAPI_OP_FLAG_LOG_CHANGE : 0 );
751
752         slapi_modify_internal_pb( pb );
753
754         return pb;
755 }
756
757 int
758 slapi_add_internal_set_pb( Slapi_PBlock *pb,
759         const char *dn,
760         LDAPMod **attrs,
761         LDAPControl **controls,
762         Slapi_ComponentId *plugin_identity,
763         int operation_flags )
764 {
765         slapi_int_connection_init_pb( pb, LDAP_REQ_ADD );
766         slapi_pblock_set( pb, SLAPI_ADD_TARGET,      (void *)dn );
767         slapi_pblock_set( pb, SLAPI_MODIFY_MODS,     (void *)attrs );
768         slapi_pblock_set( pb, SLAPI_REQCONTROLS,     (void *)controls );
769         slapi_pblock_set( pb, SLAPI_PLUGIN_IDENTITY, (void *)plugin_identity );
770         slapi_pblock_set( pb, SLAPI_X_INTOP_FLAGS,   (void *)operation_flags );
771         slapi_int_set_operation_dn( pb );
772
773         return 0;
774 }
775
776 Slapi_PBlock *
777 slapi_add_internal(
778         char * dn,
779         LDAPMod **attrs,
780         LDAPControl **controls,
781         int log_changes )
782 {
783         Slapi_PBlock *pb;
784
785         pb = slapi_pblock_new();
786
787         slapi_add_internal_set_pb( pb, dn, attrs, controls, NULL,
788                 log_changes ? SLAPI_OP_FLAG_LOG_CHANGE : 0 );
789         
790         slapi_add_internal_pb( pb );
791
792         return pb;
793 }
794
795 void
796 slapi_add_entry_internal_set_pb( Slapi_PBlock *pb,
797         Slapi_Entry *e,
798         LDAPControl **controls,
799         Slapi_ComponentId *plugin_identity,
800         int operation_flags )
801 {
802         slapi_int_connection_init_pb( pb, LDAP_REQ_ADD );
803         slapi_pblock_set( pb, SLAPI_ADD_ENTRY,       (void *)e );
804         slapi_pblock_set( pb, SLAPI_REQCONTROLS,     (void *)controls );
805         slapi_pblock_set( pb, SLAPI_PLUGIN_IDENTITY, (void *)plugin_identity );
806         slapi_pblock_set( pb, SLAPI_X_INTOP_FLAGS,   (void *)operation_flags );
807         slapi_int_set_operation_dn( pb );
808 }
809
810 Slapi_PBlock * 
811 slapi_add_entry_internal(
812         Slapi_Entry *e, 
813         LDAPControl **controls, 
814         int log_changes )
815 {
816         Slapi_PBlock *pb;
817
818         pb = slapi_pblock_new();
819
820         slapi_add_entry_internal_set_pb( pb, e, controls, NULL,
821                 log_changes ? SLAPI_OP_FLAG_LOG_CHANGE : 0 );
822         
823         slapi_add_internal_pb( pb );
824
825         return pb;
826 }
827
828 void
829 slapi_rename_internal_set_pb( Slapi_PBlock *pb,
830         const char *olddn,
831         const char *newrdn,
832         const char *newsuperior,
833         int deloldrdn,
834         LDAPControl **controls,
835         const char *uniqueid,
836         Slapi_ComponentId *plugin_identity,
837         int operation_flags )
838 {
839         slapi_int_connection_init_pb( pb, LDAP_REQ_MODRDN );
840         slapi_pblock_set( pb, SLAPI_MODRDN_TARGET,      (void *)olddn );
841         slapi_pblock_set( pb, SLAPI_MODRDN_NEWRDN,      (void *)newrdn );
842         slapi_pblock_set( pb, SLAPI_MODRDN_NEWSUPERIOR, (void *)newsuperior );
843         slapi_pblock_set( pb, SLAPI_MODRDN_DELOLDRDN,   (void *)deloldrdn );
844         slapi_pblock_set( pb, SLAPI_REQCONTROLS,        (void *)controls );
845         slapi_pblock_set( pb, SLAPI_TARGET_UNIQUEID,    (void *)uniqueid );
846         slapi_pblock_set( pb, SLAPI_PLUGIN_IDENTITY,    (void *)plugin_identity );
847         slapi_pblock_set( pb, SLAPI_X_INTOP_FLAGS,      (void *)operation_flags );
848         slapi_int_set_operation_dn( pb );
849 }
850
851 /* Function : slapi_modrdn_internal
852  *
853  * Description : Plugin functions call this routine to modify the rdn 
854  *                               of an entry in the backend directly
855  * Return values : LDAP_SUCCESS
856  *                 LDAP_PARAM_ERROR
857  *                 LDAP_NO_MEMORY
858  *                 LDAP_OTHER
859  *                 LDAP_UNWILLING_TO_PERFORM
860  *
861  * NOTE: This function does not support the "newSuperior" option from LDAP V3.
862  */
863 Slapi_PBlock *
864 slapi_modrdn_internal(
865         char *olddn, 
866         char *lnewrdn, 
867         int deloldrdn, 
868         LDAPControl **controls, 
869         int log_change )
870 {
871         Slapi_PBlock *pb;
872
873         pb = slapi_pblock_new ();
874
875         slapi_rename_internal_set_pb( pb, olddn, lnewrdn, NULL,
876                 deloldrdn, controls, NULL, NULL,
877                 log_change ? SLAPI_OP_FLAG_LOG_CHANGE : 0 );
878
879         slapi_modrdn_internal_pb( pb );
880
881         return pb;
882 }
883
884 void
885 slapi_delete_internal_set_pb( Slapi_PBlock *pb,
886         const char *dn,
887         LDAPControl **controls,
888         const char *uniqueid,
889         Slapi_ComponentId *plugin_identity,
890         int operation_flags )
891 {
892         slapi_int_connection_init_pb( pb, LDAP_REQ_DELETE );
893         slapi_pblock_set( pb, SLAPI_TARGET_DN,       (void *)dn );
894         slapi_pblock_set( pb, SLAPI_REQCONTROLS,     (void *)controls );
895         slapi_pblock_set( pb, SLAPI_TARGET_UNIQUEID, (void *)uniqueid );
896         slapi_pblock_set( pb, SLAPI_PLUGIN_IDENTITY, (void *)plugin_identity );
897         slapi_pblock_set( pb, SLAPI_X_INTOP_FLAGS,   (void *)operation_flags );
898         slapi_int_set_operation_dn( pb );
899 }
900
901 /* Function : slapi_delete_internal
902  *
903  * Description : Plugin functions call this routine to delete an entry 
904  *               in the backend directly
905  * Return values : LDAP_SUCCESS
906  *                 LDAP_PARAM_ERROR
907  *                 LDAP_NO_MEMORY
908  *                 LDAP_OTHER
909  *                 LDAP_UNWILLING_TO_PERFORM
910 */
911 Slapi_PBlock *
912 slapi_delete_internal(
913         char *ldn, 
914         LDAPControl **controls, 
915         int log_change )
916 {
917         Slapi_PBlock *pb;
918
919         pb = slapi_pblock_new();
920
921         slapi_delete_internal_set_pb( pb, ldn, controls, NULL, NULL,
922                 log_change ? SLAPI_OP_FLAG_LOG_CHANGE : 0 );
923
924         slapi_delete_internal_pb( pb );
925
926         return pb;
927 }
928
929 #endif /* LDAP_SLAPI */
930