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