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 = { 0, NULL };
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 );
105 /* collect modifications & save for later */
107 for ( tag = ber_first_element( op->o_ber, &len, &last );
109 tag = ber_next_element( op->o_ber, &len, last ) )
112 Modifications tmp, *mod;
114 tmp.sml_nvalues = NULL;
116 if ( ber_scanf( op->o_ber, "{i{m[W]}}", &mop,
117 &tmp.sml_type, &tmp.sml_values )
120 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding modlist error" );
121 rs->sr_err = SLAPD_DISCONNECT;
125 mod = (Modifications *) ch_malloc( sizeof(Modifications) );
127 mod->sml_type = tmp.sml_type;
128 mod->sml_values = tmp.sml_values;
129 mod->sml_nvalues = NULL;
130 mod->sml_desc = NULL;
131 mod->sml_next = NULL;
136 if ( mod->sml_values == NULL ) {
138 LDAP_LOG( OPERATION, ERR,
139 "do_modify: modify/add operation (%ld) requires values\n",
142 Debug( LDAP_DEBUG_ANY,
143 "do_modify: modify/add operation (%ld) requires values\n",
147 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
148 "modify/add operation requires values" );
154 case LDAP_MOD_DELETE:
155 case LDAP_MOD_REPLACE:
158 case LDAP_MOD_INCREMENT:
159 if( op->o_protocol >= LDAP_VERSION3 ) {
161 if ( mod->sml_values == NULL ) {
163 LDAP_LOG( OPERATION, ERR, "do_modify: "
164 "modify/increment operation (%ld) requires value\n",
167 Debug( LDAP_DEBUG_ANY, "do_modify: "
168 "modify/increment operation (%ld) requires value\n",
172 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
173 "modify/increment operation requires value" );
177 if( mod->sml_values[1].bv_val ) {
179 LDAP_LOG( OPERATION, ERR, "do_modify: modify/increment "
180 "operation (%ld) requires single value\n",
183 Debug( LDAP_DEBUG_ANY, "do_modify: modify/increment "
184 "operation (%ld) requires single value\n",
188 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
189 "modify/increment operation requires single value" );
199 LDAP_LOG( OPERATION, ERR,
200 "do_modify: unrecognized modify operation (%ld)\n",
203 Debug( LDAP_DEBUG_ANY,
204 "do_modify: unrecognized modify operation (%ld)\n",
208 send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR,
209 "unrecognized modify operation" );
214 modtail = &mod->sml_next;
218 if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
220 LDAP_LOG( OPERATION, ERR, "do_modify: get_ctrls failed\n", 0, 0, 0 );
222 Debug( LDAP_DEBUG_ANY, "do_modify: get_ctrls failed\n", 0, 0, 0 );
228 rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn,
230 if( rs->sr_err != LDAP_SUCCESS ) {
232 LDAP_LOG( OPERATION, INFO, "do_modify: conn %d invalid dn (%s)\n",
233 op->o_connid, dn.bv_val, 0 );
235 Debug( LDAP_DEBUG_ANY,
236 "do_modify: invalid dn (%s)\n", dn.bv_val, 0, 0 );
238 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
242 if( op->o_req_ndn.bv_len == 0 ) {
244 LDAP_LOG( OPERATION, ERR,
245 "do_modify: attempt to modify root DSE.\n",0, 0, 0 );
247 Debug( LDAP_DEBUG_ANY, "do_modify: root dse!\n", 0, 0, 0 );
250 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
251 "modify upon the root DSE not supported" );
254 } else if ( bvmatch( &op->o_req_ndn, &global_schemandn ) ) {
256 LDAP_LOG( OPERATION, ERR,
257 "do_modify: attempt to modify subschema subentry.\n" , 0, 0, 0 );
259 Debug( LDAP_DEBUG_ANY, "do_modify: subschema subentry!\n", 0, 0, 0 );
262 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
263 "modification of subschema subentry not supported" );
269 LDAP_LOG( OPERATION, DETAIL1, "do_modify: modifications:\n", 0, 0, 0 );
271 Debug( LDAP_DEBUG_ARGS, "modifications:\n", 0, 0, 0 );
274 for ( tmp = modlist; tmp != NULL; tmp = tmp->sml_next ) {
276 LDAP_LOG( OPERATION, DETAIL1, "\t%s: %s\n",
277 tmp->sml_op == LDAP_MOD_ADD ? "add" :
278 (tmp->sml_op == LDAP_MOD_INCREMENT ? "increment" :
279 (tmp->sml_op == LDAP_MOD_DELETE ? "delete" :
280 "replace")), tmp->sml_type.bv_val, 0 );
282 if ( tmp->sml_values == NULL ) {
283 LDAP_LOG( OPERATION, DETAIL1, "\t\tno values", 0, 0, 0 );
284 } else if ( tmp->sml_values[0].bv_val == NULL ) {
285 LDAP_LOG( OPERATION, DETAIL1, "\t\tzero values", 0, 0, 0 );
286 } else if ( tmp->sml_values[1].bv_val == NULL ) {
287 LDAP_LOG( OPERATION, DETAIL1, "\t\tone value", 0, 0, 0 );
289 LDAP_LOG( OPERATION, DETAIL1, "\t\tmultiple values", 0, 0, 0 );
293 Debug( LDAP_DEBUG_ARGS, "\t%s: %s\n",
294 tmp->sml_op == LDAP_MOD_ADD ? "add" :
295 (tmp->sml_op == LDAP_MOD_INCREMENT ? "increment" :
296 (tmp->sml_op == LDAP_MOD_DELETE ? "delete" :
297 "replace")), tmp->sml_type.bv_val, 0 );
299 if ( tmp->sml_values == NULL ) {
300 Debug( LDAP_DEBUG_ARGS, "%s\n",
301 "\t\tno values", NULL, NULL );
302 } else if ( tmp->sml_values[0].bv_val == NULL ) {
303 Debug( LDAP_DEBUG_ARGS, "%s\n",
304 "\t\tzero values", NULL, NULL );
305 } else if ( tmp->sml_values[1].bv_val == NULL ) {
306 Debug( LDAP_DEBUG_ARGS, "%s, length %ld\n",
307 "\t\tone value", (long) tmp->sml_values[0].bv_len, NULL );
309 Debug( LDAP_DEBUG_ARGS, "%s\n",
310 "\t\tmultiple values", NULL, NULL );
315 if ( StatslogTest( LDAP_DEBUG_STATS ) ) {
316 char abuf[BUFSIZ/2], *ptr = abuf;
319 Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu MOD dn=\"%s\"\n",
320 op->o_connid, op->o_opid, dn.bv_val, 0, 0 );
322 for ( tmp = modlist; tmp != NULL; tmp = tmp->sml_next ) {
323 if (len + 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
324 Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu MOD attr=%s\n",
325 op->o_connid, op->o_opid, abuf, 0, 0 );
330 if( 1 + tmp->sml_type.bv_len > sizeof(abuf)) {
331 Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu MOD attr=%s\n",
332 op->o_connid, op->o_opid, tmp->sml_type.bv_val, 0, 0 );
340 ptr = lutil_strcopy(ptr, tmp->sml_type.bv_val);
341 len += tmp->sml_type.bv_len;
344 Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu MOD attr=%s\n",
345 op->o_connid, op->o_opid, abuf, 0, 0 );
348 #endif /* LDAP_DEBUG */
350 manageDSAit = get_manageDSAit( op );
353 * We could be serving multiple database backends. Select the
354 * appropriate one, or send a referral to our "referral server"
355 * if we don't hold it.
357 op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 0 );
358 if ( op->o_bd == NULL ) {
359 rs->sr_ref = referral_rewrite( default_referral,
360 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
361 if (!rs->sr_ref) rs->sr_ref = default_referral;
363 if (rs->sr_ref != NULL ) {
364 rs->sr_err = LDAP_REFERRAL;
365 send_ldap_result( op, rs );
367 if (rs->sr_ref != default_referral) ber_bvarray_free( rs->sr_ref );
369 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
370 "referral missing" );
375 /* check restrictions */
376 if( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
377 send_ldap_result( op, rs );
381 /* check for referrals */
382 if( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
386 /* check for modify/increment support */
387 if( increment && !SLAP_INCREMENT( op->o_bd ) ) {
388 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
389 "modify/increment not supported in context" );
392 #if defined( LDAP_SLAPI )
395 slapi_int_pblock_set_operation( pb, op );
396 slapi_pblock_set( pb, SLAPI_MODIFY_TARGET, (void *)dn.bv_val );
397 slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)manageDSAit );
398 modv = slapi_int_modifications2ldapmods( &modlist );
399 slapi_pblock_set( pb, SLAPI_MODIFY_MODS, (void *)modv );
401 rs->sr_err = slapi_int_call_plugins( op->o_bd, SLAPI_PLUGIN_PRE_MODIFY_FN, pb );
402 if ( rs->sr_err < 0 ) {
404 * A preoperation plugin failure will abort the
408 LDAP_LOG( OPERATION, INFO, "do_modify: modify preoperation plugin "
409 "failed\n", 0, 0, 0 );
411 Debug(LDAP_DEBUG_TRACE, "do_modify: modify preoperation plugin failed.\n",
414 if ( ( slapi_pblock_get( op->o_pb, SLAPI_RESULT_CODE, (void *)&rs->sr_err ) != 0 ) ||
415 rs->sr_err == LDAP_SUCCESS ) {
416 rs->sr_err = LDAP_OTHER;
418 slapi_int_free_ldapmods( modv );
424 * It's possible that the preoperation plugin changed the
425 * modification array, so we need to convert it back to
426 * a Modification list.
428 * Calling slapi_int_modifications2ldapmods() destroyed modlist so
429 * we don't need to free it.
431 slapi_pblock_get( pb, SLAPI_MODIFY_MODS, (void **)&modv );
432 modlist = slapi_int_ldapmods2modifications( modv );
436 * NB: it is valid for the plugin to return no modifications
437 * (for example, a plugin might store some attributes elsewhere
438 * and remove them from the modification list; if only those
439 * attribute types were included in the modification request,
440 * then slapi_int_ldapmods2modifications() above will return
443 * However, the post-operation plugin should still be
446 if ( modlist == NULL ) {
447 rs->sr_err = LDAP_SUCCESS;
448 send_ldap_result( op, rs );
450 #endif /* defined( LDAP_SLAPI ) */
453 * do the modify if 1 && (2 || 3)
454 * 1) there is a modify function implemented in this backend;
455 * 2) this backend is master for what it holds;
456 * 3) it's a replica and the dn supplied is the update_ndn.
458 if ( op->o_bd->be_modify ) {
459 /* do the update here */
460 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
462 /* Multimaster slapd does not have to check for replicator dn
463 * because it accepts each modify request
465 #ifndef SLAPD_MULTIMASTER
466 if ( LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo ) &&
467 ( !op->o_bd->be_update_ndn.bv_len || repl_user ))
469 if ( LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo ))
472 int update = op->o_bd->be_update_ndn.bv_len;
473 char textbuf[SLAP_TEXT_BUFLEN];
474 size_t textlen = sizeof textbuf;
475 slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
477 rs->sr_err = slap_mods_check( modlist, update, &rs->sr_text,
478 textbuf, textlen, NULL );
480 if( rs->sr_err != LDAP_SUCCESS ) {
481 send_ldap_result( op, rs );
486 for( modtail = &modlist;
488 modtail = &(*modtail)->sml_next )
493 rs->sr_err = slap_mods_opattrs( op, modlist, modtail,
494 &rs->sr_text, textbuf, textlen );
495 if( rs->sr_err != LDAP_SUCCESS ) {
496 send_ldap_result( op, rs );
501 op->orm_modlist = modlist;
502 #ifdef SLAPD_MULTIMASTER
506 /* but we log only the ones not from a replicator user */
507 cb.sc_next = op->o_callback;
508 op->o_callback = &cb;
510 op->o_bd->be_modify( op, rs );
512 #ifndef SLAPD_MULTIMASTER
513 /* send a referral */
515 BerVarray defref = NULL;
516 if ( !LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo )) {
518 LDAP_STAILQ_FOREACH( si, &op->o_bd->be_syncinfo, si_next ) {
520 ber_dupbv( &tmpbv, &si->si_provideruri_bv[0] );
521 ber_bvarray_add( &defref, &tmpbv );
524 defref = op->o_bd->be_update_refs
525 ? op->o_bd->be_update_refs : default_referral;
527 if ( defref != NULL ) {
528 rs->sr_ref = referral_rewrite( defref,
530 LDAP_SCOPE_DEFAULT );
531 if (!rs->sr_ref) rs->sr_ref = defref;
532 rs->sr_err = LDAP_REFERRAL;
533 send_ldap_result( op, rs );
534 if (rs->sr_ref != defref) {
535 ber_bvarray_free( rs->sr_ref );
538 send_ldap_error( op, rs,
539 LDAP_UNWILLING_TO_PERFORM,
540 "referral missing" );
545 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
546 "operation not supported within namingContext" );
549 #if defined( LDAP_SLAPI )
550 } /* modlist != NULL */
552 if ( pb != NULL && slapi_int_call_plugins( op->o_bd, SLAPI_PLUGIN_POST_MODIFY_FN, pb ) < 0 ) {
554 LDAP_LOG( OPERATION, INFO, "do_modify: modify postoperation plugins "
555 "failed\n", 0, 0, 0 );
557 Debug(LDAP_DEBUG_TRACE, "do_modify: modify postoperation plugins "
558 "failed.\n", 0, 0, 0);
561 #endif /* defined( LDAP_SLAPI ) */
565 slap_graduate_commit_csn( op );
567 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
568 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
569 if ( modlist != NULL ) slap_mods_free( modlist );
570 #if defined( LDAP_SLAPI )
571 if ( modv != NULL ) slapi_int_free_ldapmods( modv );
577 * Do basic attribute type checking and syntax validation.
589 for( ; ml != NULL; ml = ml->sml_next ) {
590 AttributeDescription *ad = NULL;
592 /* convert to attribute description */
593 rc = slap_bv2ad( &ml->sml_type, &ml->sml_desc, text );
595 if( rc != LDAP_SUCCESS ) {
596 snprintf( textbuf, textlen, "%s: %s",
597 ml->sml_type.bv_val, *text );
604 if( slap_syntax_is_binary( ad->ad_type->sat_syntax )
605 && !slap_ad_is_binary( ad ))
607 /* attribute requires binary transfer */
608 snprintf( textbuf, textlen,
609 "%s: requires ;binary transfer",
610 ml->sml_type.bv_val );
612 return LDAP_UNDEFINED_TYPE;
615 if( !slap_syntax_is_binary( ad->ad_type->sat_syntax )
616 && slap_ad_is_binary( ad ))
618 /* attribute requires binary transfer */
619 snprintf( textbuf, textlen,
620 "%s: disallows ;binary transfer",
621 ml->sml_type.bv_val );
623 return LDAP_UNDEFINED_TYPE;
626 if( slap_ad_is_tag_range( ad )) {
627 /* attribute requires binary transfer */
628 snprintf( textbuf, textlen,
629 "%s: inappropriate use of tag range option",
630 ml->sml_type.bv_val );
632 return LDAP_UNDEFINED_TYPE;
635 if (!update && is_at_no_user_mod( ad->ad_type )) {
636 /* user modification disallowed */
637 snprintf( textbuf, textlen,
638 "%s: no user modification allowed",
639 ml->sml_type.bv_val );
641 return LDAP_CONSTRAINT_VIOLATION;
644 if ( is_at_obsolete( ad->ad_type ) &&
645 (( ml->sml_op != LDAP_MOD_REPLACE &&
646 ml->sml_op != LDAP_MOD_DELETE ) ||
647 ml->sml_values != NULL ))
650 * attribute is obsolete,
651 * only allow replace/delete with no values
653 snprintf( textbuf, textlen,
654 "%s: attribute is obsolete",
655 ml->sml_type.bv_val );
657 return LDAP_CONSTRAINT_VIOLATION;
660 if ( ml->sml_op == LDAP_MOD_INCREMENT &&
661 #ifdef SLAPD_REAL_SYNTAX
662 !is_at_syntax( ad->ad_type, SLAPD_REAL_SYNTAX ) &&
664 !is_at_syntax( ad->ad_type, SLAPD_INTEGER_SYNTAX ) )
667 * attribute values must be INTEGER or REAL
669 snprintf( textbuf, textlen,
670 "%s: attribute syntax inappropriate for increment",
671 ml->sml_type.bv_val );
673 return LDAP_CONSTRAINT_VIOLATION;
679 if( ml->sml_values != NULL ) {
681 slap_syntax_validate_func *validate =
682 ad->ad_type->sat_syntax->ssyn_validate;
683 slap_syntax_transform_func *pretty =
684 ad->ad_type->sat_syntax->ssyn_pretty;
686 if( !pretty && !validate ) {
687 *text = "no validator for syntax";
688 snprintf( textbuf, textlen,
689 "%s: no validator for syntax %s",
691 ad->ad_type->sat_syntax->ssyn_oid );
693 return LDAP_INVALID_SYNTAX;
697 * check that each value is valid per syntax
698 * and pretty if appropriate
700 for( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) {
703 rc = pretty( ad->ad_type->sat_syntax,
704 &ml->sml_values[nvals], &pval, ctx );
706 rc = validate( ad->ad_type->sat_syntax,
707 &ml->sml_values[nvals] );
711 snprintf( textbuf, textlen,
712 "%s: value #%ld invalid per syntax",
713 ml->sml_type.bv_val, (long) nvals );
715 return LDAP_INVALID_SYNTAX;
719 ber_memfree_x( ml->sml_values[nvals].bv_val, ctx );
720 ml->sml_values[nvals] = pval;
725 * a rough single value check... an additional check is needed
726 * to catch add of single value to existing single valued attribute
728 if ((ml->sml_op == LDAP_MOD_ADD || ml->sml_op == LDAP_MOD_REPLACE)
729 && nvals > 1 && is_at_single_value( ad->ad_type ))
731 snprintf( textbuf, textlen,
732 "%s: multiple values provided",
733 ml->sml_type.bv_val );
735 return LDAP_CONSTRAINT_VIOLATION;
738 /* if the type has a normalizer, generate the
739 * normalized values. otherwise leave them NULL.
741 * this is different from the rule for attributes
742 * in an entry - in an attribute list, the normalized
743 * value is set equal to the non-normalized value
744 * when there is no normalizer.
746 if( nvals && ad->ad_type->sat_equality &&
747 ad->ad_type->sat_equality->smr_normalize )
749 ml->sml_nvalues = ber_memalloc_x(
750 (nvals+1)*sizeof(struct berval), ctx );
752 for( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) {
753 rc = ad->ad_type->sat_equality->smr_normalize(
754 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
755 ad->ad_type->sat_syntax,
756 ad->ad_type->sat_equality,
757 &ml->sml_values[nvals], &ml->sml_nvalues[nvals], ctx );
760 LDAP_LOG( OPERATION, DETAIL1,
761 "str2entry: NULL (ssyn_normalize %d)\n",
764 Debug( LDAP_DEBUG_ANY,
765 "<= str2entry NULL (ssyn_normalize %d)\n",
768 snprintf( textbuf, textlen,
769 "%s: value #%ld normalization failed",
770 ml->sml_type.bv_val, (long) nvals );
776 ml->sml_nvalues[nvals].bv_val = NULL;
777 ml->sml_nvalues[nvals].bv_len = 0;
785 int slap_mods_opattrs(
788 Modifications **modtail,
790 char *textbuf, size_t textlen )
792 struct berval name, timestamp, csn;
794 char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
795 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
798 int mop = op->o_tag == LDAP_REQ_ADD
799 ? LDAP_MOD_ADD : LDAP_MOD_REPLACE;
801 assert( modtail != NULL );
802 assert( *modtail == NULL );
804 if ( SLAP_LASTMOD( op->o_bd )) {
809 time_t now = slap_get_time();
812 ltm = gmtime_r( &now, <m_buf );
814 ldap_pvt_thread_mutex_lock( &gmtime_mutex );
815 ltm = gmtime( &now );
816 #endif /* HAVE_GMTIME_R */
817 lutil_gentime( timebuf, sizeof(timebuf), ltm );
819 slap_get_csn( op, csnbuf, sizeof(csnbuf), &csn, 1 );
821 #ifndef HAVE_GMTIME_R
822 ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
825 timestamp.bv_val = timebuf;
826 timestamp.bv_len = strlen(timebuf);
828 if( op->o_dn.bv_len == 0 ) {
829 name.bv_val = SLAPD_ANONYMOUS;
830 name.bv_len = sizeof(SLAPD_ANONYMOUS)-1;
838 if( op->o_tag == LDAP_REQ_ADD ) {
839 struct berval tmpval;
841 if( global_schemacheck ) {
842 int rc = mods_structural_class( mods, &tmpval,
843 text, textbuf, textlen );
844 if( rc != LDAP_SUCCESS ) return rc;
846 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
848 mod->sml_type.bv_val = NULL;
849 mod->sml_desc = slap_schema.si_ad_structuralObjectClass;
851 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
852 ber_dupbv( &mod->sml_values[0], &tmpval );
853 mod->sml_values[1].bv_len = 0;
854 mod->sml_values[1].bv_val = NULL;
855 assert( mod->sml_values[0].bv_val );
857 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
858 ber_dupbv( &mod->sml_nvalues[0], &tmpval );
859 mod->sml_nvalues[1].bv_len = 0;
860 mod->sml_nvalues[1].bv_val = NULL;
861 assert( mod->sml_nvalues[0].bv_val );
863 modtail = &mod->sml_next;
866 if ( SLAP_LASTMOD( op->o_bd )) {
867 char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
869 tmpval.bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ) );
870 tmpval.bv_val = uuidbuf;
872 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
874 mod->sml_type.bv_val = NULL;
875 mod->sml_desc = slap_schema.si_ad_entryUUID;
877 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
878 ber_dupbv( &mod->sml_values[0], &tmpval );
879 mod->sml_values[1].bv_len = 0;
880 mod->sml_values[1].bv_val = NULL;
881 assert( mod->sml_values[0].bv_val );
883 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
884 (*mod->sml_desc->ad_type->sat_equality->smr_normalize)(
885 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
886 mod->sml_desc->ad_type->sat_syntax,
887 mod->sml_desc->ad_type->sat_equality,
888 mod->sml_values, mod->sml_nvalues, NULL );
889 mod->sml_nvalues[1].bv_len = 0;
890 mod->sml_nvalues[1].bv_val = NULL;
892 modtail = &mod->sml_next;
894 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
896 mod->sml_type.bv_val = NULL;
897 mod->sml_desc = slap_schema.si_ad_creatorsName;
899 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
900 ber_dupbv( &mod->sml_values[0], &name );
901 mod->sml_values[1].bv_len = 0;
902 mod->sml_values[1].bv_val = NULL;
903 assert( mod->sml_values[0].bv_val );
905 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
906 ber_dupbv( &mod->sml_nvalues[0], &nname );
907 mod->sml_nvalues[1].bv_len = 0;
908 mod->sml_nvalues[1].bv_val = NULL;
909 assert( mod->sml_nvalues[0].bv_val );
911 modtail = &mod->sml_next;
913 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
915 mod->sml_type.bv_val = NULL;
916 mod->sml_desc = slap_schema.si_ad_createTimestamp;
918 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
919 ber_dupbv( &mod->sml_values[0], ×tamp );
920 mod->sml_values[1].bv_len = 0;
921 mod->sml_values[1].bv_val = NULL;
922 assert( mod->sml_values[0].bv_val );
923 mod->sml_nvalues = NULL;
925 modtail = &mod->sml_next;
929 if ( SLAP_LASTMOD( op->o_bd )) {
930 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
932 mod->sml_type.bv_val = NULL;
933 mod->sml_desc = slap_schema.si_ad_entryCSN;
934 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
935 ber_dupbv( &mod->sml_values[0], &csn );
936 mod->sml_values[1].bv_len = 0;
937 mod->sml_values[1].bv_val = NULL;
938 assert( mod->sml_values[0].bv_val );
939 mod->sml_nvalues = NULL;
941 modtail = &mod->sml_next;
943 mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
945 mod->sml_type.bv_val = NULL;
946 mod->sml_desc = slap_schema.si_ad_modifiersName;
947 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
948 ber_dupbv( &mod->sml_values[0], &name );
949 mod->sml_values[1].bv_len = 0;
950 mod->sml_values[1].bv_val = NULL;
951 assert( mod->sml_values[0].bv_val );
953 (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
954 ber_dupbv( &mod->sml_nvalues[0], &nname );
955 mod->sml_nvalues[1].bv_len = 0;
956 mod->sml_nvalues[1].bv_val = NULL;
957 assert( mod->sml_nvalues[0].bv_val );
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_modifyTimestamp;
965 mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
966 ber_dupbv( &mod->sml_values[0], ×tamp );
967 mod->sml_values[1].bv_len = 0;
968 mod->sml_values[1].bv_val = NULL;
969 assert( mod->sml_values[0].bv_val );
970 mod->sml_nvalues = NULL;
972 modtail = &mod->sml_next;