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