]> git.sur5r.net Git - openldap/commitdiff
more args elimination + allow specific messages when mapping client API errors to...
authorPierangelo Masarati <ando@openldap.org>
Fri, 4 Apr 2003 22:20:49 +0000 (22:20 +0000)
committerPierangelo Masarati <ando@openldap.org>
Fri, 4 Apr 2003 22:20:49 +0000 (22:20 +0000)
servers/slapd/back-ldap/add.c
servers/slapd/back-ldap/back-ldap.h
servers/slapd/back-ldap/bind.c
servers/slapd/back-ldap/compare.c
servers/slapd/back-ldap/config.c
servers/slapd/back-ldap/delete.c
servers/slapd/back-ldap/extended.c
servers/slapd/back-ldap/modify.c
servers/slapd/back-ldap/modrdn.c
servers/slapd/back-ldap/search.c

index f6fa13cae653144905d5e91e573b12da3966d745..eeba3763b2f385cd2a74ab67ef3c129c775a544b 100644 (file)
@@ -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
index f450254a6643ced701ebf2a3ca0330d8d78fbf53..77fdda68a27188958a9a00f31d06c71a55ded0bd 100644 (file)
@@ -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,
index 8430059d3c80f1aaa49d807e0ead8ac7b037cd2d..141c8db487537283a70c3c4a279a690108ad0edf 100644 (file)
@@ -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 );
 }
 
index 86e274b603193a52e7f223b616efb42dbbc73cad..7951a169162185702548c5e6ab92d6f8b29ca068 100644 (file)
@@ -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 ) );
 }
index dcc22ff65d5c578b89ef7bb0d81eb39424bcc4db..2f2186e52db10101bad07bef152835c84dbbf25a 100644 (file)
@@ -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 */
index e97ff05263be1fc4b5849bd90d284062b02ed04b..e6c635ce433397f0bb2c15256443430a63172731 100644 (file)
@@ -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 ) );
 }
index e5043d6a72d4b2e40756509a5aa99db1dfdbc8bc..3673800fa2c4ecd79156bef6dec901ffe20c4376 100644 (file)
@@ -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);
index 7c802806d038dbaf972036fb4c01b0852219a3ef..1001c1891dbd6860d535521b5d9cac5731e8e598 100644 (file)
@@ -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 );
 }
 
index 74a6813914f5fba06578897c614af4b89341a714..90cf289b37630d553815dce4d76bc750022c67c2 100644 (file)
@@ -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 ) );
 }
+
index 76cf81cb4fb3a77acc2df66149d86e3fa8ff8a30..0e141a9efd7c62aabc871a10be36c8aad974bbde 100644 (file)
@@ -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;
                }