From 006e51539b7c0f20b169e591dafb335f17cf885f Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Mon, 3 Nov 2014 11:57:50 +1100 Subject: [PATCH] s4-dns: dlz-bind: Add terminating '.' to all fqdn strings BIND 9.10.x is strict when sending records via putrr and putnamedrr. Thanks to Guenter Kukkukk for identifying the problem and resolution. Signed-off-by: Amitay Isaacs --- source4/dns_server/dlz_bind9.c | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/source4/dns_server/dlz_bind9.c b/source4/dns_server/dlz_bind9.c index d43b404..28dfa11 100644 --- a/source4/dns_server/dlz_bind9.c +++ b/source4/dns_server/dlz_bind9.c @@ -110,6 +110,27 @@ static void b9_add_helper(struct dlz_bind9_data *state, const char *helper_name, } /* + * Add a terminating '.' if it's missing + */ +static const char *b9_format_fqdn(TALLOC_CTX *mem_ctx, const char *str) +{ + size_t len; + const char *tmp; + + if (str == NULL) { + return str; + } + + len = strlen(str); + if (str[len-1] != '.') { + tmp = talloc_asprintf(mem_ctx, "%s.", str); + } else { + tmp = str; + } + return tmp; +} + +/* format a record for bind9 */ static bool b9_format(struct dlz_bind9_data *state, @@ -133,7 +154,7 @@ static bool b9_format(struct dlz_bind9_data *state, case DNS_TYPE_CNAME: *type = "cname"; - *data = rec->data.cname; + *data = b9_format_fqdn(mem_ctx, rec->data.cname); break; case DNS_TYPE_TXT: @@ -147,7 +168,7 @@ static bool b9_format(struct dlz_bind9_data *state, case DNS_TYPE_PTR: *type = "ptr"; - *data = rec->data.ptr; + *data = b9_format_fqdn(mem_ctx, rec->data.ptr); break; case DNS_TYPE_SRV: @@ -156,14 +177,16 @@ static bool b9_format(struct dlz_bind9_data *state, rec->data.srv.wPriority, rec->data.srv.wWeight, rec->data.srv.wPort, - rec->data.srv.nameTarget); + b9_format_fqdn(mem_ctx, + rec->data.srv.nameTarget)); break; case DNS_TYPE_MX: *type = "mx"; *data = talloc_asprintf(mem_ctx, "%u %s", rec->data.mx.wPriority, - rec->data.mx.nameTarget); + b9_format_fqdn(mem_ctx, + rec->data.mx.nameTarget)); break; case DNS_TYPE_HINFO: @@ -175,7 +198,7 @@ static bool b9_format(struct dlz_bind9_data *state, case DNS_TYPE_NS: *type = "ns"; - *data = rec->data.ns; + *data = b9_format_fqdn(mem_ctx, rec->data.ns); break; case DNS_TYPE_SOA: { @@ -187,7 +210,8 @@ static bool b9_format(struct dlz_bind9_data *state, * force clients to send updates to the right local DC */ mname = talloc_asprintf(mem_ctx, "%s.%s", - lpcfg_netbios_name(state->lp), lpcfg_dnsdomain(state->lp)); + lpcfg_netbios_name(state->lp), + lpcfg_dnsdomain(state->lp)); if (mname == NULL) { return false; } @@ -199,8 +223,9 @@ static bool b9_format(struct dlz_bind9_data *state, state->soa_serial = rec->data.soa.serial; *data = talloc_asprintf(mem_ctx, "%s %s %u %u %u %u %u", - mname, - rec->data.soa.rname, + b9_format_fqdn(mem_ctx, mname), + b9_format_fqdn(mem_ctx, + rec->data.soa.rname), rec->data.soa.serial, rec->data.soa.refresh, rec->data.soa.retry, @@ -957,6 +982,7 @@ _PUBLIC_ isc_result_t dlz_allnodes(const char *zone, void *dbdata, } else { name = talloc_asprintf(el_ctx, "%s.%s", rdn, zone); } + name = b9_format_fqdn(el_ctx, name); if (name == NULL) { talloc_free(tmp_ctx); return ISC_R_NOMEMORY; -- 1.9.3