diff options
author | Andrew Tridgell <tridge@samba.org> | 2011-08-22 17:29:08 +1000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2011-08-25 07:39:38 +1000 |
commit | 9784fbc378f155b07a08c29d4787b0896165d5db (patch) | |
tree | 8bfc8c4877f79930accf33f7e1c2da3ac3a813a4 /source4/dsdb | |
parent | 42ae193e3f8ace2e81b4b754e557ba37dcf2b80e (diff) | |
download | samba-9784fbc378f155b07a08c29d4787b0896165d5db.tar.gz samba-9784fbc378f155b07a08c29d4787b0896165d5db.tar.bz2 samba-9784fbc378f155b07a08c29d4787b0896165d5db.zip |
s4-dsdb: added samdb_ntds_msdcs_dns_name()
this gets the DNS name for a NTDS GUID, based on the forest DNS name
Pair-Programmed-With: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'source4/dsdb')
-rw-r--r-- | source4/dsdb/common/util.c | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/source4/dsdb/common/util.c b/source4/dsdb/common/util.c index cf2e766f01..f64e624dfd 100644 --- a/source4/dsdb/common/util.c +++ b/source4/dsdb/common/util.c @@ -2367,13 +2367,14 @@ char *samdb_dn_to_dns_domain(TALLOC_CTX *mem_ctx, struct ldb_dn *dn) } for (i=0; i<num_components; i++) { - struct ldb_val *v = ldb_dn_get_component_val(dn, i); + const 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); + s = talloc_asprintf_append_buffer(dns_name, "%*.*s.", + (int)v->length, (int)v->length, (char *)v->data); if (s == NULL) { talloc_free(dns_name); return NULL; @@ -2389,6 +2390,40 @@ char *samdb_dn_to_dns_domain(TALLOC_CTX *mem_ctx, struct ldb_dn *dn) return dns_name; } +/* + Find the DNS _msdcs name for a given NTDS GUID. The resulting DNS + name is based on the forest DNS name +*/ +char *samdb_ntds_msdcs_dns_name(struct ldb_context *samdb, + TALLOC_CTX *mem_ctx, + const struct GUID *ntds_guid) +{ + TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx); + const char *guid_str; + struct ldb_dn *forest_dn; + const char *dnsforest; + char *ret; + + guid_str = GUID_string(tmp_ctx, ntds_guid); + if (guid_str == NULL) { + talloc_free(tmp_ctx); + return NULL; + } + forest_dn = ldb_get_root_basedn(samdb); + if (forest_dn == NULL) { + talloc_free(tmp_ctx); + return NULL; + } + dnsforest = samdb_dn_to_dns_domain(tmp_ctx, forest_dn); + if (dnsforest == NULL) { + talloc_free(tmp_ctx); + return NULL; + } + ret = talloc_asprintf(mem_ctx, "%s._msdcs.%s", guid_str, dnsforest); + talloc_free(tmp_ctx); + return ret; +} + /* Find the DN of a domain, be it the netbios or DNS name |