2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2010 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 );
88 if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
89 Debug( LDAP_DEBUG_ANY, "%s do_modify: get_ctrls failed\n",
90 op->o_log_prefix, 0, 0 );
94 rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn,
96 if( rs->sr_err != LDAP_SUCCESS ) {
97 Debug( LDAP_DEBUG_ANY, "%s do_modify: invalid dn (%s)\n",
98 op->o_log_prefix, dn.bv_val, 0 );
99 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
103 op->orm_no_opattrs = 0;
106 Debug( LDAP_DEBUG_ARGS, "%s modifications:\n",
107 op->o_log_prefix, 0, 0 );
109 for ( tmp = op->orm_modlist; tmp != NULL; tmp = tmp->sml_next ) {
110 Debug( LDAP_DEBUG_ARGS, "\t%s: %s\n",
111 tmp->sml_op == LDAP_MOD_ADD ? "add" :
112 (tmp->sml_op == LDAP_MOD_INCREMENT ? "increment" :
113 (tmp->sml_op == LDAP_MOD_DELETE ? "delete" :
114 "replace")), tmp->sml_type.bv_val, 0 );
116 if ( tmp->sml_values == NULL ) {
117 Debug( LDAP_DEBUG_ARGS, "%s\n",
118 "\t\tno values", NULL, NULL );
119 } else if ( BER_BVISNULL( &tmp->sml_values[ 0 ] ) ) {
120 Debug( LDAP_DEBUG_ARGS, "%s\n",
121 "\t\tzero values", NULL, NULL );
122 } else if ( BER_BVISNULL( &tmp->sml_values[ 1 ] ) ) {
123 Debug( LDAP_DEBUG_ARGS, "%s, length %ld\n",
124 "\t\tone value", (long) tmp->sml_values[0].bv_len, NULL );
126 Debug( LDAP_DEBUG_ARGS, "%s\n",
127 "\t\tmultiple values", NULL, NULL );
131 if ( StatslogTest( LDAP_DEBUG_STATS ) ) {
132 char abuf[BUFSIZ/2], *ptr = abuf;
135 Statslog( LDAP_DEBUG_STATS, "%s MOD dn=\"%s\"\n",
136 op->o_log_prefix, op->o_req_dn.bv_val, 0, 0, 0 );
138 for ( tmp = op->orm_modlist; tmp != NULL; tmp = tmp->sml_next ) {
139 if (len + 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
140 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
141 op->o_log_prefix, abuf, 0, 0, 0 );
146 if( 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
147 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
148 op->o_log_prefix, tmp->sml_type.bv_val, 0, 0, 0 );
156 ptr = lutil_strcopy(ptr, tmp->sml_type.bv_val);
157 len += tmp->sml_type.bv_len;
160 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
161 op->o_log_prefix, abuf, 0, 0, 0 );
164 #endif /* LDAP_DEBUG */
166 rs->sr_err = slap_mods_check( op, op->orm_modlist,
167 &rs->sr_text, textbuf, textlen, NULL );
169 if ( rs->sr_err != LDAP_SUCCESS ) {
170 send_ldap_result( op, rs );
174 op->o_bd = frontendDB;
175 rs->sr_err = frontendDB->be_modify( op, rs );
178 if( rs->sr_err == LDAP_X_TXN_SPECIFY_OKAY ) {
185 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
186 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
187 if ( op->orm_modlist != NULL ) slap_mods_free( op->orm_modlist, 1 );
193 fe_op_modify( Operation *op, SlapReply *rs )
195 BackendDB *op_be, *bd = op->o_bd;
196 char textbuf[ SLAP_TEXT_BUFLEN ];
197 size_t textlen = sizeof( textbuf );
199 if ( BER_BVISEMPTY( &op->o_req_ndn ) ) {
200 Debug( LDAP_DEBUG_ANY, "%s do_modify: root dse!\n",
201 op->o_log_prefix, 0, 0 );
202 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
203 "modify upon the root DSE not supported" );
206 } else if ( bvmatch( &op->o_req_ndn, &frontendDB->be_schemandn ) ) {
207 Debug( LDAP_DEBUG_ANY, "%s do_modify: subschema subentry!\n",
208 op->o_log_prefix, 0, 0 );
209 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
210 "modification of subschema subentry not supported" );
215 * We could be serving multiple database backends. Select the
216 * appropriate one, or send a referral to our "referral server"
217 * if we don't hold it.
219 op->o_bd = select_backend( &op->o_req_ndn, 1 );
220 if ( op->o_bd == NULL ) {
222 rs->sr_ref = referral_rewrite( default_referral,
223 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
225 rs->sr_ref = default_referral;
228 if ( rs->sr_ref != NULL ) {
229 rs->sr_err = LDAP_REFERRAL;
230 send_ldap_result( op, rs );
232 if ( rs->sr_ref != default_referral ) {
233 ber_bvarray_free( rs->sr_ref );
237 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
238 "no global superior knowledge" );
243 /* If we've got a glued backend, check the real backend */
245 if ( SLAP_GLUE_INSTANCE( op->o_bd )) {
246 op->o_bd = select_backend( &op->o_req_ndn, 0 );
249 /* check restrictions */
250 if ( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
251 send_ldap_result( op, rs );
255 /* check for referrals */
256 if ( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
260 rs->sr_err = slap_mods_obsolete_check( op, op->orm_modlist,
261 &rs->sr_text, textbuf, textlen );
262 if ( rs->sr_err != LDAP_SUCCESS ) {
263 send_ldap_result( op, rs );
267 /* check for modify/increment support */
268 if ( op->orm_increment && !SLAP_INCREMENT( op->o_bd ) ) {
269 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
270 "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 ( ml->sml_flags & SLAP_MOD_INTERNAL ) {
391 if ( get_relax( op ) ) {
392 if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_MANAGEABLE ) {
393 ml->sml_flags |= SLAP_MOD_MANAGING;
397 /* attribute not manageable */
398 snprintf( textbuf, textlen,
399 "%s: no-user-modification attribute not manageable",
400 ml->sml_type.bv_val );
403 /* user modification disallowed */
404 snprintf( textbuf, textlen,
405 "%s: no user modification allowed",
406 ml->sml_type.bv_val );
410 return LDAP_CONSTRAINT_VIOLATION;
417 slap_mods_no_repl_user_mod_check(
427 for ( mods = ml; mods != NULL; mods = mods->sml_next ) {
428 assert( mods->sml_op == LDAP_MOD_ADD );
430 /* check doesn't already appear */
431 for ( modp = ml; modp != NULL; modp = modp->sml_next ) {
432 if ( mods->sml_desc == modp->sml_desc && mods != modp ) {
433 snprintf( textbuf, textlen,
434 "attribute '%s' provided more than once",
435 mods->sml_desc->ad_cname.bv_val );
437 return LDAP_TYPE_OR_VALUE_EXISTS;
446 * Do basic attribute type checking and syntax validation.
458 for( ; ml != NULL; ml = ml->sml_next ) {
459 AttributeDescription *ad = NULL;
461 /* convert to attribute description */
462 if ( ml->sml_desc == NULL ) {
463 rc = slap_bv2ad( &ml->sml_type, &ml->sml_desc, text );
464 if( rc != LDAP_SUCCESS ) {
465 if ( get_no_schema_check( op )) {
466 rc = slap_bv2undef_ad( &ml->sml_type, &ml->sml_desc,
470 if( rc != LDAP_SUCCESS ) {
471 snprintf( textbuf, textlen, "%s: %s",
472 ml->sml_type.bv_val, *text );
480 if( slap_syntax_is_binary( ad->ad_type->sat_syntax )
481 && !slap_ad_is_binary( ad ))
483 /* attribute requires binary transfer */
484 snprintf( textbuf, textlen,
485 "%s: requires ;binary transfer",
486 ml->sml_type.bv_val );
488 return LDAP_UNDEFINED_TYPE;
491 if( !slap_syntax_is_binary( ad->ad_type->sat_syntax )
492 && slap_ad_is_binary( ad ))
494 /* attribute does not require binary transfer */
495 snprintf( textbuf, textlen,
496 "%s: disallows ;binary transfer",
497 ml->sml_type.bv_val );
499 return LDAP_UNDEFINED_TYPE;
502 if( slap_ad_is_tag_range( ad )) {
503 /* attribute requires binary transfer */
504 snprintf( textbuf, textlen,
505 "%s: inappropriate use of tag range option",
506 ml->sml_type.bv_val );
508 return LDAP_UNDEFINED_TYPE;
512 if ( is_at_obsolete( ad->ad_type ) &&
513 (( ml->sml_op != LDAP_MOD_REPLACE &&
514 ml->sml_op != LDAP_MOD_DELETE ) ||
515 ml->sml_values != NULL ))
518 * attribute is obsolete,
519 * only allow replace/delete with no values
521 snprintf( textbuf, textlen,
522 "%s: attribute is obsolete",
523 ml->sml_type.bv_val );
525 return LDAP_CONSTRAINT_VIOLATION;
529 if ( ml->sml_op == LDAP_MOD_INCREMENT &&
530 #ifdef SLAPD_REAL_SYNTAX
531 !is_at_syntax( ad->ad_type, SLAPD_REAL_SYNTAX ) &&
533 !is_at_syntax( ad->ad_type, SLAPD_INTEGER_SYNTAX ) )
536 * attribute values must be INTEGER or REAL
538 snprintf( textbuf, textlen,
539 "%s: attribute syntax inappropriate for increment",
540 ml->sml_type.bv_val );
542 return LDAP_CONSTRAINT_VIOLATION;
548 if( ml->sml_values != NULL ) {
550 slap_syntax_validate_func *validate =
551 ad->ad_type->sat_syntax->ssyn_validate;
552 slap_syntax_transform_func *pretty =
553 ad->ad_type->sat_syntax->ssyn_pretty;
555 if( !pretty && !validate ) {
556 *text = "no validator for syntax";
557 snprintf( textbuf, textlen,
558 "%s: no validator for syntax %s",
560 ad->ad_type->sat_syntax->ssyn_oid );
562 return LDAP_INVALID_SYNTAX;
566 * check that each value is valid per syntax
567 * and pretty if appropriate
569 for ( nvals = 0; !BER_BVISNULL( &ml->sml_values[nvals] ); nvals++ ) {
573 rc = ordered_value_pretty( ad,
574 &ml->sml_values[nvals], &pval, ctx );
576 rc = ordered_value_validate( ad,
577 &ml->sml_values[nvals], ml->sml_op );
581 snprintf( textbuf, textlen,
582 "%s: value #%ld invalid per syntax",
583 ml->sml_type.bv_val, (long) nvals );
585 return LDAP_INVALID_SYNTAX;
589 ber_memfree_x( ml->sml_values[nvals].bv_val, ctx );
590 ml->sml_values[nvals] = pval;
593 ml->sml_values[nvals].bv_len = 0;
594 ml->sml_numvals = nvals;
597 * a rough single value check... an additional check is needed
598 * to catch add of single value to existing single valued attribute
600 if ((ml->sml_op == LDAP_MOD_ADD || ml->sml_op == LDAP_MOD_REPLACE)
601 && nvals > 1 && is_at_single_value( ad->ad_type ))
603 snprintf( textbuf, textlen,
604 "%s: multiple values provided",
605 ml->sml_type.bv_val );
607 return LDAP_CONSTRAINT_VIOLATION;
610 /* if the type has a normalizer, generate the
611 * normalized values. otherwise leave them NULL.
613 * this is different from the rule for attributes
614 * in an entry - in an attribute list, the normalized
615 * value is set equal to the non-normalized value
616 * when there is no normalizer.
618 if( nvals && ad->ad_type->sat_equality &&
619 ad->ad_type->sat_equality->smr_normalize )
621 ml->sml_nvalues = ber_memalloc_x(
622 (nvals+1)*sizeof(struct berval), ctx );
624 for ( nvals = 0; !BER_BVISNULL( &ml->sml_values[nvals] ); nvals++ ) {
625 rc = ordered_value_normalize(
626 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
628 ad->ad_type->sat_equality,
629 &ml->sml_values[nvals], &ml->sml_nvalues[nvals], ctx );
631 Debug( LDAP_DEBUG_ANY,
632 "<= str2entry NULL (ssyn_normalize %d)\n",
634 snprintf( textbuf, textlen,
635 "%s: value #%ld normalization failed",
636 ml->sml_type.bv_val, (long) nvals );
638 BER_BVZERO( &ml->sml_nvalues[nvals] );
643 BER_BVZERO( &ml->sml_nvalues[nvals] );
646 /* check for duplicates, but ignore Deletes.
648 if( nvals > 1 && ml->sml_op != LDAP_MOD_DELETE ) {
650 rc = slap_sort_vals( ml, text, &i, ctx );
651 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS ) {
652 /* value exists already */
653 snprintf( textbuf, textlen,
654 "%s: value #%d provided more than once",
655 ml->sml_desc->ad_cname.bv_val, i );
669 /* Sort a set of values. An (Attribute *) may be used interchangeably here
670 * instead of a (Modifications *) structure.
672 * Uses Quicksort + Insertion sort for small arrays
682 AttributeDescription *ad;
684 int istack[sizeof(int)*16];
685 int i, j, k, l, ir, jstack, match, *ix, itmp, nvals, rc;
687 struct berval a, *cv;
690 #define SWAP(a,b,tmp) tmp=(a);(a)=(b);(b)=tmp
691 #define COMP(a,b) match=0; rc = ordered_value_match( &match, \
692 ad, mr, SLAP_MR_EQUALITY \
693 | SLAP_MR_VALUE_OF_ASSERTION_SYNTAX \
694 | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH \
695 | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH, \
699 #define EXCH(x,y) SWAP(ix[x],ix[y],itmp)
700 #define SETA(x) itmp = ix[x]; a = cv[itmp]
701 #define GETA(x) ix[x] = itmp;
702 #define SET(x,y) ix[x] = ix[y]
705 nvals = ml->sml_numvals;
707 /* For Modifications, sml_nvalues is NULL if normalization wasn't needed.
708 * For Attributes, sml_nvalues == sml_values when normalization isn't needed.
710 if ( ml->sml_nvalues && ml->sml_nvalues != ml->sml_values ) {
711 cv = ml->sml_nvalues;
718 if ( ad == slap_schema.si_ad_objectClass )
719 mr = NULL; /* shortcut matching */
721 mr = ad->ad_type->sat_equality;
723 /* record indices to preserve input ordering */
724 ix = slap_sl_malloc( nvals * sizeof(int), ctx );
725 for (i=0; i<nvals; i++) ix[i] = i;
732 if (ir - l < SMALL) { /* Insertion sort */
734 for (j=l+1;j<=ir;j++) {
736 for (i=j-1;i>=0;i--) {
743 if ( match == 0 ) goto done;
745 if ( jstack == 0 ) break;
746 if ( match == 0 ) break;
747 ir = istack[jstack--];
748 l = istack[jstack--];
750 k = (l + ir) >> 1; /* Choose median of left, center, right */
752 COMP( cv[IX(l)], cv[IX(ir)] );
755 } else if ( match == 0 ) {
759 COMP( cv[IX(l+1)], cv[IX(ir)] );
762 } else if ( match == 0 ) {
766 COMP( cv[IX(l)], cv[IX(l+1)] );
769 } else if ( match == 0 ) {
779 COMP( cv[IX(i)], a );
780 } while( match < 0 );
783 COMP( cv[IX(j)], a );
801 istack[jstack-1] = i;
805 istack[jstack-1] = l;
811 if ( match == 0 && i >= 0 )
814 /* For sorted attributes, put the values in index order */
815 if ( rc == LDAP_SUCCESS && match &&
816 ( ad->ad_type->sat_flags & SLAP_AT_SORTED_VAL )) {
817 BerVarray tmpv = slap_sl_malloc( sizeof( struct berval ) * nvals, ctx );
818 for ( i = 0; i<nvals; i++ )
820 for ( i = 0; i<nvals; i++ )
822 /* Check if the non-normalized array needs to move too */
825 for ( i = 0; i<nvals; i++ )
827 for ( i = 0; i<nvals; i++ )
830 slap_sl_free( tmpv, ctx );
833 slap_sl_free( ix, ctx );
835 if ( rc != LDAP_SUCCESS ) {
837 } else if ( match == 0 ) {
838 /* value exists already */
841 return LDAP_TYPE_OR_VALUE_EXISTS;
846 /* Enter with bv->bv_len = sizeof buffer, returns with
847 * actual length of string
849 void slap_timestamp( time_t *tm, struct berval *bv )
855 ltm = gmtime_r( tm, <m_buf );
857 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
861 bv->bv_len = lutil_gentime( bv->bv_val, bv->bv_len, ltm );
863 #ifndef HAVE_GMTIME_R
864 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
868 /* Called for all modify and modrdn ops. If the current op was replicated
869 * from elsewhere, all of the attrs should already be present.
871 void slap_mods_opattrs(
873 Modifications **modsp,
876 struct berval name, timestamp, csn = BER_BVNULL;
878 char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
879 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
880 Modifications *mod, **modtail, *modlast;
881 int gotcsn = 0, gotmname = 0, gotmtime = 0;
883 if ( SLAP_LASTMOD( op->o_bd ) && !op->orm_no_opattrs ) {
885 timestamp.bv_val = timebuf;
886 for ( modtail = modsp; *modtail; modtail = &(*modtail)->sml_next ) {
887 if ( (*modtail)->sml_op != LDAP_MOD_ADD &&
888 (*modtail)->sml_op != SLAP_MOD_SOFTADD &&
889 (*modtail)->sml_op != LDAP_MOD_REPLACE )
894 if ( (*modtail)->sml_desc == slap_schema.si_ad_entryCSN )
896 csn = (*modtail)->sml_values[0];
899 } else if ( (*modtail)->sml_desc == slap_schema.si_ad_modifiersName )
903 } else if ( (*modtail)->sml_desc == slap_schema.si_ad_modifyTimestamp )
909 if ( BER_BVISEMPTY( &op->o_csn )) {
912 csn.bv_len = sizeof( csnbuf );
913 slap_get_csn( op, &csn, manage_ctxcsn );
916 if ( manage_ctxcsn ) {
917 slap_queue_csn( op, &csn );
925 ptr = ber_bvchr( &csn, '#' );
927 timestamp.bv_len = STRLENOF("YYYYMMDDHHMMSSZ");
928 AC_MEMCPY( timebuf, csn.bv_val, timestamp.bv_len );
929 timebuf[timestamp.bv_len-1] = 'Z';
930 timebuf[timestamp.bv_len] = '\0';
933 time_t now = slap_get_time();
935 timestamp.bv_len = sizeof(timebuf);
937 slap_timestamp( &now, ×tamp );
940 if ( BER_BVISEMPTY( &op->o_dn ) ) {
941 BER_BVSTR( &name, SLAPD_ANONYMOUS );
950 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
951 mod->sml_op = LDAP_MOD_REPLACE;
952 mod->sml_flags = SLAP_MOD_INTERNAL;
953 mod->sml_next = NULL;
954 BER_BVZERO( &mod->sml_type );
955 mod->sml_desc = slap_schema.si_ad_entryCSN;
956 mod->sml_numvals = 1;
957 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
958 ber_dupbv( &mod->sml_values[0], &csn );
959 BER_BVZERO( &mod->sml_values[1] );
960 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
961 mod->sml_nvalues = NULL;
964 modtail = &mod->sml_next;
968 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
969 mod->sml_op = LDAP_MOD_REPLACE;
970 mod->sml_flags = SLAP_MOD_INTERNAL;
971 mod->sml_next = NULL;
972 BER_BVZERO( &mod->sml_type );
973 mod->sml_desc = slap_schema.si_ad_modifiersName;
974 mod->sml_numvals = 1;
975 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
976 ber_dupbv( &mod->sml_values[0], &name );
977 BER_BVZERO( &mod->sml_values[1] );
978 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
980 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
981 ber_dupbv( &mod->sml_nvalues[0], &nname );
982 BER_BVZERO( &mod->sml_nvalues[1] );
983 assert( !BER_BVISNULL( &mod->sml_nvalues[0] ) );
985 modtail = &mod->sml_next;
989 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
990 mod->sml_op = LDAP_MOD_REPLACE;
991 mod->sml_flags = SLAP_MOD_INTERNAL;
992 mod->sml_next = NULL;
993 BER_BVZERO( &mod->sml_type );
994 mod->sml_desc = slap_schema.si_ad_modifyTimestamp;
995 mod->sml_numvals = 1;
996 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
997 ber_dupbv( &mod->sml_values[0], ×tamp );
998 BER_BVZERO( &mod->sml_values[1] );
999 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
1000 mod->sml_nvalues = NULL;
1002 modtail = &mod->sml_next;
1017 Modifications **modtail = &ms->rs_mods.rs_modlist;
1019 ms->rs_mods.rs_modlist = NULL;
1020 ms->rs_increment = 0;
1022 rs->sr_err = LDAP_SUCCESS;
1024 /* collect modifications & save for later */
1025 for ( tag = ber_first_element( ber, &len, &last );
1026 tag != LBER_DEFAULT;
1027 tag = ber_next_element( ber, &len, last ) )
1030 Modifications tmp, *mod;
1032 tmp.sml_nvalues = NULL;
1034 if ( ber_scanf( ber, "{e{m[W]}}", &mop,
1035 &tmp.sml_type, &tmp.sml_values ) == LBER_ERROR )
1037 rs->sr_text = "decoding modlist error";
1038 rs->sr_err = LDAP_PROTOCOL_ERROR;
1042 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
1045 mod->sml_type = tmp.sml_type;
1046 mod->sml_values = tmp.sml_values;
1047 mod->sml_nvalues = NULL;
1048 mod->sml_desc = NULL;
1049 mod->sml_next = NULL;
1054 if ( mod->sml_values == NULL ) {
1055 rs->sr_text = "modify/add operation requires values";
1056 rs->sr_err = LDAP_PROTOCOL_ERROR;
1062 case LDAP_MOD_DELETE:
1063 case LDAP_MOD_REPLACE:
1066 case LDAP_MOD_INCREMENT:
1067 if( op->o_protocol >= LDAP_VERSION3 ) {
1069 if ( mod->sml_values == NULL ) {
1070 rs->sr_text = "modify/increment operation requires value";
1071 rs->sr_err = LDAP_PROTOCOL_ERROR;
1075 if ( !BER_BVISNULL( &mod->sml_values[ 1 ] ) ) {
1076 rs->sr_text = "modify/increment operation requires single value";
1077 rs->sr_err = LDAP_PROTOCOL_ERROR;
1086 rs->sr_text = "unrecognized modify operation";
1087 rs->sr_err = LDAP_PROTOCOL_ERROR;
1091 modtail = &mod->sml_next;
1096 if ( rs->sr_err != LDAP_SUCCESS ) {
1097 slap_mods_free( ms->rs_mods.rs_modlist, 1 );
1098 ms->rs_mods.rs_modlist = NULL;
1099 ms->rs_increment = 0;