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