summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-05-11 05:59:46 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:16:38 -0500
commit49304e965f87d00b7ba5d66fe929611d3ad2ebef (patch)
treebb3805993536a500264f6917006f8aef687eebf7
parent7b18fcd84799e0b9e1c014af575ca292f905d0a3 (diff)
downloadsamba-49304e965f87d00b7ba5d66fe929611d3ad2ebef.tar.gz
samba-49304e965f87d00b7ba5d66fe929611d3ad2ebef.tar.bz2
samba-49304e965f87d00b7ba5d66fe929611d3ad2ebef.zip
r6726: support binary search elements in ldap_decode()
(This used to be commit 2b36f1dfdd6cf3ab89f63b541ae4cd905fb03c8d)
-rw-r--r--source4/libcli/ldap/ldap.c48
1 files changed, 42 insertions, 6 deletions
diff --git a/source4/libcli/ldap/ldap.c b/source4/libcli/ldap/ldap.c
index 37c3266b97..1a4f323ebf 100644
--- a/source4/libcli/ldap/ldap.c
+++ b/source4/libcli/ldap/ldap.c
@@ -141,6 +141,39 @@ static struct ldap_val ldap_binary_decode(TALLOC_CTX *mem_ctx, const char *str)
/*
+ encode a blob as a RFC2254 binary string, escaping any
+ non-printable or '\' characters
+*/
+static const char *ldap_binary_encode(TALLOC_CTX *mem_ctx, DATA_BLOB blob)
+{
+ int i;
+ char *ret;
+ int len = blob.length;
+ for (i=0;i<blob.length;i++) {
+ if (!isprint(blob.data[i]) || blob.data[i] == '\\') {
+ len += 2;
+ }
+ }
+ ret = talloc_array(mem_ctx, char, len+1);
+ if (ret == NULL) return NULL;
+
+ len = 0;
+ for (i=0;i<blob.length;i++) {
+ if (!isprint(blob.data[i]) || blob.data[i] == '\\') {
+ snprintf(ret+len, 4, "\\%02X", blob.data[i]);
+ len += 3;
+ } else {
+ ret[len++] = blob.data[i];
+ }
+ }
+
+ ret[len] = 0;
+
+ return ret;
+}
+
+
+/*
<simple> ::= <attributetype> <filtertype> <attributevalue>
*/
static struct ldap_parse_tree *ldap_parse_simple(TALLOC_CTX *mem_ctx,
@@ -765,7 +798,7 @@ static BOOL ldap_decode_filter(TALLOC_CTX *mem_ctx, struct asn1_data *data,
}
asn1_end_tag(data);
- filter = talloc_asprintf(mem_ctx, "%s)", filter);
+ filter = talloc_asprintf_append(filter, ")");
break;
}
case 1: {
@@ -790,21 +823,24 @@ static BOOL ldap_decode_filter(TALLOC_CTX *mem_ctx, struct asn1_data *data,
asn1_end_tag(data);
- filter = talloc_asprintf(mem_ctx, "%s)", filter);
+ filter = talloc_asprintf_append(filter, ")");
break;
}
case 3: {
/* equalityMatch */
- const char *attrib, *value;
+ const char *attrib;
+ DATA_BLOB value;
if (tag_desc != 0xa0) /* context compound */
return False;
asn1_start_tag(data, ASN1_CONTEXT(3));
asn1_read_OctetString_talloc(mem_ctx, data, &attrib);
- asn1_read_OctetString_talloc(mem_ctx, data, &value);
+ asn1_read_OctetString(data, &value);
asn1_end_tag(data);
- if ((data->has_error) || (attrib == NULL) || (value == NULL))
+ if ((data->has_error) || (attrib == NULL) || (value.data == NULL))
return False;
- filter = talloc_asprintf(mem_ctx, "(%s=%s)", attrib, value);
+ filter = talloc_asprintf(mem_ctx, "(%s=%s)",
+ attrib, ldap_binary_encode(mem_ctx, value));
+ data_blob_free(&value);
break;
}
case 7: {