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
33 #include "s_newconf.h"
43 #include "rb_radixtree.h"
46 static const char rehash_desc
[] =
47 "Provides the REHASH command to reload configuration and other files";
49 static void mo_rehash(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
50 static void me_rehash(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
52 struct Message rehash_msgtab
= {
54 {mg_unreg
, mg_not_oper
, mg_ignore
, mg_ignore
, {me_rehash
, 0}, {mo_rehash
, 0}}
57 mapi_clist_av1 rehash_clist
[] = { &rehash_msgtab
, NULL
};
59 DECLARE_MODULE_AV2(rehash
, NULL
, NULL
, rehash_clist
, NULL
, NULL
, NULL
, NULL
, rehash_desc
);
64 void (*handler
) (struct Client
* source_p
);
68 rehash_bans_loc(struct Client
*source_p
)
70 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is rehashing bans",
71 get_oper_name(source_p
));
72 if (!MyConnect(source_p
))
73 remote_rehash_oper_p
= source_p
;
79 rehash_dns(struct Client
*source_p
)
81 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is rehashing DNS",
82 get_oper_name(source_p
));
83 if (!MyConnect(source_p
))
84 remote_rehash_oper_p
= source_p
;
90 rehash_ssld(struct Client
*source_p
)
92 if (!IsOperAdmin(source_p
))
94 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
95 me
.name
, source_p
->name
, "admin");
99 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is restarting ssld",
100 get_oper_name(source_p
));
106 rehash_motd(struct Client
*source_p
)
108 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
109 "%s is forcing re-reading of MOTD file",
110 get_oper_name(source_p
));
111 if (!MyConnect(source_p
))
112 remote_rehash_oper_p
= source_p
;
118 rehash_omotd(struct Client
*source_p
)
120 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
121 "%s is forcing re-reading of OPER MOTD file",
122 get_oper_name(source_p
));
123 if (!MyConnect(source_p
))
124 remote_rehash_oper_p
= source_p
;
126 free_cachefile(oper_motd
);
127 oper_motd
= cache_file(ircd_paths
[IRCD_PATH_IRCD_OMOTD
], "opers.motd", 0);
131 rehash_tklines(struct Client
*source_p
)
133 struct ConfItem
*aconf
;
134 rb_dlink_node
*ptr
, *next_ptr
;
137 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing temp klines",
138 get_oper_name(source_p
));
139 if (!MyConnect(source_p
))
140 remote_rehash_oper_p
= source_p
;
142 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
144 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, temp_klines
[i
].head
)
148 delete_one_address_conf(aconf
->host
, aconf
);
149 rb_dlinkDestroy(ptr
, &temp_klines
[i
]);
155 rehash_tdlines(struct Client
*source_p
)
157 struct ConfItem
*aconf
;
158 rb_dlink_node
*ptr
, *next_ptr
;
161 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing temp dlines",
162 get_oper_name(source_p
));
163 if (!MyConnect(source_p
))
164 remote_rehash_oper_p
= source_p
;
166 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
168 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, temp_dlines
[i
].head
)
172 delete_one_address_conf(aconf
->host
, aconf
);
173 rb_dlinkDestroy(ptr
, &temp_dlines
[i
]);
179 rehash_txlines(struct Client
*source_p
)
181 struct ConfItem
*aconf
;
183 rb_dlink_node
*next_ptr
;
185 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing temp xlines",
186 get_oper_name(source_p
));
187 if (!MyConnect(source_p
))
188 remote_rehash_oper_p
= source_p
;
190 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, xline_conf_list
.head
)
194 if(!aconf
->hold
|| aconf
->lifetime
)
198 rb_dlinkDestroy(ptr
, &xline_conf_list
);
203 rehash_tresvs(struct Client
*source_p
)
205 struct ConfItem
*aconf
;
206 rb_radixtree_iteration_state iter
;
208 rb_dlink_node
*next_ptr
;
210 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing temp resvs",
211 get_oper_name(source_p
));
212 if (!MyConnect(source_p
))
213 remote_rehash_oper_p
= source_p
;
215 RB_RADIXTREE_FOREACH(aconf
, &iter
, resv_tree
)
217 if(!aconf
->hold
|| aconf
->lifetime
)
220 rb_radixtree_delete(resv_tree
, aconf
->host
);
224 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, resv_conf_list
.head
)
228 if(!aconf
->hold
|| aconf
->lifetime
)
232 rb_dlinkDestroy(ptr
, &resv_conf_list
);
237 rehash_rejectcache(struct Client
*source_p
)
239 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing reject cache",
240 get_oper_name(source_p
));
241 if (!MyConnect(source_p
))
242 remote_rehash_oper_p
= source_p
;
248 rehash_throttles(struct Client
*source_p
)
250 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing throttles",
251 get_oper_name(source_p
));
252 if (!MyConnect(source_p
))
253 remote_rehash_oper_p
= source_p
;
259 rehash_help(struct Client
*source_p
)
261 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
262 "%s is forcing re-reading of HELP files",
263 get_oper_name(source_p
));
264 if (!MyConnect(source_p
))
265 remote_rehash_oper_p
= source_p
;
270 rehash_nickdelay(struct Client
*source_p
)
274 rb_dlink_node
*safe_ptr
;
276 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
277 "%s is clearing the nick delay table",
278 get_oper_name(source_p
));
279 if (!MyConnect(source_p
))
280 remote_rehash_oper_p
= source_p
;
282 RB_DLINK_FOREACH_SAFE(ptr
, safe_ptr
, nd_list
.head
)
291 static struct hash_commands rehash_commands
[] =
293 {"BANS", rehash_bans_loc
},
294 {"DNS", rehash_dns
},
295 {"SSLD", rehash_ssld
},
296 {"MOTD", rehash_motd
},
297 {"OMOTD", rehash_omotd
},
298 {"TKLINES", rehash_tklines
},
299 {"TDLINES", rehash_tdlines
},
300 {"TXLINES", rehash_txlines
},
301 {"TRESVS", rehash_tresvs
},
302 {"REJECTCACHE", rehash_rejectcache
},
303 {"THROTTLES", rehash_throttles
},
304 {"HELP", rehash_help
},
305 {"NICKDELAY", rehash_nickdelay
},
311 do_rehash(struct Client
*source_p
, const char *type
)
318 for (x
= 0; rehash_commands
[x
].cmd
!= NULL
&& rehash_commands
[x
].handler
!= NULL
;
321 if(irccmp(type
, rehash_commands
[x
].cmd
) == 0)
323 sendto_one(source_p
, form_str(RPL_REHASHING
), me
.name
,
324 source_p
->name
, rehash_commands
[x
].cmd
);
325 ilog(L_MAIN
, "REHASH %s From %s[%s]", type
,
326 get_oper_name(source_p
), source_p
->sockhost
);
327 rehash_commands
[x
].handler(source_p
);
328 remote_rehash_oper_p
= NULL
;
333 /* We are still here..we didn't match */
335 for (x
= 0; rehash_commands
[x
].cmd
!= NULL
&& rehash_commands
[x
].handler
!= NULL
;
338 rb_strlcat(cmdbuf
, " ", sizeof(cmdbuf
));
339 rb_strlcat(cmdbuf
, rehash_commands
[x
].cmd
, sizeof(cmdbuf
));
341 sendto_one_notice(source_p
, ":rehash one of:%s", cmdbuf
);
345 sendto_one(source_p
, form_str(RPL_REHASHING
), me
.name
, source_p
->name
,
346 ConfigFileEntry
.configfile
);
347 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
348 "%s is rehashing server config file", get_oper_name(source_p
));
349 if (!MyConnect(source_p
))
350 remote_rehash_oper_p
= source_p
;
351 ilog(L_MAIN
, "REHASH From %s[%s]", get_oper_name(source_p
),
354 remote_rehash_oper_p
= NULL
;
359 * mo_rehash - REHASH message handler
361 * parv[1] = rehash type or destination
362 * parv[2] = destination
365 mo_rehash(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
367 const char *type
= NULL
, *target_server
= NULL
;
369 if(!IsOperRehash(source_p
))
371 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
372 me
.name
, source_p
->name
, "rehash");
377 type
= parv
[1], target_server
= parv
[2];
378 else if (parc
> 1 && (strchr(parv
[1], '.') || strchr(parv
[1], '?') || strchr(parv
[1], '*')))
379 type
= NULL
, target_server
= parv
[1];
381 type
= parv
[1], target_server
= NULL
;
383 type
= NULL
, target_server
= NULL
;
385 if (target_server
!= NULL
)
387 if(!IsOperRemoteBan(source_p
))
389 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
390 me
.name
, source_p
->name
, "remoteban");
393 sendto_match_servs(source_p
, target_server
,
395 "ENCAP %s REHASH %s",
396 target_server
, type
!= NULL
? type
: "");
397 if (match(target_server
, me
.name
) == 0)
401 do_rehash(source_p
, type
);
405 me_rehash(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
408 if (!IsPerson(source_p
))
411 if (!find_shared_conf(source_p
->username
, source_p
->host
,
412 source_p
->servptr
->name
, SHARED_REHASH
))
415 do_rehash(source_p
, parc
> 1 ? parv
[1] : NULL
);