No empty .Rs/.Re
[netbsd-mini2440.git] / external / bsd / bind / dist / bin / named / control.c
blobbb7560de8a20856bacc33ec5b0b24d9abdb7afa1
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2004-2007, 2009 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 2001-2003 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: control.c,v 1.36 2009/10/12 20:48:11 each Exp */
22 /*! \file */
24 #include <config.h>
27 #include <isc/app.h>
28 #include <isc/event.h>
29 #include <isc/mem.h>
30 #include <isc/string.h>
31 #include <isc/timer.h>
32 #include <isc/util.h>
34 #include <dns/result.h>
36 #include <isccc/alist.h>
37 #include <isccc/cc.h>
38 #include <isccc/result.h>
40 #include <named/control.h>
41 #include <named/log.h>
42 #include <named/os.h>
43 #include <named/server.h>
44 #ifdef HAVE_LIBSCF
45 #include <named/ns_smf_globals.h>
46 #endif
48 static isc_boolean_t
49 command_compare(const char *text, const char *command) {
50 unsigned int commandlen = strlen(command);
51 if (strncasecmp(text, command, commandlen) == 0 &&
52 (text[commandlen] == '\0' ||
53 text[commandlen] == ' ' ||
54 text[commandlen] == '\t'))
55 return (ISC_TRUE);
56 return (ISC_FALSE);
59 /*%
60 * This function is called to process the incoming command
61 * when a control channel message is received.
63 isc_result_t
64 ns_control_docommand(isccc_sexpr_t *message, isc_buffer_t *text) {
65 isccc_sexpr_t *data;
66 char *command;
67 isc_result_t result;
68 int log_level;
69 #ifdef HAVE_LIBSCF
70 ns_smf_want_disable = 0;
71 #endif
73 data = isccc_alist_lookup(message, "_data");
74 if (data == NULL) {
76 * No data section.
78 return (ISC_R_FAILURE);
81 result = isccc_cc_lookupstring(data, "type", &command);
82 if (result != ISC_R_SUCCESS) {
84 * We have no idea what this is.
86 return (result);
90 * Compare the 'command' parameter against all known control commands.
92 if (command_compare(command, NS_COMMAND_NULL) ||
93 command_compare(command, NS_COMMAND_STATUS)) {
94 log_level = ISC_LOG_DEBUG(1);
95 } else {
96 log_level = ISC_LOG_INFO;
98 isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
99 NS_LOGMODULE_CONTROL, log_level,
100 "received control channel command '%s'",
101 command);
103 if (command_compare(command, NS_COMMAND_RELOAD)) {
104 result = ns_server_reloadcommand(ns_g_server, command, text);
105 } else if (command_compare(command, NS_COMMAND_RECONFIG)) {
106 result = ns_server_reconfigcommand(ns_g_server, command);
107 } else if (command_compare(command, NS_COMMAND_REFRESH)) {
108 result = ns_server_refreshcommand(ns_g_server, command, text);
109 } else if (command_compare(command, NS_COMMAND_RETRANSFER)) {
110 result = ns_server_retransfercommand(ns_g_server, command);
111 } else if (command_compare(command, NS_COMMAND_HALT)) {
112 #ifdef HAVE_LIBSCF
114 * If we are managed by smf(5), AND in chroot, then
115 * we cannot connect to the smf repository, so just
116 * return with an appropriate message back to rndc.
118 if (ns_smf_got_instance == 1 && ns_smf_chroot == 1) {
119 result = ns_smf_add_message(text);
120 return (result);
123 * If we are managed by smf(5) but not in chroot,
124 * try to disable ourselves the smf way.
126 if (ns_smf_got_instance == 1 && ns_smf_chroot == 0)
127 ns_smf_want_disable = 1;
129 * If ns_smf_got_instance = 0, ns_smf_chroot
130 * is not relevant and we fall through to
131 * isc_app_shutdown below.
133 #endif
134 ns_server_flushonshutdown(ns_g_server, ISC_FALSE);
135 ns_os_shutdownmsg(command, text);
136 isc_app_shutdown();
137 result = ISC_R_SUCCESS;
138 } else if (command_compare(command, NS_COMMAND_STOP)) {
139 #ifdef HAVE_LIBSCF
140 if (ns_smf_got_instance == 1 && ns_smf_chroot == 1) {
141 result = ns_smf_add_message(text);
142 return (result);
144 if (ns_smf_got_instance == 1 && ns_smf_chroot == 0)
145 ns_smf_want_disable = 1;
146 #endif
147 ns_server_flushonshutdown(ns_g_server, ISC_TRUE);
148 ns_os_shutdownmsg(command, text);
149 isc_app_shutdown();
150 result = ISC_R_SUCCESS;
151 } else if (command_compare(command, NS_COMMAND_DUMPSTATS)) {
152 result = ns_server_dumpstats(ns_g_server);
153 } else if (command_compare(command, NS_COMMAND_QUERYLOG)) {
154 result = ns_server_togglequerylog(ns_g_server);
155 } else if (command_compare(command, NS_COMMAND_DUMPDB)) {
156 ns_server_dumpdb(ns_g_server, command);
157 result = ISC_R_SUCCESS;
158 } else if (command_compare(command, NS_COMMAND_TRACE)) {
159 result = ns_server_setdebuglevel(ns_g_server, command);
160 } else if (command_compare(command, NS_COMMAND_NOTRACE)) {
161 ns_g_debuglevel = 0;
162 isc_log_setdebuglevel(ns_g_lctx, ns_g_debuglevel);
163 result = ISC_R_SUCCESS;
164 } else if (command_compare(command, NS_COMMAND_FLUSH)) {
165 result = ns_server_flushcache(ns_g_server, command);
166 } else if (command_compare(command, NS_COMMAND_FLUSHNAME)) {
167 result = ns_server_flushname(ns_g_server, command);
168 } else if (command_compare(command, NS_COMMAND_STATUS)) {
169 result = ns_server_status(ns_g_server, text);
170 } else if (command_compare(command, NS_COMMAND_TSIGLIST)) {
171 result = ns_server_tsiglist(ns_g_server, text);
172 } else if (command_compare(command, NS_COMMAND_TSIGDELETE)) {
173 result = ns_server_tsigdelete(ns_g_server, command, text);
174 } else if (command_compare(command, NS_COMMAND_FREEZE)) {
175 result = ns_server_freeze(ns_g_server, ISC_TRUE, command,
176 text);
177 } else if (command_compare(command, NS_COMMAND_UNFREEZE) ||
178 command_compare(command, NS_COMMAND_THAW)) {
179 result = ns_server_freeze(ns_g_server, ISC_FALSE, command,
180 text);
181 } else if (command_compare(command, NS_COMMAND_RECURSING)) {
182 result = ns_server_dumprecursing(ns_g_server);
183 } else if (command_compare(command, NS_COMMAND_TIMERPOKE)) {
184 result = ISC_R_SUCCESS;
185 isc_timermgr_poke(ns_g_timermgr);
186 } else if (command_compare(command, NS_COMMAND_NULL)) {
187 result = ISC_R_SUCCESS;
188 } else if (command_compare(command, NS_COMMAND_NOTIFY)) {
189 result = ns_server_notifycommand(ns_g_server, command, text);
190 } else if (command_compare(command, NS_COMMAND_VALIDATION)) {
191 result = ns_server_validation(ns_g_server, command);
192 } else if (command_compare(command, NS_COMMAND_SIGN)) {
193 result = ns_server_sign(ns_g_server, command);
194 } else {
195 isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
196 NS_LOGMODULE_CONTROL, ISC_LOG_WARNING,
197 "unknown control channel command '%s'",
198 command);
199 result = DNS_R_UNKNOWNCOMMAND;
202 return (result);