ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 5847
Committed: Sun Apr 26 19:02:58 2015 UTC (8 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 50208 byte(s)
Log Message:
- conf.c:clear_out_old_conf(): also don't remove database based XLINE and RESVs from their
  associated linked list(s)

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

Properties

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