2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2005 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
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>.
15 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
16 * All rights reserved.
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.
30 #include <ac/socket.h>
31 #include <ac/string.h>
43 struct berval dn = BER_BVNULL;
47 Modifications *modlist = NULL;
48 Modifications **modtail = &modlist;
50 char textbuf[ SLAP_TEXT_BUFLEN ];
51 size_t textlen = sizeof( textbuf );
53 Debug( LDAP_DEBUG_TRACE, "do_modify\n", 0, 0, 0 );
56 * Parse the modify request. It looks like this:
58 * ModifyRequest := [APPLICATION 6] SEQUENCE {
59 * name DistinguishedName,
60 * mods SEQUENCE OF SEQUENCE {
61 * operation ENUMERATED {
66 * modification SEQUENCE {
68 * values SET OF AttributeValue
74 if ( ber_scanf( op->o_ber, "{m" /*}*/, &dn ) == LBER_ERROR ) {
75 Debug( LDAP_DEBUG_ANY, "do_modify: ber_scanf failed\n", 0, 0, 0 );
77 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
78 return SLAPD_DISCONNECT;
81 Debug( LDAP_DEBUG_ARGS, "do_modify: dn (%s)\n", dn.bv_val, 0, 0 );
83 /* collect modifications & save for later */
84 for ( tag = ber_first_element( op->o_ber, &len, &last );
86 tag = ber_next_element( op->o_ber, &len, last ) )
89 Modifications tmp, *mod;
91 tmp.sml_nvalues = NULL;
93 if ( ber_scanf( op->o_ber, "{e{m[W]}}", &mop,
94 &tmp.sml_type, &tmp.sml_values ) == LBER_ERROR )
96 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR,
97 "decoding modlist error" );
98 rs->sr_err = SLAPD_DISCONNECT;
102 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
105 mod->sml_type = tmp.sml_type;
106 mod->sml_values = tmp.sml_values;
107 mod->sml_nvalues = NULL;
108 mod->sml_desc = NULL;
109 mod->sml_next = NULL;
114 if ( mod->sml_values == NULL ) {
115 Debug( LDAP_DEBUG_ANY,
116 "do_modify: modify/add operation (%ld) requires values\n",
119 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
120 "modify/add operation requires values" );
126 case LDAP_MOD_DELETE:
127 case LDAP_MOD_REPLACE:
130 case LDAP_MOD_INCREMENT:
131 if( op->o_protocol >= LDAP_VERSION3 ) {
133 if ( mod->sml_values == NULL ) {
134 Debug( LDAP_DEBUG_ANY, "do_modify: "
135 "modify/increment operation (%ld) requires value\n",
138 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
139 "modify/increment operation requires value" );
143 if ( !BER_BVISNULL( &mod->sml_values[ 1 ] ) ) {
144 Debug( LDAP_DEBUG_ANY, "do_modify: modify/increment "
145 "operation (%ld) requires single value\n",
148 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
149 "modify/increment operation requires single value" );
158 Debug( LDAP_DEBUG_ANY,
159 "do_modify: unrecognized modify operation (%ld)\n",
162 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
163 "unrecognized modify operation" );
168 modtail = &mod->sml_next;
172 if ( modlist == NULL ) {
173 Debug( LDAP_DEBUG_ANY, "do_modify: no modifications\n", 0, 0, 0 );
174 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
175 "change sequence empty" );
180 if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
181 Debug( LDAP_DEBUG_ANY, "do_modify: get_ctrls failed\n", 0, 0, 0 );
186 rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn,
188 if( rs->sr_err != LDAP_SUCCESS ) {
189 Debug( LDAP_DEBUG_ANY,
190 "do_modify: invalid dn (%s)\n", dn.bv_val, 0, 0 );
191 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
195 rs->sr_err = slap_mods_check( modlist,
196 &rs->sr_text, textbuf, textlen, NULL );
198 if ( rs->sr_err != LDAP_SUCCESS ) {
199 send_ldap_result( op, rs );
203 /* FIXME: needs review */
204 op->orm_modlist = modlist;
205 op->orm_increment = increment;
207 op->o_bd = frontendDB;
208 rs->sr_err = frontendDB->be_modify( op, rs );
211 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
212 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
213 if ( op->orm_modlist != NULL ) slap_mods_free( op->orm_modlist, 1 );
219 fe_op_modify( Operation *op, SlapReply *rs )
225 Modifications *modlist = op->orm_modlist;
226 int increment = op->orm_increment;
228 char textbuf[ SLAP_TEXT_BUFLEN ];
229 size_t textlen = sizeof( textbuf );
231 if( BER_BVISEMPTY( &op->o_req_ndn ) ) {
232 Debug( LDAP_DEBUG_ANY, "do_modify: root dse!\n", 0, 0, 0 );
234 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
235 "modify upon the root DSE not supported" );
238 } else if ( bvmatch( &op->o_req_ndn, &frontendDB->be_schemandn ) ) {
239 Debug( LDAP_DEBUG_ANY, "do_modify: subschema subentry!\n", 0, 0, 0 );
241 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
242 "modification of subschema subentry not supported" );
247 Debug( LDAP_DEBUG_ARGS, "modifications:\n", 0, 0, 0 );
249 for ( tmp = modlist; tmp != NULL; tmp = tmp->sml_next ) {
250 Debug( LDAP_DEBUG_ARGS, "\t%s: %s\n",
251 tmp->sml_op == LDAP_MOD_ADD ? "add" :
252 (tmp->sml_op == LDAP_MOD_INCREMENT ? "increment" :
253 (tmp->sml_op == LDAP_MOD_DELETE ? "delete" :
254 "replace")), tmp->sml_type.bv_val, 0 );
256 if ( tmp->sml_values == NULL ) {
257 Debug( LDAP_DEBUG_ARGS, "%s\n",
258 "\t\tno values", NULL, NULL );
259 } else if ( BER_BVISNULL( &tmp->sml_values[ 0 ] ) ) {
260 Debug( LDAP_DEBUG_ARGS, "%s\n",
261 "\t\tzero values", NULL, NULL );
262 } else if ( BER_BVISNULL( &tmp->sml_values[ 1 ] ) ) {
263 Debug( LDAP_DEBUG_ARGS, "%s, length %ld\n",
264 "\t\tone value", (long) tmp->sml_values[0].bv_len, NULL );
266 Debug( LDAP_DEBUG_ARGS, "%s\n",
267 "\t\tmultiple values", NULL, NULL );
271 if ( StatslogTest( LDAP_DEBUG_STATS ) ) {
272 char abuf[BUFSIZ/2], *ptr = abuf;
275 Statslog( LDAP_DEBUG_STATS, "%s MOD dn=\"%s\"\n",
276 op->o_log_prefix, op->o_req_dn.bv_val, 0, 0, 0 );
278 for ( tmp = modlist; tmp != NULL; tmp = tmp->sml_next ) {
279 if (len + 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
280 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
281 op->o_log_prefix, abuf, 0, 0, 0 );
286 if( 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
287 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
288 op->o_log_prefix, tmp->sml_type.bv_val, 0, 0, 0 );
296 ptr = lutil_strcopy(ptr, tmp->sml_type.bv_val);
297 len += tmp->sml_type.bv_len;
300 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
301 op->o_log_prefix, abuf, 0, 0, 0 );
304 #endif /* LDAP_DEBUG */
306 manageDSAit = get_manageDSAit( op );
309 * We could be serving multiple database backends. Select the
310 * appropriate one, or send a referral to our "referral server"
311 * if we don't hold it.
313 op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 1 );
314 if ( op->o_bd == NULL ) {
315 rs->sr_ref = referral_rewrite( default_referral,
316 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
317 if (!rs->sr_ref) rs->sr_ref = default_referral;
319 if (rs->sr_ref != NULL ) {
320 rs->sr_err = LDAP_REFERRAL;
321 op->o_bd = frontendDB;
322 send_ldap_result( op, rs );
325 if (rs->sr_ref != default_referral) ber_bvarray_free( rs->sr_ref );
327 op->o_bd = frontendDB;
328 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
329 "no global superior knowledge" );
335 /* If we've got a glued backend, check the real backend */
337 if ( SLAP_GLUE_INSTANCE( op->o_bd )) {
338 op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 0 );
341 /* check restrictions */
342 if( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
343 send_ldap_result( op, rs );
347 /* check for referrals */
348 if( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
352 rs->sr_err = slap_mods_obsolete_check( op, modlist,
353 &rs->sr_text, textbuf, textlen );
354 if ( rs->sr_err != LDAP_SUCCESS ) {
355 send_ldap_result( op, rs );
359 /* check for modify/increment support */
360 if( increment && !SLAP_INCREMENT( op->o_bd ) ) {
361 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
362 "modify/increment not supported in context" );
366 * do the modify if 1 && (2 || 3)
367 * 1) there is a modify function implemented in this backend;
368 * 2) this backend is master for what it holds;
369 * 3) it's a replica and the dn supplied is the update_ndn.
371 if ( op->o_bd->be_modify ) {
372 /* do the update here */
373 int repl_user = be_isupdate( op );
375 /* Multimaster slapd does not have to check for replicator dn
376 * because it accepts each modify request
378 #ifndef SLAPD_MULTIMASTER
379 if ( !SLAP_SHADOW(op->o_bd) || repl_user )
382 int update = !BER_BVISEMPTY( &op->o_bd->be_update_ndn );
383 slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
388 rs->sr_err = slap_mods_no_user_mod_check( op, modlist,
389 &rs->sr_text, textbuf, textlen );
390 if ( rs->sr_err != LDAP_SUCCESS ) {
391 send_ldap_result( op, rs );
396 op->orm_modlist = modlist;
397 #ifdef SLAPD_MULTIMASTER
401 /* but multimaster slapd logs only the ones
402 * not from a replicator user */
403 cb.sc_next = op->o_callback;
404 op->o_callback = &cb;
406 op->o_bd->be_modify( op, rs );
408 #ifndef SLAPD_MULTIMASTER
409 /* send a referral */
411 BerVarray defref = op->o_bd->be_update_refs
412 ? op->o_bd->be_update_refs : default_referral;
413 if ( defref != NULL ) {
414 rs->sr_ref = referral_rewrite( defref,
416 LDAP_SCOPE_DEFAULT );
417 if ( rs->sr_ref == NULL ) {
418 /* FIXME: must duplicate, because
419 * overlays may muck with it */
422 rs->sr_err = LDAP_REFERRAL;
423 send_ldap_result( op, rs );
424 if ( rs->sr_ref != defref ) {
425 ber_bvarray_free( rs->sr_ref );
429 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
430 "shadow context; no update referral" );
435 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
436 "operation not supported within namingContext" );
444 * Obsolete constraint checking.
447 slap_mods_obsolete_check(
454 if( get_manageDIT( op ) ) return LDAP_SUCCESS;
456 for ( ; ml != NULL; ml = ml->sml_next ) {
457 if ( is_at_obsolete( ml->sml_desc->ad_type ) &&
458 (( ml->sml_op != LDAP_MOD_REPLACE &&
459 ml->sml_op != LDAP_MOD_DELETE ) ||
460 ml->sml_values != NULL ))
463 * attribute is obsolete,
464 * only allow replace/delete with no values
466 snprintf( textbuf, textlen,
467 "%s: attribute is obsolete",
468 ml->sml_type.bv_val );
470 return LDAP_CONSTRAINT_VIOLATION;
478 * No-user-modification constraint checking.
481 slap_mods_no_user_mod_check(
488 for ( ; ml != NULL; ml = ml->sml_next ) {
489 if ( !is_at_no_user_mod( ml->sml_desc->ad_type ) ) continue;
491 if ( get_manageDIT( op ) ) {
492 if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_MANAGEABLE ) {
493 ml->sml_flags |= SLAP_MOD_MANAGING;
497 /* attribute not manageable */
498 snprintf( textbuf, textlen,
499 "%s: no-user-modification attribute not manageable",
500 ml->sml_type.bv_val );
503 /* user modification disallowed */
504 snprintf( textbuf, textlen,
505 "%s: no user modification allowed",
506 ml->sml_type.bv_val );
510 return LDAP_CONSTRAINT_VIOLATION;
517 slap_mods_no_repl_user_mod_check(
527 for ( mods = ml; mods != NULL; mods = mods->sml_next ) {
528 assert( mods->sml_op == LDAP_MOD_ADD );
530 /* check doesn't already appear */
531 for ( modp = ml; modp != NULL; modp = modp->sml_next ) {
532 if ( mods->sml_desc == modp->sml_desc && mods != modp ) {
533 snprintf( textbuf, textlen,
534 "attribute '%s' provided more than once",
535 mods->sml_desc->ad_cname.bv_val );
537 return LDAP_TYPE_OR_VALUE_EXISTS;
546 * Do basic attribute type checking and syntax validation.
557 for( ; ml != NULL; ml = ml->sml_next ) {
558 AttributeDescription *ad = NULL;
560 /* convert to attribute description */
561 if ( ml->sml_desc == NULL ) {
562 rc = slap_bv2ad( &ml->sml_type, &ml->sml_desc, text );
563 if( rc != LDAP_SUCCESS ) {
564 snprintf( textbuf, textlen, "%s: %s",
565 ml->sml_type.bv_val, *text );
573 if( slap_syntax_is_binary( ad->ad_type->sat_syntax )
574 && !slap_ad_is_binary( ad ))
576 /* attribute requires binary transfer */
577 snprintf( textbuf, textlen,
578 "%s: requires ;binary transfer",
579 ml->sml_type.bv_val );
581 return LDAP_UNDEFINED_TYPE;
584 if( !slap_syntax_is_binary( ad->ad_type->sat_syntax )
585 && slap_ad_is_binary( ad ))
587 /* attribute does not require binary transfer */
588 snprintf( textbuf, textlen,
589 "%s: disallows ;binary transfer",
590 ml->sml_type.bv_val );
592 return LDAP_UNDEFINED_TYPE;
595 if( slap_ad_is_tag_range( ad )) {
596 /* attribute requires binary transfer */
597 snprintf( textbuf, textlen,
598 "%s: inappropriate use of tag range option",
599 ml->sml_type.bv_val );
601 return LDAP_UNDEFINED_TYPE;
605 if ( is_at_obsolete( ad->ad_type ) &&
606 (( ml->sml_op != LDAP_MOD_REPLACE &&
607 ml->sml_op != LDAP_MOD_DELETE ) ||
608 ml->sml_values != NULL ))
611 * attribute is obsolete,
612 * only allow replace/delete with no values
614 snprintf( textbuf, textlen,
615 "%s: attribute is obsolete",
616 ml->sml_type.bv_val );
618 return LDAP_CONSTRAINT_VIOLATION;
622 if ( ml->sml_op == LDAP_MOD_INCREMENT &&
623 #ifdef SLAPD_REAL_SYNTAX
624 !is_at_syntax( ad->ad_type, SLAPD_REAL_SYNTAX ) &&
626 !is_at_syntax( ad->ad_type, SLAPD_INTEGER_SYNTAX ) )
629 * attribute values must be INTEGER or REAL
631 snprintf( textbuf, textlen,
632 "%s: attribute syntax inappropriate for increment",
633 ml->sml_type.bv_val );
635 return LDAP_CONSTRAINT_VIOLATION;
641 if( ml->sml_values != NULL ) {
643 slap_syntax_validate_func *validate =
644 ad->ad_type->sat_syntax->ssyn_validate;
645 slap_syntax_transform_func *pretty =
646 ad->ad_type->sat_syntax->ssyn_pretty;
648 if( !pretty && !validate ) {
649 *text = "no validator for syntax";
650 snprintf( textbuf, textlen,
651 "%s: no validator for syntax %s",
653 ad->ad_type->sat_syntax->ssyn_oid );
655 return LDAP_INVALID_SYNTAX;
659 * check that each value is valid per syntax
660 * and pretty if appropriate
662 for ( nvals = 0; !BER_BVISNULL( &ml->sml_values[nvals] ); nvals++ ) {
666 #ifdef SLAP_ORDERED_PRETTYNORM
667 rc = ordered_value_pretty( ad,
668 &ml->sml_values[nvals], &pval, ctx );
669 #else /* ! SLAP_ORDERED_PRETTYNORM */
670 rc = pretty( ad->ad_type->sat_syntax,
671 &ml->sml_values[nvals], &pval, ctx );
672 #endif /* ! SLAP_ORDERED_PRETTYNORM */
674 #ifdef SLAP_ORDERED_PRETTYNORM
675 rc = ordered_value_validate( ad,
676 &ml->sml_values[nvals] );
677 #else /* ! SLAP_ORDERED_PRETTYNORM */
678 rc = validate( ad->ad_type->sat_syntax,
679 &ml->sml_values[nvals] );
680 #endif /* ! SLAP_ORDERED_PRETTYNORM */
684 snprintf( textbuf, textlen,
685 "%s: value #%ld invalid per syntax",
686 ml->sml_type.bv_val, (long) nvals );
688 return LDAP_INVALID_SYNTAX;
692 ber_memfree_x( ml->sml_values[nvals].bv_val, ctx );
693 ml->sml_values[nvals] = pval;
698 * a rough single value check... an additional check is needed
699 * to catch add of single value to existing single valued attribute
701 if ((ml->sml_op == LDAP_MOD_ADD || ml->sml_op == LDAP_MOD_REPLACE)
702 && nvals > 1 && is_at_single_value( ad->ad_type ))
704 snprintf( textbuf, textlen,
705 "%s: multiple values provided",
706 ml->sml_type.bv_val );
708 return LDAP_CONSTRAINT_VIOLATION;
711 /* if the type has a normalizer, generate the
712 * normalized values. otherwise leave them NULL.
714 * this is different from the rule for attributes
715 * in an entry - in an attribute list, the normalized
716 * value is set equal to the non-normalized value
717 * when there is no normalizer.
719 if( nvals && ad->ad_type->sat_equality &&
720 ad->ad_type->sat_equality->smr_normalize )
722 ml->sml_nvalues = ber_memalloc_x(
723 (nvals+1)*sizeof(struct berval), ctx );
725 for ( nvals = 0; !BER_BVISNULL( &ml->sml_values[nvals] ); nvals++ ) {
726 #ifdef SLAP_ORDERED_PRETTYNORM
727 rc = ordered_value_normalize(
728 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
730 ad->ad_type->sat_equality,
731 &ml->sml_values[nvals], &ml->sml_nvalues[nvals], ctx );
732 #else /* ! SLAP_ORDERED_PRETTYNORM */
733 rc = ad->ad_type->sat_equality->smr_normalize(
734 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
735 ad->ad_type->sat_syntax,
736 ad->ad_type->sat_equality,
737 &ml->sml_values[nvals], &ml->sml_nvalues[nvals], ctx );
738 #endif /* ! SLAP_ORDERED_PRETTYNORM */
740 Debug( LDAP_DEBUG_ANY,
741 "<= str2entry NULL (ssyn_normalize %d)\n",
743 snprintf( textbuf, textlen,
744 "%s: value #%ld normalization failed",
745 ml->sml_type.bv_val, (long) nvals );
751 BER_BVZERO( &ml->sml_nvalues[nvals] );
754 /* check for duplicates, but ignore Deletes.
756 if( nvals > 1 && ml->sml_op != LDAP_MOD_DELETE ) {
758 MatchingRule *mr = ad->ad_type->sat_equality;
760 for ( i = 1; i < nvals ; i++ ) {
761 /* test asserted values against themselves */
762 for( j = 0; j < i; j++ ) {
763 rc = ordered_value_match( &match, ml->sml_desc, mr,
765 | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX
766 | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH
767 | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH,
769 ? &ml->sml_nvalues[i]
770 : &ml->sml_values[i],
772 ? &ml->sml_nvalues[j]
773 : &ml->sml_values[j],
775 if ( rc == LDAP_SUCCESS && match == 0 ) {
776 /* value exists already */
777 snprintf( textbuf, textlen,
778 "%s: value #%d provided more than once",
779 ml->sml_desc->ad_cname.bv_val, j );
781 return LDAP_TYPE_OR_VALUE_EXISTS;
783 } else if ( rc != LDAP_SUCCESS ) {
796 /* Enter with bv->bv_len = sizeof buffer, returns with
797 * actual length of string
799 void slap_timestamp( time_t *tm, struct berval *bv )
805 ltm = gmtime_r( tm, <m_buf );
807 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
811 bv->bv_len = lutil_gentime( bv->bv_val, bv->bv_len, ltm );
813 #ifndef HAVE_GMTIME_R
814 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
818 /* modify only calls this for non-replicas. modrdn always calls.
820 void slap_mods_opattrs(
825 struct berval name, timestamp, csn = BER_BVNULL;
827 char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
828 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
829 Modifications *mod, **modtail, *modlast;
831 if ( SLAP_LASTMOD( op->o_bd ) ) {
833 timestamp.bv_val = timebuf;
834 if ( BER_BVISEMPTY( &op->o_csn )) {
836 csn.bv_len = sizeof( csnbuf );
837 slap_get_csn( op, &csn, manage_ctxcsn );
841 ptr = ber_bvchr( &csn, '#' );
842 if ( ptr && ptr < &csn.bv_val[csn.bv_len] ) {
843 timestamp.bv_len = ptr - csn.bv_val;
844 if ( timestamp.bv_len >= sizeof( timebuf ))
845 timestamp.bv_len = sizeof( timebuf ) - 1;
846 strncpy( timebuf, csn.bv_val, timestamp.bv_len );
847 timebuf[timestamp.bv_len] = '\0';
849 time_t now = slap_get_time();
851 timestamp.bv_len = sizeof(timebuf);
853 slap_timestamp( &now, ×tamp );
856 if ( BER_BVISEMPTY( &op->o_dn ) ) {
857 BER_BVSTR( &name, SLAPD_ANONYMOUS );
864 for ( mod = mods; mod->sml_next; mod = mod->sml_next )
866 modtail = &mod->sml_next;
868 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
869 mod->sml_op = LDAP_MOD_REPLACE;
870 mod->sml_flags = SLAP_MOD_INTERNAL;
871 mod->sml_next = NULL;
872 BER_BVZERO( &mod->sml_type );
873 mod->sml_desc = slap_schema.si_ad_entryCSN;
874 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
875 ber_dupbv( &mod->sml_values[0], &csn );
876 BER_BVZERO( &mod->sml_values[1] );
877 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
878 mod->sml_nvalues = NULL;
881 modtail = &mod->sml_next;
883 if ( get_manageDIT( op ) ) {
884 for ( mod = mods; mod != modlast; mod = mod->sml_next ) {
885 if ( mod->sml_desc == slap_schema.si_ad_modifiersName ) {
891 if ( mod->sml_desc != slap_schema.si_ad_modifiersName ) {
892 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
893 mod->sml_op = LDAP_MOD_REPLACE;
894 mod->sml_flags = SLAP_MOD_INTERNAL;
895 mod->sml_next = NULL;
896 BER_BVZERO( &mod->sml_type );
897 mod->sml_desc = slap_schema.si_ad_modifiersName;
898 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
899 ber_dupbv( &mod->sml_values[0], &name );
900 BER_BVZERO( &mod->sml_values[1] );
901 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
903 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
904 ber_dupbv( &mod->sml_nvalues[0], &nname );
905 BER_BVZERO( &mod->sml_nvalues[1] );
906 assert( !BER_BVISNULL( &mod->sml_nvalues[0] ) );
908 modtail = &mod->sml_next;
911 if ( get_manageDIT( op ) ) {
912 for ( mod = mods; mod != modlast; mod = mod->sml_next ) {
913 if ( mod->sml_desc == slap_schema.si_ad_modifyTimestamp ) {
919 if ( mod->sml_desc != slap_schema.si_ad_modifyTimestamp ) {
920 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
921 mod->sml_op = LDAP_MOD_REPLACE;
922 mod->sml_flags = SLAP_MOD_INTERNAL;
923 mod->sml_next = NULL;
924 BER_BVZERO( &mod->sml_type );
925 mod->sml_desc = slap_schema.si_ad_modifyTimestamp;
926 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
927 ber_dupbv( &mod->sml_values[0], ×tamp );
928 BER_BVZERO( &mod->sml_values[1] );
929 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
930 mod->sml_nvalues = NULL;
932 modtail = &mod->sml_next;