]> git.sur5r.net Git - openldap/blob - servers/slapd/add.c
Happy New Year
[openldap] / servers / slapd / add.c
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1998-2018 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 "lutil.h"
34 #include "slap.h"
35
36 int
37 do_add( Operation *op, SlapReply *rs )
38 {
39         BerElement      *ber = op->o_ber;
40         char            *last;
41         struct berval   dn = BER_BVNULL;
42         ber_len_t       len;
43         ber_tag_t       tag;
44         Modifications   *modlist = NULL;
45         Modifications   **modtail = &modlist;
46         Modifications   tmp;
47         char            textbuf[ SLAP_TEXT_BUFLEN ];
48         size_t          textlen = sizeof( textbuf );
49         int             rc = 0;
50         int             freevals = 1;
51         OpExtraDB *oex;
52
53         Debug( LDAP_DEBUG_TRACE, "%s do_add\n",
54                 op->o_log_prefix, 0, 0 );
55
56         /*
57          * Parse the add request.  It looks like this:
58          *
59          *      AddRequest := [APPLICATION 14] SEQUENCE {
60          *              name    DistinguishedName,
61          *              attrs   SEQUENCE OF SEQUENCE {
62          *                      type    AttributeType,
63          *                      values  SET OF AttributeValue
64          *              }
65          *      }
66          */
67
68         /* get the name */
69         if ( ber_scanf( ber, "{m", /*}*/ &dn ) == LBER_ERROR ) {
70                 Debug( LDAP_DEBUG_ANY, "%s do_add: ber_scanf failed\n",
71                         op->o_log_prefix, 0, 0 );
72                 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
73                 return SLAPD_DISCONNECT;
74         }
75
76         Debug( LDAP_DEBUG_ARGS, "%s do_add: dn (%s)\n",
77                 op->o_log_prefix, dn.bv_val, 0 );
78
79         /* get the attrs */
80         for ( tag = ber_first_element( ber, &len, &last ); tag != LBER_DEFAULT;
81             tag = ber_next_element( ber, &len, last ) )
82         {
83                 Modifications *mod;
84                 ber_tag_t rtag;
85
86                 tmp.sml_nvalues = NULL;
87
88                 rtag = ber_scanf( ber, "{m{W}}", &tmp.sml_type, &tmp.sml_values );
89
90                 if ( rtag == LBER_ERROR ) {
91                         Debug( LDAP_DEBUG_ANY, "%s do_add: decoding error\n",
92                                 op->o_log_prefix, 0, 0 );
93                         send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
94                         rs->sr_err = SLAPD_DISCONNECT;
95                         goto done;
96                 }
97
98                 if ( tmp.sml_values == NULL ) {
99                         Debug( LDAP_DEBUG_ANY, "%s do_add: no values for type %s\n",
100                                 op->o_log_prefix, tmp.sml_type.bv_val, 0 );
101                         send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
102                                 "no values for attribute type" );
103                         goto done;
104                 }
105
106                 mod  = (Modifications *) ch_malloc( sizeof(Modifications) );
107                 mod->sml_op = LDAP_MOD_ADD;
108                 mod->sml_flags = 0;
109                 mod->sml_next = NULL;
110                 mod->sml_desc = NULL;
111                 mod->sml_type = tmp.sml_type;
112                 mod->sml_values = tmp.sml_values;
113                 mod->sml_nvalues = NULL;
114
115                 *modtail = mod;
116                 modtail = &mod->sml_next;
117         }
118
119         if ( ber_scanf( ber, /*{*/ "}") == LBER_ERROR ) {
120                 Debug( LDAP_DEBUG_ANY, "%s do_add: ber_scanf failed\n",
121                         op->o_log_prefix, 0, 0 );
122                 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
123                 rs->sr_err = SLAPD_DISCONNECT;
124                 goto done;
125         }
126
127         if ( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
128                 Debug( LDAP_DEBUG_ANY, "%s do_add: get_ctrls failed\n",
129                         op->o_log_prefix, 0, 0 );
130                 goto done;
131         } 
132
133         rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn,
134                 op->o_tmpmemctx );
135
136         if ( rs->sr_err != LDAP_SUCCESS ) {
137                 Debug( LDAP_DEBUG_ANY, "%s do_add: invalid dn (%s)\n",
138                         op->o_log_prefix, dn.bv_val, 0 );
139                 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
140                 goto done;
141         }
142
143         op->ora_e = entry_alloc();
144         ber_dupbv( &op->ora_e->e_name, &op->o_req_dn );
145         ber_dupbv( &op->ora_e->e_nname, &op->o_req_ndn );
146
147         Statslog( LDAP_DEBUG_STATS, "%s ADD dn=\"%s\"\n",
148             op->o_log_prefix, op->o_req_dn.bv_val, 0, 0, 0 );
149
150         if ( modlist == NULL ) {
151                 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
152                         "no attributes provided" );
153                 goto done;
154         }
155
156         if ( dn_match( &op->ora_e->e_nname, &slap_empty_bv ) ) {
157                 /* protocolError may be a more appropriate error */
158                 send_ldap_error( op, rs, LDAP_ALREADY_EXISTS,
159                         "root DSE already exists" );
160                 goto done;
161
162         } else if ( dn_match( &op->ora_e->e_nname, &frontendDB->be_schemandn ) ) {
163                 send_ldap_error( op, rs, LDAP_ALREADY_EXISTS,
164                         "subschema subentry already exists" );
165                 goto done;
166         }
167
168         rs->sr_err = slap_mods_check( op, modlist, &rs->sr_text,
169                 textbuf, textlen, NULL );
170
171         if ( rs->sr_err != LDAP_SUCCESS ) {
172                 send_ldap_result( op, rs );
173                 goto done;
174         }
175
176         /* temporary; remove if not invoking backend function */
177         op->ora_modlist = modlist;
178
179         /* call this so global overlays/SLAPI have access to ora_e */
180         rs->sr_err = slap_mods2entry( op->ora_modlist, &op->ora_e,
181                 1, 0, &rs->sr_text, textbuf, textlen );
182         if ( rs->sr_err != LDAP_SUCCESS ) {
183                 send_ldap_result( op, rs );
184                 goto done;
185         }
186
187         freevals = 0;
188         oex = op->o_tmpalloc( sizeof(OpExtraDB), op->o_tmpmemctx );
189         oex->oe.oe_key = (void *)do_add;
190         oex->oe_db = NULL;
191         LDAP_SLIST_INSERT_HEAD(&op->o_extra, &oex->oe, oe_next);
192
193         op->o_bd = frontendDB;
194         rc = frontendDB->be_add( op, rs );
195
196         if ( rc == SLAPD_ASYNCOP ) {
197                 /* skip cleanup */
198                 return rc;
199         }
200
201         LDAP_SLIST_REMOVE(&op->o_extra, &oex->oe, OpExtra, oe_next);
202 #ifdef LDAP_X_TXN
203         if ( rc == LDAP_X_TXN_SPECIFY_OKAY ) {
204                 /* skip cleanup */
205                 return rc;
206         } else
207 #endif
208         if ( rc == 0 ) {
209                 if ( op->ora_e != NULL && oex->oe_db != NULL ) {
210                         BackendDB       *bd = op->o_bd;
211
212                         op->o_bd = oex->oe_db;
213
214                         be_entry_release_w( op, op->ora_e );
215
216                         op->ora_e = NULL;
217                         op->o_bd = bd;
218                 }
219         }
220         op->o_tmpfree( oex, op->o_tmpmemctx );
221
222 done:;
223         if ( modlist != NULL ) {
224                 /* in case of error, free the values as well */
225                 slap_mods_free( modlist, freevals );
226         }
227
228         if ( op->ora_e != NULL ) {
229                 entry_free( op->ora_e );
230         }
231         op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
232         op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
233
234         return rc;
235 }
236
237 int
238 fe_op_add( Operation *op, SlapReply *rs )
239 {
240         Modifications   **modtail = &op->ora_modlist;
241         int             rc = 0;
242         BackendDB       *op_be, *bd = op->o_bd;
243         char            textbuf[ SLAP_TEXT_BUFLEN ];
244         size_t          textlen = sizeof( textbuf );
245
246         /*
247          * We could be serving multiple database backends.  Select the
248          * appropriate one, or send a referral to our "referral server"
249          * if we don't hold it.
250          */
251         op->o_bd = select_backend( &op->ora_e->e_nname, 1 );
252         if ( op->o_bd == NULL ) {
253                 op->o_bd = bd;
254                 rs->sr_ref = referral_rewrite( default_referral,
255                         NULL, &op->ora_e->e_name, LDAP_SCOPE_DEFAULT );
256                 if ( !rs->sr_ref ) rs->sr_ref = default_referral;
257                 if ( rs->sr_ref ) {
258                         rs->sr_err = LDAP_REFERRAL;
259                         send_ldap_result( op, rs );
260
261                         if ( rs->sr_ref != default_referral ) {
262                                 ber_bvarray_free( rs->sr_ref );
263                         }
264                 } else {
265                         send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
266                                 "no global superior knowledge" );
267                 }
268                 goto done;
269         }
270
271         /* If we've got a glued backend, check the real backend */
272         op_be = op->o_bd;
273         if ( SLAP_GLUE_INSTANCE( op->o_bd )) {
274                 op->o_bd = select_backend( &op->ora_e->e_nname, 0 );
275         }
276
277         /* check restrictions */
278         if( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
279                 send_ldap_result( op, rs );
280                 goto done;
281         }
282
283         /* check for referrals */
284         if( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
285                 goto done;
286         }
287
288         rs->sr_err = slap_mods_obsolete_check( op, op->ora_modlist,
289                 &rs->sr_text, textbuf, textlen );
290
291         if ( rs->sr_err != LDAP_SUCCESS ) {
292                 send_ldap_result( op, rs );
293                 goto done;
294         }
295
296         /*
297          * do the add if 1 && (2 || 3)
298          * 1) there is an add function implemented in this backend;
299          * 2) this backend is master for what it holds;
300          * 3) it's a replica and the dn supplied is the updatedn.
301          */
302         if ( op->o_bd->be_add ) {
303                 /* do the update here */
304                 int repl_user = be_isupdate( op );
305                 if ( !SLAP_SINGLE_SHADOW(op->o_bd) || repl_user ) {
306                         int             update = !BER_BVISEMPTY( &op->o_bd->be_update_ndn );
307
308                         op->o_bd = op_be;
309
310                         if ( !update ) {
311                                 rs->sr_err = slap_mods_no_user_mod_check( op, op->ora_modlist,
312                                         &rs->sr_text, textbuf, textlen );
313
314                                 if ( rs->sr_err != LDAP_SUCCESS ) {
315                                         send_ldap_result( op, rs );
316                                         goto done;
317                                 }
318                         }
319
320                         if ( !repl_user ) {
321                                 /* go to the last mod */
322                                 for ( modtail = &op->ora_modlist;
323                                                 *modtail != NULL;
324                                                 modtail = &(*modtail)->sml_next )
325                                 {
326                                         assert( (*modtail)->sml_op == LDAP_MOD_ADD );
327                                         assert( (*modtail)->sml_desc != NULL );
328                                 }
329
330
331                                 /* check for unmodifiable attributes */
332                                 rs->sr_err = slap_mods_no_repl_user_mod_check( op,
333                                         op->ora_modlist, &rs->sr_text, textbuf, textlen );
334                                 if ( rs->sr_err != LDAP_SUCCESS ) {
335                                         send_ldap_result( op, rs );
336                                         goto done;
337                                 }
338                         }
339
340                         rc = op->o_bd->be_add( op, rs );
341                         if ( rc == LDAP_SUCCESS ) {
342                                 OpExtra *oex;
343                                 /* NOTE: be_entry_release_w() is
344                                  * called by do_add(), so that global
345                                  * overlays on the way back can
346                                  * at least read the entry */
347                                 LDAP_SLIST_FOREACH(oex, &op->o_extra, oe_next) {
348                                         if ( oex->oe_key == (void *)do_add ) {
349                                                 ((OpExtraDB *)oex)->oe_db = op->o_bd;
350                                                 break;
351                                         }
352                                 }
353                         }
354
355                 } else {
356                         BerVarray defref = NULL;
357
358                         defref = op->o_bd->be_update_refs
359                                 ? op->o_bd->be_update_refs : default_referral;
360
361                         if ( defref != NULL ) {
362                                 rs->sr_ref = referral_rewrite( defref,
363                                         NULL, &op->ora_e->e_name, LDAP_SCOPE_DEFAULT );
364                                 if ( rs->sr_ref == NULL ) rs->sr_ref = defref;
365                                 rs->sr_err = LDAP_REFERRAL;
366                                 if (!rs->sr_ref) rs->sr_ref = default_referral;
367                                 send_ldap_result( op, rs );
368
369                                 if ( rs->sr_ref != default_referral ) {
370                                         ber_bvarray_free( rs->sr_ref );
371                                 }
372                         } else {
373                                 send_ldap_error( op, rs,
374                                         LDAP_UNWILLING_TO_PERFORM,
375                                         "shadow context; no update referral" );
376                         }
377                 }
378         } else {
379                 Debug( LDAP_DEBUG_ARGS, "do_add: no backend support\n", 0, 0, 0 );
380                 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
381                         "operation not supported within namingContext" );
382         }
383
384 done:;
385         op->o_bd = bd;
386         return rc;
387 }
388
389 int
390 slap_mods2entry(
391         Modifications *mods,
392         Entry **e,
393         int initial,
394         int dup,
395         const char **text,
396         char *textbuf, size_t textlen )
397 {
398         Attribute **tail;
399         int i;
400
401         if ( initial ) {
402                 assert( (*e)->e_attrs == NULL );
403         }
404
405         for ( tail = &(*e)->e_attrs; *tail != NULL; tail = &(*tail)->a_next )
406                 ;
407
408         *text = textbuf;
409
410         for( ; mods != NULL; mods = mods->sml_next ) {
411                 Attribute *attr;
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                         int j;
421
422                         if ( !initial ) {
423                                 /*      
424                                  * This check allows overlays to override operational
425                                  * attributes by setting them directly in the entry.
426                                  * We assume slap_mods_no_user_mod_check() was called
427                                  * with the user modifications.
428                                  */
429                                 *text = NULL;
430                                 return LDAP_SUCCESS;
431                         }
432
433                         i = attr->a_numvals;
434                         j = mods->sml_numvals;
435                         attr->a_numvals += j;
436                         j++;    /* NULL */
437                         
438                         attr->a_vals = ch_realloc( attr->a_vals,
439                                 sizeof( struct berval ) * (i+j) );
440
441                         /* checked for duplicates in slap_mods_check */
442
443                         if ( dup ) {
444                                 for ( j = 0; mods->sml_values[j].bv_val; j++ ) {
445                                         ber_dupbv( &attr->a_vals[i+j], &mods->sml_values[j] );
446                                 }
447                                 BER_BVZERO( &attr->a_vals[i+j] );
448                                 j++;
449                         } else {
450                                 AC_MEMCPY( &attr->a_vals[i], mods->sml_values,
451                                         sizeof( struct berval ) * j );
452                         }
453
454                         if( mods->sml_nvalues ) {
455                                 attr->a_nvals = ch_realloc( attr->a_nvals,
456                                         sizeof( struct berval ) * (i+j) );
457                                 if ( dup ) {
458                                         for ( j = 0; mods->sml_nvalues[j].bv_val; j++ ) {
459                                                 ber_dupbv( &attr->a_nvals[i+j], &mods->sml_nvalues[j] );
460                                         }
461                                         BER_BVZERO( &attr->a_nvals[i+j] );      
462                                 } else {
463                                         AC_MEMCPY( &attr->a_nvals[i], mods->sml_nvalues,
464                                                 sizeof( struct berval ) * j );
465                                 }
466                         } else {
467                                 attr->a_nvals = attr->a_vals;
468                         }
469
470                         continue;
471 #else
472                         snprintf( textbuf, textlen,
473                                 "attribute '%s' provided more than once",
474                                 mods->sml_desc->ad_cname.bv_val );
475                         *text = textbuf;
476                         return LDAP_TYPE_OR_VALUE_EXISTS;
477 #endif
478                 }
479
480                 attr = attr_alloc( mods->sml_desc );
481
482                 /* move values to attr structure */
483                 i = mods->sml_numvals;
484                 attr->a_numvals = mods->sml_numvals;
485                 if ( dup ) { 
486                         attr->a_vals = (BerVarray) ch_calloc( i+1, sizeof( BerValue ));
487                         for ( i = 0; mods->sml_values[i].bv_val; i++ ) {
488                                 ber_dupbv( &attr->a_vals[i], &mods->sml_values[i] );
489                         }
490                         BER_BVZERO( &attr->a_vals[i] );
491                 } else {
492                         attr->a_vals = mods->sml_values;
493                 }
494
495                 if ( mods->sml_nvalues ) {
496                         if ( dup ) {
497                                 i = mods->sml_numvals;
498                                 attr->a_nvals = (BerVarray) ch_calloc( i+1, sizeof( BerValue ));
499                                 for ( i = 0; mods->sml_nvalues[i].bv_val; i++ ) {
500                                         ber_dupbv( &attr->a_nvals[i], &mods->sml_nvalues[i] );
501                                 }
502                                 BER_BVZERO( &attr->a_nvals[i] );
503                         } else {
504                                 attr->a_nvals = mods->sml_nvalues;
505                         }
506                 } else {
507                         attr->a_nvals = attr->a_vals;
508                 }
509
510                 *tail = attr;
511                 tail = &attr->a_next;
512         }
513
514         *text = NULL;
515
516         return LDAP_SUCCESS;
517 }
518
519 int
520 slap_entry2mods(
521         Entry *e,
522         Modifications **mods,
523         const char **text,
524         char *textbuf, size_t textlen )
525 {
526         Modifications   *modhead = NULL;
527         Modifications   *mod;
528         Modifications   **modtail = &modhead;
529         Attribute               *a_new;
530         AttributeDescription    *a_new_desc;
531         int                             i, count;
532
533         a_new = e->e_attrs;
534
535         while ( a_new != NULL ) {
536                 a_new_desc = a_new->a_desc;
537                 mod = (Modifications *) ch_malloc( sizeof( Modifications ));
538                 
539                 mod->sml_op = LDAP_MOD_REPLACE;
540                 mod->sml_flags = 0;
541
542                 mod->sml_type = a_new_desc->ad_cname;
543
544                 count = a_new->a_numvals;
545                 mod->sml_numvals = a_new->a_numvals;
546
547                 mod->sml_values = (struct berval*) ch_malloc(
548                         (count+1) * sizeof( struct berval) );
549
550                 /* see slap_mods_check() comments...
551                  * if a_vals == a_nvals, there is no normalizer.
552                  * in this case, mod->sml_nvalues must be left NULL.
553                  */
554                 if ( a_new->a_vals != a_new->a_nvals ) {
555                         mod->sml_nvalues = (struct berval*) ch_malloc(
556                                 (count+1) * sizeof( struct berval) );
557                 } else {
558                         mod->sml_nvalues = NULL;
559                 }
560
561                 for ( i = 0; i < count; i++ ) {
562                         ber_dupbv(mod->sml_values+i, a_new->a_vals+i); 
563                         if ( mod->sml_nvalues ) {
564                                 ber_dupbv( mod->sml_nvalues+i, a_new->a_nvals+i ); 
565                         } 
566                 }
567
568                 mod->sml_values[count].bv_val = NULL; 
569                 mod->sml_values[count].bv_len = 0; 
570
571                 if ( mod->sml_nvalues ) {
572                         mod->sml_nvalues[count].bv_val = NULL; 
573                         mod->sml_nvalues[count].bv_len = 0; 
574                 }
575
576                 mod->sml_desc = a_new_desc;
577                 mod->sml_next =NULL;
578                 *modtail = mod;
579                 modtail = &mod->sml_next;
580                 a_new = a_new->a_next; 
581         }
582
583         *mods = modhead;
584
585         return LDAP_SUCCESS;
586 }
587
588 int slap_add_opattrs(
589         Operation *op,
590         const char **text,
591         char *textbuf,
592         size_t textlen,
593         int manage_ctxcsn )
594 {
595         struct berval name, timestamp, csn = BER_BVNULL;
596         struct berval nname, tmp;
597         char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
598         char csnbuf[ LDAP_PVT_CSNSTR_BUFSIZE ];
599         Attribute *a;
600
601         if ( SLAP_LASTMOD( op->o_bd ) ) {
602                 char *ptr;
603                 int gotcsn = 0;
604
605                 timestamp.bv_val = timebuf;
606                 a = attr_find( op->ora_e->e_attrs, slap_schema.si_ad_entryCSN );
607                 if ( a ) {
608                         gotcsn = 1;
609                         csn = a->a_vals[0];
610                 }
611                 if ( BER_BVISEMPTY( &op->o_csn )) {
612                         if ( !gotcsn ) {
613                                 csn.bv_val = csnbuf;
614                                 csn.bv_len = sizeof(csnbuf);
615                                 slap_get_csn( op, &csn, manage_ctxcsn );
616                         } else {
617                                 if ( manage_ctxcsn )
618                                         slap_queue_csn( op, &csn );
619                         }
620                 } else {
621                         csn = op->o_csn;
622                 }
623                 ptr = ber_bvchr( &csn, '#' );
624                 if ( ptr ) {
625                         timestamp.bv_len = STRLENOF("YYYYMMDDHHMMSSZ");
626                         AC_MEMCPY( timebuf, csn.bv_val, timestamp.bv_len );
627                         timebuf[timestamp.bv_len-1] = 'Z';
628                         timebuf[timestamp.bv_len] = '\0';
629                 } else {
630                         time_t now = slap_get_time();
631
632                         timestamp.bv_len = sizeof(timebuf);
633
634                         slap_timestamp( &now, &timestamp );
635                 }
636
637                 if ( BER_BVISEMPTY( &op->o_dn ) ) {
638                         BER_BVSTR( &name, SLAPD_ANONYMOUS );
639                         nname = name;
640                 } else {
641                         name = op->o_dn;
642                         nname = op->o_ndn;
643                 }
644
645                 a = attr_find( op->ora_e->e_attrs,
646                         slap_schema.si_ad_entryUUID );
647                 if ( !a ) {
648                         char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
649
650                         tmp.bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ) );
651                         tmp.bv_val = uuidbuf;
652                         
653                         attr_merge_normalize_one( op->ora_e,
654                                 slap_schema.si_ad_entryUUID, &tmp, op->o_tmpmemctx );
655                 }
656
657                 a = attr_find( op->ora_e->e_attrs,
658                         slap_schema.si_ad_creatorsName );
659                 if ( !a ) {
660                         attr_merge_one( op->ora_e,
661                                 slap_schema.si_ad_creatorsName, &name, &nname );
662                 }
663
664                 a = attr_find( op->ora_e->e_attrs,
665                         slap_schema.si_ad_createTimestamp );
666                 if ( !a ) {
667                         attr_merge_one( op->ora_e,
668                                 slap_schema.si_ad_createTimestamp, &timestamp, NULL );
669                 }
670
671                 if ( !gotcsn ) {
672                         attr_merge_one( op->ora_e,
673                                 slap_schema.si_ad_entryCSN, &csn, NULL );
674                 }
675
676                 a = attr_find( op->ora_e->e_attrs,
677                         slap_schema.si_ad_modifiersName );
678                 if ( !a ) {
679                         attr_merge_one( op->ora_e,
680                                 slap_schema.si_ad_modifiersName, &name, &nname );
681                 }
682
683                 a = attr_find( op->ora_e->e_attrs,
684                         slap_schema.si_ad_modifyTimestamp );
685                 if ( !a ) {
686                         attr_merge_one( op->ora_e,
687                                 slap_schema.si_ad_modifyTimestamp, &timestamp, NULL );
688                 }
689         }
690
691         return LDAP_SUCCESS;
692 }