#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;
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
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;
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
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;
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;
}
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 ) {
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;
+}
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;
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;
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) +
(((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 );
"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 }
#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
#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
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 */
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
../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
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 )
{
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;
{
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
#include "slapcommon.h"
+static char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
+
int
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
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;
if( continuemode ) continue;
break;
}
-
+
if ( verbose ) {
fprintf( stderr, "added: \"%s\" (%08lx)\n",
e->e_dn, (long) id );
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;
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 );
}
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;
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:
switch( tool ) {
case SLAPADD:
- options = "b:cd:f:l:n:tuv";
+ options = "b:cd:f:l:n:tuvWw";
break;
case SLAPINDEX:
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;
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;
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;
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;