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