ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
(Generate patch)

Comparing:
ircd-hybrid-7.2/src/s_conf.c (file contents), Revision 201 by adx, Tue Nov 1 11:41:52 2005 UTC vs.
ircd-hybrid-8/src/conf.c (file contents), Revision 1547 by michael, Sun Sep 30 17:50:03 2012 UTC

# Line 1 | Line 1
1   /*
2   *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  s_conf.c: Configuration file functions.
3 > *  conf.c: Configuration file functions.
4   *
5   *  Copyright (C) 2002 by the past and present ircd coders, and others.
6   *
# Line 23 | Line 23
23   */
24  
25   #include "stdinc.h"
26 + #include "list.h"
27   #include "ircd_defs.h"
28 < #include "tools.h"
29 < #include "s_conf.h"
28 > #include "balloc.h"
29 > #include "conf.h"
30   #include "s_serv.h"
31   #include "resv.h"
31 #include "s_stats.h"
32   #include "channel.h"
33   #include "client.h"
34 #include "common.h"
34   #include "event.h"
36 #include "hash.h"
35   #include "hook.h"
36   #include "irc_string.h"
39 #include "sprintf_irc.h"
37   #include "s_bsd.h"
41 #include "irc_getnameinfo.h"
42 #include "irc_getaddrinfo.h"
38   #include "ircd.h"
44 #include "list.h"
39   #include "listener.h"
40   #include "hostmask.h"
41   #include "modules.h"
42   #include "numeric.h"
43   #include "fdlist.h"
44 < #include "s_log.h"
44 > #include "log.h"
45   #include "send.h"
46   #include "s_gline.h"
53 #include "fileio.h"
47   #include "memory.h"
48   #include "irc_res.h"
49   #include "userhost.h"
50   #include "s_user.h"
51   #include "channel_mode.h"
52 + #include "parse.h"
53 + #include "s_misc.h"
54  
55   struct Callback *client_check_cb = NULL;
56   struct config_server_hide ConfigServerHide;
57  
58   /* general conf items link list root, other than k lines etc. */
59 + dlink_list service_items = { NULL, NULL, 0 };
60   dlink_list server_items  = { NULL, NULL, 0 };
61   dlink_list cluster_items = { NULL, NULL, 0 };
66 dlink_list hub_items     = { NULL, NULL, 0 };
67 dlink_list leaf_items    = { NULL, NULL, 0 };
62   dlink_list oconf_items   = { NULL, NULL, 0 };
63   dlink_list uconf_items   = { NULL, NULL, 0 };
64   dlink_list xconf_items   = { NULL, NULL, 0 };
# Line 72 | Line 66 | dlink_list rxconf_items  = { NULL, NULL,
66   dlink_list rkconf_items  = { NULL, NULL, 0 };
67   dlink_list nresv_items   = { NULL, NULL, 0 };
68   dlink_list class_items   = { NULL, NULL, 0 };
75 dlink_list gdeny_items   = { NULL, NULL, 0 };
69  
77 dlink_list temporary_klines  = { NULL, NULL, 0 };
78 dlink_list temporary_dlines  = { NULL, NULL, 0 };
70   dlink_list temporary_xlines  = { NULL, NULL, 0 };
80 dlink_list temporary_rklines = { NULL, NULL, 0 };
81 dlink_list temporary_glines  = { NULL, NULL, 0 };
82 dlink_list temporary_rxlines = { NULL, NULL, 0 };
71   dlink_list temporary_resv = { NULL, NULL, 0 };
72  
73   extern unsigned int lineno;
74   extern char linebuf[];
75   extern char conffilebuf[IRCD_BUFSIZE];
88 extern char yytext[];
76   extern int yyparse(); /* defined in y.tab.c */
77 < unsigned int scount = 0; /* used by yyparse(), etc */
78 < int ypass  = 1; /* used by yyparse()      */
77 >
78 > struct conf_parser_context conf_parser_ctx = { 0, 0, NULL };
79  
80   /* internally defined functions */
81 < static void lookup_confhost(struct ConfItem *);
95 < static void set_default_conf(void);
96 < static void validate_conf(void);
97 < static void read_conf(FBFILE *);
81 > static void read_conf(FILE *);
82   static void clear_out_old_conf(void);
83   static void flush_deleted_I_P(void);
84   static void expire_tklines(dlink_list *);
# Line 117 | Line 101 | static void destroy_cidr_class(struct Cl
101  
102   static void flags_to_ascii(unsigned int, const unsigned int[], char *, int);
103  
120 FBFILE *conf_fbfile_in = NULL;
121
104   /* address of default class conf */
105   static struct ConfItem *class_default;
106  
# Line 141 | Line 123 | static BlockHeap *ip_entry_heap = NULL;
123   static int ip_entries_count = 0;
124  
125  
126 < inline void *
126 > void *
127   map_to_conf(struct ConfItem *aconf)
128   {
129    void *conf;
130 <  conf = (void *)((unsigned long)aconf +
131 <                  (unsigned long)sizeof(struct ConfItem));
130 >  conf = (void *)((uintptr_t)aconf +
131 >                  (uintptr_t)sizeof(struct ConfItem));
132    return(conf);
133   }
134  
135 < inline struct ConfItem *
135 > struct ConfItem *
136   unmap_conf_item(void *aconf)
137   {
138    struct ConfItem *conf;
139  
140 <  conf = (struct ConfItem *)((unsigned long)aconf -
141 <                             (unsigned long)sizeof(struct ConfItem));
140 >  conf = (struct ConfItem *)((uintptr_t)aconf -
141 >                             (uintptr_t)sizeof(struct ConfItem));
142    return(conf);
143   }
144  
# Line 171 | Line 153 | unmap_conf_item(void *aconf)
153   * if successful save hp in the conf item it was called with
154   */
155   static void
156 < conf_dns_callback(void *vptr, struct DNSReply *reply)
156 > conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name)
157   {
158 <  struct AccessItem *aconf = (struct AccessItem *)vptr;
177 <  struct ConfItem *conf;
158 >  struct AccessItem *aconf = vptr;
159  
160 <  MyFree(aconf->dns_query);
180 <  aconf->dns_query = NULL;
160 >  aconf->dns_pending = 0;
161  
162 <  if (reply != NULL)
163 <    memcpy(&aconf->ipnum, &reply->addr, sizeof(reply->addr));
164 <  else {
165 <    ilog(L_NOTICE, "Host not found: %s, ignoring connect{} block",
186 <         aconf->host);
187 <    conf = unmap_conf_item(aconf);
188 <    sendto_realops_flags(UMODE_ALL, L_ALL,
189 <                         "Ignoring connect{} block for %s - host not found",
190 <                         conf->name);
191 <    delete_conf_item(conf);
192 <  }
162 >  if (addr != NULL)
163 >    memcpy(&aconf->addr, addr, sizeof(aconf->addr));
164 >  else
165 >    aconf->dns_failed = 1;
166   }
167  
168   /* conf_dns_lookup()
# Line 201 | Line 174 | conf_dns_callback(void *vptr, struct DNS
174   static void
175   conf_dns_lookup(struct AccessItem *aconf)
176   {
177 <  if (aconf->dns_query == NULL)
177 >  if (!aconf->dns_pending)
178    {
179 <    aconf->dns_query = MyMalloc(sizeof(struct DNSQuery));
180 <    aconf->dns_query->ptr = aconf;
208 <    aconf->dns_query->callback = conf_dns_callback;
209 <    gethost_byname(aconf->host, aconf->dns_query);
179 >    aconf->dns_pending = 1;
180 >    gethost_byname(conf_dns_callback, aconf, aconf->host);
181    }
182   }
183  
# Line 277 | Line 248 | make_conf_item(ConfType type)
248      aconf->status = status;
249      break;
250  
280  case LEAF_TYPE:
281    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
282                                       sizeof(struct MatchItem));
283    dlinkAdd(conf, &conf->node, &leaf_items);
284    break;
285
286  case HUB_TYPE:
287    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
288                                       sizeof(struct MatchItem));
289    dlinkAdd(conf, &conf->node, &hub_items);
290    break;
291
251    case ULINE_TYPE:
252      conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
253                                         sizeof(struct MatchItem));
254      dlinkAdd(conf, &conf->node, &uconf_items);
255      break;
256  
298  case GDENY_TYPE:
299    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
300                                       sizeof(struct AccessItem));
301    dlinkAdd(conf, &conf->node, &gdeny_items);
302    break;
303
257    case XLINE_TYPE:
258      conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
259                                         sizeof(struct MatchItem));
260      dlinkAdd(conf, &conf->node, &xconf_items);
261      break;
262 <
262 > #ifdef HAVE_LIBPCRE
263    case RXLINE_TYPE:
264      conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
265                                         sizeof(struct MatchItem));
# Line 320 | Line 273 | make_conf_item(ConfType type)
273      aconf->status = CONF_KLINE;
274      dlinkAdd(conf, &conf->node, &rkconf_items);
275      break;
276 <
276 > #endif
277    case CLUSTER_TYPE:
278      conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem));
279      dlinkAdd(conf, &conf->node, &cluster_items);
# Line 337 | Line 290 | make_conf_item(ConfType type)
290      dlinkAdd(conf, &conf->node, &nresv_items);
291      break;
292  
293 +  case SERVICE_TYPE:
294 +    status = CONF_SERVICE;
295 +    conf = MyMalloc(sizeof(struct ConfItem));
296 +    dlinkAdd(conf, &conf->node, &service_items);
297 +    break;
298 +
299    case CLASS_TYPE:
300 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
301 <                                       sizeof(struct ClassItem));
300 >    conf = MyMalloc(sizeof(struct ConfItem) +
301 >                           sizeof(struct ClassItem));
302      dlinkAdd(conf, &conf->node, &class_items);
303 <    aclass = (struct ClassItem *)map_to_conf(conf);
304 <    ConFreq(aclass)  = DEFAULT_CONNECTFREQUENCY;
305 <    PingFreq(aclass) = DEFAULT_PINGFREQUENCY;
306 <    MaxTotal(aclass) = MAXIMUM_LINKS_DEFAULT;
307 <    MaxSendq(aclass) = DEFAULT_SENDQ;
308 <    CurrUserCount(aclass) = 0;
303 >
304 >    aclass = map_to_conf(conf);
305 >    aclass->active = 1;
306 >    aclass->con_freq = DEFAULT_CONNECTFREQUENCY;
307 >    aclass->ping_freq = DEFAULT_PINGFREQUENCY;
308 >    aclass->max_total = MAXIMUM_LINKS_DEFAULT;
309 >    aclass->max_sendq = DEFAULT_SENDQ;
310 >    aclass->max_recvq = DEFAULT_RECVQ;
311 >
312      break;
313  
314    default:
# Line 357 | Line 319 | make_conf_item(ConfType type)
319    /* XXX Yes, this will core if default is hit. I want it to for now - db */
320    conf->type = type;
321  
322 <  return(conf);
322 >  return conf;
323   }
324  
325   void
326   delete_conf_item(struct ConfItem *conf)
327   {
328 +  dlink_node *m = NULL, *m_next = NULL;
329    struct MatchItem *match_item;
330    struct AccessItem *aconf;
331    ConfType type = conf->type;
# Line 381 | Line 344 | delete_conf_item(struct ConfItem *conf)
344    case SERVER_TYPE:
345      aconf = map_to_conf(conf);
346  
347 <    if (aconf->dns_query != NULL)
348 <    {
386 <      delete_resolver_queries(aconf->dns_query);
387 <      MyFree(aconf->dns_query);
388 <    }
347 >    if (aconf->dns_pending)
348 >      delete_resolver_queries(aconf);
349      if (aconf->passwd != NULL)
350        memset(aconf->passwd, 0, strlen(aconf->passwd));
351      if (aconf->spasswd != NULL)
# Line 398 | Line 358 | delete_conf_item(struct ConfItem *conf)
358      MyFree(aconf->oper_reason);
359      MyFree(aconf->user);
360      MyFree(aconf->host);
401    MyFree(aconf->fakename);
361   #ifdef HAVE_LIBCRYPTO
362 +    MyFree(aconf->cipher_list);
363 +
364      if (aconf->rsa_public_key)
365        RSA_free(aconf->rsa_public_key);
366      MyFree(aconf->rsa_public_key_file);
# Line 425 | Line 386 | delete_conf_item(struct ConfItem *conf)
386  
387      case SERVER_TYPE:
388        aconf = map_to_conf(conf);
389 +
390 +      DLINK_FOREACH_SAFE(m, m_next, aconf->hub_list.head)
391 +      {
392 +        MyFree(m->data);
393 +        free_dlink_node(m);
394 +      }
395 +
396 +      DLINK_FOREACH_SAFE(m, m_next, aconf->leaf_list.head)
397 +      {
398 +        MyFree(m->data);
399 +        free_dlink_node(m);  
400 +      }
401 +
402        if (!IsConfIllegal(aconf))
403          dlinkDelete(&conf->node, &server_items);
404        MyFree(conf);
# Line 435 | Line 409 | delete_conf_item(struct ConfItem *conf)
409      }
410      break;
411  
438  case HUB_TYPE:
439    match_item = map_to_conf(conf);
440    MyFree(match_item->user);
441    MyFree(match_item->host);
442    MyFree(match_item->reason);
443    MyFree(match_item->oper_reason);
444    /* If marked illegal, its already been pulled off of the hub_items list */
445    if (!match_item->illegal)
446      dlinkDelete(&conf->node, &hub_items);
447    MyFree(conf);
448    break;
449
450  case LEAF_TYPE:
451    match_item = map_to_conf(conf);
452    MyFree(match_item->user);
453    MyFree(match_item->host);
454    MyFree(match_item->reason);
455    MyFree(match_item->oper_reason);
456    /* If marked illegal, its already been pulled off of the leaf_items list */
457    if (!match_item->illegal)
458      dlinkDelete(&conf->node, &leaf_items);
459    MyFree(conf);
460    break;
461
412    case ULINE_TYPE:
413      match_item = map_to_conf(conf);
414      MyFree(match_item->user);
# Line 478 | Line 428 | delete_conf_item(struct ConfItem *conf)
428      dlinkDelete(&conf->node, &xconf_items);
429      MyFree(conf);
430      break;
431 <
431 > #ifdef HAVE_LIBPCRE
432    case RKLINE_TYPE:
433      aconf = map_to_conf(conf);
434      MyFree(aconf->regexuser);
# Line 501 | Line 451 | delete_conf_item(struct ConfItem *conf)
451      dlinkDelete(&conf->node, &rxconf_items);
452      MyFree(conf);
453      break;
454 <
454 > #endif
455    case NRESV_TYPE:
456      match_item = map_to_conf(conf);
457      MyFree(match_item->user);
# Line 509 | Line 459 | delete_conf_item(struct ConfItem *conf)
459      MyFree(match_item->reason);
460      MyFree(match_item->oper_reason);
461      dlinkDelete(&conf->node, &nresv_items);
512    MyFree(conf);
513    break;
462  
463 <  case GDENY_TYPE:
464 <    aconf = map_to_conf(conf);
465 <    MyFree(aconf->user);
466 <    MyFree(aconf->host);
519 <    dlinkDelete(&conf->node, &gdeny_items);
463 >    if (conf->flags & CONF_FLAGS_TEMPORARY)
464 >      if ((m = dlinkFindDelete(&temporary_resv, conf)) != NULL)
465 >        free_dlink_node(m);
466 >
467      MyFree(conf);
468      break;
469  
# Line 526 | Line 473 | delete_conf_item(struct ConfItem *conf)
473      break;
474  
475    case CRESV_TYPE:
476 +    if (conf->flags & CONF_FLAGS_TEMPORARY)
477 +      if ((m = dlinkFindDelete(&temporary_resv, conf)) != NULL)
478 +        free_dlink_node(m);
479 +
480      MyFree(conf);
481      break;
482  
# Line 534 | Line 485 | delete_conf_item(struct ConfItem *conf)
485      MyFree(conf);
486      break;
487  
488 +  case SERVICE_TYPE:
489 +    dlinkDelete(&conf->node, &service_items);
490 +    MyFree(conf);
491 +    break;
492 +
493    default:
494      break;
495    }
# Line 567 | Line 523 | static const unsigned int shared_bit_tab
523   * side effects -
524   */
525   void
526 < report_confitem_types(struct Client *source_p, ConfType type, int temp)
526 > report_confitem_types(struct Client *source_p, ConfType type)
527   {
528 <  dlink_node *ptr = NULL;
528 >  dlink_node *ptr = NULL, *dptr = NULL;
529    struct ConfItem *conf = NULL;
530    struct AccessItem *aconf = NULL;
531    struct MatchItem *matchitem = NULL;
# Line 579 | Line 535 | report_confitem_types(struct Client *sou
535  
536    switch (type)
537    {
582  case GDENY_TYPE:
583    DLINK_FOREACH(ptr, gdeny_items.head)
584    {
585      conf = ptr->data;
586      aconf = map_to_conf(conf);
587
588      p = buf;
589
590      if (aconf->flags & GDENY_BLOCK)
591        *p++ = 'B';
592      else
593        *p++ = 'b';
594
595      if (aconf->flags & GDENY_REJECT)
596        *p++ = 'R';
597      else
598        *p++ = 'r';
599
600      *p = '\0';
601
602      sendto_one(source_p, ":%s %d %s V %s@%s %s %s",
603                 me.name, RPL_STATSDEBUG, source_p->name,
604                 aconf->user, aconf->host, conf->name, buf);
605    }
606    break;
607
538    case XLINE_TYPE:
539      DLINK_FOREACH(ptr, xconf_items.head)
540      {
# Line 618 | Line 548 | report_confitem_types(struct Client *sou
548      }
549      break;
550  
551 + #ifdef HAVE_LIBPCRE
552    case RXLINE_TYPE:
553      DLINK_FOREACH(ptr, rxconf_items.head)
554      {
# Line 626 | Line 557 | report_confitem_types(struct Client *sou
557  
558        sendto_one(source_p, form_str(RPL_STATSXLINE),
559                   me.name, source_p->name,
560 <                 matchitem->hold ? "xR": "XR", matchitem->count,
560 >                 "XR", matchitem->count,
561                   conf->name, matchitem->reason);
562      }
563      break;
564  
565    case RKLINE_TYPE:
635    p = temp ? "Rk" : "RK";
636
566      DLINK_FOREACH(ptr, rkconf_items.head)
567      {
568        aconf = map_to_conf((conf = ptr->data));
569  
641      if (temp && !(conf->flags & CONF_FLAGS_TEMPORARY))
642        continue;
643
570        sendto_one(source_p, form_str(RPL_STATSKLINE), me.name,
571 <                 source_p->name, p, aconf->host, aconf->user,
571 >                 source_p->name, "KR", aconf->host, aconf->user,
572                   aconf->reason, aconf->oper_reason ? aconf->oper_reason : "");
573      }
574      break;
575 + #endif
576  
577    case ULINE_TYPE:
578      DLINK_FOREACH(ptr, uconf_items.head)
# Line 690 | Line 617 | report_confitem_types(struct Client *sou
617        aconf = map_to_conf(conf);
618  
619        /* Don't allow non opers to see oper privs */
620 <      if (IsOper(source_p))
620 >      if (HasUMode(source_p, UMODE_OPER))
621          sendto_one(source_p, form_str(RPL_STATSOLINE),
622                     me.name, source_p->name, 'O', aconf->user, aconf->host,
623                     conf->name, oper_privs_as_string(aconf->port),
# Line 710 | Line 637 | report_confitem_types(struct Client *sou
637        classitem = map_to_conf(conf);
638        sendto_one(source_p, form_str(RPL_STATSYLINE),
639                   me.name, source_p->name, 'Y',
640 <                 conf->name, PingFreq(classitem),
641 <                 ConFreq(classitem),
642 <                 MaxTotal(classitem), MaxSendq(classitem));
640 >                 conf->name, classitem->ping_freq,
641 >                 classitem->con_freq,
642 >                 classitem->max_total, classitem->max_sendq,
643 >                 classitem->max_recvq,
644 >                 classitem->curr_user_count,
645 >                 classitem->number_per_cidr, classitem->cidr_bitlen_ipv4,
646 >                 classitem->number_per_cidr, classitem->cidr_bitlen_ipv6,
647 >                 classitem->active ? "active" : "disabled");
648      }
649      break;
650  
# Line 720 | Line 652 | report_confitem_types(struct Client *sou
652    case CLIENT_TYPE:
653      break;
654  
655 +  case SERVICE_TYPE:
656 +    DLINK_FOREACH(ptr, service_items.head)
657 +    {
658 +      conf = ptr->data;
659 +      sendto_one(source_p, form_str(RPL_STATSSERVICE),
660 +                 me.name, source_p->name, 'S', "*", conf->name, 0, 0);
661 +    }
662 +    break;
663 +
664    case SERVER_TYPE:
665      DLINK_FOREACH(ptr, server_items.head)
666      {
# Line 732 | Line 673 | report_confitem_types(struct Client *sou
673  
674        if (IsConfAllowAutoConn(aconf))
675          *p++ = 'A';
676 <      if (IsConfCryptLink(aconf))
677 <        *p++ = 'C';
737 <      if (IsConfLazyLink(aconf))
738 <        *p++ = 'L';
739 <      if (aconf->fakename)
740 <        *p++ = 'M';
741 <      if (IsConfTopicBurst(aconf))
742 <        *p++ = 'T';
743 <      if (IsConfCompressed(aconf))
744 <        *p++ = 'Z';
676 >      if (IsConfSSL(aconf))
677 >        *p++ = 'S';
678        if (buf[0] == '\0')
679          *p++ = '*';
680  
681        *p = '\0';
682  
683 <      /* Allow admins to see actual ips
684 <       * unless hide_server_ips is enabled
683 >      /*
684 >       * Allow admins to see actual ips unless hide_server_ips is enabled
685         */
686 <      if (!ConfigServerHide.hide_server_ips && IsAdmin(source_p))
686 >      if (!ConfigServerHide.hide_server_ips && HasUMode(source_p, UMODE_ADMIN))
687          sendto_one(source_p, form_str(RPL_STATSCLINE),
688                     me.name, source_p->name, 'C', aconf->host,
689                     buf, conf->name, aconf->port,
# Line 764 | Line 697 | report_confitem_types(struct Client *sou
697      break;
698  
699    case HUB_TYPE:
700 <    DLINK_FOREACH(ptr, hub_items.head)
700 >    DLINK_FOREACH(ptr, server_items.head)
701      {
702        conf = ptr->data;
703 <      matchitem = map_to_conf(conf);
704 <      sendto_one(source_p, form_str(RPL_STATSHLINE), me.name,
705 <                 source_p->name, 'H', matchitem->host, conf->name, 0, "*");
703 >      aconf = map_to_conf(conf);
704 >
705 >      DLINK_FOREACH(dptr, aconf->hub_list.head)
706 >        sendto_one(source_p, form_str(RPL_STATSHLINE), me.name,
707 >                   source_p->name, 'H', dptr->data, conf->name, 0, "*");
708      }
709      break;
710  
711    case LEAF_TYPE:
712 <    DLINK_FOREACH(ptr, leaf_items.head)
712 >    DLINK_FOREACH(ptr, server_items.head)
713      {
714        conf = ptr->data;
715 <      matchitem = map_to_conf(conf);
716 <      sendto_one(source_p, form_str(RPL_STATSLLINE), me.name,
717 <                 source_p->name, 'L', matchitem->host, conf->name, 0, "*");
715 >      aconf = map_to_conf(conf);
716 >
717 >      DLINK_FOREACH(dptr, aconf->leaf_list.head)
718 >        sendto_one(source_p, form_str(RPL_STATSLLINE), me.name,
719 >                   source_p->name, 'L', dptr->data, conf->name, 0, "*");
720      }
721      break;
722  
# Line 790 | Line 727 | report_confitem_types(struct Client *sou
727    case CRESV_TYPE:
728    case NRESV_TYPE:
729    case CLUSTER_TYPE:
730 +  default:
731      break;
732    }
733   }
# Line 816 | Line 754 | check_client(va_list args)
754  
755    /* I'm already in big trouble if source_p->localClient is NULL -db */
756    if ((i = verify_access(source_p, username)))
757 <  {
820 <    ilog(L_INFO, "Access denied: %s[%s]",
757 >    ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
758           source_p->name, source_p->sockhost);
822  }
759  
760    switch (i)
761    {
826    case IRCD_SOCKET_ERROR:
827      exit_client(source_p, &me, "Socket Error");
828      break;
829
762      case TOO_MANY:
763        sendto_realops_flags(UMODE_FULL, L_ALL,
764                             "Too many on IP for %s (%s).",
765                             get_client_name(source_p, SHOW_IP),
766                             source_p->sockhost);
767 <      ilog(L_INFO,"Too many connections on IP from %s.",
767 >      ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
768             get_client_name(source_p, SHOW_IP));
769 <      ServerStats->is_ref++;
769 >      ++ServerStats.is_ref;
770        exit_client(source_p, &me, "No more connections allowed on that IP");
771        break;
772  
# Line 843 | Line 775 | check_client(va_list args)
775                             "I-line is full for %s (%s).",
776                             get_client_name(source_p, SHOW_IP),
777                             source_p->sockhost);
778 <      ilog(L_INFO,"Too many connections from %s.",
778 >      ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
779             get_client_name(source_p, SHOW_IP));
780 <       ServerStats->is_ref++;
780 >      ++ServerStats.is_ref;
781        exit_client(source_p, &me,
782                  "No more connections allowed in your connection class");
783        break;
784  
785      case NOT_AUTHORIZED:
786 <    {
855 <      static char ipaddr[HOSTIPLEN];
856 <      ServerStats->is_ref++;
786 >      ++ServerStats.is_ref;
787        /* jdc - lists server name & port connections are on */
788        /*       a purely cosmetical change */
859      irc_getnameinfo((struct sockaddr*)&source_p->localClient->ip,
860            source_p->localClient->ip.ss_len, ipaddr, HOSTIPLEN, NULL, 0,
861            NI_NUMERICHOST);
789        sendto_realops_flags(UMODE_UNAUTH, L_ALL,
790                             "Unauthorized client connection from %s [%s] on [%s/%u].",
791                             get_client_name(source_p, SHOW_IP),
792 <                           ipaddr,
792 >                           source_p->sockhost,
793                             source_p->localClient->listener->name,
794                             source_p->localClient->listener->port);
795 <      ilog(L_INFO,
795 >      ilog(LOG_TYPE_IRCD,
796            "Unauthorized client connection from %s on [%s/%u].",
797            get_client_name(source_p, SHOW_IP),
798            source_p->localClient->listener->name,
# Line 875 | Line 802 | check_client(va_list args)
802         * capture reject code here or rely on the connecting too fast code.
803         * - Dianora
804         */
805 <      if(REJECT_HOLD_TIME > 0)
805 >      if (REJECT_HOLD_TIME > 0)
806        {
807          sendto_one(source_p, ":%s NOTICE %s :You are not authorized to use this server",
808                     me.name, source_p->name);
# Line 885 | Line 812 | check_client(va_list args)
812        else
813          exit_client(source_p, &me, "You are not authorized to use this server");
814        break;
815 <    }
889 <
815 >
816     case BANNED_CLIENT:
817       /*
818        * Don't exit them immediately, play with them a bit.
# Line 899 | Line 825 | check_client(va_list args)
825       }
826       else
827         exit_client(source_p, &me, "Banned");
828 <     ServerStats->is_ref++;
828 >     ++ServerStats.is_ref;
829       break;
830  
831     case 0:
# Line 1016 | Line 942 | attach_iline(struct Client *client_p, st
942    ip_found->count++;
943    SetIpHash(client_p);
944  
945 <  aconf = (struct AccessItem *)map_to_conf(conf);
945 >  aconf = map_to_conf(conf);
946    if (aconf->class_ptr == NULL)
947      return NOT_AUTHORIZED;  /* If class is missing, this is best */
948  
949 <  aclass = (struct ClassItem *)map_to_conf(aconf->class_ptr);
949 >  aclass = map_to_conf(aconf->class_ptr);
950  
951    count_user_host(client_p->username, client_p->host,
952                    &global, &local, &ident);
# Line 1029 | Line 955 | attach_iline(struct Client *client_p, st
955     * setting a_limit_reached if any limit is reached.
956     * - Dianora
957     */
958 <  if (MaxTotal(aclass) != 0 && CurrUserCount(aclass) >= MaxTotal(aclass))
958 >  if (aclass->max_total != 0 && aclass->curr_user_count >= aclass->max_total)
959      a_limit_reached = 1;
960 <  else if (MaxPerIp(aclass) != 0 && ip_found->count >= MaxPerIp(aclass))
960 >  else if (aclass->max_perip != 0 && ip_found->count > aclass->max_perip)
961      a_limit_reached = 1;
962 <  else if (MaxLocal(aclass) != 0 && local >= MaxLocal(aclass))
962 >  else if (aclass->max_local != 0 && local >= aclass->max_local)
963      a_limit_reached = 1;
964 <  else if (MaxGlobal(aclass) != 0 && global >= MaxGlobal(aclass))
964 >  else if (aclass->max_global != 0 && global >= aclass->max_global)
965      a_limit_reached = 1;
966 <  else if (MaxIdent(aclass) != 0 && ident >= MaxIdent(aclass) &&
966 >  else if (aclass->max_ident != 0 && ident >= aclass->max_ident &&
967             client_p->username[0] != '~')
968      a_limit_reached = 1;
969  
970    if (a_limit_reached)
971    {
972      if (!IsConfExemptLimits(aconf))
973 <      return TOO_MANY;  /* Already at maximum allowed */
973 >      return TOO_MANY;   /* Already at maximum allowed */
974  
975      sendto_one(client_p,
976                 ":%s NOTICE %s :*** Your connection class is full, "
# Line 1193 | Line 1119 | hash_ip(struct irc_ssaddr *addr)
1119    {
1120      struct sockaddr_in *v4 = (struct sockaddr_in *)addr;
1121      int hash;
1122 <    u_int32_t ip;
1122 >    uint32_t ip;
1123  
1124      ip   = ntohl(v4->sin_addr.s_addr);
1125      hash = ((ip >> 12) + ip) & (IP_HASH_SIZE-1);
# Line 1204 | Line 1130 | hash_ip(struct irc_ssaddr *addr)
1130    {
1131      int hash;
1132      struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr;
1133 <    u_int32_t *ip = (u_int32_t *)&v6->sin6_addr.s6_addr;
1133 >    uint32_t *ip = (uint32_t *)&v6->sin6_addr.s6_addr;
1134  
1135      hash  = ip[0] ^ ip[3];
1136      hash ^= hash >> 16;  
# Line 1228 | Line 1154 | hash_ip(struct irc_ssaddr *addr)
1154   * used in the hash.
1155   */
1156   void
1157 < count_ip_hash(int *number_ips_stored, unsigned long *mem_ips_stored)
1157 > count_ip_hash(unsigned int *number_ips_stored, uint64_t *mem_ips_stored)
1158   {
1159    struct ip_entry *ptr;
1160    int i;
# Line 1300 | Line 1226 | detach_conf(struct Client *client_p, Con
1226    struct ClassItem *aclass;
1227    struct AccessItem *aconf;
1228    struct ConfItem *aclass_conf;
1303  struct MatchItem *match_item;
1229  
1230    DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->confs.head)
1231    {
# Line 1316 | Line 1241 | detach_conf(struct Client *client_p, Con
1241        case CLIENT_TYPE:
1242        case OPER_TYPE:
1243        case SERVER_TYPE:
1244 <        aconf = (struct AccessItem *)map_to_conf(conf);
1245 <        if ((aclass_conf = ClassPtr(aconf)) != NULL)
1244 >        aconf = map_to_conf(conf);
1245 >
1246 >        assert(aconf->clients > 0);
1247 >
1248 >        if ((aclass_conf = aconf->class_ptr) != NULL)
1249          {
1250 <          aclass = (struct ClassItem *)map_to_conf(aclass_conf);
1250 >          aclass = map_to_conf(aclass_conf);
1251 >
1252 >          assert(aclass->curr_user_count > 0);
1253  
1254            if (conf->type == CLIENT_TYPE)
1255              remove_from_cidr_check(&client_p->localClient->ip, aclass);
1256 <
1327 <          if (CurrUserCount(aclass) > 0)
1328 <            aclass->curr_user_count--;
1329 <          if (MaxTotal(aclass) < 0 && CurrUserCount(aclass) <= 0)
1256 >          if (--aclass->curr_user_count == 0 && aclass->active == 0)
1257              delete_conf_item(aclass_conf);
1258          }
1259  
1260 <        /* Please, no ioccc entries - Dianora */
1334 <        if (aconf->clients > 0)
1335 <          --aconf->clients;
1336 <        if (aconf->clients == 0 && IsConfIllegal(aconf))
1337 <          delete_conf_item(conf);
1338 <        break;
1339 <      case LEAF_TYPE:
1340 <      case HUB_TYPE:
1341 <        match_item = (struct MatchItem *)map_to_conf(conf);
1342 <        if (match_item->ref_count == 0 && match_item->illegal)
1260 >        if (--aconf->clients == 0 && IsConfIllegal(aconf))
1261            delete_conf_item(conf);
1262 +
1263          break;
1264        default:
1265          break;
# Line 1367 | Line 1286 | detach_conf(struct Client *client_p, Con
1286   int
1287   attach_conf(struct Client *client_p, struct ConfItem *conf)
1288   {
1289 <  struct AccessItem *aconf;
1290 <  struct MatchItem *match_item;
1289 >  struct AccessItem *aconf = map_to_conf(conf);
1290 >  struct ClassItem *aclass = map_to_conf(aconf->class_ptr);
1291  
1292    if (dlinkFind(&client_p->localClient->confs, conf) != NULL)
1293      return 1;
1294  
1295 <  if (conf->type == CLIENT_TYPE ||
1296 <      conf->type == SERVER_TYPE ||
1378 <      conf->type == OPER_TYPE)
1379 <  {
1380 <    aconf = (struct AccessItem *)map_to_conf(conf);
1381 <
1382 <    if (IsConfIllegal(aconf))
1383 <      return NOT_AUTHORIZED;
1384 <
1385 <    if (conf->type == CLIENT_TYPE)
1386 <    {
1387 <      struct ClassItem *aclass;
1388 <      aclass = (struct ClassItem *)map_to_conf(aconf->class_ptr);
1389 <
1390 <      if (cidr_limit_reached(IsConfExemptLimits(aconf),
1391 <                             &client_p->localClient->ip, aclass))
1392 <        return TOO_MANY;  /* Already at maximum allowed */
1295 >  if (IsConfIllegal(aconf)) /* TBV: can't happen */
1296 >    return NOT_AUTHORIZED;
1297  
1298 <      CurrUserCount(aclass)++;
1299 <    }
1298 >  if (conf->type == CLIENT_TYPE)
1299 >    if (cidr_limit_reached(IsConfExemptLimits(aconf),
1300 >                           &client_p->localClient->ip, aclass))
1301 >      return TOO_MANY;    /* Already at maximum allowed */
1302  
1303 <    aconf->clients++;
1304 <  }
1399 <  else if (conf->type == HUB_TYPE || conf->type == LEAF_TYPE)
1400 <  {
1401 <    match_item = (struct MatchItem *)map_to_conf(conf);
1402 <    match_item->ref_count++;
1403 <  }
1303 >  aclass->curr_user_count++;
1304 >  aconf->clients++;
1305  
1306    dlinkAdd(conf, make_dlink_node(), &client_p->localClient->confs);
1307  
# Line 1432 | Line 1333 | attach_connect_block(struct Client *clie
1333    DLINK_FOREACH(ptr, server_items.head)
1334    {
1335      conf = ptr->data;
1336 <    aconf = (struct AccessItem *)map_to_conf(conf);
1336 >    aconf = map_to_conf(conf);
1337  
1338      if (match(conf->name, name) == 0 || match(aconf->host, host) == 0)
1339        continue;
# Line 1472 | Line 1373 | find_conf_exact(ConfType type, const cha
1373  
1374      if (conf->name == NULL)
1375        continue;
1376 <    aconf = (struct AccessItem *)map_to_conf(conf);
1376 >    aconf = map_to_conf(conf);
1377      if (aconf->host == NULL)
1378        continue;
1379      if (irccmp(conf->name, name) != 0)
# Line 1483 | Line 1384 | find_conf_exact(ConfType type, const cha
1384      ** socket host) matches *either* host or name field
1385      ** of the configuration.
1386      */
1387 <    if (!match(aconf->host, host) || !match(aconf->user,user)
1487 <        || irccmp(conf->name, name) )
1387 >    if (!match(aconf->host, host) || !match(aconf->user, user))
1388        continue;
1389      if (type == OPER_TYPE)
1390      {
1391 <      struct ClassItem *aclass;
1391 >      struct ClassItem *aclass = map_to_conf(aconf->class_ptr);
1392  
1393 <      aclass = (struct ClassItem *)aconf->class_ptr;
1494 <      if (aconf->clients < MaxTotal(aclass))
1495 <        return conf;
1496 <      else
1393 >      if (aconf->clients >= aclass->max_total)
1394          continue;
1395      }
1396 <    else
1397 <      return conf;
1396 >
1397 >    return conf;
1398    }
1399 +
1400    return NULL;
1401   }
1402  
# Line 1564 | Line 1462 | map_to_list(ConfType type)
1462    case SERVER_TYPE:
1463      return(&server_items);
1464      break;
1465 +  case SERVICE_TYPE:
1466 +    return(&service_items);
1467 +    break;
1468    case CLUSTER_TYPE:
1469      return(&cluster_items);
1470      break;
# Line 1599 | Line 1500 | find_matching_name_conf(ConfType type, c
1500  
1501    switch (type)
1502    {
1503 <    case RXLINE_TYPE:
1503 > #ifdef HAVE_LIBPCRE
1504 >  case RXLINE_TYPE:
1505        DLINK_FOREACH(ptr, list_p->head)
1506        {
1507          conf = ptr->data;
# Line 1609 | Line 1511 | find_matching_name_conf(ConfType type, c
1511            return conf;
1512        }
1513        break;
1514 + #endif
1515 +  case SERVICE_TYPE:
1516 +    DLINK_FOREACH(ptr, list_p->head)
1517 +    {
1518 +      conf = ptr->data;
1519 +
1520 +      if (EmptyString(conf->name))
1521 +        continue;
1522 +      if ((name != NULL) && !irccmp(name, conf->name))
1523 +        return conf;
1524 +    }
1525 +    break;
1526  
1527    case XLINE_TYPE:
1528    case ULINE_TYPE:
# Line 1663 | Line 1577 | find_matching_name_conf(ConfType type, c
1577   * side effects - looks for an exact match on name field
1578   */
1579   struct ConfItem *
1580 < find_exact_name_conf(ConfType type, const char *name,
1580 > find_exact_name_conf(ConfType type, const struct Client *who, const char *name,
1581                       const char *user, const char *host)
1582   {
1583    dlink_node *ptr = NULL;
# Line 1704 | Line 1618 | find_exact_name_conf(ConfType type, cons
1618      DLINK_FOREACH(ptr, list_p->head)
1619      {
1620        conf = ptr->data;
1621 <      aconf = (struct AccessItem *)map_to_conf(conf);
1621 >      aconf = map_to_conf(conf);
1622 >
1623        if (EmptyString(conf->name))
1624 <        continue;
1625 <    
1626 <      if (irccmp(conf->name, name) == 0)
1624 >        continue;
1625 >
1626 >      if (!irccmp(conf->name, name))
1627        {
1628 <        if ((user == NULL && (host == NULL)))
1629 <          return (conf);
1630 <        if (EmptyString(aconf->user) || EmptyString(aconf->host))
1631 <          return (conf);
1632 <        if (match(aconf->user, user) && match(aconf->host, host))
1633 <          return (conf);
1628 >        if (!who)
1629 >          return conf;
1630 >        if (EmptyString(aconf->user) || EmptyString(aconf->host))
1631 >          return conf;
1632 >        if (match(aconf->user, who->username))
1633 >        {
1634 >          switch (aconf->type)
1635 >          {
1636 >            case HM_HOST:
1637 >              if (match(aconf->host, who->host) || match(aconf->host, who->sockhost))
1638 >                return conf;
1639 >              break;
1640 >            case HM_IPV4:
1641 >              if (who->localClient->aftype == AF_INET)
1642 >                if (match_ipv4(&who->localClient->ip, &aconf->addr, aconf->bits))
1643 >                  return conf;
1644 >              break;
1645 > #ifdef IPV6
1646 >            case HM_IPV6:
1647 >              if (who->localClient->aftype == AF_INET6)
1648 >                if (match_ipv6(&who->localClient->ip, &aconf->addr, aconf->bits))
1649 >                  return conf;
1650 >              break;
1651 > #endif
1652 >            default:
1653 >              assert(0);
1654 >          }
1655 >        }
1656        }
1657      }
1658 +
1659      break;
1660  
1661    case SERVER_TYPE:
# Line 1773 | Line 1711 | rehash(int sig)
1711      sendto_realops_flags(UMODE_ALL, L_ALL,
1712                           "Got signal SIGHUP, reloading ircd.conf file");
1713  
1776 #ifndef _WIN32
1714    restart_resolver();
1715 < #endif
1715 >
1716    /* don't close listeners until we know we can go ahead with the rehash */
1717  
1718    /* Check to see if we magically got(or lost) IPv6 support */
# Line 1786 | Line 1723 | rehash(int sig)
1723    if (ServerInfo.description != NULL)
1724      strlcpy(me.info, ServerInfo.description, sizeof(me.info));
1725  
1789 #ifndef STATIC_MODULES
1726    load_conf_modules();
1791 #endif
1727  
1728    flush_deleted_I_P();
1729  
1730    rehashed_klines = 1;
1731 <
1731 > /* XXX */
1732    if (ConfigLoggingEntry.use_logging)
1733 <    reopen_log(logFileName);
1733 >    log_close_all();
1734  
1735    return(0);
1736   }
# Line 1834 | Line 1769 | set_default_conf(void)
1769    ServerInfo.specific_ipv6_vhost = 0;
1770  
1771    ServerInfo.max_clients = MAXCLIENTS_MAX;
1772 <  /* Don't reset hub, as that will break lazylinks */
1773 <  /* ServerInfo.hub = NO; */
1772 >
1773 >  ServerInfo.hub = 0;
1774    ServerInfo.dns_host.sin_addr.s_addr = 0;
1775    ServerInfo.dns_host.sin_port = 0;
1776    AdminInfo.name = NULL;
1777    AdminInfo.email = NULL;
1778    AdminInfo.description = NULL;
1779  
1780 <  set_log_level(L_NOTICE);
1780 >  log_close_all();
1781 >
1782    ConfigLoggingEntry.use_logging = 1;
1783 <  ConfigLoggingEntry.operlog[0] = '\0';
1784 <  ConfigLoggingEntry.userlog[0] = '\0';
1785 <  ConfigLoggingEntry.klinelog[0] = '\0';
1850 <  ConfigLoggingEntry.glinelog[0] = '\0';
1851 <  ConfigLoggingEntry.killlog[0] = '\0';
1852 <  ConfigLoggingEntry.operspylog[0] = '\0';
1853 <  ConfigLoggingEntry.ioerrlog[0] = '\0';
1854 <  ConfigLoggingEntry.failed_operlog[0] = '\0';
1855 <
1856 <  ConfigChannel.restrict_channels = NO;
1857 <  ConfigChannel.disable_local_channels = NO;
1858 <  ConfigChannel.use_invex = YES;
1859 <  ConfigChannel.use_except = YES;
1860 <  ConfigChannel.use_knock = YES;
1783 >
1784 >  ConfigChannel.disable_fake_channels = 0;
1785 >  ConfigChannel.restrict_channels = 0;
1786    ConfigChannel.knock_delay = 300;
1787    ConfigChannel.knock_delay_channel = 60;
1788 <  ConfigChannel.max_chans_per_user = 15;
1789 <  ConfigChannel.quiet_on_ban = YES;
1788 >  ConfigChannel.max_chans_per_user = 25;
1789 >  ConfigChannel.max_chans_per_oper = 50;
1790 >  ConfigChannel.quiet_on_ban = 1;
1791    ConfigChannel.max_bans = 25;
1792    ConfigChannel.default_split_user_count = 0;
1793    ConfigChannel.default_split_server_count = 0;
1794 <  ConfigChannel.no_join_on_split = NO;
1795 <  ConfigChannel.no_create_on_split = NO;
1870 <  ConfigChannel.burst_topicwho = YES;
1794 >  ConfigChannel.no_join_on_split = 0;
1795 >  ConfigChannel.no_create_on_split = 0;
1796  
1797 <  ConfigServerHide.flatten_links = NO;
1797 >  ConfigServerHide.flatten_links = 0;
1798    ConfigServerHide.links_delay = 300;
1799 <  ConfigServerHide.hidden = NO;
1800 <  ConfigServerHide.disable_hidden = NO;
1876 <  ConfigServerHide.hide_servers = NO;
1799 >  ConfigServerHide.hidden = 0;
1800 >  ConfigServerHide.hide_servers = 0;
1801    DupString(ConfigServerHide.hidden_name, NETWORK_NAME_DEFAULT);
1802 <  ConfigServerHide.hide_server_ips = NO;
1802 >  ConfigServerHide.hide_server_ips = 0;
1803  
1804 +  
1805 +  DupString(ConfigFileEntry.service_name, SERVICE_NAME_DEFAULT);
1806 +  ConfigFileEntry.max_watch = WATCHSIZE_DEFAULT;
1807 +  ConfigFileEntry.glines = 0;
1808 +  ConfigFileEntry.gline_time = 12 * 3600;
1809 +  ConfigFileEntry.gline_request_time = GLINE_REQUEST_EXPIRE_DEFAULT;
1810    ConfigFileEntry.gline_min_cidr = 16;
1811    ConfigFileEntry.gline_min_cidr6 = 48;
1812 <  ConfigFileEntry.invisible_on_connect = YES;
1813 <  ConfigFileEntry.burst_away = NO;
1814 <  ConfigFileEntry.use_whois_actually = YES;
1815 <  ConfigFileEntry.tkline_expire_notices = YES;
1816 <  ConfigFileEntry.hide_spoof_ips = YES;
1817 <  ConfigFileEntry.ignore_bogus_ts = NO;
1888 <  ConfigFileEntry.disable_auth = NO;
1889 <  ConfigFileEntry.disable_remote = NO;
1812 >  ConfigFileEntry.invisible_on_connect = 1;
1813 >  ConfigFileEntry.tkline_expire_notices = 1;
1814 >  ConfigFileEntry.hide_spoof_ips = 1;
1815 >  ConfigFileEntry.ignore_bogus_ts = 0;
1816 >  ConfigFileEntry.disable_auth = 0;
1817 >  ConfigFileEntry.disable_remote = 0;
1818    ConfigFileEntry.kill_chase_time_limit = 90;
1819 <  ConfigFileEntry.default_floodcount = 8; /* XXX */
1820 <  ConfigFileEntry.failed_oper_notice = YES;
1821 <  ConfigFileEntry.dots_in_ident = 0;      /* XXX */
1894 <  ConfigFileEntry.dot_in_ip6_addr = YES;
1819 >  ConfigFileEntry.default_floodcount = 8;
1820 >  ConfigFileEntry.failed_oper_notice = 1;
1821 >  ConfigFileEntry.dots_in_ident = 0;
1822    ConfigFileEntry.min_nonwildcard = 4;
1823    ConfigFileEntry.min_nonwildcard_simple = 3;
1824    ConfigFileEntry.max_accept = 20;
1825 <  ConfigFileEntry.anti_nick_flood = NO;   /* XXX */
1825 >  ConfigFileEntry.anti_nick_flood = 0;
1826    ConfigFileEntry.max_nick_time = 20;
1827    ConfigFileEntry.max_nick_changes = 5;
1828 <  ConfigFileEntry.anti_spam_exit_message_time = 0;  /* XXX */
1828 >  ConfigFileEntry.anti_spam_exit_message_time = 0;
1829    ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
1830 <  ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;  /* XXX */
1831 <  ConfigFileEntry.kline_with_reason = YES;
1830 >  ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
1831 >  ConfigFileEntry.kline_with_reason = 1;
1832    ConfigFileEntry.kline_reason = NULL;
1833 <  ConfigFileEntry.warn_no_nline = YES;
1834 <  ConfigFileEntry.stats_o_oper_only = NO; /* XXX */
1833 >  ConfigFileEntry.warn_no_nline = 1;
1834 >  ConfigFileEntry.stats_o_oper_only = 0;
1835    ConfigFileEntry.stats_k_oper_only = 1;  /* masked */
1836    ConfigFileEntry.stats_i_oper_only = 1;  /* masked */
1837 <  ConfigFileEntry.stats_P_oper_only = NO;
1837 >  ConfigFileEntry.stats_P_oper_only = 0;
1838    ConfigFileEntry.caller_id_wait = 60;
1839 <  ConfigFileEntry.opers_bypass_callerid = NO;
1839 >  ConfigFileEntry.opers_bypass_callerid = 0;
1840    ConfigFileEntry.pace_wait = 10;
1841    ConfigFileEntry.pace_wait_simple = 1;
1842 <  ConfigFileEntry.short_motd = NO;
1843 <  ConfigFileEntry.ping_cookie = NO;
1844 <  ConfigFileEntry.no_oper_flood = NO;     /* XXX */
1845 <  ConfigFileEntry.true_no_oper_flood = NO;  /* XXX */
1846 <  ConfigFileEntry.oper_pass_resv = YES;
1920 <  ConfigFileEntry.glines = NO;            /* XXX */
1921 <  ConfigFileEntry.gline_time = 12 * 3600; /* XXX */
1922 <  ConfigFileEntry.idletime = 0;
1842 >  ConfigFileEntry.short_motd = 0;
1843 >  ConfigFileEntry.ping_cookie = 0;
1844 >  ConfigFileEntry.no_oper_flood = 0;
1845 >  ConfigFileEntry.true_no_oper_flood = 0;
1846 >  ConfigFileEntry.oper_pass_resv = 1;
1847    ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT;
1848 <  ConfigFileEntry.client_flood = CLIENT_FLOOD_DEFAULT;
1849 <  ConfigFileEntry.oper_only_umodes = UMODE_DEBUG;  /* XXX */
1850 <  ConfigFileEntry.oper_umodes = UMODE_LOCOPS | UMODE_SERVNOTICE |
1851 <    UMODE_OPERWALL | UMODE_WALLOP;        /* XXX */
1928 <  DupString(ConfigFileEntry.servlink_path, SLPATH);
1929 < #ifdef HAVE_LIBCRYPTO
1930 <  /* jdc -- This is our default value for a cipher.  According to the
1931 <   *        CRYPTLINK document (doc/cryptlink.txt), BF/128 must be supported
1932 <   *        under all circumstances if cryptlinks are enabled.  So,
1933 <   *        this will be our default.
1934 <   *
1935 <   *        NOTE: I apologise for the hard-coded value of "1" (BF/128).
1936 <   *              This should be moved into a find_cipher() routine.
1937 <   */
1938 <  ConfigFileEntry.default_cipher_preference = &CipherTable[1];
1939 < #endif
1940 <  ConfigFileEntry.use_egd = NO;
1848 >  ConfigFileEntry.oper_only_umodes = UMODE_DEBUG;
1849 >  ConfigFileEntry.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE |
1850 >    UMODE_OPERWALL | UMODE_WALLOP;
1851 >  ConfigFileEntry.use_egd = 0;
1852    ConfigFileEntry.egdpool_path = NULL;
1942 #ifdef HAVE_LIBZ
1943  ConfigFileEntry.compression_level = 0;
1944 #endif
1853    ConfigFileEntry.throttle_time = 10;
1854   }
1855  
1856 + static void
1857 + validate_conf(void)
1858 + {
1859 +  if (ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN)
1860 +    ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
1861 +
1862 +  if (ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN)
1863 +    ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
1864 +
1865 +  if (ServerInfo.network_name == NULL)
1866 +    DupString(ServerInfo.network_name,NETWORK_NAME_DEFAULT);
1867 +
1868 +  if (ServerInfo.network_desc == NULL)
1869 +    DupString(ServerInfo.network_desc,NETWORK_DESC_DEFAULT);
1870 +
1871 +  if (ConfigFileEntry.service_name == NULL)
1872 +    DupString(ConfigFileEntry.service_name, SERVICE_NAME_DEFAULT);
1873 +
1874 +  ConfigFileEntry.max_watch = IRCD_MAX(ConfigFileEntry.max_watch, WATCHSIZE_MIN);
1875 + }
1876 +
1877   /* read_conf()
1878   *
1879   * inputs       - file descriptor pointing to config file to use
# Line 1952 | Line 1881 | set_default_conf(void)
1881   * side effects - Read configuration file.
1882   */
1883   static void
1884 < read_conf(FBFILE *file)
1884 > read_conf(FILE *file)
1885   {
1886 <  scount = lineno = 0;
1886 >  lineno = 0;
1887  
1888    set_default_conf(); /* Set default values prior to conf parsing */
1889 <  ypass = 1;
1889 >  conf_parser_ctx.pass = 1;
1890    yyparse();          /* pick up the classes first */
1891  
1892 <  fbrewind(file);
1892 >  rewind(file);
1893  
1894 <  ypass = 2;
1894 >  conf_parser_ctx.pass = 2;
1895    yyparse();          /* Load the values from the conf */
1896    validate_conf();    /* Check to make sure some values are still okay. */
1897                        /* Some global values are also loaded here. */
1898    check_class();      /* Make sure classes are valid */
1899   }
1900  
1972 static void
1973 validate_conf(void)
1974 {
1975  if (ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN)
1976    ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
1977
1978  if (ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN)
1979    ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
1980
1981  if (ConfigFileEntry.servlink_path == NULL)
1982    DupString(ConfigFileEntry.servlink_path, SLPATH);
1983
1984  if (ServerInfo.network_name == NULL)
1985    DupString(ServerInfo.network_name,NETWORK_NAME_DEFAULT);
1986
1987  if (ServerInfo.network_desc == NULL)
1988    DupString(ServerInfo.network_desc,NETWORK_DESC_DEFAULT);
1989
1990  if ((ConfigFileEntry.client_flood < CLIENT_FLOOD_MIN) ||
1991      (ConfigFileEntry.client_flood > CLIENT_FLOOD_MAX))
1992    ConfigFileEntry.client_flood = CLIENT_FLOOD_MAX;
1993 }
1994
1901   /* lookup_confhost()
1902   *
1903   * start DNS lookups of all hostnames in the conf
# Line 2005 | Line 1911 | lookup_confhost(struct ConfItem *conf)
1911  
1912    aconf = map_to_conf(conf);
1913  
1914 <  if (EmptyString(aconf->host) ||
2009 <      EmptyString(aconf->user))
1914 >  if (has_wildcards(aconf->host))
1915    {
1916 <    ilog(L_ERROR, "Host/server name error: (%s) (%s)",
1916 >    ilog(LOG_TYPE_IRCD, "Host/server name error: (%s) (%s)",
1917           aconf->host, conf->name);
1918      return;
1919    }
1920  
2016  if (strchr(aconf->host, '*') ||
2017      strchr(aconf->host, '?'))
2018    return;
2019
1921    /* Do name lookup now on hostnames given and store the
1922     * ip numbers in conf structure.
1923     */
# Line 2028 | Line 1929 | lookup_confhost(struct ConfItem *conf)
1929    /* Get us ready for a bind() and don't bother doing dns lookup */
1930    hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
1931  
1932 <  if (irc_getaddrinfo(aconf->host, NULL, &hints, &res))
1932 >  if (getaddrinfo(aconf->host, NULL, &hints, &res))
1933    {
1934      conf_dns_lookup(aconf);
1935      return;
# Line 2036 | Line 1937 | lookup_confhost(struct ConfItem *conf)
1937  
1938    assert(res != NULL);
1939  
1940 <  memcpy(&aconf->ipnum, res->ai_addr, res->ai_addrlen);
1941 <  aconf->ipnum.ss_len = res->ai_addrlen;
1942 <  aconf->ipnum.ss.ss_family = res->ai_family;
1943 <  irc_freeaddrinfo(res);
1940 >  memcpy(&aconf->addr, res->ai_addr, res->ai_addrlen);
1941 >  aconf->addr.ss_len = res->ai_addrlen;
1942 >  aconf->addr.ss.ss_family = res->ai_family;
1943 >  freeaddrinfo(res);
1944   }
1945  
1946   /* conf_connect_allowed()
# Line 2078 | Line 1979 | conf_connect_allowed(struct irc_ssaddr *
1979   static struct AccessItem *
1980   find_regexp_kline(const char *uhi[])
1981   {
1982 + #ifdef HAVE_LIBPCRE
1983    const dlink_node *ptr = NULL;
1984  
1985    DLINK_FOREACH(ptr, rkconf_items.head)
# Line 2092 | Line 1994 | find_regexp_kline(const char *uhi[])
1994           !ircd_pcre_exec(aptr->regexhost, uhi[2])))
1995        return aptr;
1996    }
1997 <
1997 > #endif
1998    return NULL;
1999   }
2000  
# Line 2115 | Line 2017 | find_kill(struct Client *client_p)
2017  
2018    assert(client_p != NULL);
2019  
2020 <  aconf = find_kline_conf(client_p->host, client_p->username,
2021 <                          &client_p->localClient->ip,
2022 <                          client_p->localClient->aftype);
2020 >  aconf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
2021 >                               CONF_KLINE, client_p->localClient->aftype,
2022 >                               client_p->username, NULL, 1);
2023    if (aconf == NULL)
2024      aconf = find_regexp_kline(uhi);
2025  
2026 <  if (aconf && (aconf->status & CONF_KLINE))
2125 <    return aconf;
2126 <
2127 <  return NULL;
2026 >  return aconf;
2027   }
2028  
2029   struct AccessItem *
# Line 2134 | Line 2033 | find_gline(struct Client *client_p)
2033  
2034    assert(client_p != NULL);
2035  
2036 <  aconf = find_gline_conf(client_p->host, client_p->username,
2037 <                          &client_p->localClient->ip,
2038 <                          client_p->localClient->aftype);
2039 <
2141 <  if (aconf && (aconf->status & CONF_GLINE))
2142 <    return aconf;
2143 <
2144 <  return NULL;
2036 >  aconf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
2037 >                               CONF_GLINE, client_p->localClient->aftype,
2038 >                               client_p->username, NULL, 1);
2039 >  return aconf;
2040   }
2041  
2042   /* add_temp_line()
# Line 2154 | Line 2049 | find_gline(struct Client *client_p)
2049   void
2050   add_temp_line(struct ConfItem *conf)
2051   {
2052 <  struct AccessItem *aconf;
2158 <
2159 <  if (conf->type == DLINE_TYPE)
2160 <  {
2161 <    aconf = map_to_conf(conf);
2162 <    SetConfTemporary(aconf);
2163 <    dlinkAdd(conf, &conf->node, &temporary_dlines);
2164 <    MyFree(aconf->user);
2165 <    aconf->user = NULL;
2166 <    add_conf_by_address(CONF_DLINE, aconf);
2167 <  }
2168 <  else if (conf->type == KLINE_TYPE)
2169 <  {
2170 <    aconf = map_to_conf(conf);
2171 <    SetConfTemporary(aconf);
2172 <    dlinkAdd(conf, &conf->node, &temporary_klines);
2173 <    add_conf_by_address(CONF_KILL, aconf);
2174 <  }
2175 <  else if (conf->type == GLINE_TYPE)
2176 <  {
2177 <    aconf = map_to_conf(conf);
2178 <    SetConfTemporary(aconf);
2179 <    dlinkAdd(conf, &conf->node, &temporary_glines);
2180 <    add_conf_by_address(CONF_GLINE, aconf);
2181 <  }
2182 <  else if (conf->type == XLINE_TYPE)
2052 >  if (conf->type == XLINE_TYPE)
2053    {
2054      conf->flags |= CONF_FLAGS_TEMPORARY;
2055      dlinkAdd(conf, make_dlink_node(), &temporary_xlines);
2056    }
2187  else if (conf->type == RXLINE_TYPE)
2188  {
2189    conf->flags |= CONF_FLAGS_TEMPORARY;
2190    dlinkAdd(conf, make_dlink_node(), &temporary_rxlines);
2191  }
2192  else if (conf->type == RKLINE_TYPE)
2193  {
2194    conf->flags |= CONF_FLAGS_TEMPORARY;
2195    dlinkAdd(conf, make_dlink_node(), &temporary_rklines);
2196  }
2057    else if ((conf->type == NRESV_TYPE) || (conf->type == CRESV_TYPE))
2058    {
2059      conf->flags |= CONF_FLAGS_TEMPORARY;
# Line 2211 | Line 2071 | add_temp_line(struct ConfItem *conf)
2071   void
2072   cleanup_tklines(void *notused)
2073   {
2074 <  expire_tklines(&temporary_glines);
2215 <  expire_tklines(&temporary_klines);
2216 <  expire_tklines(&temporary_dlines);
2074 >  hostmask_expire_temporary();
2075    expire_tklines(&temporary_xlines);
2218  expire_tklines(&temporary_rxlines);
2219  expire_tklines(&temporary_rklines);
2076    expire_tklines(&temporary_resv);
2077   }
2078  
# Line 2234 | Line 2090 | expire_tklines(dlink_list *tklist)
2090    struct ConfItem *conf;
2091    struct MatchItem *xconf;
2092    struct MatchItem *nconf;
2237  struct AccessItem *aconf;
2093    struct ResvChannel *cconf;
2094  
2095    DLINK_FOREACH_SAFE(ptr, next_ptr, tklist->head)
2096    {
2097      conf = ptr->data;
2243    if (conf->type == GLINE_TYPE ||
2244        conf->type == KLINE_TYPE ||
2245        conf->type == DLINE_TYPE)
2246    {
2247      aconf = (struct AccessItem *)map_to_conf(conf);
2248      if (aconf->hold <= CurrentTime)
2249      {
2250        /* XXX - Do we want GLINE expiry notices?? */
2251        /* Alert opers that a TKline expired - Hwy */
2252        if (ConfigFileEntry.tkline_expire_notices)
2253        {
2254          if (aconf->status & CONF_KILL)
2255          {
2256            sendto_realops_flags(UMODE_ALL, L_ALL,
2257                                 "Temporary K-line for [%s@%s] expired",
2258                                 (aconf->user) ? aconf->user : "*",
2259                                 (aconf->host) ? aconf->host : "*");
2260          }
2261          else if (conf->type == DLINE_TYPE)
2262          {
2263            sendto_realops_flags(UMODE_ALL, L_ALL,
2264                                 "Temporary D-line for [%s] expired",
2265                                 (aconf->host) ? aconf->host : "*");
2266          }
2267        }
2098  
2099 <        delete_one_address_conf(aconf->host, aconf);
2270 <        dlinkDelete(ptr, tklist);
2271 <      }
2272 <    }
2273 <    else if (conf->type == XLINE_TYPE ||
2274 <             conf->type == RXLINE_TYPE)
2099 >    if (conf->type == XLINE_TYPE)
2100      {
2101        xconf = (struct MatchItem *)map_to_conf(conf);
2102        if (xconf->hold <= CurrentTime)
2103        {
2104          if (ConfigFileEntry.tkline_expire_notices)
2105            sendto_realops_flags(UMODE_ALL, L_ALL,
2106 <                               "Temporary X-line for [%s] %sexpired", conf->name,
2282 <                               conf->type == RXLINE_TYPE ? "(REGEX) " : "");
2106 >                               "Temporary X-line for [%s] sexpired", conf->name);
2107          dlinkDelete(ptr, tklist);
2108          free_dlink_node(ptr);
2109          delete_conf_item(conf);
2110        }
2111      }
2288    else if (conf->type == RKLINE_TYPE)
2289    {
2290      aconf = map_to_conf(conf);
2291      if (aconf->hold <= CurrentTime)
2292      {
2293        if (ConfigFileEntry.tkline_expire_notices)
2294           sendto_realops_flags(UMODE_ALL, L_ALL,
2295                                "Temporary K-line for [%s@%s] (REGEX) expired",
2296                                (aconf->user) ? aconf->user : "*",
2297                                (aconf->host) ? aconf->host : "*");
2298        dlinkDelete(ptr, tklist);
2299        free_dlink_node(ptr);
2300        delete_conf_item(conf);
2301      }
2302    }
2112      else if (conf->type == NRESV_TYPE)
2113      {
2114        nconf = (struct MatchItem *)map_to_conf(conf);
# Line 2321 | Line 2130 | expire_tklines(dlink_list *tklist)
2130          if (ConfigFileEntry.tkline_expire_notices)
2131            sendto_realops_flags(UMODE_ALL, L_ALL,
2132                                 "Temporary RESV for [%s] expired", cconf->name);
2133 <        dlinkDelete(ptr, tklist);
2325 <        free_dlink_node(ptr);
2326 <        delete_conf_item(conf);
2133 >        delete_channel_resv(cconf);
2134        }
2135      }
2136    }
# Line 2338 | Line 2145 | expire_tklines(dlink_list *tklist)
2145   static const struct oper_privs
2146   {
2147    const unsigned int oprivs;
2341  const unsigned int hidden;
2148    const unsigned char c;
2149   } flag_list[] = {
2150 <  { OPER_FLAG_ADMIN,       OPER_FLAG_HIDDEN_ADMIN,  'A' },
2151 <  { OPER_FLAG_REMOTEBAN,   0,                       'B' },
2152 <  { OPER_FLAG_DIE,         0,                       'D' },
2153 <  { OPER_FLAG_GLINE,       0,                       'G' },
2154 <  { OPER_FLAG_REHASH,      0,                       'H' },
2155 <  { OPER_FLAG_K,           0,                       'K' },
2156 <  { OPER_FLAG_OPERWALL,    0,                       'L' },
2157 <  { OPER_FLAG_N,           0,                       'N' },
2158 <  { OPER_FLAG_GLOBAL_KILL, 0,                       'O' },
2159 <  { OPER_FLAG_REMOTE,      0,                       'R' },
2160 <  { OPER_FLAG_OPER_SPY,    0,                       'S' },
2161 <  { OPER_FLAG_UNKLINE,     0,                       'U' },
2162 <  { OPER_FLAG_X,           0,                       'X' },
2163 <  { 0, 0, '\0' }
2150 >  { OPER_FLAG_ADMIN,       'A' },
2151 >  { OPER_FLAG_REMOTEBAN,   'B' },
2152 >  { OPER_FLAG_DIE,         'D' },
2153 >  { OPER_FLAG_GLINE,       'G' },
2154 >  { OPER_FLAG_REHASH,      'H' },
2155 >  { OPER_FLAG_K,           'K' },
2156 >  { OPER_FLAG_OPERWALL,    'L' },
2157 >  { OPER_FLAG_N,           'N' },
2158 >  { OPER_FLAG_GLOBAL_KILL, 'O' },
2159 >  { OPER_FLAG_REMOTE,      'R' },
2160 >  { OPER_FLAG_OPER_SPY,    'S' },
2161 >  { OPER_FLAG_UNKLINE,     'U' },
2162 >  { OPER_FLAG_X,           'X' },
2163 >  { 0, '\0' }
2164   };
2165  
2166   char *
# Line 2366 | Line 2172 | oper_privs_as_string(const unsigned int
2172  
2173    for (; flag_list[i].oprivs; ++i)
2174    {
2175 <    if ((port & flag_list[i].oprivs) &&
2370 <        (port & flag_list[i].hidden) == 0)
2175 >    if (port & flag_list[i].oprivs)
2176        *privs_ptr++ = flag_list[i].c;
2177      else
2178        *privs_ptr++ = ToLowerTab[flag_list[i].c];
# Line 2384 | Line 2189 | oper_privs_as_string(const unsigned int
2189   *         "oper" is server name for remote opers
2190   * Side effects: None.
2191   */
2192 < char *
2192 > const char *
2193   get_oper_name(const struct Client *client_p)
2194   {
2195 <  dlink_node *cnode;
2391 <  struct ConfItem *conf;
2392 <  struct AccessItem *aconf;
2393 <
2195 >  dlink_node *cnode = NULL;
2196    /* +5 for !,@,{,} and null */
2197 <  static char buffer[NICKLEN+USERLEN+HOSTLEN+HOSTLEN+5];
2197 >  static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5];
2198  
2199    if (MyConnect(client_p))
2200    {
2201 <    DLINK_FOREACH(cnode, client_p->localClient->confs.head)
2201 >    if ((cnode = client_p->localClient->confs.head))
2202      {
2203 <      conf = cnode->data;
2204 <      aconf = map_to_conf(conf);
2203 >      struct ConfItem *conf = cnode->data;
2204 >      const struct AccessItem *aconf = map_to_conf(conf);
2205  
2206        if (IsConfOperator(aconf))
2207        {
2208 <        ircsprintf(buffer, "%s!%s@%s{%s}", client_p->name,
2209 <                   client_p->username, client_p->host,
2408 <                   conf->name);
2208 >        snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
2209 >                 client_p->username, client_p->host, conf->name);
2210          return buffer;
2211        }
2212      }
# Line 2416 | Line 2217 | get_oper_name(const struct Client *clien
2217      assert(0); /* Oper without oper conf! */
2218    }
2219  
2220 <  ircsprintf(buffer, "%s!%s@%s{%s}", client_p->name,
2221 <             client_p->username, client_p->host, client_p->servptr->name);
2220 >  snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
2221 >           client_p->username, client_p->host, client_p->servptr->name);
2222    return buffer;
2223   }
2224  
# Line 2434 | Line 2235 | read_conf_files(int cold)
2235    char chanmodes[32];
2236    char chanlimit[32];
2237  
2238 +  conf_parser_ctx.boot = cold;
2239    filename = get_conf_name(CONF_TYPE);
2240  
2241    /* We need to know the initial filename for the yyerror() to report
# Line 2444 | Line 2246 | read_conf_files(int cold)
2246    */
2247    strlcpy(conffilebuf, filename, sizeof(conffilebuf));
2248  
2249 <  if ((conf_fbfile_in = fbopen(filename, "r")) == NULL)
2249 >  if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL)
2250    {
2251      if (cold)
2252      {
2253 <      ilog(L_CRIT, "Unable to read configuration file '%s': %s",
2253 >      ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
2254             filename, strerror(errno));
2255        exit(-1);
2256      }
# Line 2464 | Line 2266 | read_conf_files(int cold)
2266    if (!cold)
2267      clear_out_old_conf();
2268  
2269 <  read_conf(conf_fbfile_in);
2270 <  fbclose(conf_fbfile_in);
2269 >  read_conf(conf_parser_ctx.conf_file);
2270 >  fclose(conf_parser_ctx.conf_file);
2271  
2272    add_isupport("NETWORK", ServerInfo.network_name, -1);
2273 <  ircsprintf(chanmodes, "b%s%s:%d", ConfigChannel.use_except ? "e" : "",
2274 <             ConfigChannel.use_invex ? "I" : "", ConfigChannel.max_bans);
2273 >  snprintf(chanmodes, sizeof(chanmodes), "beI:%d",
2274 >           ConfigChannel.max_bans);
2275    add_isupport("MAXLIST", chanmodes, -1);
2276    add_isupport("MAXTARGETS", NULL, ConfigFileEntry.max_targets);
2277 <  if (ConfigChannel.disable_local_channels)
2278 <    add_isupport("CHANTYPES", "#", -1);
2279 <  else
2280 <    add_isupport("CHANTYPES", "#&", -1);
2281 <  ircsprintf(chanlimit, "%s:%d", ConfigChannel.disable_local_channels ? "#" : "#&",
2480 <             ConfigChannel.max_chans_per_user);
2277 >
2278 >  add_isupport("CHANTYPES", "#", -1);
2279 >
2280 >  snprintf(chanlimit, sizeof(chanlimit), "#:%d",
2281 >           ConfigChannel.max_chans_per_user);
2282    add_isupport("CHANLIMIT", chanlimit, -1);
2283 <  ircsprintf(chanmodes, "%s%s%s", ConfigChannel.use_except ? "e" : "",
2284 <             ConfigChannel.use_invex ? "I" : "", "b,k,l,imnpst");
2283 >  snprintf(chanmodes, sizeof(chanmodes), "%s",
2284 >           "beI,k,l,imnprstORS");
2285    add_isupport("CHANNELLEN", NULL, LOCAL_CHANNELLEN);
2286 <  if (ConfigChannel.use_except)
2287 <    add_isupport("EXCEPTS", "e", -1);
2288 <  if (ConfigChannel.use_invex)
2488 <    add_isupport("INVEX", "I", -1);
2286 >
2287 >  add_isupport("EXCEPTS", "e", -1);
2288 >  add_isupport("INVEX", "I", -1);
2289    add_isupport("CHANMODES", chanmodes, -1);
2290  
2291    /*
# Line 2495 | Line 2295 | read_conf_files(int cold)
2295    rebuild_isupport_message_line();
2296  
2297    parse_conf_file(KLINE_TYPE, cold);
2498  parse_conf_file(RKLINE_TYPE, cold);
2298    parse_conf_file(DLINE_TYPE, cold);
2299    parse_conf_file(XLINE_TYPE, cold);
2501  parse_conf_file(RXLINE_TYPE, cold);
2300    parse_conf_file(NRESV_TYPE, cold);
2301    parse_conf_file(CRESV_TYPE, cold);
2302   }
# Line 2512 | Line 2310 | read_conf_files(int cold)
2310   static void
2311   parse_conf_file(int type, int cold)
2312   {
2313 <  FBFILE *file = NULL;
2313 >  FILE *file = NULL;
2314    const char *filename = get_conf_name(type);
2315  
2316 <  if ((file = fbopen(filename, "r")) == NULL)
2316 >  if ((file = fopen(filename, "r")) == NULL)
2317    {
2318      if (cold)
2319 <      ilog(L_ERROR, "Unable to read configuration file '%s': %s",
2319 >      ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
2320             filename, strerror(errno));
2321      else
2322        sendto_realops_flags(UMODE_ALL, L_ALL,
# Line 2528 | Line 2326 | parse_conf_file(int type, int cold)
2326    else
2327    {
2328      parse_csv_file(file, type);
2329 <    fbclose(file);
2329 >    fclose(file);
2330    }
2331   }
2332  
# Line 2545 | Line 2343 | clear_out_old_conf(void)
2343    struct ConfItem *conf;
2344    struct AccessItem *aconf;
2345    struct ClassItem *cltmp;
2548  struct MatchItem *match_item;
2346    dlink_list *free_items [] = {
2347 <    &server_items,   &oconf_items,    &hub_items, &leaf_items,
2347 >    &server_items,   &oconf_items,
2348       &uconf_items,   &xconf_items, &rxconf_items, &rkconf_items,
2349 <     &nresv_items, &cluster_items,  &gdeny_items, NULL
2349 >     &nresv_items, &cluster_items,  &service_items, NULL
2350    };
2351  
2352    dlink_list ** iterator = free_items; /* C is dumb */
# Line 2566 | Line 2363 | clear_out_old_conf(void)
2363        /* XXX This is less than pretty */
2364        if (conf->type == SERVER_TYPE)
2365        {
2366 <        aconf = (struct AccessItem *)map_to_conf(conf);
2366 >        aconf = map_to_conf(conf);
2367 >
2368          if (aconf->clients != 0)
2369          {
2370            SetConfIllegal(aconf);
# Line 2579 | Line 2377 | clear_out_old_conf(void)
2377        }
2378        else if (conf->type == OPER_TYPE)
2379        {
2380 <        aconf = (struct AccessItem *)map_to_conf(conf);
2380 >        aconf = map_to_conf(conf);
2381 >
2382          if (aconf->clients != 0)
2383          {
2384            SetConfIllegal(aconf);
# Line 2590 | Line 2389 | clear_out_old_conf(void)
2389            delete_conf_item(conf);
2390          }
2391        }
2593      else if (conf->type == CLIENT_TYPE)
2594      {
2595        aconf = (struct AccessItem *)map_to_conf(conf);
2596        if (aconf->clients != 0)
2597        {
2598          SetConfIllegal(aconf);
2599        }
2600        else
2601        {
2602          delete_conf_item(conf);
2603        }
2604      }
2392        else if (conf->type == XLINE_TYPE  ||
2393                 conf->type == RXLINE_TYPE ||
2394                 conf->type == RKLINE_TYPE)
# Line 2615 | Line 2402 | clear_out_old_conf(void)
2402        }
2403        else
2404        {
2618        if ((conf->type == LEAF_TYPE) || (conf->type == HUB_TYPE))
2619        {
2620          match_item = (struct MatchItem *)map_to_conf(conf);
2621          if ((match_item->ref_count <= 0))
2622            delete_conf_item(conf);
2623          else
2624          {
2625            match_item->illegal = 1;
2626            dlinkDelete(&conf->node, *iterator);
2627          }
2628        }
2629        else
2405            delete_conf_item(conf);
2406        }
2407      }
2408    }
2409  
2410 <  /* don't delete the class table, rather mark all entries
2410 >  /*
2411 >   * don't delete the class table, rather mark all entries
2412     * for deletion. The table is cleaned up by check_class. - avalon
2413     */
2414    DLINK_FOREACH(ptr, class_items.head)
2415    {
2416 <    conf = ptr->data;
2417 <    cltmp = (struct ClassItem *)map_to_conf(conf);
2416 >    cltmp = map_to_conf(ptr->data);
2417 >
2418      if (ptr != class_items.tail)  /* never mark the "default" class */
2419 <      MaxTotal(cltmp) = -1;
2419 >      cltmp->active = 0;
2420    }
2421  
2422    clear_out_address_conf();
2423  
2424    /* clean out module paths */
2649 #ifndef STATIC_MODULES
2425    mod_clear_paths();
2651 #endif
2426  
2427    /* clean out ServerInfo */
2428    MyFree(ServerInfo.description);
# Line 2668 | Line 2442 | clear_out_old_conf(void)
2442  
2443    MyFree(ServerInfo.rsa_private_key_file);
2444    ServerInfo.rsa_private_key_file = NULL;
2445 +
2446 +  if (ServerInfo.server_ctx)
2447 +    SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|
2448 +                                               SSL_OP_NO_SSLv3|
2449 +                                               SSL_OP_NO_TLSv1);
2450 +  if (ServerInfo.client_ctx)
2451 +    SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|
2452 +                                               SSL_OP_NO_SSLv3|
2453 +                                               SSL_OP_NO_TLSv1);
2454   #endif
2455  
2456    /* clean out old resvs from the conf */
# Line 2690 | Line 2473 | clear_out_old_conf(void)
2473     */
2474  
2475    /* clean out general */
2476 <  MyFree(ConfigFileEntry.servlink_path);
2477 <  ConfigFileEntry.servlink_path = NULL;
2478 < #ifdef HAVE_LIBCRYPTO
2696 <  ConfigFileEntry.default_cipher_preference = NULL;
2697 < #endif /* HAVE_LIBCRYPTO */
2476 >  MyFree(ConfigFileEntry.service_name);
2477 >  ConfigFileEntry.service_name = NULL;
2478 >
2479    delete_isupport("INVEX");
2480    delete_isupport("EXCEPTS");
2481   }
# Line 2755 | Line 2536 | get_conf_name(ConfType type)
2536      case KLINE_TYPE:
2537        return ConfigFileEntry.klinefile;
2538        break;
2758    case RKLINE_TYPE:
2759      return ConfigFileEntry.rklinefile;
2760      break;
2539      case DLINE_TYPE:
2540        return ConfigFileEntry.dlinefile;
2541        break;
2542      case XLINE_TYPE:
2543        return ConfigFileEntry.xlinefile;
2544        break;
2767    case RXLINE_TYPE:
2768      return ConfigFileEntry.rxlinefile;
2769      break;
2545      case CRESV_TYPE:
2546        return ConfigFileEntry.cresvfile;
2547        break;
2548      case NRESV_TYPE:
2549        return ConfigFileEntry.nresvfile;
2550        break;
2776    case GLINE_TYPE:
2777      return ConfigFileEntry.glinefile;
2778      break;
2779
2551      default:
2552        return NULL;  /* This should NEVER HAPPEN since we call this function
2553                         only with the above values, this will cause us to core
# Line 2805 | Line 2576 | get_conf_ping(struct ConfItem *conf, int
2576      if (aconf->class_ptr != NULL)
2577      {
2578        aclass = (struct ClassItem *)map_to_conf(aconf->class_ptr);
2579 <      *pingwarn = PingWarning(aclass);
2580 <      return PingFreq(aclass);
2579 >      *pingwarn = aclass->ping_warning;
2580 >      return aclass->ping_freq;
2581      }
2582    }
2583  
# Line 2822 | Line 2593 | get_conf_ping(struct ConfItem *conf, int
2593   const char *
2594   get_client_class(struct Client *target_p)
2595   {
2596 <  dlink_node *ptr;
2597 <  struct ConfItem *conf;
2827 <  struct AccessItem *aconf;
2596 >  dlink_node *cnode = NULL;
2597 >  struct AccessItem *aconf = NULL;
2598  
2599 <  if (target_p != NULL && !IsMe(target_p) &&
2600 <      target_p->localClient->confs.head != NULL)
2599 >  assert(!IsMe(target_p));
2600 >
2601 >  if ((cnode = target_p->localClient->confs.head))
2602    {
2603 <    DLINK_FOREACH(ptr, target_p->localClient->confs.head)
2833 <    {
2834 <      conf = ptr->data;
2603 >    struct ConfItem *conf = cnode->data;
2604  
2605 <      if (conf->type == CLIENT_TYPE || conf->type == SERVER_TYPE ||
2606 <          conf->type == OPER_TYPE)
2607 <      {
2608 <        aconf = (struct AccessItem *) map_to_conf(conf);
2609 <        if (aconf->class_ptr != NULL)
2610 <          return aconf->class_ptr->name;
2842 <      }
2843 <    }
2605 >    assert((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2606 >          (conf->type == OPER_TYPE));
2607 >
2608 >    aconf = map_to_conf(conf);
2609 >    if (aconf->class_ptr != NULL)
2610 >      return aconf->class_ptr->name;
2611    }
2612  
2613    return "default";
# Line 2856 | Line 2623 | get_client_class(struct Client *target_p
2623   int
2624   get_client_ping(struct Client *target_p, int *pingwarn)
2625   {
2626 <  int ping;
2627 <  struct ConfItem *conf;
2861 <  dlink_node *nlink;
2626 >  int ping = 0;
2627 >  dlink_node *cnode = NULL;
2628  
2629 <  if (target_p->localClient->confs.head != NULL)
2630 <    DLINK_FOREACH(nlink, target_p->localClient->confs.head)
2631 <    {
2866 <      conf = nlink->data;
2629 >  if ((cnode = target_p->localClient->confs.head))
2630 >  {
2631 >    struct ConfItem *conf = cnode->data;
2632  
2633 <      if ((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2634 <          (conf->type == OPER_TYPE))
2635 <      {
2636 <        ping = get_conf_ping(conf, pingwarn);
2637 <        if (ping > 0)
2638 <          return ping;
2639 <      }
2875 <    }
2633 >    assert((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2634 >          (conf->type == OPER_TYPE));
2635 >
2636 >    ping = get_conf_ping(conf, pingwarn);
2637 >    if (ping > 0)
2638 >      return ping;
2639 >  }
2640  
2641    *pingwarn = 0;
2642    return DEFAULT_PINGFREQUENCY;
# Line 2889 | Line 2653 | find_class(const char *classname)
2653   {
2654    struct ConfItem *conf;
2655  
2656 <  if ((conf = find_exact_name_conf(CLASS_TYPE, classname, NULL, NULL)) != NULL)
2657 <    return(conf);
2656 >  if ((conf = find_exact_name_conf(CLASS_TYPE, NULL, classname, NULL, NULL)) != NULL)
2657 >    return conf;
2658  
2659    return class_default;
2660   }
# Line 2904 | Line 2668 | find_class(const char *classname)
2668   void
2669   check_class(void)
2670   {
2671 <  dlink_node *ptr;
2908 <  dlink_node *next_ptr;
2909 <  struct ConfItem *conf;
2910 <  struct ClassItem *aclass;
2671 >  dlink_node *ptr = NULL, *next_ptr = NULL;
2672  
2673    DLINK_FOREACH_SAFE(ptr, next_ptr, class_items.head)
2674    {
2675 <    conf = ptr->data;
2915 <    aclass = (struct ClassItem *)map_to_conf(conf);
2675 >    struct ClassItem *aclass = map_to_conf(ptr->data);
2676  
2677 <    if (MaxTotal(aclass) < 0)
2677 >    if (!aclass->active && !aclass->curr_user_count)
2678      {
2679        destroy_cidr_class(aclass);
2680 <      if (CurrUserCount(aclass) > 0)
2921 <        dlinkDelete(&conf->node, &class_items);
2922 <      else
2923 <        delete_conf_item(conf);
2680 >      delete_conf_item(ptr->data);
2681      }
2682    }
2683   }
# Line 2937 | Line 2694 | init_class(void)
2694    struct ClassItem *aclass;
2695  
2696    class_default = make_conf_item(CLASS_TYPE);
2697 <  aclass = (struct ClassItem *)map_to_conf(class_default);
2697 >
2698 >  aclass = map_to_conf(class_default);
2699 >  aclass->active = 1;
2700    DupString(class_default->name, "default");
2701 <  ConFreq(aclass)  = DEFAULT_CONNECTFREQUENCY;
2702 <  PingFreq(aclass) = DEFAULT_PINGFREQUENCY;
2703 <  MaxTotal(aclass) = MAXIMUM_LINKS_DEFAULT;
2704 <  MaxSendq(aclass) = DEFAULT_SENDQ;
2701 >  aclass->con_freq  = DEFAULT_CONNECTFREQUENCY;
2702 >  aclass->ping_freq = DEFAULT_PINGFREQUENCY;
2703 >  aclass->max_total = MAXIMUM_LINKS_DEFAULT;
2704 >  aclass->max_sendq = DEFAULT_SENDQ;
2705 >  aclass->max_recvq = DEFAULT_RECVQ;
2706  
2707    client_check_cb = register_callback("check_client", check_client);
2708   }
# Line 2953 | Line 2713 | init_class(void)
2713   * output       - sendq for this client as found from its class
2714   * side effects - NONE
2715   */
2716 < unsigned long
2716 > unsigned int
2717   get_sendq(struct Client *client_p)
2718   {
2719 <  unsigned long sendq = DEFAULT_SENDQ;
2720 <  dlink_node *ptr;
2961 <  struct ConfItem *conf;
2719 >  unsigned int sendq = DEFAULT_SENDQ;
2720 >  dlink_node *cnode;
2721    struct ConfItem *class_conf;
2722    struct ClassItem *aclass;
2723    struct AccessItem *aconf;
2724  
2725 <  if (client_p && !IsMe(client_p) && (client_p->localClient->confs.head))
2725 >  assert(!IsMe(client_p));
2726 >
2727 >  if ((cnode = client_p->localClient->confs.head))
2728    {
2729 <    DLINK_FOREACH(ptr, client_p->localClient->confs.head)
2730 <    {
2731 <      conf = ptr->data;
2732 <      if ((conf->type == SERVER_TYPE) || (conf->type == OPER_TYPE)
2733 <          || (conf->type == CLIENT_TYPE))
2734 <      {
2735 <        aconf = (struct AccessItem *)map_to_conf(conf);
2736 <        if ((class_conf = aconf->class_ptr) == NULL)
2737 <          continue;
2738 <        aclass = (struct ClassItem *)map_to_conf(class_conf);
2739 <        sendq = MaxSendq(aclass);
2740 <        return sendq;
2741 <      }
2981 <    }
2729 >    struct ConfItem *conf = cnode->data;
2730 >
2731 >    assert((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2732 >          (conf->type == OPER_TYPE));
2733 >
2734 >    aconf = map_to_conf(conf);
2735 >
2736 >    if ((class_conf = aconf->class_ptr) == NULL)
2737 >      return DEFAULT_SENDQ; /* TBV: shouldn't be possible at all */
2738 >
2739 >    aclass = map_to_conf(class_conf);
2740 >    sendq = aclass->max_sendq;
2741 >    return sendq;
2742    }
2743 +
2744    /* XXX return a default?
2745     * if here, then there wasn't an attached conf with a sendq
2746     * that is very bad -Dianora
# Line 2987 | Line 2748 | get_sendq(struct Client *client_p)
2748    return DEFAULT_SENDQ;
2749   }
2750  
2751 + unsigned int
2752 + get_recvq(struct Client *client_p)
2753 + {
2754 +  unsigned int recvq = DEFAULT_RECVQ;
2755 +  dlink_node *cnode;
2756 +  struct ConfItem *class_conf;
2757 +  struct ClassItem *aclass;
2758 +  struct AccessItem *aconf;
2759 +
2760 +  assert(!IsMe(client_p));
2761 +
2762 +  if ((cnode = client_p->localClient->confs.head))
2763 +  {
2764 +    struct ConfItem *conf = cnode->data;
2765 +
2766 +    assert((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2767 +          (conf->type == OPER_TYPE));
2768 +
2769 +    aconf = map_to_conf(conf);
2770 +
2771 +    if ((class_conf = aconf->class_ptr) == NULL)
2772 +      return DEFAULT_RECVQ; /* TBV: shouldn't be possible at all */
2773 +
2774 +    aclass = map_to_conf(class_conf);
2775 +    recvq = aclass->max_recvq;
2776 +    return recvq;
2777 +  }
2778 +
2779 +  /* XXX return a default?
2780 +   * if here, then there wasn't an attached conf with a recvq
2781 +   * that is very bad -Dianora
2782 +   */
2783 +  return DEFAULT_RECVQ;
2784 + }
2785 +
2786   /* conf_add_class_to_conf()
2787   *
2788   * inputs       - pointer to config item
# Line 2996 | Line 2792 | get_sendq(struct Client *client_p)
2792   void
2793   conf_add_class_to_conf(struct ConfItem *conf, const char *class_name)
2794   {
2795 <  struct AccessItem *aconf;
2796 <  struct ClassItem *aclass;
3001 <
3002 <  aconf = (struct AccessItem *)map_to_conf(conf);
2795 >  struct AccessItem *aconf = map_to_conf(conf);
2796 >  struct ClassItem *class = NULL;
2797  
2798    if (class_name == NULL)
2799    {
2800      aconf->class_ptr = class_default;
2801 +
2802      if (conf->type == CLIENT_TYPE)
2803        sendto_realops_flags(UMODE_ALL, L_ALL,
2804                             "Warning *** Defaulting to default class for %s@%s",
# Line 3014 | Line 2809 | conf_add_class_to_conf(struct ConfItem *
2809                             conf->name);
2810    }
2811    else
3017  {
2812      aconf->class_ptr = find_class(class_name);
3019  }
2813  
2814 <  if (aconf->class_ptr == NULL)
2814 >  if (aconf->class_ptr)
2815 >    class = map_to_conf(aconf->class_ptr);
2816 >
2817 >  if (aconf->class_ptr == NULL || !class->active)
2818    {
2819      if (conf->type == CLIENT_TYPE)
2820        sendto_realops_flags(UMODE_ALL, L_ALL,
# Line 3030 | Line 2826 | conf_add_class_to_conf(struct ConfItem *
2826                             conf->name);
2827      aconf->class_ptr = class_default;
2828    }
3033  else
3034  {
3035    aclass = (struct ClassItem *)map_to_conf(aconf->class_ptr);
3036    if (MaxTotal(aclass) < 0)
3037    {
3038      aconf->class_ptr = class_default;
3039    }
3040  }
2829   }
2830  
3043 #define MAXCONFLINKS 150
3044
2831   /* conf_add_server()
2832   *
2833   * inputs       - pointer to config item
# Line 3050 | Line 2836 | conf_add_class_to_conf(struct ConfItem *
2836   * side effects - Add a connect block
2837   */
2838   int
2839 < conf_add_server(struct ConfItem *conf, unsigned int lcount, const char *class_name)
2839 > conf_add_server(struct ConfItem *conf, const char *class_name)
2840   {
2841 <  struct AccessItem *aconf;
3056 <  char *orig_host;
3057 <
3058 <  aconf = map_to_conf(conf);
2841 >  struct AccessItem *aconf = map_to_conf(conf);
2842  
2843    conf_add_class_to_conf(conf, class_name);
2844  
2845 <  if (lcount > MAXCONFLINKS || !aconf->host || !conf->name)
2845 >  if (!aconf->host || !conf->name)
2846    {
2847      sendto_realops_flags(UMODE_ALL, L_ALL, "Bad connect block");
2848 <    ilog(L_WARN, "Bad connect block");
2848 >    ilog(LOG_TYPE_IRCD, "Bad connect block");
2849      return -1;
2850    }
2851  
2852 <  if (EmptyString(aconf->passwd) && !IsConfCryptLink(aconf))
2852 >  if (EmptyString(aconf->passwd))
2853    {
2854      sendto_realops_flags(UMODE_ALL, L_ALL, "Bad connect block, name %s",
2855                           conf->name);
2856 <    ilog(L_WARN, "Bad connect block, host %s", conf->name);
2856 >    ilog(LOG_TYPE_IRCD, "Bad connect block, host %s", conf->name);
2857      return -1;
2858    }
2859  
3077  orig_host = aconf->host;
3078  split_nuh(orig_host, NULL, &aconf->user, &aconf->host);
3079  MyFree(orig_host);
2860    lookup_confhost(conf);
2861  
2862    return 0;
2863   }
2864  
3085 /* conf_add_d_conf()
3086 *
3087 * inputs       - pointer to config item
3088 * output       - NONE
3089 * side effects - Add a d/D line
3090 */
3091 void
3092 conf_add_d_conf(struct AccessItem *aconf)
3093 {
3094  if (aconf->host == NULL)
3095    return;
3096
3097  aconf->user = NULL;
3098
3099  /* XXX - Should 'd' ever be in the old conf? For new conf we don't
3100   *       need this anyway, so I will disable it for now... -A1kmm
3101   */
3102  if (parse_netmask(aconf->host, NULL, NULL) == HM_HOST)
3103  {
3104    ilog(L_WARN, "Invalid Dline %s ignored", aconf->host);
3105    free_access_item(aconf);
3106  }
3107  else
3108  {
3109    /* XXX ensure user is NULL */
3110    MyFree(aconf->user);
3111    aconf->user = NULL;
3112    add_conf_by_address(CONF_DLINE, aconf);
3113  }
3114 }
3115
2865   /* yyerror()
2866   *
2867   * inputs       - message from parser
# Line 3124 | Line 2873 | yyerror(const char *msg)
2873   {
2874    char newlinebuf[IRCD_BUFSIZE];
2875  
2876 <  if (ypass != 1)
2876 >  if (conf_parser_ctx.pass != 1)
2877      return;
2878  
2879    strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
2880    sendto_realops_flags(UMODE_ALL, L_ALL, "\"%s\", line %u: %s: %s",
2881                         conffilebuf, lineno + 1, msg, newlinebuf);
2882 <  ilog(L_WARN, "\"%s\", line %u: %s: %s",
2882 >  ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
2883         conffilebuf, lineno + 1, msg, newlinebuf);
2884   }
2885  
3137 int
3138 conf_fbgets(char *lbuf, unsigned int max_size, FBFILE *fb)
3139 {
3140  if (fbgets(lbuf, max_size, fb) == NULL)
3141    return 0;
3142
3143  return strlen(lbuf);
3144 }
3145
3146 int
3147 conf_yy_fatal_error(const char *msg)
3148 {
3149  return 0;
3150 }
3151
2886   /*
2887   * valid_tkline()
2888   *
# Line 3160 | Line 2894 | conf_yy_fatal_error(const char *msg)
2894   * Originally written by Dianora (Diane, db@db.net)
2895   */
2896   time_t
2897 < valid_tkline(char *p, int minutes)
2897 > valid_tkline(const char *p, int minutes)
2898   {
2899    time_t result = 0;
2900  
2901 <  while (*p)
2901 >  for (; *p; ++p)
2902    {
2903 <    if (IsDigit(*p))
3170 <    {
3171 <      result *= 10;
3172 <      result += ((*p) & 0xF);
3173 <      p++;
3174 <    }
3175 <    else
2903 >    if (!IsDigit(*p))
2904        return 0;
2905 +
2906 +    result *= 10;
2907 +    result += ((*p) & 0xF);
2908    }
2909  
2910 <  /* in the degenerate case where oper does a /quote kline 0 user@host :reason
2910 >  /*
2911 >   * In the degenerate case where oper does a /quote kline 0 user@host :reason
2912     * i.e. they specifically use 0, I am going to return 1 instead
2913     * as a return value of non-zero is used to flag it as a temporary kline
2914     */
3183
2915    if (result == 0)
2916      result = 1;
2917  
# Line 3281 | Line 3012 | valid_wild_card(struct Client *source_p,
3012   *                if target_server is NULL and an "ON" is found error
3013   *                is reported.
3014   *                if reason pointer is NULL ignore pointer,
3015 < *                this allows usee of parse_a_line in unkline etc.
3015 > *                this allows use of parse_a_line in unkline etc.
3016   *
3017   * - Dianora
3018   */
# Line 3351 | Line 3082 | parse_aline(const char *cmd, struct Clie
3082          return -1;
3083        }
3084  
3085 <      if (!IsOperRemoteBan(source_p))
3085 >      if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN))
3086        {
3087          sendto_one(source_p, form_str(ERR_NOPRIVS),
3088                     me.name, source_p->name, "remoteban");
# Line 3388 | Line 3119 | parse_aline(const char *cmd, struct Clie
3119        return -1;
3120      }
3121  
3122 <    if ((parse_flags & AWILD) && !valid_wild_card(source_p, YES, 2, *up_p, *h_p))
3122 >    if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 2, *up_p, *h_p))
3123        return -1;
3124    }
3125    else
3126 <    if ((parse_flags & AWILD) && !valid_wild_card(source_p, YES, 1, *up_p))
3126 >    if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 1, *up_p))
3127        return -1;
3128  
3129    if (reason != NULL)
3130    {
3131 <    if (parc != 0)
3131 >    if (parc != 0 && !EmptyString(*parv))
3132      {
3133        *reason = *parv;
3134 <      if (!valid_comment(source_p, *reason, YES))
3134 >      if (!valid_comment(source_p, *reason, 1))
3135          return -1;
3136      }
3137      else
# Line 3436 | Line 3167 | find_user_host(struct Client *source_p,
3167    {
3168      /* Explicit user@host mask given */
3169  
3170 <    if(hostp != NULL)                            /* I'm a little user@host */
3170 >    if (hostp != NULL)                            /* I'm a little user@host */
3171      {
3172        *(hostp++) = '\0';                       /* short and squat */
3173        if (*user_host_or_nick)
# Line 3457 | Line 3188 | find_user_host(struct Client *source_p,
3188      
3189      return 1;
3190    }
3191 <  else if (!(flags & NOUSERLOOKUP))
3191 >  else
3192    {
3193      /* Try to find user@host mask from nick */
3194      /* Okay to use source_p as the first param, because source_p == client_p */
# Line 3531 | Line 3262 | match_conf_password(const char *password
3262   {
3263    const char *encr = NULL;
3264  
3265 <  if (password == NULL || aconf->passwd == NULL)
3265 >  if (EmptyString(password) || EmptyString(aconf->passwd))
3266      return 0;
3267  
3268    if (aconf->flags & CONF_FLAGS_ENCRYPTED)
3269 <  {
3539 <    /* use first two chars of the password they send in as salt */
3540 <    /* If the password in the conf is MD5, and ircd is linked
3541 <     * to scrypt on FreeBSD, or the standard crypt library on
3542 <     * glibc Linux, then this code will work fine on generating
3543 <     * the proper encrypted hash for comparison.
3544 <     */
3545 <    if (*aconf->passwd)
3546 <      encr = crypt(password, aconf->passwd);
3547 <    else
3548 <      encr = "";
3549 <  }
3269 >    encr = crypt(password, aconf->passwd);
3270    else
3271      encr = password;
3272  
# Line 3559 | Line 3279 | match_conf_password(const char *password
3279   * inputs       - client sending the cluster
3280   *              - command name "KLINE" "XLINE" etc.
3281   *              - capab -- CAP_KLN etc. from s_serv.h
3282 < *              - cluster type -- CLUSTER_KLINE etc. from s_conf.h
3282 > *              - cluster type -- CLUSTER_KLINE etc. from conf.h
3283   *              - pattern and args to send along
3284   * output       - none
3285   * side effects - Take source_p send the pattern with args given
# Line 3567 | Line 3287 | match_conf_password(const char *password
3287   */
3288   void
3289   cluster_a_line(struct Client *source_p, const char *command,
3290 <               int capab, int cluster_type, const char *pattern, ...)
3290 >               int capab, int cluster_type, const char *pattern, ...)
3291   {
3292    va_list args;
3293    char buffer[IRCD_BUFSIZE];
3294 <  struct ConfItem *conf;
3575 <  dlink_node *ptr;
3294 >  const dlink_node *ptr = NULL;
3295  
3296    va_start(args, pattern);
3297    vsnprintf(buffer, sizeof(buffer), pattern, args);
# Line 3580 | Line 3299 | cluster_a_line(struct Client *source_p,
3299  
3300    DLINK_FOREACH(ptr, cluster_items.head)
3301    {
3302 <    conf = ptr->data;
3302 >    const struct ConfItem *conf = ptr->data;
3303  
3304      if (conf->flags & cluster_type)
3586    {
3305        sendto_match_servs(source_p, conf->name, CAP_CLUSTER|capab,
3306                           "%s %s %s", command, conf->name, buffer);
3589    }
3307    }
3308   }
3309  
# Line 3618 | Line 3335 | cluster_a_line(struct Client *source_p,
3335   * @                            *       *       *
3336   * !                            *       *       *
3337   */
3621
3338   void
3339 < split_nuh(char *mask, char **nick, char **user, char **host)
3339 > split_nuh(struct split_nuh_item *const iptr)
3340   {
3341    char *p = NULL, *q = NULL;
3342  
3343 <  if ((p = strchr(mask, '!')) != NULL)
3343 >  if (iptr->nickptr)
3344 >    strlcpy(iptr->nickptr, "*", iptr->nicksize);
3345 >  if (iptr->userptr)
3346 >    strlcpy(iptr->userptr, "*", iptr->usersize);
3347 >  if (iptr->hostptr)
3348 >    strlcpy(iptr->hostptr, "*", iptr->hostsize);
3349 >
3350 >  if ((p = strchr(iptr->nuhmask, '!')))
3351    {
3352      *p = '\0';
3630    if (nick != NULL)
3631    {
3632      if (*mask != '\0')
3633        *nick = xstrldup(mask, NICKLEN);
3634      else
3635        DupString(*nick, "*");
3636    }
3353  
3354 <    if ((q = strchr(++p, '@')) != NULL)
3355 <    {
3356 <      *q = '\0';
3354 >    if (iptr->nickptr && *iptr->nuhmask != '\0')
3355 >      strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
3356 >
3357 >    if ((q = strchr(++p, '@'))) {
3358 >      *q++ = '\0';
3359  
3360        if (*p != '\0')
3361 <        *user = xstrldup(p, USERLEN+1);
3644 <      else
3645 <        DupString(*user, "*");
3361 >        strlcpy(iptr->userptr, p, iptr->usersize);
3362  
3363 <      if (*++q != '\0')
3364 <        *host = xstrldup(q, HOSTLEN+1);
3649 <      else
3650 <        DupString(*host, "*");
3363 >      if (*q != '\0')
3364 >        strlcpy(iptr->hostptr, q, iptr->hostsize);
3365      }
3366      else
3367      {
3368        if (*p != '\0')
3369 <        *user = xstrldup(p, USERLEN+1);
3656 <      else
3657 <        DupString(*user, "*");
3658 <
3659 <      DupString(*host, "*");
3369 >        strlcpy(iptr->userptr, p, iptr->usersize);
3370      }
3371    }
3372 <  else  /* No ! found so lets look for a user@host */
3372 >  else
3373    {
3374 <    if ((p = strchr(mask, '@')) != NULL)        /* if found a @ */
3374 >    /* No ! found so lets look for a user@host */
3375 >    if ((p = strchr(iptr->nuhmask, '@')))
3376      {
3377 <      if (nick != NULL)
3378 <        DupString(*nick, "*");
3668 <      *p = '\0';
3377 >      /* if found a @ */
3378 >      *p++ = '\0';
3379  
3380 <      if (*mask != '\0')
3381 <        *user = xstrldup(mask, USERLEN+1);
3672 <      else
3673 <        DupString(*user, "*");
3380 >      if (*iptr->nuhmask != '\0')
3381 >        strlcpy(iptr->userptr, iptr->nuhmask, iptr->usersize);
3382  
3383 <      if (*++p != '\0')
3384 <        *host = xstrldup(p, HOSTLEN+1);
3677 <      else
3678 <        DupString(*host, "*");
3383 >      if (*p != '\0')
3384 >        strlcpy(iptr->hostptr, p, iptr->hostsize);
3385      }
3386 <    else                                        /* no @ found */
3386 >    else
3387      {
3388 <      if (nick != NULL)
3389 <      {
3390 <        if (strpbrk(mask, ".:"))
3685 <        {
3686 <          DupString(*nick, "*");
3687 <          *host = xstrldup(mask, HOSTLEN+1);
3688 <        }
3689 <        else
3690 <        {
3691 <          *nick = xstrldup(mask, NICKLEN);
3692 <          DupString(*host, "*");
3693 <        }
3694 <
3695 <        DupString(*user, "*");
3696 <      }
3388 >      /* no @ found */
3389 >      if (!iptr->nickptr || strpbrk(iptr->nuhmask, ".:"))
3390 >        strlcpy(iptr->hostptr, iptr->nuhmask, iptr->hostsize);
3391        else
3392 <      {
3699 <        DupString(*user, "*");
3700 <        *host = xstrldup(mask, HOSTLEN+1);
3701 <      }
3392 >        strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
3393      }
3394    }
3395   }
# Line 3725 | Line 3416 | flags_to_ascii(unsigned int flags, const
3416    {
3417      if (flags & mask)
3418        *p++ = bit_table[i];
3419 <    else if(lowerit)
3419 >    else if (lowerit)
3420        *p++ = ToLower(bit_table[i]);
3421    }
3422    *p = '\0';
# Line 3748 | Line 3439 | cidr_limit_reached(int over_rule,
3439    dlink_node *ptr = NULL;
3440    struct CidrItem *cidr;
3441  
3442 <  if (NumberPerCidr(aclass) <= 0)
3442 >  if (aclass->number_per_cidr <= 0)
3443      return 0;
3444  
3445    if (ip->ss.ss_family == AF_INET)
3446    {
3447 <    if (CidrBitlenIPV4(aclass) <= 0)
3447 >    if (aclass->cidr_bitlen_ipv4 <= 0)
3448        return 0;
3449  
3450      DLINK_FOREACH(ptr, aclass->list_ipv4.head)
3451      {
3452        cidr = ptr->data;
3453 <      if (match_ipv4(ip, &cidr->mask, CidrBitlenIPV4(aclass)))
3453 >      if (match_ipv4(ip, &cidr->mask, aclass->cidr_bitlen_ipv4))
3454        {
3455 <        if (!over_rule && (cidr->number_on_this_cidr >= NumberPerCidr(aclass)))
3455 >        if (!over_rule && (cidr->number_on_this_cidr >= aclass->number_per_cidr))
3456            return -1;
3457          cidr->number_on_this_cidr++;
3458          return 0;
# Line 3770 | Line 3461 | cidr_limit_reached(int over_rule,
3461      cidr = MyMalloc(sizeof(struct CidrItem));
3462      cidr->number_on_this_cidr = 1;
3463      cidr->mask = *ip;
3464 <    mask_addr(&cidr->mask, CidrBitlenIPV4(aclass));
3464 >    mask_addr(&cidr->mask, aclass->cidr_bitlen_ipv4);
3465      dlinkAdd(cidr, &cidr->node, &aclass->list_ipv4);
3466    }
3467   #ifdef IPV6
3468 <  else if (CidrBitlenIPV6(aclass) > 0)
3468 >  else if (aclass->cidr_bitlen_ipv6 > 0)
3469    {
3470      DLINK_FOREACH(ptr, aclass->list_ipv6.head)
3471      {
3472        cidr = ptr->data;
3473 <      if (match_ipv6(ip, &cidr->mask, CidrBitlenIPV6(aclass)))
3473 >      if (match_ipv6(ip, &cidr->mask, aclass->cidr_bitlen_ipv6))
3474        {
3475 <        if (!over_rule && (cidr->number_on_this_cidr >= NumberPerCidr(aclass)))
3475 >        if (!over_rule && (cidr->number_on_this_cidr >= aclass->number_per_cidr))
3476            return -1;
3477          cidr->number_on_this_cidr++;
3478          return 0;
# Line 3790 | Line 3481 | cidr_limit_reached(int over_rule,
3481      cidr = MyMalloc(sizeof(struct CidrItem));
3482      cidr->number_on_this_cidr = 1;
3483      cidr->mask = *ip;
3484 <    mask_addr(&cidr->mask, CidrBitlenIPV6(aclass));
3484 >    mask_addr(&cidr->mask, aclass->cidr_bitlen_ipv6);
3485      dlinkAdd(cidr, &cidr->node, &aclass->list_ipv6);
3486    }
3487   #endif
# Line 3812 | Line 3503 | remove_from_cidr_check(struct irc_ssaddr
3503    dlink_node *next_ptr = NULL;
3504    struct CidrItem *cidr;
3505  
3506 <  if (NumberPerCidr(aclass) == 0)
3506 >  if (aclass->number_per_cidr == 0)
3507      return;
3508  
3509    if (ip->ss.ss_family == AF_INET)
3510    {
3511 <    if (CidrBitlenIPV4(aclass) <= 0)
3511 >    if (aclass->cidr_bitlen_ipv4 <= 0)
3512        return;
3513  
3514      DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv4.head)
3515      {
3516        cidr = ptr->data;
3517 <      if (match_ipv4(ip, &cidr->mask, CidrBitlenIPV4(aclass)))
3517 >      if (match_ipv4(ip, &cidr->mask, aclass->cidr_bitlen_ipv4))
3518        {
3519          cidr->number_on_this_cidr--;
3520          if (cidr->number_on_this_cidr == 0)
# Line 3836 | Line 3527 | remove_from_cidr_check(struct irc_ssaddr
3527      }
3528    }
3529   #ifdef IPV6
3530 <  else if (CidrBitlenIPV6(aclass) > 0)
3530 >  else if (aclass->cidr_bitlen_ipv6 > 0)
3531    {
3532      DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv6.head)
3533      {
3534        cidr = ptr->data;
3535 <      if (match_ipv6(ip, &cidr->mask, CidrBitlenIPV6(aclass)))
3535 >      if (match_ipv6(ip, &cidr->mask, aclass->cidr_bitlen_ipv6))
3536        {
3537          cidr->number_on_this_cidr--;
3538          if (cidr->number_on_this_cidr == 0)
# Line 3904 | Line 3595 | rebuild_cidr_class(struct ConfItem *conf
3595   {
3596    struct ClassItem *old_class = map_to_conf(conf);
3597  
3598 <  if (NumberPerCidr(old_class) > 0 && NumberPerCidr(new_class) > 0)
3598 >  if (old_class->number_per_cidr > 0 && new_class->number_per_cidr > 0)
3599    {
3600 <    if (CidrBitlenIPV4(old_class) > 0 && CidrBitlenIPV4(new_class) > 0)
3600 >    if (old_class->cidr_bitlen_ipv4 > 0 && new_class->cidr_bitlen_ipv4 > 0)
3601        rebuild_cidr_list(AF_INET, conf, new_class,
3602                          &old_class->list_ipv4, &new_class->list_ipv4,
3603 <                        CidrBitlenIPV4(old_class) != CidrBitlenIPV4(new_class));
3603 >                        old_class->cidr_bitlen_ipv4 != new_class->cidr_bitlen_ipv4);
3604  
3605   #ifdef IPV6
3606 <    if (CidrBitlenIPV6(old_class) > 0 && CidrBitlenIPV6(new_class) > 0)
3606 >    if (old_class->cidr_bitlen_ipv6 > 0 && new_class->cidr_bitlen_ipv6 > 0)
3607        rebuild_cidr_list(AF_INET6, conf, new_class,
3608                          &old_class->list_ipv6, &new_class->list_ipv6,
3609 <                        CidrBitlenIPV6(old_class) != CidrBitlenIPV6(new_class));
3609 >                        old_class->cidr_bitlen_ipv6 != new_class->cidr_bitlen_ipv6);
3610   #endif
3611    }
3612  
# Line 3932 | Line 3623 | rebuild_cidr_class(struct ConfItem *conf
3623   static void
3624   destroy_cidr_list(dlink_list *list)
3625   {
3626 <  dlink_node *ptr = NULL;
3936 <  dlink_node *next_ptr = NULL;
3937 <  struct CidrItem *cidr;
3626 >  dlink_node *ptr = NULL, *next_ptr = NULL;
3627  
3628    DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
3629    {
3941    cidr = ptr->data;
3630      dlinkDelete(ptr, list);
3631 <    MyFree(cidr);
3631 >    MyFree(ptr->data);
3632    }
3633   }
3634  

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)