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