summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2011-08-22 17:00:54 +1000
committerAndrew Tridgell <tridge@samba.org>2011-08-25 07:39:38 +1000
commit9f404b3dea7bd34890eb66ff60432e05efdc2f09 (patch)
tree9aa42e43da01110b2f7669e1acbfe34cbf479b13
parentbcbb35b0888696db53f63f095e9bf07e493cb9ee (diff)
downloadsamba-9f404b3dea7bd34890eb66ff60432e05efdc2f09.tar.gz
samba-9f404b3dea7bd34890eb66ff60432e05efdc2f09.tar.bz2
samba-9f404b3dea7bd34890eb66ff60432e05efdc2f09.zip
s4-dsdb: added samdb_dn_to_dns_domain()
this converts a DC into the equivalent DNS domain. It is used when forming t_msdcs NTDS DNS names Pair-Programmed-With: Amitay Isaacs <amitay@gmail.com>
-rw-r--r--source4/dsdb/common/util.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/source4/dsdb/common/util.c b/source4/dsdb/common/util.c
index ac380e9db6..cf2e766f01 100644
--- a/source4/dsdb/common/util.c
+++ b/source4/dsdb/common/util.c
@@ -2354,6 +2354,42 @@ struct ldb_dn *samdb_dns_domain_to_dn(struct ldb_context *ldb, TALLOC_CTX *mem_c
return dn;
}
+
+/*
+ Find the DNS equivalent of a DN, in dotted DNS form
+*/
+char *samdb_dn_to_dns_domain(TALLOC_CTX *mem_ctx, struct ldb_dn *dn)
+{
+ int i, num_components = ldb_dn_get_comp_num(dn);
+ char *dns_name = talloc_strdup(mem_ctx, "");
+ if (dns_name == NULL) {
+ return NULL;
+ }
+
+ for (i=0; i<num_components; i++) {
+ struct ldb_val *v = ldb_dn_get_component_val(dn, i);
+ char *s;
+ if (v == NULL) {
+ talloc_free(dns_name);
+ return NULL;
+ }
+ s = talloc_asprintf_append_buffer(dns_name, "%*.*s.", v->length, v->length, (char *)v->data);
+ if (s == NULL) {
+ talloc_free(dns_name);
+ return NULL;
+ }
+ dns_name = s;
+ }
+
+ /* remove the last '.' */
+ if (dns_name[0] != 0) {
+ dns_name[strlen(dns_name)-1] = 0;
+ }
+
+ return dns_name;
+}
+
+
/*
Find the DN of a domain, be it the netbios or DNS name
*/