notify.c revision 70e5a7403f0e0a3bd292b8287c5fed5772c15270
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC")
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Copyright (C) 1999-2003 Internet Software Consortium.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Permission to use, copy, modify, and/or distribute this software for any
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * purpose with or without fee is hereby granted, provided that the above
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * copyright notice and this permission notice appear in all copies.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * PERFORMANCE OF THIS SOFTWARE.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson/* $Id: notify.c,v 1.37 2007/06/19 23:46:59 tbox Exp $ */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * This module implements notify as in RFC1996.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonnotify_log(ns_client_t *client, int level, const char *fmt, ...) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_client_logv(client, DNS_LOGCATEGORY_NOTIFY, NS_LOGMODULE_NOTIFY,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafssonrespond(ns_client_t *client, isc_result_t result) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson msg_result = dns_message_reply(message, ISC_TRUE);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson msg_result = dns_message_reply(message, ISC_FALSE);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson dns_message_t *request = client->message;
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson char tsigbuf[DNS_NAME_FORMATSIZE + sizeof(": TSIG ''")];
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * Interpret the question section.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson result = dns_message_firstname(request, DNS_SECTION_QUESTION);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "notify question section empty");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson * The question section must contain exactly one question.
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson dns_message_currentname(request, DNS_SECTION_QUESTION, &zonename);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson zone_rdataset = ISC_LIST_HEAD(zonename->list);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (ISC_LIST_NEXT(zone_rdataset, link) != NULL) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "notify question section contains multiple RRs");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /* The zone section must have exactly one name. */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson result = dns_message_nextname(request, DNS_SECTION_ZONE);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "notify question section contains multiple RRs");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson /* The one rdataset must be an SOA. */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson if (zone_rdataset->type != dns_rdatatype_soa) {
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "notify question section contains no SOA");
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson tsigkey = dns_message_gettsigkey(request);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson dns_name_format(&tsigkey->name, namebuf, sizeof(namebuf));
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson dns_name_format(tsigkey->creator, cnamebuf,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson snprintf(tsigbuf, sizeof(tsigbuf), ": TSIG '%s' (%s)",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson snprintf(tsigbuf, sizeof(tsigbuf), ": TSIG '%s'",
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson dns_name_format(zonename, namebuf, sizeof(namebuf));
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson result = dns_zt_find(client->view->zonetable, zonename, 0, NULL,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson case dns_zone_stub: /* Allow dialup passive to work. */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "received notify for zone '%s'%s", namebuf, tsigbuf);
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson respond(client, dns_zone_notifyreceive(zone,
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson ns_client_getsockaddr(client), request));
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "received notify for zone '%s'%s: not authoritative",