]> git.sur5r.net Git - openldap/commitdiff
slaptool update for LDAP Sync replication
authorJong Hyuk Choi <jongchoi@openldap.org>
Sat, 30 Aug 2003 15:19:35 +0000 (15:19 +0000)
committerJong Hyuk Choi <jongchoi@openldap.org>
Sat, 30 Aug 2003 15:19:35 +0000 (15:19 +0000)
16 files changed:
servers/slapd/back-bdb/external.h
servers/slapd/back-bdb/init.c
servers/slapd/back-bdb/proto-bdb.h
servers/slapd/back-bdb/tools.c
servers/slapd/back-ldbm/init.c
servers/slapd/back-monitor/init.c
servers/slapd/backglue.c
servers/slapd/proto-slap.h
servers/slapd/schema_prep.c
servers/slapd/slap.h
servers/slapd/tools/Makefile.in
servers/slapd/tools/mimic.c
servers/slapd/tools/slapadd.c
servers/slapd/tools/slapcat.c
servers/slapd/tools/slapcommon.c
servers/slapd/tools/slapcommon.h

index 92fda884d8eae41733694f73c8eaccfa442b8cd8..e95b86dd8fae57f39e9dda2e40a20cf14c8d7c80 100644 (file)
@@ -36,6 +36,9 @@ LDAP_BEGIN_DECL
 #define bdb_tool_entry_get                     BDB_SYMBOL(tool_entry_get)
 #define bdb_tool_entry_put                     BDB_SYMBOL(tool_entry_put)
 #define bdb_tool_entry_reindex         BDB_SYMBOL(tool_entry_reindex)
+#define bdb_tool_dn2id_get                     BDB_SYMBOL(tool_dn2id_get)
+#define bdb_tool_id2entry_get          BDB_SYMBOL(tool_id2entry_get)
+#define bdb_tool_entry_modify          BDB_SYMBOL(tool_entry_modify)
 
 extern BI_init bdb_initialize;
 
@@ -70,8 +73,9 @@ extern BI_tool_entry_next     bdb_tool_entry_next;
 extern BI_tool_entry_get       bdb_tool_entry_get;
 extern BI_tool_entry_put       bdb_tool_entry_put;
 extern BI_tool_entry_reindex   bdb_tool_entry_reindex;
-
-
+extern BI_tool_dn2id_get       bdb_tool_dn2id_get;
+extern BI_tool_id2entry_get    bdb_tool_id2entry_get;
+extern BI_tool_entry_modify    bdb_tool_entry_modify;
 
 LDAP_END_DECL
 
index 7d57e497d09367cf1fd304495aff35bc09e3c77e..740e33888ec0a23d3ce6e90824c8e8cda11d7952 100644 (file)
@@ -694,6 +694,9 @@ bdb_initialize(
        bi->bi_tool_entry_put = bdb_tool_entry_put;
        bi->bi_tool_entry_reindex = bdb_tool_entry_reindex;
        bi->bi_tool_sync = 0;
+       bi->bi_tool_dn2id_get = bdb_tool_dn2id_get;
+       bi->bi_tool_id2entry_get = bdb_tool_id2entry_get;
+       bi->bi_tool_entry_modify = bdb_tool_entry_modify;
 
        bi->bi_connection_init = 0;
        bi->bi_connection_destroy = 0;
index 18a5e304d79ec68b0a613c07cdc18a0a312d87b7..8336beb4a9e5d27c7f648296af0858c91c359b48 100644 (file)
@@ -309,10 +309,10 @@ bdb_index_values LDAP_P((
 
 int bdb_index_entry LDAP_P(( Operation *op, DB_TXN *t, int r, Entry *e ));
 
-#define bdb_index_entry_add(be,t,e) \
-       bdb_index_entry((be),(t),SLAP_INDEX_ADD_OP,(e))
-#define bdb_index_entry_del(be,t,e) \
-       bdb_index_entry((be),(t),SLAP_INDEX_DELETE_OP,(e))
+#define bdb_index_entry_add(op,t,e) \
+       bdb_index_entry((op),(t),SLAP_INDEX_ADD_OP,(e))
+#define bdb_index_entry_del(op,t,e) \
+       bdb_index_entry((op),(t),SLAP_INDEX_DELETE_OP,(e))
 
 /*
  * init.c
index 69aeea22aea59b9ae632faf1da58688638f50679..06e2454d1ed2103b7059a1f8d85fb28accc806ad 100644 (file)
@@ -104,6 +104,54 @@ ID bdb_tool_entry_next(
        return id;
 }
 
+ID bdb_tool_dn2id_get(
+       Backend *be,
+       struct berval *dn
+)
+{
+       struct bdb_info *bdb = (struct bdb_nifo *) be->be_private;
+       DB *db = bdb->bi_dn2id->bdi_db;
+       int rc;
+       DBT     key, data;
+       ID      id;
+
+       DBTzero( &key );
+       key.size = dn->bv_len + 2;
+       key.data = ch_malloc( key.size );
+       ((char*)key.data)[0] = DN_BASE_PREFIX;
+       AC_MEMCPY( &((char*)key.data)[1], dn->bv_val, key.size - 1 );
+
+       DBTzero( &data );
+       data.data = &id;
+       data.ulen = sizeof(ID);
+       data.flags = DB_DBT_USERMEM;
+
+       rc = db->get( db, NULL, &key, &data, bdb->bi_db_opflags );
+
+    if( rc != 0 ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG ( INDEX, ERR, "bdb_tool_dn2id_get: get failed %s (%d)\n",
+                               db_strerror(rc), rc, 0 );
+#else
+               Debug( LDAP_DEBUG_TRACE, "bdb_tool_dn2id_get: get failed: %s (%d)\n",
+                               db_strerror( rc ), rc, 0 );
+#endif
+               id = NOID;
+       }
+
+       ch_free( key.data );
+       return id;
+}
+
+int bdb_tool_id2entry_get(
+       Backend *be,
+       ID id,
+       Entry **e
+)
+{
+       return bdb_id2entry( be, NULL, id, e );
+}
+
 Entry* bdb_tool_entry_get( BackendDB *be, ID id )
 {
        int rc;
@@ -173,10 +221,10 @@ static int bdb_tool_next_id(
                                db_strerror(rc), rc );
 #ifdef NEW_LOGGING
                LDAP_LOG ( TOOLS, ERR, 
-                       "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
+                       "=> bdb_tool_next_id: %s\n", text->bv_val, 0, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
-                       "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
+                       "=> bdb_tool_next_id: %s\n", text->bv_val, 0, 0 );
 #endif
                        return rc;
                }
@@ -188,10 +236,10 @@ static int bdb_tool_next_id(
                                db_strerror(rc), rc );
 #ifdef NEW_LOGGING
                LDAP_LOG ( TOOLS, ERR, 
-                       "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
+                       "=> bdb_tool_next_id: %s\n", text->bv_val, 0, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
-                       "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
+                       "=> bdb_tool_next_id: %s\n", text->bv_val, 0, 0 );
 #endif
                } else if ( hole ) {
                        if ( nholes == nhmax - 1 ) {
@@ -464,3 +512,134 @@ done:
 
        return rc;
 }
+
+ID bdb_tool_entry_modify(
+       BackendDB *be,
+       Entry *e,
+       struct berval *text )
+{
+       int rc;
+       struct bdb_info *bdb = (struct bdb_info *) be->be_private;
+       DB_TXN *tid = NULL;
+       Operation op = {0};
+
+       assert( be != NULL );
+       assert( slapMode & SLAP_TOOL_MODE );
+
+       assert( text );
+       assert( text->bv_val );
+       assert( text->bv_val[0] == '\0' );      /* overconservative? */
+
+       assert ( e->e_id != NOID );
+       assert ( e->e_id != 0 );
+
+#ifdef NEW_LOGGING
+       LDAP_LOG ( TOOLS, ARGS, "=> bdb_tool_entry_put( %ld, \"%s\" )\n",
+               (long) e->e_id, e->e_dn, 0 );
+#else
+       Debug( LDAP_DEBUG_TRACE, "=> bdb_tool_entry_put( %ld, \"%s\" )\n",
+               (long) e->e_id, e->e_dn, 0 );
+#endif
+
+       rc = TXN_BEGIN( bdb->bi_dbenv, NULL, &tid, 
+               bdb->bi_db_opflags );
+       if( rc != 0 ) {
+               snprintf( text->bv_val, text->bv_len,
+                       "txn_begin failed: %s (%d)",
+                       db_strerror(rc), rc );
+#ifdef NEW_LOGGING
+       LDAP_LOG ( TOOLS, ERR, "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_ANY,
+                       "=> bdb_tool_entry_put: %s\n",
+                        text->bv_val, 0, 0 );
+#endif
+               return NOID;
+       }
+
+       op.o_bd = be;
+       op.o_tmpmemctx = NULL;
+       op.o_tmpmfuncs = &ch_mfuncs;
+
+       /* id2entry index */
+       rc = bdb_id2entry_update( be, tid, e );
+       if( rc != 0 ) {
+               snprintf( text->bv_val, text->bv_len,
+                               "id2entry_add failed: %s (%d)",
+                               db_strerror(rc), rc );
+#ifdef NEW_LOGGING
+               LDAP_LOG ( TOOLS, ERR, 
+                       "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_ANY,
+                       "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
+#endif
+               goto done;
+       }
+
+       rc = bdb_index_entry_del( &op, tid, e );
+       if( rc != 0 ) {
+               snprintf( text->bv_val, text->bv_len,
+                               "index_entry_del failed: %s (%d)",
+                               db_strerror(rc), rc );
+#ifdef NEW_LOGGING
+               LDAP_LOG ( TOOLS, ERR, 
+                       "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_ANY,
+                       "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
+#endif
+               goto done;
+       }
+
+       rc = bdb_index_entry_add( &op, tid, e );
+       if( rc != 0 ) {
+               snprintf( text->bv_val, text->bv_len,
+                               "index_entry_add failed: %s (%d)",
+                               db_strerror(rc), rc );
+#ifdef NEW_LOGGING
+               LDAP_LOG ( TOOLS, ERR, 
+                       "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_ANY,
+                       "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
+#endif
+               goto done;
+       }
+
+done:
+       if( rc == 0 ) {
+               rc = TXN_COMMIT( tid, 0 );
+               if( rc != 0 ) {
+                       snprintf( text->bv_val, text->bv_len,
+                                       "txn_commit failed: %s (%d)",
+                                       db_strerror(rc), rc );
+#ifdef NEW_LOGGING
+                       LDAP_LOG ( TOOLS, ERR, 
+                               "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
+#else
+                       Debug( LDAP_DEBUG_ANY,
+                               "=> bdb_tool_entry_put: %s\n",
+                               text->bv_val, 0, 0 );
+#endif
+                       e->e_id = NOID;
+               }
+
+       } else {
+               TXN_ABORT( tid );
+               snprintf( text->bv_val, text->bv_len,
+                       "txn_aborted! %s (%d)",
+                       db_strerror(rc), rc );
+#ifdef NEW_LOGGING
+               LDAP_LOG ( TOOLS, ERR, 
+                       "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_ANY,
+                       "=> bdb_tool_entry_put: %s\n",
+                       text->bv_val, 0, 0 );
+#endif
+               e->e_id = NOID;
+       }
+
+       return e->e_id;
+}
index 3797b2b60cb9a7f341b2e1c4164cc752e335b966..cab46804e1c8a255ebf76fc5db4f2e8b9e97c483 100644 (file)
@@ -84,6 +84,10 @@ ldbm_back_initialize(
        bi->bi_tool_entry_reindex = ldbm_tool_entry_reindex;
        bi->bi_tool_sync = ldbm_tool_sync;
 
+       bi->bi_tool_dn2id_get = 0;
+       bi->bi_tool_id2entry_get = 0;
+       bi->bi_tool_entry_modify = 0;
+
        bi->bi_connection_init = 0;
        bi->bi_connection_destroy = 0;
 
index d2b01efb7ba48ee38ccea47a199599644b86c416..5e53226d55a9f5ae6b0713c8186c94fc4198128f 100644 (file)
@@ -219,6 +219,9 @@ monitor_back_initialize(
        bi->bi_tool_entry_put = 0;
        bi->bi_tool_entry_reindex = 0;
        bi->bi_tool_sync = 0;
+       bi->bi_tool_dn2id_get = 0;
+       bi->bi_tool_id2entry_get = 0;
+       bi->bi_tool_entry_modify = 0;
 
        bi->bi_connection_init = 0;
        bi->bi_connection_destroy = 0;
index a22be0a1c51bc93f3e275cf0e803348e89b28698..d99eaa10de99f10f55d66f0098952193a0bf3fca 100644 (file)
@@ -587,6 +587,10 @@ glue_sub_init( )
                                bi->bi_tool_entry_put = glue_tool_entry_put;
                                bi->bi_tool_entry_reindex = glue_tool_entry_reindex;
                                bi->bi_tool_sync = glue_tool_sync;
+                               /* FIXME : will support later */
+                               bi->bi_tool_dn2id_get = 0;
+                               bi->bi_tool_id2entry_get = 0;
+                               bi->bi_tool_entry_modify = 0;
                        } else {
                                gi = (glueinfo *)ch_realloc(gi,
                                        sizeof(glueinfo) +
index 1acac49d95d57a8e4d080b6927cc22b8b29f45ec..9af2191271126f98adf90d01ff7a9f17887bf106 100644 (file)
@@ -736,6 +736,14 @@ LDAP_SLAPD_F (int) is_entry_objectclass LDAP_P((
        (((e)->e_ocflags & SLAP_OC__END) \
         ? (((e)->e_ocflags & SLAP_OC_GLUE) != 0) \
         : is_entry_objectclass((e), slap_schema.si_oc_glue, 1))
+#define is_entry_syncProviderSubentry(e)       \
+       (((e)->e_ocflags & SLAP_OC__END) \
+        ? (((e)->e_ocflags & SLAP_OC_SYNCPROVIDERSUBENTRY) != 0) \
+        : is_entry_objectclass((e), slap_schema.si_oc_syncProviderSubentry, 1))
+#define is_entry_syncConsumerSubentry(e)       \
+       (((e)->e_ocflags & SLAP_OC__END) \
+        ? (((e)->e_ocflags & SLAP_OC_SYNCCONSUMERSUBENTRY) != 0) \
+        : is_entry_objectclass((e), slap_schema.si_oc_syncConsumerSubentry, 1))
 
 LDAP_SLAPD_F (int) oc_schema_info( Entry *e );
 
index 0af3f42a57c0567b12e7bc68d34a1ad783bfa71c..cf4c06fefe9c784b7a429c62f8fb6ac62ef45cd0 100644 (file)
@@ -235,14 +235,14 @@ static struct slap_schema_oc_map {
                        "DESC 'Persistent Info for SyncRepl Consumer' "
                        "AUXILIARY "
                        "MAY syncreplCookie )",
-               0, SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
+               0, SLAP_OC_SYNCCONSUMERSUBENTRY|SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
                offsetof(struct slap_internal_schema, si_oc_syncConsumerSubentry) },
        { "syncProviderSubentry", "( 1.3.6.1.4.1.4203.666.3.6 "
                        "NAME 'syncProviderSubentry' "
                        "DESC 'Persistent Info for SyncRepl Producer' "
                        "AUXILIARY "
                        "MAY contextCSN )",
-               0, SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
+               0, SLAP_OC_SYNCPROVIDERSUBENTRY|SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
                offsetof(struct slap_internal_schema, si_oc_syncProviderSubentry) },
 
        { NULL, NULL, NULL, 0, 0 }
index 6c9e110b5fa32f115b7d63c38b7b99a068dde42c..2e86932c6ffc5d7786caef222dcd2df2c0cdb415 100644 (file)
@@ -642,8 +642,10 @@ typedef struct slap_object_class {
 #define        SLAP_OC_DYNAMICOBJECT   0x0008
 #define        SLAP_OC_COLLECTIVEATTRIBUTESUBENTRY     0x0010
 #define SLAP_OC_GLUE           0x0020
-#define        SLAP_OC__MASK           0x003F
-#define        SLAP_OC__END            0x0040
+#define SLAP_OC_SYNCPROVIDERSUBENTRY           0x0040
+#define SLAP_OC_SYNCCONSUMERSUBENTRY           0x0080
+#define        SLAP_OC__MASK           0x00FF
+#define        SLAP_OC__END            0x0100
 #define SLAP_OC_OPERATIONAL    0x4000
 #ifdef LDAP_DEVEL
 #define SLAP_OC_HIDE           0x0000
@@ -1375,6 +1377,9 @@ struct slap_backend_db {
 #define                be_entry_get bd_info->bi_tool_entry_get
 #define                be_entry_put bd_info->bi_tool_entry_put
 #define                be_sync bd_info->bi_tool_sync
+#define                be_dn2id_get bd_info->bi_tool_dn2id_get
+#define                be_id2entry_get bd_info->bi_tool_id2entry_get
+#define                be_entry_modify bd_info->bi_tool_entry_modify
 #endif
 
 #define SLAP_BFLAG_NOLASTMOD           0x0001U
@@ -1630,6 +1635,10 @@ typedef ID (BI_tool_entry_put) LDAP_P(( BackendDB *be, Entry *e,
                        struct berval *text ));
 typedef int (BI_tool_entry_reindex) LDAP_P(( BackendDB *be, ID id ));
 typedef int (BI_tool_sync) LDAP_P(( BackendDB *be ));
+typedef ID (BI_tool_dn2id_get) LDAP_P(( BackendDB *be, struct berval *dn ));
+typedef int (BI_tool_id2entry_get) LDAP_P(( BackendDB *be, ID id, Entry **e ));
+typedef ID (BI_tool_entry_modify) LDAP_P(( BackendDB *be, Entry *e, 
+                       struct berval *text ));
 
 struct slap_backend_info {
        char    *bi_type; /* type of backend */
@@ -1714,14 +1723,17 @@ struct slap_backend_info {
        BI_connection_destroy   *bi_connection_destroy;
 
        /* hooks for slap tools */
-       BI_tool_entry_open      *bi_tool_entry_open;
-       BI_tool_entry_close     *bi_tool_entry_close;
-       BI_tool_entry_first     *bi_tool_entry_first;
-       BI_tool_entry_next      *bi_tool_entry_next;
-       BI_tool_entry_get       *bi_tool_entry_get;
-       BI_tool_entry_put       *bi_tool_entry_put;
+       BI_tool_entry_open              *bi_tool_entry_open;
+       BI_tool_entry_close             *bi_tool_entry_close;
+       BI_tool_entry_first             *bi_tool_entry_first;
+       BI_tool_entry_next              *bi_tool_entry_next;
+       BI_tool_entry_get               *bi_tool_entry_get;
+       BI_tool_entry_put               *bi_tool_entry_put;
        BI_tool_entry_reindex   *bi_tool_entry_reindex;
-       BI_tool_sync            *bi_tool_sync;
+       BI_tool_sync                    *bi_tool_sync;
+       BI_tool_dn2id_get               *bi_tool_dn2id_get;
+       BI_tool_id2entry_get    *bi_tool_id2entry_get;
+       BI_tool_entry_modify    *bi_tool_entry_modify;
 
 #define SLAP_INDEX_ADD_OP              0x0001
 #define SLAP_INDEX_DELETE_OP   0x0002
index dbddeb02c025d4a1ba3463578fdc0bcba5ca5ce2..f0cac091398f3db4f94c3cd750bb7ba621ebcbbd 100644 (file)
@@ -46,7 +46,7 @@ SLAPD_OBJS = ../globals.o ../config.o ../ch_malloc.o ../cr.o ../backend.o \
                ../init.o ../controls.o ../kerberos.o ../passwd.o \
                ../index.o ../extended.o ../starttls.o ../sets.o ../mra.o \
                ../referral.o ../backglue.o ../oidm.o ../mods.o ../operation.o \
-               ../cancel.o ../sl_malloc.o ../backover.o ../ctxcsn.o
+               ../cancel.o ../sl_malloc.o ../backover.o ../ctxcsn.o ../add.o ../modify.o
 
 SLAPOBJS = $(SLAPD_OBJS) slapcommon.o mimic.o
 
index 483550ab6eeb0a4d8874ddabe1c9273a2aa450cd..15833f823313e02c61894374d911bc4afdfdaec1 100644 (file)
@@ -208,28 +208,6 @@ slap_modrdn2mods(
        return 0;
 }
 
-int
-slap_mods2entry(
-       Modifications *mods,
-       Entry **e,
-       int repl_user,
-       int dup,
-       const char **text,
-       char *textbuf, size_t textlen )
-{
-       return 0;
-}
-
-int
-slap_entry2mods(
-       Entry *e,
-       Modifications **mods,
-       const char **text
-)
-{
-       return 0;
-}
-
 int slap_sasl_getdn( Connection *conn, Operation *op, char *id, int len,
        char *user_realm, struct berval *dn, int flags )
 {
@@ -242,19 +220,6 @@ int slap_sasl_authorized( Operation *op,
        return -1;
 }
 
-int slap_mods_check( Modifications *ml, int update, const char **text,
-       char *textbuf, size_t textlen, void *ctx )
-{
-       return -1;
-}
-
-int slap_mods_opattrs( Operation *op, Modifications *mods,
-       Modifications **modtail, const char **text,
-       char *textbuf, size_t textlen )
-{
-       return -1;
-}
-
 int root_dse_info( Connection *conn, Entry **entry, const char **text )
 {
        return -1;
@@ -283,25 +248,3 @@ void syncrepl_add_glue( syncinfo_t *si, LDAP *ld, Operation *op, Entry *e,
 {
        return;
 }
-
-#if 0
-struct berval *slap_get_commit_csn( Operation *op )
-{
-       return NULL;
-}
-
-void slap_rewind_commit_csn( Operation *op )
-{
-       return;
-}
-
-void slap_graduate_commit_csn( Operation *op )
-{
-       return;
-}
-
-Entry *slap_create_context_csn_entry( Backend *be, struct berval *context_csn )
-{
-       return NULL;
-}
-#endif
index 50559180d7c7e3fb5f3fa2423ddef4e43f908c6f..87059a57b558b1c796fabc6beeffac39fae5d4af 100644 (file)
@@ -20,6 +20,8 @@
 
 #include "slapcommon.h"
 
+static char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
+
 int
 main( int argc, char **argv )
 {
@@ -32,6 +34,7 @@ main( int argc, char **argv )
        char textbuf[SLAP_TEXT_BUFLEN] = { '\0' };
        size_t textlen = sizeof textbuf;
 
+       struct berval csn;
 #ifdef NEW_LOGGING
        lutil_log_initialize(argc, argv );
 #endif
@@ -161,12 +164,11 @@ main( int argc, char **argv )
                        char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
                        struct berval vals[ 2 ];
 
-                       struct berval name, timestamp, csn;
+                       struct berval name, timestamp;
 
                        struct berval nvals[ 2 ];
                        struct berval nname;
                        char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
-                       char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
 
                        vals[1].bv_len = 0;
                        vals[1].bv_val = NULL;
@@ -249,7 +251,7 @@ main( int argc, char **argv )
                                if( continuemode ) continue;
                                break;
                        }
-               
+
                        if ( verbose ) {
                                fprintf( stderr, "added: \"%s\" (%08lx)\n",
                                        e->e_dn, (long) id );
@@ -263,6 +265,54 @@ main( int argc, char **argv )
                entry_free( e );
        }
 
+       if ( SLAP_LASTMOD(be) && update_ctxcsn == SLAP_TOOL_CTXCSN_BATCH && csn.bv_len > 0 ) {
+               Entry *ctxcsn_e;
+               ID      ctxcsn_id;
+               struct berval   ctxcsn_rdn = { 0, NULL };
+               struct berval   ctxcsn_ndn = { 0, NULL };
+               int ret;
+               struct berval bvtext;
+               Attribute *attr;
+
+               bvtext.bv_len = textlen;
+               bvtext.bv_val = textbuf;
+               bvtext.bv_val[0] = '\0';
+
+               ber_str2bv( "cn=ldapsync", strlen( "cn=ldapsync" ), 0, &ctxcsn_rdn );
+               build_new_dn( &ctxcsn_ndn, &be->be_nsuffix[0], &ctxcsn_rdn );
+               ctxcsn_id = be->be_dn2id_get( be, &ctxcsn_ndn );
+               
+               if ( ctxcsn_id == NOID ) {
+                       ctxcsn_e = slap_create_context_csn_entry( be, &csn );
+                       ctxcsn_id = be->be_entry_put( be, ctxcsn_e, &bvtext );
+                       if( ctxcsn_id == NOID ) {
+                               fprintf( stderr, "%s: could not add ctxcsn subentry\n", progname);
+                               rc = EXIT_FAILURE;
+                       }
+                       if ( verbose ) {
+                               fprintf( stderr, "added: \"%s\" (%08lx)\n", ctxcsn_e->e_dn, (long) ctxcsn_id );
+                       }
+                       entry_free( ctxcsn_e );
+               } else {
+                       ret = be->be_id2entry_get( be, ctxcsn_id, &ctxcsn_e );
+                       if ( ret == LDAP_SUCCESS ) {
+                               attr = attr_find( ctxcsn_e->e_attrs, slap_schema.si_ad_contextCSN );
+                               attr->a_vals[0] = csn;
+                               ctxcsn_id = be->be_entry_modify( be, ctxcsn_e, &bvtext );
+                               if( ctxcsn_id == NOID ) {
+                                       fprintf( stderr, "%s: could not modify ctxcsn subentry\n", progname);
+                                       rc = EXIT_FAILURE;
+                               }
+                               if ( verbose ) {
+                                       fprintf( stderr, "modified: \"%s\" (%08lx)\n", ctxcsn_e->e_dn, (long) ctxcsn_id );
+                               }
+                       } else {
+                               fprintf( stderr, "%s: could not modify ctxcsn subentry\n", progname);
+                               rc = EXIT_FAILURE;
+                       }
+               }
+       }
+
        ch_free( buf );
 
        if( be->be_entry_close( be )) rc = EXIT_FAILURE;
index 02130fdaf79aab6e4d298d4bd3c67eaaffe2a8f7..7aa5d0ed445003f9296b62f421a878798399341f 100644 (file)
@@ -54,6 +54,20 @@ main( int argc, char **argv )
                        continue;
                }
 
+               if ( retrieve_ctxcsn == 0 ) {
+                       if ( is_entry_syncProviderSubentry( e ) ) {
+                               be_entry_release_r( &op, e );
+                               continue;
+                       }
+               }
+
+               if ( retrieve_synccookie == 0 ) {
+                       if ( is_entry_syncConsumerSubentry( e ) ) {
+                               be_entry_release_r( &op, e );
+                               continue;
+                       }
+               }
+
                if( verbose ) {
                        printf( "# id=%08lx\n", (long) id );
                }
index 7e8514f277f57b71cd4813b0aaa393496f6d76fb..c0a2d47a9d3c54db41731aafca4f01855c55c62e 100644 (file)
@@ -23,6 +23,9 @@ char  *progname       = NULL;
 char   *conffile       = SLAPD_DEFAULT_CONFIGFILE;
 int            truncatemode = 0;
 int            verbose         = 0;
+int            update_ctxcsn = SLAP_TOOL_CTXCSN_NONE;
+int            retrieve_ctxcsn = 0;
+int            retrieve_synccookie = 0;
 int            continuemode = 0;
 int            nosubordinates = 0;
 int            dryrun = 0;
@@ -48,11 +51,11 @@ usage( int tool )
 
        switch( tool ) {
        case SLAPADD:
-               options = "\t[-l ldiffile] [-u]\n";
+               options = "\t[-l ldiffile] [-u] [-W] [-w]\n";
                break;
 
        case SLAPCAT:
-               options = "\t[-l ldiffile]\n";
+               options = "\t[-l ldiffile] [-m] [-k]\n";
                break;
 
        case SLAPINDEX:
@@ -100,7 +103,7 @@ slap_tool_init(
 
        switch( tool ) {
        case SLAPADD:
-               options = "b:cd:f:l:n:tuv";
+               options = "b:cd:f:l:n:tuvWw";
                break;
 
        case SLAPINDEX:
@@ -109,7 +112,7 @@ slap_tool_init(
                break;
 
        case SLAPCAT:
-               options = "b:cd:f:l:n:s:v";
+               options = "b:cd:f:kl:mn:s:v";
                mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
                break;
 
@@ -141,10 +144,18 @@ slap_tool_init(
                        conffile = strdup( optarg );
                        break;
 
+               case 'k':       /* Retrieve sync cookie entry */
+                       retrieve_synccookie = 1;
+                       break;
+
                case 'l':       /* LDIF file */
                        ldiffile = strdup( optarg );
                        break;
 
+               case 'm':       /* Retrieve ldapsync entry */
+                       retrieve_ctxcsn = 1;
+                       break;
+
                case 'n':       /* which config file db to index */
                        dbnum = atoi( optarg ) - 1;
                        break;
@@ -166,6 +177,15 @@ slap_tool_init(
                        verbose++;
                        break;
 
+               case 'W':       /* write context csn on every entry add */
+                       update_ctxcsn = SLAP_TOOL_CTXCSN_BATCH;
+                       /* FIXME : update_ctxcsn = SLAP_TOOL_CTXCSN_ENTRY; */
+                       break;
+
+               case 'w':       /* write context csn on at the end */
+                       update_ctxcsn = SLAP_TOOL_CTXCSN_BATCH;
+                       break;
+
                default:
                        usage( tool );
                        break;
index 3a1120ba98caac7a7a0669ab1c2e0be8770430b1..925b9976b185f406d91129d9837b4a02153aec70 100644 (file)
@@ -18,12 +18,18 @@ enum slaptool {
        SLAPTEST        /* database testing tool */
 };
 
+#define SLAP_TOOL_CTXCSN_NONE  0
+#define SLAP_TOOL_CTXCSN_ENTRY 1
+#define SLAP_TOOL_CTXCSN_BATCH 2
 
 extern char    *progname;
 extern char    *conffile;
 extern Backend *be;
 extern int             appendmode;
 extern int             verbose;
+extern int             update_ctxcsn;
+extern int             retrieve_ctxcsn;
+extern int             retrieve_synccookie;
 extern int             continuemode;
 extern int             nosubordinates;
 extern int             dryrun;