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
34 #include "s_newconf.h"
44 #include "irc_radixtree.h"
47 static int mo_rehash(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
48 static int me_rehash(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
50 struct Message rehash_msgtab
= {
52 {mg_unreg
, mg_not_oper
, mg_ignore
, mg_ignore
, {me_rehash
, 0}, {mo_rehash
, 0}}
55 mapi_clist_av1 rehash_clist
[] = { &rehash_msgtab
, NULL
};
56 DECLARE_MODULE_AV1(rehash
, NULL
, NULL
, rehash_clist
, NULL
, NULL
, "$Revision: 3161 $");
61 void (*handler
) (struct Client
* source_p
);
65 rehash_bans_loc(struct Client
*source_p
)
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
;
76 rehash_dns(struct Client
*source_p
)
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
;
83 /* reread /etc/resolv.conf and reopen res socket */
88 rehash_ssld(struct Client
*source_p
)
90 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is restarting ssld",
91 get_oper_name(source_p
));
97 rehash_motd(struct Client
*source_p
)
99 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
100 "%s is forcing re-reading of MOTD file",
101 get_oper_name(source_p
));
102 if (!MyConnect(source_p
))
103 remote_rehash_oper_p
= source_p
;
109 rehash_omotd(struct Client
*source_p
)
111 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
112 "%s is forcing re-reading of OPER MOTD file",
113 get_oper_name(source_p
));
114 if (!MyConnect(source_p
))
115 remote_rehash_oper_p
= source_p
;
117 free_cachefile(oper_motd
);
118 oper_motd
= cache_file(OPATH
, "opers.motd", 0);
122 rehash_tklines(struct Client
*source_p
)
124 struct ConfItem
*aconf
;
125 rb_dlink_node
*ptr
, *next_ptr
;
128 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing temp klines",
129 get_oper_name(source_p
));
130 if (!MyConnect(source_p
))
131 remote_rehash_oper_p
= source_p
;
133 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
135 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, temp_klines
[i
].head
)
139 delete_one_address_conf(aconf
->host
, aconf
);
140 rb_dlinkDestroy(ptr
, &temp_klines
[i
]);
146 rehash_tdlines(struct Client
*source_p
)
148 struct ConfItem
*aconf
;
149 rb_dlink_node
*ptr
, *next_ptr
;
152 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing temp dlines",
153 get_oper_name(source_p
));
154 if (!MyConnect(source_p
))
155 remote_rehash_oper_p
= source_p
;
157 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
159 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, temp_dlines
[i
].head
)
163 delete_one_address_conf(aconf
->host
, aconf
);
164 rb_dlinkDestroy(ptr
, &temp_dlines
[i
]);
170 rehash_txlines(struct Client
*source_p
)
172 struct ConfItem
*aconf
;
174 rb_dlink_node
*next_ptr
;
176 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing temp xlines",
177 get_oper_name(source_p
));
178 if (!MyConnect(source_p
))
179 remote_rehash_oper_p
= source_p
;
181 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, xline_conf_list
.head
)
185 if(!aconf
->hold
|| aconf
->lifetime
)
189 rb_dlinkDestroy(ptr
, &xline_conf_list
);
194 rehash_tresvs(struct Client
*source_p
)
196 struct ConfItem
*aconf
;
197 struct irc_radixtree_iteration_state iter
;
199 rb_dlink_node
*next_ptr
;
202 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing temp resvs",
203 get_oper_name(source_p
));
204 if (!MyConnect(source_p
))
205 remote_rehash_oper_p
= source_p
;
207 IRC_RADIXTREE_FOREACH(aconf
, &iter
, resv_tree
)
209 if(!aconf
->hold
|| aconf
->lifetime
)
212 irc_radixtree_delete(resv_tree
, aconf
->host
);
216 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, resv_conf_list
.head
)
220 if(!aconf
->hold
|| aconf
->lifetime
)
224 rb_dlinkDestroy(ptr
, &resv_conf_list
);
229 rehash_rejectcache(struct Client
*source_p
)
231 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing reject cache",
232 get_oper_name(source_p
));
233 if (!MyConnect(source_p
))
234 remote_rehash_oper_p
= source_p
;
240 rehash_throttles(struct Client
*source_p
)
242 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing throttles",
243 get_oper_name(source_p
));
244 if (!MyConnect(source_p
))
245 remote_rehash_oper_p
= source_p
;
251 rehash_help(struct Client
*source_p
)
253 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
254 "%s is forcing re-reading of HELP files",
255 get_oper_name(source_p
));
256 if (!MyConnect(source_p
))
257 remote_rehash_oper_p
= source_p
;
262 rehash_nickdelay(struct Client
*source_p
)
266 rb_dlink_node
*safe_ptr
;
268 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
269 "%s is clearing the nick delay table",
270 get_oper_name(source_p
));
271 if (!MyConnect(source_p
))
272 remote_rehash_oper_p
= source_p
;
274 RB_DLINK_FOREACH_SAFE(ptr
, safe_ptr
, nd_list
.head
)
283 static struct hash_commands rehash_commands
[] =
285 {"BANS", rehash_bans_loc
},
286 {"DNS", rehash_dns
},
287 {"SSLD", rehash_ssld
},
288 {"MOTD", rehash_motd
},
289 {"OMOTD", rehash_omotd
},
290 {"TKLINES", rehash_tklines
},
291 {"TDLINES", rehash_tdlines
},
292 {"TXLINES", rehash_txlines
},
293 {"TRESVS", rehash_tresvs
},
294 {"REJECTCACHE", rehash_rejectcache
},
295 {"THROTTLES", rehash_throttles
},
296 {"HELP", rehash_help
},
297 {"NICKDELAY", rehash_nickdelay
},
303 do_rehash(struct Client
*source_p
, const char *type
)
310 for (x
= 0; rehash_commands
[x
].cmd
!= NULL
&& rehash_commands
[x
].handler
!= NULL
;
313 if(irccmp(type
, rehash_commands
[x
].cmd
) == 0)
315 sendto_one(source_p
, form_str(RPL_REHASHING
), me
.name
,
316 source_p
->name
, rehash_commands
[x
].cmd
);
317 ilog(L_MAIN
, "REHASH %s From %s[%s]", type
,
318 get_oper_name(source_p
), source_p
->sockhost
);
319 rehash_commands
[x
].handler(source_p
);
320 remote_rehash_oper_p
= NULL
;
325 /* We are still here..we didn't match */
327 for (x
= 0; rehash_commands
[x
].cmd
!= NULL
&& rehash_commands
[x
].handler
!= NULL
;
330 rb_strlcat(cmdbuf
, " ", sizeof(cmdbuf
));
331 rb_strlcat(cmdbuf
, rehash_commands
[x
].cmd
, sizeof(cmdbuf
));
333 sendto_one_notice(source_p
, ":rehash one of:%s", cmdbuf
);
337 sendto_one(source_p
, form_str(RPL_REHASHING
), me
.name
, source_p
->name
,
338 ConfigFileEntry
.configfile
);
339 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
340 "%s is rehashing server config file", get_oper_name(source_p
));
341 if (!MyConnect(source_p
))
342 remote_rehash_oper_p
= source_p
;
343 ilog(L_MAIN
, "REHASH From %s[%s]", get_oper_name(source_p
),
346 remote_rehash_oper_p
= NULL
;
351 * mo_rehash - REHASH message handler
353 * parv[1] = rehash type or destination
354 * parv[2] = destination
357 mo_rehash(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
359 const char *type
= NULL
, *target_server
= NULL
;
361 if(!IsOperRehash(source_p
))
363 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
364 me
.name
, source_p
->name
, "rehash");
369 type
= parv
[1], target_server
= parv
[2];
370 else if (parc
> 1 && (strchr(parv
[1], '.') || strchr(parv
[1], '?') || strchr(parv
[1], '*')))
371 type
= NULL
, target_server
= parv
[1];
373 type
= parv
[1], target_server
= NULL
;
375 type
= NULL
, target_server
= NULL
;
377 if (target_server
!= NULL
)
379 if(!IsOperRemoteBan(source_p
))
381 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
382 me
.name
, source_p
->name
, "remoteban");
385 sendto_match_servs(source_p
, target_server
,
387 "ENCAP %s REHASH %s",
388 target_server
, type
!= NULL
? type
: "");
389 if (match(target_server
, me
.name
) == 0)
393 do_rehash(source_p
, type
);
399 me_rehash(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
402 if (!IsPerson(source_p
))
405 if (!find_shared_conf(source_p
->username
, source_p
->host
,
406 source_p
->servptr
->name
, SHARED_REHASH
))
409 do_rehash(source_p
, parc
> 1 ? parv
[1] : NULL
);