2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2005 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>
36 #include "slapi/slapi.h"
46 struct berval dn = BER_BVNULL;
50 Modifications *modlist = NULL;
51 Modifications **modtail = &modlist;
53 char textbuf[ SLAP_TEXT_BUFLEN ];
54 size_t textlen = sizeof( textbuf );
56 Debug( LDAP_DEBUG_TRACE, "do_modify\n", 0, 0, 0 );
59 * Parse the modify request. It looks like this:
61 * ModifyRequest := [APPLICATION 6] SEQUENCE {
62 * name DistinguishedName,
63 * mods SEQUENCE OF SEQUENCE {
64 * operation ENUMERATED {
69 * modification SEQUENCE {
71 * values SET OF AttributeValue
77 if ( ber_scanf( op->o_ber, "{m" /*}*/, &dn ) == LBER_ERROR ) {
78 Debug( LDAP_DEBUG_ANY, "do_modify: ber_scanf failed\n", 0, 0, 0 );
80 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
81 return SLAPD_DISCONNECT;
84 Debug( LDAP_DEBUG_ARGS, "do_modify: dn (%s)\n", dn.bv_val, 0, 0 );
86 /* collect modifications & save for later */
87 for ( tag = ber_first_element( op->o_ber, &len, &last );
89 tag = ber_next_element( op->o_ber, &len, last ) )
92 Modifications tmp, *mod;
94 tmp.sml_nvalues = NULL;
96 if ( ber_scanf( op->o_ber, "{i{m[W]}}", &mop,
97 &tmp.sml_type, &tmp.sml_values ) == LBER_ERROR )
99 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR,
100 "decoding modlist error" );
101 rs->sr_err = SLAPD_DISCONNECT;
105 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
108 mod->sml_type = tmp.sml_type;
109 mod->sml_values = tmp.sml_values;
110 mod->sml_nvalues = NULL;
111 mod->sml_desc = NULL;
112 mod->sml_next = NULL;
117 if ( mod->sml_values == NULL ) {
118 Debug( LDAP_DEBUG_ANY,
119 "do_modify: modify/add operation (%ld) requires values\n",
122 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
123 "modify/add operation requires values" );
129 case LDAP_MOD_DELETE:
130 case LDAP_MOD_REPLACE:
133 case LDAP_MOD_INCREMENT:
134 if( op->o_protocol >= LDAP_VERSION3 ) {
136 if ( mod->sml_values == NULL ) {
137 Debug( LDAP_DEBUG_ANY, "do_modify: "
138 "modify/increment operation (%ld) requires value\n",
141 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
142 "modify/increment operation requires value" );
146 if( mod->sml_values[1].bv_val ) {
147 Debug( LDAP_DEBUG_ANY, "do_modify: modify/increment "
148 "operation (%ld) requires single value\n",
151 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
152 "modify/increment operation requires single value" );
161 Debug( LDAP_DEBUG_ANY,
162 "do_modify: unrecognized modify operation (%ld)\n",
165 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
166 "unrecognized modify operation" );
171 modtail = &mod->sml_next;
175 if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
176 Debug( LDAP_DEBUG_ANY, "do_modify: get_ctrls failed\n", 0, 0, 0 );
181 rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn,
183 if( rs->sr_err != LDAP_SUCCESS ) {
184 Debug( LDAP_DEBUG_ANY,
185 "do_modify: invalid dn (%s)\n", dn.bv_val, 0, 0 );
186 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
190 rs->sr_err = slap_mods_check( modlist, &rs->sr_text,
191 textbuf, textlen, NULL );
193 if ( rs->sr_err != LDAP_SUCCESS ) {
194 send_ldap_result( op, rs );
198 /* FIXME: needs review */
199 op->orm_modlist = modlist;
200 op->orm_increment = increment;
202 op->o_bd = frontendDB;
203 rs->sr_err = frontendDB->be_modify( op, rs );
206 slap_graduate_commit_csn( op );
208 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
209 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
210 if ( op->orm_modlist != NULL ) slap_mods_free( op->orm_modlist );
216 fe_op_modify( Operation *op, SlapReply *rs )
222 Modifications *modlist = op->orm_modlist;
223 Modifications **modtail = &modlist;
225 LDAPMod **modv = NULL;
227 int increment = op->orm_increment;
230 char textbuf[ SLAP_TEXT_BUFLEN ];
231 size_t textlen = sizeof( textbuf );
233 if( op->o_req_ndn.bv_len == 0 ) {
234 Debug( LDAP_DEBUG_ANY, "do_modify: root dse!\n", 0, 0, 0 );
236 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
237 "modify upon the root DSE not supported" );
240 } else if ( bvmatch( &op->o_req_ndn, &frontendDB->be_schemandn ) ) {
241 Debug( LDAP_DEBUG_ANY, "do_modify: subschema subentry!\n", 0, 0, 0 );
243 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
244 "modification of subschema subentry not supported" );
249 Debug( LDAP_DEBUG_ARGS, "modifications:\n", 0, 0, 0 );
251 for ( tmp = modlist; tmp != NULL; tmp = tmp->sml_next ) {
252 Debug( LDAP_DEBUG_ARGS, "\t%s: %s\n",
253 tmp->sml_op == LDAP_MOD_ADD ? "add" :
254 (tmp->sml_op == LDAP_MOD_INCREMENT ? "increment" :
255 (tmp->sml_op == LDAP_MOD_DELETE ? "delete" :
256 "replace")), tmp->sml_type.bv_val, 0 );
258 if ( tmp->sml_values == NULL ) {
259 Debug( LDAP_DEBUG_ARGS, "%s\n",
260 "\t\tno values", NULL, NULL );
261 } else if ( tmp->sml_values[0].bv_val == NULL ) {
262 Debug( LDAP_DEBUG_ARGS, "%s\n",
263 "\t\tzero values", NULL, NULL );
264 } else if ( tmp->sml_values[1].bv_val == NULL ) {
265 Debug( LDAP_DEBUG_ARGS, "%s, length %ld\n",
266 "\t\tone value", (long) tmp->sml_values[0].bv_len, NULL );
268 Debug( LDAP_DEBUG_ARGS, "%s\n",
269 "\t\tmultiple values", NULL, NULL );
273 if ( StatslogTest( LDAP_DEBUG_STATS ) ) {
274 char abuf[BUFSIZ/2], *ptr = abuf;
277 Statslog( LDAP_DEBUG_STATS, "%s MOD dn=\"%s\"\n",
278 op->o_log_prefix, op->o_req_dn.bv_val, 0, 0, 0 );
280 for ( tmp = modlist; tmp != NULL; tmp = tmp->sml_next ) {
281 if (len + 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
282 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
283 op->o_log_prefix, abuf, 0, 0, 0 );
288 if( 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
289 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
290 op->o_log_prefix, tmp->sml_type.bv_val, 0, 0, 0 );
298 ptr = lutil_strcopy(ptr, tmp->sml_type.bv_val);
299 len += tmp->sml_type.bv_len;
302 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
303 op->o_log_prefix, abuf, 0, 0, 0 );
306 #endif /* LDAP_DEBUG */
308 manageDSAit = get_manageDSAit( op );
311 * We could be serving multiple database backends. Select the
312 * appropriate one, or send a referral to our "referral server"
313 * if we don't hold it.
315 op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 1 );
316 if ( op->o_bd == NULL ) {
317 rs->sr_ref = referral_rewrite( default_referral,
318 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
319 if (!rs->sr_ref) rs->sr_ref = default_referral;
321 if (rs->sr_ref != NULL ) {
322 rs->sr_err = LDAP_REFERRAL;
323 op->o_bd = frontendDB;
324 send_ldap_result( op, rs );
327 if (rs->sr_ref != default_referral) ber_bvarray_free( rs->sr_ref );
329 op->o_bd = frontendDB;
330 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
331 "no global superior knowledge" );
337 /* If we've got a glued backend, check the real backend */
339 if ( SLAP_GLUE_INSTANCE( op->o_bd )) {
340 op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 0 );
343 /* check restrictions */
344 if( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
345 send_ldap_result( op, rs );
349 /* check for referrals */
350 if( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
355 rs->sr_err = slap_mods_obsolete_check( op, modlist,
356 &rs->sr_text, textbuf, textlen );
357 if ( rs->sr_err != LDAP_SUCCESS ) {
358 send_ldap_result( op, rs );
363 /* check for modify/increment support */
364 if( increment && !SLAP_INCREMENT( op->o_bd ) ) {
365 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
366 "modify/increment not supported in context" );
369 #if defined( LDAP_SLAPI )
372 slapi_int_pblock_set_operation( pb, op );
373 slapi_pblock_set( pb, SLAPI_MODIFY_TARGET, (void *)op->o_req_dn.bv_val );
374 slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)manageDSAit );
375 modv = slapi_int_modifications2ldapmods( &modlist );
376 slapi_pblock_set( pb, SLAPI_MODIFY_MODS, (void *)modv );
378 rs->sr_err = slapi_int_call_plugins( op->o_bd,
379 SLAPI_PLUGIN_PRE_MODIFY_FN, pb );
382 * It's possible that the preoperation plugin changed the
383 * modification array, so we need to convert it back to
384 * a Modification list.
386 * Calling slapi_int_modifications2ldapmods() destroyed modlist so
387 * we don't need to free it.
389 slapi_pblock_get( pb, SLAPI_MODIFY_MODS, (void **)&modv );
390 modlist = slapi_int_ldapmods2modifications( modv );
392 if ( rs->sr_err < 0 ) {
394 * A preoperation plugin failure will abort the
397 Debug(LDAP_DEBUG_TRACE,
398 "do_modify: modify preoperation plugin failed.\n",
400 if ( ( slapi_pblock_get( op->o_pb, SLAPI_RESULT_CODE,
401 (void *)&rs->sr_err ) != 0 ) || rs->sr_err == LDAP_SUCCESS )
403 rs->sr_err = LDAP_OTHER;
405 slapi_int_free_ldapmods( modv );
412 * NB: it is valid for the plugin to return no modifications
413 * (for example, a plugin might store some attributes elsewhere
414 * and remove them from the modification list; if only those
415 * attribute types were included in the modification request,
416 * then slapi_int_ldapmods2modifications() above will return
419 * However, the post-operation plugin should still be
422 #endif /* defined( LDAP_SLAPI ) */
425 * do the modify if 1 && (2 || 3)
426 * 1) there is a modify function implemented in this backend;
427 * 2) this backend is master for what it holds;
428 * 3) it's a replica and the dn supplied is the update_ndn.
430 if ( op->o_bd->be_modify ) {
431 /* do the update here */
432 int repl_user = be_isupdate( op );
434 /* Multimaster slapd does not have to check for replicator dn
435 * because it accepts each modify request
437 #ifndef SLAPD_MULTIMASTER
438 if ( !SLAP_SHADOW(op->o_bd) || repl_user )
441 int update = !BER_BVISEMPTY( &op->o_bd->be_update_ndn );
442 slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
447 rs->sr_err = slap_mods_no_user_mod_check( op, modlist,
448 &rs->sr_text, textbuf, textlen );
449 if ( rs->sr_err != LDAP_SUCCESS ) {
450 send_ldap_result( op, rs );
456 for( modtail = &modlist;
458 modtail = &(*modtail)->sml_next )
463 rs->sr_err = slap_mods_opattrs( op, modlist, modtail,
464 &rs->sr_text, textbuf, textlen, 1 );
465 if( rs->sr_err != LDAP_SUCCESS ) {
466 send_ldap_result( op, rs );
471 op->orm_modlist = modlist;
472 #ifdef SLAPD_MULTIMASTER
476 /* but multimaster slapd logs only the ones
477 * not from a replicator user */
478 cb.sc_next = op->o_callback;
479 op->o_callback = &cb;
481 op->o_bd->be_modify( op, rs );
483 #ifndef SLAPD_MULTIMASTER
484 /* send a referral */
486 BerVarray defref = op->o_bd->be_update_refs
487 ? op->o_bd->be_update_refs : default_referral;
488 if ( defref != NULL ) {
489 rs->sr_ref = referral_rewrite( defref,
491 LDAP_SCOPE_DEFAULT );
492 if ( rs->sr_ref == NULL ) {
493 /* FIXME: must duplicate, because
494 * overlays may muck with it */
497 rs->sr_err = LDAP_REFERRAL;
498 send_ldap_result( op, rs );
499 if ( rs->sr_ref != defref ) {
500 ber_bvarray_free( rs->sr_ref );
504 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
505 "shadow context; no update referral" );
510 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
511 "operation not supported within namingContext" );
514 #if defined( LDAP_SLAPI )
515 if ( pb != NULL && slapi_int_call_plugins( op->o_bd,
516 SLAPI_PLUGIN_POST_MODIFY_FN, pb ) < 0 )
518 Debug(LDAP_DEBUG_TRACE,
519 "do_modify: modify postoperation plugins failed.\n", 0, 0, 0);
521 #endif /* defined( LDAP_SLAPI ) */
524 #if defined( LDAP_SLAPI )
525 if ( modv != NULL ) slapi_int_free_ldapmods( modv );
532 * Obsolete constraint checking.
535 slap_mods_obsolete_check(
542 if( get_manageDIT( op ) ) return LDAP_SUCCESS;
544 for ( ; ml != NULL; ml = ml->sml_next ) {
545 if ( is_at_obsolete( ml->sml_desc->ad_type ) &&
546 (( ml->sml_op != LDAP_MOD_REPLACE &&
547 ml->sml_op != LDAP_MOD_DELETE ) ||
548 ml->sml_values != NULL ))
551 * attribute is obsolete,
552 * only allow replace/delete with no values
554 snprintf( textbuf, textlen,
555 "%s: attribute is obsolete",
556 ml->sml_type.bv_val );
558 return LDAP_CONSTRAINT_VIOLATION;
566 * No-user-modification constraint checking.
569 slap_mods_no_user_mod_check(
576 for ( ; ml != NULL; ml = ml->sml_next ) {
577 if ( !is_at_no_user_mod( ml->sml_desc->ad_type ) ) continue;
579 if( get_manageDIT( op )) {
580 if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_MANAGEABLE ) {
584 /* attribute not manageable */
585 snprintf( textbuf, textlen,
586 "%s: no-user-modification attribute not manageable",
587 ml->sml_type.bv_val );
590 /* user modification disallowed */
591 snprintf( textbuf, textlen,
592 "%s: no user modification allowed",
593 ml->sml_type.bv_val );
597 return LDAP_CONSTRAINT_VIOLATION;
604 * Do basic attribute type checking and syntax validation.
615 for( ; ml != NULL; ml = ml->sml_next ) {
616 AttributeDescription *ad = NULL;
618 /* convert to attribute description */
619 rc = slap_bv2ad( &ml->sml_type, &ml->sml_desc, text );
621 if( rc != LDAP_SUCCESS ) {
622 snprintf( textbuf, textlen, "%s: %s",
623 ml->sml_type.bv_val, *text );
630 if( slap_syntax_is_binary( ad->ad_type->sat_syntax )
631 && !slap_ad_is_binary( ad ))
633 /* attribute requires binary transfer */
634 snprintf( textbuf, textlen,
635 "%s: requires ;binary transfer",
636 ml->sml_type.bv_val );
638 return LDAP_UNDEFINED_TYPE;
641 if( !slap_syntax_is_binary( ad->ad_type->sat_syntax )
642 && slap_ad_is_binary( ad ))
644 /* attribute does not require binary transfer */
645 snprintf( textbuf, textlen,
646 "%s: disallows ;binary transfer",
647 ml->sml_type.bv_val );
649 return LDAP_UNDEFINED_TYPE;
652 if( slap_ad_is_tag_range( ad )) {
653 /* attribute requires binary transfer */
654 snprintf( textbuf, textlen,
655 "%s: inappropriate use of tag range option",
656 ml->sml_type.bv_val );
658 return LDAP_UNDEFINED_TYPE;
662 if ( is_at_obsolete( ad->ad_type ) &&
663 (( ml->sml_op != LDAP_MOD_REPLACE &&
664 ml->sml_op != LDAP_MOD_DELETE ) ||
665 ml->sml_values != NULL ))
668 * attribute is obsolete,
669 * only allow replace/delete with no values
671 snprintf( textbuf, textlen,
672 "%s: attribute is obsolete",
673 ml->sml_type.bv_val );
675 return LDAP_CONSTRAINT_VIOLATION;
679 if ( ml->sml_op == LDAP_MOD_INCREMENT &&
680 #ifdef SLAPD_REAL_SYNTAX
681 !is_at_syntax( ad->ad_type, SLAPD_REAL_SYNTAX ) &&
683 !is_at_syntax( ad->ad_type, SLAPD_INTEGER_SYNTAX ) )
686 * attribute values must be INTEGER or REAL
688 snprintf( textbuf, textlen,
689 "%s: attribute syntax inappropriate for increment",
690 ml->sml_type.bv_val );
692 return LDAP_CONSTRAINT_VIOLATION;
698 if( ml->sml_values != NULL ) {
700 slap_syntax_validate_func *validate =
701 ad->ad_type->sat_syntax->ssyn_validate;
702 slap_syntax_transform_func *pretty =
703 ad->ad_type->sat_syntax->ssyn_pretty;
705 if( !pretty && !validate ) {
706 *text = "no validator for syntax";
707 snprintf( textbuf, textlen,
708 "%s: no validator for syntax %s",
710 ad->ad_type->sat_syntax->ssyn_oid );
712 return LDAP_INVALID_SYNTAX;
716 * check that each value is valid per syntax
717 * and pretty if appropriate
719 for( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) {
722 rc = pretty( ad->ad_type->sat_syntax,
723 &ml->sml_values[nvals], &pval, ctx );
725 rc = validate( ad->ad_type->sat_syntax,
726 &ml->sml_values[nvals] );
730 snprintf( textbuf, textlen,
731 "%s: value #%ld invalid per syntax",
732 ml->sml_type.bv_val, (long) nvals );
734 return LDAP_INVALID_SYNTAX;
738 ber_memfree_x( ml->sml_values[nvals].bv_val, ctx );
739 ml->sml_values[nvals] = pval;
744 * a rough single value check... an additional check is needed
745 * to catch add of single value to existing single valued attribute
747 if ((ml->sml_op == LDAP_MOD_ADD || ml->sml_op == LDAP_MOD_REPLACE)
748 && nvals > 1 && is_at_single_value( ad->ad_type ))
750 snprintf( textbuf, textlen,
751 "%s: multiple values provided",
752 ml->sml_type.bv_val );
754 return LDAP_CONSTRAINT_VIOLATION;
757 /* if the type has a normalizer, generate the
758 * normalized values. otherwise leave them NULL.
760 * this is different from the rule for attributes
761 * in an entry - in an attribute list, the normalized
762 * value is set equal to the non-normalized value
763 * when there is no normalizer.
765 if( nvals && ad->ad_type->sat_equality &&
766 ad->ad_type->sat_equality->smr_normalize )
768 ml->sml_nvalues = ber_memalloc_x(
769 (nvals+1)*sizeof(struct berval), ctx );
771 for( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) {
772 rc = ad->ad_type->sat_equality->smr_normalize(
773 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
774 ad->ad_type->sat_syntax,
775 ad->ad_type->sat_equality,
776 &ml->sml_values[nvals], &ml->sml_nvalues[nvals], ctx );
778 Debug( LDAP_DEBUG_ANY,
779 "<= str2entry NULL (ssyn_normalize %d)\n",
781 snprintf( textbuf, textlen,
782 "%s: value #%ld normalization failed",
783 ml->sml_type.bv_val, (long) nvals );
789 ml->sml_nvalues[nvals].bv_val = NULL;
790 ml->sml_nvalues[nvals].bv_len = 0;
793 /* check for duplicates, but ignore Deletes.
795 if( nvals > 1 && ml->sml_op != LDAP_MOD_DELETE ) {
797 MatchingRule *mr = ad->ad_type->sat_equality;
799 for ( i = 1; i < nvals ; i++ ) {
800 /* test asserted values against themselves */
801 for( j = 0; j < i; j++ ) {
802 rc = ordered_value_match( &match, ml->sml_desc, mr,
804 | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX
805 | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH
806 | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH,
808 ? &ml->sml_nvalues[i]
809 : &ml->sml_values[i],
811 ? &ml->sml_nvalues[j]
812 : &ml->sml_values[j],
814 if ( rc == LDAP_SUCCESS && match == 0 ) {
815 /* value exists already */
816 snprintf( textbuf, textlen,
817 "%s: value #%d provided more than once",
818 ml->sml_desc->ad_cname.bv_val, j );
820 return LDAP_TYPE_OR_VALUE_EXISTS;
822 } else if ( rc != LDAP_SUCCESS ) {
835 /* Enter with bv->bv_len = sizeof buffer, returns with
836 * actual length of string
838 void slap_timestamp( time_t *tm, struct berval *bv )
844 ltm = gmtime_r( tm, <m_buf );
846 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
850 bv->bv_len = lutil_gentime( bv->bv_val, bv->bv_len, ltm );
852 #ifndef HAVE_GMTIME_R
853 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
857 int slap_mods_opattrs(
860 Modifications **modtail,
862 char *textbuf, size_t textlen,
865 struct berval name, timestamp, csn;
867 char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
868 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
871 int mop = op->o_tag == LDAP_REQ_ADD
872 ? LDAP_MOD_ADD : LDAP_MOD_REPLACE;
874 assert( modtail != NULL );
875 assert( *modtail == NULL );
877 if ( SLAP_LASTMOD( op->o_bd )) {
878 time_t now = slap_get_time();
880 slap_get_csn( op, csnbuf, sizeof(csnbuf), &csn, manage_ctxcsn );
882 timestamp.bv_val = timebuf;
883 timestamp.bv_len = sizeof(timebuf);
885 slap_timestamp( &now, ×tamp );
887 if( op->o_dn.bv_len == 0 ) {
888 BER_BVSTR( &name, SLAPD_ANONYMOUS );
896 if( op->o_tag == LDAP_REQ_ADD ) {
897 struct berval tmpval;
900 int rc = mods_structural_class( mods, &tmpval,
901 text, textbuf, textlen );
902 if( rc != LDAP_SUCCESS ) return rc;
904 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
906 mod->sml_flags = SLAP_MOD_INTERNAL;
907 mod->sml_type.bv_val = NULL;
908 mod->sml_desc = slap_schema.si_ad_structuralObjectClass;
910 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
911 ber_dupbv( &mod->sml_values[0], &tmpval );
912 mod->sml_values[1].bv_len = 0;
913 mod->sml_values[1].bv_val = NULL;
914 assert( mod->sml_values[0].bv_val );
916 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
917 ber_dupbv( &mod->sml_nvalues[0], &tmpval );
918 mod->sml_nvalues[1].bv_len = 0;
919 mod->sml_nvalues[1].bv_val = NULL;
920 assert( mod->sml_nvalues[0].bv_val );
922 modtail = &mod->sml_next;
925 if ( SLAP_LASTMOD( op->o_bd )) {
926 char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
928 tmpval.bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ) );
929 tmpval.bv_val = uuidbuf;
931 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
933 mod->sml_flags = SLAP_MOD_INTERNAL;
934 mod->sml_type.bv_val = NULL;
935 mod->sml_desc = slap_schema.si_ad_entryUUID;
937 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
938 ber_dupbv( &mod->sml_values[0], &tmpval );
939 mod->sml_values[1].bv_len = 0;
940 mod->sml_values[1].bv_val = NULL;
941 assert( mod->sml_values[0].bv_val );
943 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
944 (*mod->sml_desc->ad_type->sat_equality->smr_normalize)(
945 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
946 mod->sml_desc->ad_type->sat_syntax,
947 mod->sml_desc->ad_type->sat_equality,
948 mod->sml_values, mod->sml_nvalues, NULL );
949 mod->sml_nvalues[1].bv_len = 0;
950 mod->sml_nvalues[1].bv_val = NULL;
952 modtail = &mod->sml_next;
954 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
956 mod->sml_flags = SLAP_MOD_INTERNAL;
957 mod->sml_type.bv_val = NULL;
958 mod->sml_desc = slap_schema.si_ad_creatorsName;
960 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
961 ber_dupbv( &mod->sml_values[0], &name );
962 mod->sml_values[1].bv_len = 0;
963 mod->sml_values[1].bv_val = NULL;
964 assert( mod->sml_values[0].bv_val );
966 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
967 ber_dupbv( &mod->sml_nvalues[0], &nname );
968 mod->sml_nvalues[1].bv_len = 0;
969 mod->sml_nvalues[1].bv_val = NULL;
970 assert( mod->sml_nvalues[0].bv_val );
972 modtail = &mod->sml_next;
974 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
976 mod->sml_flags = SLAP_MOD_INTERNAL;
977 mod->sml_type.bv_val = NULL;
978 mod->sml_desc = slap_schema.si_ad_createTimestamp;
980 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
981 ber_dupbv( &mod->sml_values[0], ×tamp );
982 mod->sml_values[1].bv_len = 0;
983 mod->sml_values[1].bv_val = NULL;
984 assert( mod->sml_values[0].bv_val );
985 mod->sml_nvalues = NULL;
987 modtail = &mod->sml_next;
991 if ( SLAP_LASTMOD( op->o_bd )) {
992 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
994 mod->sml_flags = SLAP_MOD_INTERNAL;
995 mod->sml_type.bv_val = NULL;
996 mod->sml_desc = slap_schema.si_ad_entryCSN;
997 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
998 ber_dupbv( &mod->sml_values[0], &csn );
999 mod->sml_values[1].bv_len = 0;
1000 mod->sml_values[1].bv_val = NULL;
1001 assert( mod->sml_values[0].bv_val );
1002 mod->sml_nvalues = NULL;
1004 modtail = &mod->sml_next;
1006 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
1008 mod->sml_flags = SLAP_MOD_INTERNAL;
1009 mod->sml_type.bv_val = NULL;
1010 mod->sml_desc = slap_schema.si_ad_modifiersName;
1011 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
1012 ber_dupbv( &mod->sml_values[0], &name );
1013 mod->sml_values[1].bv_len = 0;
1014 mod->sml_values[1].bv_val = NULL;
1015 assert( mod->sml_values[0].bv_val );
1017 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
1018 ber_dupbv( &mod->sml_nvalues[0], &nname );
1019 mod->sml_nvalues[1].bv_len = 0;
1020 mod->sml_nvalues[1].bv_val = NULL;
1021 assert( mod->sml_nvalues[0].bv_val );
1023 modtail = &mod->sml_next;
1025 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
1027 mod->sml_flags = SLAP_MOD_INTERNAL;
1028 mod->sml_type.bv_val = NULL;
1029 mod->sml_desc = slap_schema.si_ad_modifyTimestamp;
1030 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
1031 ber_dupbv( &mod->sml_values[0], ×tamp );
1032 mod->sml_values[1].bv_len = 0;
1033 mod->sml_values[1].bv_val = NULL;
1034 assert( mod->sml_values[0].bv_val );
1035 mod->sml_nvalues = NULL;
1037 modtail = &mod->sml_next;
1041 return LDAP_SUCCESS;