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