ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 7209
Committed: Wed Feb 3 15:10:39 2016 UTC (9 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 48593 byte(s)
Log Message:
- Clustering has been broken in -r7159. Rewrote most of the shared/cluster implementation to be less obscure.
  This introduces a little bit of code duplication, but increases readability, is less error prone, and
  reduces memory consumption a bit.

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

Properties

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