]> git.sur5r.net Git - openldap/commitdiff
Move CSN invocations to backends
authorHoward Chu <hyc@openldap.org>
Thu, 13 Oct 2005 11:58:44 +0000 (11:58 +0000)
committerHoward Chu <hyc@openldap.org>
Thu, 13 Oct 2005 11:58:44 +0000 (11:58 +0000)
29 files changed:
servers/slapd/acl.c
servers/slapd/add.c
servers/slapd/back-bdb/add.c
servers/slapd/back-bdb/delete.c
servers/slapd/back-bdb/modify.c
servers/slapd/back-ldbm/add.c
servers/slapd/back-ldbm/delete.c
servers/slapd/back-ldbm/modify.c
servers/slapd/back-ldif/ldif.c
servers/slapd/back-sql/add.c
servers/slapd/back-sql/modrdn.c
servers/slapd/back-sql/operational.c
servers/slapd/connection.c
servers/slapd/ctxcsn.c
servers/slapd/delete.c
servers/slapd/modify.c
servers/slapd/modrdn.c
servers/slapd/operation.c
servers/slapd/overlays/accesslog.c
servers/slapd/overlays/lastmod.c
servers/slapd/overlays/refint.c
servers/slapd/overlays/syncprov.c
servers/slapd/passwd.c
servers/slapd/proto-slap.h
servers/slapd/sasl.c
servers/slapd/saslauthz.c
servers/slapd/slap.h
servers/slapd/slapi/slapi_ops.c
servers/slapd/syncrepl.c

index f224e68e8a1b823178c7284c00ba9432fa80c11a..8bff33752d108dea7ca3b293c0c40c5034bb33e9 100644 (file)
@@ -2603,7 +2603,7 @@ acl_set_gather( SetCookie *cookie, struct berval *name, AttributeDescription *de
        op2.o_tag = LDAP_REQ_SEARCH;
        op2.o_ndn = op2.o_bd->be_rootndn;
        op2.o_callback = &cb;
-       op2.o_time = slap_get_time();
+       slap_op_time( &op2.o_time, &op2.o_tincr );
        op2.o_do_not_cache = 1;
        op2.o_is_auth_check = 0;
        ber_dupbv_x( &op2.o_req_dn, &op2.o_req_ndn, cp->asc_op->o_tmpmemctx );
index 7df87348aa1c7b1b5b8740e63044c4b5e5b24230..250da6093a9fa81555c0a336a6ddb54d49f7b499 100644 (file)
@@ -30,6 +30,7 @@
 #include <ac/time.h>
 #include <ac/socket.h>
 
+#include "lutil.h"
 #include "slap.h"
 
 int
@@ -192,8 +193,6 @@ do_add( Operation *op, SlapReply *rs )
        }
 
 done:;
-       slap_graduate_commit_csn( op );
-
        if ( modlist != NULL ) {
                slap_mods_free( modlist, 0 );
        }
@@ -312,14 +311,6 @@ fe_op_add( Operation *op, SlapReply *rs )
                                }
 
 
-                               rs->sr_err = slap_mods_opattrs( op, modlist,
-                                               modtail, &rs->sr_text,
-                                               textbuf, textlen, 1 );
-                               if ( rs->sr_err != LDAP_SUCCESS ) {
-                                       send_ldap_result( op, rs );
-                                       goto done;
-                               }
-
                                /* check for duplicate values */
                                rs->sr_err = slap_mods_no_repl_user_mod_check( op,
                                        modlist, &rs->sr_text, textbuf, textlen );
@@ -626,3 +617,119 @@ slap_entry2mods(
        return LDAP_SUCCESS;
 }
 
+int slap_add_opattrs(
+       Operation *op,
+       const char **text,
+       char *textbuf,
+       size_t textlen,
+       int manage_ctxcsn )
+{
+       struct berval name, timestamp, csn = BER_BVNULL;
+       struct berval nname, tmp;
+       char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
+       char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
+       Attribute *a;
+
+       a = attr_find( op->ora_e->e_attrs,
+               slap_schema.si_ad_structuralObjectClass );
+
+       if ( !a ) {
+               Attribute *oc;
+               int rc;
+
+               oc = attr_find( op->ora_e->e_attrs, slap_schema.si_ad_objectClass );
+               if ( oc ) {
+                       rc = structural_class( oc->a_vals, &tmp, NULL, text,
+                               textbuf, textlen );
+                       if( rc != LDAP_SUCCESS ) return rc;
+
+                       attr_merge_one( op->ora_e, slap_schema.si_ad_structuralObjectClass,
+                               &tmp, NULL );
+               }
+       }
+
+       if ( SLAP_LASTMOD( op->o_bd ) ) {
+               char *ptr;
+               timestamp.bv_val = timebuf;
+               if ( BER_BVISEMPTY( &op->o_csn )) {
+                       if ( SLAP_SHADOW( op->o_bd ))
+                               manage_ctxcsn = 0;
+                       csn.bv_val = csnbuf;
+                       csn.bv_len = sizeof(csnbuf);
+                       slap_get_csn( op, &csn, manage_ctxcsn );
+               } else {
+                       csn = op->o_csn;
+               }
+               ptr = strchr( csn.bv_val, '#' );
+               if ( ptr ) {
+                       timestamp.bv_len = ptr - csn.bv_val;
+                       if ( timestamp.bv_len >= sizeof(timebuf) )
+                               timestamp.bv_len = sizeof(timebuf) - 1;
+                       strncpy( timebuf, csn.bv_val, timestamp.bv_len );
+                       timebuf[timestamp.bv_len] = '\0';
+               } else {
+                       time_t now = slap_get_time();
+
+                       timestamp.bv_len = sizeof(timebuf);
+
+                       slap_timestamp( &now, &timestamp );
+               }
+
+               if ( BER_BVISEMPTY( &op->o_dn ) ) {
+                       BER_BVSTR( &name, SLAPD_ANONYMOUS );
+                       nname = name;
+               } else {
+                       name = op->o_dn;
+                       nname = op->o_ndn;
+               }
+
+               a = attr_find( op->ora_e->e_attrs,
+                       slap_schema.si_ad_entryUUID );
+               if ( !a ) {
+                       char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
+
+                       tmp.bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ) );
+                       tmp.bv_val = uuidbuf;
+                       
+                       attr_merge_normalize_one( op->ora_e,
+                               slap_schema.si_ad_entryUUID, &tmp, op->o_tmpmemctx );
+               }
+
+               a = attr_find( op->ora_e->e_attrs,
+                       slap_schema.si_ad_creatorsName );
+               if ( !a ) {
+                       attr_merge_one( op->ora_e,
+                               slap_schema.si_ad_creatorsName, &name, &nname );
+               }
+
+               a = attr_find( op->ora_e->e_attrs,
+                       slap_schema.si_ad_createTimestamp );
+               if ( !a ) {
+                       attr_merge_one( op->ora_e,
+                               slap_schema.si_ad_createTimestamp, &timestamp, NULL );
+               }
+
+               a = attr_find( op->ora_e->e_attrs,
+                       slap_schema.si_ad_entryCSN );
+               if ( !a ) {
+                       attr_merge_one( op->ora_e,
+                               slap_schema.si_ad_entryCSN, &csn, NULL );
+               }
+
+               a = attr_find( op->ora_e->e_attrs,
+                       slap_schema.si_ad_modifiersName );
+               if ( !a ) {
+                       attr_merge_one( op->ora_e,
+                               slap_schema.si_ad_modifiersName, &name, &nname );
+               }
+
+               a = attr_find( op->ora_e->e_attrs,
+                       slap_schema.si_ad_modifyTimestamp );
+               if ( !a ) {
+                       attr_merge_one( op->ora_e,
+                               slap_schema.si_ad_modifyTimestamp, &timestamp, NULL );
+               }
+
+       }
+       return LDAP_SUCCESS;
+}
index 227652077e1258978d857763b6d58426693c4226..16861df67046f29652022218d311070df9eb6ced 100644 (file)
@@ -51,6 +51,8 @@ bdb_add(Operation *op, SlapReply *rs )
 
        ctrls[num_ctrls] = 0;
 
+       slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
+
        /* check entry's schema */
        rs->sr_err = entry_schema_check( op, op->oq_add.rs_e, NULL,
                get_manageDIT(op), &rs->sr_text, textbuf, textlen );
@@ -170,14 +172,8 @@ retry:     /* transaction retry */
                                "does not exist\n", 0, 0, 0 );
 
                        rs->sr_err = LDAP_REFERRAL;
-                       send_ldap_result( op, rs );
-
-                       ber_bvarray_free( rs->sr_ref );
-                       op->o_tmpfree( (char *)rs->sr_matched, op->o_tmpmemctx );
-                       rs->sr_ref = NULL;
-                       rs->sr_matched = NULL;
-
-                       goto done;
+                       rs->sr_flags = REP_MATCHED_MUSTBEFREED | REP_REF_MUSTBEFREED;
+                       goto return_results;
                }
 
                rs->sr_err = access_allowed( op, p,
@@ -221,22 +217,18 @@ retry:    /* transaction retry */
 
                if ( is_entry_referral( p ) ) {
                        /* parent is a referral, don't allow add */
-                       rs->sr_matched = p->e_name.bv_val;
+                       rs->sr_matched = ber_strdup_x( p->e_name.bv_val,
+                               op->o_tmpmemctx );
                        rs->sr_ref = get_entry_referrals( op, p );
-
+                       bdb_unlocked_cache_return_entry_r( &bdb->bi_cache, p );
+                       p = NULL;
                        Debug( LDAP_DEBUG_TRACE,
                                LDAP_XSTRING(bdb_add) ": parent is referral\n",
                                0, 0, 0 );
 
                        rs->sr_err = LDAP_REFERRAL;
-                       send_ldap_result( op, rs );
-
-                       ber_bvarray_free( rs->sr_ref );
-                       bdb_unlocked_cache_return_entry_r( &bdb->bi_cache, p );
-                       rs->sr_ref = NULL;
-                       rs->sr_matched = NULL;
-                       p = NULL;
-                       goto done;
+                       rs->sr_flags = REP_MATCHED_MUSTBEFREED | REP_REF_MUSTBEFREED;
+                       goto return_results;
                }
 
 #ifdef BDB_SUBENTRIES
@@ -430,14 +422,9 @@ retry:     /* transaction retry */
 
 return_results:
        send_ldap_result( op, rs );
+       if ( !SLAP_SHADOW( op->o_bd ))
+               slap_graduate_commit_csn( op );
 
-       if( rs->sr_err == LDAP_SUCCESS && bdb->bi_txn_cp ) {
-               ldap_pvt_thread_yield();
-               TXN_CHECKPOINT( bdb->bi_dbenv,
-                       bdb->bi_txn_cp_kbyte, bdb->bi_txn_cp_min, 0 );
-       }
-
-done:
        if( ltid != NULL ) {
                TXN_ABORT( ltid );
                op->o_private = NULL;
@@ -447,5 +434,11 @@ done:
                slap_sl_free( (*postread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
                slap_sl_free( *postread_ctrl, op->o_tmpmemctx );
        }
+
+       if( rs->sr_err == LDAP_SUCCESS && bdb->bi_txn_cp ) {
+               ldap_pvt_thread_yield();
+               TXN_CHECKPOINT( bdb->bi_dbenv,
+                       bdb->bi_txn_cp_kbyte, bdb->bi_txn_cp_min, 0 );
+       }
        return rs->sr_err;
 }
index 16e42d9bb12afb1df2512a103b3b65957374800c..5e70633adf88749fb1990fb76656cc09e342c260 100644 (file)
@@ -19,6 +19,7 @@
 #include <stdio.h>
 #include <ac/string.h>
 
+#include "lutil.h"
 #include "back-bdb.h"
 
 int
@@ -56,6 +57,16 @@ bdb_delete( Operation *op, SlapReply *rs )
        Debug( LDAP_DEBUG_ARGS, "==> " LDAP_XSTRING(bdb_delete) ": %s\n",
                op->o_req_dn.bv_val, 0, 0 );
 
+       /* allocate CSN */
+       if ( !SLAP_SHADOW( op->o_bd )) {
+               struct berval csn;
+               char csnbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
+
+               csn.bv_val = csnbuf;
+               csn.bv_len = sizeof(csnbuf);
+               slap_get_csn( op, &csn, 1 );
+       }
+
        if( 0 ) {
 retry: /* transaction retry */
                if( e != NULL ) {
@@ -161,17 +172,8 @@ retry:     /* transaction retry */
                }
 
                rs->sr_err = LDAP_REFERRAL;
-               send_ldap_result( op, rs );
-
-               if ( rs->sr_ref != default_referral ) {
-                       ber_bvarray_free( rs->sr_ref );
-               }
-               free( (char *)rs->sr_matched );
-               rs->sr_ref = NULL;
-               rs->sr_matched = NULL;
-
-               rs->sr_err = -1;
-               goto done;
+               rs->sr_flags = REP_MATCHED_MUSTBEFREED | REP_REF_MUSTBEFREED;
+               goto return_results;
        }
 
        rc = bdb_cache_find_id( op, ltid, eip->bei_id, &eip, 0, locker, &plock );
@@ -291,15 +293,9 @@ retry:     /* transaction retry */
                        0, 0, 0 );
 
                rs->sr_err = LDAP_REFERRAL;
-               rs->sr_matched = e->e_name.bv_val;
-               send_ldap_result( op, rs );
-
-               ber_bvarray_free( rs->sr_ref );
-               rs->sr_ref = NULL;
-               rs->sr_matched = NULL;
-
-               rs->sr_err = 1;
-               goto done;
+               rs->sr_matched = ch_strdup( e->e_name.bv_val );
+               rs->sr_flags = REP_MATCHED_MUSTBEFREED | REP_REF_MUSTBEFREED;
+               goto return_results;
        }
 
        /* pre-read */
@@ -487,19 +483,10 @@ retry:    /* transaction retry */
        if( num_ctrls ) rs->sr_ctrls = ctrls;
 
 return_results:
-       send_ldap_result( op, rs );
-
-       if( rs->sr_err == LDAP_SUCCESS && bdb->bi_txn_cp ) {
-               ldap_pvt_thread_yield();
-               TXN_CHECKPOINT( bdb->bi_dbenv,
-                       bdb->bi_txn_cp_kbyte, bdb->bi_txn_cp_min, 0 );
-       }
-
        if ( rs->sr_err == LDAP_SUCCESS && parent_is_glue && parent_is_leaf ) {
                op->o_delete_glue_parent = 1;
        }
 
-done:
        if ( p )
                bdb_unlocked_cache_return_entry_r(&bdb->bi_cache, p);
 
@@ -518,9 +505,19 @@ done:
                op->o_private = NULL;
        }
 
+       send_ldap_result( op, rs );
+       if ( !SLAP_SHADOW( op->o_bd ))
+               slap_graduate_commit_csn( op );
+
        if( preread_ctrl != NULL ) {
                slap_sl_free( (*preread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
                slap_sl_free( *preread_ctrl, op->o_tmpmemctx );
        }
+
+       if( rs->sr_err == LDAP_SUCCESS && bdb->bi_txn_cp ) {
+               ldap_pvt_thread_yield();
+               TXN_CHECKPOINT( bdb->bi_dbenv,
+                       bdb->bi_txn_cp_kbyte, bdb->bi_txn_cp_min, 0 );
+       }
        return rs->sr_err;
 }
index e680de5ef2a176f9720f394f1272a1915c4bf565..00d314e7a58516bbd373d89874781e1740ce0edd 100644 (file)
@@ -289,6 +289,9 @@ bdb_modify( Operation *op, SlapReply *rs )
 
        ctrls[num_ctrls] = NULL;
 
+       if ( !SLAP_SHADOW( op->o_bd ))
+               slap_mods_opattrs( op, op->orm_modlist, 1 );
+
        if( 0 ) {
 retry: /* transaction retry */
                if ( dummy.e_attrs ) {
@@ -573,6 +576,8 @@ return_results:
                attrs_free( dummy.e_attrs );
        }
        send_ldap_result( op, rs );
+       if ( !SLAP_SHADOW( op->o_bd ))
+               slap_graduate_commit_csn( op );
 
        if( rs->sr_err == LDAP_SUCCESS && bdb->bi_txn_cp ) {
                ldap_pvt_thread_yield();
index 413d292508e2145487552d3eba4d500217761a01..0f98eca3d0ffc46cbda6303507bee694cddb98ff 100644 (file)
 #include "back-ldbm.h"
 #include "proto-back-ldbm.h"
 
+static int
+ldbm_csn_cb(
+       Operation *op,
+       SlapReply *rs )
+{
+       op->o_callback = op->o_callback->sc_next;
+       slap_graduate_commit_csn( op );
+       return SLAP_CB_CONTINUE;
+}
+
 int
 ldbm_back_add(
     Operation  *op,
@@ -38,6 +48,7 @@ ldbm_back_add(
        AttributeDescription *entry = slap_schema.si_ad_entry;
        char textbuf[SLAP_TEXT_BUFLEN];
        size_t textlen = sizeof textbuf;
+       slap_callback cb = { NULL };
 #ifdef LDBM_SUBENTRIES
        int subentry;
 #endif
@@ -45,6 +56,12 @@ ldbm_back_add(
        Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_add: %s\n",
                op->o_req_dn.bv_val, 0, 0);
        
+       slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
+
+       cb.sc_cleanup = ldbm_csn_cb;
+       cb.sc_next = op->o_callback;
+       op->o_callback = &cb;
+
        rs->sr_err = entry_schema_check( op, op->oq_add.rs_e, NULL,
                get_manageDIT(op), &rs->sr_text, textbuf, textlen );
 
index 6db0d31dbf47be50e88496c1be6621d0850f28ff..36232ecb10dbd66e57b85647dcf3ea761fde9007 100644 (file)
@@ -44,6 +44,16 @@ ldbm_back_delete(
        /* grab giant lock for writing */
        ldap_pvt_thread_rdwr_wlock(&li->li_giant_rwlock);
 
+       /* allocate CSN */
+       if ( !SLAP_SHADOW( op->o_bd )) {
+               struct berval csn;
+               char csnbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
+
+               csn.bv_val = csnbuf;
+               csn.bv_len = sizeof(csnbuf);
+               slap_get_csn( op, &csn, 1 );
+       }
+
        /* get entry with writer lock */
        e = dn2entry_w( op->o_bd, &op->o_req_ndn, &matched );
 
@@ -64,16 +74,9 @@ ldbm_back_delete(
                                                        &op->o_req_dn, LDAP_SCOPE_DEFAULT );
                }
 
-               ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
-
                rs->sr_err = LDAP_REFERRAL;
-               send_ldap_result( op, rs );
-
-               if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref );
-               free( (char *)rs->sr_matched );
-               rs->sr_ref = NULL;
-               rs->sr_matched = NULL;
-               return( -1 );
+               rs->sr_flags |= REP_MATCHED_MUST_BE_FREED | REP_REF_MUSTBEFREED;
+               goto return_results;
        }
 
        /* check entry for "entry" acl */
@@ -83,10 +86,8 @@ ldbm_back_delete(
                        "<=- ldbm_back_delete: no write access to entry\n", 0,
                        0, 0 );
 
-               send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
-                       "no write access to entry" );
-
-               rc = LDAP_INSUFFICIENT_ACCESS;
+               rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
+               rs->sr_text = "no write access to entry";
                goto return_results;
        }
 
@@ -99,13 +100,8 @@ ldbm_back_delete(
                    0, 0 );
 
                rs->sr_err = LDAP_REFERRAL;
-               rs->sr_matched = e->e_name.bv_val;
-               send_ldap_result( op, rs );
-
-               if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref );
-               rs->sr_ref = NULL;
-               rs->sr_matched = NULL;
-               rc = LDAP_REFERRAL;
+               rs->sr_matched = ch_strdup( e->e_name.bv_val );
+               rs->sr_flags = REP_MATCHED_MUSTBEFREED | REP_REF_MUSTBEFREED;
                goto return_results;
        }
 
@@ -113,8 +109,8 @@ ldbm_back_delete(
                Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: non leaf %s\n",
                        op->o_req_dn.bv_val, 0, 0);
 
-               send_ldap_error( op, rs, LDAP_NOT_ALLOWED_ON_NONLEAF,
-                       "subordinate objects must be deleted first");
+               rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
+               rs->sr_text = "subordinate objects must be deleted first";
                goto return_results;
        }
 
@@ -126,8 +122,8 @@ ldbm_back_delete(
                                "<=- ldbm_back_delete: parent does not exist\n",
                                0, 0, 0);
 
-                       send_ldap_error( op, rs, LDAP_OTHER,
-                               "could not locate parent of entry" );
+                       rs->sr_err = LDAP_OTHER;
+                       rs->sr_text = "could not locate parent of entry";
                        goto return_results;
                }
 
@@ -139,8 +135,8 @@ ldbm_back_delete(
                                "<=- ldbm_back_delete: no access to parent\n", 0,
                                0, 0 );
 
-                       send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
-                               "no write access to parent" );
+                       rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
+                       rs->sr_text = "no write access to parent";
                        goto return_results;
                }
 
@@ -161,8 +157,8 @@ ldbm_back_delete(
                                                "<=- ldbm_back_delete: no "
                                                "access to parent\n", 0, 0, 0 );
 
-                                       send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
-                                               "no write access to parent" );
+                                       rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
+                                       rs->sr_text = "no write access to parent";
                                        goto return_results;
                                }
 
@@ -171,9 +167,7 @@ ldbm_back_delete(
                                        "<=- ldbm_back_delete: no parent & "
                                        "not root\n", 0, 0, 0);
 
-                               send_ldap_error( op, rs,
-                                       LDAP_INSUFFICIENT_ACCESS,
-                                       NULL );
+                               rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
                                goto return_results;
                        }
                }
@@ -185,8 +179,8 @@ ldbm_back_delete(
                        "<=- ldbm_back_delete: operations error %s\n",
                        op->o_req_dn.bv_val, 0, 0);
 
-               send_ldap_error( op, rs, LDAP_OTHER,
-                       "DN index delete failed" );
+               rs->sr_err = LDAP_OTHER;
+               rs->sr_text = "DN index delete failed";
                goto return_results;
        }
 
@@ -196,8 +190,8 @@ ldbm_back_delete(
                        "<=- ldbm_back_delete: operations error %s\n",
                        op->o_req_dn.bv_val, 0, 0);
 
-               send_ldap_error( op, rs, LDAP_OTHER,
-                       "entry delete failed" );
+               rs->sr_err = LDAP_OTHER;
+               rs->sr_text = "entry delete failed";
                goto return_results;
        }
 
@@ -205,19 +199,25 @@ ldbm_back_delete(
        (void) index_entry_del( op, e );
 
        rs->sr_err = LDAP_SUCCESS;
-       send_ldap_result( op, rs );
-       rc = LDAP_SUCCESS;
 
 return_results:;
+       rc = rs->sr_err;
+
        if( p != NULL ) {
                /* free parent and writer lock */
                cache_return_entry_w( &li->li_cache, p );
        }
 
-       /* free entry and writer lock */
-       cache_return_entry_w( &li->li_cache, e );
+       if ( e != NULL ) {
+               /* free entry and writer lock */
+               cache_return_entry_w( &li->li_cache, e );
+       }
 
        ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
 
+       send_ldap_result( op, rs );
+       if ( !SLAP_SHADOW( op->o_bd ))
+               slap_graduate_commit_csn( op );
+
        return rc;
 }
index 2dd696919fbde91b3d885c344ca7d74151f6e7b6..1df17bd4f78bc72a4debe856fe395262c6577124 100644 (file)
@@ -241,6 +241,9 @@ ldbm_back_modify(
 
        Debug(LDAP_DEBUG_ARGS, "ldbm_back_modify:\n", 0, 0, 0);
 
+       if ( !SLAP_SHADOW( op->o_bd ))
+               slap_mods_opattrs( op, op->orm_modlist, 1 );
+
        /* grab giant lock for writing */
        ldap_pvt_thread_rdwr_wlock(&li->li_giant_rwlock);
 
@@ -250,7 +253,7 @@ ldbm_back_modify(
        /* FIXME: dn2entry() should return non-glue entry */
        if (( e == NULL ) || ( !manageDSAit && e && is_entry_glue( e ))) {
                if ( matched != NULL ) {
-                       rs->sr_matched = ch_strdup( matched->e_dn );
+                       rs->sr_matched = ber_strdup_x( matched->e_dn, op->o_tmpmemctx );
                        rs->sr_ref = is_entry_referral( matched )
                                ? get_entry_referrals( op, matched )
                                : NULL;
@@ -260,16 +263,9 @@ ldbm_back_modify(
                                                &op->o_req_dn, LDAP_SCOPE_DEFAULT );
                }
 
-               ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
                rs->sr_err = LDAP_REFERRAL;
-               send_ldap_result( op, rs );
-
-               if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref );
-               free( (char *)rs->sr_matched );
-
-               rs->sr_ref = NULL;
-               rs->sr_matched = NULL;
-               return rs->sr_err;
+               rs->sr_flags = REP_MATCHED_MUSTBEFREED | REP_REF_MUSTBEFREED;
+               goto return_results;
        }
 
        if ( !manageDSAit && is_entry_referral( e ) )
@@ -282,47 +278,31 @@ ldbm_back_modify(
                    0, 0 );
 
                rs->sr_err = LDAP_REFERRAL;
-               rs->sr_matched = e->e_name.bv_val;
-               send_ldap_result( op, rs );
-
-               if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref );
-               rs->sr_ref = NULL;
-               rs->sr_matched = NULL;
-               goto error_return;
+               rs->sr_matched = ber_strdup_x( e->e_name.bv_val, op->o_tmpmemctx );
+               rs->sr_flags = REP_MATCHED_MUSTBEFREED | REP_REF_MUSTBEFREED;
+               goto return_results;
        }
        
        /* Modify the entry */
        rs->sr_err = ldbm_modify_internal( op, op->oq_modify.rs_modlist, e,
                &rs->sr_text, textbuf, textlen );
 
-       if( rs->sr_err != LDAP_SUCCESS ) {
-               if( rs->sr_err != SLAPD_ABANDON ) {
-                       send_ldap_result( op, rs );
-               }
-
-               goto error_return;
-       }
-
        /* change the entry itself */
-       if ( id2entry_add( op->o_bd, e ) != 0 ) {
-               send_ldap_error( op, rs, LDAP_OTHER,
-                       "id2entry failure" );
-               rs->sr_err = LDAP_OTHER;
-               goto error_return;
+       if( rs->sr_err == LDAP_SUCCESS ) {
+               if ( id2entry_add( op->o_bd, e ) != 0 ) {
+                       rs->sr_err = LDAP_OTHER;
+                       rs->sr_text = "id2entry failure";
+               }
        }
 
-       rs->sr_text = NULL;
-       send_ldap_error( op, rs, LDAP_SUCCESS,
-               NULL );
-
+return_results:;
        cache_return_entry_w( &li->li_cache, e );
        ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
 
-       return LDAP_SUCCESS;
+       send_ldap_result( op, rs );
+       if ( !SLAP_SHADOW( op->o_bd ))
+               slap_graduate_commit_csn( op );
 
-error_return:;
-       cache_return_entry_w( &li->li_cache, e );
-       ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
        rs->sr_text = NULL;
        return rs->sr_err;
 }
index e6dd8a78f90ee10ddf004983b9af2968269d0c02..0b566f5b750913be498d7a0273650e9454a4ad5a 100644 (file)
@@ -767,6 +767,8 @@ static int ldif_back_add(Operation *op, SlapReply *rs) {
        int statres;
        char textbuf[SLAP_TEXT_BUFLEN];
 
+       slap_add_opattrs( op, &rs->sr_text, textbuf, sizeof( textbuf ), 1 );
+
        rs->sr_err = entry_schema_check(op, e, NULL, 0,
                &rs->sr_text, textbuf, sizeof( textbuf ) );
        if ( rs->sr_err != LDAP_SUCCESS ) goto send_res;
@@ -815,6 +817,8 @@ static int ldif_back_add(Operation *op, SlapReply *rs) {
 
 send_res:
        send_ldap_result(op, rs);
+       if ( !SLAP_SHADOW( op->o_bd ))
+               slap_graduate_commit_csn( op );
        return 0;
 }
 
@@ -825,6 +829,9 @@ static int ldif_back_modify(Operation *op, SlapReply *rs) {
        Entry * entry = NULL;
        int spew_res;
 
+       if ( !SLAP_SHADOW( op->o_bd ))
+               slap_mods_opattrs( op, op->orm_modlist, 1 );
+
        ldap_pvt_thread_mutex_lock(&ni->li_mutex);
        dn2path(&op->o_req_ndn, &op->o_bd->be_nsuffix[0], &ni->li_base_path,
                &path);
@@ -853,6 +860,8 @@ static int ldif_back_modify(Operation *op, SlapReply *rs) {
        rs->sr_text = NULL;
        ldap_pvt_thread_mutex_unlock(&ni->li_mutex);
        send_ldap_result(op, rs);
+       if ( !SLAP_SHADOW( op->o_bd ))
+               slap_graduate_commit_csn( op );
        return 0;
 }
 
@@ -861,6 +870,15 @@ static int ldif_back_delete(Operation *op, SlapReply *rs) {
        struct berval path = BER_BVNULL;
        int res = 0;
 
+       if ( !SLAP_SHADOW( op->o_bd )) {
+               struct berval csn;
+               char csnbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
+
+               csn.bv_val = csnbuf;
+               csn.bv_len = sizeof( csnbuf );
+               slap_get_csn( op, &csn, 1 );
+       }
+
        ldap_pvt_thread_mutex_lock(&ni->li_mutex);
        dn2path(&op->o_req_ndn, &op->o_bd->be_nsuffix[0], &ni->li_base_path, &path);
 
@@ -885,6 +903,8 @@ static int ldif_back_delete(Operation *op, SlapReply *rs) {
        SLAP_FREE(path.bv_val);
        ldap_pvt_thread_mutex_unlock(&ni->li_mutex);
        send_ldap_result(op, rs);
+       if ( !SLAP_SHADOW( op->o_bd ))
+               slap_graduate_commit_csn( op );
        return 0;
 }
 
index 548bfd835eb809bf2618ca3b471f5b0864c332e5..6656b774f311965baa79305f2064152ba84eb2e9 100644 (file)
@@ -936,9 +936,11 @@ backsql_add( Operation *op, SlapReply *rs )
         */
        if ( op->o_sync ) {
                char            buf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
-               struct berval   csn = BER_BVNULL;
+               struct berval   csn;
 
-               slap_get_csn( op, buf, sizeof( buf ), &csn, 1 );
+               csn.bv_val = buf;
+               csn.bv_len = sizeof( buf );
+               slap_get_csn( op, &csn, 1 );
 
                rs->sr_err = LDAP_SUCCESS;
                send_ldap_result( op, rs );
index 306e557d02fd145492529e130d883861027c9f4f..a6aca06c96eee281873fb0f68bc3e6c1693b9dc3 100644 (file)
@@ -438,6 +438,7 @@ backsql_modrdn( Operation *op, SlapReply *rs )
 
        oc = backsql_id2oc( bi, e_id.eid_oc_id );
        rs->sr_err = backsql_modify_internal( op, rs, dbh, oc, &e_id, mod );
+       slap_graduate_commit_csn( op );
        if ( rs->sr_err != LDAP_SUCCESS ) {
                e = &r;
                goto done;
index 6edde629ca61613ace4f92c219973a02bc32759c..1423e2156a88cf1d331527d98a621fd7996a9c9f 100644 (file)
@@ -91,7 +91,9 @@ backsql_operational_entryCSN( Operation *op )
        } else
 #endif /* BACKSQL_SYNCPROV */
        {
-               slap_get_csn( op, csnbuf, sizeof(csnbuf), &entryCSN, 0 );
+               entryCSN.bv_val = csnbuf;
+               entryCSN.bv_len = sizeof( csnbuf );
+               slap_get_csn( op, &entryCSN, 0 );
        }
 
        ber_dupbv( &a->a_vals[ 0 ], &entryCSN );
index aa8f1bb2b693c920d8bde8e7d74957e9f9742ba1..309d82fa1d130e0a23f30920933305aad7311004 100644 (file)
@@ -2138,7 +2138,7 @@ connection_fake_init(
        op->o_connid = op->o_conn->c_connid;
        connection_init_log_prefix( op );
 
-       op->o_time = slap_get_time();
+       slap_op_time( &op->o_time, &op->o_tincr );
 }
 
 void
index 6d29007b58ef542dedff258f4a381626f4540633..87d8cbc3717464a32af500e8d61551df2216d694 100644 (file)
@@ -100,6 +100,9 @@ slap_graduate_commit_csn( Operation *op )
                if ( csne->ce_opid == op->o_opid && csne->ce_connid == op->o_connid ) {
                        LDAP_TAILQ_REMOVE( op->o_bd->be_pending_csn_list,
                                csne, ce_csn_link );
+                       if ( op->o_csn.bv_val == csne->ce_csn.bv_val ) {
+                               BER_BVZERO( &op->o_csn );
+                       }
                        ch_free( csne->ce_csn.bv_val );
                        ch_free( csne );
                        break;
@@ -163,6 +166,7 @@ slap_queue_csn(
        ldap_pvt_thread_mutex_lock( op->o_bd->be_pcl_mutexp );
 
        ber_dupbv( &pending->ce_csn, csn );
+       op->o_csn = pending->ce_csn;
        pending->ce_connid = op->o_connid;
        pending->ce_opid = op->o_opid;
        pending->ce_state = SLAP_CSN_PENDING;
@@ -174,8 +178,6 @@ slap_queue_csn(
 int
 slap_get_csn(
        Operation *op,
-       char *csnbuf,
-       int     len,
        struct berval *csn,
        int manage_ctxcsn )
 {
@@ -184,11 +186,10 @@ slap_get_csn(
 #ifndef HAVE_GMTIME_R
        ldap_pvt_thread_mutex_lock( &gmtime_mutex );
 #endif
-       csn->bv_len = lutil_csnstr( csnbuf, len, 0, 0 );
+       csn->bv_len = lutil_csnstr( csn->bv_val, csn->bv_len, 0, 0 );
 #ifndef HAVE_GMTIME_R
        ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
 #endif
-       csn->bv_val = csnbuf;
 
        if ( manage_ctxcsn )
                slap_queue_csn( op, csn );
index 51bb8d7902d706a95343559cad1285413d9c143e..078505cd221eaf2affd0cff80b67fd9a364f7e62 100644 (file)
@@ -91,8 +91,6 @@ do_delete(
        rs->sr_err = frontendDB->be_delete( op, rs );
 
 cleanup:;
-       slap_graduate_commit_csn( op );
-
        op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
        op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
        return rs->sr_err;
@@ -174,12 +172,6 @@ fe_op_delete( Operation *op, SlapReply *rs )
 
                        op->o_bd = op_be;
 
-                       if ( !repl_user ) {
-                               struct berval csn = BER_BVNULL;
-                               char csnbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
-                               slap_get_csn( op, csnbuf, sizeof(csnbuf), &csn, 1 );
-                       }
-
 #ifdef SLAPD_MULTIMASTER
                        if ( !op->o_bd->be_update_ndn.bv_len || !repl_user )
 #endif
index ca628ef5ff424a93f86a8b243407d6e93f351fc7..4473e1b7dac665308372ab4ab58cfab0a5e9a593 100644 (file)
@@ -200,8 +200,6 @@ do_modify(
        rs->sr_err = frontendDB->be_modify( op, rs );
 
 cleanup:
-       slap_graduate_commit_csn( op );
-
        op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
        op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
        if ( op->orm_modlist != NULL ) slap_mods_free( op->orm_modlist, 1 );
@@ -388,22 +386,6 @@ fe_op_modify( Operation *op, SlapReply *rs )
                                }
                        }
 
-                       if ( !repl_user ) {
-                               for( modtail = &modlist;
-                                       *modtail != NULL;
-                                       modtail = &(*modtail)->sml_next )
-                               {
-                                       /* empty */
-                               }
-
-                               rs->sr_err = slap_mods_opattrs( op, modlist, modtail,
-                                       &rs->sr_text, textbuf, textlen, 1 );
-                               if( rs->sr_err != LDAP_SUCCESS ) {
-                                       send_ldap_result( op, rs );
-                                       goto cleanup;
-                               }
-                       }
-
                        op->orm_modlist = modlist;
 #ifdef SLAPD_MULTIMASTER
                        if ( !repl_user )
@@ -825,35 +807,43 @@ void slap_timestamp( time_t *tm, struct berval *bv )
 #endif
 }
 
-int slap_mods_opattrs(
+/* modify only calls this for non-replicas. modrdn always calls.
+ */
+void slap_mods_opattrs(
        Operation *op,
        Modifications *mods,
-       Modifications **modtail,
-       const char **text,
-       char *textbuf, size_t textlen,
        int manage_ctxcsn )
 {
-       struct berval name, timestamp, csn;
+       struct berval name, timestamp, csn = BER_BVNULL;
        struct berval nname;
        char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
        char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
-       Modifications *mod;
-
-       int mop = op->o_tag == LDAP_REQ_ADD
-               ? LDAP_MOD_ADD : LDAP_MOD_REPLACE;
-
-       assert( modtail != NULL );
-       assert( *modtail == NULL );
+       Modifications *mod, **modtail;
 
        if ( SLAP_LASTMOD( op->o_bd ) ) {
-               time_t now = slap_get_time();
-
-               slap_get_csn( op, csnbuf, sizeof(csnbuf), &csn, manage_ctxcsn );
-
+               char *ptr;
                timestamp.bv_val = timebuf;
-               timestamp.bv_len = sizeof(timebuf);
+               if ( BER_BVISEMPTY( &op->o_csn )) {
+                       csn.bv_val = csnbuf;
+                       csn.bv_len = sizeof( csnbuf );
+                       slap_get_csn( op, &csn, manage_ctxcsn );
+               } else {
+                       csn = op->o_csn;
+               }
+               ptr = strchr( csn.bv_val, '#' );
+               if ( ptr ) {
+                       timestamp.bv_len = ptr - csn.bv_val;
+                       if ( timestamp.bv_len >= sizeof( timebuf ))
+                               timestamp.bv_len = sizeof( timebuf ) - 1;
+                       strncpy( timebuf, csn.bv_val, timestamp.bv_len );
+                       timebuf[timestamp.bv_len] = '\0';
+               } else {
+                       time_t now = slap_get_time();
 
-               slap_timestamp( &now, &timestamp );
+                       timestamp.bv_len = sizeof(timebuf);
+
+                       slap_timestamp( &now, &timestamp );
+               }
 
                if ( BER_BVISEMPTY( &op->o_dn ) ) {
                        BER_BVSTR( &name, SLAPD_ANONYMOUS );
@@ -862,146 +852,13 @@ int slap_mods_opattrs(
                        name = op->o_dn;
                        nname = op->o_ndn;
                }
-       }
-
-       if ( op->o_tag == LDAP_REQ_ADD ) {
-               struct berval tmpval;
-
-               mod = *modtail;
-               if ( get_manageDIT( op ) ) {
-                       for ( mod = mods; mod != *modtail; mod = mod->sml_next ) {
-                               if ( mod->sml_desc == slap_schema.si_ad_structuralObjectClass ) {
-                                       break;
-                               }
-                       }
-
-               }
-
-               if ( mod == *modtail ) {
-                       int rc = mods_structural_class( mods, &tmpval,
-                               text, textbuf, textlen );
-                       if( rc != LDAP_SUCCESS ) return rc;
-
-                       mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
-                       mod->sml_op = mop;
-                       mod->sml_flags = SLAP_MOD_INTERNAL;
-                       mod->sml_next = NULL;
-                       BER_BVZERO( &mod->sml_type );
-                       mod->sml_desc = slap_schema.si_ad_structuralObjectClass;
-                       mod->sml_values =
-                               (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
-                       ber_dupbv( &mod->sml_values[0], &tmpval );
-                       BER_BVZERO( &mod->sml_values[1] );
-                       assert( !BER_BVISNULL( &mod->sml_values[0] ) );
-                       mod->sml_nvalues =
-                               (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
-                       ber_dupbv( &mod->sml_nvalues[0], &tmpval );
-                       BER_BVZERO( &mod->sml_nvalues[1] );
-                       assert( !BER_BVISNULL( &mod->sml_nvalues[0] ) );
-                       *modtail = mod;
-                       modtail = &mod->sml_next;
-               }
 
-               if ( SLAP_LASTMOD( op->o_bd ) ) {
-                       mod = *modtail;
-                       if ( get_manageDIT( op ) ) {
-                               for ( mod = mods; mod != *modtail; mod = mod->sml_next ) {
-                                       if ( mod->sml_desc == slap_schema.si_ad_entryUUID ) {
-                                               break;
-                                       }
-                               }
-                       }
-
-                       if ( mod == *modtail ) {
-                               char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
-
-                               tmpval.bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ) );
-                               tmpval.bv_val = uuidbuf;
-                       
-                               mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
-                               mod->sml_op = mop;
-                               mod->sml_flags = SLAP_MOD_INTERNAL;
-                               mod->sml_next = NULL;
-                               BER_BVZERO( &mod->sml_type );
-                               mod->sml_desc = slap_schema.si_ad_entryUUID;
-                               mod->sml_values =
-                                       (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
-                               ber_dupbv( &mod->sml_values[0], &tmpval );
-                               BER_BVZERO( &mod->sml_values[1] );
-                               assert( !BER_BVISNULL( &mod->sml_values[0] ) );
-                               mod->sml_nvalues =
-                                       (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
-                               (*mod->sml_desc->ad_type->sat_equality->smr_normalize)(
-                                               SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
-                                               mod->sml_desc->ad_type->sat_syntax,
-                                               mod->sml_desc->ad_type->sat_equality,
-                                               mod->sml_values, mod->sml_nvalues, NULL );
-                               BER_BVZERO( &mod->sml_nvalues[1] );
-                               *modtail = mod;
-                               modtail = &mod->sml_next;
-                       }
-
-                       mod = *modtail;
-                       if ( get_manageDIT( op ) ) {
-                               for ( mod = mods; mod != *modtail; mod = mod->sml_next ) {
-                                       if ( mod->sml_desc == slap_schema.si_ad_creatorsName ) {
-                                               break;
-                                       }
-                               }
-                       }
-
-                       if ( mod == *modtail ) {
-                               mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
-                               mod->sml_op = mop;
-                               mod->sml_flags = SLAP_MOD_INTERNAL;
-                               mod->sml_next = NULL;
-                               BER_BVZERO( &mod->sml_type );
-                               mod->sml_desc = slap_schema.si_ad_creatorsName;
-                               mod->sml_values =
-                                       (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
-                               ber_dupbv( &mod->sml_values[0], &name );
-                               BER_BVZERO( &mod->sml_values[1] );
-                               assert( !BER_BVISNULL( &mod->sml_values[0] ) );
-                               mod->sml_nvalues =
-                                       (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
-                               ber_dupbv( &mod->sml_nvalues[0], &nname );
-                               BER_BVZERO( &mod->sml_nvalues[1] );
-                               assert( !BER_BVISNULL( &mod->sml_nvalues[0] ) );
-                               *modtail = mod;
-                               modtail = &mod->sml_next;
-                       }
-       
-                       mod = *modtail;
-                       if ( get_manageDIT( op ) ) {
-                               for ( mod = mods; mod != *modtail; mod = mod->sml_next ) {
-                                       if ( mod->sml_desc == slap_schema.si_ad_createTimestamp ) {
-                                               break;
-                                       }
-                               }
-                       }
-
-                       if ( mod == *modtail ) {
-                               mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
-                               mod->sml_op = mop;
-                               mod->sml_flags = SLAP_MOD_INTERNAL;
-                               mod->sml_next = NULL;
-                               BER_BVZERO( &mod->sml_type );
-                               mod->sml_desc = slap_schema.si_ad_createTimestamp;
-                               mod->sml_values =
-                                       (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
-                               ber_dupbv( &mod->sml_values[0], &timestamp );
-                               BER_BVZERO( &mod->sml_values[1] );
-                               assert( !BER_BVISNULL( &mod->sml_values[0] ) );
-                               mod->sml_nvalues = NULL;
-                               *modtail = mod;
-                               modtail = &mod->sml_next;
-                       }
-               }
-       }
+               for ( mod = mods; mod->sml_next; mod = mod->sml_next )
+                       ;
+               modtail = &mod->sml_next;
 
-       if ( SLAP_LASTMOD( op->o_bd ) ) {
                mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
-               mod->sml_op = mop;
+               mod->sml_op = LDAP_MOD_REPLACE;
                mod->sml_flags = SLAP_MOD_INTERNAL;
                mod->sml_next = NULL;
                BER_BVZERO( &mod->sml_type );
@@ -1016,7 +873,7 @@ int slap_mods_opattrs(
        
                mod = *modtail;
                if ( get_manageDIT( op ) ) {
-                       for ( mod = mods; mod != *modtail; mod = mod->sml_next ) {
+                       for ( mod = mods; mod->sml_next; mod = mod->sml_next ) {
                                if ( mod->sml_desc == slap_schema.si_ad_modifiersName ) {
                                        break;
                                }
@@ -1025,7 +882,7 @@ int slap_mods_opattrs(
 
                if ( mod == *modtail ) {
                        mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
-                       mod->sml_op = mop;
+                       mod->sml_op = LDAP_MOD_REPLACE;
                        mod->sml_flags = SLAP_MOD_INTERNAL;
                        mod->sml_next = NULL;
                        BER_BVZERO( &mod->sml_type );
@@ -1045,7 +902,7 @@ int slap_mods_opattrs(
 
                mod = *modtail;
                if ( get_manageDIT( op ) ) {
-                       for ( mod = mods; mod != *modtail; mod = mod->sml_next ) {
+                       for ( mod = mods; mod->sml_next; mod = mod->sml_next ) {
                                if ( mod->sml_desc == slap_schema.si_ad_modifyTimestamp ) {
                                        break;
                                }
@@ -1054,7 +911,7 @@ int slap_mods_opattrs(
 
                if ( mod == *modtail ) {
                        mod = (Modifications *) ch_malloc( sizeof( Modifications ) );
-                       mod->sml_op = mop;
+                       mod->sml_op = LDAP_MOD_REPLACE;
                        mod->sml_flags = SLAP_MOD_INTERNAL;
                        mod->sml_next = NULL;
                        BER_BVZERO( &mod->sml_type );
@@ -1064,12 +921,7 @@ int slap_mods_opattrs(
                        BER_BVZERO( &mod->sml_values[1] );
                        assert( !BER_BVISNULL( &mod->sml_values[0] ) );
                        mod->sml_nvalues = NULL;
-                       *modtail = mod;
-                       modtail = &mod->sml_next;
                }
        }
-
-       *modtail = NULL;
-       return LDAP_SUCCESS;
 }
 
index f54f714103772eb95bcc8a3de356dd6e5668e478..496abe34d7a300599bbc6b0538c283d357cc0a3c 100644 (file)
@@ -178,8 +178,6 @@ do_modrdn(
        rs->sr_err = frontendDB->be_modrdn( op, rs );
 
 cleanup:
-       slap_graduate_commit_csn( op );
-
        op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
        op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
 
@@ -386,7 +384,6 @@ slap_modrdn2mods(
        Modifications   **pmod )
 {
        Modifications   *mod = NULL;
-       Modifications   **modtail = &mod;
        int             a_cnt, d_cnt;
        int repl_user;
 
@@ -506,18 +503,7 @@ slap_modrdn2mods(
 done:
 
        if ( rs->sr_err == LDAP_SUCCESS && !repl_user ) {
-               char textbuf[ SLAP_TEXT_BUFLEN ];
-               size_t textlen = sizeof textbuf;
-
-               for( modtail = &mod;
-                       *modtail != NULL;
-                       modtail = &(*modtail)->sml_next )
-               {
-                       /* empty */
-               }
-
-               rs->sr_err = slap_mods_opattrs( op, mod, modtail,
-                                               &rs->sr_text, textbuf, textlen, 1 );
+               slap_mods_opattrs( op, mod, 1 );
        }
 
        /* LDAP v2 supporting correct attribute handling. */
index f8ecf3b920548920b5d3bbb7f85372ea9e09882d..68ee4d198a371cab500ca6b37082ab9c6bf0831c 100644 (file)
@@ -112,6 +112,21 @@ slap_op_free( Operation *op )
        ldap_pvt_thread_mutex_unlock( &slap_op_mutex );
 }
 
+void
+slap_op_time(time_t *t, int *nop)
+{
+       *t = slap_get_time();
+       ldap_pvt_thread_mutex_lock( &slap_op_mutex );
+       if ( *t == last_time ) {
+               *nop = ++last_incr;
+       } else {
+               last_time = *t;
+               last_incr = 0;
+               *nop = 0;
+       }
+       ldap_pvt_thread_mutex_unlock( &slap_op_mutex );
+}
+
 Operation *
 slap_op_alloc(
     BerElement         *ber,
@@ -139,13 +154,7 @@ slap_op_alloc(
        op->o_msgid = msgid;
        op->o_tag = tag;
 
-       op->o_time = slap_get_time();
-       if ( op->o_time == last_time ) {
-               op->o_tincr = ++last_incr;
-       } else {
-               last_time = op->o_time;
-               last_incr = 0;  /* o_tincr is alredy zero */
-       }
+       slap_op_time( &op->o_time, &op->o_tincr );
        op->o_opid = id;
        op->o_res_ber = NULL;
 
index 9da3a59b30dfbd7a1952a38cbdbd2dc8cfd381fa..9b35ac8805fcdbccb8e0a4dc4b7292fb5845d990 100644 (file)
@@ -58,6 +58,8 @@ typedef struct log_info {
        int li_cycle;
        struct re_s *li_task;
        int li_success;
+       ldap_pvt_thread_mutex_t li_op_mutex;
+       ldap_pvt_thread_mutex_t li_log_mutex;
 } log_info;
 
 static ConfigDriver log_cf_gen;
@@ -735,11 +737,11 @@ static int accesslog_response(Operation *op, SlapReply *rs) {
        Modifications *m;
        struct berval *b;
        time_t endtime;
-       int i;
+       int i, nop;
        int logop;
        slap_verbmasks *lo;
        Entry *e;
-       char timebuf[LDAP_LUTIL_GENTIME_BUFSIZE];
+       char timebuf[LDAP_LUTIL_GENTIME_BUFSIZE+8];
        struct berval bv;
        char *ptr;
        BerVarray vals;
@@ -749,9 +751,6 @@ static int accesslog_response(Operation *op, SlapReply *rs) {
        if ( rs->sr_type != REP_RESULT && rs->sr_type != REP_EXTENDED )
                return SLAP_CB_CONTINUE;
 
-       if ( li->li_success && rs->sr_err != LDAP_SUCCESS )
-               return SLAP_CB_CONTINUE;
-
        switch ( op->o_tag ) {
        case LDAP_REQ_ADD:              logop = LOG_EN_ADD; break;
        case LDAP_REQ_DELETE:   logop = LOG_EN_DELETE; break;
@@ -769,15 +768,25 @@ static int accesslog_response(Operation *op, SlapReply *rs) {
        if ( !( li->li_ops & lo->mask ))
                return SLAP_CB_CONTINUE;
 
-       endtime = slap_get_time();
+       if ( lo->mask & LOG_OP_WRITES ) {
+               ldap_pvt_thread_mutex_lock( &li->li_log_mutex );
+               ldap_pvt_thread_mutex_unlock( &li->li_op_mutex );
+       }
+
+       if ( li->li_success && rs->sr_err != LDAP_SUCCESS )
+               goto done;
+
+       slap_op_time( &endtime, &nop );
 
        e = accesslog_entry( op, logop );
 
        bv.bv_val = timebuf;
        bv.bv_len = sizeof(timebuf);
        slap_timestamp( &endtime, &bv );
+       sprintf( bv.bv_val + bv.bv_len-1, ".%06dZ", nop );
+       bv.bv_len += 7;
 
-       attr_merge_one( e, ad_reqEnd, &bv, NULL );
+       attr_merge_normalize_one( e, ad_reqEnd, &bv, op->o_tmpmemctx );
 
        attr_merge_one( e, ad_reqDN, &op->o_req_dn, &op->o_req_ndn );
 
@@ -980,16 +989,30 @@ static int accesslog_response(Operation *op, SlapReply *rs) {
        op2.ora_e = e;
        op2.o_callback = &nullsc;
 
-       if ( lo->mask & LOG_OP_WRITES ) {
-               slap_get_commit_csn( op, NULL, &bv );
-               attr_merge_one( e, slap_schema.si_ad_entryCSN, &bv, NULL );
-               slap_queue_csn( &op2, &bv );
+       if (( lo->mask & LOG_OP_WRITES ) && !BER_BVISEMPTY( &op->o_csn )) {
+               slap_queue_csn( &op2, &op->o_csn );
        }
 
        op2.o_bd->be_add( &op2, &rs2 );
-       slap_graduate_commit_csn( &op2 );
        entry_free( e );
 
+done:
+       ldap_pvt_thread_mutex_unlock( &li->li_log_mutex );
+       return SLAP_CB_CONTINUE;
+}
+
+static int
+accesslog_op_mod( Operation *op, SlapReply *rs )
+{
+       slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
+       log_info *li = on->on_bi.bi_private;
+
+       if ( li->li_ops & LOG_OP_WRITES ) {
+               /* FIXME: this needs to be a recursive mutex to allow
+                * overlays like refint to keep working.
+                */
+               ldap_pvt_thread_mutex_lock( &li->li_op_mutex );
+       }
        return SLAP_CB_CONTINUE;
 }
 
@@ -1076,6 +1099,8 @@ accesslog_db_init(
        log_info *li = ch_calloc(1, sizeof(log_info));
 
        on->on_bi.bi_private = li;
+       ldap_pvt_thread_mutex_init( &li->li_op_mutex );
+       ldap_pvt_thread_mutex_init( &li->li_log_mutex );
        return 0;
 }
 
@@ -1087,6 +1112,8 @@ accesslog_db_destroy(
        slap_overinst *on = (slap_overinst *)be->bd_info;
        log_info *li = on->on_bi.bi_private;
        
+       ldap_pvt_thread_mutex_destroy( &li->li_log_mutex );
+       ldap_pvt_thread_mutex_destroy( &li->li_op_mutex );
        free( li );
        return LDAP_SUCCESS;
 }
@@ -1099,6 +1126,10 @@ int accesslog_init()
        accesslog.on_bi.bi_db_init = accesslog_db_init;
        accesslog.on_bi.bi_db_destroy = accesslog_db_destroy;
 
+       accesslog.on_bi.bi_op_add = accesslog_op_mod;
+       accesslog.on_bi.bi_op_delete = accesslog_op_mod;
+       accesslog.on_bi.bi_op_modify = accesslog_op_mod;
+       accesslog.on_bi.bi_op_modrdn = accesslog_op_mod;
        accesslog.on_bi.bi_op_unbind = accesslog_unbind;
        accesslog.on_bi.bi_op_abandon = accesslog_abandon;
        accesslog.on_response = accesslog_response;
index 07e06eb0d21f605e32d7188c1da8688a98b23ed6..63a30e6301fece21a0e0276849db76fd3b6e579e 100644 (file)
@@ -370,7 +370,9 @@ best_guess( Operation *op,
                char            csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
                struct berval   entryCSN;
        
-               slap_get_csn( NULL, csnbuf, sizeof(csnbuf), &entryCSN, 0 );
+               entryCSN.bv_val = csnbuf;
+               entryCSN.bv_len = sizeof( csnbuf );
+               slap_get_csn( NULL, &entryCSN, 0 );
 
                ber_dupbv( bv_entryCSN, &entryCSN );
                ber_dupbv( bv_nentryCSN, &entryCSN );
@@ -909,7 +911,9 @@ lastmod_db_open(
        timestamp.bv_len = sizeof(tmbuf);
        slap_timestamp( &starttime, &timestamp );
 
-       slap_get_csn( NULL, csnbuf, sizeof(csnbuf), &entryCSN, 0 );
+       entryCSN.bv_val = csnbuf;
+       entryCSN.bv_len = sizeof( csnbuf );
+       slap_get_csn( NULL, &entryCSN, 0 );
 
        if ( BER_BVISNULL( &lmi->lmi_rdnvalue ) ) {
                ber_str2bv( "Lastmod", 0, 1, &lmi->lmi_rdnvalue );
index 41e1cbc9cf0739e4f49a38ceff0836545a565879..9004f902f971aff10053b3fb89a9c42d33535a12 100644 (file)
@@ -621,10 +621,6 @@ refint_response(
        */
 
        for(dp = dd.mods; dp; dp = dp->next) {
-               Modifications **tail, *m;
-
-               for(m = dp->mm; m && m->sml_next; m = m->sml_next);
-               tail = &m->sml_next;
                nop.o_req_dn    = dp->dn;
                nop.o_req_ndn   = dp->dn;
                nop.o_bd = select_backend(&dp->dn, 0, 1);
@@ -637,8 +633,6 @@ refint_response(
                nop.orm_modlist = dp->mm;       /* callback did all the work */
                nop.o_dn = refint_dn;
                nop.o_ndn = refint_dn;
-               rs->sr_err = slap_mods_opattrs( &nop, nop.orm_modlist,
-                       tail, &rs->sr_text, NULL, 0, 1 );
                nop.o_dn = nop.o_bd->be_rootdn;
                nop.o_ndn = nop.o_bd->be_rootndn;
                if(rs->sr_err != LDAP_SUCCESS) goto done;
index 4070d5dd09626a2c412df00eecca9cdc95527b4d..38946321c17894b7e8df8813a5caf02012ad428c 100644 (file)
@@ -2275,8 +2275,8 @@ syncprov_db_open(
        }
 
        if ( BER_BVISEMPTY( &si->si_ctxcsn ) ) {
-               slap_get_csn( op, si->si_ctxcsnbuf, sizeof(si->si_ctxcsnbuf),
-                               &si->si_ctxcsn, 0 );
+               si->si_ctxcsn.bv_len = sizeof( si->si_ctxcsnbuf );
+               slap_get_csn( op, &si->si_ctxcsn, 0 );
        }
 
        /* If our ctxcsn is different from what was read from the root
index 4c69a2e6b5f4845ec72990bf3bec472b807573ab..fee10439dd2f1af387073e6fef9010b262c5f333 100644 (file)
@@ -273,12 +273,7 @@ old_good:
                cb2.sc_private = qpw;   /* let Modify know this was pwdMod,
                                         * if it cares... */
 
-               rs->sr_err = slap_mods_opattrs( op, ml, qpw->rs_modtail, &rs->sr_text,
-                       NULL, 0, 1 );
-               
-               if ( rs->sr_err == LDAP_SUCCESS ) {
-                       rs->sr_err = op->o_bd->be_modify( op, rs );
-               }
+               rs->sr_err = op->o_bd->be_modify( op, rs );
                if ( rs->sr_err == LDAP_SUCCESS ) {
                        rs->sr_rspdata = rsp;
                } else if ( rsp ) {
index 995bc053595b633bf441eb8efb431d57c8173d46..6369ef409dbc4f6bad77df8899fd74ef7057b1f6 100644 (file)
@@ -206,6 +206,12 @@ LDAP_SLAPD_F (int) slap_mods2entry LDAP_P(( Modifications *mods, Entry **e,
 LDAP_SLAPD_F (int) slap_entry2mods LDAP_P(( Entry *e,
                                                Modifications **mods, const char **text,
                                                char *textbuf, size_t textlen ));
+LDAP_SLAPD_F( int ) slap_add_opattrs(
+       Operation *op,
+       const char **text,
+       char *textbuf, size_t textlen,
+       int manage_ctxcsn );
+
 
 /*
  * at.c
@@ -697,7 +703,7 @@ LDAP_SLAPD_F (void) slap_get_commit_csn LDAP_P((
 LDAP_SLAPD_F (void) slap_rewind_commit_csn LDAP_P(( Operation * ));
 LDAP_SLAPD_F (void) slap_graduate_commit_csn LDAP_P(( Operation * ));
 LDAP_SLAPD_F (Entry *) slap_create_context_csn_entry LDAP_P(( Backend *, struct berval *));
-LDAP_SLAPD_F (int) slap_get_csn LDAP_P(( Operation *, char *, int, struct berval *, int ));
+LDAP_SLAPD_F (int) slap_get_csn LDAP_P(( Operation *, struct berval *, int ));
 LDAP_SLAPD_F (void) slap_queue_csn LDAP_P(( Operation *, struct berval * ));
 
 /*
@@ -1041,12 +1047,9 @@ LDAP_SLAPD_F( void ) slap_timestamp(
        time_t *tm,
        struct berval *bv );
 
-LDAP_SLAPD_F( int ) slap_mods_opattrs(
+LDAP_SLAPD_F( void ) slap_mods_opattrs(
        Operation *op,
        Modifications *mods,
-       Modifications **modlist,
-       const char **text,
-       char *textbuf, size_t textlen,
        int manage_ctxcsn );
 
 /*
@@ -1210,6 +1213,7 @@ LDAP_SLAPD_F (int) parse_oidm LDAP_P((
 LDAP_SLAPD_F (void) slap_op_init LDAP_P(( void ));
 LDAP_SLAPD_F (void) slap_op_destroy LDAP_P(( void ));
 LDAP_SLAPD_F (void) slap_op_free LDAP_P(( Operation *op ));
+LDAP_SLAPD_F (void) slap_op_time LDAP_P(( time_t *t, int *n ));
 LDAP_SLAPD_F (Operation *) slap_op_alloc LDAP_P((
        BerElement *ber, ber_int_t msgid,
        ber_tag_t tag, ber_int_t id ));
index 66c591a956c5496648599ac266b835508f5a078a..394c0a087130104e7061f95d9e95aee1f71a6356 100644 (file)
@@ -374,7 +374,7 @@ slap_auxprop_lookup(
                                op.o_tag = LDAP_REQ_SEARCH;
                                op.o_ndn = conn->c_ndn;
                                op.o_callback = &cb;
-                               op.o_time = slap_get_time();
+                               slap_op_time( &op.o_time, &op.o_tincr );
                                op.o_do_not_cache = 1;
                                op.o_is_auth_check = 1;
                                op.o_req_dn = op.o_req_ndn;
@@ -472,22 +472,17 @@ slap_auxprop_store(
                        &text, textbuf, textlen );
 
                if ( rc == LDAP_SUCCESS ) {
-                       rc = slap_mods_opattrs( &op, modlist, modtail,
-                                       &text, textbuf, textlen, 1 );
-
-                       if ( rc == LDAP_SUCCESS ) {
-                               op.o_hdr = conn->c_sasl_bindop->o_hdr;
-                               op.o_tag = LDAP_REQ_MODIFY;
-                               op.o_ndn = op.o_req_ndn;
-                               op.o_callback = &cb;
-                               op.o_time = slap_get_time();
-                               op.o_do_not_cache = 1;
-                               op.o_is_auth_check = 1;
-                               op.o_req_dn = op.o_req_ndn;
-                               op.orm_modlist = modlist;
-
-                               rc = op.o_bd->be_modify( &op, &rs );
-                       }
+                       op.o_hdr = conn->c_sasl_bindop->o_hdr;
+                       op.o_tag = LDAP_REQ_MODIFY;
+                       op.o_ndn = op.o_req_ndn;
+                       op.o_callback = &cb;
+                       slap_op_time( &op.o_time, &op.o_tincr );
+                       op.o_do_not_cache = 1;
+                       op.o_is_auth_check = 1;
+                       op.o_req_dn = op.o_req_ndn;
+                       op.orm_modlist = modlist;
+
+                       rc = op.o_bd->be_modify( &op, &rs );
                }
        }
        slap_mods_free( modlist, 1 );
index d2d2facdad463f010490fff1a4da1d61ddec357a..a7ef89783d27b3b3c6503ed3050476fe324e3519 100644 (file)
@@ -1831,7 +1831,7 @@ exact_match:
        op.o_tag = LDAP_REQ_SEARCH;
        op.o_ndn = *authc;
        op.o_callback = &cb;
-       op.o_time = slap_get_time();
+       slap_op_time( &op.o_time, &op.o_tincr );
        op.o_do_not_cache = 1;
        op.o_is_auth_check = 1;
        /* use req_ndn as req_dn instead of non-pretty base of uri */
@@ -1999,7 +1999,7 @@ slap_sasl2dn(
        op.o_tag = LDAP_REQ_SEARCH;
        op.o_ndn = opx->o_conn->c_ndn;
        op.o_callback = &cb;
-       op.o_time = slap_get_time();
+       slap_op_time( &op.o_time, &op.o_tincr );
        op.o_do_not_cache = 1;
        op.o_is_auth_check = 1;
        op.ors_deref = LDAP_DEREF_NEVER;
index a0c66a555c819c710a70ced63d4dccd1f4b47a9f..30dbdc35828e2e73fe5b2e1eaf86ec0135a24aff 100644 (file)
@@ -2553,6 +2553,7 @@ typedef struct slap_op {
        BerElement      *o_res_ber;     /* ber of the CLDAP reply or readback control */
        slap_callback *o_callback;      /* callback pointers */
        LDAPControl     **o_ctrls;       /* controls */
+       struct berval o_csn;
 
        void    *o_private;     /* anything the backend needs */
 
index 3820f57af23866593c0a9f62f3f6501400386a6b..376fd48abb9820be32a9b6135b7488588f2253a1 100644 (file)
@@ -409,7 +409,6 @@ slapi_delete_internal_pb( Slapi_PBlock *pb )
        PBLOCK_ASSERT_INTOP( pb, LDAP_REQ_DELETE );
 
        slapi_int_func_internal_pb( pb, op_delete );
-       slap_graduate_commit_csn( pb->pb_op );
 
        return 0;
 }
@@ -492,7 +491,6 @@ slapi_add_internal_pb( Slapi_PBlock *pb )
        }
 
 cleanup:
-       slap_graduate_commit_csn( pb->pb_op );
 
        if ( pb->pb_op->ora_e != NULL ) {
                slapi_entry_free( pb->pb_op->ora_e );
@@ -524,7 +522,6 @@ slapi_modrdn_internal_pb( Slapi_PBlock *pb )
        slapi_int_func_internal_pb( pb, op_modrdn );
 
 cleanup:
-       slap_graduate_commit_csn( pb->pb_op );
 
        return 0;
 }
@@ -561,7 +558,6 @@ slapi_modify_internal_pb( Slapi_PBlock *pb )
        slapi_int_func_internal_pb( pb, op_modify );
 
 cleanup:
-       slap_graduate_commit_csn( pb->pb_op );
 
        return 0;
 }
index deeacc5f4958fa5948145ea9c85103fceff92bca..250e06910d540d2aa82728fa7bc26875723eb763 100644 (file)
@@ -1633,6 +1633,11 @@ syncrepl_entry(
        switch ( syncstate ) {
        case LDAP_SYNC_ADD:
        case LDAP_SYNC_MODIFY:
+               {
+                       Attribute *a = attr_find( entry->e_attrs, slap_schema.si_ad_entryCSN );
+                       if ( a )
+                               op->o_csn = a->a_vals[0];
+               }
 retry_add:;
                if ( BER_BVISNULL( &dni.dn )) {
 
@@ -1852,6 +1857,7 @@ done :
        if ( !BER_BVISNULL( &dni.dn ) ) {
                op->o_tmpfree( dni.dn.bv_val, op->o_tmpmemctx );
        }
+       BER_BVZERO( &op->o_csn );
        return ret;
 }