1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-02 00:22:11 +03:00

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 912d0427f5)
This commit is contained in:
Andrew Tridgell
2005-06-15 00:27:51 +00:00
committed by Gerald (Jerry) Carter
parent 74a3621089
commit c0947b0d7f
13 changed files with 156 additions and 154 deletions

View File

@ -32,12 +32,16 @@ struct ldapsrv_reply *ldapsrv_init_reply(struct ldapsrv_call *call, uint8_t type
if (!reply) { if (!reply) {
return NULL; return NULL;
} }
reply->msg = talloc(reply, struct ldap_message);
if (reply->msg == NULL) {
talloc_free(reply);
return NULL;
}
reply->prev = reply->next = NULL; reply->prev = reply->next = NULL;
reply->state = LDAPSRV_REPLY_STATE_NEW; reply->state = LDAPSRV_REPLY_STATE_NEW;
reply->msg.messageid = call->request.messageid; reply->msg->messageid = call->request->messageid;
reply->msg.type = type; reply->msg->type = type;
reply->msg.mem_ctx = reply;
return reply; return reply;
} }
@ -63,14 +67,14 @@ NTSTATUS ldapsrv_unwilling(struct ldapsrv_call *call, int error)
struct ldapsrv_reply *reply; struct ldapsrv_reply *reply;
struct ldap_ExtendedResponse *r; 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); reply = ldapsrv_init_reply(call, LDAP_TAG_ExtendedResponse);
if (!reply) { if (!reply) {
return NT_STATUS_NO_MEMORY; return NT_STATUS_NO_MEMORY;
} }
r = &reply->msg.r.ExtendedResponse; r = &reply->msg->r.ExtendedResponse;
r->response.resultcode = error; r->response.resultcode = error;
r->response.dn = NULL; r->response.dn = NULL;
r->response.errormessage = 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) 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; struct ldapsrv_partition *part;
DEBUG(10, ("SearchRequest")); DEBUG(10, ("SearchRequest"));
@ -102,7 +106,7 @@ static NTSTATUS ldapsrv_SearchRequest(struct ldapsrv_call *call)
return NT_STATUS_NO_MEMORY; return NT_STATUS_NO_MEMORY;
} }
done = &done_r->msg.r.SearchResultDone; done = &done_r->msg->r.SearchResultDone;
done->resultcode = 53; done->resultcode = 53;
done->dn = NULL; done->dn = NULL;
done->errormessage = NULL; done->errormessage = NULL;
@ -116,7 +120,7 @@ static NTSTATUS ldapsrv_SearchRequest(struct ldapsrv_call *call)
static NTSTATUS ldapsrv_ModifyRequest(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; struct ldapsrv_partition *part;
DEBUG(10, ("ModifyRequest")); DEBUG(10, ("ModifyRequest"));
@ -133,7 +137,7 @@ static NTSTATUS ldapsrv_ModifyRequest(struct ldapsrv_call *call)
static NTSTATUS ldapsrv_AddRequest(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; struct ldapsrv_partition *part;
DEBUG(10, ("AddRequest")); DEBUG(10, ("AddRequest"));
@ -150,7 +154,7 @@ static NTSTATUS ldapsrv_AddRequest(struct ldapsrv_call *call)
static NTSTATUS ldapsrv_DelRequest(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; struct ldapsrv_partition *part;
DEBUG(10, ("DelRequest")); DEBUG(10, ("DelRequest"));
@ -167,7 +171,7 @@ static NTSTATUS ldapsrv_DelRequest(struct ldapsrv_call *call)
static NTSTATUS ldapsrv_ModifyDNRequest(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; struct ldapsrv_partition *part;
DEBUG(10, ("ModifyDNRequrest")); DEBUG(10, ("ModifyDNRequrest"));
@ -185,7 +189,7 @@ static NTSTATUS ldapsrv_ModifyDNRequest(struct ldapsrv_call *call)
static NTSTATUS ldapsrv_CompareRequest(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; struct ldapsrv_partition *part;
DEBUG(10, ("CompareRequest")); DEBUG(10, ("CompareRequest"));
@ -219,14 +223,14 @@ static NTSTATUS ldapsrv_ExtendedRequest(struct ldapsrv_call *call)
return NT_STATUS_NO_MEMORY; return NT_STATUS_NO_MEMORY;
} }
ZERO_STRUCT(reply->msg.r); ZERO_STRUCT(reply->msg->r);
return ldapsrv_queue_reply(call, reply); return ldapsrv_queue_reply(call, reply);
} }
NTSTATUS ldapsrv_do_call(struct ldapsrv_call *call) NTSTATUS ldapsrv_do_call(struct ldapsrv_call *call)
{ {
switch(call->request.type) { switch(call->request->type) {
case LDAP_TAG_BindRequest: case LDAP_TAG_BindRequest:
return ldapsrv_BindRequest(call); return ldapsrv_BindRequest(call);
case LDAP_TAG_UnbindRequest: case LDAP_TAG_UnbindRequest:

View File

@ -25,7 +25,7 @@
static NTSTATUS ldapsrv_BindSimple(struct ldapsrv_call *call) 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 ldapsrv_reply *reply;
struct ldap_BindResponse *resp; struct ldap_BindResponse *resp;
@ -36,7 +36,7 @@ static NTSTATUS ldapsrv_BindSimple(struct ldapsrv_call *call)
return NT_STATUS_NO_MEMORY; return NT_STATUS_NO_MEMORY;
} }
resp = &reply->msg.r.BindResponse; resp = &reply->msg->r.BindResponse;
resp->response.resultcode = 0; resp->response.resultcode = 0;
resp->response.dn = NULL; resp->response.dn = NULL;
resp->response.errormessage = 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) 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 ldapsrv_reply *reply;
struct ldap_BindResponse *resp; struct ldap_BindResponse *resp;
struct ldapsrv_connection *conn; struct ldapsrv_connection *conn;
@ -92,7 +92,7 @@ reply:
if (!reply) { if (!reply) {
return NT_STATUS_NO_MEMORY; return NT_STATUS_NO_MEMORY;
} }
resp = &reply->msg.r.BindResponse; resp = &reply->msg->r.BindResponse;
conn = call->conn; conn = call->conn;
@ -142,7 +142,7 @@ reply:
NTSTATUS ldapsrv_BindRequest(struct ldapsrv_call *call) 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 ldapsrv_reply *reply;
struct ldap_BindResponse *resp; struct ldap_BindResponse *resp;
@ -158,7 +158,7 @@ NTSTATUS ldapsrv_BindRequest(struct ldapsrv_call *call)
return NT_STATUS_NO_MEMORY; return NT_STATUS_NO_MEMORY;
} }
resp = &reply->msg.r.BindResponse; resp = &reply->msg->r.BindResponse;
resp->response.resultcode = 7; resp->response.resultcode = 7;
resp->response.dn = NULL; resp->response.dn = NULL;
resp->response.errormessage = talloc_asprintf(reply, "Bad AuthenticationChoice [%d]", req->mechanism); resp->response.errormessage = talloc_asprintf(reply, "Bad AuthenticationChoice [%d]", req->mechanism);

View File

@ -253,7 +253,7 @@ static NTSTATUS hacked_wellknown_Search(struct ldapsrv_partition *partition, str
ent_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultEntry); ent_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultEntry);
NT_STATUS_HAVE_NO_MEMORY(ent_r); 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); ent->dn = talloc_steal(ent_r, wkdn);
DEBUG(0,("hacked result [0] dn: %s\n", ent->dn)); DEBUG(0,("hacked result [0] dn: %s\n", ent->dn));
ent->num_attributes = 0; 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)); DEBUG(10,("hacked_Search: results: [%d]\n",count));
done = &done_r->msg.r.SearchResultDone; done = &done_r->msg->r.SearchResultDone;
done->dn = NULL; done->dn = NULL;
done->resultcode = LDAP_SUCCESS; done->resultcode = LDAP_SUCCESS;
done->errormessage = NULL; 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); ent_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultEntry);
NT_STATUS_HAVE_NO_MEMORY(ent_r); 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); ent->dn = talloc_steal(ent_r, res[0]->dn);
DEBUG(0,("hacked result [0] dn: %s\n", ent->dn)); DEBUG(0,("hacked result [0] dn: %s\n", ent->dn));
ent->num_attributes = 0; ent->num_attributes = 0;
@ -394,7 +394,7 @@ queue_reply:
ent_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultEntry); ent_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultEntry);
NT_STATUS_HAVE_NO_MEMORY(ent_r); 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->dn = talloc_steal(ent_r, res[i]->dn);
DEBUG(0,("hacked result [%d] dn: %s\n", i, ent->dn)); DEBUG(0,("hacked result [%d] dn: %s\n", i, ent->dn));
ent->num_attributes = 0; ent->num_attributes = 0;
@ -457,7 +457,7 @@ queue_reply2:
errstr = ldb_errstring(samdb); errstr = ldb_errstring(samdb);
} }
done = &done_r->msg.r.SearchResultDone; done = &done_r->msg->r.SearchResultDone;
done->dn = NULL; done->dn = NULL;
done->resultcode = result; done->resultcode = result;
done->errormessage = (errstr?talloc_strdup(done_r,errstr):NULL);; 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->dn = NULL;
add_result->resultcode = result; add_result->resultcode = result;
add_result->errormessage = (errstr?talloc_strdup(add_reply,errstr):NULL); 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->dn = NULL;
del_result->resultcode = result; del_result->resultcode = result;
del_result->errormessage = (errstr?talloc_strdup(del_reply,errstr):NULL); 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->dn = NULL;
modify_result->resultcode = result; modify_result->resultcode = result;
modify_result->errormessage = (errstr?talloc_strdup(modify_reply,errstr):NULL); 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->dn = NULL;
compare->resultcode = result; compare->resultcode = result;
compare->errormessage = (errstr?talloc_strdup(compare_r,errstr):NULL); 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->dn = NULL;
modifydn->resultcode = result; modifydn->resultcode = result;
modifydn->errormessage = (errstr?talloc_strdup(modifydn_r,errstr):NULL); modifydn->errormessage = (errstr?talloc_strdup(modifydn_r,errstr):NULL);

View File

@ -338,7 +338,7 @@ static NTSTATUS rootdse_Search(struct ldapsrv_partition *partition, struct ldaps
ent_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultEntry); ent_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultEntry);
NT_STATUS_HAVE_NO_MEMORY(ent_r); NT_STATUS_HAVE_NO_MEMORY(ent_r);
ent = &ent_r->msg.r.SearchResultEntry; ent = &ent_r->msg->r.SearchResultEntry;
ent->dn = ""; ent->dn = "";
ent->num_attributes = 0; ent->num_attributes = 0;
ent->attributes = NULL; ent->attributes = NULL;
@ -398,7 +398,7 @@ queue_reply:
errstr = ldb_errstring(rootdsedb->ldb); errstr = ldb_errstring(rootdsedb->ldb);
} }
done = &done_r->msg.r.SearchResultDone; done = &done_r->msg->r.SearchResultDone;
done->dn = NULL; done->dn = NULL;
done->resultcode = result; done->resultcode = result;
done->errormessage = (errstr?talloc_strdup(done_r,errstr):NULL);; done->errormessage = (errstr?talloc_strdup(done_r,errstr):NULL);;

View File

@ -305,7 +305,7 @@ NTSTATUS ldapsrv_do_responses(struct ldapsrv_connection *conn)
for (call=conn->calls; call; call=next_call) { for (call=conn->calls; call; call=next_call) {
for (reply=call->replies; reply; reply=next_reply) { 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; return NT_STATUS_FOOBAR;
} }
next_reply = reply->next; next_reply = reply->next;
@ -375,18 +375,22 @@ static void ldapsrv_recv(struct stream_connection *conn, uint16_t flags)
return; return;
} }
call = talloc(ldap_conn, struct ldapsrv_call); call = talloc_zero(ldap_conn, struct ldapsrv_call);
if (!call) { if (!call) {
ldapsrv_terminate_connection(ldap_conn, "no memory"); ldapsrv_terminate_connection(ldap_conn, "no memory");
return; 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->state = LDAPSRV_CALL_STATE_NEW;
call->conn = ldap_conn; 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); dump_data(0,buf, msg_length);
asn1_free(&data); asn1_free(&data);
ldapsrv_terminate_connection(ldap_conn, "ldap_decode() failed"); ldapsrv_terminate_connection(ldap_conn, "ldap_decode() failed");

View File

@ -47,12 +47,12 @@ struct ldapsrv_call {
struct ldapsrv_connection *conn; struct ldapsrv_connection *conn;
struct ldap_message request; struct ldap_message *request;
struct ldapsrv_reply { struct ldapsrv_reply {
struct ldapsrv_reply *prev,*next; struct ldapsrv_reply *prev,*next;
enum ldapsrv_reply_state state; enum ldapsrv_reply_state state;
struct ldap_message msg; struct ldap_message *msg;
} *replies; } *replies;
}; };

View File

@ -90,6 +90,9 @@ static NTSTATUS sldb_Search(struct ldapsrv_partition *partition, struct ldapsrv_
attrs[i] = NULL; 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); count = ldb_search_bytree(samdb, basedn->dn, scope, r->tree, attrs, &res);
talloc_steal(samdb, 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); ent_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultEntry);
NT_STATUS_HAVE_NO_MEMORY(ent_r); 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->dn = talloc_steal(ent_r, res[i]->dn);
ent->num_attributes = 0; ent->num_attributes = 0;
ent->attributes = NULL; ent->attributes = NULL;
@ -151,7 +154,7 @@ reply:
} }
} }
done = &done_r->msg.r.SearchResultDone; done = &done_r->msg->r.SearchResultDone;
done->dn = NULL; done->dn = NULL;
done->resultcode = result; done->resultcode = result;
done->errormessage = (errstr?talloc_strdup(done_r,errstr):NULL); 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->dn = NULL;
add_result->resultcode = result; add_result->resultcode = result;
add_result->errormessage = (errstr?talloc_strdup(add_reply,errstr):NULL); 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->dn = NULL;
del_result->resultcode = result; del_result->resultcode = result;
del_result->errormessage = (errstr?talloc_strdup(del_reply,errstr):NULL); 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->dn = NULL;
modify_result->resultcode = result; modify_result->resultcode = result;
modify_result->errormessage = (errstr?talloc_strdup(modify_reply,errstr):NULL); 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->dn = NULL;
compare->resultcode = result; compare->resultcode = result;
compare->errormessage = (errstr?talloc_strdup(compare_r,errstr):NULL); 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->dn = NULL;
modifydn->resultcode = result; modifydn->resultcode = result;
modifydn->errormessage = (errstr?talloc_strdup(modifydn_r,errstr):NULL); modifydn->errormessage = (errstr?talloc_strdup(modifydn_r,errstr):NULL);

View File

@ -68,7 +68,7 @@ static void cldap_socket_recv(struct cldap_socket *cldap)
DATA_BLOB blob; DATA_BLOB blob;
size_t nread, dsize; size_t nread, dsize;
struct asn1_data asn1; struct asn1_data asn1;
struct ldap_message ldap_msg; struct ldap_message *ldap_msg;
struct cldap_request *req; struct cldap_request *req;
status = socket_pending(cldap->sock, &dsize); 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); talloc_steal(tmp_ctx, asn1.data);
ZERO_STRUCT(ldap_msg); ldap_msg = talloc(tmp_ctx, struct ldap_message);
ldap_msg.mem_ctx = tmp_ctx; if (ldap_msg == NULL) {
talloc_free(tmp_ctx);
return;
}
/* this initial decode is used to find the message id */ /* 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")); DEBUG(2,("Failed to decode ldap message\n"));
talloc_free(tmp_ctx); talloc_free(tmp_ctx);
return; return;
} }
/* find the pending request */ /* find the pending request */
req = idr_find(cldap->idr, ldap_msg.messageid); req = idr_find(cldap->idr, ldap_msg->messageid);
if (req == NULL) { if (req == NULL) {
if (cldap->incoming.handler) { 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 { } else {
DEBUG(2,("Mismatched cldap reply %u from %s:%d\n", 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); talloc_free(tmp_ctx);
return; 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_request *cldap_search_send(struct cldap_socket *cldap,
struct cldap_search *io) struct cldap_search *io)
{ {
struct ldap_message msg; struct ldap_message *msg;
struct cldap_request *req; struct cldap_request *req;
struct ldap_SearchRequest *search; 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); talloc_set_destructor(req, cldap_request_destructor);
msg.mem_ctx = req; msg = talloc(req, struct ldap_message);
msg.messageid = req->message_id; if (msg == NULL) goto failed;
msg.type = LDAP_TAG_SearchRequest; msg->messageid = req->message_id;
msg.num_controls = 0; msg->type = LDAP_TAG_SearchRequest;
msg.controls = NULL; msg->num_controls = 0;
search = &msg.r.SearchRequest; msg->controls = NULL;
search = &msg->r.SearchRequest;
search->basedn = ""; search->basedn = "";
search->scope = LDAP_SEARCH_SCOPE_BASE; search->scope = LDAP_SEARCH_SCOPE_BASE;
@ -333,7 +337,7 @@ struct cldap_request *cldap_search_send(struct cldap_socket *cldap,
goto failed; 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", DEBUG(0,("Failed to encode cldap message to %s:%d\n",
req->dest_addr, req->dest_port)); req->dest_addr, req->dest_port));
goto failed; goto failed;
@ -357,7 +361,7 @@ failed:
*/ */
NTSTATUS cldap_reply_send(struct cldap_socket *cldap, struct cldap_reply *io) NTSTATUS cldap_reply_send(struct cldap_socket *cldap, struct cldap_reply *io)
{ {
struct ldap_message msg; struct ldap_message *msg;
struct cldap_request *req; struct cldap_request *req;
DATA_BLOB blob1, blob2; DATA_BLOB blob1, blob2;
NTSTATUS status = NT_STATUS_NO_MEMORY; 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); talloc_set_destructor(req, cldap_request_destructor);
msg.mem_ctx = req; msg = talloc(req, struct ldap_message);
msg.messageid = io->messageid; if (msg == NULL) goto failed;
msg.num_controls = 0; msg->messageid = io->messageid;
msg.controls = NULL; msg->num_controls = 0;
msg->controls = NULL;
if (io->response) { if (io->response) {
msg.type = LDAP_TAG_SearchResultEntry; msg->type = LDAP_TAG_SearchResultEntry;
msg.r.SearchResultEntry = *io->response; 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", DEBUG(0,("Failed to encode cldap message to %s:%d\n",
req->dest_addr, req->dest_port)); req->dest_addr, req->dest_port));
status = NT_STATUS_INVALID_PARAMETER; 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); blob1 = data_blob(NULL, 0);
} }
msg.type = LDAP_TAG_SearchResultDone; msg->type = LDAP_TAG_SearchResultDone;
msg.r.SearchResultDone = *io->result; 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", DEBUG(0,("Failed to encode cldap message to %s:%d\n",
req->dest_addr, req->dest_port)); req->dest_addr, req->dest_port));
status = NT_STATUS_INVALID_PARAMETER; status = NT_STATUS_INVALID_PARAMETER;
@ -430,7 +435,7 @@ NTSTATUS cldap_search_recv(struct cldap_request *req,
TALLOC_CTX *mem_ctx, TALLOC_CTX *mem_ctx,
struct cldap_search *io) struct cldap_search *io)
{ {
struct ldap_message ldap_msg; struct ldap_message *ldap_msg;
if (req == NULL) { if (req == NULL) {
return NT_STATUS_NO_MEMORY; return NT_STATUS_NO_MEMORY;
@ -448,10 +453,10 @@ NTSTATUS cldap_search_recv(struct cldap_request *req,
return NT_STATUS_IO_TIMEOUT; return NT_STATUS_IO_TIMEOUT;
} }
ZERO_STRUCT(ldap_msg); ldap_msg = talloc(mem_ctx, struct ldap_message);
ldap_msg.mem_ctx = mem_ctx; NT_STATUS_HAVE_NO_MEMORY(ldap_msg);
if (!ldap_decode(&req->asn1, &ldap_msg)) { if (!ldap_decode(&req->asn1, ldap_msg)) {
talloc_free(req); talloc_free(req);
return NT_STATUS_INVALID_PARAMETER; return NT_STATUS_INVALID_PARAMETER;
} }
@ -459,26 +464,26 @@ NTSTATUS cldap_search_recv(struct cldap_request *req,
ZERO_STRUCT(io->out); ZERO_STRUCT(io->out);
/* the first possible form has a search result in first place */ /* 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); io->out.response = talloc(mem_ctx, struct ldap_SearchResEntry);
NT_STATUS_HAVE_NO_MEMORY(io->out.response); 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 */ /* decode the 2nd part */
if (!ldap_decode(&req->asn1, &ldap_msg)) { if (!ldap_decode(&req->asn1, ldap_msg)) {
talloc_free(req); talloc_free(req);
return NT_STATUS_INVALID_PARAMETER; return NT_STATUS_INVALID_PARAMETER;
} }
} }
if (ldap_msg.type != LDAP_TAG_SearchResultDone) { if (ldap_msg->type != LDAP_TAG_SearchResultDone) {
talloc_free(req); talloc_free(req);
return NT_STATUS_UNEXPECTED_NETWORK_ERROR; return NT_STATUS_UNEXPECTED_NETWORK_ERROR;
} }
io->out.result = talloc(mem_ctx, struct ldap_Result); io->out.result = talloc(mem_ctx, struct ldap_Result);
NT_STATUS_HAVE_NO_MEMORY(io->out.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); talloc_free(req);
return NT_STATUS_OK; return NT_STATUS_OK;

View File

@ -647,7 +647,7 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
msg->type = LDAP_TAG_BindRequest; msg->type = LDAP_TAG_BindRequest;
asn1_start_tag(data, tag); asn1_start_tag(data, tag);
asn1_read_Integer(data, &r->version); 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))) { if (asn1_peek_tag(data, ASN1_CONTEXT_SIMPLE(0))) {
int pwlen; int pwlen;
r->creds.password = ""; 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)); asn1_start_tag(data, ASN1_CONTEXT_SIMPLE(0));
pwlen = asn1_tag_remaining(data); pwlen = asn1_tag_remaining(data);
if (pwlen != 0) { if (pwlen != 0) {
char *pw = talloc_size(msg->mem_ctx, pwlen+1); char *pw = talloc_size(msg, pwlen+1);
asn1_read(data, pw, pwlen); asn1_read(data, pw, pwlen);
pw[pwlen] = '\0'; pw[pwlen] = '\0';
r->creds.password = pw; 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))){ } else if (asn1_peek_tag(data, ASN1_CONTEXT(3))){
asn1_start_tag(data, ASN1_CONTEXT(3)); asn1_start_tag(data, ASN1_CONTEXT(3));
r->mechanism = LDAP_AUTH_MECH_SASL; 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); asn1_read_OctetString(data, &r->creds.SASL.secblob);
if (r->creds.SASL.secblob.data) { 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); 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; struct ldap_BindResponse *r = &msg->r.BindResponse;
msg->type = LDAP_TAG_BindResponse; msg->type = LDAP_TAG_BindResponse;
asn1_start_tag(data, tag); 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))) { if (asn1_peek_tag(data, ASN1_CONTEXT_SIMPLE(7))) {
DATA_BLOB tmp_blob = data_blob(NULL, 0); DATA_BLOB tmp_blob = data_blob(NULL, 0);
asn1_read_ContextSimple(data, 7, &tmp_blob); 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); data_blob_free(&tmp_blob);
} else { } else {
r->SASL.secblob = data_blob(NULL, 0); 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; struct ldap_SearchRequest *r = &msg->r.SearchRequest;
msg->type = LDAP_TAG_SearchRequest; msg->type = LDAP_TAG_SearchRequest;
asn1_start_tag(data, tag); 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->scope));
asn1_read_enumerated(data, (int *)&(r->deref)); asn1_read_enumerated(data, (int *)&(r->deref));
asn1_read_Integer(data, &r->sizelimit); asn1_read_Integer(data, &r->sizelimit);
asn1_read_Integer(data, &r->timelimit); asn1_read_Integer(data, &r->timelimit);
asn1_read_BOOLEAN(data, &r->attributesonly); 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) { if (r->tree == NULL) {
return False; return False;
} }
@ -722,10 +722,10 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
while (asn1_tag_remaining(data) > 0) { while (asn1_tag_remaining(data) > 0) {
const char *attr; const char *attr;
if (!asn1_read_OctetString_talloc(msg->mem_ctx, data, if (!asn1_read_OctetString_talloc(msg, data,
&attr)) &attr))
return False; return False;
if (!add_string_to_array(msg->mem_ctx, attr, if (!add_string_to_array(msg, attr,
&r->attributes, &r->attributes,
&r->num_attributes)) &r->num_attributes))
return False; return False;
@ -742,8 +742,8 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
r->attributes = NULL; r->attributes = NULL;
r->num_attributes = 0; r->num_attributes = 0;
asn1_start_tag(data, tag); asn1_start_tag(data, tag);
asn1_read_OctetString_talloc(msg->mem_ctx, data, &r->dn); asn1_read_OctetString_talloc(msg, data, &r->dn);
ldap_decode_attribs(msg->mem_ctx, data, &r->attributes, ldap_decode_attribs(msg, data, &r->attributes,
&r->num_attributes); &r->num_attributes);
asn1_end_tag(data); asn1_end_tag(data);
break; break;
@ -753,7 +753,7 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
struct ldap_Result *r = &msg->r.SearchResultDone; struct ldap_Result *r = &msg->r.SearchResultDone;
msg->type = LDAP_TAG_SearchResultDone; msg->type = LDAP_TAG_SearchResultDone;
asn1_start_tag(data, tag); asn1_start_tag(data, tag);
ldap_decode_response(msg->mem_ctx, data, r); ldap_decode_response(msg, data, r);
asn1_end_tag(data); asn1_end_tag(data);
break; break;
} }
@ -762,7 +762,7 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
struct ldap_SearchResRef *r = &msg->r.SearchResultReference; struct ldap_SearchResRef *r = &msg->r.SearchResultReference;
msg->type = LDAP_TAG_SearchResultReference; msg->type = LDAP_TAG_SearchResultReference;
asn1_start_tag(data, tag); 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); asn1_end_tag(data);
break; break;
} }
@ -771,7 +771,7 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
struct ldap_ModifyRequest *r = &msg->r.ModifyRequest; struct ldap_ModifyRequest *r = &msg->r.ModifyRequest;
msg->type = LDAP_TAG_ModifyRequest; msg->type = LDAP_TAG_ModifyRequest;
asn1_start_tag(data, ASN1_APPLICATION(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)); asn1_start_tag(data, ASN1_SEQUENCE(0));
r->num_mods = 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_start_tag(data, ASN1_SEQUENCE(0));
asn1_read_enumerated(data, &v); asn1_read_enumerated(data, &v);
mod.type = v; mod.type = v;
ldap_decode_attrib(msg->mem_ctx, data, &mod.attrib); ldap_decode_attrib(msg, data, &mod.attrib);
asn1_end_tag(data); 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)) &r->mods, &r->num_mods))
break; break;
} }
@ -800,7 +800,7 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
struct ldap_Result *r = &msg->r.ModifyResponse; struct ldap_Result *r = &msg->r.ModifyResponse;
msg->type = LDAP_TAG_ModifyResponse; msg->type = LDAP_TAG_ModifyResponse;
asn1_start_tag(data, tag); asn1_start_tag(data, tag);
ldap_decode_response(msg->mem_ctx, data, r); ldap_decode_response(msg, data, r);
asn1_end_tag(data); asn1_end_tag(data);
break; break;
} }
@ -809,11 +809,11 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
struct ldap_AddRequest *r = &msg->r.AddRequest; struct ldap_AddRequest *r = &msg->r.AddRequest;
msg->type = LDAP_TAG_AddRequest; msg->type = LDAP_TAG_AddRequest;
asn1_start_tag(data, tag); 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->attributes = NULL;
r->num_attributes = 0; r->num_attributes = 0;
ldap_decode_attribs(msg->mem_ctx, data, &r->attributes, ldap_decode_attribs(msg, data, &r->attributes,
&r->num_attributes); &r->num_attributes);
asn1_end_tag(data); 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; struct ldap_Result *r = &msg->r.AddResponse;
msg->type = LDAP_TAG_AddResponse; msg->type = LDAP_TAG_AddResponse;
asn1_start_tag(data, tag); asn1_start_tag(data, tag);
ldap_decode_response(msg->mem_ctx, data, r); ldap_decode_response(msg, data, r);
asn1_end_tag(data); asn1_end_tag(data);
break; break;
} }
@ -837,7 +837,7 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
asn1_start_tag(data, asn1_start_tag(data,
ASN1_APPLICATION_SIMPLE(LDAP_TAG_DelRequest)); ASN1_APPLICATION_SIMPLE(LDAP_TAG_DelRequest));
len = asn1_tag_remaining(data); len = asn1_tag_remaining(data);
dn = talloc_size(msg->mem_ctx, len+1); dn = talloc_size(msg, len+1);
if (dn == NULL) if (dn == NULL)
break; break;
asn1_read(data, dn, len); 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; struct ldap_Result *r = &msg->r.DelResponse;
msg->type = LDAP_TAG_DelResponse; msg->type = LDAP_TAG_DelResponse;
asn1_start_tag(data, tag); asn1_start_tag(data, tag);
ldap_decode_response(msg->mem_ctx, data, r); ldap_decode_response(msg, data, r);
asn1_end_tag(data); asn1_end_tag(data);
break; break;
} }
@ -861,8 +861,8 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
msg->type = LDAP_TAG_ModifyDNRequest; msg->type = LDAP_TAG_ModifyDNRequest;
asn1_start_tag(data, asn1_start_tag(data,
ASN1_APPLICATION(LDAP_TAG_ModifyDNRequest)); ASN1_APPLICATION(LDAP_TAG_ModifyDNRequest));
asn1_read_OctetString_talloc(msg->mem_ctx, data, &r->dn); asn1_read_OctetString_talloc(msg, data, &r->dn);
asn1_read_OctetString_talloc(msg->mem_ctx, data, &r->newrdn); asn1_read_OctetString_talloc(msg, data, &r->newrdn);
asn1_read_BOOLEAN(data, &r->deleteolddn); asn1_read_BOOLEAN(data, &r->deleteolddn);
r->newsuperior = NULL; r->newsuperior = NULL;
if (asn1_tag_remaining(data) > 0) { if (asn1_tag_remaining(data) > 0) {
@ -870,7 +870,7 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
char *newsup; char *newsup;
asn1_start_tag(data, ASN1_CONTEXT_SIMPLE(0)); asn1_start_tag(data, ASN1_CONTEXT_SIMPLE(0));
len = asn1_tag_remaining(data); len = asn1_tag_remaining(data);
newsup = talloc_size(msg->mem_ctx, len+1); newsup = talloc_size(msg, len+1);
if (newsup == NULL) if (newsup == NULL)
break; break;
asn1_read(data, newsup, len); 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; struct ldap_Result *r = &msg->r.ModifyDNResponse;
msg->type = LDAP_TAG_ModifyDNResponse; msg->type = LDAP_TAG_ModifyDNResponse;
asn1_start_tag(data, tag); asn1_start_tag(data, tag);
ldap_decode_response(msg->mem_ctx, data, r); ldap_decode_response(msg, data, r);
asn1_end_tag(data); asn1_end_tag(data);
break; break;
} }
@ -896,12 +896,12 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
msg->type = LDAP_TAG_CompareRequest; msg->type = LDAP_TAG_CompareRequest;
asn1_start_tag(data, asn1_start_tag(data,
ASN1_APPLICATION(LDAP_TAG_CompareRequest)); 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_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); asn1_read_OctetString(data, &r->value);
if (r->value.data) { 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);
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; struct ldap_Result *r = &msg->r.CompareResponse;
msg->type = LDAP_TAG_CompareResponse; msg->type = LDAP_TAG_CompareResponse;
asn1_start_tag(data, tag); asn1_start_tag(data, tag);
ldap_decode_response(msg->mem_ctx, data, r); ldap_decode_response(msg, data, r);
asn1_end_tag(data); asn1_end_tag(data);
break; break;
} }
@ -935,7 +935,7 @@ BOOL ldap_decode(struct asn1_data *data, struct ldap_message *msg)
if (!asn1_read_ContextSimple(data, 0, &tmp_blob)) { if (!asn1_read_ContextSimple(data, 0, &tmp_blob)) {
return False; return False;
} }
r->oid = blob2string_talloc(msg->mem_ctx, tmp_blob); r->oid = blob2string_talloc(msg, tmp_blob);
data_blob_free(&tmp_blob); data_blob_free(&tmp_blob);
if (!r->oid) { if (!r->oid) {
return False; 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))) { if (asn1_peek_tag(data, ASN1_CONTEXT_SIMPLE(1))) {
asn1_read_ContextSimple(data, 1, &tmp_blob); 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); data_blob_free(&tmp_blob);
} else { } else {
r->value = data_blob(NULL, 0); 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; struct ldap_ExtendedResponse *r = &msg->r.ExtendedResponse;
msg->type = LDAP_TAG_ExtendedResponse; msg->type = LDAP_TAG_ExtendedResponse;
asn1_start_tag(data, tag); 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 /* I have to come across an operation that actually sends
* something back to really see what's going on. The currently * something back to really see what's going on. The currently
* needed pwdchange does not send anything back. */ * 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++) { for (i=0; asn1_peek_tag(data, ASN1_SEQUENCE(0)); i++) {
asn1_start_tag(data, ASN1_SEQUENCE(0)); 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) { if (!ctrl) {
return False; 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)) { if (asn1_peek_tag(data, ASN1_OCTET_STRING)) {
asn1_read_OctetString(data, &ctrl[i].value); asn1_read_OctetString(data, &ctrl[i].value);
if (ctrl[i].value.data) { if (ctrl[i].value.data) {
talloc_steal(msg->mem_ctx, ctrl[i].value.data); talloc_steal(msg, ctrl[i].value.data);
} }
} }

View File

@ -252,7 +252,6 @@ struct ldap_Control {
}; };
struct ldap_message { struct ldap_message {
TALLOC_CTX *mem_ctx;
uint32_t messageid; uint32_t messageid;
enum ldap_request_tag type; enum ldap_request_tag type;
union ldap_Request r; union ldap_Request r;
@ -267,7 +266,6 @@ struct ldap_queue_entry {
}; };
struct ldap_connection { struct ldap_connection {
TALLOC_CTX *mem_ctx;
int sock; int sock;
int next_msgid; int next_msgid;
char *host; char *host;

View File

@ -312,9 +312,9 @@ static struct ldap_message *new_ldap_simple_bind_msg(struct ldap_connection *con
res->type = LDAP_TAG_BindRequest; res->type = LDAP_TAG_BindRequest;
res->r.BindRequest.version = 3; 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.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; 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.version = 3;
res->r.BindRequest.dn = ""; res->r.BindRequest.dn = "";
res->r.BindRequest.mechanism = LDAP_AUTH_MECH_SASL; 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; res->r.BindRequest.creds.SASL.secblob = *secblob;
return res; return res;
@ -348,7 +348,6 @@ static struct ldap_connection *new_ldap_connection(TALLOC_CTX *mem_ctx)
return NULL; return NULL;
} }
result->mem_ctx = result;
result->next_msgid = 1; result->next_msgid = 1;
result->outstanding = NULL; result->outstanding = NULL;
result->searchid = 0; result->searchid = 0;
@ -372,8 +371,8 @@ struct ldap_connection *ldap_connect(TALLOC_CTX *mem_ctx, const char *url)
return NULL; return NULL;
} }
ret = ldap_parse_basic_url(conn->mem_ctx, url, &conn->host, ret = ldap_parse_basic_url(conn, url, &conn->host,
&conn->port, &conn->ldaps); &conn->port, &conn->ldaps);
if (!ret) { if (!ret) {
talloc_free(conn); talloc_free(conn);
return NULL; 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 *new_ldap_message(TALLOC_CTX *mem_ctx)
{ {
struct ldap_message *result; return talloc(mem_ctx, struct ldap_message);
result = talloc(mem_ctx, struct ldap_message);
if (!result) {
return NULL;
}
result->mem_ctx = result;
return result;
} }
BOOL ldap_send_msg(struct ldap_connection *conn, struct ldap_message *msg, 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; return NULL;
status = gensec_wrap(conn->gensec, status = gensec_wrap(conn->gensec,
req->mem_ctx, req,
&request, &request,
&wrapped); &wrapped);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
@ -653,7 +642,7 @@ static struct ldap_message *ldap_transaction_sasl(struct ldap_connection *conn,
wrapped.length = len; wrapped.length = len;
status = gensec_unwrap(conn->gensec, status = gensec_unwrap(conn->gensec,
req->mem_ctx, req,
&wrapped, &wrapped,
&request); &request);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
@ -661,7 +650,7 @@ static struct ldap_message *ldap_transaction_sasl(struct ldap_connection *conn,
return NULL; return NULL;
} }
rep = new_ldap_message(req->mem_ctx); rep = new_ldap_message(req);
asn1_load(&asn1, request); asn1_load(&asn1, request);
if (!ldap_decode(&asn1, rep)) { if (!ldap_decode(&asn1, rep)) {
@ -776,7 +765,7 @@ int ldap_bind_sasl(struct ldap_connection *conn, struct cli_credentials *creds)
goto done; 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)) { if (!NT_STATUS_IS_OK(status)) {
DEBUG(1, ("Failed to start set GENSEC client SPNEGO mechanism: %s\n", DEBUG(1, ("Failed to start set GENSEC client SPNEGO mechanism: %s\n",
nt_errstr(status))); nt_errstr(status)));
@ -828,8 +817,7 @@ int ldap_bind_sasl(struct ldap_connection *conn, struct cli_credentials *creds)
} }
done: done:
if (mem_ctx) talloc_free(mem_ctx);
talloc_free(mem_ctx);
return result; return result;
} }

View File

@ -212,7 +212,7 @@ static BOOL fill_add_attributes(struct ldap_message *msg, char **chunk)
} }
if (attrib == NULL) { if (attrib == NULL) {
r->attributes = talloc_realloc(msg->mem_ctx, r->attributes = talloc_realloc(msg,
r->attributes, r->attributes,
struct ldap_attribute, struct ldap_attribute,
r->num_attributes+1); 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]); attrib = &(r->attributes[r->num_attributes]);
r->num_attributes += 1; r->num_attributes += 1;
ZERO_STRUCTP(attrib); ZERO_STRUCTP(attrib);
attrib->name = talloc_strdup(msg->mem_ctx, attrib->name = talloc_strdup(msg,
attr_name); attr_name);
} }
if (!add_value_to_attrib(msg->mem_ctx, &value, attrib)) if (!add_value_to_attrib(msg, &value, attrib))
return False; return False;
} }
return True; return True;
@ -261,7 +261,7 @@ static BOOL fill_mods(struct ldap_message *msg, char **chunk)
struct ldap_mod mod; struct ldap_mod mod;
mod.type = LDAP_MODIFY_NONE; 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")) if (strequal(attr_name, "add"))
mod.type = LDAP_MODIFY_ADD; mod.type = LDAP_MODIFY_ADD;
@ -290,14 +290,14 @@ static BOOL fill_mods(struct ldap_message *msg, char **chunk)
mod.attrib.name)); mod.attrib.name));
return False; return False;
} }
if (!add_value_to_attrib(msg->mem_ctx, &value, if (!add_value_to_attrib(msg, &value,
&mod.attrib)) { &mod.attrib)) {
DEBUG(3, ("Could not add value\n")); DEBUG(3, ("Could not add value\n"));
return False; 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)) &r->num_mods))
return False; return False;
} }
@ -370,7 +370,7 @@ static struct ldap_message *ldif_read(TALLOC_CTX *mem_ctx, int (*fgetc_fn)(void
if (msg == NULL) if (msg == NULL)
return NULL; return NULL;
chunk = next_chunk(msg->mem_ctx, fgetc_fn, private_data); chunk = next_chunk(msg, fgetc_fn, private_data);
if (!chunk) { if (!chunk) {
goto failed; goto failed;
} }
@ -388,7 +388,7 @@ static struct ldap_message *ldif_read(TALLOC_CTX *mem_ctx, int (*fgetc_fn)(void
goto failed; goto failed;
} }
dn = talloc_strdup(msg->mem_ctx, value.data); dn = talloc_strdup(msg, value.data);
if (next_attr(&s, &attr, &value) != 0) { if (next_attr(&s, &attr, &value) != 0) {
goto failed; goto failed;

View File

@ -97,7 +97,7 @@ static BOOL test_search_rootDSE(struct ldap_connection *conn, char **basedn)
msg->r.SearchRequest.timelimit = 0; msg->r.SearchRequest.timelimit = 0;
msg->r.SearchRequest.sizelimit = 0; msg->r.SearchRequest.sizelimit = 0;
msg->r.SearchRequest.attributesonly = False; 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.num_attributes = 0;
msg->r.SearchRequest.attributes = NULL; 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)); (char *)r->attributes[i].values[j].data));
if (!(*basedn) && if (!(*basedn) &&
strcasecmp("defaultNamingContext",r->attributes[i].name)==0) { 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, r->attributes[i].values[j].length,
(char *)r->attributes[i].values[j].data); (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->type = LDAP_TAG_CompareRequest;
req->r.CompareRequest.dn = basedn; 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"; 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); rep = ldap_transaction(conn, req);
if (!rep) { if (!rep) {