Commit 090ac0a7 authored by Jong Hyuk Choi's avatar Jong Hyuk Choi
Browse files

unifdef LDAP_SYNC and LDAP_SYNCREPL

parent 4559aa06
......@@ -75,10 +75,8 @@ usage( void )
#ifdef LDAP_CONTROL_SUBENTRIES
fprintf( stderr, _(" [!]subentries[=true|false] (subentries)\n"));
#endif
#ifdef LDAP_SYNC
fprintf( stderr, _(" [!]sync=ro[/<cookie>] (LDAP Sync refreshOnly)\n"));
fprintf( stderr, _(" rp[/<cookie>][/<slimit>] (LDAP Sync refreshAndPersist)\n"));
#endif
fprintf( stderr, _(" -F prefix URL prefix for files (default: %s)\n"), def_urlpre);
fprintf( stderr, _(" -l limit time limit (in seconds) for search\n"));
fprintf( stderr, _(" -L print responses in LDIFv1 format\n"));
......@@ -153,11 +151,9 @@ static char *vrFilter = NULL;
static int domainScope = 0;
#endif
#ifdef LDAP_SYNC
static int ldapsync = 0;
static struct berval sync_cookie = { 0, NULL };
static int sync_slimit = -1;
#endif
#ifdef LDAP_CONTROL_PAGEDRESULTS
static int pagedResults = 0;
......@@ -313,7 +309,6 @@ handle_private_option( int i )
if( crit ) subentries *= -1;
#endif
#ifdef LDAP_SYNC
} else if ( strcasecmp( control, "sync" ) == 0 ) {
char *cookiep;
char *slimitp;
......@@ -357,7 +352,6 @@ handle_private_option( int i )
exit( EXIT_FAILURE );
}
if ( crit ) ldapsync *= -1;
#endif
} else {
fprintf( stderr, _("Invalid control name: %s\n"), control );
......@@ -447,10 +441,8 @@ main( int argc, char **argv )
LDAP *ld = NULL;
BerElement *seber = NULL, *vrber = NULL, *prber = NULL;
#ifdef LDAP_SYNC
BerElement *syncber = NULL;
struct berval *syncbvalp = NULL;
#endif
tool_init();
......@@ -555,9 +547,7 @@ getNextPage:
#ifdef LDAP_CONTROL_PAGEDRESULTS
|| pageSize
#endif
#ifdef LDAP_SYNC
|| ldapsync
#endif
|| subentries || valuesReturnFilter )
{
int err;
......@@ -597,7 +587,6 @@ getNextPage:
}
#endif
#ifdef LDAP_SYNC
if ( ldapsync ) {
if (( syncber = ber_alloc_t(LBER_USE_DER)) == NULL ) {
return EXIT_FAILURE;
......@@ -625,7 +614,6 @@ getNextPage:
c[i].ldctl_iscritical = ldapsync < 0;
i++;
}
#endif
if ( valuesReturnFilter ) {
if (( vrber = ber_alloc_t(LBER_USE_DER)) == NULL ) {
......@@ -831,12 +819,10 @@ static int dosearch(
int npartial;
LDAPMessage *res, *msg;
ber_int_t msgid;
#ifdef LDAP_SYNC
char *retoid = NULL;
struct berval *retdata = NULL;
int nresponses_psearch = -1;
int cancel_msgid = -1;
#endif
if( filtpatt != NULL ) {
filter = malloc( strlen( filtpatt ) + strlen( value ) );
......@@ -894,10 +880,8 @@ static int dosearch(
msg = ldap_next_message( ld, msg ) )
{
if ( nresponses++ ) putchar('\n');
#if LDAP_SYNC
if ( nresponses_psearch >= 0 )
nresponses_psearch++;
#endif
switch( ldap_msgtype( msg ) ) {
case LDAP_RES_SEARCH_ENTRY:
......@@ -919,14 +903,12 @@ static int dosearch(
goto done;
}
#ifdef LDAP_SYNC
if ( cancel_msgid != -1 &&
cancel_msgid == ldap_msgid( msg ) ) {
printf(_("Cancelled \n"));
printf(_("cancel_msgid = %d\n"), cancel_msgid);
goto done;
}
#endif
break;
case LDAP_RES_SEARCH_RESULT:
......@@ -937,19 +919,14 @@ static int dosearch(
}
#endif
#ifdef LDAP_SYNC
if ( ldapsync == LDAP_SYNC_REFRESH_AND_PERSIST ) {
break;
}
#endif
goto done;
case LDAP_RES_INTERMEDIATE:
npartial++;
#ifndef LDAP_SYNC
print_partial( ld, msg );
#else
ldap_parse_intermediate( ld, msg,
&retoid, &retdata, NULL, 0 );
......@@ -966,10 +943,8 @@ static int dosearch(
ldap_memfree( retoid );
ber_bvfree( retdata );
goto done;
#endif
}
#ifdef LDAP_SYNC
if ( ldapsync && sync_slimit != -1 &&
nresponses_psearch >= sync_slimit ) {
BerElement *msgidber = NULL;
......@@ -981,8 +956,6 @@ static int dosearch(
msgidvalp, NULL, NULL, &cancel_msgid);
nresponses_psearch = -1;
}
#endif
}
ldap_msgfree( res );
......
......@@ -201,9 +201,6 @@ typedef struct ldapcontrol {
#define LDAP_CONTROL_PAGEDRESULTS "1.2.840.113556.1.4.319"
#define LDAP_SYNC 2
#ifdef LDAP_SYNC
#define LDAP_SYNCREPL 1
#define LDAP_CONTROL_SYNC "1.3.6.1.4.1.4203.666.5.6"
#define LDAP_CONTROL_SYNC_STATE "1.3.6.1.4.1.4203.666.5.7"
#define LDAP_CONTROL_SYNC_DONE "1.3.6.1.4.1.4203.666.5.8"
......@@ -222,7 +219,6 @@ typedef struct ldapcontrol {
#define LDAP_SYNC_ADD 1
#define LDAP_SYNC_MODIFY 2
#define LDAP_SYNC_DELETE 3
#endif
#define LDAP_CONTROL_SORTREQUEST "1.2.840.113556.1.4.473"
#define LDAP_CONTROL_SORTRESPONSE "1.2.840.113556.1.4.474"
......@@ -297,9 +293,7 @@ typedef struct ldapcontrol {
#define LDAP_TAG_SASL_RES_CREDS ((ber_tag_t) 0x87U) /* context specific + primitive */
#ifdef LDAP_SYNC
#define LDAP_SYNC_TAG_COOKIE ((ber_tag_t) 0x04U) /* octet string */
#endif
/* possible operations a client can invoke */
......@@ -476,14 +470,12 @@ typedef struct ldapcontrol {
#define LDAP_CLIENT_LOOP 0x60 /* draft-ietf-ldap-c-api-xx */
#define LDAP_REFERRAL_LIMIT_EXCEEDED 0x61 /* draft-ietf-ldap-c-api-xx */
#ifdef LDAP_SYNC
#define LDAP_SYNC_RESOURCES_EXHAUSTED 0x100
#define LDAP_SYNC_SECURITY_VIOLATION 0x101
#define LDAP_SYNC_INVALID_COOKIE 0x102
#define LDAP_SYNC_UNSUPPORTED_SCHEME 0x103
#define LDAP_SYNC_CLIENT_DISCONNECT 0x104
#define LDAP_SYNC_RELOAD_REQUIRED 0x105
#endif
#define LDAP_ASSERTION_FAILED 0x10f
......@@ -496,11 +488,9 @@ typedef struct ldapcontrol {
#endif
/* LDAP SYNC request type */
#ifdef LDAP_SYNC
#define LDAP_SYNC_NONE 0x00
#define LDAP_SYNC_REFRESH_ONLY 0x01
#define LDAP_SYNC_REFRESH_AND_PERSIST 0x03
#endif
/*
* This structure represents both ldap messages and ldap responses.
......
......@@ -99,14 +99,12 @@ static struct ldaperror ldap_builtin_errlist[] = {
{LDAP_ASSERTION_FAILED, N_("Assertion Failed")},
#ifdef LDAP_SYNC
{LDAP_SYNC_RESOURCES_EXHAUSTED, N_("Content Sync Resource Exhausted")},
{LDAP_SYNC_SECURITY_VIOLATION, N_("Content Sync Security Violation")},
{LDAP_SYNC_INVALID_COOKIE, N_("Content Sync Invalid Cookie")},
{LDAP_SYNC_UNSUPPORTED_SCHEME, N_("Content Sync Unsupported Scheme")},
{LDAP_SYNC_CLIENT_DISCONNECT, N_("Content Sync Client Disconnect")},
{LDAP_SYNC_RELOAD_REQUIRED, N_("Content Sync Reload Required")},
#endif
#ifdef LDAP_EXOP_X_CANCEL
{LDAP_CANCELLED, N_("Cancelled")},
......
......@@ -243,13 +243,11 @@ do_add( Operation *op, SlapReply *rs )
if ( op->o_bd->be_add ) {
/* do the update here */
int repl_user = be_isupdate(op->o_bd, &op->o_ndn );
#if defined(LDAP_SYNCREPL) && !defined(SLAPD_MULTIMASTER)
#ifndef SLAPD_MULTIMASTER
if ( !op->o_bd->syncinfo &&
( !op->o_bd->be_update_ndn.bv_len || repl_user ))
#elif defined(LDAP_SYNCREPL) && defined(SLAPD_MULTIMASTER)
if ( !op->o_bd->syncinfo ) /* LDAP_SYNCREPL overrides MM */
#elif !defined(LDAP_SYNCREPL) && !defined(SLAPD_MULTIMASTER)
if ( !op->o_bd->be_update_ndn.bv_len || repl_user )
#else
if ( !op->o_bd->syncinfo )
#endif
{
int update = op->o_bd->be_update_ndn.bv_len;
......@@ -311,7 +309,7 @@ do_add( Operation *op, SlapReply *rs )
e = NULL;
}
#if defined(LDAP_SYNCREPL) || !defined(SLAPD_MULTIMASTER)
#ifndef SLAPD_MULTIMASTER
} else {
BerVarray defref = NULL;
#ifdef LDAP_SLAPI
......@@ -326,12 +324,9 @@ do_add( Operation *op, SlapReply *rs )
}
#endif /* LDAP_SLAPI */
#ifdef LDAP_SYNCREPL
if ( op->o_bd->syncinfo ) {
defref = op->o_bd->syncinfo->provideruri_bv;
} else
#endif
{
} else {
defref = op->o_bd->be_update_refs
? op->o_bd->be_update_refs : default_referral;
}
......@@ -376,9 +371,7 @@ do_add( Operation *op, SlapReply *rs )
done:
#ifdef LDAP_SYNC
slap_graduate_commit_csn( op );
#endif
if( modlist != NULL ) {
slap_mods_free( modlist );
......@@ -409,10 +402,7 @@ slap_mods2entry(
for( ; mods != NULL; mods = mods->sml_next ) {
Attribute *attr;
#ifdef LDAP_SYNCREPL
if ( !repl_user )
#endif
{
if ( !repl_user ) {
assert( mods->sml_op == LDAP_MOD_ADD );
}
assert( mods->sml_desc != NULL );
......
......@@ -35,13 +35,11 @@ bdb_add(Operation *op, SlapReply *rs )
int num_retries = 0;
#ifdef LDAP_SYNC
Operation* ps_list;
int rc;
EntryInfo *suffix_ei;
Entry *ctxcsn_e;
int ctxcsn_added = 0;
#endif
#ifdef NEW_LOGGING
LDAP_LOG ( OPERATION, ARGS, "==> bdb_add: %s\n", op->oq_add.rs_e->e_name.bv_val, 0, 0 );
......@@ -317,11 +315,7 @@ retry: /* transaction retry */
rs->sr_text = "no write access to parent";
goto return_results;
}
#ifdef LDAP_SYNCREPL
} else if ( !is_entry_glue( op->oq_add.rs_e )) {
#else
} else {
#endif
#ifdef NEW_LOGGING
LDAP_LOG ( OPERATION, DETAIL1, "bdb_add: %s denied\n",
pdn.bv_len == 0 ? "suffix" : "entry at root", 0, 0 );
......@@ -470,11 +464,7 @@ retry: /* transaction retry */
goto return_results;
}
#ifdef LDAP_SYNCREPL
if ( !op->o_bd->syncinfo )
#endif
#ifdef LDAP_SYNC
{
if ( !op->o_bd->syncinfo ) {
rc = bdb_csn_commit( op, rs, ltid, ei, &suffix_ei, &ctxcsn_e, &ctxcsn_added, locker );
switch ( rc ) {
case BDB_CSN_ABORT :
......@@ -483,7 +473,6 @@ retry: /* transaction retry */
goto retry;
}
}
#endif
if ( op->o_noop ) {
if (( rs->sr_err=TXN_ABORT( ltid )) != 0 ) {
......@@ -504,9 +493,7 @@ retry: /* transaction retry */
} else {
struct berval nrdn;
#ifdef LDAP_SYNC
struct berval ctx_nrdn;
#endif
if (pdn.bv_len) {
nrdn.bv_val = op->ora_e->e_nname.bv_val;
......@@ -517,18 +504,13 @@ retry: /* transaction retry */
bdb_cache_add( bdb, ei, op->oq_add.rs_e, &nrdn, locker );
#ifdef LDAP_SYNCREPL
if ( !op->o_bd->syncinfo )
#endif
#ifdef LDAP_SYNC
{
if ( !op->o_bd->syncinfo ) {
if ( ctxcsn_added ) {
ctx_nrdn.bv_val = "cn=ldapsync";
ctx_nrdn.bv_len = strlen( ctx_nrdn.bv_val );
bdb_cache_add( bdb, suffix_ei, ctxcsn_e, &ctx_nrdn, locker );
}
}
#endif
if(( rs->sr_err=TXN_COMMIT( ltid, 0 )) != 0 ) {
rs->sr_text = "txn_commit failed";
......@@ -566,13 +548,11 @@ retry: /* transaction retry */
return_results:
send_ldap_result( op, rs );
#ifdef LDAP_SYNC
if ( rs->sr_err == LDAP_SUCCESS && !noop ) {
LDAP_LIST_FOREACH ( ps_list, &bdb->bi_psearch_list, o_ps_link ) {
bdb_psearch( op, rs, ps_list, op->oq_add.rs_e, LDAP_PSEARCH_BY_ADD );
}
}
#endif
if( rs->sr_err == LDAP_SUCCESS && bdb->bi_txn_cp ) {
ldap_pvt_thread_yield();
......
......@@ -14,9 +14,7 @@
LDAP_BEGIN_DECL
#ifdef LDAP_SYNCREPL
#define BDB_SUBENTRIES 1
#endif
#define DN_BASE_PREFIX SLAP_INDEX_EQUALITY_PREFIX
#define DN_ONE_PREFIX '%'
......@@ -158,9 +156,7 @@ struct bdb_info {
ID bi_lastid;
ldap_pvt_thread_mutex_t bi_lastid_mutex;
#ifdef LDAP_SYNC
LDAP_LIST_HEAD(pl, slap_op) bi_psearch_list;
#endif
#ifdef SLAP_IDL_CACHE
int bi_idl_cache_max_size;
int bi_idl_cache_size;
......@@ -223,11 +219,9 @@ struct bdb_op_info {
#define BDB_REUSE_LOCKERS
#ifdef LDAP_SYNC
#define BDB_CSN_COMMIT 0
#define BDB_CSN_ABORT 1
#define BDB_CSN_RETRY 2
#endif
LDAP_END_DECL
......
......@@ -34,11 +34,7 @@ bdb_cache_entryinfo_new( )
}
/* Atomically release and reacquire a lock */
#if LDAP_SYNC
int
#else
static int
#endif
bdb_cache_entry_db_relock(
DB_ENV *env,
u_int32_t locker,
......
......@@ -30,7 +30,6 @@
#include "back-bdb.h"
#include "external.h"
#ifdef LDAP_SYNC
int
bdb_csn_commit(
Operation *op,
......@@ -201,4 +200,3 @@ rewind :
slap_rewind_commit_csn( op );
return BDB_CSN_RETRY;
}
#endif
......@@ -35,13 +35,11 @@ bdb_delete( Operation *op, SlapReply *rs )
int num_retries = 0;
#ifdef LDAP_SYNC
Operation* ps_list;
int rc;
EntryInfo *suffix_ei;
Entry *ctxcsn_e;
int ctxcsn_added = 0;
#endif
#ifdef NEW_LOGGING
LDAP_LOG ( OPERATION, ARGS, "==> bdb_delete: %s\n", op->o_req_dn.bv_val, 0, 0 );
......@@ -230,11 +228,8 @@ retry: /* transaction retry */
}
}
#ifdef LDAP_SYNCREPL /* FIXME : dn2entry() should return non-glue entry */
/* FIXME : dn2entry() should return non-glue entry */
if ( e == NULL || ( !manageDSAit && is_entry_glue( e ))) {
#else
if ( e == NULL ) {
#endif
#ifdef NEW_LOGGING
LDAP_LOG ( OPERATION, ARGS,
"<=- bdb_delete: no such object %s\n", op->o_req_dn.bv_val, 0, 0);
......@@ -253,12 +248,8 @@ retry: /* transaction retry */
matched = NULL;
} else {
#ifdef LDAP_SYNCREPL
BerVarray deref = op->o_bd->syncinfo ?
op->o_bd->syncinfo->provideruri_bv : default_referral;
#else
BerVarray deref = default_referral;
#endif
rs->sr_ref = referral_rewrite( deref, NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
}
......@@ -460,11 +451,7 @@ retry: /* transaction retry */
ldap_pvt_thread_mutex_unlock( &bdb->bi_lastid_mutex );
#endif
#ifdef LDAP_SYNCREPL
if ( !op->o_bd->syncinfo )
#endif
#ifdef LDAP_SYNC
{
if ( !op->o_bd->syncinfo ) {
rc = bdb_csn_commit( op, rs, ltid, ei, &suffix_ei, &ctxcsn_e, &ctxcsn_added, locker );
switch ( rc ) {
case BDB_CSN_ABORT :
......@@ -473,7 +460,6 @@ retry: /* transaction retry */
goto retry;
}
}
#endif
if( op->o_noop ) {
if ( ( rs->sr_err = TXN_ABORT( ltid ) ) != 0 ) {
......@@ -483,25 +469,18 @@ retry: /* transaction retry */
rs->sr_err = LDAP_SUCCESS;
}
} else {
#ifdef LDAP_SYNC
struct berval ctx_nrdn;
#endif
bdb_cache_delete( &bdb->bi_cache, e, bdb->bi_dbenv,
locker, &lock );
#ifdef LDAP_SYNCREPL
if ( !op->o_bd->syncinfo )
#endif
#ifdef LDAP_SYNC
{
if ( !op->o_bd->syncinfo ) {
if ( ctxcsn_added ) {
ctx_nrdn.bv_val = "cn=ldapsync";
ctx_nrdn.bv_len = strlen( ctx_nrdn.bv_val );
bdb_cache_add( bdb, suffix_ei, ctxcsn_e, &ctx_nrdn, locker );
}
}
#endif
rs->sr_err = TXN_COMMIT( ltid, 0 );
}
......@@ -540,13 +519,11 @@ retry: /* transaction retry */
return_results:
send_ldap_result( op, rs );
#ifdef LDAP_SYNC
if ( rs->sr_err == LDAP_SUCCESS && !noop ) {
LDAP_LIST_FOREACH( ps_list, &bdb->bi_psearch_list, o_ps_link ) {
bdb_psearch( op, rs, ps_list, e, LDAP_PSEARCH_BY_DELETE );
}
}
#endif
if(rs->sr_err == LDAP_SUCCESS && bdb->bi_txn_cp ) {
ldap_pvt_thread_yield();
......
......@@ -91,9 +91,7 @@ bdb_db_init( BackendDB *be )
bdb->bi_search_stack_depth = DEFAULT_SEARCH_STACK_DEPTH;
bdb->bi_search_stack = NULL;
#ifdef LDAP_SYNC
LDAP_LIST_INIT (&bdb->bi_psearch_list);
#endif
ldap_pvt_thread_mutex_init( &bdb->bi_lastid_mutex );
ldap_pvt_thread_mutex_init( &bdb->bi_cache.lru_mutex );
......@@ -674,13 +672,8 @@ bdb_initialize(
bi->bi_op_unbind = 0;
#ifdef LDAP_SYNC
bi->bi_op_abandon = bdb_abandon;
bi->bi_op_cancel = bdb_cancel;
#else
bi->bi_op_abandon = 0;
bi->bi_op_cancel = 0;
#endif
bi->bi_extended = bdb_extended;
......
......@@ -328,14 +328,12 @@ bdb_modify( Operation *op, SlapReply *rs )
int num_retries = 0;
#ifdef LDAP_SYNC
Operation* ps_list;
struct psid_entry *pm_list, *pm_prev;
int rc;
EntryInfo *suffix_ei;
Entry *ctxcsn_e;
int ctxcsn_added = 0;
#endif
#ifdef NEW_LOGGING
LDAP_LOG ( OPERATION, ENTRY, "bdb_modify: %s\n", op->o_req_dn.bv_val, 0, 0 );
......@@ -356,7 +354,6 @@ retry: /* transaction retry */
"bdb_modify: retrying...\n", 0, 0, 0);
#endif
#ifdef LDAP_SYNC
pm_list = LDAP_LIST_FIRST(&op->o_pm_list);
while ( pm_list != NULL ) {
LDAP_LIST_REMOVE ( pm_list, ps_link );
......@@ -364,7 +361,6 @@ retry: /* transaction retry */
pm_list = LDAP_LIST_NEXT ( pm_list, ps_link );
ch_free( pm_prev );
}
#endif
rs->sr_err = TXN_ABORT( ltid );
ltid = NULL;
......@@ -437,11 +433,8 @@ retry: /* transaction retry */
e = ei->bei_e;
/* acquire and lock entry */
#ifdef LDAP_SYNCREPL /* FIXME: dn2entry() should return non-glue entry */
/* FIXME: dn2entry() should return non-glue entry */
if (( rs->sr_err == DB_NOTFOUND ) || ( !manageDSAit && e && is_entry_glue( e ))) {
#else
if ( rs->sr_err == DB_NOTFOUND ) {
#endif
if ( e != NULL ) {
rs->sr_matched = ch_strdup( e->e_dn );
rs->sr_ref = is_entry_referral( e )
......@@ -451,12 +444,8 @@ retry: /* transaction retry */
e = NULL;
} else {
#ifdef LDAP_SYNCREPL
BerVarray deref = op->o_bd->syncinfo ?
op->o_bd->syncinfo->provideruri_bv : default_referral;
#else
BerVarray deref = default_referral;
#endif
rs->sr_ref = referral_rewrite( deref, NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
}
......@@ -500,13 +489,11 @@ retry: /* transaction retry */
goto return_results;
}
#ifdef LDAP_SYNC
if ( rs->sr_err == LDAP_SUCCESS && !op->o_noop ) {
LDAP_LIST_FOREACH ( ps_list, &bdb->bi_psearch_list, o_ps_link ) {
bdb_psearch(op, rs, ps_list, e, LDAP_PSEARCH_BY_PREMODIFY );
}
}
#endif
/* nested transaction */
rs->sr_err = TXN_BEGIN( bdb->bi_dbenv, ltid, &lt2,
......@@ -575,11 +562,7 @@ retry: /* transaction retry */
goto return_results;
}
#ifdef LDAP_SYNCREPL
if ( !op->o_bd->syncinfo )
#endif
#ifdef LDAP_SYNC
{
if ( !op->o_bd->syncinfo ) {
rc = bdb_csn_commit( op, rs, ltid, ei, &suffix_ei, &ctxcsn_e, &ctxcsn_added, locker );
switch ( rc ) {
case BDB_CSN_ABORT :
......@@ -588,7 +571,6 @@ retry: /* transaction retry */
goto retry;
}
}
#endif
if( op->o_noop ) {