summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/common
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib/ldb/common')
-rw-r--r--source4/lib/ldb/common/ldb.c8
-rw-r--r--source4/lib/ldb/common/ldb_dn.c308
-rw-r--r--source4/lib/ldb/common/ldb_ldif.c4
-rw-r--r--source4/lib/ldb/common/ldb_match.c60
-rw-r--r--source4/lib/ldb/common/ldb_modules.c17
-rw-r--r--source4/lib/ldb/common/ldb_msg.c19
6 files changed, 338 insertions, 78 deletions
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c
index 3a2eb13297..25e7bee66b 100644
--- a/source4/lib/ldb/common/ldb.c
+++ b/source4/lib/ldb/common/ldb.c
@@ -114,7 +114,7 @@ int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, co
*/
int ldb_search(struct ldb_context *ldb,
- const char *base,
+ const struct ldb_dn *base,
enum ldb_scope scope,
const char *expression,
const char * const *attrs, struct ldb_message ***res)
@@ -131,7 +131,7 @@ int ldb_search(struct ldb_context *ldb,
*/
int ldb_search_bytree(struct ldb_context *ldb,
- const char *base,
+ const struct ldb_dn *base,
enum ldb_scope scope,
struct ldb_parse_tree *tree,
const char * const *attrs, struct ldb_message ***res)
@@ -162,7 +162,7 @@ int ldb_modify(struct ldb_context *ldb,
/*
delete a record from the database
*/
-int ldb_delete(struct ldb_context *ldb, const char *dn)
+int ldb_delete(struct ldb_context *ldb, const struct ldb_dn *dn)
{
return ldb->modules->ops->delete_record(ldb->modules, dn);
}
@@ -170,7 +170,7 @@ int ldb_delete(struct ldb_context *ldb, const char *dn)
/*
rename a record in the database
*/
-int ldb_rename(struct ldb_context *ldb, const char *olddn, const char *newdn)
+int ldb_rename(struct ldb_context *ldb, const struct ldb_dn *olddn, const struct ldb_dn *newdn)
{
return ldb->modules->ops->rename_record(ldb->modules, olddn, newdn);
}
diff --git a/source4/lib/ldb/common/ldb_dn.c b/source4/lib/ldb/common/ldb_dn.c
index d13238cc17..dae79fd9e1 100644
--- a/source4/lib/ldb/common/ldb_dn.c
+++ b/source4/lib/ldb/common/ldb_dn.c
@@ -41,8 +41,26 @@
#define LDB_DN_NULL_FAILED(x) if (!(x)) goto failed
+#define LDB_SPECIAL "@SPECIAL"
+
+BOOL ldb_dn_is_special(const struct ldb_dn *dn)
+{
+ if (dn == NULL || dn->comp_num != 1) return 0;
+
+ return ! strcmp(dn->components[0].name, LDB_SPECIAL);
+}
+
+BOOL ldb_dn_check_special(const struct ldb_dn *dn, const char *check)
+{
+ if (dn == NULL || dn->comp_num != 1) return 0;
+
+ return ! strcmp(dn->components[0].value.data, check);
+}
+
static int ldb_dn_is_valid_attribute_name(const char *name)
{
+ if (name == NULL) return 0;
+
while (*name) {
if (! isascii(*name)) {
return 0;
@@ -165,6 +183,8 @@ static int get_quotes_position(const char *source, int *quote_start, int *quote_
{
const char *p;
+ if (source == NULL || quote_start == NULL || quote_end == NULL) return -1;
+
p = source;
/* check if there are quotes surrounding the value */
@@ -197,6 +217,8 @@ static char *seek_to_separator(char *string, const char *separators)
char *p;
int ret, qs, qe;
+ if (string == NULL || separators == NULL) return NULL;
+
p = strchr(string, '=');
LDB_DN_NULL_FAILED(p);
@@ -254,6 +276,11 @@ static struct ldb_dn_component ldb_dn_explode_component(void *mem_ctx, char *raw
char *p;
int ret, qs, qe;
+ if (raw_component == NULL) {
+ dc.name = NULL;
+ return dc;
+ }
+
/* find attribute type/value separator */
p = strchr(raw_component, '=');
LDB_DN_NULL_FAILED(p);
@@ -300,14 +327,10 @@ failed:
return dc;
}
-struct ldb_dn *ldb_dn_explode(void *mem_ctx, const char *dn)
+struct ldb_dn *ldb_dn_new(void *mem_ctx)
{
- struct ldb_dn *edn; /* the exploded dn */
- char *pdn, *p;
+ struct ldb_dn *edn;
- pdn = NULL;
-
- /* Allocate a structure to hold the exploded DN */
edn = talloc(mem_ctx, struct ldb_dn);
LDB_DN_NULL_FAILED(edn);
@@ -315,12 +338,33 @@ struct ldb_dn *ldb_dn_explode(void *mem_ctx, const char *dn)
edn->comp_num = 0;
edn->components = NULL;
+ return edn;
+
+failed:
+ return NULL;
+}
+
+struct ldb_dn *ldb_dn_explode(void *mem_ctx, const char *dn)
+{
+ struct ldb_dn *edn; /* the exploded dn */
+ char *pdn, *p;
+
+ if (dn == NULL) return NULL;
+
+ /* Allocate a structure to hold the exploded DN */
+ edn = ldb_dn_new(mem_ctx);
+
+ /* Empty DNs */
+ if (dn[0] == '\0') {
+ return edn;
+ }
+
/* Special DNs case */
if (dn[0] == '@') {
edn->comp_num = 1;
edn->components = talloc(edn, struct ldb_dn_component);
if (edn->components == NULL) goto failed;
- edn->components[0].name = talloc_strdup(edn->components, "@SPECIAL");
+ edn->components[0].name = talloc_strdup(edn->components, LDB_SPECIAL);
if (edn->components[0].name == NULL) goto failed;
edn->components[0].value.data = talloc_strdup(edn->components, dn);
if (edn->components[0].value.data== NULL) goto failed;
@@ -376,8 +420,10 @@ char *ldb_dn_linearize(void *mem_ctx, const struct ldb_dn *edn)
char *dn, *value;
int i;
+ if (edn == NULL) return NULL;
+
/* Special DNs */
- if ((edn->comp_num == 1) && strcmp("@SPECIAL", edn->components[0].name) == 0) {
+ if (ldb_dn_is_special(edn)) {
dn = talloc_strdup(mem_ctx, edn->components[0].value.data);
return dn;
}
@@ -419,6 +465,10 @@ int ldb_dn_compare_base(struct ldb_context *ldb,
return (dn->comp_num - base->comp_num);
}
+ if (base == NULL || base->comp_num == 0) return 0;
+ if (dn == NULL || dn->comp_num == 0) return -1;
+ if (base->comp_num > dn->comp_num) return -1;
+
/* if the number of components doesn't match they differ */
n0 = base->comp_num - 1;
n1 = dn->comp_num - 1;
@@ -450,6 +500,8 @@ int ldb_dn_compare(struct ldb_context *ldb,
const struct ldb_dn *edn0,
const struct ldb_dn *edn1)
{
+ if (edn0 == NULL || edn1 == NULL) return edn1 - edn0;
+
if (edn0->comp_num != edn1->comp_num)
return (edn1->comp_num - edn0->comp_num);
@@ -462,6 +514,8 @@ int ldb_dn_cmp(struct ldb_context *ldb, const char *dn0, const char *dn1)
struct ldb_dn *edn1;
int ret;
+ if (dn0 == NULL || dn1 == NULL) return dn1 - dn0;
+
edn0 = ldb_dn_explode_casefold(ldb, dn0);
if (edn0 == NULL) return 0;
@@ -488,7 +542,9 @@ struct ldb_dn *ldb_dn_casefold(struct ldb_context *ldb, const struct ldb_dn *edn
struct ldb_dn *cedn;
int i;
- cedn = talloc(ldb, struct ldb_dn);
+ if (edn == NULL) return NULL;
+
+ cedn = ldb_dn_new(ldb);
LDB_DN_NULL_FAILED(cedn);
cedn->comp_num = edn->comp_num;
@@ -521,6 +577,8 @@ struct ldb_dn *ldb_dn_explode_casefold(struct ldb_context *ldb, const char *dn)
{
struct ldb_dn *edn, *cdn;
+ if (dn == NULL) return NULL;
+
edn = ldb_dn_explode(ldb, dn);
if (edn == NULL) return NULL;
@@ -529,3 +587,235 @@ struct ldb_dn *ldb_dn_explode_casefold(struct ldb_context *ldb, const char *dn)
talloc_free(edn);
return cdn;
}
+
+char *ldb_dn_linearize_casefold(struct ldb_context *ldb, const struct ldb_dn *edn)
+{
+ struct ldb_dn *cdn;
+ char *dn;
+
+ if (edn == NULL) return NULL;
+
+ /* Special DNs */
+ if (ldb_dn_is_special(edn)) {
+ dn = talloc_strdup(ldb, edn->components[0].value.data);
+ return dn;
+ }
+
+ cdn = ldb_dn_casefold(ldb, edn);
+ if (cdn == NULL) return NULL;
+
+ dn = ldb_dn_linearize(ldb, cdn);
+ if (dn == NULL) {
+ talloc_free(cdn);
+ return NULL;
+ }
+
+ talloc_free(cdn);
+ return dn;
+}
+
+static struct ldb_dn_component ldb_dn_copy_component(void *mem_ctx, struct ldb_dn_component *src)
+{
+ struct ldb_dn_component dst;
+
+ dst.name = NULL;
+
+ if (src == NULL) {
+ return dst;
+ }
+
+ dst.value = ldb_val_dup(mem_ctx, &(src->value));
+ if (dst.value.data == NULL) {
+ return dst;
+ }
+
+ dst.name = talloc_strdup(mem_ctx, src->name);
+ if (dst.name == NULL) {
+ talloc_free(dst.value.data);
+ }
+
+ return dst;
+}
+
+/* copy specified number of elements of a dn into a new one
+ element are copied from top level up to the unique rdn
+ num_el may be greater then dn->comp_num (see ldb_dn_make_child)
+*/
+struct ldb_dn *ldb_dn_copy_partial(void *mem_ctx, const struct ldb_dn *dn, int num_el)
+{
+ struct ldb_dn *new;
+ int i, n, e;
+
+ if (dn == NULL) return NULL;
+ if (num_el <= 0) return NULL;
+
+ new = ldb_dn_new(mem_ctx);
+ LDB_DN_NULL_FAILED(new);
+
+ new->comp_num = num_el;
+ n = new->comp_num - 1;
+ new->components = talloc_array(new, struct ldb_dn_component, new->comp_num);
+
+ if (dn->comp_num == 0) return new;
+ e = dn->comp_num - 1;
+
+ for (i = 0; i < new->comp_num; i++) {
+ new->components[n - i] = ldb_dn_copy_component(new->components,
+ &(dn->components[e - i]));
+ if ((e - i) == 0) {
+ return new;
+ }
+ }
+
+ return new;
+
+failed:
+ talloc_free(new);
+ return NULL;
+}
+
+struct ldb_dn *ldb_dn_copy(void *mem_ctx, const struct ldb_dn *dn)
+{
+ if (dn == NULL) return NULL;
+ return ldb_dn_copy_partial(mem_ctx, dn, dn->comp_num);
+}
+
+struct ldb_dn *ldb_dn_get_parent(void *mem_ctx, const struct ldb_dn *dn)
+{
+ if (dn == NULL) return NULL;
+ return ldb_dn_copy_partial(mem_ctx, dn, dn->comp_num - 1);
+}
+
+struct ldb_dn_component *ldb_dn_build_component(void *mem_ctx, const char *attr,
+ const char *val)
+{
+ struct ldb_dn_component *dc;
+
+ if (attr == NULL || val == NULL) return NULL;
+
+ dc = talloc(mem_ctx, struct ldb_dn_component);
+ if (dc == NULL) return NULL;
+
+ dc->name = talloc_strdup(dc, attr);
+ if (dc->name == NULL) {
+ talloc_free(dc);
+ return NULL;
+ }
+
+ dc->value.data = talloc_strdup(dc, val);
+ if (dc->value.data == NULL) {
+ talloc_free(dc);
+ return NULL;
+ }
+
+ dc->value.length = strlen(val);
+
+ return dc;
+}
+
+struct ldb_dn *ldb_dn_build_child(void *mem_ctx, const char *attr,
+ const char * value,
+ const struct ldb_dn *base)
+{
+ struct ldb_dn *new;
+ if (! ldb_dn_is_valid_attribute_name(attr)) return NULL;
+ if (value == NULL || value == '\0') return NULL;
+
+ if (base != NULL) {
+ new = ldb_dn_copy_partial(mem_ctx, base, base->comp_num + 1);
+ LDB_DN_NULL_FAILED(new);
+ } else {
+ new = ldb_dn_new(mem_ctx);
+ LDB_DN_NULL_FAILED(new);
+
+ new->comp_num = 1;
+ new->components = talloc_array(new, struct ldb_dn_component, new->comp_num);
+ }
+
+ new->components[0].name = talloc_strdup(new->components, attr);
+ LDB_DN_NULL_FAILED(new->components[0].name);
+
+ new->components[0].value.data = talloc_strdup(new->components, value);
+ LDB_DN_NULL_FAILED(new->components[0].value.data);
+ new->components[0].value.length = strlen(new->components[0].value.data);
+
+ return new;
+
+failed:
+ talloc_free(new);
+ return NULL;
+
+}
+
+struct ldb_dn *ldb_dn_make_child(void *mem_ctx, const struct ldb_dn_component *component,
+ const struct ldb_dn *base)
+{
+ if (component == NULL) return NULL;
+
+ return ldb_dn_build_child(mem_ctx, component->name, component->value.data, base);
+}
+
+struct ldb_dn *ldb_dn_compose(void *mem_ctx, const struct ldb_dn *dn1, const struct ldb_dn *dn2)
+{
+ int i;
+ struct ldb_dn *new;
+
+ if (dn2 == NULL && dn1 == NULL) {
+ return NULL;
+ }
+
+ if (dn2 == NULL) {
+ new = ldb_dn_new(mem_ctx);
+ LDB_DN_NULL_FAILED(new);
+
+ new->comp_num = dn1->comp_num;
+ new->components = talloc_array(new, struct ldb_dn_component, new->comp_num);
+ } else {
+ new = ldb_dn_copy_partial(mem_ctx, dn2, dn2->comp_num + dn1?dn1->comp_num:0);
+ }
+
+ if (dn1 == NULL) {
+ return new;
+ }
+
+ for (i = 0; i < dn1->comp_num; i++) {
+ new->components[i] = ldb_dn_copy_component(new->components,
+ &(dn1->components[i]));
+ }
+
+ return new;
+
+failed:
+ talloc_free(new);
+ return NULL;
+}
+
+struct ldb_dn *ldb_dn_compose_string_dn(void *mem_ctx, const char *dn1, const struct ldb_dn *dn2)
+{
+ if (dn1 == NULL) return NULL;
+
+ return ldb_dn_compose(mem_ctx, ldb_dn_explode(mem_ctx, dn1), dn2);
+}
+
+struct ldb_dn_component *ldb_dn_get_rdn(void *mem_ctx, const struct ldb_dn *dn)
+{
+ struct ldb_dn_component *rdn;
+
+ if (dn == NULL) return NULL;
+
+ if (dn->comp_num < 1) {
+ return NULL;
+ }
+
+ rdn = talloc(mem_ctx, struct ldb_dn_component);
+ if (rdn == NULL) return NULL;
+
+ *rdn = ldb_dn_copy_component(mem_ctx, &dn->components[0]);
+ if (rdn->name == NULL) {
+ talloc_free(rdn);
+ return NULL;
+ }
+
+ return rdn;
+}
+
diff --git a/source4/lib/ldb/common/ldb_ldif.c b/source4/lib/ldb/common/ldb_ldif.c
index 463bae483b..6359c9a014 100644
--- a/source4/lib/ldb/common/ldb_ldif.c
+++ b/source4/lib/ldb/common/ldb_ldif.c
@@ -275,7 +275,7 @@ int ldb_ldif_write(struct ldb_context *ldb,
msg = ldif->msg;
- ret = fprintf_fn(private_data, "dn: %s\n", msg->dn);
+ ret = fprintf_fn(private_data, "dn: %s\n", ldb_dn_linearize(msg->dn, msg->dn));
CHECK_RET;
if (ldif->changetype != LDB_CHANGETYPE_NONE) {
@@ -587,7 +587,7 @@ struct ldb_ldif *ldb_ldif_read(struct ldb_context *ldb,
goto failed;
}
- msg->dn = value.data;
+ msg->dn = ldb_dn_explode(msg, value.data);
while (next_attr(ldif, &s, &attr, &value) == 0) {
const struct ldb_attrib_handler *h;
diff --git a/source4/lib/ldb/common/ldb_match.c b/source4/lib/ldb/common/ldb_match.c
index b6f5f5a18d..1269d99a0f 100644
--- a/source4/lib/ldb/common/ldb_match.c
+++ b/source4/lib/ldb/common/ldb_match.c
@@ -42,27 +42,16 @@
check if the scope matches in a search result
*/
static int ldb_match_scope(struct ldb_context *ldb,
- const char *base_str,
- const char *dn_str,
+ const struct ldb_dn *base,
+ const struct ldb_dn *dn,
enum ldb_scope scope)
{
- struct ldb_dn *base;
- struct ldb_dn *dn;
int ret = 0;
- if (base_str == NULL) {
+ if (base == NULL || dn == NULL) {
return 1;
}
- base = ldb_dn_explode_casefold(ldb, base_str);
- if (base == NULL) return 0;
-
- dn = ldb_dn_explode_casefold(ldb, dn_str);
- if (dn == NULL) {
- talloc_free(base);
- return 0;
- }
-
switch (scope) {
case LDB_SCOPE_BASE:
if (ldb_dn_compare(ldb, base, dn) == 0) {
@@ -86,8 +75,6 @@ static int ldb_match_scope(struct ldb_context *ldb,
break;
}
- talloc_free(base);
- talloc_free(dn);
return ret;
}
@@ -98,7 +85,6 @@ static int ldb_match_scope(struct ldb_context *ldb,
static int ldb_match_present(struct ldb_context *ldb,
struct ldb_message *msg,
struct ldb_parse_tree *tree,
- const char *base,
enum ldb_scope scope)
{
@@ -116,7 +102,6 @@ static int ldb_match_present(struct ldb_context *ldb,
static int ldb_match_comparison(struct ldb_context *ldb,
struct ldb_message *msg,
struct ldb_parse_tree *tree,
- const char *base,
enum ldb_scope scope,
enum ldb_parse_op comp_op)
{
@@ -158,29 +143,23 @@ static int ldb_match_comparison(struct ldb_context *ldb,
static int ldb_match_equality(struct ldb_context *ldb,
struct ldb_message *msg,
struct ldb_parse_tree *tree,
- const char *base,
enum ldb_scope scope)
{
unsigned int i;
struct ldb_message_element *el;
const struct ldb_attrib_handler *h;
- struct ldb_dn *msgdn, *valuedn;
+ struct ldb_dn *valuedn;
int ret;
if (ldb_attr_cmp(tree->u.equality.attr, "dn") == 0) {
- msgdn = ldb_dn_explode_casefold(ldb, msg->dn);
- if (msgdn == NULL) return 0;
-
valuedn = ldb_dn_explode_casefold(ldb, tree->u.equality.value.data);
if (valuedn == NULL) {
- talloc_free(msgdn);
return 0;
}
- ret = ldb_dn_compare(ldb, msgdn, valuedn);
+ ret = ldb_dn_compare(ldb, msg->dn, valuedn);
- talloc_free(msgdn);
talloc_free(valuedn);
if (ret == 0) return 1;
@@ -277,7 +256,6 @@ failed:
static int ldb_match_substring(struct ldb_context *ldb,
struct ldb_message *msg,
struct ldb_parse_tree *tree,
- const char *base,
enum ldb_scope scope)
{
unsigned int i;
@@ -327,7 +305,6 @@ static int ldb_comparator_or(struct ldb_val *v1, struct ldb_val *v2)
static int ldb_match_extended(struct ldb_context *ldb,
struct ldb_message *msg,
struct ldb_parse_tree *tree,
- const char *base,
enum ldb_scope scope)
{
int i;
@@ -391,7 +368,6 @@ static int ldb_match_extended(struct ldb_context *ldb,
static int ldb_match_message(struct ldb_context *ldb,
struct ldb_message *msg,
struct ldb_parse_tree *tree,
- const char *base,
enum ldb_scope scope)
{
unsigned int i;
@@ -400,43 +376,41 @@ static int ldb_match_message(struct ldb_context *ldb,
switch (tree->operation) {
case LDB_OP_AND:
for (i=0;i<tree->u.list.num_elements;i++) {
- v = ldb_match_message(ldb, msg, tree->u.list.elements[i],
- base, scope);
+ v = ldb_match_message(ldb, msg, tree->u.list.elements[i], scope);
if (!v) return 0;
}
return 1;
case LDB_OP_OR:
for (i=0;i<tree->u.list.num_elements;i++) {
- v = ldb_match_message(ldb, msg, tree->u.list.elements[i],
- base, scope);
+ v = ldb_match_message(ldb, msg, tree->u.list.elements[i], scope);
if (v) return 1;
}
return 0;
case LDB_OP_NOT:
- return ! ldb_match_message(ldb, msg, tree->u.isnot.child, base, scope);
+ return ! ldb_match_message(ldb, msg, tree->u.isnot.child, scope);
case LDB_OP_EQUALITY:
- return ldb_match_equality(ldb, msg, tree, base, scope);
+ return ldb_match_equality(ldb, msg, tree, scope);
case LDB_OP_SUBSTRING:
- return ldb_match_substring(ldb, msg, tree, base, scope);
+ return ldb_match_substring(ldb, msg, tree, scope);
case LDB_OP_GREATER:
- return ldb_match_comparison(ldb, msg, tree, base, scope, LDB_OP_GREATER);
+ return ldb_match_comparison(ldb, msg, tree, scope, LDB_OP_GREATER);
case LDB_OP_LESS:
- return ldb_match_comparison(ldb, msg, tree, base, scope, LDB_OP_LESS);
+ return ldb_match_comparison(ldb, msg, tree, scope, LDB_OP_LESS);
case LDB_OP_PRESENT:
- return ldb_match_present(ldb, msg, tree, base, scope);
+ return ldb_match_present(ldb, msg, tree, scope);
case LDB_OP_APPROX:
- return ldb_match_comparison(ldb, msg, tree, base, scope, LDB_OP_APPROX);
+ return ldb_match_comparison(ldb, msg, tree, scope, LDB_OP_APPROX);
case LDB_OP_EXTENDED:
- return ldb_match_extended(ldb, msg, tree, base, scope);
+ return ldb_match_extended(ldb, msg, tree, scope);
}
@@ -446,12 +420,12 @@ static int ldb_match_message(struct ldb_context *ldb,
int ldb_match_msg(struct ldb_context *ldb,
struct ldb_message *msg,
struct ldb_parse_tree *tree,
- const char *base,
+ const struct ldb_dn *base,
enum ldb_scope scope)
{
if ( ! ldb_match_scope(ldb, base, msg->dn, scope) ) {
return 0;
}
- return ldb_match_message(ldb, msg, tree, base, scope);
+ return ldb_match_message(ldb, msg, tree, scope);
}
diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c
index dcc384ffad..ab743d1b49 100644
--- a/source4/lib/ldb/common/ldb_modules.c
+++ b/source4/lib/ldb/common/ldb_modules.c
@@ -139,8 +139,15 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
int ret;
const char * const attrs[] = { "@LIST" , NULL};
struct ldb_message **msg = NULL;
+ struct ldb_dn *mods;
- ret = ldb_search(ldb, "@MODULES", LDB_SCOPE_BASE, "", attrs, &msg);
+ mods = ldb_dn_explode(ldb, "@MODULES");
+ if (mods == NULL) {
+ return -1;
+ }
+
+ ret = ldb_search(ldb, mods, LDB_SCOPE_BASE, "", attrs, &msg);
+ talloc_free(mods);
if (ret == 0 || (ret == 1 && msg[0]->num_elements == 0)) {
ldb_debug(ldb, LDB_DEBUG_TRACE, "no modules required by the db\n");
} else {
@@ -233,7 +240,7 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
*/
int ldb_next_search(struct ldb_module *module,
- const char *base,
+ const struct ldb_dn *base,
enum ldb_scope scope,
const char *expression,
const char * const *attrs, struct ldb_message ***res)
@@ -245,7 +252,7 @@ int ldb_next_search(struct ldb_module *module,
}
int ldb_next_search_bytree(struct ldb_module *module,
- const char *base,
+ const struct ldb_dn *base,
enum ldb_scope scope,
struct ldb_parse_tree *tree,
const char * const *attrs, struct ldb_message ***res)
@@ -272,7 +279,7 @@ int ldb_next_modify_record(struct ldb_module *module, const struct ldb_message *
return module->next->ops->modify_record(module->next, message);
}
-int ldb_next_delete_record(struct ldb_module *module, const char *dn)
+int ldb_next_delete_record(struct ldb_module *module, const struct ldb_dn *dn)
{
if (!module->next) {
return -1;
@@ -280,7 +287,7 @@ int ldb_next_delete_record(struct ldb_module *module, const char *dn)
return module->next->ops->delete_record(module->next, dn);
}
-int ldb_next_rename_record(struct ldb_module *module, const char *olddn, const char *newdn)
+int ldb_next_rename_record(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn)
{
if (!module->next) {
return -1;
diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c
index 295c74c90d..197c42ddb5 100644
--- a/source4/lib/ldb/common/ldb_msg.c
+++ b/source4/lib/ldb/common/ldb_msg.c
@@ -344,7 +344,6 @@ const char *ldb_msg_find_string(const struct ldb_message *msg,
return v->data;
}
-
/*
sort the elements of a message by name
*/
@@ -354,32 +353,23 @@ void ldb_msg_sort_elements(struct ldb_message *msg)
(comparison_fn_t)ldb_msg_element_compare_name);
}
-
-/*
- free a message created using ldb_msg_copy
-*/
-void ldb_msg_free(struct ldb_context *ldb, struct ldb_message *msg)
-{
- talloc_free(msg);
-}
-
/*
copy a message, allocating new memory for all parts
*/
-struct ldb_message *ldb_msg_copy(struct ldb_context *ldb,
+struct ldb_message *ldb_msg_copy(TALLOC_CTX *mem_ctx,
const struct ldb_message *msg)
{
struct ldb_message *msg2;
int i, j;
- msg2 = talloc(ldb, struct ldb_message);
+ msg2 = talloc(mem_ctx, struct ldb_message);
if (msg2 == NULL) return NULL;
msg2->elements = NULL;
msg2->num_elements = 0;
msg2->private_data = NULL;
- msg2->dn = talloc_strdup(msg2, msg->dn);
+ msg2->dn = ldb_dn_copy(msg2, msg->dn);
if (msg2->dn == NULL) goto failed;
msg2->elements = talloc_array(msg2, struct ldb_message_element, msg->num_elements);
@@ -396,12 +386,11 @@ struct ldb_message *ldb_msg_copy(struct ldb_context *ldb,
if (el2->name == NULL) goto failed;
el2->values = talloc_array(msg2->elements, struct ldb_val, el1->num_values);
for (j=0;j<el1->num_values;j++) {
- el2->values[j] = ldb_val_dup(ldb, &el1->values[j]);
+ el2->values[j] = ldb_val_dup(el2->values, &el1->values[j]);
if (el2->values[j].data == NULL &&
el1->values[j].length != 0) {
goto failed;
}
- el2->values[j].data = talloc_steal(el2->values, el2->values[j].data);
el2->num_values++;
}