diff options
author | Simo Sorce <idra@samba.org> | 2006-10-25 02:06:05 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:15:39 -0500 |
commit | 151237477bef0d8fdcf926fa0fbe048580a58be5 (patch) | |
tree | a0e7ba5ef168739b4f1b191b65b19ad9d28d4275 /source3/lib/ldb/common/ldb_msg.c | |
parent | e6b56f9f0c601c740432c7040a737f679c131eb3 (diff) | |
download | samba-151237477bef0d8fdcf926fa0fbe048580a58be5.tar.gz samba-151237477bef0d8fdcf926fa0fbe048580a58be5.tar.bz2 samba-151237477bef0d8fdcf926fa0fbe048580a58be5.zip |
r19491: backport changes from samba4
(This used to be commit aa464c9fda978f615230241921f83884a60f4c6f)
Diffstat (limited to 'source3/lib/ldb/common/ldb_msg.c')
-rw-r--r-- | source3/lib/ldb/common/ldb_msg.c | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/source3/lib/ldb/common/ldb_msg.c b/source3/lib/ldb/common/ldb_msg.c index 0d9cb47882..46ab721e2e 100644 --- a/source3/lib/ldb/common/ldb_msg.c +++ b/source3/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,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; } } |