r21761: - Give more detail on LDAP client library failures (make it clear
authorAndrew Bartlett <abartlet@samba.org>
Thu, 8 Mar 2007 06:23:39 +0000 (06:23 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:49:24 +0000 (14:49 -0500)
  where the error is from)

- Make default error string more consistant

Andrew Bartlett
(This used to be commit 7f115579d20a3112efd11444fafcbf78698fc9a1)

source4/lib/ldb/common/ldb_modules.c
source4/lib/ldb/ldb_ildap/ldb_ildap.c
source4/libcli/ldap/ldap_client.c
source4/torture/ldap/common.c

index 59a2713df87946c4c55bdc1d903dc54f89cbaa66..e10332a0e1a16140bfca20ffb5e7013cced7fe02 100644 (file)
@@ -432,7 +432,7 @@ int ldb_next_request(struct ldb_module *module, struct ldb_request *request)
        }
        if (!ldb_errstring(module->ldb)) {
                /* Set a default error string, to place the blame somewhere */
-               ldb_asprintf_errstring(module->ldb, "error in module %s: %s", module->ops->name, ldb_strerror(ret));
+               ldb_asprintf_errstring(module->ldb, "error in module %s: %s (%d)", module->ops->name, ldb_strerror(ret), ret);
        }
        return ret;
 }
index bff54ded2db5df5894cce53f3bfabd42aec77022..f5642f83034196d85c437d48d9d1d03a02a4c14c 100644 (file)
@@ -123,10 +123,16 @@ failed:
 */
 static int ildb_map_error(struct ildb_private *ildb, NTSTATUS status)
 {
+       TALLOC_CTX *mem_ctx = talloc_new(ildb);
        if (NT_STATUS_IS_OK(status)) {
                return LDB_SUCCESS;
        }
-       ldb_set_errstring(ildb->module->ldb, ldap_errstr(ildb->ldap, status));
+       if (!mem_ctx) {
+               ldb_oom(ildb->module->ldb);
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+       ldb_set_errstring(ildb->module->ldb, ldap_errstr(ildb->ldap, mem_ctx, status));
+       talloc_free(mem_ctx);
        if (NT_STATUS_IS_LDAP(status)) {
                return NT_STATUS_LDAP_CODE(status);
        }
@@ -763,7 +769,7 @@ static int ildb_connect(struct ldb_context *ldb, const char *url,
        status = ldap_connect(ildb->ldap, url);
        if (!NT_STATUS_IS_OK(status)) {
                ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to connect to ldap URL '%s' - %s\n",
-                         url, ldap_errstr(ildb->ldap, status));
+                         url, ldap_errstr(ildb->ldap, module, status));
                goto failed;
        }
 
@@ -783,14 +789,14 @@ static int ildb_connect(struct ldb_context *ldb, const char *url,
                        status = ldap_bind_simple(ildb->ldap, bind_dn, password);
                        if (!NT_STATUS_IS_OK(status)) {
                                ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to bind - %s\n",
-                                         ldap_errstr(ildb->ldap, status));
+                                         ldap_errstr(ildb->ldap, module, status));
                                goto failed;
                        }
                } else {
                        status = ldap_bind_sasl(ildb->ldap, creds);
                        if (!NT_STATUS_IS_OK(status)) {
                                ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to bind - %s\n",
-                                         ldap_errstr(ildb->ldap, status));
+                                         ldap_errstr(ildb->ldap, module, status));
                                goto failed;
                        }
                }
index 2c2cd0dd6620471b904caff12641d466c5a40a0d..82cafd721a00654c3c405a72520ed58e124aa366 100644 (file)
@@ -562,6 +562,7 @@ struct ldap_request *ldap_request_send(struct ldap_connection *conn,
        msg->messageid = req->messageid;
 
        if (!ldap_encode(msg, &req->data, req)) {
+               status = NT_STATUS_INTERNAL_ERROR;
                goto failed;            
        }
 
@@ -704,12 +705,14 @@ NTSTATUS ldap_check_response(struct ldap_connection *conn, struct ldap_Result *r
 /*
   return error string representing the last error
 */
-const char *ldap_errstr(struct ldap_connection *conn, NTSTATUS status)
+const char *ldap_errstr(struct ldap_connection *conn, 
+                       TALLOC_CTX *mem_ctx, 
+                       NTSTATUS status)
 {
        if (NT_STATUS_IS_LDAP(status) && conn->last_error != NULL) {
-               return conn->last_error;
+               return talloc_strdup(mem_ctx, conn->last_error);
        }
-       return nt_errstr(status);
+       return talloc_asprintf(mem_ctx, "LDAP client internal error: %s", nt_errstr(status));
 }
 
 
index ebf302ad095f778a63cf7819ef3d3cb2e81cc68a..7a4aa8050fc3bcad2e02edc5ae886cad36dca380 100644 (file)
@@ -86,7 +86,7 @@ NTSTATUS torture_ldap_connection2(TALLOC_CTX *mem_ctx, struct ldap_connection **
 
        status = ldap_bind_simple(*conn, userdn, password);
        if (!NT_STATUS_IS_OK(status)) {
-               printf("Failed a simple ldap bind - %s\n", ldap_errstr(*conn, status));
+               printf("Failed a simple ldap bind - %s\n", ldap_errstr(*conn, mem_ctx, status));
        }
  
        return status;