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>
43 struct berval dn = BER_BVNULL;
47 Modifications *modlist = NULL;
48 Modifications **modtail = &modlist;
50 char textbuf[ SLAP_TEXT_BUFLEN ];
51 size_t textlen = sizeof( textbuf );
53 Debug( LDAP_DEBUG_TRACE, "do_modify\n", 0, 0, 0 );
56 * Parse the modify request. It looks like this:
58 * ModifyRequest := [APPLICATION 6] SEQUENCE {
59 * name DistinguishedName,
60 * mods SEQUENCE OF SEQUENCE {
61 * operation ENUMERATED {
66 * modification SEQUENCE {
68 * values SET OF AttributeValue
74 if ( ber_scanf( op->o_ber, "{m" /*}*/, &dn ) == LBER_ERROR ) {
75 Debug( LDAP_DEBUG_ANY, "do_modify: ber_scanf failed\n", 0, 0, 0 );
77 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
78 return SLAPD_DISCONNECT;
81 Debug( LDAP_DEBUG_ARGS, "do_modify: dn (%s)\n", dn.bv_val, 0, 0 );
83 /* collect modifications & save for later */
84 for ( tag = ber_first_element( op->o_ber, &len, &last );
86 tag = ber_next_element( op->o_ber, &len, last ) )
89 Modifications tmp, *mod;
91 tmp.sml_nvalues = NULL;
93 if ( ber_scanf( op->o_ber, "{e{m[W]}}", &mop,
94 &tmp.sml_type, &tmp.sml_values ) == LBER_ERROR )
96 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR,
97 "decoding modlist error" );
98 rs->sr_err = SLAPD_DISCONNECT;
102 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
105 mod->sml_type = tmp.sml_type;
106 mod->sml_values = tmp.sml_values;
107 mod->sml_nvalues = NULL;
108 mod->sml_desc = NULL;
109 mod->sml_managing = 0;
110 mod->sml_next = NULL;
115 if ( mod->sml_values == NULL ) {
116 Debug( LDAP_DEBUG_ANY,
117 "do_modify: modify/add operation (%ld) requires values\n",
120 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
121 "modify/add operation requires values" );
127 case LDAP_MOD_DELETE:
128 case LDAP_MOD_REPLACE:
131 case LDAP_MOD_INCREMENT:
132 if( op->o_protocol >= LDAP_VERSION3 ) {
134 if ( mod->sml_values == NULL ) {
135 Debug( LDAP_DEBUG_ANY, "do_modify: "
136 "modify/increment operation (%ld) requires value\n",
139 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
140 "modify/increment operation requires value" );
144 if ( !BER_BVISNULL( &mod->sml_values[ 1 ] ) ) {
145 Debug( LDAP_DEBUG_ANY, "do_modify: modify/increment "
146 "operation (%ld) requires single value\n",
149 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
150 "modify/increment operation requires single value" );
159 Debug( LDAP_DEBUG_ANY,
160 "do_modify: unrecognized modify operation (%ld)\n",
163 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
164 "unrecognized modify operation" );
169 modtail = &mod->sml_next;
173 if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
174 Debug( LDAP_DEBUG_ANY, "do_modify: get_ctrls failed\n", 0, 0, 0 );
179 rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn,
181 if( rs->sr_err != LDAP_SUCCESS ) {
182 Debug( LDAP_DEBUG_ANY,
183 "do_modify: invalid dn (%s)\n", dn.bv_val, 0, 0 );
184 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
188 rs->sr_err = slap_mods_check( modlist,
189 &rs->sr_text, textbuf, textlen, NULL );
191 if ( rs->sr_err != LDAP_SUCCESS ) {
192 send_ldap_result( op, rs );
196 /* FIXME: needs review */
197 op->orm_modlist = modlist;
198 op->orm_increment = increment;
200 op->o_bd = frontendDB;
201 rs->sr_err = frontendDB->be_modify( op, rs );
204 slap_graduate_commit_csn( op );
206 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
207 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
208 if ( op->orm_modlist != NULL ) slap_mods_free( op->orm_modlist, 1 );
214 fe_op_modify( Operation *op, SlapReply *rs )
220 Modifications *modlist = op->orm_modlist;
221 Modifications **modtail = &modlist;
222 int increment = op->orm_increment;
224 char textbuf[ SLAP_TEXT_BUFLEN ];
225 size_t textlen = sizeof( textbuf );
227 if( op->o_req_ndn.bv_len == 0 ) {
228 Debug( LDAP_DEBUG_ANY, "do_modify: root dse!\n", 0, 0, 0 );
230 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
231 "modify upon the root DSE not supported" );
234 } else if ( bvmatch( &op->o_req_ndn, &frontendDB->be_schemandn ) ) {
235 Debug( LDAP_DEBUG_ANY, "do_modify: subschema subentry!\n", 0, 0, 0 );
237 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
238 "modification of subschema subentry not supported" );
243 Debug( LDAP_DEBUG_ARGS, "modifications:\n", 0, 0, 0 );
245 for ( tmp = modlist; tmp != NULL; tmp = tmp->sml_next ) {
246 Debug( LDAP_DEBUG_ARGS, "\t%s: %s\n",
247 tmp->sml_op == LDAP_MOD_ADD ? "add" :
248 (tmp->sml_op == LDAP_MOD_INCREMENT ? "increment" :
249 (tmp->sml_op == LDAP_MOD_DELETE ? "delete" :
250 "replace")), tmp->sml_type.bv_val, 0 );
252 if ( tmp->sml_values == NULL ) {
253 Debug( LDAP_DEBUG_ARGS, "%s\n",
254 "\t\tno values", NULL, NULL );
255 } else if ( BER_BVISNULL( &tmp->sml_values[ 0 ] ) ) {
256 Debug( LDAP_DEBUG_ARGS, "%s\n",
257 "\t\tzero values", NULL, NULL );
258 } else if ( BER_BVISNULL( &tmp->sml_values[ 1 ] ) ) {
259 Debug( LDAP_DEBUG_ARGS, "%s, length %ld\n",
260 "\t\tone value", (long) tmp->sml_values[0].bv_len, NULL );
262 Debug( LDAP_DEBUG_ARGS, "%s\n",
263 "\t\tmultiple values", NULL, NULL );
267 if ( StatslogTest( LDAP_DEBUG_STATS ) ) {
268 char abuf[BUFSIZ/2], *ptr = abuf;
271 Statslog( LDAP_DEBUG_STATS, "%s MOD dn=\"%s\"\n",
272 op->o_log_prefix, op->o_req_dn.bv_val, 0, 0, 0 );
274 for ( tmp = modlist; tmp != NULL; tmp = tmp->sml_next ) {
275 if (len + 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
276 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
277 op->o_log_prefix, abuf, 0, 0, 0 );
282 if( 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
283 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
284 op->o_log_prefix, tmp->sml_type.bv_val, 0, 0, 0 );
292 ptr = lutil_strcopy(ptr, tmp->sml_type.bv_val);
293 len += tmp->sml_type.bv_len;
296 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
297 op->o_log_prefix, abuf, 0, 0, 0 );
300 #endif /* LDAP_DEBUG */
302 manageDSAit = get_manageDSAit( op );
305 * We could be serving multiple database backends. Select the
306 * appropriate one, or send a referral to our "referral server"
307 * if we don't hold it.
309 op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 1 );
310 if ( op->o_bd == NULL ) {
311 rs->sr_ref = referral_rewrite( default_referral,
312 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
313 if (!rs->sr_ref) rs->sr_ref = default_referral;
315 if (rs->sr_ref != NULL ) {
316 rs->sr_err = LDAP_REFERRAL;
317 op->o_bd = frontendDB;
318 send_ldap_result( op, rs );
321 if (rs->sr_ref != default_referral) ber_bvarray_free( rs->sr_ref );
323 op->o_bd = frontendDB;
324 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
325 "no global superior knowledge" );
331 /* If we've got a glued backend, check the real backend */
333 if ( SLAP_GLUE_INSTANCE( op->o_bd )) {
334 op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 0 );
337 /* check restrictions */
338 if( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
339 send_ldap_result( op, rs );
343 /* check for referrals */
344 if( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
348 rs->sr_err = slap_mods_obsolete_check( op, modlist,
349 &rs->sr_text, textbuf, textlen );
350 if ( rs->sr_err != LDAP_SUCCESS ) {
351 send_ldap_result( op, rs );
355 /* check for modify/increment support */
356 if( increment && !SLAP_INCREMENT( op->o_bd ) ) {
357 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
358 "modify/increment not supported in context" );
362 * do the modify if 1 && (2 || 3)
363 * 1) there is a modify function implemented in this backend;
364 * 2) this backend is master for what it holds;
365 * 3) it's a replica and the dn supplied is the update_ndn.
367 if ( op->o_bd->be_modify ) {
368 /* do the update here */
369 int repl_user = be_isupdate( op );
371 /* Multimaster slapd does not have to check for replicator dn
372 * because it accepts each modify request
374 #ifndef SLAPD_MULTIMASTER
375 if ( !SLAP_SHADOW(op->o_bd) || repl_user )
378 int update = !BER_BVISEMPTY( &op->o_bd->be_update_ndn );
379 slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
384 rs->sr_err = slap_mods_no_user_mod_check( op, modlist,
385 &rs->sr_text, textbuf, textlen );
386 if ( rs->sr_err != LDAP_SUCCESS ) {
387 send_ldap_result( op, rs );
393 for( modtail = &modlist;
395 modtail = &(*modtail)->sml_next )
400 rs->sr_err = slap_mods_opattrs( op, modlist, modtail,
401 &rs->sr_text, textbuf, textlen, 1 );
402 if( rs->sr_err != LDAP_SUCCESS ) {
403 send_ldap_result( op, rs );
408 op->orm_modlist = modlist;
409 #ifdef SLAPD_MULTIMASTER
413 /* but multimaster slapd logs only the ones
414 * not from a replicator user */
415 cb.sc_next = op->o_callback;
416 op->o_callback = &cb;
418 op->o_bd->be_modify( op, rs );
420 #ifndef SLAPD_MULTIMASTER
421 /* send a referral */
423 BerVarray defref = op->o_bd->be_update_refs
424 ? op->o_bd->be_update_refs : default_referral;
425 if ( defref != NULL ) {
426 rs->sr_ref = referral_rewrite( defref,
428 LDAP_SCOPE_DEFAULT );
429 if ( rs->sr_ref == NULL ) {
430 /* FIXME: must duplicate, because
431 * overlays may muck with it */
434 rs->sr_err = LDAP_REFERRAL;
435 send_ldap_result( op, rs );
436 if ( rs->sr_ref != defref ) {
437 ber_bvarray_free( rs->sr_ref );
441 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
442 "shadow context; no update referral" );
447 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
448 "operation not supported within namingContext" );
456 * Obsolete constraint checking.
459 slap_mods_obsolete_check(
466 if( get_manageDIT( op ) ) return LDAP_SUCCESS;
468 for ( ; ml != NULL; ml = ml->sml_next ) {
469 if ( is_at_obsolete( ml->sml_desc->ad_type ) &&
470 (( ml->sml_op != LDAP_MOD_REPLACE &&
471 ml->sml_op != LDAP_MOD_DELETE ) ||
472 ml->sml_values != NULL ))
475 * attribute is obsolete,
476 * only allow replace/delete with no values
478 snprintf( textbuf, textlen,
479 "%s: attribute is obsolete",
480 ml->sml_type.bv_val );
482 return LDAP_CONSTRAINT_VIOLATION;
490 * No-user-modification constraint checking.
493 slap_mods_no_user_mod_check(
500 for ( ; ml != NULL; ml = ml->sml_next ) {
501 if ( !is_at_no_user_mod( ml->sml_desc->ad_type ) ) continue;
503 if ( get_manageDIT( op ) ) {
504 if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_MANAGEABLE ) {
505 ml->sml_managing = 1;
509 /* attribute not manageable */
510 snprintf( textbuf, textlen,
511 "%s: no-user-modification attribute not manageable",
512 ml->sml_type.bv_val );
515 /* user modification disallowed */
516 snprintf( textbuf, textlen,
517 "%s: no user modification allowed",
518 ml->sml_type.bv_val );
522 return LDAP_CONSTRAINT_VIOLATION;
529 slap_mods_no_repl_user_mod_check(
539 for ( mods = ml; mods != NULL; mods = mods->sml_next ) {
540 assert( mods->sml_op == LDAP_MOD_ADD );
542 /* check doesn't already appear */
543 for ( modp = ml; modp != NULL; modp = modp->sml_next ) {
544 if ( mods->sml_desc == modp->sml_desc && mods != modp ) {
545 snprintf( textbuf, textlen,
546 "attribute '%s' provided more than once",
547 mods->sml_desc->ad_cname.bv_val );
548 return LDAP_TYPE_OR_VALUE_EXISTS;
557 * Do basic attribute type checking and syntax validation.
568 for( ; ml != NULL; ml = ml->sml_next ) {
569 AttributeDescription *ad = NULL;
571 /* convert to attribute description */
572 if ( ml->sml_desc == NULL ) {
573 rc = slap_bv2ad( &ml->sml_type, &ml->sml_desc, text );
574 if( rc != LDAP_SUCCESS ) {
575 snprintf( textbuf, textlen, "%s: %s",
576 ml->sml_type.bv_val, *text );
584 if( slap_syntax_is_binary( ad->ad_type->sat_syntax )
585 && !slap_ad_is_binary( ad ))
587 /* attribute requires binary transfer */
588 snprintf( textbuf, textlen,
589 "%s: requires ;binary transfer",
590 ml->sml_type.bv_val );
592 return LDAP_UNDEFINED_TYPE;
595 if( !slap_syntax_is_binary( ad->ad_type->sat_syntax )
596 && slap_ad_is_binary( ad ))
598 /* attribute does not require binary transfer */
599 snprintf( textbuf, textlen,
600 "%s: disallows ;binary transfer",
601 ml->sml_type.bv_val );
603 return LDAP_UNDEFINED_TYPE;
606 if( slap_ad_is_tag_range( ad )) {
607 /* attribute requires binary transfer */
608 snprintf( textbuf, textlen,
609 "%s: inappropriate use of tag range option",
610 ml->sml_type.bv_val );
612 return LDAP_UNDEFINED_TYPE;
616 if ( is_at_obsolete( ad->ad_type ) &&
617 (( ml->sml_op != LDAP_MOD_REPLACE &&
618 ml->sml_op != LDAP_MOD_DELETE ) ||
619 ml->sml_values != NULL ))
622 * attribute is obsolete,
623 * only allow replace/delete with no values
625 snprintf( textbuf, textlen,
626 "%s: attribute is obsolete",
627 ml->sml_type.bv_val );
629 return LDAP_CONSTRAINT_VIOLATION;
633 if ( ml->sml_op == LDAP_MOD_INCREMENT &&
634 #ifdef SLAPD_REAL_SYNTAX
635 !is_at_syntax( ad->ad_type, SLAPD_REAL_SYNTAX ) &&
637 !is_at_syntax( ad->ad_type, SLAPD_INTEGER_SYNTAX ) )
640 * attribute values must be INTEGER or REAL
642 snprintf( textbuf, textlen,
643 "%s: attribute syntax inappropriate for increment",
644 ml->sml_type.bv_val );
646 return LDAP_CONSTRAINT_VIOLATION;
652 if( ml->sml_values != NULL ) {
654 slap_syntax_validate_func *validate =
655 ad->ad_type->sat_syntax->ssyn_validate;
656 slap_syntax_transform_func *pretty =
657 ad->ad_type->sat_syntax->ssyn_pretty;
659 if( !pretty && !validate ) {
660 *text = "no validator for syntax";
661 snprintf( textbuf, textlen,
662 "%s: no validator for syntax %s",
664 ad->ad_type->sat_syntax->ssyn_oid );
666 return LDAP_INVALID_SYNTAX;
670 * check that each value is valid per syntax
671 * and pretty if appropriate
673 for ( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) {
677 #ifdef SLAP_ORDERED_PRETTYNORM
678 rc = ordered_value_pretty( ad,
679 &ml->sml_values[nvals], &pval, ctx );
680 #else /* ! SLAP_ORDERED_PRETTYNORM */
681 rc = pretty( ad->ad_type->sat_syntax,
682 &ml->sml_values[nvals], &pval, ctx );
683 #endif /* ! SLAP_ORDERED_PRETTYNORM */
685 #ifdef SLAP_ORDERED_PRETTYNORM
686 rc = ordered_value_validate( ad,
687 &ml->sml_values[nvals] );
688 #else /* ! SLAP_ORDERED_PRETTYNORM */
689 rc = validate( ad->ad_type->sat_syntax,
690 &ml->sml_values[nvals] );
691 #endif /* ! SLAP_ORDERED_PRETTYNORM */
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 #ifdef SLAP_ORDERED_PRETTYNORM
738 rc = ordered_value_normalize(
739 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
741 ad->ad_type->sat_equality,
742 &ml->sml_values[nvals], &ml->sml_nvalues[nvals], ctx );
743 #else /* ! SLAP_ORDERED_PRETTYNORM */
744 rc = ad->ad_type->sat_equality->smr_normalize(
745 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
746 ad->ad_type->sat_syntax,
747 ad->ad_type->sat_equality,
748 &ml->sml_values[nvals], &ml->sml_nvalues[nvals], ctx );
749 #endif /* ! SLAP_ORDERED_PRETTYNORM */
751 Debug( LDAP_DEBUG_ANY,
752 "<= str2entry NULL (ssyn_normalize %d)\n",
754 snprintf( textbuf, textlen,
755 "%s: value #%ld normalization failed",
756 ml->sml_type.bv_val, (long) nvals );
762 BER_BVZERO( &ml->sml_nvalues[nvals] );
765 /* check for duplicates, but ignore Deletes.
767 if( nvals > 1 && ml->sml_op != LDAP_MOD_DELETE ) {
769 MatchingRule *mr = ad->ad_type->sat_equality;
771 for ( i = 1; i < nvals ; i++ ) {
772 /* test asserted values against themselves */
773 for( j = 0; j < i; j++ ) {
774 rc = ordered_value_match( &match, ml->sml_desc, mr,
776 | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX
777 | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH
778 | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH,
780 ? &ml->sml_nvalues[i]
781 : &ml->sml_values[i],
783 ? &ml->sml_nvalues[j]
784 : &ml->sml_values[j],
786 if ( rc == LDAP_SUCCESS && match == 0 ) {
787 /* value exists already */
788 snprintf( textbuf, textlen,
789 "%s: value #%d provided more than once",
790 ml->sml_desc->ad_cname.bv_val, j );
792 return LDAP_TYPE_OR_VALUE_EXISTS;
794 } else if ( rc != LDAP_SUCCESS ) {
807 /* Enter with bv->bv_len = sizeof buffer, returns with
808 * actual length of string
810 void slap_timestamp( time_t *tm, struct berval *bv )
816 ltm = gmtime_r( tm, <m_buf );
818 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
822 bv->bv_len = lutil_gentime( bv->bv_val, bv->bv_len, ltm );
824 #ifndef HAVE_GMTIME_R
825 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
829 int slap_mods_opattrs(
832 Modifications **modtail,
834 char *textbuf, size_t textlen,
837 struct berval name, timestamp, csn;
839 char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
840 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
843 int mop = op->o_tag == LDAP_REQ_ADD
844 ? LDAP_MOD_ADD : LDAP_MOD_REPLACE;
846 assert( modtail != NULL );
847 assert( *modtail == NULL );
849 if ( SLAP_LASTMOD( op->o_bd ) ) {
850 time_t now = slap_get_time();
852 slap_get_csn( op, csnbuf, sizeof(csnbuf), &csn, manage_ctxcsn );
854 timestamp.bv_val = timebuf;
855 timestamp.bv_len = sizeof(timebuf);
857 slap_timestamp( &now, ×tamp );
859 if ( BER_BVISEMPTY( &op->o_dn ) ) {
860 BER_BVSTR( &name, SLAPD_ANONYMOUS );
868 if ( op->o_tag == LDAP_REQ_ADD ) {
869 struct berval tmpval;
872 if ( get_manageDIT( op ) ) {
873 for ( mod = mods; mod != *modtail; mod = mod->sml_next ) {
874 if ( mod->sml_desc == slap_schema.si_ad_structuralObjectClass ) {
881 if ( mod == *modtail ) {
882 int rc = mods_structural_class( mods, &tmpval,
883 text, textbuf, textlen );
884 if( rc != LDAP_SUCCESS ) return rc;
886 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
887 mod->sml_managing = 0;
889 mod->sml_flags = SLAP_MOD_INTERNAL;
890 BER_BVZERO( &mod->sml_type );
891 mod->sml_desc = slap_schema.si_ad_structuralObjectClass;
893 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
894 ber_dupbv( &mod->sml_values[0], &tmpval );
895 BER_BVZERO( &mod->sml_values[1] );
896 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
898 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
899 ber_dupbv( &mod->sml_nvalues[0], &tmpval );
900 BER_BVZERO( &mod->sml_nvalues[1] );
901 assert( !BER_BVISNULL( &mod->sml_nvalues[0] ) );
903 modtail = &mod->sml_next;
906 if ( SLAP_LASTMOD( op->o_bd ) ) {
908 if ( get_manageDIT( op ) ) {
909 for ( mod = mods; mod != *modtail; mod = mod->sml_next ) {
910 if ( mod->sml_desc == slap_schema.si_ad_entryUUID ) {
916 if ( mod == *modtail ) {
917 char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
919 tmpval.bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ) );
920 tmpval.bv_val = uuidbuf;
922 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
923 mod->sml_managing = 0;
925 mod->sml_flags = SLAP_MOD_INTERNAL;
926 BER_BVZERO( &mod->sml_type );
927 mod->sml_desc = slap_schema.si_ad_entryUUID;
929 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
930 ber_dupbv( &mod->sml_values[0], &tmpval );
931 BER_BVZERO( &mod->sml_values[1] );
932 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
934 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
935 (*mod->sml_desc->ad_type->sat_equality->smr_normalize)(
936 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
937 mod->sml_desc->ad_type->sat_syntax,
938 mod->sml_desc->ad_type->sat_equality,
939 mod->sml_values, mod->sml_nvalues, NULL );
940 BER_BVZERO( &mod->sml_nvalues[1] );
942 modtail = &mod->sml_next;
946 if ( get_manageDIT( op ) ) {
947 for ( mod = mods; mod != *modtail; mod = mod->sml_next ) {
948 if ( mod->sml_desc == slap_schema.si_ad_creatorsName ) {
954 if ( mod == *modtail ) {
955 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
956 mod->sml_managing = 0;
958 mod->sml_flags = SLAP_MOD_INTERNAL;
959 BER_BVZERO( &mod->sml_type );
960 mod->sml_desc = slap_schema.si_ad_creatorsName;
962 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
963 ber_dupbv( &mod->sml_values[0], &name );
964 BER_BVZERO( &mod->sml_values[1] );
965 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
967 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
968 ber_dupbv( &mod->sml_nvalues[0], &nname );
969 BER_BVZERO( &mod->sml_nvalues[1] );
970 assert( !BER_BVISNULL( &mod->sml_nvalues[0] ) );
972 modtail = &mod->sml_next;
976 if ( get_manageDIT( op ) ) {
977 for ( mod = mods; mod != *modtail; mod = mod->sml_next ) {
978 if ( mod->sml_desc == slap_schema.si_ad_createTimestamp ) {
984 if ( mod == *modtail ) {
985 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
986 mod->sml_managing = 0;
988 mod->sml_flags = SLAP_MOD_INTERNAL;
989 BER_BVZERO( &mod->sml_type );
990 mod->sml_desc = slap_schema.si_ad_createTimestamp;
992 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
993 ber_dupbv( &mod->sml_values[0], ×tamp );
994 BER_BVZERO( &mod->sml_values[1] );
995 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
996 mod->sml_nvalues = NULL;
998 modtail = &mod->sml_next;
1003 if ( SLAP_LASTMOD( op->o_bd ) ) {
1004 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
1005 mod->sml_managing = 0;
1007 mod->sml_flags = SLAP_MOD_INTERNAL;
1008 BER_BVZERO( &mod->sml_type );
1009 mod->sml_desc = slap_schema.si_ad_entryCSN;
1010 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
1011 ber_dupbv( &mod->sml_values[0], &csn );
1012 BER_BVZERO( &mod->sml_values[1] );
1013 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
1014 mod->sml_nvalues = NULL;
1016 modtail = &mod->sml_next;
1019 if ( get_manageDIT( op ) ) {
1020 for ( mod = mods; mod != *modtail; mod = mod->sml_next ) {
1021 if ( mod->sml_desc == slap_schema.si_ad_modifiersName ) {
1027 if ( mod == *modtail ) {
1028 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
1029 mod->sml_managing = 0;
1031 mod->sml_flags = SLAP_MOD_INTERNAL;
1032 BER_BVZERO( &mod->sml_type );
1033 mod->sml_desc = slap_schema.si_ad_modifiersName;
1034 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
1035 ber_dupbv( &mod->sml_values[0], &name );
1036 BER_BVZERO( &mod->sml_values[1] );
1037 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
1039 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
1040 ber_dupbv( &mod->sml_nvalues[0], &nname );
1041 BER_BVZERO( &mod->sml_nvalues[1] );
1042 assert( !BER_BVISNULL( &mod->sml_nvalues[0] ) );
1044 modtail = &mod->sml_next;
1048 if ( get_manageDIT( op ) ) {
1049 for ( mod = mods; mod != *modtail; mod = mod->sml_next ) {
1050 if ( mod->sml_desc == slap_schema.si_ad_modifyTimestamp ) {
1056 if ( mod == *modtail ) {
1057 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
1058 mod->sml_managing = 0;
1060 mod->sml_flags = SLAP_MOD_INTERNAL;
1061 BER_BVZERO( &mod->sml_type );
1062 mod->sml_desc = slap_schema.si_ad_modifyTimestamp;
1063 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
1064 ber_dupbv( &mod->sml_values[0], ×tamp );
1065 BER_BVZERO( &mod->sml_values[1] );
1066 assert( !BER_BVISNULL( &mod->sml_values[0] ) );
1067 mod->sml_nvalues = NULL;
1069 modtail = &mod->sml_next;
1074 return LDAP_SUCCESS;