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 );
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" );
274 * do the modify if 1 && (2 || 3)
275 * 1) there is a modify function implemented in this backend;
276 * 2) this backend is master for what it holds;
277 * 3) it's a replica and the dn supplied is the update_ndn.
279 if ( op->o_bd->be_modify ) {
280 /* do the update here */
281 int repl_user = be_isupdate( op );
284 * Multimaster slapd does not have to check for replicator dn
285 * because it accepts each modify request
287 if ( !SLAP_SINGLE_SHADOW(op->o_bd) || repl_user ) {
288 int update = !BER_BVISEMPTY( &op->o_bd->be_update_ndn );
293 rs->sr_err = slap_mods_no_user_mod_check( op, op->orm_modlist,
294 &rs->sr_text, textbuf, textlen );
295 if ( rs->sr_err != LDAP_SUCCESS ) {
296 send_ldap_result( op, rs );
300 op->o_bd->be_modify( op, rs );
302 } else { /* send a referral */
303 BerVarray defref = op->o_bd->be_update_refs
304 ? op->o_bd->be_update_refs : default_referral;
305 if ( defref != NULL ) {
306 rs->sr_ref = referral_rewrite( defref,
308 LDAP_SCOPE_DEFAULT );
309 if ( rs->sr_ref == NULL ) {
310 /* FIXME: must duplicate, because
311 * overlays may muck with it */
314 rs->sr_err = LDAP_REFERRAL;
315 send_ldap_result( op, rs );
316 if ( rs->sr_ref != defref ) {
317 ber_bvarray_free( rs->sr_ref );
321 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
322 "shadow context; no update referral" );
327 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
328 "operation not supported within namingContext" );
337 * Obsolete constraint checking.
340 slap_mods_obsolete_check(
347 if( get_relax( op ) ) return LDAP_SUCCESS;
349 for ( ; ml != NULL; ml = ml->sml_next ) {
350 if ( is_at_obsolete( ml->sml_desc->ad_type ) &&
351 (( ml->sml_op != LDAP_MOD_REPLACE &&
352 ml->sml_op != LDAP_MOD_DELETE ) ||
353 ml->sml_values != NULL ))
356 * attribute is obsolete,
357 * only allow replace/delete with no values
359 snprintf( textbuf, textlen,
360 "%s: attribute is obsolete",
361 ml->sml_type.bv_val );
363 return LDAP_CONSTRAINT_VIOLATION;
371 * No-user-modification constraint checking.
374 slap_mods_no_user_mod_check(
381 for ( ; ml != NULL; ml = ml->sml_next ) {
382 if ( !is_at_no_user_mod( ml->sml_desc->ad_type ) ) {
386 if ( get_relax( op ) ) {
387 if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_MANAGEABLE ) {
388 ml->sml_flags |= SLAP_MOD_MANAGING;
392 /* attribute not manageable */
393 snprintf( textbuf, textlen,
394 "%s: no-user-modification attribute not manageable",
395 ml->sml_type.bv_val );
398 /* user modification disallowed */
399 snprintf( textbuf, textlen,
400 "%s: no user modification allowed",
401 ml->sml_type.bv_val );
405 return LDAP_CONSTRAINT_VIOLATION;
412 slap_mods_no_repl_user_mod_check(
422 for ( mods = ml; mods != NULL; mods = mods->sml_next ) {
423 assert( mods->sml_op == LDAP_MOD_ADD );
425 /* check doesn't already appear */
426 for ( modp = ml; modp != NULL; modp = modp->sml_next ) {
427 if ( mods->sml_desc == modp->sml_desc && mods != modp ) {
428 snprintf( textbuf, textlen,
429 "attribute '%s' provided more than once",
430 mods->sml_desc->ad_cname.bv_val );
432 return LDAP_TYPE_OR_VALUE_EXISTS;
441 * Do basic attribute type checking and syntax validation.
453 for( ; ml != NULL; ml = ml->sml_next ) {
454 AttributeDescription *ad = NULL;
456 /* convert to attribute description */
457 if ( ml->sml_desc == NULL ) {
458 rc = slap_bv2ad( &ml->sml_type, &ml->sml_desc, text );
459 if( rc != LDAP_SUCCESS ) {
460 if ( get_no_schema_check( op )) {
461 rc = slap_bv2undef_ad( &ml->sml_type, &ml->sml_desc,
465 if( rc != LDAP_SUCCESS ) {
466 snprintf( textbuf, textlen, "%s: %s",
467 ml->sml_type.bv_val, *text );
475 if( slap_syntax_is_binary( ad->ad_type->sat_syntax )
476 && !slap_ad_is_binary( ad ))
478 /* attribute requires binary transfer */
479 snprintf( textbuf, textlen,
480 "%s: requires ;binary transfer",
481 ml->sml_type.bv_val );
483 return LDAP_UNDEFINED_TYPE;
486 if( !slap_syntax_is_binary( ad->ad_type->sat_syntax )
487 && slap_ad_is_binary( ad ))
489 /* attribute does not require binary transfer */
490 snprintf( textbuf, textlen,
491 "%s: disallows ;binary transfer",
492 ml->sml_type.bv_val );
494 return LDAP_UNDEFINED_TYPE;
497 if( slap_ad_is_tag_range( ad )) {
498 /* attribute requires binary transfer */
499 snprintf( textbuf, textlen,
500 "%s: inappropriate use of tag range option",
501 ml->sml_type.bv_val );
503 return LDAP_UNDEFINED_TYPE;
507 if ( is_at_obsolete( ad->ad_type ) &&
508 (( ml->sml_op != LDAP_MOD_REPLACE &&
509 ml->sml_op != LDAP_MOD_DELETE ) ||
510 ml->sml_values != NULL ))
513 * attribute is obsolete,
514 * only allow replace/delete with no values
516 snprintf( textbuf, textlen,
517 "%s: attribute is obsolete",
518 ml->sml_type.bv_val );
520 return LDAP_CONSTRAINT_VIOLATION;
524 if ( ml->sml_op == LDAP_MOD_INCREMENT &&
525 #ifdef SLAPD_REAL_SYNTAX
526 !is_at_syntax( ad->ad_type, SLAPD_REAL_SYNTAX ) &&
528 !is_at_syntax( ad->ad_type, SLAPD_INTEGER_SYNTAX ) )
531 * attribute values must be INTEGER or REAL
533 snprintf( textbuf, textlen,
534 "%s: attribute syntax inappropriate for increment",
535 ml->sml_type.bv_val );
537 return LDAP_CONSTRAINT_VIOLATION;
543 if( ml->sml_values != NULL ) {
545 slap_syntax_validate_func *validate =
546 ad->ad_type->sat_syntax->ssyn_validate;
547 slap_syntax_transform_func *pretty =
548 ad->ad_type->sat_syntax->ssyn_pretty;
550 if( !pretty && !validate ) {
551 *text = "no validator for syntax";
552 snprintf( textbuf, textlen,
553 "%s: no validator for syntax %s",
555 ad->ad_type->sat_syntax->ssyn_oid );
557 return LDAP_INVALID_SYNTAX;
561 * check that each value is valid per syntax
562 * and pretty if appropriate
564 for ( nvals = 0; !BER_BVISNULL( &ml->sml_values[nvals] ); nvals++ ) {
568 rc = ordered_value_pretty( ad,
569 &ml->sml_values[nvals], &pval, ctx );
571 rc = ordered_value_validate( ad,
572 &ml->sml_values[nvals], ml->sml_op );
576 snprintf( textbuf, textlen,
577 "%s: value #%ld invalid per syntax",
578 ml->sml_type.bv_val, (long) nvals );
580 return LDAP_INVALID_SYNTAX;
584 ber_memfree_x( ml->sml_values[nvals].bv_val, ctx );
585 ml->sml_values[nvals] = pval;
588 ml->sml_numvals = nvals;
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 );
632 BER_BVZERO( &ml->sml_nvalues[nvals] );
637 BER_BVZERO( &ml->sml_nvalues[nvals] );
640 /* check for duplicates, but ignore Deletes.
642 if( nvals > 1 && ml->sml_op != LDAP_MOD_DELETE ) {
644 rc = slap_sort_vals( ml, text, &i, ctx );
645 if ( rc == LDAP_TYPE_OR_VALUE_EXISTS ) {
646 /* value exists already */
647 snprintf( textbuf, textlen,
648 "%s: value #%d provided more than once",
649 ml->sml_desc->ad_cname.bv_val, i );
663 /* Sort a set of values. An (Attribute *) may be used interchangeably here
664 * instead of a (Modifications *) structure.
666 * Uses Quicksort + Insertion sort for small arrays
676 AttributeDescription *ad;
678 int istack[sizeof(int)*16];
679 int i, j, k, l, ir, jstack, match, *ix, itmp, nvals, rc;
681 struct berval a, *cv;
684 #define SWAP(a,b,tmp) tmp=(a);(a)=(b);(b)=tmp
685 #define COMP(a,b) match=0; rc = ordered_value_match( &match, \
686 ad, mr, SLAP_MR_EQUALITY \
687 | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX \
688 | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH \
689 | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH, \
693 #define EXCH(x,y) SWAP(ix[x],ix[y],itmp)
694 #define SETA(x) itmp = ix[x]; a = cv[itmp]
695 #define GETA(x) ix[x] = itmp;
696 #define SET(x,y) ix[x] = ix[y]
699 nvals = ml->sml_numvals;
701 /* For Modifications, sml_nvalues is NULL if normalization wasn't needed.
702 * For Attributes, sml_nvalues == sml_values when normalization isn't needed.
704 if ( ml->sml_nvalues && ml->sml_nvalues != ml->sml_values ) {
705 cv = ml->sml_nvalues;
712 if ( ad == slap_schema.si_ad_objectClass )
713 mr = NULL; /* shortcut matching */
715 mr = ad->ad_type->sat_equality;
717 /* record indices to preserve input ordering */
718 ix = slap_sl_malloc( nvals * sizeof(int), ctx );
719 for (i=0; i<nvals; i++) ix[i] = i;
726 if (ir - l < SMALL) { /* Insertion sort */
728 for (j=l+1;j<=ir;j++) {
730 for (i=j-1;i>=0;i--) {
737 if ( match == 0 ) goto done;
739 if ( jstack == 0 ) break;
740 if ( match == 0 ) break;
741 ir = istack[jstack--];
742 l = istack[jstack--];
744 k = (l + ir) >> 1; /* Choose median of left, center, right */
746 COMP( cv[IX(l)], cv[IX(ir)] );
749 } else if ( match == 0 ) {
753 COMP( cv[IX(l+1)], cv[IX(ir)] );
756 } else if ( match == 0 ) {
760 COMP( cv[IX(l)], cv[IX(l+1)] );
763 } else if ( match == 0 ) {
773 COMP( cv[IX(i)], a );
774 } while( match < 0 );
777 COMP( cv[IX(j)], a );
795 istack[jstack-1] = i;
799 istack[jstack-1] = l;
808 /* For sorted attributes, put the values in index order */
809 if ( rc == LDAP_SUCCESS && match &&
810 ( ad->ad_type->sat_flags & SLAP_AT_SORTED_VAL )) {
811 BerVarray tmpv = slap_sl_malloc( sizeof( struct berval ) * nvals, ctx );
812 for ( i = 0; i<nvals; i++ )
814 for ( i = 0; i<nvals; i++ )
816 /* Check if the non-normalized array needs to move too */
819 for ( i = 0; i<nvals; i++ )
821 for ( i = 0; i<nvals; i++ )
824 slap_sl_free( tmpv, ctx );
827 slap_sl_free( ix, ctx );
829 if ( rc != LDAP_SUCCESS ) {
831 } else if ( match == 0 ) {
832 /* value exists already */
835 return LDAP_TYPE_OR_VALUE_EXISTS;
840 /* Enter with bv->bv_len = sizeof buffer, returns with
841 * actual length of string
843 void slap_timestamp( time_t *tm, struct berval *bv )
849 ltm = gmtime_r( tm, <m_buf );
851 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
855 bv->bv_len = lutil_gentime( bv->bv_val, bv->bv_len, ltm );
857 #ifndef HAVE_GMTIME_R
858 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
862 /* Called for all modify and modrdn ops. If the current op was replicated
863 * from elsewhere, all of the attrs should already be present.
865 void slap_mods_opattrs(
867 Modifications **modsp,
870 struct berval name, timestamp, csn = BER_BVNULL;
872 char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
873 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
874 Modifications *mod, **modtail, *modlast;
875 int gotcsn = 0, gotmname = 0, gotmtime = 0;
877 if ( SLAP_LASTMOD( op->o_bd ) && !op->orm_no_opattrs ) {
879 timestamp.bv_val = timebuf;
880 for ( modtail = modsp; *modtail; modtail = &(*modtail)->sml_next ) {
881 if ( (*modtail)->sml_op != LDAP_MOD_ADD &&
882 (*modtail)->sml_op != SLAP_MOD_SOFTADD &&
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;