1999-12-14 01:58:27 -05:00
|
|
|
/*
|
2003-07-22 00:03:54 -04:00
|
|
|
* Copyright (C) 1999-2001, 2003 Internet Software Consortium.
|
2000-07-31 21:33:37 -04:00
|
|
|
*
|
1999-12-14 01:58:27 -05:00
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
2000-07-31 21:33:37 -04:00
|
|
|
*
|
2000-07-27 05:55:03 -04:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
|
|
|
|
|
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
|
|
|
|
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
|
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
|
|
|
|
|
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
|
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
|
|
|
|
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
1999-12-14 01:58:27 -05:00
|
|
|
*/
|
|
|
|
|
|
2003-10-15 01:32:25 -04:00
|
|
|
/* $Id: notify.c,v 1.24.2.2.2.4 2003/10/15 05:32:10 marka Exp $ */
|
2000-06-22 18:00:42 -04:00
|
|
|
|
1999-12-14 01:58:27 -05:00
|
|
|
#include <config.h>
|
|
|
|
|
|
2001-03-30 20:03:26 -05:00
|
|
|
#include <isc/log.h>
|
|
|
|
|
|
1999-12-14 01:58:27 -05:00
|
|
|
#include <dns/message.h>
|
|
|
|
|
#include <dns/rdataset.h>
|
|
|
|
|
#include <dns/result.h>
|
|
|
|
|
#include <dns/view.h>
|
|
|
|
|
#include <dns/zone.h>
|
|
|
|
|
#include <dns/zt.h>
|
|
|
|
|
|
|
|
|
|
#include <named/log.h>
|
|
|
|
|
#include <named/notify.h>
|
|
|
|
|
|
|
|
|
|
/*
|
1999-12-15 20:23:17 -05:00
|
|
|
* This module implements notify as in RFC 1996.
|
1999-12-14 01:58:27 -05:00
|
|
|
*/
|
2000-07-31 21:33:37 -04:00
|
|
|
|
2001-03-30 20:03:26 -05:00
|
|
|
static void
|
2003-08-12 00:54:59 -04:00
|
|
|
notify_log(ns_client_t *client, int level, const char *fmt, ...) {
|
2001-03-30 20:03:26 -05:00
|
|
|
va_list ap;
|
1999-12-14 01:58:27 -05:00
|
|
|
|
2001-03-30 20:03:26 -05:00
|
|
|
va_start(ap, fmt);
|
2003-08-12 00:54:59 -04:00
|
|
|
ns_client_logv(client, DNS_LOGCATEGORY_NOTIFY, NS_LOGMODULE_NOTIFY,
|
2001-03-30 20:03:26 -05:00
|
|
|
level, fmt, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
}
|
1999-12-14 01:58:27 -05:00
|
|
|
|
|
|
|
|
static void
|
1999-12-22 19:09:04 -05:00
|
|
|
respond(ns_client_t *client, isc_result_t result) {
|
1999-12-15 20:23:17 -05:00
|
|
|
dns_rcode_t rcode;
|
2000-12-11 14:24:30 -05:00
|
|
|
dns_message_t *message;
|
|
|
|
|
isc_result_t msg_result;
|
1999-12-15 20:23:17 -05:00
|
|
|
|
|
|
|
|
message = client->message;
|
1999-12-22 17:11:18 -05:00
|
|
|
rcode = dns_result_torcode(result);
|
1999-12-15 20:23:17 -05:00
|
|
|
|
|
|
|
|
msg_result = dns_message_reply(message, ISC_TRUE);
|
|
|
|
|
if (msg_result != ISC_R_SUCCESS)
|
|
|
|
|
msg_result = dns_message_reply(message, ISC_FALSE);
|
|
|
|
|
if (msg_result != ISC_R_SUCCESS) {
|
|
|
|
|
ns_client_next(client, msg_result);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
message->rcode = rcode;
|
2000-06-23 13:26:38 -04:00
|
|
|
if (rcode == dns_rcode_noerror)
|
|
|
|
|
message->flags |= DNS_MESSAGEFLAG_AA;
|
|
|
|
|
else
|
|
|
|
|
message->flags &= ~DNS_MESSAGEFLAG_AA;
|
1999-12-15 20:23:17 -05:00
|
|
|
ns_client_send(client);
|
1999-12-14 01:58:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2000-05-23 23:19:21 -04:00
|
|
|
ns_notify_start(ns_client_t *client) {
|
1999-12-14 01:58:27 -05:00
|
|
|
dns_message_t *request = client->message;
|
1999-12-22 19:09:04 -05:00
|
|
|
isc_result_t result;
|
1999-12-14 01:58:27 -05:00
|
|
|
dns_name_t *zonename;
|
|
|
|
|
dns_rdataset_t *zone_rdataset;
|
|
|
|
|
dns_zone_t *zone = NULL;
|
2003-08-26 21:28:25 -04:00
|
|
|
char namebuf[DNS_NAME_FORMATSIZE];
|
|
|
|
|
char tsigbuf[DNS_NAME_FORMATSIZE + sizeof(": TSIG ''")];
|
|
|
|
|
dns_name_t *tsigname;
|
2000-07-31 21:33:37 -04:00
|
|
|
|
1999-12-14 01:58:27 -05:00
|
|
|
/*
|
|
|
|
|
* Interpret the question section.
|
|
|
|
|
*/
|
|
|
|
|
result = dns_message_firstname(request, DNS_SECTION_QUESTION);
|
2001-03-30 20:03:26 -05:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2003-08-18 22:58:19 -04:00
|
|
|
notify_log(client, ISC_LOG_NOTICE,
|
2003-08-12 00:54:59 -04:00
|
|
|
"notify question section empty");
|
2003-05-13 01:10:27 -04:00
|
|
|
goto formerr;
|
2001-03-30 20:03:26 -05:00
|
|
|
}
|
1999-12-14 01:58:27 -05:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The question section must contain exactly one question.
|
|
|
|
|
*/
|
|
|
|
|
zonename = NULL;
|
|
|
|
|
dns_message_currentname(request, DNS_SECTION_QUESTION, &zonename);
|
|
|
|
|
zone_rdataset = ISC_LIST_HEAD(zonename->list);
|
2001-03-30 20:03:26 -05:00
|
|
|
if (ISC_LIST_NEXT(zone_rdataset, link) != NULL) {
|
2003-08-18 22:58:19 -04:00
|
|
|
notify_log(client, ISC_LOG_NOTICE,
|
2001-03-30 20:03:26 -05:00
|
|
|
"notify question section contains multiple RRs");
|
2003-05-13 01:10:27 -04:00
|
|
|
goto formerr;
|
2001-03-30 20:03:26 -05:00
|
|
|
}
|
1999-12-14 01:58:27 -05:00
|
|
|
|
|
|
|
|
/* The zone section must have exactly one name. */
|
|
|
|
|
result = dns_message_nextname(request, DNS_SECTION_ZONE);
|
2001-03-30 20:03:26 -05:00
|
|
|
if (result != ISC_R_NOMORE) {
|
2003-08-18 22:58:19 -04:00
|
|
|
notify_log(client, ISC_LOG_NOTICE,
|
2001-03-30 20:03:26 -05:00
|
|
|
"notify question section contains multiple RRs");
|
2003-08-26 21:28:25 -04:00
|
|
|
goto formerr;
|
2001-03-30 20:03:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The one rdataset must be an SOA. */
|
|
|
|
|
if (zone_rdataset->type != dns_rdatatype_soa) {
|
2003-08-18 22:58:19 -04:00
|
|
|
notify_log(client, ISC_LOG_NOTICE,
|
2001-03-30 20:03:26 -05:00
|
|
|
"notify question section contains no SOA");
|
2003-05-13 01:10:27 -04:00
|
|
|
goto formerr;
|
2001-03-30 20:03:26 -05:00
|
|
|
}
|
1999-12-14 01:58:27 -05:00
|
|
|
|
2003-08-26 21:28:25 -04:00
|
|
|
tsigname = NULL;
|
|
|
|
|
if (dns_message_gettsig(request, &tsigname) != NULL) {
|
|
|
|
|
dns_name_format(tsigname, namebuf, sizeof(namebuf));
|
|
|
|
|
snprintf(tsigbuf, sizeof(tsigbuf), ": TSIG '%s'", namebuf);
|
|
|
|
|
} else
|
|
|
|
|
tsigbuf[0] = '\0';
|
|
|
|
|
dns_name_format(zonename, namebuf, sizeof(namebuf));
|
2000-04-19 14:27:42 -04:00
|
|
|
result = dns_zt_find(client->view->zonetable, zonename, 0, NULL,
|
|
|
|
|
&zone);
|
2003-05-13 01:10:27 -04:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
|
goto notauth;
|
1999-12-14 01:58:27 -05:00
|
|
|
|
2003-10-15 01:32:25 -04:00
|
|
|
switch (dns_zone_gettype(zone)) {
|
1999-12-14 01:58:27 -05:00
|
|
|
case dns_zone_master:
|
|
|
|
|
case dns_zone_slave:
|
2000-11-27 22:17:48 -05:00
|
|
|
case dns_zone_stub: /* Allow dialup passive to work. */
|
2003-08-12 00:54:59 -04:00
|
|
|
notify_log(client, ISC_LOG_INFO,
|
2003-08-26 21:28:25 -04:00
|
|
|
"received notify for zone '%s'%s", namebuf, tsigbuf);
|
1999-12-14 01:58:27 -05:00
|
|
|
respond(client, dns_zone_notifyreceive(zone,
|
|
|
|
|
ns_client_getsockaddr(client), request));
|
1999-12-15 20:23:17 -05:00
|
|
|
break;
|
1999-12-14 01:58:27 -05:00
|
|
|
default:
|
2003-05-13 01:10:27 -04:00
|
|
|
goto notauth;
|
1999-12-14 01:58:27 -05:00
|
|
|
}
|
2000-05-08 03:26:37 -04:00
|
|
|
dns_zone_detach(&zone);
|
1999-12-14 01:58:27 -05:00
|
|
|
return;
|
2000-07-31 21:33:37 -04:00
|
|
|
|
2003-05-13 01:10:27 -04:00
|
|
|
notauth:
|
2003-08-18 22:58:19 -04:00
|
|
|
notify_log(client, ISC_LOG_NOTICE,
|
2003-08-26 21:28:25 -04:00
|
|
|
"received notify for zone '%s'%s: not authoritative",
|
|
|
|
|
namebuf, tsigbuf);
|
2003-05-13 01:10:27 -04:00
|
|
|
result = DNS_R_NOTAUTH;
|
|
|
|
|
goto failure;
|
|
|
|
|
|
|
|
|
|
formerr:
|
|
|
|
|
result = DNS_R_FORMERR;
|
|
|
|
|
|
1999-12-14 01:58:27 -05:00
|
|
|
failure:
|
2000-05-08 03:26:37 -04:00
|
|
|
if (zone != NULL)
|
|
|
|
|
dns_zone_detach(&zone);
|
1999-12-14 01:58:27 -05:00
|
|
|
respond(client, result);
|
|
|
|
|
}
|