]> jfr.im git - irc/rqf/shadowircd.git/blob - src/s_conf.c
Remove ^M on line endings.
[irc/rqf/shadowircd.git] / src / s_conf.c
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 "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"
45 #include "logger.h"
46 #include "send.h"
47 #include "reject.h"
48 #include "cache.h"
49 #include "blacklist.h"
50 #include "sslproc.h"
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
61 static rb_bh *confitem_heap = NULL;
62
63 rb_dlink_list temp_klines[LAST_TEMP_TYPE];
64 rb_dlink_list temp_dlines[LAST_TEMP_TYPE];
65 rb_dlink_list service_list;
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 {
85 confitem_heap = rb_bh_create(sizeof(struct ConfItem), CONFITEM_HEAP_SIZE, "confitem_heap");
86
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);
89
90 rb_event_addish("expire_temp_klines_hour", reorganise_temp_kd,
91 &temp_klines[TEMP_HOUR], 3600);
92 rb_event_addish("expire_temp_dlines_hour", reorganise_temp_kd,
93 &temp_dlines[TEMP_HOUR], 3600);
94 rb_event_addish("expire_temp_klines_day", reorganise_temp_kd,
95 &temp_klines[TEMP_DAY], 86400);
96 rb_event_addish("expire_temp_dlines_day", reorganise_temp_kd,
97 &temp_dlines[TEMP_DAY], 86400);
98 rb_event_addish("expire_temp_klines_week", reorganise_temp_kd,
99 &temp_klines[TEMP_WEEK], 604800);
100 rb_event_addish("expire_temp_dlines_week", reorganise_temp_kd,
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
116 aconf = rb_bh_alloc(confitem_heap);
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
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);
147
148 rb_bh_free(confitem_heap, aconf);
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
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:
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 */
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) ? "" : "~",
190 source_p->username,
191 show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : source_p->host);
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
197 ServerStats.is_ref++;
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) ? "" : "~",
205 source_p->username,
206 show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : source_p->host);
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
211 ServerStats.is_ref++;
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) ? "" : "~",
219 source_p->username,
220 show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : source_p->host);
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
225 ServerStats.is_ref++;
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,
234 show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : "255.255.255.255");
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
240 ServerStats.is_ref++;
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;
248 #ifdef RB_IPV6
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
255 ServerStats.is_ref++;
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);
276 add_reject(client_p, NULL, NULL);
277 exit_client(client_p, source_p, &me,
278 "You are not authorised to use this server");
279 break;
280 }
281 case BANNED_CLIENT:
282 exit_client(client_p, client_p, &me, "*** Banned ");
283 ServerStats.is_ref++;
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 {
331 sendto_one_numeric(client_p, RPL_REDIR, form_str(RPL_REDIR),
332 aconf->name ? aconf->name : "", aconf->port);
333 return (NOT_AUTHORISED);
334 }
335
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,
375 form_str(ERR_YOUREBANNEDCREEP),
376 me.name, client_p->name, aconf->passwd);
377 }
378 add_reject(client_p, aconf->user, aconf->host);
379 return (BANNED_CLIENT);
380 }
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 {
398 rb_patricia_node_t *pnode;
399
400 /* If the limits are 0 don't do anything.. */
401 if(ConfCidrAmount(aconf) == 0 || ConfCidrBitlen(aconf) == 0)
402 return -1;
403
404 pnode = rb_match_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip);
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 {
419 rb_patricia_remove(ConfIpLimits(aconf), pnode);
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 {
432 rb_patricia_node_t *pnode;
433
434 /* If the limits are 0 don't do anything.. */
435 if(ConfCidrAmount(aconf) == 0 || ConfCidrBitlen(aconf) == 0)
436 return;
437
438 pnode = rb_match_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip);
439 if(pnode == NULL)
440 return;
441
442 pnode->data--;
443 if(((unsigned long) pnode->data) == 0)
444 {
445 rb_patricia_remove(ConfIpLimits(aconf), pnode);
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;
462 rb_dlink_node *ptr;
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 */
476 RB_DLINK_FOREACH(ptr, find_hostname(client_p->host))
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 {
583 sendto_one_notice(client_p, ":*** I: line is full, but you have an >I: line!");
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;
707 ServerInfo.network_name = rb_strdup(NETWORK_NAME_DEFAULT);
708 ServerInfo.network_desc = rb_strdup(NETWORK_DESC_DEFAULT);
709
710 memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip));
711 ServerInfo.specific_ipv4_vhost = 0;
712 #ifdef RB_IPV6
713 memset(&ServerInfo.ip6, 0, sizeof(ServerInfo.ip6));
714 ServerInfo.specific_ipv6_vhost = 0;
715 #endif
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
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");
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;
766 ConfigFileEntry.fname_klinelog = NULL;
767 ConfigFileEntry.fname_operspylog = NULL;
768 ConfigFileEntry.fname_ioerrorlog = NULL;
769 ConfigFileEntry.use_egd = NO;
770 ConfigFileEntry.hide_spoof_ips = YES;
771 ConfigFileEntry.hide_error_messages = 1;
772 ConfigFileEntry.dots_in_ident = 0;
773 ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT;
774 ConfigFileEntry.servlink_path = rb_strdup(SLPATH);
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.max_unknown_ip = 2;
823
824 ServerInfo.default_max_clients = MAXCONNECTIONS;
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)
860 ConfigFileEntry.servlink_path = rb_strdup(SLPATH);
861
862 if(ServerInfo.network_name == NULL)
863 ServerInfo.network_name = rb_strdup(NETWORK_NAME_DEFAULT);
864
865 if(ServerInfo.network_desc == NULL)
866 ServerInfo.network_desc = rb_strdup(NETWORK_DESC_DEFAULT);
867
868 if(ServerInfo.ssld_count < 1)
869 ServerInfo.ssld_count = 1;
870
871 if(!rb_setup_ssl_server(ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params))
872 {
873 ilog(L_MAIN, "WARNING: Unable to setup SSL.");
874 ssl_ok = 0;
875 } else {
876 ssl_ok = 1;
877 send_new_ssl_certs(ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params);
878 }
879
880 if(ServerInfo.ssld_count > get_ssld_count())
881 {
882 int start = ServerInfo.ssld_count - get_ssld_count();
883 /* start up additional ssld if needed */
884 start_ssldaemon(start, ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params);
885
886 }
887
888 if((ConfigFileEntry.client_flood < CLIENT_FLOOD_MIN) ||
889 (ConfigFileEntry.client_flood > CLIENT_FLOOD_MAX))
890 ConfigFileEntry.client_flood = CLIENT_FLOOD_MAX;
891
892 if(!split_users || !split_servers ||
893 (!ConfigChannel.no_create_on_split && !ConfigChannel.no_join_on_split))
894 {
895 rb_event_delete(check_splitmode_ev);
896 check_splitmode_ev = NULL;
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 {
941 if(aconf->hold >= rb_current_time() + (10080 * 60))
942 {
943 rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_WEEK]);
944 aconf->port = TEMP_WEEK;
945 }
946 else if(aconf->hold >= rb_current_time() + (1440 * 60))
947 {
948 rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_DAY]);
949 aconf->port = TEMP_DAY;
950 }
951 else if(aconf->hold >= rb_current_time() + (60 * 60))
952 {
953 rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_HOUR]);
954 aconf->port = TEMP_HOUR;
955 }
956 else
957 {
958 rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_MIN]);
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 {
975 if(aconf->hold >= rb_current_time() + (10080 * 60))
976 {
977 rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_WEEK]);
978 aconf->port = TEMP_WEEK;
979 }
980 else if(aconf->hold >= rb_current_time() + (1440 * 60))
981 {
982 rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_DAY]);
983 aconf->port = TEMP_DAY;
984 }
985 else if(aconf->hold >= rb_current_time() + (60 * 60))
986 {
987 rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_HOUR]);
988 aconf->port = TEMP_HOUR;
989 }
990 else
991 {
992 rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_MIN]);
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 {
1010 rb_dlink_node *ptr;
1011 rb_dlink_node *next_ptr;
1012 struct ConfItem *aconf;
1013
1014 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, ((rb_dlink_list *) list)->head)
1015 {
1016 aconf = ptr->data;
1017
1018 if(aconf->hold <= rb_current_time())
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);
1028 rb_dlinkDestroy(ptr, list);
1029 }
1030 }
1031 }
1032
1033 static void
1034 reorganise_temp_kd(void *list)
1035 {
1036 struct ConfItem *aconf;
1037 rb_dlink_node *ptr, *next_ptr;
1038
1039 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, ((rb_dlink_list *) list)->head)
1040 {
1041 aconf = ptr->data;
1042
1043 if(aconf->hold < (rb_current_time() + (60 * 60)))
1044 {
1045 rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ?
1046 &temp_klines[TEMP_MIN] : &temp_dlines[TEMP_MIN]);
1047 aconf->port = TEMP_MIN;
1048 }
1049 else if(aconf->port > TEMP_HOUR)
1050 {
1051 if(aconf->hold < (rb_current_time() + (1440 * 60)))
1052 {
1053 rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ?
1054 &temp_klines[TEMP_HOUR] : &temp_dlines[TEMP_HOUR]);
1055 aconf->port = TEMP_HOUR;
1056 }
1057 else if(aconf->port > TEMP_DAY &&
1058 (aconf->hold < (rb_current_time() + (10080 * 60))))
1059 {
1060 rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ?
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 {
1083 rb_snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}",
1084 client_p->name, client_p->username,
1085 client_p->host, client_p->localClient->opername);
1086 return buffer;
1087 }
1088
1089 rb_snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}",
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
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;
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
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
1199 rb_free(aptr->name);
1200 rb_free(aptr->target);
1201 rb_free(aptr);
1202 }
1203
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;
1215 rb_dlink_node *ptr;
1216 rb_dlink_node *next_ptr;
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 */
1222 RB_DLINK_FOREACH(ptr, class_list.head)
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 */
1239 rb_free(ServerInfo.description);
1240 ServerInfo.description = NULL;
1241 rb_free(ServerInfo.network_name);
1242 ServerInfo.network_name = NULL;
1243 rb_free(ServerInfo.network_desc);
1244 ServerInfo.network_desc = NULL;
1245
1246 ServerInfo.ssld_count = 1;
1247
1248 /* clean out AdminInfo */
1249 rb_free(AdminInfo.name);
1250 AdminInfo.name = NULL;
1251 rb_free(AdminInfo.email);
1252 AdminInfo.email = NULL;
1253 rb_free(AdminInfo.description);
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 */
1265 rb_free(ConfigFileEntry.servlink_path);
1266 ConfigFileEntry.servlink_path = NULL;
1267
1268 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, service_list.head)
1269 {
1270 rb_free(ptr->data);
1271 rb_dlinkDestroy(ptr, &service_list);
1272 }
1273
1274 /* remove any aliases... -- nenolod */
1275 irc_dictionary_destroy(alias_dict, free_alias_cb, NULL);
1276 alias_dict = NULL;
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
1355 sendto_one_notice(source_p, ":Added D-Line [%s] to %s", host, filename);
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 {
1382 rb_snprintf(buffer, sizeof(buffer),
1383 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n",
1384 user, host, reason, oper_reason, current_date,
1385 get_oper_name(source_p), (long int)rb_current_time());
1386 }
1387 else if(type == DLINE_TYPE)
1388 {
1389 rb_snprintf(buffer, sizeof(buffer),
1390 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n", host,
1391 reason, oper_reason, current_date, get_oper_name(source_p), (long int)rb_current_time());
1392 }
1393 else if(type == RESV_TYPE)
1394 {
1395 rb_snprintf(buffer, sizeof(buffer), "\"%s\",\"%s\",\"%s\",%ld\n",
1396 host, reason, get_oper_name(source_p), (long int)rb_current_time());
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 {
1452 aconf->className = rb_strdup("default");
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
1468 rb_free(aconf->className);
1469 aconf->className = rb_strdup("default");
1470 return;
1471 }
1472
1473 if(ConfMaxUsers(aconf) < 0)
1474 {
1475 ClassPtr(aconf) = default_class;
1476 rb_free(aconf->className);
1477 aconf->className = rb_strdup("default");
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 }