ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 5583
Committed: Sun Feb 15 14:43:15 2015 UTC (10 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 51384 byte(s)
Log Message:
- Style corrections only

File Contents

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

Properties

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