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