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