diff options
author | Simo Sorce <idra@samba.org> | 2006-10-25 01:42:59 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:24:38 -0500 |
commit | 7f833458ca0083654e34cbfde1c6c6510cab1826 (patch) | |
tree | 0e2d7a740b8c29896ed7ee5635d2520b9913945e /source4/lib/ldb | |
parent | 3cee746a3f23f1040daa60d1208145bff87b3d01 (diff) | |
download | samba-7f833458ca0083654e34cbfde1c6c6510cab1826.tar.gz samba-7f833458ca0083654e34cbfde1c6c6510cab1826.tar.bz2 samba-7f833458ca0083654e34cbfde1c6c6510cab1826.zip |
r19489: Change ldb_msg_add_value and ldb_msg_add_empty to take a foruth argument.
This is a pointer to an element pointer. If it is not null it will be
filled with the pointer of the manipulated element.
Will avoid double searches on the elements list in some cases.
(This used to be commit 0fa5d4bc225b83e9f63ac6d75bffc4c08eb6b620)
Diffstat (limited to 'source4/lib/ldb')
-rw-r--r-- | source4/lib/ldb/common/ldb_ldif.c | 2 | ||||
-rw-r--r-- | source4/lib/ldb/common/ldb_msg.c | 31 | ||||
-rw-r--r-- | source4/lib/ldb/include/ldb.h | 10 | ||||
-rw-r--r-- | source4/lib/ldb/modules/ldb_map.c | 2 | ||||
-rw-r--r-- | source4/lib/ldb/modules/ldb_map_inbound.c | 2 | ||||
-rw-r--r-- | source4/lib/ldb/modules/ldb_map_outbound.c | 7 | ||||
-rw-r--r-- | source4/lib/ldb/modules/objectclass.c | 6 | ||||
-rw-r--r-- | source4/lib/ldb/modules/rdn_name.c | 12 | ||||
-rwxr-xr-x | source4/lib/ldb/standalone.sh | 2 |
9 files changed, 42 insertions, 32 deletions
diff --git a/source4/lib/ldb/common/ldb_ldif.c b/source4/lib/ldb/common/ldb_ldif.c index 4992eb01ad..135ce9eecd 100644 --- a/source4/lib/ldb/common/ldb_ldif.c +++ b/source4/lib/ldb/common/ldb_ldif.c @@ -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; diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c index 7e001f9180..da8ab4994f 100644 --- a/source4/lib/ldb/common/ldb_msg.c +++ b/source4/lib/ldb/common/ldb_msg.c @@ -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,15 +178,15 @@ 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; 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); + ldb_msg_add_empty(msg, attr_name, 0, &el); } if (!el) { return LDB_ERR_OPERATIONS_ERROR; @@ -194,6 +201,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,10 +217,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; - el = ldb_msg_find_element(msg, attr_name); talloc_steal(el->values, val->data); } return ret; @@ -232,7 +243,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); } /* @@ -576,7 +587,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; } } diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h index 62e8039a2c..aa8b9447b2 100644 --- a/source4/lib/ldb/include/ldb.h +++ b/source4/lib/ldb/include/ldb.h @@ -1366,7 +1366,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 @@ -1375,8 +1378,9 @@ int ldb_msg_add(struct ldb_message *msg, const struct ldb_message_element *el, int flags); int ldb_msg_add_value(struct ldb_message *msg, - const char *attr_name, - const struct ldb_val *val); + const char *attr_name, + 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); diff --git a/source4/lib/ldb/modules/ldb_map.c b/source4/lib/ldb/modules/ldb_map.c index f9ae66a2aa..1cdeeeb293 100644 --- a/source4/lib/ldb/modules/ldb_map.c +++ b/source4/lib/ldb/modules/ldb_map.c @@ -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) { diff --git a/source4/lib/ldb/modules/ldb_map_inbound.c b/source4/lib/ldb/modules/ldb_map_inbound.c index 404b2ce528..b83a17e502 100644 --- a/source4/lib/ldb/modules/ldb_map_inbound.c +++ b/source4/lib/ldb/modules/ldb_map_inbound.c @@ -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) { diff --git a/source4/lib/ldb/modules/ldb_map_outbound.c b/source4/lib/ldb/modules/ldb_map_outbound.c index cd33f29043..ff3b5c3aa2 100644 --- a/source4/lib/ldb/modules/ldb_map_outbound.c +++ b/source4/lib/ldb/modules/ldb_map_outbound.c @@ -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; } } diff --git a/source4/lib/ldb/modules/objectclass.c b/source4/lib/ldb/modules/objectclass.c index e4040a8e3d..191238f9c9 100644 --- a/source4/lib/ldb/modules/objectclass.c +++ b/source4/lib/ldb/modules/objectclass.c @@ -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); diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index fce1d34ac0..510a43dbc9 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -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; } diff --git a/source4/lib/ldb/standalone.sh b/source4/lib/ldb/standalone.sh index 5987380880..fa1b9bafe3 100755 --- a/source4/lib/ldb/standalone.sh +++ b/source4/lib/ldb/standalone.sh @@ -18,7 +18,7 @@ rm -fr build mkdir build cd build -../configure +../configure $* make dirs make all |