]> jfr.im git - irc/rqf/shadowircd.git/blame - src/s_conf.c
'rb_dlink_list global_channel_list' declaration moved to channel.c
[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
b9f46fc5 53extern int yyparse(void); /* defined in y.tab.c */
212380e3 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,
969a1ae6
VY
311 client_p->localClient->ip.ss_family,
312 client_p->localClient->auth_user);
212380e3 313 }
314 else
315 {
907468c4 316 rb_strlcpy(non_ident, "~", sizeof(non_ident));
a64c5173 317 rb_strlcat(non_ident, username, sizeof(non_ident));
212380e3 318 aconf = find_address_conf(client_p->host, client_p->sockhost,
319 non_ident, client_p->username,
320 (struct sockaddr *) &client_p->localClient->ip,
969a1ae6
VY
321 client_p->localClient->ip.ss_family,
322 client_p->localClient->auth_user);
212380e3 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 {
88520303 332 sendto_one_numeric(client_p, RPL_REDIR, form_str(RPL_REDIR),
212380e3 333 aconf->name ? aconf->name : "", aconf->port);
334 return (NOT_AUTHORISED);
335 }
336
212380e3 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
907468c4 360 rb_strlcpy(client_p->username, aconf->name,
212380e3 361 sizeof(client_p->username));
907468c4 362 rb_strlcpy(client_p->host, host,
212380e3 363 sizeof(client_p->host));
364 *p = '@';
365 }
366 else
907468c4 367 rb_strlcpy(client_p->host, aconf->name, sizeof(client_p->host));
212380e3 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,
92fb5c31 376 form_str(ERR_YOUREBANNEDCREEP),
212380e3 377 me.name, client_p->name, aconf->passwd);
378 }
35f6f850 379 add_reject(client_p, aconf->user, aconf->host);
212380e3 380 return (BANNED_CLIENT);
381 }
212380e3 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
396static int
397add_ip_limit(struct Client *client_p, struct ConfItem *aconf)
398{
0cca1f52 399 rb_patricia_node_t *pnode;
212380e3 400
401 /* If the limits are 0 don't do anything.. */
402 if(ConfCidrAmount(aconf) == 0 || ConfCidrBitlen(aconf) == 0)
403 return -1;
404
0cca1f52 405 pnode = rb_match_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip);
212380e3 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 {
0cca1f52 420 rb_patricia_remove(ConfIpLimits(aconf), pnode);
212380e3 421 }
422 return (0);
423 }
424
425 pnode->data++;
426 }
427 return 1;
428}
429
430static void
431remove_ip_limit(struct Client *client_p, struct ConfItem *aconf)
432{
0cca1f52 433 rb_patricia_node_t *pnode;
212380e3 434
435 /* If the limits are 0 don't do anything.. */
436 if(ConfCidrAmount(aconf) == 0 || ConfCidrBitlen(aconf) == 0)
437 return;
438
0cca1f52 439 pnode = rb_match_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip);
212380e3 440 if(pnode == NULL)
441 return;
442
443 pnode->data--;
444 if(((unsigned long) pnode->data) == 0)
445 {
0cca1f52 446 rb_patricia_remove(ConfIpLimits(aconf), pnode);
212380e3 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 */
459static int
460attach_iline(struct Client *client_p, struct ConfItem *aconf)
461{
462 struct Client *target_p;
af81d5a0 463 rb_dlink_node *ptr;
212380e3 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 */
8e69bb4e 477 RB_DLINK_FOREACH(ptr, find_hostname(client_p->host))
212380e3 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 */
517int
518detach_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 */
563int
564attach_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 {
5366977b 584 sendto_one_notice(client_p, ":*** I: line is full, but you have an >I: line!");
212380e3 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 */
606int
607rehash(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)
907468c4 620 rb_strlcpy(me.info, ServerInfo.description, sizeof(me.info));
212380e3 621 else
907468c4 622 rb_strlcpy(me.info, "unknown", sizeof(me.info));
212380e3 623
624 open_logfiles();
625 return (0);
626}
627
628static 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
645void
646rehash_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
702static void
703set_default_conf(void)
704{
705 /* ServerInfo.name is not rehashable */
706 /* ServerInfo.name = ServerInfo.name; */
707 ServerInfo.description = NULL;
62d28946
VY
708 ServerInfo.network_name = rb_strdup(NETWORK_NAME_DEFAULT);
709 ServerInfo.network_desc = rb_strdup(NETWORK_DESC_DEFAULT);
212380e3 710
711 memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip));
712 ServerInfo.specific_ipv4_vhost = 0;
2c2e0aa9 713#ifdef RB_IPV6
212380e3 714 memset(&ServerInfo.ip6, 0, sizeof(ServerInfo.ip6));
715 ServerInfo.specific_ipv6_vhost = 0;
716#endif
212380e3 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
62d28946
VY
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");
212380e3 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;
212380e3 767 ConfigFileEntry.fname_klinelog = NULL;
768 ConfigFileEntry.fname_operspylog = NULL;
769 ConfigFileEntry.fname_ioerrorlog = NULL;
212380e3 770 ConfigFileEntry.use_egd = NO;
212380e3 771 ConfigFileEntry.hide_spoof_ips = YES;
772 ConfigFileEntry.hide_error_messages = 1;
212380e3 773 ConfigFileEntry.dots_in_ident = 0;
774 ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT;
62d28946 775 ConfigFileEntry.servlink_path = rb_strdup(SLPATH);
212380e3 776 ConfigFileEntry.egdpool_path = NULL;
777 ConfigFileEntry.use_whois_actually = YES;
778 ConfigFileEntry.burst_away = NO;
779 ConfigFileEntry.collision_fnc = YES;
780 ConfigFileEntry.global_snotices = YES;
781 ConfigFileEntry.operspy_dont_care_user_info = NO;
782
783#ifdef HAVE_LIBZ
784 ConfigFileEntry.compression_level = 4;
785#endif
786
787 ConfigFileEntry.oper_umodes = UMODE_LOCOPS | UMODE_SERVNOTICE |
788 UMODE_OPERWALL | UMODE_WALLOP;
789 ConfigFileEntry.oper_only_umodes = UMODE_SERVNOTICE;
790 ConfigFileEntry.oper_snomask = SNO_GENERAL;
791
792 ConfigChannel.use_except = YES;
793 ConfigChannel.use_invex = YES;
794 ConfigChannel.use_knock = YES;
795 ConfigChannel.use_forward = YES;
796 ConfigChannel.knock_delay = 300;
797 ConfigChannel.knock_delay_channel = 60;
798 ConfigChannel.max_chans_per_user = 15;
799 ConfigChannel.max_bans = 25;
800 ConfigChannel.max_bans_large = 500;
801 ConfigChannel.burst_topicwho = NO;
212380e3 802 ConfigChannel.kick_on_split_riding = NO;
803
804 ConfigChannel.default_split_user_count = 15000;
805 ConfigChannel.default_split_server_count = 10;
806 ConfigChannel.no_join_on_split = NO;
807 ConfigChannel.no_create_on_split = YES;
808
809 ConfigServerHide.flatten_links = 0;
810 ConfigServerHide.links_delay = 300;
811 ConfigServerHide.hidden = 0;
812 ConfigServerHide.disable_hidden = 0;
813
814 ConfigFileEntry.min_nonwildcard = 4;
815 ConfigFileEntry.min_nonwildcard_simple = 3;
816 ConfigFileEntry.default_floodcount = 8;
817 ConfigFileEntry.client_flood = CLIENT_FLOOD_DEFAULT;
818 ConfigFileEntry.tkline_expire_notices = 0;
819
820 ConfigFileEntry.reject_after_count = 5;
821 ConfigFileEntry.reject_ban_time = 300;
822 ConfigFileEntry.reject_duration = 120;
54015b5f 823 ConfigFileEntry.max_unknown_ip = 2;
c2d96fcb 824
3fe90825 825 ServerInfo.default_max_clients = MAXCONNECTIONS;
212380e3 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 */
839static void
840read_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
851static void
852validate_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(ConfigFileEntry.servlink_path == NULL)
62d28946 861 ConfigFileEntry.servlink_path = rb_strdup(SLPATH);
212380e3 862
863 if(ServerInfo.network_name == NULL)
62d28946 864 ServerInfo.network_name = rb_strdup(NETWORK_NAME_DEFAULT);
212380e3 865
866 if(ServerInfo.network_desc == NULL)
62d28946 867 ServerInfo.network_desc = rb_strdup(NETWORK_DESC_DEFAULT);
212380e3 868
b717a466 869 if(ServerInfo.ssld_count < 1)
8db00894
VY
870 ServerInfo.ssld_count = 1;
871
b717a466
JT
872 if(!rb_setup_ssl_server(ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params))
873 {
874 ilog(L_MAIN, "WARNING: Unable to setup SSL.");
875 ssl_ok = 0;
876 } else {
877 ssl_ok = 1;
878 send_new_ssl_certs(ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params);
879 }
880
881 if(ServerInfo.ssld_count > get_ssld_count())
882 {
883 int start = ServerInfo.ssld_count - get_ssld_count();
884 /* start up additional ssld if needed */
885 start_ssldaemon(start, ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params);
886
8db00894
VY
887 }
888
212380e3 889 if((ConfigFileEntry.client_flood < CLIENT_FLOOD_MIN) ||
890 (ConfigFileEntry.client_flood > CLIENT_FLOOD_MAX))
891 ConfigFileEntry.client_flood = CLIENT_FLOOD_MAX;
892
212380e3 893 if(!split_users || !split_servers ||
894 (!ConfigChannel.no_create_on_split && !ConfigChannel.no_join_on_split))
895 {
0cca1f52
JT
896 rb_event_delete(check_splitmode_ev);
897 check_splitmode_ev = NULL;
212380e3 898 splitmode = 0;
899 splitchecking = 0;
900 }
901}
902
212380e3 903/* add_temp_kline()
904 *
905 * inputs - pointer to struct ConfItem
906 * output - none
907 * Side effects - links in given struct ConfItem into
908 * temporary kline link list
909 */
910void
911add_temp_kline(struct ConfItem *aconf)
912{
9f6bbe3c 913 if(aconf->hold >= rb_current_time() + (10080 * 60))
212380e3 914 {
af81d5a0 915 rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_WEEK]);
212380e3 916 aconf->port = TEMP_WEEK;
917 }
9f6bbe3c 918 else if(aconf->hold >= rb_current_time() + (1440 * 60))
212380e3 919 {
af81d5a0 920 rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_DAY]);
212380e3 921 aconf->port = TEMP_DAY;
922 }
9f6bbe3c 923 else if(aconf->hold >= rb_current_time() + (60 * 60))
212380e3 924 {
af81d5a0 925 rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_HOUR]);
212380e3 926 aconf->port = TEMP_HOUR;
927 }
928 else
929 {
af81d5a0 930 rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_MIN]);
212380e3 931 aconf->port = TEMP_MIN;
932 }
933
934 aconf->flags |= CONF_FLAGS_TEMPORARY;
969a1ae6 935 add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf);
212380e3 936}
937
938/* add_temp_dline()
939 *
940 * input - pointer to struct ConfItem
941 * output - none
942 * side effects - added to tdline link list and address hash
943 */
944void
945add_temp_dline(struct ConfItem *aconf)
946{
9f6bbe3c 947 if(aconf->hold >= rb_current_time() + (10080 * 60))
212380e3 948 {
af81d5a0 949 rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_WEEK]);
212380e3 950 aconf->port = TEMP_WEEK;
951 }
9f6bbe3c 952 else if(aconf->hold >= rb_current_time() + (1440 * 60))
212380e3 953 {
af81d5a0 954 rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_DAY]);
212380e3 955 aconf->port = TEMP_DAY;
956 }
9f6bbe3c 957 else if(aconf->hold >= rb_current_time() + (60 * 60))
212380e3 958 {
af81d5a0 959 rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_HOUR]);
212380e3 960 aconf->port = TEMP_HOUR;
961 }
962 else
963 {
af81d5a0 964 rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_MIN]);
212380e3 965 aconf->port = TEMP_MIN;
966 }
967
968 aconf->flags |= CONF_FLAGS_TEMPORARY;
969a1ae6 969 add_conf_by_address(aconf->host, CONF_DLINE, aconf->user, NULL, aconf);
212380e3 970}
971
972/* expire_tkline()
973 *
974 * inputs - list pointer
975 * - type
976 * output - NONE
977 * side effects - expire tklines and moves them between lists
978 */
979static void
980expire_temp_kd(void *list)
981{
af81d5a0 982 rb_dlink_node *ptr;
90a3c35b 983 rb_dlink_node *next_ptr;
212380e3 984 struct ConfItem *aconf;
985
90a3c35b 986 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, ((rb_dlink_list *) list)->head)
212380e3 987 {
988 aconf = ptr->data;
989
9f6bbe3c 990 if(aconf->hold <= rb_current_time())
212380e3 991 {
992 /* Alert opers that a TKline expired - Hwy */
993 if(ConfigFileEntry.tkline_expire_notices)
994 sendto_realops_snomask(SNO_GENERAL, L_ALL,
995 "Temporary K-line for [%s@%s] expired",
996 (aconf->user) ? aconf->
997 user : "*", (aconf->host) ? aconf->host : "*");
998
999 delete_one_address_conf(aconf->host, aconf);
af81d5a0 1000 rb_dlinkDestroy(ptr, list);
212380e3 1001 }
1002 }
1003}
1004
1005static void
1006reorganise_temp_kd(void *list)
1007{
1008 struct ConfItem *aconf;
90a3c35b 1009 rb_dlink_node *ptr, *next_ptr;
212380e3 1010
90a3c35b 1011 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, ((rb_dlink_list *) list)->head)
212380e3 1012 {
1013 aconf = ptr->data;
1014
9f6bbe3c 1015 if(aconf->hold < (rb_current_time() + (60 * 60)))
212380e3 1016 {
af81d5a0 1017 rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ?
212380e3 1018 &temp_klines[TEMP_MIN] : &temp_dlines[TEMP_MIN]);
1019 aconf->port = TEMP_MIN;
1020 }
1021 else if(aconf->port > TEMP_HOUR)
1022 {
9f6bbe3c 1023 if(aconf->hold < (rb_current_time() + (1440 * 60)))
212380e3 1024 {
af81d5a0 1025 rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ?
212380e3 1026 &temp_klines[TEMP_HOUR] : &temp_dlines[TEMP_HOUR]);
1027 aconf->port = TEMP_HOUR;
1028 }
1029 else if(aconf->port > TEMP_DAY &&
9f6bbe3c 1030 (aconf->hold < (rb_current_time() + (10080 * 60))))
212380e3 1031 {
af81d5a0 1032 rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ?
212380e3 1033 &temp_klines[TEMP_DAY] : &temp_dlines[TEMP_DAY]);
1034 aconf->port = TEMP_DAY;
1035 }
1036 }
1037 }
1038}
1039
1040
1041/* const char* get_oper_name(struct Client *client_p)
1042 * Input: A client to find the active oper{} name for.
1043 * Output: The nick!user@host{oper} of the oper.
1044 * "oper" is server name for remote opers
1045 * Side effects: None.
1046 */
1047char *
1048get_oper_name(struct Client *client_p)
1049{
1050 /* +5 for !,@,{,} and null */
1051 static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5];
1052
1053 if(MyOper(client_p))
1054 {
38e6acdd 1055 rb_snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}",
212380e3 1056 client_p->name, client_p->username,
1057 client_p->host, client_p->localClient->opername);
1058 return buffer;
1059 }
1060
38e6acdd 1061 rb_snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}",
212380e3 1062 client_p->name, client_p->username,
1063 client_p->host, client_p->servptr->name);
1064 return buffer;
1065}
1066
1067/*
1068 * get_printable_conf
1069 *
1070 * inputs - struct ConfItem
1071 *
1072 * output - name
1073 * - host
1074 * - pass
1075 * - user
1076 * - port
1077 *
1078 * side effects -
1079 * Examine the struct struct ConfItem, setting the values
1080 * of name, host, pass, user to values either
1081 * in aconf, or "<NULL>" port is set to aconf->port in all cases.
1082 */
1083void
1084get_printable_conf(struct ConfItem *aconf, char **name, char **host,
1085 char **pass, char **user, int *port, char **classname)
1086{
1087 static char null[] = "<NULL>";
1088 static char zero[] = "default";
1089
1090 *name = EmptyString(aconf->name) ? null : aconf->name;
1091 *host = EmptyString(aconf->host) ? null : aconf->host;
1092 *pass = EmptyString(aconf->passwd) ? null : aconf->passwd;
1093 *user = EmptyString(aconf->user) ? null : aconf->user;
1094 *classname = EmptyString(aconf->className) ? zero : aconf->className;
1095 *port = (int) aconf->port;
1096}
1097
21c9d815
VY
1098void
1099get_printable_kline(struct Client *source_p, struct ConfItem *aconf,
1100 char **host, char **reason,
1101 char **user, char **oper_reason)
1102{
1103 static char null[] = "<NULL>";
1104
1105 *host = EmptyString(aconf->host) ? null : aconf->host;
1106 *reason = EmptyString(aconf->passwd) ? null : aconf->passwd;
1107 *user = EmptyString(aconf->user) ? null : aconf->user;
1108
1109 if(EmptyString(aconf->spasswd) || !IsOper(source_p))
1110 *oper_reason = NULL;
1111 else
1112 *oper_reason = aconf->spasswd;
212380e3 1113}
1114
1115/*
1116 * read_conf_files
1117 *
1118 * inputs - cold start YES or NO
1119 * output - none
1120 * side effects - read all conf files needed, ircd.conf kline.conf etc.
1121 */
1122void
1123read_conf_files(int cold)
1124{
1125 const char *filename;
1126
1127 conf_fbfile_in = NULL;
1128
1129 filename = get_conf_name(CONF_TYPE);
1130
1131 /* We need to know the initial filename for the yyerror() to report
1132 FIXME: The full path is in conffilenamebuf first time since we
1133 dont know anything else
1134
1135 - Gozem 2002-07-21
1136 */
907468c4 1137 rb_strlcpy(conffilebuf, filename, sizeof(conffilebuf));
212380e3 1138
1139 if((conf_fbfile_in = fopen(filename, "r")) == NULL)
1140 {
1141 if(cold)
1142 {
1143 ilog(L_MAIN, "Failed in reading configuration file %s", filename);
1144 exit(-1);
1145 }
1146 else
1147 {
1148 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1149 "Can't open file '%s' - aborting rehash!", filename);
1150 return;
1151 }
1152 }
1153
1154 if(!cold)
1155 {
1156 clear_out_old_conf();
1157 }
1158
1159 read_conf(conf_fbfile_in);
1160 fclose(conf_fbfile_in);
1161}
1162
8ac75529
WP
1163/*
1164 * free an alias{} entry.
1165 */
1166static void
1167free_alias_cb(struct DictionaryElement *ptr, void *unused)
1168{
1169 struct alias_entry *aptr = ptr->data;
1170
90a3c35b
VY
1171 rb_free(aptr->name);
1172 rb_free(aptr->target);
1173 rb_free(aptr);
8ac75529
WP
1174}
1175
212380e3 1176/*
1177 * clear_out_old_conf
1178 *
1179 * inputs - none
1180 * output - none
1181 * side effects - Clear out the old configuration
1182 */
1183static void
1184clear_out_old_conf(void)
1185{
1186 struct Class *cltmp;
af81d5a0 1187 rb_dlink_node *ptr;
90a3c35b 1188 rb_dlink_node *next_ptr;
212380e3 1189
1190 /*
1191 * don't delete the class table, rather mark all entries
1192 * for deletion. The table is cleaned up by check_class. - avalon
1193 */
8e69bb4e 1194 RB_DLINK_FOREACH(ptr, class_list.head)
212380e3 1195 {
1196 cltmp = ptr->data;
1197 MaxUsers(cltmp) = -1;
1198 }
1199
1200 clear_out_address_conf();
1201 clear_s_newconf();
1202
1203 /* clean out module paths */
1204#ifndef STATIC_MODULES
1205 mod_clear_paths();
1206 mod_add_path(MODULE_DIR);
1207 mod_add_path(MODULE_DIR "/autoload");
1208#endif
1209
1210 /* clean out ServerInfo */
90a3c35b 1211 rb_free(ServerInfo.description);
212380e3 1212 ServerInfo.description = NULL;
90a3c35b 1213 rb_free(ServerInfo.network_name);
212380e3 1214 ServerInfo.network_name = NULL;
90a3c35b 1215 rb_free(ServerInfo.network_desc);
212380e3 1216 ServerInfo.network_desc = NULL;
1217
8db00894
VY
1218 ServerInfo.ssld_count = 1;
1219
212380e3 1220 /* clean out AdminInfo */
90a3c35b 1221 rb_free(AdminInfo.name);
212380e3 1222 AdminInfo.name = NULL;
90a3c35b 1223 rb_free(AdminInfo.email);
212380e3 1224 AdminInfo.email = NULL;
90a3c35b 1225 rb_free(AdminInfo.description);
212380e3 1226 AdminInfo.description = NULL;
1227
1228 /* operator{} and class{} blocks are freed above */
1229 /* clean out listeners */
1230 close_listeners();
1231
1232 /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{}, exempt{}
1233 * and gecos{} blocks are freed above too
1234 */
1235
1236 /* clean out general */
90a3c35b 1237 rb_free(ConfigFileEntry.servlink_path);
212380e3 1238 ConfigFileEntry.servlink_path = NULL;
1239
90a3c35b 1240 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, service_list.head)
212380e3 1241 {
90a3c35b 1242 rb_free(ptr->data);
af81d5a0 1243 rb_dlinkDestroy(ptr, &service_list);
212380e3 1244 }
1245
1246 /* remove any aliases... -- nenolod */
8ac75529
WP
1247 irc_dictionary_destroy(alias_dict, free_alias_cb, NULL);
1248 alias_dict = NULL;
212380e3 1249
1250 destroy_blacklists();
1251
1252 /* OK, that should be everything... */
1253}
1254
1255
1256/* write_confitem()
1257 *
1258 * inputs - kline, dline or resv type flag
1259 * - client pointer to report to
1260 * - user name of target
1261 * - host name of target
1262 * - reason for target
1263 * - time string
1264 * - type of xline
1265 * output - NONE
1266 * side effects - This function takes care of finding the right conf
1267 * file and adding the line to it, as well as notifying
1268 * opers and the user.
1269 */
1270void
1271write_confitem(KlineType type, struct Client *source_p, char *user,
1272 char *host, const char *reason, const char *oper_reason,
1273 const char *current_date, int xtype)
1274{
1275 char buffer[1024];
1276 FILE *out;
1277 const char *filename; /* filename to use for kline */
1278
1279 filename = get_conf_name(type);
1280
1281 if(type == KLINE_TYPE)
1282 {
1283 if(EmptyString(oper_reason))
1284 {
1285 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1286 "%s added K-Line for [%s@%s] [%s]",
1287 get_oper_name(source_p), user,
1288 host, reason);
1289 ilog(L_KLINE, "K %s 0 %s %s %s",
1290 get_oper_name(source_p), user, host, reason);
1291 }
1292 else
1293 {
1294 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1295 "%s added K-Line for [%s@%s] [%s|%s]",
1296 get_oper_name(source_p), user,
1297 host, reason, oper_reason);
1298 ilog(L_KLINE, "K %s 0 %s %s %s|%s",
1299 get_oper_name(source_p), user, host,
1300 reason, oper_reason);
1301 }
1302
1303 sendto_one_notice(source_p, ":Added K-Line [%s@%s]",
1304 user, host);
1305 }
1306 else if(type == DLINE_TYPE)
1307 {
1308 if(EmptyString(oper_reason))
1309 {
1310 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1311 "%s added D-Line for [%s] [%s]",
1312 get_oper_name(source_p), host, reason);
1313 ilog(L_KLINE, "D %s 0 %s %s",
1314 get_oper_name(source_p), host, reason);
1315 }
1316 else
1317 {
1318 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1319 "%s added D-Line for [%s] [%s|%s]",
1320 get_oper_name(source_p), host,
1321 reason, oper_reason);
1322 ilog(L_KLINE, "D %s 0 %s %s|%s",
1323 get_oper_name(source_p), host,
1324 reason, oper_reason);
1325 }
1326
5366977b 1327 sendto_one_notice(source_p, ":Added D-Line [%s] to %s", host, filename);
212380e3 1328
1329 }
1330 else if(type == RESV_TYPE)
1331 {
1332 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1333 "%s added RESV for [%s] [%s]",
1334 get_oper_name(source_p), host, reason);
1335 ilog(L_KLINE, "R %s 0 %s %s",
1336 get_oper_name(source_p), host, reason);
1337
1338 sendto_one_notice(source_p, ":Added RESV for [%s] [%s]",
1339 host, reason);
1340 }
1341
1342 if((out = fopen(filename, "a")) == NULL)
1343 {
1344 sendto_realops_snomask(SNO_GENERAL, L_ALL, "*** Problem opening %s ", filename);
1345 sendto_one_notice(source_p, ":*** Problem opening file, added temporarily only");
1346 return;
1347 }
1348
1349 if(oper_reason == NULL)
1350 oper_reason = "";
1351
1352 if(type == KLINE_TYPE)
1353 {
38e6acdd 1354 rb_snprintf(buffer, sizeof(buffer),
212380e3 1355 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n",
1356 user, host, reason, oper_reason, current_date,
8a78afe4 1357 get_oper_name(source_p), (long int)rb_current_time());
212380e3 1358 }
1359 else if(type == DLINE_TYPE)
1360 {
38e6acdd 1361 rb_snprintf(buffer, sizeof(buffer),
212380e3 1362 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n", host,
8a78afe4 1363 reason, oper_reason, current_date, get_oper_name(source_p), (long int)rb_current_time());
212380e3 1364 }
1365 else if(type == RESV_TYPE)
1366 {
38e6acdd 1367 rb_snprintf(buffer, sizeof(buffer), "\"%s\",\"%s\",\"%s\",%ld\n",
8a78afe4 1368 host, reason, get_oper_name(source_p), (long int)rb_current_time());
212380e3 1369 }
1370
1371 if(fputs(buffer, out) == -1)
1372 {
1373 sendto_realops_snomask(SNO_GENERAL, L_ALL, "*** Problem writing to %s", filename);
1374 sendto_one_notice(source_p, ":*** Problem writing to file, added temporarily only");
1375 fclose(out);
1376 return;
1377 }
1378
1379 if (fclose(out))
1380 {
1381 sendto_realops_snomask(SNO_GENERAL, L_ALL, "*** Problem writing to %s", filename);
1382 sendto_one_notice(source_p, ":*** Problem writing to file, added temporarily only");
1383 return;
1384 }
1385}
1386
1387/* get_conf_name
1388 *
1389 * inputs - type of conf file to return name of file for
1390 * output - pointer to filename for type of conf
1391 * side effects - none
1392 */
1393const char *
1394get_conf_name(KlineType type)
1395{
1396 if(type == CONF_TYPE)
1397 {
1398 return (ConfigFileEntry.configfile);
1399 }
1400 else if(type == DLINE_TYPE)
1401 {
1402 return (ConfigFileEntry.dlinefile);
1403 }
1404 else if(type == RESV_TYPE)
1405 {
1406 return (ConfigFileEntry.resvfile);
1407 }
1408
1409 return ConfigFileEntry.klinefile;
1410}
1411
1412/*
1413 * conf_add_class_to_conf
1414 * inputs - pointer to config item
1415 * output - NONE
1416 * side effects - Add a class pointer to a conf
1417 */
1418
1419void
1420conf_add_class_to_conf(struct ConfItem *aconf)
1421{
1422 if(aconf->className == NULL)
1423 {
62d28946 1424 aconf->className = rb_strdup("default");
212380e3 1425 ClassPtr(aconf) = default_class;
1426 return;
1427 }
1428
1429 ClassPtr(aconf) = find_class(aconf->className);
1430
1431 if(ClassPtr(aconf) == default_class)
1432 {
1433 if(aconf->status == CONF_CLIENT)
1434 {
1435 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1436 "Warning -- Using default class for missing class \"%s\" in auth{} for %s@%s",
1437 aconf->className, aconf->user, aconf->host);
1438 }
1439
90a3c35b 1440 rb_free(aconf->className);
62d28946 1441 aconf->className = rb_strdup("default");
212380e3 1442 return;
1443 }
1444
1445 if(ConfMaxUsers(aconf) < 0)
1446 {
1447 ClassPtr(aconf) = default_class;
90a3c35b 1448 rb_free(aconf->className);
62d28946 1449 aconf->className = rb_strdup("default");
212380e3 1450 return;
1451 }
1452}
1453
1454/*
1455 * conf_add_d_conf
1456 * inputs - pointer to config item
1457 * output - NONE
1458 * side effects - Add a d/D line
1459 */
1460void
1461conf_add_d_conf(struct ConfItem *aconf)
1462{
1463 if(aconf->host == NULL)
1464 return;
1465
1466 aconf->user = NULL;
1467
1468 /* XXX - Should 'd' ever be in the old conf? For new conf we don't
1469 * need this anyway, so I will disable it for now... -A1kmm
1470 */
1471
1472 if(parse_netmask(aconf->host, NULL, NULL) == HM_HOST)
1473 {
1474 ilog(L_MAIN, "Invalid Dline %s ignored", aconf->host);
1475 free_conf(aconf);
1476 }
1477 else
1478 {
969a1ae6 1479 add_conf_by_address(aconf->host, CONF_DLINE, NULL, NULL, aconf);
212380e3 1480 }
1481}
1482
5f4f1d05
VY
1483static char *
1484strip_tabs(char *dest, const char *src, size_t len)
1485{
1486 char *d = dest;
1487
1488 if(dest == NULL || src == NULL)
1489 return NULL;
1490
1491 rb_strlcpy(dest, src, len);
1492
1493 while(*d)
1494 {
1495 if(*d == '\t')
1496 *d = ' ';
1497 d++;
1498 }
1499 return dest;
1500}
212380e3 1501
1502/*
1503 * yyerror
1504 *
1505 * inputs - message from parser
1506 * output - none
1507 * side effects - message to opers and log file entry is made
1508 */
1509void
1510yyerror(const char *msg)
1511{
1512 char newlinebuf[BUFSIZE];
1513
78a47af0 1514 strip_tabs(newlinebuf, linebuf, strlen(linebuf));
212380e3 1515
1516 sendto_realops_snomask(SNO_GENERAL, L_ALL, "\"%s\", line %d: %s at '%s'",
1517 conffilebuf, lineno + 1, msg, newlinebuf);
1518
1519 ilog(L_MAIN, "\"%s\", line %d: %s at '%s'", conffilebuf, lineno + 1, msg, newlinebuf);
1520}
1521
1522int
1523conf_fgets(char *lbuf, int max_size, FILE * fb)
1524{
1525 char *buff;
1526
1527 if((buff = fgets(lbuf, max_size, fb)) == NULL)
1528 return (0);
1529
1530 return (strlen(lbuf));
1531}
1532
1533int
1534conf_yy_fatal_error(const char *msg)
1535{
1536 return (0);
1537}