]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bind9/bin/named/control.c
This commit was generated by cvs2svn to compensate for changes in r151940,
[FreeBSD/FreeBSD.git] / contrib / bind9 / bin / named / control.c
1 /*
2  * Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 2001-2003  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15  * PERFORMANCE OF THIS SOFTWARE.
16  */
17
18 /* $Id: control.c,v 1.7.2.2.2.11 2004/09/03 03:43:31 marka Exp $ */
19
20 #include <config.h>
21
22 #include <string.h>
23
24 #include <isc/app.h>
25 #include <isc/event.h>
26 #include <isc/mem.h>
27 #include <isc/timer.h>
28 #include <isc/util.h>
29
30 #include <dns/result.h>
31
32 #include <isccc/alist.h>
33 #include <isccc/cc.h>
34 #include <isccc/result.h>
35
36 #include <named/control.h>
37 #include <named/log.h>
38 #include <named/os.h>
39 #include <named/server.h>
40
41 static isc_boolean_t
42 command_compare(const char *text, const char *command) {
43         unsigned int commandlen = strlen(command);
44         if (strncasecmp(text, command, commandlen) == 0 &&
45             (text[commandlen] == '\0' ||
46              text[commandlen] == ' ' ||
47              text[commandlen] == '\t'))
48                 return (ISC_TRUE);
49         return (ISC_FALSE);
50 }
51
52 /*
53  * This function is called to process the incoming command
54  * when a control channel message is received.  
55  */
56 isc_result_t
57 ns_control_docommand(isccc_sexpr_t *message, isc_buffer_t *text) {
58         isccc_sexpr_t *data;
59         char *command;
60         isc_result_t result;
61
62         data = isccc_alist_lookup(message, "_data");
63         if (data == NULL) {
64                 /*
65                  * No data section.
66                  */
67                 return (ISC_R_FAILURE);
68         }
69
70         result = isccc_cc_lookupstring(data, "type", &command);
71         if (result != ISC_R_SUCCESS) {
72                 /*
73                  * We have no idea what this is.
74                  */
75                 return (result);
76         }
77
78         isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
79                       NS_LOGMODULE_CONTROL, ISC_LOG_DEBUG(1),
80                       "received control channel command '%s'",
81                       command);
82
83         /*
84          * Compare the 'command' parameter against all known control commands.
85          */
86         if (command_compare(command, NS_COMMAND_RELOAD)) {
87                 result = ns_server_reloadcommand(ns_g_server, command, text);
88         } else if (command_compare(command, NS_COMMAND_RECONFIG)) {
89                 result = ns_server_reconfigcommand(ns_g_server, command);
90         } else if (command_compare(command, NS_COMMAND_REFRESH)) {
91                 result = ns_server_refreshcommand(ns_g_server, command, text);
92         } else if (command_compare(command, NS_COMMAND_RETRANSFER)) {
93                 result = ns_server_retransfercommand(ns_g_server, command);
94         } else if (command_compare(command, NS_COMMAND_HALT)) {
95                 ns_server_flushonshutdown(ns_g_server, ISC_FALSE);
96                 ns_os_shutdownmsg(command, text);
97                 isc_app_shutdown();
98                 result = ISC_R_SUCCESS;
99         } else if (command_compare(command, NS_COMMAND_STOP)) {
100                 ns_server_flushonshutdown(ns_g_server, ISC_TRUE);
101                 ns_os_shutdownmsg(command, text);
102                 isc_app_shutdown();
103                 result = ISC_R_SUCCESS;
104         } else if (command_compare(command, NS_COMMAND_DUMPSTATS)) {
105                 result = ns_server_dumpstats(ns_g_server);
106         } else if (command_compare(command, NS_COMMAND_QUERYLOG)) {
107                 result = ns_server_togglequerylog(ns_g_server);
108         } else if (command_compare(command, NS_COMMAND_DUMPDB)) {
109                 ns_server_dumpdb(ns_g_server, command);
110                 result = ISC_R_SUCCESS;
111         } else if (command_compare(command, NS_COMMAND_TRACE)) {
112                 result = ns_server_setdebuglevel(ns_g_server, command);
113         } else if (command_compare(command, NS_COMMAND_NOTRACE)) {
114                 ns_g_debuglevel = 0;
115                 isc_log_setdebuglevel(ns_g_lctx, ns_g_debuglevel);
116                 result = ISC_R_SUCCESS;
117         } else if (command_compare(command, NS_COMMAND_FLUSH)) {
118                 result = ns_server_flushcache(ns_g_server, command);
119         } else if (command_compare(command, NS_COMMAND_FLUSHNAME)) {
120                 result = ns_server_flushname(ns_g_server, command);
121         } else if (command_compare(command, NS_COMMAND_STATUS)) {
122                 result = ns_server_status(ns_g_server, text);
123         } else if (command_compare(command, NS_COMMAND_FREEZE)) {
124                 result = ns_server_freeze(ns_g_server, ISC_TRUE, command);
125         } else if (command_compare(command, NS_COMMAND_UNFREEZE) ||
126                    command_compare(command, NS_COMMAND_THAW)) {
127                 result = ns_server_freeze(ns_g_server, ISC_FALSE, command);
128         } else if (command_compare(command, NS_COMMAND_RECURSING)) {
129                 result = ns_server_dumprecursing(ns_g_server);
130         } else if (command_compare(command, NS_COMMAND_NULL)) {
131                 result = ISC_R_SUCCESS;
132         } else {
133                 isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
134                               NS_LOGMODULE_CONTROL, ISC_LOG_WARNING,
135                               "unknown control channel command '%s'",
136                               command);
137                 result = DNS_R_UNKNOWNCOMMAND;
138         }
139
140         return (result);
141 }