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