mirror of
https://github.com/samba-team/samba.git
synced 2025-12-04 08:23:50 +03:00
r6726: support binary search elements in ldap_decode()
(This used to be commit 2b36f1dfdd)
This commit is contained in:
committed by
Gerald (Jerry) Carter
parent
7b18fcd847
commit
49304e965f
@@ -140,6 +140,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>
|
<simple> ::= <attributetype> <filtertype> <attributevalue>
|
||||||
*/
|
*/
|
||||||
@@ -765,7 +798,7 @@ static BOOL ldap_decode_filter(TALLOC_CTX *mem_ctx, struct asn1_data *data,
|
|||||||
}
|
}
|
||||||
asn1_end_tag(data);
|
asn1_end_tag(data);
|
||||||
|
|
||||||
filter = talloc_asprintf(mem_ctx, "%s)", filter);
|
filter = talloc_asprintf_append(filter, ")");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 1: {
|
case 1: {
|
||||||
@@ -790,21 +823,24 @@ static BOOL ldap_decode_filter(TALLOC_CTX *mem_ctx, struct asn1_data *data,
|
|||||||
|
|
||||||
asn1_end_tag(data);
|
asn1_end_tag(data);
|
||||||
|
|
||||||
filter = talloc_asprintf(mem_ctx, "%s)", filter);
|
filter = talloc_asprintf_append(filter, ")");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 3: {
|
case 3: {
|
||||||
/* equalityMatch */
|
/* equalityMatch */
|
||||||
const char *attrib, *value;
|
const char *attrib;
|
||||||
|
DATA_BLOB value;
|
||||||
if (tag_desc != 0xa0) /* context compound */
|
if (tag_desc != 0xa0) /* context compound */
|
||||||
return False;
|
return False;
|
||||||
asn1_start_tag(data, ASN1_CONTEXT(3));
|
asn1_start_tag(data, ASN1_CONTEXT(3));
|
||||||
asn1_read_OctetString_talloc(mem_ctx, data, &attrib);
|
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);
|
asn1_end_tag(data);
|
||||||
if ((data->has_error) || (attrib == NULL) || (value == NULL))
|
if ((data->has_error) || (attrib == NULL) || (value.data == NULL))
|
||||||
return False;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
case 7: {
|
case 7: {
|
||||||
|
|||||||
Reference in New Issue
Block a user