ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_rehash.c
Revision: 9857
Committed: Fri Jan 1 04:43:22 2021 UTC (4 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 6570 byte(s)
Log Message:
- Bump copyright years

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2021 ircd-hybrid development team
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA
20 */
21
22 /*! \file m_rehash.c
23 * \brief Includes required functions for processing the REHASH command.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "client.h"
29 #include "irc_string.h"
30 #include "ircd.h"
31 #include "list.h"
32 #include "numeric.h"
33 #include "res.h"
34 #include "conf.h"
35 #include "conf_shared.h"
36 #include "log.h"
37 #include "send.h"
38 #include "parse.h"
39 #include "modules.h"
40 #include "motd.h"
41
42
43 /*! \brief REHASH CONF handler
44 * Attempts to reload server's configuration file(s)
45 * \param source_p Pointer to client issuing the command
46 */
47 static void
48 rehash_conf(struct Client *source_p)
49 {
50 sendto_one_numeric(source_p, &me, RPL_REHASHING, "CONF");
51 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
52 "%s is rehashing configuration file(s)",
53 get_oper_name(source_p));
54 ilog(LOG_TYPE_IRCD, "REHASH CONF from %s",
55 get_oper_name(source_p));
56 conf_rehash(false);
57 }
58
59 /*! \brief REHASH MOTD handler
60 * Attempts to recache server's MOTD file(s)
61 * \param source_p Pointer to client issuing the command
62 */
63 static void
64 rehash_motd(struct Client *source_p)
65 {
66 sendto_one_numeric(source_p, &me, RPL_REHASHING, "MOTD");
67 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
68 "%s is forcing re-reading of MOTD files",
69 get_oper_name(source_p));
70 ilog(LOG_TYPE_IRCD, "REHASH MOTD from %s",
71 get_oper_name(source_p));
72 motd_recache();
73 }
74
75 /*! \brief REHASH DNS handler
76 * Attempts to restart server's resolver
77 * \param source_p Pointer to client issuing the command
78 */
79 static void
80 rehash_dns(struct Client *source_p)
81 {
82 sendto_one_numeric(source_p, &me, RPL_REHASHING, "DNS");
83 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
84 "%s is rehashing DNS",
85 get_oper_name(source_p));
86 ilog(LOG_TYPE_IRCD, "REHASH DNS from %s",
87 get_oper_name(source_p));
88 restart_resolver();
89 }
90
91 struct RehashStruct
92 {
93 const char *const option;
94 void (*const handler)(struct Client *);
95 };
96
97 static const struct RehashStruct rehash_cmd_table[] =
98 {
99 { .option = "CONF", .handler = rehash_conf },
100 { .option = "MOTD", .handler = rehash_motd },
101 { .option = "DNS", .handler = rehash_dns },
102 { .option = NULL }
103 };
104
105 /*! \brief REHASH command handler
106 *
107 * \param source_p Pointer to allocated Client struct from which the message
108 * originally comes from. This can be a local or remote client.
109 * \param parc Integer holding the number of supplied arguments.
110 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
111 * pointers.
112 * \note Valid arguments for this command are:
113 * - parv[0] = command
114 * - parv[1] = option [CONF, DNS, MOTD]
115 * or for remote REHASH:
116 * - parv[0] = command
117 * - parv[1] = target server mask
118 * - parv[2] = option [CONF, DNS, MOTD]
119 */
120 static void
121 mo_rehash(struct Client *source_p, int parc, char *parv[])
122 {
123 const char *option = NULL;
124 const char *server = NULL;
125
126 if (parc < 3)
127 {
128 if (!HasOFlag(source_p, OPER_FLAG_REHASH))
129 {
130 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "rehash");
131 return;
132 }
133
134 option = parv[1];
135 }
136 else
137 {
138 if (!HasOFlag(source_p, OPER_FLAG_REHASH_REMOTE))
139 {
140 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "rehash:remote");
141 return;
142 }
143
144 server = parv[1];
145 option = parv[2];
146 }
147
148 for (const struct RehashStruct *tab = rehash_cmd_table; tab->handler; ++tab)
149 {
150 if (irccmp(tab->option, option))
151 continue;
152
153 if (!EmptyString(server))
154 sendto_match_servs(source_p, server, 0, "REHASH %s %s", server, option);
155
156 if (EmptyString(server) || match(server, me.name) == 0)
157 tab->handler(source_p);
158
159 return;
160 }
161
162 sendto_one_notice(source_p, &me, ":%s is not a valid option. "
163 "Choose from CONF, DNS, MOTD",
164 option);
165 }
166
167 /*! \brief REHASH command handler
168 *
169 * \param source_p Pointer to allocated Client struct from which the message
170 * originally comes from. This can be a local or remote client.
171 * \param parc Integer holding the number of supplied arguments.
172 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
173 * pointers.
174 * \note Valid arguments for this command are:
175 * - parv[0] = command
176 * - parv[1] = target server mask
177 * - parv[2] = option [CONF, DNS, MOTD]
178 */
179 static void
180 ms_rehash(struct Client *source_p, int parc, char *parv[])
181 {
182 const char *const option = parv[2];
183 const char *const server = parv[1];
184
185 sendto_match_servs(source_p, server, 0, "REHASH %s %s", server, option);
186
187 if (match(server, me.name))
188 return;
189
190 if (!shared_find(SHARED_REHASH, source_p->servptr->name,
191 source_p->username, source_p->host))
192 return;
193
194 for (const struct RehashStruct *tab = rehash_cmd_table; tab->handler; ++tab)
195 {
196 if (irccmp(tab->option, option))
197 continue;
198
199 tab->handler(source_p);
200 return;
201 }
202 }
203
204 static struct Message rehash_msgtab =
205 {
206 .cmd = "REHASH",
207 .handlers[UNREGISTERED_HANDLER] = { .handler = m_unregistered },
208 .handlers[CLIENT_HANDLER] = { .handler = m_not_oper },
209 .handlers[SERVER_HANDLER] = { .handler = ms_rehash, .args_min = 3 },
210 .handlers[ENCAP_HANDLER] = { .handler = m_ignore },
211 .handlers[OPER_HANDLER] = { .handler = mo_rehash, .args_min = 2 }
212 };
213
214 static void
215 module_init(void)
216 {
217 mod_add_cmd(&rehash_msgtab);
218 }
219
220 static void
221 module_exit(void)
222 {
223 mod_del_cmd(&rehash_msgtab);
224 }
225
226 struct module module_entry =
227 {
228 .version = "$Revision$",
229 .modinit = module_init,
230 .modexit = module_exit,
231 };

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision