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