From c36f32a9e4d792e3599bd33bad2fc72fde17040a Mon Sep 17 00:00:00 2001 From: Jong Hyuk Choi Date: Sat, 30 Aug 2003 15:19:35 +0000 Subject: [PATCH] slaptool update for LDAP Sync replication --- servers/slapd/back-bdb/external.h | 8 +- servers/slapd/back-bdb/init.c | 3 + servers/slapd/back-bdb/proto-bdb.h | 8 +- servers/slapd/back-bdb/tools.c | 187 ++++++++++++++++++++++++++++- servers/slapd/back-ldbm/init.c | 4 + servers/slapd/back-monitor/init.c | 3 + servers/slapd/backglue.c | 4 + servers/slapd/proto-slap.h | 8 ++ servers/slapd/schema_prep.c | 4 +- servers/slapd/slap.h | 30 +++-- servers/slapd/tools/Makefile.in | 2 +- servers/slapd/tools/mimic.c | 57 --------- servers/slapd/tools/slapadd.c | 56 ++++++++- servers/slapd/tools/slapcat.c | 14 +++ servers/slapd/tools/slapcommon.c | 28 ++++- servers/slapd/tools/slapcommon.h | 6 + 16 files changed, 336 insertions(+), 86 deletions(-) diff --git a/servers/slapd/back-bdb/external.h b/servers/slapd/back-bdb/external.h index 92fda884d8..e95b86dd8f 100644 --- a/servers/slapd/back-bdb/external.h +++ b/servers/slapd/back-bdb/external.h @@ -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 diff --git a/servers/slapd/back-bdb/init.c b/servers/slapd/back-bdb/init.c index 7d57e497d0..740e33888e 100644 --- a/servers/slapd/back-bdb/init.c +++ b/servers/slapd/back-bdb/init.c @@ -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; diff --git a/servers/slapd/back-bdb/proto-bdb.h b/servers/slapd/back-bdb/proto-bdb.h index 18a5e304d7..8336beb4a9 100644 --- a/servers/slapd/back-bdb/proto-bdb.h +++ b/servers/slapd/back-bdb/proto-bdb.h @@ -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 diff --git a/servers/slapd/back-bdb/tools.c b/servers/slapd/back-bdb/tools.c index 69aeea22ae..06e2454d1e 100644 --- a/servers/slapd/back-bdb/tools.c +++ b/servers/slapd/back-bdb/tools.c @@ -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; +} diff --git a/servers/slapd/back-ldbm/init.c b/servers/slapd/back-ldbm/init.c index 3797b2b60c..cab46804e1 100644 --- a/servers/slapd/back-ldbm/init.c +++ b/servers/slapd/back-ldbm/init.c @@ -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; diff --git a/servers/slapd/back-monitor/init.c b/servers/slapd/back-monitor/init.c index d2b01efb7b..5e53226d55 100644 --- a/servers/slapd/back-monitor/init.c +++ b/servers/slapd/back-monitor/init.c @@ -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; diff --git a/servers/slapd/backglue.c b/servers/slapd/backglue.c index a22be0a1c5..d99eaa10de 100644 --- a/servers/slapd/backglue.c +++ b/servers/slapd/backglue.c @@ -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) + diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 1acac49d95..9af2191271 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -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 ); diff --git a/servers/slapd/schema_prep.c b/servers/slapd/schema_prep.c index 0af3f42a57..cf4c06fefe 100644 --- a/servers/slapd/schema_prep.c +++ b/servers/slapd/schema_prep.c @@ -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 } diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 6c9e110b5f..2e86932c6f 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -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 diff --git a/servers/slapd/tools/Makefile.in b/servers/slapd/tools/Makefile.in index dbddeb02c0..f0cac09139 100644 --- a/servers/slapd/tools/Makefile.in +++ b/servers/slapd/tools/Makefile.in @@ -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 diff --git a/servers/slapd/tools/mimic.c b/servers/slapd/tools/mimic.c index 483550ab6e..15833f8233 100644 --- a/servers/slapd/tools/mimic.c +++ b/servers/slapd/tools/mimic.c @@ -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 diff --git a/servers/slapd/tools/slapadd.c b/servers/slapd/tools/slapadd.c index 50559180d7..87059a57b5 100644 --- a/servers/slapd/tools/slapadd.c +++ b/servers/slapd/tools/slapadd.c @@ -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; diff --git a/servers/slapd/tools/slapcat.c b/servers/slapd/tools/slapcat.c index 02130fdaf7..7aa5d0ed44 100644 --- a/servers/slapd/tools/slapcat.c +++ b/servers/slapd/tools/slapcat.c @@ -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 ); } diff --git a/servers/slapd/tools/slapcommon.c b/servers/slapd/tools/slapcommon.c index 7e8514f277..c0a2d47a9d 100644 --- a/servers/slapd/tools/slapcommon.c +++ b/servers/slapd/tools/slapcommon.c @@ -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; diff --git a/servers/slapd/tools/slapcommon.h b/servers/slapd/tools/slapcommon.h index 3a1120ba98..925b9976b1 100644 --- a/servers/slapd/tools/slapcommon.h +++ b/servers/slapd/tools/slapcommon.h @@ -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; -- 2.39.5