#include "includes.h"
#include "ldb/include/includes.h"
+void ldb_dump_results(struct ldb_context *ldb, struct ldb_result *result, FILE *f);
+int ldb_msg_element_compare_name(struct ldb_message_element *el1,
+ struct ldb_message_element *el2);
+
/*
create a new ldb_message in a given memory context (NULL for top level)
*/
/*
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;
msg->elements = els;
msg->num_elements++;
+ if (return_el) {
+ *return_el = &els[msg->num_elements-1];
+ }
+
return LDB_SUCCESS;
}
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;
}
*/
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);
el->values[el->num_values] = *val;
el->num_values++;
+ if (return_el) {
+ *return_el = el;
+ }
+
return LDB_SUCCESS;
}
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;
if (val.length == 0) {
/* allow empty strings as non-existant attributes */
- return 0;
+ return LDB_SUCCESS;
}
- return ldb_msg_add_value(msg, attr_name, &val);
+ return ldb_msg_add_value(msg, attr_name, &val, NULL);
}
/*
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;
}
}
ldb_set_errstring(ldb, "ldb message lacks a DN!");
return LDB_ERR_INVALID_DN_SYNTAX;
}
- if (msg->dn->comp_num == 0) {
- /* root dse has empty dn */
- ldb_set_errstring(ldb, "DN on new ldb message is '' (not permitted)!");
- return LDB_ERR_ENTRY_ALREADY_EXISTS;
- }
/* basic syntax checks */
for (i = 0; i < msg->num_elements; i++) {
/*
copy an attribute list. This only copies the array, not the elements
- (ie. the elements are left as the same pointers)
+ (ie. the elements are left as the same pointers). The new attribute is added to the list.
*/
const char **ldb_attr_list_copy_add(TALLOC_CTX *mem_ctx, const char * const *attrs, const char *new_attr)
{
}
}
+/*
+ remove the specified element in a search result
+*/
+void ldb_msg_remove_element(struct ldb_message *msg, struct ldb_message_element *el)
+{
+ int n = (el - msg->elements);
+ if (n != msg->num_elements-1) {
+ memmove(el, el+1, ((msg->num_elements-1) - n)*sizeof(*el));
+ }
+ msg->num_elements--;
+}
+
/*
return a LDAP formatted time string
*/