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_next = NULL;
114 if ( mod->sml_values == NULL ) {
115 Debug( LDAP_DEBUG_ANY,
116 "do_modify: modify/add operation (%ld) requires values\n",
119 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
120 "modify/add operation requires values" );
126 case LDAP_MOD_DELETE:
127 case LDAP_MOD_REPLACE:
130 case LDAP_MOD_INCREMENT:
131 if( op->o_protocol >= LDAP_VERSION3 ) {
133 if ( mod->sml_values == NULL ) {
134 Debug( LDAP_DEBUG_ANY, "do_modify: "
135 "modify/increment operation (%ld) requires value\n",
138 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
139 "modify/increment operation requires value" );
143 if( mod->sml_values[1].bv_val ) {
144 Debug( LDAP_DEBUG_ANY, "do_modify: modify/increment "
145 "operation (%ld) requires single value\n",
148 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
149 "modify/increment operation requires single value" );
158 Debug( LDAP_DEBUG_ANY,
159 "do_modify: unrecognized modify operation (%ld)\n",
162 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
163 "unrecognized modify operation" );
168 modtail = &mod->sml_next;
172 if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
173 Debug( LDAP_DEBUG_ANY, "do_modify: get_ctrls failed\n", 0, 0, 0 );
178 rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn,
180 if( rs->sr_err != LDAP_SUCCESS ) {
181 Debug( LDAP_DEBUG_ANY,
182 "do_modify: invalid dn (%s)\n", dn.bv_val, 0, 0 );
183 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
187 rs->sr_err = slap_mods_check( modlist, &rs->sr_text,
188 textbuf, textlen, NULL );
190 if ( rs->sr_err != LDAP_SUCCESS ) {
191 send_ldap_result( op, rs );
195 /* FIXME: needs review */
196 op->orm_modlist = modlist;
197 op->orm_increment = increment;
199 op->o_bd = frontendDB;
200 rs->sr_err = frontendDB->be_modify( op, rs );
203 slap_graduate_commit_csn( op );
205 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
206 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
207 if ( op->orm_modlist != NULL ) slap_mods_free( op->orm_modlist, 1 );
213 fe_op_modify( Operation *op, SlapReply *rs )
219 Modifications *modlist = op->orm_modlist;
220 Modifications **modtail = &modlist;
221 int increment = op->orm_increment;
223 char textbuf[ SLAP_TEXT_BUFLEN ];
224 size_t textlen = sizeof( textbuf );
226 if( op->o_req_ndn.bv_len == 0 ) {
227 Debug( LDAP_DEBUG_ANY, "do_modify: root dse!\n", 0, 0, 0 );
229 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
230 "modify upon the root DSE not supported" );
233 } else if ( bvmatch( &op->o_req_ndn, &frontendDB->be_schemandn ) ) {
234 Debug( LDAP_DEBUG_ANY, "do_modify: subschema subentry!\n", 0, 0, 0 );
236 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
237 "modification of subschema subentry not supported" );
242 Debug( LDAP_DEBUG_ARGS, "modifications:\n", 0, 0, 0 );
244 for ( tmp = modlist; tmp != NULL; tmp = tmp->sml_next ) {
245 Debug( LDAP_DEBUG_ARGS, "\t%s: %s\n",
246 tmp->sml_op == LDAP_MOD_ADD ? "add" :
247 (tmp->sml_op == LDAP_MOD_INCREMENT ? "increment" :
248 (tmp->sml_op == LDAP_MOD_DELETE ? "delete" :
249 "replace")), tmp->sml_type.bv_val, 0 );
251 if ( tmp->sml_values == NULL ) {
252 Debug( LDAP_DEBUG_ARGS, "%s\n",
253 "\t\tno values", NULL, NULL );
254 } else if ( tmp->sml_values[0].bv_val == NULL ) {
255 Debug( LDAP_DEBUG_ARGS, "%s\n",
256 "\t\tzero values", NULL, NULL );
257 } else if ( tmp->sml_values[1].bv_val == NULL ) {
258 Debug( LDAP_DEBUG_ARGS, "%s, length %ld\n",
259 "\t\tone value", (long) tmp->sml_values[0].bv_len, NULL );
261 Debug( LDAP_DEBUG_ARGS, "%s\n",
262 "\t\tmultiple values", NULL, NULL );
266 if ( StatslogTest( LDAP_DEBUG_STATS ) ) {
267 char abuf[BUFSIZ/2], *ptr = abuf;
270 Statslog( LDAP_DEBUG_STATS, "%s MOD dn=\"%s\"\n",
271 op->o_log_prefix, op->o_req_dn.bv_val, 0, 0, 0 );
273 for ( tmp = modlist; tmp != NULL; tmp = tmp->sml_next ) {
274 if (len + 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
275 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
276 op->o_log_prefix, abuf, 0, 0, 0 );
281 if( 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
282 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
283 op->o_log_prefix, tmp->sml_type.bv_val, 0, 0, 0 );
291 ptr = lutil_strcopy(ptr, tmp->sml_type.bv_val);
292 len += tmp->sml_type.bv_len;
295 Statslog( LDAP_DEBUG_STATS, "%s MOD attr=%s\n",
296 op->o_log_prefix, abuf, 0, 0, 0 );
299 #endif /* LDAP_DEBUG */
301 manageDSAit = get_manageDSAit( op );
304 * We could be serving multiple database backends. Select the
305 * appropriate one, or send a referral to our "referral server"
306 * if we don't hold it.
308 op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 1 );
309 if ( op->o_bd == NULL ) {
310 rs->sr_ref = referral_rewrite( default_referral,
311 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
312 if (!rs->sr_ref) rs->sr_ref = default_referral;
314 if (rs->sr_ref != NULL ) {
315 rs->sr_err = LDAP_REFERRAL;
316 op->o_bd = frontendDB;
317 send_ldap_result( op, rs );
320 if (rs->sr_ref != default_referral) ber_bvarray_free( rs->sr_ref );
322 op->o_bd = frontendDB;
323 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
324 "no global superior knowledge" );
330 /* If we've got a glued backend, check the real backend */
332 if ( SLAP_GLUE_INSTANCE( op->o_bd )) {
333 op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 0 );
336 /* check restrictions */
337 if( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
338 send_ldap_result( op, rs );
342 /* check for referrals */
343 if( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
347 rs->sr_err = slap_mods_obsolete_check( op, modlist,
348 &rs->sr_text, textbuf, textlen );
349 if ( rs->sr_err != LDAP_SUCCESS ) {
350 send_ldap_result( op, rs );
354 /* check for modify/increment support */
355 if( increment && !SLAP_INCREMENT( op->o_bd ) ) {
356 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
357 "modify/increment not supported in context" );
361 * do the modify if 1 && (2 || 3)
362 * 1) there is a modify function implemented in this backend;
363 * 2) this backend is master for what it holds;
364 * 3) it's a replica and the dn supplied is the update_ndn.
366 if ( op->o_bd->be_modify ) {
367 /* do the update here */
368 int repl_user = be_isupdate( op );
370 /* Multimaster slapd does not have to check for replicator dn
371 * because it accepts each modify request
373 #ifndef SLAPD_MULTIMASTER
374 if ( !SLAP_SHADOW(op->o_bd) || repl_user )
377 int update = !BER_BVISEMPTY( &op->o_bd->be_update_ndn );
378 slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
383 rs->sr_err = slap_mods_no_user_mod_check( op, modlist,
384 &rs->sr_text, textbuf, textlen );
385 if ( rs->sr_err != LDAP_SUCCESS ) {
386 send_ldap_result( op, rs );
392 for( modtail = &modlist;
394 modtail = &(*modtail)->sml_next )
399 rs->sr_err = slap_mods_opattrs( op, modlist, modtail,
400 &rs->sr_text, textbuf, textlen, 1 );
401 if( rs->sr_err != LDAP_SUCCESS ) {
402 send_ldap_result( op, rs );
407 op->orm_modlist = modlist;
408 #ifdef SLAPD_MULTIMASTER
412 /* but multimaster slapd logs only the ones
413 * not from a replicator user */
414 cb.sc_next = op->o_callback;
415 op->o_callback = &cb;
417 op->o_bd->be_modify( op, rs );
419 #ifndef SLAPD_MULTIMASTER
420 /* send a referral */
422 BerVarray defref = op->o_bd->be_update_refs
423 ? op->o_bd->be_update_refs : default_referral;
424 if ( defref != NULL ) {
425 rs->sr_ref = referral_rewrite( defref,
427 LDAP_SCOPE_DEFAULT );
428 if ( rs->sr_ref == NULL ) {
429 /* FIXME: must duplicate, because
430 * overlays may muck with it */
433 rs->sr_err = LDAP_REFERRAL;
434 send_ldap_result( op, rs );
435 if ( rs->sr_ref != defref ) {
436 ber_bvarray_free( rs->sr_ref );
440 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
441 "shadow context; no update referral" );
446 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
447 "operation not supported within namingContext" );
455 * Obsolete constraint checking.
458 slap_mods_obsolete_check(
465 if( get_manageDIT( op ) ) return LDAP_SUCCESS;
467 for ( ; ml != NULL; ml = ml->sml_next ) {
468 if ( is_at_obsolete( ml->sml_desc->ad_type ) &&
469 (( ml->sml_op != LDAP_MOD_REPLACE &&
470 ml->sml_op != LDAP_MOD_DELETE ) ||
471 ml->sml_values != NULL ))
474 * attribute is obsolete,
475 * only allow replace/delete with no values
477 snprintf( textbuf, textlen,
478 "%s: attribute is obsolete",
479 ml->sml_type.bv_val );
481 return LDAP_CONSTRAINT_VIOLATION;
489 * No-user-modification constraint checking.
492 slap_mods_no_user_mod_check(
499 for ( ; ml != NULL; ml = ml->sml_next ) {
500 if ( !is_at_no_user_mod( ml->sml_desc->ad_type ) ) continue;
502 if( get_manageDIT( op )) {
503 if ( ml->sml_desc->ad_type->sat_flags & SLAP_AT_MANAGEABLE ) {
507 /* attribute not manageable */
508 snprintf( textbuf, textlen,
509 "%s: no-user-modification attribute not manageable",
510 ml->sml_type.bv_val );
513 /* user modification disallowed */
514 snprintf( textbuf, textlen,
515 "%s: no user modification allowed",
516 ml->sml_type.bv_val );
520 return LDAP_CONSTRAINT_VIOLATION;
527 slap_mods_no_repl_user_mod_check(
537 for ( mods = ml; mods != NULL; mods = mods->sml_next ) {
538 assert( mods->sml_op == LDAP_MOD_ADD );
540 /* check doesn't already appear */
541 for ( modp = ml; modp != NULL; modp = modp->sml_next ) {
542 if ( mods->sml_desc == modp->sml_desc && mods != modp ) {
543 snprintf( textbuf, textlen,
544 "attribute '%s' provided more than once",
545 mods->sml_desc->ad_cname.bv_val );
546 return LDAP_TYPE_OR_VALUE_EXISTS;
555 * Do basic attribute type checking and syntax validation.
566 for( ; ml != NULL; ml = ml->sml_next ) {
567 AttributeDescription *ad = NULL;
569 /* convert to attribute description */
570 if ( ml->sml_desc == NULL ) {
571 rc = slap_bv2ad( &ml->sml_type, &ml->sml_desc, text );
572 if( rc != LDAP_SUCCESS ) {
573 snprintf( textbuf, textlen, "%s: %s",
574 ml->sml_type.bv_val, *text );
582 if( slap_syntax_is_binary( ad->ad_type->sat_syntax )
583 && !slap_ad_is_binary( ad ))
585 /* attribute requires binary transfer */
586 snprintf( textbuf, textlen,
587 "%s: requires ;binary transfer",
588 ml->sml_type.bv_val );
590 return LDAP_UNDEFINED_TYPE;
593 if( !slap_syntax_is_binary( ad->ad_type->sat_syntax )
594 && slap_ad_is_binary( ad ))
596 /* attribute does not require binary transfer */
597 snprintf( textbuf, textlen,
598 "%s: disallows ;binary transfer",
599 ml->sml_type.bv_val );
601 return LDAP_UNDEFINED_TYPE;
604 if( slap_ad_is_tag_range( ad )) {
605 /* attribute requires binary transfer */
606 snprintf( textbuf, textlen,
607 "%s: inappropriate use of tag range option",
608 ml->sml_type.bv_val );
610 return LDAP_UNDEFINED_TYPE;
614 if ( is_at_obsolete( ad->ad_type ) &&
615 (( ml->sml_op != LDAP_MOD_REPLACE &&
616 ml->sml_op != LDAP_MOD_DELETE ) ||
617 ml->sml_values != NULL ))
620 * attribute is obsolete,
621 * only allow replace/delete with no values
623 snprintf( textbuf, textlen,
624 "%s: attribute is obsolete",
625 ml->sml_type.bv_val );
627 return LDAP_CONSTRAINT_VIOLATION;
631 if ( ml->sml_op == LDAP_MOD_INCREMENT &&
632 #ifdef SLAPD_REAL_SYNTAX
633 !is_at_syntax( ad->ad_type, SLAPD_REAL_SYNTAX ) &&
635 !is_at_syntax( ad->ad_type, SLAPD_INTEGER_SYNTAX ) )
638 * attribute values must be INTEGER or REAL
640 snprintf( textbuf, textlen,
641 "%s: attribute syntax inappropriate for increment",
642 ml->sml_type.bv_val );
644 return LDAP_CONSTRAINT_VIOLATION;
650 if( ml->sml_values != NULL ) {
652 slap_syntax_validate_func *validate =
653 ad->ad_type->sat_syntax->ssyn_validate;
654 slap_syntax_transform_func *pretty =
655 ad->ad_type->sat_syntax->ssyn_pretty;
657 if( !pretty && !validate ) {
658 *text = "no validator for syntax";
659 snprintf( textbuf, textlen,
660 "%s: no validator for syntax %s",
662 ad->ad_type->sat_syntax->ssyn_oid );
664 return LDAP_INVALID_SYNTAX;
668 * check that each value is valid per syntax
669 * and pretty if appropriate
671 for ( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) {
675 #ifdef SLAP_ORDERED_PRETTYNORM
676 rc = ordered_value_pretty( ad,
677 &ml->sml_values[nvals], &pval, ctx );
678 #else /* ! SLAP_ORDERED_PRETTYNORM */
679 rc = pretty( ad->ad_type->sat_syntax,
680 &ml->sml_values[nvals], &pval, ctx );
681 #endif /* ! SLAP_ORDERED_PRETTYNORM */
683 #ifdef SLAP_ORDERED_PRETTYNORM
684 rc = ordered_value_validate( ad,
685 &ml->sml_values[nvals] );
686 #else /* ! SLAP_ORDERED_PRETTYNORM */
687 rc = validate( ad->ad_type->sat_syntax,
688 &ml->sml_values[nvals] );
689 #endif /* ! SLAP_ORDERED_PRETTYNORM */
693 snprintf( textbuf, textlen,
694 "%s: value #%ld invalid per syntax",
695 ml->sml_type.bv_val, (long) nvals );
697 return LDAP_INVALID_SYNTAX;
701 ber_memfree_x( ml->sml_values[nvals].bv_val, ctx );
702 ml->sml_values[nvals] = pval;
707 * a rough single value check... an additional check is needed
708 * to catch add of single value to existing single valued attribute
710 if ((ml->sml_op == LDAP_MOD_ADD || ml->sml_op == LDAP_MOD_REPLACE)
711 && nvals > 1 && is_at_single_value( ad->ad_type ))
713 snprintf( textbuf, textlen,
714 "%s: multiple values provided",
715 ml->sml_type.bv_val );
717 return LDAP_CONSTRAINT_VIOLATION;
720 /* if the type has a normalizer, generate the
721 * normalized values. otherwise leave them NULL.
723 * this is different from the rule for attributes
724 * in an entry - in an attribute list, the normalized
725 * value is set equal to the non-normalized value
726 * when there is no normalizer.
728 if( nvals && ad->ad_type->sat_equality &&
729 ad->ad_type->sat_equality->smr_normalize )
731 ml->sml_nvalues = ber_memalloc_x(
732 (nvals+1)*sizeof(struct berval), ctx );
734 for ( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) {
735 #ifdef SLAP_ORDERED_PRETTYNORM
736 rc = ordered_value_normalize(
737 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
739 ad->ad_type->sat_equality,
740 &ml->sml_values[nvals], &ml->sml_nvalues[nvals], ctx );
741 #else /* ! SLAP_ORDERED_PRETTYNORM */
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 );
747 #endif /* ! SLAP_ORDERED_PRETTYNORM */
749 Debug( LDAP_DEBUG_ANY,
750 "<= 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 BER_BVZERO( &ml->sml_nvalues[nvals] );
763 /* check for duplicates, but ignore Deletes.
765 if( nvals > 1 && ml->sml_op != LDAP_MOD_DELETE ) {
767 MatchingRule *mr = ad->ad_type->sat_equality;
769 for ( i = 1; i < nvals ; i++ ) {
770 /* test asserted values against themselves */
771 for( j = 0; j < i; j++ ) {
772 rc = ordered_value_match( &match, ml->sml_desc, mr,
774 | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX
775 | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH
776 | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH,
778 ? &ml->sml_nvalues[i]
779 : &ml->sml_values[i],
781 ? &ml->sml_nvalues[j]
782 : &ml->sml_values[j],
784 if ( rc == LDAP_SUCCESS && match == 0 ) {
785 /* value exists already */
786 snprintf( textbuf, textlen,
787 "%s: value #%d provided more than once",
788 ml->sml_desc->ad_cname.bv_val, j );
790 return LDAP_TYPE_OR_VALUE_EXISTS;
792 } else if ( rc != LDAP_SUCCESS ) {
805 /* Enter with bv->bv_len = sizeof buffer, returns with
806 * actual length of string
808 void slap_timestamp( time_t *tm, struct berval *bv )
814 ltm = gmtime_r( tm, <m_buf );
816 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
820 bv->bv_len = lutil_gentime( bv->bv_val, bv->bv_len, ltm );
822 #ifndef HAVE_GMTIME_R
823 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
827 int slap_mods_opattrs(
830 Modifications **modtail,
832 char *textbuf, size_t textlen,
835 struct berval name, timestamp, csn;
837 char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
838 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
841 int mop = op->o_tag == LDAP_REQ_ADD
842 ? LDAP_MOD_ADD : LDAP_MOD_REPLACE;
844 assert( modtail != NULL );
845 assert( *modtail == NULL );
847 if ( SLAP_LASTMOD( op->o_bd ) ) {
848 time_t now = slap_get_time();
850 slap_get_csn( op, csnbuf, sizeof(csnbuf), &csn, manage_ctxcsn );
852 timestamp.bv_val = timebuf;
853 timestamp.bv_len = sizeof(timebuf);
855 slap_timestamp( &now, ×tamp );
857 if ( BER_BVISEMPTY( &op->o_dn ) ) {
858 BER_BVSTR( &name, SLAPD_ANONYMOUS );
866 if ( op->o_tag == LDAP_REQ_ADD ) {
867 struct berval tmpval;
870 if ( get_manageDIT( op ) ) {
871 for ( mod = mods; mod != *modtail; mod = mod->sml_next ) {
872 if ( mod->sml_desc == slap_schema.si_ad_structuralObjectClass ) {
879 if ( mod == *modtail ) {
880 int rc = mods_structural_class( mods, &tmpval,
881 text, textbuf, textlen );
882 if( rc != LDAP_SUCCESS ) return rc;
884 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
886 mod->sml_flags = SLAP_MOD_INTERNAL;
887 mod->sml_type.bv_val = NULL;
888 mod->sml_desc = slap_schema.si_ad_structuralObjectClass;
890 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
891 ber_dupbv( &mod->sml_values[0], &tmpval );
892 mod->sml_values[1].bv_len = 0;
893 mod->sml_values[1].bv_val = NULL;
894 assert( mod->sml_values[0].bv_val != NULL );
896 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
897 ber_dupbv( &mod->sml_nvalues[0], &tmpval );
898 mod->sml_nvalues[1].bv_len = 0;
899 mod->sml_nvalues[1].bv_val = NULL;
900 assert( mod->sml_nvalues[0].bv_val != NULL );
902 modtail = &mod->sml_next;
905 if ( SLAP_LASTMOD( op->o_bd ) ) {
907 if ( get_manageDIT( op ) ) {
908 for ( mod = mods; mod != *modtail; mod = mod->sml_next ) {
909 if ( mod->sml_desc == slap_schema.si_ad_entryUUID ) {
915 if ( mod == *modtail ) {
916 char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
918 tmpval.bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ) );
919 tmpval.bv_val = uuidbuf;
921 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
923 mod->sml_flags = SLAP_MOD_INTERNAL;
924 mod->sml_type.bv_val = NULL;
925 mod->sml_desc = slap_schema.si_ad_entryUUID;
927 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
928 ber_dupbv( &mod->sml_values[0], &tmpval );
929 mod->sml_values[1].bv_len = 0;
930 mod->sml_values[1].bv_val = NULL;
931 assert( mod->sml_values[0].bv_val != NULL );
933 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
934 (*mod->sml_desc->ad_type->sat_equality->smr_normalize)(
935 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
936 mod->sml_desc->ad_type->sat_syntax,
937 mod->sml_desc->ad_type->sat_equality,
938 mod->sml_values, mod->sml_nvalues, NULL );
939 mod->sml_nvalues[1].bv_len = 0;
940 mod->sml_nvalues[1].bv_val = NULL;
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 ) );
957 mod->sml_flags = SLAP_MOD_INTERNAL;
958 mod->sml_type.bv_val = NULL;
959 mod->sml_desc = slap_schema.si_ad_creatorsName;
961 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
962 ber_dupbv( &mod->sml_values[0], &name );
963 mod->sml_values[1].bv_len = 0;
964 mod->sml_values[1].bv_val = NULL;
965 assert( mod->sml_values[0].bv_val != NULL );
967 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
968 ber_dupbv( &mod->sml_nvalues[0], &nname );
969 mod->sml_nvalues[1].bv_len = 0;
970 mod->sml_nvalues[1].bv_val = NULL;
971 assert( mod->sml_nvalues[0].bv_val != NULL );
973 modtail = &mod->sml_next;
977 if ( get_manageDIT( op ) ) {
978 for ( mod = mods; mod != *modtail; mod = mod->sml_next ) {
979 if ( mod->sml_desc == slap_schema.si_ad_createTimestamp ) {
985 if ( mod == *modtail ) {
986 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
988 mod->sml_flags = SLAP_MOD_INTERNAL;
989 mod->sml_type.bv_val = NULL;
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 mod->sml_values[1].bv_len = 0;
995 mod->sml_values[1].bv_val = NULL;
996 assert( mod->sml_values[0].bv_val != NULL );
997 mod->sml_nvalues = NULL;
999 modtail = &mod->sml_next;
1004 if ( SLAP_LASTMOD( op->o_bd ) ) {
1005 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
1007 mod->sml_flags = SLAP_MOD_INTERNAL;
1008 mod->sml_type.bv_val = NULL;
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 mod->sml_values[1].bv_len = 0;
1013 mod->sml_values[1].bv_val = NULL;
1014 assert( mod->sml_values[0].bv_val != NULL );
1015 mod->sml_nvalues = NULL;
1017 modtail = &mod->sml_next;
1020 if ( get_manageDIT( op ) ) {
1021 for ( mod = mods; mod != *modtail; mod = mod->sml_next ) {
1022 if ( mod->sml_desc == slap_schema.si_ad_modifiersName ) {
1028 if ( mod == *modtail ) {
1029 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
1031 mod->sml_flags = SLAP_MOD_INTERNAL;
1032 mod->sml_type.bv_val = NULL;
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 mod->sml_values[1].bv_len = 0;
1037 mod->sml_values[1].bv_val = NULL;
1038 assert( mod->sml_values[0].bv_val != NULL );
1040 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
1041 ber_dupbv( &mod->sml_nvalues[0], &nname );
1042 mod->sml_nvalues[1].bv_len = 0;
1043 mod->sml_nvalues[1].bv_val = NULL;
1044 assert( mod->sml_nvalues[0].bv_val != NULL );
1046 modtail = &mod->sml_next;
1050 if ( get_manageDIT( op ) ) {
1051 for ( mod = mods; mod != *modtail; mod = mod->sml_next ) {
1052 if ( mod->sml_desc == slap_schema.si_ad_modifyTimestamp ) {
1058 if ( mod == *modtail ) {
1059 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
1061 mod->sml_flags = SLAP_MOD_INTERNAL;
1062 mod->sml_type.bv_val = NULL;
1063 mod->sml_desc = slap_schema.si_ad_modifyTimestamp;
1064 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
1065 ber_dupbv( &mod->sml_values[0], ×tamp );
1066 mod->sml_values[1].bv_len = 0;
1067 mod->sml_values[1].bv_val = NULL;
1068 assert( mod->sml_values[0].bv_val != NULL );
1069 mod->sml_nvalues = NULL;
1071 modtail = &mod->sml_next;
1076 return LDAP_SUCCESS;