]> jfr.im git - solanum.git/blob - modules/m_rehash.c
Remove ^M on line endings.
[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 "irc_string.h"
32 #include "ircd.h"
33 #include "s_serv.h"
34 #include "numeric.h"
35 #include "res.h"
36 #include "s_conf.h"
37 #include "s_newconf.h"
38 #include "logger.h"
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
48 static int mo_rehash(struct Client *, struct Client *, int, const char **);
49 static int me_rehash(struct Client *, struct Client *, int, const char **);
50
51 struct 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
56 mapi_clist_av1 rehash_clist[] = { &rehash_msgtab, NULL };
57 DECLARE_MODULE_AV1(rehash, NULL, NULL, rehash_clist, NULL, NULL, "$Revision: 3161 $");
58
59 struct hash_commands
60 {
61 const char *cmd;
62 void (*handler) (struct Client * source_p);
63 };
64
65 static void
66 rehash_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));
70
71 rehash_bans(0);
72 }
73
74 static void
75 rehash_dns(struct Client *source_p)
76 {
77 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is rehashing DNS",
78 get_oper_name(source_p));
79
80 /* reread /etc/resolv.conf and reopen res socket */
81 restart_resolver();
82 }
83
84 static void
85 rehash_motd(struct Client *source_p)
86 {
87 sendto_realops_snomask(SNO_GENERAL, L_ALL,
88 "%s is forcing re-reading of MOTD file",
89 get_oper_name(source_p));
90
91 free_cachefile(user_motd);
92 user_motd = cache_file(MPATH, "ircd.motd", 0);
93 }
94
95 static void
96 rehash_omotd(struct Client *source_p)
97 {
98 sendto_realops_snomask(SNO_GENERAL, L_ALL,
99 "%s is forcing re-reading of OPER MOTD file",
100 get_oper_name(source_p));
101
102 free_cachefile(oper_motd);
103 oper_motd = cache_file(OPATH, "opers.motd", 0);
104 }
105
106 static void
107 rehash_tklines(struct Client *source_p)
108 {
109 struct ConfItem *aconf;
110 rb_dlink_node *ptr, *next_ptr;
111 int i;
112
113 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp klines",
114 get_oper_name(source_p));
115
116 for(i = 0; i < LAST_TEMP_TYPE; i++)
117 {
118 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, temp_klines[i].head)
119 {
120 aconf = ptr->data;
121
122 delete_one_address_conf(aconf->host, aconf);
123 rb_dlinkDestroy(ptr, &temp_klines[i]);
124 }
125 }
126 }
127
128 static void
129 rehash_tdlines(struct Client *source_p)
130 {
131 struct ConfItem *aconf;
132 rb_dlink_node *ptr, *next_ptr;
133 int i;
134
135 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp dlines",
136 get_oper_name(source_p));
137
138 for(i = 0; i < LAST_TEMP_TYPE; i++)
139 {
140 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, temp_dlines[i].head)
141 {
142 aconf = ptr->data;
143
144 delete_one_address_conf(aconf->host, aconf);
145 rb_dlinkDestroy(ptr, &temp_dlines[i]);
146 }
147 }
148 }
149
150 static void
151 rehash_txlines(struct Client *source_p)
152 {
153 struct ConfItem *aconf;
154 rb_dlink_node *ptr;
155 rb_dlink_node *next_ptr;
156
157 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp xlines",
158 get_oper_name(source_p));
159
160 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, xline_conf_list.head)
161 {
162 aconf = ptr->data;
163
164 if(!aconf->hold)
165 continue;
166
167 free_conf(aconf);
168 rb_dlinkDestroy(ptr, &xline_conf_list);
169 }
170 }
171
172 static void
173 rehash_tresvs(struct Client *source_p)
174 {
175 struct ConfItem *aconf;
176 rb_dlink_node *ptr;
177 rb_dlink_node *next_ptr;
178 int i;
179
180 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing temp resvs",
181 get_oper_name(source_p));
182
183 HASH_WALK_SAFE(i, R_MAX, ptr, next_ptr, resvTable)
184 {
185 aconf = ptr->data;
186
187 if(!aconf->hold)
188 continue;
189
190 free_conf(aconf);
191 rb_dlinkDestroy(ptr, &resvTable[i]);
192 }
193 HASH_WALK_END
194
195 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, resv_conf_list.head)
196 {
197 aconf = ptr->data;
198
199 if(!aconf->hold)
200 continue;
201
202 free_conf(aconf);
203 rb_dlinkDestroy(ptr, &resv_conf_list);
204 }
205 }
206
207 static void
208 rehash_rejectcache(struct Client *source_p)
209 {
210 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s is clearing reject cache",
211 get_oper_name(source_p));
212 flush_reject();
213
214 }
215
216 static void
217 rehash_help(struct Client *source_p)
218 {
219 sendto_realops_snomask(SNO_GENERAL, L_ALL,
220 "%s is forcing re-reading of HELP files",
221 get_oper_name(source_p));
222 load_help();
223 }
224
225 static void
226 rehash_nickdelay(struct Client *source_p)
227 {
228 struct nd_entry *nd;
229 rb_dlink_node *ptr;
230 rb_dlink_node *safe_ptr;
231
232 sendto_realops_snomask(SNO_GENERAL, L_ALL,
233 "%s is clearing the nick delay table",
234 get_oper_name(source_p));
235
236 RB_DLINK_FOREACH_SAFE(ptr, safe_ptr, nd_list.head)
237 {
238 nd = ptr->data;
239
240 free_nd_entry(nd);
241 }
242 }
243
244 /* *INDENT-OFF* */
245 static struct hash_commands rehash_commands[] =
246 {
247 {"BANS", rehash_bans_loc },
248 {"DNS", rehash_dns },
249 {"MOTD", rehash_motd },
250 {"OMOTD", rehash_omotd },
251 {"TKLINES", rehash_tklines },
252 {"TDLINES", rehash_tdlines },
253 {"TXLINES", rehash_txlines },
254 {"TRESVS", rehash_tresvs },
255 {"REJECTCACHE", rehash_rejectcache },
256 {"HELP", rehash_help },
257 {"NICKDELAY", rehash_nickdelay },
258 {NULL, NULL }
259 };
260 /* *INDENT-ON* */
261
262 static void
263 do_rehash(struct Client *source_p, const char *type)
264 {
265 if (type != NULL)
266 {
267 int x;
268 char cmdbuf[100];
269
270 for (x = 0; rehash_commands[x].cmd != NULL && rehash_commands[x].handler != NULL;
271 x++)
272 {
273 if(irccmp(type, rehash_commands[x].cmd) == 0)
274 {
275 sendto_one(source_p, form_str(RPL_REHASHING), me.name,
276 source_p->name, rehash_commands[x].cmd);
277 rehash_commands[x].handler(source_p);
278 ilog(L_MAIN, "REHASH %s From %s[%s]", type,
279 get_oper_name(source_p), source_p->sockhost);
280 return;
281 }
282 }
283
284 /* We are still here..we didn't match */
285 cmdbuf[0] = '\0';
286 for (x = 0; rehash_commands[x].cmd != NULL && rehash_commands[x].handler != NULL;
287 x++)
288 {
289 strlcat(cmdbuf, " ", sizeof(cmdbuf));
290 strlcat(cmdbuf, rehash_commands[x].cmd, sizeof(cmdbuf));
291 }
292 sendto_one_notice(source_p, ":rehash one of:%s", cmdbuf);
293 }
294 else
295 {
296 sendto_one(source_p, form_str(RPL_REHASHING), me.name, source_p->name,
297 ConfigFileEntry.configfile);
298 sendto_realops_snomask(SNO_GENERAL, L_ALL,
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);
303 }
304 }
305
306 /*
307 * mo_rehash - REHASH message handler
308 *
309 * parv[1] = rehash type or destination
310 * parv[2] = destination
311 */
312 static int
313 mo_rehash(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
314 {
315 const char *type = NULL, *target_server = NULL;
316
317 if(!IsOperRehash(source_p))
318 {
319 sendto_one(source_p, form_str(ERR_NOPRIVS),
320 me.name, source_p->name, "rehash");
321 return 0;
322 }
323
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;
332
333 if (target_server != NULL)
334 {
335 if(!IsOperRemoteBan(source_p))
336 {
337 sendto_one(source_p, form_str(ERR_NOPRIVS),
338 me.name, source_p->name, "remoteban");
339 return 0;
340 }
341 sendto_match_servs(source_p, target_server,
342 CAP_ENCAP, NOCAPS,
343 "ENCAP %s REHASH %s",
344 target_server, type != NULL ? type : "");
345 if (match(target_server, me.name) == 0)
346 return 0;
347 }
348
349 do_rehash(source_p, type);
350
351 return 0;
352 }
353
354 static int
355 me_rehash(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
356 {
357
358 if (!IsPerson(source_p))
359 return 0;
360
361 if (!find_shared_conf(source_p->username, source_p->host,
362 source_p->servptr->name, SHARED_REHASH))
363 return 0;
364
365 do_rehash(source_p, parc > 1 ? parv[1] : NULL);
366
367 return 0;
368 }