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) );
107 mod->sml_type = tmp.sml_type;
108 mod->sml_values = tmp.sml_values;
109 mod->sml_nvalues = NULL;
110 mod->sml_desc = NULL;
111 mod->sml_next = NULL;
116 if ( mod->sml_values == NULL ) {
117 Debug( LDAP_DEBUG_ANY,
118 "do_modify: modify/add operation (%ld) requires values\n",
121 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
122 "modify/add operation requires values" );
128 case LDAP_MOD_DELETE:
129 case LDAP_MOD_REPLACE:
132 case LDAP_MOD_INCREMENT:
133 if( op->o_protocol >= LDAP_VERSION3 ) {
135 if ( mod->sml_values == NULL ) {
136 Debug( LDAP_DEBUG_ANY, "do_modify: "
137 "modify/increment operation (%ld) requires value\n",
140 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
141 "modify/increment operation requires value" );
145 if( mod->sml_values[1].bv_val ) {
146 Debug( LDAP_DEBUG_ANY, "do_modify: modify/increment "
147 "operation (%ld) requires single value\n",
150 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
151 "modify/increment operation requires single value" );
160 Debug( LDAP_DEBUG_ANY,
161 "do_modify: unrecognized modify operation (%ld)\n",
164 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
165 "unrecognized modify operation" );
170 modtail = &mod->sml_next;
174 if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
175 Debug( LDAP_DEBUG_ANY, "do_modify: get_ctrls failed\n", 0, 0, 0 );
180 rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn,
182 if( rs->sr_err != LDAP_SUCCESS ) {
183 Debug( LDAP_DEBUG_ANY,
184 "do_modify: invalid dn (%s)\n", dn.bv_val, 0, 0 );
185 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
189 rs->sr_err = slap_mods_check( modlist, &rs->sr_text,
190 textbuf, textlen, NULL );
192 if ( rs->sr_err != LDAP_SUCCESS ) {
193 send_ldap_result( op, rs );
197 /* FIXME: needs review */
198 op->orm_modlist = modlist;
199 op->orm_increment = increment;
201 op->o_bd = frontendDB;
202 rs->sr_err = frontendDB->be_modify( op, rs );
205 slap_graduate_commit_csn( op );
207 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
208 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
209 if ( modlist != NULL ) slap_mods_free( modlist );
215 fe_op_modify( Operation *op, SlapReply *rs )
221 Modifications *modlist = op->orm_modlist;
222 Modifications **modtail = &modlist;
224 LDAPMod **modv = NULL;
226 int increment = op->orm_increment;
229 if( op->o_req_ndn.bv_len == 0 ) {
230 Debug( LDAP_DEBUG_ANY, "do_modify: root dse!\n", 0, 0, 0 );
232 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
233 "modify upon the root DSE not supported" );
236 } else if ( bvmatch( &op->o_req_ndn, &frontendDB->be_schemandn ) ) {
237 Debug( LDAP_DEBUG_ANY, "do_modify: subschema subentry!\n", 0, 0, 0 );
239 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
240 "modification of subschema subentry not supported" );
245 Debug( LDAP_DEBUG_ARGS, "modifications:\n", 0, 0, 0 );
247 for ( tmp = modlist; tmp != NULL; tmp = tmp->sml_next ) {
248 Debug( LDAP_DEBUG_ARGS, "\t%s: %s\n",
249 tmp->sml_op == LDAP_MOD_ADD ? "add" :
250 (tmp->sml_op == LDAP_MOD_INCREMENT ? "increment" :
251 (tmp->sml_op == LDAP_MOD_DELETE ? "delete" :
252 "replace")), tmp->sml_type.bv_val, 0 );
254 if ( tmp->sml_values == NULL ) {
255 Debug( LDAP_DEBUG_ARGS, "%s\n",
256 "\t\tno values", NULL, NULL );
257 } else if ( tmp->sml_values[0].bv_val == NULL ) {
258 Debug( LDAP_DEBUG_ARGS, "%s\n",
259 "\t\tzero values", NULL, NULL );
260 } else if ( tmp->sml_values[1].bv_val == NULL ) {
261 Debug( LDAP_DEBUG_ARGS, "%s, length %ld\n",
262 "\t\tone value", (long) tmp->sml_values[0].bv_len, NULL );
264 Debug( LDAP_DEBUG_ARGS, "%s\n",
265 "\t\tmultiple values", NULL, NULL );
269 if ( StatslogTest( LDAP_DEBUG_STATS ) ) {
270 char abuf[BUFSIZ/2], *ptr = abuf;
273 Statslog( LDAP_DEBUG_STATS, "%s MOD dn=\"%s\"\n",
274 op->o_log_prefix, op->o_req_dn.bv_val, 0, 0, 0 );
276 for ( tmp = modlist; tmp != NULL; tmp = tmp->sml_next ) {
277 if (len + 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
278 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
279 op->o_log_prefix, abuf, 0, 0, 0 );
284 if( 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
285 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
286 op->o_log_prefix, tmp->sml_type.bv_val, 0, 0, 0 );
294 ptr = lutil_strcopy(ptr, tmp->sml_type.bv_val);
295 len += tmp->sml_type.bv_len;
298 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
299 op->o_log_prefix, abuf, 0, 0, 0 );
302 #endif /* LDAP_DEBUG */
304 manageDSAit = get_manageDSAit( op );
307 * We could be serving multiple database backends. Select the
308 * appropriate one, or send a referral to our "referral server"
309 * if we don't hold it.
311 op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 1 );
312 if ( op->o_bd == NULL ) {
313 rs->sr_ref = referral_rewrite( default_referral,
314 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
315 if (!rs->sr_ref) rs->sr_ref = default_referral;
317 if (rs->sr_ref != NULL ) {
318 rs->sr_err = LDAP_REFERRAL;
319 send_ldap_result( op, rs );
321 if (rs->sr_ref != default_referral) ber_bvarray_free( rs->sr_ref );
323 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
324 "no global superior knowledge" );
329 /* check restrictions */
330 if( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
331 send_ldap_result( op, rs );
335 /* check for referrals */
336 if( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
340 /* check for modify/increment support */
341 if( increment && !SLAP_INCREMENT( op->o_bd ) ) {
342 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
343 "modify/increment not supported in context" );
346 #if defined( LDAP_SLAPI )
349 slapi_int_pblock_set_operation( pb, op );
350 slapi_pblock_set( pb, SLAPI_MODIFY_TARGET, (void *)op->o_req_dn.bv_val );
351 slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)manageDSAit );
352 modv = slapi_int_modifications2ldapmods( &modlist );
353 slapi_pblock_set( pb, SLAPI_MODIFY_MODS, (void *)modv );
355 rs->sr_err = slapi_int_call_plugins( op->o_bd,
356 SLAPI_PLUGIN_PRE_MODIFY_FN, pb );
359 * It's possible that the preoperation plugin changed the
360 * modification array, so we need to convert it back to
361 * a Modification list.
363 * Calling slapi_int_modifications2ldapmods() destroyed modlist so
364 * we don't need to free it.
366 slapi_pblock_get( pb, SLAPI_MODIFY_MODS, (void **)&modv );
367 modlist = slapi_int_ldapmods2modifications( modv );
369 if ( rs->sr_err < 0 ) {
371 * A preoperation plugin failure will abort the
374 Debug(LDAP_DEBUG_TRACE,
375 "do_modify: modify preoperation plugin failed.\n",
377 if ( ( slapi_pblock_get( op->o_pb, SLAPI_RESULT_CODE,
378 (void *)&rs->sr_err ) != 0 ) || rs->sr_err == LDAP_SUCCESS )
380 rs->sr_err = LDAP_OTHER;
382 slapi_int_free_ldapmods( modv );
389 * NB: it is valid for the plugin to return no modifications
390 * (for example, a plugin might store some attributes elsewhere
391 * and remove them from the modification list; if only those
392 * attribute types were included in the modification request,
393 * then slapi_int_ldapmods2modifications() above will return
396 * However, the post-operation plugin should still be
399 #endif /* defined( LDAP_SLAPI ) */
402 * do the modify if 1 && (2 || 3)
403 * 1) there is a modify function implemented in this backend;
404 * 2) this backend is master for what it holds;
405 * 3) it's a replica and the dn supplied is the update_ndn.
407 if ( op->o_bd->be_modify ) {
408 /* do the update here */
409 int repl_user = be_isupdate( op );
411 /* Multimaster slapd does not have to check for replicator dn
412 * because it accepts each modify request
414 #ifndef SLAPD_MULTIMASTER
415 if ( !SLAP_SHADOW(op->o_bd) || repl_user )
418 int update = !BER_BVISEMPTY( &op->o_bd->be_update_ndn );
419 char textbuf[ SLAP_TEXT_BUFLEN ];
420 size_t textlen = sizeof( textbuf );
421 slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
425 rs->sr_err = slap_mods_no_update_check( modlist,
426 &rs->sr_text, textbuf, textlen );
427 if ( rs->sr_err != LDAP_SUCCESS ) {
428 send_ldap_result( op, rs );
436 for( modtail = &modlist;
438 modtail = &(*modtail)->sml_next )
443 rs->sr_err = slap_mods_opattrs( op, modlist, modtail,
444 &rs->sr_text, textbuf, textlen, 1 );
445 if( rs->sr_err != LDAP_SUCCESS ) {
446 send_ldap_result( op, rs );
451 op->orm_modlist = modlist;
452 #ifdef SLAPD_MULTIMASTER
456 /* but multimaster slapd logs only the ones
457 * not from a replicator user */
458 cb.sc_next = op->o_callback;
459 op->o_callback = &cb;
461 op->o_bd->be_modify( op, rs );
463 #ifndef SLAPD_MULTIMASTER
464 /* send a referral */
466 BerVarray defref = op->o_bd->be_update_refs
467 ? op->o_bd->be_update_refs : default_referral;
468 if ( defref != NULL ) {
469 rs->sr_ref = referral_rewrite( defref,
471 LDAP_SCOPE_DEFAULT );
472 if ( rs->sr_ref == NULL ) {
473 /* FIXME: must duplicate, because
474 * overlays may muck with it */
477 rs->sr_err = LDAP_REFERRAL;
478 send_ldap_result( op, rs );
479 if ( rs->sr_ref != defref ) {
480 ber_bvarray_free( rs->sr_ref );
484 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
485 "shadow context; no update referral" );
490 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
491 "operation not supported within namingContext" );
494 #if defined( LDAP_SLAPI )
495 if ( pb != NULL && slapi_int_call_plugins( op->o_bd,
496 SLAPI_PLUGIN_POST_MODIFY_FN, pb ) < 0 )
498 Debug(LDAP_DEBUG_TRACE,
499 "do_modify: modify postoperation plugins failed.\n", 0, 0, 0);
501 #endif /* defined( LDAP_SLAPI ) */
504 #if defined( LDAP_SLAPI )
505 if ( modv != NULL ) slapi_int_free_ldapmods( modv );
512 * Do non-update constraint checking.
515 slap_mods_no_update_check(
521 for ( ; ml != NULL; ml = ml->sml_next ) {
522 if ( is_at_no_user_mod( ml->sml_desc->ad_type ) ) {
523 /* user modification disallowed */
524 snprintf( textbuf, textlen,
525 "%s: no user modification allowed",
526 ml->sml_type.bv_val );
528 return LDAP_CONSTRAINT_VIOLATION;
536 * Do basic attribute type checking and syntax validation.
547 for( ; ml != NULL; ml = ml->sml_next ) {
548 AttributeDescription *ad = NULL;
550 /* convert to attribute description */
551 rc = slap_bv2ad( &ml->sml_type, &ml->sml_desc, text );
553 if( rc != LDAP_SUCCESS ) {
554 snprintf( textbuf, textlen, "%s: %s",
555 ml->sml_type.bv_val, *text );
562 if( slap_syntax_is_binary( ad->ad_type->sat_syntax )
563 && !slap_ad_is_binary( ad ))
565 /* attribute requires binary transfer */
566 snprintf( textbuf, textlen,
567 "%s: requires ;binary transfer",
568 ml->sml_type.bv_val );
570 return LDAP_UNDEFINED_TYPE;
573 if( !slap_syntax_is_binary( ad->ad_type->sat_syntax )
574 && slap_ad_is_binary( ad ))
576 /* attribute does not require binary transfer */
577 snprintf( textbuf, textlen,
578 "%s: disallows ;binary transfer",
579 ml->sml_type.bv_val );
581 return LDAP_UNDEFINED_TYPE;
584 if( slap_ad_is_tag_range( ad )) {
585 /* attribute requires binary transfer */
586 snprintf( textbuf, textlen,
587 "%s: inappropriate use of tag range option",
588 ml->sml_type.bv_val );
590 return LDAP_UNDEFINED_TYPE;
594 /* moved to slap_mods_no_update_check() */
595 if (!update && is_at_no_user_mod( ad->ad_type )) {
596 /* user modification disallowed */
597 snprintf( textbuf, textlen,
598 "%s: no user modification allowed",
599 ml->sml_type.bv_val );
601 return LDAP_CONSTRAINT_VIOLATION;
605 if ( is_at_obsolete( ad->ad_type ) &&
606 (( ml->sml_op != LDAP_MOD_REPLACE &&
607 ml->sml_op != LDAP_MOD_DELETE ) ||
608 ml->sml_values != NULL ))
611 * attribute is obsolete,
612 * only allow replace/delete with no values
614 snprintf( textbuf, textlen,
615 "%s: attribute is obsolete",
616 ml->sml_type.bv_val );
618 return LDAP_CONSTRAINT_VIOLATION;
621 if ( ml->sml_op == LDAP_MOD_INCREMENT &&
622 #ifdef SLAPD_REAL_SYNTAX
623 !is_at_syntax( ad->ad_type, SLAPD_REAL_SYNTAX ) &&
625 !is_at_syntax( ad->ad_type, SLAPD_INTEGER_SYNTAX ) )
628 * attribute values must be INTEGER or REAL
630 snprintf( textbuf, textlen,
631 "%s: attribute syntax inappropriate for increment",
632 ml->sml_type.bv_val );
634 return LDAP_CONSTRAINT_VIOLATION;
640 if( ml->sml_values != NULL ) {
642 slap_syntax_validate_func *validate =
643 ad->ad_type->sat_syntax->ssyn_validate;
644 slap_syntax_transform_func *pretty =
645 ad->ad_type->sat_syntax->ssyn_pretty;
647 if( !pretty && !validate ) {
648 *text = "no validator for syntax";
649 snprintf( textbuf, textlen,
650 "%s: no validator for syntax %s",
652 ad->ad_type->sat_syntax->ssyn_oid );
654 return LDAP_INVALID_SYNTAX;
658 * check that each value is valid per syntax
659 * and pretty if appropriate
661 for( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) {
664 rc = pretty( ad->ad_type->sat_syntax,
665 &ml->sml_values[nvals], &pval, ctx );
667 rc = validate( ad->ad_type->sat_syntax,
668 &ml->sml_values[nvals] );
672 snprintf( textbuf, textlen,
673 "%s: value #%ld invalid per syntax",
674 ml->sml_type.bv_val, (long) nvals );
676 return LDAP_INVALID_SYNTAX;
680 ber_memfree_x( ml->sml_values[nvals].bv_val, ctx );
681 ml->sml_values[nvals] = pval;
686 * a rough single value check... an additional check is needed
687 * to catch add of single value to existing single valued attribute
689 if ((ml->sml_op == LDAP_MOD_ADD || ml->sml_op == LDAP_MOD_REPLACE)
690 && nvals > 1 && is_at_single_value( ad->ad_type ))
692 snprintf( textbuf, textlen,
693 "%s: multiple values provided",
694 ml->sml_type.bv_val );
696 return LDAP_CONSTRAINT_VIOLATION;
699 /* if the type has a normalizer, generate the
700 * normalized values. otherwise leave them NULL.
702 * this is different from the rule for attributes
703 * in an entry - in an attribute list, the normalized
704 * value is set equal to the non-normalized value
705 * when there is no normalizer.
707 if( nvals && ad->ad_type->sat_equality &&
708 ad->ad_type->sat_equality->smr_normalize )
710 ml->sml_nvalues = ber_memalloc_x(
711 (nvals+1)*sizeof(struct berval), ctx );
713 for( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) {
714 rc = ad->ad_type->sat_equality->smr_normalize(
715 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
716 ad->ad_type->sat_syntax,
717 ad->ad_type->sat_equality,
718 &ml->sml_values[nvals], &ml->sml_nvalues[nvals], ctx );
720 Debug( LDAP_DEBUG_ANY,
721 "<= str2entry NULL (ssyn_normalize %d)\n",
723 snprintf( textbuf, textlen,
724 "%s: value #%ld normalization failed",
725 ml->sml_type.bv_val, (long) nvals );
731 ml->sml_nvalues[nvals].bv_val = NULL;
732 ml->sml_nvalues[nvals].bv_len = 0;
736 /* check for duplicates */
738 MatchingRule *mr = ad->ad_type->sat_equality;
740 /* check if the values we're adding already exist */
741 if( mr == NULL || !mr->smr_match ) {
742 for ( i = 1; ml->sml_values[i].bv_val != NULL; i++ ) {
743 /* test asserted values against themselves */
744 for( j = 0; j < i; j++ ) {
745 if ( bvmatch( &ml->sml_values[i],
746 &ml->sml_values[j] ) )
748 /* value exists already */
749 snprintf( textbuf, textlen,
750 "%s: value #%d provided more than once",
751 ml->sml_desc->ad_cname.bv_val, j );
753 return LDAP_TYPE_OR_VALUE_EXISTS;
762 for ( i = 1; ml->sml_values[i].bv_val != NULL; i++ ) {
763 /* test asserted values against themselves */
764 for( j = 0; j < i; j++ ) {
765 rc = value_match( &match, ml->sml_desc, mr,
767 | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX
768 | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH
769 | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH,
771 ? &ml->sml_nvalues[i]
772 : &ml->sml_values[i],
774 ? &ml->sml_nvalues[j]
775 : &ml->sml_values[j],
777 if ( rc == LDAP_SUCCESS && match == 0 ) {
778 /* value exists already */
779 snprintf( textbuf, textlen,
780 "%s: value #%d provided more than once",
781 ml->sml_desc->ad_cname.bv_val, j );
783 return LDAP_TYPE_OR_VALUE_EXISTS;
785 } else if ( rc != LDAP_SUCCESS ) {
799 int slap_mods_opattrs(
802 Modifications **modtail,
804 char *textbuf, size_t textlen,
807 struct berval name, timestamp, csn;
809 char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
810 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
813 int mop = op->o_tag == LDAP_REQ_ADD
814 ? LDAP_MOD_ADD : LDAP_MOD_REPLACE;
816 assert( modtail != NULL );
817 assert( *modtail == NULL );
819 if ( SLAP_LASTMOD( op->o_bd )) {
824 time_t now = slap_get_time();
827 ltm = gmtime_r( &now, <m_buf );
829 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
830 ltm = gmtime( &now );
831 #endif /* HAVE_GMTIME_R */
832 lutil_gentime( timebuf, sizeof(timebuf), ltm );
834 slap_get_csn( op, csnbuf, sizeof(csnbuf), &csn, manage_ctxcsn );
836 #ifndef HAVE_GMTIME_R
837 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
840 timestamp.bv_val = timebuf;
841 timestamp.bv_len = strlen(timebuf);
843 if( op->o_dn.bv_len == 0 ) {
844 BER_BVSTR( &name, SLAPD_ANONYMOUS );
852 if( op->o_tag == LDAP_REQ_ADD ) {
853 struct berval tmpval;
855 if( global_schemacheck ) {
856 int rc = mods_structural_class( mods, &tmpval,
857 text, textbuf, textlen );
858 if( rc != LDAP_SUCCESS ) return rc;
860 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
862 mod->sml_type.bv_val = NULL;
863 mod->sml_desc = slap_schema.si_ad_structuralObjectClass;
865 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
866 ber_dupbv( &mod->sml_values[0], &tmpval );
867 mod->sml_values[1].bv_len = 0;
868 mod->sml_values[1].bv_val = NULL;
869 assert( mod->sml_values[0].bv_val );
871 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
872 ber_dupbv( &mod->sml_nvalues[0], &tmpval );
873 mod->sml_nvalues[1].bv_len = 0;
874 mod->sml_nvalues[1].bv_val = NULL;
875 assert( mod->sml_nvalues[0].bv_val );
877 modtail = &mod->sml_next;
880 if ( SLAP_LASTMOD( op->o_bd )) {
881 char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
883 tmpval.bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ) );
884 tmpval.bv_val = uuidbuf;
886 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
888 mod->sml_type.bv_val = NULL;
889 mod->sml_desc = slap_schema.si_ad_entryUUID;
891 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
892 ber_dupbv( &mod->sml_values[0], &tmpval );
893 mod->sml_values[1].bv_len = 0;
894 mod->sml_values[1].bv_val = NULL;
895 assert( mod->sml_values[0].bv_val );
897 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
898 (*mod->sml_desc->ad_type->sat_equality->smr_normalize)(
899 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
900 mod->sml_desc->ad_type->sat_syntax,
901 mod->sml_desc->ad_type->sat_equality,
902 mod->sml_values, mod->sml_nvalues, NULL );
903 mod->sml_nvalues[1].bv_len = 0;
904 mod->sml_nvalues[1].bv_val = NULL;
906 modtail = &mod->sml_next;
908 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
910 mod->sml_type.bv_val = NULL;
911 mod->sml_desc = slap_schema.si_ad_creatorsName;
913 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
914 ber_dupbv( &mod->sml_values[0], &name );
915 mod->sml_values[1].bv_len = 0;
916 mod->sml_values[1].bv_val = NULL;
917 assert( mod->sml_values[0].bv_val );
919 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
920 ber_dupbv( &mod->sml_nvalues[0], &nname );
921 mod->sml_nvalues[1].bv_len = 0;
922 mod->sml_nvalues[1].bv_val = NULL;
923 assert( mod->sml_nvalues[0].bv_val );
925 modtail = &mod->sml_next;
927 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
929 mod->sml_type.bv_val = NULL;
930 mod->sml_desc = slap_schema.si_ad_createTimestamp;
932 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
933 ber_dupbv( &mod->sml_values[0], ×tamp );
934 mod->sml_values[1].bv_len = 0;
935 mod->sml_values[1].bv_val = NULL;
936 assert( mod->sml_values[0].bv_val );
937 mod->sml_nvalues = NULL;
939 modtail = &mod->sml_next;
943 if ( SLAP_LASTMOD( op->o_bd )) {
944 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
946 mod->sml_type.bv_val = NULL;
947 mod->sml_desc = slap_schema.si_ad_entryCSN;
948 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
949 ber_dupbv( &mod->sml_values[0], &csn );
950 mod->sml_values[1].bv_len = 0;
951 mod->sml_values[1].bv_val = NULL;
952 assert( mod->sml_values[0].bv_val );
953 mod->sml_nvalues = NULL;
955 modtail = &mod->sml_next;
957 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
959 mod->sml_type.bv_val = NULL;
960 mod->sml_desc = slap_schema.si_ad_modifiersName;
961 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
962 ber_dupbv( &mod->sml_values[0], &name );
963 mod->sml_values[1].bv_len = 0;
964 mod->sml_values[1].bv_val = NULL;
965 assert( mod->sml_values[0].bv_val );
967 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
968 ber_dupbv( &mod->sml_nvalues[0], &nname );
969 mod->sml_nvalues[1].bv_len = 0;
970 mod->sml_nvalues[1].bv_val = NULL;
971 assert( mod->sml_nvalues[0].bv_val );
973 modtail = &mod->sml_next;
975 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
977 mod->sml_type.bv_val = NULL;
978 mod->sml_desc = slap_schema.si_ad_modifyTimestamp;
979 mod->sml_values = (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 );
984 mod->sml_nvalues = NULL;
986 modtail = &mod->sml_next;