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
;
87 /* reread /etc/resolv.conf and reopen res socket */
92 rehash_ssld(struct Client
*source_p
)
94 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is restarting ssld",
95 get_oper_name(source_p
));
101 rehash_motd(struct Client
*source_p
)
103 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
104 "%s is forcing re-reading of MOTD file",
105 get_oper_name(source_p
));
106 if (!MyConnect(source_p
))
107 remote_rehash_oper_p
= source_p
;
113 rehash_omotd(struct Client
*source_p
)
115 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
116 "%s is forcing re-reading of OPER MOTD file",
117 get_oper_name(source_p
));
118 if (!MyConnect(source_p
))
119 remote_rehash_oper_p
= source_p
;
121 free_cachefile(oper_motd
);
122 oper_motd
= cache_file(OPATH
, "opers.motd", 0);
126 rehash_tklines(struct Client
*source_p
)
128 struct ConfItem
*aconf
;
129 rb_dlink_node
*ptr
, *next_ptr
;
132 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing temp klines",
133 get_oper_name(source_p
));
134 if (!MyConnect(source_p
))
135 remote_rehash_oper_p
= source_p
;
137 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
139 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, temp_klines
[i
].head
)
143 delete_one_address_conf(aconf
->host
, aconf
);
144 rb_dlinkDestroy(ptr
, &temp_klines
[i
]);
150 rehash_tdlines(struct Client
*source_p
)
152 struct ConfItem
*aconf
;
153 rb_dlink_node
*ptr
, *next_ptr
;
156 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing temp dlines",
157 get_oper_name(source_p
));
158 if (!MyConnect(source_p
))
159 remote_rehash_oper_p
= source_p
;
161 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
163 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, temp_dlines
[i
].head
)
167 delete_one_address_conf(aconf
->host
, aconf
);
168 rb_dlinkDestroy(ptr
, &temp_dlines
[i
]);
174 rehash_txlines(struct Client
*source_p
)
176 struct ConfItem
*aconf
;
178 rb_dlink_node
*next_ptr
;
180 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing temp xlines",
181 get_oper_name(source_p
));
182 if (!MyConnect(source_p
))
183 remote_rehash_oper_p
= source_p
;
185 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, xline_conf_list
.head
)
189 if(!aconf
->hold
|| aconf
->lifetime
)
193 rb_dlinkDestroy(ptr
, &xline_conf_list
);
198 rehash_tresvs(struct Client
*source_p
)
200 struct ConfItem
*aconf
;
201 struct rb_radixtree_iteration_state iter
;
203 rb_dlink_node
*next_ptr
;
206 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing temp resvs",
207 get_oper_name(source_p
));
208 if (!MyConnect(source_p
))
209 remote_rehash_oper_p
= source_p
;
211 RB_RADIXTREE_FOREACH(aconf
, &iter
, resv_tree
)
213 if(!aconf
->hold
|| aconf
->lifetime
)
216 rb_radixtree_delete(resv_tree
, aconf
->host
);
220 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, resv_conf_list
.head
)
224 if(!aconf
->hold
|| aconf
->lifetime
)
228 rb_dlinkDestroy(ptr
, &resv_conf_list
);
233 rehash_rejectcache(struct Client
*source_p
)
235 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing reject cache",
236 get_oper_name(source_p
));
237 if (!MyConnect(source_p
))
238 remote_rehash_oper_p
= source_p
;
244 rehash_throttles(struct Client
*source_p
)
246 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing throttles",
247 get_oper_name(source_p
));
248 if (!MyConnect(source_p
))
249 remote_rehash_oper_p
= source_p
;
255 rehash_help(struct Client
*source_p
)
257 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
258 "%s is forcing re-reading of HELP files",
259 get_oper_name(source_p
));
260 if (!MyConnect(source_p
))
261 remote_rehash_oper_p
= source_p
;
266 rehash_nickdelay(struct Client
*source_p
)
270 rb_dlink_node
*safe_ptr
;
272 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
273 "%s is clearing the nick delay table",
274 get_oper_name(source_p
));
275 if (!MyConnect(source_p
))
276 remote_rehash_oper_p
= source_p
;
278 RB_DLINK_FOREACH_SAFE(ptr
, safe_ptr
, nd_list
.head
)
287 static struct hash_commands rehash_commands
[] =
289 {"BANS", rehash_bans_loc
},
290 {"DNS", rehash_dns
},
291 {"SSLD", rehash_ssld
},
292 {"MOTD", rehash_motd
},
293 {"OMOTD", rehash_omotd
},
294 {"TKLINES", rehash_tklines
},
295 {"TDLINES", rehash_tdlines
},
296 {"TXLINES", rehash_txlines
},
297 {"TRESVS", rehash_tresvs
},
298 {"REJECTCACHE", rehash_rejectcache
},
299 {"THROTTLES", rehash_throttles
},
300 {"HELP", rehash_help
},
301 {"NICKDELAY", rehash_nickdelay
},
307 do_rehash(struct Client
*source_p
, const char *type
)
314 for (x
= 0; rehash_commands
[x
].cmd
!= NULL
&& rehash_commands
[x
].handler
!= NULL
;
317 if(irccmp(type
, rehash_commands
[x
].cmd
) == 0)
319 sendto_one(source_p
, form_str(RPL_REHASHING
), me
.name
,
320 source_p
->name
, rehash_commands
[x
].cmd
);
321 ilog(L_MAIN
, "REHASH %s From %s[%s]", type
,
322 get_oper_name(source_p
), source_p
->sockhost
);
323 rehash_commands
[x
].handler(source_p
);
324 remote_rehash_oper_p
= NULL
;
329 /* We are still here..we didn't match */
331 for (x
= 0; rehash_commands
[x
].cmd
!= NULL
&& rehash_commands
[x
].handler
!= NULL
;
334 rb_strlcat(cmdbuf
, " ", sizeof(cmdbuf
));
335 rb_strlcat(cmdbuf
, rehash_commands
[x
].cmd
, sizeof(cmdbuf
));
337 sendto_one_notice(source_p
, ":rehash one of:%s", cmdbuf
);
341 sendto_one(source_p
, form_str(RPL_REHASHING
), me
.name
, source_p
->name
,
342 ConfigFileEntry
.configfile
);
343 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
344 "%s is rehashing server config file", get_oper_name(source_p
));
345 if (!MyConnect(source_p
))
346 remote_rehash_oper_p
= source_p
;
347 ilog(L_MAIN
, "REHASH From %s[%s]", get_oper_name(source_p
),
350 remote_rehash_oper_p
= NULL
;
355 * mo_rehash - REHASH message handler
357 * parv[1] = rehash type or destination
358 * parv[2] = destination
361 mo_rehash(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
363 const char *type
= NULL
, *target_server
= NULL
;
365 if(!IsOperRehash(source_p
))
367 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
368 me
.name
, source_p
->name
, "rehash");
373 type
= parv
[1], target_server
= parv
[2];
374 else if (parc
> 1 && (strchr(parv
[1], '.') || strchr(parv
[1], '?') || strchr(parv
[1], '*')))
375 type
= NULL
, target_server
= parv
[1];
377 type
= parv
[1], target_server
= NULL
;
379 type
= NULL
, target_server
= NULL
;
381 if (target_server
!= NULL
)
383 if(!IsOperRemoteBan(source_p
))
385 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
386 me
.name
, source_p
->name
, "remoteban");
389 sendto_match_servs(source_p
, target_server
,
391 "ENCAP %s REHASH %s",
392 target_server
, type
!= NULL
? type
: "");
393 if (match(target_server
, me
.name
) == 0)
397 do_rehash(source_p
, type
);
401 me_rehash(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
404 if (!IsPerson(source_p
))
407 if (!find_shared_conf(source_p
->username
, source_p
->host
,
408 source_p
->servptr
->name
, SHARED_REHASH
))
411 do_rehash(source_p
, parc
> 1 ? parv
[1] : NULL
);