s4 dns: Implement update record prescan logic
authorKai Blin <kai@samba.org>
Sun, 3 Oct 2010 10:21:00 +0000 (12:21 +0200)
committerKai Blin <kai@samba.org>
Sat, 23 Oct 2010 10:58:18 +0000 (10:58 +0000)
Autobuild-User: Kai Blin <kai@samba.org>
Autobuild-Date: Sat Oct 23 10:58:18 UTC 2010 on sn-devel-104

source4/dns_server/dns_update.c

index 81e3fce5997c46cc81b1dee684534c5e8e2f61ca..f789f2d6258115b31132f1556834da0995bee3b5 100644 (file)
@@ -91,6 +91,40 @@ static WERROR check_prerequsites(struct dns_server *dns,
        return WERR_OK;
 }
 
+static WERROR update_prescan(const struct dns_name_question *zone,
+                            const struct dns_res_rec *updates, uint16_t count)
+{
+       const struct dns_res_rec *r;
+       uint16_t i;
+       size_t host_part_len;
+       bool match;
+
+       for (i = 0; i < count; i++) {
+               r = &updates[i];
+               match = dns_name_match(zone->name, r->name, &host_part_len);
+               if (!match) {
+                       return DNS_ERR(NOTZONE);
+               }
+               if (zone->question_class == r->rr_class) {
+                       /*TODO: also check for AXFR,MAILA,MAILB  */
+                       if (r->rr_type == DNS_QTYPE_ALL) {
+                               return DNS_ERR(FORMAT_ERROR);
+                       }
+               } else if (r->rr_class == DNS_QCLASS_ANY) {
+                       if (r->ttl != 0 || r->length != 0) {
+                               return DNS_ERR(FORMAT_ERROR);
+                       }
+               } else if (r->rr_class == DNS_QCLASS_NONE) {
+                       if (r->ttl != 0 || r->rr_type == DNS_QTYPE_ALL) {
+                               return DNS_ERR(FORMAT_ERROR);
+                       }
+               } else {
+                       return DNS_ERR(FORMAT_ERROR);
+               }
+       }
+       return WERR_OK;
+}
+
 WERROR dns_server_process_update(struct dns_server *dns,
                                 TALLOC_CTX *mem_ctx,
                                 struct dns_name_packet *in,
@@ -144,5 +178,8 @@ WERROR dns_server_process_update(struct dns_server *dns,
                return DNS_ERR(REFUSED);
        }
 
+       werror = update_prescan(in->questions, *updates, *update_count);
+       W_ERROR_NOT_OK_RETURN(werror);
+
        return werror;
 }