s4:libcli/ldap: split out a ldap_decode_attribs_bare() function
authorAndrew Bartlett <abartlet@samba.org>
Tue, 16 Dec 2008 07:27:51 +0000 (08:27 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 17 Dec 2008 01:29:24 +0000 (12:29 +1100)
The OpenLDAP dereference control (draft-masarati-ldap-deref-00) uses
an attribute list, as found in the search reply, but without one
enclosing ASN1_SEQUENCE(0)

This allows the dereference control parsing code to use this as a
helper function.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
source4/libcli/ldap/ldap.c

index 87c89daf9f47301a2665f2011bf24122c0028ce6..7a65cc5c2746fad95cebc851d4a1240930a29488 100644 (file)
@@ -504,9 +504,9 @@ static const char *blob2string_talloc(TALLOC_CTX *mem_ctx,
        return result;
 }
 
-static bool asn1_read_OctetString_talloc(TALLOC_CTX *mem_ctx,
-                                        struct asn1_data *data,
-                                        const char **result)
+bool asn1_read_OctetString_talloc(TALLOC_CTX *mem_ctx,
+                                 struct asn1_data *data,
+                                 const char **result)
 {
        DATA_BLOB string;
        if (!asn1_read_OctetString(data, mem_ctx, &string))
@@ -894,7 +894,7 @@ failed:
        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)
 {
@@ -911,11 +911,11 @@ static void ldap_decode_attrib(TALLOC_CTX *mem_ctx, struct asn1_data *data,
        
 }
 
-static 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);
@@ -923,6 +923,16 @@ static void ldap_decode_attribs(TALLOC_CTX *mem_ctx, struct asn1_data *data,
                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);
 }