2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2006 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( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
173 Debug( LDAP_DEBUG_ANY, "do_modify: get_ctrls failed\n", 0, 0, 0 );
177 rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn,
179 if( rs->sr_err != LDAP_SUCCESS ) {
180 Debug( LDAP_DEBUG_ANY,
181 "do_modify: invalid dn (%s)\n", dn.bv_val, 0, 0 );
182 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
186 rs->sr_err = slap_mods_check( modlist,
187 &rs->sr_text, textbuf, textlen, NULL );
189 if ( rs->sr_err != LDAP_SUCCESS ) {
190 send_ldap_result( op, rs );
194 /* FIXME: needs review */
195 op->orm_modlist = modlist;
196 op->orm_increment = increment;
198 op->o_bd = frontendDB;
199 rs->sr_err = frontendDB->be_modify( op, rs );
202 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
203 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
204 if ( op->orm_modlist != NULL ) slap_mods_free( op->orm_modlist, 1 );
210 fe_op_modify( Operation *op, SlapReply *rs )
216 BackendDB *op_be, *bd = op->o_bd;
217 char textbuf[ SLAP_TEXT_BUFLEN ];
218 size_t textlen = sizeof( textbuf );
220 if ( BER_BVISEMPTY( &op->o_req_ndn ) ) {
221 Debug( LDAP_DEBUG_ANY, "do_modify: root dse!\n", 0, 0, 0 );
223 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
224 "modify upon the root DSE not supported" );
227 } else if ( bvmatch( &op->o_req_ndn, &frontendDB->be_schemandn ) ) {
228 Debug( LDAP_DEBUG_ANY, "do_modify: subschema subentry!\n", 0, 0, 0 );
230 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
231 "modification of subschema subentry not supported" );
236 Debug( LDAP_DEBUG_ARGS, "modifications:\n", 0, 0, 0 );
238 for ( tmp = op->orm_modlist; tmp != NULL; tmp = tmp->sml_next ) {
239 Debug( LDAP_DEBUG_ARGS, "\t%s: %s\n",
240 tmp->sml_op == LDAP_MOD_ADD ? "add" :
241 (tmp->sml_op == LDAP_MOD_INCREMENT ? "increment" :
242 (tmp->sml_op == LDAP_MOD_DELETE ? "delete" :
243 "replace")), tmp->sml_type.bv_val, 0 );
245 if ( tmp->sml_values == NULL ) {
246 Debug( LDAP_DEBUG_ARGS, "%s\n",
247 "\t\tno values", NULL, NULL );
248 } else if ( BER_BVISNULL( &tmp->sml_values[ 0 ] ) ) {
249 Debug( LDAP_DEBUG_ARGS, "%s\n",
250 "\t\tzero values", NULL, NULL );
251 } else if ( BER_BVISNULL( &tmp->sml_values[ 1 ] ) ) {
252 Debug( LDAP_DEBUG_ARGS, "%s, length %ld\n",
253 "\t\tone value", (long) tmp->sml_values[0].bv_len, NULL );
255 Debug( LDAP_DEBUG_ARGS, "%s\n",
256 "\t\tmultiple values", NULL, NULL );
260 if ( StatslogTest( LDAP_DEBUG_STATS ) ) {
261 char abuf[BUFSIZ/2], *ptr = abuf;
264 Statslog( LDAP_DEBUG_STATS, "%s MOD dn=\"%s\"\n",
265 op->o_log_prefix, op->o_req_dn.bv_val, 0, 0, 0 );
267 for ( tmp = op->orm_modlist; tmp != NULL; tmp = tmp->sml_next ) {
268 if (len + 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
269 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
270 op->o_log_prefix, abuf, 0, 0, 0 );
275 if( 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
276 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
277 op->o_log_prefix, tmp->sml_type.bv_val, 0, 0, 0 );
285 ptr = lutil_strcopy(ptr, tmp->sml_type.bv_val);
286 len += tmp->sml_type.bv_len;
289 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
290 op->o_log_prefix, abuf, 0, 0, 0 );
293 #endif /* LDAP_DEBUG */
295 manageDSAit = get_manageDSAit( op );
298 * We could be serving multiple database backends. Select the
299 * appropriate one, or send a referral to our "referral server"
300 * if we don't hold it.
302 op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 1 );
303 if ( op->o_bd == NULL ) {
305 rs->sr_ref = referral_rewrite( default_referral,
306 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
308 rs->sr_ref = default_referral;
311 if ( rs->sr_ref != NULL ) {
312 rs->sr_err = LDAP_REFERRAL;
313 send_ldap_result( op, rs );
315 if ( rs->sr_ref != default_referral ) {
316 ber_bvarray_free( rs->sr_ref );
320 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
321 "no global superior knowledge" );
326 /* If we've got a glued backend, check the real backend */
328 if ( SLAP_GLUE_INSTANCE( op->o_bd )) {
329 op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 0 );
332 /* check restrictions */
333 if ( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
334 send_ldap_result( op, rs );
338 /* check for referrals */
339 if ( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
343 rs->sr_err = slap_mods_obsolete_check( op, op->orm_modlist,
344 &rs->sr_text, textbuf, textlen );
345 if ( rs->sr_err != LDAP_SUCCESS ) {
346 send_ldap_result( op, rs );
350 /* check for modify/increment support */
351 if ( op->orm_increment && !SLAP_INCREMENT( op->o_bd ) ) {
352 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
353 "modify/increment not supported in context" );
357 * do the modify if 1 && (2 || 3)
358 * 1) there is a modify function implemented in this backend;
359 * 2) this backend is master for what it holds;
360 * 3) it's a replica and the dn supplied is the update_ndn.
362 if ( op->o_bd->be_modify ) {
363 /* do the update here */
364 int repl_user = be_isupdate( op );
367 * Multimaster slapd does not have to check for replicator dn
368 * because it accepts each modify request
370 if ( !SLAP_SINGLE_SHADOW(op->o_bd) || repl_user ) {
371 int update = !BER_BVISEMPTY( &op->o_bd->be_update_ndn );
372 slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
377 rs->sr_err = slap_mods_no_user_mod_check( op, op->orm_modlist,
378 &rs->sr_text, textbuf, textlen );
379 if ( rs->sr_err != LDAP_SUCCESS ) {
380 send_ldap_result( op, rs );
386 /* but multimaster slapd logs only the ones
387 * not from a replicator user */
388 cb.sc_next = op->o_callback;
389 op->o_callback = &cb;
391 op->o_bd->be_modify( op, rs );
393 } else { /* send a referral */
394 BerVarray defref = op->o_bd->be_update_refs
395 ? op->o_bd->be_update_refs : default_referral;
396 if ( defref != NULL ) {
397 rs->sr_ref = referral_rewrite( defref,
399 LDAP_SCOPE_DEFAULT );
400 if ( rs->sr_ref == NULL ) {
401 /* FIXME: must duplicate, because
402 * overlays may muck with it */
405 rs->sr_err = LDAP_REFERRAL;
406 send_ldap_result( op, rs );
407 if ( rs->sr_ref != defref ) {
408 ber_bvarray_free( rs->sr_ref );
412 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
413 "shadow context; no update referral" );
418 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
419 "operation not supported within namingContext" );
428 * Obsolete constraint checking.
431 slap_mods_obsolete_check(
438 if( get_manageDIT( op ) ) return LDAP_SUCCESS;
440 for ( ; ml != NULL; ml = ml->sml_next ) {
441 if ( is_at_obsolete( ml->sml_desc->ad_type ) &&
442 (( ml->sml_op != LDAP_MOD_REPLACE &&
443 ml->sml_op != LDAP_MOD_DELETE ) ||
444 ml->sml_values != NULL ))
447 * attribute is obsolete,
448 * only allow replace/delete with no values
450 snprintf( textbuf, textlen,
451 "%s: attribute is obsolete",
452 ml->sml_type.bv_val );
454 return LDAP_CONSTRAINT_VIOLATION;
462 * No-user-modification constraint checking.
465 slap_mods_no_user_mod_check(
472 for ( ; ml != NULL; ml = ml->sml_next ) {
473 if ( !is_at_no_user_mod( ml->sml_desc->ad_type ) ) {
477 if ( get_manageDIT( op ) ) {
478 if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_MANAGEABLE ) {
479 ml->sml_flags |= SLAP_MOD_MANAGING;
483 /* attribute not manageable */
484 snprintf( textbuf, textlen,
485 "%s: no-user-modification attribute not manageable",
486 ml->sml_type.bv_val );
489 /* user modification disallowed */
490 snprintf( textbuf, textlen,
491 "%s: no user modification allowed",
492 ml->sml_type.bv_val );
496 return LDAP_CONSTRAINT_VIOLATION;
503 slap_mods_no_repl_user_mod_check(
513 for ( mods = ml; mods != NULL; mods = mods->sml_next ) {
514 assert( mods->sml_op == LDAP_MOD_ADD );
516 /* check doesn't already appear */
517 for ( modp = ml; modp != NULL; modp = modp->sml_next ) {
518 if ( mods->sml_desc == modp->sml_desc && mods != modp ) {
519 snprintf( textbuf, textlen,
520 "attribute '%s' provided more than once",
521 mods->sml_desc->ad_cname.bv_val );
523 return LDAP_TYPE_OR_VALUE_EXISTS;
532 * Do basic attribute type checking and syntax validation.
543 for( ; ml != NULL; ml = ml->sml_next ) {
544 AttributeDescription *ad = NULL;
546 /* convert to attribute description */
547 if ( ml->sml_desc == NULL ) {
548 rc = slap_bv2ad( &ml->sml_type, &ml->sml_desc, text );
549 if( rc != LDAP_SUCCESS ) {
550 snprintf( textbuf, textlen, "%s: %s",
551 ml->sml_type.bv_val, *text );
559 if( slap_syntax_is_binary( ad->ad_type->sat_syntax )
560 && !slap_ad_is_binary( ad ))
562 /* attribute requires binary transfer */
563 snprintf( textbuf, textlen,
564 "%s: requires ;binary transfer",
565 ml->sml_type.bv_val );
567 return LDAP_UNDEFINED_TYPE;
570 if( !slap_syntax_is_binary( ad->ad_type->sat_syntax )
571 && slap_ad_is_binary( ad ))
573 /* attribute does not require binary transfer */
574 snprintf( textbuf, textlen,
575 "%s: disallows ;binary transfer",
576 ml->sml_type.bv_val );
578 return LDAP_UNDEFINED_TYPE;
581 if( slap_ad_is_tag_range( ad )) {
582 /* attribute requires binary transfer */
583 snprintf( textbuf, textlen,
584 "%s: inappropriate use of tag range option",
585 ml->sml_type.bv_val );
587 return LDAP_UNDEFINED_TYPE;
591 if ( is_at_obsolete( ad->ad_type ) &&
592 (( ml->sml_op != LDAP_MOD_REPLACE &&
593 ml->sml_op != LDAP_MOD_DELETE ) ||
594 ml->sml_values != NULL ))
597 * attribute is obsolete,
598 * only allow replace/delete with no values
600 snprintf( textbuf, textlen,
601 "%s: attribute is obsolete",
602 ml->sml_type.bv_val );
604 return LDAP_CONSTRAINT_VIOLATION;
608 if ( ml->sml_op == LDAP_MOD_INCREMENT &&
609 #ifdef SLAPD_REAL_SYNTAX
610 !is_at_syntax( ad->ad_type, SLAPD_REAL_SYNTAX ) &&
612 !is_at_syntax( ad->ad_type, SLAPD_INTEGER_SYNTAX ) )
615 * attribute values must be INTEGER or REAL
617 snprintf( textbuf, textlen,
618 "%s: attribute syntax inappropriate for increment",
619 ml->sml_type.bv_val );
621 return LDAP_CONSTRAINT_VIOLATION;
627 if( ml->sml_values != NULL ) {
629 slap_syntax_validate_func *validate =
630 ad->ad_type->sat_syntax->ssyn_validate;
631 slap_syntax_transform_func *pretty =
632 ad->ad_type->sat_syntax->ssyn_pretty;
634 if( !pretty && !validate ) {
635 *text = "no validator for syntax";
636 snprintf( textbuf, textlen,
637 "%s: no validator for syntax %s",
639 ad->ad_type->sat_syntax->ssyn_oid );
641 return LDAP_INVALID_SYNTAX;
645 * check that each value is valid per syntax
646 * and pretty if appropriate
648 for ( nvals = 0; !BER_BVISNULL( &ml->sml_values[nvals] ); nvals++ ) {
652 #ifdef SLAP_ORDERED_PRETTYNORM
653 rc = ordered_value_pretty( ad,
654 &ml->sml_values[nvals], &pval, ctx );
655 #else /* ! SLAP_ORDERED_PRETTYNORM */
656 rc = pretty( ad->ad_type->sat_syntax,
657 &ml->sml_values[nvals], &pval, ctx );
658 #endif /* ! SLAP_ORDERED_PRETTYNORM */
660 #ifdef SLAP_ORDERED_PRETTYNORM
661 rc = ordered_value_validate( ad,
662 &ml->sml_values[nvals], ml->sml_op );
663 #else /* ! SLAP_ORDERED_PRETTYNORM */
664 rc = validate( ad->ad_type->sat_syntax,
665 &ml->sml_values[nvals] );
666 #endif /* ! SLAP_ORDERED_PRETTYNORM */
670 snprintf( textbuf, textlen,
671 "%s: value #%ld invalid per syntax",
672 ml->sml_type.bv_val, (long) nvals );
674 return LDAP_INVALID_SYNTAX;
678 ber_memfree_x( ml->sml_values[nvals].bv_val, ctx );
679 ml->sml_values[nvals] = pval;
684 * a rough single value check... an additional check is needed
685 * to catch add of single value to existing single valued attribute
687 if ((ml->sml_op == LDAP_MOD_ADD || ml->sml_op == LDAP_MOD_REPLACE)
688 && nvals > 1 && is_at_single_value( ad->ad_type ))
690 snprintf( textbuf, textlen,
691 "%s: multiple values provided",
692 ml->sml_type.bv_val );
694 return LDAP_CONSTRAINT_VIOLATION;
697 /* if the type has a normalizer, generate the
698 * normalized values. otherwise leave them NULL.
700 * this is different from the rule for attributes
701 * in an entry - in an attribute list, the normalized
702 * value is set equal to the non-normalized value
703 * when there is no normalizer.
705 if( nvals && ad->ad_type->sat_equality &&
706 ad->ad_type->sat_equality->smr_normalize )
708 ml->sml_nvalues = ber_memalloc_x(
709 (nvals+1)*sizeof(struct berval), ctx );
711 for ( nvals = 0; !BER_BVISNULL( &ml->sml_values[nvals] ); nvals++ ) {
712 #ifdef SLAP_ORDERED_PRETTYNORM
713 rc = ordered_value_normalize(
714 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
716 ad->ad_type->sat_equality,
717 &ml->sml_values[nvals], &ml->sml_nvalues[nvals], ctx );
718 #else /* ! SLAP_ORDERED_PRETTYNORM */
719 rc = ad->ad_type->sat_equality->smr_normalize(
720 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
721 ad->ad_type->sat_syntax,
722 ad->ad_type->sat_equality,
723 &ml->sml_values[nvals], &ml->sml_nvalues[nvals], ctx );
724 #endif /* ! SLAP_ORDERED_PRETTYNORM */
726 Debug( LDAP_DEBUG_ANY,
727 "<= str2entry NULL (ssyn_normalize %d)\n",
729 snprintf( textbuf, textlen,
730 "%s: value #%ld normalization failed",
731 ml->sml_type.bv_val, (long) nvals );
737 BER_BVZERO( &ml->sml_nvalues[nvals] );
740 /* check for duplicates, but ignore Deletes.
742 if( nvals > 1 && ml->sml_op != LDAP_MOD_DELETE ) {
744 MatchingRule *mr = ad->ad_type->sat_equality;
746 for ( i = 1; i < nvals ; i++ ) {
747 /* test asserted values against themselves */
748 for( j = 0; j < i; j++ ) {
749 rc = ordered_value_match( &match, ml->sml_desc, mr,
751 | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX
752 | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH
753 | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH,
755 ? &ml->sml_nvalues[i]
756 : &ml->sml_values[i],
758 ? &ml->sml_nvalues[j]
759 : &ml->sml_values[j],
761 if ( rc == LDAP_SUCCESS && match == 0 ) {
762 /* value exists already */
763 snprintf( textbuf, textlen,
764 "%s: value #%d provided more than once",
765 ml->sml_desc->ad_cname.bv_val, j );
767 return LDAP_TYPE_OR_VALUE_EXISTS;
769 } else if ( rc != LDAP_SUCCESS ) {
782 /* Enter with bv->bv_len = sizeof buffer, returns with
783 * actual length of string
785 void slap_timestamp( time_t *tm, struct berval *bv )
791 ltm = gmtime_r( tm, <m_buf );
793 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
797 bv->bv_len = lutil_gentime( bv->bv_val, bv->bv_len, ltm );
799 #ifndef HAVE_GMTIME_R
800 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
804 /* Called for all modify and modrdn ops. If the current op was replicated
805 * from elsewhere, all of the attrs should already be present.
807 void slap_mods_opattrs(
809 Modifications **modsp,
812 struct berval name, timestamp, csn = BER_BVNULL;
814 char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
815 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
816 Modifications *mod, **modtail, *modlast;
817 int gotcsn = 0, gotmname = 0, gotmtime = 0;
819 if ( SLAP_LASTMOD( op->o_bd ) ) {
821 timestamp.bv_val = timebuf;
822 for ( modtail = modsp; *modtail; modtail = &(*modtail)->sml_next ) {
823 if ( (*modtail)->sml_op != LDAP_MOD_ADD &&
824 (*modtail)->sml_op != LDAP_MOD_REPLACE ) continue;
825 if ( (*modtail)->sml_desc == slap_schema.si_ad_entryCSN ) {
826 csn = (*modtail)->sml_values[0];
829 if ( (*modtail)->sml_desc == slap_schema.si_ad_modifiersName ) {
832 if ( (*modtail)->sml_desc == slap_schema.si_ad_modifyTimestamp ) {
836 if ( BER_BVISEMPTY( &op->o_csn )) {
839 csn.bv_len = sizeof( csnbuf );
840 slap_get_csn( op, &csn, manage_ctxcsn );
843 slap_queue_csn( op, &csn );
848 ptr = ber_bvchr( &csn, '#' );
850 timestamp.bv_len = ptr - csn.bv_val;
851 if ( timestamp.bv_len >= sizeof( timebuf )) /* ?!? */
852 timestamp.bv_len = sizeof( timebuf ) - 1;
853 AC_MEMCPY( timebuf, csn.bv_val, timestamp.bv_len );
854 timebuf[timestamp.bv_len] = '\0';
856 time_t now = slap_get_time();
858 timestamp.bv_len = sizeof(timebuf);
860 slap_timestamp( &now, ×tamp );
863 if ( BER_BVISEMPTY( &op->o_dn ) ) {
864 BER_BVSTR( &name, SLAPD_ANONYMOUS );
872 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
873 mod->sml_op = LDAP_MOD_REPLACE;
874 mod->sml_flags = SLAP_MOD_INTERNAL;
875 mod->sml_next = NULL;
876 BER_BVZERO( &mod->sml_type );
877 mod->sml_desc = slap_schema.si_ad_entryCSN;
878 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
879 ber_dupbv( &mod->sml_values[0], &csn );
880 BER_BVZERO( &mod->sml_values[1] );
881 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
882 mod->sml_nvalues = NULL;
885 modtail = &mod->sml_next;
889 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
890 mod->sml_op = LDAP_MOD_REPLACE;
891 mod->sml_flags = SLAP_MOD_INTERNAL;
892 mod->sml_next = NULL;
893 BER_BVZERO( &mod->sml_type );
894 mod->sml_desc = slap_schema.si_ad_modifiersName;
895 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
896 ber_dupbv( &mod->sml_values[0], &name );
897 BER_BVZERO( &mod->sml_values[1] );
898 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
900 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
901 ber_dupbv( &mod->sml_nvalues[0], &nname );
902 BER_BVZERO( &mod->sml_nvalues[1] );
903 assert( !BER_BVISNULL( &mod->sml_nvalues[0] ) );
905 modtail = &mod->sml_next;
909 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
910 mod->sml_op = LDAP_MOD_REPLACE;
911 mod->sml_flags = SLAP_MOD_INTERNAL;
912 mod->sml_next = NULL;
913 BER_BVZERO( &mod->sml_type );
914 mod->sml_desc = slap_schema.si_ad_modifyTimestamp;
915 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
916 ber_dupbv( &mod->sml_values[0], ×tamp );
917 BER_BVZERO( &mod->sml_values[1] );
918 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
919 mod->sml_nvalues = NULL;
921 modtail = &mod->sml_next;