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;
229 char textbuf[ SLAP_TEXT_BUFLEN ];
230 size_t textlen = sizeof( textbuf );
232 if( op->o_req_ndn.bv_len == 0 ) {
233 Debug( LDAP_DEBUG_ANY, "do_modify: root dse!\n", 0, 0, 0 );
235 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
236 "modify upon the root DSE not supported" );
239 } else if ( bvmatch( &op->o_req_ndn, &frontendDB->be_schemandn ) ) {
240 Debug( LDAP_DEBUG_ANY, "do_modify: subschema subentry!\n", 0, 0, 0 );
242 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
243 "modification of subschema subentry not supported" );
248 Debug( LDAP_DEBUG_ARGS, "modifications:\n", 0, 0, 0 );
250 for ( tmp = modlist; tmp != NULL; tmp = tmp->sml_next ) {
251 Debug( LDAP_DEBUG_ARGS, "\t%s: %s\n",
252 tmp->sml_op == LDAP_MOD_ADD ? "add" :
253 (tmp->sml_op == LDAP_MOD_INCREMENT ? "increment" :
254 (tmp->sml_op == LDAP_MOD_DELETE ? "delete" :
255 "replace")), tmp->sml_type.bv_val, 0 );
257 if ( tmp->sml_values == NULL ) {
258 Debug( LDAP_DEBUG_ARGS, "%s\n",
259 "\t\tno values", NULL, NULL );
260 } else if ( tmp->sml_values[0].bv_val == NULL ) {
261 Debug( LDAP_DEBUG_ARGS, "%s\n",
262 "\t\tzero values", NULL, NULL );
263 } else if ( tmp->sml_values[1].bv_val == NULL ) {
264 Debug( LDAP_DEBUG_ARGS, "%s, length %ld\n",
265 "\t\tone value", (long) tmp->sml_values[0].bv_len, NULL );
267 Debug( LDAP_DEBUG_ARGS, "%s\n",
268 "\t\tmultiple values", NULL, NULL );
272 if ( StatslogTest( LDAP_DEBUG_STATS ) ) {
273 char abuf[BUFSIZ/2], *ptr = abuf;
276 Statslog( LDAP_DEBUG_STATS, "%s MOD dn=\"%s\"\n",
277 op->o_log_prefix, op->o_req_dn.bv_val, 0, 0, 0 );
279 for ( tmp = modlist; tmp != NULL; tmp = tmp->sml_next ) {
280 if (len + 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
281 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
282 op->o_log_prefix, abuf, 0, 0, 0 );
287 if( 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
288 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
289 op->o_log_prefix, tmp->sml_type.bv_val, 0, 0, 0 );
297 ptr = lutil_strcopy(ptr, tmp->sml_type.bv_val);
298 len += tmp->sml_type.bv_len;
301 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
302 op->o_log_prefix, abuf, 0, 0, 0 );
305 #endif /* LDAP_DEBUG */
307 manageDSAit = get_manageDSAit( op );
310 * We could be serving multiple database backends. Select the
311 * appropriate one, or send a referral to our "referral server"
312 * if we don't hold it.
314 op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 1 );
315 if ( op->o_bd == NULL ) {
316 rs->sr_ref = referral_rewrite( default_referral,
317 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
318 if (!rs->sr_ref) rs->sr_ref = default_referral;
320 if (rs->sr_ref != NULL ) {
321 rs->sr_err = LDAP_REFERRAL;
322 op->o_bd = frontendDB;
323 send_ldap_result( op, rs );
326 if (rs->sr_ref != default_referral) ber_bvarray_free( rs->sr_ref );
328 op->o_bd = frontendDB;
329 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
330 "no global superior knowledge" );
336 /* If we've got a glued backend, check the real backend */
338 if ( SLAP_GLUE_INSTANCE( op->o_bd )) {
339 op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 0 );
342 /* check restrictions */
343 if( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
344 send_ldap_result( op, rs );
348 /* check for referrals */
349 if( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
354 rs->sr_err = slap_mods_obsolete_check( op, modlist,
355 &rs->sr_text, textbuf, textlen );
356 if ( rs->sr_err != LDAP_SUCCESS ) {
357 send_ldap_result( op, rs );
362 /* check for modify/increment support */
363 if( increment && !SLAP_INCREMENT( op->o_bd ) ) {
364 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
365 "modify/increment not supported in context" );
368 #if defined( LDAP_SLAPI )
371 slapi_int_pblock_set_operation( pb, op );
372 slapi_pblock_set( pb, SLAPI_MODIFY_TARGET, (void *)op->o_req_dn.bv_val );
373 slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)manageDSAit );
374 modv = slapi_int_modifications2ldapmods( &modlist );
375 slapi_pblock_set( pb, SLAPI_MODIFY_MODS, (void *)modv );
377 rs->sr_err = slapi_int_call_plugins( op->o_bd,
378 SLAPI_PLUGIN_PRE_MODIFY_FN, pb );
381 * It's possible that the preoperation plugin changed the
382 * modification array, so we need to convert it back to
383 * a Modification list.
385 * Calling slapi_int_modifications2ldapmods() destroyed modlist so
386 * we don't need to free it.
388 slapi_pblock_get( pb, SLAPI_MODIFY_MODS, (void **)&modv );
389 modlist = slapi_int_ldapmods2modifications( modv );
391 if ( rs->sr_err < 0 ) {
393 * A preoperation plugin failure will abort the
396 Debug(LDAP_DEBUG_TRACE,
397 "do_modify: modify preoperation plugin failed.\n",
399 if ( ( slapi_pblock_get( op->o_pb, SLAPI_RESULT_CODE,
400 (void *)&rs->sr_err ) != 0 ) || rs->sr_err == LDAP_SUCCESS )
402 rs->sr_err = LDAP_OTHER;
404 slapi_int_free_ldapmods( modv );
411 * NB: it is valid for the plugin to return no modifications
412 * (for example, a plugin might store some attributes elsewhere
413 * and remove them from the modification list; if only those
414 * attribute types were included in the modification request,
415 * then slapi_int_ldapmods2modifications() above will return
418 * However, the post-operation plugin should still be
421 #endif /* defined( LDAP_SLAPI ) */
424 * do the modify if 1 && (2 || 3)
425 * 1) there is a modify function implemented in this backend;
426 * 2) this backend is master for what it holds;
427 * 3) it's a replica and the dn supplied is the update_ndn.
429 if ( op->o_bd->be_modify ) {
430 /* do the update here */
431 int repl_user = be_isupdate( op );
433 /* Multimaster slapd does not have to check for replicator dn
434 * because it accepts each modify request
436 #ifndef SLAPD_MULTIMASTER
437 if ( !SLAP_SHADOW(op->o_bd) || repl_user )
440 int update = !BER_BVISEMPTY( &op->o_bd->be_update_ndn );
441 slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
446 rs->sr_err = slap_mods_no_user_mod_check( op, modlist,
447 &rs->sr_text, textbuf, textlen );
448 if ( rs->sr_err != LDAP_SUCCESS ) {
449 send_ldap_result( op, rs );
455 for( modtail = &modlist;
457 modtail = &(*modtail)->sml_next )
462 rs->sr_err = slap_mods_opattrs( op, modlist, modtail,
463 &rs->sr_text, textbuf, textlen, 1 );
464 if( rs->sr_err != LDAP_SUCCESS ) {
465 send_ldap_result( op, rs );
470 op->orm_modlist = modlist;
471 #ifdef SLAPD_MULTIMASTER
475 /* but multimaster slapd logs only the ones
476 * not from a replicator user */
477 cb.sc_next = op->o_callback;
478 op->o_callback = &cb;
480 op->o_bd->be_modify( op, rs );
482 #ifndef SLAPD_MULTIMASTER
483 /* send a referral */
485 BerVarray defref = op->o_bd->be_update_refs
486 ? op->o_bd->be_update_refs : default_referral;
487 if ( defref != NULL ) {
488 rs->sr_ref = referral_rewrite( defref,
490 LDAP_SCOPE_DEFAULT );
491 if ( rs->sr_ref == NULL ) {
492 /* FIXME: must duplicate, because
493 * overlays may muck with it */
496 rs->sr_err = LDAP_REFERRAL;
497 send_ldap_result( op, rs );
498 if ( rs->sr_ref != defref ) {
499 ber_bvarray_free( rs->sr_ref );
503 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
504 "shadow context; no update referral" );
509 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
510 "operation not supported within namingContext" );
513 #if defined( LDAP_SLAPI )
514 if ( pb != NULL && slapi_int_call_plugins( op->o_bd,
515 SLAPI_PLUGIN_POST_MODIFY_FN, pb ) < 0 )
517 Debug(LDAP_DEBUG_TRACE,
518 "do_modify: modify postoperation plugins failed.\n", 0, 0, 0);
520 #endif /* defined( LDAP_SLAPI ) */
523 #if defined( LDAP_SLAPI )
524 if ( modv != NULL ) slapi_int_free_ldapmods( modv );
531 * Obsolete constraint checking.
534 slap_mods_obsolete_check(
541 if( get_manageDIT( op ) ) return LDAP_SUCCESS;
543 for ( ; ml != NULL; ml = ml->sml_next ) {
544 if ( is_at_obsolete( ml->sml_desc->ad_type ) &&
545 (( ml->sml_op != LDAP_MOD_REPLACE &&
546 ml->sml_op != LDAP_MOD_DELETE ) ||
547 ml->sml_values != NULL ))
550 * attribute is obsolete,
551 * only allow replace/delete with no values
553 snprintf( textbuf, textlen,
554 "%s: attribute is obsolete",
555 ml->sml_type.bv_val );
557 return LDAP_CONSTRAINT_VIOLATION;
565 * No-user-modification constraint checking.
568 slap_mods_no_user_mod_check(
575 for ( ; ml != NULL; ml = ml->sml_next ) {
576 if ( !is_at_no_user_mod( ml->sml_desc->ad_type ) ) continue;
578 if( get_manageDIT( op )) {
579 if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_MANAGEABLE ) {
583 /* attribute not manageable */
584 snprintf( textbuf, textlen,
585 "%s: no-user-modification attribute not manageable",
586 ml->sml_type.bv_val );
589 /* user modification disallowed */
590 snprintf( textbuf, textlen,
591 "%s: no user modification allowed",
592 ml->sml_type.bv_val );
596 return LDAP_CONSTRAINT_VIOLATION;
603 * Do basic attribute type checking and syntax validation.
614 for( ; ml != NULL; ml = ml->sml_next ) {
615 AttributeDescription *ad = NULL;
617 /* convert to attribute description */
618 rc = slap_bv2ad( &ml->sml_type, &ml->sml_desc, text );
620 if( rc != LDAP_SUCCESS ) {
621 snprintf( textbuf, textlen, "%s: %s",
622 ml->sml_type.bv_val, *text );
629 if( slap_syntax_is_binary( ad->ad_type->sat_syntax )
630 && !slap_ad_is_binary( ad ))
632 /* attribute requires binary transfer */
633 snprintf( textbuf, textlen,
634 "%s: requires ;binary transfer",
635 ml->sml_type.bv_val );
637 return LDAP_UNDEFINED_TYPE;
640 if( !slap_syntax_is_binary( ad->ad_type->sat_syntax )
641 && slap_ad_is_binary( ad ))
643 /* attribute does not require binary transfer */
644 snprintf( textbuf, textlen,
645 "%s: disallows ;binary transfer",
646 ml->sml_type.bv_val );
648 return LDAP_UNDEFINED_TYPE;
651 if( slap_ad_is_tag_range( ad )) {
652 /* attribute requires binary transfer */
653 snprintf( textbuf, textlen,
654 "%s: inappropriate use of tag range option",
655 ml->sml_type.bv_val );
657 return LDAP_UNDEFINED_TYPE;
661 if ( is_at_obsolete( ad->ad_type ) &&
662 (( ml->sml_op != LDAP_MOD_REPLACE &&
663 ml->sml_op != LDAP_MOD_DELETE ) ||
664 ml->sml_values != NULL ))
667 * attribute is obsolete,
668 * only allow replace/delete with no values
670 snprintf( textbuf, textlen,
671 "%s: attribute is obsolete",
672 ml->sml_type.bv_val );
674 return LDAP_CONSTRAINT_VIOLATION;
678 if ( ml->sml_op == LDAP_MOD_INCREMENT &&
679 #ifdef SLAPD_REAL_SYNTAX
680 !is_at_syntax( ad->ad_type, SLAPD_REAL_SYNTAX ) &&
682 !is_at_syntax( ad->ad_type, SLAPD_INTEGER_SYNTAX ) )
685 * attribute values must be INTEGER or REAL
687 snprintf( textbuf, textlen,
688 "%s: attribute syntax inappropriate for increment",
689 ml->sml_type.bv_val );
691 return LDAP_CONSTRAINT_VIOLATION;
697 if( ml->sml_values != NULL ) {
699 slap_syntax_validate_func *validate =
700 ad->ad_type->sat_syntax->ssyn_validate;
701 slap_syntax_transform_func *pretty =
702 ad->ad_type->sat_syntax->ssyn_pretty;
704 if( !pretty && !validate ) {
705 *text = "no validator for syntax";
706 snprintf( textbuf, textlen,
707 "%s: no validator for syntax %s",
709 ad->ad_type->sat_syntax->ssyn_oid );
711 return LDAP_INVALID_SYNTAX;
715 * check that each value is valid per syntax
716 * and pretty if appropriate
718 for( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) {
721 rc = pretty( ad->ad_type->sat_syntax,
722 &ml->sml_values[nvals], &pval, ctx );
724 rc = validate( ad->ad_type->sat_syntax,
725 &ml->sml_values[nvals] );
729 snprintf( textbuf, textlen,
730 "%s: value #%ld invalid per syntax",
731 ml->sml_type.bv_val, (long) nvals );
733 return LDAP_INVALID_SYNTAX;
737 ber_memfree_x( ml->sml_values[nvals].bv_val, ctx );
738 ml->sml_values[nvals] = pval;
743 * a rough single value check... an additional check is needed
744 * to catch add of single value to existing single valued attribute
746 if ((ml->sml_op == LDAP_MOD_ADD || ml->sml_op == LDAP_MOD_REPLACE)
747 && nvals > 1 && is_at_single_value( ad->ad_type ))
749 snprintf( textbuf, textlen,
750 "%s: multiple values provided",
751 ml->sml_type.bv_val );
753 return LDAP_CONSTRAINT_VIOLATION;
756 /* if the type has a normalizer, generate the
757 * normalized values. otherwise leave them NULL.
759 * this is different from the rule for attributes
760 * in an entry - in an attribute list, the normalized
761 * value is set equal to the non-normalized value
762 * when there is no normalizer.
764 if( nvals && ad->ad_type->sat_equality &&
765 ad->ad_type->sat_equality->smr_normalize )
767 ml->sml_nvalues = ber_memalloc_x(
768 (nvals+1)*sizeof(struct berval), ctx );
770 for( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) {
771 rc = ad->ad_type->sat_equality->smr_normalize(
772 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
773 ad->ad_type->sat_syntax,
774 ad->ad_type->sat_equality,
775 &ml->sml_values[nvals], &ml->sml_nvalues[nvals], ctx );
777 Debug( LDAP_DEBUG_ANY,
778 "<= str2entry NULL (ssyn_normalize %d)\n",
780 snprintf( textbuf, textlen,
781 "%s: value #%ld normalization failed",
782 ml->sml_type.bv_val, (long) nvals );
788 ml->sml_nvalues[nvals].bv_val = NULL;
789 ml->sml_nvalues[nvals].bv_len = 0;
792 /* check for duplicates, but ignore Deletes.
794 if( nvals > 1 && ml->sml_op != LDAP_MOD_DELETE ) {
796 MatchingRule *mr = ad->ad_type->sat_equality;
798 for ( i = 1; i < nvals ; i++ ) {
799 /* test asserted values against themselves */
800 for( j = 0; j < i; j++ ) {
801 rc = ordered_value_match( &match, ml->sml_desc, mr,
803 | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX
804 | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH
805 | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH,
807 ? &ml->sml_nvalues[i]
808 : &ml->sml_values[i],
810 ? &ml->sml_nvalues[j]
811 : &ml->sml_values[j],
813 if ( rc == LDAP_SUCCESS && match == 0 ) {
814 /* value exists already */
815 snprintf( textbuf, textlen,
816 "%s: value #%d provided more than once",
817 ml->sml_desc->ad_cname.bv_val, j );
819 return LDAP_TYPE_OR_VALUE_EXISTS;
821 } else if ( rc != LDAP_SUCCESS ) {
834 /* Enter with bv->bv_len = sizeof buffer, returns with
835 * actual length of string
837 void slap_timestamp( time_t *tm, struct berval *bv )
843 ltm = gmtime_r( tm, <m_buf );
845 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
849 bv->bv_len = lutil_gentime( bv->bv_val, bv->bv_len, ltm );
851 #ifndef HAVE_GMTIME_R
852 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
856 int slap_mods_opattrs(
859 Modifications **modtail,
861 char *textbuf, size_t textlen,
864 struct berval name, timestamp, csn;
866 char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
867 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
870 int mop = op->o_tag == LDAP_REQ_ADD
871 ? LDAP_MOD_ADD : LDAP_MOD_REPLACE;
873 assert( modtail != NULL );
874 assert( *modtail == NULL );
876 if ( SLAP_LASTMOD( op->o_bd )) {
877 time_t now = slap_get_time();
879 slap_get_csn( op, csnbuf, sizeof(csnbuf), &csn, manage_ctxcsn );
881 timestamp.bv_val = timebuf;
882 timestamp.bv_len = sizeof(timebuf);
884 slap_timestamp( &now, ×tamp );
886 if( op->o_dn.bv_len == 0 ) {
887 BER_BVSTR( &name, SLAPD_ANONYMOUS );
895 if( op->o_tag == LDAP_REQ_ADD ) {
896 struct berval tmpval;
899 int rc = mods_structural_class( mods, &tmpval,
900 text, textbuf, textlen );
901 if( rc != LDAP_SUCCESS ) return rc;
903 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
905 mod->sml_flags = SLAP_MOD_INTERNAL;
906 mod->sml_type.bv_val = NULL;
907 mod->sml_desc = slap_schema.si_ad_structuralObjectClass;
909 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
910 ber_dupbv( &mod->sml_values[0], &tmpval );
911 mod->sml_values[1].bv_len = 0;
912 mod->sml_values[1].bv_val = NULL;
913 assert( mod->sml_values[0].bv_val != NULL );
915 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
916 ber_dupbv( &mod->sml_nvalues[0], &tmpval );
917 mod->sml_nvalues[1].bv_len = 0;
918 mod->sml_nvalues[1].bv_val = NULL;
919 assert( mod->sml_nvalues[0].bv_val != NULL );
921 modtail = &mod->sml_next;
924 if ( SLAP_LASTMOD( op->o_bd )) {
925 char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
927 tmpval.bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ) );
928 tmpval.bv_val = uuidbuf;
930 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
932 mod->sml_flags = SLAP_MOD_INTERNAL;
933 mod->sml_type.bv_val = NULL;
934 mod->sml_desc = slap_schema.si_ad_entryUUID;
936 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
937 ber_dupbv( &mod->sml_values[0], &tmpval );
938 mod->sml_values[1].bv_len = 0;
939 mod->sml_values[1].bv_val = NULL;
940 assert( mod->sml_values[0].bv_val != NULL );
942 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
943 (*mod->sml_desc->ad_type->sat_equality->smr_normalize)(
944 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
945 mod->sml_desc->ad_type->sat_syntax,
946 mod->sml_desc->ad_type->sat_equality,
947 mod->sml_values, mod->sml_nvalues, NULL );
948 mod->sml_nvalues[1].bv_len = 0;
949 mod->sml_nvalues[1].bv_val = NULL;
951 modtail = &mod->sml_next;
953 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
955 mod->sml_flags = SLAP_MOD_INTERNAL;
956 mod->sml_type.bv_val = NULL;
957 mod->sml_desc = slap_schema.si_ad_creatorsName;
959 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
960 ber_dupbv( &mod->sml_values[0], &name );
961 mod->sml_values[1].bv_len = 0;
962 mod->sml_values[1].bv_val = NULL;
963 assert( mod->sml_values[0].bv_val != NULL );
965 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
966 ber_dupbv( &mod->sml_nvalues[0], &nname );
967 mod->sml_nvalues[1].bv_len = 0;
968 mod->sml_nvalues[1].bv_val = NULL;
969 assert( mod->sml_nvalues[0].bv_val != NULL );
971 modtail = &mod->sml_next;
973 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
975 mod->sml_flags = SLAP_MOD_INTERNAL;
976 mod->sml_type.bv_val = NULL;
977 mod->sml_desc = slap_schema.si_ad_createTimestamp;
979 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
980 ber_dupbv( &mod->sml_values[0], ×tamp );
981 mod->sml_values[1].bv_len = 0;
982 mod->sml_values[1].bv_val = NULL;
983 assert( mod->sml_values[0].bv_val != NULL );
984 mod->sml_nvalues = NULL;
986 modtail = &mod->sml_next;
990 if ( SLAP_LASTMOD( op->o_bd )) {
991 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
993 mod->sml_flags = SLAP_MOD_INTERNAL;
994 mod->sml_type.bv_val = NULL;
995 mod->sml_desc = slap_schema.si_ad_entryCSN;
996 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
997 ber_dupbv( &mod->sml_values[0], &csn );
998 mod->sml_values[1].bv_len = 0;
999 mod->sml_values[1].bv_val = NULL;
1000 assert( mod->sml_values[0].bv_val != NULL );
1001 mod->sml_nvalues = NULL;
1003 modtail = &mod->sml_next;
1005 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
1007 mod->sml_flags = SLAP_MOD_INTERNAL;
1008 mod->sml_type.bv_val = NULL;
1009 mod->sml_desc = slap_schema.si_ad_modifiersName;
1010 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
1011 ber_dupbv( &mod->sml_values[0], &name );
1012 mod->sml_values[1].bv_len = 0;
1013 mod->sml_values[1].bv_val = NULL;
1014 assert( mod->sml_values[0].bv_val != NULL );
1016 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
1017 ber_dupbv( &mod->sml_nvalues[0], &nname );
1018 mod->sml_nvalues[1].bv_len = 0;
1019 mod->sml_nvalues[1].bv_val = NULL;
1020 assert( mod->sml_nvalues[0].bv_val != NULL );
1022 modtail = &mod->sml_next;
1024 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
1026 mod->sml_flags = SLAP_MOD_INTERNAL;
1027 mod->sml_type.bv_val = NULL;
1028 mod->sml_desc = slap_schema.si_ad_modifyTimestamp;
1029 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
1030 ber_dupbv( &mod->sml_values[0], ×tamp );
1031 mod->sml_values[1].bv_len = 0;
1032 mod->sml_values[1].bv_val = NULL;
1033 assert( mod->sml_values[0].bv_val != NULL );
1034 mod->sml_nvalues = NULL;
1036 modtail = &mod->sml_next;
1040 return LDAP_SUCCESS;