From f49f6e0c83a8296bcaba3cb11b5fcaa55dd5ce5d Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 9 Oct 2004 23:59:12 +0000 Subject: r2884: parse LDAP Control messages metze (This used to be commit e23dcb18870450be4252a0dba3e427f73291da25) --- source4/libcli/ldap/ldap.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/source4/libcli/ldap/ldap.c b/source4/libcli/ldap/ldap.c index fbb5a21d84..7e12f42f06 100644 --- a/source4/libcli/ldap/ldap.c +++ b/source4/libcli/ldap/ldap.c @@ -1162,6 +1162,47 @@ BOOL ldap_decode(ASN1_DATA *data, struct ldap_message *msg) return False; } + msg->num_controls = 0; + msg->controls = NULL; + + if (asn1_peek_tag(data, ASN1_CONTEXT(0))) { + int i; + struct ldap_Control *ctrl = NULL; + + asn1_start_tag(data, ASN1_CONTEXT(0)); + + for (i=0; asn1_peek_tag(data, ASN1_SEQUENCE(0)); i++) { + asn1_start_tag(data, ASN1_SEQUENCE(0)); + + ctrl = talloc_realloc_p(msg->mem_ctx, ctrl, struct ldap_Control, i+1); + if (!ctrl) { + return False; + } + ctrl[i].oid = NULL; + ctrl[i].critical = False; + ctrl[i].value = data_blob(NULL, 0); + + asn1_read_OctetString_talloc(ctrl, data, &ctrl[i].oid); + + if (asn1_peek_tag(data, ASN1_BOOLEAN)) { + asn1_read_BOOLEAN(data, &ctrl[i].critical); + } + + if (asn1_peek_tag(data, ASN1_OCTET_STRING)) { + asn1_read_OctetString(data, &ctrl[i].value); + if (ctrl[i].value.data) { + talloc_steal(msg->mem_ctx, ctrl[i].value.data); + } + } + + asn1_end_tag(data); + } + msg->num_controls = i; + msg->controls = ctrl; + + asn1_end_tag(data); + } + asn1_end_tag(data); return ((!data->has_error) && (data->nesting == NULL)); } -- cgit