ldb_ldap: use ldb_msg API to add elements
[samba.git] / lib / ldb / ldb_ldap / ldb_ldap.c
index 484b810ac88acf5766c65617566a5ed9fa0e2453..d7222997732983833d5ff7276396df5e14ab47b4 100644 (file)
@@ -141,7 +141,7 @@ static int lldb_add_msg_attr(struct ldb_context *ldb,
                             struct ldb_message *msg, 
                             const char *attr, struct berval **bval)
 {
-       int count, i;
+       int count, i, ret;
        struct ldb_message_element *el;
 
        count = ldap_count_values_len(bval);
@@ -150,25 +150,12 @@ static int lldb_add_msg_attr(struct ldb_context *ldb,
                return -1;
        }
 
-       el = talloc_realloc(msg, msg->elements, struct ldb_message_element, 
-                             msg->num_elements + 1);
-       if (!el) {
-               errno = ENOMEM;
-               return -1;
-       }
-
-       msg->elements = el;
-
-       el = &msg->elements[msg->num_elements];
-
-       el->name = talloc_strdup(msg->elements, attr);
-       if (!el->name) {
+       ret = ldb_msg_add_empty(msg, attr, 0, &el);
+       if (ret != LDB_SUCCESS) {
                errno = ENOMEM;
                return -1;
        }
-       el->flags = 0;
 
-       el->num_values = 0;
        el->values = talloc_array(msg->elements, struct ldb_val, count);
        if (!el->values) {
                errno = ENOMEM;