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