mirror of
https://github.com/samba-team/samba.git
synced 2025-07-29 15:42:04 +03:00
ldap_server: Run the ldap_encode() step in ldapsrv_queue_reply()
This avoids holding the memory for the response twice, by the time the result is queued it is only ASN.1 encoded. Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
This commit is contained in:
@ -32,6 +32,7 @@
|
|||||||
#include <ldb_module.h>
|
#include <ldb_module.h>
|
||||||
#include "ldb_wrap.h"
|
#include "ldb_wrap.h"
|
||||||
#include "lib/tsocket/tsocket.h"
|
#include "lib/tsocket/tsocket.h"
|
||||||
|
#include "libcli/ldap/ldap_proto.h"
|
||||||
|
|
||||||
static int map_ldb_error(TALLOC_CTX *mem_ctx, int ldb_err,
|
static int map_ldb_error(TALLOC_CTX *mem_ctx, int ldb_err,
|
||||||
const char *add_err_string, const char **errstring)
|
const char *add_err_string, const char **errstring)
|
||||||
@ -257,9 +258,24 @@ struct ldapsrv_reply *ldapsrv_init_reply(struct ldapsrv_call *call, uint8_t type
|
|||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ldapsrv_queue_reply(struct ldapsrv_call *call, struct ldapsrv_reply *reply)
|
NTSTATUS ldapsrv_queue_reply(struct ldapsrv_call *call, struct ldapsrv_reply *reply)
|
||||||
{
|
{
|
||||||
|
bool bret = ldap_encode(reply->msg,
|
||||||
|
samba_ldap_control_handlers(),
|
||||||
|
&reply->blob,
|
||||||
|
call);
|
||||||
|
TALLOC_FREE(reply->msg);
|
||||||
|
if (!bret) {
|
||||||
|
DEBUG(0,("Failed to encode ldap reply of type %d: ldap_encode() failed\n",
|
||||||
|
call->replies->msg->type));
|
||||||
|
return NT_STATUS_NO_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
talloc_set_name_const(reply->blob.data,
|
||||||
|
"Outgoing, encoded single LDAP reply");
|
||||||
|
|
||||||
DLIST_ADD_END(call->replies, reply);
|
DLIST_ADD_END(call->replies, reply);
|
||||||
|
return NT_STATUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static NTSTATUS ldapsrv_unwilling(struct ldapsrv_call *call, int error)
|
static NTSTATUS ldapsrv_unwilling(struct ldapsrv_call *call, int error)
|
||||||
@ -525,6 +541,7 @@ static NTSTATUS ldapsrv_SearchRequest(struct ldapsrv_call *call)
|
|||||||
int ldb_ret = -1;
|
int ldb_ret = -1;
|
||||||
unsigned int i, j;
|
unsigned int i, j;
|
||||||
int extended_type = 1;
|
int extended_type = 1;
|
||||||
|
NTSTATUS status;
|
||||||
|
|
||||||
DEBUG(10, ("SearchRequest"));
|
DEBUG(10, ("SearchRequest"));
|
||||||
DEBUGADD(10, (" basedn: %s", req->basedn));
|
DEBUGADD(10, (" basedn: %s", req->basedn));
|
||||||
@ -690,7 +707,11 @@ static NTSTATUS ldapsrv_SearchRequest(struct ldapsrv_call *call)
|
|||||||
ent->attributes[j].values = res->msgs[i]->elements[j].values;
|
ent->attributes[j].values = res->msgs[i]->elements[j].values;
|
||||||
}
|
}
|
||||||
queue_reply:
|
queue_reply:
|
||||||
ldapsrv_queue_reply(call, ent_r);
|
status = ldapsrv_queue_reply(call, ent_r);
|
||||||
|
if (!NT_STATUS_IS_OK(status)) {
|
||||||
|
result = ldb_operr(samdb);
|
||||||
|
goto reply;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (call->notification.busy) {
|
if (call->notification.busy) {
|
||||||
@ -761,8 +782,7 @@ reply:
|
|||||||
|
|
||||||
talloc_free(local_ctx);
|
talloc_free(local_ctx);
|
||||||
|
|
||||||
ldapsrv_queue_reply(call, done_r);
|
return ldapsrv_queue_reply(call, done_r);
|
||||||
return NT_STATUS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NTSTATUS ldapsrv_ModifyRequest(struct ldapsrv_call *call)
|
static NTSTATUS ldapsrv_ModifyRequest(struct ldapsrv_call *call)
|
||||||
@ -866,8 +886,7 @@ reply:
|
|||||||
}
|
}
|
||||||
talloc_free(local_ctx);
|
talloc_free(local_ctx);
|
||||||
|
|
||||||
ldapsrv_queue_reply(call, modify_reply);
|
return ldapsrv_queue_reply(call, modify_reply);
|
||||||
return NT_STATUS_OK;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -955,8 +974,7 @@ static NTSTATUS ldapsrv_AddRequest(struct ldapsrv_call *call)
|
|||||||
}
|
}
|
||||||
talloc_free(local_ctx);
|
talloc_free(local_ctx);
|
||||||
|
|
||||||
ldapsrv_queue_reply(call, add_reply);
|
return ldapsrv_queue_reply(call, add_reply);
|
||||||
return NT_STATUS_OK;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1011,8 +1029,7 @@ static NTSTATUS ldapsrv_DelRequest(struct ldapsrv_call *call)
|
|||||||
|
|
||||||
talloc_free(local_ctx);
|
talloc_free(local_ctx);
|
||||||
|
|
||||||
ldapsrv_queue_reply(call, del_reply);
|
return ldapsrv_queue_reply(call, del_reply);
|
||||||
return NT_STATUS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NTSTATUS ldapsrv_ModifyDNRequest(struct ldapsrv_call *call)
|
static NTSTATUS ldapsrv_ModifyDNRequest(struct ldapsrv_call *call)
|
||||||
@ -1118,8 +1135,7 @@ reply:
|
|||||||
|
|
||||||
talloc_free(local_ctx);
|
talloc_free(local_ctx);
|
||||||
|
|
||||||
ldapsrv_queue_reply(call, modifydn_r);
|
return ldapsrv_queue_reply(call, modifydn_r);
|
||||||
return NT_STATUS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NTSTATUS ldapsrv_CompareRequest(struct ldapsrv_call *call)
|
static NTSTATUS ldapsrv_CompareRequest(struct ldapsrv_call *call)
|
||||||
@ -1190,8 +1206,7 @@ static NTSTATUS ldapsrv_CompareRequest(struct ldapsrv_call *call)
|
|||||||
|
|
||||||
talloc_free(local_ctx);
|
talloc_free(local_ctx);
|
||||||
|
|
||||||
ldapsrv_queue_reply(call, compare_r);
|
return ldapsrv_queue_reply(call, compare_r);
|
||||||
return NT_STATUS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NTSTATUS ldapsrv_AbandonRequest(struct ldapsrv_call *call)
|
static NTSTATUS ldapsrv_AbandonRequest(struct ldapsrv_call *call)
|
||||||
|
@ -677,18 +677,13 @@ static void ldapsrv_call_writev_start(struct ldapsrv_call *call)
|
|||||||
|
|
||||||
/* build all the replies into a single blob */
|
/* build all the replies into a single blob */
|
||||||
while (call->replies) {
|
while (call->replies) {
|
||||||
DATA_BLOB b;
|
|
||||||
bool ret;
|
bool ret;
|
||||||
|
|
||||||
if (!ldap_encode(call->replies->msg, samba_ldap_control_handlers(), &b, call)) {
|
ret = data_blob_append(call,
|
||||||
DEBUG(0,("Failed to encode ldap reply of type %d\n",
|
&blob,
|
||||||
call->replies->msg->type));
|
call->replies->blob.data,
|
||||||
ldapsrv_terminate_connection(conn, "ldap_encode failed");
|
call->replies->blob.length);
|
||||||
return;
|
data_blob_free(&call->replies->blob);
|
||||||
}
|
|
||||||
|
|
||||||
ret = data_blob_append(call, &blob, b.data, b.length);
|
|
||||||
data_blob_free(&b);
|
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
ldapsrv_terminate_connection(conn, "data_blob_append failed");
|
ldapsrv_terminate_connection(conn, "data_blob_append failed");
|
||||||
|
@ -70,6 +70,7 @@ struct ldapsrv_call {
|
|||||||
struct ldapsrv_reply {
|
struct ldapsrv_reply {
|
||||||
struct ldapsrv_reply *prev, *next;
|
struct ldapsrv_reply *prev, *next;
|
||||||
struct ldap_message *msg;
|
struct ldap_message *msg;
|
||||||
|
DATA_BLOB blob;
|
||||||
} *replies;
|
} *replies;
|
||||||
struct iovec out_iov;
|
struct iovec out_iov;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user