]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * s_conf.c: Configuration file functions. | |
4 | * | |
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 | |
8 | * | |
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. | |
13 | * | |
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. | |
18 | * | |
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 | |
22 | * USA | |
212380e3 AC |
23 | */ |
24 | ||
25 | #include "stdinc.h" | |
26 | #include "ircd_defs.h" | |
212380e3 | 27 | #include "s_conf.h" |
c4e6888e | 28 | #include "s_user.h" |
212380e3 | 29 | #include "s_newconf.h" |
8b801ad1 | 30 | #include "newconf.h" |
212380e3 AC |
31 | #include "s_serv.h" |
32 | #include "s_stats.h" | |
33 | #include "channel.h" | |
34 | #include "class.h" | |
35 | #include "client.h" | |
212380e3 | 36 | #include "hash.h" |
4562c604 | 37 | #include "match.h" |
212380e3 AC |
38 | #include "ircd.h" |
39 | #include "listener.h" | |
40 | #include "hostmask.h" | |
41 | #include "modules.h" | |
42 | #include "numeric.h" | |
4016731b | 43 | #include "logger.h" |
212380e3 | 44 | #include "send.h" |
212380e3 AC |
45 | #include "reject.h" |
46 | #include "cache.h" | |
422bb0b5 | 47 | #include "privilege.h" |
c6d72037 | 48 | #include "sslproc.h" |
c53ca1e0 | 49 | #include "wsproc.h" |
80c9ac51 | 50 | #include "bandbi.h" |
27f616dd | 51 | #include "operhash.h" |
c55b2782 | 52 | #include "chmode.h" |
7d603754 | 53 | #include "hook.h" |
77d3d2db | 54 | #include "s_assert.h" |
64fae260 | 55 | #include "authproc.h" |
01978a2c | 56 | #include "supported.h" |
212380e3 AC |
57 | |
58 | struct config_server_hide ConfigServerHide; | |
59 | ||
6ab8c0d3 | 60 | extern int yyparse(void); /* defined in y.tab.c */ |
401cb2bb | 61 | extern char yy_linebuf[16384]; /* defined in ircd_lexer.l */ |
212380e3 | 62 | |
398b6a73 | 63 | static rb_bh *confitem_heap = NULL; |
212380e3 | 64 | |
9197bc35 JT |
65 | rb_dlink_list prop_bans; |
66 | ||
330fc5c1 AC |
67 | rb_dlink_list temp_klines[LAST_TEMP_TYPE]; |
68 | rb_dlink_list temp_dlines[LAST_TEMP_TYPE]; | |
69 | rb_dlink_list service_list; | |
212380e3 AC |
70 | |
71 | /* internally defined functions */ | |
72 | static void set_default_conf(void); | |
73 | static void validate_conf(void); | |
29c92cf9 | 74 | static void read_conf(void); |
212380e3 AC |
75 | static void clear_out_old_conf(void); |
76 | ||
9197bc35 | 77 | static void expire_prop_bans(void *list); |
212380e3 AC |
78 | static void expire_temp_kd(void *list); |
79 | static void reorganise_temp_kd(void *list); | |
80 | ||
81 | FILE *conf_fbfile_in; | |
82 | extern char yytext[]; | |
83 | ||
84 | static int verify_access(struct Client *client_p, const char *username); | |
b4a7304c | 85 | static struct ConfItem *find_address_conf_by_client(struct Client *client_p, const char *username); |
212380e3 AC |
86 | static int attach_iline(struct Client *, struct ConfItem *); |
87 | ||
88 | void | |
89 | init_s_conf(void) | |
90 | { | |
b2c190a6 | 91 | confitem_heap = rb_bh_create(sizeof(struct ConfItem), CONFITEM_HEAP_SIZE, "confitem_heap"); |
212380e3 | 92 | |
9197bc35 JT |
93 | rb_event_addish("expire_prop_bans", expire_prop_bans, &prop_bans, 60); |
94 | ||
12aea5fe VY |
95 | rb_event_addish("expire_temp_klines", expire_temp_kd, &temp_klines[TEMP_MIN], 60); |
96 | rb_event_addish("expire_temp_dlines", expire_temp_kd, &temp_dlines[TEMP_MIN], 60); | |
212380e3 | 97 | |
12aea5fe | 98 | rb_event_addish("expire_temp_klines_hour", reorganise_temp_kd, |
212380e3 | 99 | &temp_klines[TEMP_HOUR], 3600); |
12aea5fe | 100 | rb_event_addish("expire_temp_dlines_hour", reorganise_temp_kd, |
212380e3 | 101 | &temp_dlines[TEMP_HOUR], 3600); |
12aea5fe | 102 | rb_event_addish("expire_temp_klines_day", reorganise_temp_kd, |
212380e3 | 103 | &temp_klines[TEMP_DAY], 86400); |
12aea5fe | 104 | rb_event_addish("expire_temp_dlines_day", reorganise_temp_kd, |
212380e3 | 105 | &temp_dlines[TEMP_DAY], 86400); |
12aea5fe | 106 | rb_event_addish("expire_temp_klines_week", reorganise_temp_kd, |
212380e3 | 107 | &temp_klines[TEMP_WEEK], 604800); |
12aea5fe | 108 | rb_event_addish("expire_temp_dlines_week", reorganise_temp_kd, |
212380e3 AC |
109 | &temp_dlines[TEMP_WEEK], 604800); |
110 | } | |
111 | ||
112 | /* | |
113 | * make_conf | |
114 | * | |
115 | * inputs - none | |
116 | * output - pointer to new conf entry | |
117 | * side effects - none | |
118 | */ | |
119 | struct ConfItem * | |
120 | make_conf() | |
121 | { | |
122 | struct ConfItem *aconf; | |
123 | ||
398b6a73 | 124 | aconf = rb_bh_alloc(confitem_heap); |
212380e3 AC |
125 | aconf->status = CONF_ILLEGAL; |
126 | return (aconf); | |
127 | } | |
128 | ||
129 | /* | |
130 | * free_conf | |
131 | * | |
132 | * inputs - pointer to conf to free | |
133 | * output - none | |
134 | * side effects - crucial password fields are zeroed, conf is freed | |
135 | */ | |
136 | void | |
137 | free_conf(struct ConfItem *aconf) | |
138 | { | |
139 | s_assert(aconf != NULL); | |
140 | if(aconf == NULL) | |
141 | return; | |
142 | ||
143 | /* security.. */ | |
144 | if(aconf->passwd) | |
145 | memset(aconf->passwd, 0, strlen(aconf->passwd)); | |
146 | if(aconf->spasswd) | |
147 | memset(aconf->spasswd, 0, strlen(aconf->spasswd)); | |
148 | ||
637c4932 VY |
149 | rb_free(aconf->passwd); |
150 | rb_free(aconf->spasswd); | |
637c4932 VY |
151 | rb_free(aconf->className); |
152 | rb_free(aconf->user); | |
153 | rb_free(aconf->host); | |
212380e3 | 154 | |
27f616dd JT |
155 | if(IsConfBan(aconf)) |
156 | operhash_delete(aconf->info.oper); | |
157 | else | |
158 | rb_free(aconf->info.name); | |
159 | ||
398b6a73 | 160 | rb_bh_free(confitem_heap, aconf); |
212380e3 AC |
161 | } |
162 | ||
163 | /* | |
164 | * check_client | |
165 | * | |
166 | * inputs - pointer to client | |
167 | * output - 0 = Success | |
168 | * NOT_AUTHORISED (-1) = Access denied (no I line match) | |
85368a13 | 169 | * I_SOCKET_ERROR (-2) = Bad socket. |
212380e3 AC |
170 | * I_LINE_FULL (-3) = I-line is full |
171 | * TOO_MANY (-4) = Too many connections from hostname | |
172 | * BANNED_CLIENT (-5) = K-lined | |
173 | * side effects - Ordinary client access check. | |
174 | * Look for conf lines which have the same | |
175 | * status as the flags passed. | |
176 | */ | |
177 | int | |
178 | check_client(struct Client *client_p, struct Client *source_p, const char *username) | |
179 | { | |
180 | int i; | |
181 | ||
212380e3 AC |
182 | if((i = verify_access(source_p, username))) |
183 | { | |
55abcbb2 | 184 | ilog(L_FUSER, "Access denied: %s[%s]", |
212380e3 AC |
185 | source_p->name, source_p->sockhost); |
186 | } | |
55abcbb2 | 187 | |
212380e3 AC |
188 | switch (i) |
189 | { | |
85368a13 | 190 | case I_SOCKET_ERROR: |
212380e3 AC |
191 | exit_client(client_p, source_p, &me, "Socket Error"); |
192 | break; | |
193 | ||
194 | case TOO_MANY_LOCAL: | |
606384ae JT |
195 | /* Note that these notices are sent to opers on other |
196 | * servers also, so even if local opers are allowed to | |
197 | * see the IP, we still cannot send it. | |
198 | */ | |
212380e3 AC |
199 | sendto_realops_snomask(SNO_FULL, L_NETWIDE, |
200 | "Too many local connections for %s!%s%s@%s", | |
201 | source_p->name, IsGotId(source_p) ? "" : "~", | |
606384ae JT |
202 | source_p->username, |
203 | show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : source_p->host); | |
212380e3 AC |
204 | |
205 | ilog(L_FUSER, "Too many local connections from %s!%s%s@%s", | |
206 | source_p->name, IsGotId(source_p) ? "" : "~", | |
55abcbb2 | 207 | source_p->username, source_p->sockhost); |
212380e3 | 208 | |
47adde3d | 209 | ServerStats.is_ref++; |
212380e3 AC |
210 | exit_client(client_p, source_p, &me, "Too many host connections (local)"); |
211 | break; | |
212 | ||
213 | case TOO_MANY_GLOBAL: | |
214 | sendto_realops_snomask(SNO_FULL, L_NETWIDE, | |
215 | "Too many global connections for %s!%s%s@%s", | |
216 | source_p->name, IsGotId(source_p) ? "" : "~", | |
606384ae JT |
217 | source_p->username, |
218 | show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : source_p->host); | |
212380e3 AC |
219 | ilog(L_FUSER, "Too many global connections from %s!%s%s@%s", |
220 | source_p->name, IsGotId(source_p) ? "" : "~", | |
221 | source_p->username, source_p->sockhost); | |
222 | ||
47adde3d | 223 | ServerStats.is_ref++; |
212380e3 AC |
224 | exit_client(client_p, source_p, &me, "Too many host connections (global)"); |
225 | break; | |
226 | ||
227 | case TOO_MANY_IDENT: | |
228 | sendto_realops_snomask(SNO_FULL, L_NETWIDE, | |
229 | "Too many user connections for %s!%s%s@%s", | |
230 | source_p->name, IsGotId(source_p) ? "" : "~", | |
606384ae JT |
231 | source_p->username, |
232 | show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : source_p->host); | |
212380e3 AC |
233 | ilog(L_FUSER, "Too many user connections from %s!%s%s@%s", |
234 | source_p->name, IsGotId(source_p) ? "" : "~", | |
235 | source_p->username, source_p->sockhost); | |
236 | ||
47adde3d | 237 | ServerStats.is_ref++; |
212380e3 AC |
238 | exit_client(client_p, source_p, &me, "Too many user connections (global)"); |
239 | break; | |
240 | ||
241 | case I_LINE_FULL: | |
242 | sendto_realops_snomask(SNO_FULL, L_NETWIDE, | |
243 | "I-line is full for %s!%s%s@%s (%s).", | |
244 | source_p->name, IsGotId(source_p) ? "" : "~", | |
245 | source_p->username, source_p->host, | |
4b7e6904 | 246 | show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : "255.255.255.255"); |
212380e3 | 247 | |
55abcbb2 | 248 | ilog(L_FUSER, "Too many connections from %s!%s%s@%s.", |
212380e3 AC |
249 | source_p->name, IsGotId(source_p) ? "" : "~", |
250 | source_p->username, source_p->sockhost); | |
251 | ||
47adde3d | 252 | ServerStats.is_ref++; |
212380e3 AC |
253 | exit_client(client_p, source_p, &me, |
254 | "No more connections allowed in your connection class"); | |
255 | break; | |
256 | ||
257 | case NOT_AUTHORISED: | |
258 | { | |
259 | int port = -1; | |
c6ad9b0c | 260 | port = ntohs(GET_SS_PORT(&source_p->localClient->listener->addr[0])); |
55abcbb2 | 261 | |
47adde3d | 262 | ServerStats.is_ref++; |
212380e3 AC |
263 | /* jdc - lists server name & port connections are on */ |
264 | /* a purely cosmetical change */ | |
265 | /* why ipaddr, and not just source_p->sockhost? --fl */ | |
266 | #if 0 | |
267 | static char ipaddr[HOSTIPLEN]; | |
caa4d9d2 | 268 | rb_inet_ntop_sock(&source_p->localClient->ip, ipaddr, sizeof(ipaddr)); |
212380e3 AC |
269 | #endif |
270 | sendto_realops_snomask(SNO_UNAUTH, L_ALL, | |
271 | "Unauthorised client connection from " | |
272 | "%s!%s%s@%s [%s] on [%s/%u].", | |
273 | source_p->name, IsGotId(source_p) ? "" : "~", | |
274 | source_p->username, source_p->host, | |
275 | source_p->sockhost, | |
276 | source_p->localClient->listener->name, port); | |
277 | ||
278 | ilog(L_FUSER, | |
279 | "Unauthorised client connection from %s!%s%s@%s on [%s/%u].", | |
280 | source_p->name, IsGotId(source_p) ? "" : "~", | |
281 | source_p->username, source_p->sockhost, | |
282 | source_p->localClient->listener->name, port); | |
35f6f850 | 283 | add_reject(client_p, NULL, NULL); |
212380e3 AC |
284 | exit_client(client_p, source_p, &me, |
285 | "You are not authorised to use this server"); | |
286 | break; | |
287 | } | |
288 | case BANNED_CLIENT: | |
212380e3 | 289 | exit_client(client_p, client_p, &me, "*** Banned "); |
47adde3d | 290 | ServerStats.is_ref++; |
212380e3 AC |
291 | break; |
292 | ||
293 | case 0: | |
294 | default: | |
295 | break; | |
296 | } | |
297 | return (i); | |
298 | } | |
299 | ||
300 | /* | |
301 | * verify_access | |
302 | * | |
303 | * inputs - pointer to client to verify | |
304 | * - pointer to proposed username | |
305 | * output - 0 if success -'ve if not | |
306 | * side effect - find the first (best) I line to attach. | |
307 | */ | |
308 | static int | |
309 | verify_access(struct Client *client_p, const char *username) | |
310 | { | |
311 | struct ConfItem *aconf; | |
212380e3 | 312 | |
b4a7304c | 313 | aconf = find_address_conf_by_client(client_p, username); |
212380e3 AC |
314 | if(aconf == NULL) |
315 | return NOT_AUTHORISED; | |
316 | ||
317 | if(aconf->status & CONF_CLIENT) | |
318 | { | |
319 | if(aconf->flags & CONF_FLAGS_REDIR) | |
320 | { | |
88520303 | 321 | sendto_one_numeric(client_p, RPL_REDIR, form_str(RPL_REDIR), |
27f616dd | 322 | aconf->info.name ? aconf->info.name : "", aconf->port); |
212380e3 AC |
323 | return (NOT_AUTHORISED); |
324 | } | |
325 | ||
212380e3 AC |
326 | /* Thanks for spoof idea amm */ |
327 | if(IsConfDoSpoofIp(aconf)) | |
328 | { | |
329 | char *p; | |
330 | ||
331 | /* show_ip() depends on this --fl */ | |
332 | SetIPSpoof(client_p); | |
333 | ||
334 | if(IsConfSpoofNotice(aconf)) | |
335 | { | |
336 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
337 | "%s spoofing: %s as %s", | |
338 | client_p->name, | |
27f616dd JT |
339 | show_ip(NULL, client_p) ? client_p->host : aconf->info.name, |
340 | aconf->info.name); | |
212380e3 AC |
341 | } |
342 | ||
343 | /* user@host spoof */ | |
27f616dd | 344 | if((p = strchr(aconf->info.name, '@')) != NULL) |
212380e3 AC |
345 | { |
346 | char *host = p+1; | |
347 | *p = '\0'; | |
348 | ||
27f616dd | 349 | rb_strlcpy(client_p->username, aconf->info.name, |
212380e3 | 350 | sizeof(client_p->username)); |
f427c8b0 | 351 | rb_strlcpy(client_p->host, host, |
212380e3 AC |
352 | sizeof(client_p->host)); |
353 | *p = '@'; | |
354 | } | |
355 | else | |
27f616dd | 356 | rb_strlcpy(client_p->host, aconf->info.name, sizeof(client_p->host)); |
212380e3 AC |
357 | } |
358 | return (attach_iline(client_p, aconf)); | |
359 | } | |
360 | else if(aconf->status & CONF_KILL) | |
361 | { | |
362 | if(ConfigFileEntry.kline_with_reason) | |
212380e3 | 363 | sendto_one(client_p, |
92fb5c31 | 364 | form_str(ERR_YOUREBANNEDCREEP), |
a12ad044 JT |
365 | me.name, client_p->name, |
366 | get_user_ban_reason(aconf)); | |
35f6f850 | 367 | add_reject(client_p, aconf->user, aconf->host); |
212380e3 AC |
368 | return (BANNED_CLIENT); |
369 | } | |
212380e3 AC |
370 | |
371 | return NOT_AUTHORISED; | |
372 | } | |
373 | ||
374 | ||
b4a7304c JT |
375 | /* |
376 | * find_address_conf_by_client | |
377 | */ | |
378 | static struct ConfItem * | |
379 | find_address_conf_by_client(struct Client *client_p, const char *username) | |
380 | { | |
381 | struct ConfItem *aconf; | |
382 | char non_ident[USERLEN + 1]; | |
383 | ||
384 | if(IsGotId(client_p)) | |
385 | { | |
386 | aconf = find_address_conf(client_p->host, client_p->sockhost, | |
387 | client_p->username, client_p->username, | |
388 | (struct sockaddr *) &client_p->localClient->ip, | |
e867208d | 389 | GET_SS_FAMILY(&client_p->localClient->ip), |
b4a7304c JT |
390 | client_p->localClient->auth_user); |
391 | } | |
392 | else | |
393 | { | |
394 | rb_strlcpy(non_ident, "~", sizeof(non_ident)); | |
395 | rb_strlcat(non_ident, username, sizeof(non_ident)); | |
396 | aconf = find_address_conf(client_p->host, client_p->sockhost, | |
397 | non_ident, client_p->username, | |
398 | (struct sockaddr *) &client_p->localClient->ip, | |
e867208d | 399 | GET_SS_FAMILY(&client_p->localClient->ip), |
b4a7304c JT |
400 | client_p->localClient->auth_user); |
401 | } | |
402 | return aconf; | |
403 | } | |
404 | ||
405 | ||
212380e3 AC |
406 | /* |
407 | * add_ip_limit | |
55abcbb2 | 408 | * |
212380e3 AC |
409 | * Returns 1 if successful 0 if not |
410 | * | |
411 | * This checks if the user has exceed the limits for their class | |
412 | * unless of course they are exempt.. | |
413 | */ | |
414 | ||
415 | static int | |
416 | add_ip_limit(struct Client *client_p, struct ConfItem *aconf) | |
417 | { | |
b2c190a6 | 418 | rb_patricia_node_t *pnode; |
e33e589c | 419 | int bitlen; |
212380e3 AC |
420 | |
421 | /* If the limits are 0 don't do anything.. */ | |
e33e589c JT |
422 | if(ConfCidrAmount(aconf) == 0 |
423 | || (ConfCidrIpv4Bitlen(aconf) == 0 && ConfCidrIpv6Bitlen(aconf) == 0)) | |
212380e3 AC |
424 | return -1; |
425 | ||
b2c190a6 | 426 | pnode = rb_match_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip); |
212380e3 | 427 | |
e33e589c JT |
428 | if(GET_SS_FAMILY(&client_p->localClient->ip) == AF_INET) |
429 | bitlen = ConfCidrIpv4Bitlen(aconf); | |
430 | else | |
431 | bitlen = ConfCidrIpv6Bitlen(aconf); | |
432 | ||
212380e3 | 433 | if(pnode == NULL) |
e33e589c | 434 | pnode = make_and_lookup_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip, bitlen); |
212380e3 AC |
435 | |
436 | s_assert(pnode != NULL); | |
437 | ||
438 | if(pnode != NULL) | |
439 | { | |
e33e589c | 440 | if(((intptr_t)pnode->data) >= ConfCidrAmount(aconf) && !IsConfExemptLimits(aconf)) |
212380e3 AC |
441 | { |
442 | /* This should only happen if the limits are set to 0 */ | |
e33e589c | 443 | if((intptr_t)pnode->data == 0) |
212380e3 | 444 | { |
b2c190a6 | 445 | rb_patricia_remove(ConfIpLimits(aconf), pnode); |
212380e3 AC |
446 | } |
447 | return (0); | |
448 | } | |
449 | ||
e33e589c | 450 | pnode->data = (void *)(((intptr_t)pnode->data) + 1); |
212380e3 AC |
451 | } |
452 | return 1; | |
453 | } | |
454 | ||
455 | static void | |
456 | remove_ip_limit(struct Client *client_p, struct ConfItem *aconf) | |
457 | { | |
b2c190a6 | 458 | rb_patricia_node_t *pnode; |
212380e3 AC |
459 | |
460 | /* If the limits are 0 don't do anything.. */ | |
e33e589c JT |
461 | if(ConfCidrAmount(aconf) == 0 |
462 | || (ConfCidrIpv4Bitlen(aconf) == 0 && ConfCidrIpv6Bitlen(aconf) == 0)) | |
212380e3 AC |
463 | return; |
464 | ||
b2c190a6 | 465 | pnode = rb_match_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip); |
212380e3 AC |
466 | if(pnode == NULL) |
467 | return; | |
468 | ||
e33e589c JT |
469 | pnode->data = (void *)(((intptr_t)pnode->data) - 1); |
470 | if(((intptr_t)pnode->data) == 0) | |
212380e3 | 471 | { |
b2c190a6 | 472 | rb_patricia_remove(ConfIpLimits(aconf), pnode); |
212380e3 AC |
473 | } |
474 | ||
475 | } | |
476 | ||
477 | /* | |
478 | * attach_iline | |
479 | * | |
480 | * inputs - client pointer | |
481 | * - conf pointer | |
482 | * output - | |
483 | * side effects - do actual attach | |
484 | */ | |
485 | static int | |
486 | attach_iline(struct Client *client_p, struct ConfItem *aconf) | |
487 | { | |
488 | struct Client *target_p; | |
330fc5c1 | 489 | rb_dlink_node *ptr; |
212380e3 AC |
490 | int local_count = 0; |
491 | int global_count = 0; | |
492 | int ident_count = 0; | |
15f92147 | 493 | int unidented; |
212380e3 AC |
494 | |
495 | if(IsConfExemptLimits(aconf)) | |
496 | return (attach_conf(client_p, aconf)); | |
497 | ||
15f92147 JT |
498 | unidented = !IsGotId(client_p) && !IsNoTilde(aconf) && |
499 | (!IsConfDoSpoofIp(aconf) || !strchr(aconf->info.name, '@')); | |
212380e3 AC |
500 | |
501 | /* find_hostname() returns the head of the list to search */ | |
5cefa1d6 | 502 | RB_DLINK_FOREACH(ptr, find_hostname(client_p->host)) |
212380e3 AC |
503 | { |
504 | target_p = ptr->data; | |
505 | ||
506 | if(irccmp(client_p->host, target_p->orighost) != 0) | |
507 | continue; | |
508 | ||
509 | if(MyConnect(target_p)) | |
510 | local_count++; | |
511 | ||
512 | global_count++; | |
513 | ||
514 | if(unidented) | |
515 | { | |
516 | if(*target_p->username == '~') | |
517 | ident_count++; | |
518 | } | |
519 | else if(irccmp(target_p->username, client_p->username) == 0) | |
520 | ident_count++; | |
521 | ||
522 | if(ConfMaxLocal(aconf) && local_count >= ConfMaxLocal(aconf)) | |
523 | return (TOO_MANY_LOCAL); | |
524 | else if(ConfMaxGlobal(aconf) && global_count >= ConfMaxGlobal(aconf)) | |
525 | return (TOO_MANY_GLOBAL); | |
526 | else if(ConfMaxIdent(aconf) && ident_count >= ConfMaxIdent(aconf)) | |
527 | return (TOO_MANY_IDENT); | |
528 | } | |
529 | ||
530 | ||
531 | return (attach_conf(client_p, aconf)); | |
532 | } | |
533 | ||
534 | /* | |
535 | * detach_conf | |
536 | * | |
537 | * inputs - pointer to client to detach | |
538 | * output - 0 for success, -1 for failure | |
539 | * side effects - Disassociate configuration from the client. | |
540 | * Also removes a class from the list if marked for deleting. | |
541 | */ | |
542 | int | |
543 | detach_conf(struct Client *client_p) | |
544 | { | |
545 | struct ConfItem *aconf; | |
546 | ||
547 | aconf = client_p->localClient->att_conf; | |
548 | ||
549 | if(aconf != NULL) | |
550 | { | |
551 | if(ClassPtr(aconf)) | |
552 | { | |
553 | remove_ip_limit(client_p, aconf); | |
554 | ||
555 | if(ConfCurrUsers(aconf) > 0) | |
556 | --ConfCurrUsers(aconf); | |
557 | ||
558 | if(ConfMaxUsers(aconf) == -1 && ConfCurrUsers(aconf) == 0) | |
559 | { | |
560 | free_class(ClassPtr(aconf)); | |
561 | ClassPtr(aconf) = NULL; | |
562 | } | |
563 | ||
564 | } | |
565 | ||
566 | aconf->clients--; | |
567 | if(!aconf->clients && IsIllegal(aconf)) | |
568 | free_conf(aconf); | |
569 | ||
570 | client_p->localClient->att_conf = NULL; | |
571 | return 0; | |
572 | } | |
573 | ||
574 | return -1; | |
575 | } | |
576 | ||
577 | /* | |
578 | * attach_conf | |
55abcbb2 | 579 | * |
212380e3 AC |
580 | * inputs - client pointer |
581 | * - conf pointer | |
582 | * output - | |
583 | * side effects - Associate a specific configuration entry to a *local* | |
584 | * client (this is the one which used in accepting the | |
585 | * connection). Note, that this automatically changes the | |
586 | * attachment if there was an old one... | |
587 | */ | |
588 | int | |
589 | attach_conf(struct Client *client_p, struct ConfItem *aconf) | |
590 | { | |
591 | if(IsIllegal(aconf)) | |
592 | return (NOT_AUTHORISED); | |
593 | ||
86432f8f SA |
594 | if(s_assert(ClassPtr(aconf))) |
595 | return (NOT_AUTHORISED); | |
596 | ||
597 | if(!add_ip_limit(client_p, aconf)) | |
598 | return (TOO_MANY_LOCAL); | |
212380e3 AC |
599 | |
600 | if((aconf->status & CONF_CLIENT) && | |
601 | ConfCurrUsers(aconf) >= ConfMaxUsers(aconf) && ConfMaxUsers(aconf) > 0) | |
602 | { | |
603 | if(!IsConfExemptLimits(aconf)) | |
604 | { | |
605 | return (I_LINE_FULL); | |
606 | } | |
607 | else | |
608 | { | |
5366977b | 609 | sendto_one_notice(client_p, ":*** I: line is full, but you have an >I: line!"); |
212380e3 AC |
610 | } |
611 | ||
612 | } | |
613 | ||
614 | if(client_p->localClient->att_conf != NULL) | |
615 | detach_conf(client_p); | |
616 | ||
617 | client_p->localClient->att_conf = aconf; | |
618 | ||
619 | aconf->clients++; | |
620 | ConfCurrUsers(aconf)++; | |
621 | return (0); | |
622 | } | |
623 | ||
624 | /* | |
625 | * rehash | |
626 | * | |
627 | * Actual REHASH service routine. Called with sig == 0 if it has been called | |
628 | * as a result of an operator issuing this command, else assume it has been | |
629 | * called as a result of the server receiving a HUP signal. | |
630 | */ | |
ab31d2b0 EM |
631 | bool |
632 | rehash(bool sig) | |
212380e3 | 633 | { |
c4e6888e EK |
634 | rb_dlink_node *n; |
635 | ||
2575a78b EM |
636 | hook_data_rehash hdata = { sig }; |
637 | ||
ab31d2b0 | 638 | if(sig) |
212380e3 AC |
639 | sendto_realops_snomask(SNO_GENERAL, L_ALL, |
640 | "Got signal SIGHUP, reloading ircd conf. file"); | |
212380e3 | 641 | |
f60055d3 | 642 | rehash_authd(); |
2575a78b | 643 | |
212380e3 | 644 | /* don't close listeners until we know we can go ahead with the rehash */ |
ab31d2b0 | 645 | read_conf_files(false); |
212380e3 AC |
646 | |
647 | if(ServerInfo.description != NULL) | |
f427c8b0 | 648 | rb_strlcpy(me.info, ServerInfo.description, sizeof(me.info)); |
212380e3 | 649 | else |
f427c8b0 | 650 | rb_strlcpy(me.info, "unknown", sizeof(me.info)); |
212380e3 AC |
651 | |
652 | open_logfiles(); | |
2575a78b | 653 | |
c4e6888e EK |
654 | RB_DLINK_FOREACH(n, local_oper_list.head) |
655 | { | |
656 | struct Client *oper = n->data; | |
657 | const char *modeparv[4]; | |
658 | modeparv[0] = modeparv[1] = oper->name; | |
659 | modeparv[2] = "+"; | |
660 | modeparv[3] = NULL; | |
661 | user_mode(oper, oper, 3, modeparv); | |
662 | } | |
663 | ||
2575a78b | 664 | call_hook(h_rehash, &hdata); |
ab31d2b0 | 665 | return false; |
212380e3 AC |
666 | } |
667 | ||
212380e3 | 668 | void |
ab31d2b0 | 669 | rehash_bans(void) |
212380e3 | 670 | { |
80c9ac51 | 671 | bandb_rehash_bans(); |
212380e3 AC |
672 | } |
673 | ||
674 | /* | |
675 | * set_default_conf() | |
676 | * | |
677 | * inputs - NONE | |
678 | * output - NONE | |
679 | * side effects - Set default values here. | |
680 | * This is called **PRIOR** to parsing the | |
681 | * configuration file. If you want to do some validation | |
682 | * of values later, put them in validate_conf(). | |
683 | */ | |
684 | ||
212380e3 AC |
685 | static void |
686 | set_default_conf(void) | |
687 | { | |
688 | /* ServerInfo.name is not rehashable */ | |
689 | /* ServerInfo.name = ServerInfo.name; */ | |
690 | ServerInfo.description = NULL; | |
010c4fbd | 691 | ServerInfo.network_name = NULL; |
212380e3 | 692 | |
d4214e94 SA |
693 | memset(&ServerInfo.bind4, 0, sizeof(ServerInfo.bind4)); |
694 | SET_SS_FAMILY(&ServerInfo.bind4, AF_UNSPEC); | |
d4214e94 SA |
695 | memset(&ServerInfo.bind6, 0, sizeof(ServerInfo.bind6)); |
696 | SET_SS_FAMILY(&ServerInfo.bind6, AF_UNSPEC); | |
212380e3 | 697 | |
212380e3 AC |
698 | AdminInfo.name = NULL; |
699 | AdminInfo.email = NULL; | |
700 | AdminInfo.description = NULL; | |
701 | ||
010c4fbd KB |
702 | ConfigFileEntry.default_operstring = NULL; |
703 | ConfigFileEntry.default_adminstring = NULL; | |
704 | ConfigFileEntry.servicestring = NULL; | |
7d33cce8 | 705 | ConfigFileEntry.sasl_service = NULL; |
212380e3 | 706 | |
55abcbb2 | 707 | ConfigFileEntry.default_umodes = UMODE_INVISIBLE; |
d2e0b78f AC |
708 | ConfigFileEntry.failed_oper_notice = true; |
709 | ConfigFileEntry.anti_nick_flood = false; | |
710 | ConfigFileEntry.disable_fake_channels = false; | |
212380e3 AC |
711 | ConfigFileEntry.max_nick_time = 20; |
712 | ConfigFileEntry.max_nick_changes = 5; | |
713 | ConfigFileEntry.max_accept = 20; | |
714 | ConfigFileEntry.max_monitor = 60; | |
715 | ConfigFileEntry.nick_delay = 900; /* 15 minutes */ | |
d2e0b78f | 716 | ConfigFileEntry.target_change = true; |
212380e3 AC |
717 | ConfigFileEntry.anti_spam_exit_message_time = 0; |
718 | ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT; | |
719 | ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT; | |
d2e0b78f AC |
720 | ConfigFileEntry.client_exit = true; |
721 | ConfigFileEntry.dline_with_reason = true; | |
722 | ConfigFileEntry.kline_with_reason = true; | |
d2e0b78f AC |
723 | ConfigFileEntry.warn_no_nline = true; |
724 | ConfigFileEntry.non_redundant_klines = true; | |
725 | ConfigFileEntry.stats_e_disabled = false; | |
726 | ConfigFileEntry.stats_o_oper_only = false; | |
212380e3 AC |
727 | ConfigFileEntry.stats_k_oper_only = 1; /* masked */ |
728 | ConfigFileEntry.stats_i_oper_only = 1; /* masked */ | |
d2e0b78f AC |
729 | ConfigFileEntry.stats_P_oper_only = false; |
730 | ConfigFileEntry.stats_c_oper_only = false; | |
731 | ConfigFileEntry.stats_y_oper_only = false; | |
732 | ConfigFileEntry.stats_h_oper_only = false; | |
733 | ConfigFileEntry.map_oper_only = true; | |
734 | ConfigFileEntry.operspy_admin_only = false; | |
212380e3 AC |
735 | ConfigFileEntry.pace_wait = 10; |
736 | ConfigFileEntry.caller_id_wait = 60; | |
737 | ConfigFileEntry.pace_wait_simple = 1; | |
d2e0b78f AC |
738 | ConfigFileEntry.short_motd = false; |
739 | ConfigFileEntry.no_oper_flood = false; | |
212380e3 AC |
740 | ConfigFileEntry.fname_userlog = NULL; |
741 | ConfigFileEntry.fname_fuserlog = NULL; | |
742 | ConfigFileEntry.fname_operlog = NULL; | |
743 | ConfigFileEntry.fname_foperlog = NULL; | |
744 | ConfigFileEntry.fname_serverlog = NULL; | |
00533129 | 745 | ConfigFileEntry.fname_killlog = NULL; |
212380e3 AC |
746 | ConfigFileEntry.fname_klinelog = NULL; |
747 | ConfigFileEntry.fname_operspylog = NULL; | |
748 | ConfigFileEntry.fname_ioerrorlog = NULL; | |
d2e0b78f | 749 | ConfigFileEntry.hide_spoof_ips = true; |
212380e3 | 750 | ConfigFileEntry.hide_error_messages = 1; |
212380e3 AC |
751 | ConfigFileEntry.dots_in_ident = 0; |
752 | ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT; | |
d2e0b78f AC |
753 | ConfigFileEntry.use_whois_actually = true; |
754 | ConfigFileEntry.burst_away = false; | |
755 | ConfigFileEntry.collision_fnc = true; | |
756 | ConfigFileEntry.resv_fnc = true; | |
757 | ConfigFileEntry.global_snotices = true; | |
758 | ConfigFileEntry.operspy_dont_care_user_info = false; | |
759 | ConfigFileEntry.use_propagated_bans = true; | |
e88a1f1b | 760 | ConfigFileEntry.max_ratelimit_tokens = 30; |
d42e6915 | 761 | ConfigFileEntry.away_interval = 30; |
212380e3 AC |
762 | |
763 | #ifdef HAVE_LIBZ | |
764 | ConfigFileEntry.compression_level = 4; | |
765 | #endif | |
766 | ||
767 | ConfigFileEntry.oper_umodes = UMODE_LOCOPS | UMODE_SERVNOTICE | | |
768 | UMODE_OPERWALL | UMODE_WALLOP; | |
769 | ConfigFileEntry.oper_only_umodes = UMODE_SERVNOTICE; | |
770 | ConfigFileEntry.oper_snomask = SNO_GENERAL; | |
771 | ||
d2e0b78f AC |
772 | ConfigChannel.use_except = true; |
773 | ConfigChannel.use_invex = true; | |
774 | ConfigChannel.use_forward = true; | |
775 | ConfigChannel.use_knock = true; | |
212380e3 AC |
776 | ConfigChannel.knock_delay = 300; |
777 | ConfigChannel.knock_delay_channel = 60; | |
778 | ConfigChannel.max_chans_per_user = 15; | |
a4721f5e | 779 | ConfigChannel.max_chans_per_user_large = 60; |
212380e3 AC |
780 | ConfigChannel.max_bans = 25; |
781 | ConfigChannel.max_bans_large = 500; | |
d2e0b78f AC |
782 | ConfigChannel.only_ascii_channels = false; |
783 | ConfigChannel.burst_topicwho = false; | |
784 | ConfigChannel.kick_on_split_riding = false; | |
212380e3 AC |
785 | |
786 | ConfigChannel.default_split_user_count = 15000; | |
787 | ConfigChannel.default_split_server_count = 10; | |
d2e0b78f AC |
788 | ConfigChannel.no_join_on_split = false; |
789 | ConfigChannel.no_create_on_split = true; | |
790 | ConfigChannel.resv_forcepart = true; | |
791 | ConfigChannel.channel_target_change = true; | |
792 | ConfigChannel.disable_local_channels = false; | |
d513218a | 793 | ConfigChannel.displayed_usercount = 3; |
212380e3 | 794 | |
63eb8567 AC |
795 | ConfigChannel.autochanmodes = MODE_TOPICLIMIT | MODE_NOPRIVMSGS; |
796 | ||
212380e3 AC |
797 | ConfigServerHide.flatten_links = 0; |
798 | ConfigServerHide.links_delay = 300; | |
799 | ConfigServerHide.hidden = 0; | |
800 | ConfigServerHide.disable_hidden = 0; | |
801 | ||
802 | ConfigFileEntry.min_nonwildcard = 4; | |
803 | ConfigFileEntry.min_nonwildcard_simple = 3; | |
804 | ConfigFileEntry.default_floodcount = 8; | |
7f3382fe | 805 | ConfigFileEntry.default_ident_timeout = IDENT_TIMEOUT_DEFAULT; |
212380e3 AC |
806 | ConfigFileEntry.tkline_expire_notices = 0; |
807 | ||
808 | ConfigFileEntry.reject_after_count = 5; | |
55abcbb2 | 809 | ConfigFileEntry.reject_ban_time = 300; |
212380e3 | 810 | ConfigFileEntry.reject_duration = 120; |
43946961 JT |
811 | ConfigFileEntry.throttle_count = 4; |
812 | ConfigFileEntry.throttle_duration = 60; | |
c2d96fcb | 813 | |
e6e54763 SB |
814 | ConfigFileEntry.client_flood_max_lines = CLIENT_FLOOD_DEFAULT; |
815 | ConfigFileEntry.client_flood_burst_rate = 5; | |
816 | ConfigFileEntry.client_flood_burst_max = 5; | |
817 | ConfigFileEntry.client_flood_message_time = 1; | |
818 | ConfigFileEntry.client_flood_message_num = 2; | |
819 | ||
101db4c4 | 820 | ServerInfo.default_max_clients = MAXCONNECTIONS; |
456e5b3d | 821 | |
b583faf9 | 822 | ConfigFileEntry.nicklen = NICKLEN; |
cf430c1a | 823 | ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_CERT_SHA1; |
71c95533 | 824 | ConfigFileEntry.hide_opers_in_whois = 0; |
1123eefc | 825 | ConfigFileEntry.hide_opers = 0; |
b583faf9 | 826 | |
456e5b3d | 827 | if (!alias_dict) |
f956cb0f | 828 | alias_dict = rb_dictionary_create("alias", rb_strcasecmp); |
212380e3 AC |
829 | } |
830 | ||
212380e3 | 831 | /* |
55abcbb2 | 832 | * read_conf() |
212380e3 AC |
833 | * |
834 | * | |
29c92cf9 | 835 | * inputs - None |
212380e3 AC |
836 | * output - None |
837 | * side effects - Read configuration file. | |
838 | */ | |
839 | static void | |
29c92cf9 | 840 | read_conf(void) |
212380e3 AC |
841 | { |
842 | lineno = 0; | |
843 | ||
844 | set_default_conf(); /* Set default values prior to conf parsing */ | |
845 | yyparse(); /* Load the values from the conf */ | |
846 | validate_conf(); /* Check to make sure some values are still okay. */ | |
847 | /* Some global values are also loaded here. */ | |
848 | check_class(); /* Make sure classes are valid */ | |
422bb0b5 | 849 | privilegeset_delete_all_illegal(); |
c55b2782 | 850 | construct_cflags_strings(); |
212380e3 AC |
851 | } |
852 | ||
853 | static void | |
854 | validate_conf(void) | |
855 | { | |
7f3382fe KB |
856 | if(ConfigFileEntry.default_ident_timeout < 1) |
857 | ConfigFileEntry.default_ident_timeout = IDENT_TIMEOUT_DEFAULT; | |
858 | ||
212380e3 AC |
859 | if(ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN) |
860 | ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT; | |
861 | ||
862 | if(ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN) | |
863 | ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT; | |
864 | ||
212380e3 | 865 | if(ServerInfo.network_name == NULL) |
47a03750 | 866 | ServerInfo.network_name = rb_strdup(NETWORK_NAME_DEFAULT); |
212380e3 | 867 | |
8bd5767b | 868 | if(ServerInfo.ssld_count < 1) |
c6d72037 VY |
869 | ServerInfo.ssld_count = 1; |
870 | ||
c53ca1e0 AC |
871 | /* XXX: configurable? */ |
872 | ServerInfo.wsockd_count = 1; | |
873 | ||
c1725bda | 874 | if(!rb_setup_ssl_server(ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params, ServerInfo.ssl_cipher_list)) |
8bd5767b JT |
875 | { |
876 | ilog(L_MAIN, "WARNING: Unable to setup SSL."); | |
bfc44622 | 877 | ircd_ssl_ok = false; |
8bd5767b | 878 | } else { |
bfc44622 | 879 | ircd_ssl_ok = true; |
f7b0c4b3 | 880 | ssld_update_config(); |
8bd5767b JT |
881 | } |
882 | ||
883 | if(ServerInfo.ssld_count > get_ssld_count()) | |
884 | { | |
885 | int start = ServerInfo.ssld_count - get_ssld_count(); | |
886 | /* start up additional ssld if needed */ | |
f7b0c4b3 | 887 | start_ssldaemon(start); |
c6d72037 VY |
888 | } |
889 | ||
c53ca1e0 AC |
890 | if(ServerInfo.wsockd_count > get_wsockd_count()) |
891 | { | |
34b88b65 | 892 | int start = ServerInfo.wsockd_count - get_wsockd_count(); |
c53ca1e0 AC |
893 | start_wsockd(start); |
894 | } | |
895 | ||
010c4fbd KB |
896 | /* General conf */ |
897 | if (ConfigFileEntry.default_operstring == NULL) | |
898 | ConfigFileEntry.default_operstring = rb_strdup("is an IRC operator"); | |
899 | ||
900 | if (ConfigFileEntry.default_adminstring == NULL) | |
901 | ConfigFileEntry.default_adminstring = rb_strdup("is a Server Administrator"); | |
902 | ||
903 | if (ConfigFileEntry.servicestring == NULL) | |
904 | ConfigFileEntry.servicestring = rb_strdup("is a Network Service"); | |
905 | ||
7d33cce8 MT |
906 | if (ConfigFileEntry.sasl_service == NULL) |
907 | ConfigFileEntry.sasl_service = rb_strdup("SaslServ"); | |
908 | ||
894325fe JT |
909 | /* RFC 1459 says 1 message per 2 seconds on average and bursts of |
910 | * 5 messages are acceptable, so allow at least that. | |
41ca4cac | 911 | */ |
894325fe JT |
912 | if(ConfigFileEntry.client_flood_burst_rate < 5) |
913 | ConfigFileEntry.client_flood_burst_rate = 5; | |
914 | if(ConfigFileEntry.client_flood_burst_max < 5) | |
915 | ConfigFileEntry.client_flood_burst_max = 5; | |
41ca4cac JT |
916 | if(ConfigFileEntry.client_flood_message_time > |
917 | ConfigFileEntry.client_flood_message_num * 2) | |
918 | ConfigFileEntry.client_flood_message_time = | |
919 | ConfigFileEntry.client_flood_message_num * 2; | |
920 | ||
e6e54763 SB |
921 | if((ConfigFileEntry.client_flood_max_lines < CLIENT_FLOOD_MIN) || |
922 | (ConfigFileEntry.client_flood_max_lines > CLIENT_FLOOD_MAX)) | |
923 | ConfigFileEntry.client_flood_max_lines = CLIENT_FLOOD_MAX; | |
212380e3 | 924 | |
212380e3 AC |
925 | if(!split_users || !split_servers || |
926 | (!ConfigChannel.no_create_on_split && !ConfigChannel.no_join_on_split)) | |
927 | { | |
b2c190a6 JT |
928 | rb_event_delete(check_splitmode_ev); |
929 | check_splitmode_ev = NULL; | |
212380e3 AC |
930 | splitmode = 0; |
931 | splitchecking = 0; | |
932 | } | |
01978a2c AC |
933 | |
934 | CharAttrs['&'] |= CHANPFX_C; | |
935 | if (ConfigChannel.disable_local_channels) | |
936 | CharAttrs['&'] &= ~CHANPFX_C; | |
937 | ||
938 | chantypes_update(); | |
212380e3 AC |
939 | } |
940 | ||
212380e3 AC |
941 | /* add_temp_kline() |
942 | * | |
943 | * inputs - pointer to struct ConfItem | |
944 | * output - none | |
55abcbb2 | 945 | * Side effects - links in given struct ConfItem into |
212380e3 AC |
946 | * temporary kline link list |
947 | */ | |
948 | void | |
949 | add_temp_kline(struct ConfItem *aconf) | |
950 | { | |
e3354945 | 951 | if(aconf->hold >= rb_current_time() + (10080 * 60)) |
212380e3 | 952 | { |
330fc5c1 | 953 | rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_WEEK]); |
212380e3 AC |
954 | aconf->port = TEMP_WEEK; |
955 | } | |
e3354945 | 956 | else if(aconf->hold >= rb_current_time() + (1440 * 60)) |
212380e3 | 957 | { |
330fc5c1 | 958 | rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_DAY]); |
212380e3 AC |
959 | aconf->port = TEMP_DAY; |
960 | } | |
e3354945 | 961 | else if(aconf->hold >= rb_current_time() + (60 * 60)) |
212380e3 | 962 | { |
330fc5c1 | 963 | rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_HOUR]); |
212380e3 AC |
964 | aconf->port = TEMP_HOUR; |
965 | } | |
966 | else | |
967 | { | |
330fc5c1 | 968 | rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_MIN]); |
212380e3 AC |
969 | aconf->port = TEMP_MIN; |
970 | } | |
971 | ||
972 | aconf->flags |= CONF_FLAGS_TEMPORARY; | |
40c1fd47 | 973 | add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf); |
212380e3 AC |
974 | } |
975 | ||
976 | /* add_temp_dline() | |
977 | * | |
978 | * input - pointer to struct ConfItem | |
979 | * output - none | |
980 | * side effects - added to tdline link list and address hash | |
981 | */ | |
982 | void | |
983 | add_temp_dline(struct ConfItem *aconf) | |
984 | { | |
e3354945 | 985 | if(aconf->hold >= rb_current_time() + (10080 * 60)) |
212380e3 | 986 | { |
330fc5c1 | 987 | rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_WEEK]); |
212380e3 AC |
988 | aconf->port = TEMP_WEEK; |
989 | } | |
e3354945 | 990 | else if(aconf->hold >= rb_current_time() + (1440 * 60)) |
212380e3 | 991 | { |
330fc5c1 | 992 | rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_DAY]); |
212380e3 AC |
993 | aconf->port = TEMP_DAY; |
994 | } | |
e3354945 | 995 | else if(aconf->hold >= rb_current_time() + (60 * 60)) |
212380e3 | 996 | { |
330fc5c1 | 997 | rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_HOUR]); |
212380e3 AC |
998 | aconf->port = TEMP_HOUR; |
999 | } | |
1000 | else | |
1001 | { | |
330fc5c1 | 1002 | rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_MIN]); |
212380e3 AC |
1003 | aconf->port = TEMP_MIN; |
1004 | } | |
1005 | ||
1006 | aconf->flags |= CONF_FLAGS_TEMPORARY; | |
40c1fd47 | 1007 | add_conf_by_address(aconf->host, CONF_DLINE, aconf->user, NULL, aconf); |
212380e3 AC |
1008 | } |
1009 | ||
5c2b9eaf | 1010 | /* valid_wild_card() |
55abcbb2 | 1011 | * |
5c2b9eaf JT |
1012 | * input - user buffer, host buffer |
1013 | * output - 0 if invalid, 1 if valid | |
1014 | * side effects - | |
1015 | */ | |
1016 | int | |
1017 | valid_wild_card(const char *luser, const char *lhost) | |
1018 | { | |
1019 | const char *p; | |
1020 | char tmpch; | |
1021 | int nonwild = 0; | |
1022 | int bitlen; | |
1023 | ||
1024 | /* user has no wildcards, always accept -- jilles */ | |
1025 | if(!strchr(luser, '?') && !strchr(luser, '*')) | |
1026 | return 1; | |
1027 | ||
1028 | /* check there are enough non wildcard chars */ | |
1029 | p = luser; | |
1030 | while((tmpch = *p++)) | |
1031 | { | |
1032 | if(!IsKWildChar(tmpch)) | |
1033 | { | |
1034 | /* found enough chars, return */ | |
1035 | if(++nonwild >= ConfigFileEntry.min_nonwildcard) | |
1036 | return 1; | |
1037 | } | |
1038 | } | |
1039 | ||
1040 | /* try host, as user didnt contain enough */ | |
1041 | /* special case for cidr masks -- jilles */ | |
1042 | if((p = strrchr(lhost, '/')) != NULL && IsDigit(p[1])) | |
1043 | { | |
1044 | bitlen = atoi(p + 1); | |
1045 | /* much like non-cidr for ipv6, rather arbitrary for ipv4 */ | |
1046 | if(bitlen > 0 | |
1047 | && bitlen >= | |
1048 | (strchr(lhost, ':') ? 4 * (ConfigFileEntry.min_nonwildcard - nonwild) : 6 - | |
1049 | 2 * nonwild)) | |
1050 | return 1; | |
1051 | } | |
1052 | else | |
1053 | { | |
1054 | p = lhost; | |
1055 | while((tmpch = *p++)) | |
1056 | { | |
1057 | if(!IsKWildChar(tmpch)) | |
1058 | if(++nonwild >= ConfigFileEntry.min_nonwildcard) | |
1059 | return 1; | |
1060 | } | |
1061 | } | |
1062 | ||
1063 | return 0; | |
1064 | } | |
1065 | ||
431a1a27 JT |
1066 | rb_dlink_node * |
1067 | find_prop_ban(unsigned int status, const char *user, const char *host) | |
1068 | { | |
1069 | rb_dlink_node *ptr; | |
1070 | struct ConfItem *aconf; | |
1071 | ||
1072 | RB_DLINK_FOREACH(ptr, prop_bans.head) | |
1073 | { | |
1074 | aconf = ptr->data; | |
1075 | ||
1076 | if((aconf->status & ~CONF_ILLEGAL) == status && | |
1077 | (!user || !aconf->user || | |
1078 | !irccmp(aconf->user, user)) && | |
1079 | !irccmp(aconf->host, host)) | |
1080 | return ptr; | |
1081 | } | |
1082 | return NULL; | |
1083 | } | |
1084 | ||
9197bc35 | 1085 | void |
483987a4 | 1086 | deactivate_conf(struct ConfItem *aconf, rb_dlink_node *ptr, time_t now) |
9197bc35 JT |
1087 | { |
1088 | int i; | |
1089 | ||
1090 | s_assert(ptr->data == aconf); | |
1091 | ||
1092 | switch (aconf->status) | |
1093 | { | |
1094 | case CONF_KILL: | |
1095 | if (aconf->lifetime == 0 && | |
1096 | aconf->flags & CONF_FLAGS_TEMPORARY) | |
1097 | for (i = 0; i < LAST_TEMP_TYPE; i++) | |
1098 | rb_dlinkFindDestroy(aconf, &temp_klines[i]); | |
1099 | /* Make sure delete_one_address_conf() does not | |
1100 | * free the aconf. | |
1101 | */ | |
1102 | aconf->clients++; | |
1103 | delete_one_address_conf(aconf->host, aconf); | |
1104 | aconf->clients--; | |
1105 | break; | |
1106 | case CONF_DLINE: | |
1107 | if (aconf->lifetime == 0 && | |
1108 | aconf->flags & CONF_FLAGS_TEMPORARY) | |
1109 | for (i = 0; i < LAST_TEMP_TYPE; i++) | |
1110 | rb_dlinkFindDestroy(aconf, &temp_dlines[i]); | |
1111 | aconf->clients++; | |
1112 | delete_one_address_conf(aconf->host, aconf); | |
1113 | aconf->clients--; | |
1114 | break; | |
1115 | case CONF_XLINE: | |
1116 | rb_dlinkFindDestroy(aconf, &xline_conf_list); | |
1117 | break; | |
1118 | case CONF_RESV_NICK: | |
1119 | rb_dlinkFindDestroy(aconf, &resv_conf_list); | |
1120 | break; | |
1121 | case CONF_RESV_CHANNEL: | |
1122 | del_from_resv_hash(aconf->host, aconf); | |
1123 | break; | |
1124 | } | |
483987a4 | 1125 | if (aconf->lifetime != 0 && now < aconf->lifetime) |
9197bc35 JT |
1126 | aconf->status |= CONF_ILLEGAL; |
1127 | else | |
1128 | { | |
1129 | if (aconf->lifetime != 0) | |
1130 | rb_dlinkDestroy(ptr, &prop_bans); | |
1131 | free_conf(aconf); | |
1132 | } | |
1133 | } | |
1134 | ||
3cbbfb25 JT |
1135 | /* Given a new ban ConfItem, look for any matching ban, update the lifetime |
1136 | * from it and delete it. | |
1137 | */ | |
1138 | void | |
1139 | replace_old_ban(struct ConfItem *aconf) | |
1140 | { | |
1141 | rb_dlink_node *ptr; | |
1142 | struct ConfItem *oldconf; | |
1143 | ||
1144 | ptr = find_prop_ban(aconf->status, aconf->user, aconf->host); | |
1145 | if(ptr != NULL) | |
1146 | { | |
1147 | oldconf = ptr->data; | |
1148 | /* Remember at least as long as the old one. */ | |
1149 | if(oldconf->lifetime > aconf->lifetime) | |
1150 | aconf->lifetime = oldconf->lifetime; | |
1151 | /* Force creation time to increase. */ | |
1152 | if(oldconf->created >= aconf->created) | |
1153 | aconf->created = oldconf->created + 1; | |
1154 | /* Leave at least one second of validity. */ | |
1155 | if(aconf->hold <= aconf->created) | |
1156 | aconf->hold = aconf->created + 1; | |
1157 | if(aconf->lifetime < aconf->hold) | |
1158 | aconf->lifetime = aconf->hold; | |
1159 | /* Tell deactivate_conf() to destroy it. */ | |
1160 | oldconf->lifetime = rb_current_time(); | |
483987a4 | 1161 | deactivate_conf(oldconf, ptr, oldconf->lifetime); |
3cbbfb25 JT |
1162 | } |
1163 | } | |
1164 | ||
9197bc35 JT |
1165 | static void |
1166 | expire_prop_bans(void *list) | |
1167 | { | |
1168 | rb_dlink_node *ptr; | |
1169 | rb_dlink_node *next_ptr; | |
1170 | struct ConfItem *aconf; | |
483987a4 | 1171 | time_t now; |
9197bc35 | 1172 | |
483987a4 | 1173 | now = rb_current_time(); |
9197bc35 JT |
1174 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, ((rb_dlink_list *) list)->head) |
1175 | { | |
1176 | aconf = ptr->data; | |
1177 | ||
483987a4 JT |
1178 | if(aconf->lifetime <= now || |
1179 | (aconf->hold <= now && | |
9197bc35 JT |
1180 | !(aconf->status & CONF_ILLEGAL))) |
1181 | { | |
1182 | /* Alert opers that a TKline expired - Hwy */ | |
1183 | /* XXX show what type of ban it is */ | |
1184 | if(ConfigFileEntry.tkline_expire_notices && | |
1185 | !(aconf->status & CONF_ILLEGAL)) | |
1186 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1187 | "Propagated ban for [%s%s%s] expired", | |
1188 | aconf->user ? aconf->user : "", | |
1189 | aconf->user ? "@" : "", | |
1190 | aconf->host ? aconf->host : "*"); | |
1191 | ||
1192 | /* will destroy or mark illegal */ | |
483987a4 | 1193 | deactivate_conf(aconf, ptr, now); |
9197bc35 JT |
1194 | } |
1195 | } | |
1196 | } | |
1197 | ||
212380e3 AC |
1198 | /* expire_tkline() |
1199 | * | |
1200 | * inputs - list pointer | |
1201 | * - type | |
1202 | * output - NONE | |
1203 | * side effects - expire tklines and moves them between lists | |
1204 | */ | |
1205 | static void | |
1206 | expire_temp_kd(void *list) | |
1207 | { | |
330fc5c1 | 1208 | rb_dlink_node *ptr; |
637c4932 | 1209 | rb_dlink_node *next_ptr; |
212380e3 AC |
1210 | struct ConfItem *aconf; |
1211 | ||
637c4932 | 1212 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, ((rb_dlink_list *) list)->head) |
212380e3 AC |
1213 | { |
1214 | aconf = ptr->data; | |
1215 | ||
e3354945 | 1216 | if(aconf->hold <= rb_current_time()) |
212380e3 AC |
1217 | { |
1218 | /* Alert opers that a TKline expired - Hwy */ | |
1219 | if(ConfigFileEntry.tkline_expire_notices) | |
1220 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1221 | "Temporary K-line for [%s@%s] expired", | |
1222 | (aconf->user) ? aconf-> | |
1223 | user : "*", (aconf->host) ? aconf->host : "*"); | |
1224 | ||
1225 | delete_one_address_conf(aconf->host, aconf); | |
330fc5c1 | 1226 | rb_dlinkDestroy(ptr, list); |
212380e3 AC |
1227 | } |
1228 | } | |
1229 | } | |
1230 | ||
1231 | static void | |
1232 | reorganise_temp_kd(void *list) | |
1233 | { | |
1234 | struct ConfItem *aconf; | |
637c4932 | 1235 | rb_dlink_node *ptr, *next_ptr; |
212380e3 | 1236 | |
637c4932 | 1237 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, ((rb_dlink_list *) list)->head) |
212380e3 AC |
1238 | { |
1239 | aconf = ptr->data; | |
1240 | ||
e3354945 | 1241 | if(aconf->hold < (rb_current_time() + (60 * 60))) |
212380e3 | 1242 | { |
55abcbb2 | 1243 | rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ? |
212380e3 AC |
1244 | &temp_klines[TEMP_MIN] : &temp_dlines[TEMP_MIN]); |
1245 | aconf->port = TEMP_MIN; | |
1246 | } | |
1247 | else if(aconf->port > TEMP_HOUR) | |
1248 | { | |
e3354945 | 1249 | if(aconf->hold < (rb_current_time() + (1440 * 60))) |
212380e3 | 1250 | { |
55abcbb2 | 1251 | rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ? |
212380e3 AC |
1252 | &temp_klines[TEMP_HOUR] : &temp_dlines[TEMP_HOUR]); |
1253 | aconf->port = TEMP_HOUR; | |
1254 | } | |
55abcbb2 | 1255 | else if(aconf->port > TEMP_DAY && |
e3354945 | 1256 | (aconf->hold < (rb_current_time() + (10080 * 60)))) |
212380e3 | 1257 | { |
55abcbb2 | 1258 | rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ? |
212380e3 AC |
1259 | &temp_klines[TEMP_DAY] : &temp_dlines[TEMP_DAY]); |
1260 | aconf->port = TEMP_DAY; | |
1261 | } | |
1262 | } | |
1263 | } | |
1264 | } | |
1265 | ||
1266 | ||
1267 | /* const char* get_oper_name(struct Client *client_p) | |
1268 | * Input: A client to find the active oper{} name for. | |
1269 | * Output: The nick!user@host{oper} of the oper. | |
1270 | * "oper" is server name for remote opers | |
1271 | * Side effects: None. | |
1272 | */ | |
1273 | char * | |
1274 | get_oper_name(struct Client *client_p) | |
1275 | { | |
1276 | /* +5 for !,@,{,} and null */ | |
fe5fc851 | 1277 | static char buffer[NAMELEN + USERLEN + HOSTLEN + HOSTLEN + 5]; |
212380e3 AC |
1278 | |
1279 | if(MyOper(client_p)) | |
1280 | { | |
5203cba5 | 1281 | snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", |
212380e3 | 1282 | client_p->name, client_p->username, |
ed3ca2ff | 1283 | client_p->host, client_p->user->opername); |
212380e3 AC |
1284 | return buffer; |
1285 | } | |
1286 | ||
5203cba5 | 1287 | snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", |
55abcbb2 | 1288 | client_p->name, client_p->username, |
212380e3 AC |
1289 | client_p->host, client_p->servptr->name); |
1290 | return buffer; | |
1291 | } | |
1292 | ||
1293 | /* | |
1294 | * get_printable_conf | |
1295 | * | |
1296 | * inputs - struct ConfItem | |
1297 | * | |
55abcbb2 | 1298 | * output - name |
212380e3 AC |
1299 | * - host |
1300 | * - pass | |
1301 | * - user | |
1302 | * - port | |
1303 | * | |
1304 | * side effects - | |
1305 | * Examine the struct struct ConfItem, setting the values | |
1306 | * of name, host, pass, user to values either | |
1307 | * in aconf, or "<NULL>" port is set to aconf->port in all cases. | |
1308 | */ | |
1309 | void | |
1310 | get_printable_conf(struct ConfItem *aconf, char **name, char **host, | |
29c92cf9 | 1311 | const char **pass, char **user, int *port, char **classname) |
212380e3 AC |
1312 | { |
1313 | static char null[] = "<NULL>"; | |
1314 | static char zero[] = "default"; | |
1315 | ||
27f616dd | 1316 | *name = EmptyString(aconf->info.name) ? null : aconf->info.name; |
212380e3 AC |
1317 | *host = EmptyString(aconf->host) ? null : aconf->host; |
1318 | *pass = EmptyString(aconf->passwd) ? null : aconf->passwd; | |
1319 | *user = EmptyString(aconf->user) ? null : aconf->user; | |
1320 | *classname = EmptyString(aconf->className) ? zero : aconf->className; | |
1321 | *port = (int) aconf->port; | |
1322 | } | |
1323 | ||
a12ad044 JT |
1324 | char * |
1325 | get_user_ban_reason(struct ConfItem *aconf) | |
1326 | { | |
1327 | static char reasonbuf[BUFSIZE]; | |
1328 | ||
9914c013 EK |
1329 | if (!ConfigFileEntry.hide_tkdline_duration && |
1330 | aconf->flags & CONF_FLAGS_TEMPORARY && | |
a12ad044 | 1331 | (aconf->status == CONF_KILL || aconf->status == CONF_DLINE)) |
5203cba5 | 1332 | snprintf(reasonbuf, sizeof reasonbuf, |
a12ad044 JT |
1333 | "Temporary %c-line %d min. - ", |
1334 | aconf->status == CONF_DLINE ? 'D' : 'K', | |
803ce385 | 1335 | (int)((aconf->hold - aconf->created) / 60)); |
a12ad044 JT |
1336 | else |
1337 | reasonbuf[0] = '\0'; | |
1338 | if (aconf->passwd) | |
1339 | rb_strlcat(reasonbuf, aconf->passwd, sizeof reasonbuf); | |
1340 | else | |
1341 | rb_strlcat(reasonbuf, "No Reason", sizeof reasonbuf); | |
1342 | if (aconf->created) | |
1343 | { | |
1344 | rb_strlcat(reasonbuf, " (", sizeof reasonbuf); | |
1345 | rb_strlcat(reasonbuf, smalldate(aconf->created), | |
1346 | sizeof reasonbuf); | |
1347 | rb_strlcat(reasonbuf, ")", sizeof reasonbuf); | |
1348 | } | |
1349 | return reasonbuf; | |
1350 | } | |
1351 | ||
54ac8b60 | 1352 | void |
55abcbb2 | 1353 | get_printable_kline(struct Client *source_p, struct ConfItem *aconf, |
54ac8b60 VY |
1354 | char **host, char **reason, |
1355 | char **user, char **oper_reason) | |
1356 | { | |
1357 | static char null[] = "<NULL>"; | |
778dd56b | 1358 | static char operreasonbuf[BUFSIZE]; |
54ac8b60 VY |
1359 | |
1360 | *host = EmptyString(aconf->host) ? null : aconf->host; | |
54ac8b60 | 1361 | *user = EmptyString(aconf->user) ? null : aconf->user; |
a12ad044 | 1362 | *reason = get_user_ban_reason(aconf); |
b52c2949 | 1363 | |
778dd56b | 1364 | if(!IsOper(source_p)) |
54ac8b60 VY |
1365 | *oper_reason = NULL; |
1366 | else | |
778dd56b | 1367 | { |
5203cba5 | 1368 | snprintf(operreasonbuf, sizeof operreasonbuf, "%s%s(%s)", |
778dd56b JT |
1369 | EmptyString(aconf->spasswd) ? "" : aconf->spasswd, |
1370 | EmptyString(aconf->spasswd) ? "" : " ", | |
1371 | aconf->info.oper); | |
1372 | *oper_reason = operreasonbuf; | |
1373 | } | |
212380e3 AC |
1374 | } |
1375 | ||
1376 | /* | |
1377 | * read_conf_files | |
1378 | * | |
ea111ea5 | 1379 | * inputs - cold start |
212380e3 AC |
1380 | * output - none |
1381 | * side effects - read all conf files needed, ircd.conf kline.conf etc. | |
1382 | */ | |
1383 | void | |
ea111ea5 | 1384 | read_conf_files(bool cold) |
212380e3 AC |
1385 | { |
1386 | const char *filename; | |
1387 | ||
1388 | conf_fbfile_in = NULL; | |
1389 | ||
22342cd1 | 1390 | filename = ConfigFileEntry.configfile; |
212380e3 AC |
1391 | |
1392 | /* We need to know the initial filename for the yyerror() to report | |
1393 | FIXME: The full path is in conffilenamebuf first time since we | |
1394 | dont know anything else | |
1395 | ||
55abcbb2 | 1396 | - Gozem 2002-07-21 |
a576a0fe CD |
1397 | |
1398 | ||
212380e3 | 1399 | */ |
f427c8b0 | 1400 | rb_strlcpy(conffilebuf, filename, sizeof(conffilebuf)); |
212380e3 AC |
1401 | |
1402 | if((conf_fbfile_in = fopen(filename, "r")) == NULL) | |
1403 | { | |
1404 | if(cold) | |
1405 | { | |
f951460a | 1406 | inotice("Failed in reading configuration file %s, aborting", filename); |
a576a0fe CD |
1407 | ilog(L_MAIN, "Failed in reading configuration file %s", filename); |
1408 | ||
1409 | int e; | |
1410 | e = errno; | |
1411 | ||
2c0450fb CD |
1412 | inotice("FATAL: %s %s", strerror(e), filename); |
1413 | ilog(L_MAIN, "FATAL: %s %s", strerror(e), filename); | |
a576a0fe | 1414 | |
212380e3 AC |
1415 | exit(-1); |
1416 | } | |
1417 | else | |
1418 | { | |
1419 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1420 | "Can't open file '%s' - aborting rehash!", filename); | |
1421 | return; | |
1422 | } | |
1423 | } | |
1424 | ||
1425 | if(!cold) | |
1426 | { | |
1427 | clear_out_old_conf(); | |
1428 | } | |
1429 | ||
7d603754 | 1430 | call_hook(h_conf_read_start, NULL); |
29c92cf9 | 1431 | read_conf(); |
7d603754 KB |
1432 | call_hook(h_conf_read_end, NULL); |
1433 | ||
212380e3 AC |
1434 | fclose(conf_fbfile_in); |
1435 | } | |
1436 | ||
8ac75529 AC |
1437 | /* |
1438 | * free an alias{} entry. | |
1439 | */ | |
1440 | static void | |
4177311e | 1441 | free_alias_cb(rb_dictionary_element *ptr, void *unused) |
8ac75529 AC |
1442 | { |
1443 | struct alias_entry *aptr = ptr->data; | |
1444 | ||
637c4932 VY |
1445 | rb_free(aptr->name); |
1446 | rb_free(aptr->target); | |
1447 | rb_free(aptr); | |
8ac75529 AC |
1448 | } |
1449 | ||
212380e3 AC |
1450 | /* |
1451 | * clear_out_old_conf | |
1452 | * | |
1453 | * inputs - none | |
1454 | * output - none | |
1455 | * side effects - Clear out the old configuration | |
1456 | */ | |
1457 | static void | |
1458 | clear_out_old_conf(void) | |
1459 | { | |
1460 | struct Class *cltmp; | |
330fc5c1 | 1461 | rb_dlink_node *ptr; |
637c4932 | 1462 | rb_dlink_node *next_ptr; |
212380e3 AC |
1463 | |
1464 | /* | |
1465 | * don't delete the class table, rather mark all entries | |
1466 | * for deletion. The table is cleaned up by check_class. - avalon | |
1467 | */ | |
5cefa1d6 | 1468 | RB_DLINK_FOREACH(ptr, class_list.head) |
212380e3 AC |
1469 | { |
1470 | cltmp = ptr->data; | |
1471 | MaxUsers(cltmp) = -1; | |
1472 | } | |
1473 | ||
1474 | clear_out_address_conf(); | |
1475 | clear_s_newconf(); | |
1476 | ||
1477 | /* clean out module paths */ | |
212380e3 AC |
1478 | mod_clear_paths(); |
1479 | mod_add_path(MODULE_DIR); | |
1480 | mod_add_path(MODULE_DIR "/autoload"); | |
212380e3 AC |
1481 | |
1482 | /* clean out ServerInfo */ | |
637c4932 | 1483 | rb_free(ServerInfo.description); |
212380e3 | 1484 | ServerInfo.description = NULL; |
637c4932 | 1485 | rb_free(ServerInfo.network_name); |
212380e3 | 1486 | ServerInfo.network_name = NULL; |
212380e3 | 1487 | |
c6d72037 VY |
1488 | ServerInfo.ssld_count = 1; |
1489 | ||
212380e3 | 1490 | /* clean out AdminInfo */ |
637c4932 | 1491 | rb_free(AdminInfo.name); |
212380e3 | 1492 | AdminInfo.name = NULL; |
637c4932 | 1493 | rb_free(AdminInfo.email); |
212380e3 | 1494 | AdminInfo.email = NULL; |
637c4932 | 1495 | rb_free(AdminInfo.description); |
212380e3 AC |
1496 | AdminInfo.description = NULL; |
1497 | ||
1498 | /* operator{} and class{} blocks are freed above */ | |
1499 | /* clean out listeners */ | |
1500 | close_listeners(); | |
1501 | ||
1502 | /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{}, exempt{} | |
1503 | * and gecos{} blocks are freed above too | |
1504 | */ | |
1505 | ||
1506 | /* clean out general */ | |
010c4fbd KB |
1507 | rb_free(ConfigFileEntry.default_operstring); |
1508 | ConfigFileEntry.default_operstring = NULL; | |
1509 | rb_free(ConfigFileEntry.default_adminstring); | |
1510 | ConfigFileEntry.default_adminstring = NULL; | |
1511 | rb_free(ConfigFileEntry.servicestring); | |
1512 | ConfigFileEntry.servicestring = NULL; | |
d61a1c7e JT |
1513 | rb_free(ConfigFileEntry.kline_reason); |
1514 | ConfigFileEntry.kline_reason = NULL; | |
7d33cce8 MT |
1515 | rb_free(ConfigFileEntry.sasl_service); |
1516 | ConfigFileEntry.sasl_service = NULL; | |
d61a1c7e | 1517 | |
00533129 KB |
1518 | /* clean out log */ |
1519 | rb_free(ConfigFileEntry.fname_userlog); | |
1520 | ConfigFileEntry.fname_userlog = NULL; | |
1521 | rb_free(ConfigFileEntry.fname_fuserlog); | |
1522 | ConfigFileEntry.fname_fuserlog = NULL; | |
1523 | rb_free(ConfigFileEntry.fname_operlog); | |
1524 | ConfigFileEntry.fname_operlog = NULL; | |
1525 | rb_free(ConfigFileEntry.fname_foperlog); | |
1526 | ConfigFileEntry.fname_foperlog = NULL; | |
1527 | rb_free(ConfigFileEntry.fname_serverlog); | |
1528 | ConfigFileEntry.fname_serverlog = NULL; | |
1529 | rb_free(ConfigFileEntry.fname_killlog); | |
1530 | ConfigFileEntry.fname_killlog = NULL; | |
1531 | rb_free(ConfigFileEntry.fname_klinelog); | |
1532 | ConfigFileEntry.fname_klinelog = NULL; | |
1533 | rb_free(ConfigFileEntry.fname_operspylog); | |
1534 | ConfigFileEntry.fname_operspylog = NULL; | |
1535 | rb_free(ConfigFileEntry.fname_ioerrorlog); | |
1536 | ConfigFileEntry.fname_ioerrorlog = NULL; | |
1537 | ||
637c4932 | 1538 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, service_list.head) |
212380e3 | 1539 | { |
637c4932 | 1540 | rb_free(ptr->data); |
330fc5c1 | 1541 | rb_dlinkDestroy(ptr, &service_list); |
212380e3 AC |
1542 | } |
1543 | ||
1544 | /* remove any aliases... -- nenolod */ | |
dbcd150b AC |
1545 | if (alias_dict != NULL) |
1546 | { | |
a4bf26dd | 1547 | rb_dictionary_destroy(alias_dict, free_alias_cb, NULL); |
dbcd150b AC |
1548 | alias_dict = NULL; |
1549 | } | |
212380e3 | 1550 | |
d3f6b808 | 1551 | del_blacklist_all(); |
212380e3 | 1552 | |
422bb0b5 JT |
1553 | privilegeset_mark_all_illegal(); |
1554 | ||
212380e3 AC |
1555 | /* OK, that should be everything... */ |
1556 | } | |
1557 | ||
1558 | ||
212380e3 AC |
1559 | /* |
1560 | * conf_add_class_to_conf | |
1561 | * inputs - pointer to config item | |
1562 | * output - NONE | |
55abcbb2 | 1563 | * side effects - Add a class pointer to a conf |
212380e3 AC |
1564 | */ |
1565 | ||
1566 | void | |
1567 | conf_add_class_to_conf(struct ConfItem *aconf) | |
1568 | { | |
1569 | if(aconf->className == NULL) | |
1570 | { | |
47a03750 | 1571 | aconf->className = rb_strdup("default"); |
212380e3 AC |
1572 | ClassPtr(aconf) = default_class; |
1573 | return; | |
1574 | } | |
1575 | ||
1576 | ClassPtr(aconf) = find_class(aconf->className); | |
1577 | ||
1578 | if(ClassPtr(aconf) == default_class) | |
1579 | { | |
1580 | if(aconf->status == CONF_CLIENT) | |
1581 | { | |
8b801ad1 JT |
1582 | conf_report_error( |
1583 | "Using default class for missing class \"%s\" in auth{} for %s@%s", | |
212380e3 AC |
1584 | aconf->className, aconf->user, aconf->host); |
1585 | } | |
1586 | ||
637c4932 | 1587 | rb_free(aconf->className); |
47a03750 | 1588 | aconf->className = rb_strdup("default"); |
212380e3 AC |
1589 | return; |
1590 | } | |
1591 | ||
1592 | if(ConfMaxUsers(aconf) < 0) | |
1593 | { | |
1594 | ClassPtr(aconf) = default_class; | |
637c4932 | 1595 | rb_free(aconf->className); |
47a03750 | 1596 | aconf->className = rb_strdup("default"); |
212380e3 AC |
1597 | return; |
1598 | } | |
1599 | } | |
1600 | ||
1601 | /* | |
1602 | * conf_add_d_conf | |
1603 | * inputs - pointer to config item | |
1604 | * output - NONE | |
1605 | * side effects - Add a d/D line | |
1606 | */ | |
1607 | void | |
1608 | conf_add_d_conf(struct ConfItem *aconf) | |
1609 | { | |
1610 | if(aconf->host == NULL) | |
1611 | return; | |
1612 | ||
1613 | aconf->user = NULL; | |
1614 | ||
1615 | /* XXX - Should 'd' ever be in the old conf? For new conf we don't | |
1616 | * need this anyway, so I will disable it for now... -A1kmm | |
1617 | */ | |
1618 | ||
1619 | if(parse_netmask(aconf->host, NULL, NULL) == HM_HOST) | |
1620 | { | |
1621 | ilog(L_MAIN, "Invalid Dline %s ignored", aconf->host); | |
1622 | free_conf(aconf); | |
1623 | } | |
1624 | else | |
1625 | { | |
40c1fd47 | 1626 | add_conf_by_address(aconf->host, CONF_DLINE, NULL, NULL, aconf); |
212380e3 AC |
1627 | } |
1628 | } | |
1629 | ||
89bb7d65 SA |
1630 | static void |
1631 | strip_tabs(char *dest, const char *src, size_t size) | |
decf0486 VY |
1632 | { |
1633 | char *d = dest; | |
1634 | ||
1635 | if(dest == NULL || src == NULL) | |
89bb7d65 | 1636 | return; |
decf0486 | 1637 | |
89bb7d65 | 1638 | rb_strlcpy(dest, src, size); |
decf0486 VY |
1639 | |
1640 | while(*d) | |
1641 | { | |
1642 | if(*d == '\t') | |
1643 | *d = ' '; | |
1644 | d++; | |
1645 | } | |
decf0486 | 1646 | } |
212380e3 AC |
1647 | |
1648 | /* | |
1649 | * yyerror | |
1650 | * | |
1651 | * inputs - message from parser | |
1652 | * output - none | |
1653 | * side effects - message to opers and log file entry is made | |
1654 | */ | |
1655 | void | |
1656 | yyerror(const char *msg) | |
1657 | { | |
1658 | char newlinebuf[BUFSIZE]; | |
1659 | ||
89bb7d65 | 1660 | strip_tabs(newlinebuf, yy_linebuf, sizeof(newlinebuf)); |
212380e3 | 1661 | |
beccbe31 | 1662 | ierror("\"%s\", line %d: %s at '%s'", conffilebuf, lineno + 1, msg, newlinebuf); |
212380e3 AC |
1663 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "\"%s\", line %d: %s at '%s'", |
1664 | conffilebuf, lineno + 1, msg, newlinebuf); | |
1665 | ||
212380e3 AC |
1666 | } |
1667 | ||
1668 | int | |
1669 | conf_fgets(char *lbuf, int max_size, FILE * fb) | |
1670 | { | |
eac04554 | 1671 | if(fgets(lbuf, max_size, fb) == NULL) |
212380e3 AC |
1672 | return (0); |
1673 | ||
1674 | return (strlen(lbuf)); | |
1675 | } | |
1676 | ||
1677 | int | |
1678 | conf_yy_fatal_error(const char *msg) | |
1679 | { | |
1680 | return (0); | |
1681 | } |