2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-23 10:39:16 +00:00
bind/lib/ns/notify.c

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

177 lines
4.5 KiB
C
Raw Permalink Normal View History

1999-12-14 06:58:27 +00:00
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
1999-12-14 06:58:27 +00:00
*
* SPDX-License-Identifier: MPL-2.0
*
1999-12-14 06:58:27 +00:00
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
1999-12-14 06:58:27 +00:00
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
2001-03-31 01:03:26 +00:00
#include <isc/log.h>
#include <isc/result.h>
2001-03-31 01:03:26 +00:00
1999-12-14 06:58:27 +00:00
#include <dns/message.h>
#include <dns/rdataset.h>
#include <dns/result.h>
#include <dns/tsig.h>
1999-12-14 06:58:27 +00:00
#include <dns/view.h>
#include <dns/zone.h>
#include <dns/zt.h>
#include <ns/notify.h>
#include <ns/types.h>
1999-12-14 06:58:27 +00:00
/*! \file
* \brief
* This module implements notify as in RFC1996.
1999-12-14 06:58:27 +00:00
*/
2001-03-31 01:03:26 +00:00
static void
notify_log(ns_client_t *client, int level, const char *fmt, ...) {
2001-03-31 01:03:26 +00:00
va_list ap;
1999-12-14 06:58:27 +00:00
2001-03-31 01:03:26 +00:00
va_start(ap, fmt);
ns_client_logv(client, DNS_LOGCATEGORY_NOTIFY, NS_LOGMODULE_NOTIFY,
2001-03-31 01:03:26 +00:00
level, fmt, ap);
va_end(ap);
}
1999-12-14 06:58:27 +00:00
static void
respond(ns_client_t *client, isc_result_t result) {
1999-12-16 01:23:17 +00:00
dns_rcode_t rcode;
2000-12-11 19:24:30 +00:00
dns_message_t *message;
isc_result_t msg_result;
1999-12-16 01:23:17 +00:00
message = client->message;
rcode = dns_result_torcode(result);
1999-12-16 01:23:17 +00:00
msg_result = dns_message_reply(message, true);
1999-12-16 01:23:17 +00:00
if (msg_result != ISC_R_SUCCESS) {
msg_result = dns_message_reply(message, false);
}
1999-12-16 01:23:17 +00:00
if (msg_result != ISC_R_SUCCESS) {
ns_client_drop(client, msg_result);
isc_nmhandle_detach(&client->inner.reqhandle);
1999-12-16 01:23:17 +00:00
return;
}
message->rcode = rcode;
2000-06-23 17:26:38 +00:00
if (rcode == dns_rcode_noerror) {
message->flags |= DNS_MESSAGEFLAG_AA;
} else {
message->flags &= ~DNS_MESSAGEFLAG_AA;
}
1999-12-16 01:23:17 +00:00
ns_client_send(client);
isc_nmhandle_detach(&client->inner.reqhandle);
1999-12-14 06:58:27 +00:00
}
void
ns_notify_start(ns_client_t *client, isc_nmhandle_t *handle) {
1999-12-14 06:58:27 +00:00
dns_message_t *request = client->message;
isc_result_t result;
1999-12-14 06:58:27 +00:00
dns_name_t *zonename;
dns_rdataset_t *zone_rdataset;
dns_zone_t *zone = NULL;
char namebuf[DNS_NAME_FORMATSIZE];
char tsigbuf[DNS_NAME_FORMATSIZE * 2 + sizeof(": TSIG '' ()")];
dns_tsigkey_t *tsigkey;
/*
* Attach to the request handle
*/
isc_nmhandle_attach(handle, &client->inner.reqhandle);
1999-12-14 06:58:27 +00:00
/*
* Interpret the question section.
*/
if (ISC_LIST_EMPTY(request->sections[DNS_SECTION_QUESTION])) {
notify_log(client, ISC_LOG_NOTICE,
"notify question section empty");
result = DNS_R_FORMERR;
goto done;
2001-03-31 01:03:26 +00:00
}
1999-12-14 06:58:27 +00:00
/*
* The question section must contain exactly one question.
*/
zonename = ISC_LIST_HEAD(request->sections[DNS_SECTION_QUESTION]);
1999-12-14 06:58:27 +00:00
zone_rdataset = ISC_LIST_HEAD(zonename->list);
2001-03-31 01:03:26 +00:00
if (ISC_LIST_NEXT(zone_rdataset, link) != NULL) {
notify_log(client, ISC_LOG_NOTICE,
2001-03-31 01:03:26 +00:00
"notify question section contains multiple RRs");
result = DNS_R_FORMERR;
goto done;
2001-03-31 01:03:26 +00:00
}
1999-12-14 06:58:27 +00:00
/* The zone section must have exactly one name. */
if (ISC_LIST_NEXT(zonename, link) != NULL) {
notify_log(client, ISC_LOG_NOTICE,
2001-03-31 01:03:26 +00:00
"notify question section contains multiple RRs");
result = DNS_R_FORMERR;
goto done;
2001-03-31 01:03:26 +00:00
}
/* The one rdataset must be an SOA. */
if (zone_rdataset->type != dns_rdatatype_soa) {
notify_log(client, ISC_LOG_NOTICE,
2001-03-31 01:03:26 +00:00
"notify question section contains no SOA");
result = DNS_R_FORMERR;
goto done;
2001-03-31 01:03:26 +00:00
}
1999-12-14 06:58:27 +00:00
tsigkey = dns_message_gettsigkey(request);
if (tsigkey != NULL) {
dns_name_format(tsigkey->name, namebuf, sizeof(namebuf));
if (tsigkey->generated) {
char cnamebuf[DNS_NAME_FORMATSIZE];
dns_name_format(tsigkey->creator, cnamebuf,
sizeof(cnamebuf));
snprintf(tsigbuf, sizeof(tsigbuf), ": TSIG '%s' (%s)",
namebuf, cnamebuf);
} else {
snprintf(tsigbuf, sizeof(tsigbuf), ": TSIG '%s'",
namebuf);
}
} else {
tsigbuf[0] = '\0';
}
dns_name_format(zonename, namebuf, sizeof(namebuf));
result = dns_view_findzone(client->inner.view, zonename,
DNS_ZTFIND_EXACT, &zone);
if (result == ISC_R_SUCCESS) {
dns_zonetype_t zonetype = dns_zone_gettype(zone);
if ((zonetype == dns_zone_primary) ||
(zonetype == dns_zone_secondary) ||
(zonetype == dns_zone_mirror) ||
(zonetype == dns_zone_stub))
{
isc_sockaddr_t *from = ns_client_getsockaddr(client);
isc_sockaddr_t *to = ns_client_getdestaddr(client);
notify_log(client, ISC_LOG_INFO,
"received notify for zone '%s'%s", namebuf,
tsigbuf);
result = dns_zone_notifyreceive(zone, from, to,
request);
goto done;
}
1999-12-14 06:58:27 +00:00
}
result = DNS_R_NOTAUTH;
notify_log(client, ISC_LOG_NOTICE,
"received notify for zone '%s'%s: %s", namebuf, tsigbuf,
isc_result_totext(result));
done:
if (zone != NULL) {
dns_zone_detach(&zone);
}
1999-12-14 06:58:27 +00:00
respond(client, result);
}