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 );
290 slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
295 rs->sr_err = slap_mods_no_user_mod_check( op, op->orm_modlist,
296 &rs->sr_text, textbuf, textlen );
297 if ( rs->sr_err != LDAP_SUCCESS ) {
298 send_ldap_result( op, rs );
304 /* but multimaster slapd logs only the ones
305 * not from a replicator user */
306 cb.sc_next = op->o_callback;
307 op->o_callback = &cb;
309 op->o_bd->be_modify( op, rs );
311 } else { /* send a referral */
312 BerVarray defref = op->o_bd->be_update_refs
313 ? op->o_bd->be_update_refs : default_referral;
314 if ( defref != NULL ) {
315 rs->sr_ref = referral_rewrite( defref,
317 LDAP_SCOPE_DEFAULT );
318 if ( rs->sr_ref == NULL ) {
319 /* FIXME: must duplicate, because
320 * overlays may muck with it */
323 rs->sr_err = LDAP_REFERRAL;
324 send_ldap_result( op, rs );
325 if ( rs->sr_ref != defref ) {
326 ber_bvarray_free( rs->sr_ref );
330 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
331 "shadow context; no update referral" );
336 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
337 "operation not supported within namingContext" );
346 * Obsolete constraint checking.
349 slap_mods_obsolete_check(
356 if( get_relax( op ) ) return LDAP_SUCCESS;
358 for ( ; ml != NULL; ml = ml->sml_next ) {
359 if ( is_at_obsolete( ml->sml_desc->ad_type ) &&
360 (( ml->sml_op != LDAP_MOD_REPLACE &&
361 ml->sml_op != LDAP_MOD_DELETE ) ||
362 ml->sml_values != NULL ))
365 * attribute is obsolete,
366 * only allow replace/delete with no values
368 snprintf( textbuf, textlen,
369 "%s: attribute is obsolete",
370 ml->sml_type.bv_val );
372 return LDAP_CONSTRAINT_VIOLATION;
380 * No-user-modification constraint checking.
383 slap_mods_no_user_mod_check(
390 for ( ; ml != NULL; ml = ml->sml_next ) {
391 if ( !is_at_no_user_mod( ml->sml_desc->ad_type ) ) {
395 if ( get_relax( op ) ) {
396 if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_MANAGEABLE ) {
397 ml->sml_flags |= SLAP_MOD_MANAGING;
401 /* attribute not manageable */
402 snprintf( textbuf, textlen,
403 "%s: no-user-modification attribute not manageable",
404 ml->sml_type.bv_val );
407 /* user modification disallowed */
408 snprintf( textbuf, textlen,
409 "%s: no user modification allowed",
410 ml->sml_type.bv_val );
414 return LDAP_CONSTRAINT_VIOLATION;
421 slap_mods_no_repl_user_mod_check(
431 for ( mods = ml; mods != NULL; mods = mods->sml_next ) {
432 assert( mods->sml_op == LDAP_MOD_ADD );
434 /* check doesn't already appear */
435 for ( modp = ml; modp != NULL; modp = modp->sml_next ) {
436 if ( mods->sml_desc == modp->sml_desc && mods != modp ) {
437 snprintf( textbuf, textlen,
438 "attribute '%s' provided more than once",
439 mods->sml_desc->ad_cname.bv_val );
441 return LDAP_TYPE_OR_VALUE_EXISTS;
450 * Do basic attribute type checking and syntax validation.
462 for( ; ml != NULL; ml = ml->sml_next ) {
463 AttributeDescription *ad = NULL;
465 /* convert to attribute description */
466 if ( ml->sml_desc == NULL ) {
467 rc = slap_bv2ad( &ml->sml_type, &ml->sml_desc, text );
468 if( rc != LDAP_SUCCESS ) {
469 if ( get_no_schema_check( op )) {
470 rc = slap_bv2undef_ad( &ml->sml_type, &ml->sml_desc,
474 if( rc != LDAP_SUCCESS ) {
475 snprintf( textbuf, textlen, "%s: %s",
476 ml->sml_type.bv_val, *text );
484 if( slap_syntax_is_binary( ad->ad_type->sat_syntax )
485 && !slap_ad_is_binary( ad ))
487 /* attribute requires binary transfer */
488 snprintf( textbuf, textlen,
489 "%s: requires ;binary transfer",
490 ml->sml_type.bv_val );
492 return LDAP_UNDEFINED_TYPE;
495 if( !slap_syntax_is_binary( ad->ad_type->sat_syntax )
496 && slap_ad_is_binary( ad ))
498 /* attribute does not require binary transfer */
499 snprintf( textbuf, textlen,
500 "%s: disallows ;binary transfer",
501 ml->sml_type.bv_val );
503 return LDAP_UNDEFINED_TYPE;
506 if( slap_ad_is_tag_range( ad )) {
507 /* attribute requires binary transfer */
508 snprintf( textbuf, textlen,
509 "%s: inappropriate use of tag range option",
510 ml->sml_type.bv_val );
512 return LDAP_UNDEFINED_TYPE;
516 if ( is_at_obsolete( ad->ad_type ) &&
517 (( ml->sml_op != LDAP_MOD_REPLACE &&
518 ml->sml_op != LDAP_MOD_DELETE ) ||
519 ml->sml_values != NULL ))
522 * attribute is obsolete,
523 * only allow replace/delete with no values
525 snprintf( textbuf, textlen,
526 "%s: attribute is obsolete",
527 ml->sml_type.bv_val );
529 return LDAP_CONSTRAINT_VIOLATION;
533 if ( ml->sml_op == LDAP_MOD_INCREMENT &&
534 #ifdef SLAPD_REAL_SYNTAX
535 !is_at_syntax( ad->ad_type, SLAPD_REAL_SYNTAX ) &&
537 !is_at_syntax( ad->ad_type, SLAPD_INTEGER_SYNTAX ) )
540 * attribute values must be INTEGER or REAL
542 snprintf( textbuf, textlen,
543 "%s: attribute syntax inappropriate for increment",
544 ml->sml_type.bv_val );
546 return LDAP_CONSTRAINT_VIOLATION;
552 if( ml->sml_values != NULL ) {
554 slap_syntax_validate_func *validate =
555 ad->ad_type->sat_syntax->ssyn_validate;
556 slap_syntax_transform_func *pretty =
557 ad->ad_type->sat_syntax->ssyn_pretty;
559 if( !pretty && !validate ) {
560 *text = "no validator for syntax";
561 snprintf( textbuf, textlen,
562 "%s: no validator for syntax %s",
564 ad->ad_type->sat_syntax->ssyn_oid );
566 return LDAP_INVALID_SYNTAX;
570 * check that each value is valid per syntax
571 * and pretty if appropriate
573 for ( nvals = 0; !BER_BVISNULL( &ml->sml_values[nvals] ); nvals++ ) {
577 rc = ordered_value_pretty( ad,
578 &ml->sml_values[nvals], &pval, ctx );
580 rc = ordered_value_validate( ad,
581 &ml->sml_values[nvals], ml->sml_op );
585 snprintf( textbuf, textlen,
586 "%s: value #%ld invalid per syntax",
587 ml->sml_type.bv_val, (long) nvals );
589 return LDAP_INVALID_SYNTAX;
593 ber_memfree_x( ml->sml_values[nvals].bv_val, ctx );
594 ml->sml_values[nvals] = pval;
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 );
644 BER_BVZERO( &ml->sml_nvalues[nvals] );
647 /* check for duplicates, but ignore Deletes.
649 if( nvals > 1 && ml->sml_op != LDAP_MOD_DELETE ) {
650 #define SLAP_MODS_CHECK_QUICKSORT
651 #ifndef SLAP_MODS_CHECK_QUICKSORT
653 MatchingRule *mr = ad->ad_type->sat_equality;
655 for ( i = 1; i < nvals ; i++ ) {
656 /* test asserted values against themselves */
657 for( j = 0; j < i; j++ ) {
658 rc = ordered_value_match( &match, ml->sml_desc, mr,
660 | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX
661 | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH
662 | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH,
664 ? &ml->sml_nvalues[i]
665 : &ml->sml_values[i],
667 ? &ml->sml_nvalues[j]
668 : &ml->sml_values[j],
670 if ( rc == LDAP_SUCCESS && match == 0 ) {
671 /* value exists already */
672 snprintf( textbuf, textlen,
673 "%s: value #%d provided more than once",
674 ml->sml_desc->ad_cname.bv_val, j );
676 return LDAP_TYPE_OR_VALUE_EXISTS;
678 } else if ( rc != LDAP_SUCCESS ) {
683 #else /* SLAP_MODS_CHECK_QUICKSORT */
685 /* Quicksort + Insertion sort for small arrays */
688 #define SWAP(a,b,tmp) tmp=(a);(a)=(b);(b)=tmp
689 #define COMP(a,b) match=0; rc = ordered_value_match( &match, \
690 ml->sml_desc, mr, SLAP_MR_EQUALITY \
691 | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX \
692 | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH \
693 | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH, \
696 MatchingRule *mr = ad->ad_type->sat_equality;
697 int istack[sizeof(int)*16];
698 int i,j,k,l,ir,jstack, rc, match, *ix, itmp;
699 struct berval a, *cv;
701 /* If PRESERVE_ORDER is defined only the index array is sorted; the
702 * actual values are left in their incoming order. Otherwise, the
703 * only reason to keep the index array is to identify the offending
704 * value when duplicates are found.
706 #define PRESERVE_ORDER
707 #ifndef PRESERVE_ORDER
708 struct berval va, *v, *nv, bvtmp;
711 #define EXCH(x,y) SWAP(ix[x],ix[y],itmp); SWAP(cv[x],cv[y],bvtmp); \
712 if (nv) {SWAP(v[x],v[y],bvtmp);}
713 #define SETA(x) itmp = ix[x]; a = cv[x]; if (nv) va=v[x]
714 #define GETA(x) ix[x] = itmp; cv[x] = a; if (nv) v[x]=va
715 #define SET(x,y) ix[x] = ix[y]; cv[x] = cv[y]; if (nv) v[x]=v[y]
718 nv = ml->sml_nvalues;
720 #else /* PRESERVE_ORDER */
723 #define EXCH(x,y) SWAP(ix[x],ix[y],itmp)
724 #define SETA(x) itmp = ix[x]; a = cv[itmp]
725 #define GETA(x) ix[x] = itmp;
726 #define SET(x,y) ix[x] = ix[y]
728 #endif /* PRESERVE_ORDER */
730 cv = ml->sml_nvalues ? ml->sml_nvalues : ml->sml_values;
731 if ( ad == slap_schema.si_ad_objectClass )
732 mr = NULL; /* shortcut matching */
734 /* record indices to preserve input ordering */
735 ix = slap_sl_malloc( nvals * sizeof(int), ctx );
736 for (i=0; i<nvals; i++) ix[i] = i;
743 if (ir - l < SMALL) { /* Insertion sort */
745 for (j=l+1;j<=ir;j++) {
747 for (i=j-1;i>=0;i--) {
754 if ( match == 0 ) goto done;
756 if ( jstack == 0 ) break;
757 if ( match == 0 ) break;
758 ir = istack[jstack--];
759 l = istack[jstack--];
761 k = (l + ir) >> 1; /* Choose median of left, center, right */
763 COMP( cv[IX(l)], cv[IX(ir)] );
766 } else if ( match == 0 ) {
770 COMP( cv[IX(l+1)], cv[IX(ir)] );
773 } else if ( match == 0 ) {
777 COMP( cv[IX(l)], cv[IX(l+1)] );
780 } else if ( match == 0 ) {
790 COMP( cv[IX(i)], a );
791 } while( match < 0 );
794 COMP( cv[IX(j)], a );
812 istack[jstack-1] = i;
816 istack[jstack-1] = l;
825 slap_sl_free( ix, ctx );
827 if ( rc != LDAP_SUCCESS ) {
829 } else if ( match == 0 ) {
830 /* value exists already */
833 snprintf( textbuf, textlen,
834 "%s: value #%d provided more than once",
835 ml->sml_desc->ad_cname.bv_val, j );
837 return LDAP_TYPE_OR_VALUE_EXISTS;
839 #endif /* SLAP_MODS_CHECK_QUICKSORT */
847 /* Enter with bv->bv_len = sizeof buffer, returns with
848 * actual length of string
850 void slap_timestamp( time_t *tm, struct berval *bv )
856 ltm = gmtime_r( tm, <m_buf );
858 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
862 bv->bv_len = lutil_gentime( bv->bv_val, bv->bv_len, ltm );
864 #ifndef HAVE_GMTIME_R
865 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
869 /* Called for all modify and modrdn ops. If the current op was replicated
870 * from elsewhere, all of the attrs should already be present.
872 void slap_mods_opattrs(
874 Modifications **modsp,
877 struct berval name, timestamp, csn = BER_BVNULL;
879 char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
880 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
881 Modifications *mod, **modtail, *modlast;
882 int gotcsn = 0, gotmname = 0, gotmtime = 0;
884 if ( SLAP_LASTMOD( op->o_bd ) && !op->orm_no_opattrs ) {
886 timestamp.bv_val = timebuf;
887 for ( modtail = modsp; *modtail; modtail = &(*modtail)->sml_next ) {
888 if ( (*modtail)->sml_op != LDAP_MOD_ADD &&
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_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
957 ber_dupbv( &mod->sml_values[0], &csn );
958 BER_BVZERO( &mod->sml_values[1] );
959 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
960 mod->sml_nvalues = NULL;
963 modtail = &mod->sml_next;
967 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
968 mod->sml_op = LDAP_MOD_REPLACE;
969 mod->sml_flags = SLAP_MOD_INTERNAL;
970 mod->sml_next = NULL;
971 BER_BVZERO( &mod->sml_type );
972 mod->sml_desc = slap_schema.si_ad_modifiersName;
973 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
974 ber_dupbv( &mod->sml_values[0], &name );
975 BER_BVZERO( &mod->sml_values[1] );
976 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
978 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
979 ber_dupbv( &mod->sml_nvalues[0], &nname );
980 BER_BVZERO( &mod->sml_nvalues[1] );
981 assert( !BER_BVISNULL( &mod->sml_nvalues[0] ) );
983 modtail = &mod->sml_next;
987 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
988 mod->sml_op = LDAP_MOD_REPLACE;
989 mod->sml_flags = SLAP_MOD_INTERNAL;
990 mod->sml_next = NULL;
991 BER_BVZERO( &mod->sml_type );
992 mod->sml_desc = slap_schema.si_ad_modifyTimestamp;
993 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
994 ber_dupbv( &mod->sml_values[0], ×tamp );
995 BER_BVZERO( &mod->sml_values[1] );
996 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
997 mod->sml_nvalues = NULL;
999 modtail = &mod->sml_next;
1014 Modifications **modtail = &ms->rs_modlist;
1016 ms->rs_modlist = NULL;
1017 ms->rs_increment = 0;
1019 rs->sr_err = LDAP_SUCCESS;
1021 /* collect modifications & save for later */
1022 for ( tag = ber_first_element( ber, &len, &last );
1023 tag != LBER_DEFAULT;
1024 tag = ber_next_element( ber, &len, last ) )
1027 Modifications tmp, *mod;
1029 tmp.sml_nvalues = NULL;
1031 if ( ber_scanf( ber, "{e{m[W]}}", &mop,
1032 &tmp.sml_type, &tmp.sml_values ) == LBER_ERROR )
1034 rs->sr_text = "decoding modlist error";
1035 rs->sr_err = LDAP_PROTOCOL_ERROR;
1039 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
1042 mod->sml_type = tmp.sml_type;
1043 mod->sml_values = tmp.sml_values;
1044 mod->sml_nvalues = NULL;
1045 mod->sml_desc = NULL;
1046 mod->sml_next = NULL;
1051 if ( mod->sml_values == NULL ) {
1052 Debug( LDAP_DEBUG_ANY, "slap_parse_modlist: "
1053 "modify/add operation (%ld) requires values\n",
1056 rs->sr_text = "modify/add operation requires values";
1057 rs->sr_err = LDAP_PROTOCOL_ERROR;
1063 case LDAP_MOD_DELETE:
1064 case LDAP_MOD_REPLACE:
1067 case LDAP_MOD_INCREMENT:
1068 if( op->o_protocol >= LDAP_VERSION3 ) {
1070 if ( mod->sml_values == NULL ) {
1071 Debug( LDAP_DEBUG_ANY, "slap_parse_modlist: "
1072 "modify/increment operation (%ld) requires value\n",
1075 rs->sr_text = "modify/increment operation requires value";
1076 rs->sr_err = LDAP_PROTOCOL_ERROR;
1080 if ( !BER_BVISNULL( &mod->sml_values[ 1 ] ) ) {
1081 Debug( LDAP_DEBUG_ANY, "slap_parse_modlist: modify/increment "
1082 "operation (%ld) requires single value\n",
1085 rs->sr_text = "modify/increment operation requires single value";
1086 rs->sr_err = LDAP_PROTOCOL_ERROR;
1095 Debug( LDAP_DEBUG_ANY, "slap_parse_modlist: "
1096 "unrecognized modify operation (%ld)\n",
1099 rs->sr_text = "unrecognized modify operation";
1100 rs->sr_err = LDAP_PROTOCOL_ERROR;
1104 modtail = &mod->sml_next;
1109 if ( rs->sr_err != LDAP_SUCCESS ) {
1110 slap_mods_free( ms->rs_modlist, 1 );
1111 ms->rs_modlist = NULL;
1112 ms->rs_increment = 0;