summaryrefslogtreecommitdiff
path: root/source4/libcli
diff options
context:
space:
mode:
Diffstat (limited to 'source4/libcli')
-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
5 files changed, 95 insertions, 104 deletions
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;