2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2007 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;
44 char textbuf[ SLAP_TEXT_BUFLEN ];
45 size_t textlen = sizeof( textbuf );
47 Debug( LDAP_DEBUG_TRACE, "do_modify\n", 0, 0, 0 );
50 * Parse the modify request. It looks like this:
52 * ModifyRequest := [APPLICATION 6] SEQUENCE {
53 * name DistinguishedName,
54 * mods SEQUENCE OF SEQUENCE {
55 * operation ENUMERATED {
60 * modification SEQUENCE {
62 * values SET OF AttributeValue
68 if ( ber_scanf( op->o_ber, "{m" /*}*/, &dn ) == LBER_ERROR ) {
69 Debug( LDAP_DEBUG_ANY, "do_modify: ber_scanf failed\n", 0, 0, 0 );
71 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
72 return SLAPD_DISCONNECT;
75 Debug( LDAP_DEBUG_ARGS, "do_modify: dn (%s)\n", dn.bv_val, 0, 0 );
77 rs->sr_err = slap_parse_modlist( op, rs, op->o_ber, &op->oq_modify );
78 if ( rs->sr_err != LDAP_SUCCESS ) {
79 Debug( LDAP_DEBUG_ANY, "do_modify: slap_parse_modlist failed err=%d msg=%s\n",
80 rs->sr_err, rs->sr_text, 0 );
84 if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
85 Debug( LDAP_DEBUG_ANY, "do_modify: get_ctrls failed\n", 0, 0, 0 );
89 rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn,
91 if( rs->sr_err != LDAP_SUCCESS ) {
92 Debug( LDAP_DEBUG_ANY,
93 "do_modify: invalid dn (%s)\n", dn.bv_val, 0, 0 );
94 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
98 op->orm_no_opattrs = 0;
100 rs->sr_err = slap_mods_check( op, op->orm_modlist,
101 &rs->sr_text, textbuf, textlen, NULL );
103 if ( rs->sr_err != LDAP_SUCCESS ) {
104 send_ldap_result( op, rs );
108 op->o_bd = frontendDB;
109 rs->sr_err = frontendDB->be_modify( op, rs );
112 if( rs->sr_err == LDAP_X_TXN_SPECIFY_OKAY ) {
119 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
120 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
121 if ( op->orm_modlist != NULL ) slap_mods_free( op->orm_modlist, 1 );
127 fe_op_modify( Operation *op, SlapReply *rs )
132 BackendDB *op_be, *bd = op->o_bd;
133 char textbuf[ SLAP_TEXT_BUFLEN ];
134 size_t textlen = sizeof( textbuf );
136 if ( BER_BVISEMPTY( &op->o_req_ndn ) ) {
137 Debug( LDAP_DEBUG_ANY, "do_modify: root dse!\n", 0, 0, 0 );
139 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
140 "modify upon the root DSE not supported" );
143 } else if ( bvmatch( &op->o_req_ndn, &frontendDB->be_schemandn ) ) {
144 Debug( LDAP_DEBUG_ANY, "do_modify: subschema subentry!\n", 0, 0, 0 );
146 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
147 "modification of subschema subentry not supported" );
152 Debug( LDAP_DEBUG_ARGS, "modifications:\n", 0, 0, 0 );
154 for ( tmp = op->orm_modlist; tmp != NULL; tmp = tmp->sml_next ) {
155 Debug( LDAP_DEBUG_ARGS, "\t%s: %s\n",
156 tmp->sml_op == LDAP_MOD_ADD ? "add" :
157 (tmp->sml_op == LDAP_MOD_INCREMENT ? "increment" :
158 (tmp->sml_op == LDAP_MOD_DELETE ? "delete" :
159 "replace")), tmp->sml_type.bv_val, 0 );
161 if ( tmp->sml_values == NULL ) {
162 Debug( LDAP_DEBUG_ARGS, "%s\n",
163 "\t\tno values", NULL, NULL );
164 } else if ( BER_BVISNULL( &tmp->sml_values[ 0 ] ) ) {
165 Debug( LDAP_DEBUG_ARGS, "%s\n",
166 "\t\tzero values", NULL, NULL );
167 } else if ( BER_BVISNULL( &tmp->sml_values[ 1 ] ) ) {
168 Debug( LDAP_DEBUG_ARGS, "%s, length %ld\n",
169 "\t\tone value", (long) tmp->sml_values[0].bv_len, NULL );
171 Debug( LDAP_DEBUG_ARGS, "%s\n",
172 "\t\tmultiple values", NULL, NULL );
176 if ( StatslogTest( LDAP_DEBUG_STATS ) ) {
177 char abuf[BUFSIZ/2], *ptr = abuf;
180 Statslog( LDAP_DEBUG_STATS, "%s MOD dn=\"%s\"\n",
181 op->o_log_prefix, op->o_req_dn.bv_val, 0, 0, 0 );
183 for ( tmp = op->orm_modlist; tmp != NULL; tmp = tmp->sml_next ) {
184 if (len + 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
185 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
186 op->o_log_prefix, abuf, 0, 0, 0 );
191 if( 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
192 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
193 op->o_log_prefix, tmp->sml_type.bv_val, 0, 0, 0 );
201 ptr = lutil_strcopy(ptr, tmp->sml_type.bv_val);
202 len += tmp->sml_type.bv_len;
205 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
206 op->o_log_prefix, abuf, 0, 0, 0 );
209 #endif /* LDAP_DEBUG */
212 * We could be serving multiple database backends. Select the
213 * appropriate one, or send a referral to our "referral server"
214 * if we don't hold it.
216 op->o_bd = select_backend( &op->o_req_ndn, 1 );
217 if ( op->o_bd == NULL ) {
219 rs->sr_ref = referral_rewrite( default_referral,
220 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
222 rs->sr_ref = default_referral;
225 if ( rs->sr_ref != NULL ) {
226 rs->sr_err = LDAP_REFERRAL;
227 send_ldap_result( op, rs );
229 if ( rs->sr_ref != default_referral ) {
230 ber_bvarray_free( rs->sr_ref );
234 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
235 "no global superior knowledge" );
240 /* If we've got a glued backend, check the real backend */
242 if ( SLAP_GLUE_INSTANCE( op->o_bd )) {
243 op->o_bd = select_backend( &op->o_req_ndn, 0 );
246 /* check restrictions */
247 if ( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
248 send_ldap_result( op, rs );
252 /* check for referrals */
253 if ( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
257 rs->sr_err = slap_mods_obsolete_check( op, op->orm_modlist,
258 &rs->sr_text, textbuf, textlen );
259 if ( rs->sr_err != LDAP_SUCCESS ) {
260 send_ldap_result( op, rs );
264 /* check for modify/increment support */
265 if ( op->orm_increment && !SLAP_INCREMENT( op->o_bd ) ) {
266 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
267 "modify/increment not supported in context" );
271 * do the modify if 1 && (2 || 3)
272 * 1) there is a modify function implemented in this backend;
273 * 2) this backend is master for what it holds;
274 * 3) it's a replica and the dn supplied is the update_ndn.
276 if ( op->o_bd->be_modify ) {
277 /* do the update here */
278 int repl_user = be_isupdate( op );
281 * Multimaster slapd does not have to check for replicator dn
282 * because it accepts each modify request
284 if ( !SLAP_SINGLE_SHADOW(op->o_bd) || repl_user ) {
285 int update = !BER_BVISEMPTY( &op->o_bd->be_update_ndn );
290 rs->sr_err = slap_mods_no_user_mod_check( op, op->orm_modlist,
291 &rs->sr_text, textbuf, textlen );
292 if ( rs->sr_err != LDAP_SUCCESS ) {
293 send_ldap_result( op, rs );
297 op->o_bd->be_modify( op, rs );
299 } else { /* send a referral */
300 BerVarray defref = op->o_bd->be_update_refs
301 ? op->o_bd->be_update_refs : default_referral;
302 if ( defref != NULL ) {
303 rs->sr_ref = referral_rewrite( defref,
305 LDAP_SCOPE_DEFAULT );
306 if ( rs->sr_ref == NULL ) {
307 /* FIXME: must duplicate, because
308 * overlays may muck with it */
311 rs->sr_err = LDAP_REFERRAL;
312 send_ldap_result( op, rs );
313 if ( rs->sr_ref != defref ) {
314 ber_bvarray_free( rs->sr_ref );
318 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
319 "shadow context; no update referral" );
324 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
325 "operation not supported within namingContext" );
334 * Obsolete constraint checking.
337 slap_mods_obsolete_check(
344 if( get_relax( op ) ) return LDAP_SUCCESS;
346 for ( ; ml != NULL; ml = ml->sml_next ) {
347 if ( is_at_obsolete( ml->sml_desc->ad_type ) &&
348 (( ml->sml_op != LDAP_MOD_REPLACE &&
349 ml->sml_op != LDAP_MOD_DELETE ) ||
350 ml->sml_values != NULL ))
353 * attribute is obsolete,
354 * only allow replace/delete with no values
356 snprintf( textbuf, textlen,
357 "%s: attribute is obsolete",
358 ml->sml_type.bv_val );
360 return LDAP_CONSTRAINT_VIOLATION;
368 * No-user-modification constraint checking.
371 slap_mods_no_user_mod_check(
378 for ( ; ml != NULL; ml = ml->sml_next ) {
379 if ( !is_at_no_user_mod( ml->sml_desc->ad_type ) ) {
383 if ( get_relax( op ) ) {
384 if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_MANAGEABLE ) {
385 ml->sml_flags |= SLAP_MOD_MANAGING;
389 /* attribute not manageable */
390 snprintf( textbuf, textlen,
391 "%s: no-user-modification attribute not manageable",
392 ml->sml_type.bv_val );
395 /* user modification disallowed */
396 snprintf( textbuf, textlen,
397 "%s: no user modification allowed",
398 ml->sml_type.bv_val );
402 return LDAP_CONSTRAINT_VIOLATION;
409 slap_mods_no_repl_user_mod_check(
419 for ( mods = ml; mods != NULL; mods = mods->sml_next ) {
420 assert( mods->sml_op == LDAP_MOD_ADD );
422 /* check doesn't already appear */
423 for ( modp = ml; modp != NULL; modp = modp->sml_next ) {
424 if ( mods->sml_desc == modp->sml_desc && mods != modp ) {
425 snprintf( textbuf, textlen,
426 "attribute '%s' provided more than once",
427 mods->sml_desc->ad_cname.bv_val );
429 return LDAP_TYPE_OR_VALUE_EXISTS;
438 * Do basic attribute type checking and syntax validation.
450 for( ; ml != NULL; ml = ml->sml_next ) {
451 AttributeDescription *ad = NULL;
453 /* convert to attribute description */
454 if ( ml->sml_desc == NULL ) {
455 rc = slap_bv2ad( &ml->sml_type, &ml->sml_desc, text );
456 if( rc != LDAP_SUCCESS ) {
457 if ( get_no_schema_check( op )) {
458 rc = slap_bv2undef_ad( &ml->sml_type, &ml->sml_desc,
462 if( rc != LDAP_SUCCESS ) {
463 snprintf( textbuf, textlen, "%s: %s",
464 ml->sml_type.bv_val, *text );
472 if( slap_syntax_is_binary( ad->ad_type->sat_syntax )
473 && !slap_ad_is_binary( ad ))
475 /* attribute requires binary transfer */
476 snprintf( textbuf, textlen,
477 "%s: requires ;binary transfer",
478 ml->sml_type.bv_val );
480 return LDAP_UNDEFINED_TYPE;
483 if( !slap_syntax_is_binary( ad->ad_type->sat_syntax )
484 && slap_ad_is_binary( ad ))
486 /* attribute does not require binary transfer */
487 snprintf( textbuf, textlen,
488 "%s: disallows ;binary transfer",
489 ml->sml_type.bv_val );
491 return LDAP_UNDEFINED_TYPE;
494 if( slap_ad_is_tag_range( ad )) {
495 /* attribute requires binary transfer */
496 snprintf( textbuf, textlen,
497 "%s: inappropriate use of tag range option",
498 ml->sml_type.bv_val );
500 return LDAP_UNDEFINED_TYPE;
504 if ( is_at_obsolete( ad->ad_type ) &&
505 (( ml->sml_op != LDAP_MOD_REPLACE &&
506 ml->sml_op != LDAP_MOD_DELETE ) ||
507 ml->sml_values != NULL ))
510 * attribute is obsolete,
511 * only allow replace/delete with no values
513 snprintf( textbuf, textlen,
514 "%s: attribute is obsolete",
515 ml->sml_type.bv_val );
517 return LDAP_CONSTRAINT_VIOLATION;
521 if ( ml->sml_op == LDAP_MOD_INCREMENT &&
522 #ifdef SLAPD_REAL_SYNTAX
523 !is_at_syntax( ad->ad_type, SLAPD_REAL_SYNTAX ) &&
525 !is_at_syntax( ad->ad_type, SLAPD_INTEGER_SYNTAX ) )
528 * attribute values must be INTEGER or REAL
530 snprintf( textbuf, textlen,
531 "%s: attribute syntax inappropriate for increment",
532 ml->sml_type.bv_val );
534 return LDAP_CONSTRAINT_VIOLATION;
540 if( ml->sml_values != NULL ) {
542 slap_syntax_validate_func *validate =
543 ad->ad_type->sat_syntax->ssyn_validate;
544 slap_syntax_transform_func *pretty =
545 ad->ad_type->sat_syntax->ssyn_pretty;
547 if( !pretty && !validate ) {
548 *text = "no validator for syntax";
549 snprintf( textbuf, textlen,
550 "%s: no validator for syntax %s",
552 ad->ad_type->sat_syntax->ssyn_oid );
554 return LDAP_INVALID_SYNTAX;
558 * check that each value is valid per syntax
559 * and pretty if appropriate
561 for ( nvals = 0; !BER_BVISNULL( &ml->sml_values[nvals] ); nvals++ ) {
565 rc = ordered_value_pretty( ad,
566 &ml->sml_values[nvals], &pval, ctx );
568 rc = ordered_value_validate( ad,
569 &ml->sml_values[nvals], ml->sml_op );
573 snprintf( textbuf, textlen,
574 "%s: value #%ld invalid per syntax",
575 ml->sml_type.bv_val, (long) nvals );
577 return LDAP_INVALID_SYNTAX;
581 ber_memfree_x( ml->sml_values[nvals].bv_val, ctx );
582 ml->sml_values[nvals] = pval;
587 * a rough single value check... an additional check is needed
588 * to catch add of single value to existing single valued attribute
590 if ((ml->sml_op == LDAP_MOD_ADD || ml->sml_op == LDAP_MOD_REPLACE)
591 && nvals > 1 && is_at_single_value( ad->ad_type ))
593 snprintf( textbuf, textlen,
594 "%s: multiple values provided",
595 ml->sml_type.bv_val );
597 return LDAP_CONSTRAINT_VIOLATION;
600 /* if the type has a normalizer, generate the
601 * normalized values. otherwise leave them NULL.
603 * this is different from the rule for attributes
604 * in an entry - in an attribute list, the normalized
605 * value is set equal to the non-normalized value
606 * when there is no normalizer.
608 if( nvals && ad->ad_type->sat_equality &&
609 ad->ad_type->sat_equality->smr_normalize )
611 ml->sml_nvalues = ber_memalloc_x(
612 (nvals+1)*sizeof(struct berval), ctx );
614 for ( nvals = 0; !BER_BVISNULL( &ml->sml_values[nvals] ); nvals++ ) {
615 rc = ordered_value_normalize(
616 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
618 ad->ad_type->sat_equality,
619 &ml->sml_values[nvals], &ml->sml_nvalues[nvals], ctx );
621 Debug( LDAP_DEBUG_ANY,
622 "<= str2entry NULL (ssyn_normalize %d)\n",
624 snprintf( textbuf, textlen,
625 "%s: value #%ld normalization failed",
626 ml->sml_type.bv_val, (long) nvals );
632 BER_BVZERO( &ml->sml_nvalues[nvals] );
635 /* check for duplicates, but ignore Deletes.
637 if( nvals > 1 && ml->sml_op != LDAP_MOD_DELETE ) {
638 #define SLAP_MODS_CHECK_QUICKSORT
639 #ifndef SLAP_MODS_CHECK_QUICKSORT
641 MatchingRule *mr = ad->ad_type->sat_equality;
643 for ( i = 1; i < nvals ; i++ ) {
644 /* test asserted values against themselves */
645 for( j = 0; j < i; j++ ) {
646 rc = ordered_value_match( &match, ml->sml_desc, mr,
648 | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX
649 | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH
650 | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH,
652 ? &ml->sml_nvalues[i]
653 : &ml->sml_values[i],
655 ? &ml->sml_nvalues[j]
656 : &ml->sml_values[j],
658 if ( rc == LDAP_SUCCESS && match == 0 ) {
659 /* value exists already */
660 snprintf( textbuf, textlen,
661 "%s: value #%d provided more than once",
662 ml->sml_desc->ad_cname.bv_val, j );
664 return LDAP_TYPE_OR_VALUE_EXISTS;
666 } else if ( rc != LDAP_SUCCESS ) {
671 #else /* SLAP_MODS_CHECK_QUICKSORT */
673 /* Quicksort + Insertion sort for small arrays */
676 #define SWAP(a,b,tmp) tmp=(a);(a)=(b);(b)=tmp
677 #define COMP(a,b) match=0; rc = ordered_value_match( &match, \
678 ml->sml_desc, mr, SLAP_MR_EQUALITY \
679 | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX \
680 | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH \
681 | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH, \
684 MatchingRule *mr = ad->ad_type->sat_equality;
685 int istack[sizeof(int)*16];
686 int i, j, k, l, ir, jstack, match, *ix, itmp;
687 struct berval a, *cv;
689 /* If PRESERVE_ORDER is defined only the index array is sorted; the
690 * actual values are left in their incoming order. Otherwise, the
691 * only reason to keep the index array is to identify the offending
692 * value when duplicates are found.
694 #define PRESERVE_ORDER
695 #ifndef PRESERVE_ORDER
696 struct berval va, *v, *nv, bvtmp;
699 #define EXCH(x,y) SWAP(ix[x],ix[y],itmp); SWAP(cv[x],cv[y],bvtmp); \
700 if (nv) {SWAP(v[x],v[y],bvtmp);}
701 #define SETA(x) itmp = ix[x]; a = cv[x]; if (nv) va=v[x]
702 #define GETA(x) ix[x] = itmp; cv[x] = a; if (nv) v[x]=va
703 #define SET(x,y) ix[x] = ix[y]; cv[x] = cv[y]; if (nv) v[x]=v[y]
706 nv = ml->sml_nvalues;
708 #else /* PRESERVE_ORDER */
711 #define EXCH(x,y) SWAP(ix[x],ix[y],itmp)
712 #define SETA(x) itmp = ix[x]; a = cv[itmp]
713 #define GETA(x) ix[x] = itmp;
714 #define SET(x,y) ix[x] = ix[y]
716 #endif /* PRESERVE_ORDER */
718 cv = ml->sml_nvalues ? ml->sml_nvalues : ml->sml_values;
719 if ( ad == slap_schema.si_ad_objectClass )
720 mr = NULL; /* shortcut matching */
722 /* record indices to preserve input ordering */
723 ix = slap_sl_malloc( nvals * sizeof(int), ctx );
724 for (i=0; i<nvals; i++) ix[i] = i;
731 if (ir - l < SMALL) { /* Insertion sort */
733 for (j=l+1;j<=ir;j++) {
735 for (i=j-1;i>=0;i--) {
742 if ( match == 0 ) goto done;
744 if ( jstack == 0 ) break;
745 if ( match == 0 ) break;
746 ir = istack[jstack--];
747 l = istack[jstack--];
749 k = (l + ir) >> 1; /* Choose median of left, center, right */
751 COMP( cv[IX(l)], cv[IX(ir)] );
754 } else if ( match == 0 ) {
758 COMP( cv[IX(l+1)], cv[IX(ir)] );
761 } else if ( match == 0 ) {
765 COMP( cv[IX(l)], cv[IX(l+1)] );
768 } else if ( match == 0 ) {
778 COMP( cv[IX(i)], a );
779 } while( match < 0 );
782 COMP( cv[IX(j)], a );
800 istack[jstack-1] = i;
804 istack[jstack-1] = l;
813 slap_sl_free( ix, ctx );
815 if ( rc != LDAP_SUCCESS ) {
817 } else if ( match == 0 ) {
818 /* value exists already */
821 snprintf( textbuf, textlen,
822 "%s: value #%d provided more than once",
823 ml->sml_desc->ad_cname.bv_val, j );
825 return LDAP_TYPE_OR_VALUE_EXISTS;
827 #endif /* SLAP_MODS_CHECK_QUICKSORT */
835 /* Enter with bv->bv_len = sizeof buffer, returns with
836 * actual length of string
838 void slap_timestamp( time_t *tm, struct berval *bv )
844 ltm = gmtime_r( tm, <m_buf );
846 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
850 bv->bv_len = lutil_gentime( bv->bv_val, bv->bv_len, ltm );
852 #ifndef HAVE_GMTIME_R
853 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
857 /* Called for all modify and modrdn ops. If the current op was replicated
858 * from elsewhere, all of the attrs should already be present.
860 void slap_mods_opattrs(
862 Modifications **modsp,
865 struct berval name, timestamp, csn = BER_BVNULL;
867 char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
868 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
869 Modifications *mod, **modtail, *modlast;
870 int gotcsn = 0, gotmname = 0, gotmtime = 0;
872 if ( SLAP_LASTMOD( op->o_bd ) && !op->orm_no_opattrs ) {
874 timestamp.bv_val = timebuf;
875 for ( modtail = modsp; *modtail; modtail = &(*modtail)->sml_next ) {
876 if ( (*modtail)->sml_op != LDAP_MOD_ADD &&
877 (*modtail)->sml_op != LDAP_MOD_REPLACE )
882 if ( (*modtail)->sml_desc == slap_schema.si_ad_entryCSN )
884 csn = (*modtail)->sml_values[0];
887 } else if ( (*modtail)->sml_desc == slap_schema.si_ad_modifiersName )
891 } else if ( (*modtail)->sml_desc == slap_schema.si_ad_modifyTimestamp )
897 if ( BER_BVISEMPTY( &op->o_csn )) {
900 csn.bv_len = sizeof( csnbuf );
901 slap_get_csn( op, &csn, manage_ctxcsn );
904 if ( manage_ctxcsn ) {
905 slap_queue_csn( op, &csn );
913 ptr = ber_bvchr( &csn, '#' );
915 timestamp.bv_len = STRLENOF("YYYYMMDDHHMMSSZ");
916 AC_MEMCPY( timebuf, csn.bv_val, timestamp.bv_len );
917 timebuf[timestamp.bv_len-1] = 'Z';
918 timebuf[timestamp.bv_len] = '\0';
921 time_t now = slap_get_time();
923 timestamp.bv_len = sizeof(timebuf);
925 slap_timestamp( &now, ×tamp );
928 if ( BER_BVISEMPTY( &op->o_dn ) ) {
929 BER_BVSTR( &name, SLAPD_ANONYMOUS );
938 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
939 mod->sml_op = LDAP_MOD_REPLACE;
940 mod->sml_flags = SLAP_MOD_INTERNAL;
941 mod->sml_next = NULL;
942 BER_BVZERO( &mod->sml_type );
943 mod->sml_desc = slap_schema.si_ad_entryCSN;
944 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
945 ber_dupbv( &mod->sml_values[0], &csn );
946 BER_BVZERO( &mod->sml_values[1] );
947 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
948 mod->sml_nvalues = NULL;
951 modtail = &mod->sml_next;
955 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
956 mod->sml_op = LDAP_MOD_REPLACE;
957 mod->sml_flags = SLAP_MOD_INTERNAL;
958 mod->sml_next = NULL;
959 BER_BVZERO( &mod->sml_type );
960 mod->sml_desc = slap_schema.si_ad_modifiersName;
961 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
962 ber_dupbv( &mod->sml_values[0], &name );
963 BER_BVZERO( &mod->sml_values[1] );
964 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
966 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
967 ber_dupbv( &mod->sml_nvalues[0], &nname );
968 BER_BVZERO( &mod->sml_nvalues[1] );
969 assert( !BER_BVISNULL( &mod->sml_nvalues[0] ) );
971 modtail = &mod->sml_next;
975 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
976 mod->sml_op = LDAP_MOD_REPLACE;
977 mod->sml_flags = SLAP_MOD_INTERNAL;
978 mod->sml_next = NULL;
979 BER_BVZERO( &mod->sml_type );
980 mod->sml_desc = slap_schema.si_ad_modifyTimestamp;
981 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
982 ber_dupbv( &mod->sml_values[0], ×tamp );
983 BER_BVZERO( &mod->sml_values[1] );
984 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
985 mod->sml_nvalues = NULL;
987 modtail = &mod->sml_next;
1002 Modifications **modtail = &ms->rs_modlist;
1004 ms->rs_modlist = NULL;
1005 ms->rs_increment = 0;
1007 rs->sr_err = LDAP_SUCCESS;
1009 /* collect modifications & save for later */
1010 for ( tag = ber_first_element( ber, &len, &last );
1011 tag != LBER_DEFAULT;
1012 tag = ber_next_element( ber, &len, last ) )
1015 Modifications tmp, *mod;
1017 tmp.sml_nvalues = NULL;
1019 if ( ber_scanf( ber, "{e{m[W]}}", &mop,
1020 &tmp.sml_type, &tmp.sml_values ) == LBER_ERROR )
1022 rs->sr_text = "decoding modlist error";
1023 rs->sr_err = LDAP_PROTOCOL_ERROR;
1027 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
1030 mod->sml_type = tmp.sml_type;
1031 mod->sml_values = tmp.sml_values;
1032 mod->sml_nvalues = NULL;
1033 mod->sml_desc = NULL;
1034 mod->sml_next = NULL;
1039 if ( mod->sml_values == NULL ) {
1040 Debug( LDAP_DEBUG_ANY, "slap_parse_modlist: "
1041 "modify/add operation (%ld) requires values\n",
1044 rs->sr_text = "modify/add operation requires values";
1045 rs->sr_err = LDAP_PROTOCOL_ERROR;
1051 case LDAP_MOD_DELETE:
1052 case LDAP_MOD_REPLACE:
1055 case LDAP_MOD_INCREMENT:
1056 if( op->o_protocol >= LDAP_VERSION3 ) {
1058 if ( mod->sml_values == NULL ) {
1059 Debug( LDAP_DEBUG_ANY, "slap_parse_modlist: "
1060 "modify/increment operation (%ld) requires value\n",
1063 rs->sr_text = "modify/increment operation requires value";
1064 rs->sr_err = LDAP_PROTOCOL_ERROR;
1068 if ( !BER_BVISNULL( &mod->sml_values[ 1 ] ) ) {
1069 Debug( LDAP_DEBUG_ANY, "slap_parse_modlist: modify/increment "
1070 "operation (%ld) requires single value\n",
1073 rs->sr_text = "modify/increment operation requires single value";
1074 rs->sr_err = LDAP_PROTOCOL_ERROR;
1083 Debug( LDAP_DEBUG_ANY, "slap_parse_modlist: "
1084 "unrecognized modify operation (%ld)\n",
1087 rs->sr_text = "unrecognized modify operation";
1088 rs->sr_err = LDAP_PROTOCOL_ERROR;
1092 modtail = &mod->sml_next;
1097 if ( rs->sr_err != LDAP_SUCCESS ) {
1098 slap_mods_free( ms->rs_modlist, 1 );
1099 ms->rs_modlist = NULL;
1100 ms->rs_increment = 0;