2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2004 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>
37 #include "slapi/slapi.h"
47 struct berval dn = BER_BVNULL;
51 Modifications *modlist = NULL;
52 Modifications **modtail = &modlist;
57 LDAPMod **modv = NULL;
63 LDAP_LOG( OPERATION, ENTRY, "do_modify: enter\n", 0, 0, 0 );
65 Debug( LDAP_DEBUG_TRACE, "do_modify\n", 0, 0, 0 );
69 * Parse the modify request. It looks like this:
71 * ModifyRequest := [APPLICATION 6] SEQUENCE {
72 * name DistinguishedName,
73 * mods SEQUENCE OF SEQUENCE {
74 * operation ENUMERATED {
79 * modification SEQUENCE {
81 * values SET OF AttributeValue
87 if ( ber_scanf( op->o_ber, "{m" /*}*/, &dn ) == LBER_ERROR ) {
89 LDAP_LOG( OPERATION, ERR, "do_modify: ber_scanf failed\n", 0, 0, 0 );
91 Debug( LDAP_DEBUG_ANY, "do_modify: ber_scanf failed\n", 0, 0, 0 );
94 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
95 return SLAPD_DISCONNECT;
99 LDAP_LOG( OPERATION, ARGS, "do_modify: dn (%s)\n", dn.bv_val, 0, 0 );
101 Debug( LDAP_DEBUG_ARGS, "do_modify: dn (%s)\n", dn.bv_val, 0, 0 );
104 /* collect modifications & save for later */
105 for ( tag = ber_first_element( op->o_ber, &len, &last );
107 tag = ber_next_element( op->o_ber, &len, last ) )
110 Modifications tmp, *mod;
112 tmp.sml_nvalues = NULL;
114 if ( ber_scanf( op->o_ber, "{i{m[W]}}", &mop,
115 &tmp.sml_type, &tmp.sml_values ) == LBER_ERROR )
117 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR,
118 "decoding modlist error" );
119 rs->sr_err = SLAPD_DISCONNECT;
123 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
125 mod->sml_type = tmp.sml_type;
126 mod->sml_values = tmp.sml_values;
127 mod->sml_nvalues = NULL;
128 mod->sml_desc = NULL;
129 mod->sml_next = NULL;
134 if ( mod->sml_values == NULL ) {
136 LDAP_LOG( OPERATION, ERR,
137 "do_modify: modify/add operation (%ld) requires values\n",
140 Debug( LDAP_DEBUG_ANY,
141 "do_modify: modify/add operation (%ld) requires values\n",
145 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
146 "modify/add operation requires values" );
152 case LDAP_MOD_DELETE:
153 case LDAP_MOD_REPLACE:
156 case LDAP_MOD_INCREMENT:
157 if( op->o_protocol >= LDAP_VERSION3 ) {
159 if ( mod->sml_values == NULL ) {
161 LDAP_LOG( OPERATION, ERR, "do_modify: "
162 "modify/increment operation (%ld) requires value\n",
165 Debug( LDAP_DEBUG_ANY, "do_modify: "
166 "modify/increment operation (%ld) requires value\n",
170 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
171 "modify/increment operation requires value" );
175 if( mod->sml_values[1].bv_val ) {
177 LDAP_LOG( OPERATION, ERR, "do_modify: modify/increment "
178 "operation (%ld) requires single value\n",
181 Debug( LDAP_DEBUG_ANY, "do_modify: modify/increment "
182 "operation (%ld) requires single value\n",
186 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
187 "modify/increment operation requires single value" );
197 LDAP_LOG( OPERATION, ERR,
198 "do_modify: unrecognized modify operation (%ld)\n",
201 Debug( LDAP_DEBUG_ANY,
202 "do_modify: unrecognized modify operation (%ld)\n",
206 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
207 "unrecognized modify operation" );
212 modtail = &mod->sml_next;
216 if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
218 LDAP_LOG( OPERATION, ERR, "do_modify: get_ctrls failed\n", 0, 0, 0 );
220 Debug( LDAP_DEBUG_ANY, "do_modify: get_ctrls failed\n", 0, 0, 0 );
226 rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn,
228 if( rs->sr_err != LDAP_SUCCESS ) {
230 LDAP_LOG( OPERATION, INFO, "do_modify: conn %d invalid dn (%s)\n",
231 op->o_connid, dn.bv_val, 0 );
233 Debug( LDAP_DEBUG_ANY,
234 "do_modify: invalid dn (%s)\n", dn.bv_val, 0, 0 );
236 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
240 if( op->o_req_ndn.bv_len == 0 ) {
242 LDAP_LOG( OPERATION, ERR,
243 "do_modify: attempt to modify root DSE.\n",0, 0, 0 );
245 Debug( LDAP_DEBUG_ANY, "do_modify: root dse!\n", 0, 0, 0 );
248 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
249 "modify upon the root DSE not supported" );
252 } else if ( bvmatch( &op->o_req_ndn, &global_schemandn ) ) {
254 LDAP_LOG( OPERATION, ERR,
255 "do_modify: attempt to modify subschema subentry.\n" , 0, 0, 0 );
257 Debug( LDAP_DEBUG_ANY, "do_modify: subschema subentry!\n", 0, 0, 0 );
260 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
261 "modification of subschema subentry not supported" );
267 LDAP_LOG( OPERATION, DETAIL1, "do_modify: modifications:\n", 0, 0, 0 );
269 Debug( LDAP_DEBUG_ARGS, "modifications:\n", 0, 0, 0 );
272 for ( tmp = modlist; tmp != NULL; tmp = tmp->sml_next ) {
274 LDAP_LOG( OPERATION, DETAIL1, "\t%s: %s\n",
275 tmp->sml_op == LDAP_MOD_ADD ? "add" :
276 (tmp->sml_op == LDAP_MOD_INCREMENT ? "increment" :
277 (tmp->sml_op == LDAP_MOD_DELETE ? "delete" :
278 "replace")), tmp->sml_type.bv_val, 0 );
280 if ( tmp->sml_values == NULL ) {
281 LDAP_LOG( OPERATION, DETAIL1, "\t\tno values", 0, 0, 0 );
282 } else if ( tmp->sml_values[0].bv_val == NULL ) {
283 LDAP_LOG( OPERATION, DETAIL1, "\t\tzero values", 0, 0, 0 );
284 } else if ( tmp->sml_values[1].bv_val == NULL ) {
285 LDAP_LOG( OPERATION, DETAIL1, "\t\tone value", 0, 0, 0 );
287 LDAP_LOG( OPERATION, DETAIL1, "\t\tmultiple values", 0, 0, 0 );
291 Debug( LDAP_DEBUG_ARGS, "\t%s: %s\n",
292 tmp->sml_op == LDAP_MOD_ADD ? "add" :
293 (tmp->sml_op == LDAP_MOD_INCREMENT ? "increment" :
294 (tmp->sml_op == LDAP_MOD_DELETE ? "delete" :
295 "replace")), tmp->sml_type.bv_val, 0 );
297 if ( tmp->sml_values == NULL ) {
298 Debug( LDAP_DEBUG_ARGS, "%s\n",
299 "\t\tno values", NULL, NULL );
300 } else if ( tmp->sml_values[0].bv_val == NULL ) {
301 Debug( LDAP_DEBUG_ARGS, "%s\n",
302 "\t\tzero values", NULL, NULL );
303 } else if ( tmp->sml_values[1].bv_val == NULL ) {
304 Debug( LDAP_DEBUG_ARGS, "%s, length %ld\n",
305 "\t\tone value", (long) tmp->sml_values[0].bv_len, NULL );
307 Debug( LDAP_DEBUG_ARGS, "%s\n",
308 "\t\tmultiple values", NULL, NULL );
313 if ( StatslogTest( LDAP_DEBUG_STATS ) ) {
314 char abuf[BUFSIZ/2], *ptr = abuf;
317 Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu MOD dn=\"%s\"\n",
318 op->o_connid, op->o_opid, dn.bv_val, 0, 0 );
320 for ( tmp = modlist; tmp != NULL; tmp = tmp->sml_next ) {
321 if (len + 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
322 Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu MOD attr=%s\n",
323 op->o_connid, op->o_opid, abuf, 0, 0 );
328 if( 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
329 Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu MOD attr=%s\n",
330 op->o_connid, op->o_opid, tmp->sml_type.bv_val, 0, 0 );
338 ptr = lutil_strcopy(ptr, tmp->sml_type.bv_val);
339 len += tmp->sml_type.bv_len;
342 Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu MOD attr=%s\n",
343 op->o_connid, op->o_opid, abuf, 0, 0 );
346 #endif /* LDAP_DEBUG */
348 manageDSAit = get_manageDSAit( op );
351 * We could be serving multiple database backends. Select the
352 * appropriate one, or send a referral to our "referral server"
353 * if we don't hold it.
355 op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 0 );
356 if ( op->o_bd == NULL ) {
357 rs->sr_ref = referral_rewrite( default_referral,
358 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
359 if (!rs->sr_ref) rs->sr_ref = default_referral;
361 if (rs->sr_ref != NULL ) {
362 rs->sr_err = LDAP_REFERRAL;
363 send_ldap_result( op, rs );
365 if (rs->sr_ref != default_referral) ber_bvarray_free( rs->sr_ref );
367 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
368 "no global superior knowledge" );
373 /* check restrictions */
374 if( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
375 send_ldap_result( op, rs );
379 /* check for referrals */
380 if( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
384 /* check for modify/increment support */
385 if( increment && !SLAP_INCREMENT( op->o_bd ) ) {
386 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
387 "modify/increment not supported in context" );
390 #if defined( LDAP_SLAPI )
393 slapi_int_pblock_set_operation( pb, op );
394 slapi_pblock_set( pb, SLAPI_MODIFY_TARGET, (void *)dn.bv_val );
395 slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)manageDSAit );
396 modv = slapi_int_modifications2ldapmods( &modlist );
397 slapi_pblock_set( pb, SLAPI_MODIFY_MODS, (void *)modv );
399 rs->sr_err = slapi_int_call_plugins( op->o_bd,
400 SLAPI_PLUGIN_PRE_MODIFY_FN, pb );
401 if ( rs->sr_err < 0 ) {
403 * A preoperation plugin failure will abort the
407 LDAP_LOG( OPERATION, INFO,
408 "do_modify: modify preoperation plugin failed\n",
411 Debug(LDAP_DEBUG_TRACE,
412 "do_modify: modify preoperation plugin failed.\n",
415 if ( ( slapi_pblock_get( op->o_pb, SLAPI_RESULT_CODE,
416 (void *)&rs->sr_err ) != 0 ) || rs->sr_err == LDAP_SUCCESS )
418 rs->sr_err = LDAP_OTHER;
420 slapi_int_free_ldapmods( modv );
426 * It's possible that the preoperation plugin changed the
427 * modification array, so we need to convert it back to
428 * a Modification list.
430 * Calling slapi_int_modifications2ldapmods() destroyed modlist so
431 * we don't need to free it.
433 slapi_pblock_get( pb, SLAPI_MODIFY_MODS, (void **)&modv );
434 modlist = slapi_int_ldapmods2modifications( modv );
438 * NB: it is valid for the plugin to return no modifications
439 * (for example, a plugin might store some attributes elsewhere
440 * and remove them from the modification list; if only those
441 * attribute types were included in the modification request,
442 * then slapi_int_ldapmods2modifications() above will return
445 * However, the post-operation plugin should still be
448 if ( modlist == NULL ) {
449 rs->sr_err = LDAP_SUCCESS;
450 send_ldap_result( op, rs );
452 #endif /* defined( LDAP_SLAPI ) */
455 * do the modify if 1 && (2 || 3)
456 * 1) there is a modify function implemented in this backend;
457 * 2) this backend is master for what it holds;
458 * 3) it's a replica and the dn supplied is the update_ndn.
460 if ( op->o_bd->be_modify ) {
461 /* do the update here */
462 int repl_user = be_isupdate( op );
464 /* Multimaster slapd does not have to check for replicator dn
465 * because it accepts each modify request
467 #ifndef SLAPD_MULTIMASTER
468 if ( !SLAP_SHADOW(op->o_bd) || repl_user )
471 int update = op->o_bd->be_update_ndn.bv_len;
472 char textbuf[SLAP_TEXT_BUFLEN];
473 size_t textlen = sizeof textbuf;
474 slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
476 rs->sr_err = slap_mods_check( modlist, update, &rs->sr_text,
477 textbuf, textlen, NULL );
479 if( rs->sr_err != LDAP_SUCCESS ) {
480 send_ldap_result( op, rs );
485 for( modtail = &modlist;
487 modtail = &(*modtail)->sml_next )
492 rs->sr_err = slap_mods_opattrs( op, modlist, modtail,
493 &rs->sr_text, textbuf, textlen );
494 if( rs->sr_err != LDAP_SUCCESS ) {
495 send_ldap_result( op, rs );
500 op->orm_modlist = modlist;
501 #ifdef SLAPD_MULTIMASTER
505 /* but we log only the ones not from a replicator user */
506 cb.sc_next = op->o_callback;
507 op->o_callback = &cb;
509 op->o_bd->be_modify( op, rs );
511 #ifndef SLAPD_MULTIMASTER
512 /* send a referral */
514 BerVarray defref = op->o_bd->be_update_refs
515 ? op->o_bd->be_update_refs : default_referral;
516 if ( defref != NULL ) {
517 rs->sr_ref = referral_rewrite( defref,
519 LDAP_SCOPE_DEFAULT );
520 if (!rs->sr_ref) rs->sr_ref = defref;
521 rs->sr_err = LDAP_REFERRAL;
522 send_ldap_result( op, rs );
523 if (rs->sr_ref != defref) {
524 ber_bvarray_free( rs->sr_ref );
527 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
528 "shadow context; no update referral" );
533 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
534 "operation not supported within namingContext" );
537 #if defined( LDAP_SLAPI )
538 } /* modlist != NULL */
540 if ( pb != NULL && slapi_int_call_plugins( op->o_bd,
541 SLAPI_PLUGIN_POST_MODIFY_FN, pb ) < 0 )
544 LDAP_LOG( OPERATION, INFO,
545 "do_modify: modify postoperation plugins failed\n", 0, 0, 0 );
547 Debug(LDAP_DEBUG_TRACE,
548 "do_modify: modify postoperation plugins failed.\n", 0, 0, 0);
551 #endif /* defined( LDAP_SLAPI ) */
554 slap_graduate_commit_csn( op );
556 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
557 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
558 if ( modlist != NULL ) slap_mods_free( modlist );
559 #if defined( LDAP_SLAPI )
560 if ( modv != NULL ) slapi_int_free_ldapmods( modv );
566 * Do basic attribute type checking and syntax validation.
578 for( ; ml != NULL; ml = ml->sml_next ) {
579 AttributeDescription *ad = NULL;
581 /* convert to attribute description */
582 rc = slap_bv2ad( &ml->sml_type, &ml->sml_desc, text );
584 if( rc != LDAP_SUCCESS ) {
585 snprintf( textbuf, textlen, "%s: %s",
586 ml->sml_type.bv_val, *text );
593 if( slap_syntax_is_binary( ad->ad_type->sat_syntax )
594 && !slap_ad_is_binary( ad ))
596 /* attribute requires binary transfer */
597 snprintf( textbuf, textlen,
598 "%s: requires ;binary transfer",
599 ml->sml_type.bv_val );
601 return LDAP_UNDEFINED_TYPE;
604 if( !slap_syntax_is_binary( ad->ad_type->sat_syntax )
605 && slap_ad_is_binary( ad ))
607 /* attribute requires binary transfer */
608 snprintf( textbuf, textlen,
609 "%s: disallows ;binary transfer",
610 ml->sml_type.bv_val );
612 return LDAP_UNDEFINED_TYPE;
615 if( slap_ad_is_tag_range( ad )) {
616 /* attribute requires binary transfer */
617 snprintf( textbuf, textlen,
618 "%s: inappropriate use of tag range option",
619 ml->sml_type.bv_val );
621 return LDAP_UNDEFINED_TYPE;
624 if (!update && is_at_no_user_mod( ad->ad_type )) {
625 /* user modification disallowed */
626 snprintf( textbuf, textlen,
627 "%s: no user modification allowed",
628 ml->sml_type.bv_val );
630 return LDAP_CONSTRAINT_VIOLATION;
633 if ( is_at_obsolete( ad->ad_type ) &&
634 (( ml->sml_op != LDAP_MOD_REPLACE &&
635 ml->sml_op != LDAP_MOD_DELETE ) ||
636 ml->sml_values != NULL ))
639 * attribute is obsolete,
640 * only allow replace/delete with no values
642 snprintf( textbuf, textlen,
643 "%s: attribute is obsolete",
644 ml->sml_type.bv_val );
646 return LDAP_CONSTRAINT_VIOLATION;
649 if ( ml->sml_op == LDAP_MOD_INCREMENT &&
650 #ifdef SLAPD_REAL_SYNTAX
651 !is_at_syntax( ad->ad_type, SLAPD_REAL_SYNTAX ) &&
653 !is_at_syntax( ad->ad_type, SLAPD_INTEGER_SYNTAX ) )
656 * attribute values must be INTEGER or REAL
658 snprintf( textbuf, textlen,
659 "%s: attribute syntax inappropriate for increment",
660 ml->sml_type.bv_val );
662 return LDAP_CONSTRAINT_VIOLATION;
668 if( ml->sml_values != NULL ) {
670 slap_syntax_validate_func *validate =
671 ad->ad_type->sat_syntax->ssyn_validate;
672 slap_syntax_transform_func *pretty =
673 ad->ad_type->sat_syntax->ssyn_pretty;
675 if( !pretty && !validate ) {
676 *text = "no validator for syntax";
677 snprintf( textbuf, textlen,
678 "%s: no validator for syntax %s",
680 ad->ad_type->sat_syntax->ssyn_oid );
682 return LDAP_INVALID_SYNTAX;
686 * check that each value is valid per syntax
687 * and pretty if appropriate
689 for( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) {
692 rc = pretty( ad->ad_type->sat_syntax,
693 &ml->sml_values[nvals], &pval, ctx );
695 rc = validate( ad->ad_type->sat_syntax,
696 &ml->sml_values[nvals] );
700 snprintf( textbuf, textlen,
701 "%s: value #%ld invalid per syntax",
702 ml->sml_type.bv_val, (long) nvals );
704 return LDAP_INVALID_SYNTAX;
708 ber_memfree_x( ml->sml_values[nvals].bv_val, ctx );
709 ml->sml_values[nvals] = pval;
714 * a rough single value check... an additional check is needed
715 * to catch add of single value to existing single valued attribute
717 if ((ml->sml_op == LDAP_MOD_ADD || ml->sml_op == LDAP_MOD_REPLACE)
718 && nvals > 1 && is_at_single_value( ad->ad_type ))
720 snprintf( textbuf, textlen,
721 "%s: multiple values provided",
722 ml->sml_type.bv_val );
724 return LDAP_CONSTRAINT_VIOLATION;
727 /* if the type has a normalizer, generate the
728 * normalized values. otherwise leave them NULL.
730 * this is different from the rule for attributes
731 * in an entry - in an attribute list, the normalized
732 * value is set equal to the non-normalized value
733 * when there is no normalizer.
735 if( nvals && ad->ad_type->sat_equality &&
736 ad->ad_type->sat_equality->smr_normalize )
738 ml->sml_nvalues = ber_memalloc_x(
739 (nvals+1)*sizeof(struct berval), ctx );
741 for( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) {
742 rc = ad->ad_type->sat_equality->smr_normalize(
743 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
744 ad->ad_type->sat_syntax,
745 ad->ad_type->sat_equality,
746 &ml->sml_values[nvals], &ml->sml_nvalues[nvals], ctx );
749 LDAP_LOG( OPERATION, DETAIL1,
750 "str2entry: NULL (ssyn_normalize %d)\n",
753 Debug( LDAP_DEBUG_ANY,
754 "<= str2entry NULL (ssyn_normalize %d)\n",
757 snprintf( textbuf, textlen,
758 "%s: value #%ld normalization failed",
759 ml->sml_type.bv_val, (long) nvals );
765 ml->sml_nvalues[nvals].bv_val = NULL;
766 ml->sml_nvalues[nvals].bv_len = 0;
770 /* check for duplicates */
772 MatchingRule *mr = ad->ad_type->sat_equality;
774 /* check if the values we're adding already exist */
775 if( mr == NULL || !mr->smr_match ) {
776 for ( i = 1; ml->sml_values[i].bv_val != NULL; i++ ) {
777 /* test asserted values against themselves */
778 for( j = 0; j < i; j++ ) {
779 if ( bvmatch( &ml->sml_values[i],
780 &ml->sml_values[j] ) )
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;
793 int rc = LDAP_SUCCESS;
796 for ( i = 1; ml->sml_values[i].bv_val != NULL; i++ ) {
797 /* test asserted values against themselves */
798 for( j = 0; j < i; j++ ) {
799 rc = value_match( &match, ml->sml_desc, mr,
801 | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX
802 | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH
803 | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH,
805 ? &ml->sml_nvalues[i]
806 : &ml->sml_values[i],
808 ? &ml->sml_nvalues[j]
809 : &ml->sml_values[j],
811 if ( rc == LDAP_SUCCESS && match == 0 ) {
812 /* value exists already */
813 snprintf( textbuf, textlen,
814 "%s: value #%d provided more than once",
815 ml->sml_desc->ad_cname.bv_val, j );
817 return LDAP_TYPE_OR_VALUE_EXISTS;
822 if ( rc != LDAP_SUCCESS ) return rc;
832 int slap_mods_opattrs(
835 Modifications **modtail,
837 char *textbuf, size_t textlen )
839 struct berval name, timestamp, csn;
841 char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
842 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
845 int mop = op->o_tag == LDAP_REQ_ADD
846 ? LDAP_MOD_ADD : LDAP_MOD_REPLACE;
848 assert( modtail != NULL );
849 assert( *modtail == NULL );
851 if ( SLAP_LASTMOD( op->o_bd )) {
856 time_t now = slap_get_time();
859 ltm = gmtime_r( &now, <m_buf );
861 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
862 ltm = gmtime( &now );
863 #endif /* HAVE_GMTIME_R */
864 lutil_gentime( timebuf, sizeof(timebuf), ltm );
866 slap_get_csn( op, csnbuf, sizeof(csnbuf), &csn, 1 );
868 #ifndef HAVE_GMTIME_R
869 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
872 timestamp.bv_val = timebuf;
873 timestamp.bv_len = strlen(timebuf);
875 if( op->o_dn.bv_len == 0 ) {
876 name.bv_val = SLAPD_ANONYMOUS;
877 name.bv_len = sizeof(SLAPD_ANONYMOUS)-1;
885 if( op->o_tag == LDAP_REQ_ADD ) {
886 struct berval tmpval;
888 if( global_schemacheck ) {
889 int rc = mods_structural_class( mods, &tmpval,
890 text, textbuf, textlen );
891 if( rc != LDAP_SUCCESS ) return rc;
893 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
895 mod->sml_type.bv_val = NULL;
896 mod->sml_desc = slap_schema.si_ad_structuralObjectClass;
898 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
899 ber_dupbv( &mod->sml_values[0], &tmpval );
900 mod->sml_values[1].bv_len = 0;
901 mod->sml_values[1].bv_val = NULL;
902 assert( mod->sml_values[0].bv_val );
904 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
905 ber_dupbv( &mod->sml_nvalues[0], &tmpval );
906 mod->sml_nvalues[1].bv_len = 0;
907 mod->sml_nvalues[1].bv_val = NULL;
908 assert( mod->sml_nvalues[0].bv_val );
910 modtail = &mod->sml_next;
913 if ( SLAP_LASTMOD( op->o_bd )) {
914 char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
916 tmpval.bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ) );
917 tmpval.bv_val = uuidbuf;
919 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
921 mod->sml_type.bv_val = NULL;
922 mod->sml_desc = slap_schema.si_ad_entryUUID;
924 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
925 ber_dupbv( &mod->sml_values[0], &tmpval );
926 mod->sml_values[1].bv_len = 0;
927 mod->sml_values[1].bv_val = NULL;
928 assert( mod->sml_values[0].bv_val );
930 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
931 (*mod->sml_desc->ad_type->sat_equality->smr_normalize)(
932 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
933 mod->sml_desc->ad_type->sat_syntax,
934 mod->sml_desc->ad_type->sat_equality,
935 mod->sml_values, mod->sml_nvalues, NULL );
936 mod->sml_nvalues[1].bv_len = 0;
937 mod->sml_nvalues[1].bv_val = NULL;
939 modtail = &mod->sml_next;
941 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
943 mod->sml_type.bv_val = NULL;
944 mod->sml_desc = slap_schema.si_ad_creatorsName;
946 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
947 ber_dupbv( &mod->sml_values[0], &name );
948 mod->sml_values[1].bv_len = 0;
949 mod->sml_values[1].bv_val = NULL;
950 assert( mod->sml_values[0].bv_val );
952 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
953 ber_dupbv( &mod->sml_nvalues[0], &nname );
954 mod->sml_nvalues[1].bv_len = 0;
955 mod->sml_nvalues[1].bv_val = NULL;
956 assert( mod->sml_nvalues[0].bv_val );
958 modtail = &mod->sml_next;
960 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
962 mod->sml_type.bv_val = NULL;
963 mod->sml_desc = slap_schema.si_ad_createTimestamp;
965 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
966 ber_dupbv( &mod->sml_values[0], ×tamp );
967 mod->sml_values[1].bv_len = 0;
968 mod->sml_values[1].bv_val = NULL;
969 assert( mod->sml_values[0].bv_val );
970 mod->sml_nvalues = NULL;
972 modtail = &mod->sml_next;
976 if ( SLAP_LASTMOD( op->o_bd )) {
977 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
979 mod->sml_type.bv_val = NULL;
980 mod->sml_desc = slap_schema.si_ad_entryCSN;
981 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
982 ber_dupbv( &mod->sml_values[0], &csn );
983 mod->sml_values[1].bv_len = 0;
984 mod->sml_values[1].bv_val = NULL;
985 assert( mod->sml_values[0].bv_val );
986 mod->sml_nvalues = NULL;
988 modtail = &mod->sml_next;
990 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
992 mod->sml_type.bv_val = NULL;
993 mod->sml_desc = slap_schema.si_ad_modifiersName;
994 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
995 ber_dupbv( &mod->sml_values[0], &name );
996 mod->sml_values[1].bv_len = 0;
997 mod->sml_values[1].bv_val = NULL;
998 assert( mod->sml_values[0].bv_val );
1000 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
1001 ber_dupbv( &mod->sml_nvalues[0], &nname );
1002 mod->sml_nvalues[1].bv_len = 0;
1003 mod->sml_nvalues[1].bv_val = NULL;
1004 assert( mod->sml_nvalues[0].bv_val );
1006 modtail = &mod->sml_next;
1008 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
1010 mod->sml_type.bv_val = NULL;
1011 mod->sml_desc = slap_schema.si_ad_modifyTimestamp;
1012 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
1013 ber_dupbv( &mod->sml_values[0], ×tamp );
1014 mod->sml_values[1].bv_len = 0;
1015 mod->sml_values[1].bv_val = NULL;
1016 assert( mod->sml_values[0].bv_val );
1017 mod->sml_nvalues = NULL;
1019 modtail = &mod->sml_next;
1023 return LDAP_SUCCESS;