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 "rb_radixtree.h"
47 static const char rehash_desc
[] =
48 "Provides the REHASH command to reload configuration and other files";
50 static void mo_rehash(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
51 static void me_rehash(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
53 struct Message rehash_msgtab
= {
55 {mg_unreg
, mg_not_oper
, mg_ignore
, mg_ignore
, {me_rehash
, 0}, {mo_rehash
, 0}}
58 mapi_clist_av1 rehash_clist
[] = { &rehash_msgtab
, NULL
};
60 DECLARE_MODULE_AV2(rehash
, NULL
, NULL
, rehash_clist
, NULL
, NULL
, NULL
, NULL
, rehash_desc
);
65 void (*handler
) (struct Client
* source_p
);
69 rehash_bans_loc(struct Client
*source_p
)
71 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is rehashing bans",
72 get_oper_name(source_p
));
73 if (!MyConnect(source_p
))
74 remote_rehash_oper_p
= source_p
;
80 rehash_dns(struct Client
*source_p
)
82 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is rehashing DNS",
83 get_oper_name(source_p
));
84 if (!MyConnect(source_p
))
85 remote_rehash_oper_p
= source_p
;
91 rehash_ssld(struct Client
*source_p
)
93 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is restarting ssld",
94 get_oper_name(source_p
));
100 rehash_motd(struct Client
*source_p
)
102 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
103 "%s is forcing re-reading of MOTD file",
104 get_oper_name(source_p
));
105 if (!MyConnect(source_p
))
106 remote_rehash_oper_p
= source_p
;
112 rehash_omotd(struct Client
*source_p
)
114 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
115 "%s is forcing re-reading of OPER MOTD file",
116 get_oper_name(source_p
));
117 if (!MyConnect(source_p
))
118 remote_rehash_oper_p
= source_p
;
120 free_cachefile(oper_motd
);
121 oper_motd
= cache_file(OPATH
, "opers.motd", 0);
125 rehash_tklines(struct Client
*source_p
)
127 struct ConfItem
*aconf
;
128 rb_dlink_node
*ptr
, *next_ptr
;
131 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing temp klines",
132 get_oper_name(source_p
));
133 if (!MyConnect(source_p
))
134 remote_rehash_oper_p
= source_p
;
136 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
138 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, temp_klines
[i
].head
)
142 delete_one_address_conf(aconf
->host
, aconf
);
143 rb_dlinkDestroy(ptr
, &temp_klines
[i
]);
149 rehash_tdlines(struct Client
*source_p
)
151 struct ConfItem
*aconf
;
152 rb_dlink_node
*ptr
, *next_ptr
;
155 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing temp dlines",
156 get_oper_name(source_p
));
157 if (!MyConnect(source_p
))
158 remote_rehash_oper_p
= source_p
;
160 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
162 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, temp_dlines
[i
].head
)
166 delete_one_address_conf(aconf
->host
, aconf
);
167 rb_dlinkDestroy(ptr
, &temp_dlines
[i
]);
173 rehash_txlines(struct Client
*source_p
)
175 struct ConfItem
*aconf
;
177 rb_dlink_node
*next_ptr
;
179 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing temp xlines",
180 get_oper_name(source_p
));
181 if (!MyConnect(source_p
))
182 remote_rehash_oper_p
= source_p
;
184 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, xline_conf_list
.head
)
188 if(!aconf
->hold
|| aconf
->lifetime
)
192 rb_dlinkDestroy(ptr
, &xline_conf_list
);
197 rehash_tresvs(struct Client
*source_p
)
199 struct ConfItem
*aconf
;
200 struct rb_radixtree_iteration_state iter
;
202 rb_dlink_node
*next_ptr
;
205 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing temp resvs",
206 get_oper_name(source_p
));
207 if (!MyConnect(source_p
))
208 remote_rehash_oper_p
= source_p
;
210 RB_RADIXTREE_FOREACH(aconf
, &iter
, resv_tree
)
212 if(!aconf
->hold
|| aconf
->lifetime
)
215 rb_radixtree_delete(resv_tree
, aconf
->host
);
219 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, resv_conf_list
.head
)
223 if(!aconf
->hold
|| aconf
->lifetime
)
227 rb_dlinkDestroy(ptr
, &resv_conf_list
);
232 rehash_rejectcache(struct Client
*source_p
)
234 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing reject cache",
235 get_oper_name(source_p
));
236 if (!MyConnect(source_p
))
237 remote_rehash_oper_p
= source_p
;
243 rehash_throttles(struct Client
*source_p
)
245 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing throttles",
246 get_oper_name(source_p
));
247 if (!MyConnect(source_p
))
248 remote_rehash_oper_p
= source_p
;
254 rehash_help(struct Client
*source_p
)
256 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
257 "%s is forcing re-reading of HELP files",
258 get_oper_name(source_p
));
259 if (!MyConnect(source_p
))
260 remote_rehash_oper_p
= source_p
;
265 rehash_nickdelay(struct Client
*source_p
)
269 rb_dlink_node
*safe_ptr
;
271 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
272 "%s is clearing the nick delay table",
273 get_oper_name(source_p
));
274 if (!MyConnect(source_p
))
275 remote_rehash_oper_p
= source_p
;
277 RB_DLINK_FOREACH_SAFE(ptr
, safe_ptr
, nd_list
.head
)
286 static struct hash_commands rehash_commands
[] =
288 {"BANS", rehash_bans_loc
},
289 {"DNS", rehash_dns
},
290 {"SSLD", rehash_ssld
},
291 {"MOTD", rehash_motd
},
292 {"OMOTD", rehash_omotd
},
293 {"TKLINES", rehash_tklines
},
294 {"TDLINES", rehash_tdlines
},
295 {"TXLINES", rehash_txlines
},
296 {"TRESVS", rehash_tresvs
},
297 {"REJECTCACHE", rehash_rejectcache
},
298 {"THROTTLES", rehash_throttles
},
299 {"HELP", rehash_help
},
300 {"NICKDELAY", rehash_nickdelay
},
306 do_rehash(struct Client
*source_p
, const char *type
)
313 for (x
= 0; rehash_commands
[x
].cmd
!= NULL
&& rehash_commands
[x
].handler
!= NULL
;
316 if(irccmp(type
, rehash_commands
[x
].cmd
) == 0)
318 sendto_one(source_p
, form_str(RPL_REHASHING
), me
.name
,
319 source_p
->name
, rehash_commands
[x
].cmd
);
320 ilog(L_MAIN
, "REHASH %s From %s[%s]", type
,
321 get_oper_name(source_p
), source_p
->sockhost
);
322 rehash_commands
[x
].handler(source_p
);
323 remote_rehash_oper_p
= NULL
;
328 /* We are still here..we didn't match */
330 for (x
= 0; rehash_commands
[x
].cmd
!= NULL
&& rehash_commands
[x
].handler
!= NULL
;
333 rb_strlcat(cmdbuf
, " ", sizeof(cmdbuf
));
334 rb_strlcat(cmdbuf
, rehash_commands
[x
].cmd
, sizeof(cmdbuf
));
336 sendto_one_notice(source_p
, ":rehash one of:%s", cmdbuf
);
340 sendto_one(source_p
, form_str(RPL_REHASHING
), me
.name
, source_p
->name
,
341 ConfigFileEntry
.configfile
);
342 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
343 "%s is rehashing server config file", get_oper_name(source_p
));
344 if (!MyConnect(source_p
))
345 remote_rehash_oper_p
= source_p
;
346 ilog(L_MAIN
, "REHASH From %s[%s]", get_oper_name(source_p
),
349 remote_rehash_oper_p
= NULL
;
354 * mo_rehash - REHASH message handler
356 * parv[1] = rehash type or destination
357 * parv[2] = destination
360 mo_rehash(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
362 const char *type
= NULL
, *target_server
= NULL
;
364 if(!IsOperRehash(source_p
))
366 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
367 me
.name
, source_p
->name
, "rehash");
372 type
= parv
[1], target_server
= parv
[2];
373 else if (parc
> 1 && (strchr(parv
[1], '.') || strchr(parv
[1], '?') || strchr(parv
[1], '*')))
374 type
= NULL
, target_server
= parv
[1];
376 type
= parv
[1], target_server
= NULL
;
378 type
= NULL
, target_server
= NULL
;
380 if (target_server
!= NULL
)
382 if(!IsOperRemoteBan(source_p
))
384 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
385 me
.name
, source_p
->name
, "remoteban");
388 sendto_match_servs(source_p
, target_server
,
390 "ENCAP %s REHASH %s",
391 target_server
, type
!= NULL
? type
: "");
392 if (match(target_server
, me
.name
) == 0)
396 do_rehash(source_p
, type
);
400 me_rehash(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
403 if (!IsPerson(source_p
))
406 if (!find_shared_conf(source_p
->username
, source_p
->host
,
407 source_p
->servptr
->name
, SHARED_REHASH
))
410 do_rehash(source_p
, parc
> 1 ? parv
[1] : NULL
);