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