summaryrefslogtreecommitdiff
path: root/source4/ldap_server
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 /source4/ldap_server
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)
Diffstat (limited to 'source4/ldap_server')
-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
7 files changed, 57 insertions, 46 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);