r7596: next step in ldap cleanup. I'm aiming to get rid of the cut&pasted
authorAndrew Tridgell <tridge@samba.org>
Wed, 15 Jun 2005 01:02:53 +0000 (01:02 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:18:12 +0000 (13:18 -0500)
ldif parsing code in libcli/ldap/ldap_ldif.c, and instead use the ldb
ldif code. To do that I have changed the ldap code to use 'struct
ldb_message_element' instead of 'struct ldap_attribute'. They are
essentially the same structure anyway, so by making them really the
same it will be much easier to use the ldb code in libcli/ldap/

I have also made 'struct ldb_val' the same as a DATA_BLOB, which will
simplify data handling in quite a few places (I haven't yet removed
all the code that maps between these two, that will come later)
(This used to be commit 87fc3073392236221a3a6b933284e9e477c24ae5)

source4/include/smb.h
source4/ldap_server/ldap_hacked_ldb.c
source4/ldap_server/ldap_rootdse.c
source4/ldap_server/ldap_simple_ldb.c
source4/lib/ldb/include/ldb.h
source4/libcli/cldap/cldap.c
source4/libcli/ldap/ldap.c
source4/libcli/ldap/ldap.h
source4/libcli/ldap/ldap_ldif.c

index ab1e11a02ddf8a7eb25162bd35111c6f639afd6d..5bc46d6a14edae216396d9bb6dd16f4481606b69 100644 (file)
@@ -192,6 +192,10 @@ typedef struct data_blob {
        size_t length;
 } DATA_BLOB;
 
+/* by making struct ldb_val and DATA_BLOB the same, we can simplify
+   a fair bit of code */
+#define ldb_val data_blob
+
 /* 64 bit time (100 nanosec) 1601 - cifs6.txt, section 3.5, page 30, 4 byte aligned */
 typedef uint64_t NTTIME;
 
index e00ed65f2987cd7ebc3a909f18e46ac736dc0c34..be252c738f8e8d769fbff3cadac2c84a7416c73d 100644 (file)
@@ -52,7 +52,7 @@
 
 static NTSTATUS convert_values(TALLOC_CTX *mem_ctx,
                               struct ldb_message_element *elem,
-                              struct ldap_attribute *attrs,
+                              struct ldb_message_element *attrs,
                               struct ldb_context *samdb,
                               const char **dn,
                               struct ldap_SearchRequest *r)
@@ -355,7 +355,7 @@ DEBUGADD(0,("hacked filter: %s\n", ldb_filter_from_tree(r, r->tree)));
                        goto queue_reply;
                }
                ent->num_attributes = res[0]->num_elements;
-               ent->attributes = talloc_array(ent_r, struct ldap_attribute, ent->num_attributes);
+               ent->attributes = talloc_array(ent_r, struct ldb_message_element, ent->num_attributes);
                NT_STATUS_HAVE_NO_MEMORY(ent->attributes);
                for (j=0; j < ent->num_attributes; j++) {
                        ent->attributes[j].name = talloc_steal(ent->attributes, res[0]->elements[j].name);
@@ -403,7 +403,7 @@ queue_reply:
                                goto queue_reply2;
                        }
                        ent->num_attributes = res[i]->num_elements;
-                       ent->attributes = talloc_array(ent_r, struct ldap_attribute, ent->num_attributes);
+                       ent->attributes = talloc_array(ent_r, struct ldb_message_element, ent->num_attributes);
                        NT_STATUS_HAVE_NO_MEMORY(ent->attributes);
                        for (j=0; j < ent->num_attributes; j++) {
                                ent->attributes[j].name = talloc_steal(ent->attributes, res[i]->elements[j].name);
@@ -553,7 +553,7 @@ static NTSTATUS hldb_Search(struct ldapsrv_partition *partition, struct ldapsrv_
                        goto queue_reply;
                }
                ent->num_attributes = res[i]->num_elements;
-               ent->attributes = talloc_array(ent_r, struct ldap_attribute, ent->num_attributes);
+               ent->attributes = talloc_array(ent_r, struct ldb_message_element, ent->num_attributes);
                NT_STATUS_HAVE_NO_MEMORY(ent->attributes);
                for (j=0; j < ent->num_attributes; j++) {
                        ent->attributes[j].name = talloc_steal(ent->attributes, res[i]->elements[j].name);
index a75460127977403d53067acb636f22664fb84203..1740a296374a41da8547fa5cfd2e5869d7dc502c 100644 (file)
@@ -112,7 +112,7 @@ static void *rootdse_db_connect(TALLOC_CTX *mem_ctx)
 }
 
 
-static NTSTATUS fill_dynamic_values(void *mem_ctx, struct ldap_attribute *attrs)
+static NTSTATUS fill_dynamic_values(void *mem_ctx, struct ldb_message_element *attrs)
 {
        /* 
         * currentTime
@@ -346,7 +346,7 @@ static NTSTATUS rootdse_Search(struct ldapsrv_partition *partition, struct ldaps
                        goto queue_reply;
                }
                ent->num_attributes = res[0]->num_elements;
-               ent->attributes = talloc_array(ent_r, struct ldap_attribute, ent->num_attributes);
+               ent->attributes = talloc_array(ent_r, struct ldb_message_element, ent->num_attributes);
                NT_STATUS_HAVE_NO_MEMORY(ent->attributes);
                for (j=0; j < ent->num_attributes; j++) {
                        ent->attributes[j].name = talloc_steal(ent->attributes, res[0]->elements[j].name);
index 1106919891e8f1270b41450da645e664561c1aa4..898b5fd82ac4b45870b1baca5e3ab3a39c384bce 100644 (file)
@@ -108,7 +108,7 @@ static NTSTATUS sldb_Search(struct ldapsrv_partition *partition, struct ldapsrv_
                        goto queue_reply;
                }
                ent->num_attributes = res[i]->num_elements;
-               ent->attributes = talloc_array(ent_r, struct ldap_attribute, ent->num_attributes);
+               ent->attributes = talloc_array(ent_r, struct ldb_message_element, ent->num_attributes);
                NT_STATUS_HAVE_NO_MEMORY(ent->attributes);
                for (j=0; j < ent->num_attributes; j++) {
                        ent->attributes[j].name = talloc_steal(ent->attributes, res[i]->elements[j].name);
index 7a28d05b3804af9231d33c63b5747165227b8208..4bf2f9581faa469dafc250adb4d9a92a23c73da7 100644 (file)
   sensible, but it can be to anything you like, including binary data
   blobs of arbitrary size.
 */
+#ifndef ldb_val
 struct ldb_val {
-       unsigned int length;
-       void *data;
+       uint8_t *data;
+       size_t length;
 };
+#endif
 
 /* these flags are used in ldd_message_element.flags fields. The
    LDA_FLAGS_MOD_* flags are used in ldap_modify() calls to specify
@@ -82,7 +84,7 @@ struct ldb_val {
 */
 struct ldb_message_element {
        unsigned int flags;
-       char *name;
+       const char *name;
        unsigned int num_values;
        struct ldb_val *values;
 };
index 1674031c9950a9dad14570974757d511142730ec..79cdff2437be90bde5018dfead427ad15ef1b6b2 100644 (file)
@@ -679,7 +679,7 @@ NTSTATUS cldap_netlogon_reply(struct cldap_socket *cldap,
 
        response.dn = "";
        response.num_attributes = 1;
-       response.attributes = talloc(tmp_ctx, struct ldap_attribute);
+       response.attributes = talloc(tmp_ctx, struct ldb_message_element);
        NT_STATUS_HAVE_NO_MEMORY(response.attributes);
        response.attributes->name = "netlogon";
        response.attributes->num_values = 1;
index 0ac17c39bd1ff8334275ae0278808502f60bf2e5..1a3ab6e0a5933663dbd1418aef6db04aa23c5eab 100644 (file)
@@ -201,7 +201,7 @@ BOOL ldap_encode(struct ldap_message *msg, DATA_BLOB *result)
                asn1_write_OctetString(&data, r->dn, strlen(r->dn));
                asn1_push_tag(&data, ASN1_SEQUENCE(0));
                for (i=0; i<r->num_attributes; i++) {
-                       struct ldap_attribute *attr = &r->attributes[i];
+                       struct ldb_message_element *attr = &r->attributes[i];
                        asn1_push_tag(&data, ASN1_SEQUENCE(0));
                        asn1_write_OctetString(&data, attr->name,
                                               strlen(attr->name));
@@ -232,7 +232,7 @@ BOOL ldap_encode(struct ldap_message *msg, DATA_BLOB *result)
                asn1_push_tag(&data, ASN1_SEQUENCE(0));
 
                for (i=0; i<r->num_mods; i++) {
-                       struct ldap_attribute *attrib = &r->mods[i].attrib;
+                       struct ldb_message_element *attrib = &r->mods[i].attrib;
                        asn1_push_tag(&data, ASN1_SEQUENCE(0));
                        asn1_write_enumerated(&data, r->mods[i].type);
                        asn1_push_tag(&data, ASN1_SEQUENCE(0));
@@ -268,7 +268,7 @@ BOOL ldap_encode(struct ldap_message *msg, DATA_BLOB *result)
                asn1_push_tag(&data, ASN1_SEQUENCE(0));
 
                for (i=0; i<r->num_attributes; i++) {
-                       struct ldap_attribute *attrib = &r->attributes[i];
+                       struct ldb_message_element *attrib = &r->attributes[i];
                        asn1_push_tag(&data, ASN1_SEQUENCE(0));
                        asn1_write_OctetString(&data, attrib->name,
                                               strlen(attrib->name));
@@ -596,7 +596,7 @@ failed:
 
 
 static void ldap_decode_attrib(TALLOC_CTX *mem_ctx, struct asn1_data *data,
-                              struct ldap_attribute *attrib)
+                              struct ldb_message_element *attrib)
 {
        asn1_start_tag(data, ASN1_SEQUENCE(0));
        asn1_read_OctetString_talloc(mem_ctx, data, &attrib->name);
@@ -616,12 +616,12 @@ 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 ldap_attribute **attributes,
+                               struct ldb_message_element **attributes,
                                int *num_attributes)
 {
        asn1_start_tag(data, ASN1_SEQUENCE(0));
        while (asn1_peek_tag(data, ASN1_SEQUENCE(0))) {
-               struct ldap_attribute attrib;
+               struct ldb_message_element attrib;
                ZERO_STRUCT(attrib);
                ldap_decode_attrib(mem_ctx, data, &attrib);
                add_attrib_to_array_talloc(mem_ctx, &attrib,
index f0f43e65fcf87c48ece9e7a3c206901127461a4c..577df1fc3d8d362f86cfeca78c97b3b5215171e8 100644 (file)
@@ -101,12 +101,6 @@ struct ldap_Result {
        const char *referral;
 };
 
-struct ldap_attribute {
-       const char *name;
-       int num_values;
-       DATA_BLOB *values;
-};
-
 struct ldap_BindRequest {
        int version;
        const char *dn;
@@ -159,7 +153,7 @@ struct ldap_SearchRequest {
 struct ldap_SearchResEntry {
        const char *dn;
        int num_attributes;
-       struct ldap_attribute *attributes;
+       struct ldb_message_element *attributes;
 };
 
 struct ldap_SearchResRef {
@@ -175,7 +169,7 @@ enum ldap_modify_type {
 
 struct ldap_mod {
        enum ldap_modify_type type;
-       struct ldap_attribute attrib;
+       struct ldb_message_element attrib;
 };
 
 struct ldap_ModifyRequest {
@@ -187,7 +181,7 @@ struct ldap_ModifyRequest {
 struct ldap_AddRequest {
        const char *dn;
        int num_attributes;
-       struct ldap_attribute *attributes;
+       struct ldb_message_element *attributes;
 };
 
 struct ldap_DelRequest {
@@ -338,10 +332,10 @@ NTSTATUS ldap2nterror(int ldaperror);
 /* The following definitions come from libcli/ldap/ldap_ldif.c  */
 
 BOOL add_value_to_attrib(TALLOC_CTX *mem_ctx, struct ldb_val *value,
-                        struct ldap_attribute *attrib);
+                        struct ldb_message_element *attrib);
 BOOL add_attrib_to_array_talloc(TALLOC_CTX *mem_ctx,
-                                      const struct ldap_attribute *attrib,
-                                      struct ldap_attribute **attribs,
+                                      const struct ldb_message_element *attrib,
+                                      struct ldb_message_element **attribs,
                                       int *num_attribs);
 BOOL add_mod_to_array_talloc(TALLOC_CTX *mem_ctx,
                                    struct ldap_mod *mod,
index 0e0885c1ccb26d98316bfb63b560ad4a1077dfef..594640179e0f264dcb9bbe84b01897122bf720b1 100644 (file)
@@ -158,7 +158,7 @@ static int next_attr(char **s, const char **attr, struct ldb_val *value)
 }
 
 BOOL add_value_to_attrib(TALLOC_CTX *mem_ctx, struct ldb_val *value,
-                        struct ldap_attribute *attrib)
+                        struct ldb_message_element *attrib)
 {
        attrib->values = talloc_realloc(mem_ctx, 
                                          attrib->values,
@@ -174,13 +174,13 @@ BOOL add_value_to_attrib(TALLOC_CTX *mem_ctx, struct ldb_val *value,
 }
 
 BOOL add_attrib_to_array_talloc(TALLOC_CTX *mem_ctx,
-                                      const struct ldap_attribute *attrib,
-                                      struct ldap_attribute **attribs,
+                                      const struct ldb_message_element *attrib,
+                                      struct ldb_message_element **attribs,
                                       int *num_attribs)
 {
        *attribs = talloc_realloc(mem_ctx,
                                    *attribs,
-                                   struct ldap_attribute,
+                                   struct ldb_message_element,
                                    *num_attribs+1);
 
        if (*attribs == NULL)
@@ -202,7 +202,7 @@ static BOOL fill_add_attributes(struct ldap_message *msg, char **chunk)
 
        while (next_attr(chunk, &attr_name, &value) == 0) {
                int i;
-               struct ldap_attribute *attrib = NULL;
+               struct ldb_message_element *attrib = NULL;
                
                for (i=0; i<r->num_attributes; i++) {
                        if (strequal(r->attributes[i].name, attr_name)) {
@@ -214,7 +214,7 @@ static BOOL fill_add_attributes(struct ldap_message *msg, char **chunk)
                if (attrib == NULL) {
                        r->attributes = talloc_realloc(msg,
                                                         r->attributes,
-                                                        struct ldap_attribute,
+                                                        struct ldb_message_element,
                                                         r->num_attributes+1);
                        if (r->attributes == NULL)
                                return False;