From 0431dc5ce92cf34dba07f15eec2f6c02b696a8db Mon Sep 17 00:00:00 2001 From: Garming Sam Date: Mon, 19 Jun 2017 14:49:55 +1200 Subject: [PATCH] dsdb: Add a samdb_dns_host_name which avoids searching This ideally should also be used in rootDSE. Signed-off-by: Garming Sam Reviewed-by: Andrew Bartlett --- source4/dsdb/common/util.c | 47 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/source4/dsdb/common/util.c b/source4/dsdb/common/util.c index b46a7fc4054..7a12c71799b 100644 --- a/source4/dsdb/common/util.c +++ b/source4/dsdb/common/util.c @@ -3485,6 +3485,53 @@ int samdb_rodc(struct ldb_context *sam_ctx, bool *am_rodc) return LDB_SUCCESS; } +int samdb_dns_host_name(struct ldb_context *sam_ctx, const char **host_name) +{ + const char *_host_name = NULL; + const char *attrs[] = { "dnsHostName", NULL }; + TALLOC_CTX *tmp_ctx = NULL; + int ret; + struct ldb_result *res = NULL; + + _host_name = (const char *)ldb_get_opaque(sam_ctx, "cache.dns_host_name"); + if (_host_name != NULL) { + *host_name = _host_name; + return LDB_SUCCESS; + } + + tmp_ctx = talloc_new(sam_ctx); + + ret = dsdb_search_dn(sam_ctx, tmp_ctx, &res, NULL, attrs, 0); + + if (res->count != 1 || ret != LDB_SUCCESS) { + DEBUG(0, ("Failed to get rootDSE for dnsHostName: %s", + ldb_errstring(sam_ctx))); + TALLOC_FREE(tmp_ctx); + return ret; + } + + + _host_name = ldb_msg_find_attr_as_string(res->msgs[0], + "dnsHostName", + NULL); + if (_host_name == NULL) { + DEBUG(0, ("Failed to get dnsHostName from rootDSE")); + TALLOC_FREE(tmp_ctx); + return LDB_ERR_OPERATIONS_ERROR; + } + ret = ldb_set_opaque(sam_ctx, "cache.dns_host_name", + discard_const_p(char *, _host_name)); + if (ret != LDB_SUCCESS) { + TALLOC_FREE(tmp_ctx); + return ldb_operr(sam_ctx); + } + + *host_name = talloc_steal(sam_ctx, _host_name); + + TALLOC_FREE(tmp_ctx); + return LDB_SUCCESS; +} + bool samdb_set_am_rodc(struct ldb_context *ldb, bool am_rodc) { TALLOC_CTX *tmp_ctx; -- 2.47.2