diff options
author | Andrew Tridgell <tridge@samba.org> | 2005-06-15 00:27:51 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:18:12 -0500 |
commit | c0947b0d7f809f5139fbfcdbd618ed7b0a77d2be (patch) | |
tree | 7c0d7391b8f27d55e40b22f2c16315356e10a167 /source4/libcli/ldap | |
parent | 74a3621089d4d1e9ba4c1a02e44247d1cff29200 (diff) | |
download | samba-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/libcli/ldap')
-rw-r--r-- | source4/libcli/ldap/ldap.c | 72 | ||||
-rw-r--r-- | source4/libcli/ldap/ldap.h | 2 | ||||
-rw-r--r-- | source4/libcli/ldap/ldap_client.c | 34 | ||||
-rw-r--r-- | source4/libcli/ldap/ldap_ldif.c | 16 |
4 files changed, 55 insertions, 69 deletions
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; |