ber_int_t msgid;
dncookie dc;
int isupdate;
+ int do_retry = 1;
LDAPControl **ctrls = NULL;
-#ifdef LDAP_BACK_PROXY_AUTHZ
int rc = LDAP_SUCCESS;
-#endif /* LDAP_BACK_PROXY_AUTHZ */
Debug(LDAP_DEBUG_ARGS, "==> ldap_back_add: %s\n", op->o_req_dn.bv_val, 0, 0);
#ifdef LDAP_BACK_PROXY_AUTHZ
rc = ldap_back_proxy_authz_ctrl( lc, op, rs, &ctrls );
if ( rc != LDAP_SUCCESS ) {
+ send_ldap_result( op, rs );
+ rc = -1;
goto cleanup;
}
#endif /* LDAP_BACK_PROXY_AUTHZ */
+retry:
rs->sr_err = ldap_add_ext(lc->ld, mdn.bv_val, attrs,
ctrls, NULL, &msgid);
-
+ rc = ldap_back_op_result( lc, op, rs, msgid, 1 );
+ if ( rs->sr_err == LDAP_UNAVAILABLE && do_retry ) {
+ do_retry = 0;
+ if ( ldap_back_retry (lc, op, rs )) goto retry;
+ }
#ifdef LDAP_BACK_PROXY_AUTHZ
cleanup:
if ( ctrls && ctrls != op->o_ctrls ) {
free( ctrls );
}
#endif /* LDAP_BACK_PROXY_AUTHZ */
-
for (--i; i>= 0; --i) {
ch_free(attrs[i]->mod_vals.modv_bvals);
ch_free(attrs[i]);
if ( mdn.bv_val != op->o_req_dn.bv_val ) {
free( mdn.bv_val );
}
-#ifdef LDAP_BACK_PROXY_AUTHZ
- if ( rc != LDAP_SUCCESS ) {
- send_ldap_result( op, rs );
- return -1;
- }
-#endif /* LDAP_BACK_PROXY_AUTHZ */
- return ldap_back_op_result( lc, op, rs, msgid, 1 ) != LDAP_SUCCESS;
+ return rc;
}
int ldap_back_freeconn( Operation *op, struct ldapconn *lc );
struct ldapconn *ldap_back_getconn(struct slap_op *op, struct slap_rep *rs);
int ldap_back_dobind(struct ldapconn *lc, Operation *op, SlapReply *rs);
+int ldap_back_retry(struct ldapconn *lc, Operation *op, SlapReply *rs);
int ldap_back_map_result(SlapReply *rs);
int ldap_back_op_result(struct ldapconn *lc, Operation *op, SlapReply *rs,
ber_int_t msgid, int sendok);
return( ERR_OK( rs->sr_err ) ? 0 : -1 );
}
+/* return true if bound, false if failed */
+int
+ldap_back_retry( struct ldapconn *lc, Operation *op, SlapReply *rs )
+{
+ struct ldapinfo *li = (struct ldapinfo *)op->o_bd->be_private;
+ int vers = op->o_protocol;
+ LDAP *ld;
+
+ ldap_pvt_thread_mutex_lock( &lc->lc_mutex );
+ ldap_unbind( lc->ld );
+ lc->bound = 0;
+ rs->sr_err = ldap_initialize(&ld, li->url);
+
+ if (rs->sr_err != LDAP_SUCCESS) {
+ rs->sr_err = slap_map_api2result( rs );
+ if (rs->sr_text == NULL) {
+ rs->sr_text = "ldap_initialize() failed";
+ }
+ if (op->o_conn) send_ldap_result( op, rs );
+ rs->sr_text = NULL;
+ return 0;
+ }
+ /* Set LDAP version. This will always succeed: If the client
+ * bound with a particular version, then so can we.
+ */
+ ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, (const void *)&vers);
+ /* FIXME: configurable? */
+ ldap_set_option(ld, LDAP_OPT_REFERRALS, LDAP_OPT_ON);
+ lc->ld = ld;
+ ldap_pvt_thread_mutex_unlock( &lc->lc_mutex );
+ return ldap_back_dobind( lc, op, rs );
+}
+
#ifdef LDAP_BACK_PROXY_AUTHZ
/*
* ldap_back_proxy_authz_ctrl() prepends a proxyAuthz control
struct berval mdn = BER_BVNULL;
ber_int_t msgid;
int freeval = 0;
+ int do_retry = 1;
dncookie dc;
LDAPControl **ctrls = NULL;
-#ifdef LDAP_BACK_PROXY_AUTHZ
int rc = LDAP_SUCCESS;
-#endif /* LDAP_BACK_PROXY_AUTHZ */
lc = ldap_back_getconn(op, rs);
if (!lc || !ldap_back_dobind( lc, op, rs ) ) {
#ifdef LDAP_BACK_PROXY_AUTHZ
rc = ldap_back_proxy_authz_ctrl( lc, op, rs, &ctrls );
if ( rc != LDAP_SUCCESS ) {
+ send_ldap_result( op, rs );
+ rc = -1;
goto cleanup;
}
#endif /* LDAP_BACK_PROXY_AUTHZ */
+retry:
rs->sr_err = ldap_compare_ext( lc->ld, mdn.bv_val,
mapped_at.bv_val, &mapped_val,
ctrls, NULL, &msgid );
+ rc = ldap_back_op_result( lc, op, rs, msgid, 1 );
+ if ( rs->sr_err == LDAP_UNAVAILABLE && do_retry ) {
+ do_retry = 0;
+ if ( ldap_back_retry (lc, op, rs )) goto retry;
+ }
#ifdef LDAP_BACK_PROXY_AUTHZ
cleanup:
if ( freeval ) {
free( mapped_val.bv_val );
}
-
-#ifdef LDAP_BACK_PROXY_AUTHZ
- if ( rc != LDAP_SUCCESS ) {
- send_ldap_result( op, rs );
- return -1;
- }
-#endif /* LDAP_BACK_PROXY_AUTHZ */
- return( ldap_back_op_result( lc, op, rs, msgid, 1 ) );
+ return rc;
}
ber_int_t msgid;
dncookie dc;
LDAPControl **ctrls = NULL;
-#ifdef LDAP_BACK_PROXY_AUTHZ
+ int do_retry = 1;
int rc = LDAP_SUCCESS;
-#endif /* LDAP_BACK_PROXY_AUTHZ */
struct berval mdn = BER_BVNULL;
ctrls = op->o_ctrls;
rc = ldap_back_proxy_authz_ctrl( lc, op, rs, &ctrls );
if ( rc != LDAP_SUCCESS ) {
+ send_ldap_result( op, rs );
+ rc = -1;
goto cleanup;
}
#endif /* LDAP_BACK_PROXY_AUTHZ */
+retry:
rs->sr_err = ldap_delete_ext( lc->ld, mdn.bv_val,
ctrls, NULL, &msgid );
+ rc = ldap_back_op_result( lc, op, rs, msgid, 1 );
+ if ( rs->sr_err == LDAP_SERVER_DOWN && do_retry ) {
+ do_retry = 0;
+ if ( ldap_back_retry (lc, op, rs )) goto retry;
+ }
#ifdef LDAP_BACK_PROXY_AUTHZ
cleanup:
free( mdn.bv_val );
}
-#ifdef LDAP_BACK_PROXY_AUTHZ
- if ( rc != LDAP_SUCCESS ) {
- send_ldap_result( op, rs );
- return -1;
- }
-#endif /* LDAP_BACK_PROXY_AUTHZ */
-
- return( ldap_back_op_result( lc, op, rs, msgid, 1 ) );
+ return rc;
}
LDAPMessage *res;
ber_int_t msgid;
int rc, isproxy;
+ int do_retry = 1;
dncookie dc;
lc = ldap_back_getconn(op, rs);
}
}
+retry:
rc = ldap_passwd(lc->ld, isproxy ? &mdn : NULL,
qpw->rs_old.bv_val ? &qpw->rs_old : NULL,
qpw->rs_new.bv_val ? &qpw->rs_new : NULL,
op->o_ctrls, NULL, &msgid);
- if (mdn.bv_val != op->o_req_dn.bv_val) {
- free(mdn.bv_val);
- }
-
if (rc == LDAP_SUCCESS) {
if (ldap_result(lc->ld, msgid, 1, NULL, &res) == -1) {
ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER, &rc);
}
if (rc != LDAP_SUCCESS) {
rs->sr_err = slap_map_api2result( rs );
+ if ( rs->sr_err == LDAP_UNAVAILABLE && do_retry ) {
+ do_retry = 0;
+ if ( ldap_back_retry (lc, op, rs )) goto retry;
+ }
send_ldap_result(op, rs);
if (rs->sr_matched) free((char *)rs->sr_matched);
if (rs->sr_text) free((char *)rs->sr_text);
rs->sr_text = NULL;
rc = -1;
}
+ if (mdn.bv_val != op->o_req_dn.bv_val) {
+ free(mdn.bv_val);
+ }
+
return rc;
}
ber_int_t msgid;
dncookie dc;
int isupdate;
+ int do_retry = 1;
LDAPControl **ctrls = NULL;
lc = ldap_back_getconn(op, rs);
#ifdef LDAP_BACK_PROXY_AUTHZ
rc = ldap_back_proxy_authz_ctrl( lc, op, rs, &ctrls );
if ( rc != LDAP_SUCCESS ) {
+ send_ldap_result( op, rs );
+ rc = -1;
goto cleanup;
}
#endif /* LDAP_BACK_PROXY_AUTHZ */
+retry:
rs->sr_err = ldap_modify_ext( lc->ld, mdn.bv_val, modv,
ctrls, NULL, &msgid );
+ rc = ldap_back_op_result( lc, op, rs, msgid, 1 );
+ if ( rs->sr_err == LDAP_UNAVAILABLE && do_retry ) {
+ do_retry = 0;
+ if ( ldap_back_retry (lc, op, rs )) goto retry;
+ }
cleanup:;
#ifdef LDAP_BACK_PROXY_AUTHZ
ch_free( mods );
ch_free( modv );
-#ifdef LDAP_BACK_PROXY_AUTHZ
- if ( rc != LDAP_SUCCESS ) {
- send_ldap_result( op, rs );
- return -1;
- }
-#endif /* LDAP_BACK_PROXY_AUTHZ */
-
- return ldap_back_op_result( lc, op, rs, msgid, 1 );
+ return rc;
}
ber_int_t msgid;
dncookie dc;
LDAPControl **ctrls = NULL;
-#ifdef LDAP_BACK_PROXY_AUTHZ
+ int do_retry = 1;
int rc = LDAP_SUCCESS;
-#endif /* LDAP_BACK_PROXY_AUTHZ */
struct berval mdn = BER_BVNULL, mnewSuperior = BER_BVNULL;
#ifdef LDAP_BACK_PROXY_AUTHZ
rc = ldap_back_proxy_authz_ctrl( lc, op, rs, &ctrls );
if ( rc != LDAP_SUCCESS ) {
+ send_ldap_result( op, rs );
+ rc = -1;
goto cleanup;
}
#endif /* LDAP_BACK_PROXY_AUTHZ */
+retry:
rs->sr_err = ldap_rename( lc->ld, mdn.bv_val,
op->orr_newrdn.bv_val, mnewSuperior.bv_val,
op->orr_deleteoldrdn,
ctrls,
NULL, &msgid );
+ rc = ldap_back_op_result( lc, op, rs, msgid, 1 );
+ if ( rs->sr_err == LDAP_SERVER_DOWN && do_retry ) {
+ do_retry = 0;
+ if ( ldap_back_retry (lc, op, rs )) goto retry;
+ }
#ifdef LDAP_BACK_PROXY_AUTHZ
cleanup:
free( mnewSuperior.bv_val );
}
-#ifdef LDAP_BACK_PROXY_AUTHZ
- if ( rc != LDAP_SUCCESS ) {
- send_ldap_result( op, rs );
- return -1;
- }
-#endif /* LDAP_BACK_PROXY_AUTHZ */
-
- return( ldap_back_op_result( lc, op, rs, msgid, 1 ) );
+ return rc;
}
struct berval mfilter = BER_BVNULL;
int dontfreetext = 0;
int freeconn = 0;
+ int do_retry = 1;
dncookie dc;
LDAPControl **ctrls = NULL;
}
#endif /* LDAP_BACK_PROXY_AUTHZ */
+retry:
rs->sr_err = ldap_search_ext( lc->ld, mbase.bv_val,
op->ors_scope, mfilter.bv_val,
mapped_attrs, op->ors_attrsonly,
Entry ent = {0};
struct berval bdn;
int abort = 0;
+ do_retry = 0;
+
e = ldap_first_entry( lc->ld, res );
rc = ldap_build_entry( op, e, &ent, &bdn,
LDAP_BUILD_ENTRY_PRIVATE );
char **references = NULL;
int cnt;
+ do_retry = 0;
rc = ldap_parse_reference( lc->ld, res,
&references, &rs->sr_ctrls, 1 );
}
if ( rc == -1 ) {
+ if ( do_retry ) {
+ do_retry = 0;
+ if ( ldap_back_retry( lc, op, rs ))
+ goto retry;
+ }
/* FIXME: invalidate the connection? */
rs->sr_err = LDAP_SERVER_DOWN;
freeconn = 1;