From c908d0b2aa111659e57a73efb8c33c413965c846 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 6 Jan 2006 04:01:23 +0000 Subject: r12733: Merge ldap/ldb controls into main tree There's still lot of work to do but the patch is stable enough to be pushed into the main samba4 tree. Simo. (This used to be commit 77125feaff252cab44d26593093a9c211c846ce8) --- source4/libcli/ldap/ldap_controls.c | 470 ++++++++++++++++++++++++++++++++++++ 1 file changed, 470 insertions(+) create mode 100644 source4/libcli/ldap/ldap_controls.c (limited to 'source4/libcli/ldap/ldap_controls.c') diff --git a/source4/libcli/ldap/ldap_controls.c b/source4/libcli/ldap/ldap_controls.c new file mode 100644 index 0000000000..55e7a94aa7 --- /dev/null +++ b/source4/libcli/ldap/ldap_controls.c @@ -0,0 +1,470 @@ +/* + Unix SMB/CIFS mplementation. + LDAP protocol helper functions for SAMBA + + Copyright (C) Simo Sorce 2005 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "includes.h" +#include "system/iconv.h" +#include "libcli/util/asn_1.h" +#include "libcli/ldap/ldap.h" +#include "lib/ldb/include/ldb.h" + +struct control_handler { + const char *oid; + BOOL (*decode)(void *mem_ctx, DATA_BLOB in, void **out); + BOOL (*encode)(void *mem_ctx, void *in, DATA_BLOB *out); +}; + +static BOOL decode_server_sort_response(void *mem_ctx, DATA_BLOB in, void **out) +{ + DATA_BLOB attr; + struct asn1_data data; + struct ldb_sort_resp_control *lsrc; + + if (!asn1_load(&data, in)) { + return False; + } + + lsrc = talloc(mem_ctx, struct ldb_sort_resp_control); + if (!lsrc) { + return False; + } + + if (!asn1_start_tag(&data, ASN1_SEQUENCE(0))) { + return False; + } + + if (!asn1_read_enumerated(&data, &(lsrc->result))) { + return False; + } + + lsrc->attr_desc = NULL; + if (asn1_peek_tag(&data, ASN1_OCTET_STRING)) { + if (!asn1_read_OctetString(&data, &attr)) { + return False; + } + lsrc->attr_desc = talloc_strndup(lsrc, attr.data, attr.length); + if (!lsrc->attr_desc) { + return False; + } + } + + if (!asn1_end_tag(&data)) { + return False; + } + + *out = lsrc; + + return True; +} + +static BOOL decode_server_sort_request(void *mem_ctx, DATA_BLOB in, void **out) +{ + DATA_BLOB attr; + DATA_BLOB rule; + struct asn1_data data; + struct ldb_server_sort_control **lssc; + int num; + + if (!asn1_load(&data, in)) { + return False; + } + + if (!asn1_start_tag(&data, ASN1_SEQUENCE(0))) { + return False; + } + + lssc = NULL; + + for (num = 0; asn1_peek_tag(&data, ASN1_SEQUENCE(0)); num++) { + lssc = talloc_realloc(mem_ctx, lssc, struct ldb_server_sort_control *, num + 2); + if (!lssc) { + return False; + } + lssc[num] = talloc(lssc, struct ldb_server_sort_control); + if (!lssc[num]) { + return False; + } + + if (!asn1_start_tag(&data, ASN1_SEQUENCE(0))) { + return False; + } + + if (!asn1_read_OctetString(&data, &attr)) { + return False; + } + + lssc[num]->attributeName = talloc_strndup(lssc[num], attr.data, attr.length); + if (!lssc [num]->attributeName) { + return False; + } + + if (asn1_peek_tag(&data, ASN1_OCTET_STRING)) { + if (!asn1_read_OctetString(&data, &rule)) { + return False; + } + lssc[num]->orderingRule = talloc_strndup(lssc[num], rule.data, rule.length); + if (!lssc[num]->orderingRule) { + return False; + } + } + + if (asn1_peek_tag(&data, ASN1_BOOLEAN)) { + if (!asn1_read_BOOLEAN(&data, &(lssc[num]->reverse))) { + return False; + } + } + + if (!asn1_end_tag(&data)) { + return False; + } + } + + lssc[num] = NULL; + + if (!asn1_end_tag(&data)) { + return False; + } + + *out = lssc; + + return True; +} + +static BOOL decode_extended_dn_request(void *mem_ctx, DATA_BLOB in, void **out) +{ + struct asn1_data data; + struct ldb_extended_dn_control *ledc; + + if (!asn1_load(&data, in)) { + return False; + } + + ledc = talloc(mem_ctx, struct ldb_extended_dn_control); + if (!ledc) { + return False; + } + + if (!asn1_start_tag(&data, ASN1_SEQUENCE(0))) { + return False; + } + + if (!asn1_read_Integer(&data, &(ledc->type))) { + return False; + } + + if (!asn1_end_tag(&data)) { + return False; + } + + *out = ledc; + + return True; +} + +static BOOL decode_paged_results_request(void *mem_ctx, DATA_BLOB in, void **out) +{ + DATA_BLOB cookie; + struct asn1_data data; + struct ldb_paged_control *lprc; + + if (!asn1_load(&data, in)) { + return False; + } + + lprc = talloc(mem_ctx, struct ldb_paged_control); + if (!lprc) { + return False; + } + + if (!asn1_start_tag(&data, ASN1_SEQUENCE(0))) { + return False; + } + + if (!asn1_read_Integer(&data, &(lprc->size))) { + return False; + } + + if (!asn1_read_OctetString(&data, &cookie)) { + return False; + } + lprc->cookie_len = cookie.length; + if (lprc->cookie_len) { + lprc->cookie = talloc_memdup(lprc, cookie.data, cookie.length); + + if (!(lprc->cookie)) { + return False; + } + } else { + lprc->cookie = NULL; + } + + if (!asn1_end_tag(&data)) { + return False; + } + + *out = lprc; + + return True; +} + +static BOOL encode_server_sort_response(void *mem_ctx, void *in, DATA_BLOB *out) +{ + struct ldb_sort_resp_control *lsrc = talloc_get_type(in, struct ldb_sort_resp_control); + struct asn1_data data; + + ZERO_STRUCT(data); + + if (!asn1_push_tag(&data, ASN1_SEQUENCE(0))) { + return False; + } + + if (!asn1_write_enumerated(&data, lsrc->result)) { + return False; + } + + if (lsrc->attr_desc) { + if (!asn1_write_OctetString(&data, lsrc->attr_desc, strlen(lsrc->attr_desc))) { + return False; + } + } + + if (!asn1_pop_tag(&data)) { + return False; + } + + *out = data_blob_talloc(mem_ctx, data.data, data.length); + if (out->data == NULL) { + return False; + } + + return True; +} + +static BOOL encode_server_sort_request(void *mem_ctx, void *in, DATA_BLOB *out) +{ + struct ldb_server_sort_control **lssc = talloc_get_type(in, struct ldb_server_sort_control *); + struct asn1_data data; + int num; + + ZERO_STRUCT(data); + + if (!asn1_push_tag(&data, ASN1_SEQUENCE(0))) { + return False; + } + + for (num = 0; lssc[num]; num++) { + if (!asn1_push_tag(&data, ASN1_SEQUENCE(0))) { + return False; + } + + if (!asn1_write_OctetString(&data, lssc[num]->attributeName, strlen(lssc[num]->attributeName))) { + return False; + } + + if (lssc[num]->orderingRule) { + if (!asn1_write_OctetString(&data, lssc[num]->orderingRule, strlen(lssc[num]->orderingRule))) { + return False; + } + } + + if (lssc[num]->reverse) { + if (!asn1_write_BOOLEAN(&data, lssc[num]->reverse)) { + return False; + } + } + + if (!asn1_pop_tag(&data)) { + return False; + } + } + + if (!asn1_pop_tag(&data)) { + return False; + } + + *out = data_blob_talloc(mem_ctx, data.data, data.length); + if (out->data == NULL) { + return False; + } + + return True; +} + +static BOOL encode_extended_dn_request(void *mem_ctx, void *in, DATA_BLOB *out) +{ + struct ldb_extended_dn_control *ledc = talloc_get_type(in, struct ldb_extended_dn_control); + struct asn1_data data; + + ZERO_STRUCT(data); + + if (!asn1_push_tag(&data, ASN1_SEQUENCE(0))) { + return False; + } + + if (!asn1_write_Integer(&data, ledc->type)) { + return False; + } + + if (!asn1_pop_tag(&data)) { + return False; + } + + *out = data_blob_talloc(mem_ctx, data.data, data.length); + if (out->data == NULL) { + return False; + } + + return True; +} + +static BOOL encode_paged_results_request(void *mem_ctx, void *in, DATA_BLOB *out) +{ + struct ldb_paged_control *lprc = talloc_get_type(in, struct ldb_paged_control); + struct asn1_data data; + + ZERO_STRUCT(data); + + if (!asn1_push_tag(&data, ASN1_SEQUENCE(0))) { + return False; + } + + if (!asn1_write_Integer(&data, lprc->size)) { + return False; + } + + if (!asn1_write_OctetString(&data, lprc->cookie, lprc->cookie_len)) { + return False; + } + + if (!asn1_pop_tag(&data)) { + return False; + } + + *out = data_blob_talloc(mem_ctx, data.data, data.length); + if (out->data == NULL) { + return False; + } + + return True; +} + +struct control_handler ldap_known_controls[] = { + { "1.2.840.113556.1.4.319", decode_paged_results_request, encode_paged_results_request }, + { "1.2.840.113556.1.4.529", decode_extended_dn_request, encode_extended_dn_request }, + { "1.2.840.113556.1.4.473", decode_server_sort_request, encode_server_sort_request }, + { "1.2.840.113556.1.4.474", decode_server_sort_response, encode_server_sort_response }, + { NULL, NULL, NULL } +}; + +BOOL ldap_decode_control(void *mem_ctx, struct asn1_data *data, struct ldap_Control *ctrl) +{ + int i; + DATA_BLOB oid; + DATA_BLOB value; + + if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) { + return False; + } + + if (!asn1_read_OctetString(data, &oid)) { + return False; + } + ctrl->oid = talloc_strndup(mem_ctx, (char *)oid.data, oid.length); + if (!(ctrl->oid)) { + return False; + } + + if (asn1_peek_tag(data, ASN1_BOOLEAN)) { + if (!asn1_read_BOOLEAN(data, &(ctrl->critical))) { + return False; + } + } else { + ctrl->critical = False; + } + + ctrl->value = NULL; + + for (i = 0; ldap_known_controls[i].oid != NULL; i++) { + if (strcmp(ldap_known_controls[i].oid, ctrl->oid) == 0) { + + if (!asn1_read_OctetString(data, &value)) { + return False; + } + if (!ldap_known_controls[i].decode(mem_ctx, value, &(ctrl->value))) { + return False; + } + break; + } + } + if (ldap_known_controls[i].oid == NULL) { + return False; + } + + if (!asn1_end_tag(data)) { + return False; + } + + return True; +} + +BOOL ldap_encode_control(void *mem_ctx, struct asn1_data *data, struct ldap_Control *ctrl) +{ + DATA_BLOB value; + int i; + + if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { + return False; + } + + if (!asn1_write_OctetString(data, ctrl->oid, strlen(ctrl->oid))) { + return False; + } + + if (ctrl->critical) { + if (!asn1_write_BOOLEAN(data, ctrl->critical)) { + return False; + } + } + + for (i = 0; ldap_known_controls[i].oid != NULL; i++) { + if (strcmp(ldap_known_controls[i].oid, ctrl->oid) == 0) { + if (!ldap_known_controls[i].encode(mem_ctx, ctrl->value, &value)) { + return False; + } + break; + } + } + if (ldap_known_controls[i].oid == NULL) { + return False; + } + + if (value.length != 0) { + if (!asn1_write_OctetString(data, value.data, value.length)) { + return False; + } + } + + if (!asn1_pop_tag(data)) { + return False; + } + + return True; +} -- cgit From 5db0c6b3042292e0f343ced3d45f2f7a8f97de12 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 14 Jan 2006 01:06:16 +0000 Subject: r12925: implement client side of ASQ control (This used to be commit dd386bdc6ca6fe0b25705d5a375d29e6940b437f) --- source4/libcli/ldap/ldap_controls.c | 99 +++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) (limited to 'source4/libcli/ldap/ldap_controls.c') diff --git a/source4/libcli/ldap/ldap_controls.c b/source4/libcli/ldap/ldap_controls.c index 55e7a94aa7..2a48d401c9 100644 --- a/source4/libcli/ldap/ldap_controls.c +++ b/source4/libcli/ldap/ldap_controls.c @@ -225,6 +225,67 @@ static BOOL decode_paged_results_request(void *mem_ctx, DATA_BLOB in, void **out return True; } +/* seem that this controls has 2 forms one in case it is used with + * a Search Request and another when used ina Search Response + */ +static BOOL decode_asq_control(void *mem_ctx, DATA_BLOB in, void **out) +{ + DATA_BLOB source_attribute; + struct asn1_data data; + struct ldb_asq_control *lac; + + if (!asn1_load(&data, in)) { + return False; + } + + lac = talloc(mem_ctx, struct ldb_asq_control); + if (!lac) { + return False; + } + + if (!asn1_start_tag(&data, ASN1_SEQUENCE(0))) { + return False; + } + + if (asn1_peek_tag(&data, ASN1_OCTET_STRING)) { + + if (!asn1_read_OctetString(&data, &source_attribute)) { + return False; + } + lac->src_attr_len = source_attribute.length; + if (lac->src_attr_len) { + lac->source_attribute = talloc_memdup(lac, source_attribute.data, source_attribute.length); + + if (!(lac->source_attribute)) { + return False; + } + } else { + lac->source_attribute = NULL; + } + + lac->request = 1; + + } else if (asn1_peek_tag(&data, ASN1_ENUMERATED)) { + + if (!asn1_read_enumerated(&data, &(lac->result))) { + return False; + } + + lac->request = 0; + + } else { + return False; + } + + if (!asn1_end_tag(&data)) { + return False; + } + + *out = lac; + + return True; +} + static BOOL encode_server_sort_response(void *mem_ctx, void *in, DATA_BLOB *out) { struct ldb_sort_resp_control *lsrc = talloc_get_type(in, struct ldb_sort_resp_control); @@ -366,11 +427,49 @@ static BOOL encode_paged_results_request(void *mem_ctx, void *in, DATA_BLOB *out return True; } +/* seem that this controls has 2 forms one in case it is used with + * a Search Request and another when used ina Search Response + */ +static BOOL encode_asq_control(void *mem_ctx, void *in, DATA_BLOB *out) +{ + struct ldb_asq_control *lac = talloc_get_type(in, struct ldb_asq_control); + struct asn1_data data; + + ZERO_STRUCT(data); + + if (!asn1_push_tag(&data, ASN1_SEQUENCE(0))) { + return False; + } + + if (lac->request) { + + if (!asn1_write_OctetString(&data, lac->source_attribute, lac->src_attr_len)) { + return False; + } + } else { + if (!asn1_write_enumerated(&data, lac->result)) { + return False; + } + } + + if (!asn1_pop_tag(&data)) { + return False; + } + + *out = data_blob_talloc(mem_ctx, data.data, data.length); + if (out->data == NULL) { + return False; + } + + return True; +} + struct control_handler ldap_known_controls[] = { { "1.2.840.113556.1.4.319", decode_paged_results_request, encode_paged_results_request }, { "1.2.840.113556.1.4.529", decode_extended_dn_request, encode_extended_dn_request }, { "1.2.840.113556.1.4.473", decode_server_sort_request, encode_server_sort_request }, { "1.2.840.113556.1.4.474", decode_server_sort_response, encode_server_sort_response }, + { "1.2.840.113556.1.4.1504", decode_asq_control, encode_asq_control }, { NULL, NULL, NULL } }; -- cgit From 3b447ab4a131509491b42a1843c52ba69bab5e11 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 17 Jan 2006 04:04:57 +0000 Subject: r12977: Some code to implement the client side of the Dirsync control Still investigating how it works. Simo. (This used to be commit bebd403523e581606505e05e7cb621efbc22fa36) --- source4/libcli/ldap/ldap_controls.c | 86 +++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) (limited to 'source4/libcli/ldap/ldap_controls.c') diff --git a/source4/libcli/ldap/ldap_controls.c b/source4/libcli/ldap/ldap_controls.c index 2a48d401c9..744f21fed1 100644 --- a/source4/libcli/ldap/ldap_controls.c +++ b/source4/libcli/ldap/ldap_controls.c @@ -225,6 +225,56 @@ static BOOL decode_paged_results_request(void *mem_ctx, DATA_BLOB in, void **out return True; } +static BOOL decode_dirsync_request(void *mem_ctx, DATA_BLOB in, void **out) +{ + DATA_BLOB cookie; + struct asn1_data data; + struct ldb_dirsync_control *ldc; + + if (!asn1_load(&data, in)) { + return False; + } + + ldc = talloc(mem_ctx, struct ldb_dirsync_control); + if (!ldc) { + return False; + } + + if (!asn1_start_tag(&data, ASN1_SEQUENCE(0))) { + return False; + } + + if (!asn1_read_Integer(&data, &(ldc->flags))) { + return False; + } + + if (!asn1_read_Integer(&data, &(ldc->max_attributes))) { + return False; + } + + if (!asn1_read_OctetString(&data, &cookie)) { + return False; + } + ldc->cookie_len = cookie.length; + if (ldc->cookie_len) { + ldc->cookie = talloc_memdup(ldc, cookie.data, cookie.length); + + if (!(ldc->cookie)) { + return False; + } + } else { + ldc->cookie = NULL; + } + + if (!asn1_end_tag(&data)) { + return False; + } + + *out = ldc; + + return True; +} + /* seem that this controls has 2 forms one in case it is used with * a Search Request and another when used ina Search Response */ @@ -464,12 +514,48 @@ static BOOL encode_asq_control(void *mem_ctx, void *in, DATA_BLOB *out) return True; } +static BOOL encode_dirsync_request(void *mem_ctx, void *in, DATA_BLOB *out) +{ + struct ldb_dirsync_control *ldc = talloc_get_type(in, struct ldb_dirsync_control); + struct asn1_data data; + + ZERO_STRUCT(data); + + if (!asn1_push_tag(&data, ASN1_SEQUENCE(0))) { + return False; + } + + if (!asn1_write_Integer(&data, ldc->flags)) { + return False; + } + + if (!asn1_write_Integer(&data, ldc->max_attributes)) { + return False; + } + + if (!asn1_write_OctetString(&data, ldc->cookie, ldc->cookie_len)) { + return False; + } + + if (!asn1_pop_tag(&data)) { + return False; + } + + *out = data_blob_talloc(mem_ctx, data.data, data.length); + if (out->data == NULL) { + return False; + } + + return True; +} + struct control_handler ldap_known_controls[] = { { "1.2.840.113556.1.4.319", decode_paged_results_request, encode_paged_results_request }, { "1.2.840.113556.1.4.529", decode_extended_dn_request, encode_extended_dn_request }, { "1.2.840.113556.1.4.473", decode_server_sort_request, encode_server_sort_request }, { "1.2.840.113556.1.4.474", decode_server_sort_response, encode_server_sort_response }, { "1.2.840.113556.1.4.1504", decode_asq_control, encode_asq_control }, + { "1.2.840.113556.1.4.841", decode_dirsync_request, encode_dirsync_request }, { NULL, NULL, NULL } }; -- cgit From 828ee2bc6fa4f757c63a31054a0046fe09f8c26e Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 17 Jan 2006 18:56:04 +0000 Subject: r12984: add parse code and ldbsearch cmdline code for NOTIFICATION LDAP Controls http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ldap/ldap/ldap_server_notification_oid.asp this doesn't work yet, but it shows that we need to extend ldb to correctly handle async requests... metze (This used to be commit 1fe67189490c9faf499b68a28071a6294a53db0e) --- source4/libcli/ldap/ldap_controls.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'source4/libcli/ldap/ldap_controls.c') diff --git a/source4/libcli/ldap/ldap_controls.c b/source4/libcli/ldap/ldap_controls.c index 744f21fed1..1f7a415e8e 100644 --- a/source4/libcli/ldap/ldap_controls.c +++ b/source4/libcli/ldap/ldap_controls.c @@ -60,7 +60,7 @@ static BOOL decode_server_sort_response(void *mem_ctx, DATA_BLOB in, void **out) if (!asn1_read_OctetString(&data, &attr)) { return False; } - lsrc->attr_desc = talloc_strndup(lsrc, attr.data, attr.length); + lsrc->attr_desc = talloc_strndup(lsrc, (const char *)attr.data, attr.length); if (!lsrc->attr_desc) { return False; } @@ -111,7 +111,7 @@ static BOOL decode_server_sort_request(void *mem_ctx, DATA_BLOB in, void **out) return False; } - lssc[num]->attributeName = talloc_strndup(lssc[num], attr.data, attr.length); + lssc[num]->attributeName = talloc_strndup(lssc[num], (const char *)attr.data, attr.length); if (!lssc [num]->attributeName) { return False; } @@ -120,7 +120,7 @@ static BOOL decode_server_sort_request(void *mem_ctx, DATA_BLOB in, void **out) if (!asn1_read_OctetString(&data, &rule)) { return False; } - lssc[num]->orderingRule = talloc_strndup(lssc[num], rule.data, rule.length); + lssc[num]->orderingRule = talloc_strndup(lssc[num], (const char *)rule.data, rule.length); if (!lssc[num]->orderingRule) { return False; } @@ -336,6 +336,15 @@ static BOOL decode_asq_control(void *mem_ctx, DATA_BLOB in, void **out) return True; } +static BOOL decode_notification_request(void *mem_ctx, DATA_BLOB in, void **out) +{ + if (in.length != 0) { + return False; + } + + return True; +} + static BOOL encode_server_sort_response(void *mem_ctx, void *in, DATA_BLOB *out) { struct ldb_sort_resp_control *lsrc = talloc_get_type(in, struct ldb_sort_resp_control); @@ -549,6 +558,16 @@ static BOOL encode_dirsync_request(void *mem_ctx, void *in, DATA_BLOB *out) return True; } +static BOOL encode_notification_request(void *mem_ctx, void *in, DATA_BLOB *out) +{ + if (in) { + return False; + } + + *out = data_blob(NULL, 0); + return True; +} + struct control_handler ldap_known_controls[] = { { "1.2.840.113556.1.4.319", decode_paged_results_request, encode_paged_results_request }, { "1.2.840.113556.1.4.529", decode_extended_dn_request, encode_extended_dn_request }, @@ -556,6 +575,7 @@ struct control_handler ldap_known_controls[] = { { "1.2.840.113556.1.4.474", decode_server_sort_response, encode_server_sort_response }, { "1.2.840.113556.1.4.1504", decode_asq_control, encode_asq_control }, { "1.2.840.113556.1.4.841", decode_dirsync_request, encode_dirsync_request }, + { "1.2.840.113556.1.4.528", decode_notification_request, encode_notification_request }, { NULL, NULL, NULL } }; -- cgit From ad5e8bbe9d5c2250092bb3a83098c3af46304a82 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 5 Feb 2006 17:28:27 +0000 Subject: r13352: Integrate Patch to support the ManageDSAIT control from Pete Rowley (This used to be commit bf20a848fda1607ca1b0d84791c299c0035793a1) --- source4/libcli/ldap/ldap_controls.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'source4/libcli/ldap/ldap_controls.c') diff --git a/source4/libcli/ldap/ldap_controls.c b/source4/libcli/ldap/ldap_controls.c index 1f7a415e8e..cb7b52d423 100644 --- a/source4/libcli/ldap/ldap_controls.c +++ b/source4/libcli/ldap/ldap_controls.c @@ -345,6 +345,15 @@ static BOOL decode_notification_request(void *mem_ctx, DATA_BLOB in, void **out) return True; } +static BOOL decode_manageDSAIT_request(void *mem_ctx, DATA_BLOB in, void **out) +{ + if (in.length != 0) { + return False; + } + + return True; +} + static BOOL encode_server_sort_response(void *mem_ctx, void *in, DATA_BLOB *out) { struct ldb_sort_resp_control *lsrc = talloc_get_type(in, struct ldb_sort_resp_control); @@ -568,6 +577,16 @@ static BOOL encode_notification_request(void *mem_ctx, void *in, DATA_BLOB *out) return True; } +static BOOL encode_manageDSAIT_request(void *mem_ctx, void *in, DATA_BLOB *out) +{ + if (in) { + return False; + } + + *out = data_blob(NULL, 0); + return True; +} + struct control_handler ldap_known_controls[] = { { "1.2.840.113556.1.4.319", decode_paged_results_request, encode_paged_results_request }, { "1.2.840.113556.1.4.529", decode_extended_dn_request, encode_extended_dn_request }, @@ -576,6 +595,7 @@ struct control_handler ldap_known_controls[] = { { "1.2.840.113556.1.4.1504", decode_asq_control, encode_asq_control }, { "1.2.840.113556.1.4.841", decode_dirsync_request, encode_dirsync_request }, { "1.2.840.113556.1.4.528", decode_notification_request, encode_notification_request }, + { "2.16.840.1.113730.3.4.2", decode_manageDSAIT_request, encode_manageDSAIT_request }, { NULL, NULL, NULL } }; -- cgit From 3721bca79dc6ff409085a2fc40cbd060d25191d4 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 5 Feb 2006 20:48:27 +0000 Subject: r13354: Add tests to check that controls work properly Fix asq module, add a second_stage_init to register with rootdse Fix asq control ldap parsing routines (this was nasty to find out) (This used to be commit 933a80397d137f7d5b79c82a068d62bb6928ef47) --- source4/libcli/ldap/ldap_controls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/ldap/ldap_controls.c') diff --git a/source4/libcli/ldap/ldap_controls.c b/source4/libcli/ldap/ldap_controls.c index cb7b52d423..e02efdee2c 100644 --- a/source4/libcli/ldap/ldap_controls.c +++ b/source4/libcli/ldap/ldap_controls.c @@ -304,7 +304,7 @@ static BOOL decode_asq_control(void *mem_ctx, DATA_BLOB in, void **out) } lac->src_attr_len = source_attribute.length; if (lac->src_attr_len) { - lac->source_attribute = talloc_memdup(lac, source_attribute.data, source_attribute.length); + lac->source_attribute = talloc_strndup(lac, source_attribute.data, source_attribute.length); if (!(lac->source_attribute)) { return False; -- cgit From 338c410fec8dbd902485e56567f6aecf256cdba2 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 6 Feb 2006 01:21:17 +0000 Subject: r13361: initial implementation of the vlv control seem still buggy, can't make w2k3 to like it yet (This used to be commit e1318383e91f6f6db39e3e3c9946fbb089753947) --- source4/libcli/ldap/ldap_controls.c | 245 +++++++++++++++++++++++++++++++++++- 1 file changed, 244 insertions(+), 1 deletion(-) (limited to 'source4/libcli/ldap/ldap_controls.c') diff --git a/source4/libcli/ldap/ldap_controls.c b/source4/libcli/ldap/ldap_controls.c index e02efdee2c..222b4a3358 100644 --- a/source4/libcli/ldap/ldap_controls.c +++ b/source4/libcli/ldap/ldap_controls.c @@ -304,7 +304,7 @@ static BOOL decode_asq_control(void *mem_ctx, DATA_BLOB in, void **out) } lac->src_attr_len = source_attribute.length; if (lac->src_attr_len) { - lac->source_attribute = talloc_strndup(lac, source_attribute.data, source_attribute.length); + lac->source_attribute = talloc_strndup(lac, (char *)source_attribute.data, source_attribute.length); if (!(lac->source_attribute)) { return False; @@ -354,6 +354,154 @@ static BOOL decode_manageDSAIT_request(void *mem_ctx, DATA_BLOB in, void **out) return True; } +static BOOL decode_vlv_request(void *mem_ctx, DATA_BLOB in, void **out) +{ + DATA_BLOB assertion_value, context_id; + struct asn1_data data; + struct ldb_vlv_req_control *lvrc; + + if (!asn1_load(&data, in)) { + return False; + } + + lvrc = talloc(mem_ctx, struct ldb_vlv_req_control); + if (!lvrc) { + return False; + } + + if (!asn1_start_tag(&data, ASN1_SEQUENCE(0))) { + return False; + } + + if (!asn1_read_Integer(&data, &(lvrc->beforeCount))) { + return False; + } + + if (!asn1_read_Integer(&data, &(lvrc->afterCount))) { + return False; + } + + if (asn1_peek_tag(&data, ASN1_SEQUENCE(0))) { + + lvrc->type = 0; + + if (!asn1_start_tag(&data, ASN1_SEQUENCE(0))) { + return False; + } + + if (!asn1_read_Integer(&data, &(lvrc->match.byOffset.offset))) { + return False; + } + + if (!asn1_read_Integer(&data, &(lvrc->match.byOffset.contentCount))) { + return False; + } + + if (!asn1_end_tag(&data)) { + return False; + } + + } else { + + lvrc->type = 1; + + if (!asn1_read_OctetString(&data, &assertion_value)) { + return False; + } + lvrc->match.gtOrEq.value_len = assertion_value.length; + if (lvrc->match.gtOrEq.value_len) { + lvrc->match.gtOrEq.value = talloc_memdup(lvrc, assertion_value.data, assertion_value.length); + + if (!(lvrc->match.gtOrEq.value)) { + return False; + } + } else { + lvrc->match.gtOrEq.value = NULL; + } + } + + if (asn1_peek_tag(&data, ASN1_OCTET_STRING)) { + if (!asn1_read_OctetString(&data, &context_id)) { + return False; + } + lvrc->ctxid_len = context_id.length; + if (lvrc->ctxid_len) { + lvrc->contextId = talloc_memdup(lvrc, context_id.data, context_id.length); + + if (!(lvrc->contextId)) { + return False; + } + } else { + lvrc->contextId = NULL; + } + } else { + lvrc->contextId = NULL; + lvrc->ctxid_len = 0; + } + + if (!asn1_end_tag(&data)) { + return False; + } + + *out = lvrc; + + return True; +} + +static BOOL decode_vlv_response(void *mem_ctx, DATA_BLOB in, void **out) +{ + DATA_BLOB context_id; + struct asn1_data data; + struct ldb_vlv_resp_control *lvrc; + + if (!asn1_load(&data, in)) { + return False; + } + + lvrc = talloc(mem_ctx, struct ldb_vlv_resp_control); + if (!lvrc) { + return False; + } + + if (!asn1_start_tag(&data, ASN1_SEQUENCE(0))) { + return False; + } + + if (!asn1_read_Integer(&data, &(lvrc->targetPosition))) { + return False; + } + + if (!asn1_read_Integer(&data, &(lvrc->contentCount))) { + return False; + } + + if (!asn1_read_enumerated(&data, &(lvrc->vlv_result))) { + return False; + } + + if (asn1_peek_tag(&data, ASN1_OCTET_STRING)) { + if (!asn1_read_OctetString(&data, &context_id)) { + return False; + } + lvrc->contextId = talloc_strndup(lvrc, (const char *)context_id.data, context_id.length); + if (!lvrc->contextId) { + return False; + } + lvrc->ctxid_len = context_id.length; + } else { + lvrc->contextId = NULL; + lvrc->ctxid_len = 0; + } + + if (!asn1_end_tag(&data)) { + return False; + } + + *out = lvrc; + + return True; +} + static BOOL encode_server_sort_response(void *mem_ctx, void *in, DATA_BLOB *out) { struct ldb_sort_resp_control *lsrc = talloc_get_type(in, struct ldb_sort_resp_control); @@ -587,6 +735,99 @@ static BOOL encode_manageDSAIT_request(void *mem_ctx, void *in, DATA_BLOB *out) return True; } +static BOOL encode_vlv_request(void *mem_ctx, void *in, DATA_BLOB *out) +{ + struct ldb_vlv_req_control *lvrc = talloc_get_type(in, struct ldb_vlv_req_control); + struct asn1_data data; + + ZERO_STRUCT(data); + + if (!asn1_push_tag(&data, ASN1_SEQUENCE(0))) { + return False; + } + + if (!asn1_write_Integer(&data, lvrc->beforeCount)) { + return False; + } + + if (!asn1_write_Integer(&data, lvrc->afterCount)) { + return False; + } + + if (lvrc->type == 0) { + if (!asn1_write_Integer(&data, lvrc->match.byOffset.offset)) { + return False; + } + + if (!asn1_write_Integer(&data, lvrc->match.byOffset.contentCount)) { + return False; + } + } else { + + if (!asn1_write_OctetString(&data, lvrc->match.gtOrEq.value, lvrc->match.gtOrEq.value_len)) { + return False; + } + } + + if (lvrc->ctxid_len) { + if (!asn1_write_OctetString(&data, lvrc->contextId, lvrc->ctxid_len)) { + return False; + } + } + + if (!asn1_pop_tag(&data)) { + return False; + } + + *out = data_blob_talloc(mem_ctx, data.data, data.length); + if (out->data == NULL) { + return False; + } + + return True; +} + +static BOOL encode_vlv_response(void *mem_ctx, void *in, DATA_BLOB *out) +{ + struct ldb_vlv_resp_control *lvrc = talloc_get_type(in, struct ldb_vlv_resp_control); + struct asn1_data data; + + ZERO_STRUCT(data); + + if (!asn1_push_tag(&data, ASN1_SEQUENCE(0))) { + return False; + } + + if (!asn1_write_Integer(&data, lvrc->targetPosition)) { + return False; + } + + if (!asn1_write_Integer(&data, lvrc->contentCount)) { + return False; + } + + if (!asn1_write_enumerated(&data, lvrc->vlv_result)) { + return False; + } + + if (lvrc->ctxid_len) { + if (!asn1_write_OctetString(&data, lvrc->contextId, lvrc->ctxid_len)) { + return False; + } + } + + if (!asn1_pop_tag(&data)) { + return False; + } + + *out = data_blob_talloc(mem_ctx, data.data, data.length); + if (out->data == NULL) { + return False; + } + + return True; +} + struct control_handler ldap_known_controls[] = { { "1.2.840.113556.1.4.319", decode_paged_results_request, encode_paged_results_request }, { "1.2.840.113556.1.4.529", decode_extended_dn_request, encode_extended_dn_request }, @@ -596,6 +837,8 @@ struct control_handler ldap_known_controls[] = { { "1.2.840.113556.1.4.841", decode_dirsync_request, encode_dirsync_request }, { "1.2.840.113556.1.4.528", decode_notification_request, encode_notification_request }, { "2.16.840.1.113730.3.4.2", decode_manageDSAIT_request, encode_manageDSAIT_request }, + { "2.16.840.1.113730.3.4.9", decode_vlv_request, encode_vlv_request }, + { "2.16.840.1.113730.3.4.10", decode_vlv_response, encode_vlv_response }, { NULL, NULL, NULL } }; -- cgit From f7def09a1ec105294b189c0d933f59977a252057 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 6 Feb 2006 22:55:34 +0000 Subject: r13372: fixes ... still no joy (This used to be commit 0e2cca9153619d646b90f32620905ab66b017c6a) --- source4/libcli/ldap/ldap_controls.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source4/libcli/ldap/ldap_controls.c') diff --git a/source4/libcli/ldap/ldap_controls.c b/source4/libcli/ldap/ldap_controls.c index 222b4a3358..f85e4843c1 100644 --- a/source4/libcli/ldap/ldap_controls.c +++ b/source4/libcli/ldap/ldap_controls.c @@ -755,6 +755,10 @@ static BOOL encode_vlv_request(void *mem_ctx, void *in, DATA_BLOB *out) } if (lvrc->type == 0) { + if (!asn1_push_tag(&data, ASN1_SEQUENCE(0))) { + return False; + } + if (!asn1_write_Integer(&data, lvrc->match.byOffset.offset)) { return False; } @@ -762,6 +766,10 @@ static BOOL encode_vlv_request(void *mem_ctx, void *in, DATA_BLOB *out) if (!asn1_write_Integer(&data, lvrc->match.byOffset.contentCount)) { return False; } + + if (!asn1_pop_tag(&data)) { + return False; + } } else { if (!asn1_write_OctetString(&data, lvrc->match.gtOrEq.value, lvrc->match.gtOrEq.value_len)) { -- cgit From f2e88ab7cf2010ffeae2f16762f88285d1a77fd8 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 15 Feb 2006 13:33:33 +0000 Subject: r13506: zero memory as some ASN.1 elements are optional, and we should initialize them for the internal use... found by 'make valgrindtest' metze (This used to be commit 1db9501c5261a974c6da1938537c7991ff6cfefd) --- source4/libcli/ldap/ldap_controls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/ldap/ldap_controls.c') diff --git a/source4/libcli/ldap/ldap_controls.c b/source4/libcli/ldap/ldap_controls.c index f85e4843c1..4a28fa510b 100644 --- a/source4/libcli/ldap/ldap_controls.c +++ b/source4/libcli/ldap/ldap_controls.c @@ -98,7 +98,7 @@ static BOOL decode_server_sort_request(void *mem_ctx, DATA_BLOB in, void **out) if (!lssc) { return False; } - lssc[num] = talloc(lssc, struct ldb_server_sort_control); + lssc[num] = talloc_zero(lssc, struct ldb_server_sort_control); if (!lssc[num]) { return False; } -- cgit From 7449f4d8030e7d4a14c75d35af5ea68cf682d24f Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 15 Feb 2006 15:19:10 +0000 Subject: r13508: some ASN.1 element in LDAP are optional, make it possible to code the difference between a zero length and a NULL DATA_BLOB... metze (This used to be commit 54f0b19c55df8ad3882f31a114e2ea0e4cf940ae) --- source4/libcli/ldap/ldap_controls.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'source4/libcli/ldap/ldap_controls.c') diff --git a/source4/libcli/ldap/ldap_controls.c b/source4/libcli/ldap/ldap_controls.c index 4a28fa510b..5bd46cf7a9 100644 --- a/source4/libcli/ldap/ldap_controls.c +++ b/source4/libcli/ldap/ldap_controls.c @@ -304,7 +304,7 @@ static BOOL decode_asq_control(void *mem_ctx, DATA_BLOB in, void **out) } lac->src_attr_len = source_attribute.length; if (lac->src_attr_len) { - lac->source_attribute = talloc_strndup(lac, (char *)source_attribute.data, source_attribute.length); + lac->source_attribute = talloc_strndup(lac, (const char *)source_attribute.data, source_attribute.length); if (!(lac->source_attribute)) { return False; @@ -864,7 +864,7 @@ BOOL ldap_decode_control(void *mem_ctx, struct asn1_data *data, struct ldap_Cont return False; } ctrl->oid = talloc_strndup(mem_ctx, (char *)oid.data, oid.length); - if (!(ctrl->oid)) { + if (!ctrl->oid) { return False; } @@ -878,13 +878,17 @@ BOOL ldap_decode_control(void *mem_ctx, struct asn1_data *data, struct ldap_Cont ctrl->value = NULL; + if (!asn1_peek_tag(data, ASN1_OCTET_STRING)) { + goto end_tag; + } + + if (!asn1_read_OctetString(data, &value)) { + return False; + } + for (i = 0; ldap_known_controls[i].oid != NULL; i++) { if (strcmp(ldap_known_controls[i].oid, ctrl->oid) == 0) { - - if (!asn1_read_OctetString(data, &value)) { - return False; - } - if (!ldap_known_controls[i].decode(mem_ctx, value, &(ctrl->value))) { + if (!ldap_known_controls[i].decode(mem_ctx, value, &ctrl->value)) { return False; } break; @@ -894,6 +898,7 @@ BOOL ldap_decode_control(void *mem_ctx, struct asn1_data *data, struct ldap_Cont return False; } +end_tag: if (!asn1_end_tag(data)) { return False; } @@ -909,17 +914,21 @@ BOOL ldap_encode_control(void *mem_ctx, struct asn1_data *data, struct ldap_Cont if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { return False; } - + if (!asn1_write_OctetString(data, ctrl->oid, strlen(ctrl->oid))) { return False; } - + if (ctrl->critical) { if (!asn1_write_BOOLEAN(data, ctrl->critical)) { return False; } } + if (!ctrl->value) { + goto pop_tag; + } + for (i = 0; ldap_known_controls[i].oid != NULL; i++) { if (strcmp(ldap_known_controls[i].oid, ctrl->oid) == 0) { if (!ldap_known_controls[i].encode(mem_ctx, ctrl->value, &value)) { @@ -932,12 +941,11 @@ BOOL ldap_encode_control(void *mem_ctx, struct asn1_data *data, struct ldap_Cont return False; } - if (value.length != 0) { - if (!asn1_write_OctetString(data, value.data, value.length)) { - return False; - } + if (!asn1_write_OctetString(data, value.data, value.length)) { + return False; } +pop_tag: if (!asn1_pop_tag(data)) { return False; } -- cgit From 00fe70e5b917769418f68eaa255d3a06a9a08ce7 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 22 Feb 2006 01:31:35 +0000 Subject: r13609: Get in the initial work on making ldb async Currently only ldb_ildap is async, the plan is to first make all backend support the async calls, and then remove the sync functions from backends and keep the only in the API. Modules will need to be transformed along the way. Simo (This used to be commit 1e2c13b2d52de7c534493dd79a2c0596a3e8c1f5) --- source4/libcli/ldap/ldap_controls.c | 49 ++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 9 deletions(-) (limited to 'source4/libcli/ldap/ldap_controls.c') diff --git a/source4/libcli/ldap/ldap_controls.c b/source4/libcli/ldap/ldap_controls.c index 5bd46cf7a9..373b71d370 100644 --- a/source4/libcli/ldap/ldap_controls.c +++ b/source4/libcli/ldap/ldap_controls.c @@ -381,10 +381,14 @@ static BOOL decode_vlv_request(void *mem_ctx, DATA_BLOB in, void **out) return False; } - if (asn1_peek_tag(&data, ASN1_SEQUENCE(0))) { + if (asn1_peek_tag(&data, ASN1_CONTEXT(0))) { lvrc->type = 0; + if (!asn1_start_tag(&data, ASN1_CONTEXT(0))) { + return False; + } + if (!asn1_start_tag(&data, ASN1_SEQUENCE(0))) { return False; } @@ -397,7 +401,11 @@ static BOOL decode_vlv_request(void *mem_ctx, DATA_BLOB in, void **out) return False; } - if (!asn1_end_tag(&data)) { + if (!asn1_end_tag(&data)) { /*SEQUENCE*/ + return False; + } + + if (!asn1_end_tag(&data)) { /*CONTEXT*/ return False; } @@ -405,6 +413,10 @@ static BOOL decode_vlv_request(void *mem_ctx, DATA_BLOB in, void **out) lvrc->type = 1; + if (!asn1_start_tag(&data, ASN1_CONTEXT(1))) { + return False; + } + if (!asn1_read_OctetString(&data, &assertion_value)) { return False; } @@ -418,6 +430,10 @@ static BOOL decode_vlv_request(void *mem_ctx, DATA_BLOB in, void **out) } else { lvrc->match.gtOrEq.value = NULL; } + + if (!asn1_end_tag(&data)) { /*CONTEXT*/ + return False; + } } if (asn1_peek_tag(&data, ASN1_OCTET_STRING)) { @@ -755,6 +771,10 @@ static BOOL encode_vlv_request(void *mem_ctx, void *in, DATA_BLOB *out) } if (lvrc->type == 0) { + if (!asn1_push_tag(&data, ASN1_CONTEXT(0))) { + return False; + } + if (!asn1_push_tag(&data, ASN1_SEQUENCE(0))) { return False; } @@ -767,14 +787,25 @@ static BOOL encode_vlv_request(void *mem_ctx, void *in, DATA_BLOB *out) return False; } - if (!asn1_pop_tag(&data)) { + if (!asn1_pop_tag(&data)) { /*SEQUENCE*/ + return False; + } + + if (!asn1_pop_tag(&data)) { /*CONTEXT*/ return False; } } else { + if (!asn1_push_tag(&data, ASN1_CONTEXT(1))) { + return False; + } if (!asn1_write_OctetString(&data, lvrc->match.gtOrEq.value, lvrc->match.gtOrEq.value_len)) { return False; } + + if (!asn1_pop_tag(&data)) { /*CONTEXT*/ + return False; + } } if (lvrc->ctxid_len) { @@ -850,7 +881,7 @@ struct control_handler ldap_known_controls[] = { { NULL, NULL, NULL } }; -BOOL ldap_decode_control(void *mem_ctx, struct asn1_data *data, struct ldap_Control *ctrl) +BOOL ldap_decode_control(void *mem_ctx, struct asn1_data *data, struct ldb_control *ctrl) { int i; DATA_BLOB oid; @@ -876,7 +907,7 @@ BOOL ldap_decode_control(void *mem_ctx, struct asn1_data *data, struct ldap_Cont ctrl->critical = False; } - ctrl->value = NULL; + ctrl->data = NULL; if (!asn1_peek_tag(data, ASN1_OCTET_STRING)) { goto end_tag; @@ -888,7 +919,7 @@ BOOL ldap_decode_control(void *mem_ctx, struct asn1_data *data, struct ldap_Cont for (i = 0; ldap_known_controls[i].oid != NULL; i++) { if (strcmp(ldap_known_controls[i].oid, ctrl->oid) == 0) { - if (!ldap_known_controls[i].decode(mem_ctx, value, &ctrl->value)) { + if (!ldap_known_controls[i].decode(mem_ctx, value, &ctrl->data)) { return False; } break; @@ -906,7 +937,7 @@ end_tag: return True; } -BOOL ldap_encode_control(void *mem_ctx, struct asn1_data *data, struct ldap_Control *ctrl) +BOOL ldap_encode_control(void *mem_ctx, struct asn1_data *data, struct ldb_control *ctrl) { DATA_BLOB value; int i; @@ -925,13 +956,13 @@ BOOL ldap_encode_control(void *mem_ctx, struct asn1_data *data, struct ldap_Cont } } - if (!ctrl->value) { + if (!ctrl->data) { goto pop_tag; } for (i = 0; ldap_known_controls[i].oid != NULL; i++) { if (strcmp(ldap_known_controls[i].oid, ctrl->oid) == 0) { - if (!ldap_known_controls[i].encode(mem_ctx, ctrl->value, &value)) { + if (!ldap_known_controls[i].encode(mem_ctx, ctrl->data, &value)) { return False; } break; -- cgit From 07fd3bd5121aa9b81b6c7a14910f09f64ab4bad9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 15 Mar 2006 05:31:51 +0000 Subject: r14424: another empty controls case (This used to be commit 7d0eb678bf3649fb4e09da039dd1b716ea3df2cc) --- source4/libcli/ldap/ldap_controls.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source4/libcli/ldap/ldap_controls.c') diff --git a/source4/libcli/ldap/ldap_controls.c b/source4/libcli/ldap/ldap_controls.c index 373b71d370..ccb1b74a55 100644 --- a/source4/libcli/ldap/ldap_controls.c +++ b/source4/libcli/ldap/ldap_controls.c @@ -137,7 +137,9 @@ static BOOL decode_server_sort_request(void *mem_ctx, DATA_BLOB in, void **out) } } - lssc[num] = NULL; + if (lssc != NULL) { + lssc[num] = NULL; + } if (!asn1_end_tag(&data)) { return False; -- cgit From cf0f4ec073b694e43daeeddf9aab51cd3e51fd2b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 30 Apr 2006 13:54:03 +0000 Subject: r15358: Fix some compiler warnings / type safety. Found by tcc (This used to be commit 12ba42de5886f9f4f9b1698476557e0c217d06f3) --- source4/libcli/ldap/ldap_controls.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source4/libcli/ldap/ldap_controls.c') diff --git a/source4/libcli/ldap/ldap_controls.c b/source4/libcli/ldap/ldap_controls.c index ccb1b74a55..47b1262aea 100644 --- a/source4/libcli/ldap/ldap_controls.c +++ b/source4/libcli/ldap/ldap_controls.c @@ -127,9 +127,11 @@ static BOOL decode_server_sort_request(void *mem_ctx, DATA_BLOB in, void **out) } if (asn1_peek_tag(&data, ASN1_BOOLEAN)) { - if (!asn1_read_BOOLEAN(&data, &(lssc[num]->reverse))) { + bool reverse; + if (!asn1_read_BOOLEAN(&data, &reverse)) { return False; } + lssc[num]->reverse = reverse; } if (!asn1_end_tag(&data)) { @@ -902,9 +904,11 @@ BOOL ldap_decode_control(void *mem_ctx, struct asn1_data *data, struct ldb_contr } if (asn1_peek_tag(data, ASN1_BOOLEAN)) { - if (!asn1_read_BOOLEAN(data, &(ctrl->critical))) { + bool critical; + if (!asn1_read_BOOLEAN(data, &critical)) { return False; } + critical = ctrl->critical; } else { ctrl->critical = False; } -- cgit From 37e94956e0a976b6d144b5885b2ef18bb8e4b39b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 30 Apr 2006 20:00:37 +0000 Subject: r15365: Fix error in my previous commit, caught by metze. (This used to be commit 0d99397007960e555f562f1498a202407e235f36) --- source4/libcli/ldap/ldap_controls.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/libcli/ldap/ldap_controls.c') diff --git a/source4/libcli/ldap/ldap_controls.c b/source4/libcli/ldap/ldap_controls.c index 47b1262aea..f4f54ec2e2 100644 --- a/source4/libcli/ldap/ldap_controls.c +++ b/source4/libcli/ldap/ldap_controls.c @@ -127,7 +127,7 @@ static BOOL decode_server_sort_request(void *mem_ctx, DATA_BLOB in, void **out) } if (asn1_peek_tag(&data, ASN1_BOOLEAN)) { - bool reverse; + BOOL reverse; if (!asn1_read_BOOLEAN(&data, &reverse)) { return False; } @@ -904,11 +904,11 @@ BOOL ldap_decode_control(void *mem_ctx, struct asn1_data *data, struct ldb_contr } if (asn1_peek_tag(data, ASN1_BOOLEAN)) { - bool critical; + BOOL critical; if (!asn1_read_BOOLEAN(data, &critical)) { return False; } - critical = ctrl->critical; + ctrl->critical = critical; } else { ctrl->critical = False; } -- cgit From 172a83d72491f90f6191be1040ef8b2e1789bd2e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 13 May 2006 19:14:12 +0000 Subject: r15573: Fix build of systems that have iconv headers in non-standard locations Split of system/locale.h header from system/iconv.h Previously, iconv wasn't being used on these systems (This used to be commit aa6d66fda69779d1c2948a1aca85dbd5208f1cba) --- source4/libcli/ldap/ldap_controls.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/libcli/ldap/ldap_controls.c') diff --git a/source4/libcli/ldap/ldap_controls.c b/source4/libcli/ldap/ldap_controls.c index f4f54ec2e2..ee8f9d4bb1 100644 --- a/source4/libcli/ldap/ldap_controls.c +++ b/source4/libcli/ldap/ldap_controls.c @@ -21,7 +21,6 @@ */ #include "includes.h" -#include "system/iconv.h" #include "libcli/util/asn_1.h" #include "libcli/ldap/ldap.h" #include "lib/ldb/include/ldb.h" -- cgit From b4028ca1041fc8e0266de2f5c858dd40e660aafb Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 5 Aug 2006 10:26:23 +0000 Subject: r17418: add client support for the LDAP_SERVER_SD_FLAGS control metze (This used to be commit 23759a1e9b05c4fde475a9016cb0b7447656d7e7) --- source4/libcli/ldap/ldap_controls.c | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'source4/libcli/ldap/ldap_controls.c') diff --git a/source4/libcli/ldap/ldap_controls.c b/source4/libcli/ldap/ldap_controls.c index ee8f9d4bb1..445b5f8086 100644 --- a/source4/libcli/ldap/ldap_controls.c +++ b/source4/libcli/ldap/ldap_controls.c @@ -182,6 +182,37 @@ static BOOL decode_extended_dn_request(void *mem_ctx, DATA_BLOB in, void **out) return True; } +static BOOL decode_sd_flags_request(void *mem_ctx, DATA_BLOB in, void **out) +{ + struct asn1_data data; + struct ldb_sd_flags_control *lsdfc; + + if (!asn1_load(&data, in)) { + return False; + } + + lsdfc = talloc(mem_ctx, struct ldb_sd_flags_control); + if (!lsdfc) { + return False; + } + + if (!asn1_start_tag(&data, ASN1_SEQUENCE(0))) { + return False; + } + + if (!asn1_read_Integer(&data, &(lsdfc->secinfo_flags))) { + return False; + } + + if (!asn1_end_tag(&data)) { + return False; + } + + *out = lsdfc; + + return True; +} + static BOOL decode_paged_results_request(void *mem_ctx, DATA_BLOB in, void **out) { DATA_BLOB cookie; @@ -631,6 +662,33 @@ static BOOL encode_extended_dn_request(void *mem_ctx, void *in, DATA_BLOB *out) return True; } +static BOOL encode_sd_flags_request(void *mem_ctx, void *in, DATA_BLOB *out) +{ + struct ldb_sd_flags_control *lsdfc = talloc_get_type(in, struct ldb_sd_flags_control); + struct asn1_data data; + + ZERO_STRUCT(data); + + if (!asn1_push_tag(&data, ASN1_SEQUENCE(0))) { + return False; + } + + if (!asn1_write_Integer(&data, lsdfc->secinfo_flags)) { + return False; + } + + if (!asn1_pop_tag(&data)) { + return False; + } + + *out = data_blob_talloc(mem_ctx, data.data, data.length); + if (out->data == NULL) { + return False; + } + + return True; +} + static BOOL encode_paged_results_request(void *mem_ctx, void *in, DATA_BLOB *out) { struct ldb_paged_control *lprc = talloc_get_type(in, struct ldb_paged_control); @@ -878,6 +936,7 @@ struct control_handler ldap_known_controls[] = { { "1.2.840.113556.1.4.1504", decode_asq_control, encode_asq_control }, { "1.2.840.113556.1.4.841", decode_dirsync_request, encode_dirsync_request }, { "1.2.840.113556.1.4.528", decode_notification_request, encode_notification_request }, + { "1.2.840.113556.1.4.801", decode_sd_flags_request, encode_sd_flags_request }, { "2.16.840.1.113730.3.4.2", decode_manageDSAIT_request, encode_manageDSAIT_request }, { "2.16.840.1.113730.3.4.9", decode_vlv_request, encode_vlv_request }, { "2.16.840.1.113730.3.4.10", decode_vlv_response, encode_vlv_response }, -- cgit From 817610f38540fb99595f6e3b77b9f6696f9e3b3f Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 5 Aug 2006 11:18:14 +0000 Subject: r17419: add client support for the LDAP_SERVER_SEARCH_OPTIONS support. with this you can limit a search to a specific partitions or a search over all partitions without getting referrals. (Witch is the default behavior on the Global Catalog Port) metze (This used to be commit 4ccd0f8171f3748ee6efe1abd3f894d2cdf46bf4) --- source4/libcli/ldap/ldap_controls.c | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'source4/libcli/ldap/ldap_controls.c') diff --git a/source4/libcli/ldap/ldap_controls.c b/source4/libcli/ldap/ldap_controls.c index 445b5f8086..4c5d214a8f 100644 --- a/source4/libcli/ldap/ldap_controls.c +++ b/source4/libcli/ldap/ldap_controls.c @@ -213,6 +213,37 @@ static BOOL decode_sd_flags_request(void *mem_ctx, DATA_BLOB in, void **out) return True; } +static BOOL decode_search_options_request(void *mem_ctx, DATA_BLOB in, void **out) +{ + struct asn1_data data; + struct ldb_search_options_control *lsoc; + + if (!asn1_load(&data, in)) { + return False; + } + + lsoc = talloc(mem_ctx, struct ldb_search_options_control); + if (!lsoc) { + return False; + } + + if (!asn1_start_tag(&data, ASN1_SEQUENCE(0))) { + return False; + } + + if (!asn1_read_Integer(&data, &(lsoc->search_options))) { + return False; + } + + if (!asn1_end_tag(&data)) { + return False; + } + + *out = lsoc; + + return True; +} + static BOOL decode_paged_results_request(void *mem_ctx, DATA_BLOB in, void **out) { DATA_BLOB cookie; @@ -689,6 +720,33 @@ static BOOL encode_sd_flags_request(void *mem_ctx, void *in, DATA_BLOB *out) return True; } +static BOOL encode_search_options_request(void *mem_ctx, void *in, DATA_BLOB *out) +{ + struct ldb_search_options_control *lsoc = talloc_get_type(in, struct ldb_search_options_control); + struct asn1_data data; + + ZERO_STRUCT(data); + + if (!asn1_push_tag(&data, ASN1_SEQUENCE(0))) { + return False; + } + + if (!asn1_write_Integer(&data, lsoc->search_options)) { + return False; + } + + if (!asn1_pop_tag(&data)) { + return False; + } + + *out = data_blob_talloc(mem_ctx, data.data, data.length); + if (out->data == NULL) { + return False; + } + + return True; +} + static BOOL encode_paged_results_request(void *mem_ctx, void *in, DATA_BLOB *out) { struct ldb_paged_control *lprc = talloc_get_type(in, struct ldb_paged_control); @@ -937,6 +995,7 @@ struct control_handler ldap_known_controls[] = { { "1.2.840.113556.1.4.841", decode_dirsync_request, encode_dirsync_request }, { "1.2.840.113556.1.4.528", decode_notification_request, encode_notification_request }, { "1.2.840.113556.1.4.801", decode_sd_flags_request, encode_sd_flags_request }, + { "1.2.840.113556.1.4.1340", decode_search_options_request, encode_search_options_request }, { "2.16.840.1.113730.3.4.2", decode_manageDSAIT_request, encode_manageDSAIT_request }, { "2.16.840.1.113730.3.4.9", decode_vlv_request, encode_vlv_request }, { "2.16.840.1.113730.3.4.10", decode_vlv_response, encode_vlv_response }, -- cgit From 8ac0237eba1831c8ba6d01c2b9d8402636a21bb2 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 5 Aug 2006 11:38:50 +0000 Subject: r17420: add client support for the LDAP_SERVER_DOMAIN_SCOPE control metze (This used to be commit 84e74a759cfa49ebc8b4ba1b8e729d6d920fc55a) --- source4/libcli/ldap/ldap_controls.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'source4/libcli/ldap/ldap_controls.c') diff --git a/source4/libcli/ldap/ldap_controls.c b/source4/libcli/ldap/ldap_controls.c index 4c5d214a8f..395c4eb836 100644 --- a/source4/libcli/ldap/ldap_controls.c +++ b/source4/libcli/ldap/ldap_controls.c @@ -401,6 +401,15 @@ static BOOL decode_asq_control(void *mem_ctx, DATA_BLOB in, void **out) return True; } +static BOOL decode_domain_scope_request(void *mem_ctx, DATA_BLOB in, void **out) +{ + if (in.length != 0) { + return False; + } + + return True; +} + static BOOL decode_notification_request(void *mem_ctx, DATA_BLOB in, void **out) { if (in.length != 0) { @@ -850,6 +859,16 @@ static BOOL encode_dirsync_request(void *mem_ctx, void *in, DATA_BLOB *out) return True; } +static BOOL encode_domain_scope_request(void *mem_ctx, void *in, DATA_BLOB *out) +{ + if (in) { + return False; + } + + *out = data_blob(NULL, 0); + return True; +} + static BOOL encode_notification_request(void *mem_ctx, void *in, DATA_BLOB *out) { if (in) { @@ -995,6 +1014,7 @@ struct control_handler ldap_known_controls[] = { { "1.2.840.113556.1.4.841", decode_dirsync_request, encode_dirsync_request }, { "1.2.840.113556.1.4.528", decode_notification_request, encode_notification_request }, { "1.2.840.113556.1.4.801", decode_sd_flags_request, encode_sd_flags_request }, + { "1.2.840.113556.1.4.1339", decode_domain_scope_request, encode_domain_scope_request }, { "1.2.840.113556.1.4.1340", decode_search_options_request, encode_search_options_request }, { "2.16.840.1.113730.3.4.2", decode_manageDSAIT_request, encode_manageDSAIT_request }, { "2.16.840.1.113730.3.4.9", decode_vlv_request, encode_vlv_request }, -- cgit From 12050962f6dd37819e58e1e0b572c159f0406f7a Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 5 Aug 2006 19:35:00 +0000 Subject: r17429: implement the LDAP_SERVER_SHOW_DELETED control in the client metze (This used to be commit 40dc7c1787c16bfc15ac87fee81d2d2d1f3d2fde) --- source4/libcli/ldap/ldap_controls.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'source4/libcli/ldap/ldap_controls.c') diff --git a/source4/libcli/ldap/ldap_controls.c b/source4/libcli/ldap/ldap_controls.c index 395c4eb836..75af597c33 100644 --- a/source4/libcli/ldap/ldap_controls.c +++ b/source4/libcli/ldap/ldap_controls.c @@ -419,6 +419,15 @@ static BOOL decode_notification_request(void *mem_ctx, DATA_BLOB in, void **out) return True; } +static BOOL decode_show_deleted_request(void *mem_ctx, DATA_BLOB in, void **out) +{ + if (in.length != 0) { + return False; + } + + return True; +} + static BOOL decode_manageDSAIT_request(void *mem_ctx, DATA_BLOB in, void **out) { if (in.length != 0) { @@ -879,6 +888,16 @@ static BOOL encode_notification_request(void *mem_ctx, void *in, DATA_BLOB *out) return True; } +static BOOL encode_show_deleted_request(void *mem_ctx, void *in, DATA_BLOB *out) +{ + if (in) { + return False; + } + + *out = data_blob(NULL, 0); + return True; +} + static BOOL encode_manageDSAIT_request(void *mem_ctx, void *in, DATA_BLOB *out) { if (in) { @@ -1013,6 +1032,7 @@ struct control_handler ldap_known_controls[] = { { "1.2.840.113556.1.4.1504", decode_asq_control, encode_asq_control }, { "1.2.840.113556.1.4.841", decode_dirsync_request, encode_dirsync_request }, { "1.2.840.113556.1.4.528", decode_notification_request, encode_notification_request }, + { "1.2.840.113556.1.4.417", decode_show_deleted_request, encode_show_deleted_request }, { "1.2.840.113556.1.4.801", decode_sd_flags_request, encode_sd_flags_request }, { "1.2.840.113556.1.4.1339", decode_domain_scope_request, encode_domain_scope_request }, { "1.2.840.113556.1.4.1340", decode_search_options_request, encode_search_options_request }, -- cgit From 3a083f8f53b998b6aabf69e845fd0fbdf86b6499 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 5 Aug 2006 19:50:58 +0000 Subject: r17430: implement the LDAP_SERVER_PERMISSIVE_MODIFY control in the client metze (This used to be commit 96259f0f24b114e505241c9d2deb702a8b40f1b6) --- source4/libcli/ldap/ldap_controls.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'source4/libcli/ldap/ldap_controls.c') diff --git a/source4/libcli/ldap/ldap_controls.c b/source4/libcli/ldap/ldap_controls.c index 75af597c33..5cd0451136 100644 --- a/source4/libcli/ldap/ldap_controls.c +++ b/source4/libcli/ldap/ldap_controls.c @@ -428,6 +428,15 @@ static BOOL decode_show_deleted_request(void *mem_ctx, DATA_BLOB in, void **out) return True; } +static BOOL decode_permissive_modify_request(void *mem_ctx, DATA_BLOB in, void **out) +{ + if (in.length != 0) { + return False; + } + + return True; +} + static BOOL decode_manageDSAIT_request(void *mem_ctx, DATA_BLOB in, void **out) { if (in.length != 0) { @@ -898,6 +907,16 @@ static BOOL encode_show_deleted_request(void *mem_ctx, void *in, DATA_BLOB *out) return True; } +static BOOL encode_permissive_modify_request(void *mem_ctx, void *in, DATA_BLOB *out) +{ + if (in) { + return False; + } + + *out = data_blob(NULL, 0); + return True; +} + static BOOL encode_manageDSAIT_request(void *mem_ctx, void *in, DATA_BLOB *out) { if (in) { @@ -1033,6 +1052,7 @@ struct control_handler ldap_known_controls[] = { { "1.2.840.113556.1.4.841", decode_dirsync_request, encode_dirsync_request }, { "1.2.840.113556.1.4.528", decode_notification_request, encode_notification_request }, { "1.2.840.113556.1.4.417", decode_show_deleted_request, encode_show_deleted_request }, + { "1.2.840.113556.1.4.1413", decode_permissive_modify_request, encode_permissive_modify_request }, { "1.2.840.113556.1.4.801", decode_sd_flags_request, encode_sd_flags_request }, { "1.2.840.113556.1.4.1339", decode_domain_scope_request, encode_domain_scope_request }, { "1.2.840.113556.1.4.1340", decode_search_options_request, encode_search_options_request }, -- cgit From 9b03286b32a916dbef59f1459eefa01f0ebfeed3 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 13 Mar 2007 00:59:06 +0000 Subject: r21806: I've been working over the last week to fix up the LDAP backend for Samba4. This only broke on global catalog queries, which turned out to be due to changes in the partitions module that metze needed for his DRSUAPI work. I've reworked partitions.c to always include the 'problematic' control, and therefore demonstrated that this is the issue. This ensures consistency, and should help with finding issues like this in future. As this control (DSDB_CONTROL_CURRENT_PARTITION_OID) is not intended to be linearised, I've added logic to allow it to be skipped when creating network packets. I've likewise make our LDAP server skip unknown controls, when marked 'not critical' on it's input, rather than just dropping the entire request. I need some help to generate a correct error packet when it is marked critical. Further work could perhaps be to have the ldap_encode routine return a textual description of what failed to encode, as that would have saved me a lot of time... Andrew Bartlett (This used to be commit eef710668f91d1bbaa2d834d9e653e11c8aac817) --- source4/libcli/ldap/ldap_controls.c | 71 +++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 27 deletions(-) (limited to 'source4/libcli/ldap/ldap_controls.c') diff --git a/source4/libcli/ldap/ldap_controls.c b/source4/libcli/ldap/ldap_controls.c index 5cd0451136..bbb0cb1aa5 100644 --- a/source4/libcli/ldap/ldap_controls.c +++ b/source4/libcli/ldap/ldap_controls.c @@ -1059,14 +1059,35 @@ struct control_handler ldap_known_controls[] = { { "2.16.840.1.113730.3.4.2", decode_manageDSAIT_request, encode_manageDSAIT_request }, { "2.16.840.1.113730.3.4.9", decode_vlv_request, encode_vlv_request }, { "2.16.840.1.113730.3.4.10", decode_vlv_response, encode_vlv_response }, +/* DSDB_CONTROL_CURRENT_PARTITION_OID is internal only, and has no network representation */ + { "1.3.6.1.4.1.7165.4.3.2", NULL, NULL }, +/* DSDB_EXTENDED_REPLICATED_OBJECTS_OID is internal only, and has no network representation */ + { "1.3.6.1.4.1.7165.4.4.1", NULL, NULL }, { NULL, NULL, NULL } }; -BOOL ldap_decode_control(void *mem_ctx, struct asn1_data *data, struct ldb_control *ctrl) +BOOL ldap_decode_control_value(void *mem_ctx, DATA_BLOB value, struct ldb_control *ctrl) { int i; + + for (i = 0; ldap_known_controls[i].oid != NULL; i++) { + if (strcmp(ldap_known_controls[i].oid, ctrl->oid) == 0) { + if (!ldap_known_controls[i].decode || !ldap_known_controls[i].decode(mem_ctx, value, &ctrl->data)) { + return False; + } + break; + } + } + if (ldap_known_controls[i].oid == NULL) { + return False; + } + + return True; +} + +BOOL ldap_decode_control_wrapper(void *mem_ctx, struct asn1_data *data, struct ldb_control *ctrl, DATA_BLOB *value) +{ DATA_BLOB oid; - DATA_BLOB value; if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) { return False; @@ -1096,19 +1117,7 @@ BOOL ldap_decode_control(void *mem_ctx, struct asn1_data *data, struct ldb_contr goto end_tag; } - if (!asn1_read_OctetString(data, &value)) { - return False; - } - - for (i = 0; ldap_known_controls[i].oid != NULL; i++) { - if (strcmp(ldap_known_controls[i].oid, ctrl->oid) == 0) { - if (!ldap_known_controls[i].decode(mem_ctx, value, &ctrl->data)) { - return False; - } - break; - } - } - if (ldap_known_controls[i].oid == NULL) { + if (!asn1_read_OctetString(data, value)) { return False; } @@ -1125,6 +1134,26 @@ BOOL ldap_encode_control(void *mem_ctx, struct asn1_data *data, struct ldb_contr DATA_BLOB value; int i; + for (i = 0; ldap_known_controls[i].oid != NULL; i++) { + if (strcmp(ldap_known_controls[i].oid, ctrl->oid) == 0) { + if (!ldap_known_controls[i].encode) { + if (ctrl->critical) { + return False; + } else { + /* not encoding this control */ + return True; + } + } + if (!ldap_known_controls[i].encode(mem_ctx, ctrl->data, &value)) { + return False; + } + break; + } + } + if (ldap_known_controls[i].oid == NULL) { + return False; + } + if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { return False; } @@ -1143,18 +1172,6 @@ BOOL ldap_encode_control(void *mem_ctx, struct asn1_data *data, struct ldb_contr goto pop_tag; } - for (i = 0; ldap_known_controls[i].oid != NULL; i++) { - if (strcmp(ldap_known_controls[i].oid, ctrl->oid) == 0) { - if (!ldap_known_controls[i].encode(mem_ctx, ctrl->data, &value)) { - return False; - } - break; - } - } - if (ldap_known_controls[i].oid == NULL) { - return False; - } - if (!asn1_write_OctetString(data, value.data, value.length)) { return False; } -- cgit From 7bb939b1cb2b39a8271cf16d9f5fce5312a9af10 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 21 May 2007 06:12:06 +0000 Subject: r23030: finally fixed up our asn1 code to use better memory allocation. This should allow us to fix some long standing memory leaks. (This used to be commit 3db49c2ec9968221c1361785b94061046ecd159d) --- source4/libcli/ldap/ldap_controls.c | 344 +++++++++++++++++------------------- 1 file changed, 167 insertions(+), 177 deletions(-) (limited to 'source4/libcli/ldap/ldap_controls.c') diff --git a/source4/libcli/ldap/ldap_controls.c b/source4/libcli/ldap/ldap_controls.c index bbb0cb1aa5..180e6eeb62 100644 --- a/source4/libcli/ldap/ldap_controls.c +++ b/source4/libcli/ldap/ldap_controls.c @@ -34,10 +34,10 @@ struct control_handler { static BOOL decode_server_sort_response(void *mem_ctx, DATA_BLOB in, void **out) { DATA_BLOB attr; - struct asn1_data data; + struct asn1_data *data = asn1_init(mem_ctx); struct ldb_sort_resp_control *lsrc; - if (!asn1_load(&data, in)) { + if (!asn1_load(data, in)) { return False; } @@ -46,17 +46,17 @@ static BOOL decode_server_sort_response(void *mem_ctx, DATA_BLOB in, void **out) return False; } - if (!asn1_start_tag(&data, ASN1_SEQUENCE(0))) { + if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) { return False; } - if (!asn1_read_enumerated(&data, &(lsrc->result))) { + if (!asn1_read_enumerated(data, &(lsrc->result))) { return False; } lsrc->attr_desc = NULL; - if (asn1_peek_tag(&data, ASN1_OCTET_STRING)) { - if (!asn1_read_OctetString(&data, &attr)) { + if (asn1_peek_tag(data, ASN1_OCTET_STRING)) { + if (!asn1_read_OctetString(data, mem_ctx, &attr)) { return False; } lsrc->attr_desc = talloc_strndup(lsrc, (const char *)attr.data, attr.length); @@ -65,7 +65,7 @@ static BOOL decode_server_sort_response(void *mem_ctx, DATA_BLOB in, void **out) } } - if (!asn1_end_tag(&data)) { + if (!asn1_end_tag(data)) { return False; } @@ -78,21 +78,21 @@ static BOOL decode_server_sort_request(void *mem_ctx, DATA_BLOB in, void **out) { DATA_BLOB attr; DATA_BLOB rule; - struct asn1_data data; + struct asn1_data *data = asn1_init(mem_ctx); struct ldb_server_sort_control **lssc; int num; - if (!asn1_load(&data, in)) { + if (!asn1_load(data, in)) { return False; } - if (!asn1_start_tag(&data, ASN1_SEQUENCE(0))) { + if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) { return False; } lssc = NULL; - for (num = 0; asn1_peek_tag(&data, ASN1_SEQUENCE(0)); num++) { + for (num = 0; asn1_peek_tag(data, ASN1_SEQUENCE(0)); num++) { lssc = talloc_realloc(mem_ctx, lssc, struct ldb_server_sort_control *, num + 2); if (!lssc) { return False; @@ -102,11 +102,11 @@ static BOOL decode_server_sort_request(void *mem_ctx, DATA_BLOB in, void **out) return False; } - if (!asn1_start_tag(&data, ASN1_SEQUENCE(0))) { + if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) { return False; } - if (!asn1_read_OctetString(&data, &attr)) { + if (!asn1_read_OctetString(data, mem_ctx, &attr)) { return False; } @@ -115,8 +115,8 @@ static BOOL decode_server_sort_request(void *mem_ctx, DATA_BLOB in, void **out) return False; } - if (asn1_peek_tag(&data, ASN1_OCTET_STRING)) { - if (!asn1_read_OctetString(&data, &rule)) { + if (asn1_peek_tag(data, ASN1_OCTET_STRING)) { + if (!asn1_read_OctetString(data, mem_ctx, &rule)) { return False; } lssc[num]->orderingRule = talloc_strndup(lssc[num], (const char *)rule.data, rule.length); @@ -125,15 +125,15 @@ static BOOL decode_server_sort_request(void *mem_ctx, DATA_BLOB in, void **out) } } - if (asn1_peek_tag(&data, ASN1_BOOLEAN)) { + if (asn1_peek_tag(data, ASN1_BOOLEAN)) { BOOL reverse; - if (!asn1_read_BOOLEAN(&data, &reverse)) { + if (!asn1_read_BOOLEAN(data, &reverse)) { return False; } lssc[num]->reverse = reverse; } - if (!asn1_end_tag(&data)) { + if (!asn1_end_tag(data)) { return False; } } @@ -142,7 +142,7 @@ static BOOL decode_server_sort_request(void *mem_ctx, DATA_BLOB in, void **out) lssc[num] = NULL; } - if (!asn1_end_tag(&data)) { + if (!asn1_end_tag(data)) { return False; } @@ -153,10 +153,10 @@ static BOOL decode_server_sort_request(void *mem_ctx, DATA_BLOB in, void **out) static BOOL decode_extended_dn_request(void *mem_ctx, DATA_BLOB in, void **out) { - struct asn1_data data; + struct asn1_data *data = asn1_init(mem_ctx); struct ldb_extended_dn_control *ledc; - if (!asn1_load(&data, in)) { + if (!asn1_load(data, in)) { return False; } @@ -165,15 +165,15 @@ static BOOL decode_extended_dn_request(void *mem_ctx, DATA_BLOB in, void **out) return False; } - if (!asn1_start_tag(&data, ASN1_SEQUENCE(0))) { + if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) { return False; } - if (!asn1_read_Integer(&data, &(ledc->type))) { + if (!asn1_read_Integer(data, &(ledc->type))) { return False; } - if (!asn1_end_tag(&data)) { + if (!asn1_end_tag(data)) { return False; } @@ -184,10 +184,10 @@ static BOOL decode_extended_dn_request(void *mem_ctx, DATA_BLOB in, void **out) static BOOL decode_sd_flags_request(void *mem_ctx, DATA_BLOB in, void **out) { - struct asn1_data data; + struct asn1_data *data = asn1_init(mem_ctx); struct ldb_sd_flags_control *lsdfc; - if (!asn1_load(&data, in)) { + if (!asn1_load(data, in)) { return False; } @@ -196,15 +196,15 @@ static BOOL decode_sd_flags_request(void *mem_ctx, DATA_BLOB in, void **out) return False; } - if (!asn1_start_tag(&data, ASN1_SEQUENCE(0))) { + if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) { return False; } - if (!asn1_read_Integer(&data, &(lsdfc->secinfo_flags))) { + if (!asn1_read_Integer(data, &(lsdfc->secinfo_flags))) { return False; } - if (!asn1_end_tag(&data)) { + if (!asn1_end_tag(data)) { return False; } @@ -215,10 +215,10 @@ static BOOL decode_sd_flags_request(void *mem_ctx, DATA_BLOB in, void **out) static BOOL decode_search_options_request(void *mem_ctx, DATA_BLOB in, void **out) { - struct asn1_data data; + struct asn1_data *data = asn1_init(mem_ctx); struct ldb_search_options_control *lsoc; - if (!asn1_load(&data, in)) { + if (!asn1_load(data, in)) { return False; } @@ -227,15 +227,15 @@ static BOOL decode_search_options_request(void *mem_ctx, DATA_BLOB in, void **ou return False; } - if (!asn1_start_tag(&data, ASN1_SEQUENCE(0))) { + if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) { return False; } - if (!asn1_read_Integer(&data, &(lsoc->search_options))) { + if (!asn1_read_Integer(data, &(lsoc->search_options))) { return False; } - if (!asn1_end_tag(&data)) { + if (!asn1_end_tag(data)) { return False; } @@ -247,10 +247,10 @@ static BOOL decode_search_options_request(void *mem_ctx, DATA_BLOB in, void **ou static BOOL decode_paged_results_request(void *mem_ctx, DATA_BLOB in, void **out) { DATA_BLOB cookie; - struct asn1_data data; + struct asn1_data *data = asn1_init(mem_ctx); struct ldb_paged_control *lprc; - if (!asn1_load(&data, in)) { + if (!asn1_load(data, in)) { return False; } @@ -259,15 +259,15 @@ static BOOL decode_paged_results_request(void *mem_ctx, DATA_BLOB in, void **out return False; } - if (!asn1_start_tag(&data, ASN1_SEQUENCE(0))) { + if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) { return False; } - if (!asn1_read_Integer(&data, &(lprc->size))) { + if (!asn1_read_Integer(data, &(lprc->size))) { return False; } - if (!asn1_read_OctetString(&data, &cookie)) { + if (!asn1_read_OctetString(data, mem_ctx, &cookie)) { return False; } lprc->cookie_len = cookie.length; @@ -281,7 +281,7 @@ static BOOL decode_paged_results_request(void *mem_ctx, DATA_BLOB in, void **out lprc->cookie = NULL; } - if (!asn1_end_tag(&data)) { + if (!asn1_end_tag(data)) { return False; } @@ -293,10 +293,10 @@ static BOOL decode_paged_results_request(void *mem_ctx, DATA_BLOB in, void **out static BOOL decode_dirsync_request(void *mem_ctx, DATA_BLOB in, void **out) { DATA_BLOB cookie; - struct asn1_data data; + struct asn1_data *data = asn1_init(mem_ctx); struct ldb_dirsync_control *ldc; - if (!asn1_load(&data, in)) { + if (!asn1_load(data, in)) { return False; } @@ -305,19 +305,19 @@ static BOOL decode_dirsync_request(void *mem_ctx, DATA_BLOB in, void **out) return False; } - if (!asn1_start_tag(&data, ASN1_SEQUENCE(0))) { + if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) { return False; } - if (!asn1_read_Integer(&data, &(ldc->flags))) { + if (!asn1_read_Integer(data, &(ldc->flags))) { return False; } - if (!asn1_read_Integer(&data, &(ldc->max_attributes))) { + if (!asn1_read_Integer(data, &(ldc->max_attributes))) { return False; } - if (!asn1_read_OctetString(&data, &cookie)) { + if (!asn1_read_OctetString(data, mem_ctx, &cookie)) { return False; } ldc->cookie_len = cookie.length; @@ -331,7 +331,7 @@ static BOOL decode_dirsync_request(void *mem_ctx, DATA_BLOB in, void **out) ldc->cookie = NULL; } - if (!asn1_end_tag(&data)) { + if (!asn1_end_tag(data)) { return False; } @@ -346,10 +346,10 @@ static BOOL decode_dirsync_request(void *mem_ctx, DATA_BLOB in, void **out) static BOOL decode_asq_control(void *mem_ctx, DATA_BLOB in, void **out) { DATA_BLOB source_attribute; - struct asn1_data data; + struct asn1_data *data = asn1_init(mem_ctx); struct ldb_asq_control *lac; - if (!asn1_load(&data, in)) { + if (!asn1_load(data, in)) { return False; } @@ -358,13 +358,13 @@ static BOOL decode_asq_control(void *mem_ctx, DATA_BLOB in, void **out) return False; } - if (!asn1_start_tag(&data, ASN1_SEQUENCE(0))) { + if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) { return False; } - if (asn1_peek_tag(&data, ASN1_OCTET_STRING)) { + if (asn1_peek_tag(data, ASN1_OCTET_STRING)) { - if (!asn1_read_OctetString(&data, &source_attribute)) { + if (!asn1_read_OctetString(data, mem_ctx, &source_attribute)) { return False; } lac->src_attr_len = source_attribute.length; @@ -380,9 +380,9 @@ static BOOL decode_asq_control(void *mem_ctx, DATA_BLOB in, void **out) lac->request = 1; - } else if (asn1_peek_tag(&data, ASN1_ENUMERATED)) { + } else if (asn1_peek_tag(data, ASN1_ENUMERATED)) { - if (!asn1_read_enumerated(&data, &(lac->result))) { + if (!asn1_read_enumerated(data, &(lac->result))) { return False; } @@ -392,7 +392,7 @@ static BOOL decode_asq_control(void *mem_ctx, DATA_BLOB in, void **out) return False; } - if (!asn1_end_tag(&data)) { + if (!asn1_end_tag(data)) { return False; } @@ -449,10 +449,10 @@ static BOOL decode_manageDSAIT_request(void *mem_ctx, DATA_BLOB in, void **out) static BOOL decode_vlv_request(void *mem_ctx, DATA_BLOB in, void **out) { DATA_BLOB assertion_value, context_id; - struct asn1_data data; + struct asn1_data *data = asn1_init(mem_ctx); struct ldb_vlv_req_control *lvrc; - if (!asn1_load(&data, in)) { + if (!asn1_load(data, in)) { return False; } @@ -461,43 +461,43 @@ static BOOL decode_vlv_request(void *mem_ctx, DATA_BLOB in, void **out) return False; } - if (!asn1_start_tag(&data, ASN1_SEQUENCE(0))) { + if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) { return False; } - if (!asn1_read_Integer(&data, &(lvrc->beforeCount))) { + if (!asn1_read_Integer(data, &(lvrc->beforeCount))) { return False; } - if (!asn1_read_Integer(&data, &(lvrc->afterCount))) { + if (!asn1_read_Integer(data, &(lvrc->afterCount))) { return False; } - if (asn1_peek_tag(&data, ASN1_CONTEXT(0))) { + if (asn1_peek_tag(data, ASN1_CONTEXT(0))) { lvrc->type = 0; - if (!asn1_start_tag(&data, ASN1_CONTEXT(0))) { + if (!asn1_start_tag(data, ASN1_CONTEXT(0))) { return False; } - if (!asn1_start_tag(&data, ASN1_SEQUENCE(0))) { + if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) { return False; } - if (!asn1_read_Integer(&data, &(lvrc->match.byOffset.offset))) { + if (!asn1_read_Integer(data, &(lvrc->match.byOffset.offset))) { return False; } - if (!asn1_read_Integer(&data, &(lvrc->match.byOffset.contentCount))) { + if (!asn1_read_Integer(data, &(lvrc->match.byOffset.contentCount))) { return False; } - if (!asn1_end_tag(&data)) { /*SEQUENCE*/ + if (!asn1_end_tag(data)) { /*SEQUENCE*/ return False; } - if (!asn1_end_tag(&data)) { /*CONTEXT*/ + if (!asn1_end_tag(data)) { /*CONTEXT*/ return False; } @@ -505,11 +505,11 @@ static BOOL decode_vlv_request(void *mem_ctx, DATA_BLOB in, void **out) lvrc->type = 1; - if (!asn1_start_tag(&data, ASN1_CONTEXT(1))) { + if (!asn1_start_tag(data, ASN1_CONTEXT(1))) { return False; } - if (!asn1_read_OctetString(&data, &assertion_value)) { + if (!asn1_read_OctetString(data, mem_ctx, &assertion_value)) { return False; } lvrc->match.gtOrEq.value_len = assertion_value.length; @@ -523,13 +523,13 @@ static BOOL decode_vlv_request(void *mem_ctx, DATA_BLOB in, void **out) lvrc->match.gtOrEq.value = NULL; } - if (!asn1_end_tag(&data)) { /*CONTEXT*/ + if (!asn1_end_tag(data)) { /*CONTEXT*/ return False; } } - if (asn1_peek_tag(&data, ASN1_OCTET_STRING)) { - if (!asn1_read_OctetString(&data, &context_id)) { + if (asn1_peek_tag(data, ASN1_OCTET_STRING)) { + if (!asn1_read_OctetString(data, mem_ctx, &context_id)) { return False; } lvrc->ctxid_len = context_id.length; @@ -547,7 +547,7 @@ static BOOL decode_vlv_request(void *mem_ctx, DATA_BLOB in, void **out) lvrc->ctxid_len = 0; } - if (!asn1_end_tag(&data)) { + if (!asn1_end_tag(data)) { return False; } @@ -559,10 +559,10 @@ static BOOL decode_vlv_request(void *mem_ctx, DATA_BLOB in, void **out) static BOOL decode_vlv_response(void *mem_ctx, DATA_BLOB in, void **out) { DATA_BLOB context_id; - struct asn1_data data; + struct asn1_data *data = asn1_init(mem_ctx); struct ldb_vlv_resp_control *lvrc; - if (!asn1_load(&data, in)) { + if (!asn1_load(data, in)) { return False; } @@ -571,24 +571,24 @@ static BOOL decode_vlv_response(void *mem_ctx, DATA_BLOB in, void **out) return False; } - if (!asn1_start_tag(&data, ASN1_SEQUENCE(0))) { + if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) { return False; } - if (!asn1_read_Integer(&data, &(lvrc->targetPosition))) { + if (!asn1_read_Integer(data, &(lvrc->targetPosition))) { return False; } - if (!asn1_read_Integer(&data, &(lvrc->contentCount))) { + if (!asn1_read_Integer(data, &(lvrc->contentCount))) { return False; } - if (!asn1_read_enumerated(&data, &(lvrc->vlv_result))) { + if (!asn1_read_enumerated(data, &(lvrc->vlv_result))) { return False; } - if (asn1_peek_tag(&data, ASN1_OCTET_STRING)) { - if (!asn1_read_OctetString(&data, &context_id)) { + if (asn1_peek_tag(data, ASN1_OCTET_STRING)) { + if (!asn1_read_OctetString(data, mem_ctx, &context_id)) { return False; } lvrc->contextId = talloc_strndup(lvrc, (const char *)context_id.data, context_id.length); @@ -601,7 +601,7 @@ static BOOL decode_vlv_response(void *mem_ctx, DATA_BLOB in, void **out) lvrc->ctxid_len = 0; } - if (!asn1_end_tag(&data)) { + if (!asn1_end_tag(data)) { return False; } @@ -613,32 +613,31 @@ static BOOL decode_vlv_response(void *mem_ctx, DATA_BLOB in, void **out) static BOOL encode_server_sort_response(void *mem_ctx, void *in, DATA_BLOB *out) { struct ldb_sort_resp_control *lsrc = talloc_get_type(in, struct ldb_sort_resp_control); - struct asn1_data data; - - ZERO_STRUCT(data); + struct asn1_data *data = asn1_init(mem_ctx); - if (!asn1_push_tag(&data, ASN1_SEQUENCE(0))) { + if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { return False; } - if (!asn1_write_enumerated(&data, lsrc->result)) { + if (!asn1_write_enumerated(data, lsrc->result)) { return False; } if (lsrc->attr_desc) { - if (!asn1_write_OctetString(&data, lsrc->attr_desc, strlen(lsrc->attr_desc))) { + if (!asn1_write_OctetString(data, lsrc->attr_desc, strlen(lsrc->attr_desc))) { return False; } } - if (!asn1_pop_tag(&data)) { + if (!asn1_pop_tag(data)) { return False; } - *out = data_blob_talloc(mem_ctx, data.data, data.length); + *out = data_blob_talloc(mem_ctx, data->data, data->length); if (out->data == NULL) { return False; } + talloc_free(data); return True; } @@ -646,49 +645,48 @@ static BOOL encode_server_sort_response(void *mem_ctx, void *in, DATA_BLOB *out) static BOOL encode_server_sort_request(void *mem_ctx, void *in, DATA_BLOB *out) { struct ldb_server_sort_control **lssc = talloc_get_type(in, struct ldb_server_sort_control *); - struct asn1_data data; + struct asn1_data *data = asn1_init(mem_ctx); int num; - ZERO_STRUCT(data); - - if (!asn1_push_tag(&data, ASN1_SEQUENCE(0))) { + if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { return False; } for (num = 0; lssc[num]; num++) { - if (!asn1_push_tag(&data, ASN1_SEQUENCE(0))) { + if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { return False; } - if (!asn1_write_OctetString(&data, lssc[num]->attributeName, strlen(lssc[num]->attributeName))) { + if (!asn1_write_OctetString(data, lssc[num]->attributeName, strlen(lssc[num]->attributeName))) { return False; } if (lssc[num]->orderingRule) { - if (!asn1_write_OctetString(&data, lssc[num]->orderingRule, strlen(lssc[num]->orderingRule))) { + if (!asn1_write_OctetString(data, lssc[num]->orderingRule, strlen(lssc[num]->orderingRule))) { return False; } } if (lssc[num]->reverse) { - if (!asn1_write_BOOLEAN(&data, lssc[num]->reverse)) { + if (!asn1_write_BOOLEAN(data, lssc[num]->reverse)) { return False; } } - if (!asn1_pop_tag(&data)) { + if (!asn1_pop_tag(data)) { return False; } } - if (!asn1_pop_tag(&data)) { + if (!asn1_pop_tag(data)) { return False; } - *out = data_blob_talloc(mem_ctx, data.data, data.length); + *out = data_blob_talloc(mem_ctx, data->data, data->length); if (out->data == NULL) { return False; } + talloc_free(data); return True; } @@ -696,26 +694,25 @@ static BOOL encode_server_sort_request(void *mem_ctx, void *in, DATA_BLOB *out) static BOOL encode_extended_dn_request(void *mem_ctx, void *in, DATA_BLOB *out) { struct ldb_extended_dn_control *ledc = talloc_get_type(in, struct ldb_extended_dn_control); - struct asn1_data data; - - ZERO_STRUCT(data); + struct asn1_data *data = asn1_init(mem_ctx); - if (!asn1_push_tag(&data, ASN1_SEQUENCE(0))) { + if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { return False; } - if (!asn1_write_Integer(&data, ledc->type)) { + if (!asn1_write_Integer(data, ledc->type)) { return False; } - if (!asn1_pop_tag(&data)) { + if (!asn1_pop_tag(data)) { return False; } - *out = data_blob_talloc(mem_ctx, data.data, data.length); + *out = data_blob_talloc(mem_ctx, data->data, data->length); if (out->data == NULL) { return False; } + talloc_free(data); return True; } @@ -723,26 +720,25 @@ static BOOL encode_extended_dn_request(void *mem_ctx, void *in, DATA_BLOB *out) static BOOL encode_sd_flags_request(void *mem_ctx, void *in, DATA_BLOB *out) { struct ldb_sd_flags_control *lsdfc = talloc_get_type(in, struct ldb_sd_flags_control); - struct asn1_data data; + struct asn1_data *data = asn1_init(mem_ctx); - ZERO_STRUCT(data); - - if (!asn1_push_tag(&data, ASN1_SEQUENCE(0))) { + if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { return False; } - if (!asn1_write_Integer(&data, lsdfc->secinfo_flags)) { + if (!asn1_write_Integer(data, lsdfc->secinfo_flags)) { return False; } - if (!asn1_pop_tag(&data)) { + if (!asn1_pop_tag(data)) { return False; } - *out = data_blob_talloc(mem_ctx, data.data, data.length); + *out = data_blob_talloc(mem_ctx, data->data, data->length); if (out->data == NULL) { return False; } + talloc_free(data); return True; } @@ -750,26 +746,25 @@ static BOOL encode_sd_flags_request(void *mem_ctx, void *in, DATA_BLOB *out) static BOOL encode_search_options_request(void *mem_ctx, void *in, DATA_BLOB *out) { struct ldb_search_options_control *lsoc = talloc_get_type(in, struct ldb_search_options_control); - struct asn1_data data; + struct asn1_data *data = asn1_init(mem_ctx); - ZERO_STRUCT(data); - - if (!asn1_push_tag(&data, ASN1_SEQUENCE(0))) { + if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { return False; } - if (!asn1_write_Integer(&data, lsoc->search_options)) { + if (!asn1_write_Integer(data, lsoc->search_options)) { return False; } - if (!asn1_pop_tag(&data)) { + if (!asn1_pop_tag(data)) { return False; } - *out = data_blob_talloc(mem_ctx, data.data, data.length); + *out = data_blob_talloc(mem_ctx, data->data, data->length); if (out->data == NULL) { return False; } + talloc_free(data); return True; } @@ -777,30 +772,29 @@ static BOOL encode_search_options_request(void *mem_ctx, void *in, DATA_BLOB *ou static BOOL encode_paged_results_request(void *mem_ctx, void *in, DATA_BLOB *out) { struct ldb_paged_control *lprc = talloc_get_type(in, struct ldb_paged_control); - struct asn1_data data; + struct asn1_data *data = asn1_init(mem_ctx); - ZERO_STRUCT(data); - - if (!asn1_push_tag(&data, ASN1_SEQUENCE(0))) { + if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { return False; } - if (!asn1_write_Integer(&data, lprc->size)) { + if (!asn1_write_Integer(data, lprc->size)) { return False; } - if (!asn1_write_OctetString(&data, lprc->cookie, lprc->cookie_len)) { + if (!asn1_write_OctetString(data, lprc->cookie, lprc->cookie_len)) { return False; } - if (!asn1_pop_tag(&data)) { + if (!asn1_pop_tag(data)) { return False; } - *out = data_blob_talloc(mem_ctx, data.data, data.length); + *out = data_blob_talloc(mem_ctx, data->data, data->length); if (out->data == NULL) { return False; } + talloc_free(data); return True; } @@ -811,33 +805,32 @@ static BOOL encode_paged_results_request(void *mem_ctx, void *in, DATA_BLOB *out static BOOL encode_asq_control(void *mem_ctx, void *in, DATA_BLOB *out) { struct ldb_asq_control *lac = talloc_get_type(in, struct ldb_asq_control); - struct asn1_data data; + struct asn1_data *data = asn1_init(mem_ctx); - ZERO_STRUCT(data); - - if (!asn1_push_tag(&data, ASN1_SEQUENCE(0))) { + if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { return False; } if (lac->request) { - if (!asn1_write_OctetString(&data, lac->source_attribute, lac->src_attr_len)) { + if (!asn1_write_OctetString(data, lac->source_attribute, lac->src_attr_len)) { return False; } } else { - if (!asn1_write_enumerated(&data, lac->result)) { + if (!asn1_write_enumerated(data, lac->result)) { return False; } } - if (!asn1_pop_tag(&data)) { + if (!asn1_pop_tag(data)) { return False; } - *out = data_blob_talloc(mem_ctx, data.data, data.length); + *out = data_blob_talloc(mem_ctx, data->data, data->length); if (out->data == NULL) { return False; } + talloc_free(data); return True; } @@ -845,34 +838,33 @@ static BOOL encode_asq_control(void *mem_ctx, void *in, DATA_BLOB *out) static BOOL encode_dirsync_request(void *mem_ctx, void *in, DATA_BLOB *out) { struct ldb_dirsync_control *ldc = talloc_get_type(in, struct ldb_dirsync_control); - struct asn1_data data; + struct asn1_data *data = asn1_init(mem_ctx); - ZERO_STRUCT(data); - - if (!asn1_push_tag(&data, ASN1_SEQUENCE(0))) { + if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { return False; } - if (!asn1_write_Integer(&data, ldc->flags)) { + if (!asn1_write_Integer(data, ldc->flags)) { return False; } - if (!asn1_write_Integer(&data, ldc->max_attributes)) { + if (!asn1_write_Integer(data, ldc->max_attributes)) { return False; } - if (!asn1_write_OctetString(&data, ldc->cookie, ldc->cookie_len)) { + if (!asn1_write_OctetString(data, ldc->cookie, ldc->cookie_len)) { return False; } - if (!asn1_pop_tag(&data)) { + if (!asn1_pop_tag(data)) { return False; } - *out = data_blob_talloc(mem_ctx, data.data, data.length); + *out = data_blob_talloc(mem_ctx, data->data, data->length); if (out->data == NULL) { return False; } + talloc_free(data); return True; } @@ -930,74 +922,73 @@ static BOOL encode_manageDSAIT_request(void *mem_ctx, void *in, DATA_BLOB *out) static BOOL encode_vlv_request(void *mem_ctx, void *in, DATA_BLOB *out) { struct ldb_vlv_req_control *lvrc = talloc_get_type(in, struct ldb_vlv_req_control); - struct asn1_data data; + struct asn1_data *data = asn1_init(mem_ctx); - ZERO_STRUCT(data); - - if (!asn1_push_tag(&data, ASN1_SEQUENCE(0))) { + if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { return False; } - if (!asn1_write_Integer(&data, lvrc->beforeCount)) { + if (!asn1_write_Integer(data, lvrc->beforeCount)) { return False; } - if (!asn1_write_Integer(&data, lvrc->afterCount)) { + if (!asn1_write_Integer(data, lvrc->afterCount)) { return False; } if (lvrc->type == 0) { - if (!asn1_push_tag(&data, ASN1_CONTEXT(0))) { + if (!asn1_push_tag(data, ASN1_CONTEXT(0))) { return False; } - if (!asn1_push_tag(&data, ASN1_SEQUENCE(0))) { + if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { return False; } - if (!asn1_write_Integer(&data, lvrc->match.byOffset.offset)) { + if (!asn1_write_Integer(data, lvrc->match.byOffset.offset)) { return False; } - if (!asn1_write_Integer(&data, lvrc->match.byOffset.contentCount)) { + if (!asn1_write_Integer(data, lvrc->match.byOffset.contentCount)) { return False; } - if (!asn1_pop_tag(&data)) { /*SEQUENCE*/ + if (!asn1_pop_tag(data)) { /*SEQUENCE*/ return False; } - if (!asn1_pop_tag(&data)) { /*CONTEXT*/ + if (!asn1_pop_tag(data)) { /*CONTEXT*/ return False; } } else { - if (!asn1_push_tag(&data, ASN1_CONTEXT(1))) { + if (!asn1_push_tag(data, ASN1_CONTEXT(1))) { return False; } - if (!asn1_write_OctetString(&data, lvrc->match.gtOrEq.value, lvrc->match.gtOrEq.value_len)) { + if (!asn1_write_OctetString(data, lvrc->match.gtOrEq.value, lvrc->match.gtOrEq.value_len)) { return False; } - if (!asn1_pop_tag(&data)) { /*CONTEXT*/ + if (!asn1_pop_tag(data)) { /*CONTEXT*/ return False; } } if (lvrc->ctxid_len) { - if (!asn1_write_OctetString(&data, lvrc->contextId, lvrc->ctxid_len)) { + if (!asn1_write_OctetString(data, lvrc->contextId, lvrc->ctxid_len)) { return False; } } - if (!asn1_pop_tag(&data)) { + if (!asn1_pop_tag(data)) { return False; } - *out = data_blob_talloc(mem_ctx, data.data, data.length); + *out = data_blob_talloc(mem_ctx, data->data, data->length); if (out->data == NULL) { return False; } + talloc_free(data); return True; } @@ -1005,40 +996,39 @@ static BOOL encode_vlv_request(void *mem_ctx, void *in, DATA_BLOB *out) static BOOL encode_vlv_response(void *mem_ctx, void *in, DATA_BLOB *out) { struct ldb_vlv_resp_control *lvrc = talloc_get_type(in, struct ldb_vlv_resp_control); - struct asn1_data data; + struct asn1_data *data = asn1_init(mem_ctx); - ZERO_STRUCT(data); - - if (!asn1_push_tag(&data, ASN1_SEQUENCE(0))) { + if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { return False; } - if (!asn1_write_Integer(&data, lvrc->targetPosition)) { + if (!asn1_write_Integer(data, lvrc->targetPosition)) { return False; } - if (!asn1_write_Integer(&data, lvrc->contentCount)) { + if (!asn1_write_Integer(data, lvrc->contentCount)) { return False; } - if (!asn1_write_enumerated(&data, lvrc->vlv_result)) { + if (!asn1_write_enumerated(data, lvrc->vlv_result)) { return False; } if (lvrc->ctxid_len) { - if (!asn1_write_OctetString(&data, lvrc->contextId, lvrc->ctxid_len)) { + if (!asn1_write_OctetString(data, lvrc->contextId, lvrc->ctxid_len)) { return False; } } - if (!asn1_pop_tag(&data)) { + if (!asn1_pop_tag(data)) { return False; } - *out = data_blob_talloc(mem_ctx, data.data, data.length); + *out = data_blob_talloc(mem_ctx, data->data, data->length); if (out->data == NULL) { return False; } + talloc_free(data); return True; } @@ -1093,7 +1083,7 @@ BOOL ldap_decode_control_wrapper(void *mem_ctx, struct asn1_data *data, struct l return False; } - if (!asn1_read_OctetString(data, &oid)) { + if (!asn1_read_OctetString(data, mem_ctx, &oid)) { return False; } ctrl->oid = talloc_strndup(mem_ctx, (char *)oid.data, oid.length); @@ -1117,7 +1107,7 @@ BOOL ldap_decode_control_wrapper(void *mem_ctx, struct asn1_data *data, struct l goto end_tag; } - if (!asn1_read_OctetString(data, value)) { + if (!asn1_read_OctetString(data, mem_ctx, value)) { return False; } -- cgit From 931f594cf16b8c7f9f416d7a8831432b783a0ec8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 21 May 2007 12:47:18 +0000 Subject: r23036: error checking on asn1_init() failure (This used to be commit 26cf8494084c0106ef0e1c9b6ef40eeadf945ef2) --- source4/libcli/ldap/ldap_controls.c | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'source4/libcli/ldap/ldap_controls.c') diff --git a/source4/libcli/ldap/ldap_controls.c b/source4/libcli/ldap/ldap_controls.c index 180e6eeb62..79c16afc95 100644 --- a/source4/libcli/ldap/ldap_controls.c +++ b/source4/libcli/ldap/ldap_controls.c @@ -37,6 +37,8 @@ static BOOL decode_server_sort_response(void *mem_ctx, DATA_BLOB in, void **out) struct asn1_data *data = asn1_init(mem_ctx); struct ldb_sort_resp_control *lsrc; + if (!data) return False; + if (!asn1_load(data, in)) { return False; } @@ -82,6 +84,8 @@ static BOOL decode_server_sort_request(void *mem_ctx, DATA_BLOB in, void **out) struct ldb_server_sort_control **lssc; int num; + if (!data) return False; + if (!asn1_load(data, in)) { return False; } @@ -156,6 +160,8 @@ static BOOL decode_extended_dn_request(void *mem_ctx, DATA_BLOB in, void **out) struct asn1_data *data = asn1_init(mem_ctx); struct ldb_extended_dn_control *ledc; + if (!data) return False; + if (!asn1_load(data, in)) { return False; } @@ -187,6 +193,8 @@ static BOOL decode_sd_flags_request(void *mem_ctx, DATA_BLOB in, void **out) struct asn1_data *data = asn1_init(mem_ctx); struct ldb_sd_flags_control *lsdfc; + if (!data) return False; + if (!asn1_load(data, in)) { return False; } @@ -218,6 +226,8 @@ static BOOL decode_search_options_request(void *mem_ctx, DATA_BLOB in, void **ou struct asn1_data *data = asn1_init(mem_ctx); struct ldb_search_options_control *lsoc; + if (!data) return False; + if (!asn1_load(data, in)) { return False; } @@ -250,6 +260,8 @@ static BOOL decode_paged_results_request(void *mem_ctx, DATA_BLOB in, void **out struct asn1_data *data = asn1_init(mem_ctx); struct ldb_paged_control *lprc; + if (!data) return False; + if (!asn1_load(data, in)) { return False; } @@ -296,6 +308,8 @@ static BOOL decode_dirsync_request(void *mem_ctx, DATA_BLOB in, void **out) struct asn1_data *data = asn1_init(mem_ctx); struct ldb_dirsync_control *ldc; + if (!data) return False; + if (!asn1_load(data, in)) { return False; } @@ -349,6 +363,8 @@ static BOOL decode_asq_control(void *mem_ctx, DATA_BLOB in, void **out) struct asn1_data *data = asn1_init(mem_ctx); struct ldb_asq_control *lac; + if (!data) return False; + if (!asn1_load(data, in)) { return False; } @@ -452,6 +468,8 @@ static BOOL decode_vlv_request(void *mem_ctx, DATA_BLOB in, void **out) struct asn1_data *data = asn1_init(mem_ctx); struct ldb_vlv_req_control *lvrc; + if (!data) return False; + if (!asn1_load(data, in)) { return False; } @@ -562,6 +580,8 @@ static BOOL decode_vlv_response(void *mem_ctx, DATA_BLOB in, void **out) struct asn1_data *data = asn1_init(mem_ctx); struct ldb_vlv_resp_control *lvrc; + if (!data) return False; + if (!asn1_load(data, in)) { return False; } @@ -615,6 +635,8 @@ static BOOL encode_server_sort_response(void *mem_ctx, void *in, DATA_BLOB *out) struct ldb_sort_resp_control *lsrc = talloc_get_type(in, struct ldb_sort_resp_control); struct asn1_data *data = asn1_init(mem_ctx); + if (!data) return False; + if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { return False; } @@ -648,6 +670,8 @@ static BOOL encode_server_sort_request(void *mem_ctx, void *in, DATA_BLOB *out) struct asn1_data *data = asn1_init(mem_ctx); int num; + if (!data) return False; + if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { return False; } @@ -696,6 +720,8 @@ static BOOL encode_extended_dn_request(void *mem_ctx, void *in, DATA_BLOB *out) struct ldb_extended_dn_control *ledc = talloc_get_type(in, struct ldb_extended_dn_control); struct asn1_data *data = asn1_init(mem_ctx); + if (!data) return False; + if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { return False; } @@ -722,6 +748,8 @@ static BOOL encode_sd_flags_request(void *mem_ctx, void *in, DATA_BLOB *out) struct ldb_sd_flags_control *lsdfc = talloc_get_type(in, struct ldb_sd_flags_control); struct asn1_data *data = asn1_init(mem_ctx); + if (!data) return False; + if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { return False; } @@ -748,6 +776,8 @@ static BOOL encode_search_options_request(void *mem_ctx, void *in, DATA_BLOB *ou struct ldb_search_options_control *lsoc = talloc_get_type(in, struct ldb_search_options_control); struct asn1_data *data = asn1_init(mem_ctx); + if (!data) return False; + if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { return False; } @@ -774,6 +804,8 @@ static BOOL encode_paged_results_request(void *mem_ctx, void *in, DATA_BLOB *out struct ldb_paged_control *lprc = talloc_get_type(in, struct ldb_paged_control); struct asn1_data *data = asn1_init(mem_ctx); + if (!data) return False; + if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { return False; } @@ -807,6 +839,8 @@ static BOOL encode_asq_control(void *mem_ctx, void *in, DATA_BLOB *out) struct ldb_asq_control *lac = talloc_get_type(in, struct ldb_asq_control); struct asn1_data *data = asn1_init(mem_ctx); + if (!data) return False; + if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { return False; } @@ -840,6 +874,8 @@ static BOOL encode_dirsync_request(void *mem_ctx, void *in, DATA_BLOB *out) struct ldb_dirsync_control *ldc = talloc_get_type(in, struct ldb_dirsync_control); struct asn1_data *data = asn1_init(mem_ctx); + if (!data) return False; + if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { return False; } @@ -924,6 +960,8 @@ static BOOL encode_vlv_request(void *mem_ctx, void *in, DATA_BLOB *out) struct ldb_vlv_req_control *lvrc = talloc_get_type(in, struct ldb_vlv_req_control); struct asn1_data *data = asn1_init(mem_ctx); + if (!data) return False; + if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { return False; } @@ -998,6 +1036,8 @@ static BOOL encode_vlv_response(void *mem_ctx, void *in, DATA_BLOB *out) struct ldb_vlv_resp_control *lvrc = talloc_get_type(in, struct ldb_vlv_resp_control); struct asn1_data *data = asn1_init(mem_ctx); + if (!data) return False; + if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { return False; } -- cgit From 0479a2f1cbae51fcd8dbdc3c148c808421fb4d25 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:07:03 +0000 Subject: r23792: convert Samba4 to GPLv3 There are still a few tidyups of old FSF addresses to come (in both s3 and s4). More commits soon. (This used to be commit fcf38a38ac691abd0fa51b89dc951a08e89fdafa) --- source4/libcli/ldap/ldap_controls.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/libcli/ldap/ldap_controls.c') diff --git a/source4/libcli/ldap/ldap_controls.c b/source4/libcli/ldap/ldap_controls.c index 79c16afc95..4f76c7315b 100644 --- a/source4/libcli/ldap/ldap_controls.c +++ b/source4/libcli/ldap/ldap_controls.c @@ -6,7 +6,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -15,8 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ -- cgit From 210971d092e908e1ec482646b3ceb2f579d89440 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 6 Aug 2007 04:07:05 +0000 Subject: r24248: Attempt to fix bug #4830 by . If there is no payload to the control, we still need to inialise *value, as otherwise we read uninitialised data later. Andrew Bartlett (This used to be commit f6566480b7f1b4036b38284aa539f3a69f5c4573) --- source4/libcli/ldap/ldap_controls.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/ldap/ldap_controls.c') diff --git a/source4/libcli/ldap/ldap_controls.c b/source4/libcli/ldap/ldap_controls.c index 4f76c7315b..3a5d14c0c9 100644 --- a/source4/libcli/ldap/ldap_controls.c +++ b/source4/libcli/ldap/ldap_controls.c @@ -1143,6 +1143,7 @@ BOOL ldap_decode_control_wrapper(void *mem_ctx, struct asn1_data *data, struct l ctrl->data = NULL; if (!asn1_peek_tag(data, ASN1_OCTET_STRING)) { + *value = data_blob(NULL, 0); goto end_tag; } -- cgit From 2151cde58014ea2e822c13d2f8a369b45dc19ca8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 6 Oct 2007 22:28:14 +0000 Subject: r25554: Convert last instances of BOOL, True and False to the standard types. (This used to be commit 566aa14139510788548a874e9213d91317f83ca9) --- source4/libcli/ldap/ldap_controls.c | 530 ++++++++++++++++++------------------ 1 file changed, 265 insertions(+), 265 deletions(-) (limited to 'source4/libcli/ldap/ldap_controls.c') diff --git a/source4/libcli/ldap/ldap_controls.c b/source4/libcli/ldap/ldap_controls.c index 3a5d14c0c9..b7fd1ce178 100644 --- a/source4/libcli/ldap/ldap_controls.c +++ b/source4/libcli/ldap/ldap_controls.c @@ -26,56 +26,56 @@ struct control_handler { const char *oid; - BOOL (*decode)(void *mem_ctx, DATA_BLOB in, void **out); - BOOL (*encode)(void *mem_ctx, void *in, DATA_BLOB *out); + bool (*decode)(void *mem_ctx, DATA_BLOB in, void **out); + bool (*encode)(void *mem_ctx, void *in, DATA_BLOB *out); }; -static BOOL decode_server_sort_response(void *mem_ctx, DATA_BLOB in, void **out) +static bool decode_server_sort_response(void *mem_ctx, DATA_BLOB in, void **out) { DATA_BLOB attr; struct asn1_data *data = asn1_init(mem_ctx); struct ldb_sort_resp_control *lsrc; - if (!data) return False; + if (!data) return false; if (!asn1_load(data, in)) { - return False; + return false; } lsrc = talloc(mem_ctx, struct ldb_sort_resp_control); if (!lsrc) { - return False; + return false; } if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) { - return False; + return false; } if (!asn1_read_enumerated(data, &(lsrc->result))) { - return False; + return false; } lsrc->attr_desc = NULL; if (asn1_peek_tag(data, ASN1_OCTET_STRING)) { if (!asn1_read_OctetString(data, mem_ctx, &attr)) { - return False; + return false; } lsrc->attr_desc = talloc_strndup(lsrc, (const char *)attr.data, attr.length); if (!lsrc->attr_desc) { - return False; + return false; } } if (!asn1_end_tag(data)) { - return False; + return false; } *out = lsrc; - return True; + return true; } -static BOOL decode_server_sort_request(void *mem_ctx, DATA_BLOB in, void **out) +static bool decode_server_sort_request(void *mem_ctx, DATA_BLOB in, void **out) { DATA_BLOB attr; DATA_BLOB rule; @@ -83,14 +83,14 @@ static BOOL decode_server_sort_request(void *mem_ctx, DATA_BLOB in, void **out) struct ldb_server_sort_control **lssc; int num; - if (!data) return False; + if (!data) return false; if (!asn1_load(data, in)) { - return False; + return false; } if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) { - return False; + return false; } lssc = NULL; @@ -98,46 +98,46 @@ static BOOL decode_server_sort_request(void *mem_ctx, DATA_BLOB in, void **out) for (num = 0; asn1_peek_tag(data, ASN1_SEQUENCE(0)); num++) { lssc = talloc_realloc(mem_ctx, lssc, struct ldb_server_sort_control *, num + 2); if (!lssc) { - return False; + return false; } lssc[num] = talloc_zero(lssc, struct ldb_server_sort_control); if (!lssc[num]) { - return False; + return false; } if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) { - return False; + return false; } if (!asn1_read_OctetString(data, mem_ctx, &attr)) { - return False; + return false; } lssc[num]->attributeName = talloc_strndup(lssc[num], (const char *)attr.data, attr.length); if (!lssc [num]->attributeName) { - return False; + return false; } if (asn1_peek_tag(data, ASN1_OCTET_STRING)) { if (!asn1_read_OctetString(data, mem_ctx, &rule)) { - return False; + return false; } lssc[num]->orderingRule = talloc_strndup(lssc[num], (const char *)rule.data, rule.length); if (!lssc[num]->orderingRule) { - return False; + return false; } } if (asn1_peek_tag(data, ASN1_BOOLEAN)) { - BOOL reverse; + bool reverse; if (!asn1_read_BOOLEAN(data, &reverse)) { - return False; + return false; } lssc[num]->reverse = reverse; } if (!asn1_end_tag(data)) { - return False; + return false; } } @@ -146,248 +146,248 @@ static BOOL decode_server_sort_request(void *mem_ctx, DATA_BLOB in, void **out) } if (!asn1_end_tag(data)) { - return False; + return false; } *out = lssc; - return True; + return true; } -static BOOL decode_extended_dn_request(void *mem_ctx, DATA_BLOB in, void **out) +static bool decode_extended_dn_request(void *mem_ctx, DATA_BLOB in, void **out) { struct asn1_data *data = asn1_init(mem_ctx); struct ldb_extended_dn_control *ledc; - if (!data) return False; + if (!data) return false; if (!asn1_load(data, in)) { - return False; + return false; } ledc = talloc(mem_ctx, struct ldb_extended_dn_control); if (!ledc) { - return False; + return false; } if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) { - return False; + return false; } if (!asn1_read_Integer(data, &(ledc->type))) { - return False; + return false; } if (!asn1_end_tag(data)) { - return False; + return false; } *out = ledc; - return True; + return true; } -static BOOL decode_sd_flags_request(void *mem_ctx, DATA_BLOB in, void **out) +static bool decode_sd_flags_request(void *mem_ctx, DATA_BLOB in, void **out) { struct asn1_data *data = asn1_init(mem_ctx); struct ldb_sd_flags_control *lsdfc; - if (!data) return False; + if (!data) return false; if (!asn1_load(data, in)) { - return False; + return false; } lsdfc = talloc(mem_ctx, struct ldb_sd_flags_control); if (!lsdfc) { - return False; + return false; } if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) { - return False; + return false; } if (!asn1_read_Integer(data, &(lsdfc->secinfo_flags))) { - return False; + return false; } if (!asn1_end_tag(data)) { - return False; + return false; } *out = lsdfc; - return True; + return true; } -static BOOL decode_search_options_request(void *mem_ctx, DATA_BLOB in, void **out) +static bool decode_search_options_request(void *mem_ctx, DATA_BLOB in, void **out) { struct asn1_data *data = asn1_init(mem_ctx); struct ldb_search_options_control *lsoc; - if (!data) return False; + if (!data) return false; if (!asn1_load(data, in)) { - return False; + return false; } lsoc = talloc(mem_ctx, struct ldb_search_options_control); if (!lsoc) { - return False; + return false; } if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) { - return False; + return false; } if (!asn1_read_Integer(data, &(lsoc->search_options))) { - return False; + return false; } if (!asn1_end_tag(data)) { - return False; + return false; } *out = lsoc; - return True; + return true; } -static BOOL decode_paged_results_request(void *mem_ctx, DATA_BLOB in, void **out) +static bool decode_paged_results_request(void *mem_ctx, DATA_BLOB in, void **out) { DATA_BLOB cookie; struct asn1_data *data = asn1_init(mem_ctx); struct ldb_paged_control *lprc; - if (!data) return False; + if (!data) return false; if (!asn1_load(data, in)) { - return False; + return false; } lprc = talloc(mem_ctx, struct ldb_paged_control); if (!lprc) { - return False; + return false; } if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) { - return False; + return false; } if (!asn1_read_Integer(data, &(lprc->size))) { - return False; + return false; } if (!asn1_read_OctetString(data, mem_ctx, &cookie)) { - return False; + return false; } lprc->cookie_len = cookie.length; if (lprc->cookie_len) { lprc->cookie = talloc_memdup(lprc, cookie.data, cookie.length); if (!(lprc->cookie)) { - return False; + return false; } } else { lprc->cookie = NULL; } if (!asn1_end_tag(data)) { - return False; + return false; } *out = lprc; - return True; + return true; } -static BOOL decode_dirsync_request(void *mem_ctx, DATA_BLOB in, void **out) +static bool decode_dirsync_request(void *mem_ctx, DATA_BLOB in, void **out) { DATA_BLOB cookie; struct asn1_data *data = asn1_init(mem_ctx); struct ldb_dirsync_control *ldc; - if (!data) return False; + if (!data) return false; if (!asn1_load(data, in)) { - return False; + return false; } ldc = talloc(mem_ctx, struct ldb_dirsync_control); if (!ldc) { - return False; + return false; } if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) { - return False; + return false; } if (!asn1_read_Integer(data, &(ldc->flags))) { - return False; + return false; } if (!asn1_read_Integer(data, &(ldc->max_attributes))) { - return False; + return false; } if (!asn1_read_OctetString(data, mem_ctx, &cookie)) { - return False; + return false; } ldc->cookie_len = cookie.length; if (ldc->cookie_len) { ldc->cookie = talloc_memdup(ldc, cookie.data, cookie.length); if (!(ldc->cookie)) { - return False; + return false; } } else { ldc->cookie = NULL; } if (!asn1_end_tag(data)) { - return False; + return false; } *out = ldc; - return True; + return true; } /* seem that this controls has 2 forms one in case it is used with * a Search Request and another when used ina Search Response */ -static BOOL decode_asq_control(void *mem_ctx, DATA_BLOB in, void **out) +static bool decode_asq_control(void *mem_ctx, DATA_BLOB in, void **out) { DATA_BLOB source_attribute; struct asn1_data *data = asn1_init(mem_ctx); struct ldb_asq_control *lac; - if (!data) return False; + if (!data) return false; if (!asn1_load(data, in)) { - return False; + return false; } lac = talloc(mem_ctx, struct ldb_asq_control); if (!lac) { - return False; + return false; } if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) { - return False; + return false; } if (asn1_peek_tag(data, ASN1_OCTET_STRING)) { if (!asn1_read_OctetString(data, mem_ctx, &source_attribute)) { - return False; + return false; } lac->src_attr_len = source_attribute.length; if (lac->src_attr_len) { lac->source_attribute = talloc_strndup(lac, (const char *)source_attribute.data, source_attribute.length); if (!(lac->source_attribute)) { - return False; + return false; } } else { lac->source_attribute = NULL; @@ -398,96 +398,96 @@ static BOOL decode_asq_control(void *mem_ctx, DATA_BLOB in, void **out) } else if (asn1_peek_tag(data, ASN1_ENUMERATED)) { if (!asn1_read_enumerated(data, &(lac->result))) { - return False; + return false; } lac->request = 0; } else { - return False; + return false; } if (!asn1_end_tag(data)) { - return False; + return false; } *out = lac; - return True; + return true; } -static BOOL decode_domain_scope_request(void *mem_ctx, DATA_BLOB in, void **out) +static bool decode_domain_scope_request(void *mem_ctx, DATA_BLOB in, void **out) { if (in.length != 0) { - return False; + return false; } - return True; + return true; } -static BOOL decode_notification_request(void *mem_ctx, DATA_BLOB in, void **out) +static bool decode_notification_request(void *mem_ctx, DATA_BLOB in, void **out) { if (in.length != 0) { - return False; + return false; } - return True; + return true; } -static BOOL decode_show_deleted_request(void *mem_ctx, DATA_BLOB in, void **out) +static bool decode_show_deleted_request(void *mem_ctx, DATA_BLOB in, void **out) { if (in.length != 0) { - return False; + return false; } - return True; + return true; } -static BOOL decode_permissive_modify_request(void *mem_ctx, DATA_BLOB in, void **out) +static bool decode_permissive_modify_request(void *mem_ctx, DATA_BLOB in, void **out) { if (in.length != 0) { - return False; + return false; } - return True; + return true; } -static BOOL decode_manageDSAIT_request(void *mem_ctx, DATA_BLOB in, void **out) +static bool decode_manageDSAIT_request(void *mem_ctx, DATA_BLOB in, void **out) { if (in.length != 0) { - return False; + return false; } - return True; + return true; } -static BOOL decode_vlv_request(void *mem_ctx, DATA_BLOB in, void **out) +static bool decode_vlv_request(void *mem_ctx, DATA_BLOB in, void **out) { DATA_BLOB assertion_value, context_id; struct asn1_data *data = asn1_init(mem_ctx); struct ldb_vlv_req_control *lvrc; - if (!data) return False; + if (!data) return false; if (!asn1_load(data, in)) { - return False; + return false; } lvrc = talloc(mem_ctx, struct ldb_vlv_req_control); if (!lvrc) { - return False; + return false; } if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) { - return False; + return false; } if (!asn1_read_Integer(data, &(lvrc->beforeCount))) { - return False; + return false; } if (!asn1_read_Integer(data, &(lvrc->afterCount))) { - return False; + return false; } if (asn1_peek_tag(data, ASN1_CONTEXT(0))) { @@ -495,27 +495,27 @@ static BOOL decode_vlv_request(void *mem_ctx, DATA_BLOB in, void **out) lvrc->type = 0; if (!asn1_start_tag(data, ASN1_CONTEXT(0))) { - return False; + return false; } if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) { - return False; + return false; } if (!asn1_read_Integer(data, &(lvrc->match.byOffset.offset))) { - return False; + return false; } if (!asn1_read_Integer(data, &(lvrc->match.byOffset.contentCount))) { - return False; + return false; } if (!asn1_end_tag(data)) { /*SEQUENCE*/ - return False; + return false; } if (!asn1_end_tag(data)) { /*CONTEXT*/ - return False; + return false; } } else { @@ -523,38 +523,38 @@ static BOOL decode_vlv_request(void *mem_ctx, DATA_BLOB in, void **out) lvrc->type = 1; if (!asn1_start_tag(data, ASN1_CONTEXT(1))) { - return False; + return false; } if (!asn1_read_OctetString(data, mem_ctx, &assertion_value)) { - return False; + return false; } lvrc->match.gtOrEq.value_len = assertion_value.length; if (lvrc->match.gtOrEq.value_len) { lvrc->match.gtOrEq.value = talloc_memdup(lvrc, assertion_value.data, assertion_value.length); if (!(lvrc->match.gtOrEq.value)) { - return False; + return false; } } else { lvrc->match.gtOrEq.value = NULL; } if (!asn1_end_tag(data)) { /*CONTEXT*/ - return False; + return false; } } if (asn1_peek_tag(data, ASN1_OCTET_STRING)) { if (!asn1_read_OctetString(data, mem_ctx, &context_id)) { - return False; + return false; } lvrc->ctxid_len = context_id.length; if (lvrc->ctxid_len) { lvrc->contextId = talloc_memdup(lvrc, context_id.data, context_id.length); if (!(lvrc->contextId)) { - return False; + return false; } } else { lvrc->contextId = NULL; @@ -565,54 +565,54 @@ static BOOL decode_vlv_request(void *mem_ctx, DATA_BLOB in, void **out) } if (!asn1_end_tag(data)) { - return False; + return false; } *out = lvrc; - return True; + return true; } -static BOOL decode_vlv_response(void *mem_ctx, DATA_BLOB in, void **out) +static bool decode_vlv_response(void *mem_ctx, DATA_BLOB in, void **out) { DATA_BLOB context_id; struct asn1_data *data = asn1_init(mem_ctx); struct ldb_vlv_resp_control *lvrc; - if (!data) return False; + if (!data) return false; if (!asn1_load(data, in)) { - return False; + return false; } lvrc = talloc(mem_ctx, struct ldb_vlv_resp_control); if (!lvrc) { - return False; + return false; } if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) { - return False; + return false; } if (!asn1_read_Integer(data, &(lvrc->targetPosition))) { - return False; + return false; } if (!asn1_read_Integer(data, &(lvrc->contentCount))) { - return False; + return false; } if (!asn1_read_enumerated(data, &(lvrc->vlv_result))) { - return False; + return false; } if (asn1_peek_tag(data, ASN1_OCTET_STRING)) { if (!asn1_read_OctetString(data, mem_ctx, &context_id)) { - return False; + return false; } lvrc->contextId = talloc_strndup(lvrc, (const char *)context_id.data, context_id.length); if (!lvrc->contextId) { - return False; + return false; } lvrc->ctxid_len = context_id.length; } else { @@ -621,455 +621,455 @@ static BOOL decode_vlv_response(void *mem_ctx, DATA_BLOB in, void **out) } if (!asn1_end_tag(data)) { - return False; + return false; } *out = lvrc; - return True; + return true; } -static BOOL encode_server_sort_response(void *mem_ctx, void *in, DATA_BLOB *out) +static bool encode_server_sort_response(void *mem_ctx, void *in, DATA_BLOB *out) { struct ldb_sort_resp_control *lsrc = talloc_get_type(in, struct ldb_sort_resp_control); struct asn1_data *data = asn1_init(mem_ctx); - if (!data) return False; + if (!data) return false; if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { - return False; + return false; } if (!asn1_write_enumerated(data, lsrc->result)) { - return False; + return false; } if (lsrc->attr_desc) { if (!asn1_write_OctetString(data, lsrc->attr_desc, strlen(lsrc->attr_desc))) { - return False; + return false; } } if (!asn1_pop_tag(data)) { - return False; + return false; } *out = data_blob_talloc(mem_ctx, data->data, data->length); if (out->data == NULL) { - return False; + return false; } talloc_free(data); - return True; + return true; } -static BOOL encode_server_sort_request(void *mem_ctx, void *in, DATA_BLOB *out) +static bool encode_server_sort_request(void *mem_ctx, void *in, DATA_BLOB *out) { struct ldb_server_sort_control **lssc = talloc_get_type(in, struct ldb_server_sort_control *); struct asn1_data *data = asn1_init(mem_ctx); int num; - if (!data) return False; + if (!data) return false; if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { - return False; + return false; } for (num = 0; lssc[num]; num++) { if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { - return False; + return false; } if (!asn1_write_OctetString(data, lssc[num]->attributeName, strlen(lssc[num]->attributeName))) { - return False; + return false; } if (lssc[num]->orderingRule) { if (!asn1_write_OctetString(data, lssc[num]->orderingRule, strlen(lssc[num]->orderingRule))) { - return False; + return false; } } if (lssc[num]->reverse) { if (!asn1_write_BOOLEAN(data, lssc[num]->reverse)) { - return False; + return false; } } if (!asn1_pop_tag(data)) { - return False; + return false; } } if (!asn1_pop_tag(data)) { - return False; + return false; } *out = data_blob_talloc(mem_ctx, data->data, data->length); if (out->data == NULL) { - return False; + return false; } talloc_free(data); - return True; + return true; } -static BOOL encode_extended_dn_request(void *mem_ctx, void *in, DATA_BLOB *out) +static bool encode_extended_dn_request(void *mem_ctx, void *in, DATA_BLOB *out) { struct ldb_extended_dn_control *ledc = talloc_get_type(in, struct ldb_extended_dn_control); struct asn1_data *data = asn1_init(mem_ctx); - if (!data) return False; + if (!data) return false; if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { - return False; + return false; } if (!asn1_write_Integer(data, ledc->type)) { - return False; + return false; } if (!asn1_pop_tag(data)) { - return False; + return false; } *out = data_blob_talloc(mem_ctx, data->data, data->length); if (out->data == NULL) { - return False; + return false; } talloc_free(data); - return True; + return true; } -static BOOL encode_sd_flags_request(void *mem_ctx, void *in, DATA_BLOB *out) +static bool encode_sd_flags_request(void *mem_ctx, void *in, DATA_BLOB *out) { struct ldb_sd_flags_control *lsdfc = talloc_get_type(in, struct ldb_sd_flags_control); struct asn1_data *data = asn1_init(mem_ctx); - if (!data) return False; + if (!data) return false; if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { - return False; + return false; } if (!asn1_write_Integer(data, lsdfc->secinfo_flags)) { - return False; + return false; } if (!asn1_pop_tag(data)) { - return False; + return false; } *out = data_blob_talloc(mem_ctx, data->data, data->length); if (out->data == NULL) { - return False; + return false; } talloc_free(data); - return True; + return true; } -static BOOL encode_search_options_request(void *mem_ctx, void *in, DATA_BLOB *out) +static bool encode_search_options_request(void *mem_ctx, void *in, DATA_BLOB *out) { struct ldb_search_options_control *lsoc = talloc_get_type(in, struct ldb_search_options_control); struct asn1_data *data = asn1_init(mem_ctx); - if (!data) return False; + if (!data) return false; if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { - return False; + return false; } if (!asn1_write_Integer(data, lsoc->search_options)) { - return False; + return false; } if (!asn1_pop_tag(data)) { - return False; + return false; } *out = data_blob_talloc(mem_ctx, data->data, data->length); if (out->data == NULL) { - return False; + return false; } talloc_free(data); - return True; + return true; } -static BOOL encode_paged_results_request(void *mem_ctx, void *in, DATA_BLOB *out) +static bool encode_paged_results_request(void *mem_ctx, void *in, DATA_BLOB *out) { struct ldb_paged_control *lprc = talloc_get_type(in, struct ldb_paged_control); struct asn1_data *data = asn1_init(mem_ctx); - if (!data) return False; + if (!data) return false; if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { - return False; + return false; } if (!asn1_write_Integer(data, lprc->size)) { - return False; + return false; } if (!asn1_write_OctetString(data, lprc->cookie, lprc->cookie_len)) { - return False; + return false; } if (!asn1_pop_tag(data)) { - return False; + return false; } *out = data_blob_talloc(mem_ctx, data->data, data->length); if (out->data == NULL) { - return False; + return false; } talloc_free(data); - return True; + return true; } /* seem that this controls has 2 forms one in case it is used with * a Search Request and another when used ina Search Response */ -static BOOL encode_asq_control(void *mem_ctx, void *in, DATA_BLOB *out) +static bool encode_asq_control(void *mem_ctx, void *in, DATA_BLOB *out) { struct ldb_asq_control *lac = talloc_get_type(in, struct ldb_asq_control); struct asn1_data *data = asn1_init(mem_ctx); - if (!data) return False; + if (!data) return false; if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { - return False; + return false; } if (lac->request) { if (!asn1_write_OctetString(data, lac->source_attribute, lac->src_attr_len)) { - return False; + return false; } } else { if (!asn1_write_enumerated(data, lac->result)) { - return False; + return false; } } if (!asn1_pop_tag(data)) { - return False; + return false; } *out = data_blob_talloc(mem_ctx, data->data, data->length); if (out->data == NULL) { - return False; + return false; } talloc_free(data); - return True; + return true; } -static BOOL encode_dirsync_request(void *mem_ctx, void *in, DATA_BLOB *out) +static bool encode_dirsync_request(void *mem_ctx, void *in, DATA_BLOB *out) { struct ldb_dirsync_control *ldc = talloc_get_type(in, struct ldb_dirsync_control); struct asn1_data *data = asn1_init(mem_ctx); - if (!data) return False; + if (!data) return false; if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { - return False; + return false; } if (!asn1_write_Integer(data, ldc->flags)) { - return False; + return false; } if (!asn1_write_Integer(data, ldc->max_attributes)) { - return False; + return false; } if (!asn1_write_OctetString(data, ldc->cookie, ldc->cookie_len)) { - return False; + return false; } if (!asn1_pop_tag(data)) { - return False; + return false; } *out = data_blob_talloc(mem_ctx, data->data, data->length); if (out->data == NULL) { - return False; + return false; } talloc_free(data); - return True; + return true; } -static BOOL encode_domain_scope_request(void *mem_ctx, void *in, DATA_BLOB *out) +static bool encode_domain_scope_request(void *mem_ctx, void *in, DATA_BLOB *out) { if (in) { - return False; + return false; } *out = data_blob(NULL, 0); - return True; + return true; } -static BOOL encode_notification_request(void *mem_ctx, void *in, DATA_BLOB *out) +static bool encode_notification_request(void *mem_ctx, void *in, DATA_BLOB *out) { if (in) { - return False; + return false; } *out = data_blob(NULL, 0); - return True; + return true; } -static BOOL encode_show_deleted_request(void *mem_ctx, void *in, DATA_BLOB *out) +static bool encode_show_deleted_request(void *mem_ctx, void *in, DATA_BLOB *out) { if (in) { - return False; + return false; } *out = data_blob(NULL, 0); - return True; + return true; } -static BOOL encode_permissive_modify_request(void *mem_ctx, void *in, DATA_BLOB *out) +static bool encode_permissive_modify_request(void *mem_ctx, void *in, DATA_BLOB *out) { if (in) { - return False; + return false; } *out = data_blob(NULL, 0); - return True; + return true; } -static BOOL encode_manageDSAIT_request(void *mem_ctx, void *in, DATA_BLOB *out) +static bool encode_manageDSAIT_request(void *mem_ctx, void *in, DATA_BLOB *out) { if (in) { - return False; + return false; } *out = data_blob(NULL, 0); - return True; + return true; } -static BOOL encode_vlv_request(void *mem_ctx, void *in, DATA_BLOB *out) +static bool encode_vlv_request(void *mem_ctx, void *in, DATA_BLOB *out) { struct ldb_vlv_req_control *lvrc = talloc_get_type(in, struct ldb_vlv_req_control); struct asn1_data *data = asn1_init(mem_ctx); - if (!data) return False; + if (!data) return false; if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { - return False; + return false; } if (!asn1_write_Integer(data, lvrc->beforeCount)) { - return False; + return false; } if (!asn1_write_Integer(data, lvrc->afterCount)) { - return False; + return false; } if (lvrc->type == 0) { if (!asn1_push_tag(data, ASN1_CONTEXT(0))) { - return False; + return false; } if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { - return False; + return false; } if (!asn1_write_Integer(data, lvrc->match.byOffset.offset)) { - return False; + return false; } if (!asn1_write_Integer(data, lvrc->match.byOffset.contentCount)) { - return False; + return false; } if (!asn1_pop_tag(data)) { /*SEQUENCE*/ - return False; + return false; } if (!asn1_pop_tag(data)) { /*CONTEXT*/ - return False; + return false; } } else { if (!asn1_push_tag(data, ASN1_CONTEXT(1))) { - return False; + return false; } if (!asn1_write_OctetString(data, lvrc->match.gtOrEq.value, lvrc->match.gtOrEq.value_len)) { - return False; + return false; } if (!asn1_pop_tag(data)) { /*CONTEXT*/ - return False; + return false; } } if (lvrc->ctxid_len) { if (!asn1_write_OctetString(data, lvrc->contextId, lvrc->ctxid_len)) { - return False; + return false; } } if (!asn1_pop_tag(data)) { - return False; + return false; } *out = data_blob_talloc(mem_ctx, data->data, data->length); if (out->data == NULL) { - return False; + return false; } talloc_free(data); - return True; + return true; } -static BOOL encode_vlv_response(void *mem_ctx, void *in, DATA_BLOB *out) +static bool encode_vlv_response(void *mem_ctx, void *in, DATA_BLOB *out) { struct ldb_vlv_resp_control *lvrc = talloc_get_type(in, struct ldb_vlv_resp_control); struct asn1_data *data = asn1_init(mem_ctx); - if (!data) return False; + if (!data) return false; if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { - return False; + return false; } if (!asn1_write_Integer(data, lvrc->targetPosition)) { - return False; + return false; } if (!asn1_write_Integer(data, lvrc->contentCount)) { - return False; + return false; } if (!asn1_write_enumerated(data, lvrc->vlv_result)) { - return False; + return false; } if (lvrc->ctxid_len) { if (!asn1_write_OctetString(data, lvrc->contextId, lvrc->ctxid_len)) { - return False; + return false; } } if (!asn1_pop_tag(data)) { - return False; + return false; } *out = data_blob_talloc(mem_ctx, data->data, data->length); if (out->data == NULL) { - return False; + return false; } talloc_free(data); - return True; + return true; } struct control_handler ldap_known_controls[] = { @@ -1095,49 +1095,49 @@ struct control_handler ldap_known_controls[] = { { NULL, NULL, NULL } }; -BOOL ldap_decode_control_value(void *mem_ctx, DATA_BLOB value, struct ldb_control *ctrl) +bool ldap_decode_control_value(void *mem_ctx, DATA_BLOB value, struct ldb_control *ctrl) { int i; for (i = 0; ldap_known_controls[i].oid != NULL; i++) { if (strcmp(ldap_known_controls[i].oid, ctrl->oid) == 0) { if (!ldap_known_controls[i].decode || !ldap_known_controls[i].decode(mem_ctx, value, &ctrl->data)) { - return False; + return false; } break; } } if (ldap_known_controls[i].oid == NULL) { - return False; + return false; } - return True; + return true; } -BOOL ldap_decode_control_wrapper(void *mem_ctx, struct asn1_data *data, struct ldb_control *ctrl, DATA_BLOB *value) +bool ldap_decode_control_wrapper(void *mem_ctx, struct asn1_data *data, struct ldb_control *ctrl, DATA_BLOB *value) { DATA_BLOB oid; if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) { - return False; + return false; } if (!asn1_read_OctetString(data, mem_ctx, &oid)) { - return False; + return false; } ctrl->oid = talloc_strndup(mem_ctx, (char *)oid.data, oid.length); if (!ctrl->oid) { - return False; + return false; } if (asn1_peek_tag(data, ASN1_BOOLEAN)) { - BOOL critical; + bool critical; if (!asn1_read_BOOLEAN(data, &critical)) { - return False; + return false; } ctrl->critical = critical; } else { - ctrl->critical = False; + ctrl->critical = false; } ctrl->data = NULL; @@ -1148,18 +1148,18 @@ BOOL ldap_decode_control_wrapper(void *mem_ctx, struct asn1_data *data, struct l } if (!asn1_read_OctetString(data, mem_ctx, value)) { - return False; + return false; } end_tag: if (!asn1_end_tag(data)) { - return False; + return false; } - return True; + return true; } -BOOL ldap_encode_control(void *mem_ctx, struct asn1_data *data, struct ldb_control *ctrl) +bool ldap_encode_control(void *mem_ctx, struct asn1_data *data, struct ldb_control *ctrl) { DATA_BLOB value; int i; @@ -1168,33 +1168,33 @@ BOOL ldap_encode_control(void *mem_ctx, struct asn1_data *data, struct ldb_contr if (strcmp(ldap_known_controls[i].oid, ctrl->oid) == 0) { if (!ldap_known_controls[i].encode) { if (ctrl->critical) { - return False; + return false; } else { /* not encoding this control */ - return True; + return true; } } if (!ldap_known_controls[i].encode(mem_ctx, ctrl->data, &value)) { - return False; + return false; } break; } } if (ldap_known_controls[i].oid == NULL) { - return False; + return false; } if (!asn1_push_tag(data, ASN1_SEQUENCE(0))) { - return False; + return false; } if (!asn1_write_OctetString(data, ctrl->oid, strlen(ctrl->oid))) { - return False; + return false; } if (ctrl->critical) { if (!asn1_write_BOOLEAN(data, ctrl->critical)) { - return False; + return false; } } @@ -1203,13 +1203,13 @@ BOOL ldap_encode_control(void *mem_ctx, struct asn1_data *data, struct ldb_contr } if (!asn1_write_OctetString(data, value.data, value.length)) { - return False; + return false; } pop_tag: if (!asn1_pop_tag(data)) { - return False; + return false; } - return True; + return true; } -- cgit From 364266e22a08e730f2442cf87ec385620cff2700 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 29 Nov 2007 08:00:04 +0100 Subject: r26192: Handle, test and implement the style of extended_dn requiest that MMC uses. It appears that the control value is optional, implying type 0 responses. Failing to parse this was causing LDAP disconnects with 'unavailable critical extension'. Andrew Bartlett (This used to be commit 833dfc2f2af84c45f954e428c9ea6babf100ba92) --- source4/libcli/ldap/ldap_controls.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'source4/libcli/ldap/ldap_controls.c') diff --git a/source4/libcli/ldap/ldap_controls.c b/source4/libcli/ldap/ldap_controls.c index b7fd1ce178..34e5cccf75 100644 --- a/source4/libcli/ldap/ldap_controls.c +++ b/source4/libcli/ldap/ldap_controls.c @@ -156,9 +156,16 @@ static bool decode_server_sort_request(void *mem_ctx, DATA_BLOB in, void **out) static bool decode_extended_dn_request(void *mem_ctx, DATA_BLOB in, void **out) { - struct asn1_data *data = asn1_init(mem_ctx); + struct asn1_data *data; struct ldb_extended_dn_control *ledc; + /* The content of this control is optional */ + if (in.length == 0) { + *out = NULL; + return true; + } + + data = asn1_init(mem_ctx); if (!data) return false; if (!asn1_load(data, in)) { @@ -717,7 +724,14 @@ static bool encode_server_sort_request(void *mem_ctx, void *in, DATA_BLOB *out) static bool encode_extended_dn_request(void *mem_ctx, void *in, DATA_BLOB *out) { struct ldb_extended_dn_control *ledc = talloc_get_type(in, struct ldb_extended_dn_control); - struct asn1_data *data = asn1_init(mem_ctx); + struct asn1_data *data; + + if (!in) { + *out = data_blob(NULL, 0); + return true; + } + + data = asn1_init(mem_ctx); if (!data) return false; -- cgit From 939edd0eb7c3952859afb802c8e542449a2c4031 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 15 Jan 2008 01:04:38 +0100 Subject: util: Move asn1 to lib/util to trim down the number of subsystems. (This used to be commit 44e1cfd2d0ef62e4ee541cec00581a7151d951b3) --- source4/libcli/ldap/ldap_controls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/ldap/ldap_controls.c') diff --git a/source4/libcli/ldap/ldap_controls.c b/source4/libcli/ldap/ldap_controls.c index 34e5cccf75..3b94580033 100644 --- a/source4/libcli/ldap/ldap_controls.c +++ b/source4/libcli/ldap/ldap_controls.c @@ -20,7 +20,7 @@ */ #include "includes.h" -#include "libcli/util/asn_1.h" +#include "lib/util/asn1.h" #include "libcli/ldap/ldap.h" #include "lib/ldb/include/ldb.h" -- cgit