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
36 #include "s_newconf.h"
47 static int mo_rehash(struct Client
*, struct Client
*, int, const char **);
48 static int me_rehash(struct Client
*, struct Client
*, int, const char **);
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}}
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_motd(struct Client
*source_p
)
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
;
100 rehash_omotd(struct Client
*source_p
)
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
;
108 free_cachefile(oper_motd
);
109 oper_motd
= cache_file(OPATH
, "opers.motd", 0);
113 rehash_tklines(struct Client
*source_p
)
115 struct ConfItem
*aconf
;
116 rb_dlink_node
*ptr
, *next_ptr
;
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
;
124 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
126 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, temp_klines
[i
].head
)
130 delete_one_address_conf(aconf
->host
, aconf
);
131 rb_dlinkDestroy(ptr
, &temp_klines
[i
]);
137 rehash_tdlines(struct Client
*source_p
)
139 struct ConfItem
*aconf
;
140 rb_dlink_node
*ptr
, *next_ptr
;
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
;
148 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
150 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, temp_dlines
[i
].head
)
154 delete_one_address_conf(aconf
->host
, aconf
);
155 rb_dlinkDestroy(ptr
, &temp_dlines
[i
]);
161 rehash_txlines(struct Client
*source_p
)
163 struct ConfItem
*aconf
;
165 rb_dlink_node
*next_ptr
;
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
;
172 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, xline_conf_list
.head
)
176 if(!aconf
->hold
|| aconf
->lifetime
)
180 rb_dlinkDestroy(ptr
, &xline_conf_list
);
185 rehash_tresvs(struct Client
*source_p
)
187 struct ConfItem
*aconf
;
189 rb_dlink_node
*next_ptr
;
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
;
197 HASH_WALK_SAFE(i
, R_MAX
, ptr
, next_ptr
, resvTable
)
201 if(!aconf
->hold
|| aconf
->lifetime
)
205 rb_dlinkDestroy(ptr
, &resvTable
[i
]);
209 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, resv_conf_list
.head
)
213 if(!aconf
->hold
|| aconf
->lifetime
)
217 rb_dlinkDestroy(ptr
, &resv_conf_list
);
222 rehash_rejectcache(struct Client
*source_p
)
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
;
233 rehash_throttles(struct Client
*source_p
)
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
;
244 rehash_help(struct Client
*source_p
)
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
;
255 rehash_nickdelay(struct Client
*source_p
)
259 rb_dlink_node
*safe_ptr
;
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
;
267 RB_DLINK_FOREACH_SAFE(ptr
, safe_ptr
, nd_list
.head
)
276 static struct hash_commands rehash_commands
[] =
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
},
295 do_rehash(struct Client
*source_p
, const char *type
)
302 for (x
= 0; rehash_commands
[x
].cmd
!= NULL
&& rehash_commands
[x
].handler
!= NULL
;
305 if(irccmp(type
, rehash_commands
[x
].cmd
) == 0)
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
;
317 /* We are still here..we didn't match */
319 for (x
= 0; rehash_commands
[x
].cmd
!= NULL
&& rehash_commands
[x
].handler
!= NULL
;
322 rb_strlcat(cmdbuf
, " ", sizeof(cmdbuf
));
323 rb_strlcat(cmdbuf
, rehash_commands
[x
].cmd
, sizeof(cmdbuf
));
325 sendto_one_notice(source_p
, ":rehash one of:%s", cmdbuf
);
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
),
338 remote_rehash_oper_p
= NULL
;
343 * mo_rehash - REHASH message handler
345 * parv[1] = rehash type or destination
346 * parv[2] = destination
349 mo_rehash(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
351 const char *type
= NULL
, *target_server
= NULL
;
353 if(!IsOperRehash(source_p
))
355 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
356 me
.name
, source_p
->name
, "rehash");
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];
365 type
= parv
[1], target_server
= NULL
;
367 type
= NULL
, target_server
= NULL
;
369 if (target_server
!= NULL
)
371 if(!IsOperRemoteBan(source_p
))
373 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
374 me
.name
, source_p
->name
, "remoteban");
377 sendto_match_servs(source_p
, target_server
,
379 "ENCAP %s REHASH %s",
380 target_server
, type
!= NULL
? type
: "");
381 if (match(target_server
, me
.name
) == 0)
385 do_rehash(source_p
, type
);
391 me_rehash(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
394 if (!IsPerson(source_p
))
397 if (!find_shared_conf(source_p
->username
, source_p
->host
,
398 source_p
->servptr
->name
, SHARED_REHASH
))
401 do_rehash(source_p
, parc
> 1 ? parv
[1] : NULL
);