]> jfr.im git - solanum.git/blob - modules/m_rehash.c
librb: configure: also include ws2tcpip.h
[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 reload_nameservers();
88 }
89
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
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));
105 if (!MyConnect(source_p))
106 remote_rehash_oper_p = source_p;
107
108 cache_user_motd();
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));
117 if (!MyConnect(source_p))
118 remote_rehash_oper_p = source_p;
119
120 free_cachefile(oper_motd);
121 oper_motd = cache_file(OPATH, "opers.motd", 0);
122 }
123
124 static void
125 rehash_tklines(struct Client *source_p)
126 {
127 struct ConfItem *aconf;
128 rb_dlink_node *ptr, *next_ptr;
129 int i;
130
131 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp klines",
132 get_oper_name(source_p));
133 if (!MyConnect(source_p))
134 remote_rehash_oper_p = source_p;
135
136 for(i = 0; i < LAST_TEMP_TYPE; i++)
137 {
138 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, temp_klines[i].head)
139 {
140 aconf = ptr->data;
141
142 delete_one_address_conf(aconf->host, aconf);
143 rb_dlinkDestroy(ptr, &temp_klines[i]);
144 }
145 }
146 }
147
148 static void
149 rehash_tdlines(struct Client *source_p)
150 {
151 struct ConfItem *aconf;
152 rb_dlink_node *ptr, *next_ptr;
153 int i;
154
155 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp dlines",
156 get_oper_name(source_p));
157 if (!MyConnect(source_p))
158 remote_rehash_oper_p = source_p;
159
160 for(i = 0; i < LAST_TEMP_TYPE; i++)
161 {
162 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, temp_dlines[i].head)
163 {
164 aconf = ptr->data;
165
166 delete_one_address_conf(aconf->host, aconf);
167 rb_dlinkDestroy(ptr, &temp_dlines[i]);
168 }
169 }
170 }
171
172 static void
173 rehash_txlines(struct Client *source_p)
174 {
175 struct ConfItem *aconf;
176 rb_dlink_node *ptr;
177 rb_dlink_node *next_ptr;
178
179 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp xlines",
180 get_oper_name(source_p));
181 if (!MyConnect(source_p))
182 remote_rehash_oper_p = source_p;
183
184 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, xline_conf_list.head)
185 {
186 aconf = ptr->data;
187
188 if(!aconf->hold || aconf->lifetime)
189 continue;
190
191 free_conf(aconf);
192 rb_dlinkDestroy(ptr, &xline_conf_list);
193 }
194 }
195
196 static void
197 rehash_tresvs(struct Client *source_p)
198 {
199 struct ConfItem *aconf;
200 struct rb_radixtree_iteration_state iter;
201 rb_dlink_node *ptr;
202 rb_dlink_node *next_ptr;
203 int i;
204
205 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp resvs",
206 get_oper_name(source_p));
207 if (!MyConnect(source_p))
208 remote_rehash_oper_p = source_p;
209
210 RB_RADIXTREE_FOREACH(aconf, &iter, resv_tree)
211 {
212 if(!aconf->hold || aconf->lifetime)
213 continue;
214
215 rb_radixtree_delete(resv_tree, aconf->host);
216 free_conf(aconf);
217 }
218
219 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, resv_conf_list.head)
220 {
221 aconf = ptr->data;
222
223 if(!aconf->hold || aconf->lifetime)
224 continue;
225
226 free_conf(aconf);
227 rb_dlinkDestroy(ptr, &resv_conf_list);
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));
236 if (!MyConnect(source_p))
237 remote_rehash_oper_p = source_p;
238 flush_reject();
239
240 }
241
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));
247 if (!MyConnect(source_p))
248 remote_rehash_oper_p = source_p;
249 flush_throttle();
250
251 }
252
253 static void
254 rehash_help(struct Client *source_p)
255 {
256 sendto_realops_snomask(SNO_GENERAL, L_ALL,
257 "%s is forcing re-reading of HELP files",
258 get_oper_name(source_p));
259 if (!MyConnect(source_p))
260 remote_rehash_oper_p = source_p;
261 load_help();
262 }
263
264 static void
265 rehash_nickdelay(struct Client *source_p)
266 {
267 struct nd_entry *nd;
268 rb_dlink_node *ptr;
269 rb_dlink_node *safe_ptr;
270
271 sendto_realops_snomask(SNO_GENERAL, L_ALL,
272 "%s is clearing the nick delay table",
273 get_oper_name(source_p));
274 if (!MyConnect(source_p))
275 remote_rehash_oper_p = source_p;
276
277 RB_DLINK_FOREACH_SAFE(ptr, safe_ptr, nd_list.head)
278 {
279 nd = ptr->data;
280
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 },
290 {"SSLD", rehash_ssld },
291 {"MOTD", rehash_motd },
292 {"OMOTD", rehash_omotd },
293 {"TKLINES", rehash_tklines },
294 {"TDLINES", rehash_tdlines },
295 {"TXLINES", rehash_txlines },
296 {"TRESVS", rehash_tresvs },
297 {"REJECTCACHE", rehash_rejectcache },
298 {"THROTTLES", rehash_throttles },
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);
320 ilog(L_MAIN, "REHASH %s From %s[%s]", type,
321 get_oper_name(source_p), source_p->sockhost);
322 rehash_commands[x].handler(source_p);
323 remote_rehash_oper_p = NULL;
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 {
333 rb_strlcat(cmdbuf, " ", sizeof(cmdbuf));
334 rb_strlcat(cmdbuf, rehash_commands[x].cmd, sizeof(cmdbuf));
335 }
336 sendto_one_notice(source_p, ":rehash one of:%s", cmdbuf);
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));
344 if (!MyConnect(source_p))
345 remote_rehash_oper_p = source_p;
346 ilog(L_MAIN, "REHASH From %s[%s]", get_oper_name(source_p),
347 source_p->sockhost);
348 rehash(0);
349 remote_rehash_oper_p = NULL;
350 }
351 }
352
353 /*
354 * mo_rehash - REHASH message handler
355 *
356 * parv[1] = rehash type or destination
357 * parv[2] = destination
358 */
359 static void
360 mo_rehash(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
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");
368 return;
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");
386 return;
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)
393 return;
394 }
395
396 do_rehash(source_p, type);
397 }
398
399 static void
400 me_rehash(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
401 {
402
403 if (!IsPerson(source_p))
404 return;
405
406 if (!find_shared_conf(source_p->username, source_p->host,
407 source_p->servptr->name, SHARED_REHASH))
408 return;
409
410 do_rehash(source_p, parc > 1 ? parv[1] : NULL);
411 }