summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-06-15 00:27:51 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:18:12 -0500
commitc0947b0d7f809f5139fbfcdbd618ed7b0a77d2be (patch)
tree7c0d7391b8f27d55e40b22f2c16315356e10a167
parent74a3621089d4d1e9ba4c1a02e44247d1cff29200 (diff)
downloadsamba-c0947b0d7f809f5139fbfcdbd618ed7b0a77d2be.tar.gz
samba-c0947b0d7f809f5139fbfcdbd618ed7b0a77d2be.tar.bz2
samba-c0947b0d7f809f5139fbfcdbd618ed7b0a77d2be.zip
r7593: simplified the memory management in the ldap code. Having a mem_ctx
element in a structure is not necessary any more. (This used to be commit 912d0427f52eac811b27bf7e385b0642f7dc7f53)
-rw-r--r--source4/ldap_server/ldap_backend.c32
-rw-r--r--source4/ldap_server/ldap_bind.c12
-rw-r--r--source4/ldap_server/ldap_hacked_ldb.c20
-rw-r--r--source4/ldap_server/ldap_rootdse.c4
-rw-r--r--source4/ldap_server/ldap_server.c14
-rw-r--r--source4/ldap_server/ldap_server.h4
-rw-r--r--source4/ldap_server/ldap_simple_ldb.c17
-rw-r--r--source4/libcli/cldap/cldap.c75
-rw-r--r--source4/libcli/ldap/ldap.c72
-rw-r--r--source4/libcli/ldap/ldap.h2
-rw-r--r--source4/libcli/ldap/ldap_client.c34
-rw-r--r--source4/libcli/ldap/ldap_ldif.c16
-rw-r--r--source4/torture/ldap/basic.c8
13 files changed, 156 insertions, 154 deletions
diff --git a/source4/ldap_server/ldap_backend.c b/source4/ldap_server/ldap_backend.c
index 1c2ba87018..6ac9839e29 100644
--- a/source4/ldap_server/ldap_backend.c
+++ b/source4/ldap_server/ldap_backend.c
@@ -32,12 +32,16 @@ struct ldapsrv_reply *ldapsrv_init_reply(struct ldapsrv_call *call, uint8_t type
if (!reply) {
return NULL;
}
+ reply->msg = talloc(reply, struct ldap_message);
+ if (reply->msg == NULL) {
+ talloc_free(reply);
+ return NULL;
+ }
reply->prev = reply->next = NULL;
reply->state = LDAPSRV_REPLY_STATE_NEW;
- reply->msg.messageid = call->request.messageid;
- reply->msg.type = type;
- reply->msg.mem_ctx = reply;
+ reply->msg->messageid = call->request->messageid;
+ reply->msg->type = type;
return reply;
}
@@ -63,14 +67,14 @@ NTSTATUS ldapsrv_unwilling(struct ldapsrv_call *call, int error)
struct ldapsrv_reply *reply;
struct ldap_ExtendedResponse *r;
- DEBUG(10,("Unwilling type[%d] id[%d]\n", call->request.type, call->request.messageid));
+ DEBUG(10,("Unwilling type[%d] id[%d]\n", call->request->type, call->request->messageid));
reply = ldapsrv_init_reply(call, LDAP_TAG_ExtendedResponse);
if (!reply) {
return NT_STATUS_NO_MEMORY;
}
- r = &reply->msg.r.ExtendedResponse;
+ r = &reply->msg->r.ExtendedResponse;
r->response.resultcode = error;
r->response.dn = NULL;
r->response.errormessage = NULL;
@@ -84,7 +88,7 @@ NTSTATUS ldapsrv_unwilling(struct ldapsrv_call *call, int error)
static NTSTATUS ldapsrv_SearchRequest(struct ldapsrv_call *call)
{
- struct ldap_SearchRequest *req = &call->request.r.SearchRequest;
+ struct ldap_SearchRequest *req = &call->request->r.SearchRequest;
struct ldapsrv_partition *part;
DEBUG(10, ("SearchRequest"));
@@ -102,7 +106,7 @@ static NTSTATUS ldapsrv_SearchRequest(struct ldapsrv_call *call)
return NT_STATUS_NO_MEMORY;
}
- done = &done_r->msg.r.SearchResultDone;
+ done = &done_r->msg->r.SearchResultDone;
done->resultcode = 53;
done->dn = NULL;
done->errormessage = NULL;
@@ -116,7 +120,7 @@ static NTSTATUS ldapsrv_SearchRequest(struct ldapsrv_call *call)
static NTSTATUS ldapsrv_ModifyRequest(struct ldapsrv_call *call)
{
- struct ldap_ModifyRequest *req = &call->request.r.ModifyRequest;
+ struct ldap_ModifyRequest *req = &call->request->r.ModifyRequest;
struct ldapsrv_partition *part;
DEBUG(10, ("ModifyRequest"));
@@ -133,7 +137,7 @@ static NTSTATUS ldapsrv_ModifyRequest(struct ldapsrv_call *call)
static NTSTATUS ldapsrv_AddRequest(struct ldapsrv_call *call)
{
- struct ldap_AddRequest *req = &call->request.r.AddRequest;
+ struct ldap_AddRequest *req = &call->request->r.AddRequest;
struct ldapsrv_partition *part;
DEBUG(10, ("AddRequest"));
@@ -150,7 +154,7 @@ static NTSTATUS ldapsrv_AddRequest(struct ldapsrv_call *call)
static NTSTATUS ldapsrv_DelRequest(struct ldapsrv_call *call)
{
- struct ldap_DelRequest *req = &call->request.r.DelRequest;
+ struct ldap_DelRequest *req = &call->request->r.DelRequest;
struct ldapsrv_partition *part;
DEBUG(10, ("DelRequest"));
@@ -167,7 +171,7 @@ static NTSTATUS ldapsrv_DelRequest(struct ldapsrv_call *call)
static NTSTATUS ldapsrv_ModifyDNRequest(struct ldapsrv_call *call)
{
- struct ldap_ModifyDNRequest *req = &call->request.r.ModifyDNRequest;
+ struct ldap_ModifyDNRequest *req = &call->request->r.ModifyDNRequest;
struct ldapsrv_partition *part;
DEBUG(10, ("ModifyDNRequrest"));
@@ -185,7 +189,7 @@ static NTSTATUS ldapsrv_ModifyDNRequest(struct ldapsrv_call *call)
static NTSTATUS ldapsrv_CompareRequest(struct ldapsrv_call *call)
{
- struct ldap_CompareRequest *req = &call->request.r.CompareRequest;
+ struct ldap_CompareRequest *req = &call->request->r.CompareRequest;
struct ldapsrv_partition *part;
DEBUG(10, ("CompareRequest"));
@@ -219,14 +223,14 @@ static NTSTATUS ldapsrv_ExtendedRequest(struct ldapsrv_call *call)
return NT_STATUS_NO_MEMORY;
}
- ZERO_STRUCT(reply->msg.r);
+ ZERO_STRUCT(reply->msg->r);
return ldapsrv_queue_reply(call, reply);
}
NTSTATUS ldapsrv_do_call(struct ldapsrv_call *call)
{
- switch(call->request.type) {
+ switch(call->request->type) {
case LDAP_TAG_BindRequest:
return ldapsrv_BindRequest(call);
case LDAP_TAG_UnbindRequest:
diff --git a/source4/ldap_server/ldap_bind.c b/source4/ldap_server/ldap_bind.c
index 3b14606439..55ce6ed24d 100644
--- a/source4/ldap_server/ldap_bind.c
+++ b/source4/ldap_server/ldap_bind.c
@@ -25,7 +25,7 @@
static NTSTATUS ldapsrv_BindSimple(struct ldapsrv_call *call)
{
- struct ldap_BindRequest *req = &call->request.r.BindRequest;
+ struct ldap_BindRequest *req = &call->request->r.BindRequest;
struct ldapsrv_reply *reply;
struct ldap_BindResponse *resp;
@@ -36,7 +36,7 @@ static NTSTATUS ldapsrv_BindSimple(struct ldapsrv_call *call)
return NT_STATUS_NO_MEMORY;
}
- resp = &reply->msg.r.BindResponse;
+ resp = &reply->msg->r.BindResponse;
resp->response.resultcode = 0;
resp->response.dn = NULL;
resp->response.errormessage = NULL;
@@ -48,7 +48,7 @@ static NTSTATUS ldapsrv_BindSimple(struct ldapsrv_call *call)
static NTSTATUS ldapsrv_BindSASL(struct ldapsrv_call *call)
{
- struct ldap_BindRequest *req = &call->request.r.BindRequest;
+ struct ldap_BindRequest *req = &call->request->r.BindRequest;
struct ldapsrv_reply *reply;
struct ldap_BindResponse *resp;
struct ldapsrv_connection *conn;
@@ -92,7 +92,7 @@ reply:
if (!reply) {
return NT_STATUS_NO_MEMORY;
}
- resp = &reply->msg.r.BindResponse;
+ resp = &reply->msg->r.BindResponse;
conn = call->conn;
@@ -142,7 +142,7 @@ reply:
NTSTATUS ldapsrv_BindRequest(struct ldapsrv_call *call)
{
- struct ldap_BindRequest *req = &call->request.r.BindRequest;
+ struct ldap_BindRequest *req = &call->request->r.BindRequest;
struct ldapsrv_reply *reply;
struct ldap_BindResponse *resp;
@@ -158,7 +158,7 @@ NTSTATUS ldapsrv_BindRequest(struct ldapsrv_call *call)
return NT_STATUS_NO_MEMORY;
}
- resp = &reply->msg.r.BindResponse;
+ resp = &reply->msg->r.BindResponse;
resp->response.resultcode = 7;
resp->response.dn = NULL;
resp->response.errormessage = talloc_asprintf(reply, "Bad AuthenticationChoice [%d]", req->mechanism);
diff --git a/source4/ldap_server/ldap_hacked_ldb.c b/source4/ldap_server/ldap_hacked_ldb.c
index 154211ba63..e00ed65f29 100644
--- a/source4/ldap_server/ldap_hacked_ldb.c
+++ b/source4/ldap_server/ldap_hacked_ldb.c
@@ -253,7 +253,7 @@ static NTSTATUS hacked_wellknown_Search(struct ldapsrv_partition *partition, str
ent_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultEntry);
NT_STATUS_HAVE_NO_MEMORY(ent_r);
- ent = &ent_r->msg.r.SearchResultEntry;
+ ent = &ent_r->msg->r.SearchResultEntry;
ent->dn = talloc_steal(ent_r, wkdn);
DEBUG(0,("hacked result [0] dn: %s\n", ent->dn));
ent->num_attributes = 0;
@@ -269,7 +269,7 @@ static NTSTATUS hacked_wellknown_Search(struct ldapsrv_partition *partition, str
DEBUG(10,("hacked_Search: results: [%d]\n",count));
- done = &done_r->msg.r.SearchResultDone;
+ done = &done_r->msg->r.SearchResultDone;
done->dn = NULL;
done->resultcode = LDAP_SUCCESS;
done->errormessage = NULL;
@@ -346,7 +346,7 @@ DEBUGADD(0,("hacked filter: %s\n", ldb_filter_from_tree(r, r->tree)));
ent_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultEntry);
NT_STATUS_HAVE_NO_MEMORY(ent_r);
- ent = &ent_r->msg.r.SearchResultEntry;
+ ent = &ent_r->msg->r.SearchResultEntry;
ent->dn = talloc_steal(ent_r, res[0]->dn);
DEBUG(0,("hacked result [0] dn: %s\n", ent->dn));
ent->num_attributes = 0;
@@ -394,7 +394,7 @@ queue_reply:
ent_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultEntry);
NT_STATUS_HAVE_NO_MEMORY(ent_r);
- ent = &ent_r->msg.r.SearchResultEntry;
+ ent = &ent_r->msg->r.SearchResultEntry;
ent->dn = talloc_steal(ent_r, res[i]->dn);
DEBUG(0,("hacked result [%d] dn: %s\n", i, ent->dn));
ent->num_attributes = 0;
@@ -457,7 +457,7 @@ queue_reply2:
errstr = ldb_errstring(samdb);
}
- done = &done_r->msg.r.SearchResultDone;
+ done = &done_r->msg->r.SearchResultDone;
done->dn = NULL;
done->resultcode = result;
done->errormessage = (errstr?talloc_strdup(done_r,errstr):NULL);;
@@ -700,7 +700,7 @@ reply:
}
}
- add_result = &add_reply->msg.r.AddResponse;
+ add_result = &add_reply->msg->r.AddResponse;
add_result->dn = NULL;
add_result->resultcode = result;
add_result->errormessage = (errstr?talloc_strdup(add_reply,errstr):NULL);
@@ -752,7 +752,7 @@ reply:
}
}
- del_result = &del_reply->msg.r.DelResponse;
+ del_result = &del_reply->msg->r.DelResponse;
del_result->dn = NULL;
del_result->resultcode = result;
del_result->errormessage = (errstr?talloc_strdup(del_reply,errstr):NULL);
@@ -867,7 +867,7 @@ reply:
}
}
- modify_result = &modify_reply->msg.r.AddResponse;
+ modify_result = &modify_reply->msg->r.AddResponse;
modify_result->dn = NULL;
modify_result->resultcode = result;
modify_result->errormessage = (errstr?talloc_strdup(modify_reply,errstr):NULL);
@@ -936,7 +936,7 @@ reply:
}
}
- compare = &compare_r->msg.r.CompareResponse;
+ compare = &compare_r->msg->r.CompareResponse;
compare->dn = NULL;
compare->resultcode = result;
compare->errormessage = (errstr?talloc_strdup(compare_r,errstr):NULL);
@@ -1033,7 +1033,7 @@ reply:
}
}
- modifydn = &modifydn_r->msg.r.ModifyDNResponse;
+ modifydn = &modifydn_r->msg->r.ModifyDNResponse;
modifydn->dn = NULL;
modifydn->resultcode = result;
modifydn->errormessage = (errstr?talloc_strdup(modifydn_r,errstr):NULL);
diff --git a/source4/ldap_server/ldap_rootdse.c b/source4/ldap_server/ldap_rootdse.c
index 63206436a1..a754601279 100644
--- a/source4/ldap_server/ldap_rootdse.c
+++ b/source4/ldap_server/ldap_rootdse.c
@@ -338,7 +338,7 @@ static NTSTATUS rootdse_Search(struct ldapsrv_partition *partition, struct ldaps
ent_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultEntry);
NT_STATUS_HAVE_NO_MEMORY(ent_r);
- ent = &ent_r->msg.r.SearchResultEntry;
+ ent = &ent_r->msg->r.SearchResultEntry;
ent->dn = "";
ent->num_attributes = 0;
ent->attributes = NULL;
@@ -398,7 +398,7 @@ queue_reply:
errstr = ldb_errstring(rootdsedb->ldb);
}
- done = &done_r->msg.r.SearchResultDone;
+ done = &done_r->msg->r.SearchResultDone;
done->dn = NULL;
done->resultcode = result;
done->errormessage = (errstr?talloc_strdup(done_r,errstr):NULL);;
diff --git a/source4/ldap_server/ldap_server.c b/source4/ldap_server/ldap_server.c
index 9f62d72e2c..9c5f5fccc8 100644
--- a/source4/ldap_server/ldap_server.c
+++ b/source4/ldap_server/ldap_server.c
@@ -305,7 +305,7 @@ NTSTATUS ldapsrv_do_responses(struct ldapsrv_connection *conn)
for (call=conn->calls; call; call=next_call) {
for (reply=call->replies; reply; reply=next_reply) {
- if (!ldap_encode_to_buf(&reply->msg, &conn->out_buffer)) {
+ if (!ldap_encode_to_buf(reply->msg, &conn->out_buffer)) {
return NT_STATUS_FOOBAR;
}
next_reply = reply->next;
@@ -375,18 +375,22 @@ static void ldapsrv_recv(struct stream_connection *conn, uint16_t flags)
return;
}
- call = talloc(ldap_conn, struct ldapsrv_call);
+ call = talloc_zero(ldap_conn, struct ldapsrv_call);
if (!call) {
ldapsrv_terminate_connection(ldap_conn, "no memory");
return;
}
- ZERO_STRUCTP(call);
+ call->request = talloc_zero(call, struct ldap_message);
+ if (call->request == NULL) {
+ ldapsrv_terminate_connection(ldap_conn, "no memory");
+ return;
+ }
+
call->state = LDAPSRV_CALL_STATE_NEW;
call->conn = ldap_conn;
- call->request.mem_ctx = call;
- if (!ldap_decode(&data, &call->request)) {
+ if (!ldap_decode(&data, call->request)) {
dump_data(0,buf, msg_length);
asn1_free(&data);
ldapsrv_terminate_connection(ldap_conn, "ldap_decode() failed");
diff --git a/source4/ldap_server/ldap_server.h b/source4/ldap_server/ldap_server.h
index 0a16394c09..890e2f3003 100644
--- a/source4/ldap_server/ldap_server.h
+++ b/source4/ldap_server/ldap_server.h
@@ -47,12 +47,12 @@ struct ldapsrv_call {
struct ldapsrv_connection *conn;
- struct ldap_message request;
+ struct ldap_message *request;
struct ldapsrv_reply {
struct ldapsrv_reply *prev,*next;
enum ldapsrv_reply_state state;
- struct ldap_message msg;
+ struct ldap_message *msg;
} *replies;
};
diff --git a/source4/ldap_server/ldap_simple_ldb.c b/source4/ldap_server/ldap_simple_ldb.c
index d6b84a37ba..1106919891 100644
--- a/source4/ldap_server/ldap_simple_ldb.c
+++ b/source4/ldap_server/ldap_simple_ldb.c
@@ -90,6 +90,9 @@ static NTSTATUS sldb_Search(struct ldapsrv_partition *partition, struct ldapsrv_
attrs[i] = NULL;
}
+ DEBUG(5,("ldb_search_bytree dn=%s filter=%s\n",
+ basedn->dn, ldb_filter_from_tree(call, r->tree)));
+
count = ldb_search_bytree(samdb, basedn->dn, scope, r->tree, attrs, &res);
talloc_steal(samdb, res);
@@ -97,7 +100,7 @@ static NTSTATUS sldb_Search(struct ldapsrv_partition *partition, struct ldapsrv_
ent_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultEntry);
NT_STATUS_HAVE_NO_MEMORY(ent_r);
- ent = &ent_r->msg.r.SearchResultEntry;
+ ent = &ent_r->msg->r.SearchResultEntry;
ent->dn = talloc_steal(ent_r, res[i]->dn);
ent->num_attributes = 0;
ent->attributes = NULL;
@@ -151,7 +154,7 @@ reply:
}
}
- done = &done_r->msg.r.SearchResultDone;
+ done = &done_r->msg->r.SearchResultDone;
done->dn = NULL;
done->resultcode = result;
done->errormessage = (errstr?talloc_strdup(done_r,errstr):NULL);
@@ -250,7 +253,7 @@ reply:
}
}
- add_result = &add_reply->msg.r.AddResponse;
+ add_result = &add_reply->msg->r.AddResponse;
add_result->dn = NULL;
add_result->resultcode = result;
add_result->errormessage = (errstr?talloc_strdup(add_reply,errstr):NULL);
@@ -302,7 +305,7 @@ reply:
}
}
- del_result = &del_reply->msg.r.DelResponse;
+ del_result = &del_reply->msg->r.DelResponse;
del_result->dn = NULL;
del_result->resultcode = result;
del_result->errormessage = (errstr?talloc_strdup(del_reply,errstr):NULL);
@@ -412,7 +415,7 @@ reply:
}
}
- modify_result = &modify_reply->msg.r.AddResponse;
+ modify_result = &modify_reply->msg->r.AddResponse;
modify_result->dn = NULL;
modify_result->resultcode = result;
modify_result->errormessage = (errstr?talloc_strdup(modify_reply,errstr):NULL);
@@ -481,7 +484,7 @@ reply:
}
}
- compare = &compare_r->msg.r.CompareResponse;
+ compare = &compare_r->msg->r.CompareResponse;
compare->dn = NULL;
compare->resultcode = result;
compare->errormessage = (errstr?talloc_strdup(compare_r,errstr):NULL);
@@ -578,7 +581,7 @@ reply:
}
}
- modifydn = &modifydn_r->msg.r.ModifyDNResponse;
+ modifydn = &modifydn_r->msg->r.ModifyDNResponse;
modifydn->dn = NULL;
modifydn->resultcode = result;
modifydn->errormessage = (errstr?talloc_strdup(modifydn_r,errstr):NULL);
diff --git a/source4/libcli/cldap/cldap.c b/source4/libcli/cldap/cldap.c
index 71326caa37..1674031c99 100644
--- a/source4/libcli/cldap/cldap.c
+++ b/source4/libcli/cldap/cldap.c
@@ -68,7 +68,7 @@ static void cldap_socket_recv(struct cldap_socket *cldap)
DATA_BLOB blob;
size_t nread, dsize;
struct asn1_data asn1;
- struct ldap_message ldap_msg;
+ struct ldap_message *ldap_msg;
struct cldap_request *req;
status = socket_pending(cldap->sock, &dsize);
@@ -102,24 +102,27 @@ static void cldap_socket_recv(struct cldap_socket *cldap)
}
talloc_steal(tmp_ctx, asn1.data);
- ZERO_STRUCT(ldap_msg);
- ldap_msg.mem_ctx = tmp_ctx;
+ ldap_msg = talloc(tmp_ctx, struct ldap_message);
+ if (ldap_msg == NULL) {
+ talloc_free(tmp_ctx);
+ return;
+ }
/* this initial decode is used to find the message id */
- if (!ldap_decode(&asn1, &ldap_msg)) {
+ if (!ldap_decode(&asn1, ldap_msg)) {
DEBUG(2,("Failed to decode ldap message\n"));
talloc_free(tmp_ctx);
return;
}
/* find the pending request */
- req = idr_find(cldap->idr, ldap_msg.messageid);
+ req = idr_find(cldap->idr, ldap_msg->messageid);
if (req == NULL) {
if (cldap->incoming.handler) {
- cldap->incoming.handler(cldap, &ldap_msg, src_addr, src_port);
+ cldap->incoming.handler(cldap, ldap_msg, src_addr, src_port);
} else {
DEBUG(2,("Mismatched cldap reply %u from %s:%d\n",
- ldap_msg.messageid, src_addr, src_port));
+ ldap_msg->messageid, src_addr, src_port));
}
talloc_free(tmp_ctx);
return;
@@ -291,7 +294,7 @@ NTSTATUS cldap_set_incoming_handler(struct cldap_socket *cldap,
struct cldap_request *cldap_search_send(struct cldap_socket *cldap,
struct cldap_search *io)
{
- struct ldap_message msg;
+ struct ldap_message *msg;
struct cldap_request *req;
struct ldap_SearchRequest *search;
@@ -313,12 +316,13 @@ struct cldap_request *cldap_search_send(struct cldap_socket *cldap,
talloc_set_destructor(req, cldap_request_destructor);
- msg.mem_ctx = req;
- msg.messageid = req->message_id;
- msg.type = LDAP_TAG_SearchRequest;
- msg.num_controls = 0;
- msg.controls = NULL;
- search = &msg.r.SearchRequest;
+ msg = talloc(req, struct ldap_message);
+ if (msg == NULL) goto failed;
+ msg->messageid = req->message_id;
+ msg->type = LDAP_TAG_SearchRequest;
+ msg->num_controls = 0;
+ msg->controls = NULL;
+ search = &msg->r.SearchRequest;
search->basedn = "";
search->scope = LDAP_SEARCH_SCOPE_BASE;
@@ -333,7 +337,7 @@ struct cldap_request *cldap_search_send(struct cldap_socket *cldap,
goto failed;
}
- if (!ldap_encode(&msg, &req->encoded)) {
+ if (!ldap_encode(msg, &req->encoded)) {
DEBUG(0,("Failed to encode cldap message to %s:%d\n",
req->dest_addr, req->dest_port));
goto failed;
@@ -357,7 +361,7 @@ failed:
*/
NTSTATUS cldap_reply_send(struct cldap_socket *cldap, struct cldap_reply *io)
{
- struct ldap_message msg;
+ struct ldap_message *msg;
struct cldap_request *req;
DATA_BLOB blob1, blob2;
NTSTATUS status = NT_STATUS_NO_MEMORY;
@@ -375,16 +379,17 @@ NTSTATUS cldap_reply_send(struct cldap_socket *cldap, struct cldap_reply *io)
talloc_set_destructor(req, cldap_request_destructor);
- msg.mem_ctx = req;
- msg.messageid = io->messageid;
- msg.num_controls = 0;
- msg.controls = NULL;
+ msg = talloc(req, struct ldap_message);
+ if (msg == NULL) goto failed;
+ msg->messageid = io->messageid;
+ msg->num_controls = 0;
+ msg->controls = NULL;
if (io->response) {
- msg.type = LDAP_TAG_SearchResultEntry;
- msg.r.SearchResultEntry = *io->response;
+ msg->type = LDAP_TAG_SearchResultEntry;
+ msg->r.SearchResultEntry = *io->response;
- if (!ldap_encode(&msg, &blob1)) {
+ if (!ldap_encode(msg, &blob1)) {
DEBUG(0,("Failed to encode cldap message to %s:%d\n",
req->dest_addr, req->dest_port));
status = NT_STATUS_INVALID_PARAMETER;
@@ -395,10 +400,10 @@ NTSTATUS cldap_reply_send(struct cldap_socket *cldap, struct cldap_reply *io)
blob1 = data_blob(NULL, 0);
}
- msg.type = LDAP_TAG_SearchResultDone;
- msg.r.SearchResultDone = *io->result;
+ msg->type = LDAP_TAG_SearchResultDone;
+ msg->r.SearchResultDone = *io->result;
- if (!ldap_encode(&msg, &blob2)) {
+ if (!ldap_encode(msg, &blob2)) {
DEBUG(0,("Failed to encode cldap message to %s:%d\n",
req->dest_addr, req->dest_port));
status = NT_STATUS_INVALID_PARAMETER;
@@ -430,7 +435,7 @@ NTSTATUS cldap_search_recv(struct cldap_request *req,
TALLOC_CTX *mem_ctx,
struct cldap_search *io)
{
- struct ldap_message ldap_msg;
+ struct ldap_message *ldap_msg;
if (req == NULL) {
return NT_STATUS_NO_MEMORY;
@@ -448,10 +453,10 @@ NTSTATUS cldap_search_recv(struct cldap_request *req,
return NT_STATUS_IO_TIMEOUT;
}
- ZERO_STRUCT(ldap_msg);
- ldap_msg.mem_ctx = mem_ctx;
+ ldap_msg = talloc(mem_ctx, struct ldap_message);
+ NT_STATUS_HAVE_NO_MEMORY(ldap_msg);
- if (!ldap_decode(&req->asn1, &ldap_msg)) {
+ if (!ldap_decode(&req->asn1, ldap_msg)) {
talloc_free(req);
return NT_STATUS_INVALID_PARAMETER;
}
@@ -459,26 +464,26 @@ NTSTATUS cldap_search_recv(struct cldap_request *req,
ZERO_STRUCT(io->out);
/* the first possible form has a search result in first place */
- if (ldap_msg.type == LDAP_TAG_SearchResultEntry) {
+ if (ldap_msg->type == LDAP_TAG_SearchResultEntry) {
io->out.response = talloc(mem_ctx, struct ldap_SearchResEntry);
NT_STATUS_HAVE_NO_MEMORY(io->out.response);
- *io->out.response = ldap_msg.r.SearchResultEntry;
+ *io->out.response = ldap_msg->r.SearchResultEntry;
/* decode the 2nd part */
- if (!ldap_decode(&req->asn1, &ldap_msg)) {
+ if (!ldap_decode(&req->asn1, ldap_msg)) {
talloc_free(req);
return NT_STATUS_INVALID_PARAMETER;
}
}
- if (ldap_msg.type != LDAP_TAG_SearchResultDone) {
+ if (ldap_msg->type != LDAP_TAG_SearchResultDone) {
talloc_free(req);
return NT_STATUS_UNEXPECTED_NETWORK_ERROR;
}
io->out.result = talloc(mem_ctx, struct ldap_Result);
NT_STATUS_HAVE_NO_MEMORY(io->out.result);
- *io->out.result = ldap_msg.r.SearchResultDone;
+ *io->out.result = ldap_msg->r.SearchResultDone;
talloc_free(req);
return NT_STATUS_OK;
diff --git a/source4/libcli/ldap/ldap.c b/source4/libcli/ldap/ldap.c
index 048a60317a..0ac17c39bd 100644
--- a/source4/libcli/ldap/ldap.c
+++ b/source4/libcli/ldap/ldap.c
@@ -647,7 +647,7 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
msg->type = LDAP_TAG_BindRequest;
asn1_start_tag(data, tag);
asn1_read_Integer(data, &r->version);
- asn1_read_OctetString_talloc(msg->mem_ctx, data, &r->dn);
+ asn1_read_OctetString_talloc(msg, data, &r->dn);
if (asn1_peek_tag(data, ASN1_CONTEXT_SIMPLE(0))) {
int pwlen;
r->creds.password = "";
@@ -655,7 +655,7 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
asn1_start_tag(data, ASN1_CONTEXT_SIMPLE(0));
pwlen = asn1_tag_remaining(data);
if (pwlen != 0) {
- char *pw = talloc_size(msg->mem_ctx, pwlen+1);
+ char *pw = talloc_size(msg, pwlen+1);
asn1_read(data, pw, pwlen);
pw[pwlen] = '\0';
r->creds.password = pw;
@@ -664,10 +664,10 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
} else if (asn1_peek_tag(data, ASN1_CONTEXT(3))){
asn1_start_tag(data, ASN1_CONTEXT(3));
r->mechanism = LDAP_AUTH_MECH_SASL;
- asn1_read_OctetString_talloc(msg->mem_ctx, data, &r->creds.SASL.mechanism);
+ asn1_read_OctetString_talloc(msg, data, &r->creds.SASL.mechanism);
asn1_read_OctetString(data, &r->creds.SASL.secblob);
if (r->creds.SASL.secblob.data) {
- talloc_steal(msg->mem_ctx, r->creds.SASL.secblob.data);
+ talloc_steal(msg, r->creds.SASL.secblob.data);
}
asn1_end_tag(data);
}
@@ -679,11 +679,11 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
struct ldap_BindResponse *r = &msg->r.BindResponse;
msg->type = LDAP_TAG_BindResponse;
asn1_start_tag(data, tag);
- ldap_decode_response(msg->mem_ctx, data, &r->response);
+ ldap_decode_response(msg, data, &r->response);
if (asn1_peek_tag(data, ASN1_CONTEXT_SIMPLE(7))) {
DATA_BLOB tmp_blob = data_blob(NULL, 0);
asn1_read_ContextSimple(data, 7, &tmp_blob);
- r->SASL.secblob = data_blob_talloc(msg->mem_ctx, tmp_blob.data, tmp_blob.length);
+ r->SASL.secblob = data_blob_talloc(msg, tmp_blob.data, tmp_blob.length);
data_blob_free(&tmp_blob);
} else {
r->SASL.secblob = data_blob(NULL, 0);
@@ -703,14 +703,14 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
struct ldap_SearchRequest *r = &msg->r.SearchRequest;
msg->type = LDAP_TAG_SearchRequest;
asn1_start_tag(data, tag);
- asn1_read_OctetString_talloc(msg->mem_ctx, data, &r->basedn);
+ asn1_read_OctetString_talloc(msg, data, &r->basedn);
asn1_read_enumerated(data, (int *)&(r->scope));
asn1_read_enumerated(data, (int *)&(r->deref));
asn1_read_Integer(data, &r->sizelimit);
asn1_read_Integer(data, &r->timelimit);
asn1_read_BOOLEAN(data, &r->attributesonly);
- r->tree = ldap_decode_filter_tree(msg->mem_ctx, data);
+ r->tree = ldap_decode_filter_tree(msg, data);
if (r->tree == NULL) {
return False;
}
@@ -722,10 +722,10 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
while (asn1_tag_remaining(data) > 0) {
const char *attr;
- if (!asn1_read_OctetString_talloc(msg->mem_ctx, data,
+ if (!asn1_read_OctetString_talloc(msg, data,
&attr))
return False;
- if (!add_string_to_array(msg->mem_ctx, attr,
+ if (!add_string_to_array(msg, attr,
&r->attributes,
&r->num_attributes))
return False;
@@ -742,8 +742,8 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
r->attributes = NULL;
r->num_attributes = 0;
asn1_start_tag(data, tag);
- asn1_read_OctetString_talloc(msg->mem_ctx, data, &r->dn);
- ldap_decode_attribs(msg->mem_ctx, data, &r->attributes,
+ asn1_read_OctetString_talloc(msg, data, &r->dn);
+ ldap_decode_attribs(msg, data, &r->attributes,
&r->num_attributes);
asn1_end_tag(data);
break;
@@ -753,7 +753,7 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
struct ldap_Result *r = &msg->r.SearchResultDone;
msg->type = LDAP_TAG_SearchResultDone;
asn1_start_tag(data, tag);
- ldap_decode_response(msg->mem_ctx, data, r);
+ ldap_decode_response(msg, data, r);
asn1_end_tag(data);
break;
}
@@ -762,7 +762,7 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
struct ldap_SearchResRef *r = &msg->r.SearchResultReference;
msg->type = LDAP_TAG_SearchResultReference;
asn1_start_tag(data, tag);
- asn1_read_OctetString_talloc(msg->mem_ctx, data, &r->referral);
+ asn1_read_OctetString_talloc(msg, data, &r->referral);
asn1_end_tag(data);
break;
}
@@ -771,7 +771,7 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
struct ldap_ModifyRequest *r = &msg->r.ModifyRequest;
msg->type = LDAP_TAG_ModifyRequest;
asn1_start_tag(data, ASN1_APPLICATION(LDAP_TAG_ModifyRequest));
- asn1_read_OctetString_talloc(msg->mem_ctx, data, &r->dn);
+ asn1_read_OctetString_talloc(msg, data, &r->dn);
asn1_start_tag(data, ASN1_SEQUENCE(0));
r->num_mods = 0;
@@ -784,9 +784,9 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
asn1_start_tag(data, ASN1_SEQUENCE(0));
asn1_read_enumerated(data, &v);
mod.type = v;
- ldap_decode_attrib(msg->mem_ctx, data, &mod.attrib);
+ ldap_decode_attrib(msg, data, &mod.attrib);
asn1_end_tag(data);
- if (!add_mod_to_array_talloc(msg->mem_ctx, &mod,
+ if (!add_mod_to_array_talloc(msg, &mod,
&r->mods, &r->num_mods))
break;
}
@@ -800,7 +800,7 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
struct ldap_Result *r = &msg->r.ModifyResponse;
msg->type = LDAP_TAG_ModifyResponse;
asn1_start_tag(data, tag);
- ldap_decode_response(msg->mem_ctx, data, r);
+ ldap_decode_response(msg, data, r);
asn1_end_tag(data);
break;
}
@@ -809,11 +809,11 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
struct ldap_AddRequest *r = &msg->r.AddRequest;
msg->type = LDAP_TAG_AddRequest;
asn1_start_tag(data, tag);
- asn1_read_OctetString_talloc(msg->mem_ctx, data, &r->dn);
+ asn1_read_OctetString_talloc(msg, data, &r->dn);
r->attributes = NULL;
r->num_attributes = 0;
- ldap_decode_attribs(msg->mem_ctx, data, &r->attributes,
+ ldap_decode_attribs(msg, data, &r->attributes,
&r->num_attributes);
asn1_end_tag(data);
@@ -824,7 +824,7 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
struct ldap_Result *r = &msg->r.AddResponse;
msg->type = LDAP_TAG_AddResponse;
asn1_start_tag(data, tag);
- ldap_decode_response(msg->mem_ctx, data, r);
+ ldap_decode_response(msg, data, r);
asn1_end_tag(data);
break;
}
@@ -837,7 +837,7 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
asn1_start_tag(data,
ASN1_APPLICATION_SIMPLE(LDAP_TAG_DelRequest));
len = asn1_tag_remaining(data);
- dn = talloc_size(msg->mem_ctx, len+1);
+ dn = talloc_size(msg, len+1);
if (dn == NULL)
break;
asn1_read(data, dn, len);
@@ -851,7 +851,7 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
struct ldap_Result *r = &msg->r.DelResponse;
msg->type = LDAP_TAG_DelResponse;
asn1_start_tag(data, tag);
- ldap_decode_response(msg->mem_ctx, data, r);
+ ldap_decode_response(msg, data, r);
asn1_end_tag(data);
break;
}
@@ -861,8 +861,8 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
msg->type = LDAP_TAG_ModifyDNRequest;
asn1_start_tag(data,
ASN1_APPLICATION(LDAP_TAG_ModifyDNRequest));
- asn1_read_OctetString_talloc(msg->mem_ctx, data, &r->dn);
- asn1_read_OctetString_talloc(msg->mem_ctx, data, &r->newrdn);
+ asn1_read_OctetString_talloc(msg, data, &r->dn);
+ asn1_read_OctetString_talloc(msg, data, &r->newrdn);
asn1_read_BOOLEAN(data, &r->deleteolddn);
r->newsuperior = NULL;
if (asn1_tag_remaining(data) > 0) {
@@ -870,7 +870,7 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
char *newsup;
asn1_start_tag(data, ASN1_CONTEXT_SIMPLE(0));
len = asn1_tag_remaining(data);
- newsup = talloc_size(msg->mem_ctx, len+1);
+ newsup = talloc_size(msg, len+1);
if (newsup == NULL)
break;
asn1_read(data, newsup, len);
@@ -886,7 +886,7 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
struct ldap_Result *r = &msg->r.ModifyDNResponse;
msg->type = LDAP_TAG_ModifyDNResponse;
asn1_start_tag(data, tag);
- ldap_decode_response(msg->mem_ctx, data, r);
+ ldap_decode_response(msg, data, r);
asn1_end_tag(data);
break;
}
@@ -896,12 +896,12 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
msg->type = LDAP_TAG_CompareRequest;
asn1_start_tag(data,
ASN1_APPLICATION(LDAP_TAG_CompareRequest));
- asn1_read_OctetString_talloc(msg->mem_ctx, data, &r->dn);
+ asn1_read_OctetString_talloc(msg, data, &r->dn);
asn1_start_tag(data, ASN1_SEQUENCE(0));
- asn1_read_OctetString_talloc(msg->mem_ctx, data, &r->attribute);
+ asn1_read_OctetString_talloc(msg, data, &r->attribute);
asn1_read_OctetString(data, &r->value);
if (r->value.data) {
- talloc_steal(msg->mem_ctx, r->value.data);
+ talloc_steal(msg, r->value.data);
}
asn1_end_tag(data);
asn1_end_tag(data);
@@ -912,7 +912,7 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
struct ldap_Result *r = &msg->r.CompareResponse;
msg->type = LDAP_TAG_CompareResponse;
asn1_start_tag(data, tag);
- ldap_decode_response(msg->mem_ctx, data, r);
+ ldap_decode_response(msg, data, r);
asn1_end_tag(data);
break;
}
@@ -935,7 +935,7 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
if (!asn1_read_ContextSimple(data, 0, &tmp_blob)) {
return False;
}
- r->oid = blob2string_talloc(msg->mem_ctx, tmp_blob);
+ r->oid = blob2string_talloc(msg, tmp_blob);
data_blob_free(&tmp_blob);
if (!r->oid) {
return False;
@@ -943,7 +943,7 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
if (asn1_peek_tag(data, ASN1_CONTEXT_SIMPLE(1))) {
asn1_read_ContextSimple(data, 1, &tmp_blob);
- r->value = data_blob_talloc(msg->mem_ctx, tmp_blob.data, tmp_blob.length);
+ r->value = data_blob_talloc(msg, tmp_blob.data, tmp_blob.length);
data_blob_free(&tmp_blob);
} else {
r->value = data_blob(NULL, 0);
@@ -957,7 +957,7 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
struct ldap_ExtendedResponse *r = &msg->r.ExtendedResponse;
msg->type = LDAP_TAG_ExtendedResponse;
asn1_start_tag(data, tag);
- ldap_decode_response(msg->mem_ctx, data, &r->response);
+ ldap_decode_response(msg, data, &r->response);
/* I have to come across an operation that actually sends
* something back to really see what's going on. The currently
* needed pwdchange does not send anything back. */
@@ -983,7 +983,7 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
for (i=0; asn1_peek_tag(data, ASN1_SEQUENCE(0)); i++) {
asn1_start_tag(data, ASN1_SEQUENCE(0));
- ctrl = talloc_realloc(msg->mem_ctx, ctrl, struct ldap_Control, i+1);
+ ctrl = talloc_realloc(msg, ctrl, struct ldap_Control, i+1);
if (!ctrl) {
return False;
}
@@ -1000,7 +1000,7 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
if (asn1_peek_tag(data, ASN1_OCTET_STRING)) {
asn1_read_OctetString(data, &ctrl[i].value);
if (ctrl[i].value.data) {
- talloc_steal(msg->mem_ctx, ctrl[i].value.data);
+ talloc_steal(msg, ctrl[i].value.data);
}
}
diff --git a/source4/libcli/ldap/ldap.h b/source4/libcli/ldap/ldap.h
index a44c249e7a..f0f43e65fc 100644
--- a/source4/libcli/ldap/ldap.h
+++ b/source4/libcli/ldap/ldap.h
@@ -252,7 +252,6 @@ struct ldap_Control {
};
struct ldap_message {
- TALLOC_CTX *mem_ctx;
uint32_t messageid;
enum ldap_request_tag type;
union ldap_Request r;
@@ -267,7 +266,6 @@ struct ldap_queue_entry {
};
struct ldap_connection {
- TALLOC_CTX *mem_ctx;
int sock;
int next_msgid;
char *host;
diff --git a/source4/libcli/ldap/ldap_client.c b/source4/libcli/ldap/ldap_client.c
index 8867344de3..6ff8db85a5 100644
--- a/source4/libcli/ldap/ldap_client.c
+++ b/source4/libcli/ldap/ldap_client.c
@@ -312,9 +312,9 @@ static struct ldap_message *new_ldap_simple_bind_msg(struct ldap_connection *con
res->type = LDAP_TAG_BindRequest;
res->r.BindRequest.version = 3;
- res->r.BindRequest.dn = talloc_strdup(res->mem_ctx, dn);
+ res->r.BindRequest.dn = talloc_strdup(res, dn);
res->r.BindRequest.mechanism = LDAP_AUTH_MECH_SIMPLE;
- res->r.BindRequest.creds.password = talloc_strdup(res->mem_ctx, pw);
+ res->r.BindRequest.creds.password = talloc_strdup(res, pw);
return res;
}
@@ -332,7 +332,7 @@ static struct ldap_message *new_ldap_sasl_bind_msg(struct ldap_connection *conn,
res->r.BindRequest.version = 3;
res->r.BindRequest.dn = "";
res->r.BindRequest.mechanism = LDAP_AUTH_MECH_SASL;
- res->r.BindRequest.creds.SASL.mechanism = talloc_strdup(res->mem_ctx, sasl_mechanism);
+ res->r.BindRequest.creds.SASL.mechanism = talloc_strdup(res, sasl_mechanism);
res->r.BindRequest.creds.SASL.secblob = *secblob;
return res;
@@ -348,7 +348,6 @@ static struct ldap_connection *new_ldap_connection(TALLOC_CTX *mem_ctx)
return NULL;
}
- result->mem_ctx = result;
result->next_msgid = 1;
result->outstanding = NULL;
result->searchid = 0;
@@ -372,8 +371,8 @@ struct ldap_connection *ldap_connect(TALLOC_CTX *mem_ctx, const char *url)
return NULL;
}
- ret = ldap_parse_basic_url(conn->mem_ctx, url, &conn->host,
- &conn->port, &conn->ldaps);
+ ret = ldap_parse_basic_url(conn, url, &conn->host,
+ &conn->port, &conn->ldaps);
if (!ret) {
talloc_free(conn);
return NULL;
@@ -398,17 +397,7 @@ struct ldap_connection *ldap_connect(TALLOC_CTX *mem_ctx, const char *url)
struct ldap_message *new_ldap_message(TALLOC_CTX *mem_ctx)
{
- struct ldap_message *result;
-
- result = talloc(mem_ctx, struct ldap_message);
-
- if (!result) {
- return NULL;
- }
-
- result->mem_ctx = result;
-
- return result;
+ return talloc(mem_ctx, struct ldap_message);
}
BOOL ldap_send_msg(struct ldap_connection *conn, struct ldap_message *msg,
@@ -619,7 +608,7 @@ static struct ldap_message *ldap_transaction_sasl(struct ldap_connection *conn,
return NULL;
status = gensec_wrap(conn->gensec,
- req->mem_ctx,
+ req,
&request,
&wrapped);
if (!NT_STATUS_IS_OK(status)) {
@@ -653,7 +642,7 @@ static struct ldap_message *ldap_transaction_sasl(struct ldap_connection *conn,
wrapped.length = len;
status = gensec_unwrap(conn->gensec,
- req->mem_ctx,
+ req,
&wrapped,
&request);
if (!NT_STATUS_IS_OK(status)) {
@@ -661,7 +650,7 @@ static struct ldap_message *ldap_transaction_sasl(struct ldap_connection *conn,
return NULL;
}
- rep = new_ldap_message(req->mem_ctx);
+ rep = new_ldap_message(req);
asn1_load(&asn1, request);
if (!ldap_decode(&asn1, rep)) {
@@ -776,7 +765,7 @@ int ldap_bind_sasl(struct ldap_connection *conn, struct cli_credentials *creds)
goto done;
}
- status = gensec_start_mech_by_sasl_name(conn->gensec, "GSS-SPNEGO");
+ status = gensec_start_mech_by_sasl_name(conn->gensec, "NTLM");
if (!NT_STATUS_IS_OK(status)) {
DEBUG(1, ("Failed to start set GENSEC client SPNEGO mechanism: %s\n",
nt_errstr(status)));
@@ -828,8 +817,7 @@ int ldap_bind_sasl(struct ldap_connection *conn, struct cli_credentials *creds)
}
done:
- if (mem_ctx)
- talloc_free(mem_ctx);
+ talloc_free(mem_ctx);
return result;
}
diff --git a/source4/libcli/ldap/ldap_ldif.c b/source4/libcli/ldap/ldap_ldif.c
index 2489a97748..0e0885c1cc 100644
--- a/source4/libcli/ldap/ldap_ldif.c
+++ b/source4/libcli/ldap/ldap_ldif.c
@@ -212,7 +212,7 @@ static BOOL fill_add_attributes(struct ldap_message *msg, char **chunk)
}
if (attrib == NULL) {
- r->attributes = talloc_realloc(msg->mem_ctx,
+ r->attributes = talloc_realloc(msg,
r->attributes,
struct ldap_attribute,
r->num_attributes+1);
@@ -222,11 +222,11 @@ static BOOL fill_add_attributes(struct ldap_message *msg, char **chunk)
attrib = &(r->attributes[r->num_attributes]);
r->num_attributes += 1;
ZERO_STRUCTP(attrib);
- attrib->name = talloc_strdup(msg->mem_ctx,
+ attrib->name = talloc_strdup(msg,
attr_name);
}
- if (!add_value_to_attrib(msg->mem_ctx, &value, attrib))
+ if (!add_value_to_attrib(msg, &value, attrib))
return False;
}
return True;
@@ -261,7 +261,7 @@ static BOOL fill_mods(struct ldap_message *msg, char **chunk)
struct ldap_mod mod;
mod.type = LDAP_MODIFY_NONE;
- mod.attrib.name = talloc_strdup(msg->mem_ctx, value.data);
+ mod.attrib.name = talloc_strdup(msg, value.data);
if (strequal(attr_name, "add"))
mod.type = LDAP_MODIFY_ADD;
@@ -290,14 +290,14 @@ static BOOL fill_mods(struct ldap_message *msg, char **chunk)
mod.attrib.name));
return False;
}
- if (!add_value_to_attrib(msg->mem_ctx, &value,
+ if (!add_value_to_attrib(msg, &value,
&mod.attrib)) {
DEBUG(3, ("Could not add value\n"));
return False;
}
}
- if (!add_mod_to_array_talloc(msg->mem_ctx, &mod, &r->mods,
+ if (!add_mod_to_array_talloc(msg, &mod, &r->mods,
&r->num_mods))
return False;
}
@@ -370,7 +370,7 @@ static struct ldap_message *ldif_read(TALLOC_CTX *mem_ctx, int (*fgetc_fn)(void
if (msg == NULL)
return NULL;
- chunk = next_chunk(msg->mem_ctx, fgetc_fn, private_data);
+ chunk = next_chunk(msg, fgetc_fn, private_data);
if (!chunk) {
goto failed;
}
@@ -388,7 +388,7 @@ static struct ldap_message *ldif_read(TALLOC_CTX *mem_ctx, int (*fgetc_fn)(void
goto failed;
}
- dn = talloc_strdup(msg->mem_ctx, value.data);
+ dn = talloc_strdup(msg, value.data);
if (next_attr(&s, &attr, &value) != 0) {
goto failed;
diff --git a/source4/torture/ldap/basic.c b/source4/torture/ldap/basic.c
index 931a1ee2cc..97837d9ba8 100644
--- a/source4/torture/ldap/basic.c
+++ b/source4/torture/ldap/basic.c
@@ -97,7 +97,7 @@ static BOOL test_search_rootDSE(struct ldap_connection *conn, char **basedn)
msg->r.SearchRequest.timelimit = 0;
msg->r.SearchRequest.sizelimit = 0;
msg->r.SearchRequest.attributesonly = False;
- msg->r.SearchRequest.tree = ldb_parse_tree(msg->mem_ctx, "(objectclass=*)");
+ msg->r.SearchRequest.tree = ldb_parse_tree(msg, "(objectclass=*)");
msg->r.SearchRequest.num_attributes = 0;
msg->r.SearchRequest.attributes = NULL;
@@ -121,7 +121,7 @@ static BOOL test_search_rootDSE(struct ldap_connection *conn, char **basedn)
(char *)r->attributes[i].values[j].data));
if (!(*basedn) &&
strcasecmp("defaultNamingContext",r->attributes[i].name)==0) {
- *basedn = talloc_asprintf(conn->mem_ctx, "%.*s",
+ *basedn = talloc_asprintf(conn, "%.*s",
r->attributes[i].values[j].length,
(char *)r->attributes[i].values[j].data);
}
@@ -156,9 +156,9 @@ static BOOL test_compare_sasl(struct ldap_connection *conn, const char *basedn)
req->type = LDAP_TAG_CompareRequest;
req->r.CompareRequest.dn = basedn;
- req->r.CompareRequest.attribute = talloc_strdup(req->mem_ctx, "objectClass");
+ req->r.CompareRequest.attribute = talloc_strdup(req, "objectClass");
val = "domain";
- req->r.CompareRequest.value = data_blob_talloc(req->mem_ctx, val, strlen(val));
+ req->r.CompareRequest.value = data_blob_talloc(req, val, strlen(val));
rep = ldap_transaction(conn, req);
if (!rep) {