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
24 * $Id: m_rehash.c 3161 2007-01-25 07:23:01Z nenolod $
37 #include "s_newconf.h"
48 static int mo_rehash(struct Client
*, struct Client
*, int, const char **);
49 static int me_rehash(struct Client
*, struct Client
*, int, const char **);
51 struct Message rehash_msgtab
= {
52 "REHASH", 0, 0, 0, MFLG_SLOW
,
53 {mg_unreg
, mg_not_oper
, mg_ignore
, mg_ignore
, {me_rehash
, 0}, {mo_rehash
, 0}}
56 mapi_clist_av1 rehash_clist
[] = { &rehash_msgtab
, NULL
};
57 DECLARE_MODULE_AV1(rehash
, NULL
, NULL
, rehash_clist
, NULL
, NULL
, "$Revision: 3161 $");
62 void (*handler
) (struct Client
* source_p
);
66 rehash_bans_loc(struct Client
*source_p
)
68 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is rehashing bans",
69 get_oper_name(source_p
));
70 if (!MyConnect(source_p
))
71 remote_rehash_oper_p
= source_p
;
77 rehash_dns(struct Client
*source_p
)
79 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is rehashing DNS",
80 get_oper_name(source_p
));
81 if (!MyConnect(source_p
))
82 remote_rehash_oper_p
= source_p
;
84 /* reread /etc/resolv.conf and reopen res socket */
89 rehash_motd(struct Client
*source_p
)
91 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
92 "%s is forcing re-reading of MOTD file",
93 get_oper_name(source_p
));
94 if (!MyConnect(source_p
))
95 remote_rehash_oper_p
= source_p
;
101 rehash_omotd(struct Client
*source_p
)
103 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
104 "%s is forcing re-reading of OPER MOTD file",
105 get_oper_name(source_p
));
106 if (!MyConnect(source_p
))
107 remote_rehash_oper_p
= source_p
;
109 free_cachefile(oper_motd
);
110 oper_motd
= cache_file(OPATH
, "opers.motd", 0);
114 rehash_tklines(struct Client
*source_p
)
116 struct ConfItem
*aconf
;
117 rb_dlink_node
*ptr
, *next_ptr
;
120 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing temp klines",
121 get_oper_name(source_p
));
122 if (!MyConnect(source_p
))
123 remote_rehash_oper_p
= source_p
;
125 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
127 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, temp_klines
[i
].head
)
131 delete_one_address_conf(aconf
->host
, aconf
);
132 rb_dlinkDestroy(ptr
, &temp_klines
[i
]);
138 rehash_tdlines(struct Client
*source_p
)
140 struct ConfItem
*aconf
;
141 rb_dlink_node
*ptr
, *next_ptr
;
144 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing temp dlines",
145 get_oper_name(source_p
));
146 if (!MyConnect(source_p
))
147 remote_rehash_oper_p
= source_p
;
149 for(i
= 0; i
< LAST_TEMP_TYPE
; i
++)
151 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, temp_dlines
[i
].head
)
155 delete_one_address_conf(aconf
->host
, aconf
);
156 rb_dlinkDestroy(ptr
, &temp_dlines
[i
]);
162 rehash_txlines(struct Client
*source_p
)
164 struct ConfItem
*aconf
;
166 rb_dlink_node
*next_ptr
;
168 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing temp xlines",
169 get_oper_name(source_p
));
170 if (!MyConnect(source_p
))
171 remote_rehash_oper_p
= source_p
;
173 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, xline_conf_list
.head
)
177 if(!aconf
->hold
|| aconf
->lifetime
)
181 rb_dlinkDestroy(ptr
, &xline_conf_list
);
186 rehash_tresvs(struct Client
*source_p
)
188 struct ConfItem
*aconf
;
190 rb_dlink_node
*next_ptr
;
193 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing temp resvs",
194 get_oper_name(source_p
));
195 if (!MyConnect(source_p
))
196 remote_rehash_oper_p
= source_p
;
198 HASH_WALK_SAFE(i
, R_MAX
, ptr
, next_ptr
, resvTable
)
202 if(!aconf
->hold
|| aconf
->lifetime
)
206 rb_dlinkDestroy(ptr
, &resvTable
[i
]);
210 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, resv_conf_list
.head
)
214 if(!aconf
->hold
|| aconf
->lifetime
)
218 rb_dlinkDestroy(ptr
, &resv_conf_list
);
223 rehash_rejectcache(struct Client
*source_p
)
225 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing reject cache",
226 get_oper_name(source_p
));
227 if (!MyConnect(source_p
))
228 remote_rehash_oper_p
= source_p
;
234 rehash_throttles(struct Client
*source_p
)
236 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s is clearing throttles",
237 get_oper_name(source_p
));
238 if (!MyConnect(source_p
))
239 remote_rehash_oper_p
= source_p
;
245 rehash_help(struct Client
*source_p
)
247 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
248 "%s is forcing re-reading of HELP files",
249 get_oper_name(source_p
));
250 if (!MyConnect(source_p
))
251 remote_rehash_oper_p
= source_p
;
256 rehash_nickdelay(struct Client
*source_p
)
260 rb_dlink_node
*safe_ptr
;
262 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
263 "%s is clearing the nick delay table",
264 get_oper_name(source_p
));
265 if (!MyConnect(source_p
))
266 remote_rehash_oper_p
= source_p
;
268 RB_DLINK_FOREACH_SAFE(ptr
, safe_ptr
, nd_list
.head
)
277 static struct hash_commands rehash_commands
[] =
279 {"BANS", rehash_bans_loc
},
280 {"DNS", rehash_dns
},
281 {"MOTD", rehash_motd
},
282 {"OMOTD", rehash_omotd
},
283 {"TKLINES", rehash_tklines
},
284 {"TDLINES", rehash_tdlines
},
285 {"TXLINES", rehash_txlines
},
286 {"TRESVS", rehash_tresvs
},
287 {"REJECTCACHE", rehash_rejectcache
},
288 {"THROTTLES", rehash_throttles
},
289 {"HELP", rehash_help
},
290 {"NICKDELAY", rehash_nickdelay
},
296 do_rehash(struct Client
*source_p
, const char *type
)
303 for (x
= 0; rehash_commands
[x
].cmd
!= NULL
&& rehash_commands
[x
].handler
!= NULL
;
306 if(irccmp(type
, rehash_commands
[x
].cmd
) == 0)
308 sendto_one(source_p
, form_str(RPL_REHASHING
), me
.name
,
309 source_p
->name
, rehash_commands
[x
].cmd
);
310 ilog(L_MAIN
, "REHASH %s From %s[%s]", type
,
311 get_oper_name(source_p
), source_p
->sockhost
);
312 rehash_commands
[x
].handler(source_p
);
313 remote_rehash_oper_p
= NULL
;
318 /* We are still here..we didn't match */
320 for (x
= 0; rehash_commands
[x
].cmd
!= NULL
&& rehash_commands
[x
].handler
!= NULL
;
323 rb_strlcat(cmdbuf
, " ", sizeof(cmdbuf
));
324 rb_strlcat(cmdbuf
, rehash_commands
[x
].cmd
, sizeof(cmdbuf
));
326 sendto_one_notice(source_p
, ":rehash one of:%s", cmdbuf
);
330 sendto_one(source_p
, form_str(RPL_REHASHING
), me
.name
, source_p
->name
,
331 ConfigFileEntry
.configfile
);
332 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
333 "%s is rehashing server config file", get_oper_name(source_p
));
334 if (!MyConnect(source_p
))
335 remote_rehash_oper_p
= source_p
;
336 ilog(L_MAIN
, "REHASH From %s[%s]", get_oper_name(source_p
),
339 remote_rehash_oper_p
= NULL
;
344 * mo_rehash - REHASH message handler
346 * parv[1] = rehash type or destination
347 * parv[2] = destination
350 mo_rehash(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
352 const char *type
= NULL
, *target_server
= NULL
;
354 if(!IsOperRehash(source_p
))
356 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
357 me
.name
, source_p
->name
, "rehash");
362 type
= parv
[1], target_server
= parv
[2];
363 else if (parc
> 1 && (strchr(parv
[1], '.') || strchr(parv
[1], '?') || strchr(parv
[1], '*')))
364 type
= NULL
, target_server
= parv
[1];
366 type
= parv
[1], target_server
= NULL
;
368 type
= NULL
, target_server
= NULL
;
370 if (target_server
!= NULL
)
372 if(!IsOperRemoteBan(source_p
))
374 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
375 me
.name
, source_p
->name
, "remoteban");
378 sendto_match_servs(source_p
, target_server
,
380 "ENCAP %s REHASH %s",
381 target_server
, type
!= NULL
? type
: "");
382 if (match(target_server
, me
.name
) == 0)
386 do_rehash(source_p
, type
);
392 me_rehash(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
395 if (!IsPerson(source_p
))
398 if (!find_shared_conf(source_p
->username
, source_p
->host
,
399 source_p
->servptr
->name
, SHARED_REHASH
))
402 do_rehash(source_p
, parc
> 1 ? parv
[1] : NULL
);