rndc.c revision d6a0e00dc3e047f8470b938878926957070def77
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer * Copyright (C) 2000-2016 Internet Systems Consortium, Inc. ("ISC")
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * Principal Author: DCL
fdebae839745f79a7550aeb49d15a930523ec483David Lawrencestatic const char *admin_conffile;
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Huntstatic const char *admin_keyfile;
28002bd7cb4baa0eab9f47e1e51069c5ea7ea5d4Andreas Gustafssonstatic isc_boolean_t local4set = ISC_FALSE, local6set = ISC_FALSE;
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Huntstatic int currentaddr = 0;
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Huntstatic unsigned int remoteport = 0;
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Huntstatic void rndc_startconnect(isc_sockaddr_t *addr, isc_task_t *task);
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan HuntUsage: %s [-b address] [-c config] [-s server] [-p port]\n\
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt [-k key-file ] [-y key] [-r] [-V] command\n\
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Huntcommand is one of the following:\n\
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt addzone zone [class [view]] { zone-options }\n\
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt Add zone to given view. Requires allow-new-zones option.\n\
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt delzone [-clean] zone [class [view]]\n\
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt Removes zone from given view.\n\
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt dnstap -reopen\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt Close and re-open the DNSTAP output file.\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt dnstap -roll count\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt Close, rename and re-open the DNSTAP output file(s).\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt dumpdb [-all|-cache|-zones|-adb|-bad|-fail] [view ...]\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt Dump cache(s) to the dump file (named_dump.db).\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt flush Flushes all of the server's caches.\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt flush [view] Flushes the server's cache for a view.\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt flushname name [view]\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt Flush the given name from the server's cache(s)\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt flushtree name [view]\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt Flush all names under the given name from the server's cache(s)\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt freeze Suspend updates to all dynamic zones.\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt freeze zone [class [view]]\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt Suspend updates to a dynamic zone.\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt halt Stop the server without saving pending updates.\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt halt -p Stop the server without saving pending updates reporting\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt process id.\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt loadkeys zone [class [view]]\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt Update keys without signing immediately.\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt managed-keys refresh [class [view]]\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt Check trust anchor for RFC 5011 key changes\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt managed-keys status [class [view]]\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt Display RFC 5011 managed keys information\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt managed-keys sync [class [view]]\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt Write RFC 5011 managed keys to disk\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt modzone zone [class [view]] { zone-options }\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt Modify a zone's configuration.\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt Requires allow-new-zones option.\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt notify zone [class [view]]\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt Resend NOTIFY messages for the zone.\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt notrace Set debugging level to 0.\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt nta -dump\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt List all negative trust anchors.\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt nta [-lifetime duration] [-force] domain [view]\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt Set a negative trust anchor, disabling DNSSEC validation\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt for the given domain.\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt Using -lifetime specifies the duration of the NTA, up\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt to one week.\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt Using -force prevents the NTA from expiring before its\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt full lifetime, even if the domain can validate sooner.\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt nta -remove domain [view]\n\
47e70d820ed07895a25e5b3520adf953114ac01eEvan Hunt Remove a negative trust anchor, re-enabling validation\n\
47e70d820ed07895a25e5b3520adf953114ac01eEvan Hunt for the given domain.\n\
47e70d820ed07895a25e5b3520adf953114ac01eEvan Hunt querylog newstate\n\
47e70d820ed07895a25e5b3520adf953114ac01eEvan Hunt Enable / disable query logging.\n\
47e70d820ed07895a25e5b3520adf953114ac01eEvan Hunt reconfig Reload configuration file and new zones only.\n\
47e70d820ed07895a25e5b3520adf953114ac01eEvan Hunt recursing Dump the queries that are currently recursing (named.recursing)\n\
47e70d820ed07895a25e5b3520adf953114ac01eEvan Hunt refresh zone [class [view]]\n\
47e70d820ed07895a25e5b3520adf953114ac01eEvan Hunt Schedule immediate maintenance for a zone.\n\
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt reload Reload configuration file and zones.\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt reload zone [class [view]]\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt Reload a single zone.\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt retransfer zone [class [view]]\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt Retransfer a single zone without checking serial number.\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt scan Scan available network interfaces for changes.\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt secroots [view ...]\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt Write security roots to the secroots file.\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt showzone zone [class [view]]\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt Print a zone's configuration.\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt sign zone [class [view]]\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt Update zone keys, and sign as needed.\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt signing -clear all zone [class [view]]\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt Remove the private records for all keys that have\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt finished signing the given zone.\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt signing -clear <keyid>/<algorithm> zone [class [view]]\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt Remove the private record that indicating the given key\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt has finished signing the given zone.\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt signing -list zone [class [view]]\n\
2a6d60615cf07b164533dbb6bb1dce84ed2d037dEvan Hunt List the private records showing the state of DNSSEC\n\
2a6d60615cf07b164533dbb6bb1dce84ed2d037dEvan Hunt signing in the given zone.\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt signing -nsec3param hash flags iterations salt zone [class [view]]\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt Add NSEC3 chain to zone if already signed.\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt Prime zone with NSEC3 chain if not yet signed.\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt signing -nsec3param none zone [class [view]]\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt Remove NSEC3 chains from zone.\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt stats Write server statistics to the statistics file.\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt status Display status of the server.\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt stop Save pending updates to master files and stop the server.\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt stop -p Save pending updates to master files and stop the server\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt reporting process id.\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt sync [-clean] Dump changes to all dynamic zones to disk, and optionally\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt remove their journal files.\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt sync [-clean] zone [class [view]]\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt Dump a single zone's changes to disk, and optionally\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt remove its journal file.\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt thaw Enable updates to all dynamic zones and reload them.\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt thaw zone [class [view]]\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt Enable updates to a frozen dynamic zone and reload it.\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt trace Increment debugging level by one.\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt trace level Change the debugging level.\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt tsig-delete keyname [view]\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt Delete a TKEY-negotiated TSIG key.\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt tsig-list List all currently active TSIG keys, including both statically\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt configured and TKEY-negotiated keys.\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt validation newstate [view]\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt Enable / disable DNSSEC validation.\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt zonestatus zone [class [view]]\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt Display the current status of a zone.\n\
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan HuntVersion: %s\n",
cba23be7ba724b527f6a60c14caaeca9502fbc79Evan Hunt result = isc_sockaddr_frompath(&serveraddrs[nserveraddrs],
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrewsrndc_senddone(isc_task_t *task, isc_event_t *event) {
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews isc_socketevent_t *sevent = (isc_socketevent_t *)event;
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews fatal("send failed: %s", isc_result_totext(sevent->result));
c5272fb3303425f794dab68f734f6a2a45dce01eMichael Sawyer RUNTIME_CHECK(isc_app_shutdown() == ISC_R_SUCCESS);
c5272fb3303425f794dab68f734f6a2a45dce01eMichael Sawyerrndc_recvdone(isc_task_t *task, isc_event_t *event) {
dc9c461b27df798ba7c3d9ba1446840c5f85553bMichael Sawyer "This may indicate that\n"
1b003261c2dd3e32778337c7a2788e4829066bd9Andreas Gustafsson "* the remote server is using an older version of"
1b003261c2dd3e32778337c7a2788e4829066bd9Andreas Gustafsson " the command protocol,\n"
1b003261c2dd3e32778337c7a2788e4829066bd9Andreas Gustafsson "* this host is not authorized to connect,\n"
1b003261c2dd3e32778337c7a2788e4829066bd9Andreas Gustafsson "* the clocks are not synchronized, or\n"
3ad7f12f7439471a0922ed3952221e93aef9db69Andreas Gustafsson "* the key is invalid.");
3ad7f12f7439471a0922ed3952221e93aef9db69Andreas Gustafsson fatal("recv failed: %s", isc_result_totext(ccmsg.result));
3ad7f12f7439471a0922ed3952221e93aef9db69Andreas Gustafsson source.rstart = isc_buffer_base(&ccmsg.buffer);
3ad7f12f7439471a0922ed3952221e93aef9db69Andreas Gustafsson source.rend = isc_buffer_used(&ccmsg.buffer);
0759eb6a0dab024873df528b0ffad804ea31615dMichael Sawyer isccc_cc_fromwire(&source, &response, algorithm, &secret));
dc9c461b27df798ba7c3d9ba1446840c5f85553bMichael Sawyer data = isccc_alist_lookup(response, "_data");
dc9c461b27df798ba7c3d9ba1446840c5f85553bMichael Sawyer fatal("bad or missing data section in response");
dc9c461b27df798ba7c3d9ba1446840c5f85553bMichael Sawyer result = isccc_cc_lookupstring(data, "err", &errormsg);
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt fprintf(stderr, "%s: parsing response failed: %s\n",
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson result = isccc_cc_lookupstring(data, "text", &textmsg);
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson if ((!quiet || failed) && strlen(textmsg) != 0U)
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson fprintf(failed ? stderr : stdout, "%s\n", textmsg);
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson fprintf(stderr, "%s: parsing response failed: %s\n",
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson result = isccc_cc_lookupuint32(data, "result", &eresult);
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt printf("%s %u\n", isc_result_toid(eresult), eresult);
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson RUNTIME_CHECK(isc_app_shutdown() == ISC_R_SUCCESS);
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafssonrndc_recvnonce(isc_task_t *task, isc_event_t *event) {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews "This may indicate that\n"
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews "* the remote server is using an older version of"
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews " the command protocol,\n"
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews "* this host is not authorized to connect,\n"
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews "* the clocks are not synchronized,\n"
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews "* the key signing algorithm is incorrect, or\n"
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews "* the key is invalid.");
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews fatal("recv failed: %s", isc_result_totext(ccmsg.result));
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews source.rstart = isc_buffer_base(&ccmsg.buffer);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews isccc_cc_fromwire(&source, &response, algorithm, &secret));
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews fatal("bad or missing ctrl section in response");
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews if (isccc_cc_lookupuint32(_ctrl, "_nonce", &nonce) != ISC_R_SUCCESS)
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews DO("create message", isccc_cc_createmessage(1, NULL, NULL, ++serial,
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews if (isccc_cc_definestring(data, "type", args) == NULL)
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews if (isccc_cc_defineuint32(_ctrl, "_nonce", nonce) == NULL)
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews /* Skip the length field (4 bytes) */
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews isccc_cc_towire(request, &databuf, algorithm, &secret));
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews DO("schedule recv", isccc_ccmsg_readmessage(&ccmsg, task,
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews DO("send message", isc_socket_send(sock, &r, task, rndc_senddone,
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrewsrndc_connected(isc_task_t *task, isc_event_t *event) {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews isc_socketevent_t *sevent = (isc_socketevent_t *)event;
e2f470bebb3a0c107bc4ac86c6920c21e50e83e0Brian Wellington isc_sockaddr_format(&serveraddrs[currentaddr], socktext,
e2f470bebb3a0c107bc4ac86c6920c21e50e83e0Brian Wellington notify("connection failed: %s: %s", socktext,
e2f470bebb3a0c107bc4ac86c6920c21e50e83e0Brian Wellington rndc_startconnect(&serveraddrs[currentaddr], task);
82f0630bae09598209cc37c1db00ff4356efee27Mark Andrews DO("create message", isccc_cc_createmessage(1, NULL, NULL, ++serial,
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews if (isccc_cc_definestring(data, "type", "null") == NULL)
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews /* Skip the length field (4 bytes) */
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews isccc_cc_towire(request, &databuf, algorithm, &secret));
ac21f918f23ce95fd5be807428ee9e2c42319878Evan Hunt DO("schedule recv", isccc_ccmsg_readmessage(&ccmsg, task,
ac21f918f23ce95fd5be807428ee9e2c42319878Evan Hunt DO("send message", isc_socket_send(sock, &r, task, rndc_senddone,
f5b7359c5730d39ff6eff24ae87c9c74a04c2e5cMark Andrewsrndc_startconnect(isc_sockaddr_t *addr, isc_task_t *task) {
f5b7359c5730d39ff6eff24ae87c9c74a04c2e5cMark Andrews isc_sockaddr_format(addr, socktext, sizeof(socktext));
f5b7359c5730d39ff6eff24ae87c9c74a04c2e5cMark Andrews notify("using server %s (%s)", servername, socktext);
f5b7359c5730d39ff6eff24ae87c9c74a04c2e5cMark Andrews DO("create socket", isc_socket_create(socketmgr, pf, type, &sock));
1e8c2e72e7d0f48ac37b9b15712e638631b3b619Brian Wellington DO("bind socket", isc_socket_bind(sock, &local4, 0));
case AF_INET6:
NULL));
connects++;
currentaddr = 0;
const char *secretstr;
const char *algorithmstr;
if (c_flag)
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)