Remove cruft left behind by removed stats_p_hook.
[seven-1.x.git] / modules / m_rehash.c
blobabf046a28e8227dc67cbf7f39ea65cb305e6cb8c
1 /*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_rehash.c: Re-reads the configuration file.
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
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.
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.
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
25 #include "stdinc.h"
26 #include "client.h"
27 #include "channel.h"
28 #include "common.h"
29 #include "irc_string.h"
30 #include "ircd.h"
31 #include "s_serv.h"
32 #include "numeric.h"
33 #include "res.h"
34 #include "s_conf.h"
35 #include "s_newconf.h"
36 #include "s_log.h"
37 #include "send.h"
38 #include "msg.h"
39 #include "parse.h"
40 #include "modules.h"
41 #include "hostmask.h"
42 #include "reject.h"
43 #include "hash.h"
44 #include "cache.h"
46 static int mo_rehash(struct Client *, struct Client *, int, const char **);
47 static int me_rehash(struct Client *, struct Client *, int, const char **);
49 struct Message rehash_msgtab = {
50 "REHASH", 0, 0, 0, MFLG_SLOW,
51 {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_rehash, 0}, {mo_rehash, 0}}
54 mapi_clist_av1 rehash_clist[] = { &rehash_msgtab, NULL };
55 DECLARE_MODULE_AV1(rehash, NULL, NULL, rehash_clist, NULL, NULL, "$Revision: 108 $");
57 struct hash_commands
59 const char *cmd;
60 void (*handler) (struct Client * source_p);
63 static void
64 rehash_bans_loc(struct Client *source_p)
66 sendto_realops_snomask(SNO_GENERAL, MyClient(source_p) ? L_ALL : L_NETWIDE, "%s is rehashing bans",
67 get_oper_name(source_p));
69 rehash_bans(0);
72 static void
73 rehash_dns(struct Client *source_p)
75 sendto_realops_snomask(SNO_GENERAL, MyClient(source_p) ? L_ALL : L_NETWIDE, "%s is rehashing DNS",
76 get_oper_name(source_p));
78 /* reread /etc/resolv.conf and reopen res socket */
79 restart_resolver();
82 static void
83 rehash_motd(struct Client *source_p)
85 sendto_realops_snomask(SNO_GENERAL, MyClient(source_p) ? L_ALL : L_NETWIDE,
86 "%s is forcing re-reading of MOTD file",
87 get_oper_name(source_p));
89 free_cachefile(user_motd);
90 user_motd = cache_file(MPATH, "ircd.motd", 0);
93 static void
94 rehash_omotd(struct Client *source_p)
96 sendto_realops_snomask(SNO_GENERAL, MyClient(source_p) ? L_ALL : L_NETWIDE,
97 "%s is forcing re-reading of OPER MOTD file",
98 get_oper_name(source_p));
100 free_cachefile(oper_motd);
101 oper_motd = cache_file(OPATH, "opers.motd", 0);
104 static void
105 rehash_tklines(struct Client *source_p)
107 struct ConfItem *aconf;
108 dlink_node *ptr, *next_ptr;
109 int i;
111 sendto_realops_snomask(SNO_GENERAL, MyClient(source_p) ? L_ALL : L_NETWIDE, "%s is clearing temp klines",
112 get_oper_name(source_p));
114 for(i = 0; i < LAST_TEMP_TYPE; i++)
116 DLINK_FOREACH_SAFE(ptr, next_ptr, temp_klines[i].head)
118 aconf = ptr->data;
120 delete_one_address_conf(aconf->host, aconf);
121 dlinkDestroy(ptr, &temp_klines[i]);
126 static void
127 rehash_tdlines(struct Client *source_p)
129 struct ConfItem *aconf;
130 dlink_node *ptr, *next_ptr;
131 int i;
133 sendto_realops_snomask(SNO_GENERAL, MyClient(source_p) ? L_ALL : L_NETWIDE, "%s is clearing temp dlines",
134 get_oper_name(source_p));
136 for(i = 0; i < LAST_TEMP_TYPE; i++)
138 DLINK_FOREACH_SAFE(ptr, next_ptr, temp_dlines[i].head)
140 aconf = ptr->data;
142 delete_one_address_conf(aconf->host, aconf);
143 dlinkDestroy(ptr, &temp_dlines[i]);
148 static void
149 rehash_txlines(struct Client *source_p)
151 struct ConfItem *aconf;
152 dlink_node *ptr;
153 dlink_node *next_ptr;
155 sendto_realops_snomask(SNO_GENERAL, MyClient(source_p) ? L_ALL : L_NETWIDE, "%s is clearing temp xlines",
156 get_oper_name(source_p));
158 DLINK_FOREACH_SAFE(ptr, next_ptr, xline_conf_list.head)
160 aconf = ptr->data;
162 if(!aconf->hold)
163 continue;
165 free_conf(aconf);
166 dlinkDestroy(ptr, &xline_conf_list);
170 static void
171 rehash_tresvs(struct Client *source_p)
173 struct ConfItem *aconf;
174 dlink_node *ptr;
175 dlink_node *next_ptr;
176 int i;
178 sendto_realops_snomask(SNO_GENERAL, MyClient(source_p) ? L_ALL : L_NETWIDE, "%s is clearing temp resvs",
179 get_oper_name(source_p));
181 HASH_WALK_SAFE(i, R_MAX, ptr, next_ptr, resvTable)
183 aconf = ptr->data;
185 if(!aconf->hold)
186 continue;
188 free_conf(aconf);
189 dlinkDestroy(ptr, &resvTable[i]);
191 HASH_WALK_END
193 DLINK_FOREACH_SAFE(ptr, next_ptr, resv_conf_list.head)
195 aconf = ptr->data;
197 if(!aconf->hold)
198 continue;
200 free_conf(aconf);
201 dlinkDestroy(ptr, &resv_conf_list);
205 static void
206 rehash_rejectcache(struct Client *source_p)
208 sendto_realops_snomask(SNO_GENERAL, MyClient(source_p) ? L_ALL : L_NETWIDE, "%s is clearing reject cache",
209 get_oper_name(source_p));
210 flush_reject();
214 static void
215 rehash_help(struct Client *source_p)
217 sendto_realops_snomask(SNO_GENERAL, MyClient(source_p) ? L_ALL : L_NETWIDE,
218 "%s is forcing re-reading of HELP files",
219 get_oper_name(source_p));
220 clear_help_hash();
221 load_help();
224 static void
225 rehash_nickdelay(struct Client *source_p)
227 struct nd_entry *nd;
228 dlink_node *ptr;
229 dlink_node *safe_ptr;
231 sendto_realops_snomask(SNO_GENERAL, MyClient(source_p) ? L_ALL : L_NETWIDE,
232 "%s is clearing the nick delay table",
233 get_oper_name(source_p));
235 DLINK_FOREACH_SAFE(ptr, safe_ptr, nd_list.head)
237 nd = ptr->data;
239 free_nd_entry(nd);
243 /* *INDENT-OFF* */
244 static struct hash_commands rehash_commands[] =
246 {"BANS", rehash_bans_loc },
247 {"DNS", rehash_dns },
248 {"MOTD", rehash_motd },
249 {"OMOTD", rehash_omotd },
250 {"TKLINES", rehash_tklines },
251 {"TDLINES", rehash_tdlines },
252 {"TXLINES", rehash_txlines },
253 {"TRESVS", rehash_tresvs },
254 {"REJECTCACHE", rehash_rejectcache },
255 {"HELP", rehash_help },
256 {"NICKDELAY", rehash_nickdelay },
257 {NULL, NULL }
259 /* *INDENT-ON* */
261 static void
262 do_rehash(struct Client *source_p, const char *type)
264 if (type != NULL)
266 int x;
267 char cmdbuf[100];
269 for (x = 0; rehash_commands[x].cmd != NULL && rehash_commands[x].handler != NULL;
270 x++)
272 if(irccmp(type, rehash_commands[x].cmd) == 0)
274 sendto_one(source_p, form_str(RPL_REHASHING), me.name,
275 source_p->name, rehash_commands[x].cmd);
276 rehash_commands[x].handler(source_p);
277 ilog(L_MAIN, "REHASH %s From %s[%s]", type,
278 get_oper_name(source_p), source_p->sockhost);
279 return;
283 /* We are still here..we didn't match */
284 cmdbuf[0] = '\0';
285 for (x = 0; rehash_commands[x].cmd != NULL && rehash_commands[x].handler != NULL;
286 x++)
288 strlcat(cmdbuf, " ", sizeof(cmdbuf));
289 strlcat(cmdbuf, rehash_commands[x].cmd, sizeof(cmdbuf));
291 sendto_one(source_p, ":%s NOTICE %s :rehash one of:%s", me.name, source_p->name,
292 cmdbuf);
294 else
296 sendto_one(source_p, form_str(RPL_REHASHING), me.name, source_p->name,
297 ConfigFileEntry.configfile);
298 sendto_realops_snomask(SNO_GENERAL, MyClient(source_p) ? L_ALL : L_NETWIDE,
299 "%s is rehashing server config file", get_oper_name(source_p));
300 ilog(L_MAIN, "REHASH From %s[%s]", get_oper_name(source_p),
301 source_p->sockhost);
302 rehash(0);
307 * mo_rehash - REHASH message handler
309 * parv[1] = rehash type or destination
310 * parv[2] = destination
312 static int
313 mo_rehash(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
315 const char *type = NULL, *target_server = NULL;
317 if(!IsOperRehash(source_p))
319 sendto_one(source_p, form_str(ERR_NOPRIVS),
320 me.name, source_p->name, "rehash");
321 return 0;
324 if (parc > 2)
325 type = parv[1], target_server = parv[2];
326 else if (parc > 1 && (strchr(parv[1], '.') || strchr(parv[1], '?') || strchr(parv[1], '*')))
327 type = NULL, target_server = parv[1];
328 else if (parc > 1)
329 type = parv[1], target_server = NULL;
330 else
331 type = NULL, target_server = NULL;
333 if (target_server != NULL)
335 sendto_match_servs(source_p, target_server,
336 CAP_ENCAP, NOCAPS,
337 "ENCAP %s REHASH %s",
338 target_server, type != NULL ? type : "");
339 if (match(target_server, me.name) == 0)
340 return 0;
343 do_rehash(source_p, type);
345 return 0;
348 static int
349 me_rehash(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
352 if (!IsPerson(source_p))
353 return 0;
354 if (!find_client_shared_conf(source_p, SHARED_REHASH))
355 return 0;
357 do_rehash(source_p, parc > 1 ? parv[1] : NULL);
359 return 0;