]> git.sur5r.net Git - openldap/blob - servers/slapd/add.c
086efa4ba7ce1434e327f6161a060dbbb79973d5
[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 "ldap_pvt.h"
34 #include "slap.h"
35
36 #ifdef LDAP_SLAPI
37 #include "slapi/slapi.h"
38
39 static void init_add_pblock( Operation *op, struct berval *dn, Entry *e,
40         int manageDSAit );
41 static int call_add_preop_plugins( Operation *op );
42 static void call_add_postop_plugins( Operation *op );
43 #endif /* LDAP_SLAPI */
44
45 int
46 do_add( Operation *op, SlapReply *rs )
47 {
48         BerElement      *ber = op->o_ber;
49         char            *last;
50         struct berval   dn = BER_BVNULL;
51         ber_len_t       len;
52         ber_tag_t       tag;
53         Entry           *e;
54         Modifications   *modlist = NULL;
55         Modifications   **modtail = &modlist;
56         Modifications   tmp;
57
58         Debug( LDAP_DEBUG_TRACE, "do_add\n", 0, 0, 0 );
59         /*
60          * Parse the add request.  It looks like this:
61          *
62          *      AddRequest := [APPLICATION 14] SEQUENCE {
63          *              name    DistinguishedName,
64          *              attrs   SEQUENCE OF SEQUENCE {
65          *                      type    AttributeType,
66          *                      values  SET OF AttributeValue
67          *              }
68          *      }
69          */
70
71         /* get the name */
72         if ( ber_scanf( ber, "{m", /*}*/ &dn ) == LBER_ERROR ) {
73                 Debug( LDAP_DEBUG_ANY, "do_add: ber_scanf failed\n", 0, 0, 0 );
74                 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
75                 return SLAPD_DISCONNECT;
76         }
77
78         e = (Entry *) ch_calloc( 1, sizeof(Entry) );
79
80         rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn,
81                 op->o_tmpmemctx );
82
83         if( rs->sr_err != LDAP_SUCCESS ) {
84                 Debug( LDAP_DEBUG_ANY, "do_add: invalid dn (%s)\n", dn.bv_val, 0, 0 );
85                 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
86                 goto done;
87         }
88
89         ber_dupbv( &e->e_name, &op->o_req_dn );
90         ber_dupbv( &e->e_nname, &op->o_req_ndn );
91
92         Debug( LDAP_DEBUG_ARGS, "do_add: dn (%s)\n", e->e_dn, 0, 0 );
93
94         /* get the attrs */
95         for ( tag = ber_first_element( ber, &len, &last ); tag != LBER_DEFAULT;
96             tag = ber_next_element( ber, &len, last ) )
97         {
98                 Modifications *mod;
99                 ber_tag_t rtag;
100
101                 tmp.sml_nvalues = NULL;
102
103                 rtag = ber_scanf( ber, "{m{W}}", &tmp.sml_type, &tmp.sml_values );
104
105                 if ( rtag == LBER_ERROR ) {
106                         Debug( LDAP_DEBUG_ANY, "do_add: decoding error\n", 0, 0, 0 );
107                         send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
108                         rs->sr_err = SLAPD_DISCONNECT;
109                         goto done;
110                 }
111
112                 if ( tmp.sml_values == NULL ) {
113                         Debug( LDAP_DEBUG_ANY, "no values for type %s\n",
114                                 tmp.sml_type.bv_val, 0, 0 );
115                         send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
116                                 "no values for attribute type" );
117                         goto done;
118                 }
119
120                 mod  = (Modifications *) ch_malloc( sizeof(Modifications) );
121                 mod->sml_op = LDAP_MOD_ADD;
122                 mod->sml_next = NULL;
123                 mod->sml_desc = NULL;
124                 mod->sml_type = tmp.sml_type;
125                 mod->sml_values = tmp.sml_values;
126                 mod->sml_nvalues = NULL;
127
128                 *modtail = mod;
129                 modtail = &mod->sml_next;
130         }
131
132         if ( ber_scanf( ber, /*{*/ "}") == LBER_ERROR ) {
133                 Debug( LDAP_DEBUG_ANY, "do_add: ber_scanf failed\n", 0, 0, 0 );
134                 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
135                 rs->sr_err = SLAPD_DISCONNECT;
136                 goto done;
137         }
138
139         if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
140                 Debug( LDAP_DEBUG_ANY, "do_add: get_ctrls failed\n", 0, 0, 0 );
141                 goto done;
142         } 
143
144         if ( modlist == NULL ) {
145                 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
146                         "no attributes provided" );
147                 goto done;
148         }
149
150         Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu ADD dn=\"%s\"\n",
151             op->o_connid, op->o_opid, e->e_name.bv_val, 0, 0 );
152
153         if( e->e_nname.bv_len == 0 ) {
154                 /* protocolError may be a more appropriate error */
155                 send_ldap_error( op, rs, LDAP_ALREADY_EXISTS,
156                         "root DSE already exists" );
157                 goto done;
158
159         } else if ( bvmatch( &e->e_nname, &frontendDB->be_schemandn ) ) {
160                 send_ldap_error( op, rs, LDAP_ALREADY_EXISTS,
161                         "subschema subentry already exists" );
162                 goto done;
163         }
164
165         /* temporary; remove if not invoking backend function */
166         op->ora_e = e;
167         op->ora_modlist = modlist;
168
169         op->o_bd = frontendDB;
170         rs->sr_err = frontendDB->be_add( op, rs );
171         if ( rs->sr_err == 0 ) {
172                 e = NULL;
173         }
174
175 done:;
176         slap_graduate_commit_csn( op );
177
178         if( modlist != NULL ) {
179                 slap_mods_free( modlist );
180         }
181         if( e != NULL ) {
182                 entry_free( e );
183         }
184         op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
185         op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
186
187         return rs->sr_err;
188 }
189
190 int
191 fe_op_add( Operation *op, SlapReply *rs )
192 {
193         int             manageDSAit;
194         Entry           *e = op->ora_e;
195         Modifications   *modlist = op->ora_modlist;
196         Modifications   **modtail = &modlist;
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, 0 );
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                         if ( (op->o_bd->be_add)( op, rs ) == 0 ) {
311                                 be_entry_release_w( op, e );
312                                 e = NULL;
313                         }
314
315 #ifndef SLAPD_MULTIMASTER
316                 } else {
317                         BerVarray defref = NULL;
318 #ifdef LDAP_SLAPI
319                         /*
320                          * SLAPI_ADD_ENTRY will be empty, but this may be acceptable
321                          * on replicas (for now, it involves the minimum code intrusion).
322                          */
323                         if ( op->o_pb ) {
324                                 rs->sr_err = call_add_preop_plugins( op );
325                                 if ( rs->sr_err != LDAP_SUCCESS ) {
326                                         /* plugin will have sent result */
327                                         goto done;
328                                 }
329                         }
330 #endif /* LDAP_SLAPI */
331
332                         defref = op->o_bd->be_update_refs
333                                 ? op->o_bd->be_update_refs : default_referral;
334
335                         if ( defref != NULL ) {
336                                 rs->sr_ref = referral_rewrite( defref,
337                                         NULL, &e->e_name, LDAP_SCOPE_DEFAULT );
338                                 if ( rs->sr_ref == NULL ) rs->sr_ref = defref;
339                                 rs->sr_err = LDAP_REFERRAL;
340                                 if (!rs->sr_ref) rs->sr_ref = default_referral;
341                                 send_ldap_result( op, rs );
342
343                                 if ( rs->sr_ref != default_referral ) {
344                                         ber_bvarray_free( rs->sr_ref );
345                                 }
346                         } else {
347                                 send_ldap_error( op, rs,
348                                         LDAP_UNWILLING_TO_PERFORM,
349                                         "shadow context; no update referral" );
350                         }
351 #endif /* SLAPD_MULTIMASTER */
352                 }
353         } else {
354 #ifdef LDAP_SLAPI
355                 if ( op->o_pb ) {
356                         rs->sr_err = call_add_preop_plugins( op );
357                         if ( rs->sr_err != LDAP_SUCCESS ) {
358                                 /* plugin will have sent result */
359                                 goto done;
360                         }
361                 }
362 #endif
363             Debug( LDAP_DEBUG_ARGS, "    do_add: no backend support\n", 0, 0, 0 );
364             send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
365                         "operation not supported within namingContext" );
366         }
367
368 #ifdef LDAP_SLAPI
369         if ( op->o_pb ) call_add_postop_plugins( op );
370 #endif /* LDAP_SLAPI */
371
372 done:;
373         return rs->sr_err;
374 }
375
376 int
377 slap_mods2entry(
378         Modifications *mods,
379         Entry **e,
380         int repl_user,
381         int dup,
382         const char **text,
383         char *textbuf, size_t textlen )
384 {
385         Attribute **tail = &(*e)->e_attrs;
386         assert( *tail == NULL );
387
388         *text = textbuf;
389
390         for( ; mods != NULL; mods = mods->sml_next ) {
391                 Attribute *attr;
392
393                 if ( !repl_user ) {
394                         assert( mods->sml_op == LDAP_MOD_ADD );
395                 }
396                 assert( mods->sml_desc != NULL );
397
398                 attr = attr_find( (*e)->e_attrs, mods->sml_desc );
399
400                 if( attr != NULL ) {
401 #define SLURPD_FRIENDLY
402 #ifdef SLURPD_FRIENDLY
403                         ber_len_t i,j;
404
405                         if( !repl_user ) {
406                                 snprintf( textbuf, textlen,
407                                         "attribute '%s' provided more than once",
408                                         mods->sml_desc->ad_cname.bv_val );
409                                 return LDAP_TYPE_OR_VALUE_EXISTS;
410                         }
411
412                         for( i=0; attr->a_vals[i].bv_val; i++ ) {
413                                 /* count them */
414                         }
415                         for( j=0; mods->sml_values[j].bv_val; j++ ) {
416                                 /* count them */
417                         }
418                         j++;    /* NULL */
419                         
420                         attr->a_vals = ch_realloc( attr->a_vals,
421                                 sizeof( struct berval ) * (i+j) );
422
423                         /* should check for duplicates */
424
425                         if ( dup ) {
426                                 for ( j = 0; mods->sml_values[j].bv_val; j++ ) {
427                                         ber_dupbv( &attr->a_vals[i+j], &mods->sml_values[j] );
428                                 }
429                                 BER_BVZERO( &attr->a_vals[i+j] );       
430                         } else {
431                                 AC_MEMCPY( &attr->a_vals[i], mods->sml_values,
432                                         sizeof( struct berval ) * j );
433                                 ch_free( mods->sml_values );
434                                 mods->sml_values = NULL;
435                         }
436
437                         if( mods->sml_nvalues ) {
438                                 attr->a_nvals = ch_realloc( attr->a_nvals,
439                                         sizeof( struct berval ) * (i+j) );
440                                 if ( dup ) {
441                                         for ( j = 0; mods->sml_nvalues[j].bv_val; j++ ) {
442                                                 ber_dupbv( &attr->a_nvals[i+j], &mods->sml_nvalues[j] );
443                                         }
444                                         BER_BVZERO( &attr->a_nvals[i+j] );      
445                                 } else {
446                                         AC_MEMCPY( &attr->a_nvals[i], mods->sml_nvalues,
447                                                 sizeof( struct berval ) * j );
448                                         ch_free( mods->sml_nvalues );
449                                         mods->sml_nvalues = NULL;
450                                 }
451                         } else {
452                                 attr->a_nvals = attr->a_vals;
453                         }
454
455                         continue;
456 #else
457                         snprintf( textbuf, textlen,
458                                 "attribute '%s' provided more than once",
459                                 mods->sml_desc->ad_cname.bv_val );
460                         return LDAP_TYPE_OR_VALUE_EXISTS;
461 #endif
462                 }
463
464                 if( mods->sml_values[1].bv_val != NULL ) {
465                         /* check for duplicates */
466                         int             i, j;
467                         MatchingRule *mr = mods->sml_desc->ad_type->sat_equality;
468
469                         /* check if the values we're adding already exist */
470                         if( mr == NULL || !mr->smr_match ) {
471                                 for ( i = 1; mods->sml_values[i].bv_val != NULL; i++ ) {
472                                         /* test asserted values against themselves */
473                                         for( j = 0; j < i; j++ ) {
474                                                 if ( bvmatch( &mods->sml_values[i],
475                                                         &mods->sml_values[j] ) )
476                                                 {
477                                                         /* value exists already */
478                                                         snprintf( textbuf, textlen,
479                                                                 "%s: value #%d provided more than once",
480                                                                 mods->sml_desc->ad_cname.bv_val, j );
481                                                         return LDAP_TYPE_OR_VALUE_EXISTS;
482                                                 }
483                                         }
484                                 }
485
486                         } else {
487                                 int     rc;
488                                 int match;
489
490                                 for ( i = 1; mods->sml_values[i].bv_val != NULL; i++ ) {
491                                         /* test asserted values against themselves */
492                                         for( j = 0; j < i; j++ ) {
493                                                 rc = value_match( &match, mods->sml_desc, mr,
494                                                         SLAP_MR_EQUALITY
495                                                         | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX
496                                                         | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH
497                                                         | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH,
498                                                         mods->sml_nvalues
499                                                                 ? &mods->sml_nvalues[i]
500                                                                 : &mods->sml_values[i],
501                                                         mods->sml_nvalues
502                                                                 ? &mods->sml_nvalues[j]
503                                                                 : &mods->sml_values[j],
504                                                         text );
505
506                                                 if ( rc == LDAP_SUCCESS && match == 0 ) {
507                                                         /* value exists already */
508                                                         snprintf( textbuf, textlen,
509                                                                 "%s: value #%d provided more than once",
510                                                                 mods->sml_desc->ad_cname.bv_val, j );
511                                                         return LDAP_TYPE_OR_VALUE_EXISTS;
512
513                                                 } else if ( rc != LDAP_SUCCESS ) {
514                                                         return rc;
515                                                 }
516                                         }
517                                 }
518                         }
519                 }
520
521                 attr = ch_calloc( 1, sizeof(Attribute) );
522
523                 /* move ad to attr structure */
524                 attr->a_desc = mods->sml_desc;
525                 if ( !dup ) mods->sml_desc = NULL;
526
527                 /* move values to attr structure */
528                 /*      should check for duplicates */
529                 if ( dup ) { 
530                         int i;
531                         for ( i = 0; mods->sml_values[i].bv_val; i++ ) /* EMPTY */;
532                         attr->a_vals = (BerVarray) ch_calloc( i+1, sizeof( BerValue ));
533                         for ( i = 0; mods->sml_values[i].bv_val; i++ ) {
534                                 ber_dupbv( &attr->a_vals[i], &mods->sml_values[i] );
535                         }
536                         BER_BVZERO( &attr->a_vals[i] );
537                 } else {
538                         attr->a_vals = mods->sml_values;
539                         mods->sml_values = NULL;
540                 }
541
542                 if ( mods->sml_nvalues ) {
543                         if ( dup ) {
544                                 int i;
545                                 for ( i = 0; mods->sml_nvalues[i].bv_val; i++ ) /* EMPTY */;
546                                 attr->a_nvals = (BerVarray) ch_calloc( i+1, sizeof( BerValue ));
547                                 for ( i = 0; mods->sml_nvalues[i].bv_val; i++ ) {
548                                         ber_dupbv( &attr->a_nvals[i], &mods->sml_nvalues[i] );
549                                 }
550                                 BER_BVZERO( &attr->a_nvals[i] );
551                         } else {
552                                 attr->a_nvals = mods->sml_nvalues;
553                                 mods->sml_nvalues = NULL;
554                         }
555                 } else {
556                         attr->a_nvals = attr->a_vals;
557                 }
558
559                 *tail = attr;
560                 tail = &attr->a_next;
561         }
562
563         return LDAP_SUCCESS;
564 }
565
566 int
567 slap_entry2mods(
568         Entry *e,
569         Modifications **mods,
570         const char **text,
571         char *textbuf, size_t textlen )
572 {
573         Modifications   *modhead = NULL;
574         Modifications   *mod;
575         Modifications   **modtail = &modhead;
576         Attribute               *a_new;
577         AttributeDescription    *a_new_desc;
578         int                             i, count;
579
580         a_new = e->e_attrs;
581
582         while ( a_new != NULL ) {
583                 a_new_desc = a_new->a_desc;
584                 mod = (Modifications *) malloc( sizeof( Modifications ));
585                 
586                 mod->sml_op = LDAP_MOD_REPLACE;
587
588                 mod->sml_type = a_new_desc->ad_cname;
589
590                 for ( count = 0; a_new->a_vals[count].bv_val; count++ ) /* EMPTY */;
591
592                 mod->sml_values = (struct berval*) malloc(
593                         (count+1) * sizeof( struct berval) );
594
595                 /* see slap_mods_check() comments...
596                  * if a_vals == a_nvals, there is no normalizer.
597                  * in this case, mod->sml_nvalues must be left NULL.
598                  */
599                 if ( a_new->a_vals != a_new->a_nvals ) {
600                         mod->sml_nvalues = (struct berval*) malloc(
601                                 (count+1) * sizeof( struct berval) );
602                 } else {
603                         mod->sml_nvalues = NULL;
604                 }
605
606                 for ( i = 0; i < count; i++ ) {
607                         ber_dupbv(mod->sml_values+i, a_new->a_vals+i); 
608                         if ( mod->sml_nvalues ) {
609                                 ber_dupbv( mod->sml_nvalues+i, a_new->a_nvals+i ); 
610                         } 
611                 }
612
613                 mod->sml_values[count].bv_val = NULL; 
614                 mod->sml_values[count].bv_len = 0; 
615
616                 if ( mod->sml_nvalues ) {
617                         mod->sml_nvalues[count].bv_val = NULL; 
618                         mod->sml_nvalues[count].bv_len = 0; 
619                 }
620
621                 mod->sml_desc = a_new_desc;
622                 mod->sml_next =NULL;
623                 *modtail = mod;
624                 modtail = &mod->sml_next;
625                 a_new = a_new->a_next; 
626         }
627
628         *mods = modhead;
629
630         return LDAP_SUCCESS;
631 }
632
633 #ifdef LDAP_SLAPI
634 static void init_add_pblock( Operation *op,
635         struct berval *dn, Entry *e, int manageDSAit )
636 {
637         slapi_int_pblock_set_operation( op->o_pb, op );
638         slapi_pblock_set( op->o_pb, SLAPI_ADD_TARGET, (void *)dn->bv_val );
639         slapi_pblock_set( op->o_pb, SLAPI_ADD_ENTRY, (void *)e );
640         slapi_pblock_set( op->o_pb, SLAPI_MANAGEDSAIT, (void *)manageDSAit );
641 }
642
643 static int call_add_preop_plugins( Operation *op )
644 {
645         int rc;
646
647         rc = slapi_int_call_plugins( op->o_bd, SLAPI_PLUGIN_PRE_ADD_FN, op->o_pb );
648         if ( rc < 0 ) {
649                 /*
650                  * A preoperation plugin failure will abort the
651                  * entire operation.
652                  */
653                 Debug(LDAP_DEBUG_TRACE,
654                         "do_add: add preoperation plugin failed.\n",
655                         0, 0, 0);
656
657                 if (( slapi_pblock_get( op->o_pb, SLAPI_RESULT_CODE,
658                         (void *)&rc ) != 0 ) || rc == LDAP_SUCCESS )
659                 {
660                         rc = LDAP_OTHER;
661                 }
662         } else {
663                 rc = LDAP_SUCCESS;
664         }
665
666         return rc;
667 }
668
669 static void call_add_postop_plugins( Operation *op )
670 {
671         int rc;
672
673         rc = slapi_int_call_plugins( op->o_bd, SLAPI_PLUGIN_POST_ADD_FN, op->o_pb );
674         if ( rc < 0 ) {
675                 Debug(LDAP_DEBUG_TRACE,
676                         "do_add: add postoperation plugin failed\n",
677                         0, 0, 0);
678         }
679 }
680 #endif /* LDAP_SLAPI */