]> git.sur5r.net Git - openldap/blob - servers/slapd/add.c
306b65ee695a474cc69467ede685f0d45eb9f431
[openldap] / servers / slapd / add.c
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1998-2004 The OpenLDAP Foundation.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted only as authorized by the OpenLDAP
9  * Public License.
10  *
11  * A copy of this license is available in the file LICENSE in the
12  * top-level directory of the distribution or, alternatively, at
13  * <http://www.OpenLDAP.org/license.html>.
14  */
15 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
16  * All rights reserved.
17  *
18  * Redistribution and use in source and binary forms are permitted
19  * provided that this notice is preserved and that due credit is given
20  * to the University of Michigan at Ann Arbor. The name of the University
21  * may not be used to endorse or promote products derived from this
22  * software without specific prior written permission. This software
23  * is provided ``as is'' without express or implied warranty.
24  */
25
26 #include "portable.h"
27
28 #include <stdio.h>
29 #include <ac/string.h>
30 #include <ac/time.h>
31 #include <ac/socket.h>
32
33 #include "slap.h"
34
35 #ifdef LDAP_SLAPI
36 #include "slapi/slapi.h"
37
38 static void init_add_pblock( Operation *op, struct berval *dn, Entry *e,
39         int manageDSAit );
40 static int call_add_preop_plugins( Operation *op );
41 static void call_add_postop_plugins( Operation *op );
42 #endif /* LDAP_SLAPI */
43
44 int
45 do_add( Operation *op, SlapReply *rs )
46 {
47         BerElement      *ber = op->o_ber;
48         char            *last;
49         struct berval   dn = BER_BVNULL;
50         ber_len_t       len;
51         ber_tag_t       tag;
52         Entry           *e;
53         Modifications   *modlist = NULL;
54         Modifications   **modtail = &modlist;
55         Modifications   tmp;
56
57         Debug( LDAP_DEBUG_TRACE, "do_add\n", 0, 0, 0 );
58         /*
59          * Parse the add request.  It looks like this:
60          *
61          *      AddRequest := [APPLICATION 14] SEQUENCE {
62          *              name    DistinguishedName,
63          *              attrs   SEQUENCE OF SEQUENCE {
64          *                      type    AttributeType,
65          *                      values  SET OF AttributeValue
66          *              }
67          *      }
68          */
69
70         /* get the name */
71         if ( ber_scanf( ber, "{m", /*}*/ &dn ) == LBER_ERROR ) {
72                 Debug( LDAP_DEBUG_ANY, "do_add: ber_scanf failed\n", 0, 0, 0 );
73                 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
74                 return SLAPD_DISCONNECT;
75         }
76
77         e = (Entry *) ch_calloc( 1, sizeof(Entry) );
78
79         rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn,
80                 op->o_tmpmemctx );
81
82         if( rs->sr_err != LDAP_SUCCESS ) {
83                 Debug( LDAP_DEBUG_ANY, "do_add: invalid dn (%s)\n", dn.bv_val, 0, 0 );
84                 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
85                 goto done;
86         }
87
88         ber_dupbv( &e->e_name, &op->o_req_dn );
89         ber_dupbv( &e->e_nname, &op->o_req_ndn );
90
91         Debug( LDAP_DEBUG_ARGS, "do_add: dn (%s)\n", e->e_dn, 0, 0 );
92
93         /* get the attrs */
94         for ( tag = ber_first_element( ber, &len, &last ); tag != LBER_DEFAULT;
95             tag = ber_next_element( ber, &len, last ) )
96         {
97                 Modifications *mod;
98                 ber_tag_t rtag;
99
100                 tmp.sml_nvalues = NULL;
101
102                 rtag = ber_scanf( ber, "{m{W}}", &tmp.sml_type, &tmp.sml_values );
103
104                 if ( rtag == LBER_ERROR ) {
105                         Debug( LDAP_DEBUG_ANY, "do_add: decoding error\n", 0, 0, 0 );
106                         send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
107                         rs->sr_err = SLAPD_DISCONNECT;
108                         goto done;
109                 }
110
111                 if ( tmp.sml_values == NULL ) {
112                         Debug( LDAP_DEBUG_ANY, "no values for type %s\n",
113                                 tmp.sml_type.bv_val, 0, 0 );
114                         send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
115                                 "no values for attribute type" );
116                         goto done;
117                 }
118
119                 mod  = (Modifications *) ch_malloc( sizeof(Modifications) );
120                 mod->sml_op = LDAP_MOD_ADD;
121                 mod->sml_next = NULL;
122                 mod->sml_desc = NULL;
123                 mod->sml_type = tmp.sml_type;
124                 mod->sml_values = tmp.sml_values;
125                 mod->sml_nvalues = NULL;
126
127                 *modtail = mod;
128                 modtail = &mod->sml_next;
129         }
130
131         if ( ber_scanf( ber, /*{*/ "}") == LBER_ERROR ) {
132                 Debug( LDAP_DEBUG_ANY, "do_add: ber_scanf failed\n", 0, 0, 0 );
133                 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
134                 rs->sr_err = SLAPD_DISCONNECT;
135                 goto done;
136         }
137
138         if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
139                 Debug( LDAP_DEBUG_ANY, "do_add: get_ctrls failed\n", 0, 0, 0 );
140                 goto done;
141         } 
142
143         if ( modlist == NULL ) {
144                 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
145                         "no attributes provided" );
146                 goto done;
147         }
148
149         Statslog( LDAP_DEBUG_STATS, "%s ADD dn=\"%s\"\n",
150             op->o_log_prefix, e->e_name.bv_val, 0, 0, 0 );
151
152         if( e->e_nname.bv_len == 0 ) {
153                 /* protocolError may be a more appropriate error */
154                 send_ldap_error( op, rs, LDAP_ALREADY_EXISTS,
155                         "root DSE already exists" );
156                 goto done;
157
158         } else if ( bvmatch( &e->e_nname, &frontendDB->be_schemandn ) ) {
159                 send_ldap_error( op, rs, LDAP_ALREADY_EXISTS,
160                         "subschema subentry already exists" );
161                 goto done;
162         }
163
164         /* temporary; remove if not invoking backend function */
165         op->ora_e = e;
166         op->ora_modlist = modlist;
167
168         op->o_bd = frontendDB;
169         rs->sr_err = frontendDB->be_add( op, rs );
170         if ( rs->sr_err == 0 ) {
171                 e = NULL;
172         }
173
174 done:;
175         slap_graduate_commit_csn( op );
176
177         if( modlist != NULL ) {
178                 slap_mods_free( modlist );
179         }
180         if( e != NULL ) {
181                 entry_free( e );
182         }
183         op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
184         op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
185
186         return rs->sr_err;
187 }
188
189 int
190 fe_op_add( Operation *op, SlapReply *rs )
191 {
192         int             manageDSAit;
193         Entry           *e = op->ora_e;
194         Modifications   *modlist = op->ora_modlist;
195         Modifications   **modtail = &modlist;
196         int             rc = 0;
197
198         manageDSAit = get_manageDSAit( op );
199
200         /*
201          * We could be serving multiple database backends.  Select the
202          * appropriate one, or send a referral to our "referral server"
203          * if we don't hold it.
204          */
205         op->o_bd = select_backend( &e->e_nname, manageDSAit, 1 );
206         if ( op->o_bd == NULL ) {
207                 rs->sr_ref = referral_rewrite( default_referral,
208                         NULL, &e->e_name, LDAP_SCOPE_DEFAULT );
209                 if ( !rs->sr_ref ) rs->sr_ref = default_referral;
210                 if ( rs->sr_ref ) {
211                         rs->sr_err = LDAP_REFERRAL;
212                         send_ldap_result( op, rs );
213
214                         if ( rs->sr_ref != default_referral ) {
215                                 ber_bvarray_free( rs->sr_ref );
216                         }
217                 } else {
218                         send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
219                                 "no global superior knowledge" );
220                 }
221                 goto done;
222         }
223
224         /* check restrictions */
225         if( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
226                 send_ldap_result( op, rs );
227                 goto done;
228         }
229
230         /* check for referrals */
231         if( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
232                 goto done;
233         }
234
235 #ifdef LDAP_SLAPI
236         if ( op->o_pb ) init_add_pblock( op, &op->o_req_dn, e, manageDSAit );
237 #endif /* LDAP_SLAPI */
238
239         /*
240          * do the add if 1 && (2 || 3)
241          * 1) there is an add function implemented in this backend;
242          * 2) this backend is master for what it holds;
243          * 3) it's a replica and the dn supplied is the updatedn.
244          */
245         if ( op->o_bd->be_add ) {
246                 /* do the update here */
247                 int repl_user = be_isupdate( op );
248 #ifndef SLAPD_MULTIMASTER
249                 if ( !SLAP_SHADOW(op->o_bd) || repl_user )
250 #endif
251                 {
252                         int update = op->o_bd->be_update_ndn.bv_len;
253                         char textbuf[SLAP_TEXT_BUFLEN];
254                         size_t textlen = sizeof textbuf;
255                         slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
256
257                         rs->sr_err = slap_mods_check( modlist, update, &rs->sr_text,
258                                   textbuf, textlen, NULL );
259
260                         if( rs->sr_err != LDAP_SUCCESS ) {
261                                 send_ldap_result( op, rs );
262                                 goto done;
263                         }
264
265                         if ( !repl_user ) {
266                                 for( modtail = &modlist;
267                                         *modtail != NULL;
268                                         modtail = &(*modtail)->sml_next )
269                                 {
270                                         assert( (*modtail)->sml_op == LDAP_MOD_ADD );
271                                         assert( (*modtail)->sml_desc != NULL );
272                                 }
273                                 rs->sr_err = slap_mods_opattrs( op, modlist, modtail,
274                                         &rs->sr_text, textbuf, textlen, 1 );
275                                 if( rs->sr_err != LDAP_SUCCESS ) {
276                                         send_ldap_result( op, rs );
277                                         goto done;
278                                 }
279                         }
280
281                         rs->sr_err = slap_mods2entry( modlist, &e, repl_user, 0,
282                                 &rs->sr_text, textbuf, textlen );
283                         if( rs->sr_err != LDAP_SUCCESS ) {
284                                 send_ldap_result( op, rs );
285                                 goto done;
286                         }
287
288 #ifdef LDAP_SLAPI
289                         /*
290                          * Call the preoperation plugin here, because the entry
291                          * will actually contain something.
292                          */
293                         if ( op->o_pb ) {
294                                 rs->sr_err = call_add_preop_plugins( op );
295                                 if ( rs->sr_err != LDAP_SUCCESS ) {
296                                         /* plugin will have sent result */
297                                         goto done;
298                                 }
299                         }
300 #endif /* LDAP_SLAPI */
301
302                         op->ora_e = e;
303 #ifdef SLAPD_MULTIMASTER
304                         if ( !repl_user )
305 #endif
306                         {
307                                 cb.sc_next = op->o_callback;
308                                 op->o_callback = &cb;
309                         }
310                         rc = (op->o_bd->be_add)( op, rs );
311                         if ( rc == 0 ) {
312                                 /* FIXME: be_entry_release_w() should be
313                                  * called by do_add(), so that global
314                                  * overlays on the way back can
315                                  * at least read the entry */
316                                 be_entry_release_w( op, e );
317                                 e = NULL;
318                         }
319                         op->ora_e = NULL;
320
321 #ifndef SLAPD_MULTIMASTER
322                 } else {
323                         BerVarray defref = NULL;
324 #ifdef LDAP_SLAPI
325                         /*
326                          * SLAPI_ADD_ENTRY will be empty, but this may be acceptable
327                          * on replicas (for now, it involves the minimum code intrusion).
328                          */
329                         if ( op->o_pb ) {
330                                 rs->sr_err = call_add_preop_plugins( op );
331                                 if ( rs->sr_err != LDAP_SUCCESS ) {
332                                         /* plugin will have sent result */
333                                         goto done;
334                                 }
335                         }
336 #endif /* LDAP_SLAPI */
337
338                         defref = op->o_bd->be_update_refs
339                                 ? op->o_bd->be_update_refs : default_referral;
340
341                         if ( defref != NULL ) {
342                                 rs->sr_ref = referral_rewrite( defref,
343                                         NULL, &e->e_name, LDAP_SCOPE_DEFAULT );
344                                 if ( rs->sr_ref == NULL ) rs->sr_ref = defref;
345                                 rs->sr_err = LDAP_REFERRAL;
346                                 if (!rs->sr_ref) rs->sr_ref = default_referral;
347                                 send_ldap_result( op, rs );
348
349                                 if ( rs->sr_ref != default_referral ) {
350                                         ber_bvarray_free( rs->sr_ref );
351                                 }
352                         } else {
353                                 send_ldap_error( op, rs,
354                                         LDAP_UNWILLING_TO_PERFORM,
355                                         "shadow context; no update referral" );
356                         }
357 #endif /* SLAPD_MULTIMASTER */
358                 }
359         } else {
360 #ifdef LDAP_SLAPI
361                 if ( op->o_pb ) {
362                         rs->sr_err = call_add_preop_plugins( op );
363                         if ( rs->sr_err != LDAP_SUCCESS ) {
364                                 /* plugin will have sent result */
365                                 goto done;
366                         }
367                 }
368 #endif
369             Debug( LDAP_DEBUG_ARGS, "    do_add: no backend support\n", 0, 0, 0 );
370             send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
371                         "operation not supported within namingContext" );
372         }
373
374 #ifdef LDAP_SLAPI
375         if ( op->o_pb ) call_add_postop_plugins( op );
376 #endif /* LDAP_SLAPI */
377
378 done:;
379         return rc;
380 }
381
382 int
383 slap_mods2entry(
384         Modifications *mods,
385         Entry **e,
386         int repl_user,
387         int dup,
388         const char **text,
389         char *textbuf, size_t textlen )
390 {
391         Attribute **tail = &(*e)->e_attrs;
392         assert( *tail == NULL );
393
394         *text = textbuf;
395
396         for( ; mods != NULL; mods = mods->sml_next ) {
397                 Attribute *attr;
398
399                 if ( !repl_user ) {
400                         assert( mods->sml_op == LDAP_MOD_ADD );
401                 }
402                 assert( mods->sml_desc != NULL );
403
404                 attr = attr_find( (*e)->e_attrs, mods->sml_desc );
405
406                 if( attr != NULL ) {
407 #define SLURPD_FRIENDLY
408 #ifdef SLURPD_FRIENDLY
409                         ber_len_t i,j;
410
411                         if( !repl_user ) {
412                                 snprintf( textbuf, textlen,
413                                         "attribute '%s' provided more than once",
414                                         mods->sml_desc->ad_cname.bv_val );
415                                 return LDAP_TYPE_OR_VALUE_EXISTS;
416                         }
417
418                         for( i=0; attr->a_vals[i].bv_val; i++ ) {
419                                 /* count them */
420                         }
421                         for( j=0; mods->sml_values[j].bv_val; j++ ) {
422                                 /* count them */
423                         }
424                         j++;    /* NULL */
425                         
426                         attr->a_vals = ch_realloc( attr->a_vals,
427                                 sizeof( struct berval ) * (i+j) );
428
429                         /* should check for duplicates */
430
431                         if ( dup ) {
432                                 for ( j = 0; mods->sml_values[j].bv_val; j++ ) {
433                                         ber_dupbv( &attr->a_vals[i+j], &mods->sml_values[j] );
434                                 }
435                                 BER_BVZERO( &attr->a_vals[i+j] );       
436                         } else {
437                                 AC_MEMCPY( &attr->a_vals[i], mods->sml_values,
438                                         sizeof( struct berval ) * j );
439                                 ch_free( mods->sml_values );
440                                 mods->sml_values = NULL;
441                         }
442
443                         if( mods->sml_nvalues ) {
444                                 attr->a_nvals = ch_realloc( attr->a_nvals,
445                                         sizeof( struct berval ) * (i+j) );
446                                 if ( dup ) {
447                                         for ( j = 0; mods->sml_nvalues[j].bv_val; j++ ) {
448                                                 ber_dupbv( &attr->a_nvals[i+j], &mods->sml_nvalues[j] );
449                                         }
450                                         BER_BVZERO( &attr->a_nvals[i+j] );      
451                                 } else {
452                                         AC_MEMCPY( &attr->a_nvals[i], mods->sml_nvalues,
453                                                 sizeof( struct berval ) * j );
454                                         ch_free( mods->sml_nvalues );
455                                         mods->sml_nvalues = NULL;
456                                 }
457                         } else {
458                                 attr->a_nvals = attr->a_vals;
459                         }
460
461                         continue;
462 #else
463                         snprintf( textbuf, textlen,
464                                 "attribute '%s' provided more than once",
465                                 mods->sml_desc->ad_cname.bv_val );
466                         return LDAP_TYPE_OR_VALUE_EXISTS;
467 #endif
468                 }
469
470                 if( mods->sml_values[1].bv_val != NULL ) {
471                         /* check for duplicates */
472                         int             i, j;
473                         MatchingRule *mr = mods->sml_desc->ad_type->sat_equality;
474
475                         /* check if the values we're adding already exist */
476                         if( mr == NULL || !mr->smr_match ) {
477                                 for ( i = 1; mods->sml_values[i].bv_val != NULL; i++ ) {
478                                         /* test asserted values against themselves */
479                                         for( j = 0; j < i; j++ ) {
480                                                 if ( bvmatch( &mods->sml_values[i],
481                                                         &mods->sml_values[j] ) )
482                                                 {
483                                                         /* value exists already */
484                                                         snprintf( textbuf, textlen,
485                                                                 "%s: value #%d provided more than once",
486                                                                 mods->sml_desc->ad_cname.bv_val, j );
487                                                         return LDAP_TYPE_OR_VALUE_EXISTS;
488                                                 }
489                                         }
490                                 }
491
492                         } else {
493                                 int     rc;
494                                 int match;
495
496                                 for ( i = 1; mods->sml_values[i].bv_val != NULL; i++ ) {
497                                         /* test asserted values against themselves */
498                                         for( j = 0; j < i; j++ ) {
499                                                 rc = value_match( &match, mods->sml_desc, mr,
500                                                         SLAP_MR_EQUALITY
501                                                         | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX
502                                                         | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH
503                                                         | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH,
504                                                         mods->sml_nvalues
505                                                                 ? &mods->sml_nvalues[i]
506                                                                 : &mods->sml_values[i],
507                                                         mods->sml_nvalues
508                                                                 ? &mods->sml_nvalues[j]
509                                                                 : &mods->sml_values[j],
510                                                         text );
511
512                                                 if ( rc == LDAP_SUCCESS && match == 0 ) {
513                                                         /* value exists already */
514                                                         snprintf( textbuf, textlen,
515                                                                 "%s: value #%d provided more than once",
516                                                                 mods->sml_desc->ad_cname.bv_val, j );
517                                                         return LDAP_TYPE_OR_VALUE_EXISTS;
518
519                                                 } else if ( rc != LDAP_SUCCESS ) {
520                                                         return rc;
521                                                 }
522                                         }
523                                 }
524                         }
525                 }
526
527                 attr = ch_calloc( 1, sizeof(Attribute) );
528
529                 /* move ad to attr structure */
530                 attr->a_desc = mods->sml_desc;
531                 if ( !dup ) mods->sml_desc = NULL;
532
533                 /* move values to attr structure */
534                 /*      should check for duplicates */
535                 if ( dup ) { 
536                         int i;
537                         for ( i = 0; mods->sml_values[i].bv_val; i++ ) /* EMPTY */;
538                         attr->a_vals = (BerVarray) ch_calloc( i+1, sizeof( BerValue ));
539                         for ( i = 0; mods->sml_values[i].bv_val; i++ ) {
540                                 ber_dupbv( &attr->a_vals[i], &mods->sml_values[i] );
541                         }
542                         BER_BVZERO( &attr->a_vals[i] );
543                 } else {
544                         attr->a_vals = mods->sml_values;
545                         mods->sml_values = NULL;
546                 }
547
548                 if ( mods->sml_nvalues ) {
549                         if ( dup ) {
550                                 int i;
551                                 for ( i = 0; mods->sml_nvalues[i].bv_val; i++ ) /* EMPTY */;
552                                 attr->a_nvals = (BerVarray) ch_calloc( i+1, sizeof( BerValue ));
553                                 for ( i = 0; mods->sml_nvalues[i].bv_val; i++ ) {
554                                         ber_dupbv( &attr->a_nvals[i], &mods->sml_nvalues[i] );
555                                 }
556                                 BER_BVZERO( &attr->a_nvals[i] );
557                         } else {
558                                 attr->a_nvals = mods->sml_nvalues;
559                                 mods->sml_nvalues = NULL;
560                         }
561                 } else {
562                         attr->a_nvals = attr->a_vals;
563                 }
564
565                 *tail = attr;
566                 tail = &attr->a_next;
567         }
568
569         return LDAP_SUCCESS;
570 }
571
572 int
573 slap_entry2mods(
574         Entry *e,
575         Modifications **mods,
576         const char **text,
577         char *textbuf, size_t textlen )
578 {
579         Modifications   *modhead = NULL;
580         Modifications   *mod;
581         Modifications   **modtail = &modhead;
582         Attribute               *a_new;
583         AttributeDescription    *a_new_desc;
584         int                             i, count;
585
586         a_new = e->e_attrs;
587
588         while ( a_new != NULL ) {
589                 a_new_desc = a_new->a_desc;
590                 mod = (Modifications *) malloc( sizeof( Modifications ));
591                 
592                 mod->sml_op = LDAP_MOD_REPLACE;
593
594                 mod->sml_type = a_new_desc->ad_cname;
595
596                 for ( count = 0; a_new->a_vals[count].bv_val; count++ ) /* EMPTY */;
597
598                 mod->sml_values = (struct berval*) malloc(
599                         (count+1) * sizeof( struct berval) );
600
601                 /* see slap_mods_check() comments...
602                  * if a_vals == a_nvals, there is no normalizer.
603                  * in this case, mod->sml_nvalues must be left NULL.
604                  */
605                 if ( a_new->a_vals != a_new->a_nvals ) {
606                         mod->sml_nvalues = (struct berval*) malloc(
607                                 (count+1) * sizeof( struct berval) );
608                 } else {
609                         mod->sml_nvalues = NULL;
610                 }
611
612                 for ( i = 0; i < count; i++ ) {
613                         ber_dupbv(mod->sml_values+i, a_new->a_vals+i); 
614                         if ( mod->sml_nvalues ) {
615                                 ber_dupbv( mod->sml_nvalues+i, a_new->a_nvals+i ); 
616                         } 
617                 }
618
619                 mod->sml_values[count].bv_val = NULL; 
620                 mod->sml_values[count].bv_len = 0; 
621
622                 if ( mod->sml_nvalues ) {
623                         mod->sml_nvalues[count].bv_val = NULL; 
624                         mod->sml_nvalues[count].bv_len = 0; 
625                 }
626
627                 mod->sml_desc = a_new_desc;
628                 mod->sml_next =NULL;
629                 *modtail = mod;
630                 modtail = &mod->sml_next;
631                 a_new = a_new->a_next; 
632         }
633
634         *mods = modhead;
635
636         return LDAP_SUCCESS;
637 }
638
639 #ifdef LDAP_SLAPI
640 static void init_add_pblock( Operation *op,
641         struct berval *dn, Entry *e, int manageDSAit )
642 {
643         slapi_int_pblock_set_operation( op->o_pb, op );
644         slapi_pblock_set( op->o_pb, SLAPI_ADD_TARGET, (void *)dn->bv_val );
645         slapi_pblock_set( op->o_pb, SLAPI_ADD_ENTRY, (void *)e );
646         slapi_pblock_set( op->o_pb, SLAPI_MANAGEDSAIT, (void *)manageDSAit );
647 }
648
649 static int call_add_preop_plugins( Operation *op )
650 {
651         int rc;
652
653         rc = slapi_int_call_plugins( op->o_bd, SLAPI_PLUGIN_PRE_ADD_FN, op->o_pb );
654         if ( rc < 0 ) {
655                 /*
656                  * A preoperation plugin failure will abort the
657                  * entire operation.
658                  */
659                 Debug(LDAP_DEBUG_TRACE,
660                         "do_add: add preoperation plugin failed.\n",
661                         0, 0, 0);
662
663                 if (( slapi_pblock_get( op->o_pb, SLAPI_RESULT_CODE,
664                         (void *)&rc ) != 0 ) || rc == LDAP_SUCCESS )
665                 {
666                         rc = LDAP_OTHER;
667                 }
668         } else {
669                 rc = LDAP_SUCCESS;
670         }
671
672         return rc;
673 }
674
675 static void call_add_postop_plugins( Operation *op )
676 {
677         int rc;
678
679         rc = slapi_int_call_plugins( op->o_bd, SLAPI_PLUGIN_POST_ADD_FN, op->o_pb );
680         if ( rc < 0 ) {
681                 Debug(LDAP_DEBUG_TRACE,
682                         "do_add: add postoperation plugin failed\n",
683                         0, 0, 0);
684         }
685 }
686 #endif /* LDAP_SLAPI */