ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 7258
Committed: Sat Feb 6 17:29:57 2016 UTC (9 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 48945 byte(s)
Log Message:
- Improve libGeoIP support

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2016 ircd-hybrid development team
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA
20 */
21
22 /*! \file conf.c
23 * \brief Configuration file functions.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #include "ircd_defs.h"
30 #include "conf.h"
31 #include "conf_cluster.h"
32 #include "conf_pseudo.h"
33 #include "conf_resv.h"
34 #include "conf_service.h"
35 #include "conf_shared.h"
36 #include "server.h"
37 #include "channel.h"
38 #include "client.h"
39 #include "event.h"
40 #include "irc_string.h"
41 #include "s_bsd.h"
42 #include "ircd.h"
43 #include "listener.h"
44 #include "hostmask.h"
45 #include "modules.h"
46 #include "numeric.h"
47 #include "fdlist.h"
48 #include "log.h"
49 #include "send.h"
50 #include "memory.h"
51 #include "res.h"
52 #include "userhost.h"
53 #include "user.h"
54 #include "channel_mode.h"
55 #include "parse.h"
56 #include "misc.h"
57 #include "conf_db.h"
58 #include "conf_class.h"
59 #include "motd.h"
60 #include "ipcache.h"
61 #include "isupport.h"
62
63
64 struct config_channel_entry ConfigChannel;
65 struct config_serverhide_entry ConfigServerHide;
66 struct config_general_entry ConfigGeneral;
67 struct config_log_entry ConfigLog = { .use_logging = 1 };
68 struct config_serverinfo_entry ConfigServerInfo;
69 struct config_admin_entry ConfigAdminInfo;
70 struct conf_parser_context conf_parser_ctx;
71
72 /* general conf items link list root, other than k lines etc. */
73 dlink_list server_items;
74 dlink_list operator_items;
75 dlink_list gecos_items;
76 dlink_list nresv_items;
77 dlink_list cresv_items;
78
79 extern unsigned int lineno;
80 extern char linebuf[];
81 extern char conffilebuf[IRCD_BUFSIZE];
82 extern int yyparse(); /* defined in y.tab.c */
83
84
85 /* conf_dns_callback()
86 *
87 * inputs - pointer to struct MaskItem
88 * - pointer to DNSReply reply
89 * output - none
90 * side effects - called when resolver query finishes
91 * if the query resulted in a successful search, hp will contain
92 * a non-null pointer, otherwise hp will be null.
93 * if successful save hp in the conf item it was called with
94 */
95 static void
96 conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name, size_t namelength)
97 {
98 struct MaskItem *const conf = vptr;
99
100 conf->dns_pending = 0;
101
102 if (addr)
103 memcpy(&conf->addr, addr, sizeof(conf->addr));
104 else
105 conf->dns_failed = 1;
106 }
107
108 /* conf_dns_lookup()
109 *
110 * do a nameserver lookup of the conf host
111 * if the conf entry is currently doing a ns lookup do nothing, otherwise
112 * allocate a dns_query and start ns lookup.
113 */
114 static void
115 conf_dns_lookup(struct MaskItem *conf)
116 {
117 if (conf->dns_pending)
118 return;
119
120 conf->dns_pending = 1;
121
122 if (conf->aftype == AF_INET)
123 gethost_byname_type(conf_dns_callback, conf, conf->host, T_A);
124 else
125 gethost_byname_type(conf_dns_callback, conf, conf->host, T_AAAA);
126 }
127
128 /* map_to_list()
129 *
130 * inputs - ConfType conf
131 * output - pointer to dlink_list to use
132 * side effects - none
133 */
134 static dlink_list *
135 map_to_list(enum maskitem_type type)
136 {
137 switch (type)
138 {
139 case CONF_XLINE:
140 return &gecos_items;
141 break;
142 case CONF_NRESV:
143 return &nresv_items;
144 break;
145 case CONF_CRESV:
146 return &cresv_items;
147 break;
148 case CONF_OPER:
149 return &operator_items;
150 break;
151 case CONF_SERVER:
152 return &server_items;
153 break;
154 default:
155 return NULL;
156 }
157 }
158
159 struct MaskItem *
160 conf_make(enum maskitem_type type)
161 {
162 struct MaskItem *const conf = xcalloc(sizeof(*conf));
163 dlink_list *list = NULL;
164
165 conf->type = type;
166 conf->active = 1;
167 conf->aftype = AF_INET;
168
169 if ((list = map_to_list(type)))
170 dlinkAdd(conf, &conf->node, list);
171 return conf;
172 }
173
174 void
175 conf_free(struct MaskItem *conf)
176 {
177 dlink_node *node = NULL, *node_next = NULL;
178 dlink_list *list = NULL;
179
180 if ((list = map_to_list(conf->type)))
181 dlinkFindDelete(list, conf);
182
183 xfree(conf->name);
184
185 if (conf->dns_pending)
186 delete_resolver_queries(conf);
187 if (conf->passwd)
188 memset(conf->passwd, 0, strlen(conf->passwd));
189 if (conf->spasswd)
190 memset(conf->spasswd, 0, strlen(conf->spasswd));
191
192 conf->class = NULL;
193
194 xfree(conf->passwd);
195 xfree(conf->spasswd);
196 xfree(conf->reason);
197 xfree(conf->certfp);
198 xfree(conf->whois);
199 xfree(conf->user);
200 xfree(conf->host);
201 xfree(conf->cipher_list);
202
203 DLINK_FOREACH_SAFE(node, node_next, conf->hub_list.head)
204 {
205 xfree(node->data);
206 dlinkDelete(node, &conf->hub_list);
207 free_dlink_node(node);
208 }
209
210 DLINK_FOREACH_SAFE(node, node_next, conf->leaf_list.head)
211 {
212 xfree(node->data);
213 dlinkDelete(node, &conf->leaf_list);
214 free_dlink_node(node);
215 }
216
217 DLINK_FOREACH_SAFE(node, node_next, conf->exempt_list.head)
218 {
219 struct exempt *exptr = node->data;
220
221 dlinkDelete(node, &conf->exempt_list);
222 xfree(exptr->name);
223 xfree(exptr->user);
224 xfree(exptr->host);
225 xfree(exptr);
226 }
227
228 xfree(conf);
229 }
230
231 /* attach_iline()
232 *
233 * inputs - client pointer
234 * - conf pointer
235 * output -
236 * side effects - do actual attach
237 */
238 static int
239 attach_iline(struct Client *client_p, struct MaskItem *conf)
240 {
241 const struct ClassItem *const class = conf->class;
242 struct ip_entry *ip_found;
243 int a_limit_reached = 0;
244 unsigned int local = 0, global = 0, ident = 0;
245
246 ip_found = ipcache_find_or_add_address(&client_p->connection->ip);
247 ip_found->count++;
248 AddFlag(client_p, FLAGS_IPHASH);
249
250 userhost_count(client_p->username, client_p->host,
251 &global, &local, &ident);
252
253 /* XXX blah. go down checking the various silly limits
254 * setting a_limit_reached if any limit is reached.
255 * - Dianora
256 */
257 if (class->max_total && class->ref_count >= class->max_total)
258 a_limit_reached = 1;
259 else if (class->max_perip && ip_found->count > class->max_perip)
260 a_limit_reached = 1;
261 else if (class->max_local && local >= class->max_local)
262 a_limit_reached = 1;
263 else if (class->max_global && global >= class->max_global)
264 a_limit_reached = 1;
265 else if (class->max_ident && ident >= class->max_ident &&
266 client_p->username[0] != '~')
267 a_limit_reached = 1;
268
269 if (a_limit_reached)
270 {
271 if (!IsConfExemptLimits(conf))
272 return TOO_MANY; /* Already at maximum allowed */
273
274 sendto_one_notice(client_p, &me, ":*** Your connection class is full, "
275 "but you have exceed_limit = yes;");
276 }
277
278 return attach_conf(client_p, conf);
279 }
280
281 /* verify_access()
282 *
283 * inputs - pointer to client to verify
284 * output - 0 if success -'ve if not
285 * side effect - find the first (best) I line to attach.
286 */
287 static int
288 verify_access(struct Client *client_p)
289 {
290 struct MaskItem *conf = NULL;
291
292 if (HasFlag(client_p, FLAGS_GOTID))
293 {
294 conf = find_address_conf(client_p->host, client_p->username,
295 &client_p->connection->ip,
296 client_p->connection->aftype,
297 client_p->connection->password);
298 }
299 else
300 {
301 char non_ident[USERLEN + 1] = "~";
302
303 strlcpy(non_ident + 1, client_p->username, sizeof(non_ident) - 1);
304 conf = find_address_conf(client_p->host, non_ident,
305 &client_p->connection->ip,
306 client_p->connection->aftype,
307 client_p->connection->password);
308 }
309
310 if (!conf)
311 return NOT_AUTHORIZED;
312
313 assert(IsConfClient(conf) || IsConfKill(conf));
314
315 if (IsConfClient(conf))
316 {
317 if (IsConfRedir(conf))
318 {
319 sendto_one_numeric(client_p, &me, RPL_REDIR,
320 conf->name ? conf->name : "",
321 conf->port);
322 return NOT_AUTHORIZED;
323 }
324
325 if (IsConfDoSpoofIp(conf))
326 {
327 if (IsConfSpoofNotice(conf))
328 sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, "%s spoofing: %s as %s",
329 client_p->name, client_p->host, conf->name);
330
331 strlcpy(client_p->host, conf->name, sizeof(client_p->host));
332 }
333
334 return attach_iline(client_p, conf);
335 }
336
337 sendto_one_notice(client_p, &me, ":*** Banned: %s", conf->reason);
338 return BANNED_CLIENT;
339 }
340
341 /* check_client()
342 *
343 * inputs - pointer to client
344 * output - 0 = Success
345 * NOT_AUTHORIZED (-1) = Access denied (no I line match)
346 * IRCD_SOCKET_ERROR (-2) = Bad socket.
347 * I_LINE_FULL (-3) = I-line is full
348 * TOO_MANY (-4) = Too many connections from hostname
349 * BANNED_CLIENT (-5) = K-lined
350 * side effects - Ordinary client access check.
351 * Look for conf lines which have the same
352 * status as the flags passed.
353 */
354 int
355 check_client(struct Client *source_p)
356 {
357 int i;
358
359 if ((i = verify_access(source_p)))
360 ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
361 source_p->name, source_p->sockhost);
362
363 switch (i)
364 {
365 case TOO_MANY:
366 sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
367 "Too many on IP for %s (%s).",
368 get_client_name(source_p, SHOW_IP),
369 source_p->sockhost);
370 ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
371 get_client_name(source_p, SHOW_IP));
372 ++ServerStats.is_ref;
373 exit_client(source_p, "No more connections allowed on that IP");
374 break;
375
376 case I_LINE_FULL:
377 sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
378 "auth {} block is full for %s (%s).",
379 get_client_name(source_p, SHOW_IP),
380 source_p->sockhost);
381 ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
382 get_client_name(source_p, SHOW_IP));
383 ++ServerStats.is_ref;
384 exit_client(source_p, "No more connections allowed in your connection class");
385 break;
386
387 case NOT_AUTHORIZED:
388 /* jdc - lists server name & port connections are on */
389 /* a purely cosmetical change */
390 sendto_realops_flags(UMODE_UNAUTH, L_ALL, SEND_NOTICE,
391 "Unauthorized client connection from %s [%s] on [%s/%u].",
392 get_client_name(source_p, SHOW_IP),
393 source_p->sockhost,
394 source_p->connection->listener->name,
395 source_p->connection->listener->port);
396 ilog(LOG_TYPE_IRCD, "Unauthorized client connection from %s on [%s/%u].",
397 get_client_name(source_p, SHOW_IP),
398 source_p->connection->listener->name,
399 source_p->connection->listener->port);
400
401 ++ServerStats.is_ref;
402 exit_client(source_p, "You are not authorized to use this server");
403 break;
404
405 case BANNED_CLIENT:
406 ++ServerStats.is_ref;
407 exit_client(source_p, "Banned");
408 break;
409
410 case 0:
411 default:
412 break;
413 }
414
415 return !(i < 0);
416 }
417
418 /* detach_conf()
419 *
420 * inputs - pointer to client to detach
421 * - type of conf to detach
422 * output - 0 for success, -1 for failure
423 * side effects - Disassociate configuration from the client.
424 * Also removes a class from the list if marked for deleting.
425 */
426 void
427 detach_conf(struct Client *client_p, enum maskitem_type type)
428 {
429 dlink_node *node = NULL, *node_next = NULL;
430
431 DLINK_FOREACH_SAFE(node, node_next, client_p->connection->confs.head)
432 {
433 struct MaskItem *conf = node->data;
434
435 assert(conf->type & (CONF_CLIENT | CONF_OPER | CONF_SERVER));
436 assert(conf->ref_count > 0);
437 assert(conf->class->ref_count > 0);
438
439 if (!(conf->type & type))
440 continue;
441
442 dlinkDelete(node, &client_p->connection->confs);
443 free_dlink_node(node);
444
445 if (conf->type == CONF_CLIENT)
446 remove_from_cidr_check(&client_p->connection->ip, conf->class);
447
448 if (--conf->class->ref_count == 0 && conf->class->active == 0)
449 {
450 class_free(conf->class);
451 conf->class = NULL;
452 }
453
454 if (--conf->ref_count == 0 && conf->active == 0)
455 conf_free(conf);
456 }
457 }
458
459 /* attach_conf()
460 *
461 * inputs - client pointer
462 * - conf pointer
463 * output -
464 * side effects - Associate a specific configuration entry to a *local*
465 * client (this is the one which used in accepting the
466 * connection). Note, that this automatically changes the
467 * attachment if there was an old one...
468 */
469 int
470 attach_conf(struct Client *client_p, struct MaskItem *conf)
471 {
472 if (dlinkFind(&client_p->connection->confs, conf))
473 return 1;
474
475 if (conf->type == CONF_CLIENT)
476 if (cidr_limit_reached(IsConfExemptLimits(conf),
477 &client_p->connection->ip, conf->class))
478 return TOO_MANY; /* Already at maximum allowed */
479
480 conf->class->ref_count++;
481 conf->ref_count++;
482
483 dlinkAdd(conf, make_dlink_node(), &client_p->connection->confs);
484
485 return 0;
486 }
487
488 /* attach_connect_block()
489 *
490 * inputs - pointer to server to attach
491 * - name of server
492 * - hostname of server
493 * output - true (1) if both are found, otherwise return false (0)
494 * side effects - find connect block and attach them to connecting client
495 */
496 int
497 attach_connect_block(struct Client *client_p, const char *name,
498 const char *host)
499 {
500 dlink_node *node = NULL;
501
502 assert(host);
503
504 DLINK_FOREACH(node, server_items.head)
505 {
506 struct MaskItem *conf = node->data;
507
508 if (match(conf->name, name) || match(conf->host, host))
509 continue;
510
511 attach_conf(client_p, conf);
512 return 1;
513 }
514
515 return 0;
516 }
517
518 /* find_conf_name()
519 *
520 * inputs - pointer to conf link list to search
521 * - pointer to name to find
522 * - int mask of type of conf to find
523 * output - NULL or pointer to conf found
524 * side effects - find a conf entry which matches the name
525 * and has the given mask.
526 */
527 struct MaskItem *
528 find_conf_name(dlink_list *list, const char *name, enum maskitem_type type)
529 {
530 dlink_node *node = NULL;
531
532 DLINK_FOREACH(node, list->head)
533 {
534 struct MaskItem *conf = node->data;
535
536 if (conf->type == type)
537 {
538 if (conf->name && !irccmp(conf->name, name))
539 return conf;
540 }
541 }
542
543 return NULL;
544 }
545
546 /* find_matching_name_conf()
547 *
548 * inputs - type of link list to look in
549 * - pointer to name string to find
550 * - pointer to user
551 * - pointer to host
552 * - optional flags to match on as well
553 * output - NULL or pointer to found struct MaskItem
554 * side effects - looks for a match on name field
555 */
556 struct MaskItem *
557 find_matching_name_conf(enum maskitem_type type, const char *name, const char *user,
558 const char *host, unsigned int flags)
559 {
560 dlink_node *node = NULL;
561 dlink_list *list = map_to_list(type);
562 struct MaskItem *conf = NULL;
563
564 switch (type)
565 {
566 case CONF_XLINE:
567 case CONF_NRESV:
568 case CONF_CRESV:
569 DLINK_FOREACH(node, list->head)
570 {
571 conf = node->data;
572
573 if (EmptyString(conf->name))
574 continue;
575 if (name && !match(conf->name, name))
576 {
577 if ((user == NULL && (host == NULL)))
578 return conf;
579 if ((conf->modes & flags) != flags)
580 continue;
581 if (EmptyString(conf->user) || EmptyString(conf->host))
582 return conf;
583 if (!match(conf->user, user) && !match(conf->host, host))
584 return conf;
585 }
586 }
587 break;
588
589 case CONF_SERVER:
590 DLINK_FOREACH(node, list->head)
591 {
592 conf = node->data;
593
594 if (name && !match(name, conf->name))
595 return conf;
596 if (host && !match(host, conf->host))
597 return conf;
598 }
599 break;
600
601 default:
602 break;
603 }
604 return NULL;
605 }
606
607 /* find_exact_name_conf()
608 *
609 * inputs - type of link list to look in
610 * - pointer to name string to find
611 * - pointer to user
612 * - pointer to host
613 * output - NULL or pointer to found struct MaskItem
614 * side effects - looks for an exact match on name field
615 */
616 struct MaskItem *
617 find_exact_name_conf(enum maskitem_type type, const struct Client *who, const char *name,
618 const char *user, const char *host)
619 {
620 dlink_node *node = NULL;
621 dlink_list *list = map_to_list(type);
622 struct MaskItem *conf = NULL;
623
624 switch(type)
625 {
626 case CONF_XLINE:
627 case CONF_NRESV:
628 case CONF_CRESV:
629
630 DLINK_FOREACH(node, list->head)
631 {
632 conf = node->data;
633
634 if (EmptyString(conf->name))
635 continue;
636
637 if (irccmp(conf->name, name) == 0)
638 {
639 if ((user == NULL && (host == NULL)))
640 return conf;
641 if (EmptyString(conf->user) || EmptyString(conf->host))
642 return conf;
643 if (!match(conf->user, user) && !match(conf->host, host))
644 return conf;
645 }
646 }
647 break;
648
649 case CONF_OPER:
650 DLINK_FOREACH(node, list->head)
651 {
652 conf = node->data;
653
654 if (EmptyString(conf->name))
655 continue;
656
657 if (!irccmp(conf->name, name))
658 {
659 if (!who)
660 return conf;
661 if (EmptyString(conf->user) || EmptyString(conf->host))
662 return NULL;
663 if (!match(conf->user, who->username))
664 {
665 switch (conf->htype)
666 {
667 case HM_HOST:
668 if (!match(conf->host, who->host) || !match(conf->host, who->sockhost))
669 if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
670 return conf;
671 break;
672 case HM_IPV4:
673 if (who->connection->aftype == AF_INET)
674 if (match_ipv4(&who->connection->ip, &conf->addr, conf->bits))
675 if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
676 return conf;
677 break;
678 case HM_IPV6:
679 if (who->connection->aftype == AF_INET6)
680 if (match_ipv6(&who->connection->ip, &conf->addr, conf->bits))
681 if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
682 return conf;
683 break;
684 default:
685 assert(0);
686 }
687 }
688 }
689 }
690
691 break;
692
693 case CONF_SERVER:
694 DLINK_FOREACH(node, list->head)
695 {
696 conf = node->data;
697
698 if (EmptyString(conf->name))
699 continue;
700
701 if (name == NULL)
702 {
703 if (EmptyString(conf->host))
704 continue;
705 if (irccmp(conf->host, host) == 0)
706 return conf;
707 }
708 else if (irccmp(conf->name, name) == 0)
709 return conf;
710 }
711
712 break;
713
714 default:
715 break;
716 }
717
718 return NULL;
719 }
720
721 /* set_default_conf()
722 *
723 * inputs - NONE
724 * output - NONE
725 * side effects - Set default values here.
726 * This is called **PRIOR** to parsing the
727 * configuration file. If you want to do some validation
728 * of values later, put them in validate_conf().
729 */
730 static void
731 set_default_conf(void)
732 {
733 /* verify init_class() ran, this should be an unnecessary check
734 * but its not much work.
735 */
736 assert(class_default == class_get_list()->tail->data);
737
738 ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
739 ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
740
741 memset(&ConfigServerInfo.ip, 0, sizeof(ConfigServerInfo.ip));
742 ConfigServerInfo.specific_ipv4_vhost = 0;
743 memset(&ConfigServerInfo.ip6, 0, sizeof(ConfigServerInfo.ip6));
744 ConfigServerInfo.specific_ipv6_vhost = 0;
745
746 ConfigServerInfo.default_max_clients = MAXCLIENTS_MAX;
747 ConfigServerInfo.max_nick_length = 9;
748 ConfigServerInfo.max_topic_length = 80;
749 ConfigServerInfo.hub = 0;
750 ConfigServerInfo.libgeoip_database_options = 0;
751
752 log_del_all();
753
754 ConfigLog.use_logging = 1;
755
756 ConfigChannel.disable_fake_channels = 0;
757 ConfigChannel.invite_client_count = 10;
758 ConfigChannel.invite_client_time = 300;
759 ConfigChannel.invite_delay_channel = 5;
760 ConfigChannel.knock_client_count = 1;
761 ConfigChannel.knock_client_time = 300;
762 ConfigChannel.knock_delay_channel = 60;
763 ConfigChannel.max_channels = 25;
764 ConfigChannel.max_bans = 25;
765 ConfigChannel.default_join_flood_count = 18;
766 ConfigChannel.default_join_flood_time = 6;
767
768 ConfigServerHide.flatten_links = 0;
769 ConfigServerHide.flatten_links_delay = 300;
770 ConfigServerHide.hidden = 0;
771 ConfigServerHide.hide_servers = 0;
772 ConfigServerHide.hide_services = 0;
773 ConfigServerHide.hidden_name = xstrdup(NETWORK_NAME_DEFAULT);
774 ConfigServerHide.hide_server_ips = 0;
775 ConfigServerHide.disable_remote_commands = 0;
776
777 ConfigGeneral.away_count = 2;
778 ConfigGeneral.away_time = 10;
779 ConfigGeneral.max_watch = 50;
780 ConfigGeneral.cycle_on_host_change = 1;
781 ConfigGeneral.dline_min_cidr = 16;
782 ConfigGeneral.dline_min_cidr6 = 48;
783 ConfigGeneral.kline_min_cidr = 16;
784 ConfigGeneral.kline_min_cidr6 = 48;
785 ConfigGeneral.invisible_on_connect = 1;
786 ConfigGeneral.tkline_expire_notices = 1;
787 ConfigGeneral.ignore_bogus_ts = 0;
788 ConfigGeneral.disable_auth = 0;
789 ConfigGeneral.kill_chase_time_limit = 90;
790 ConfigGeneral.default_floodcount = 8;
791 ConfigGeneral.failed_oper_notice = 1;
792 ConfigGeneral.dots_in_ident = 0;
793 ConfigGeneral.min_nonwildcard = 4;
794 ConfigGeneral.min_nonwildcard_simple = 3;
795 ConfigGeneral.max_accept = 50;
796 ConfigGeneral.anti_nick_flood = 0;
797 ConfigGeneral.max_nick_time = 20;
798 ConfigGeneral.max_nick_changes = 5;
799 ConfigGeneral.anti_spam_exit_message_time = 0;
800 ConfigGeneral.ts_warn_delta = 30;
801 ConfigGeneral.ts_max_delta = 600;
802 ConfigGeneral.warn_no_connect_block = 1;
803 ConfigGeneral.stats_e_disabled = 0;
804 ConfigGeneral.stats_i_oper_only = 1; /* 1 = masked */
805 ConfigGeneral.stats_k_oper_only = 1; /* 1 = masked */
806 ConfigGeneral.stats_o_oper_only = 1;
807 ConfigGeneral.stats_m_oper_only = 1;
808 ConfigGeneral.stats_P_oper_only = 0;
809 ConfigGeneral.stats_u_oper_only = 0;
810 ConfigGeneral.caller_id_wait = 60;
811 ConfigGeneral.opers_bypass_callerid = 0;
812 ConfigGeneral.pace_wait = 10;
813 ConfigGeneral.pace_wait_simple = 1;
814 ConfigGeneral.short_motd = 0;
815 ConfigGeneral.ping_cookie = 0;
816 ConfigGeneral.no_oper_flood = 0;
817 ConfigGeneral.max_targets = MAX_TARGETS_DEFAULT;
818 ConfigGeneral.oper_only_umodes = UMODE_DEBUG | UMODE_LOCOPS | UMODE_HIDDEN | UMODE_FARCONNECT |
819 UMODE_UNAUTH | UMODE_EXTERNAL | UMODE_BOTS | UMODE_NCHANGE |
820 UMODE_SPY | UMODE_FULL | UMODE_SKILL | UMODE_REJ | UMODE_CCONN;
821 ConfigGeneral.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE | UMODE_WALLOP;
822 ConfigGeneral.throttle_count = 1;
823 ConfigGeneral.throttle_time = 1;
824 }
825
826 static void
827 validate_conf(void)
828 {
829 if (EmptyString(ConfigServerInfo.network_name))
830 ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
831
832 if (EmptyString(ConfigServerInfo.network_desc))
833 ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
834 }
835
836 /* read_conf()
837 *
838 * inputs - file descriptor pointing to config file to use
839 * output - None
840 * side effects - Read configuration file.
841 */
842 static void
843 read_conf(FILE *file)
844 {
845 lineno = 0;
846
847 set_default_conf(); /* Set default values prior to conf parsing */
848 conf_parser_ctx.pass = 1;
849 yyparse(); /* Pick up the classes first */
850
851 rewind(file);
852
853 conf_parser_ctx.pass = 2;
854 yyparse(); /* Load the values from the conf */
855 validate_conf(); /* Check to make sure some values are still okay. */
856 /* Some global values are also loaded here. */
857 class_delete_marked(); /* Delete unused classes that are marked for deletion */
858 }
859
860 /* conf_rehash()
861 *
862 * Actual REHASH service routine. Called with sig == 0 if it has been called
863 * as a result of an operator issuing this command, else assume it has been
864 * called as a result of the server receiving a HUP signal.
865 */
866 void
867 conf_rehash(int sig)
868 {
869 if (sig)
870 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
871 "Got signal SIGHUP, reloading configuration file(s)");
872
873 restart_resolver();
874
875 /* don't close listeners until we know we can go ahead with the rehash */
876
877 read_conf_files(0);
878
879 load_conf_modules();
880 check_conf_klines();
881 }
882
883 /* lookup_confhost()
884 *
885 * start DNS lookups of all hostnames in the conf
886 * line and convert an IP addresses in a.b.c.d number for to IP#s.
887 */
888 void
889 lookup_confhost(struct MaskItem *conf)
890 {
891 struct addrinfo hints, *res;
892
893 /*
894 * Do name lookup now on hostnames given and store the
895 * ip numbers in conf structure.
896 */
897 memset(&hints, 0, sizeof(hints));
898
899 hints.ai_family = AF_UNSPEC;
900 hints.ai_socktype = SOCK_STREAM;
901
902 /* Get us ready for a bind() and don't bother doing dns lookup */
903 hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
904
905 if (getaddrinfo(conf->host, NULL, &hints, &res))
906 {
907 conf_dns_lookup(conf);
908 return;
909 }
910
911 assert(res);
912
913 memcpy(&conf->addr, res->ai_addr, res->ai_addrlen);
914 conf->addr.ss_len = res->ai_addrlen;
915 conf->addr.ss.ss_family = res->ai_family;
916
917 freeaddrinfo(res);
918 }
919
920 /* conf_connect_allowed()
921 *
922 * inputs - pointer to inaddr
923 * - int type ipv4 or ipv6
924 * output - BANNED or accepted
925 * side effects - none
926 */
927 int
928 conf_connect_allowed(struct irc_ssaddr *addr, int aftype)
929 {
930 struct ip_entry *ip_found = NULL;
931 const struct MaskItem *conf = find_dline_conf(addr, aftype);
932
933 if (conf)
934 {
935 /* DLINE exempt also gets you out of static limits/pacing... */
936 if (conf->type == CONF_EXEMPT)
937 return 0;
938 return BANNED_CLIENT;
939 }
940
941 ip_found = ipcache_find_or_add_address(addr);
942
943 if ((CurrentTime - ip_found->last_attempt) < ConfigGeneral.throttle_time)
944 {
945 if (ip_found->connection_count >= ConfigGeneral.throttle_count)
946 return TOO_FAST;
947
948 ++ip_found->connection_count;
949 }
950 else
951 ip_found->connection_count = 1;
952
953 ip_found->last_attempt = CurrentTime;
954 return 0;
955 }
956
957 /* expire_tklines()
958 *
959 * inputs - tkline list pointer
960 * output - NONE
961 * side effects - expire tklines
962 */
963 static void
964 expire_tklines(dlink_list *list)
965 {
966 dlink_node *node = NULL, *node_next = NULL;
967
968 DLINK_FOREACH_SAFE(node, node_next, list->head)
969 {
970 struct MaskItem *conf = node->data;
971
972 if (!conf->until || conf->until > CurrentTime)
973 continue;
974
975 if (ConfigGeneral.tkline_expire_notices)
976 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "Temporary %s for [%s] expired",
977 (conf->type == CONF_XLINE) ? "X-line" : "RESV", conf->name);
978 conf_free(conf);
979 }
980 }
981
982 /* cleanup_tklines()
983 *
984 * inputs - NONE
985 * output - NONE
986 * side effects - call function to expire temporary k/d lines
987 * This is an event started off in ircd.c
988 */
989 void
990 cleanup_tklines(void *unused)
991 {
992 hostmask_expire_temporary();
993 expire_tklines(&gecos_items);
994 expire_tklines(&nresv_items);
995 expire_tklines(&cresv_items);
996 }
997
998 /* oper_privs_as_string()
999 *
1000 * inputs - pointer to client_p
1001 * output - pointer to static string showing oper privs
1002 * side effects - return as string, the oper privs as derived from port
1003 */
1004 static const struct oper_flags
1005 {
1006 const unsigned int flag;
1007 const unsigned char c;
1008 } flag_table[] = {
1009 { OPER_FLAG_ADMIN, 'A' },
1010 { OPER_FLAG_CLOSE, 'B' },
1011 { OPER_FLAG_CONNECT, 'C' },
1012 { OPER_FLAG_CONNECT_REMOTE, 'D' },
1013 { OPER_FLAG_DIE, 'E' },
1014 { OPER_FLAG_DLINE, 'F' },
1015 { OPER_FLAG_GLOBOPS, 'G' },
1016 { OPER_FLAG_JOIN_RESV, 'H' },
1017 { OPER_FLAG_KILL, 'I' },
1018 { OPER_FLAG_KILL_REMOTE, 'J' },
1019 { OPER_FLAG_KLINE, 'K' },
1020 { OPER_FLAG_LOCOPS, 'L' },
1021 { OPER_FLAG_MODULE, 'M' },
1022 { OPER_FLAG_NICK_RESV, 'N' },
1023 { OPER_FLAG_OPME, 'O' },
1024 { OPER_FLAG_REHASH, 'P' },
1025 { OPER_FLAG_REMOTEBAN, 'Q' },
1026 { OPER_FLAG_RESTART, 'R' },
1027 { OPER_FLAG_RESV, 'S' },
1028 { OPER_FLAG_SET, 'T' },
1029 { OPER_FLAG_SQUIT, 'U' },
1030 { OPER_FLAG_SQUIT_REMOTE, 'V' },
1031 { OPER_FLAG_UNDLINE, 'W' },
1032 { OPER_FLAG_UNKLINE, 'X' },
1033 { OPER_FLAG_UNRESV, 'Y' },
1034 { OPER_FLAG_UNXLINE, 'Z' },
1035 { OPER_FLAG_WALLOPS, 'a' },
1036 { OPER_FLAG_XLINE, 'b' },
1037 { 0, '\0' }
1038 };
1039
1040 const char *
1041 oper_privs_as_string(const unsigned int flags)
1042 {
1043 static char buf[sizeof(flag_table) / sizeof(struct oper_flags)];
1044 char *p = buf;
1045
1046 for (const struct oper_flags *tab = flag_table; tab->flag; ++tab)
1047 if (flags & tab->flag)
1048 *p++ = tab->c;
1049
1050 if (p == buf)
1051 *p++ = '0';
1052
1053 *p = '\0';
1054
1055 return buf;
1056 }
1057
1058 /*
1059 * Input: A client to find the active operator {} name for.
1060 * Output: The nick!user@host{oper} of the oper.
1061 * "oper" is server name for remote opers
1062 * Side effects: None.
1063 */
1064 const char *
1065 get_oper_name(const struct Client *client_p)
1066 {
1067 static char buffer[IRCD_BUFSIZE];
1068
1069 if (IsServer(client_p))
1070 return client_p->name;
1071
1072 if (MyConnect(client_p))
1073 {
1074 const dlink_node *const node = client_p->connection->confs.head;
1075
1076 if (node)
1077 {
1078 const struct MaskItem *const conf = node->data;
1079
1080 if (conf->type == CONF_OPER)
1081 {
1082 snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1083 client_p->username, client_p->host, conf->name);
1084 return buffer;
1085 }
1086 }
1087
1088 /*
1089 * Probably should assert here for now. If there is an oper out there
1090 * with no operator {} conf attached, it would be good for us to know...
1091 */
1092 assert(0); /* Oper without oper conf! */
1093 }
1094
1095 snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1096 client_p->username, client_p->host, client_p->servptr->name);
1097 return buffer;
1098 }
1099
1100 /* clear_out_old_conf()
1101 *
1102 * inputs - none
1103 * output - none
1104 * side effects - Clear out the old configuration
1105 */
1106 static void
1107 clear_out_old_conf(void)
1108 {
1109 dlink_node *node = NULL, *node_next = NULL;
1110 dlink_list *free_items [] = {
1111 &server_items, &operator_items,
1112 &gecos_items,
1113 &nresv_items, &cresv_items, NULL
1114 };
1115
1116 dlink_list ** iterator = free_items; /* C is dumb */
1117
1118 /* We only need to free anything allocated by yyparse() here.
1119 * Resetting structs, etc, is taken care of by set_default_conf().
1120 */
1121
1122 for (; *iterator; iterator++)
1123 {
1124 DLINK_FOREACH_SAFE(node, node_next, (*iterator)->head)
1125 {
1126 struct MaskItem *conf = node->data;
1127
1128 conf->active = 0;
1129
1130 if (!IsConfDatabase(conf))
1131 {
1132 dlinkDelete(&conf->node, *iterator);
1133
1134 if (!conf->ref_count)
1135 conf_free(conf);
1136 }
1137 }
1138 }
1139
1140 motd_clear(); /* Clear motd {} items and re-cache default motd */
1141
1142 /*
1143 * Don't delete the class table, rather mark all entries for deletion.
1144 * The table is cleaned up by class_delete_marked. - avalon
1145 */
1146 class_mark_for_deletion();
1147
1148 clear_out_address_conf();
1149
1150 modules_conf_clear(); /* Clear modules {} items */
1151
1152 motd_clear(); /* Clear motd {} items and re-cache default motd */
1153
1154 cluster_clear(); /* Clear cluster {} items */
1155
1156 service_clear(); /* Clear service {} items */
1157
1158 shared_clear(); /* Clear shared {} items */
1159
1160 pseudo_clear(); /* Clear pseudo {} items */
1161
1162 #ifdef HAVE_LIBGEOIP
1163 GeoIP_delete(GeoIPv4_ctx);
1164 GeoIPv4_ctx = NULL;
1165 GeoIP_delete(GeoIPv6_ctx);
1166 GeoIPv6_ctx = NULL;
1167 #endif
1168
1169 /* Clean out ConfigServerInfo */
1170 xfree(ConfigServerInfo.description);
1171 ConfigServerInfo.description = NULL;
1172 xfree(ConfigServerInfo.network_name);
1173 ConfigServerInfo.network_name = NULL;
1174 xfree(ConfigServerInfo.network_desc);
1175 ConfigServerInfo.network_desc = NULL;
1176 xfree(ConfigServerInfo.libgeoip_ipv6_database_file);
1177 ConfigServerInfo.libgeoip_ipv6_database_file = NULL;
1178 xfree(ConfigServerInfo.libgeoip_ipv4_database_file);
1179 ConfigServerInfo.libgeoip_ipv4_database_file = NULL;
1180 xfree(ConfigServerInfo.rsa_private_key_file);
1181 ConfigServerInfo.rsa_private_key_file = NULL;
1182 xfree(ConfigServerInfo.ssl_certificate_file);
1183 ConfigServerInfo.ssl_certificate_file = NULL;
1184 xfree(ConfigServerInfo.ssl_dh_param_file);
1185 ConfigServerInfo.ssl_dh_param_file = NULL;
1186 xfree(ConfigServerInfo.ssl_dh_elliptic_curve);
1187 ConfigServerInfo.ssl_dh_elliptic_curve = NULL;
1188 xfree(ConfigServerInfo.ssl_cipher_list);
1189 ConfigServerInfo.ssl_cipher_list = NULL;
1190 xfree(ConfigServerInfo.ssl_message_digest_algorithm);
1191 ConfigServerInfo.ssl_message_digest_algorithm = NULL;
1192
1193 /* Clean out ConfigAdminInfo */
1194 xfree(ConfigAdminInfo.name);
1195 ConfigAdminInfo.name = NULL;
1196 xfree(ConfigAdminInfo.email);
1197 ConfigAdminInfo.email = NULL;
1198 xfree(ConfigAdminInfo.description);
1199 ConfigAdminInfo.description = NULL;
1200
1201 xfree(ConfigServerHide.flatten_links_file);
1202 ConfigServerHide.flatten_links_file = NULL;
1203
1204 /* Clean out listeners */
1205 listener_close_marked();
1206 }
1207
1208 static void
1209 conf_handle_tls(int cold)
1210 {
1211 if (!tls_new_cred())
1212 {
1213 if (cold)
1214 {
1215 ilog(LOG_TYPE_IRCD, "Error while initializing TLS");
1216 exit(EXIT_FAILURE);
1217 }
1218 else
1219 {
1220 /* Failed to load new settings/certs, old ones remain active */
1221 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
1222 "Error reloading TLS settings, check the ircd log"); // report_crypto_errors logs this
1223 }
1224 }
1225 }
1226
1227 /* read_conf_files()
1228 *
1229 * inputs - cold start YES or NO
1230 * output - none
1231 * side effects - read all conf files needed, ircd.conf kline.conf etc.
1232 */
1233 void
1234 read_conf_files(int cold)
1235 {
1236 const char *filename = NULL;
1237 char chanmodes[IRCD_BUFSIZE] = "";
1238 char chanlimit[IRCD_BUFSIZE] = "";
1239
1240 conf_parser_ctx.boot = cold;
1241 filename = ConfigGeneral.configfile;
1242
1243 /* We need to know the initial filename for the yyerror() to report
1244 FIXME: The full path is in conffilenamebuf first time since we
1245 don't know anything else
1246
1247 - Gozem 2002-07-21
1248 */
1249 strlcpy(conffilebuf, filename, sizeof(conffilebuf));
1250
1251 if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL)
1252 {
1253 if (cold)
1254 {
1255 ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
1256 filename, strerror(errno));
1257 exit(EXIT_FAILURE);
1258 }
1259 else
1260 {
1261 sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1262 "Unable to read configuration file '%s': %s",
1263 filename, strerror(errno));
1264 return;
1265 }
1266 }
1267
1268 if (!cold)
1269 clear_out_old_conf();
1270
1271 read_conf(conf_parser_ctx.conf_file);
1272 fclose(conf_parser_ctx.conf_file);
1273
1274 log_reopen_all();
1275 conf_handle_tls(cold);
1276
1277 isupport_add("NICKLEN", NULL, ConfigServerInfo.max_nick_length);
1278 isupport_add("NETWORK", ConfigServerInfo.network_name, -1);
1279
1280 snprintf(chanmodes, sizeof(chanmodes), "beI:%u", ConfigChannel.max_bans);
1281 isupport_add("MAXLIST", chanmodes, -1);
1282 isupport_add("MAXTARGETS", NULL, ConfigGeneral.max_targets);
1283 isupport_add("CHANTYPES", "#", -1);
1284
1285 snprintf(chanlimit, sizeof(chanlimit), "#:%u",
1286 ConfigChannel.max_channels);
1287 isupport_add("CHANLIMIT", chanlimit, -1);
1288 snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,cimnprstCMORST");
1289 isupport_add("CHANNELLEN", NULL, CHANNELLEN);
1290 isupport_add("TOPICLEN", NULL, ConfigServerInfo.max_topic_length);
1291 isupport_add("CHANMODES", chanmodes, -1);
1292
1293 /*
1294 * message_locale may have changed. rebuild isupport since it relies
1295 * on strlen(form_str(RPL_ISUPPORT))
1296 */
1297 isupport_rebuild();
1298 }
1299
1300 /* conf_add_class_to_conf()
1301 *
1302 * inputs - pointer to config item
1303 * output - NONE
1304 * side effects - Add a class pointer to a conf
1305 */
1306 void
1307 conf_add_class_to_conf(struct MaskItem *conf, const char *name)
1308 {
1309 if (EmptyString(name) || (conf->class = class_find(name, 1)) == NULL)
1310 {
1311 conf->class = class_default;
1312
1313 if (conf->type == CONF_CLIENT || conf->type == CONF_OPER)
1314 sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1315 "Warning *** Defaulting to default class for %s@%s",
1316 conf->user, conf->host);
1317 else
1318 sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1319 "Warning *** Defaulting to default class for %s",
1320 conf->name);
1321 }
1322 }
1323
1324 /* yyerror()
1325 *
1326 * inputs - message from parser
1327 * output - NONE
1328 * side effects - message to opers and log file entry is made
1329 */
1330 void
1331 yyerror(const char *msg)
1332 {
1333 char newlinebuf[IRCD_BUFSIZE];
1334
1335 if (conf_parser_ctx.pass != 1)
1336 return;
1337
1338 strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1339 sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1340 "\"%s\", line %u: %s: %s",
1341 conffilebuf, lineno + 1, msg, newlinebuf);
1342 ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1343 conffilebuf, lineno + 1, msg, newlinebuf);
1344 }
1345
1346 void
1347 conf_error_report(const char *msg)
1348 {
1349 char newlinebuf[IRCD_BUFSIZE];
1350
1351 strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1352 sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1353 "\"%s\", line %u: %s: %s",
1354 conffilebuf, lineno + 1, msg, newlinebuf);
1355 ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1356 conffilebuf, lineno + 1, msg, newlinebuf);
1357 }
1358
1359 /*
1360 * valid_tkline()
1361 *
1362 * inputs - pointer to ascii string to check
1363 * - whether the specified time is in seconds or minutes
1364 * output - -1 not enough parameters
1365 * - 0 if not an integer number, else the number
1366 * side effects - none
1367 * Originally written by Dianora (Diane, db@db.net)
1368 */
1369 time_t
1370 valid_tkline(const char *data, const int minutes)
1371 {
1372 const unsigned char *p = (const unsigned char *)data;
1373 unsigned char tmpch = '\0';
1374 time_t result = 0;
1375
1376 while ((tmpch = *p++))
1377 {
1378 if (!IsDigit(tmpch))
1379 return 0;
1380
1381 result *= 10;
1382 result += (tmpch & 0xF);
1383 }
1384
1385 /*
1386 * In the degenerate case where oper does a /quote kline 0 user@host :reason
1387 * i.e. they specifically use 0, I am going to return 1 instead as a return
1388 * value of non-zero is used to flag it as a temporary kline
1389 */
1390 if (result == 0)
1391 result = 1;
1392
1393 /*
1394 * If the incoming time is in seconds convert it to minutes for the purpose
1395 * of this calculation
1396 */
1397 if (!minutes)
1398 result = result / 60;
1399
1400 if (result > MAX_TDKLINE_TIME)
1401 result = MAX_TDKLINE_TIME;
1402
1403 result = result * 60; /* Turn it into seconds */
1404
1405 return result;
1406 }
1407
1408 /* valid_wild_card_simple()
1409 *
1410 * inputs - data to check for sufficient non-wildcard characters
1411 * outputs - 1 if valid, else 0
1412 * side effects - none
1413 */
1414 int
1415 valid_wild_card_simple(const char *data)
1416 {
1417 const unsigned char *p = (const unsigned char *)data;
1418 unsigned char tmpch = '\0';
1419 unsigned int nonwild = 0, wild = 0;
1420
1421 while ((tmpch = *p++))
1422 {
1423 if (tmpch == '\\' && *p)
1424 {
1425 ++p;
1426 if (++nonwild >= ConfigGeneral.min_nonwildcard_simple)
1427 return 1;
1428 }
1429 else if (!IsMWildChar(tmpch))
1430 {
1431 if (++nonwild >= ConfigGeneral.min_nonwildcard_simple)
1432 return 1;
1433 }
1434 else
1435 ++wild;
1436 }
1437
1438 return !wild;
1439 }
1440
1441 /* valid_wild_card()
1442 *
1443 * input - pointer to client
1444 * - int flag, 0 for no warning oper 1 for warning oper
1445 * - count of following varargs to check
1446 * output - 0 if not valid, 1 if valid
1447 * side effects - NOTICE is given to source_p if warn is 1
1448 */
1449 int
1450 valid_wild_card(struct Client *source_p, int count, ...)
1451 {
1452 unsigned char tmpch = '\0';
1453 unsigned int nonwild = 0;
1454 va_list args;
1455
1456 /*
1457 * Now we must check the user and host to make sure there
1458 * are at least NONWILDCHARS non-wildcard characters in
1459 * them, otherwise assume they are attempting to kline
1460 * *@* or some variant of that. This code will also catch
1461 * people attempting to kline *@*.tld, as long as NONWILDCHARS
1462 * is greater than 3. In that case, there are only 3 non-wild
1463 * characters (tld), so if NONWILDCHARS is 4, the kline will
1464 * be disallowed.
1465 * -wnder
1466 */
1467
1468 va_start(args, count);
1469
1470 while (count--)
1471 {
1472 const unsigned char *p = va_arg(args, const unsigned char *);
1473 if (p == NULL)
1474 continue;
1475
1476 while ((tmpch = *p++))
1477 {
1478 if (!IsKWildChar(tmpch))
1479 {
1480 /*
1481 * If we find enough non-wild characters, we can
1482 * break - no point in searching further.
1483 */
1484 if (++nonwild >= ConfigGeneral.min_nonwildcard)
1485 {
1486 va_end(args);
1487 return 1;
1488 }
1489 }
1490 }
1491 }
1492
1493 if (IsClient(source_p))
1494 sendto_one_notice(source_p, &me,
1495 ":Please include at least %u non-wildcard characters with the mask",
1496 ConfigGeneral.min_nonwildcard);
1497 va_end(args);
1498 return 0;
1499 }
1500
1501 /* find_user_host()
1502 *
1503 * inputs - pointer to client placing kline
1504 * - pointer to user_host_or_nick
1505 * - pointer to user buffer
1506 * - pointer to host buffer
1507 * output - 0 if not ok to kline, 1 to kline i.e. if valid user host
1508 * side effects -
1509 */
1510 static int
1511 find_user_host(struct Client *source_p, char *user_host_or_nick,
1512 char *luser, char *lhost)
1513 {
1514 struct Client *target_p = NULL;
1515 char *hostp = NULL;
1516
1517 if (lhost == NULL)
1518 {
1519 strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
1520 return 1;
1521 }
1522
1523 if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
1524 {
1525 /* Explicit user@host mask given */
1526 if (hostp) /* I'm a little user@host */
1527 {
1528 *(hostp++) = '\0'; /* short and squat */
1529
1530 if (*user_host_or_nick)
1531 strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
1532 else
1533 strcpy(luser, "*");
1534
1535 if (*hostp)
1536 strlcpy(lhost, hostp, HOSTLEN + 1); /* here is my host */
1537 else
1538 strcpy(lhost, "*");
1539 }
1540 else
1541 {
1542 luser[0] = '*'; /* no @ found, assume its *@somehost */
1543 luser[1] = '\0';
1544 strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
1545 }
1546
1547 return 1;
1548 }
1549 else
1550 {
1551 /* Try to find user@host mask from nick */
1552 /* Okay to use source_p as the first param, because source_p == client_p */
1553 if ((target_p =
1554 find_chasing(source_p, user_host_or_nick)) == NULL)
1555 return 0; /* find_chasing sends ERR_NOSUCHNICK */
1556
1557 if (HasFlag(target_p, FLAGS_EXEMPTKLINE))
1558 {
1559 if (IsClient(source_p))
1560 sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
1561 return 0;
1562 }
1563
1564 /*
1565 * Turn the "user" bit into "*user", blow away '~'
1566 * if found in original user name (non-idented)
1567 */
1568 strlcpy(luser, target_p->username, USERLEN*4 + 1);
1569
1570 if (target_p->username[0] == '~')
1571 luser[0] = '*';
1572
1573 strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
1574 return 1;
1575 }
1576
1577 return 0;
1578 }
1579
1580 /* XXX should this go into a separate file ? -Dianora */
1581 /* parse_aline
1582 *
1583 * input - pointer to cmd name being used
1584 * - pointer to client using cmd
1585 * - parc parameter count
1586 * - parv[] list of parameters to parse
1587 * - parse_flags bit map of things to test
1588 * - pointer to user or string to parse into
1589 * - pointer to host or NULL to parse into if non NULL
1590 * - pointer to optional tkline time or NULL
1591 * - pointer to target_server to parse into if non NULL
1592 * - pointer to reason to parse into
1593 *
1594 * output - 1 if valid, 0 if not valid
1595 * side effects - A generalised k/d/x etc. line parser,
1596 * "ALINE [time] user@host|string [ON] target :reason"
1597 * will parse returning a parsed user, host if
1598 * h_p pointer is non NULL, string otherwise.
1599 * if tkline_time pointer is non NULL a tk line will be set
1600 * to non zero if found.
1601 * if tkline_time pointer is NULL and tk line is found,
1602 * error is reported.
1603 * if target_server is NULL and an "ON" is found error
1604 * is reported.
1605 * if reason pointer is NULL ignore pointer,
1606 * this allows use of parse_a_line in unkline etc.
1607 *
1608 * - Dianora
1609 */
1610 int
1611 parse_aline(const char *cmd, struct Client *source_p,
1612 int parc, char **parv,
1613 int parse_flags, char **up_p, char **h_p, time_t *tkline_time,
1614 char **target_server, char **reason)
1615 {
1616 int found_tkline_time=0;
1617 static char default_reason[] = CONF_NOREASON;
1618 static char user[USERLEN*4+1];
1619 static char host[HOSTLEN*4+1];
1620
1621 parv++;
1622 parc--;
1623
1624 found_tkline_time = valid_tkline(*parv, TK_MINUTES);
1625
1626 if (found_tkline_time)
1627 {
1628 parv++;
1629 parc--;
1630
1631 if (tkline_time)
1632 *tkline_time = found_tkline_time;
1633 else
1634 {
1635 sendto_one_notice(source_p, &me, ":temp_line not supported by %s", cmd);
1636 return 0;
1637 }
1638 }
1639
1640 if (parc == 0)
1641 {
1642 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1643 return 0;
1644 }
1645
1646 if (h_p == NULL)
1647 *up_p = *parv;
1648 else
1649 {
1650 if (find_user_host(source_p, *parv, user, host) == 0)
1651 return 0;
1652
1653 *up_p = user;
1654 *h_p = host;
1655 }
1656
1657 parc--;
1658 parv++;
1659
1660 if (parc)
1661 {
1662 if (irccmp(*parv, "ON") == 0)
1663 {
1664 parc--;
1665 parv++;
1666
1667 if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN))
1668 {
1669 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "remoteban");
1670 return 0;
1671 }
1672
1673 if (parc == 0 || EmptyString(*parv))
1674 {
1675 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1676 return 0;
1677 }
1678
1679 *target_server = *parv;
1680 parc--;
1681 parv++;
1682 }
1683 else
1684 {
1685 /* Make sure target_server *is* NULL if no ON server found
1686 * caller probably NULL'd it first, but no harm to do it again -db
1687 */
1688 if (target_server)
1689 *target_server = NULL;
1690 }
1691 }
1692
1693 if (h_p)
1694 {
1695 if (strchr(user, '!'))
1696 {
1697 sendto_one_notice(source_p, &me, ":Invalid character '!' in kline");
1698 return 0;
1699 }
1700
1701 if ((parse_flags & AWILD) && !valid_wild_card(source_p, 2, *up_p, *h_p))
1702 return 0;
1703 }
1704 else
1705 if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, *up_p))
1706 return 0;
1707
1708 if (reason)
1709 {
1710 if (parc && !EmptyString(*parv))
1711 *reason = *parv;
1712 else
1713 *reason = default_reason;
1714 }
1715
1716 return 1;
1717 }
1718
1719 /* match_conf_password()
1720 *
1721 * inputs - pointer to given password
1722 * - pointer to Conf
1723 * output - 1 or 0 if match
1724 * side effects - none
1725 */
1726 int
1727 match_conf_password(const char *password, const struct MaskItem *conf)
1728 {
1729 const char *encr = NULL;
1730
1731 if (EmptyString(password) || EmptyString(conf->passwd))
1732 return 0;
1733
1734 if (conf->flags & CONF_FLAGS_ENCRYPTED)
1735 encr = crypt(password, conf->passwd);
1736 else
1737 encr = password;
1738
1739 return encr && !strcmp(encr, conf->passwd);
1740 }
1741
1742 /*
1743 * split_nuh
1744 *
1745 * inputs - pointer to original mask (modified in place)
1746 * - pointer to pointer where nick should go
1747 * - pointer to pointer where user should go
1748 * - pointer to pointer where host should go
1749 * output - NONE
1750 * side effects - mask is modified in place
1751 * If nick pointer is NULL, ignore writing to it
1752 * this allows us to use this function elsewhere.
1753 *
1754 * mask nick user host
1755 * ---------------------- ------- ------- ------
1756 * Dianora!db@db.net Dianora db db.net
1757 * Dianora Dianora * *
1758 * db.net * * db.net
1759 * OR if nick pointer is NULL
1760 * Dianora - * Dianora
1761 * Dianora! Dianora * *
1762 * Dianora!@ Dianora * *
1763 * Dianora!db Dianora db *
1764 * Dianora!@db.net Dianora * db.net
1765 * db@db.net * db db.net
1766 * !@ * * *
1767 * @ * * *
1768 * ! * * *
1769 */
1770 void
1771 split_nuh(struct split_nuh_item *const iptr)
1772 {
1773 char *p = NULL, *q = NULL;
1774
1775 if (iptr->nickptr)
1776 strlcpy(iptr->nickptr, "*", iptr->nicksize);
1777
1778 if (iptr->userptr)
1779 strlcpy(iptr->userptr, "*", iptr->usersize);
1780
1781 if (iptr->hostptr)
1782 strlcpy(iptr->hostptr, "*", iptr->hostsize);
1783
1784 if ((p = strchr(iptr->nuhmask, '!')))
1785 {
1786 *p = '\0';
1787
1788 if (iptr->nickptr && *iptr->nuhmask)
1789 strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
1790
1791 if ((q = strchr(++p, '@')))
1792 {
1793 *q++ = '\0';
1794
1795 if (*p)
1796 strlcpy(iptr->userptr, p, iptr->usersize);
1797
1798 if (*q)
1799 strlcpy(iptr->hostptr, q, iptr->hostsize);
1800 }
1801 else
1802 {
1803 if (*p)
1804 strlcpy(iptr->userptr, p, iptr->usersize);
1805 }
1806 }
1807 else
1808 {
1809 /* No ! found so lets look for a user@host */
1810 if ((p = strchr(iptr->nuhmask, '@')))
1811 {
1812 /* if found a @ */
1813 *p++ = '\0';
1814
1815 if (*iptr->nuhmask)
1816 strlcpy(iptr->userptr, iptr->nuhmask, iptr->usersize);
1817
1818 if (*p)
1819 strlcpy(iptr->hostptr, p, iptr->hostsize);
1820 }
1821 else
1822 {
1823 /* No @ found */
1824 if (!iptr->nickptr || strpbrk(iptr->nuhmask, ".:"))
1825 strlcpy(iptr->hostptr, iptr->nuhmask, iptr->hostsize);
1826 else
1827 strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
1828 }
1829 }
1830 }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision