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