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