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 );
178 rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn,
180 if( rs->sr_err != LDAP_SUCCESS ) {
181 Debug( LDAP_DEBUG_ANY,
182 "do_modify: invalid dn (%s)\n", dn.bv_val, 0, 0 );
183 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
187 rs->sr_err = slap_mods_check( modlist,
188 &rs->sr_text, textbuf, textlen, NULL );
190 if ( rs->sr_err != LDAP_SUCCESS ) {
191 send_ldap_result( op, rs );
195 /* FIXME: needs review */
196 op->orm_modlist = modlist;
197 op->orm_increment = increment;
199 op->o_bd = frontendDB;
200 rs->sr_err = frontendDB->be_modify( op, rs );
203 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
204 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
205 if ( op->orm_modlist != NULL ) slap_mods_free( op->orm_modlist, 1 );
211 fe_op_modify( Operation *op, SlapReply *rs )
218 char textbuf[ SLAP_TEXT_BUFLEN ];
219 size_t textlen = sizeof( textbuf );
221 if ( BER_BVISEMPTY( &op->o_req_ndn ) ) {
222 Debug( LDAP_DEBUG_ANY, "do_modify: root dse!\n", 0, 0, 0 );
224 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
225 "modify upon the root DSE not supported" );
228 } else if ( bvmatch( &op->o_req_ndn, &frontendDB->be_schemandn ) ) {
229 Debug( LDAP_DEBUG_ANY, "do_modify: subschema subentry!\n", 0, 0, 0 );
231 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
232 "modification of subschema subentry not supported" );
237 Debug( LDAP_DEBUG_ARGS, "modifications:\n", 0, 0, 0 );
239 for ( tmp = op->orm_modlist; tmp != NULL; tmp = tmp->sml_next ) {
240 Debug( LDAP_DEBUG_ARGS, "\t%s: %s\n",
241 tmp->sml_op == LDAP_MOD_ADD ? "add" :
242 (tmp->sml_op == LDAP_MOD_INCREMENT ? "increment" :
243 (tmp->sml_op == LDAP_MOD_DELETE ? "delete" :
244 "replace")), tmp->sml_type.bv_val, 0 );
246 if ( tmp->sml_values == NULL ) {
247 Debug( LDAP_DEBUG_ARGS, "%s\n",
248 "\t\tno values", NULL, NULL );
249 } else if ( BER_BVISNULL( &tmp->sml_values[ 0 ] ) ) {
250 Debug( LDAP_DEBUG_ARGS, "%s\n",
251 "\t\tzero values", NULL, NULL );
252 } else if ( BER_BVISNULL( &tmp->sml_values[ 1 ] ) ) {
253 Debug( LDAP_DEBUG_ARGS, "%s, length %ld\n",
254 "\t\tone value", (long) tmp->sml_values[0].bv_len, NULL );
256 Debug( LDAP_DEBUG_ARGS, "%s\n",
257 "\t\tmultiple values", NULL, NULL );
261 if ( StatslogTest( LDAP_DEBUG_STATS ) ) {
262 char abuf[BUFSIZ/2], *ptr = abuf;
265 Statslog( LDAP_DEBUG_STATS, "%s MOD dn=\"%s\"\n",
266 op->o_log_prefix, op->o_req_dn.bv_val, 0, 0, 0 );
268 for ( tmp = op->orm_modlist; tmp != NULL; tmp = tmp->sml_next ) {
269 if (len + 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
270 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
271 op->o_log_prefix, abuf, 0, 0, 0 );
276 if( 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
277 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
278 op->o_log_prefix, tmp->sml_type.bv_val, 0, 0, 0 );
286 ptr = lutil_strcopy(ptr, tmp->sml_type.bv_val);
287 len += tmp->sml_type.bv_len;
290 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
291 op->o_log_prefix, abuf, 0, 0, 0 );
294 #endif /* LDAP_DEBUG */
296 manageDSAit = get_manageDSAit( op );
299 * We could be serving multiple database backends. Select the
300 * appropriate one, or send a referral to our "referral server"
301 * if we don't hold it.
303 op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 1 );
304 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 op->o_bd = frontendDB;
314 send_ldap_result( op, rs );
317 if ( rs->sr_ref != default_referral ) {
318 ber_bvarray_free( rs->sr_ref );
322 op->o_bd = frontendDB;
323 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
324 "no global superior knowledge" );
330 /* If we've got a glued backend, check the real backend */
332 if ( SLAP_GLUE_INSTANCE( op->o_bd )) {
333 op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 0 );
336 /* check restrictions */
337 if ( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
338 send_ldap_result( op, rs );
342 /* check for referrals */
343 if ( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
347 rs->sr_err = slap_mods_obsolete_check( op, op->orm_modlist,
348 &rs->sr_text, textbuf, textlen );
349 if ( rs->sr_err != LDAP_SUCCESS ) {
350 send_ldap_result( op, rs );
354 /* check for modify/increment support */
355 if ( op->orm_increment && !SLAP_INCREMENT( op->o_bd ) ) {
356 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
357 "modify/increment not supported in context" );
361 * do the modify if 1 && (2 || 3)
362 * 1) there is a modify function implemented in this backend;
363 * 2) this backend is master for what it holds;
364 * 3) it's a replica and the dn supplied is the update_ndn.
366 if ( op->o_bd->be_modify ) {
367 /* do the update here */
368 int repl_user = be_isupdate( op );
370 /* Multimaster slapd does not have to check for replicator dn
371 * because it accepts each modify request
373 #ifndef SLAPD_MULTIMASTER
374 if ( !SLAP_SHADOW(op->o_bd) || repl_user )
375 #endif /* ! SLAPD_MULTIMASTER */
377 int update = !BER_BVISEMPTY( &op->o_bd->be_update_ndn );
378 slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
383 rs->sr_err = slap_mods_no_user_mod_check( op, op->orm_modlist,
384 &rs->sr_text, textbuf, textlen );
385 if ( rs->sr_err != LDAP_SUCCESS ) {
386 send_ldap_result( op, rs );
391 #ifdef SLAPD_MULTIMASTER
393 #endif /* SLAPD_MULTIMASTER */
395 /* but multimaster slapd logs only the ones
396 * not from a replicator user */
397 cb.sc_next = op->o_callback;
398 op->o_callback = &cb;
400 op->o_bd->be_modify( op, rs );
402 #ifndef SLAPD_MULTIMASTER
403 /* send a referral */
405 BerVarray defref = op->o_bd->be_update_refs
406 ? op->o_bd->be_update_refs : default_referral;
407 if ( defref != NULL ) {
408 rs->sr_ref = referral_rewrite( defref,
410 LDAP_SCOPE_DEFAULT );
411 if ( rs->sr_ref == NULL ) {
412 /* FIXME: must duplicate, because
413 * overlays may muck with it */
416 rs->sr_err = LDAP_REFERRAL;
417 send_ldap_result( op, rs );
418 if ( rs->sr_ref != defref ) {
419 ber_bvarray_free( rs->sr_ref );
423 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
424 "shadow context; no update referral" );
426 #endif /* ! SLAPD_MULTIMASTER */
429 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
430 "operation not supported within namingContext" );
438 * Obsolete constraint checking.
441 slap_mods_obsolete_check(
448 if( get_manageDIT( op ) ) return LDAP_SUCCESS;
450 for ( ; ml != NULL; ml = ml->sml_next ) {
451 if ( is_at_obsolete( ml->sml_desc->ad_type ) &&
452 (( ml->sml_op != LDAP_MOD_REPLACE &&
453 ml->sml_op != LDAP_MOD_DELETE ) ||
454 ml->sml_values != NULL ))
457 * attribute is obsolete,
458 * only allow replace/delete with no values
460 snprintf( textbuf, textlen,
461 "%s: attribute is obsolete",
462 ml->sml_type.bv_val );
464 return LDAP_CONSTRAINT_VIOLATION;
472 * No-user-modification constraint checking.
475 slap_mods_no_user_mod_check(
482 for ( ; ml != NULL; ml = ml->sml_next ) {
483 if ( !is_at_no_user_mod( ml->sml_desc->ad_type ) ) {
487 if ( get_manageDIT( op ) ) {
488 if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_MANAGEABLE ) {
489 ml->sml_flags |= SLAP_MOD_MANAGING;
493 /* attribute not manageable */
494 snprintf( textbuf, textlen,
495 "%s: no-user-modification attribute not manageable",
496 ml->sml_type.bv_val );
499 /* user modification disallowed */
500 snprintf( textbuf, textlen,
501 "%s: no user modification allowed",
502 ml->sml_type.bv_val );
506 return LDAP_CONSTRAINT_VIOLATION;
513 slap_mods_no_repl_user_mod_check(
523 for ( mods = ml; mods != NULL; mods = mods->sml_next ) {
524 assert( mods->sml_op == LDAP_MOD_ADD );
526 /* check doesn't already appear */
527 for ( modp = ml; modp != NULL; modp = modp->sml_next ) {
528 if ( mods->sml_desc == modp->sml_desc && mods != modp ) {
529 snprintf( textbuf, textlen,
530 "attribute '%s' provided more than once",
531 mods->sml_desc->ad_cname.bv_val );
533 return LDAP_TYPE_OR_VALUE_EXISTS;
542 * Do basic attribute type checking and syntax validation.
553 for( ; ml != NULL; ml = ml->sml_next ) {
554 AttributeDescription *ad = NULL;
556 /* convert to attribute description */
557 if ( ml->sml_desc == NULL ) {
558 rc = slap_bv2ad( &ml->sml_type, &ml->sml_desc, text );
559 if( rc != LDAP_SUCCESS ) {
560 snprintf( textbuf, textlen, "%s: %s",
561 ml->sml_type.bv_val, *text );
569 if( slap_syntax_is_binary( ad->ad_type->sat_syntax )
570 && !slap_ad_is_binary( ad ))
572 /* attribute requires binary transfer */
573 snprintf( textbuf, textlen,
574 "%s: requires ;binary transfer",
575 ml->sml_type.bv_val );
577 return LDAP_UNDEFINED_TYPE;
580 if( !slap_syntax_is_binary( ad->ad_type->sat_syntax )
581 && slap_ad_is_binary( ad ))
583 /* attribute does not require binary transfer */
584 snprintf( textbuf, textlen,
585 "%s: disallows ;binary transfer",
586 ml->sml_type.bv_val );
588 return LDAP_UNDEFINED_TYPE;
591 if( slap_ad_is_tag_range( ad )) {
592 /* attribute requires binary transfer */
593 snprintf( textbuf, textlen,
594 "%s: inappropriate use of tag range option",
595 ml->sml_type.bv_val );
597 return LDAP_UNDEFINED_TYPE;
601 if ( is_at_obsolete( ad->ad_type ) &&
602 (( ml->sml_op != LDAP_MOD_REPLACE &&
603 ml->sml_op != LDAP_MOD_DELETE ) ||
604 ml->sml_values != NULL ))
607 * attribute is obsolete,
608 * only allow replace/delete with no values
610 snprintf( textbuf, textlen,
611 "%s: attribute is obsolete",
612 ml->sml_type.bv_val );
614 return LDAP_CONSTRAINT_VIOLATION;
618 if ( ml->sml_op == LDAP_MOD_INCREMENT &&
619 #ifdef SLAPD_REAL_SYNTAX
620 !is_at_syntax( ad->ad_type, SLAPD_REAL_SYNTAX ) &&
622 !is_at_syntax( ad->ad_type, SLAPD_INTEGER_SYNTAX ) )
625 * attribute values must be INTEGER or REAL
627 snprintf( textbuf, textlen,
628 "%s: attribute syntax inappropriate for increment",
629 ml->sml_type.bv_val );
631 return LDAP_CONSTRAINT_VIOLATION;
637 if( ml->sml_values != NULL ) {
639 slap_syntax_validate_func *validate =
640 ad->ad_type->sat_syntax->ssyn_validate;
641 slap_syntax_transform_func *pretty =
642 ad->ad_type->sat_syntax->ssyn_pretty;
644 if( !pretty && !validate ) {
645 *text = "no validator for syntax";
646 snprintf( textbuf, textlen,
647 "%s: no validator for syntax %s",
649 ad->ad_type->sat_syntax->ssyn_oid );
651 return LDAP_INVALID_SYNTAX;
655 * check that each value is valid per syntax
656 * and pretty if appropriate
658 for ( nvals = 0; !BER_BVISNULL( &ml->sml_values[nvals] ); nvals++ ) {
662 #ifdef SLAP_ORDERED_PRETTYNORM
663 rc = ordered_value_pretty( ad,
664 &ml->sml_values[nvals], &pval, ctx );
665 #else /* ! SLAP_ORDERED_PRETTYNORM */
666 rc = pretty( ad->ad_type->sat_syntax,
667 &ml->sml_values[nvals], &pval, ctx );
668 #endif /* ! SLAP_ORDERED_PRETTYNORM */
670 #ifdef SLAP_ORDERED_PRETTYNORM
671 rc = ordered_value_validate( ad,
672 &ml->sml_values[nvals], ml->sml_op );
673 #else /* ! SLAP_ORDERED_PRETTYNORM */
674 rc = validate( ad->ad_type->sat_syntax,
675 &ml->sml_values[nvals] );
676 #endif /* ! SLAP_ORDERED_PRETTYNORM */
680 snprintf( textbuf, textlen,
681 "%s: value #%ld invalid per syntax",
682 ml->sml_type.bv_val, (long) nvals );
684 return LDAP_INVALID_SYNTAX;
688 ber_memfree_x( ml->sml_values[nvals].bv_val, ctx );
689 ml->sml_values[nvals] = pval;
694 * a rough single value check... an additional check is needed
695 * to catch add of single value to existing single valued attribute
697 if ((ml->sml_op == LDAP_MOD_ADD || ml->sml_op == LDAP_MOD_REPLACE)
698 && nvals > 1 && is_at_single_value( ad->ad_type ))
700 snprintf( textbuf, textlen,
701 "%s: multiple values provided",
702 ml->sml_type.bv_val );
704 return LDAP_CONSTRAINT_VIOLATION;
707 /* if the type has a normalizer, generate the
708 * normalized values. otherwise leave them NULL.
710 * this is different from the rule for attributes
711 * in an entry - in an attribute list, the normalized
712 * value is set equal to the non-normalized value
713 * when there is no normalizer.
715 if( nvals && ad->ad_type->sat_equality &&
716 ad->ad_type->sat_equality->smr_normalize )
718 ml->sml_nvalues = ber_memalloc_x(
719 (nvals+1)*sizeof(struct berval), ctx );
721 for ( nvals = 0; !BER_BVISNULL( &ml->sml_values[nvals] ); nvals++ ) {
722 #ifdef SLAP_ORDERED_PRETTYNORM
723 rc = ordered_value_normalize(
724 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
726 ad->ad_type->sat_equality,
727 &ml->sml_values[nvals], &ml->sml_nvalues[nvals], ctx );
728 #else /* ! SLAP_ORDERED_PRETTYNORM */
729 rc = ad->ad_type->sat_equality->smr_normalize(
730 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
731 ad->ad_type->sat_syntax,
732 ad->ad_type->sat_equality,
733 &ml->sml_values[nvals], &ml->sml_nvalues[nvals], ctx );
734 #endif /* ! SLAP_ORDERED_PRETTYNORM */
736 Debug( LDAP_DEBUG_ANY,
737 "<= str2entry NULL (ssyn_normalize %d)\n",
739 snprintf( textbuf, textlen,
740 "%s: value #%ld normalization failed",
741 ml->sml_type.bv_val, (long) nvals );
747 BER_BVZERO( &ml->sml_nvalues[nvals] );
750 /* check for duplicates, but ignore Deletes.
752 if( nvals > 1 && ml->sml_op != LDAP_MOD_DELETE ) {
754 MatchingRule *mr = ad->ad_type->sat_equality;
756 for ( i = 1; i < nvals ; i++ ) {
757 /* test asserted values against themselves */
758 for( j = 0; j < i; j++ ) {
759 rc = ordered_value_match( &match, ml->sml_desc, mr,
761 | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX
762 | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH
763 | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH,
765 ? &ml->sml_nvalues[i]
766 : &ml->sml_values[i],
768 ? &ml->sml_nvalues[j]
769 : &ml->sml_values[j],
771 if ( rc == LDAP_SUCCESS && match == 0 ) {
772 /* value exists already */
773 snprintf( textbuf, textlen,
774 "%s: value #%d provided more than once",
775 ml->sml_desc->ad_cname.bv_val, j );
777 return LDAP_TYPE_OR_VALUE_EXISTS;
779 } else if ( rc != LDAP_SUCCESS ) {
792 /* Enter with bv->bv_len = sizeof buffer, returns with
793 * actual length of string
795 void slap_timestamp( time_t *tm, struct berval *bv )
801 ltm = gmtime_r( tm, <m_buf );
803 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
807 bv->bv_len = lutil_gentime( bv->bv_val, bv->bv_len, ltm );
809 #ifndef HAVE_GMTIME_R
810 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
814 /* modify only calls this for non-replicas. modrdn always calls.
816 void slap_mods_opattrs(
818 Modifications **modsp,
821 struct berval name, timestamp, csn = BER_BVNULL;
823 char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
824 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
825 Modifications *mod, **modtail, *modlast;
827 if ( SLAP_LASTMOD( op->o_bd ) ) {
829 timestamp.bv_val = timebuf;
830 if ( BER_BVISEMPTY( &op->o_csn )) {
832 csn.bv_len = sizeof( csnbuf );
833 slap_get_csn( op, &csn, manage_ctxcsn );
837 ptr = ber_bvchr( &csn, '#' );
839 timestamp.bv_len = ptr - csn.bv_val;
840 if ( timestamp.bv_len >= sizeof( timebuf )) /* ?!? */
841 timestamp.bv_len = sizeof( timebuf ) - 1;
842 AC_MEMCPY( timebuf, csn.bv_val, timestamp.bv_len );
843 timebuf[timestamp.bv_len] = '\0';
845 time_t now = slap_get_time();
847 timestamp.bv_len = sizeof(timebuf);
849 slap_timestamp( &now, ×tamp );
852 if ( BER_BVISEMPTY( &op->o_dn ) ) {
853 BER_BVSTR( &name, SLAPD_ANONYMOUS );
860 for ( modtail = modsp; *modtail; modtail = &(*modtail)->sml_next )
863 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
864 mod->sml_op = LDAP_MOD_REPLACE;
865 mod->sml_flags = SLAP_MOD_INTERNAL;
866 mod->sml_next = NULL;
867 BER_BVZERO( &mod->sml_type );
868 mod->sml_desc = slap_schema.si_ad_entryCSN;
869 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
870 ber_dupbv( &mod->sml_values[0], &csn );
871 BER_BVZERO( &mod->sml_values[1] );
872 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
873 mod->sml_nvalues = NULL;
876 modtail = &mod->sml_next;
878 if ( get_manageDIT( op ) ) {
879 for ( mod = *modsp; mod != modlast; mod = mod->sml_next ) {
880 if ( mod->sml_desc == slap_schema.si_ad_modifiersName ) {
886 if ( mod->sml_desc != slap_schema.si_ad_modifiersName ) {
887 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
888 mod->sml_op = LDAP_MOD_REPLACE;
889 mod->sml_flags = SLAP_MOD_INTERNAL;
890 mod->sml_next = NULL;
891 BER_BVZERO( &mod->sml_type );
892 mod->sml_desc = slap_schema.si_ad_modifiersName;
893 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
894 ber_dupbv( &mod->sml_values[0], &name );
895 BER_BVZERO( &mod->sml_values[1] );
896 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
898 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
899 ber_dupbv( &mod->sml_nvalues[0], &nname );
900 BER_BVZERO( &mod->sml_nvalues[1] );
901 assert( !BER_BVISNULL( &mod->sml_nvalues[0] ) );
903 modtail = &mod->sml_next;
906 if ( get_manageDIT( op ) ) {
907 for ( mod = *modsp; mod != modlast; mod = mod->sml_next ) {
908 if ( mod->sml_desc == slap_schema.si_ad_modifyTimestamp ) {
914 if ( mod->sml_desc != slap_schema.si_ad_modifyTimestamp ) {
915 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
916 mod->sml_op = LDAP_MOD_REPLACE;
917 mod->sml_flags = SLAP_MOD_INTERNAL;
918 mod->sml_next = NULL;
919 BER_BVZERO( &mod->sml_type );
920 mod->sml_desc = slap_schema.si_ad_modifyTimestamp;
921 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
922 ber_dupbv( &mod->sml_values[0], ×tamp );
923 BER_BVZERO( &mod->sml_values[1] );
924 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
925 mod->sml_nvalues = NULL;
927 modtail = &mod->sml_next;