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