rndc.c revision b326d7e3a3a50eb65dd06db007d2fddc62606bbf
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews * Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
0add14467b53f33ace931f9a4790113cb8b5e45dTinderbox User * Copyright (C) 2000-2003 Internet Software Consortium.
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * Permission to use, copy, modify, and distribute this software for any
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * purpose with or without fee is hereby granted, provided that the above
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * copyright notice and this permission notice appear in all copies.
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * PERFORMANCE OF THIS SOFTWARE.
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews/* $Id: rndc.c,v 1.104 2005/03/14 23:55:57 marka Exp $ */
68116c5a5fd36fef812fc207de3b7714db2994d5Evan Hunt * Principal Author: DCL
89740699cd2191d9b84e67716c281b2dfeba5e56Evan Huntstatic const char *admin_conffile;
89740699cd2191d9b84e67716c281b2dfeba5e56Evan Huntstatic const char *admin_keyfile;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrewsstatic isc_boolean_t local4set = ISC_FALSE, local6set = ISC_FALSE;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrewsstatic int currentaddr = 0;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrewsstatic unsigned int remoteport = 0;
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Huntstatic char *command;
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Huntstatic char *args;
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Huntstatic void rndc_startconnect(isc_sockaddr_t *addr, isc_task_t *task);
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan HuntUsage: %s [-c config] [-s server] [-p port]\n\
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt [-k key-file ] [-y key] [-V] command\n\
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Huntcommand is one of the following:\n\
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt reload Reload configuration file and zones.\n\
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt reload zone [class [view]]\n\
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt Reload a single zone.\n\
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt refresh zone [class [view]]\n\
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt Schedule immediate maintenance for a zone.\n\
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt retransfer zone [class [view]]\n\
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt Retransfer a single zone without checking serial number.\n\
6643b0dd91249ace16218ef667967c87b291992cMark Andrews freeze Suspend updates to all dynamic zones.\n\
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt freeze zone [class [view]]\n\
68116c5a5fd36fef812fc207de3b7714db2994d5Evan Hunt Suspend updates to a dynamic zone.\n\
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt thaw Enable updates to all dynamic zones and reload them.\n\
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt thaw zone [class [view]]\n\
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt Enable updates to a frozen dynamic zone and reload it.\n\
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt notify zone [class [view]]\n\
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt Resend NOTIFY messages for the zone.\n\
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews reconfig Reload configuration file and new zones only.\n\
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt stats Write server statistics to the statistics file.\n\
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt querylog Toggle query logging.\n\
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt dumpdb [-all|-cache|-zones] [view ...]\n\
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt Dump cache(s) to the dump file (named_dump.db).\n\
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt stop Save pending updates to master files and stop the server.\n\
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt stop -p Save pending updates to master files and stop the server\n\
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt reporting process id.\n\
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews halt Stop the server without saving pending updates.\n\
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews halt -p Stop the server without saving pending updates reporting\n\
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt process id.\n\
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews trace Increment debugging level by one.\n\
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews trace level Change the debugging level.\n\
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews notrace Set debugging level to 0.\n\
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews flush Flushes all of the server's caches.\n\
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews flush [view] Flushes the server's cache for a view.\n\
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews flushname name [view]\n\
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews Flush the given name from the server's cache(s)\n\
68116c5a5fd36fef812fc207de3b7714db2994d5Evan Hunt status Display status of the server.\n\
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews recursing Dump the queries that are currently recursing (named.recursing)\n\
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews *restart Restart the server.\n\
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews* == not yet implemented\n\
d76ed813a51465e5c47d521ab09ea20c06f1428dMark AndrewsVersion: %s\n",
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrewsget_addresses(const char *host, in_port_t port) {
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews result = isc_sockaddr_frompath(&serveraddrs[nserveraddrs],
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrewsrndc_senddone(isc_task_t *task, isc_event_t *event) {
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews isc_socketevent_t *sevent = (isc_socketevent_t *)event;
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt fatal("send failed: %s", isc_result_totext(sevent->result));
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Huntrndc_recvdone(isc_task_t *task, isc_event_t *event) {
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt "This may indicate that\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt "* the remote server is using an older version of"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt " the command protocol,\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt "* this host is not authorized to connect,\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt "* the clocks are not syncronized, or\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt "* the key is invalid.");
6643b0dd91249ace16218ef667967c87b291992cMark Andrews fatal("recv failed: %s", isc_result_totext(ccmsg.result));
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt DO("parse message", isccc_cc_fromwire(&source, &response, &secret));
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt result = isccc_cc_lookupstring(data, "err", &errormsg);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews fprintf(stderr, "%s: parsing response failed: %s\n",
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews result = isccc_cc_lookupstring(data, "text", &textmsg);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews fprintf(stderr, "%s: parsing response failed: %s\n",
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews RUNTIME_CHECK(isc_app_shutdown() == ISC_R_SUCCESS);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrewsrndc_recvnonce(isc_task_t *task, isc_event_t *event) {
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews "This may indicate that\n"
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews "* the remote server is using an older version of"
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews " the command protocol,\n"
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews "* this host is not authorized to connect,\n"
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews "* the clocks are not syncronized, or\n"
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews "* the key is invalid.");
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews fatal("recv failed: %s", isc_result_totext(ccmsg.result));
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews source.rstart = isc_buffer_base(&ccmsg.buffer);
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt DO("parse message", isccc_cc_fromwire(&source, &response, &secret));
66e50468dde42a9757ac489e738d8b2db8fd7f80Evan Hunt if (isccc_cc_lookupuint32(_ctrl, "_nonce", &nonce) != ISC_R_SUCCESS)
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews DO("create message", isccc_cc_createmessage(1, NULL, NULL, ++serial,
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt if (isccc_cc_definestring(data, "type", args) == NULL)
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt if (isccc_cc_defineuint32(_ctrl, "_nonce", nonce) == NULL)
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt DO("render message", isccc_cc_towire(request, &message, &secret));
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt DO("schedule recv", isccc_ccmsg_readmessage(&ccmsg, task,
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt DO("send message", isc_socket_send(sock, &r, task, rndc_senddone,
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Huntrndc_connected(isc_task_t *task, isc_event_t *event) {
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt isc_socketevent_t *sevent = (isc_socketevent_t *)event;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews rndc_startconnect(&serveraddrs[currentaddr++], task);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews DO("create message", isccc_cc_createmessage(1, NULL, NULL, ++serial,
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews if (isccc_cc_definestring(data, "type", "null") == NULL)
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews DO("render message", isccc_cc_towire(request, &message, &secret));
66e50468dde42a9757ac489e738d8b2db8fd7f80Evan Hunt DO("schedule recv", isccc_ccmsg_readmessage(&ccmsg, task,
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt DO("send message", isc_socket_send(sock, &r, task, rndc_senddone,
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrewsrndc_startconnect(isc_sockaddr_t *addr, isc_task_t *task) {
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt isc_sockaddr_format(addr, socktext, sizeof(socktext));
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt notify("using server %s (%s)", servername, socktext);
6643b0dd91249ace16218ef667967c87b291992cMark Andrews DO("create socket", isc_socket_create(socketmgr, pf, type, &sock));
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt DO("bind socket", isc_socket_bind(sock, &local4));
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt DO("bind socket", isc_socket_bind(sock, &local6));
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt DO("connect", isc_socket_connect(sock, addr, task, rndc_connected,
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt rndc_startconnect(&serveraddrs[currentaddr++], task);
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Huntparse_config(isc_mem_t *mctx, isc_log_t *log, const char *keyname,
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews const cfg_type_t *conftype = &cfg_type_rndcconf;
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews DO("create parser", cfg_parser_create(mctx, log, pctxp));
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews * The parser will output its own errors, so DO() is not used.
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews result = cfg_parse_file(*pctxp, conffile, conftype, &config);
if (!key_only)
if (!key_only) {
const char *name;
&defkey));
} else if (!key_only)
if (key_only)
keyname) == 0)
if (remoteport != 0)
} else if (remoteport == 0)
unsigned int myport;
const char *name;
myport == 0)
myport);
sizeof(socktext));
socktext);
int ch;
switch (ch) {
usage(0);
argslen = 0;
for (i = 0; i < argc; i++)
p = args;
for (i = 0; i < argc; i++) {
p += len;
if (nserveraddrs == 0)
if (show_final_mem)
if (failed)