}
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;
}
*/
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);
}
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;
}
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;
}
}
msg->messageid = req->messageid;
if (!ldap_encode(msg, &req->data, req)) {
+ status = NT_STATUS_INTERNAL_ERROR;
goto failed;
}
/*
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));
}
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;