summaryrefslogtreecommitdiff
path: root/source4/lib/ldb
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2005-08-18 16:18:48 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:33:33 -0500
commitac90ddfdb28050912ecab0e998089b93216c5c35 (patch)
treecb37f9654b81ec3575466689cd130dd8c92b48fd /source4/lib/ldb
parent3e4c4cff2177af33efdb15f03a1bbcb639505cee (diff)
downloadsamba-ac90ddfdb28050912ecab0e998089b93216c5c35.tar.gz
samba-ac90ddfdb28050912ecab0e998089b93216c5c35.tar.bz2
samba-ac90ddfdb28050912ecab0e998089b93216c5c35.zip
r9392: Fix ldb_dn_compose to make build farm happy
Add ldb_dn_string_compose so that you can build a dn starting from a struct ldb_dn base and a set of parameters to be composed in a format string with the same syntax of printf (This used to be commit 31c69d0655752cc8ea3bc5b7ea87792291302091)
Diffstat (limited to 'source4/lib/ldb')
-rw-r--r--source4/lib/ldb/common/ldb_dn.c25
-rw-r--r--source4/lib/ldb/include/ldb.h2
2 files changed, 22 insertions, 5 deletions
diff --git a/source4/lib/ldb/common/ldb_dn.c b/source4/lib/ldb/common/ldb_dn.c
index dae79fd9e1..df95e37dac 100644
--- a/source4/lib/ldb/common/ldb_dn.c
+++ b/source4/lib/ldb/common/ldb_dn.c
@@ -771,7 +771,9 @@ struct ldb_dn *ldb_dn_compose(void *mem_ctx, const struct ldb_dn *dn1, const str
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);
+ int comp_num = dn2->comp_num;
+ if (dn1 != NULL) comp_num += dn1->comp_num;
+ new = ldb_dn_copy_partial(mem_ctx, dn2, comp_num);
}
if (dn1 == NULL) {
@@ -790,11 +792,26 @@ failed:
return NULL;
}
-struct ldb_dn *ldb_dn_compose_string_dn(void *mem_ctx, const char *dn1, const struct ldb_dn *dn2)
+struct ldb_dn *ldb_dn_string_compose(void *mem_ctx, const struct ldb_dn *base, const char *child_fmt, ...)
{
- if (dn1 == NULL) return NULL;
+ struct ldb_dn *dn;
+ char *child_str;
+ va_list ap;
+ int ret;
+
+ if (child_fmt == NULL) return NULL;
+
+ va_start(ap, child_fmt);
+ ret = vasprintf(&child_str, child_fmt, ap);
+ va_end(ap);
+
+ if (ret <= 0) return NULL;
- return ldb_dn_compose(mem_ctx, ldb_dn_explode(mem_ctx, dn1), dn2);
+ dn = ldb_dn_compose(mem_ctx, ldb_dn_explode(mem_ctx, child_str), base);
+
+ free(child_str);
+
+ return dn;
}
struct ldb_dn_component *ldb_dn_get_rdn(void *mem_ctx, const struct ldb_dn *dn)
diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h
index 13c9b72e6d..e7862522e4 100644
--- a/source4/lib/ldb/include/ldb.h
+++ b/source4/lib/ldb/include/ldb.h
@@ -371,7 +371,7 @@ struct ldb_dn *ldb_dn_make_child(void *mem_ctx,
const struct ldb_dn_component *component,
const struct ldb_dn *base);
struct ldb_dn *ldb_dn_compose(void *mem_ctx, const struct ldb_dn *dn1, const struct ldb_dn *dn2);
-struct ldb_dn *ldb_dn_compose_string_dn(void *mem_ctx, const char *dn1, const struct ldb_dn *dn2);
+struct ldb_dn *ldb_dn_string_compose(void *mem_ctx, const struct ldb_dn *base, const char *child_fmt, ...);
struct ldb_dn_component *ldb_dn_get_rdn(void *mem_ctx, const struct ldb_dn *dn);
/* useful functions for ldb_message structure manipulation */