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