typedef struct syncinfo_s {
struct slap_backend_db *si_be;
struct re_s *si_re;
- long si_rid;
+ int si_rid;
slap_bindconf si_bindconf;
struct berval si_base;
struct berval si_logbase;
int si_tlimit;
int si_refreshDelete;
int si_refreshPresent;
+ int si_refreshDone;
int si_syncdata;
int si_logstate;
int si_conn_setup;
&si->si_syncCookie.ctxcsn, si->si_syncCookie.rid );
}
+ si->si_refreshDone = 0;
+
rc = ldap_sync_search( si, op->o_tmpmemctx );
if( rc != LDAP_SUCCESS ) {
int rc, err, i;
ber_len_t len;
- int rc_efree = 1;
-
struct berval *psub;
Modifications *modlist = NULL;
struct timeval tout = { 0, 0 };
int refreshDeletes = 0;
- int refreshDone = 1;
BerVarray syncUUIDs = NULL;
ber_tag_t si_tag;
slap_parse_sync_cookie( &syncCookie, NULL );
}
}
+ rc = 0;
if ( si->si_syncdata && si->si_logstate == SYNCLOG_LOGGING ) {
- entry = NULL;
modlist = NULL;
- if ( syncrepl_message_to_op( si, op, msg ) == LDAP_SUCCESS &&
+ if (( rc = syncrepl_message_to_op( si, op, msg )) == LDAP_SUCCESS &&
!BER_BVISNULL( &syncCookie.ctxcsn ) ) {
syncrepl_updateCookie( si, op, psub, &syncCookie );
}
- } else if ( syncrepl_message_to_entry( si, op, msg,
- &modlist, &entry, syncstate ) == LDAP_SUCCESS ) {
- rc_efree = syncrepl_entry( si, op, entry, &modlist,
- syncstate, &syncUUID, &syncCookie_req, &syncCookie.ctxcsn );
- if ( !BER_BVISNULL( &syncCookie.ctxcsn ) )
- {
+ } else if (( rc = syncrepl_message_to_entry( si, op, msg,
+ &modlist, &entry, syncstate )) == LDAP_SUCCESS ) {
+ if (( rc = syncrepl_entry( si, op, entry, &modlist,
+ syncstate, &syncUUID, &syncCookie_req,
+ &syncCookie.ctxcsn )) == LDAP_SUCCESS &&
+ !BER_BVISNULL( &syncCookie.ctxcsn ) ) {
syncrepl_updateCookie( si, op, psub, &syncCookie );
}
}
if ( modlist ) {
slap_mods_free( modlist, 1 );
}
- if ( rc_efree && entry ) {
- entry_free( entry );
- }
- entry = NULL;
+ if ( rc )
+ goto done;
break;
case LDAP_RES_SEARCH_REFERENCE:
slap_parse_sync_cookie( &syncCookie, NULL );
}
}
+ /* Defaults to TRUE */
if ( ber_peek_tag( ber, &len ) ==
LDAP_TAG_REFRESHDONE )
{
- ber_scanf( ber, "b", &refreshDone );
+ ber_scanf( ber, "b", &si->si_refreshDone );
+ } else
+ {
+ si->si_refreshDone = 1;
}
ber_scanf( ber, /*"{"*/ "}" );
break;
int rc = LDAP_SUCCESS;
int dostop = 0;
ber_socket_t s;
- int i, defer = 1;
+ int i, defer = 1, fail = 0;
Backend *be;
Debug( LDAP_DEBUG_TRACE, "=>do_syncrepl rid %03d\n", si->si_rid, 0, 0 );
if ( !si->si_retrynum || si->si_retrynum[i] == RETRYNUM_TAIL ) {
ldap_pvt_runqueue_remove( &slapd_rq, rtask );
+ fail = RETRYNUM_TAIL;
} else if ( RETRYNUM_VALID( si->si_retrynum[i] ) ) {
if ( si->si_retrynum[i] > 0 )
si->si_retrynum[i]--;
+ fail = si->si_retrynum[i];
rtask->interval.tv_sec = si->si_retryinterval[i];
ldap_pvt_runqueue_resched( &slapd_rq, rtask, 0 );
slap_wake_listener();
}
}
-
+
ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
ldap_pvt_thread_mutex_unlock( &si->si_mutex );
+ if ( rc ) {
+ if ( fail == RETRYNUM_TAIL ) {
+ Debug( LDAP_DEBUG_ANY,
+ "do_syncrepl: rid %03d quitting\n",
+ si->si_rid, 0, 0 );
+ } else if ( fail > 0 ) {
+ Debug( LDAP_DEBUG_ANY,
+ "do_syncrepl: rid %03d retrying (%d retries left)\n",
+ si->si_rid, fail, 0 );
+ } else {
+ Debug( LDAP_DEBUG_ANY,
+ "do_syncrepl: rid %03d retrying\n",
+ si->si_rid, 0, 0 );
+ }
+ }
+
return NULL;
}
} else {
op->orm_modlist = modlist;
rc = op->o_bd->be_modify( op, &rs );
+ modlist = op->orm_modlist;
Debug( rc ? LDAP_DEBUG_ANY : LDAP_DEBUG_SYNC,
"syncrepl_message_to_op: rid %03d be_modify %s (%d)\n",
si->si_rid, op->o_req_dn.bv_val, rc );
char txtbuf[SLAP_TEXT_BUFLEN];
size_t textlen = sizeof txtbuf;
- struct berval bdn = {0, NULL}, dn, ndn;
+ struct berval bdn = BER_BVNULL, dn, ndn;
int rc;
*modlist = NULL;
op->o_tag = LDAP_REQ_ADD;
rc = ldap_get_dn_ber( si->si_ld, msg, &ber, &bdn );
-
if ( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_ANY,
"syncrepl_message_to_entry: rid %03d dn get failed (%d)",
slap_sl_free( dn.bv_val, op->o_tmpmemctx );
if ( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_DELETE ) {
- if ( entry )
- *entry = NULL;
- return LDAP_SUCCESS;
+ /* NOTE: this could be done even before decoding the DN,
+ * although encoding errors wouldn't be detected */
+ rc = LDAP_SUCCESS;
+ goto done;
}
if ( entry == NULL ) {
- return -1;
+ rc = -1;
+ goto done;
}
e = ( Entry * ) ch_calloc( 1, sizeof( Entry ) );
- *entry = e;
e->e_name = op->o_req_dn;
e->e_nname = op->o_req_ndn;
}
done:
- ber_free ( ber, 0 );
+ ber_free( ber, 0 );
if ( rc != LDAP_SUCCESS ) {
if ( e ) {
entry_free( e );
- *entry = e = NULL;
+ e = NULL;
}
}
+ *entry = e;
return rc;
}
AttributeAssertion ava = { NULL, BER_BVNULL };
#endif
int rc = LDAP_SUCCESS;
- int ret = LDAP_SUCCESS;
struct berval pdn = BER_BVNULL;
dninfo dni = {0};
}
if (( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_ADD )) {
- if ( !si->si_refreshPresent ) {
+ if ( !si->si_refreshPresent && !si->si_refreshDone ) {
syncuuid_bv = ber_dupbv( NULL, syncUUID );
avl_insert( &si->si_presentlist, (caddr_t) syncuuid_bv,
syncuuid_cmp, avl_dup_error );
switch ( rs_add.sr_err ) {
case LDAP_SUCCESS:
be_entry_release_w( op, entry );
- ret = 0;
+ entry = NULL;
break;
case LDAP_REFERRAL:
/* we assume that LDAP_NO_SUCH_OBJECT is returned
* only if the suffix entry is not present */
case LDAP_NO_SUCH_OBJECT:
- syncrepl_add_glue( op, entry );
- ret = 0;
+ rc = syncrepl_add_glue( op, entry );
+ entry = NULL;
break;
/* if an entry was added via syncrepl_add_glue(),
cb2.sc_response = dn_callback;
cb2.sc_private = &dni;
- be->be_search( &op2, &rs2 );
+ rc = be->be_search( &op2, &rs2 );
+ if ( rc ) goto done;
retry = 0;
slap_op_time( &op->o_time, &op->o_tincr );
Debug( LDAP_DEBUG_ANY,
"syncrepl_entry: rid %03d be_add failed (%d)\n",
si->si_rid, rs_add.sr_err, 0 );
- ret = 1;
break;
}
goto done;
op->o_req_dn = entry->e_name;
op->o_req_ndn = entry->e_nname;
} else {
- ret = 1;
goto done;
}
if ( dni.wasChanged )
si->si_rid, rs_modify.sr_err, 0 );
}
}
- ret = 1;
goto done;
case LDAP_SYNC_DELETE :
if ( !BER_BVISNULL( &dni.dn )) {
}
}
}
- ret = 0;
goto done;
default :
Debug( LDAP_DEBUG_ANY,
"syncrepl_entry: rid %03d unknown syncstate\n", si->si_rid, 0, 0 );
- ret = 1;
goto done;
}
if ( !BER_BVISNULL( &dni.dn ) ) {
op->o_tmpfree( dni.dn.bv_val, op->o_tmpmemctx );
}
+ if ( entry )
+ entry_free( entry );
BER_BVZERO( &op->o_csn );
- return ret;
+ return rc;
}
static struct berval gcbva[] = {
for (i=0; uuids[i].bv_val; i++) {
op->ors_slimit = 1;
- slap_uuidstr_from_normalized( &uf.f_av_value, &uuids[i],
- op->o_tmpmemctx );
- filter2bv_x( op, op->ors_filter, &op->ors_filterstr );
- op->o_tmpfree( uf.f_av_value.bv_val, op->o_tmpmemctx );
uf.f_av_value = uuids[i];
+ filter2bv_x( op, op->ors_filter, &op->ors_filterstr );
rc = be->be_search( op, &rs_search );
op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
}
return;
}
-void
+int
syncrepl_add_glue(
Operation* op,
Entry *e )
} else {
/* incl. ALREADY EXIST */
entry_free( glue );
+ if ( rs_add.sr_err != LDAP_ALREADY_EXISTS ) {
+ entry_free( e );
+ return rc;
+ }
}
/* Move to next child */
entry_free( e );
}
- return;
+ return rc;
}
static void
Modifications mod = { { 0 } };
struct berval vals[ 2 ];
- int rc;
+ int rc, dbflags;
slap_callback cb = { NULL };
SlapReply rs_modify = {REP_RESULT};
/* update contextCSN */
op->o_msgid = SLAP_SYNC_UPDATE_MSGID;
op->orm_modlist = &mod;
+ dbflags = SLAP_DBFLAGS(op->o_bd);
+ SLAP_DBFLAGS(op->o_bd) |= SLAP_DBFLAG_NOLASTMOD;
rc = be->be_modify( op, &rs_modify );
+ SLAP_DBFLAGS(op->o_bd) = dbflags;
op->o_msgid = 0;
if ( rs_modify.sr_err != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
return -1;
}
+ if ( select_backend( &si->si_base, 0, 0 ) != c->be ) {
+ ber_memfree( si->si_base.bv_val );
+ snprintf( c->msg, sizeof( c->msg ),
+ "Base DN \"%s\" is not within the database naming context",
+ val );
+ Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
+ return -1;
+ }
gots |= GOT_BASE;
} else if ( !strncasecmp( c->argv[ i ], LOGBASESTR "=",
STRLENOF( LOGBASESTR "=" ) ) )
si->si_bindconf.sb_uri = uri;
ptr = buf;
- ptr += snprintf( ptr, sizeof( buf ), IDSTR "=%03ld " PROVIDERSTR "=%s",
+ ptr += snprintf( ptr, sizeof( buf ), IDSTR "=%03d " PROVIDERSTR "=%s",
si->si_rid, si->si_bindconf.sb_uri.bv_val );
if ( !BER_BVISNULL( &bc )) {
ptr = lutil_strcopy( ptr, bc.bv_val );