From 99c88eace15dbbcb1055d0b09089797298690a58 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Mon, 23 Oct 2000 13:32:14 +0000 Subject: [PATCH] Fix: remap API error codes into protocol error codes before sending back to client. --- servers/slapd/back-ldap/back-ldap.h | 1 + servers/slapd/back-ldap/bind.c | 54 +++++++++++++++++++++++++++-- servers/slapd/back-ldap/search.c | 1 + 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/servers/slapd/back-ldap/back-ldap.h b/servers/slapd/back-ldap/back-ldap.h index 1906933ab7..2d7c9f717e 100644 --- a/servers/slapd/back-ldap/back-ldap.h +++ b/servers/slapd/back-ldap/back-ldap.h @@ -51,6 +51,7 @@ struct ldapinfo { struct ldapconn *ldap_back_getconn(struct ldapinfo *li, struct slap_conn *conn, struct slap_op *op); void ldap_back_dobind(struct ldapconn *lc, Operation *op); +int ldap_back_map_result(int err); int ldap_back_op_result(struct ldapconn *lc, Operation *op); int back_ldap_LTX_init_module(int argc, char *argv[]); diff --git a/servers/slapd/back-ldap/bind.c b/servers/slapd/back-ldap/bind.c index 705203d275..921bbe0cdc 100644 --- a/servers/slapd/back-ldap/bind.c +++ b/servers/slapd/back-ldap/bind.c @@ -74,8 +74,10 @@ ldap_back_getconn(struct ldapinfo *li, Connection *conn, Operation *op) /* Looks like we didn't get a bind. Open a new session... */ if (!lc) { - if (ldap_initialize(&ld, li->url) != LDAP_SUCCESS) { - send_ldap_result( conn, op, LDAP_OTHER, + int err = ldap_initialize(&ld, li->url); + if (err != LDAP_SUCCESS) { + err = ldap_back_map_result(err); + send_ldap_result( conn, op, err, NULL, "ldap_init failed", NULL, NULL ); return( NULL ); } @@ -104,6 +106,53 @@ ldap_back_dobind(struct ldapconn *lc, Operation *op) lc->bound = 1; } +/* Map API errors to protocol errors... */ + +int +ldap_back_map_result(int err) +{ + switch(err) + { + case LDAP_SERVER_DOWN: + return LDAP_UNAVAILABLE; + case LDAP_LOCAL_ERROR: + return LDAP_OPERATIONS_ERROR; + case LDAP_ENCODING_ERROR: + case LDAP_DECODING_ERROR: + return LDAP_PROTOCOL_ERROR; + case LDAP_TIMEOUT: + return LDAP_UNAVAILABLE; + case LDAP_AUTH_UNKNOWN: + return LDAP_AUTH_METHOD_NOT_SUPPORTED; + case LDAP_FILTER_ERROR: + return LDAP_OPERATIONS_ERROR; + case LDAP_USER_CANCELLED: + return LDAP_OPERATIONS_ERROR; + case LDAP_PARAM_ERROR: + return LDAP_PROTOCOL_ERROR; + case LDAP_NO_MEMORY: + return LDAP_OPERATIONS_ERROR; + case LDAP_CONNECT_ERROR: + return LDAP_UNAVAILABLE; + case LDAP_NOT_SUPPORTED: + return LDAP_UNWILLING_TO_PERFORM; + case LDAP_CONTROL_NOT_FOUND: + return LDAP_PROTOCOL_ERROR; + case LDAP_NO_RESULTS_RETURNED: + return LDAP_NO_SUCH_OBJECT; + case LDAP_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) + return LDAP_OTHER; + else + return err; + } +} + int ldap_back_op_result(struct ldapconn *lc, Operation *op) { @@ -114,6 +163,7 @@ ldap_back_op_result(struct ldapconn *lc, Operation *op) ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER, &err); ldap_get_option(lc->ld, LDAP_OPT_ERROR_STRING, &msg); ldap_get_option(lc->ld, LDAP_OPT_MATCHED_DN, &match); + err = ldap_back_map_result(err); send_ldap_result( lc->conn, op, err, match, msg, NULL, NULL ); free(match); free(msg); diff --git a/servers/slapd/back-ldap/search.c b/servers/slapd/back-ldap/search.c index 5f0c5803f4..3604d8072c 100644 --- a/servers/slapd/back-ldap/search.c +++ b/servers/slapd/back-ldap/search.c @@ -108,6 +108,7 @@ fail: return( ldap_back_op_result(lc, op) ); ldap_msgfree(res); } else { sres = ldap_result2error(lc->ld, res, 1); + sres = ldap_back_map_result(sres); ldap_get_option(lc->ld, LDAP_OPT_ERROR_STRING, &err); ldap_get_option(lc->ld, LDAP_OPT_MATCHED_DN, &match); rc = 0; -- 2.39.5