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;
47 char textbuf[ SLAP_TEXT_BUFLEN ];
48 size_t textlen = sizeof( textbuf );
50 Debug( LDAP_DEBUG_TRACE, "do_modify\n", 0, 0, 0 );
53 * Parse the modify request. It looks like this:
55 * ModifyRequest := [APPLICATION 6] SEQUENCE {
56 * name DistinguishedName,
57 * mods SEQUENCE OF SEQUENCE {
58 * operation ENUMERATED {
63 * modification SEQUENCE {
65 * values SET OF AttributeValue
71 if ( ber_scanf( op->o_ber, "{m" /*}*/, &dn ) == LBER_ERROR ) {
72 Debug( LDAP_DEBUG_ANY, "do_modify: ber_scanf failed\n", 0, 0, 0 );
74 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
75 return SLAPD_DISCONNECT;
78 Debug( LDAP_DEBUG_ARGS, "do_modify: dn (%s)\n", dn.bv_val, 0, 0 );
80 rs->sr_err = slap_parse_modlist( op, rs, op->o_ber, &op->oq_modify );
81 if ( rs->sr_err != LDAP_SUCCESS ) {
82 Debug( LDAP_DEBUG_ANY, "do_modify: slap_parse_modlist failed err=%d msg=%s\n",
83 rs->sr_err, rs->sr_text, 0 );
87 if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
88 Debug( LDAP_DEBUG_ANY, "do_modify: get_ctrls failed\n", 0, 0, 0 );
92 rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn,
94 if( rs->sr_err != LDAP_SUCCESS ) {
95 Debug( LDAP_DEBUG_ANY,
96 "do_modify: invalid dn (%s)\n", dn.bv_val, 0, 0 );
97 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
101 rs->sr_err = slap_mods_check( op, op->orm_modlist,
102 &rs->sr_text, textbuf, textlen, NULL );
104 if ( rs->sr_err != LDAP_SUCCESS ) {
105 send_ldap_result( op, rs );
109 op->o_bd = frontendDB;
110 rs->sr_err = frontendDB->be_modify( op, rs );
113 if( rs->sr_err == LDAP_X_TXN_SPECIFY_OKAY ) {
120 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
121 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
122 if ( op->orm_modlist != NULL ) slap_mods_free( op->orm_modlist, 1 );
128 fe_op_modify( Operation *op, SlapReply *rs )
134 BackendDB *op_be, *bd = op->o_bd;
135 char textbuf[ SLAP_TEXT_BUFLEN ];
136 size_t textlen = sizeof( textbuf );
138 if ( BER_BVISEMPTY( &op->o_req_ndn ) ) {
139 Debug( LDAP_DEBUG_ANY, "do_modify: root dse!\n", 0, 0, 0 );
141 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
142 "modify upon the root DSE not supported" );
145 } else if ( bvmatch( &op->o_req_ndn, &frontendDB->be_schemandn ) ) {
146 Debug( LDAP_DEBUG_ANY, "do_modify: subschema subentry!\n", 0, 0, 0 );
148 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
149 "modification of subschema subentry not supported" );
154 Debug( LDAP_DEBUG_ARGS, "modifications:\n", 0, 0, 0 );
156 for ( tmp = op->orm_modlist; tmp != NULL; tmp = tmp->sml_next ) {
157 Debug( LDAP_DEBUG_ARGS, "\t%s: %s\n",
158 tmp->sml_op == LDAP_MOD_ADD ? "add" :
159 (tmp->sml_op == LDAP_MOD_INCREMENT ? "increment" :
160 (tmp->sml_op == LDAP_MOD_DELETE ? "delete" :
161 "replace")), tmp->sml_type.bv_val, 0 );
163 if ( tmp->sml_values == NULL ) {
164 Debug( LDAP_DEBUG_ARGS, "%s\n",
165 "\t\tno values", NULL, NULL );
166 } else if ( BER_BVISNULL( &tmp->sml_values[ 0 ] ) ) {
167 Debug( LDAP_DEBUG_ARGS, "%s\n",
168 "\t\tzero values", NULL, NULL );
169 } else if ( BER_BVISNULL( &tmp->sml_values[ 1 ] ) ) {
170 Debug( LDAP_DEBUG_ARGS, "%s, length %ld\n",
171 "\t\tone value", (long) tmp->sml_values[0].bv_len, NULL );
173 Debug( LDAP_DEBUG_ARGS, "%s\n",
174 "\t\tmultiple values", NULL, NULL );
178 if ( StatslogTest( LDAP_DEBUG_STATS ) ) {
179 char abuf[BUFSIZ/2], *ptr = abuf;
182 Statslog( LDAP_DEBUG_STATS, "%s MOD dn=\"%s\"\n",
183 op->o_log_prefix, op->o_req_dn.bv_val, 0, 0, 0 );
185 for ( tmp = op->orm_modlist; tmp != NULL; tmp = tmp->sml_next ) {
186 if (len + 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
187 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
188 op->o_log_prefix, abuf, 0, 0, 0 );
193 if( 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
194 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
195 op->o_log_prefix, tmp->sml_type.bv_val, 0, 0, 0 );
203 ptr = lutil_strcopy(ptr, tmp->sml_type.bv_val);
204 len += tmp->sml_type.bv_len;
207 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
208 op->o_log_prefix, abuf, 0, 0, 0 );
211 #endif /* LDAP_DEBUG */
213 manageDSAit = get_manageDSAit( op );
216 * We could be serving multiple database backends. Select the
217 * appropriate one, or send a referral to our "referral server"
218 * if we don't hold it.
220 op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 1 );
221 if ( op->o_bd == NULL ) {
223 rs->sr_ref = referral_rewrite( default_referral,
224 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
226 rs->sr_ref = default_referral;
229 if ( rs->sr_ref != NULL ) {
230 rs->sr_err = LDAP_REFERRAL;
231 send_ldap_result( op, rs );
233 if ( rs->sr_ref != default_referral ) {
234 ber_bvarray_free( rs->sr_ref );
238 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
239 "no global superior knowledge" );
244 /* If we've got a glued backend, check the real backend */
246 if ( SLAP_GLUE_INSTANCE( op->o_bd )) {
247 op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 0 );
250 /* check restrictions */
251 if ( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
252 send_ldap_result( op, rs );
256 /* check for referrals */
257 if ( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
261 rs->sr_err = slap_mods_obsolete_check( op, op->orm_modlist,
262 &rs->sr_text, textbuf, textlen );
263 if ( rs->sr_err != LDAP_SUCCESS ) {
264 send_ldap_result( op, rs );
268 /* check for modify/increment support */
269 if ( op->orm_increment && !SLAP_INCREMENT( op->o_bd ) ) {
270 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
271 "modify/increment not supported in context" );
275 * do the modify if 1 && (2 || 3)
276 * 1) there is a modify function implemented in this backend;
277 * 2) this backend is master for what it holds;
278 * 3) it's a replica and the dn supplied is the update_ndn.
280 if ( op->o_bd->be_modify ) {
281 /* do the update here */
282 int repl_user = be_isupdate( op );
285 * Multimaster slapd does not have to check for replicator dn
286 * because it accepts each modify request
288 if ( !SLAP_SINGLE_SHADOW(op->o_bd) || repl_user ) {
289 int update = !BER_BVISEMPTY( &op->o_bd->be_update_ndn );
294 rs->sr_err = slap_mods_no_user_mod_check( op, op->orm_modlist,
295 &rs->sr_text, textbuf, textlen );
296 if ( rs->sr_err != LDAP_SUCCESS ) {
297 send_ldap_result( op, rs );
301 op->o_bd->be_modify( op, rs );
303 } else { /* send a referral */
304 BerVarray defref = op->o_bd->be_update_refs
305 ? op->o_bd->be_update_refs : default_referral;
306 if ( defref != NULL ) {
307 rs->sr_ref = referral_rewrite( defref,
309 LDAP_SCOPE_DEFAULT );
310 if ( rs->sr_ref == NULL ) {
311 /* FIXME: must duplicate, because
312 * overlays may muck with it */
315 rs->sr_err = LDAP_REFERRAL;
316 send_ldap_result( op, rs );
317 if ( rs->sr_ref != defref ) {
318 ber_bvarray_free( rs->sr_ref );
322 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
323 "shadow context; no update referral" );
328 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
329 "operation not supported within namingContext" );
338 * Obsolete constraint checking.
341 slap_mods_obsolete_check(
348 if( get_relax( op ) ) return LDAP_SUCCESS;
350 for ( ; ml != NULL; ml = ml->sml_next ) {
351 if ( is_at_obsolete( ml->sml_desc->ad_type ) &&
352 (( ml->sml_op != LDAP_MOD_REPLACE &&
353 ml->sml_op != LDAP_MOD_DELETE ) ||
354 ml->sml_values != NULL ))
357 * attribute is obsolete,
358 * only allow replace/delete with no values
360 snprintf( textbuf, textlen,
361 "%s: attribute is obsolete",
362 ml->sml_type.bv_val );
364 return LDAP_CONSTRAINT_VIOLATION;
372 * No-user-modification constraint checking.
375 slap_mods_no_user_mod_check(
382 for ( ; ml != NULL; ml = ml->sml_next ) {
383 if ( !is_at_no_user_mod( ml->sml_desc->ad_type ) ) {
387 if ( get_relax( op ) ) {
388 if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_MANAGEABLE ) {
389 ml->sml_flags |= SLAP_MOD_MANAGING;
393 /* attribute not manageable */
394 snprintf( textbuf, textlen,
395 "%s: no-user-modification attribute not manageable",
396 ml->sml_type.bv_val );
399 /* user modification disallowed */
400 snprintf( textbuf, textlen,
401 "%s: no user modification allowed",
402 ml->sml_type.bv_val );
406 return LDAP_CONSTRAINT_VIOLATION;
413 slap_mods_no_repl_user_mod_check(
423 for ( mods = ml; mods != NULL; mods = mods->sml_next ) {
424 assert( mods->sml_op == LDAP_MOD_ADD );
426 /* check doesn't already appear */
427 for ( modp = ml; modp != NULL; modp = modp->sml_next ) {
428 if ( mods->sml_desc == modp->sml_desc && mods != modp ) {
429 snprintf( textbuf, textlen,
430 "attribute '%s' provided more than once",
431 mods->sml_desc->ad_cname.bv_val );
433 return LDAP_TYPE_OR_VALUE_EXISTS;
442 * Do basic attribute type checking and syntax validation.
454 for( ; ml != NULL; ml = ml->sml_next ) {
455 AttributeDescription *ad = NULL;
457 /* convert to attribute description */
458 if ( ml->sml_desc == NULL ) {
459 rc = slap_bv2ad( &ml->sml_type, &ml->sml_desc, text );
460 if( rc != LDAP_SUCCESS ) {
461 if ( get_no_schema_check( op )) {
462 rc = slap_bv2undef_ad( &ml->sml_type, &ml->sml_desc,
466 if( rc != LDAP_SUCCESS ) {
467 snprintf( textbuf, textlen, "%s: %s",
468 ml->sml_type.bv_val, *text );
476 if( slap_syntax_is_binary( ad->ad_type->sat_syntax )
477 && !slap_ad_is_binary( ad ))
479 /* attribute requires binary transfer */
480 snprintf( textbuf, textlen,
481 "%s: requires ;binary transfer",
482 ml->sml_type.bv_val );
484 return LDAP_UNDEFINED_TYPE;
487 if( !slap_syntax_is_binary( ad->ad_type->sat_syntax )
488 && slap_ad_is_binary( ad ))
490 /* attribute does not require binary transfer */
491 snprintf( textbuf, textlen,
492 "%s: disallows ;binary transfer",
493 ml->sml_type.bv_val );
495 return LDAP_UNDEFINED_TYPE;
498 if( slap_ad_is_tag_range( ad )) {
499 /* attribute requires binary transfer */
500 snprintf( textbuf, textlen,
501 "%s: inappropriate use of tag range option",
502 ml->sml_type.bv_val );
504 return LDAP_UNDEFINED_TYPE;
508 if ( is_at_obsolete( ad->ad_type ) &&
509 (( ml->sml_op != LDAP_MOD_REPLACE &&
510 ml->sml_op != LDAP_MOD_DELETE ) ||
511 ml->sml_values != NULL ))
514 * attribute is obsolete,
515 * only allow replace/delete with no values
517 snprintf( textbuf, textlen,
518 "%s: attribute is obsolete",
519 ml->sml_type.bv_val );
521 return LDAP_CONSTRAINT_VIOLATION;
525 if ( ml->sml_op == LDAP_MOD_INCREMENT &&
526 #ifdef SLAPD_REAL_SYNTAX
527 !is_at_syntax( ad->ad_type, SLAPD_REAL_SYNTAX ) &&
529 !is_at_syntax( ad->ad_type, SLAPD_INTEGER_SYNTAX ) )
532 * attribute values must be INTEGER or REAL
534 snprintf( textbuf, textlen,
535 "%s: attribute syntax inappropriate for increment",
536 ml->sml_type.bv_val );
538 return LDAP_CONSTRAINT_VIOLATION;
544 if( ml->sml_values != NULL ) {
546 slap_syntax_validate_func *validate =
547 ad->ad_type->sat_syntax->ssyn_validate;
548 slap_syntax_transform_func *pretty =
549 ad->ad_type->sat_syntax->ssyn_pretty;
551 if( !pretty && !validate ) {
552 *text = "no validator for syntax";
553 snprintf( textbuf, textlen,
554 "%s: no validator for syntax %s",
556 ad->ad_type->sat_syntax->ssyn_oid );
558 return LDAP_INVALID_SYNTAX;
562 * check that each value is valid per syntax
563 * and pretty if appropriate
565 for ( nvals = 0; !BER_BVISNULL( &ml->sml_values[nvals] ); nvals++ ) {
569 rc = ordered_value_pretty( ad,
570 &ml->sml_values[nvals], &pval, ctx );
572 rc = ordered_value_validate( ad,
573 &ml->sml_values[nvals], ml->sml_op );
577 snprintf( textbuf, textlen,
578 "%s: value #%ld invalid per syntax",
579 ml->sml_type.bv_val, (long) nvals );
581 return LDAP_INVALID_SYNTAX;
585 ber_memfree_x( ml->sml_values[nvals].bv_val, ctx );
586 ml->sml_values[nvals] = pval;
591 * a rough single value check... an additional check is needed
592 * to catch add of single value to existing single valued attribute
594 if ((ml->sml_op == LDAP_MOD_ADD || ml->sml_op == LDAP_MOD_REPLACE)
595 && nvals > 1 && is_at_single_value( ad->ad_type ))
597 snprintf( textbuf, textlen,
598 "%s: multiple values provided",
599 ml->sml_type.bv_val );
601 return LDAP_CONSTRAINT_VIOLATION;
604 /* if the type has a normalizer, generate the
605 * normalized values. otherwise leave them NULL.
607 * this is different from the rule for attributes
608 * in an entry - in an attribute list, the normalized
609 * value is set equal to the non-normalized value
610 * when there is no normalizer.
612 if( nvals && ad->ad_type->sat_equality &&
613 ad->ad_type->sat_equality->smr_normalize )
615 ml->sml_nvalues = ber_memalloc_x(
616 (nvals+1)*sizeof(struct berval), ctx );
618 for ( nvals = 0; !BER_BVISNULL( &ml->sml_values[nvals] ); nvals++ ) {
619 rc = ordered_value_normalize(
620 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
622 ad->ad_type->sat_equality,
623 &ml->sml_values[nvals], &ml->sml_nvalues[nvals], ctx );
625 Debug( LDAP_DEBUG_ANY,
626 "<= str2entry NULL (ssyn_normalize %d)\n",
628 snprintf( textbuf, textlen,
629 "%s: value #%ld normalization failed",
630 ml->sml_type.bv_val, (long) nvals );
636 BER_BVZERO( &ml->sml_nvalues[nvals] );
639 /* check for duplicates, but ignore Deletes.
641 if( nvals > 1 && ml->sml_op != LDAP_MOD_DELETE ) {
642 #define SLAP_MODS_CHECK_QUICKSORT
643 #ifndef SLAP_MODS_CHECK_QUICKSORT
645 MatchingRule *mr = ad->ad_type->sat_equality;
647 for ( i = 1; i < nvals ; i++ ) {
648 /* test asserted values against themselves */
649 for( j = 0; j < i; j++ ) {
650 rc = ordered_value_match( &match, ml->sml_desc, mr,
652 | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX
653 | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH
654 | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH,
656 ? &ml->sml_nvalues[i]
657 : &ml->sml_values[i],
659 ? &ml->sml_nvalues[j]
660 : &ml->sml_values[j],
662 if ( rc == LDAP_SUCCESS && match == 0 ) {
663 /* value exists already */
664 snprintf( textbuf, textlen,
665 "%s: value #%d provided more than once",
666 ml->sml_desc->ad_cname.bv_val, j );
668 return LDAP_TYPE_OR_VALUE_EXISTS;
670 } else if ( rc != LDAP_SUCCESS ) {
675 #else /* SLAP_MODS_CHECK_QUICKSORT */
677 /* Quicksort + Insertion sort for small arrays */
680 #define SWAP(a,b,tmp) tmp=(a);(a)=(b);(b)=tmp
681 #define COMP(a,b) match=0; rc = ordered_value_match( &match, \
682 ml->sml_desc, mr, SLAP_MR_EQUALITY \
683 | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX \
684 | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH \
685 | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH, \
688 MatchingRule *mr = ad->ad_type->sat_equality;
689 int istack[sizeof(int)*16];
690 int i, j, k, l, ir, jstack, match, *ix, itmp;
691 struct berval a, *cv;
693 /* If PRESERVE_ORDER is defined only the index array is sorted; the
694 * actual values are left in their incoming order. Otherwise, the
695 * only reason to keep the index array is to identify the offending
696 * value when duplicates are found.
698 #define PRESERVE_ORDER
699 #ifndef PRESERVE_ORDER
700 struct berval va, *v, *nv, bvtmp;
703 #define EXCH(x,y) SWAP(ix[x],ix[y],itmp); SWAP(cv[x],cv[y],bvtmp); \
704 if (nv) {SWAP(v[x],v[y],bvtmp);}
705 #define SETA(x) itmp = ix[x]; a = cv[x]; if (nv) va=v[x]
706 #define GETA(x) ix[x] = itmp; cv[x] = a; if (nv) v[x]=va
707 #define SET(x,y) ix[x] = ix[y]; cv[x] = cv[y]; if (nv) v[x]=v[y]
710 nv = ml->sml_nvalues;
712 #else /* PRESERVE_ORDER */
715 #define EXCH(x,y) SWAP(ix[x],ix[y],itmp)
716 #define SETA(x) itmp = ix[x]; a = cv[itmp]
717 #define GETA(x) ix[x] = itmp;
718 #define SET(x,y) ix[x] = ix[y]
720 #endif /* PRESERVE_ORDER */
722 cv = ml->sml_nvalues ? ml->sml_nvalues : ml->sml_values;
723 if ( ad == slap_schema.si_ad_objectClass )
724 mr = NULL; /* shortcut matching */
726 /* record indices to preserve input ordering */
727 ix = slap_sl_malloc( nvals * sizeof(int), ctx );
728 for (i=0; i<nvals; i++) ix[i] = i;
735 if (ir - l < SMALL) { /* Insertion sort */
737 for (j=l+1;j<=ir;j++) {
739 for (i=j-1;i>=0;i--) {
746 if ( match == 0 ) goto done;
748 if ( jstack == 0 ) break;
749 if ( match == 0 ) break;
750 ir = istack[jstack--];
751 l = istack[jstack--];
753 k = (l + ir) >> 1; /* Choose median of left, center, right */
755 COMP( cv[IX(l)], cv[IX(ir)] );
758 } else if ( match == 0 ) {
762 COMP( cv[IX(l+1)], cv[IX(ir)] );
765 } else if ( match == 0 ) {
769 COMP( cv[IX(l)], cv[IX(l+1)] );
772 } else if ( match == 0 ) {
782 COMP( cv[IX(i)], a );
783 } while( match < 0 );
786 COMP( cv[IX(j)], a );
804 istack[jstack-1] = i;
808 istack[jstack-1] = l;
817 slap_sl_free( ix, ctx );
819 if ( rc != LDAP_SUCCESS ) {
821 } else if ( match == 0 ) {
822 /* value exists already */
825 snprintf( textbuf, textlen,
826 "%s: value #%d provided more than once",
827 ml->sml_desc->ad_cname.bv_val, j );
829 return LDAP_TYPE_OR_VALUE_EXISTS;
831 #endif /* SLAP_MODS_CHECK_QUICKSORT */
839 /* Enter with bv->bv_len = sizeof buffer, returns with
840 * actual length of string
842 void slap_timestamp( time_t *tm, struct berval *bv )
848 ltm = gmtime_r( tm, <m_buf );
850 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
854 bv->bv_len = lutil_gentime( bv->bv_val, bv->bv_len, ltm );
856 #ifndef HAVE_GMTIME_R
857 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
861 /* Called for all modify and modrdn ops. If the current op was replicated
862 * from elsewhere, all of the attrs should already be present.
864 void slap_mods_opattrs(
866 Modifications **modsp,
869 struct berval name, timestamp, csn = BER_BVNULL;
871 char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
872 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
873 Modifications *mod, **modtail, *modlast;
874 int gotcsn = 0, gotmname = 0, gotmtime = 0;
876 if ( SLAP_LASTMOD( op->o_bd ) && !op->orm_no_opattrs ) {
878 timestamp.bv_val = timebuf;
879 for ( modtail = modsp; *modtail; modtail = &(*modtail)->sml_next ) {
880 if ( (*modtail)->sml_op != LDAP_MOD_ADD &&
881 (*modtail)->sml_op != LDAP_MOD_REPLACE )
886 if ( (*modtail)->sml_desc == slap_schema.si_ad_entryCSN )
888 csn = (*modtail)->sml_values[0];
891 } else if ( (*modtail)->sml_desc == slap_schema.si_ad_modifiersName )
895 } else if ( (*modtail)->sml_desc == slap_schema.si_ad_modifyTimestamp )
901 if ( BER_BVISEMPTY( &op->o_csn )) {
904 csn.bv_len = sizeof( csnbuf );
905 slap_get_csn( op, &csn, manage_ctxcsn );
908 if ( manage_ctxcsn ) {
909 slap_queue_csn( op, &csn );
917 ptr = ber_bvchr( &csn, '#' );
919 timestamp.bv_len = STRLENOF("YYYYMMDDHHMMSSZ");
920 AC_MEMCPY( timebuf, csn.bv_val, timestamp.bv_len );
921 timebuf[timestamp.bv_len-1] = 'Z';
922 timebuf[timestamp.bv_len] = '\0';
925 time_t now = slap_get_time();
927 timestamp.bv_len = sizeof(timebuf);
929 slap_timestamp( &now, ×tamp );
932 if ( BER_BVISEMPTY( &op->o_dn ) ) {
933 BER_BVSTR( &name, SLAPD_ANONYMOUS );
942 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
943 mod->sml_op = LDAP_MOD_REPLACE;
944 mod->sml_flags = SLAP_MOD_INTERNAL;
945 mod->sml_next = NULL;
946 BER_BVZERO( &mod->sml_type );
947 mod->sml_desc = slap_schema.si_ad_entryCSN;
948 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
949 ber_dupbv( &mod->sml_values[0], &csn );
950 BER_BVZERO( &mod->sml_values[1] );
951 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
952 mod->sml_nvalues = NULL;
955 modtail = &mod->sml_next;
959 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
960 mod->sml_op = LDAP_MOD_REPLACE;
961 mod->sml_flags = SLAP_MOD_INTERNAL;
962 mod->sml_next = NULL;
963 BER_BVZERO( &mod->sml_type );
964 mod->sml_desc = slap_schema.si_ad_modifiersName;
965 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
966 ber_dupbv( &mod->sml_values[0], &name );
967 BER_BVZERO( &mod->sml_values[1] );
968 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
970 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
971 ber_dupbv( &mod->sml_nvalues[0], &nname );
972 BER_BVZERO( &mod->sml_nvalues[1] );
973 assert( !BER_BVISNULL( &mod->sml_nvalues[0] ) );
975 modtail = &mod->sml_next;
979 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
980 mod->sml_op = LDAP_MOD_REPLACE;
981 mod->sml_flags = SLAP_MOD_INTERNAL;
982 mod->sml_next = NULL;
983 BER_BVZERO( &mod->sml_type );
984 mod->sml_desc = slap_schema.si_ad_modifyTimestamp;
985 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
986 ber_dupbv( &mod->sml_values[0], ×tamp );
987 BER_BVZERO( &mod->sml_values[1] );
988 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
989 mod->sml_nvalues = NULL;
991 modtail = &mod->sml_next;
1006 Modifications **modtail = &ms->rs_modlist;
1008 ms->rs_modlist = NULL;
1009 ms->rs_increment = 0;
1011 rs->sr_err = LDAP_SUCCESS;
1013 /* collect modifications & save for later */
1014 for ( tag = ber_first_element( ber, &len, &last );
1015 tag != LBER_DEFAULT;
1016 tag = ber_next_element( ber, &len, last ) )
1019 Modifications tmp, *mod;
1021 tmp.sml_nvalues = NULL;
1023 if ( ber_scanf( ber, "{e{m[W]}}", &mop,
1024 &tmp.sml_type, &tmp.sml_values ) == LBER_ERROR )
1026 rs->sr_text = "decoding modlist error";
1027 rs->sr_err = LDAP_PROTOCOL_ERROR;
1031 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
1034 mod->sml_type = tmp.sml_type;
1035 mod->sml_values = tmp.sml_values;
1036 mod->sml_nvalues = NULL;
1037 mod->sml_desc = NULL;
1038 mod->sml_next = NULL;
1043 if ( mod->sml_values == NULL ) {
1044 Debug( LDAP_DEBUG_ANY, "slap_parse_modlist: "
1045 "modify/add operation (%ld) requires values\n",
1048 rs->sr_text = "modify/add operation requires values";
1049 rs->sr_err = LDAP_PROTOCOL_ERROR;
1055 case LDAP_MOD_DELETE:
1056 case LDAP_MOD_REPLACE:
1059 case LDAP_MOD_INCREMENT:
1060 if( op->o_protocol >= LDAP_VERSION3 ) {
1062 if ( mod->sml_values == NULL ) {
1063 Debug( LDAP_DEBUG_ANY, "slap_parse_modlist: "
1064 "modify/increment operation (%ld) requires value\n",
1067 rs->sr_text = "modify/increment operation requires value";
1068 rs->sr_err = LDAP_PROTOCOL_ERROR;
1072 if ( !BER_BVISNULL( &mod->sml_values[ 1 ] ) ) {
1073 Debug( LDAP_DEBUG_ANY, "slap_parse_modlist: modify/increment "
1074 "operation (%ld) requires single value\n",
1077 rs->sr_text = "modify/increment operation requires single value";
1078 rs->sr_err = LDAP_PROTOCOL_ERROR;
1087 Debug( LDAP_DEBUG_ANY, "slap_parse_modlist: "
1088 "unrecognized modify operation (%ld)\n",
1091 rs->sr_text = "unrecognized modify operation";
1092 rs->sr_err = LDAP_PROTOCOL_ERROR;
1096 modtail = &mod->sml_next;
1101 if ( rs->sr_err != LDAP_SUCCESS ) {
1102 slap_mods_free( ms->rs_modlist, 1 );
1103 ms->rs_modlist = NULL;
1104 ms->rs_increment = 0;