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 rs->sr_err = slap_mods_check( op, op->orm_modlist,
99 &rs->sr_text, textbuf, textlen, NULL );
101 if ( rs->sr_err != LDAP_SUCCESS ) {
102 send_ldap_result( op, rs );
106 op->o_bd = frontendDB;
107 rs->sr_err = frontendDB->be_modify( op, rs );
110 if( rs->sr_err == LDAP_X_TXN_SPECIFY_OKAY ) {
117 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
118 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
119 if ( op->orm_modlist != NULL ) slap_mods_free( op->orm_modlist, 1 );
125 fe_op_modify( Operation *op, SlapReply *rs )
131 BackendDB *op_be, *bd = op->o_bd;
132 char textbuf[ SLAP_TEXT_BUFLEN ];
133 size_t textlen = sizeof( textbuf );
135 if ( BER_BVISEMPTY( &op->o_req_ndn ) ) {
136 Debug( LDAP_DEBUG_ANY, "do_modify: root dse!\n", 0, 0, 0 );
138 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
139 "modify upon the root DSE not supported" );
142 } else if ( bvmatch( &op->o_req_ndn, &frontendDB->be_schemandn ) ) {
143 Debug( LDAP_DEBUG_ANY, "do_modify: subschema subentry!\n", 0, 0, 0 );
145 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
146 "modification of subschema subentry not supported" );
151 Debug( LDAP_DEBUG_ARGS, "modifications:\n", 0, 0, 0 );
153 for ( tmp = op->orm_modlist; tmp != NULL; tmp = tmp->sml_next ) {
154 Debug( LDAP_DEBUG_ARGS, "\t%s: %s\n",
155 tmp->sml_op == LDAP_MOD_ADD ? "add" :
156 (tmp->sml_op == LDAP_MOD_INCREMENT ? "increment" :
157 (tmp->sml_op == LDAP_MOD_DELETE ? "delete" :
158 "replace")), tmp->sml_type.bv_val, 0 );
160 if ( tmp->sml_values == NULL ) {
161 Debug( LDAP_DEBUG_ARGS, "%s\n",
162 "\t\tno values", NULL, NULL );
163 } else if ( BER_BVISNULL( &tmp->sml_values[ 0 ] ) ) {
164 Debug( LDAP_DEBUG_ARGS, "%s\n",
165 "\t\tzero values", NULL, NULL );
166 } else if ( BER_BVISNULL( &tmp->sml_values[ 1 ] ) ) {
167 Debug( LDAP_DEBUG_ARGS, "%s, length %ld\n",
168 "\t\tone value", (long) tmp->sml_values[0].bv_len, NULL );
170 Debug( LDAP_DEBUG_ARGS, "%s\n",
171 "\t\tmultiple values", NULL, NULL );
175 if ( StatslogTest( LDAP_DEBUG_STATS ) ) {
176 char abuf[BUFSIZ/2], *ptr = abuf;
179 Statslog( LDAP_DEBUG_STATS, "%s MOD dn=\"%s\"\n",
180 op->o_log_prefix, op->o_req_dn.bv_val, 0, 0, 0 );
182 for ( tmp = op->orm_modlist; tmp != NULL; tmp = tmp->sml_next ) {
183 if (len + 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
184 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
185 op->o_log_prefix, abuf, 0, 0, 0 );
190 if( 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
191 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
192 op->o_log_prefix, tmp->sml_type.bv_val, 0, 0, 0 );
200 ptr = lutil_strcopy(ptr, tmp->sml_type.bv_val);
201 len += tmp->sml_type.bv_len;
204 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
205 op->o_log_prefix, abuf, 0, 0, 0 );
208 #endif /* LDAP_DEBUG */
210 manageDSAit = get_manageDSAit( op );
213 * We could be serving multiple database backends. Select the
214 * appropriate one, or send a referral to our "referral server"
215 * if we don't hold it.
217 op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 1 );
218 if ( op->o_bd == NULL ) {
220 rs->sr_ref = referral_rewrite( default_referral,
221 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
223 rs->sr_ref = default_referral;
226 if ( rs->sr_ref != NULL ) {
227 rs->sr_err = LDAP_REFERRAL;
228 send_ldap_result( op, rs );
230 if ( rs->sr_ref != default_referral ) {
231 ber_bvarray_free( rs->sr_ref );
235 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
236 "no global superior knowledge" );
241 /* If we've got a glued backend, check the real backend */
243 if ( SLAP_GLUE_INSTANCE( op->o_bd )) {
244 op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 0 );
247 /* check restrictions */
248 if ( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
249 send_ldap_result( op, rs );
253 /* check for referrals */
254 if ( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
258 rs->sr_err = slap_mods_obsolete_check( op, op->orm_modlist,
259 &rs->sr_text, textbuf, textlen );
260 if ( rs->sr_err != LDAP_SUCCESS ) {
261 send_ldap_result( op, rs );
265 /* check for modify/increment support */
266 if ( op->orm_increment && !SLAP_INCREMENT( op->o_bd ) ) {
267 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
268 "modify/increment not supported in context" );
272 * do the modify if 1 && (2 || 3)
273 * 1) there is a modify function implemented in this backend;
274 * 2) this backend is master for what it holds;
275 * 3) it's a replica and the dn supplied is the update_ndn.
277 if ( op->o_bd->be_modify ) {
278 /* do the update here */
279 int repl_user = be_isupdate( op );
282 * Multimaster slapd does not have to check for replicator dn
283 * because it accepts each modify request
285 if ( !SLAP_SINGLE_SHADOW(op->o_bd) || repl_user ) {
286 int update = !BER_BVISEMPTY( &op->o_bd->be_update_ndn );
291 rs->sr_err = slap_mods_no_user_mod_check( op, op->orm_modlist,
292 &rs->sr_text, textbuf, textlen );
293 if ( rs->sr_err != LDAP_SUCCESS ) {
294 send_ldap_result( op, rs );
298 op->o_bd->be_modify( op, rs );
300 } else { /* send a referral */
301 BerVarray defref = op->o_bd->be_update_refs
302 ? op->o_bd->be_update_refs : default_referral;
303 if ( defref != NULL ) {
304 rs->sr_ref = referral_rewrite( defref,
306 LDAP_SCOPE_DEFAULT );
307 if ( rs->sr_ref == NULL ) {
308 /* FIXME: must duplicate, because
309 * overlays may muck with it */
312 rs->sr_err = LDAP_REFERRAL;
313 send_ldap_result( op, rs );
314 if ( rs->sr_ref != defref ) {
315 ber_bvarray_free( rs->sr_ref );
319 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
320 "shadow context; no update referral" );
325 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
326 "operation not supported within namingContext" );
335 * Obsolete constraint checking.
338 slap_mods_obsolete_check(
345 if( get_relax( op ) ) return LDAP_SUCCESS;
347 for ( ; ml != NULL; ml = ml->sml_next ) {
348 if ( is_at_obsolete( ml->sml_desc->ad_type ) &&
349 (( ml->sml_op != LDAP_MOD_REPLACE &&
350 ml->sml_op != LDAP_MOD_DELETE ) ||
351 ml->sml_values != NULL ))
354 * attribute is obsolete,
355 * only allow replace/delete with no values
357 snprintf( textbuf, textlen,
358 "%s: attribute is obsolete",
359 ml->sml_type.bv_val );
361 return LDAP_CONSTRAINT_VIOLATION;
369 * No-user-modification constraint checking.
372 slap_mods_no_user_mod_check(
379 for ( ; ml != NULL; ml = ml->sml_next ) {
380 if ( !is_at_no_user_mod( ml->sml_desc->ad_type ) ) {
384 if ( get_relax( op ) ) {
385 if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_MANAGEABLE ) {
386 ml->sml_flags |= SLAP_MOD_MANAGING;
390 /* attribute not manageable */
391 snprintf( textbuf, textlen,
392 "%s: no-user-modification attribute not manageable",
393 ml->sml_type.bv_val );
396 /* user modification disallowed */
397 snprintf( textbuf, textlen,
398 "%s: no user modification allowed",
399 ml->sml_type.bv_val );
403 return LDAP_CONSTRAINT_VIOLATION;
410 slap_mods_no_repl_user_mod_check(
420 for ( mods = ml; mods != NULL; mods = mods->sml_next ) {
421 assert( mods->sml_op == LDAP_MOD_ADD );
423 /* check doesn't already appear */
424 for ( modp = ml; modp != NULL; modp = modp->sml_next ) {
425 if ( mods->sml_desc == modp->sml_desc && mods != modp ) {
426 snprintf( textbuf, textlen,
427 "attribute '%s' provided more than once",
428 mods->sml_desc->ad_cname.bv_val );
430 return LDAP_TYPE_OR_VALUE_EXISTS;
439 * Do basic attribute type checking and syntax validation.
451 for( ; ml != NULL; ml = ml->sml_next ) {
452 AttributeDescription *ad = NULL;
454 /* convert to attribute description */
455 if ( ml->sml_desc == NULL ) {
456 rc = slap_bv2ad( &ml->sml_type, &ml->sml_desc, text );
457 if( rc != LDAP_SUCCESS ) {
458 if ( get_no_schema_check( op )) {
459 rc = slap_bv2undef_ad( &ml->sml_type, &ml->sml_desc,
463 if( rc != LDAP_SUCCESS ) {
464 snprintf( textbuf, textlen, "%s: %s",
465 ml->sml_type.bv_val, *text );
473 if( slap_syntax_is_binary( ad->ad_type->sat_syntax )
474 && !slap_ad_is_binary( ad ))
476 /* attribute requires binary transfer */
477 snprintf( textbuf, textlen,
478 "%s: requires ;binary transfer",
479 ml->sml_type.bv_val );
481 return LDAP_UNDEFINED_TYPE;
484 if( !slap_syntax_is_binary( ad->ad_type->sat_syntax )
485 && slap_ad_is_binary( ad ))
487 /* attribute does not require binary transfer */
488 snprintf( textbuf, textlen,
489 "%s: disallows ;binary transfer",
490 ml->sml_type.bv_val );
492 return LDAP_UNDEFINED_TYPE;
495 if( slap_ad_is_tag_range( ad )) {
496 /* attribute requires binary transfer */
497 snprintf( textbuf, textlen,
498 "%s: inappropriate use of tag range option",
499 ml->sml_type.bv_val );
501 return LDAP_UNDEFINED_TYPE;
505 if ( is_at_obsolete( ad->ad_type ) &&
506 (( ml->sml_op != LDAP_MOD_REPLACE &&
507 ml->sml_op != LDAP_MOD_DELETE ) ||
508 ml->sml_values != NULL ))
511 * attribute is obsolete,
512 * only allow replace/delete with no values
514 snprintf( textbuf, textlen,
515 "%s: attribute is obsolete",
516 ml->sml_type.bv_val );
518 return LDAP_CONSTRAINT_VIOLATION;
522 if ( ml->sml_op == LDAP_MOD_INCREMENT &&
523 #ifdef SLAPD_REAL_SYNTAX
524 !is_at_syntax( ad->ad_type, SLAPD_REAL_SYNTAX ) &&
526 !is_at_syntax( ad->ad_type, SLAPD_INTEGER_SYNTAX ) )
529 * attribute values must be INTEGER or REAL
531 snprintf( textbuf, textlen,
532 "%s: attribute syntax inappropriate for increment",
533 ml->sml_type.bv_val );
535 return LDAP_CONSTRAINT_VIOLATION;
541 if( ml->sml_values != NULL ) {
543 slap_syntax_validate_func *validate =
544 ad->ad_type->sat_syntax->ssyn_validate;
545 slap_syntax_transform_func *pretty =
546 ad->ad_type->sat_syntax->ssyn_pretty;
548 if( !pretty && !validate ) {
549 *text = "no validator for syntax";
550 snprintf( textbuf, textlen,
551 "%s: no validator for syntax %s",
553 ad->ad_type->sat_syntax->ssyn_oid );
555 return LDAP_INVALID_SYNTAX;
559 * check that each value is valid per syntax
560 * and pretty if appropriate
562 for ( nvals = 0; !BER_BVISNULL( &ml->sml_values[nvals] ); nvals++ ) {
566 rc = ordered_value_pretty( ad,
567 &ml->sml_values[nvals], &pval, ctx );
569 rc = ordered_value_validate( ad,
570 &ml->sml_values[nvals], ml->sml_op );
574 snprintf( textbuf, textlen,
575 "%s: value #%ld invalid per syntax",
576 ml->sml_type.bv_val, (long) nvals );
578 return LDAP_INVALID_SYNTAX;
582 ber_memfree_x( ml->sml_values[nvals].bv_val, ctx );
583 ml->sml_values[nvals] = pval;
588 * a rough single value check... an additional check is needed
589 * to catch add of single value to existing single valued attribute
591 if ((ml->sml_op == LDAP_MOD_ADD || ml->sml_op == LDAP_MOD_REPLACE)
592 && nvals > 1 && is_at_single_value( ad->ad_type ))
594 snprintf( textbuf, textlen,
595 "%s: multiple values provided",
596 ml->sml_type.bv_val );
598 return LDAP_CONSTRAINT_VIOLATION;
601 /* if the type has a normalizer, generate the
602 * normalized values. otherwise leave them NULL.
604 * this is different from the rule for attributes
605 * in an entry - in an attribute list, the normalized
606 * value is set equal to the non-normalized value
607 * when there is no normalizer.
609 if( nvals && ad->ad_type->sat_equality &&
610 ad->ad_type->sat_equality->smr_normalize )
612 ml->sml_nvalues = ber_memalloc_x(
613 (nvals+1)*sizeof(struct berval), ctx );
615 for ( nvals = 0; !BER_BVISNULL( &ml->sml_values[nvals] ); nvals++ ) {
616 rc = ordered_value_normalize(
617 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
619 ad->ad_type->sat_equality,
620 &ml->sml_values[nvals], &ml->sml_nvalues[nvals], ctx );
622 Debug( LDAP_DEBUG_ANY,
623 "<= str2entry NULL (ssyn_normalize %d)\n",
625 snprintf( textbuf, textlen,
626 "%s: value #%ld normalization failed",
627 ml->sml_type.bv_val, (long) nvals );
633 BER_BVZERO( &ml->sml_nvalues[nvals] );
636 /* check for duplicates, but ignore Deletes.
638 if( nvals > 1 && ml->sml_op != LDAP_MOD_DELETE ) {
639 #define SLAP_MODS_CHECK_QUICKSORT
640 #ifndef SLAP_MODS_CHECK_QUICKSORT
642 MatchingRule *mr = ad->ad_type->sat_equality;
644 for ( i = 1; i < nvals ; i++ ) {
645 /* test asserted values against themselves */
646 for( j = 0; j < i; j++ ) {
647 rc = ordered_value_match( &match, ml->sml_desc, mr,
649 | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX
650 | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH
651 | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH,
653 ? &ml->sml_nvalues[i]
654 : &ml->sml_values[i],
656 ? &ml->sml_nvalues[j]
657 : &ml->sml_values[j],
659 if ( rc == LDAP_SUCCESS && match == 0 ) {
660 /* value exists already */
661 snprintf( textbuf, textlen,
662 "%s: value #%d provided more than once",
663 ml->sml_desc->ad_cname.bv_val, j );
665 return LDAP_TYPE_OR_VALUE_EXISTS;
667 } else if ( rc != LDAP_SUCCESS ) {
672 #else /* SLAP_MODS_CHECK_QUICKSORT */
674 /* Quicksort + Insertion sort for small arrays */
677 #define SWAP(a,b,tmp) tmp=(a);(a)=(b);(b)=tmp
678 #define COMP(a,b) match=0; rc = ordered_value_match( &match, \
679 ml->sml_desc, mr, SLAP_MR_EQUALITY \
680 | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX \
681 | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH \
682 | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH, \
685 MatchingRule *mr = ad->ad_type->sat_equality;
686 int istack[sizeof(int)*16];
687 int i, j, k, l, ir, jstack, match, *ix, itmp;
688 struct berval a, *cv;
690 /* If PRESERVE_ORDER is defined only the index array is sorted; the
691 * actual values are left in their incoming order. Otherwise, the
692 * only reason to keep the index array is to identify the offending
693 * value when duplicates are found.
695 #define PRESERVE_ORDER
696 #ifndef PRESERVE_ORDER
697 struct berval va, *v, *nv, bvtmp;
700 #define EXCH(x,y) SWAP(ix[x],ix[y],itmp); SWAP(cv[x],cv[y],bvtmp); \
701 if (nv) {SWAP(v[x],v[y],bvtmp);}
702 #define SETA(x) itmp = ix[x]; a = cv[x]; if (nv) va=v[x]
703 #define GETA(x) ix[x] = itmp; cv[x] = a; if (nv) v[x]=va
704 #define SET(x,y) ix[x] = ix[y]; cv[x] = cv[y]; if (nv) v[x]=v[y]
707 nv = ml->sml_nvalues;
709 #else /* PRESERVE_ORDER */
712 #define EXCH(x,y) SWAP(ix[x],ix[y],itmp)
713 #define SETA(x) itmp = ix[x]; a = cv[itmp]
714 #define GETA(x) ix[x] = itmp;
715 #define SET(x,y) ix[x] = ix[y]
717 #endif /* PRESERVE_ORDER */
719 cv = ml->sml_nvalues ? ml->sml_nvalues : ml->sml_values;
720 if ( ad == slap_schema.si_ad_objectClass )
721 mr = NULL; /* shortcut matching */
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;
814 slap_sl_free( ix, ctx );
816 if ( rc != LDAP_SUCCESS ) {
818 } else if ( match == 0 ) {
819 /* value exists already */
822 snprintf( textbuf, textlen,
823 "%s: value #%d provided more than once",
824 ml->sml_desc->ad_cname.bv_val, j );
826 return LDAP_TYPE_OR_VALUE_EXISTS;
828 #endif /* SLAP_MODS_CHECK_QUICKSORT */
836 /* Enter with bv->bv_len = sizeof buffer, returns with
837 * actual length of string
839 void slap_timestamp( time_t *tm, struct berval *bv )
845 ltm = gmtime_r( tm, <m_buf );
847 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
851 bv->bv_len = lutil_gentime( bv->bv_val, bv->bv_len, ltm );
853 #ifndef HAVE_GMTIME_R
854 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
858 /* Called for all modify and modrdn ops. If the current op was replicated
859 * from elsewhere, all of the attrs should already be present.
861 void slap_mods_opattrs(
863 Modifications **modsp,
866 struct berval name, timestamp, csn = BER_BVNULL;
868 char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
869 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
870 Modifications *mod, **modtail, *modlast;
871 int gotcsn = 0, gotmname = 0, gotmtime = 0;
873 if ( SLAP_LASTMOD( op->o_bd ) && !op->orm_no_opattrs ) {
875 timestamp.bv_val = timebuf;
876 for ( modtail = modsp; *modtail; modtail = &(*modtail)->sml_next ) {
877 if ( (*modtail)->sml_op != LDAP_MOD_ADD &&
878 (*modtail)->sml_op != LDAP_MOD_REPLACE )
883 if ( (*modtail)->sml_desc == slap_schema.si_ad_entryCSN )
885 csn = (*modtail)->sml_values[0];
888 } else if ( (*modtail)->sml_desc == slap_schema.si_ad_modifiersName )
892 } else if ( (*modtail)->sml_desc == slap_schema.si_ad_modifyTimestamp )
898 if ( BER_BVISEMPTY( &op->o_csn )) {
901 csn.bv_len = sizeof( csnbuf );
902 slap_get_csn( op, &csn, manage_ctxcsn );
905 if ( manage_ctxcsn ) {
906 slap_queue_csn( op, &csn );
914 ptr = ber_bvchr( &csn, '#' );
916 timestamp.bv_len = STRLENOF("YYYYMMDDHHMMSSZ");
917 AC_MEMCPY( timebuf, csn.bv_val, timestamp.bv_len );
918 timebuf[timestamp.bv_len-1] = 'Z';
919 timebuf[timestamp.bv_len] = '\0';
922 time_t now = slap_get_time();
924 timestamp.bv_len = sizeof(timebuf);
926 slap_timestamp( &now, ×tamp );
929 if ( BER_BVISEMPTY( &op->o_dn ) ) {
930 BER_BVSTR( &name, SLAPD_ANONYMOUS );
939 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
940 mod->sml_op = LDAP_MOD_REPLACE;
941 mod->sml_flags = SLAP_MOD_INTERNAL;
942 mod->sml_next = NULL;
943 BER_BVZERO( &mod->sml_type );
944 mod->sml_desc = slap_schema.si_ad_entryCSN;
945 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
946 ber_dupbv( &mod->sml_values[0], &csn );
947 BER_BVZERO( &mod->sml_values[1] );
948 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
949 mod->sml_nvalues = NULL;
952 modtail = &mod->sml_next;
956 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
957 mod->sml_op = LDAP_MOD_REPLACE;
958 mod->sml_flags = SLAP_MOD_INTERNAL;
959 mod->sml_next = NULL;
960 BER_BVZERO( &mod->sml_type );
961 mod->sml_desc = slap_schema.si_ad_modifiersName;
962 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
963 ber_dupbv( &mod->sml_values[0], &name );
964 BER_BVZERO( &mod->sml_values[1] );
965 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
967 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
968 ber_dupbv( &mod->sml_nvalues[0], &nname );
969 BER_BVZERO( &mod->sml_nvalues[1] );
970 assert( !BER_BVISNULL( &mod->sml_nvalues[0] ) );
972 modtail = &mod->sml_next;
976 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
977 mod->sml_op = LDAP_MOD_REPLACE;
978 mod->sml_flags = SLAP_MOD_INTERNAL;
979 mod->sml_next = NULL;
980 BER_BVZERO( &mod->sml_type );
981 mod->sml_desc = slap_schema.si_ad_modifyTimestamp;
982 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
983 ber_dupbv( &mod->sml_values[0], ×tamp );
984 BER_BVZERO( &mod->sml_values[1] );
985 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
986 mod->sml_nvalues = NULL;
988 modtail = &mod->sml_next;
1003 Modifications **modtail = &ms->rs_modlist;
1005 ms->rs_modlist = NULL;
1006 ms->rs_increment = 0;
1008 rs->sr_err = LDAP_SUCCESS;
1010 /* collect modifications & save for later */
1011 for ( tag = ber_first_element( ber, &len, &last );
1012 tag != LBER_DEFAULT;
1013 tag = ber_next_element( ber, &len, last ) )
1016 Modifications tmp, *mod;
1018 tmp.sml_nvalues = NULL;
1020 if ( ber_scanf( ber, "{e{m[W]}}", &mop,
1021 &tmp.sml_type, &tmp.sml_values ) == LBER_ERROR )
1023 rs->sr_text = "decoding modlist error";
1024 rs->sr_err = LDAP_PROTOCOL_ERROR;
1028 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
1031 mod->sml_type = tmp.sml_type;
1032 mod->sml_values = tmp.sml_values;
1033 mod->sml_nvalues = NULL;
1034 mod->sml_desc = NULL;
1035 mod->sml_next = NULL;
1040 if ( mod->sml_values == NULL ) {
1041 Debug( LDAP_DEBUG_ANY, "slap_parse_modlist: "
1042 "modify/add operation (%ld) requires values\n",
1045 rs->sr_text = "modify/add operation requires values";
1046 rs->sr_err = LDAP_PROTOCOL_ERROR;
1052 case LDAP_MOD_DELETE:
1053 case LDAP_MOD_REPLACE:
1056 case LDAP_MOD_INCREMENT:
1057 if( op->o_protocol >= LDAP_VERSION3 ) {
1059 if ( mod->sml_values == NULL ) {
1060 Debug( LDAP_DEBUG_ANY, "slap_parse_modlist: "
1061 "modify/increment operation (%ld) requires value\n",
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 Debug( LDAP_DEBUG_ANY, "slap_parse_modlist: modify/increment "
1071 "operation (%ld) requires single value\n",
1074 rs->sr_text = "modify/increment operation requires single value";
1075 rs->sr_err = LDAP_PROTOCOL_ERROR;
1084 Debug( LDAP_DEBUG_ANY, "slap_parse_modlist: "
1085 "unrecognized modify operation (%ld)\n",
1088 rs->sr_text = "unrecognized modify operation";
1089 rs->sr_err = LDAP_PROTOCOL_ERROR;
1093 modtail = &mod->sml_next;
1098 if ( rs->sr_err != LDAP_SUCCESS ) {
1099 slap_mods_free( ms->rs_modlist, 1 );
1100 ms->rs_modlist = NULL;
1101 ms->rs_increment = 0;