]>
Commit | Line | Data |
---|---|---|
212380e3 | 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 | |
23 | * | |
cda8e9b8 | 24 | * $Id: s_conf.c 3550 2007-08-09 06:47:26Z nenolod $ |
212380e3 | 25 | */ |
26 | ||
27 | #include "stdinc.h" | |
28 | #include "ircd_defs.h" | |
212380e3 | 29 | #include "s_conf.h" |
30 | #include "s_newconf.h" | |
31 | #include "s_serv.h" | |
32 | #include "s_stats.h" | |
33 | #include "channel.h" | |
34 | #include "class.h" | |
35 | #include "client.h" | |
36 | #include "common.h" | |
212380e3 | 37 | #include "hash.h" |
38 | #include "irc_string.h" | |
39 | #include "sprintf_irc.h" | |
40 | #include "ircd.h" | |
41 | #include "listener.h" | |
42 | #include "hostmask.h" | |
43 | #include "modules.h" | |
44 | #include "numeric.h" | |
d3455e2c | 45 | #include "logger.h" |
212380e3 | 46 | #include "send.h" |
212380e3 | 47 | #include "reject.h" |
48 | #include "cache.h" | |
49 | #include "blacklist.h" | |
8db00894 | 50 | #include "sslproc.h" |
212380e3 | 51 | |
52 | struct config_server_hide ConfigServerHide; | |
53 | ||
54 | extern int yyparse(); /* defined in y.tab.c */ | |
55 | extern char linebuf[]; | |
56 | ||
57 | #ifndef INADDR_NONE | |
58 | #define INADDR_NONE ((unsigned int) 0xffffffff) | |
59 | #endif | |
60 | ||
6e9b4415 | 61 | static rb_bh *confitem_heap = NULL; |
212380e3 | 62 | |
af81d5a0 WP |
63 | rb_dlink_list temp_klines[LAST_TEMP_TYPE]; |
64 | rb_dlink_list temp_dlines[LAST_TEMP_TYPE]; | |
65 | rb_dlink_list service_list; | |
212380e3 | 66 | |
67 | /* internally defined functions */ | |
68 | static void set_default_conf(void); | |
69 | static void validate_conf(void); | |
70 | static void read_conf(FILE *); | |
71 | static void clear_out_old_conf(void); | |
72 | ||
73 | static void expire_temp_kd(void *list); | |
74 | static void reorganise_temp_kd(void *list); | |
75 | ||
76 | FILE *conf_fbfile_in; | |
77 | extern char yytext[]; | |
78 | ||
79 | static int verify_access(struct Client *client_p, const char *username); | |
80 | static int attach_iline(struct Client *, struct ConfItem *); | |
81 | ||
82 | void | |
83 | init_s_conf(void) | |
84 | { | |
0cca1f52 | 85 | confitem_heap = rb_bh_create(sizeof(struct ConfItem), CONFITEM_HEAP_SIZE, "confitem_heap"); |
212380e3 | 86 | |
9e29fe51 VY |
87 | rb_event_addish("expire_temp_klines", expire_temp_kd, &temp_klines[TEMP_MIN], 60); |
88 | rb_event_addish("expire_temp_dlines", expire_temp_kd, &temp_dlines[TEMP_MIN], 60); | |
212380e3 | 89 | |
9e29fe51 | 90 | rb_event_addish("expire_temp_klines_hour", reorganise_temp_kd, |
212380e3 | 91 | &temp_klines[TEMP_HOUR], 3600); |
9e29fe51 | 92 | rb_event_addish("expire_temp_dlines_hour", reorganise_temp_kd, |
212380e3 | 93 | &temp_dlines[TEMP_HOUR], 3600); |
9e29fe51 | 94 | rb_event_addish("expire_temp_klines_day", reorganise_temp_kd, |
212380e3 | 95 | &temp_klines[TEMP_DAY], 86400); |
9e29fe51 | 96 | rb_event_addish("expire_temp_dlines_day", reorganise_temp_kd, |
212380e3 | 97 | &temp_dlines[TEMP_DAY], 86400); |
9e29fe51 | 98 | rb_event_addish("expire_temp_klines_week", reorganise_temp_kd, |
212380e3 | 99 | &temp_klines[TEMP_WEEK], 604800); |
9e29fe51 | 100 | rb_event_addish("expire_temp_dlines_week", reorganise_temp_kd, |
212380e3 | 101 | &temp_dlines[TEMP_WEEK], 604800); |
102 | } | |
103 | ||
104 | /* | |
105 | * make_conf | |
106 | * | |
107 | * inputs - none | |
108 | * output - pointer to new conf entry | |
109 | * side effects - none | |
110 | */ | |
111 | struct ConfItem * | |
112 | make_conf() | |
113 | { | |
114 | struct ConfItem *aconf; | |
115 | ||
6e9b4415 | 116 | aconf = rb_bh_alloc(confitem_heap); |
212380e3 | 117 | aconf->status = CONF_ILLEGAL; |
118 | return (aconf); | |
119 | } | |
120 | ||
121 | /* | |
122 | * free_conf | |
123 | * | |
124 | * inputs - pointer to conf to free | |
125 | * output - none | |
126 | * side effects - crucial password fields are zeroed, conf is freed | |
127 | */ | |
128 | void | |
129 | free_conf(struct ConfItem *aconf) | |
130 | { | |
131 | s_assert(aconf != NULL); | |
132 | if(aconf == NULL) | |
133 | return; | |
134 | ||
135 | /* security.. */ | |
136 | if(aconf->passwd) | |
137 | memset(aconf->passwd, 0, strlen(aconf->passwd)); | |
138 | if(aconf->spasswd) | |
139 | memset(aconf->spasswd, 0, strlen(aconf->spasswd)); | |
140 | ||
90a3c35b VY |
141 | rb_free(aconf->passwd); |
142 | rb_free(aconf->spasswd); | |
143 | rb_free(aconf->name); | |
144 | rb_free(aconf->className); | |
145 | rb_free(aconf->user); | |
146 | rb_free(aconf->host); | |
212380e3 | 147 | |
6e9b4415 | 148 | rb_bh_free(confitem_heap, aconf); |
212380e3 | 149 | } |
150 | ||
151 | /* | |
152 | * check_client | |
153 | * | |
154 | * inputs - pointer to client | |
155 | * output - 0 = Success | |
156 | * NOT_AUTHORISED (-1) = Access denied (no I line match) | |
157 | * SOCKET_ERROR (-2) = Bad socket. | |
158 | * I_LINE_FULL (-3) = I-line is full | |
159 | * TOO_MANY (-4) = Too many connections from hostname | |
160 | * BANNED_CLIENT (-5) = K-lined | |
161 | * side effects - Ordinary client access check. | |
162 | * Look for conf lines which have the same | |
163 | * status as the flags passed. | |
164 | */ | |
165 | int | |
166 | check_client(struct Client *client_p, struct Client *source_p, const char *username) | |
167 | { | |
168 | int i; | |
169 | ||
212380e3 | 170 | if((i = verify_access(source_p, username))) |
171 | { | |
172 | ilog(L_FUSER, "Access denied: %s[%s]", | |
173 | source_p->name, source_p->sockhost); | |
174 | } | |
175 | ||
176 | switch (i) | |
177 | { | |
178 | case SOCKET_ERROR: | |
179 | exit_client(client_p, source_p, &me, "Socket Error"); | |
180 | break; | |
181 | ||
182 | case TOO_MANY_LOCAL: | |
606384ae | 183 | /* Note that these notices are sent to opers on other |
184 | * servers also, so even if local opers are allowed to | |
185 | * see the IP, we still cannot send it. | |
186 | */ | |
212380e3 | 187 | sendto_realops_snomask(SNO_FULL, L_NETWIDE, |
188 | "Too many local connections for %s!%s%s@%s", | |
189 | source_p->name, IsGotId(source_p) ? "" : "~", | |
606384ae | 190 | source_p->username, |
191 | show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : source_p->host); | |
212380e3 | 192 | |
193 | ilog(L_FUSER, "Too many local connections from %s!%s%s@%s", | |
194 | source_p->name, IsGotId(source_p) ? "" : "~", | |
195 | source_p->username, source_p->sockhost); | |
196 | ||
83251205 | 197 | ServerStats.is_ref++; |
212380e3 | 198 | exit_client(client_p, source_p, &me, "Too many host connections (local)"); |
199 | break; | |
200 | ||
201 | case TOO_MANY_GLOBAL: | |
202 | sendto_realops_snomask(SNO_FULL, L_NETWIDE, | |
203 | "Too many global connections for %s!%s%s@%s", | |
204 | source_p->name, IsGotId(source_p) ? "" : "~", | |
606384ae | 205 | source_p->username, |
206 | show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : source_p->host); | |
212380e3 | 207 | ilog(L_FUSER, "Too many global connections from %s!%s%s@%s", |
208 | source_p->name, IsGotId(source_p) ? "" : "~", | |
209 | source_p->username, source_p->sockhost); | |
210 | ||
83251205 | 211 | ServerStats.is_ref++; |
212380e3 | 212 | exit_client(client_p, source_p, &me, "Too many host connections (global)"); |
213 | break; | |
214 | ||
215 | case TOO_MANY_IDENT: | |
216 | sendto_realops_snomask(SNO_FULL, L_NETWIDE, | |
217 | "Too many user connections for %s!%s%s@%s", | |
218 | source_p->name, IsGotId(source_p) ? "" : "~", | |
606384ae | 219 | source_p->username, |
220 | show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : source_p->host); | |
212380e3 | 221 | ilog(L_FUSER, "Too many user connections from %s!%s%s@%s", |
222 | source_p->name, IsGotId(source_p) ? "" : "~", | |
223 | source_p->username, source_p->sockhost); | |
224 | ||
83251205 | 225 | ServerStats.is_ref++; |
212380e3 | 226 | exit_client(client_p, source_p, &me, "Too many user connections (global)"); |
227 | break; | |
228 | ||
229 | case I_LINE_FULL: | |
230 | sendto_realops_snomask(SNO_FULL, L_NETWIDE, | |
231 | "I-line is full for %s!%s%s@%s (%s).", | |
232 | source_p->name, IsGotId(source_p) ? "" : "~", | |
233 | source_p->username, source_p->host, | |
4b7e6904 | 234 | show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : "255.255.255.255"); |
212380e3 | 235 | |
236 | ilog(L_FUSER, "Too many connections from %s!%s%s@%s.", | |
237 | source_p->name, IsGotId(source_p) ? "" : "~", | |
238 | source_p->username, source_p->sockhost); | |
239 | ||
83251205 | 240 | ServerStats.is_ref++; |
212380e3 | 241 | exit_client(client_p, source_p, &me, |
242 | "No more connections allowed in your connection class"); | |
243 | break; | |
244 | ||
245 | case NOT_AUTHORISED: | |
246 | { | |
247 | int port = -1; | |
2c2e0aa9 | 248 | #ifdef RB_IPV6 |
212380e3 | 249 | if(source_p->localClient->ip.ss_family == AF_INET6) |
250 | port = ntohs(((struct sockaddr_in6 *)&source_p->localClient->listener->addr)->sin6_port); | |
251 | else | |
252 | #endif | |
253 | port = ntohs(((struct sockaddr_in *)&source_p->localClient->listener->addr)->sin_port); | |
254 | ||
83251205 | 255 | ServerStats.is_ref++; |
212380e3 | 256 | /* jdc - lists server name & port connections are on */ |
257 | /* a purely cosmetical change */ | |
258 | /* why ipaddr, and not just source_p->sockhost? --fl */ | |
259 | #if 0 | |
260 | static char ipaddr[HOSTIPLEN]; | |
261 | inetntop_sock(&source_p->localClient->ip, ipaddr, sizeof(ipaddr)); | |
262 | #endif | |
263 | sendto_realops_snomask(SNO_UNAUTH, L_ALL, | |
264 | "Unauthorised client connection from " | |
265 | "%s!%s%s@%s [%s] on [%s/%u].", | |
266 | source_p->name, IsGotId(source_p) ? "" : "~", | |
267 | source_p->username, source_p->host, | |
268 | source_p->sockhost, | |
269 | source_p->localClient->listener->name, port); | |
270 | ||
271 | ilog(L_FUSER, | |
272 | "Unauthorised client connection from %s!%s%s@%s on [%s/%u].", | |
273 | source_p->name, IsGotId(source_p) ? "" : "~", | |
274 | source_p->username, source_p->sockhost, | |
275 | source_p->localClient->listener->name, port); | |
35f6f850 | 276 | add_reject(client_p, NULL, NULL); |
212380e3 | 277 | exit_client(client_p, source_p, &me, |
278 | "You are not authorised to use this server"); | |
279 | break; | |
280 | } | |
281 | case BANNED_CLIENT: | |
212380e3 | 282 | exit_client(client_p, client_p, &me, "*** Banned "); |
83251205 | 283 | ServerStats.is_ref++; |
212380e3 | 284 | break; |
285 | ||
286 | case 0: | |
287 | default: | |
288 | break; | |
289 | } | |
290 | return (i); | |
291 | } | |
292 | ||
293 | /* | |
294 | * verify_access | |
295 | * | |
296 | * inputs - pointer to client to verify | |
297 | * - pointer to proposed username | |
298 | * output - 0 if success -'ve if not | |
299 | * side effect - find the first (best) I line to attach. | |
300 | */ | |
301 | static int | |
302 | verify_access(struct Client *client_p, const char *username) | |
303 | { | |
304 | struct ConfItem *aconf; | |
305 | char non_ident[USERLEN + 1]; | |
306 | ||
307 | if(IsGotId(client_p)) | |
308 | { | |
309 | aconf = find_address_conf(client_p->host, client_p->sockhost, | |
310 | client_p->username, client_p->username, | |
311 | (struct sockaddr *) &client_p->localClient->ip, | |
312 | client_p->localClient->ip.ss_family); | |
313 | } | |
314 | else | |
315 | { | |
316 | strlcpy(non_ident, "~", sizeof(non_ident)); | |
317 | strlcat(non_ident, username, sizeof(non_ident)); | |
318 | aconf = find_address_conf(client_p->host, client_p->sockhost, | |
319 | non_ident, client_p->username, | |
320 | (struct sockaddr *) &client_p->localClient->ip, | |
321 | client_p->localClient->ip.ss_family); | |
322 | } | |
323 | ||
324 | if(aconf == NULL) | |
325 | return NOT_AUTHORISED; | |
326 | ||
327 | if(aconf->status & CONF_CLIENT) | |
328 | { | |
329 | if(aconf->flags & CONF_FLAGS_REDIR) | |
330 | { | |
88520303 | 331 | sendto_one_numeric(client_p, RPL_REDIR, form_str(RPL_REDIR), |
212380e3 | 332 | aconf->name ? aconf->name : "", aconf->port); |
333 | return (NOT_AUTHORISED); | |
334 | } | |
335 | ||
212380e3 | 336 | /* Thanks for spoof idea amm */ |
337 | if(IsConfDoSpoofIp(aconf)) | |
338 | { | |
339 | char *p; | |
340 | ||
341 | /* show_ip() depends on this --fl */ | |
342 | SetIPSpoof(client_p); | |
343 | ||
344 | if(IsConfSpoofNotice(aconf)) | |
345 | { | |
346 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
347 | "%s spoofing: %s as %s", | |
348 | client_p->name, | |
349 | show_ip(NULL, client_p) ? client_p->host : aconf->name, | |
350 | aconf->name); | |
351 | } | |
352 | ||
353 | /* user@host spoof */ | |
354 | if((p = strchr(aconf->name, '@')) != NULL) | |
355 | { | |
356 | char *host = p+1; | |
357 | *p = '\0'; | |
358 | ||
359 | strlcpy(client_p->username, aconf->name, | |
360 | sizeof(client_p->username)); | |
361 | strlcpy(client_p->host, host, | |
362 | sizeof(client_p->host)); | |
363 | *p = '@'; | |
364 | } | |
365 | else | |
366 | strlcpy(client_p->host, aconf->name, sizeof(client_p->host)); | |
367 | } | |
368 | return (attach_iline(client_p, aconf)); | |
369 | } | |
370 | else if(aconf->status & CONF_KILL) | |
371 | { | |
372 | if(ConfigFileEntry.kline_with_reason) | |
373 | { | |
374 | sendto_one(client_p, | |
92fb5c31 | 375 | form_str(ERR_YOUREBANNEDCREEP), |
212380e3 | 376 | me.name, client_p->name, aconf->passwd); |
377 | } | |
35f6f850 | 378 | add_reject(client_p, aconf->user, aconf->host); |
212380e3 | 379 | return (BANNED_CLIENT); |
380 | } | |
212380e3 | 381 | |
382 | return NOT_AUTHORISED; | |
383 | } | |
384 | ||
385 | ||
386 | /* | |
387 | * add_ip_limit | |
388 | * | |
389 | * Returns 1 if successful 0 if not | |
390 | * | |
391 | * This checks if the user has exceed the limits for their class | |
392 | * unless of course they are exempt.. | |
393 | */ | |
394 | ||
395 | static int | |
396 | add_ip_limit(struct Client *client_p, struct ConfItem *aconf) | |
397 | { | |
0cca1f52 | 398 | rb_patricia_node_t *pnode; |
212380e3 | 399 | |
400 | /* If the limits are 0 don't do anything.. */ | |
401 | if(ConfCidrAmount(aconf) == 0 || ConfCidrBitlen(aconf) == 0) | |
402 | return -1; | |
403 | ||
0cca1f52 | 404 | pnode = rb_match_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip); |
212380e3 | 405 | |
406 | if(pnode == NULL) | |
407 | pnode = make_and_lookup_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip, ConfCidrBitlen(aconf)); | |
408 | ||
409 | s_assert(pnode != NULL); | |
410 | ||
411 | if(pnode != NULL) | |
412 | { | |
413 | if(((long) pnode->data) >= ConfCidrAmount(aconf) | |
414 | && !IsConfExemptLimits(aconf)) | |
415 | { | |
416 | /* This should only happen if the limits are set to 0 */ | |
417 | if((unsigned long) pnode->data == 0) | |
418 | { | |
0cca1f52 | 419 | rb_patricia_remove(ConfIpLimits(aconf), pnode); |
212380e3 | 420 | } |
421 | return (0); | |
422 | } | |
423 | ||
424 | pnode->data++; | |
425 | } | |
426 | return 1; | |
427 | } | |
428 | ||
429 | static void | |
430 | remove_ip_limit(struct Client *client_p, struct ConfItem *aconf) | |
431 | { | |
0cca1f52 | 432 | rb_patricia_node_t *pnode; |
212380e3 | 433 | |
434 | /* If the limits are 0 don't do anything.. */ | |
435 | if(ConfCidrAmount(aconf) == 0 || ConfCidrBitlen(aconf) == 0) | |
436 | return; | |
437 | ||
0cca1f52 | 438 | pnode = rb_match_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip); |
212380e3 | 439 | if(pnode == NULL) |
440 | return; | |
441 | ||
442 | pnode->data--; | |
443 | if(((unsigned long) pnode->data) == 0) | |
444 | { | |
0cca1f52 | 445 | rb_patricia_remove(ConfIpLimits(aconf), pnode); |
212380e3 | 446 | } |
447 | ||
448 | } | |
449 | ||
450 | /* | |
451 | * attach_iline | |
452 | * | |
453 | * inputs - client pointer | |
454 | * - conf pointer | |
455 | * output - | |
456 | * side effects - do actual attach | |
457 | */ | |
458 | static int | |
459 | attach_iline(struct Client *client_p, struct ConfItem *aconf) | |
460 | { | |
461 | struct Client *target_p; | |
af81d5a0 | 462 | rb_dlink_node *ptr; |
212380e3 | 463 | int local_count = 0; |
464 | int global_count = 0; | |
465 | int ident_count = 0; | |
466 | int unidented = 0; | |
467 | ||
468 | if(IsConfExemptLimits(aconf)) | |
469 | return (attach_conf(client_p, aconf)); | |
470 | ||
471 | if(*client_p->username == '~') | |
472 | unidented = 1; | |
473 | ||
474 | ||
475 | /* find_hostname() returns the head of the list to search */ | |
8e69bb4e | 476 | RB_DLINK_FOREACH(ptr, find_hostname(client_p->host)) |
212380e3 | 477 | { |
478 | target_p = ptr->data; | |
479 | ||
480 | if(irccmp(client_p->host, target_p->orighost) != 0) | |
481 | continue; | |
482 | ||
483 | if(MyConnect(target_p)) | |
484 | local_count++; | |
485 | ||
486 | global_count++; | |
487 | ||
488 | if(unidented) | |
489 | { | |
490 | if(*target_p->username == '~') | |
491 | ident_count++; | |
492 | } | |
493 | else if(irccmp(target_p->username, client_p->username) == 0) | |
494 | ident_count++; | |
495 | ||
496 | if(ConfMaxLocal(aconf) && local_count >= ConfMaxLocal(aconf)) | |
497 | return (TOO_MANY_LOCAL); | |
498 | else if(ConfMaxGlobal(aconf) && global_count >= ConfMaxGlobal(aconf)) | |
499 | return (TOO_MANY_GLOBAL); | |
500 | else if(ConfMaxIdent(aconf) && ident_count >= ConfMaxIdent(aconf)) | |
501 | return (TOO_MANY_IDENT); | |
502 | } | |
503 | ||
504 | ||
505 | return (attach_conf(client_p, aconf)); | |
506 | } | |
507 | ||
508 | /* | |
509 | * detach_conf | |
510 | * | |
511 | * inputs - pointer to client to detach | |
512 | * output - 0 for success, -1 for failure | |
513 | * side effects - Disassociate configuration from the client. | |
514 | * Also removes a class from the list if marked for deleting. | |
515 | */ | |
516 | int | |
517 | detach_conf(struct Client *client_p) | |
518 | { | |
519 | struct ConfItem *aconf; | |
520 | ||
521 | aconf = client_p->localClient->att_conf; | |
522 | ||
523 | if(aconf != NULL) | |
524 | { | |
525 | if(ClassPtr(aconf)) | |
526 | { | |
527 | remove_ip_limit(client_p, aconf); | |
528 | ||
529 | if(ConfCurrUsers(aconf) > 0) | |
530 | --ConfCurrUsers(aconf); | |
531 | ||
532 | if(ConfMaxUsers(aconf) == -1 && ConfCurrUsers(aconf) == 0) | |
533 | { | |
534 | free_class(ClassPtr(aconf)); | |
535 | ClassPtr(aconf) = NULL; | |
536 | } | |
537 | ||
538 | } | |
539 | ||
540 | aconf->clients--; | |
541 | if(!aconf->clients && IsIllegal(aconf)) | |
542 | free_conf(aconf); | |
543 | ||
544 | client_p->localClient->att_conf = NULL; | |
545 | return 0; | |
546 | } | |
547 | ||
548 | return -1; | |
549 | } | |
550 | ||
551 | /* | |
552 | * attach_conf | |
553 | * | |
554 | * inputs - client pointer | |
555 | * - conf pointer | |
556 | * output - | |
557 | * side effects - Associate a specific configuration entry to a *local* | |
558 | * client (this is the one which used in accepting the | |
559 | * connection). Note, that this automatically changes the | |
560 | * attachment if there was an old one... | |
561 | */ | |
562 | int | |
563 | attach_conf(struct Client *client_p, struct ConfItem *aconf) | |
564 | { | |
565 | if(IsIllegal(aconf)) | |
566 | return (NOT_AUTHORISED); | |
567 | ||
568 | if(ClassPtr(aconf)) | |
569 | { | |
570 | if(!add_ip_limit(client_p, aconf)) | |
571 | return (TOO_MANY_LOCAL); | |
572 | } | |
573 | ||
574 | if((aconf->status & CONF_CLIENT) && | |
575 | ConfCurrUsers(aconf) >= ConfMaxUsers(aconf) && ConfMaxUsers(aconf) > 0) | |
576 | { | |
577 | if(!IsConfExemptLimits(aconf)) | |
578 | { | |
579 | return (I_LINE_FULL); | |
580 | } | |
581 | else | |
582 | { | |
5366977b | 583 | sendto_one_notice(client_p, ":*** I: line is full, but you have an >I: line!"); |
212380e3 | 584 | } |
585 | ||
586 | } | |
587 | ||
588 | if(client_p->localClient->att_conf != NULL) | |
589 | detach_conf(client_p); | |
590 | ||
591 | client_p->localClient->att_conf = aconf; | |
592 | ||
593 | aconf->clients++; | |
594 | ConfCurrUsers(aconf)++; | |
595 | return (0); | |
596 | } | |
597 | ||
598 | /* | |
599 | * rehash | |
600 | * | |
601 | * Actual REHASH service routine. Called with sig == 0 if it has been called | |
602 | * as a result of an operator issuing this command, else assume it has been | |
603 | * called as a result of the server receiving a HUP signal. | |
604 | */ | |
605 | int | |
606 | rehash(int sig) | |
607 | { | |
608 | if(sig != 0) | |
609 | { | |
610 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
611 | "Got signal SIGHUP, reloading ircd conf. file"); | |
612 | } | |
613 | ||
614 | restart_resolver(); | |
615 | /* don't close listeners until we know we can go ahead with the rehash */ | |
616 | read_conf_files(NO); | |
617 | ||
618 | if(ServerInfo.description != NULL) | |
619 | strlcpy(me.info, ServerInfo.description, sizeof(me.info)); | |
620 | else | |
621 | strlcpy(me.info, "unknown", sizeof(me.info)); | |
622 | ||
623 | open_logfiles(); | |
624 | return (0); | |
625 | } | |
626 | ||
627 | static struct banconf_entry | |
628 | { | |
629 | const char **filename; | |
630 | void (*func) (FILE *); | |
631 | int perm; | |
632 | } banconfs[] = { | |
633 | { &ConfigFileEntry.klinefile, parse_k_file, 0 }, | |
634 | { &ConfigFileEntry.klinefile, parse_k_file, 1 }, | |
635 | { &ConfigFileEntry.dlinefile, parse_d_file, 0 }, | |
636 | { &ConfigFileEntry.dlinefile, parse_d_file, 1 }, | |
637 | { &ConfigFileEntry.xlinefile, parse_x_file, 0 }, | |
638 | { &ConfigFileEntry.xlinefile, parse_x_file, 1 }, | |
639 | { &ConfigFileEntry.resvfile, parse_resv_file,0 }, | |
640 | { &ConfigFileEntry.resvfile, parse_resv_file,1 }, | |
641 | { NULL, NULL, 0 } | |
642 | }; | |
643 | ||
644 | void | |
645 | rehash_bans(int sig) | |
646 | { | |
647 | FILE *file; | |
648 | char buf[MAXPATHLEN]; | |
649 | int i; | |
650 | ||
651 | if(sig != 0) | |
652 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
653 | "Got signal SIGUSR2, reloading ban confs"); | |
654 | ||
655 | clear_out_address_conf_bans(); | |
656 | clear_s_newconf_bans(); | |
657 | ||
658 | for(i = 0; banconfs[i].filename; i++) | |
659 | { | |
660 | if(banconfs[i].perm) | |
661 | snprintf(buf, sizeof(buf), "%s.perm", *banconfs[i].filename); | |
662 | else | |
663 | snprintf(buf, sizeof(buf), "%s", *banconfs[i].filename); | |
664 | ||
665 | if((file = fopen(buf, "r")) == NULL) | |
666 | { | |
667 | if(banconfs[i].perm) | |
668 | continue; | |
669 | ||
670 | ilog(L_MAIN, "Failed reading ban file %s", | |
671 | *banconfs[i].filename); | |
672 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
673 | "Can't open %s file bans could be missing!", | |
674 | *banconfs[i].filename); | |
675 | } | |
676 | else | |
677 | { | |
678 | (banconfs[i].func)(file); | |
679 | fclose(file); | |
680 | } | |
681 | } | |
682 | ||
683 | check_banned_lines(); | |
684 | } | |
685 | ||
686 | /* | |
687 | * set_default_conf() | |
688 | * | |
689 | * inputs - NONE | |
690 | * output - NONE | |
691 | * side effects - Set default values here. | |
692 | * This is called **PRIOR** to parsing the | |
693 | * configuration file. If you want to do some validation | |
694 | * of values later, put them in validate_conf(). | |
695 | */ | |
696 | ||
697 | #define YES 1 | |
698 | #define NO 0 | |
699 | #define UNSET -1 | |
700 | ||
701 | static void | |
702 | set_default_conf(void) | |
703 | { | |
704 | /* ServerInfo.name is not rehashable */ | |
705 | /* ServerInfo.name = ServerInfo.name; */ | |
706 | ServerInfo.description = NULL; | |
62d28946 VY |
707 | ServerInfo.network_name = rb_strdup(NETWORK_NAME_DEFAULT); |
708 | ServerInfo.network_desc = rb_strdup(NETWORK_DESC_DEFAULT); | |
212380e3 | 709 | |
710 | memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip)); | |
711 | ServerInfo.specific_ipv4_vhost = 0; | |
2c2e0aa9 | 712 | #ifdef RB_IPV6 |
212380e3 | 713 | memset(&ServerInfo.ip6, 0, sizeof(ServerInfo.ip6)); |
714 | ServerInfo.specific_ipv6_vhost = 0; | |
715 | #endif | |
212380e3 | 716 | |
717 | /* Don't reset hub, as that will break lazylinks */ | |
718 | /* ServerInfo.hub = NO; */ | |
719 | AdminInfo.name = NULL; | |
720 | AdminInfo.email = NULL; | |
721 | AdminInfo.description = NULL; | |
722 | ||
62d28946 VY |
723 | ConfigFileEntry.default_operstring = rb_strdup("is an IRC operator"); |
724 | ConfigFileEntry.default_adminstring = rb_strdup("is a Server Administrator"); | |
725 | ConfigFileEntry.servicestring = rb_strdup("is a Network Service"); | |
212380e3 | 726 | |
727 | ConfigFileEntry.default_umodes = UMODE_INVISIBLE; | |
728 | ConfigFileEntry.failed_oper_notice = YES; | |
729 | ConfigFileEntry.anti_nick_flood = NO; | |
730 | ConfigFileEntry.disable_fake_channels = NO; | |
731 | ConfigFileEntry.max_nick_time = 20; | |
732 | ConfigFileEntry.max_nick_changes = 5; | |
733 | ConfigFileEntry.max_accept = 20; | |
734 | ConfigFileEntry.max_monitor = 60; | |
735 | ConfigFileEntry.nick_delay = 900; /* 15 minutes */ | |
736 | ConfigFileEntry.target_change = YES; | |
737 | ConfigFileEntry.anti_spam_exit_message_time = 0; | |
738 | ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT; | |
739 | ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT; | |
740 | ConfigFileEntry.client_exit = YES; | |
741 | ConfigFileEntry.dline_with_reason = YES; | |
742 | ConfigFileEntry.kline_with_reason = YES; | |
743 | ConfigFileEntry.kline_delay = 0; | |
744 | ConfigFileEntry.warn_no_nline = YES; | |
745 | ConfigFileEntry.non_redundant_klines = YES; | |
746 | ConfigFileEntry.stats_e_disabled = NO; | |
747 | ConfigFileEntry.stats_o_oper_only = NO; | |
748 | ConfigFileEntry.stats_k_oper_only = 1; /* masked */ | |
749 | ConfigFileEntry.stats_i_oper_only = 1; /* masked */ | |
750 | ConfigFileEntry.stats_P_oper_only = NO; | |
751 | ConfigFileEntry.stats_c_oper_only = NO; | |
752 | ConfigFileEntry.stats_y_oper_only = NO; | |
753 | ConfigFileEntry.stats_h_oper_only = NO; | |
754 | ConfigFileEntry.map_oper_only = YES; | |
755 | ConfigFileEntry.operspy_admin_only = NO; | |
756 | ConfigFileEntry.pace_wait = 10; | |
757 | ConfigFileEntry.caller_id_wait = 60; | |
758 | ConfigFileEntry.pace_wait_simple = 1; | |
759 | ConfigFileEntry.short_motd = NO; | |
760 | ConfigFileEntry.no_oper_flood = NO; | |
761 | ConfigFileEntry.fname_userlog = NULL; | |
762 | ConfigFileEntry.fname_fuserlog = NULL; | |
763 | ConfigFileEntry.fname_operlog = NULL; | |
764 | ConfigFileEntry.fname_foperlog = NULL; | |
765 | ConfigFileEntry.fname_serverlog = NULL; | |
212380e3 | 766 | ConfigFileEntry.fname_klinelog = NULL; |
767 | ConfigFileEntry.fname_operspylog = NULL; | |
768 | ConfigFileEntry.fname_ioerrorlog = NULL; | |
212380e3 | 769 | ConfigFileEntry.use_egd = NO; |
212380e3 | 770 | ConfigFileEntry.hide_spoof_ips = YES; |
771 | ConfigFileEntry.hide_error_messages = 1; | |
212380e3 | 772 | ConfigFileEntry.dots_in_ident = 0; |
773 | ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT; | |
62d28946 | 774 | ConfigFileEntry.servlink_path = rb_strdup(SLPATH); |
212380e3 | 775 | ConfigFileEntry.egdpool_path = NULL; |
776 | ConfigFileEntry.use_whois_actually = YES; | |
777 | ConfigFileEntry.burst_away = NO; | |
778 | ConfigFileEntry.collision_fnc = YES; | |
779 | ConfigFileEntry.global_snotices = YES; | |
780 | ConfigFileEntry.operspy_dont_care_user_info = NO; | |
781 | ||
782 | #ifdef HAVE_LIBZ | |
783 | ConfigFileEntry.compression_level = 4; | |
784 | #endif | |
785 | ||
786 | ConfigFileEntry.oper_umodes = UMODE_LOCOPS | UMODE_SERVNOTICE | | |
787 | UMODE_OPERWALL | UMODE_WALLOP; | |
788 | ConfigFileEntry.oper_only_umodes = UMODE_SERVNOTICE; | |
789 | ConfigFileEntry.oper_snomask = SNO_GENERAL; | |
790 | ||
791 | ConfigChannel.use_except = YES; | |
792 | ConfigChannel.use_invex = YES; | |
793 | ConfigChannel.use_knock = YES; | |
794 | ConfigChannel.use_forward = YES; | |
795 | ConfigChannel.knock_delay = 300; | |
796 | ConfigChannel.knock_delay_channel = 60; | |
797 | ConfigChannel.max_chans_per_user = 15; | |
798 | ConfigChannel.max_bans = 25; | |
799 | ConfigChannel.max_bans_large = 500; | |
800 | ConfigChannel.burst_topicwho = NO; | |
212380e3 | 801 | ConfigChannel.kick_on_split_riding = NO; |
802 | ||
803 | ConfigChannel.default_split_user_count = 15000; | |
804 | ConfigChannel.default_split_server_count = 10; | |
805 | ConfigChannel.no_join_on_split = NO; | |
806 | ConfigChannel.no_create_on_split = YES; | |
807 | ||
808 | ConfigServerHide.flatten_links = 0; | |
809 | ConfigServerHide.links_delay = 300; | |
810 | ConfigServerHide.hidden = 0; | |
811 | ConfigServerHide.disable_hidden = 0; | |
812 | ||
813 | ConfigFileEntry.min_nonwildcard = 4; | |
814 | ConfigFileEntry.min_nonwildcard_simple = 3; | |
815 | ConfigFileEntry.default_floodcount = 8; | |
816 | ConfigFileEntry.client_flood = CLIENT_FLOOD_DEFAULT; | |
817 | ConfigFileEntry.tkline_expire_notices = 0; | |
818 | ||
819 | ConfigFileEntry.reject_after_count = 5; | |
820 | ConfigFileEntry.reject_ban_time = 300; | |
821 | ConfigFileEntry.reject_duration = 120; | |
54015b5f | 822 | ConfigFileEntry.max_unknown_ip = 2; |
c2d96fcb | 823 | |
3fe90825 | 824 | ServerInfo.default_max_clients = MAXCONNECTIONS; |
212380e3 | 825 | } |
826 | ||
827 | #undef YES | |
828 | #undef NO | |
829 | ||
830 | /* | |
831 | * read_conf() | |
832 | * | |
833 | * | |
834 | * inputs - file descriptor pointing to config file to use | |
835 | * output - None | |
836 | * side effects - Read configuration file. | |
837 | */ | |
838 | static void | |
839 | read_conf(FILE * file) | |
840 | { | |
841 | lineno = 0; | |
842 | ||
843 | set_default_conf(); /* Set default values prior to conf parsing */ | |
844 | yyparse(); /* Load the values from the conf */ | |
845 | validate_conf(); /* Check to make sure some values are still okay. */ | |
846 | /* Some global values are also loaded here. */ | |
847 | check_class(); /* Make sure classes are valid */ | |
848 | } | |
849 | ||
850 | static void | |
851 | validate_conf(void) | |
852 | { | |
853 | if(ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN) | |
854 | ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT; | |
855 | ||
856 | if(ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN) | |
857 | ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT; | |
858 | ||
859 | if(ConfigFileEntry.servlink_path == NULL) | |
62d28946 | 860 | ConfigFileEntry.servlink_path = rb_strdup(SLPATH); |
212380e3 | 861 | |
862 | if(ServerInfo.network_name == NULL) | |
62d28946 | 863 | ServerInfo.network_name = rb_strdup(NETWORK_NAME_DEFAULT); |
212380e3 | 864 | |
865 | if(ServerInfo.network_desc == NULL) | |
62d28946 | 866 | ServerInfo.network_desc = rb_strdup(NETWORK_DESC_DEFAULT); |
212380e3 | 867 | |
8db00894 VY |
868 | if(ServerInfo.ssld_count < 1)\r |
869 | ServerInfo.ssld_count = 1; | |
870 | ||
871 | if(!rb_setup_ssl_server(ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params))\r | |
872 | {\r | |
873 | ilog(L_MAIN, "WARNING: Unable to setup SSL.");\r | |
874 | ssl_ok = 0;\r | |
875 | } else {\r | |
876 | ssl_ok = 1;\r | |
877 | send_new_ssl_certs(ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params);\r | |
878 | }\r | |
879 | \r | |
880 | if(ServerInfo.ssld_count > get_ssld_count())\r | |
881 | {\r | |
882 | int start = ServerInfo.ssld_count - get_ssld_count();\r | |
883 | /* start up additional ssld if needed */\r | |
884 | start_ssldaemon(start, ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params);\r | |
885 | \r | |
886 | } | |
887 | ||
212380e3 | 888 | if((ConfigFileEntry.client_flood < CLIENT_FLOOD_MIN) || |
889 | (ConfigFileEntry.client_flood > CLIENT_FLOOD_MAX)) | |
890 | ConfigFileEntry.client_flood = CLIENT_FLOOD_MAX; | |
891 | ||
212380e3 | 892 | if(!split_users || !split_servers || |
893 | (!ConfigChannel.no_create_on_split && !ConfigChannel.no_join_on_split)) | |
894 | { | |
0cca1f52 JT |
895 | rb_event_delete(check_splitmode_ev); |
896 | check_splitmode_ev = NULL; | |
212380e3 | 897 | splitmode = 0; |
898 | splitchecking = 0; | |
899 | } | |
900 | } | |
901 | ||
902 | /* | |
903 | * lookup_confhost - start DNS lookups of all hostnames in the conf | |
904 | * line and convert an IP addresses in a.b.c.d number for to IP#s. | |
905 | * | |
906 | */ | |
907 | ||
908 | /* | |
909 | * conf_connect_allowed | |
910 | * | |
911 | * inputs - pointer to inaddr | |
912 | * - int type ipv4 or ipv6 | |
913 | * output - ban info or NULL | |
914 | * side effects - none | |
915 | */ | |
916 | struct ConfItem * | |
917 | conf_connect_allowed(struct sockaddr *addr, int aftype) | |
918 | { | |
919 | struct ConfItem *aconf = find_dline(addr, aftype); | |
920 | ||
921 | /* DLINE exempt also gets you out of static limits/pacing... */ | |
922 | if(aconf && (aconf->status & CONF_EXEMPTDLINE)) | |
923 | return NULL; | |
924 | ||
925 | if(aconf != NULL) | |
926 | return aconf; | |
927 | ||
928 | return NULL; | |
929 | } | |
930 | ||
931 | /* add_temp_kline() | |
932 | * | |
933 | * inputs - pointer to struct ConfItem | |
934 | * output - none | |
935 | * Side effects - links in given struct ConfItem into | |
936 | * temporary kline link list | |
937 | */ | |
938 | void | |
939 | add_temp_kline(struct ConfItem *aconf) | |
940 | { | |
9f6bbe3c | 941 | if(aconf->hold >= rb_current_time() + (10080 * 60)) |
212380e3 | 942 | { |
af81d5a0 | 943 | rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_WEEK]); |
212380e3 | 944 | aconf->port = TEMP_WEEK; |
945 | } | |
9f6bbe3c | 946 | else if(aconf->hold >= rb_current_time() + (1440 * 60)) |
212380e3 | 947 | { |
af81d5a0 | 948 | rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_DAY]); |
212380e3 | 949 | aconf->port = TEMP_DAY; |
950 | } | |
9f6bbe3c | 951 | else if(aconf->hold >= rb_current_time() + (60 * 60)) |
212380e3 | 952 | { |
af81d5a0 | 953 | rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_HOUR]); |
212380e3 | 954 | aconf->port = TEMP_HOUR; |
955 | } | |
956 | else | |
957 | { | |
af81d5a0 | 958 | rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_MIN]); |
212380e3 | 959 | aconf->port = TEMP_MIN; |
960 | } | |
961 | ||
962 | aconf->flags |= CONF_FLAGS_TEMPORARY; | |
963 | add_conf_by_address(aconf->host, CONF_KILL, aconf->user, aconf); | |
964 | } | |
965 | ||
966 | /* add_temp_dline() | |
967 | * | |
968 | * input - pointer to struct ConfItem | |
969 | * output - none | |
970 | * side effects - added to tdline link list and address hash | |
971 | */ | |
972 | void | |
973 | add_temp_dline(struct ConfItem *aconf) | |
974 | { | |
9f6bbe3c | 975 | if(aconf->hold >= rb_current_time() + (10080 * 60)) |
212380e3 | 976 | { |
af81d5a0 | 977 | rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_WEEK]); |
212380e3 | 978 | aconf->port = TEMP_WEEK; |
979 | } | |
9f6bbe3c | 980 | else if(aconf->hold >= rb_current_time() + (1440 * 60)) |
212380e3 | 981 | { |
af81d5a0 | 982 | rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_DAY]); |
212380e3 | 983 | aconf->port = TEMP_DAY; |
984 | } | |
9f6bbe3c | 985 | else if(aconf->hold >= rb_current_time() + (60 * 60)) |
212380e3 | 986 | { |
af81d5a0 | 987 | rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_HOUR]); |
212380e3 | 988 | aconf->port = TEMP_HOUR; |
989 | } | |
990 | else | |
991 | { | |
af81d5a0 | 992 | rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_MIN]); |
212380e3 | 993 | aconf->port = TEMP_MIN; |
994 | } | |
995 | ||
996 | aconf->flags |= CONF_FLAGS_TEMPORARY; | |
997 | add_conf_by_address(aconf->host, CONF_DLINE, aconf->user, aconf); | |
998 | } | |
999 | ||
1000 | /* expire_tkline() | |
1001 | * | |
1002 | * inputs - list pointer | |
1003 | * - type | |
1004 | * output - NONE | |
1005 | * side effects - expire tklines and moves them between lists | |
1006 | */ | |
1007 | static void | |
1008 | expire_temp_kd(void *list) | |
1009 | { | |
af81d5a0 | 1010 | rb_dlink_node *ptr; |
90a3c35b | 1011 | rb_dlink_node *next_ptr; |
212380e3 | 1012 | struct ConfItem *aconf; |
1013 | ||
90a3c35b | 1014 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, ((rb_dlink_list *) list)->head) |
212380e3 | 1015 | { |
1016 | aconf = ptr->data; | |
1017 | ||
9f6bbe3c | 1018 | if(aconf->hold <= rb_current_time()) |
212380e3 | 1019 | { |
1020 | /* Alert opers that a TKline expired - Hwy */ | |
1021 | if(ConfigFileEntry.tkline_expire_notices) | |
1022 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1023 | "Temporary K-line for [%s@%s] expired", | |
1024 | (aconf->user) ? aconf-> | |
1025 | user : "*", (aconf->host) ? aconf->host : "*"); | |
1026 | ||
1027 | delete_one_address_conf(aconf->host, aconf); | |
af81d5a0 | 1028 | rb_dlinkDestroy(ptr, list); |
212380e3 | 1029 | } |
1030 | } | |
1031 | } | |
1032 | ||
1033 | static void | |
1034 | reorganise_temp_kd(void *list) | |
1035 | { | |
1036 | struct ConfItem *aconf; | |
90a3c35b | 1037 | rb_dlink_node *ptr, *next_ptr; |
212380e3 | 1038 | |
90a3c35b | 1039 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, ((rb_dlink_list *) list)->head) |
212380e3 | 1040 | { |
1041 | aconf = ptr->data; | |
1042 | ||
9f6bbe3c | 1043 | if(aconf->hold < (rb_current_time() + (60 * 60))) |
212380e3 | 1044 | { |
af81d5a0 | 1045 | rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ? |
212380e3 | 1046 | &temp_klines[TEMP_MIN] : &temp_dlines[TEMP_MIN]); |
1047 | aconf->port = TEMP_MIN; | |
1048 | } | |
1049 | else if(aconf->port > TEMP_HOUR) | |
1050 | { | |
9f6bbe3c | 1051 | if(aconf->hold < (rb_current_time() + (1440 * 60))) |
212380e3 | 1052 | { |
af81d5a0 | 1053 | rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ? |
212380e3 | 1054 | &temp_klines[TEMP_HOUR] : &temp_dlines[TEMP_HOUR]); |
1055 | aconf->port = TEMP_HOUR; | |
1056 | } | |
1057 | else if(aconf->port > TEMP_DAY && | |
9f6bbe3c | 1058 | (aconf->hold < (rb_current_time() + (10080 * 60)))) |
212380e3 | 1059 | { |
af81d5a0 | 1060 | rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ? |
212380e3 | 1061 | &temp_klines[TEMP_DAY] : &temp_dlines[TEMP_DAY]); |
1062 | aconf->port = TEMP_DAY; | |
1063 | } | |
1064 | } | |
1065 | } | |
1066 | } | |
1067 | ||
1068 | ||
1069 | /* const char* get_oper_name(struct Client *client_p) | |
1070 | * Input: A client to find the active oper{} name for. | |
1071 | * Output: The nick!user@host{oper} of the oper. | |
1072 | * "oper" is server name for remote opers | |
1073 | * Side effects: None. | |
1074 | */ | |
1075 | char * | |
1076 | get_oper_name(struct Client *client_p) | |
1077 | { | |
1078 | /* +5 for !,@,{,} and null */ | |
1079 | static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5]; | |
1080 | ||
1081 | if(MyOper(client_p)) | |
1082 | { | |
38e6acdd | 1083 | rb_snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", |
212380e3 | 1084 | client_p->name, client_p->username, |
1085 | client_p->host, client_p->localClient->opername); | |
1086 | return buffer; | |
1087 | } | |
1088 | ||
38e6acdd | 1089 | rb_snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", |
212380e3 | 1090 | client_p->name, client_p->username, |
1091 | client_p->host, client_p->servptr->name); | |
1092 | return buffer; | |
1093 | } | |
1094 | ||
1095 | /* | |
1096 | * get_printable_conf | |
1097 | * | |
1098 | * inputs - struct ConfItem | |
1099 | * | |
1100 | * output - name | |
1101 | * - host | |
1102 | * - pass | |
1103 | * - user | |
1104 | * - port | |
1105 | * | |
1106 | * side effects - | |
1107 | * Examine the struct struct ConfItem, setting the values | |
1108 | * of name, host, pass, user to values either | |
1109 | * in aconf, or "<NULL>" port is set to aconf->port in all cases. | |
1110 | */ | |
1111 | void | |
1112 | get_printable_conf(struct ConfItem *aconf, char **name, char **host, | |
1113 | char **pass, char **user, int *port, char **classname) | |
1114 | { | |
1115 | static char null[] = "<NULL>"; | |
1116 | static char zero[] = "default"; | |
1117 | ||
1118 | *name = EmptyString(aconf->name) ? null : aconf->name; | |
1119 | *host = EmptyString(aconf->host) ? null : aconf->host; | |
1120 | *pass = EmptyString(aconf->passwd) ? null : aconf->passwd; | |
1121 | *user = EmptyString(aconf->user) ? null : aconf->user; | |
1122 | *classname = EmptyString(aconf->className) ? zero : aconf->className; | |
1123 | *port = (int) aconf->port; | |
1124 | } | |
1125 | ||
21c9d815 VY |
1126 | void |
1127 | get_printable_kline(struct Client *source_p, struct ConfItem *aconf, | |
1128 | char **host, char **reason, | |
1129 | char **user, char **oper_reason) | |
1130 | { | |
1131 | static char null[] = "<NULL>"; | |
1132 | ||
1133 | *host = EmptyString(aconf->host) ? null : aconf->host; | |
1134 | *reason = EmptyString(aconf->passwd) ? null : aconf->passwd; | |
1135 | *user = EmptyString(aconf->user) ? null : aconf->user; | |
1136 | ||
1137 | if(EmptyString(aconf->spasswd) || !IsOper(source_p)) | |
1138 | *oper_reason = NULL; | |
1139 | else | |
1140 | *oper_reason = aconf->spasswd; | |
212380e3 | 1141 | } |
1142 | ||
1143 | /* | |
1144 | * read_conf_files | |
1145 | * | |
1146 | * inputs - cold start YES or NO | |
1147 | * output - none | |
1148 | * side effects - read all conf files needed, ircd.conf kline.conf etc. | |
1149 | */ | |
1150 | void | |
1151 | read_conf_files(int cold) | |
1152 | { | |
1153 | const char *filename; | |
1154 | ||
1155 | conf_fbfile_in = NULL; | |
1156 | ||
1157 | filename = get_conf_name(CONF_TYPE); | |
1158 | ||
1159 | /* We need to know the initial filename for the yyerror() to report | |
1160 | FIXME: The full path is in conffilenamebuf first time since we | |
1161 | dont know anything else | |
1162 | ||
1163 | - Gozem 2002-07-21 | |
1164 | */ | |
1165 | strlcpy(conffilebuf, filename, sizeof(conffilebuf)); | |
1166 | ||
1167 | if((conf_fbfile_in = fopen(filename, "r")) == NULL) | |
1168 | { | |
1169 | if(cold) | |
1170 | { | |
1171 | ilog(L_MAIN, "Failed in reading configuration file %s", filename); | |
1172 | exit(-1); | |
1173 | } | |
1174 | else | |
1175 | { | |
1176 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1177 | "Can't open file '%s' - aborting rehash!", filename); | |
1178 | return; | |
1179 | } | |
1180 | } | |
1181 | ||
1182 | if(!cold) | |
1183 | { | |
1184 | clear_out_old_conf(); | |
1185 | } | |
1186 | ||
1187 | read_conf(conf_fbfile_in); | |
1188 | fclose(conf_fbfile_in); | |
1189 | } | |
1190 | ||
8ac75529 WP |
1191 | /* |
1192 | * free an alias{} entry. | |
1193 | */ | |
1194 | static void | |
1195 | free_alias_cb(struct DictionaryElement *ptr, void *unused) | |
1196 | { | |
1197 | struct alias_entry *aptr = ptr->data; | |
1198 | ||
90a3c35b VY |
1199 | rb_free(aptr->name); |
1200 | rb_free(aptr->target); | |
1201 | rb_free(aptr); | |
8ac75529 WP |
1202 | } |
1203 | ||
212380e3 | 1204 | /* |
1205 | * clear_out_old_conf | |
1206 | * | |
1207 | * inputs - none | |
1208 | * output - none | |
1209 | * side effects - Clear out the old configuration | |
1210 | */ | |
1211 | static void | |
1212 | clear_out_old_conf(void) | |
1213 | { | |
1214 | struct Class *cltmp; | |
af81d5a0 | 1215 | rb_dlink_node *ptr; |
90a3c35b | 1216 | rb_dlink_node *next_ptr; |
212380e3 | 1217 | |
1218 | /* | |
1219 | * don't delete the class table, rather mark all entries | |
1220 | * for deletion. The table is cleaned up by check_class. - avalon | |
1221 | */ | |
8e69bb4e | 1222 | RB_DLINK_FOREACH(ptr, class_list.head) |
212380e3 | 1223 | { |
1224 | cltmp = ptr->data; | |
1225 | MaxUsers(cltmp) = -1; | |
1226 | } | |
1227 | ||
1228 | clear_out_address_conf(); | |
1229 | clear_s_newconf(); | |
1230 | ||
1231 | /* clean out module paths */ | |
1232 | #ifndef STATIC_MODULES | |
1233 | mod_clear_paths(); | |
1234 | mod_add_path(MODULE_DIR); | |
1235 | mod_add_path(MODULE_DIR "/autoload"); | |
1236 | #endif | |
1237 | ||
1238 | /* clean out ServerInfo */ | |
90a3c35b | 1239 | rb_free(ServerInfo.description); |
212380e3 | 1240 | ServerInfo.description = NULL; |
90a3c35b | 1241 | rb_free(ServerInfo.network_name); |
212380e3 | 1242 | ServerInfo.network_name = NULL; |
90a3c35b | 1243 | rb_free(ServerInfo.network_desc); |
212380e3 | 1244 | ServerInfo.network_desc = NULL; |
1245 | ||
8db00894 VY |
1246 | ServerInfo.ssld_count = 1; |
1247 | ||
212380e3 | 1248 | /* clean out AdminInfo */ |
90a3c35b | 1249 | rb_free(AdminInfo.name); |
212380e3 | 1250 | AdminInfo.name = NULL; |
90a3c35b | 1251 | rb_free(AdminInfo.email); |
212380e3 | 1252 | AdminInfo.email = NULL; |
90a3c35b | 1253 | rb_free(AdminInfo.description); |
212380e3 | 1254 | AdminInfo.description = NULL; |
1255 | ||
1256 | /* operator{} and class{} blocks are freed above */ | |
1257 | /* clean out listeners */ | |
1258 | close_listeners(); | |
1259 | ||
1260 | /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{}, exempt{} | |
1261 | * and gecos{} blocks are freed above too | |
1262 | */ | |
1263 | ||
1264 | /* clean out general */ | |
90a3c35b | 1265 | rb_free(ConfigFileEntry.servlink_path); |
212380e3 | 1266 | ConfigFileEntry.servlink_path = NULL; |
1267 | ||
90a3c35b | 1268 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, service_list.head) |
212380e3 | 1269 | { |
90a3c35b | 1270 | rb_free(ptr->data); |
af81d5a0 | 1271 | rb_dlinkDestroy(ptr, &service_list); |
212380e3 | 1272 | } |
1273 | ||
1274 | /* remove any aliases... -- nenolod */ | |
8ac75529 WP |
1275 | irc_dictionary_destroy(alias_dict, free_alias_cb, NULL); |
1276 | alias_dict = NULL; | |
212380e3 | 1277 | |
1278 | destroy_blacklists(); | |
1279 | ||
1280 | /* OK, that should be everything... */ | |
1281 | } | |
1282 | ||
1283 | ||
1284 | /* write_confitem() | |
1285 | * | |
1286 | * inputs - kline, dline or resv type flag | |
1287 | * - client pointer to report to | |
1288 | * - user name of target | |
1289 | * - host name of target | |
1290 | * - reason for target | |
1291 | * - time string | |
1292 | * - type of xline | |
1293 | * output - NONE | |
1294 | * side effects - This function takes care of finding the right conf | |
1295 | * file and adding the line to it, as well as notifying | |
1296 | * opers and the user. | |
1297 | */ | |
1298 | void | |
1299 | write_confitem(KlineType type, struct Client *source_p, char *user, | |
1300 | char *host, const char *reason, const char *oper_reason, | |
1301 | const char *current_date, int xtype) | |
1302 | { | |
1303 | char buffer[1024]; | |
1304 | FILE *out; | |
1305 | const char *filename; /* filename to use for kline */ | |
1306 | ||
1307 | filename = get_conf_name(type); | |
1308 | ||
1309 | if(type == KLINE_TYPE) | |
1310 | { | |
1311 | if(EmptyString(oper_reason)) | |
1312 | { | |
1313 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1314 | "%s added K-Line for [%s@%s] [%s]", | |
1315 | get_oper_name(source_p), user, | |
1316 | host, reason); | |
1317 | ilog(L_KLINE, "K %s 0 %s %s %s", | |
1318 | get_oper_name(source_p), user, host, reason); | |
1319 | } | |
1320 | else | |
1321 | { | |
1322 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1323 | "%s added K-Line for [%s@%s] [%s|%s]", | |
1324 | get_oper_name(source_p), user, | |
1325 | host, reason, oper_reason); | |
1326 | ilog(L_KLINE, "K %s 0 %s %s %s|%s", | |
1327 | get_oper_name(source_p), user, host, | |
1328 | reason, oper_reason); | |
1329 | } | |
1330 | ||
1331 | sendto_one_notice(source_p, ":Added K-Line [%s@%s]", | |
1332 | user, host); | |
1333 | } | |
1334 | else if(type == DLINE_TYPE) | |
1335 | { | |
1336 | if(EmptyString(oper_reason)) | |
1337 | { | |
1338 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1339 | "%s added D-Line for [%s] [%s]", | |
1340 | get_oper_name(source_p), host, reason); | |
1341 | ilog(L_KLINE, "D %s 0 %s %s", | |
1342 | get_oper_name(source_p), host, reason); | |
1343 | } | |
1344 | else | |
1345 | { | |
1346 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1347 | "%s added D-Line for [%s] [%s|%s]", | |
1348 | get_oper_name(source_p), host, | |
1349 | reason, oper_reason); | |
1350 | ilog(L_KLINE, "D %s 0 %s %s|%s", | |
1351 | get_oper_name(source_p), host, | |
1352 | reason, oper_reason); | |
1353 | } | |
1354 | ||
5366977b | 1355 | sendto_one_notice(source_p, ":Added D-Line [%s] to %s", host, filename); |
212380e3 | 1356 | |
1357 | } | |
1358 | else if(type == RESV_TYPE) | |
1359 | { | |
1360 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1361 | "%s added RESV for [%s] [%s]", | |
1362 | get_oper_name(source_p), host, reason); | |
1363 | ilog(L_KLINE, "R %s 0 %s %s", | |
1364 | get_oper_name(source_p), host, reason); | |
1365 | ||
1366 | sendto_one_notice(source_p, ":Added RESV for [%s] [%s]", | |
1367 | host, reason); | |
1368 | } | |
1369 | ||
1370 | if((out = fopen(filename, "a")) == NULL) | |
1371 | { | |
1372 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "*** Problem opening %s ", filename); | |
1373 | sendto_one_notice(source_p, ":*** Problem opening file, added temporarily only"); | |
1374 | return; | |
1375 | } | |
1376 | ||
1377 | if(oper_reason == NULL) | |
1378 | oper_reason = ""; | |
1379 | ||
1380 | if(type == KLINE_TYPE) | |
1381 | { | |
38e6acdd | 1382 | rb_snprintf(buffer, sizeof(buffer), |
212380e3 | 1383 | "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n", |
1384 | user, host, reason, oper_reason, current_date, | |
8a78afe4 | 1385 | get_oper_name(source_p), (long int)rb_current_time()); |
212380e3 | 1386 | } |
1387 | else if(type == DLINE_TYPE) | |
1388 | { | |
38e6acdd | 1389 | rb_snprintf(buffer, sizeof(buffer), |
212380e3 | 1390 | "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n", host, |
8a78afe4 | 1391 | reason, oper_reason, current_date, get_oper_name(source_p), (long int)rb_current_time()); |
212380e3 | 1392 | } |
1393 | else if(type == RESV_TYPE) | |
1394 | { | |
38e6acdd | 1395 | rb_snprintf(buffer, sizeof(buffer), "\"%s\",\"%s\",\"%s\",%ld\n", |
8a78afe4 | 1396 | host, reason, get_oper_name(source_p), (long int)rb_current_time()); |
212380e3 | 1397 | } |
1398 | ||
1399 | if(fputs(buffer, out) == -1) | |
1400 | { | |
1401 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "*** Problem writing to %s", filename); | |
1402 | sendto_one_notice(source_p, ":*** Problem writing to file, added temporarily only"); | |
1403 | fclose(out); | |
1404 | return; | |
1405 | } | |
1406 | ||
1407 | if (fclose(out)) | |
1408 | { | |
1409 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "*** Problem writing to %s", filename); | |
1410 | sendto_one_notice(source_p, ":*** Problem writing to file, added temporarily only"); | |
1411 | return; | |
1412 | } | |
1413 | } | |
1414 | ||
1415 | /* get_conf_name | |
1416 | * | |
1417 | * inputs - type of conf file to return name of file for | |
1418 | * output - pointer to filename for type of conf | |
1419 | * side effects - none | |
1420 | */ | |
1421 | const char * | |
1422 | get_conf_name(KlineType type) | |
1423 | { | |
1424 | if(type == CONF_TYPE) | |
1425 | { | |
1426 | return (ConfigFileEntry.configfile); | |
1427 | } | |
1428 | else if(type == DLINE_TYPE) | |
1429 | { | |
1430 | return (ConfigFileEntry.dlinefile); | |
1431 | } | |
1432 | else if(type == RESV_TYPE) | |
1433 | { | |
1434 | return (ConfigFileEntry.resvfile); | |
1435 | } | |
1436 | ||
1437 | return ConfigFileEntry.klinefile; | |
1438 | } | |
1439 | ||
1440 | /* | |
1441 | * conf_add_class_to_conf | |
1442 | * inputs - pointer to config item | |
1443 | * output - NONE | |
1444 | * side effects - Add a class pointer to a conf | |
1445 | */ | |
1446 | ||
1447 | void | |
1448 | conf_add_class_to_conf(struct ConfItem *aconf) | |
1449 | { | |
1450 | if(aconf->className == NULL) | |
1451 | { | |
62d28946 | 1452 | aconf->className = rb_strdup("default"); |
212380e3 | 1453 | ClassPtr(aconf) = default_class; |
1454 | return; | |
1455 | } | |
1456 | ||
1457 | ClassPtr(aconf) = find_class(aconf->className); | |
1458 | ||
1459 | if(ClassPtr(aconf) == default_class) | |
1460 | { | |
1461 | if(aconf->status == CONF_CLIENT) | |
1462 | { | |
1463 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
1464 | "Warning -- Using default class for missing class \"%s\" in auth{} for %s@%s", | |
1465 | aconf->className, aconf->user, aconf->host); | |
1466 | } | |
1467 | ||
90a3c35b | 1468 | rb_free(aconf->className); |
62d28946 | 1469 | aconf->className = rb_strdup("default"); |
212380e3 | 1470 | return; |
1471 | } | |
1472 | ||
1473 | if(ConfMaxUsers(aconf) < 0) | |
1474 | { | |
1475 | ClassPtr(aconf) = default_class; | |
90a3c35b | 1476 | rb_free(aconf->className); |
62d28946 | 1477 | aconf->className = rb_strdup("default"); |
212380e3 | 1478 | return; |
1479 | } | |
1480 | } | |
1481 | ||
1482 | /* | |
1483 | * conf_add_d_conf | |
1484 | * inputs - pointer to config item | |
1485 | * output - NONE | |
1486 | * side effects - Add a d/D line | |
1487 | */ | |
1488 | void | |
1489 | conf_add_d_conf(struct ConfItem *aconf) | |
1490 | { | |
1491 | if(aconf->host == NULL) | |
1492 | return; | |
1493 | ||
1494 | aconf->user = NULL; | |
1495 | ||
1496 | /* XXX - Should 'd' ever be in the old conf? For new conf we don't | |
1497 | * need this anyway, so I will disable it for now... -A1kmm | |
1498 | */ | |
1499 | ||
1500 | if(parse_netmask(aconf->host, NULL, NULL) == HM_HOST) | |
1501 | { | |
1502 | ilog(L_MAIN, "Invalid Dline %s ignored", aconf->host); | |
1503 | free_conf(aconf); | |
1504 | } | |
1505 | else | |
1506 | { | |
1507 | add_conf_by_address(aconf->host, CONF_DLINE, NULL, aconf); | |
1508 | } | |
1509 | } | |
1510 | ||
1511 | ||
1512 | /* | |
1513 | * yyerror | |
1514 | * | |
1515 | * inputs - message from parser | |
1516 | * output - none | |
1517 | * side effects - message to opers and log file entry is made | |
1518 | */ | |
1519 | void | |
1520 | yyerror(const char *msg) | |
1521 | { | |
1522 | char newlinebuf[BUFSIZE]; | |
1523 | ||
1524 | strip_tabs(newlinebuf, (const unsigned char *) linebuf, strlen(linebuf)); | |
1525 | ||
1526 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "\"%s\", line %d: %s at '%s'", | |
1527 | conffilebuf, lineno + 1, msg, newlinebuf); | |
1528 | ||
1529 | ilog(L_MAIN, "\"%s\", line %d: %s at '%s'", conffilebuf, lineno + 1, msg, newlinebuf); | |
1530 | } | |
1531 | ||
1532 | int | |
1533 | conf_fgets(char *lbuf, int max_size, FILE * fb) | |
1534 | { | |
1535 | char *buff; | |
1536 | ||
1537 | if((buff = fgets(lbuf, max_size, fb)) == NULL) | |
1538 | return (0); | |
1539 | ||
1540 | return (strlen(lbuf)); | |
1541 | } | |
1542 | ||
1543 | int | |
1544 | conf_yy_fatal_error(const char *msg) | |
1545 | { | |
1546 | return (0); | |
1547 | } |