]> jfr.im git - solanum.git/blame - modules/m_rehash.c
add help for `chm_regmsg`
[solanum.git] / modules / m_rehash.c
CommitLineData
212380e3
AC
1/*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_rehash.c: Re-reads the configuration file.
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
212380e3
AC
23 */
24
25#include "stdinc.h"
26#include "client.h"
27#include "channel.h"
4562c604 28#include "match.h"
212380e3 29#include "ircd.h"
212380e3
AC
30#include "s_serv.h"
31#include "numeric.h"
212380e3
AC
32#include "s_conf.h"
33#include "s_newconf.h"
4016731b 34#include "logger.h"
212380e3
AC
35#include "send.h"
36#include "msg.h"
37#include "parse.h"
38#include "modules.h"
39#include "hostmask.h"
40#include "reject.h"
41#include "hash.h"
42#include "cache.h"
a4bf26dd 43#include "rb_radixtree.h"
eb1b303d 44#include "sslproc.h"
212380e3 45
114d98b3
AW
46static const char rehash_desc[] =
47 "Provides the REHASH command to reload configuration and other files";
212380e3 48
3c7d6fcc
EM
49static void mo_rehash(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
50static void me_rehash(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
eeabf33a 51
212380e3 52struct Message rehash_msgtab = {
7baa37a9 53 "REHASH", 0, 0, 0, 0,
212380e3
AC
54 {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_rehash, 0}, {mo_rehash, 0}}
55};
56
57mapi_clist_av1 rehash_clist[] = { &rehash_msgtab, NULL };
eeabf33a 58
114d98b3 59DECLARE_MODULE_AV2(rehash, NULL, NULL, rehash_clist, NULL, NULL, NULL, NULL, rehash_desc);
212380e3
AC
60
61struct hash_commands
62{
63 const char *cmd;
64 void (*handler) (struct Client * source_p);
65};
66
67static void
68rehash_bans_loc(struct Client *source_p)
69{
70 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is rehashing bans",
71 get_oper_name(source_p));
61b7e0d9
JT
72 if (!MyConnect(source_p))
73 remote_rehash_oper_p = source_p;
212380e3 74
ab31d2b0 75 rehash_bans();
212380e3
AC
76}
77
78static void
79rehash_dns(struct Client *source_p)
80{
55abcbb2 81 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is rehashing DNS",
212380e3 82 get_oper_name(source_p));
61b7e0d9
JT
83 if (!MyConnect(source_p))
84 remote_rehash_oper_p = source_p;
212380e3 85
6445c1cf 86 reload_nameservers();
212380e3
AC
87}
88
eb1b303d
SA
89static void
90rehash_ssld(struct Client *source_p)
91{
fbd3e77e
KB
92 if (!IsOperAdmin(source_p))
93 {
94 sendto_one(source_p, form_str(ERR_NOPRIVS),
95 me.name, source_p->name, "admin");
96 return;
97 }
98
eb1b303d
SA
99 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is restarting ssld",
100 get_oper_name(source_p));
101
102 restart_ssld();
103}
104
212380e3
AC
105static void
106rehash_motd(struct Client *source_p)
107{
108 sendto_realops_snomask(SNO_GENERAL, L_ALL,
109 "%s is forcing re-reading of MOTD file",
110 get_oper_name(source_p));
61b7e0d9
JT
111 if (!MyConnect(source_p))
112 remote_rehash_oper_p = source_p;
212380e3 113
041d54ff 114 cache_user_motd();
212380e3
AC
115}
116
117static void
118rehash_omotd(struct Client *source_p)
119{
120 sendto_realops_snomask(SNO_GENERAL, L_ALL,
121 "%s is forcing re-reading of OPER MOTD file",
122 get_oper_name(source_p));
61b7e0d9
JT
123 if (!MyConnect(source_p))
124 remote_rehash_oper_p = source_p;
212380e3
AC
125
126 free_cachefile(oper_motd);
4d8cfacd 127 oper_motd = cache_file(ircd_paths[IRCD_PATH_IRCD_OMOTD], "opers.motd", 0);
212380e3
AC
128}
129
212380e3
AC
130static void
131rehash_tklines(struct Client *source_p)
132{
133 struct ConfItem *aconf;
637c4932 134 rb_dlink_node *ptr, *next_ptr;
212380e3
AC
135 int i;
136
137 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp klines",
138 get_oper_name(source_p));
61b7e0d9
JT
139 if (!MyConnect(source_p))
140 remote_rehash_oper_p = source_p;
212380e3
AC
141
142 for(i = 0; i < LAST_TEMP_TYPE; i++)
143 {
637c4932 144 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, temp_klines[i].head)
212380e3
AC
145 {
146 aconf = ptr->data;
147
148 delete_one_address_conf(aconf->host, aconf);
555ac41f 149 rb_dlinkDestroy(ptr, &temp_klines[i]);
212380e3
AC
150 }
151 }
152}
153
154static void
155rehash_tdlines(struct Client *source_p)
156{
157 struct ConfItem *aconf;
637c4932 158 rb_dlink_node *ptr, *next_ptr;
212380e3
AC
159 int i;
160
161 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp dlines",
162 get_oper_name(source_p));
61b7e0d9
JT
163 if (!MyConnect(source_p))
164 remote_rehash_oper_p = source_p;
212380e3
AC
165
166 for(i = 0; i < LAST_TEMP_TYPE; i++)
167 {
637c4932 168 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, temp_dlines[i].head)
212380e3
AC
169 {
170 aconf = ptr->data;
171
172 delete_one_address_conf(aconf->host, aconf);
555ac41f 173 rb_dlinkDestroy(ptr, &temp_dlines[i]);
212380e3
AC
174 }
175 }
176}
177
178static void
179rehash_txlines(struct Client *source_p)
180{
181 struct ConfItem *aconf;
5b96d9a6 182 rb_dlink_node *ptr;
637c4932 183 rb_dlink_node *next_ptr;
212380e3
AC
184
185 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp xlines",
186 get_oper_name(source_p));
61b7e0d9
JT
187 if (!MyConnect(source_p))
188 remote_rehash_oper_p = source_p;
212380e3 189
637c4932 190 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, xline_conf_list.head)
212380e3
AC
191 {
192 aconf = ptr->data;
193
97f44d34 194 if(!aconf->hold || aconf->lifetime)
212380e3
AC
195 continue;
196
197 free_conf(aconf);
555ac41f 198 rb_dlinkDestroy(ptr, &xline_conf_list);
212380e3
AC
199 }
200}
201
202static void
203rehash_tresvs(struct Client *source_p)
204{
205 struct ConfItem *aconf;
2fc6772e 206 rb_radixtree_iteration_state iter;
5b96d9a6 207 rb_dlink_node *ptr;
637c4932 208 rb_dlink_node *next_ptr;
212380e3
AC
209
210 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp resvs",
211 get_oper_name(source_p));
61b7e0d9
JT
212 if (!MyConnect(source_p))
213 remote_rehash_oper_p = source_p;
212380e3 214
a4bf26dd 215 RB_RADIXTREE_FOREACH(aconf, &iter, resv_tree)
212380e3 216 {
97f44d34 217 if(!aconf->hold || aconf->lifetime)
212380e3
AC
218 continue;
219
a4bf26dd 220 rb_radixtree_delete(resv_tree, aconf->host);
212380e3 221 free_conf(aconf);
212380e3 222 }
212380e3 223
637c4932 224 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, resv_conf_list.head)
212380e3
AC
225 {
226 aconf = ptr->data;
227
97f44d34 228 if(!aconf->hold || aconf->lifetime)
212380e3
AC
229 continue;
230
231 free_conf(aconf);
555ac41f 232 rb_dlinkDestroy(ptr, &resv_conf_list);
212380e3
AC
233 }
234}
235
236static void
237rehash_rejectcache(struct Client *source_p)
238{
239 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing reject cache",
240 get_oper_name(source_p));
61b7e0d9
JT
241 if (!MyConnect(source_p))
242 remote_rehash_oper_p = source_p;
212380e3
AC
243 flush_reject();
244
245}
246
995f300e
JT
247static void
248rehash_throttles(struct Client *source_p)
249{
250 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing throttles",
251 get_oper_name(source_p));
61b7e0d9
JT
252 if (!MyConnect(source_p))
253 remote_rehash_oper_p = source_p;
995f300e
JT
254 flush_throttle();
255
256}
257
212380e3
AC
258static void
259rehash_help(struct Client *source_p)
260{
261 sendto_realops_snomask(SNO_GENERAL, L_ALL,
55abcbb2 262 "%s is forcing re-reading of HELP files",
212380e3 263 get_oper_name(source_p));
61b7e0d9
JT
264 if (!MyConnect(source_p))
265 remote_rehash_oper_p = source_p;
212380e3
AC
266 load_help();
267}
268
269static void
270rehash_nickdelay(struct Client *source_p)
271{
272 struct nd_entry *nd;
5b96d9a6
AC
273 rb_dlink_node *ptr;
274 rb_dlink_node *safe_ptr;
212380e3
AC
275
276 sendto_realops_snomask(SNO_GENERAL, L_ALL,
277 "%s is clearing the nick delay table",
278 get_oper_name(source_p));
61b7e0d9
JT
279 if (!MyConnect(source_p))
280 remote_rehash_oper_p = source_p;
212380e3 281
5b96d9a6 282 RB_DLINK_FOREACH_SAFE(ptr, safe_ptr, nd_list.head)
212380e3
AC
283 {
284 nd = ptr->data;
55abcbb2 285
212380e3
AC
286 free_nd_entry(nd);
287 }
288}
289
290/* *INDENT-OFF* */
291static struct hash_commands rehash_commands[] =
292{
293 {"BANS", rehash_bans_loc },
294 {"DNS", rehash_dns },
eb1b303d 295 {"SSLD", rehash_ssld },
212380e3
AC
296 {"MOTD", rehash_motd },
297 {"OMOTD", rehash_omotd },
212380e3
AC
298 {"TKLINES", rehash_tklines },
299 {"TDLINES", rehash_tdlines },
300 {"TXLINES", rehash_txlines },
301 {"TRESVS", rehash_tresvs },
302 {"REJECTCACHE", rehash_rejectcache },
995f300e 303 {"THROTTLES", rehash_throttles },
212380e3
AC
304 {"HELP", rehash_help },
305 {"NICKDELAY", rehash_nickdelay },
306 {NULL, NULL }
307};
308/* *INDENT-ON* */
309
310static void
311do_rehash(struct Client *source_p, const char *type)
312{
313 if (type != NULL)
314 {
315 int x;
316 char cmdbuf[100];
317
318 for (x = 0; rehash_commands[x].cmd != NULL && rehash_commands[x].handler != NULL;
319 x++)
320 {
321 if(irccmp(type, rehash_commands[x].cmd) == 0)
322 {
323 sendto_one(source_p, form_str(RPL_REHASHING), me.name,
324 source_p->name, rehash_commands[x].cmd);
212380e3
AC
325 ilog(L_MAIN, "REHASH %s From %s[%s]", type,
326 get_oper_name(source_p), source_p->sockhost);
61b7e0d9
JT
327 rehash_commands[x].handler(source_p);
328 remote_rehash_oper_p = NULL;
212380e3
AC
329 return;
330 }
331 }
332
333 /* We are still here..we didn't match */
334 cmdbuf[0] = '\0';
335 for (x = 0; rehash_commands[x].cmd != NULL && rehash_commands[x].handler != NULL;
336 x++)
337 {
1f9de103
VY
338 rb_strlcat(cmdbuf, " ", sizeof(cmdbuf));
339 rb_strlcat(cmdbuf, rehash_commands[x].cmd, sizeof(cmdbuf));
212380e3 340 }
5366977b 341 sendto_one_notice(source_p, ":rehash one of:%s", cmdbuf);
212380e3
AC
342 }
343 else
344 {
345 sendto_one(source_p, form_str(RPL_REHASHING), me.name, source_p->name,
346 ConfigFileEntry.configfile);
347 sendto_realops_snomask(SNO_GENERAL, L_ALL,
348 "%s is rehashing server config file", get_oper_name(source_p));
61b7e0d9
JT
349 if (!MyConnect(source_p))
350 remote_rehash_oper_p = source_p;
212380e3
AC
351 ilog(L_MAIN, "REHASH From %s[%s]", get_oper_name(source_p),
352 source_p->sockhost);
c0483ac1 353 rehash(false);
61b7e0d9 354 remote_rehash_oper_p = NULL;
212380e3
AC
355 }
356}
357
358/*
359 * mo_rehash - REHASH message handler
360 *
361 * parv[1] = rehash type or destination
362 * parv[2] = destination
363 */
3c7d6fcc 364static void
428ca87b 365mo_rehash(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
366{
367 const char *type = NULL, *target_server = NULL;
368
369 if(!IsOperRehash(source_p))
370 {
371 sendto_one(source_p, form_str(ERR_NOPRIVS),
372 me.name, source_p->name, "rehash");
3c7d6fcc 373 return;
212380e3
AC
374 }
375
376 if (parc > 2)
377 type = parv[1], target_server = parv[2];
378 else if (parc > 1 && (strchr(parv[1], '.') || strchr(parv[1], '?') || strchr(parv[1], '*')))
379 type = NULL, target_server = parv[1];
380 else if (parc > 1)
381 type = parv[1], target_server = NULL;
382 else
383 type = NULL, target_server = NULL;
384
385 if (target_server != NULL)
386 {
387 if(!IsOperRemoteBan(source_p))
388 {
389 sendto_one(source_p, form_str(ERR_NOPRIVS),
390 me.name, source_p->name, "remoteban");
3c7d6fcc 391 return;
212380e3
AC
392 }
393 sendto_match_servs(source_p, target_server,
394 CAP_ENCAP, NOCAPS,
395 "ENCAP %s REHASH %s",
396 target_server, type != NULL ? type : "");
397 if (match(target_server, me.name) == 0)
3c7d6fcc 398 return;
212380e3
AC
399 }
400
401 do_rehash(source_p, type);
212380e3
AC
402}
403
3c7d6fcc 404static void
428ca87b 405me_rehash(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
406{
407
408 if (!IsPerson(source_p))
3c7d6fcc 409 return;
212380e3 410
212380e3 411 do_rehash(source_p, parc > 1 ? parv[1] : NULL);
212380e3 412}