control.c revision d4859b0b2a0510d8c4f3c48c606a5568a3b0c1d8
d362465c77b375be2707bc83cebc731d0645d12dAutomatic Updater * Copyright (C) 2004-2007, 2009-2014 Internet Systems Consortium, Inc. ("ISC")
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * Copyright (C) 2001-2003 Internet Software Consortium.
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * Permission to use, copy, modify, and/or distribute this software for any
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley * purpose with or without fee is hereby granted, provided that the above
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley * copyright notice and this permission notice appear in all copies.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * PERFORMANCE OF THIS SOFTWARE.
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews/* $Id: control.c,v 1.49 2012/01/31 23:47:31 tbox Exp $ */
5619558151f1aa4249b3ead979e76876e29278b6Bob Halleycommand_compare(const char *text, const char *command) {
904a5734375869ffb504ed8cde6b68cafadb6d64Bob Halley if (strncasecmp(text, command, commandlen) == 0 &&
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley * This function is called to process the incoming command
80b782f356f0692c11b4e52e8dd46ec41704e5a2Mark Andrews * when a control channel message is received.
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrewsns_control_docommand(isccc_sexpr_t *message, isc_buffer_t *text) {
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * No data section.
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley result = isccc_cc_lookupstring(data, "type", &command);
b12f0228b32775ee688ed21ddbf3a116c1adfb43Michael Graff * We have no idea what this is.
e496615043400500492fa7b891c515c8e7cb7d08Bob Halley * Compare the 'command' parameter against all known control commands.
078d49b63324f01d98301ee21671abee0c41fcdeBob Halley "received control channel command '%s'",
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley if (command_compare(command, NS_COMMAND_RELOAD)) {
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley result = ns_server_reloadcommand(ns_g_server, command, text);
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley } else if (command_compare(command, NS_COMMAND_RECONFIG)) {
904a5734375869ffb504ed8cde6b68cafadb6d64Bob Halley result = ns_server_reconfigcommand(ns_g_server, command);
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley } else if (command_compare(command, NS_COMMAND_REFRESH)) {
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley result = ns_server_refreshcommand(ns_g_server, command, text);
ca67883a666bdf314d3da958d5195e7215b1f797Bob Halley } else if (command_compare(command, NS_COMMAND_RETRANSFER)) {
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley result = ns_server_retransfercommand(ns_g_server,
61fb42c4ef45d88e115bd769c30c4f36b461870bMark Andrews } else if (command_compare(command, NS_COMMAND_HALT)) {
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley * If we are managed by smf(5), AND in chroot, then
80b782f356f0692c11b4e52e8dd46ec41704e5a2Mark Andrews * we cannot connect to the smf repository, so just
e496615043400500492fa7b891c515c8e7cb7d08Bob Halley * return with an appropriate message back to rndc.
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley if (ns_smf_got_instance == 1 && ns_smf_chroot == 1) {
28640d1da26d561f4137122fe64e9e8cc08bf11eBob Halley * If we are managed by smf(5) but not in chroot,
28640d1da26d561f4137122fe64e9e8cc08bf11eBob Halley * try to disable ourselves the smf way.
28640d1da26d561f4137122fe64e9e8cc08bf11eBob Halley if (ns_smf_got_instance == 1 && ns_smf_chroot == 0)
28640d1da26d561f4137122fe64e9e8cc08bf11eBob Halley * If ns_smf_got_instance = 0, ns_smf_chroot
28640d1da26d561f4137122fe64e9e8cc08bf11eBob Halley * is not relevant and we fall through to
28640d1da26d561f4137122fe64e9e8cc08bf11eBob Halley * isc_app_shutdown below.
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley /* Do not flush master files */
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley ns_server_flushonshutdown(ns_g_server, ISC_FALSE);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff } else if (command_compare(command, NS_COMMAND_STOP)) {
e02884167b7c969b56413f76c48c3802c4dca14dAndreas Gustafsson * "stop" is the same as "halt" except it does
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater * flush master files.
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley if (ns_smf_got_instance == 1 && ns_smf_chroot == 1) {
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley if (ns_smf_got_instance == 1 && ns_smf_chroot == 0)
e02884167b7c969b56413f76c48c3802c4dca14dAndreas Gustafsson ns_server_flushonshutdown(ns_g_server, ISC_TRUE);
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley } else if (command_compare(command, NS_COMMAND_DUMPSTATS)) {
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley } else if (command_compare(command, NS_COMMAND_QUERYLOG)) {
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley result = ns_server_togglequerylog(ns_g_server, command);
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley } else if (command_compare(command, NS_COMMAND_DUMPDB)) {
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley } else if (command_compare(command, NS_COMMAND_SECROOTS)) {
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley result = ns_server_dumpsecroots(ns_g_server, command);
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley } else if (command_compare(command, NS_COMMAND_TRACE)) {
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley result = ns_server_setdebuglevel(ns_g_server, command);
e02884167b7c969b56413f76c48c3802c4dca14dAndreas Gustafsson } else if (command_compare(command, NS_COMMAND_NOTRACE)) {
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley isc_log_setdebuglevel(ns_g_lctx, ns_g_debuglevel);
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley } else if (command_compare(command, NS_COMMAND_FLUSH)) {
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley result = ns_server_flushcache(ns_g_server, command);
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley } else if (command_compare(command, NS_COMMAND_FLUSHNAME)) {
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley result = ns_server_flushnode(ns_g_server, command, ISC_FALSE);
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley } else if (command_compare(command, NS_COMMAND_FLUSHTREE)) {
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley result = ns_server_flushnode(ns_g_server, command, ISC_TRUE);
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley } else if (command_compare(command, NS_COMMAND_STATUS)) {
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews } else if (command_compare(command, NS_COMMAND_TSIGLIST)) {
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews result = ns_server_tsiglist(ns_g_server, text);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 } else if (command_compare(command, NS_COMMAND_TSIGDELETE)) {
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = ns_server_tsigdelete(ns_g_server, command, text);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 } else if (command_compare(command, NS_COMMAND_FREEZE)) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = ns_server_freeze(ns_g_server, ISC_TRUE, command,
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews } else if (command_compare(command, NS_COMMAND_UNFREEZE) ||
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews result = ns_server_freeze(ns_g_server, ISC_FALSE, command,
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley } else if (command_compare(command, NS_COMMAND_SCAN)) {
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley } else if (command_compare(command, NS_COMMAND_SYNC)) {
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley result = ns_server_sync(ns_g_server, command, text);
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley } else if (command_compare(command, NS_COMMAND_RECURSING)) {
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley } else if (command_compare(command, NS_COMMAND_TIMERPOKE)) {
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley } else if (command_compare(command, NS_COMMAND_NULL)) {
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley } else if (command_compare(command, NS_COMMAND_NOTIFY)) {
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley result = ns_server_notifycommand(ns_g_server, command, text);
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley } else if (command_compare(command, NS_COMMAND_VALIDATION)) {
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley result = ns_server_validation(ns_g_server, command, text);
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley } else if (command_compare(command, NS_COMMAND_SIGN) ||
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley result = ns_server_rekey(ns_g_server, command, text);
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley } else if (command_compare(command, NS_COMMAND_ADDZONE)) {
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley result = ns_server_add_zone(ns_g_server, command, text);
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley } else if (command_compare(command, NS_COMMAND_DELZONE)) {
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley result = ns_server_del_zone(ns_g_server, command, text);
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley } else if (command_compare(command, NS_COMMAND_SIGNING)) {
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley result = ns_server_signing(ns_g_server, command, text);
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley } else if (command_compare(command, NS_COMMAND_ZONESTATUS)) {
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley result = ns_server_zonestatus(ns_g_server, command, text);
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley } else if (command_compare(command, NS_COMMAND_NTA)) {
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley result = ns_server_nta(ns_g_server, command, text);
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley "unknown control channel command '%s'",