Commit ab3ab80e authored by Pierangelo Masarati's avatar Pierangelo Masarati
Browse files

more args elimination + allow specific messages when mapping client API errors to LDAP_OTHER

parent 172e93bf
......@@ -174,7 +174,8 @@ ldap_back_add(
}
attrs[i] = NULL;
j = ldap_add_ext(lc->ld, mdn.bv_val, attrs, op->o_ctrls, NULL, &msgid);
rs->sr_err = ldap_add_ext(lc->ld, mdn.bv_val, attrs,
op->o_ctrls, NULL, &msgid);
for (--i; i>= 0; --i) {
ch_free(attrs[i]->mod_vals.modv_bvals);
ch_free(attrs[i]);
......@@ -184,7 +185,7 @@ ldap_back_add(
free( mdn.bv_val );
}
return( ldap_back_op_result( lc, op, rs, msgid, j, 1 ) );
return ldap_back_op_result( lc, op, rs, msgid, 1 ) != LDAP_SUCCESS;
}
#ifdef ENABLE_REWRITE
......
......@@ -93,9 +93,9 @@ struct ldapinfo {
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_map_result(int err);
int ldap_back_map_result(SlapReply *rs);
int ldap_back_op_result(struct ldapconn *lc, Operation *op, SlapReply *rs,
ber_int_t msgid, int rc, int sendok);
ber_int_t msgid, int sendok);
int back_ldap_LTX_init_module(int argc, char *argv[]);
void ldap_back_dn_massage(struct ldapinfo *li, struct berval *dn,
......
......@@ -113,9 +113,9 @@ ldap_back_bind(
}
lc->bound = 0;
/* method is always LDAP_AUTH_SIMPLE if we got here */
rc = ldap_sasl_bind(lc->ld, mdn.bv_val, LDAP_SASL_SIMPLE,
rs->sr_err = ldap_sasl_bind(lc->ld, mdn.bv_val, LDAP_SASL_SIMPLE,
&op->oq_bind.rb_cred, op->o_ctrls, NULL, &msgid);
rc = ldap_back_op_result( lc, op, rs, msgid, rc, 1 );
rc = ldap_back_op_result( lc, op, rs, msgid, 1 );
if (rc == LDAP_SUCCESS) {
lc->bound = 1;
if ( mdn.bv_val != op->o_req_dn.bv_val ) {
......@@ -273,8 +273,10 @@ ldap_back_getconn(Operation *op, SlapReply *rs)
rs->sr_err = ldap_initialize(&ld, li->url);
if (rs->sr_err != LDAP_SUCCESS) {
rs->sr_err = ldap_back_map_result(rs->sr_err);
rs->sr_text = "ldap_initialize() failed";
rs->sr_err = ldap_back_map_result(rs);
if (rs->sr_text == NULL) {
rs->sr_text = "ldap_initialize() failed";
}
send_ldap_result( op, rs );
return( NULL );
}
......@@ -430,9 +432,9 @@ ldap_back_dobind( struct ldapconn *lc, Operation *op, SlapReply *rs )
ldap_pvt_thread_mutex_lock( &lc->lc_mutex );
if ( !lc->bound ) {
rc = ldap_sasl_bind(lc->ld, lc->bound_dn.bv_val,
rs->sr_err = ldap_sasl_bind(lc->ld, lc->bound_dn.bv_val,
LDAP_SASL_SIMPLE, &lc->cred, NULL, NULL, &msgid);
rc = ldap_back_op_result( lc, op, rs, msgid, rc, 0 );
rc = ldap_back_op_result( lc, op, rs, msgid, 0 );
if (rc == LDAP_SUCCESS) {
lc->bound = 1;
}
......@@ -460,9 +462,9 @@ ldap_back_rebind( LDAP *ld, LDAP_CONST char *url, ber_tag_t request,
/* Map API errors to protocol errors... */
int
ldap_back_map_result(int err)
ldap_back_map_result(SlapReply *rs)
{
switch(err)
switch(rs->sr_err)
{
case LDAP_SERVER_DOWN:
return LDAP_UNAVAILABLE;
......@@ -476,8 +478,10 @@ ldap_back_map_result(int err)
case LDAP_AUTH_UNKNOWN:
return LDAP_AUTH_METHOD_NOT_SUPPORTED;
case LDAP_FILTER_ERROR:
rs->sr_text = "Filter error";
return LDAP_OTHER;
case LDAP_USER_CANCELLED:
rs->sr_text = "User cancelled";
return LDAP_OTHER;
case LDAP_PARAM_ERROR:
return LDAP_PROTOCOL_ERROR;
......@@ -492,41 +496,46 @@ ldap_back_map_result(int err)
case LDAP_NO_RESULTS_RETURNED:
return LDAP_NO_SUCH_OBJECT;
case LDAP_MORE_RESULTS_TO_RETURN:
rs->sr_text = "More results to return";
return LDAP_OTHER;
case LDAP_CLIENT_LOOP:
case LDAP_REFERRAL_LIMIT_EXCEEDED:
return LDAP_LOOP_DETECT;
default:
if LDAP_API_ERROR(err)
if LDAP_API_ERROR(rs->sr_err)
return LDAP_OTHER;
else
return err;
return rs->sr_err;
}
}
int
ldap_back_op_result(struct ldapconn *lc, Operation *op, SlapReply *rs,
ber_int_t msgid, int err, int sendok)
ber_int_t msgid, int sendok)
{
struct ldapinfo *li = (struct ldapinfo *)op->o_bd->be_private;
char *match = NULL;
LDAPMessage *res;
int rc;
char *text = NULL;
rs->sr_text = NULL;
rs->sr_matched = NULL;
if (err == LDAP_SUCCESS) {
if (rs->sr_err == LDAP_SUCCESS) {
if (ldap_result(lc->ld, msgid, 1, NULL, &res) == -1) {
ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER, &err);
ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER,
&rs->sr_err);
} else {
rc = ldap_parse_result(lc->ld, res, &err, &match,
(char **)&rs->sr_text, NULL, NULL, 1);
if (rc != LDAP_SUCCESS) err = rc;
rc = ldap_parse_result(lc->ld, res, &rs->sr_err, &match,
&text, NULL, NULL, 1);
rs->sr_text = text;
if (rc != LDAP_SUCCESS) rs->sr_err = rc;
}
}
if (err != LDAP_SUCCESS) {
err = ldap_back_map_result(err);
if (rs->sr_err != LDAP_SUCCESS) {
rs->sr_err = ldap_back_map_result(rs);
/* internal ops must not reply to client */
if ( op->o_conn && !op->o_do_not_cache ) {
......@@ -552,17 +561,16 @@ ldap_back_op_result(struct ldapconn *lc, Operation *op, SlapReply *rs,
#endif
}
}
if (op->o_conn && (sendok || err != LDAP_SUCCESS)) {
rs->sr_err = err;
if (op->o_conn && (sendok || rs->sr_err != LDAP_SUCCESS)) {
send_ldap_result( op, rs );
}
if (rs->sr_matched != match) free((char *)rs->sr_matched);
rs->sr_matched = NULL;
if ( match ) ldap_memfree( match );
if ( rs->sr_text ) {
ldap_memfree( (char *)rs->sr_text );
rs->sr_text = NULL;
if ( text ) {
ldap_memfree( text );
}
return( (err==LDAP_SUCCESS) ? 0 : -1 );
rs->sr_text = NULL;
return( (rs->sr_err == LDAP_SUCCESS) ? 0 : -1 );
}
......@@ -112,12 +112,12 @@ ldap_back_compare(
}
}
rc = ldap_compare_ext( lc->ld, mdn.bv_val, mapped_oc.bv_val,
rs->sr_err = ldap_compare_ext( lc->ld, mdn.bv_val, mapped_oc.bv_val,
&mapped_at, op->o_ctrls, NULL, &msgid );
if ( mdn.bv_val != op->o_req_dn.bv_val ) {
free( mdn.bv_val );
}
return( ldap_back_op_result( lc, op, rs, msgid, rc, 1 ) );
return( ldap_back_op_result( lc, op, rs, msgid, 1 ) );
}
......@@ -462,7 +462,7 @@ ldap_back_exop_whoami(
}
ch_free(c.ldctl_value.bv_val);
if (rs->sr_err != LDAP_SUCCESS) {
rs->sr_err = ldap_back_map_result(rs->sr_err);
rs->sr_err = ldap_back_map_result(rs);
}
} else {
/* else just do the same as before */
......
......@@ -95,11 +95,12 @@ ldap_back_delete(
ldap_back_dn_massage( li, &op->o_req_dn, &mdn, 0, 1 );
#endif /* !ENABLE_REWRITE */
rc = ldap_delete_ext( lc->ld, mdn.bv_val, op->o_ctrls, NULL, &msgid );
rs->sr_err = ldap_delete_ext( lc->ld, mdn.bv_val, op->o_ctrls,
NULL, &msgid );
if ( mdn.bv_val != op->o_req_dn.bv_val ) {
free( mdn.bv_val );
}
return( ldap_back_op_result( lc, op, rs, msgid, rc, 1 ) );
return( ldap_back_op_result( lc, op, rs, msgid, 1 ) );
}
......@@ -147,7 +147,7 @@ ldap_back_exop_passwd(
}
}
if (rc != LDAP_SUCCESS) {
rs->sr_err = ldap_back_map_result(rc);
rs->sr_err = ldap_back_map_result(rs);
send_ldap_result(op, rs);
if (rs->sr_matched) free((char *)rs->sr_matched);
if (rs->sr_text) free((char *)rs->sr_text);
......
......@@ -154,7 +154,8 @@ ldap_back_modify(
}
modv[i] = 0;
rc = ldap_modify_ext( lc->ld, mdn.bv_val, modv, op->o_ctrls, NULL, &msgid );
rs->sr_err = ldap_modify_ext( lc->ld, mdn.bv_val, modv,
op->o_ctrls, NULL, &msgid );
cleanup:;
if ( mdn.bv_val != op->o_req_dn.bv_val ) {
......@@ -166,6 +167,6 @@ cleanup:;
ch_free( mods );
ch_free( modv );
return ldap_back_op_result( lc, op, rs, msgid, rc, 1 );
return ldap_back_op_result( lc, op, rs, msgid, 1 );
}
......@@ -137,8 +137,10 @@ ldap_back_modrdn(
ldap_back_dn_massage( li, &op->o_req_dn, &mdn, 0, 1 );
#endif /* !ENABLE_REWRITE */
rc = ldap_rename( lc->ld, mdn.bv_val, op->oq_modrdn.rs_newrdn.bv_val, mnewSuperior.bv_val,
op->oq_modrdn.rs_deleteoldrdn, op->o_ctrls, NULL, &msgid );
rs->sr_err = ldap_rename( lc->ld, mdn.bv_val,
op->oq_modrdn.rs_newrdn.bv_val, mnewSuperior.bv_val,
op->oq_modrdn.rs_deleteoldrdn, op->o_ctrls,
NULL, &msgid );
if ( mdn.bv_val != op->o_req_dn.bv_val ) {
free( mdn.bv_val );
......@@ -148,5 +150,6 @@ ldap_back_modrdn(
free( mnewSuperior.bv_val );
}
return( ldap_back_op_result( lc, op, rs, msgid, rc, 1 ) );
return( ldap_back_op_result( lc, op, rs, msgid, 1 ) );
}
......@@ -208,12 +208,12 @@ ldap_back_search(
mapped_attrs[count] = NULL;
}
rc = ldap_search_ext(lc->ld, mbase.bv_val, op->oq_search.rs_scope, mfilter.bv_val,
rs->sr_err = ldap_search_ext(lc->ld, mbase.bv_val, op->oq_search.rs_scope, mfilter.bv_val,
mapped_attrs, op->oq_search.rs_attrsonly, op->o_ctrls, NULL, tv.tv_sec ? &tv
: NULL, op->oq_search.rs_slimit, &msgid);
if ( rc != LDAP_SUCCESS ) {
if ( rs->sr_err != LDAP_SUCCESS ) {
fail:;
rc = ldap_back_op_result(lc, op, rs, msgid, rc, 0);
rc = ldap_back_op_result(lc, op, rs, msgid, 0);
goto finish;
}
......@@ -309,7 +309,7 @@ fail:;
rc = ldap_parse_result(lc->ld, res, &rs->sr_err, &match,
(char **)&rs->sr_text, NULL, NULL, 1);
if (rc != LDAP_SUCCESS ) rs->sr_err = rc;
rs->sr_err = ldap_back_map_result(rs->sr_err);
rs->sr_err = ldap_back_map_result(rs);
rc = 0;
break;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment