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