4cd940ed10665ddd58c07ed591f384c874d82ea3
[kai/samba.git] / source4 / dns_server / dns_update.c
1 /*
2    Unix SMB/CIFS implementation.
3
4    DNS server handler for update requests
5
6    Copyright (C) 2010 Kai Blin  <kai@samba.org>
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "includes.h"
23 #include "libcli/util/ntstatus.h"
24 #include "librpc/ndr/libndr.h"
25 #include "librpc/gen_ndr/ndr_dns.h"
26 #include "librpc/gen_ndr/ndr_dnsp.h"
27 #include <ldb.h>
28 #include "dsdb/samdb/samdb.h"
29 #include "dsdb/common/util.h"
30 #include "dns_server/dns_server.h"
31
32
33 WERROR dns_server_process_update(struct dns_server *dns,
34                                  TALLOC_CTX *mem_ctx,
35                                  struct dns_name_packet *in,
36                                  const struct dns_res_rec *prereqs, uint16_t prereq_count,
37                                  struct dns_res_rec **updates,      uint16_t *update_count,
38                                  struct dns_res_rec **additional,   uint16_t *arcount)
39 {
40         struct dns_name_question *zone;
41         const struct dns_server_zone *z;
42         size_t host_part_len = 0;
43         uint16_t i;
44
45         if (in->qdcount != 1) {
46                 return DNS_ERR(FORMAT_ERROR);
47         }
48
49         zone = in->questions;
50
51         if (zone->question_type != DNS_QTYPE_SOA) {
52                 return DNS_ERR(FORMAT_ERROR);
53         }
54
55         DEBUG(0, ("Got a dns update request.\n"));
56
57         for (z = dns->zones; z != NULL; z = z->next) {
58                 bool match;
59
60                 match = dns_name_match(z->name, zone->name, &host_part_len);
61                 if (match) {
62                         break;
63                 }
64         }
65
66         if (z == NULL) {
67                 return DNS_ERR(NOTAUTH);
68         }
69
70         if (host_part_len != 0) {
71                 return DNS_ERR(NOT_IMPLEMENTED);
72         }
73
74         return DNS_ERR(NOT_IMPLEMENTED);
75 }