1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1998-2021 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
do_add(Operation * op,SlapReply * rs)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 );
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 );
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 );
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 );
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 );
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 );
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 );
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 );
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 	Debug( LDAP_DEBUG_STATS, "%s ADD dn=\"%s\"\n",
148 	    op->o_log_prefix, op->o_req_dn.bv_val );
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 	if ( rc == LDAP_TXN_SPECIFY_OKAY ) {
203 		/* skip cleanup */
204 		return rc;
205 	} else if ( rc == 0 ) {
206 		if ( op->ora_e != NULL && oex->oe_db != NULL ) {
207 			BackendDB	*bd = op->o_bd;
208 
209 			op->o_bd = oex->oe_db;
210 
211 			be_entry_release_w( op, op->ora_e );
212 
213 			op->ora_e = NULL;
214 			op->o_bd = bd;
215 		}
216 	}
217 	op->o_tmpfree( oex, op->o_tmpmemctx );
218 
219 done:;
220 	if ( modlist != NULL ) {
221 		/* in case of error, free the values as well */
222 		slap_mods_free( modlist, freevals );
223 	}
224 
225 	if ( op->ora_e != NULL ) {
226 		entry_free( op->ora_e );
227 	}
228 	op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
229 	op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
230 
231 	return rc;
232 }
233 
234 int
fe_op_add(Operation * op,SlapReply * rs)235 fe_op_add( Operation *op, SlapReply *rs )
236 {
237 	Modifications	**modtail = &op->ora_modlist;
238 	int		rc = 0;
239 	BackendDB	*op_be, *bd = op->o_bd;
240 	char		textbuf[ SLAP_TEXT_BUFLEN ];
241 	size_t		textlen = sizeof( textbuf );
242 
243 	/*
244 	 * We could be serving multiple database backends.  Select the
245 	 * appropriate one, or send a referral to our "referral server"
246 	 * if we don't hold it.
247 	 */
248 	op->o_bd = select_backend( &op->ora_e->e_nname, 1 );
249 	if ( op->o_bd == NULL ) {
250 		op->o_bd = bd;
251 		rs->sr_ref = referral_rewrite( default_referral,
252 			NULL, &op->ora_e->e_name, LDAP_SCOPE_DEFAULT );
253 		if ( !rs->sr_ref ) rs->sr_ref = default_referral;
254 		if ( rs->sr_ref ) {
255 			rs->sr_err = LDAP_REFERRAL;
256 			send_ldap_result( op, rs );
257 
258 			if ( rs->sr_ref != default_referral ) {
259 				ber_bvarray_free( rs->sr_ref );
260 			}
261 		} else {
262 			send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
263 				"no global superior knowledge" );
264 		}
265 		goto done;
266 	}
267 
268 	/* If we've got a glued backend, check the real backend */
269 	op_be = op->o_bd;
270 	if ( SLAP_GLUE_INSTANCE( op->o_bd )) {
271 		op->o_bd = select_backend( &op->ora_e->e_nname, 0 );
272 	}
273 
274 	/* check restrictions */
275 	if( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
276 		send_ldap_result( op, rs );
277 		goto done;
278 	}
279 
280 	/* check for referrals */
281 	if( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
282 		goto done;
283 	}
284 
285 	rs->sr_err = slap_mods_obsolete_check( op, op->ora_modlist,
286 		&rs->sr_text, textbuf, textlen );
287 
288 	if ( rs->sr_err != LDAP_SUCCESS ) {
289 		send_ldap_result( op, rs );
290 		goto done;
291 	}
292 
293 	/*
294 	 * do the add if 1 && (2 || 3)
295 	 * 1) there is an add function implemented in this backend;
296 	 * 2) this backend is the provider for what it holds;
297 	 * 3) it's a replica and the dn supplied is the updatedn.
298 	 */
299 	if ( op->o_bd->be_add ) {
300 		/* do the update here */
301 		int repl_user = be_isupdate( op );
302 		if ( !SLAP_SINGLE_SHADOW(op->o_bd) || repl_user ) {
303 			int		update = !BER_BVISEMPTY( &op->o_bd->be_update_ndn );
304 
305 			if ( !update ) {
306 				rs->sr_err = slap_mods_no_user_mod_check( op, op->ora_modlist,
307 					&rs->sr_text, textbuf, textlen );
308 
309 				if ( rs->sr_err != LDAP_SUCCESS ) {
310 					send_ldap_result( op, rs );
311 					goto done;
312 				}
313 			}
314 
315 			if ( !repl_user ) {
316 				/* go to the last mod */
317 				for ( modtail = &op->ora_modlist;
318 						*modtail != NULL;
319 						modtail = &(*modtail)->sml_next )
320 				{
321 					assert( (*modtail)->sml_op == LDAP_MOD_ADD );
322 					assert( (*modtail)->sml_desc != NULL );
323 				}
324 
325 
326 				/* check for unmodifiable attributes */
327 				rs->sr_err = slap_mods_no_repl_user_mod_check( op,
328 					op->ora_modlist, &rs->sr_text, textbuf, textlen );
329 				if ( rs->sr_err != LDAP_SUCCESS ) {
330 					send_ldap_result( op, rs );
331 					goto done;
332 				}
333 			}
334 
335 			if ( op->o_txnSpec ) {
336 				rc = txn_preop( op, rs );
337 				goto done;
338 			}
339 
340 			op->o_bd = op_be;
341 			rc = op->o_bd->be_add( op, rs );
342 			if ( rc == LDAP_SUCCESS ) {
343 				OpExtra *oex;
344 				/* NOTE: be_entry_release_w() is
345 				 * called by do_add(), so that global
346 				 * overlays on the way back can
347 				 * at least read the entry */
348 				LDAP_SLIST_FOREACH(oex, &op->o_extra, oe_next) {
349 					if ( oex->oe_key == (void *)do_add ) {
350 						((OpExtraDB *)oex)->oe_db = op->o_bd;
351 						break;
352 					}
353 				}
354 			}
355 
356 		} else {
357 			BerVarray defref = NULL;
358 
359 			defref = op->o_bd->be_update_refs
360 				? op->o_bd->be_update_refs : default_referral;
361 
362 			if ( defref != NULL ) {
363 				rs->sr_ref = referral_rewrite( defref,
364 					NULL, &op->ora_e->e_name, LDAP_SCOPE_DEFAULT );
365 				if ( rs->sr_ref == NULL ) rs->sr_ref = defref;
366 				rs->sr_err = LDAP_REFERRAL;
367 				if (!rs->sr_ref) rs->sr_ref = default_referral;
368 				send_ldap_result( op, rs );
369 
370 				if ( rs->sr_ref != default_referral ) {
371 					ber_bvarray_free( rs->sr_ref );
372 				}
373 			} else {
374 				send_ldap_error( op, rs,
375 					LDAP_UNWILLING_TO_PERFORM,
376 					"shadow context; no update referral" );
377 			}
378 		}
379 	} else {
380 		Debug( LDAP_DEBUG_ARGS, "do_add: no backend support\n" );
381 		send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
382 			"operation not supported within namingContext" );
383 	}
384 
385 done:;
386 	op->o_bd = bd;
387 	return rc;
388 }
389 
390 int
slap_mods2entry(Modifications * mods,Entry ** e,int initial,int dup,const char ** text,char * textbuf,size_t textlen)391 slap_mods2entry(
392 	Modifications *mods,
393 	Entry **e,
394 	int initial,
395 	int dup,
396 	const char **text,
397 	char *textbuf, size_t textlen )
398 {
399 	Attribute **tail;
400 	int i;
401 
402 	if ( initial ) {
403 		assert( (*e)->e_attrs == NULL );
404 	}
405 
406 	for ( tail = &(*e)->e_attrs; *tail != NULL; tail = &(*tail)->a_next )
407 		;
408 
409 	*text = textbuf;
410 
411 	for( ; mods != NULL; mods = mods->sml_next ) {
412 		Attribute *attr;
413 
414 		assert( mods->sml_desc != NULL );
415 
416 		attr = attr_find( (*e)->e_attrs, mods->sml_desc );
417 
418 		if( attr != NULL ) {
419 #define SLURPD_FRIENDLY
420 #ifdef SLURPD_FRIENDLY
421 			int j;
422 
423 			if ( !initial ) {
424 				/*
425 				 * This check allows overlays to override operational
426 				 * attributes by setting them directly in the entry.
427 				 * We assume slap_mods_no_user_mod_check() was called
428 				 * with the user modifications.
429 				 */
430 				*text = NULL;
431 				return LDAP_SUCCESS;
432 			}
433 
434 			i = attr->a_numvals;
435 			j = mods->sml_numvals;
436 			attr->a_numvals += j;
437 			j++;	/* NULL */
438 
439 			attr->a_vals = ch_realloc( attr->a_vals,
440 				sizeof( struct berval ) * (i+j) );
441 
442 			/* checked for duplicates in slap_mods_check */
443 
444 			if ( dup ) {
445 				for ( j = 0; mods->sml_values[j].bv_val; j++ ) {
446 					ber_dupbv( &attr->a_vals[i+j], &mods->sml_values[j] );
447 				}
448 				BER_BVZERO( &attr->a_vals[i+j] );
449 				j++;
450 			} else {
451 				AC_MEMCPY( &attr->a_vals[i], mods->sml_values,
452 					sizeof( struct berval ) * j );
453 			}
454 
455 			if( mods->sml_nvalues ) {
456 				attr->a_nvals = ch_realloc( attr->a_nvals,
457 					sizeof( struct berval ) * (i+j) );
458 				if ( dup ) {
459 					for ( j = 0; mods->sml_nvalues[j].bv_val; j++ ) {
460 						ber_dupbv( &attr->a_nvals[i+j], &mods->sml_nvalues[j] );
461 					}
462 					BER_BVZERO( &attr->a_nvals[i+j] );
463 				} else {
464 					AC_MEMCPY( &attr->a_nvals[i], mods->sml_nvalues,
465 						sizeof( struct berval ) * j );
466 				}
467 			} else {
468 				attr->a_nvals = attr->a_vals;
469 			}
470 
471 			continue;
472 #else
473 			snprintf( textbuf, textlen,
474 				"attribute '%s' provided more than once",
475 				mods->sml_desc->ad_cname.bv_val );
476 			*text = textbuf;
477 			return LDAP_TYPE_OR_VALUE_EXISTS;
478 #endif
479 		}
480 
481 		attr = attr_alloc( mods->sml_desc );
482 
483 		/* move values to attr structure */
484 		i = mods->sml_numvals;
485 		attr->a_numvals = mods->sml_numvals;
486 		if ( dup ) {
487 			attr->a_vals = (BerVarray) ch_calloc( i+1, sizeof( BerValue ));
488 			for ( i = 0; mods->sml_values[i].bv_val; i++ ) {
489 				ber_dupbv( &attr->a_vals[i], &mods->sml_values[i] );
490 			}
491 			BER_BVZERO( &attr->a_vals[i] );
492 		} else {
493 			attr->a_vals = mods->sml_values;
494 		}
495 
496 		if ( mods->sml_nvalues ) {
497 			if ( dup ) {
498 				i = mods->sml_numvals;
499 				attr->a_nvals = (BerVarray) ch_calloc( i+1, sizeof( BerValue ));
500 				for ( i = 0; mods->sml_nvalues[i].bv_val; i++ ) {
501 					ber_dupbv( &attr->a_nvals[i], &mods->sml_nvalues[i] );
502 				}
503 				BER_BVZERO( &attr->a_nvals[i] );
504 			} else {
505 				attr->a_nvals = mods->sml_nvalues;
506 			}
507 		} else {
508 			attr->a_nvals = attr->a_vals;
509 		}
510 
511 		*tail = attr;
512 		tail = &attr->a_next;
513 	}
514 
515 	*text = NULL;
516 
517 	return LDAP_SUCCESS;
518 }
519 
520 int
slap_entry2mods(Entry * e,Modifications ** mods,const char ** text,char * textbuf,size_t textlen)521 slap_entry2mods(
522 	Entry *e,
523 	Modifications **mods,
524 	const char **text,
525 	char *textbuf, size_t textlen )
526 {
527 	Modifications	*modhead = NULL;
528 	Modifications	*mod;
529 	Modifications	**modtail = &modhead;
530 	Attribute		*a_new;
531 	AttributeDescription	*a_new_desc;
532 	int				i, count;
533 
534 	a_new = e->e_attrs;
535 
536 	while ( a_new != NULL ) {
537 		a_new_desc = a_new->a_desc;
538 		mod = (Modifications *) ch_malloc( sizeof( Modifications ));
539 
540 		mod->sml_op = LDAP_MOD_REPLACE;
541 		mod->sml_flags = 0;
542 
543 		mod->sml_type = a_new_desc->ad_cname;
544 
545 		count = a_new->a_numvals;
546 		mod->sml_numvals = a_new->a_numvals;
547 
548 		mod->sml_values = (struct berval*) ch_malloc(
549 			(count+1) * sizeof( struct berval) );
550 
551 		/* see slap_mods_check() comments...
552 		 * if a_vals == a_nvals, there is no normalizer.
553 		 * in this case, mod->sml_nvalues must be left NULL.
554 		 */
555 		if ( a_new->a_vals != a_new->a_nvals ) {
556 			mod->sml_nvalues = (struct berval*) ch_malloc(
557 				(count+1) * sizeof( struct berval) );
558 		} else {
559 			mod->sml_nvalues = NULL;
560 		}
561 
562 		for ( i = 0; i < count; i++ ) {
563 			ber_dupbv(mod->sml_values+i, a_new->a_vals+i);
564 			if ( mod->sml_nvalues ) {
565 				ber_dupbv( mod->sml_nvalues+i, a_new->a_nvals+i );
566 			}
567 		}
568 
569 		mod->sml_values[count].bv_val = NULL;
570 		mod->sml_values[count].bv_len = 0;
571 
572 		if ( mod->sml_nvalues ) {
573 			mod->sml_nvalues[count].bv_val = NULL;
574 			mod->sml_nvalues[count].bv_len = 0;
575 		}
576 
577 		mod->sml_desc = a_new_desc;
578 		mod->sml_next =NULL;
579 		*modtail = mod;
580 		modtail = &mod->sml_next;
581 		a_new = a_new->a_next;
582 	}
583 
584 	*mods = modhead;
585 
586 	return LDAP_SUCCESS;
587 }
588 
slap_add_opattrs(Operation * op,const char ** text,char * textbuf,size_t textlen,int manage_ctxcsn)589 int slap_add_opattrs(
590 	Operation *op,
591 	const char **text,
592 	char *textbuf,
593 	size_t textlen,
594 	int manage_ctxcsn )
595 {
596 	struct berval name, timestamp, csn = BER_BVNULL;
597 	struct berval nname, tmp;
598 	char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
599 	char csnbuf[ LDAP_PVT_CSNSTR_BUFSIZE ];
600 	Attribute *a;
601 
602 	if ( SLAP_LASTMOD( op->o_bd ) ) {
603 		char *ptr;
604 		int gotcsn = 0;
605 
606 		timestamp.bv_val = timebuf;
607 		a = attr_find( op->ora_e->e_attrs, slap_schema.si_ad_entryCSN );
608 		if ( a ) {
609 			gotcsn = 1;
610 			csn = a->a_vals[0];
611 		}
612 		if ( BER_BVISEMPTY( &op->o_csn )) {
613 			if ( !gotcsn ) {
614 				csn.bv_val = csnbuf;
615 				csn.bv_len = sizeof(csnbuf);
616 				slap_get_csn( op, &csn, manage_ctxcsn );
617 			} else {
618 				if ( manage_ctxcsn )
619 					slap_queue_csn( op, &csn );
620 			}
621 		} else {
622 			csn = op->o_csn;
623 		}
624 		ptr = ber_bvchr( &csn, '#' );
625 		if ( ptr ) {
626 			timestamp.bv_len = STRLENOF("YYYYMMDDHHMMSSZ");
627 			AC_MEMCPY( timebuf, csn.bv_val, timestamp.bv_len );
628 			timebuf[timestamp.bv_len-1] = 'Z';
629 			timebuf[timestamp.bv_len] = '\0';
630 		} else {
631 			time_t now = slap_get_time();
632 
633 			timestamp.bv_len = sizeof(timebuf);
634 
635 			slap_timestamp( &now, &timestamp );
636 		}
637 
638 		if ( BER_BVISEMPTY( &op->o_dn ) ) {
639 			BER_BVSTR( &name, SLAPD_ANONYMOUS );
640 			nname = name;
641 		} else {
642 			name = op->o_dn;
643 			nname = op->o_ndn;
644 		}
645 
646 		a = attr_find( op->ora_e->e_attrs,
647 			slap_schema.si_ad_entryUUID );
648 		if ( !a ) {
649 			char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
650 
651 			tmp.bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ) );
652 			tmp.bv_val = uuidbuf;
653 
654 			attr_merge_normalize_one( op->ora_e,
655 				slap_schema.si_ad_entryUUID, &tmp, op->o_tmpmemctx );
656 		}
657 
658 		a = attr_find( op->ora_e->e_attrs,
659 			slap_schema.si_ad_creatorsName );
660 		if ( !a ) {
661 			attr_merge_one( op->ora_e,
662 				slap_schema.si_ad_creatorsName, &name, &nname );
663 		}
664 
665 		a = attr_find( op->ora_e->e_attrs,
666 			slap_schema.si_ad_createTimestamp );
667 		if ( !a ) {
668 			attr_merge_one( op->ora_e,
669 				slap_schema.si_ad_createTimestamp, &timestamp, NULL );
670 		}
671 
672 		if ( !gotcsn ) {
673 			attr_merge_one( op->ora_e,
674 				slap_schema.si_ad_entryCSN, &csn, NULL );
675 		}
676 
677 		a = attr_find( op->ora_e->e_attrs,
678 			slap_schema.si_ad_modifiersName );
679 		if ( !a ) {
680 			attr_merge_one( op->ora_e,
681 				slap_schema.si_ad_modifiersName, &name, &nname );
682 		}
683 
684 		a = attr_find( op->ora_e->e_attrs,
685 			slap_schema.si_ad_modifyTimestamp );
686 		if ( !a ) {
687 			attr_merge_one( op->ora_e,
688 				slap_schema.si_ad_modifyTimestamp, &timestamp, NULL );
689 		}
690 	}
691 
692 	return LDAP_SUCCESS;
693 }
694