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;
56 LDAP_LOG( OPERATION, ENTRY, "do_modify: enter\n", 0, 0, 0 );
58 Debug( LDAP_DEBUG_TRACE, "do_modify\n", 0, 0, 0 );
62 * Parse the modify request. It looks like this:
64 * ModifyRequest := [APPLICATION 6] SEQUENCE {
65 * name DistinguishedName,
66 * mods SEQUENCE OF SEQUENCE {
67 * operation ENUMERATED {
72 * modification SEQUENCE {
74 * values SET OF AttributeValue
80 if ( ber_scanf( op->o_ber, "{m" /*}*/, &dn ) == LBER_ERROR ) {
82 LDAP_LOG( OPERATION, ERR, "do_modify: ber_scanf failed\n", 0, 0, 0 );
84 Debug( LDAP_DEBUG_ANY, "do_modify: ber_scanf failed\n", 0, 0, 0 );
87 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
88 return SLAPD_DISCONNECT;
92 LDAP_LOG( OPERATION, ARGS, "do_modify: dn (%s)\n", dn.bv_val, 0, 0 );
94 Debug( LDAP_DEBUG_ARGS, "do_modify: dn (%s)\n", dn.bv_val, 0, 0 );
97 /* collect modifications & save for later */
98 for ( tag = ber_first_element( op->o_ber, &len, &last );
100 tag = ber_next_element( op->o_ber, &len, last ) )
103 Modifications tmp, *mod;
105 tmp.sml_nvalues = NULL;
107 if ( ber_scanf( op->o_ber, "{i{m[W]}}", &mop,
108 &tmp.sml_type, &tmp.sml_values ) == LBER_ERROR )
110 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR,
111 "decoding modlist error" );
112 rs->sr_err = SLAPD_DISCONNECT;
116 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
118 mod->sml_type = tmp.sml_type;
119 mod->sml_values = tmp.sml_values;
120 mod->sml_nvalues = NULL;
121 mod->sml_desc = NULL;
122 mod->sml_next = NULL;
127 if ( mod->sml_values == NULL ) {
129 LDAP_LOG( OPERATION, ERR,
130 "do_modify: modify/add operation (%ld) requires values\n",
133 Debug( LDAP_DEBUG_ANY,
134 "do_modify: modify/add operation (%ld) requires values\n",
138 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
139 "modify/add operation requires values" );
145 case LDAP_MOD_DELETE:
146 case LDAP_MOD_REPLACE:
149 case LDAP_MOD_INCREMENT:
150 if( op->o_protocol >= LDAP_VERSION3 ) {
152 if ( mod->sml_values == NULL ) {
154 LDAP_LOG( OPERATION, ERR, "do_modify: "
155 "modify/increment operation (%ld) requires value\n",
158 Debug( LDAP_DEBUG_ANY, "do_modify: "
159 "modify/increment operation (%ld) requires value\n",
163 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
164 "modify/increment operation requires value" );
168 if( mod->sml_values[1].bv_val ) {
170 LDAP_LOG( OPERATION, ERR, "do_modify: modify/increment "
171 "operation (%ld) requires single value\n",
174 Debug( LDAP_DEBUG_ANY, "do_modify: modify/increment "
175 "operation (%ld) requires single value\n",
179 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
180 "modify/increment operation requires single value" );
190 LDAP_LOG( OPERATION, ERR,
191 "do_modify: unrecognized modify operation (%ld)\n",
194 Debug( LDAP_DEBUG_ANY,
195 "do_modify: unrecognized modify operation (%ld)\n",
199 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
200 "unrecognized modify operation" );
205 modtail = &mod->sml_next;
209 if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
211 LDAP_LOG( OPERATION, ERR, "do_modify: get_ctrls failed\n", 0, 0, 0 );
213 Debug( LDAP_DEBUG_ANY, "do_modify: get_ctrls failed\n", 0, 0, 0 );
219 rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn,
221 if( rs->sr_err != LDAP_SUCCESS ) {
223 LDAP_LOG( OPERATION, INFO, "do_modify: conn %d invalid dn (%s)\n",
224 op->o_connid, dn.bv_val, 0 );
226 Debug( LDAP_DEBUG_ANY,
227 "do_modify: invalid dn (%s)\n", dn.bv_val, 0, 0 );
229 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
233 /* FIXME: temporary */
234 op->orm_modlist = modlist;
235 op->orm_increment = increment;
237 op->o_bd = frontendDB;
238 rs->sr_err = frontendDB->be_modify( op, rs );
241 slap_graduate_commit_csn( op );
243 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
244 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
245 if ( modlist != NULL ) slap_mods_free( modlist );
251 fe_op_modify( Operation *op, SlapReply *rs )
257 Modifications *modlist = op->orm_modlist;
258 Modifications **modtail = &modlist;
260 LDAPMod **modv = NULL;
262 int increment = op->orm_increment;
264 if( op->o_req_ndn.bv_len == 0 ) {
266 LDAP_LOG( OPERATION, ERR,
267 "do_modify: attempt to modify root DSE.\n",0, 0, 0 );
269 Debug( LDAP_DEBUG_ANY, "do_modify: root dse!\n", 0, 0, 0 );
272 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
273 "modify upon the root DSE not supported" );
276 } else if ( bvmatch( &op->o_req_ndn, &frontendDB->be_schemandn ) ) {
278 LDAP_LOG( OPERATION, ERR,
279 "do_modify: attempt to modify subschema subentry.\n" , 0, 0, 0 );
281 Debug( LDAP_DEBUG_ANY, "do_modify: subschema subentry!\n", 0, 0, 0 );
284 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
285 "modification of subschema subentry not supported" );
291 LDAP_LOG( OPERATION, DETAIL1, "do_modify: modifications:\n", 0, 0, 0 );
293 Debug( LDAP_DEBUG_ARGS, "modifications:\n", 0, 0, 0 );
296 for ( tmp = modlist; tmp != NULL; tmp = tmp->sml_next ) {
298 LDAP_LOG( OPERATION, DETAIL1, "\t%s: %s\n",
299 tmp->sml_op == LDAP_MOD_ADD ? "add" :
300 (tmp->sml_op == LDAP_MOD_INCREMENT ? "increment" :
301 (tmp->sml_op == LDAP_MOD_DELETE ? "delete" :
302 "replace")), tmp->sml_type.bv_val, 0 );
304 if ( tmp->sml_values == NULL ) {
305 LDAP_LOG( OPERATION, DETAIL1, "\t\tno values", 0, 0, 0 );
306 } else if ( tmp->sml_values[0].bv_val == NULL ) {
307 LDAP_LOG( OPERATION, DETAIL1, "\t\tzero values", 0, 0, 0 );
308 } else if ( tmp->sml_values[1].bv_val == NULL ) {
309 LDAP_LOG( OPERATION, DETAIL1, "\t\tone value", 0, 0, 0 );
311 LDAP_LOG( OPERATION, DETAIL1, "\t\tmultiple values", 0, 0, 0 );
315 Debug( LDAP_DEBUG_ARGS, "\t%s: %s\n",
316 tmp->sml_op == LDAP_MOD_ADD ? "add" :
317 (tmp->sml_op == LDAP_MOD_INCREMENT ? "increment" :
318 (tmp->sml_op == LDAP_MOD_DELETE ? "delete" :
319 "replace")), tmp->sml_type.bv_val, 0 );
321 if ( tmp->sml_values == NULL ) {
322 Debug( LDAP_DEBUG_ARGS, "%s\n",
323 "\t\tno values", NULL, NULL );
324 } else if ( tmp->sml_values[0].bv_val == NULL ) {
325 Debug( LDAP_DEBUG_ARGS, "%s\n",
326 "\t\tzero values", NULL, NULL );
327 } else if ( tmp->sml_values[1].bv_val == NULL ) {
328 Debug( LDAP_DEBUG_ARGS, "%s, length %ld\n",
329 "\t\tone value", (long) tmp->sml_values[0].bv_len, NULL );
331 Debug( LDAP_DEBUG_ARGS, "%s\n",
332 "\t\tmultiple values", NULL, NULL );
337 if ( StatslogTest( LDAP_DEBUG_STATS ) ) {
338 char abuf[BUFSIZ/2], *ptr = abuf;
341 Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu MOD dn=\"%s\"\n",
342 op->o_connid, op->o_opid, op->o_req_dn.bv_val, 0, 0 );
344 for ( tmp = modlist; tmp != NULL; tmp = tmp->sml_next ) {
345 if (len + 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
346 Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu MOD attr=%s\n",
347 op->o_connid, op->o_opid, abuf, 0, 0 );
352 if( 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
353 Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu MOD attr=%s\n",
354 op->o_connid, op->o_opid, tmp->sml_type.bv_val, 0, 0 );
362 ptr = lutil_strcopy(ptr, tmp->sml_type.bv_val);
363 len += tmp->sml_type.bv_len;
366 Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu MOD attr=%s\n",
367 op->o_connid, op->o_opid, abuf, 0, 0 );
370 #endif /* LDAP_DEBUG */
372 manageDSAit = get_manageDSAit( op );
375 * We could be serving multiple database backends. Select the
376 * appropriate one, or send a referral to our "referral server"
377 * if we don't hold it.
379 op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 0 );
380 if ( op->o_bd == NULL ) {
381 rs->sr_ref = referral_rewrite( default_referral,
382 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
383 if (!rs->sr_ref) rs->sr_ref = default_referral;
385 if (rs->sr_ref != NULL ) {
386 rs->sr_err = LDAP_REFERRAL;
387 send_ldap_result( op, rs );
389 if (rs->sr_ref != default_referral) ber_bvarray_free( rs->sr_ref );
391 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
392 "no global superior knowledge" );
397 /* check restrictions */
398 if( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
399 send_ldap_result( op, rs );
403 /* check for referrals */
404 if( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
408 /* check for modify/increment support */
409 if( increment && !SLAP_INCREMENT( op->o_bd ) ) {
410 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
411 "modify/increment not supported in context" );
414 #if defined( LDAP_SLAPI )
417 slapi_int_pblock_set_operation( pb, op );
418 slapi_pblock_set( pb, SLAPI_MODIFY_TARGET, (void *)op->o_req_dn.bv_val );
419 slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)manageDSAit );
420 modv = slapi_int_modifications2ldapmods( &modlist );
421 slapi_pblock_set( pb, SLAPI_MODIFY_MODS, (void *)modv );
423 rs->sr_err = slapi_int_call_plugins( op->o_bd,
424 SLAPI_PLUGIN_PRE_MODIFY_FN, pb );
425 if ( rs->sr_err < 0 ) {
427 * A preoperation plugin failure will abort the
431 LDAP_LOG( OPERATION, INFO,
432 "do_modify: modify preoperation plugin failed\n",
435 Debug(LDAP_DEBUG_TRACE,
436 "do_modify: modify preoperation plugin failed.\n",
439 if ( ( slapi_pblock_get( op->o_pb, SLAPI_RESULT_CODE,
440 (void *)&rs->sr_err ) != 0 ) || rs->sr_err == LDAP_SUCCESS )
442 rs->sr_err = LDAP_OTHER;
444 slapi_int_free_ldapmods( modv );
450 * It's possible that the preoperation plugin changed the
451 * modification array, so we need to convert it back to
452 * a Modification list.
454 * Calling slapi_int_modifications2ldapmods() destroyed modlist so
455 * we don't need to free it.
457 slapi_pblock_get( pb, SLAPI_MODIFY_MODS, (void **)&modv );
458 modlist = slapi_int_ldapmods2modifications( modv );
462 * NB: it is valid for the plugin to return no modifications
463 * (for example, a plugin might store some attributes elsewhere
464 * and remove them from the modification list; if only those
465 * attribute types were included in the modification request,
466 * then slapi_int_ldapmods2modifications() above will return
469 * However, the post-operation plugin should still be
472 if ( modlist == NULL ) {
473 rs->sr_err = LDAP_SUCCESS;
474 send_ldap_result( op, rs );
476 #endif /* defined( LDAP_SLAPI ) */
479 * do the modify if 1 && (2 || 3)
480 * 1) there is a modify function implemented in this backend;
481 * 2) this backend is master for what it holds;
482 * 3) it's a replica and the dn supplied is the update_ndn.
484 if ( op->o_bd->be_modify ) {
485 /* do the update here */
486 int repl_user = be_isupdate( op );
488 /* Multimaster slapd does not have to check for replicator dn
489 * because it accepts each modify request
491 #ifndef SLAPD_MULTIMASTER
492 if ( !SLAP_SHADOW(op->o_bd) || repl_user )
495 int update = op->o_bd->be_update_ndn.bv_len;
496 char textbuf[SLAP_TEXT_BUFLEN];
497 size_t textlen = sizeof textbuf;
498 slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
500 rs->sr_err = slap_mods_check( modlist, update, &rs->sr_text,
501 textbuf, textlen, NULL );
503 if( rs->sr_err != LDAP_SUCCESS ) {
504 send_ldap_result( op, rs );
509 for( modtail = &modlist;
511 modtail = &(*modtail)->sml_next )
516 rs->sr_err = slap_mods_opattrs( op, modlist, modtail,
517 &rs->sr_text, textbuf, textlen );
518 if( rs->sr_err != LDAP_SUCCESS ) {
519 send_ldap_result( op, rs );
524 op->orm_modlist = modlist;
525 #ifdef SLAPD_MULTIMASTER
529 /* but we log only the ones not from a replicator user */
530 cb.sc_next = op->o_callback;
531 op->o_callback = &cb;
533 op->o_bd->be_modify( op, rs );
535 #ifndef SLAPD_MULTIMASTER
536 /* send a referral */
538 BerVarray defref = op->o_bd->be_update_refs
539 ? op->o_bd->be_update_refs : default_referral;
540 if ( defref != NULL ) {
541 rs->sr_ref = referral_rewrite( defref,
543 LDAP_SCOPE_DEFAULT );
544 if (!rs->sr_ref) rs->sr_ref = defref;
545 rs->sr_err = LDAP_REFERRAL;
546 send_ldap_result( op, rs );
547 if (rs->sr_ref != defref) {
548 ber_bvarray_free( rs->sr_ref );
551 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
552 "shadow context; no update referral" );
557 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
558 "operation not supported within namingContext" );
561 #if defined( LDAP_SLAPI )
562 } /* modlist != NULL */
564 if ( pb != NULL && slapi_int_call_plugins( op->o_bd,
565 SLAPI_PLUGIN_POST_MODIFY_FN, pb ) < 0 )
568 LDAP_LOG( OPERATION, INFO,
569 "do_modify: modify postoperation plugins failed\n", 0, 0, 0 );
571 Debug(LDAP_DEBUG_TRACE,
572 "do_modify: modify postoperation plugins failed.\n", 0, 0, 0);
575 #endif /* defined( LDAP_SLAPI ) */
578 #if defined( LDAP_SLAPI )
579 if ( modv != NULL ) slapi_int_free_ldapmods( modv );
586 * Do basic attribute type checking and syntax validation.
598 for( ; ml != NULL; ml = ml->sml_next ) {
599 AttributeDescription *ad = NULL;
601 /* convert to attribute description */
602 rc = slap_bv2ad( &ml->sml_type, &ml->sml_desc, text );
604 if( rc != LDAP_SUCCESS ) {
605 snprintf( textbuf, textlen, "%s: %s",
606 ml->sml_type.bv_val, *text );
613 if( slap_syntax_is_binary( ad->ad_type->sat_syntax )
614 && !slap_ad_is_binary( ad ))
616 /* attribute requires binary transfer */
617 snprintf( textbuf, textlen,
618 "%s: requires ;binary transfer",
619 ml->sml_type.bv_val );
621 return LDAP_UNDEFINED_TYPE;
624 if( !slap_syntax_is_binary( ad->ad_type->sat_syntax )
625 && slap_ad_is_binary( ad ))
627 /* attribute does not require binary transfer */
628 snprintf( textbuf, textlen,
629 "%s: disallows ;binary transfer",
630 ml->sml_type.bv_val );
632 return LDAP_UNDEFINED_TYPE;
635 if( slap_ad_is_tag_range( ad )) {
636 /* attribute requires binary transfer */
637 snprintf( textbuf, textlen,
638 "%s: inappropriate use of tag range option",
639 ml->sml_type.bv_val );
641 return LDAP_UNDEFINED_TYPE;
644 if (!update && is_at_no_user_mod( ad->ad_type )) {
645 /* user modification disallowed */
646 snprintf( textbuf, textlen,
647 "%s: no user modification allowed",
648 ml->sml_type.bv_val );
650 return LDAP_CONSTRAINT_VIOLATION;
653 if ( is_at_obsolete( ad->ad_type ) &&
654 (( ml->sml_op != LDAP_MOD_REPLACE &&
655 ml->sml_op != LDAP_MOD_DELETE ) ||
656 ml->sml_values != NULL ))
659 * attribute is obsolete,
660 * only allow replace/delete with no values
662 snprintf( textbuf, textlen,
663 "%s: attribute is obsolete",
664 ml->sml_type.bv_val );
666 return LDAP_CONSTRAINT_VIOLATION;
669 if ( ml->sml_op == LDAP_MOD_INCREMENT &&
670 #ifdef SLAPD_REAL_SYNTAX
671 !is_at_syntax( ad->ad_type, SLAPD_REAL_SYNTAX ) &&
673 !is_at_syntax( ad->ad_type, SLAPD_INTEGER_SYNTAX ) )
676 * attribute values must be INTEGER or REAL
678 snprintf( textbuf, textlen,
679 "%s: attribute syntax inappropriate for increment",
680 ml->sml_type.bv_val );
682 return LDAP_CONSTRAINT_VIOLATION;
688 if( ml->sml_values != NULL ) {
690 slap_syntax_validate_func *validate =
691 ad->ad_type->sat_syntax->ssyn_validate;
692 slap_syntax_transform_func *pretty =
693 ad->ad_type->sat_syntax->ssyn_pretty;
695 if( !pretty && !validate ) {
696 *text = "no validator for syntax";
697 snprintf( textbuf, textlen,
698 "%s: no validator for syntax %s",
700 ad->ad_type->sat_syntax->ssyn_oid );
702 return LDAP_INVALID_SYNTAX;
706 * check that each value is valid per syntax
707 * and pretty if appropriate
709 for( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) {
712 rc = pretty( ad->ad_type->sat_syntax,
713 &ml->sml_values[nvals], &pval, ctx );
715 rc = validate( ad->ad_type->sat_syntax,
716 &ml->sml_values[nvals] );
720 snprintf( textbuf, textlen,
721 "%s: value #%ld invalid per syntax",
722 ml->sml_type.bv_val, (long) nvals );
724 return LDAP_INVALID_SYNTAX;
728 ber_memfree_x( ml->sml_values[nvals].bv_val, ctx );
729 ml->sml_values[nvals] = pval;
734 * a rough single value check... an additional check is needed
735 * to catch add of single value to existing single valued attribute
737 if ((ml->sml_op == LDAP_MOD_ADD || ml->sml_op == LDAP_MOD_REPLACE)
738 && nvals > 1 && is_at_single_value( ad->ad_type ))
740 snprintf( textbuf, textlen,
741 "%s: multiple values provided",
742 ml->sml_type.bv_val );
744 return LDAP_CONSTRAINT_VIOLATION;
747 /* if the type has a normalizer, generate the
748 * normalized values. otherwise leave them NULL.
750 * this is different from the rule for attributes
751 * in an entry - in an attribute list, the normalized
752 * value is set equal to the non-normalized value
753 * when there is no normalizer.
755 if( nvals && ad->ad_type->sat_equality &&
756 ad->ad_type->sat_equality->smr_normalize )
758 ml->sml_nvalues = ber_memalloc_x(
759 (nvals+1)*sizeof(struct berval), ctx );
761 for( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) {
762 rc = ad->ad_type->sat_equality->smr_normalize(
763 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
764 ad->ad_type->sat_syntax,
765 ad->ad_type->sat_equality,
766 &ml->sml_values[nvals], &ml->sml_nvalues[nvals], ctx );
769 LDAP_LOG( OPERATION, DETAIL1,
770 "str2entry: NULL (ssyn_normalize %d)\n",
773 Debug( LDAP_DEBUG_ANY,
774 "<= str2entry NULL (ssyn_normalize %d)\n",
777 snprintf( textbuf, textlen,
778 "%s: value #%ld normalization failed",
779 ml->sml_type.bv_val, (long) nvals );
785 ml->sml_nvalues[nvals].bv_val = NULL;
786 ml->sml_nvalues[nvals].bv_len = 0;
790 /* check for duplicates */
792 MatchingRule *mr = ad->ad_type->sat_equality;
794 /* check if the values we're adding already exist */
795 if( mr == NULL || !mr->smr_match ) {
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 if ( bvmatch( &ml->sml_values[i],
800 &ml->sml_values[j] ) )
802 /* value exists already */
803 snprintf( textbuf, textlen,
804 "%s: value #%d provided more than once",
805 ml->sml_desc->ad_cname.bv_val, j );
807 return LDAP_TYPE_OR_VALUE_EXISTS;
816 for ( i = 1; ml->sml_values[i].bv_val != NULL; i++ ) {
817 /* test asserted values against themselves */
818 for( j = 0; j < i; j++ ) {
819 rc = value_match( &match, ml->sml_desc, mr,
821 | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX
822 | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH
823 | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH,
825 ? &ml->sml_nvalues[i]
826 : &ml->sml_values[i],
828 ? &ml->sml_nvalues[j]
829 : &ml->sml_values[j],
831 if ( rc == LDAP_SUCCESS && match == 0 ) {
832 /* value exists already */
833 snprintf( textbuf, textlen,
834 "%s: value #%d provided more than once",
835 ml->sml_desc->ad_cname.bv_val, j );
837 return LDAP_TYPE_OR_VALUE_EXISTS;
839 } else if ( rc != LDAP_SUCCESS ) {
853 int slap_mods_opattrs(
856 Modifications **modtail,
858 char *textbuf, size_t textlen )
860 struct berval name, timestamp, csn;
862 char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
863 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
866 int mop = op->o_tag == LDAP_REQ_ADD
867 ? LDAP_MOD_ADD : LDAP_MOD_REPLACE;
869 assert( modtail != NULL );
870 assert( *modtail == NULL );
872 if ( SLAP_LASTMOD( op->o_bd )) {
877 time_t now = slap_get_time();
880 ltm = gmtime_r( &now, <m_buf );
882 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
883 ltm = gmtime( &now );
884 #endif /* HAVE_GMTIME_R */
885 lutil_gentime( timebuf, sizeof(timebuf), ltm );
887 slap_get_csn( op, csnbuf, sizeof(csnbuf), &csn, 1 );
889 #ifndef HAVE_GMTIME_R
890 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
893 timestamp.bv_val = timebuf;
894 timestamp.bv_len = strlen(timebuf);
896 if( op->o_dn.bv_len == 0 ) {
897 BER_BVSTR( &name, SLAPD_ANONYMOUS );
905 if( op->o_tag == LDAP_REQ_ADD ) {
906 struct berval tmpval;
908 if( global_schemacheck ) {
909 int rc = mods_structural_class( mods, &tmpval,
910 text, textbuf, textlen );
911 if( rc != LDAP_SUCCESS ) return rc;
913 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
915 mod->sml_type.bv_val = NULL;
916 mod->sml_desc = slap_schema.si_ad_structuralObjectClass;
918 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
919 ber_dupbv( &mod->sml_values[0], &tmpval );
920 mod->sml_values[1].bv_len = 0;
921 mod->sml_values[1].bv_val = NULL;
922 assert( mod->sml_values[0].bv_val );
924 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
925 ber_dupbv( &mod->sml_nvalues[0], &tmpval );
926 mod->sml_nvalues[1].bv_len = 0;
927 mod->sml_nvalues[1].bv_val = NULL;
928 assert( mod->sml_nvalues[0].bv_val );
930 modtail = &mod->sml_next;
933 if ( SLAP_LASTMOD( op->o_bd )) {
934 char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
936 tmpval.bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ) );
937 tmpval.bv_val = uuidbuf;
939 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
941 mod->sml_type.bv_val = NULL;
942 mod->sml_desc = slap_schema.si_ad_entryUUID;
944 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
945 ber_dupbv( &mod->sml_values[0], &tmpval );
946 mod->sml_values[1].bv_len = 0;
947 mod->sml_values[1].bv_val = NULL;
948 assert( mod->sml_values[0].bv_val );
950 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
951 (*mod->sml_desc->ad_type->sat_equality->smr_normalize)(
952 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
953 mod->sml_desc->ad_type->sat_syntax,
954 mod->sml_desc->ad_type->sat_equality,
955 mod->sml_values, mod->sml_nvalues, NULL );
956 mod->sml_nvalues[1].bv_len = 0;
957 mod->sml_nvalues[1].bv_val = 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_creatorsName;
966 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
967 ber_dupbv( &mod->sml_values[0], &name );
968 mod->sml_values[1].bv_len = 0;
969 mod->sml_values[1].bv_val = NULL;
970 assert( mod->sml_values[0].bv_val );
972 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
973 ber_dupbv( &mod->sml_nvalues[0], &nname );
974 mod->sml_nvalues[1].bv_len = 0;
975 mod->sml_nvalues[1].bv_val = NULL;
976 assert( mod->sml_nvalues[0].bv_val );
978 modtail = &mod->sml_next;
980 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
982 mod->sml_type.bv_val = NULL;
983 mod->sml_desc = slap_schema.si_ad_createTimestamp;
985 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
986 ber_dupbv( &mod->sml_values[0], ×tamp );
987 mod->sml_values[1].bv_len = 0;
988 mod->sml_values[1].bv_val = NULL;
989 assert( mod->sml_values[0].bv_val );
990 mod->sml_nvalues = NULL;
992 modtail = &mod->sml_next;
996 if ( SLAP_LASTMOD( op->o_bd )) {
997 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
999 mod->sml_type.bv_val = NULL;
1000 mod->sml_desc = slap_schema.si_ad_entryCSN;
1001 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
1002 ber_dupbv( &mod->sml_values[0], &csn );
1003 mod->sml_values[1].bv_len = 0;
1004 mod->sml_values[1].bv_val = NULL;
1005 assert( mod->sml_values[0].bv_val );
1006 mod->sml_nvalues = NULL;
1008 modtail = &mod->sml_next;
1010 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
1012 mod->sml_type.bv_val = NULL;
1013 mod->sml_desc = slap_schema.si_ad_modifiersName;
1014 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
1015 ber_dupbv( &mod->sml_values[0], &name );
1016 mod->sml_values[1].bv_len = 0;
1017 mod->sml_values[1].bv_val = NULL;
1018 assert( mod->sml_values[0].bv_val );
1020 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
1021 ber_dupbv( &mod->sml_nvalues[0], &nname );
1022 mod->sml_nvalues[1].bv_len = 0;
1023 mod->sml_nvalues[1].bv_val = NULL;
1024 assert( mod->sml_nvalues[0].bv_val );
1026 modtail = &mod->sml_next;
1028 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
1030 mod->sml_type.bv_val = NULL;
1031 mod->sml_desc = slap_schema.si_ad_modifyTimestamp;
1032 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
1033 ber_dupbv( &mod->sml_values[0], ×tamp );
1034 mod->sml_values[1].bv_len = 0;
1035 mod->sml_values[1].bv_val = NULL;
1036 assert( mod->sml_values[0].bv_val );
1037 mod->sml_nvalues = NULL;
1039 modtail = &mod->sml_next;
1043 return LDAP_SUCCESS;