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