summaryrefslogtreecommitdiff
path: root/source4/lib/ldb
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2005-10-13 04:24:49 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:39:45 -0500
commitd96f706bb0a6b41eddec9d467ef3d5f31bee41ab (patch)
tree1f692464945004d30cf746b864fad54e88103b20 /source4/lib/ldb
parent4c188e0a1e55ead361a4236bd8d02e198e9296a0 (diff)
downloadsamba-d96f706bb0a6b41eddec9d467ef3d5f31bee41ab.tar.gz
samba-d96f706bb0a6b41eddec9d467ef3d5f31bee41ab.tar.bz2
samba-d96f706bb0a6b41eddec9d467ef3d5f31bee41ab.zip
r10953: Add a new function to form a canonicalName out of a DN to ldb_dn.c
Use this new function in the client and server for the CrackNames case, where we particularly need it. Andrew Bartlett (This used to be commit 380037ee09ef8293bdb288d6c015e7c80f180a30)
Diffstat (limited to 'source4/lib/ldb')
-rw-r--r--source4/lib/ldb/common/ldb_dn.c55
-rw-r--r--source4/lib/ldb/include/ldb.h2
2 files changed, 57 insertions, 0 deletions
diff --git a/source4/lib/ldb/common/ldb_dn.c b/source4/lib/ldb/common/ldb_dn.c
index b497de142b..abe8985f9d 100644
--- a/source4/lib/ldb/common/ldb_dn.c
+++ b/source4/lib/ldb/common/ldb_dn.c
@@ -839,3 +839,58 @@ struct ldb_dn_component *ldb_dn_get_rdn(void *mem_ctx, const struct ldb_dn *dn)
return rdn;
}
+static char *ldb_dn_canonical(void *mem_ctx, const struct ldb_dn *dn, int ex_format) {
+ int i;
+ char *cracked = NULL;
+ for (i = dn->comp_num - 1 ; i >= 0; i--) {
+ if (strcasecmp(dn->components[i].name, "dc") != 0) {
+ break;
+ }
+ if (cracked) {
+ cracked = talloc_asprintf(mem_ctx, "%s.%s", dn->components[i].value.data,
+ cracked);
+ } else {
+ cracked = talloc_strdup(mem_ctx, dn->components[i].value.data);
+ }
+ if (!cracked) {
+ return NULL;
+ }
+ }
+
+ /* Only domain components */
+ if (i < 0) {
+ if (ex_format) {
+ cracked = talloc_asprintf(mem_ctx, "%s\n", cracked);
+ } else {
+ cracked = talloc_asprintf(mem_ctx, "%s/", cracked);
+ }
+ return cracked;
+ }
+
+ for (; i > 0; i--) {
+ cracked = talloc_asprintf(mem_ctx, "%s/%s", cracked,
+ dn->components[i].value.data);
+ if (!cracked) {
+ return NULL;
+ }
+ }
+
+ /* Last one */
+ if (ex_format) {
+ cracked = talloc_asprintf(mem_ctx, "%s\n%s", cracked,
+ dn->components[i].value.data);
+ } else {
+ cracked = talloc_asprintf(mem_ctx, "%s/%s", cracked,
+ dn->components[i].value.data);
+ }
+ return cracked;
+}
+
+char *ldb_dn_canonical_string(void *mem_ctx, const struct ldb_dn *dn) {
+ return ldb_dn_canonical(mem_ctx, dn, 0);
+
+}
+
+char *ldb_dn_canonical_ex_string(void *mem_ctx, const struct ldb_dn *dn) {
+ return ldb_dn_canonical(mem_ctx, dn, 1);
+}
diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h
index fd3577a470..27313613ab 100644
--- a/source4/lib/ldb/include/ldb.h
+++ b/source4/lib/ldb/include/ldb.h
@@ -502,4 +502,6 @@ int ldb_msg_copy_attr(struct ldb_message *msg, const char *attr, const char *rep
char *ldb_timestring(void *mem_ctx, time_t t);
time_t ldb_string_to_time(const char *s);
+char *ldb_dn_canonical_string(void *mem_ctx, const struct ldb_dn *dn);
+char *ldb_dn_canonical_ex_string(void *mem_ctx, const struct ldb_dn *dn);
#endif