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>
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 );
403 * It's possible that the preoperation plugin changed the
404 * modification array, so we need to convert it back to
405 * a Modification list.
407 * Calling slapi_int_modifications2ldapmods() destroyed modlist so
408 * we don't need to free it.
410 slapi_pblock_get( pb, SLAPI_MODIFY_MODS, (void **)&modv );
411 modlist = slapi_int_ldapmods2modifications( modv );
413 if ( rs->sr_err < 0 ) {
415 * A preoperation plugin failure will abort the
419 LDAP_LOG( OPERATION, INFO,
420 "do_modify: modify preoperation plugin failed\n",
423 Debug(LDAP_DEBUG_TRACE,
424 "do_modify: modify preoperation plugin failed.\n",
427 if ( ( slapi_pblock_get( op->o_pb, SLAPI_RESULT_CODE,
428 (void *)&rs->sr_err ) != 0 ) || rs->sr_err == LDAP_SUCCESS )
430 rs->sr_err = LDAP_OTHER;
432 slapi_int_free_ldapmods( modv );
439 * NB: it is valid for the plugin to return no modifications
440 * (for example, a plugin might store some attributes elsewhere
441 * and remove them from the modification list; if only those
442 * attribute types were included in the modification request,
443 * then slapi_int_ldapmods2modifications() above will return
446 * However, the post-operation plugin should still be
449 #endif /* defined( LDAP_SLAPI ) */
452 * do the modify if 1 && (2 || 3)
453 * 1) there is a modify function implemented in this backend;
454 * 2) this backend is master for what it holds;
455 * 3) it's a replica and the dn supplied is the update_ndn.
457 if ( op->o_bd->be_modify ) {
458 /* do the update here */
459 int repl_user = be_isupdate( op );
461 /* Multimaster slapd does not have to check for replicator dn
462 * because it accepts each modify request
464 #ifndef SLAPD_MULTIMASTER
465 if ( !SLAP_SHADOW(op->o_bd) || repl_user )
468 int update = op->o_bd->be_update_ndn.bv_len;
469 char textbuf[SLAP_TEXT_BUFLEN];
470 size_t textlen = sizeof textbuf;
471 slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
473 rs->sr_err = slap_mods_check( modlist, update, &rs->sr_text,
474 textbuf, textlen, NULL );
476 if( rs->sr_err != LDAP_SUCCESS ) {
477 send_ldap_result( op, rs );
482 for( modtail = &modlist;
484 modtail = &(*modtail)->sml_next )
489 rs->sr_err = slap_mods_opattrs( op, modlist, modtail,
490 &rs->sr_text, textbuf, textlen, 1 );
491 if( rs->sr_err != LDAP_SUCCESS ) {
492 send_ldap_result( op, rs );
497 op->orm_modlist = modlist;
498 #ifdef SLAPD_MULTIMASTER
502 /* but we log only the ones not from a replicator user */
503 cb.sc_next = op->o_callback;
504 op->o_callback = &cb;
506 op->o_bd->be_modify( op, rs );
508 #ifndef SLAPD_MULTIMASTER
509 /* send a referral */
511 BerVarray defref = op->o_bd->be_update_refs
512 ? op->o_bd->be_update_refs : default_referral;
513 if ( defref != NULL ) {
514 rs->sr_ref = referral_rewrite( defref,
516 LDAP_SCOPE_DEFAULT );
517 if (!rs->sr_ref) rs->sr_ref = defref;
518 rs->sr_err = LDAP_REFERRAL;
519 send_ldap_result( op, rs );
520 if (rs->sr_ref != defref) {
521 ber_bvarray_free( rs->sr_ref );
524 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
525 "shadow context; no update referral" );
530 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
531 "operation not supported within namingContext" );
534 #if defined( LDAP_SLAPI )
535 if ( pb != NULL && slapi_int_call_plugins( op->o_bd,
536 SLAPI_PLUGIN_POST_MODIFY_FN, pb ) < 0 )
539 LDAP_LOG( OPERATION, INFO,
540 "do_modify: modify postoperation plugins failed\n", 0, 0, 0 );
542 Debug(LDAP_DEBUG_TRACE,
543 "do_modify: modify postoperation plugins failed.\n", 0, 0, 0);
546 #endif /* defined( LDAP_SLAPI ) */
549 slap_graduate_commit_csn( op );
551 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
552 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
553 if ( modlist != NULL ) slap_mods_free( modlist );
554 #if defined( LDAP_SLAPI )
555 if ( modv != NULL ) slapi_int_free_ldapmods( modv );
561 * Do basic attribute type checking and syntax validation.
573 for( ; ml != NULL; ml = ml->sml_next ) {
574 AttributeDescription *ad = NULL;
576 /* convert to attribute description */
577 rc = slap_bv2ad( &ml->sml_type, &ml->sml_desc, text );
579 if( rc != LDAP_SUCCESS ) {
580 snprintf( textbuf, textlen, "%s: %s",
581 ml->sml_type.bv_val, *text );
588 if( slap_syntax_is_binary( ad->ad_type->sat_syntax )
589 && !slap_ad_is_binary( ad ))
591 /* attribute requires binary transfer */
592 snprintf( textbuf, textlen,
593 "%s: requires ;binary transfer",
594 ml->sml_type.bv_val );
596 return LDAP_UNDEFINED_TYPE;
599 if( !slap_syntax_is_binary( ad->ad_type->sat_syntax )
600 && slap_ad_is_binary( ad ))
602 /* attribute does not require binary transfer */
603 snprintf( textbuf, textlen,
604 "%s: disallows ;binary transfer",
605 ml->sml_type.bv_val );
607 return LDAP_UNDEFINED_TYPE;
610 if( slap_ad_is_tag_range( ad )) {
611 /* attribute requires binary transfer */
612 snprintf( textbuf, textlen,
613 "%s: inappropriate use of tag range option",
614 ml->sml_type.bv_val );
616 return LDAP_UNDEFINED_TYPE;
619 if (!update && is_at_no_user_mod( ad->ad_type )) {
620 /* user modification disallowed */
621 snprintf( textbuf, textlen,
622 "%s: no user modification allowed",
623 ml->sml_type.bv_val );
625 return LDAP_CONSTRAINT_VIOLATION;
628 if ( is_at_obsolete( ad->ad_type ) &&
629 (( ml->sml_op != LDAP_MOD_REPLACE &&
630 ml->sml_op != LDAP_MOD_DELETE ) ||
631 ml->sml_values != NULL ))
634 * attribute is obsolete,
635 * only allow replace/delete with no values
637 snprintf( textbuf, textlen,
638 "%s: attribute is obsolete",
639 ml->sml_type.bv_val );
641 return LDAP_CONSTRAINT_VIOLATION;
644 if ( ml->sml_op == LDAP_MOD_INCREMENT &&
645 #ifdef SLAPD_REAL_SYNTAX
646 !is_at_syntax( ad->ad_type, SLAPD_REAL_SYNTAX ) &&
648 !is_at_syntax( ad->ad_type, SLAPD_INTEGER_SYNTAX ) )
651 * attribute values must be INTEGER or REAL
653 snprintf( textbuf, textlen,
654 "%s: attribute syntax inappropriate for increment",
655 ml->sml_type.bv_val );
657 return LDAP_CONSTRAINT_VIOLATION;
663 if( ml->sml_values != NULL ) {
665 slap_syntax_validate_func *validate =
666 ad->ad_type->sat_syntax->ssyn_validate;
667 slap_syntax_transform_func *pretty =
668 ad->ad_type->sat_syntax->ssyn_pretty;
670 if( !pretty && !validate ) {
671 *text = "no validator for syntax";
672 snprintf( textbuf, textlen,
673 "%s: no validator for syntax %s",
675 ad->ad_type->sat_syntax->ssyn_oid );
677 return LDAP_INVALID_SYNTAX;
681 * check that each value is valid per syntax
682 * and pretty if appropriate
684 for( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) {
687 rc = pretty( ad->ad_type->sat_syntax,
688 &ml->sml_values[nvals], &pval, ctx );
690 rc = validate( ad->ad_type->sat_syntax,
691 &ml->sml_values[nvals] );
695 snprintf( textbuf, textlen,
696 "%s: value #%ld invalid per syntax",
697 ml->sml_type.bv_val, (long) nvals );
699 return LDAP_INVALID_SYNTAX;
703 ber_memfree_x( ml->sml_values[nvals].bv_val, ctx );
704 ml->sml_values[nvals] = pval;
709 * a rough single value check... an additional check is needed
710 * to catch add of single value to existing single valued attribute
712 if ((ml->sml_op == LDAP_MOD_ADD || ml->sml_op == LDAP_MOD_REPLACE)
713 && nvals > 1 && is_at_single_value( ad->ad_type ))
715 snprintf( textbuf, textlen,
716 "%s: multiple values provided",
717 ml->sml_type.bv_val );
719 return LDAP_CONSTRAINT_VIOLATION;
722 /* if the type has a normalizer, generate the
723 * normalized values. otherwise leave them NULL.
725 * this is different from the rule for attributes
726 * in an entry - in an attribute list, the normalized
727 * value is set equal to the non-normalized value
728 * when there is no normalizer.
730 if( nvals && ad->ad_type->sat_equality &&
731 ad->ad_type->sat_equality->smr_normalize )
733 ml->sml_nvalues = ber_memalloc_x(
734 (nvals+1)*sizeof(struct berval), ctx );
736 for( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) {
737 rc = ad->ad_type->sat_equality->smr_normalize(
738 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
739 ad->ad_type->sat_syntax,
740 ad->ad_type->sat_equality,
741 &ml->sml_values[nvals], &ml->sml_nvalues[nvals], ctx );
744 LDAP_LOG( OPERATION, DETAIL1,
745 "str2entry: NULL (ssyn_normalize %d)\n",
748 Debug( LDAP_DEBUG_ANY,
749 "<= str2entry NULL (ssyn_normalize %d)\n",
752 snprintf( textbuf, textlen,
753 "%s: value #%ld normalization failed",
754 ml->sml_type.bv_val, (long) nvals );
760 ml->sml_nvalues[nvals].bv_val = NULL;
761 ml->sml_nvalues[nvals].bv_len = 0;
765 /* check for duplicates */
767 MatchingRule *mr = ad->ad_type->sat_equality;
769 /* check if the values we're adding already exist */
770 if( mr == NULL || !mr->smr_match ) {
771 for ( i = 1; ml->sml_values[i].bv_val != NULL; i++ ) {
772 /* test asserted values against themselves */
773 for( j = 0; j < i; j++ ) {
774 if ( bvmatch( &ml->sml_values[i],
775 &ml->sml_values[j] ) )
777 /* value exists already */
778 snprintf( textbuf, textlen,
779 "%s: value #%d provided more than once",
780 ml->sml_desc->ad_cname.bv_val, j );
782 return LDAP_TYPE_OR_VALUE_EXISTS;
791 for ( i = 1; ml->sml_values[i].bv_val != NULL; i++ ) {
792 /* test asserted values against themselves */
793 for( j = 0; j < i; j++ ) {
794 rc = value_match( &match, ml->sml_desc, mr,
796 | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX
797 | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH
798 | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH,
800 ? &ml->sml_nvalues[i]
801 : &ml->sml_values[i],
803 ? &ml->sml_nvalues[j]
804 : &ml->sml_values[j],
806 if ( rc == LDAP_SUCCESS && match == 0 ) {
807 /* value exists already */
808 snprintf( textbuf, textlen,
809 "%s: value #%d provided more than once",
810 ml->sml_desc->ad_cname.bv_val, j );
812 return LDAP_TYPE_OR_VALUE_EXISTS;
814 } else if ( rc != LDAP_SUCCESS ) {
828 int slap_mods_opattrs(
831 Modifications **modtail,
833 char *textbuf, size_t textlen,
836 struct berval name, timestamp, csn;
838 char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
839 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
842 int mop = op->o_tag == LDAP_REQ_ADD
843 ? LDAP_MOD_ADD : LDAP_MOD_REPLACE;
845 assert( modtail != NULL );
846 assert( *modtail == NULL );
848 if ( SLAP_LASTMOD( op->o_bd )) {
853 time_t now = slap_get_time();
856 ltm = gmtime_r( &now, <m_buf );
858 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
859 ltm = gmtime( &now );
860 #endif /* HAVE_GMTIME_R */
861 lutil_gentime( timebuf, sizeof(timebuf), ltm );
863 slap_get_csn( op, csnbuf, sizeof(csnbuf), &csn, manage_ctxcsn );
865 #ifndef HAVE_GMTIME_R
866 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
869 timestamp.bv_val = timebuf;
870 timestamp.bv_len = strlen(timebuf);
872 if( op->o_dn.bv_len == 0 ) {
873 name.bv_val = SLAPD_ANONYMOUS;
874 name.bv_len = sizeof(SLAPD_ANONYMOUS)-1;
882 if( op->o_tag == LDAP_REQ_ADD ) {
883 struct berval tmpval;
885 if( global_schemacheck ) {
886 int rc = mods_structural_class( mods, &tmpval,
887 text, textbuf, textlen );
888 if( rc != LDAP_SUCCESS ) return rc;
890 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
892 mod->sml_type.bv_val = NULL;
893 mod->sml_desc = slap_schema.si_ad_structuralObjectClass;
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 ber_dupbv( &mod->sml_nvalues[0], &tmpval );
903 mod->sml_nvalues[1].bv_len = 0;
904 mod->sml_nvalues[1].bv_val = NULL;
905 assert( mod->sml_nvalues[0].bv_val );
907 modtail = &mod->sml_next;
910 if ( SLAP_LASTMOD( op->o_bd )) {
911 char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
913 tmpval.bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ) );
914 tmpval.bv_val = uuidbuf;
916 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
918 mod->sml_type.bv_val = NULL;
919 mod->sml_desc = slap_schema.si_ad_entryUUID;
921 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
922 ber_dupbv( &mod->sml_values[0], &tmpval );
923 mod->sml_values[1].bv_len = 0;
924 mod->sml_values[1].bv_val = NULL;
925 assert( mod->sml_values[0].bv_val );
927 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
928 (*mod->sml_desc->ad_type->sat_equality->smr_normalize)(
929 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
930 mod->sml_desc->ad_type->sat_syntax,
931 mod->sml_desc->ad_type->sat_equality,
932 mod->sml_values, mod->sml_nvalues, NULL );
933 mod->sml_nvalues[1].bv_len = 0;
934 mod->sml_nvalues[1].bv_val = NULL;
936 modtail = &mod->sml_next;
938 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
940 mod->sml_type.bv_val = NULL;
941 mod->sml_desc = slap_schema.si_ad_creatorsName;
943 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
944 ber_dupbv( &mod->sml_values[0], &name );
945 mod->sml_values[1].bv_len = 0;
946 mod->sml_values[1].bv_val = NULL;
947 assert( mod->sml_values[0].bv_val );
949 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
950 ber_dupbv( &mod->sml_nvalues[0], &nname );
951 mod->sml_nvalues[1].bv_len = 0;
952 mod->sml_nvalues[1].bv_val = NULL;
953 assert( mod->sml_nvalues[0].bv_val );
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_createTimestamp;
962 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
963 ber_dupbv( &mod->sml_values[0], ×tamp );
964 mod->sml_values[1].bv_len = 0;
965 mod->sml_values[1].bv_val = NULL;
966 assert( mod->sml_values[0].bv_val );
967 mod->sml_nvalues = NULL;
969 modtail = &mod->sml_next;
973 if ( SLAP_LASTMOD( op->o_bd )) {
974 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
976 mod->sml_type.bv_val = NULL;
977 mod->sml_desc = slap_schema.si_ad_entryCSN;
978 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
979 ber_dupbv( &mod->sml_values[0], &csn );
980 mod->sml_values[1].bv_len = 0;
981 mod->sml_values[1].bv_val = NULL;
982 assert( mod->sml_values[0].bv_val );
983 mod->sml_nvalues = NULL;
985 modtail = &mod->sml_next;
987 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
989 mod->sml_type.bv_val = NULL;
990 mod->sml_desc = slap_schema.si_ad_modifiersName;
991 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
992 ber_dupbv( &mod->sml_values[0], &name );
993 mod->sml_values[1].bv_len = 0;
994 mod->sml_values[1].bv_val = NULL;
995 assert( mod->sml_values[0].bv_val );
997 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
998 ber_dupbv( &mod->sml_nvalues[0], &nname );
999 mod->sml_nvalues[1].bv_len = 0;
1000 mod->sml_nvalues[1].bv_val = NULL;
1001 assert( mod->sml_nvalues[0].bv_val );
1003 modtail = &mod->sml_next;
1005 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
1007 mod->sml_type.bv_val = NULL;
1008 mod->sml_desc = slap_schema.si_ad_modifyTimestamp;
1009 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
1010 ber_dupbv( &mod->sml_values[0], ×tamp );
1011 mod->sml_values[1].bv_len = 0;
1012 mod->sml_values[1].bv_val = NULL;
1013 assert( mod->sml_values[0].bv_val );
1014 mod->sml_nvalues = NULL;
1016 modtail = &mod->sml_next;
1020 return LDAP_SUCCESS;