2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2014 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 );
50 Debug( LDAP_DEBUG_TRACE, "%s do_modify\n",
51 op->o_log_prefix, 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, "%s do_modify: ber_scanf failed\n",
73 op->o_log_prefix, 0, 0 );
74 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
75 return SLAPD_DISCONNECT;
78 Debug( LDAP_DEBUG_ARGS, "%s do_modify: dn (%s)\n",
79 op->o_log_prefix, dn.bv_val, 0 );
81 rs->sr_err = slap_parse_modlist( op, rs, op->o_ber, &op->oq_modify );
82 if ( rs->sr_err != LDAP_SUCCESS ) {
83 Debug( LDAP_DEBUG_ANY, "%s do_modify: slap_parse_modlist failed err=%d msg=%s\n",
84 op->o_log_prefix, rs->sr_err, rs->sr_text );
85 send_ldap_result( op, rs );
89 if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
90 Debug( LDAP_DEBUG_ANY, "%s do_modify: get_ctrls failed\n",
91 op->o_log_prefix, 0, 0 );
92 /* get_ctrls has sent results. Now clean up. */
96 rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn,
98 if( rs->sr_err != LDAP_SUCCESS ) {
99 Debug( LDAP_DEBUG_ANY, "%s do_modify: invalid dn (%s)\n",
100 op->o_log_prefix, dn.bv_val, 0 );
101 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
105 op->orm_no_opattrs = 0;
108 Debug( LDAP_DEBUG_ARGS, "%s modifications:\n",
109 op->o_log_prefix, 0, 0 );
111 for ( tmp = op->orm_modlist; tmp != NULL; tmp = tmp->sml_next ) {
112 Debug( LDAP_DEBUG_ARGS, "\t%s: %s\n",
113 tmp->sml_op == LDAP_MOD_ADD ? "add" :
114 (tmp->sml_op == LDAP_MOD_INCREMENT ? "increment" :
115 (tmp->sml_op == LDAP_MOD_DELETE ? "delete" :
116 "replace")), tmp->sml_type.bv_val, 0 );
118 if ( tmp->sml_values == NULL ) {
119 Debug( LDAP_DEBUG_ARGS, "%s\n",
120 "\t\tno values", NULL, NULL );
121 } else if ( BER_BVISNULL( &tmp->sml_values[ 0 ] ) ) {
122 Debug( LDAP_DEBUG_ARGS, "%s\n",
123 "\t\tzero values", NULL, NULL );
124 } else if ( BER_BVISNULL( &tmp->sml_values[ 1 ] ) ) {
125 Debug( LDAP_DEBUG_ARGS, "%s, length %ld\n",
126 "\t\tone value", (long) tmp->sml_values[0].bv_len, NULL );
128 Debug( LDAP_DEBUG_ARGS, "%s\n",
129 "\t\tmultiple values", NULL, NULL );
133 if ( StatslogTest( LDAP_DEBUG_STATS ) ) {
134 char abuf[BUFSIZ/2], *ptr = abuf;
137 Statslog( LDAP_DEBUG_STATS, "%s MOD dn=\"%s\"\n",
138 op->o_log_prefix, op->o_req_dn.bv_val, 0, 0, 0 );
140 for ( tmp = op->orm_modlist; tmp != NULL; tmp = tmp->sml_next ) {
141 if (len + 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
142 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
143 op->o_log_prefix, abuf, 0, 0, 0 );
148 if( 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
149 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
150 op->o_log_prefix, tmp->sml_type.bv_val, 0, 0, 0 );
158 ptr = lutil_strcopy(ptr, tmp->sml_type.bv_val);
159 len += tmp->sml_type.bv_len;
162 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
163 op->o_log_prefix, abuf, 0, 0, 0 );
166 #endif /* LDAP_DEBUG */
168 rs->sr_err = slap_mods_check( op, op->orm_modlist,
169 &rs->sr_text, textbuf, textlen, NULL );
171 if ( rs->sr_err != LDAP_SUCCESS ) {
172 send_ldap_result( op, rs );
176 op->o_bd = frontendDB;
177 rs->sr_err = frontendDB->be_modify( op, rs );
180 if( rs->sr_err == LDAP_X_TXN_SPECIFY_OKAY ) {
187 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
188 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
189 if ( op->orm_modlist != NULL ) slap_mods_free( op->orm_modlist, 1 );
195 fe_op_modify( Operation *op, SlapReply *rs )
197 BackendDB *op_be, *bd = op->o_bd;
198 char textbuf[ SLAP_TEXT_BUFLEN ];
199 size_t textlen = sizeof( textbuf );
201 if ( BER_BVISEMPTY( &op->o_req_ndn ) ) {
202 Debug( LDAP_DEBUG_ANY, "%s do_modify: root dse!\n",
203 op->o_log_prefix, 0, 0 );
204 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
205 "modify upon the root DSE not supported" );
208 } else if ( bvmatch( &op->o_req_ndn, &frontendDB->be_schemandn ) ) {
209 Debug( LDAP_DEBUG_ANY, "%s do_modify: subschema subentry!\n",
210 op->o_log_prefix, 0, 0 );
211 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
212 "modification of subschema subentry not supported" );
217 * We could be serving multiple database backends. Select the
218 * appropriate one, or send a referral to our "referral server"
219 * if we don't hold it.
221 op->o_bd = select_backend( &op->o_req_ndn, 1 );
222 if ( op->o_bd == NULL ) {
224 rs->sr_ref = referral_rewrite( default_referral,
225 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
227 rs->sr_ref = default_referral;
230 if ( rs->sr_ref != NULL ) {
231 rs->sr_err = LDAP_REFERRAL;
232 send_ldap_result( op, rs );
234 if ( rs->sr_ref != default_referral ) {
235 ber_bvarray_free( rs->sr_ref );
239 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
240 "no global superior knowledge" );
245 /* If we've got a glued backend, check the real backend */
247 if ( SLAP_GLUE_INSTANCE( op->o_bd )) {
248 op->o_bd = select_backend( &op->o_req_ndn, 0 );
251 /* check restrictions */
252 if ( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
253 send_ldap_result( op, rs );
257 /* check for referrals */
258 if ( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
262 rs->sr_err = slap_mods_obsolete_check( op, op->orm_modlist,
263 &rs->sr_text, textbuf, textlen );
264 if ( rs->sr_err != LDAP_SUCCESS ) {
265 send_ldap_result( op, rs );
269 /* check for modify/increment support */
270 if ( op->orm_increment && !SLAP_INCREMENT( op->o_bd ) ) {
271 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
272 "modify/increment not supported in context" );
277 * do the modify if 1 && (2 || 3)
278 * 1) there is a modify function implemented in this backend;
279 * 2) this backend is master for what it holds;
280 * 3) it's a replica and the dn supplied is the update_ndn.
282 if ( op->o_bd->be_modify ) {
283 /* do the update here */
284 int repl_user = be_isupdate( op );
287 * Multimaster slapd does not have to check for replicator dn
288 * because it accepts each modify request
290 if ( !SLAP_SINGLE_SHADOW(op->o_bd) || repl_user ) {
291 int update = !BER_BVISEMPTY( &op->o_bd->be_update_ndn );
296 rs->sr_err = slap_mods_no_user_mod_check( op, op->orm_modlist,
297 &rs->sr_text, textbuf, textlen );
298 if ( rs->sr_err != LDAP_SUCCESS ) {
299 send_ldap_result( op, rs );
303 op->o_bd->be_modify( op, rs );
305 } else { /* send a referral */
306 BerVarray defref = op->o_bd->be_update_refs
307 ? op->o_bd->be_update_refs : default_referral;
308 if ( defref != NULL ) {
309 rs->sr_ref = referral_rewrite( defref,
311 LDAP_SCOPE_DEFAULT );
312 if ( rs->sr_ref == NULL ) {
313 /* FIXME: must duplicate, because
314 * overlays may muck with it */
317 rs->sr_err = LDAP_REFERRAL;
318 send_ldap_result( op, rs );
319 if ( rs->sr_ref != defref ) {
320 ber_bvarray_free( rs->sr_ref );
324 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
325 "shadow context; no update referral" );
330 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
331 "operation not supported within namingContext" );
340 * Obsolete constraint checking.
343 slap_mods_obsolete_check(
350 if( get_relax( op ) ) return LDAP_SUCCESS;
352 for ( ; ml != NULL; ml = ml->sml_next ) {
353 if ( is_at_obsolete( ml->sml_desc->ad_type ) &&
354 (( ml->sml_op != LDAP_MOD_REPLACE &&
355 ml->sml_op != LDAP_MOD_DELETE ) ||
356 ml->sml_values != NULL ))
359 * attribute is obsolete,
360 * only allow replace/delete with no values
362 snprintf( textbuf, textlen,
363 "%s: attribute is obsolete",
364 ml->sml_type.bv_val );
366 return LDAP_CONSTRAINT_VIOLATION;
374 * No-user-modification constraint checking.
377 slap_mods_no_user_mod_check(
384 for ( ; ml != NULL; ml = ml->sml_next ) {
385 if ( !is_at_no_user_mod( ml->sml_desc->ad_type ) ) {
389 if ( ml->sml_flags & SLAP_MOD_INTERNAL ) {
393 if ( get_relax( op ) ) {
394 if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_MANAGEABLE ) {
395 ml->sml_flags |= SLAP_MOD_MANAGING;
399 /* attribute not manageable */
400 snprintf( textbuf, textlen,
401 "%s: no-user-modification attribute not manageable",
402 ml->sml_type.bv_val );
405 /* user modification disallowed */
406 snprintf( textbuf, textlen,
407 "%s: no user modification allowed",
408 ml->sml_type.bv_val );
412 return LDAP_CONSTRAINT_VIOLATION;
419 slap_mods_no_repl_user_mod_check(
429 for ( mods = ml; mods != NULL; mods = mods->sml_next ) {
430 assert( mods->sml_op == LDAP_MOD_ADD );
432 /* check doesn't already appear */
433 for ( modp = ml; modp != NULL; modp = modp->sml_next ) {
434 if ( mods->sml_desc == modp->sml_desc && mods != modp ) {
435 snprintf( textbuf, textlen,
436 "attribute '%s' provided more than once",
437 mods->sml_desc->ad_cname.bv_val );
439 return LDAP_TYPE_OR_VALUE_EXISTS;
448 * Do basic attribute type checking and syntax validation.
460 for( ; ml != NULL; ml = ml->sml_next ) {
461 AttributeDescription *ad = NULL;
463 /* convert to attribute description */
464 if ( ml->sml_desc == NULL ) {
465 rc = slap_bv2ad( &ml->sml_type, &ml->sml_desc, text );
466 if( rc != LDAP_SUCCESS ) {
467 if ( get_no_schema_check( op )) {
468 rc = slap_bv2undef_ad( &ml->sml_type, &ml->sml_desc,
472 if( rc != LDAP_SUCCESS ) {
473 snprintf( textbuf, textlen, "%s: %s",
474 ml->sml_type.bv_val, *text );
482 if( slap_syntax_is_binary( ad->ad_type->sat_syntax )
483 && !slap_ad_is_binary( ad ))
485 /* attribute requires binary transfer */
486 snprintf( textbuf, textlen,
487 "%s: requires ;binary transfer",
488 ml->sml_type.bv_val );
490 return LDAP_UNDEFINED_TYPE;
493 if( !slap_syntax_is_binary( ad->ad_type->sat_syntax )
494 && slap_ad_is_binary( ad ))
496 /* attribute does not require binary transfer */
497 snprintf( textbuf, textlen,
498 "%s: disallows ;binary transfer",
499 ml->sml_type.bv_val );
501 return LDAP_UNDEFINED_TYPE;
504 if( slap_ad_is_tag_range( ad )) {
505 /* attribute requires binary transfer */
506 snprintf( textbuf, textlen,
507 "%s: inappropriate use of tag range option",
508 ml->sml_type.bv_val );
510 return LDAP_UNDEFINED_TYPE;
514 if ( is_at_obsolete( ad->ad_type ) &&
515 (( ml->sml_op != LDAP_MOD_REPLACE &&
516 ml->sml_op != LDAP_MOD_DELETE ) ||
517 ml->sml_values != NULL ))
520 * attribute is obsolete,
521 * only allow replace/delete with no values
523 snprintf( textbuf, textlen,
524 "%s: attribute is obsolete",
525 ml->sml_type.bv_val );
527 return LDAP_CONSTRAINT_VIOLATION;
531 if ( ml->sml_op == LDAP_MOD_INCREMENT &&
532 #ifdef SLAPD_REAL_SYNTAX
533 !is_at_syntax( ad->ad_type, SLAPD_REAL_SYNTAX ) &&
535 !is_at_syntax( ad->ad_type, SLAPD_INTEGER_SYNTAX ) )
538 * attribute values must be INTEGER or REAL
540 snprintf( textbuf, textlen,
541 "%s: attribute syntax inappropriate for increment",
542 ml->sml_type.bv_val );
544 return LDAP_CONSTRAINT_VIOLATION;
550 if( ml->sml_values != NULL ) {
552 slap_syntax_validate_func *validate =
553 ad->ad_type->sat_syntax->ssyn_validate;
554 slap_syntax_transform_func *pretty =
555 ad->ad_type->sat_syntax->ssyn_pretty;
557 if( !pretty && !validate ) {
558 *text = "no validator for syntax";
559 snprintf( textbuf, textlen,
560 "%s: no validator for syntax %s",
562 ad->ad_type->sat_syntax->ssyn_oid );
564 return LDAP_INVALID_SYNTAX;
568 * check that each value is valid per syntax
569 * and pretty if appropriate
571 for ( nvals = 0; !BER_BVISNULL( &ml->sml_values[nvals] ); nvals++ ) {
575 rc = ordered_value_pretty( ad,
576 &ml->sml_values[nvals], &pval, ctx );
578 rc = ordered_value_validate( ad,
579 &ml->sml_values[nvals], ml->sml_op );
583 snprintf( textbuf, textlen,
584 "%s: value #%ld invalid per syntax",
585 ml->sml_type.bv_val, (long) nvals );
587 return LDAP_INVALID_SYNTAX;
591 ber_memfree_x( ml->sml_values[nvals].bv_val, ctx );
592 ml->sml_values[nvals] = pval;
595 ml->sml_values[nvals].bv_len = 0;
596 ml->sml_numvals = nvals;
599 * a rough single value check... an additional check is needed
600 * to catch add of single value to existing single valued attribute
602 if ((ml->sml_op == LDAP_MOD_ADD || ml->sml_op == LDAP_MOD_REPLACE)
603 && nvals > 1 && is_at_single_value( ad->ad_type ))
605 snprintf( textbuf, textlen,
606 "%s: multiple values provided",
607 ml->sml_type.bv_val );
609 return LDAP_CONSTRAINT_VIOLATION;
612 /* if the type has a normalizer, generate the
613 * normalized values. otherwise leave them NULL.
615 * this is different from the rule for attributes
616 * in an entry - in an attribute list, the normalized
617 * value is set equal to the non-normalized value
618 * when there is no normalizer.
620 if( nvals && ad->ad_type->sat_equality &&
621 ad->ad_type->sat_equality->smr_normalize )
623 ml->sml_nvalues = ber_memalloc_x(
624 (nvals+1)*sizeof(struct berval), ctx );
626 for ( nvals = 0; !BER_BVISNULL( &ml->sml_values[nvals] ); nvals++ ) {
627 rc = ordered_value_normalize(
628 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
630 ad->ad_type->sat_equality,
631 &ml->sml_values[nvals], &ml->sml_nvalues[nvals], ctx );
633 Debug( LDAP_DEBUG_ANY,
634 "<= str2entry NULL (ssyn_normalize %d)\n",
636 snprintf( textbuf, textlen,
637 "%s: value #%ld normalization failed",
638 ml->sml_type.bv_val, (long) nvals );
640 BER_BVZERO( &ml->sml_nvalues[nvals] );
645 BER_BVZERO( &ml->sml_nvalues[nvals] );
648 /* check for duplicates, but ignore Deletes.
650 if( nvals > 1 && ml->sml_op != LDAP_MOD_DELETE ) {
652 rc = slap_sort_vals( ml, text, &i, ctx );
653 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS ) {
654 /* value exists already */
655 snprintf( textbuf, textlen,
656 "%s: value #%d provided more than once",
657 ml->sml_desc->ad_cname.bv_val, i );
671 /* Sort a set of values. An (Attribute *) may be used interchangeably here
672 * instead of a (Modifications *) structure.
674 * Uses Quicksort + Insertion sort for small arrays
684 AttributeDescription *ad;
686 int istack[sizeof(int)*16];
687 int i, j, k, l, ir, jstack, match, *ix, itmp, nvals, rc = LDAP_SUCCESS;
689 struct berval a, *cv;
692 #define SWAP(a,b,tmp) tmp=(a);(a)=(b);(b)=tmp
693 #define COMP(a,b) match=0; rc = ordered_value_match( &match, \
694 ad, mr, SLAP_MR_EQUALITY \
695 | SLAP_MR_VALUE_OF_ASSERTION_SYNTAX \
696 | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH \
697 | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH, \
701 #define EXCH(x,y) SWAP(ix[x],ix[y],itmp)
702 #define SETA(x) itmp = ix[x]; a = cv[itmp]
703 #define GETA(x) ix[x] = itmp;
704 #define SET(x,y) ix[x] = ix[y]
707 nvals = ml->sml_numvals;
711 /* For Modifications, sml_nvalues is NULL if normalization wasn't needed.
712 * For Attributes, sml_nvalues == sml_values when normalization isn't needed.
714 if ( ml->sml_nvalues && ml->sml_nvalues != ml->sml_values ) {
715 cv = ml->sml_nvalues;
722 if ( ad == slap_schema.si_ad_objectClass )
723 mr = NULL; /* shortcut matching */
725 mr = ad->ad_type->sat_equality;
727 /* record indices to preserve input ordering */
728 ix = slap_sl_malloc( nvals * sizeof(int), ctx );
729 for (i=0; i<nvals; i++) ix[i] = i;
736 if (ir - l < SMALL) { /* Insertion sort */
738 for (j=l+1;j<=ir;j++) {
740 for (i=j-1;i>=0;i--) {
747 if ( match == 0 ) goto done;
749 if ( jstack == 0 ) break;
750 if ( match == 0 ) break;
751 ir = istack[jstack--];
752 l = istack[jstack--];
754 k = (l + ir) >> 1; /* Choose median of left, center, right */
756 COMP( cv[IX(l)], cv[IX(ir)] );
759 } else if ( match == 0 ) {
763 COMP( cv[IX(l+1)], cv[IX(ir)] );
766 } else if ( match == 0 ) {
770 COMP( cv[IX(l)], cv[IX(l+1)] );
773 } else if ( match == 0 ) {
783 COMP( cv[IX(i)], a );
784 } while( match < 0 );
787 COMP( cv[IX(j)], a );
805 istack[jstack-1] = i;
809 istack[jstack-1] = l;
815 if ( match == 0 && i >= 0 )
818 /* For sorted attributes, put the values in index order */
819 if ( rc == LDAP_SUCCESS && match &&
820 ( ad->ad_type->sat_flags & SLAP_AT_SORTED_VAL )) {
821 BerVarray tmpv = slap_sl_malloc( sizeof( struct berval ) * nvals, ctx );
822 for ( i = 0; i<nvals; i++ )
824 for ( i = 0; i<nvals; i++ )
826 /* Check if the non-normalized array needs to move too */
829 for ( i = 0; i<nvals; i++ )
831 for ( i = 0; i<nvals; i++ )
834 slap_sl_free( tmpv, ctx );
837 slap_sl_free( ix, ctx );
839 if ( rc == LDAP_SUCCESS && match == 0 ) {
840 /* value exists already */
843 rc = LDAP_TYPE_OR_VALUE_EXISTS;
849 /* Enter with bv->bv_len = sizeof buffer, returns with
850 * actual length of string
852 void slap_timestamp( time_t *tm, struct berval *bv )
856 ldap_pvt_gmtime( tm, <m );
858 bv->bv_len = lutil_gentime( bv->bv_val, bv->bv_len, <m );
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_PVT_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 != SLAP_MOD_SOFTADD &&
882 (*modtail)->sml_op != SLAP_MOD_ADD_IF_NOT_PRESENT &&
883 (*modtail)->sml_op != LDAP_MOD_REPLACE )
888 if ( (*modtail)->sml_desc == slap_schema.si_ad_entryCSN )
890 csn = (*modtail)->sml_values[0];
893 } else if ( (*modtail)->sml_desc == slap_schema.si_ad_modifiersName )
897 } else if ( (*modtail)->sml_desc == slap_schema.si_ad_modifyTimestamp )
903 if ( BER_BVISEMPTY( &op->o_csn )) {
906 csn.bv_len = sizeof( csnbuf );
907 slap_get_csn( op, &csn, manage_ctxcsn );
910 if ( manage_ctxcsn ) {
911 slap_queue_csn( op, &csn );
919 ptr = ber_bvchr( &csn, '#' );
921 timestamp.bv_len = STRLENOF("YYYYMMDDHHMMSSZ");
922 AC_MEMCPY( timebuf, csn.bv_val, timestamp.bv_len );
923 timebuf[timestamp.bv_len-1] = 'Z';
924 timebuf[timestamp.bv_len] = '\0';
927 time_t now = slap_get_time();
929 timestamp.bv_len = sizeof(timebuf);
931 slap_timestamp( &now, ×tamp );
934 if ( BER_BVISEMPTY( &op->o_dn ) ) {
935 BER_BVSTR( &name, SLAPD_ANONYMOUS );
944 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
945 mod->sml_op = LDAP_MOD_REPLACE;
946 mod->sml_flags = SLAP_MOD_INTERNAL;
947 mod->sml_next = NULL;
948 BER_BVZERO( &mod->sml_type );
949 mod->sml_desc = slap_schema.si_ad_entryCSN;
950 mod->sml_numvals = 1;
951 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
952 ber_dupbv( &mod->sml_values[0], &csn );
953 BER_BVZERO( &mod->sml_values[1] );
954 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
955 mod->sml_nvalues = NULL;
958 modtail = &mod->sml_next;
962 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
963 mod->sml_op = LDAP_MOD_REPLACE;
964 mod->sml_flags = SLAP_MOD_INTERNAL;
965 mod->sml_next = NULL;
966 BER_BVZERO( &mod->sml_type );
967 mod->sml_desc = slap_schema.si_ad_modifiersName;
968 mod->sml_numvals = 1;
969 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
970 ber_dupbv( &mod->sml_values[0], &name );
971 BER_BVZERO( &mod->sml_values[1] );
972 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
974 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
975 ber_dupbv( &mod->sml_nvalues[0], &nname );
976 BER_BVZERO( &mod->sml_nvalues[1] );
977 assert( !BER_BVISNULL( &mod->sml_nvalues[0] ) );
979 modtail = &mod->sml_next;
983 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
984 mod->sml_op = LDAP_MOD_REPLACE;
985 mod->sml_flags = SLAP_MOD_INTERNAL;
986 mod->sml_next = NULL;
987 BER_BVZERO( &mod->sml_type );
988 mod->sml_desc = slap_schema.si_ad_modifyTimestamp;
989 mod->sml_numvals = 1;
990 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
991 ber_dupbv( &mod->sml_values[0], ×tamp );
992 BER_BVZERO( &mod->sml_values[1] );
993 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
994 mod->sml_nvalues = NULL;
996 modtail = &mod->sml_next;
1011 Modifications **modtail = &ms->rs_mods.rs_modlist;
1013 ms->rs_mods.rs_modlist = NULL;
1014 ms->rs_increment = 0;
1016 rs->sr_err = LDAP_SUCCESS;
1018 /* collect modifications & save for later */
1019 for ( tag = ber_first_element( ber, &len, &last );
1020 tag != LBER_DEFAULT;
1021 tag = ber_next_element( ber, &len, last ) )
1024 Modifications tmp, *mod;
1026 tmp.sml_nvalues = NULL;
1028 if ( ber_scanf( ber, "{e{m[W]}}", &mop,
1029 &tmp.sml_type, &tmp.sml_values ) == LBER_ERROR )
1031 rs->sr_text = "decoding modlist error";
1032 rs->sr_err = LDAP_PROTOCOL_ERROR;
1036 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
1039 mod->sml_type = tmp.sml_type;
1040 mod->sml_values = tmp.sml_values;
1041 mod->sml_nvalues = NULL;
1042 mod->sml_desc = NULL;
1043 mod->sml_next = NULL;
1048 if ( mod->sml_values == NULL ) {
1049 rs->sr_text = "modify/add operation requires values";
1050 rs->sr_err = LDAP_PROTOCOL_ERROR;
1056 case LDAP_MOD_DELETE:
1057 case LDAP_MOD_REPLACE:
1060 case LDAP_MOD_INCREMENT:
1061 if( op->o_protocol >= LDAP_VERSION3 ) {
1063 if ( mod->sml_values == NULL ) {
1064 rs->sr_text = "modify/increment operation requires value";
1065 rs->sr_err = LDAP_PROTOCOL_ERROR;
1069 if ( !BER_BVISNULL( &mod->sml_values[ 1 ] ) ) {
1070 rs->sr_text = "modify/increment operation requires single value";
1071 rs->sr_err = LDAP_PROTOCOL_ERROR;
1080 rs->sr_text = "unrecognized modify operation";
1081 rs->sr_err = LDAP_PROTOCOL_ERROR;
1085 modtail = &mod->sml_next;
1090 if ( rs->sr_err != LDAP_SUCCESS ) {
1091 slap_mods_free( ms->rs_mods.rs_modlist, 1 );
1092 ms->rs_mods.rs_modlist = NULL;
1093 ms->rs_increment = 0;