]> jfr.im git - solanum.git/blame - modules/m_rehash.c
librb: whoops, didn't realise this was needed... :x
[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"
28#include "common.h"
4562c604 29#include "match.h"
212380e3 30#include "ircd.h"
212380e3
AC
31#include "s_serv.h"
32#include "numeric.h"
212380e3
AC
33#include "s_conf.h"
34#include "s_newconf.h"
4016731b 35#include "logger.h"
212380e3
AC
36#include "send.h"
37#include "msg.h"
38#include "parse.h"
39#include "modules.h"
40#include "hostmask.h"
41#include "reject.h"
42#include "hash.h"
43#include "cache.h"
46be39fa 44#include "irc_radixtree.h"
eb1b303d 45#include "sslproc.h"
212380e3 46
428ca87b
AC
47static int mo_rehash(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
48static int me_rehash(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
212380e3
AC
49
50struct Message rehash_msgtab = {
7baa37a9 51 "REHASH", 0, 0, 0, 0,
212380e3
AC
52 {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_rehash, 0}, {mo_rehash, 0}}
53};
54
55mapi_clist_av1 rehash_clist[] = { &rehash_msgtab, NULL };
5366977b 56DECLARE_MODULE_AV1(rehash, NULL, NULL, rehash_clist, NULL, NULL, "$Revision: 3161 $");
212380e3
AC
57
58struct hash_commands
59{
60 const char *cmd;
61 void (*handler) (struct Client * source_p);
62};
63
64static void
65rehash_bans_loc(struct Client *source_p)
66{
67 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is rehashing bans",
68 get_oper_name(source_p));
61b7e0d9
JT
69 if (!MyConnect(source_p))
70 remote_rehash_oper_p = source_p;
212380e3
AC
71
72 rehash_bans(0);
73}
74
75static void
76rehash_dns(struct Client *source_p)
77{
55abcbb2 78 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is rehashing DNS",
212380e3 79 get_oper_name(source_p));
61b7e0d9
JT
80 if (!MyConnect(source_p))
81 remote_rehash_oper_p = source_p;
212380e3
AC
82
83 /* reread /etc/resolv.conf and reopen res socket */
1eeb0469 84 restart_authd();
212380e3
AC
85}
86
eb1b303d
SA
87static void
88rehash_ssld(struct Client *source_p)
89{
90 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is restarting ssld",
91 get_oper_name(source_p));
92
93 restart_ssld();
94}
95
212380e3
AC
96static void
97rehash_motd(struct Client *source_p)
98{
99 sendto_realops_snomask(SNO_GENERAL, L_ALL,
100 "%s is forcing re-reading of MOTD file",
101 get_oper_name(source_p));
61b7e0d9
JT
102 if (!MyConnect(source_p))
103 remote_rehash_oper_p = source_p;
212380e3 104
041d54ff 105 cache_user_motd();
212380e3
AC
106}
107
108static void
109rehash_omotd(struct Client *source_p)
110{
111 sendto_realops_snomask(SNO_GENERAL, L_ALL,
112 "%s is forcing re-reading of OPER MOTD file",
113 get_oper_name(source_p));
61b7e0d9
JT
114 if (!MyConnect(source_p))
115 remote_rehash_oper_p = source_p;
212380e3
AC
116
117 free_cachefile(oper_motd);
118 oper_motd = cache_file(OPATH, "opers.motd", 0);
119}
120
212380e3
AC
121static void
122rehash_tklines(struct Client *source_p)
123{
124 struct ConfItem *aconf;
637c4932 125 rb_dlink_node *ptr, *next_ptr;
212380e3
AC
126 int i;
127
128 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp klines",
129 get_oper_name(source_p));
61b7e0d9
JT
130 if (!MyConnect(source_p))
131 remote_rehash_oper_p = source_p;
212380e3
AC
132
133 for(i = 0; i < LAST_TEMP_TYPE; i++)
134 {
637c4932 135 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, temp_klines[i].head)
212380e3
AC
136 {
137 aconf = ptr->data;
138
139 delete_one_address_conf(aconf->host, aconf);
555ac41f 140 rb_dlinkDestroy(ptr, &temp_klines[i]);
212380e3
AC
141 }
142 }
143}
144
145static void
146rehash_tdlines(struct Client *source_p)
147{
148 struct ConfItem *aconf;
637c4932 149 rb_dlink_node *ptr, *next_ptr;
212380e3
AC
150 int i;
151
152 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp dlines",
153 get_oper_name(source_p));
61b7e0d9
JT
154 if (!MyConnect(source_p))
155 remote_rehash_oper_p = source_p;
212380e3
AC
156
157 for(i = 0; i < LAST_TEMP_TYPE; i++)
158 {
637c4932 159 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, temp_dlines[i].head)
212380e3
AC
160 {
161 aconf = ptr->data;
162
163 delete_one_address_conf(aconf->host, aconf);
555ac41f 164 rb_dlinkDestroy(ptr, &temp_dlines[i]);
212380e3
AC
165 }
166 }
167}
168
169static void
170rehash_txlines(struct Client *source_p)
171{
172 struct ConfItem *aconf;
5b96d9a6 173 rb_dlink_node *ptr;
637c4932 174 rb_dlink_node *next_ptr;
212380e3
AC
175
176 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp xlines",
177 get_oper_name(source_p));
61b7e0d9
JT
178 if (!MyConnect(source_p))
179 remote_rehash_oper_p = source_p;
212380e3 180
637c4932 181 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, xline_conf_list.head)
212380e3
AC
182 {
183 aconf = ptr->data;
184
97f44d34 185 if(!aconf->hold || aconf->lifetime)
212380e3
AC
186 continue;
187
188 free_conf(aconf);
555ac41f 189 rb_dlinkDestroy(ptr, &xline_conf_list);
212380e3
AC
190 }
191}
192
193static void
194rehash_tresvs(struct Client *source_p)
195{
196 struct ConfItem *aconf;
46be39fa 197 struct irc_radixtree_iteration_state iter;
5b96d9a6 198 rb_dlink_node *ptr;
637c4932 199 rb_dlink_node *next_ptr;
212380e3
AC
200 int i;
201
202 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp resvs",
203 get_oper_name(source_p));
61b7e0d9
JT
204 if (!MyConnect(source_p))
205 remote_rehash_oper_p = source_p;
212380e3 206
46be39fa 207 IRC_RADIXTREE_FOREACH(aconf, &iter, resv_tree)
212380e3 208 {
97f44d34 209 if(!aconf->hold || aconf->lifetime)
212380e3
AC
210 continue;
211
46be39fa 212 irc_radixtree_delete(resv_tree, aconf->host);
212380e3 213 free_conf(aconf);
212380e3 214 }
212380e3 215
637c4932 216 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, resv_conf_list.head)
212380e3
AC
217 {
218 aconf = ptr->data;
219
97f44d34 220 if(!aconf->hold || aconf->lifetime)
212380e3
AC
221 continue;
222
223 free_conf(aconf);
555ac41f 224 rb_dlinkDestroy(ptr, &resv_conf_list);
212380e3
AC
225 }
226}
227
228static void
229rehash_rejectcache(struct Client *source_p)
230{
231 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing reject cache",
232 get_oper_name(source_p));
61b7e0d9
JT
233 if (!MyConnect(source_p))
234 remote_rehash_oper_p = source_p;
212380e3
AC
235 flush_reject();
236
237}
238
995f300e
JT
239static void
240rehash_throttles(struct Client *source_p)
241{
242 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing throttles",
243 get_oper_name(source_p));
61b7e0d9
JT
244 if (!MyConnect(source_p))
245 remote_rehash_oper_p = source_p;
995f300e
JT
246 flush_throttle();
247
248}
249
212380e3
AC
250static void
251rehash_help(struct Client *source_p)
252{
253 sendto_realops_snomask(SNO_GENERAL, L_ALL,
55abcbb2 254 "%s is forcing re-reading of HELP files",
212380e3 255 get_oper_name(source_p));
61b7e0d9
JT
256 if (!MyConnect(source_p))
257 remote_rehash_oper_p = source_p;
212380e3
AC
258 load_help();
259}
260
261static void
262rehash_nickdelay(struct Client *source_p)
263{
264 struct nd_entry *nd;
5b96d9a6
AC
265 rb_dlink_node *ptr;
266 rb_dlink_node *safe_ptr;
212380e3
AC
267
268 sendto_realops_snomask(SNO_GENERAL, L_ALL,
269 "%s is clearing the nick delay table",
270 get_oper_name(source_p));
61b7e0d9
JT
271 if (!MyConnect(source_p))
272 remote_rehash_oper_p = source_p;
212380e3 273
5b96d9a6 274 RB_DLINK_FOREACH_SAFE(ptr, safe_ptr, nd_list.head)
212380e3
AC
275 {
276 nd = ptr->data;
55abcbb2 277
212380e3
AC
278 free_nd_entry(nd);
279 }
280}
281
282/* *INDENT-OFF* */
283static struct hash_commands rehash_commands[] =
284{
285 {"BANS", rehash_bans_loc },
286 {"DNS", rehash_dns },
eb1b303d 287 {"SSLD", rehash_ssld },
212380e3
AC
288 {"MOTD", rehash_motd },
289 {"OMOTD", rehash_omotd },
212380e3
AC
290 {"TKLINES", rehash_tklines },
291 {"TDLINES", rehash_tdlines },
292 {"TXLINES", rehash_txlines },
293 {"TRESVS", rehash_tresvs },
294 {"REJECTCACHE", rehash_rejectcache },
995f300e 295 {"THROTTLES", rehash_throttles },
212380e3
AC
296 {"HELP", rehash_help },
297 {"NICKDELAY", rehash_nickdelay },
298 {NULL, NULL }
299};
300/* *INDENT-ON* */
301
302static void
303do_rehash(struct Client *source_p, const char *type)
304{
305 if (type != NULL)
306 {
307 int x;
308 char cmdbuf[100];
309
310 for (x = 0; rehash_commands[x].cmd != NULL && rehash_commands[x].handler != NULL;
311 x++)
312 {
313 if(irccmp(type, rehash_commands[x].cmd) == 0)
314 {
315 sendto_one(source_p, form_str(RPL_REHASHING), me.name,
316 source_p->name, rehash_commands[x].cmd);
212380e3
AC
317 ilog(L_MAIN, "REHASH %s From %s[%s]", type,
318 get_oper_name(source_p), source_p->sockhost);
61b7e0d9
JT
319 rehash_commands[x].handler(source_p);
320 remote_rehash_oper_p = NULL;
212380e3
AC
321 return;
322 }
323 }
324
325 /* We are still here..we didn't match */
326 cmdbuf[0] = '\0';
327 for (x = 0; rehash_commands[x].cmd != NULL && rehash_commands[x].handler != NULL;
328 x++)
329 {
1f9de103
VY
330 rb_strlcat(cmdbuf, " ", sizeof(cmdbuf));
331 rb_strlcat(cmdbuf, rehash_commands[x].cmd, sizeof(cmdbuf));
212380e3 332 }
5366977b 333 sendto_one_notice(source_p, ":rehash one of:%s", cmdbuf);
212380e3
AC
334 }
335 else
336 {
337 sendto_one(source_p, form_str(RPL_REHASHING), me.name, source_p->name,
338 ConfigFileEntry.configfile);
339 sendto_realops_snomask(SNO_GENERAL, L_ALL,
340 "%s is rehashing server config file", get_oper_name(source_p));
61b7e0d9
JT
341 if (!MyConnect(source_p))
342 remote_rehash_oper_p = source_p;
212380e3
AC
343 ilog(L_MAIN, "REHASH From %s[%s]", get_oper_name(source_p),
344 source_p->sockhost);
345 rehash(0);
61b7e0d9 346 remote_rehash_oper_p = NULL;
212380e3
AC
347 }
348}
349
350/*
351 * mo_rehash - REHASH message handler
352 *
353 * parv[1] = rehash type or destination
354 * parv[2] = destination
355 */
356static int
428ca87b 357mo_rehash(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
358{
359 const char *type = NULL, *target_server = NULL;
360
361 if(!IsOperRehash(source_p))
362 {
363 sendto_one(source_p, form_str(ERR_NOPRIVS),
364 me.name, source_p->name, "rehash");
365 return 0;
366 }
367
368 if (parc > 2)
369 type = parv[1], target_server = parv[2];
370 else if (parc > 1 && (strchr(parv[1], '.') || strchr(parv[1], '?') || strchr(parv[1], '*')))
371 type = NULL, target_server = parv[1];
372 else if (parc > 1)
373 type = parv[1], target_server = NULL;
374 else
375 type = NULL, target_server = NULL;
376
377 if (target_server != NULL)
378 {
379 if(!IsOperRemoteBan(source_p))
380 {
381 sendto_one(source_p, form_str(ERR_NOPRIVS),
382 me.name, source_p->name, "remoteban");
383 return 0;
384 }
385 sendto_match_servs(source_p, target_server,
386 CAP_ENCAP, NOCAPS,
387 "ENCAP %s REHASH %s",
388 target_server, type != NULL ? type : "");
389 if (match(target_server, me.name) == 0)
390 return 0;
391 }
392
393 do_rehash(source_p, type);
394
395 return 0;
396}
397
398static int
428ca87b 399me_rehash(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
400{
401
402 if (!IsPerson(source_p))
403 return 0;
404
405 if (!find_shared_conf(source_p->username, source_p->host,
c88cdb00 406 source_p->servptr->name, SHARED_REHASH))
212380e3
AC
407 return 0;
408
409 do_rehash(source_p, parc > 1 ? parv[1] : NULL);
410
411 return 0;
412}