From 52cc7a55018c0a8243e4b7e35206bd9d3616abd8 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 13 Oct 2005 07:47:57 +0000 Subject: r10956: Tridge thought some comments might be a good idea :-) Andrew Bartlett (This used to be commit c0d6126effdf31e0a107c06a400973c731e0e263) --- source4/lib/ldb/common/ldb_dn.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'source4') diff --git a/source4/lib/ldb/common/ldb_dn.c b/source4/lib/ldb/common/ldb_dn.c index abe8985f9d..5895432431 100644 --- a/source4/lib/ldb/common/ldb_dn.c +++ b/source4/lib/ldb/common/ldb_dn.c @@ -839,9 +839,19 @@ struct ldb_dn_component *ldb_dn_get_rdn(void *mem_ctx, const struct ldb_dn *dn) return rdn; } +/* Create a 'canonical name' string from a DN: + + ie dc=samba,dc=org -> samba.org/ + uid=administrator,ou=users,dc=samba,dc=org = samba.org/users/administrator + + There are two formats, the EX format has the last / replaced with a newline (\n). + +*/ static char *ldb_dn_canonical(void *mem_ctx, const struct ldb_dn *dn, int ex_format) { int i; char *cracked = NULL; + + /* Walk backwards down the DN, grabbing 'dc' components at first */ for (i = dn->comp_num - 1 ; i >= 0; i--) { if (strcasecmp(dn->components[i].name, "dc") != 0) { break; @@ -857,7 +867,7 @@ static char *ldb_dn_canonical(void *mem_ctx, const struct ldb_dn *dn, int ex_for } } - /* Only domain components */ + /* Only domain components? Finish here */ if (i < 0) { if (ex_format) { cracked = talloc_asprintf(mem_ctx, "%s\n", cracked); @@ -867,6 +877,7 @@ static char *ldb_dn_canonical(void *mem_ctx, const struct ldb_dn *dn, int ex_for return cracked; } + /* Now walk backwards appending remaining components */ for (; i > 0; i--) { cracked = talloc_asprintf(mem_ctx, "%s/%s", cracked, dn->components[i].value.data); @@ -875,7 +886,7 @@ static char *ldb_dn_canonical(void *mem_ctx, const struct ldb_dn *dn, int ex_for } } - /* Last one */ + /* Last one, possibly a newline for the 'ex' format */ if (ex_format) { cracked = talloc_asprintf(mem_ctx, "%s\n%s", cracked, dn->components[i].value.data); @@ -886,6 +897,7 @@ static char *ldb_dn_canonical(void *mem_ctx, const struct ldb_dn *dn, int ex_for return cracked; } +/* Wrapper functions for the above, for the two different string formats */ char *ldb_dn_canonical_string(void *mem_ctx, const struct ldb_dn *dn) { return ldb_dn_canonical(mem_ctx, dn, 0); -- cgit