]>
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" | |
212380e3 AC |
35 | #include "s_conf.h" |
36 | #include "s_newconf.h" | |
4016731b | 37 | #include "logger.h" |
212380e3 AC |
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 | ||
47 | static int mo_rehash(struct Client *, struct Client *, int, const char **); | |
48 | static int me_rehash(struct Client *, struct Client *, int, const char **); | |
49 | ||
50 | struct 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 | ||
55 | mapi_clist_av1 rehash_clist[] = { &rehash_msgtab, NULL }; | |
5366977b | 56 | DECLARE_MODULE_AV1(rehash, NULL, NULL, rehash_clist, NULL, NULL, "$Revision: 3161 $"); |
212380e3 AC |
57 | |
58 | struct hash_commands | |
59 | { | |
60 | const char *cmd; | |
61 | void (*handler) (struct Client * source_p); | |
62 | }; | |
63 | ||
64 | static void | |
65 | rehash_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)); | |
61b7e0d9 JT |
69 | if (!MyConnect(source_p)) |
70 | remote_rehash_oper_p = source_p; | |
212380e3 AC |
71 | |
72 | rehash_bans(0); | |
73 | } | |
74 | ||
75 | static void | |
76 | rehash_dns(struct Client *source_p) | |
77 | { | |
55abcbb2 | 78 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is rehashing DNS", |
212380e3 | 79 | get_oper_name(source_p)); |
61b7e0d9 JT |
80 | if (!MyConnect(source_p)) |
81 | remote_rehash_oper_p = source_p; | |
212380e3 AC |
82 | |
83 | /* reread /etc/resolv.conf and reopen res socket */ | |
1eeb0469 | 84 | restart_authd(); |
212380e3 AC |
85 | } |
86 | ||
87 | static void | |
88 | rehash_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)); | |
61b7e0d9 JT |
93 | if (!MyConnect(source_p)) |
94 | remote_rehash_oper_p = source_p; | |
212380e3 | 95 | |
041d54ff | 96 | cache_user_motd(); |
212380e3 AC |
97 | } |
98 | ||
99 | static void | |
100 | rehash_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)); | |
61b7e0d9 JT |
105 | if (!MyConnect(source_p)) |
106 | remote_rehash_oper_p = source_p; | |
212380e3 AC |
107 | |
108 | free_cachefile(oper_motd); | |
109 | oper_motd = cache_file(OPATH, "opers.motd", 0); | |
110 | } | |
111 | ||
212380e3 AC |
112 | static void |
113 | rehash_tklines(struct Client *source_p) | |
114 | { | |
115 | struct ConfItem *aconf; | |
637c4932 | 116 | rb_dlink_node *ptr, *next_ptr; |
212380e3 AC |
117 | int i; |
118 | ||
119 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp klines", | |
120 | get_oper_name(source_p)); | |
61b7e0d9 JT |
121 | if (!MyConnect(source_p)) |
122 | remote_rehash_oper_p = source_p; | |
212380e3 AC |
123 | |
124 | for(i = 0; i < LAST_TEMP_TYPE; i++) | |
125 | { | |
637c4932 | 126 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, temp_klines[i].head) |
212380e3 AC |
127 | { |
128 | aconf = ptr->data; | |
129 | ||
130 | delete_one_address_conf(aconf->host, aconf); | |
555ac41f | 131 | rb_dlinkDestroy(ptr, &temp_klines[i]); |
212380e3 AC |
132 | } |
133 | } | |
134 | } | |
135 | ||
136 | static void | |
137 | rehash_tdlines(struct Client *source_p) | |
138 | { | |
139 | struct ConfItem *aconf; | |
637c4932 | 140 | rb_dlink_node *ptr, *next_ptr; |
212380e3 AC |
141 | int i; |
142 | ||
143 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp dlines", | |
144 | get_oper_name(source_p)); | |
61b7e0d9 JT |
145 | if (!MyConnect(source_p)) |
146 | remote_rehash_oper_p = source_p; | |
212380e3 AC |
147 | |
148 | for(i = 0; i < LAST_TEMP_TYPE; i++) | |
149 | { | |
637c4932 | 150 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, temp_dlines[i].head) |
212380e3 AC |
151 | { |
152 | aconf = ptr->data; | |
153 | ||
154 | delete_one_address_conf(aconf->host, aconf); | |
555ac41f | 155 | rb_dlinkDestroy(ptr, &temp_dlines[i]); |
212380e3 AC |
156 | } |
157 | } | |
158 | } | |
159 | ||
160 | static void | |
161 | rehash_txlines(struct Client *source_p) | |
162 | { | |
163 | struct ConfItem *aconf; | |
5b96d9a6 | 164 | rb_dlink_node *ptr; |
637c4932 | 165 | rb_dlink_node *next_ptr; |
212380e3 AC |
166 | |
167 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp xlines", | |
168 | get_oper_name(source_p)); | |
61b7e0d9 JT |
169 | if (!MyConnect(source_p)) |
170 | remote_rehash_oper_p = source_p; | |
212380e3 | 171 | |
637c4932 | 172 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, xline_conf_list.head) |
212380e3 AC |
173 | { |
174 | aconf = ptr->data; | |
175 | ||
97f44d34 | 176 | if(!aconf->hold || aconf->lifetime) |
212380e3 AC |
177 | continue; |
178 | ||
179 | free_conf(aconf); | |
555ac41f | 180 | rb_dlinkDestroy(ptr, &xline_conf_list); |
212380e3 AC |
181 | } |
182 | } | |
183 | ||
184 | static void | |
185 | rehash_tresvs(struct Client *source_p) | |
186 | { | |
187 | struct ConfItem *aconf; | |
5b96d9a6 | 188 | rb_dlink_node *ptr; |
637c4932 | 189 | rb_dlink_node *next_ptr; |
212380e3 AC |
190 | int i; |
191 | ||
192 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp resvs", | |
193 | get_oper_name(source_p)); | |
61b7e0d9 JT |
194 | if (!MyConnect(source_p)) |
195 | remote_rehash_oper_p = source_p; | |
212380e3 | 196 | |
637c4932 | 197 | HASH_WALK_SAFE(i, R_MAX, ptr, next_ptr, resvTable) |
212380e3 AC |
198 | { |
199 | aconf = ptr->data; | |
200 | ||
97f44d34 | 201 | if(!aconf->hold || aconf->lifetime) |
212380e3 AC |
202 | continue; |
203 | ||
204 | free_conf(aconf); | |
555ac41f | 205 | rb_dlinkDestroy(ptr, &resvTable[i]); |
212380e3 AC |
206 | } |
207 | HASH_WALK_END | |
208 | ||
637c4932 | 209 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, resv_conf_list.head) |
212380e3 AC |
210 | { |
211 | aconf = ptr->data; | |
212 | ||
97f44d34 | 213 | if(!aconf->hold || aconf->lifetime) |
212380e3 AC |
214 | continue; |
215 | ||
216 | free_conf(aconf); | |
555ac41f | 217 | rb_dlinkDestroy(ptr, &resv_conf_list); |
212380e3 AC |
218 | } |
219 | } | |
220 | ||
221 | static void | |
222 | rehash_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)); | |
61b7e0d9 JT |
226 | if (!MyConnect(source_p)) |
227 | remote_rehash_oper_p = source_p; | |
212380e3 AC |
228 | flush_reject(); |
229 | ||
230 | } | |
231 | ||
995f300e JT |
232 | static void |
233 | rehash_throttles(struct Client *source_p) | |
234 | { | |
235 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing throttles", | |
236 | get_oper_name(source_p)); | |
61b7e0d9 JT |
237 | if (!MyConnect(source_p)) |
238 | remote_rehash_oper_p = source_p; | |
995f300e JT |
239 | flush_throttle(); |
240 | ||
241 | } | |
242 | ||
212380e3 AC |
243 | static void |
244 | rehash_help(struct Client *source_p) | |
245 | { | |
246 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
55abcbb2 | 247 | "%s is forcing re-reading of HELP files", |
212380e3 | 248 | get_oper_name(source_p)); |
61b7e0d9 JT |
249 | if (!MyConnect(source_p)) |
250 | remote_rehash_oper_p = source_p; | |
212380e3 AC |
251 | load_help(); |
252 | } | |
253 | ||
254 | static void | |
255 | rehash_nickdelay(struct Client *source_p) | |
256 | { | |
257 | struct nd_entry *nd; | |
5b96d9a6 AC |
258 | rb_dlink_node *ptr; |
259 | rb_dlink_node *safe_ptr; | |
212380e3 AC |
260 | |
261 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
262 | "%s is clearing the nick delay table", | |
263 | get_oper_name(source_p)); | |
61b7e0d9 JT |
264 | if (!MyConnect(source_p)) |
265 | remote_rehash_oper_p = source_p; | |
212380e3 | 266 | |
5b96d9a6 | 267 | RB_DLINK_FOREACH_SAFE(ptr, safe_ptr, nd_list.head) |
212380e3 AC |
268 | { |
269 | nd = ptr->data; | |
55abcbb2 | 270 | |
212380e3 AC |
271 | free_nd_entry(nd); |
272 | } | |
273 | } | |
274 | ||
275 | /* *INDENT-OFF* */ | |
276 | static struct hash_commands rehash_commands[] = | |
277 | { | |
278 | {"BANS", rehash_bans_loc }, | |
279 | {"DNS", rehash_dns }, | |
280 | {"MOTD", rehash_motd }, | |
281 | {"OMOTD", rehash_omotd }, | |
212380e3 AC |
282 | {"TKLINES", rehash_tklines }, |
283 | {"TDLINES", rehash_tdlines }, | |
284 | {"TXLINES", rehash_txlines }, | |
285 | {"TRESVS", rehash_tresvs }, | |
286 | {"REJECTCACHE", rehash_rejectcache }, | |
995f300e | 287 | {"THROTTLES", rehash_throttles }, |
212380e3 AC |
288 | {"HELP", rehash_help }, |
289 | {"NICKDELAY", rehash_nickdelay }, | |
290 | {NULL, NULL } | |
291 | }; | |
292 | /* *INDENT-ON* */ | |
293 | ||
294 | static void | |
295 | do_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 AC |
309 | ilog(L_MAIN, "REHASH %s From %s[%s]", type, |
310 | get_oper_name(source_p), source_p->sockhost); | |
61b7e0d9 JT |
311 | rehash_commands[x].handler(source_p); |
312 | remote_rehash_oper_p = NULL; | |
212380e3 AC |
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 | { | |
1f9de103 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 AC |
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)); | |
61b7e0d9 JT |
333 | if (!MyConnect(source_p)) |
334 | remote_rehash_oper_p = source_p; | |
212380e3 AC |
335 | ilog(L_MAIN, "REHASH From %s[%s]", get_oper_name(source_p), |
336 | source_p->sockhost); | |
337 | rehash(0); | |
61b7e0d9 | 338 | remote_rehash_oper_p = NULL; |
212380e3 AC |
339 | } |
340 | } | |
341 | ||
342 | /* | |
343 | * mo_rehash - REHASH message handler | |
344 | * | |
345 | * parv[1] = rehash type or destination | |
346 | * parv[2] = destination | |
347 | */ | |
348 | static int | |
349 | mo_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 | ||
390 | static int | |
391 | me_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 AC |
399 | return 0; |
400 | ||
401 | do_rehash(source_p, parc > 1 ? parv[1] : NULL); | |
402 | ||
403 | return 0; | |
404 | } |