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