]> git.sur5r.net Git - openldap/blob - servers/slapd/add.c
1c3a5f276633720013b86c669426f578a65cf498
[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, "conn=%lu op=%lu ADD dn=\"%s\"\n",
150             op->o_connid, op->o_opid, e->e_name.bv_val, 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
197         manageDSAit = get_manageDSAit( op );
198
199         /*
200          * We could be serving multiple database backends.  Select the
201          * appropriate one, or send a referral to our "referral server"
202          * if we don't hold it.
203          */
204         op->o_bd = select_backend( &e->e_nname, manageDSAit, 0 );
205         if ( op->o_bd == NULL ) {
206                 rs->sr_ref = referral_rewrite( default_referral,
207                         NULL, &e->e_name, LDAP_SCOPE_DEFAULT );
208                 if ( !rs->sr_ref ) rs->sr_ref = default_referral;
209                 if ( rs->sr_ref ) {
210                         rs->sr_err = LDAP_REFERRAL;
211                         send_ldap_result( op, rs );
212
213                         if ( rs->sr_ref != default_referral ) {
214                                 ber_bvarray_free( rs->sr_ref );
215                         }
216                 } else {
217                         send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
218                                 "no global superior knowledge" );
219                 }
220                 goto done;
221         }
222
223         /* check restrictions */
224         if( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
225                 send_ldap_result( op, rs );
226                 goto done;
227         }
228
229         /* check for referrals */
230         if( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
231                 goto done;
232         }
233
234 #ifdef LDAP_SLAPI
235         if ( op->o_pb ) init_add_pblock( op, &op->o_req_dn, e, manageDSAit );
236 #endif /* LDAP_SLAPI */
237
238         /*
239          * do the add if 1 && (2 || 3)
240          * 1) there is an add function implemented in this backend;
241          * 2) this backend is master for what it holds;
242          * 3) it's a replica and the dn supplied is the updatedn.
243          */
244         if ( op->o_bd->be_add ) {
245                 /* do the update here */
246                 int repl_user = be_isupdate( op );
247 #ifndef SLAPD_MULTIMASTER
248                 if ( !SLAP_SHADOW(op->o_bd) || repl_user )
249 #endif
250                 {
251                         int update = op->o_bd->be_update_ndn.bv_len;
252                         char textbuf[SLAP_TEXT_BUFLEN];
253                         size_t textlen = sizeof textbuf;
254                         slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
255
256                         rs->sr_err = slap_mods_check( modlist, update, &rs->sr_text,
257                                   textbuf, textlen, NULL );
258
259                         if( rs->sr_err != LDAP_SUCCESS ) {
260                                 send_ldap_result( op, rs );
261                                 goto done;
262                         }
263
264                         if ( !repl_user ) {
265                                 for( modtail = &modlist;
266                                         *modtail != NULL;
267                                         modtail = &(*modtail)->sml_next )
268                                 {
269                                         assert( (*modtail)->sml_op == LDAP_MOD_ADD );
270                                         assert( (*modtail)->sml_desc != NULL );
271                                 }
272                                 rs->sr_err = slap_mods_opattrs( op, modlist, modtail,
273                                         &rs->sr_text, textbuf, textlen, 1 );
274                                 if( rs->sr_err != LDAP_SUCCESS ) {
275                                         send_ldap_result( op, rs );
276                                         goto done;
277                                 }
278                         }
279
280                         rs->sr_err = slap_mods2entry( modlist, &e, repl_user, 0,
281                                 &rs->sr_text, textbuf, textlen );
282                         if( rs->sr_err != LDAP_SUCCESS ) {
283                                 send_ldap_result( op, rs );
284                                 goto done;
285                         }
286
287 #ifdef LDAP_SLAPI
288                         /*
289                          * Call the preoperation plugin here, because the entry
290                          * will actually contain something.
291                          */
292                         if ( op->o_pb ) {
293                                 rs->sr_err = call_add_preop_plugins( op );
294                                 if ( rs->sr_err != LDAP_SUCCESS ) {
295                                         /* plugin will have sent result */
296                                         goto done;
297                                 }
298                         }
299 #endif /* LDAP_SLAPI */
300
301                         op->ora_e = e;
302 #ifdef SLAPD_MULTIMASTER
303                         if ( !repl_user )
304 #endif
305                         {
306                                 cb.sc_next = op->o_callback;
307                                 op->o_callback = &cb;
308                         }
309                         if ( (op->o_bd->be_add)( op, rs ) == 0 ) {
310                                 be_entry_release_w( op, e );
311                                 e = NULL;
312                         }
313
314 #ifndef SLAPD_MULTIMASTER
315                 } else {
316                         BerVarray defref = NULL;
317 #ifdef LDAP_SLAPI
318                         /*
319                          * SLAPI_ADD_ENTRY will be empty, but this may be acceptable
320                          * on replicas (for now, it involves the minimum code intrusion).
321                          */
322                         if ( op->o_pb ) {
323                                 rs->sr_err = call_add_preop_plugins( op );
324                                 if ( rs->sr_err != LDAP_SUCCESS ) {
325                                         /* plugin will have sent result */
326                                         goto done;
327                                 }
328                         }
329 #endif /* LDAP_SLAPI */
330
331                         defref = op->o_bd->be_update_refs
332                                 ? op->o_bd->be_update_refs : default_referral;
333
334                         if ( defref != NULL ) {
335                                 rs->sr_ref = referral_rewrite( defref,
336                                         NULL, &e->e_name, LDAP_SCOPE_DEFAULT );
337                                 if ( rs->sr_ref == NULL ) rs->sr_ref = defref;
338                                 rs->sr_err = LDAP_REFERRAL;
339                                 if (!rs->sr_ref) rs->sr_ref = default_referral;
340                                 send_ldap_result( op, rs );
341
342                                 if ( rs->sr_ref != default_referral ) {
343                                         ber_bvarray_free( rs->sr_ref );
344                                 }
345                         } else {
346                                 send_ldap_error( op, rs,
347                                         LDAP_UNWILLING_TO_PERFORM,
348                                         "shadow context; no update referral" );
349                         }
350 #endif /* SLAPD_MULTIMASTER */
351                 }
352         } else {
353 #ifdef LDAP_SLAPI
354                 if ( op->o_pb ) {
355                         rs->sr_err = call_add_preop_plugins( op );
356                         if ( rs->sr_err != LDAP_SUCCESS ) {
357                                 /* plugin will have sent result */
358                                 goto done;
359                         }
360                 }
361 #endif
362             Debug( LDAP_DEBUG_ARGS, "    do_add: no backend support\n", 0, 0, 0 );
363             send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
364                         "operation not supported within namingContext" );
365         }
366
367 #ifdef LDAP_SLAPI
368         if ( op->o_pb ) call_add_postop_plugins( op );
369 #endif /* LDAP_SLAPI */
370
371 done:;
372         return rs->sr_err;
373 }
374
375 int
376 slap_mods2entry(
377         Modifications *mods,
378         Entry **e,
379         int repl_user,
380         int dup,
381         const char **text,
382         char *textbuf, size_t textlen )
383 {
384         Attribute **tail = &(*e)->e_attrs;
385         assert( *tail == NULL );
386
387         *text = textbuf;
388
389         for( ; mods != NULL; mods = mods->sml_next ) {
390                 Attribute *attr;
391
392                 if ( !repl_user ) {
393                         assert( mods->sml_op == LDAP_MOD_ADD );
394                 }
395                 assert( mods->sml_desc != NULL );
396
397                 attr = attr_find( (*e)->e_attrs, mods->sml_desc );
398
399                 if( attr != NULL ) {
400 #define SLURPD_FRIENDLY
401 #ifdef SLURPD_FRIENDLY
402                         ber_len_t i,j;
403
404                         if( !repl_user ) {
405                                 snprintf( textbuf, textlen,
406                                         "attribute '%s' provided more than once",
407                                         mods->sml_desc->ad_cname.bv_val );
408                                 return LDAP_TYPE_OR_VALUE_EXISTS;
409                         }
410
411                         for( i=0; attr->a_vals[i].bv_val; i++ ) {
412                                 /* count them */
413                         }
414                         for( j=0; mods->sml_values[j].bv_val; j++ ) {
415                                 /* count them */
416                         }
417                         j++;    /* NULL */
418                         
419                         attr->a_vals = ch_realloc( attr->a_vals,
420                                 sizeof( struct berval ) * (i+j) );
421
422                         /* should check for duplicates */
423
424                         if ( dup ) {
425                                 for ( j = 0; mods->sml_values[j].bv_val; j++ ) {
426                                         ber_dupbv( &attr->a_vals[i+j], &mods->sml_values[j] );
427                                 }
428                                 BER_BVZERO( &attr->a_vals[i+j] );       
429                         } else {
430                                 AC_MEMCPY( &attr->a_vals[i], mods->sml_values,
431                                         sizeof( struct berval ) * j );
432                                 ch_free( mods->sml_values );
433                                 mods->sml_values = NULL;
434                         }
435
436                         if( mods->sml_nvalues ) {
437                                 attr->a_nvals = ch_realloc( attr->a_nvals,
438                                         sizeof( struct berval ) * (i+j) );
439                                 if ( dup ) {
440                                         for ( j = 0; mods->sml_nvalues[j].bv_val; j++ ) {
441                                                 ber_dupbv( &attr->a_nvals[i+j], &mods->sml_nvalues[j] );
442                                         }
443                                         BER_BVZERO( &attr->a_nvals[i+j] );      
444                                 } else {
445                                         AC_MEMCPY( &attr->a_nvals[i], mods->sml_nvalues,
446                                                 sizeof( struct berval ) * j );
447                                         ch_free( mods->sml_nvalues );
448                                         mods->sml_nvalues = NULL;
449                                 }
450                         } else {
451                                 attr->a_nvals = attr->a_vals;
452                         }
453
454                         continue;
455 #else
456                         snprintf( textbuf, textlen,
457                                 "attribute '%s' provided more than once",
458                                 mods->sml_desc->ad_cname.bv_val );
459                         return LDAP_TYPE_OR_VALUE_EXISTS;
460 #endif
461                 }
462
463                 if( mods->sml_values[1].bv_val != NULL ) {
464                         /* check for duplicates */
465                         int             i, j;
466                         MatchingRule *mr = mods->sml_desc->ad_type->sat_equality;
467
468                         /* check if the values we're adding already exist */
469                         if( mr == NULL || !mr->smr_match ) {
470                                 for ( i = 1; mods->sml_values[i].bv_val != NULL; i++ ) {
471                                         /* test asserted values against themselves */
472                                         for( j = 0; j < i; j++ ) {
473                                                 if ( bvmatch( &mods->sml_values[i],
474                                                         &mods->sml_values[j] ) )
475                                                 {
476                                                         /* value exists already */
477                                                         snprintf( textbuf, textlen,
478                                                                 "%s: value #%d provided more than once",
479                                                                 mods->sml_desc->ad_cname.bv_val, j );
480                                                         return LDAP_TYPE_OR_VALUE_EXISTS;
481                                                 }
482                                         }
483                                 }
484
485                         } else {
486                                 int     rc;
487                                 int match;
488
489                                 for ( i = 1; mods->sml_values[i].bv_val != NULL; i++ ) {
490                                         /* test asserted values against themselves */
491                                         for( j = 0; j < i; j++ ) {
492                                                 rc = value_match( &match, mods->sml_desc, mr,
493                                                         SLAP_MR_EQUALITY
494                                                         | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX
495                                                         | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH
496                                                         | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH,
497                                                         mods->sml_nvalues
498                                                                 ? &mods->sml_nvalues[i]
499                                                                 : &mods->sml_values[i],
500                                                         mods->sml_nvalues
501                                                                 ? &mods->sml_nvalues[j]
502                                                                 : &mods->sml_values[j],
503                                                         text );
504
505                                                 if ( rc == LDAP_SUCCESS && match == 0 ) {
506                                                         /* value exists already */
507                                                         snprintf( textbuf, textlen,
508                                                                 "%s: value #%d provided more than once",
509                                                                 mods->sml_desc->ad_cname.bv_val, j );
510                                                         return LDAP_TYPE_OR_VALUE_EXISTS;
511
512                                                 } else if ( rc != LDAP_SUCCESS ) {
513                                                         return rc;
514                                                 }
515                                         }
516                                 }
517                         }
518                 }
519
520                 attr = ch_calloc( 1, sizeof(Attribute) );
521
522                 /* move ad to attr structure */
523                 attr->a_desc = mods->sml_desc;
524                 if ( !dup ) mods->sml_desc = NULL;
525
526                 /* move values to attr structure */
527                 /*      should check for duplicates */
528                 if ( dup ) { 
529                         int i;
530                         for ( i = 0; mods->sml_values[i].bv_val; i++ ) /* EMPTY */;
531                         attr->a_vals = (BerVarray) ch_calloc( i+1, sizeof( BerValue ));
532                         for ( i = 0; mods->sml_values[i].bv_val; i++ ) {
533                                 ber_dupbv( &attr->a_vals[i], &mods->sml_values[i] );
534                         }
535                         BER_BVZERO( &attr->a_vals[i] );
536                 } else {
537                         attr->a_vals = mods->sml_values;
538                         mods->sml_values = NULL;
539                 }
540
541                 if ( mods->sml_nvalues ) {
542                         if ( dup ) {
543                                 int i;
544                                 for ( i = 0; mods->sml_nvalues[i].bv_val; i++ ) /* EMPTY */;
545                                 attr->a_nvals = (BerVarray) ch_calloc( i+1, sizeof( BerValue ));
546                                 for ( i = 0; mods->sml_nvalues[i].bv_val; i++ ) {
547                                         ber_dupbv( &attr->a_nvals[i], &mods->sml_nvalues[i] );
548                                 }
549                                 BER_BVZERO( &attr->a_nvals[i] );
550                         } else {
551                                 attr->a_nvals = mods->sml_nvalues;
552                                 mods->sml_nvalues = NULL;
553                         }
554                 } else {
555                         attr->a_nvals = attr->a_vals;
556                 }
557
558                 *tail = attr;
559                 tail = &attr->a_next;
560         }
561
562         return LDAP_SUCCESS;
563 }
564
565 int
566 slap_entry2mods(
567         Entry *e,
568         Modifications **mods,
569         const char **text,
570         char *textbuf, size_t textlen )
571 {
572         Modifications   *modhead = NULL;
573         Modifications   *mod;
574         Modifications   **modtail = &modhead;
575         Attribute               *a_new;
576         AttributeDescription    *a_new_desc;
577         int                             i, count;
578
579         a_new = e->e_attrs;
580
581         while ( a_new != NULL ) {
582                 a_new_desc = a_new->a_desc;
583                 mod = (Modifications *) malloc( sizeof( Modifications ));
584                 
585                 mod->sml_op = LDAP_MOD_REPLACE;
586
587                 mod->sml_type = a_new_desc->ad_cname;
588
589                 for ( count = 0; a_new->a_vals[count].bv_val; count++ ) /* EMPTY */;
590
591                 mod->sml_values = (struct berval*) malloc(
592                         (count+1) * sizeof( struct berval) );
593
594                 /* see slap_mods_check() comments...
595                  * if a_vals == a_nvals, there is no normalizer.
596                  * in this case, mod->sml_nvalues must be left NULL.
597                  */
598                 if ( a_new->a_vals != a_new->a_nvals ) {
599                         mod->sml_nvalues = (struct berval*) malloc(
600                                 (count+1) * sizeof( struct berval) );
601                 } else {
602                         mod->sml_nvalues = NULL;
603                 }
604
605                 for ( i = 0; i < count; i++ ) {
606                         ber_dupbv(mod->sml_values+i, a_new->a_vals+i); 
607                         if ( mod->sml_nvalues ) {
608                                 ber_dupbv( mod->sml_nvalues+i, a_new->a_nvals+i ); 
609                         } 
610                 }
611
612                 mod->sml_values[count].bv_val = NULL; 
613                 mod->sml_values[count].bv_len = 0; 
614
615                 if ( mod->sml_nvalues ) {
616                         mod->sml_nvalues[count].bv_val = NULL; 
617                         mod->sml_nvalues[count].bv_len = 0; 
618                 }
619
620                 mod->sml_desc = a_new_desc;
621                 mod->sml_next =NULL;
622                 *modtail = mod;
623                 modtail = &mod->sml_next;
624                 a_new = a_new->a_next; 
625         }
626
627         *mods = modhead;
628
629         return LDAP_SUCCESS;
630 }
631
632 #ifdef LDAP_SLAPI
633 static void init_add_pblock( Operation *op,
634         struct berval *dn, Entry *e, int manageDSAit )
635 {
636         slapi_int_pblock_set_operation( op->o_pb, op );
637         slapi_pblock_set( op->o_pb, SLAPI_ADD_TARGET, (void *)dn->bv_val );
638         slapi_pblock_set( op->o_pb, SLAPI_ADD_ENTRY, (void *)e );
639         slapi_pblock_set( op->o_pb, SLAPI_MANAGEDSAIT, (void *)manageDSAit );
640 }
641
642 static int call_add_preop_plugins( Operation *op )
643 {
644         int rc;
645
646         rc = slapi_int_call_plugins( op->o_bd, SLAPI_PLUGIN_PRE_ADD_FN, op->o_pb );
647         if ( rc < 0 ) {
648                 /*
649                  * A preoperation plugin failure will abort the
650                  * entire operation.
651                  */
652                 Debug(LDAP_DEBUG_TRACE,
653                         "do_add: add preoperation plugin failed.\n",
654                         0, 0, 0);
655
656                 if (( slapi_pblock_get( op->o_pb, SLAPI_RESULT_CODE,
657                         (void *)&rc ) != 0 ) || rc == LDAP_SUCCESS )
658                 {
659                         rc = LDAP_OTHER;
660                 }
661         } else {
662                 rc = LDAP_SUCCESS;
663         }
664
665         return rc;
666 }
667
668 static void call_add_postop_plugins( Operation *op )
669 {
670         int rc;
671
672         rc = slapi_int_call_plugins( op->o_bd, SLAPI_PLUGIN_POST_ADD_FN, op->o_pb );
673         if ( rc < 0 ) {
674                 Debug(LDAP_DEBUG_TRACE,
675                         "do_add: add postoperation plugin failed\n",
676                         0, 0, 0);
677         }
678 }
679 #endif /* LDAP_SLAPI */