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 op->o_bd = frontendDB;
320 send_ldap_result( op, rs );
323 if (rs->sr_ref != default_referral) ber_bvarray_free( rs->sr_ref );
325 op->o_bd = frontendDB;
326 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
327 "no global superior knowledge" );
333 /* check restrictions */
334 if( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
335 send_ldap_result( op, rs );
339 /* check for referrals */
340 if( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
344 /* check for modify/increment support */
345 if( increment && !SLAP_INCREMENT( op->o_bd ) ) {
346 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
347 "modify/increment not supported in context" );
350 #if defined( LDAP_SLAPI )
353 slapi_int_pblock_set_operation( pb, op );
354 slapi_pblock_set( pb, SLAPI_MODIFY_TARGET, (void *)op->o_req_dn.bv_val );
355 slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)manageDSAit );
356 modv = slapi_int_modifications2ldapmods( &modlist );
357 slapi_pblock_set( pb, SLAPI_MODIFY_MODS, (void *)modv );
359 rs->sr_err = slapi_int_call_plugins( op->o_bd,
360 SLAPI_PLUGIN_PRE_MODIFY_FN, pb );
363 * It's possible that the preoperation plugin changed the
364 * modification array, so we need to convert it back to
365 * a Modification list.
367 * Calling slapi_int_modifications2ldapmods() destroyed modlist so
368 * we don't need to free it.
370 slapi_pblock_get( pb, SLAPI_MODIFY_MODS, (void **)&modv );
371 modlist = slapi_int_ldapmods2modifications( modv );
373 if ( rs->sr_err < 0 ) {
375 * A preoperation plugin failure will abort the
378 Debug(LDAP_DEBUG_TRACE,
379 "do_modify: modify preoperation plugin failed.\n",
381 if ( ( slapi_pblock_get( op->o_pb, SLAPI_RESULT_CODE,
382 (void *)&rs->sr_err ) != 0 ) || rs->sr_err == LDAP_SUCCESS )
384 rs->sr_err = LDAP_OTHER;
386 slapi_int_free_ldapmods( modv );
393 * NB: it is valid for the plugin to return no modifications
394 * (for example, a plugin might store some attributes elsewhere
395 * and remove them from the modification list; if only those
396 * attribute types were included in the modification request,
397 * then slapi_int_ldapmods2modifications() above will return
400 * However, the post-operation plugin should still be
403 #endif /* defined( LDAP_SLAPI ) */
406 * do the modify if 1 && (2 || 3)
407 * 1) there is a modify function implemented in this backend;
408 * 2) this backend is master for what it holds;
409 * 3) it's a replica and the dn supplied is the update_ndn.
411 if ( op->o_bd->be_modify ) {
412 /* do the update here */
413 int repl_user = be_isupdate( op );
415 /* Multimaster slapd does not have to check for replicator dn
416 * because it accepts each modify request
418 #ifndef SLAPD_MULTIMASTER
419 if ( !SLAP_SHADOW(op->o_bd) || repl_user )
422 int update = !BER_BVISEMPTY( &op->o_bd->be_update_ndn );
423 char textbuf[ SLAP_TEXT_BUFLEN ];
424 size_t textlen = sizeof( textbuf );
425 slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
429 rs->sr_err = slap_mods_no_update_check( modlist,
430 &rs->sr_text, textbuf, textlen );
431 if ( rs->sr_err != LDAP_SUCCESS ) {
432 send_ldap_result( op, rs );
440 for( modtail = &modlist;
442 modtail = &(*modtail)->sml_next )
447 rs->sr_err = slap_mods_opattrs( op, modlist, modtail,
448 &rs->sr_text, textbuf, textlen, 1 );
449 if( rs->sr_err != LDAP_SUCCESS ) {
450 send_ldap_result( op, rs );
455 op->orm_modlist = modlist;
456 #ifdef SLAPD_MULTIMASTER
460 /* but multimaster slapd logs only the ones
461 * not from a replicator user */
462 cb.sc_next = op->o_callback;
463 op->o_callback = &cb;
465 op->o_bd->be_modify( op, rs );
467 #ifndef SLAPD_MULTIMASTER
468 /* send a referral */
470 BerVarray defref = op->o_bd->be_update_refs
471 ? op->o_bd->be_update_refs : default_referral;
472 if ( defref != NULL ) {
473 rs->sr_ref = referral_rewrite( defref,
475 LDAP_SCOPE_DEFAULT );
476 if ( rs->sr_ref == NULL ) {
477 /* FIXME: must duplicate, because
478 * overlays may muck with it */
481 rs->sr_err = LDAP_REFERRAL;
482 send_ldap_result( op, rs );
483 if ( rs->sr_ref != defref ) {
484 ber_bvarray_free( rs->sr_ref );
488 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
489 "shadow context; no update referral" );
494 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
495 "operation not supported within namingContext" );
498 #if defined( LDAP_SLAPI )
499 if ( pb != NULL && slapi_int_call_plugins( op->o_bd,
500 SLAPI_PLUGIN_POST_MODIFY_FN, pb ) < 0 )
502 Debug(LDAP_DEBUG_TRACE,
503 "do_modify: modify postoperation plugins failed.\n", 0, 0, 0);
505 #endif /* defined( LDAP_SLAPI ) */
508 #if defined( LDAP_SLAPI )
509 if ( modv != NULL ) slapi_int_free_ldapmods( modv );
516 * Do non-update constraint checking.
519 slap_mods_no_update_check(
525 for ( ; ml != NULL; ml = ml->sml_next ) {
526 if ( is_at_no_user_mod( ml->sml_desc->ad_type ) ) {
527 /* user modification disallowed */
528 snprintf( textbuf, textlen,
529 "%s: no user modification allowed",
530 ml->sml_type.bv_val );
532 return LDAP_CONSTRAINT_VIOLATION;
540 * Do basic attribute type checking and syntax validation.
551 for( ; ml != NULL; ml = ml->sml_next ) {
552 AttributeDescription *ad = NULL;
554 /* convert to attribute description */
555 rc = slap_bv2ad( &ml->sml_type, &ml->sml_desc, text );
557 if( rc != LDAP_SUCCESS ) {
558 snprintf( textbuf, textlen, "%s: %s",
559 ml->sml_type.bv_val, *text );
566 if( slap_syntax_is_binary( ad->ad_type->sat_syntax )
567 && !slap_ad_is_binary( ad ))
569 /* attribute requires binary transfer */
570 snprintf( textbuf, textlen,
571 "%s: requires ;binary transfer",
572 ml->sml_type.bv_val );
574 return LDAP_UNDEFINED_TYPE;
577 if( !slap_syntax_is_binary( ad->ad_type->sat_syntax )
578 && slap_ad_is_binary( ad ))
580 /* attribute does not require binary transfer */
581 snprintf( textbuf, textlen,
582 "%s: disallows ;binary transfer",
583 ml->sml_type.bv_val );
585 return LDAP_UNDEFINED_TYPE;
588 if( slap_ad_is_tag_range( ad )) {
589 /* attribute requires binary transfer */
590 snprintf( textbuf, textlen,
591 "%s: inappropriate use of tag range option",
592 ml->sml_type.bv_val );
594 return LDAP_UNDEFINED_TYPE;
598 /* moved to slap_mods_no_update_check() */
599 if (!update && is_at_no_user_mod( ad->ad_type )) {
600 /* user modification disallowed */
601 snprintf( textbuf, textlen,
602 "%s: no user modification allowed",
603 ml->sml_type.bv_val );
605 return LDAP_CONSTRAINT_VIOLATION;
609 if ( is_at_obsolete( ad->ad_type ) &&
610 (( ml->sml_op != LDAP_MOD_REPLACE &&
611 ml->sml_op != LDAP_MOD_DELETE ) ||
612 ml->sml_values != NULL ))
615 * attribute is obsolete,
616 * only allow replace/delete with no values
618 snprintf( textbuf, textlen,
619 "%s: attribute is obsolete",
620 ml->sml_type.bv_val );
622 return LDAP_CONSTRAINT_VIOLATION;
625 if ( ml->sml_op == LDAP_MOD_INCREMENT &&
626 #ifdef SLAPD_REAL_SYNTAX
627 !is_at_syntax( ad->ad_type, SLAPD_REAL_SYNTAX ) &&
629 !is_at_syntax( ad->ad_type, SLAPD_INTEGER_SYNTAX ) )
632 * attribute values must be INTEGER or REAL
634 snprintf( textbuf, textlen,
635 "%s: attribute syntax inappropriate for increment",
636 ml->sml_type.bv_val );
638 return LDAP_CONSTRAINT_VIOLATION;
644 if( ml->sml_values != NULL ) {
646 slap_syntax_validate_func *validate =
647 ad->ad_type->sat_syntax->ssyn_validate;
648 slap_syntax_transform_func *pretty =
649 ad->ad_type->sat_syntax->ssyn_pretty;
651 if( !pretty && !validate ) {
652 *text = "no validator for syntax";
653 snprintf( textbuf, textlen,
654 "%s: no validator for syntax %s",
656 ad->ad_type->sat_syntax->ssyn_oid );
658 return LDAP_INVALID_SYNTAX;
662 * check that each value is valid per syntax
663 * and pretty if appropriate
665 for( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) {
668 rc = pretty( ad->ad_type->sat_syntax,
669 &ml->sml_values[nvals], &pval, ctx );
671 rc = validate( ad->ad_type->sat_syntax,
672 &ml->sml_values[nvals] );
676 snprintf( textbuf, textlen,
677 "%s: value #%ld invalid per syntax",
678 ml->sml_type.bv_val, (long) nvals );
680 return LDAP_INVALID_SYNTAX;
684 ber_memfree_x( ml->sml_values[nvals].bv_val, ctx );
685 ml->sml_values[nvals] = pval;
690 * a rough single value check... an additional check is needed
691 * to catch add of single value to existing single valued attribute
693 if ((ml->sml_op == LDAP_MOD_ADD || ml->sml_op == LDAP_MOD_REPLACE)
694 && nvals > 1 && is_at_single_value( ad->ad_type ))
696 snprintf( textbuf, textlen,
697 "%s: multiple values provided",
698 ml->sml_type.bv_val );
700 return LDAP_CONSTRAINT_VIOLATION;
703 /* if the type has a normalizer, generate the
704 * normalized values. otherwise leave them NULL.
706 * this is different from the rule for attributes
707 * in an entry - in an attribute list, the normalized
708 * value is set equal to the non-normalized value
709 * when there is no normalizer.
711 if( nvals && ad->ad_type->sat_equality &&
712 ad->ad_type->sat_equality->smr_normalize )
714 ml->sml_nvalues = ber_memalloc_x(
715 (nvals+1)*sizeof(struct berval), ctx );
717 for( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) {
718 rc = ad->ad_type->sat_equality->smr_normalize(
719 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
720 ad->ad_type->sat_syntax,
721 ad->ad_type->sat_equality,
722 &ml->sml_values[nvals], &ml->sml_nvalues[nvals], ctx );
724 Debug( LDAP_DEBUG_ANY,
725 "<= str2entry NULL (ssyn_normalize %d)\n",
727 snprintf( textbuf, textlen,
728 "%s: value #%ld normalization failed",
729 ml->sml_type.bv_val, (long) nvals );
735 ml->sml_nvalues[nvals].bv_val = NULL;
736 ml->sml_nvalues[nvals].bv_len = 0;
740 /* check for duplicates */
742 MatchingRule *mr = ad->ad_type->sat_equality;
744 /* check if the values we're adding already exist */
745 if( mr == NULL || !mr->smr_match ) {
746 for ( i = 1; ml->sml_values[i].bv_val != NULL; i++ ) {
747 /* test asserted values against themselves */
748 for( j = 0; j < i; j++ ) {
749 if ( bvmatch( &ml->sml_values[i],
750 &ml->sml_values[j] ) )
752 /* value exists already */
753 snprintf( textbuf, textlen,
754 "%s: value #%d provided more than once",
755 ml->sml_desc->ad_cname.bv_val, j );
757 return LDAP_TYPE_OR_VALUE_EXISTS;
766 for ( i = 1; ml->sml_values[i].bv_val != NULL; i++ ) {
767 /* test asserted values against themselves */
768 for( j = 0; j < i; j++ ) {
769 rc = value_match( &match, ml->sml_desc, mr,
771 | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX
772 | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH
773 | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH,
775 ? &ml->sml_nvalues[i]
776 : &ml->sml_values[i],
778 ? &ml->sml_nvalues[j]
779 : &ml->sml_values[j],
781 if ( rc == LDAP_SUCCESS && match == 0 ) {
782 /* value exists already */
783 snprintf( textbuf, textlen,
784 "%s: value #%d provided more than once",
785 ml->sml_desc->ad_cname.bv_val, j );
787 return LDAP_TYPE_OR_VALUE_EXISTS;
789 } else if ( rc != LDAP_SUCCESS ) {
803 int slap_mods_opattrs(
806 Modifications **modtail,
808 char *textbuf, size_t textlen,
811 struct berval name, timestamp, csn;
813 char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
814 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
817 int mop = op->o_tag == LDAP_REQ_ADD
818 ? LDAP_MOD_ADD : LDAP_MOD_REPLACE;
820 assert( modtail != NULL );
821 assert( *modtail == NULL );
823 if ( SLAP_LASTMOD( op->o_bd )) {
828 time_t now = slap_get_time();
831 ltm = gmtime_r( &now, <m_buf );
833 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
834 ltm = gmtime( &now );
835 #endif /* HAVE_GMTIME_R */
836 lutil_gentime( timebuf, sizeof(timebuf), ltm );
838 slap_get_csn( op, csnbuf, sizeof(csnbuf), &csn, manage_ctxcsn );
840 #ifndef HAVE_GMTIME_R
841 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
844 timestamp.bv_val = timebuf;
845 timestamp.bv_len = strlen(timebuf);
847 if( op->o_dn.bv_len == 0 ) {
848 BER_BVSTR( &name, SLAPD_ANONYMOUS );
856 if( op->o_tag == LDAP_REQ_ADD ) {
857 struct berval tmpval;
859 if( global_schemacheck ) {
860 int rc = mods_structural_class( mods, &tmpval,
861 text, textbuf, textlen );
862 if( rc != LDAP_SUCCESS ) return rc;
864 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
866 mod->sml_type.bv_val = NULL;
867 mod->sml_desc = slap_schema.si_ad_structuralObjectClass;
869 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
870 ber_dupbv( &mod->sml_values[0], &tmpval );
871 mod->sml_values[1].bv_len = 0;
872 mod->sml_values[1].bv_val = NULL;
873 assert( mod->sml_values[0].bv_val );
875 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
876 ber_dupbv( &mod->sml_nvalues[0], &tmpval );
877 mod->sml_nvalues[1].bv_len = 0;
878 mod->sml_nvalues[1].bv_val = NULL;
879 assert( mod->sml_nvalues[0].bv_val );
881 modtail = &mod->sml_next;
884 if ( SLAP_LASTMOD( op->o_bd )) {
885 char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
887 tmpval.bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ) );
888 tmpval.bv_val = uuidbuf;
890 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
892 mod->sml_type.bv_val = NULL;
893 mod->sml_desc = slap_schema.si_ad_entryUUID;
895 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
896 ber_dupbv( &mod->sml_values[0], &tmpval );
897 mod->sml_values[1].bv_len = 0;
898 mod->sml_values[1].bv_val = NULL;
899 assert( mod->sml_values[0].bv_val );
901 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
902 (*mod->sml_desc->ad_type->sat_equality->smr_normalize)(
903 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
904 mod->sml_desc->ad_type->sat_syntax,
905 mod->sml_desc->ad_type->sat_equality,
906 mod->sml_values, mod->sml_nvalues, NULL );
907 mod->sml_nvalues[1].bv_len = 0;
908 mod->sml_nvalues[1].bv_val = NULL;
910 modtail = &mod->sml_next;
912 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
914 mod->sml_type.bv_val = NULL;
915 mod->sml_desc = slap_schema.si_ad_creatorsName;
917 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
918 ber_dupbv( &mod->sml_values[0], &name );
919 mod->sml_values[1].bv_len = 0;
920 mod->sml_values[1].bv_val = NULL;
921 assert( mod->sml_values[0].bv_val );
923 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
924 ber_dupbv( &mod->sml_nvalues[0], &nname );
925 mod->sml_nvalues[1].bv_len = 0;
926 mod->sml_nvalues[1].bv_val = NULL;
927 assert( mod->sml_nvalues[0].bv_val );
929 modtail = &mod->sml_next;
931 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
933 mod->sml_type.bv_val = NULL;
934 mod->sml_desc = slap_schema.si_ad_createTimestamp;
936 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
937 ber_dupbv( &mod->sml_values[0], ×tamp );
938 mod->sml_values[1].bv_len = 0;
939 mod->sml_values[1].bv_val = NULL;
940 assert( mod->sml_values[0].bv_val );
941 mod->sml_nvalues = NULL;
943 modtail = &mod->sml_next;
947 if ( SLAP_LASTMOD( op->o_bd )) {
948 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
950 mod->sml_type.bv_val = NULL;
951 mod->sml_desc = slap_schema.si_ad_entryCSN;
952 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
953 ber_dupbv( &mod->sml_values[0], &csn );
954 mod->sml_values[1].bv_len = 0;
955 mod->sml_values[1].bv_val = NULL;
956 assert( mod->sml_values[0].bv_val );
957 mod->sml_nvalues = NULL;
959 modtail = &mod->sml_next;
961 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
963 mod->sml_type.bv_val = NULL;
964 mod->sml_desc = slap_schema.si_ad_modifiersName;
965 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
966 ber_dupbv( &mod->sml_values[0], &name );
967 mod->sml_values[1].bv_len = 0;
968 mod->sml_values[1].bv_val = NULL;
969 assert( mod->sml_values[0].bv_val );
971 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
972 ber_dupbv( &mod->sml_nvalues[0], &nname );
973 mod->sml_nvalues[1].bv_len = 0;
974 mod->sml_nvalues[1].bv_val = NULL;
975 assert( mod->sml_nvalues[0].bv_val );
977 modtail = &mod->sml_next;
979 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
981 mod->sml_type.bv_val = NULL;
982 mod->sml_desc = slap_schema.si_ad_modifyTimestamp;
983 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
984 ber_dupbv( &mod->sml_values[0], ×tamp );
985 mod->sml_values[1].bv_len = 0;
986 mod->sml_values[1].bv_val = NULL;
987 assert( mod->sml_values[0].bv_val );
988 mod->sml_nvalues = NULL;
990 modtail = &mod->sml_next;