}
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]);
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
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,
}
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 ) {
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 );
}
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;
}
/* 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;
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;
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 ) {
#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 );
}
}
}
- 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 ) );
}
}
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 */
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 ) );
}
}
}
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);
}
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 ) {
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 );
}
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 );
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 ) );
}
+
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;
}
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;
}