]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
dns: Add a SOA record to error replies
authorKai Blin <kai@samba.org>
Wed, 29 Oct 2014 12:41:53 +0000 (13:41 +0100)
committerKai Blin <kai@samba.org>
Thu, 6 Aug 2015 09:03:14 +0000 (11:03 +0200)
Signed-off-by: Kai Blin <kai@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
source4/dns_server/dns_query.c

index aa79f1f7b0268bc7dbbb459b527bd34a84824bd1..8ff48a5d60ceb98e298863e46094c6e41be13042 100644 (file)
@@ -253,6 +253,52 @@ static WERROR ask_forwarder_recv(
        return WERR_OK;
 }
 
+static WERROR add_zone_authority_record(struct dns_server *dns,
+                                       TALLOC_CTX *mem_ctx,
+                                       const struct dns_name_question *question,
+                                       struct dns_res_rec **nsrecs, uint16_t *nscount)
+{
+       const char *zone = NULL;
+       struct dnsp_DnssrvRpcRecord *recs;
+       struct dns_res_rec *ns = *nsrecs;
+       uint16_t rec_count, ni = *nscount;
+       struct ldb_dn *dn = NULL;
+       unsigned int ri;
+       WERROR werror;
+
+       zone = dns_get_authoritative_zone(dns, question->name);
+       DEBUG(10, ("Creating zone authority record for '%s'\n", zone));
+
+       werror = dns_name2dn(dns, mem_ctx, zone, &dn);
+       if (!W_ERROR_IS_OK(werror)) {
+               return werror;
+       }
+
+       werror = dns_lookup_records(dns, mem_ctx, dn, &recs, &rec_count);
+       if (!W_ERROR_IS_OK(werror)) {
+               return werror;
+       }
+
+       ns = talloc_realloc(mem_ctx, ns, struct dns_res_rec, rec_count + ni);
+       if (ns == NULL) {
+               return WERR_NOMEM;
+       }
+       for (ri = 0; ri < rec_count; ri++) {
+               if (recs[ri].wType == DNS_TYPE_SOA) {
+                       werror = create_response_rr(zone, &recs[ri], &ns, &ni);
+                       if (!W_ERROR_IS_OK(werror)) {
+                               return werror;
+                       }
+               }
+       }
+
+       *nscount = ni;
+       *nsrecs = ns;
+
+       return WERR_OK;
+}
+
+
 static WERROR handle_question(struct dns_server *dns,
                              TALLOC_CTX *mem_ctx,
                              const struct dns_name_question *question,
@@ -271,7 +317,11 @@ static WERROR handle_question(struct dns_server *dns,
        W_ERROR_NOT_OK_RETURN(werror);
 
        werror = dns_lookup_records(dns, mem_ctx, dn, &recs, &rec_count);
-       W_ERROR_NOT_OK_RETURN(werror);
+       if (!W_ERROR_IS_OK(werror)) {
+               werror_return = werror;
+               add_zone_authority_record(dns, mem_ctx, question, &ns, &ni);
+               goto done;
+       }
 
        ans = talloc_realloc(mem_ctx, ans, struct dns_res_rec, rec_count + ai);
        if (ans == NULL) {