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