diff options
Diffstat (limited to 'source4/lib/ldb')
-rw-r--r-- | source4/lib/ldb/common/ldb_msg.c | 32 | ||||
-rw-r--r-- | source4/lib/ldb/include/ldb.h | 5 | ||||
-rw-r--r-- | source4/lib/ldb/modules/operational.c | 2 |
3 files changed, 38 insertions, 1 deletions
diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c index 497d2cb0d5..8c59518296 100644 --- a/source4/lib/ldb/common/ldb_msg.c +++ b/source4/lib/ldb/common/ldb_msg.c @@ -199,6 +199,24 @@ int ldb_msg_add_value(struct ldb_message *msg, /* + add a value to a message, stealing it into the 'right' place +*/ +int ldb_msg_add_steal_value(struct ldb_message *msg, + const char *attr_name, + struct ldb_val *val) +{ + int ret; + ret = ldb_msg_add_value(msg, attr_name, val); + 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; +} + + +/* add a string element to a message */ int ldb_msg_add_string(struct ldb_message *msg, @@ -213,6 +231,20 @@ int ldb_msg_add_string(struct ldb_message *msg, } /* + add a string element to a message, stealing it into the 'right' place +*/ +int ldb_msg_add_steal_string(struct ldb_message *msg, + const char *attr_name, char *str) +{ + struct ldb_val val; + + val.data = (uint8_t *)str; + val.length = strlen(str); + + return ldb_msg_add_steal_value(msg, attr_name, &val); +} + +/* add a printf formatted element to a message */ int ldb_msg_add_fmt(struct ldb_message *msg, diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h index 8a9e8bea76..488f782c9b 100644 --- a/source4/lib/ldb/include/ldb.h +++ b/source4/lib/ldb/include/ldb.h @@ -1098,6 +1098,11 @@ 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); +int ldb_msg_add_steal_value(struct ldb_message *msg, + const char *attr_name, + struct ldb_val *val); +int ldb_msg_add_steal_string(struct ldb_message *msg, + const char *attr_name, char *str); int ldb_msg_add_string(struct ldb_message *msg, const char *attr_name, const char *str); int ldb_msg_add_fmt(struct ldb_message *msg, diff --git a/source4/lib/ldb/modules/operational.c b/source4/lib/ldb/modules/operational.c index 3deb9422f3..8b7d6b3518 100644 --- a/source4/lib/ldb/modules/operational.c +++ b/source4/lib/ldb/modules/operational.c @@ -86,7 +86,7 @@ static int construct_canonical_name(struct ldb_module *module, struct ldb_messag if (canonicalName == NULL) { return -1; } - return ldb_msg_add_string(msg, "canonicalName", canonicalName); + return ldb_msg_add_steal_string(msg, "canonicalName", canonicalName); } /* |