r19491: backport changes from samba4
authorSimo Sorce <idra@samba.org>
Wed, 25 Oct 2006 02:06:05 +0000 (02:06 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:15:39 +0000 (12:15 -0500)
(This used to be commit aa464c9fda978f615230241921f83884a60f4c6f)

source3/lib/ldb/common/ldb_ldif.c
source3/lib/ldb/common/ldb_msg.c
source3/lib/ldb/include/ldb.h
source3/lib/ldb/modules/ldb_map.c
source3/lib/ldb/modules/ldb_map_inbound.c
source3/lib/ldb/modules/ldb_map_outbound.c
source3/lib/ldb/modules/objectclass.c
source3/lib/ldb/modules/rdn_name.c

index 4992eb01ad66d9b22b5fcea87ac2713ee1199e6a..135ce9eecd908c3fc13dcc866541c9b8fd26a329 100644 (file)
@@ -613,7 +613,7 @@ struct ldb_ldif *ldb_ldif_read(struct ldb_context *ldb,
                }
 
                if (empty) {
-                       if (ldb_msg_add_empty(msg, (char *)value.data, flags) != 0) {
+                       if (ldb_msg_add_empty(msg, (char *)value.data, flags, NULL) != 0) {
                                goto failed;
                        }
                        continue;
index 0d9cb47882bd60d79929e4a48b53b62440948ab5..46ab721e2e9d43274c2845cdc6db0e6615387019 100644 (file)
@@ -119,7 +119,10 @@ struct ldb_val ldb_val_dup(void *mem_ctx, const struct ldb_val *v)
 /*
   add an empty element to a message
 */
-int ldb_msg_add_empty(struct ldb_message *msg, const char *attr_name, int flags)
+int ldb_msg_add_empty(struct ldb_message *msg,
+                     const char *attr_name,
+                     int flags,
+                     struct ldb_message_element **return_el)
 {
        struct ldb_message_element *els;
 
@@ -146,6 +149,10 @@ int ldb_msg_add_empty(struct ldb_message *msg, const char *attr_name, int flags)
        msg->elements = els;
        msg->num_elements++;
 
+       if (return_el) {
+               *return_el = &els[msg->num_elements-1];
+       }
+
        return LDB_SUCCESS;
 }
 
@@ -156,7 +163,7 @@ int ldb_msg_add(struct ldb_message *msg,
                const struct ldb_message_element *el, 
                int flags)
 {
-       if (ldb_msg_add_empty(msg, el->name, flags) != 0) {
+       if (ldb_msg_add_empty(msg, el->name, flags, NULL) != 0) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
@@ -171,18 +178,19 @@ int ldb_msg_add(struct ldb_message *msg,
 */
 int ldb_msg_add_value(struct ldb_message *msg, 
                      const char *attr_name,
-                     const struct ldb_val *val)
+                     const struct ldb_val *val,
+                     struct ldb_message_element **return_el)
 {
        struct ldb_message_element *el;
        struct ldb_val *vals;
+       int ret;
 
        el = ldb_msg_find_element(msg, attr_name);
        if (!el) {
-               ldb_msg_add_empty(msg, attr_name, 0);
-               el = ldb_msg_find_element(msg, attr_name);
-       }
-       if (!el) {
-               return LDB_ERR_OPERATIONS_ERROR;
+               ret = ldb_msg_add_empty(msg, attr_name, 0, &el);
+               if (ret != LDB_SUCCESS) {
+                       return ret;
+               }
        }
 
        vals = talloc_realloc(msg, el->values, struct ldb_val, el->num_values+1);
@@ -194,6 +202,10 @@ int ldb_msg_add_value(struct ldb_message *msg,
        el->values[el->num_values] = *val;
        el->num_values++;
 
+       if (return_el) {
+               *return_el = el;
+       }
+
        return LDB_SUCCESS;
 }
 
@@ -206,12 +218,10 @@ int ldb_msg_add_steal_value(struct ldb_message *msg,
                            struct ldb_val *val)
 {
        int ret;
-       ret = ldb_msg_add_value(msg, attr_name, val);
+       struct ldb_message_element *el;
+
+       ret = ldb_msg_add_value(msg, attr_name, val, &el);
        if (ret == LDB_SUCCESS) {
-               struct ldb_message_element *el;
-               if (!(el = ldb_msg_find_element(msg, attr_name))) {
-                       return LDB_ERR_OPERATIONS_ERROR;
-               }
                talloc_steal(el->values, val->data);
        }
        return ret;
@@ -234,7 +244,7 @@ int ldb_msg_add_string(struct ldb_message *msg,
                return LDB_SUCCESS;
        }
 
-       return ldb_msg_add_value(msg, attr_name, &val);
+       return ldb_msg_add_value(msg, attr_name, &val, NULL);
 }
 
 /*
@@ -578,7 +588,7 @@ struct ldb_message *ldb_msg_diff(struct ldb_context *ldb,
                if (!el) {
                        if (ldb_msg_add_empty(mod, 
                                              msg1->elements[i].name,
-                                             LDB_FLAG_MOD_DELETE) != 0) {
+                                             LDB_FLAG_MOD_DELETE, NULL) != 0) {
                                return NULL;
                        }
                }
index 0af734eb13d80d3ed5411fa1d348305744b0baa1..2c332b2f9d4dff0fca6528e0352e35f4aa04535a 100644 (file)
@@ -1227,7 +1227,10 @@ struct ldb_val *ldb_msg_find_val(const struct ldb_message_element *el,
 /**
    add a new empty element to a ldb_message
 */
-int ldb_msg_add_empty(struct ldb_message *msg, const char *attr_name, int flags);
+int ldb_msg_add_empty(struct ldb_message *msg,
+                     const char *attr_name,
+                     int flags,
+                     struct ldb_message_element **return_el);
 
 /**
    add a element to a ldb_message
@@ -1237,7 +1240,8 @@ int ldb_msg_add(struct ldb_message *msg,
                int flags);
 int ldb_msg_add_value(struct ldb_message *msg, 
                      const char *attr_name,
-                     const struct ldb_val *val);
+                     const struct ldb_val *val,
+                     struct ldb_message_element **return_el);
 int ldb_msg_add_steal_value(struct ldb_message *msg, 
                      const char *attr_name,
                      struct ldb_val *val);
index f9ae66a2aa5b0d1ada01ea8f041156bcdea5919c..1cdeeeb2934729ea41c34a1066f2ff0195ad11d6 100644 (file)
@@ -964,7 +964,7 @@ struct ldb_request *map_build_fixup_req(struct map_context *ac, const struct ldb
        if (dn == NULL) {
                goto failed;
        }
-       if (ldb_msg_add_empty(msg, IS_MAPPED, LDB_FLAG_MOD_REPLACE) != 0) {
+       if (ldb_msg_add_empty(msg, IS_MAPPED, LDB_FLAG_MOD_REPLACE, NULL) != 0) {
                goto failed;
        }
        if (ldb_msg_add_string(msg, IS_MAPPED, dn) != 0) {
index 404b2ce528baf1f8f27308da4f2063c54bd7e257..b83a17e502c41a641247ad9d76ae9d285c0882f7 100644 (file)
@@ -345,7 +345,7 @@ int map_modify_do_local(struct ldb_handle *handle)
                /* Add local 'IS_MAPPED' */
                /* TODO: use GUIDs here instead */
                dn = ldb_dn_linearize(msg, ac->remote_req->op.mod.message->dn);
-               if (ldb_msg_add_empty(msg, IS_MAPPED, LDB_FLAG_MOD_ADD) != 0) {
+               if (ldb_msg_add_empty(msg, IS_MAPPED, LDB_FLAG_MOD_ADD, NULL) != 0) {
                        return LDB_ERR_OPERATIONS_ERROR;
                }
                if (ldb_msg_add_string(msg, IS_MAPPED, dn) != 0) {
index cd33f2904363714277c32666f2f567a61c6f8b8e..ff3b5c3aa2b26c2aa778a3f805d6e0851e88f50c 100644 (file)
@@ -192,12 +192,7 @@ static int ldb_msg_replace(struct ldb_message *msg, const struct ldb_message_ele
 
        /* no local result, add as new element */
        if (old == NULL) {
-               if (ldb_msg_add_empty(msg, el->name, 0) != 0) {
-                       return -1;
-               }
-
-               old = ldb_msg_find_element(msg, el->name);
-               if (old == NULL) {
+               if (ldb_msg_add_empty(msg, el->name, 0, &old) != 0) {
                        return -1;
                }
        }
index e4040a8e3d18d765dbef173c2fea020e5ea60979..191238f9c95ca61388a5d6e1cdcb930d9cc3438c 100644 (file)
@@ -250,7 +250,7 @@ static int objectclass_add(struct ldb_module *module, struct ldb_request *req)
        }
 
        ldb_msg_remove_attr(msg, "objectClass");
-       ret = ldb_msg_add_empty(msg, "objectClass", 0);
+       ret = ldb_msg_add_empty(msg, "objectClass", 0, NULL);
        
        if (ret != LDB_SUCCESS) {
                talloc_free(mem_ctx);
@@ -351,7 +351,7 @@ static int objectclass_modify(struct ldb_module *module, struct ldb_request *req
                 * because we need it sorted */
                
                ldb_msg_remove_attr(msg, "objectClass");
-               ret = ldb_msg_add_empty(msg, "objectClass", LDB_FLAG_MOD_REPLACE);
+               ret = ldb_msg_add_empty(msg, "objectClass", LDB_FLAG_MOD_REPLACE, NULL);
                
                if (ret != LDB_SUCCESS) {
                        talloc_free(mem_ctx);
@@ -537,7 +537,7 @@ static int objectclass_do_mod(struct ldb_handle *h) {
         * We could do a constrained add/del, but we are meant to be
         * in a transaction... */
 
-       ret = ldb_msg_add_empty(msg, "objectClass", LDB_FLAG_MOD_REPLACE);
+       ret = ldb_msg_add_empty(msg, "objectClass", LDB_FLAG_MOD_REPLACE, NULL);
        if (ret != LDB_SUCCESS) {
                ldb_set_errstring(ac->module->ldb, "objectclass: could not clear objectclass in modify msg");
                talloc_free(mem_ctx);
index fce1d34ac0d139f13b32a6858d89ef10824c235c..510a43dbc941cc6635da081b0687ed4090157de8 100644 (file)
@@ -91,7 +91,7 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req)
                attribute->num_values = 0;
        }
 
-       if (ldb_msg_add_value(msg, "name", &rdn->value) != 0) {
+       if (ldb_msg_add_value(msg, "name", &rdn->value, NULL) != 0) {
                talloc_free(down_req);
                return LDB_ERR_OPERATIONS_ERROR;
        }
@@ -99,7 +99,7 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req)
        attribute = rdn_name_find_attribute(msg, rdn->name);
 
        if (!attribute) {
-               if (ldb_msg_add_value(msg, rdn->name, &rdn->value) != 0) {
+               if (ldb_msg_add_value(msg, rdn->name, &rdn->value, NULL) != 0) {
                        talloc_free(down_req);
                        return LDB_ERR_OPERATIONS_ERROR;
                }
@@ -213,16 +213,16 @@ static int rdn_name_rename_do_mod(struct ldb_handle *h) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       if (ldb_msg_add_empty(msg, rdn->name, LDB_FLAG_MOD_REPLACE) != 0) {
+       if (ldb_msg_add_empty(msg, rdn->name, LDB_FLAG_MOD_REPLACE, NULL) != 0) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
-       if (ldb_msg_add_value(msg, rdn->name, &rdn->value) != 0) {
+       if (ldb_msg_add_value(msg, rdn->name, &rdn->value, NULL) != 0) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
-       if (ldb_msg_add_empty(msg, "name", LDB_FLAG_MOD_REPLACE) != 0) {
+       if (ldb_msg_add_empty(msg, "name", LDB_FLAG_MOD_REPLACE, NULL) != 0) {
                return LDB_ERR_OPERATIONS_ERROR;
        }
-       if (ldb_msg_add_value(msg, "name", &rdn->value) != 0) {
+       if (ldb_msg_add_value(msg, "name", &rdn->value, NULL) != 0) {
                return LDB_ERR_OPERATIONS_ERROR;
        }