return NULL;
}
-
+/* Decode a single LDAP attribute, possibly containing multiple values */
static void ldap_decode_attrib(TALLOC_CTX *mem_ctx, struct asn1_data *data,
struct ldb_message_element *attrib)
{
}
-void ldap_decode_attribs(TALLOC_CTX *mem_ctx, struct asn1_data *data,
- struct ldb_message_element **attributes,
- int *num_attributes)
+/* Decode a set of LDAP attributes, as found in the dereference control */
+void ldap_decode_attribs_bare(TALLOC_CTX *mem_ctx, struct asn1_data *data,
+ struct ldb_message_element **attributes,
+ int *num_attributes)
{
- asn1_start_tag(data, ASN1_SEQUENCE(0));
while (asn1_peek_tag(data, ASN1_SEQUENCE(0))) {
struct ldb_message_element attrib;
ZERO_STRUCT(attrib);
add_attrib_to_array_talloc(mem_ctx, &attrib,
attributes, num_attributes);
}
+}
+
+/* Decode a set of LDAP attributes, as found in a search entry */
+void ldap_decode_attribs(TALLOC_CTX *mem_ctx, struct asn1_data *data,
+ struct ldb_message_element **attributes,
+ int *num_attributes)
+{
+ asn1_start_tag(data, ASN1_SEQUENCE(0));
+ ldap_decode_attribs_bare(mem_ctx, data,
+ attributes, num_attributes);
asn1_end_tag(data);
}
{
struct asn1_data *data = asn1_init(mem_ctx);
struct dsdb_openldap_dereference_result_control *control;
- struct dsdb_openldap_dereference_result **r;
+ struct dsdb_openldap_dereference_result **r = NULL;
int i = 0;
if (!data) return false;
control = talloc(mem_ctx, struct dsdb_openldap_dereference_result_control);
if (!control) return false;
- r = control->attributes = talloc_array(control, struct dsdb_openldap_dereference_result *, 0);
- if (!r) return false;
-
if (!asn1_load(data, in)) {
return false;
}
}
while (asn1_tag_remaining(data) > 0) {
- i++;
- r = talloc_realloc(r, control, struct dsdb_openldap_dereference_result *, i + 1);
-
- r[i] = talloc(r, struct dsdb_openldap_dereference_result);
+ r = talloc_realloc(control, r, struct dsdb_openldap_dereference_result *, i + 2);
+ if (!r) {
+ return false;
+ }
+ r[i] = talloc_zero(r, struct dsdb_openldap_dereference_result);
+ if (!r[i]) {
+ return false;
+ }
if (!asn1_start_tag(data, ASN1_SEQUENCE(0))) {
return false;
asn1_read_OctetString_talloc(r[i], data, &r[i]->source_attribute);
asn1_read_OctetString_talloc(r[i], data, &r[i]->dereferenced_dn);
- ldap_decode_attribs(r[i], data, &r[i]->attributes,
- &r[i]->num_attributes);
-
+ if (asn1_peek_tag(data, ASN1_CONTEXT(0))) {
+ if (!asn1_start_tag(data, ASN1_CONTEXT(0))) {
+ return false;
+ }
+
+ ldap_decode_attribs_bare(r, data, &r[i]->attributes,
+ &r[i]->num_attributes);
+
+ if (!asn1_end_tag(data)) {
+ return false;
+ }
+ }
if (!asn1_end_tag(data)) {
return false;
}
- r[i+1] = NULL;
+ i++;
+ r[i] = NULL;
}
if (!asn1_end_tag(data)) {
return false;
}
+ control->attributes = r;
*out = control;
return true;