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