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 1444 by michael, Sat Jun 23 18:12:16 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 74 | Line 68 | dlink_list nresv_items   = { NULL, NULL,
68   dlink_list class_items   = { NULL, NULL, 0 };
69   dlink_list gdeny_items   = { NULL, NULL, 0 };
70  
77 dlink_list temporary_klines  = { NULL, NULL, 0 };
78 dlink_list temporary_dlines  = { NULL, NULL, 0 };
71   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 };
72   dlink_list temporary_resv = { NULL, NULL, 0 };
73  
74   extern unsigned int lineno;
75   extern char linebuf[];
76   extern char conffilebuf[IRCD_BUFSIZE];
88 extern char yytext[];
77   extern int yyparse(); /* defined in y.tab.c */
78 < unsigned int scount = 0; /* used by yyparse(), etc */
79 < int ypass  = 1; /* used by yyparse()      */
78 >
79 > struct conf_parser_context conf_parser_ctx = { 0, 0, NULL };
80  
81   /* internally defined functions */
82 < 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 *);
82 > static void read_conf(FILE *);
83   static void clear_out_old_conf(void);
84   static void flush_deleted_I_P(void);
85   static void expire_tklines(dlink_list *);
# Line 117 | Line 102 | static void destroy_cidr_class(struct Cl
102  
103   static void flags_to_ascii(unsigned int, const unsigned int[], char *, int);
104  
120 FBFILE *conf_fbfile_in = NULL;
121
105   /* address of default class conf */
106   static struct ConfItem *class_default;
107  
# Line 141 | Line 124 | static BlockHeap *ip_entry_heap = NULL;
124   static int ip_entries_count = 0;
125  
126  
127 < inline void *
127 > void *
128   map_to_conf(struct ConfItem *aconf)
129   {
130    void *conf;
131 <  conf = (void *)((unsigned long)aconf +
132 <                  (unsigned long)sizeof(struct ConfItem));
131 >  conf = (void *)((uintptr_t)aconf +
132 >                  (uintptr_t)sizeof(struct ConfItem));
133    return(conf);
134   }
135  
136 < inline struct ConfItem *
136 > struct ConfItem *
137   unmap_conf_item(void *aconf)
138   {
139    struct ConfItem *conf;
140  
141 <  conf = (struct ConfItem *)((unsigned long)aconf -
142 <                             (unsigned long)sizeof(struct ConfItem));
141 >  conf = (struct ConfItem *)((uintptr_t)aconf -
142 >                             (uintptr_t)sizeof(struct ConfItem));
143    return(conf);
144   }
145  
# Line 171 | Line 154 | unmap_conf_item(void *aconf)
154   * if successful save hp in the conf item it was called with
155   */
156   static void
157 < conf_dns_callback(void *vptr, struct DNSReply *reply)
157 > conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name)
158   {
159 <  struct AccessItem *aconf = (struct AccessItem *)vptr;
177 <  struct ConfItem *conf;
159 >  struct AccessItem *aconf = vptr;
160  
161 <  MyFree(aconf->dns_query);
180 <  aconf->dns_query = NULL;
161 >  aconf->dns_pending = 0;
162  
163 <  if (reply != NULL)
164 <    memcpy(&aconf->ipnum, &reply->addr, sizeof(reply->addr));
165 <  else {
166 <    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 <  }
163 >  if (addr != NULL)
164 >    memcpy(&aconf->addr, addr, sizeof(aconf->addr));
165 >  else
166 >    aconf->dns_failed = 1;
167   }
168  
169   /* conf_dns_lookup()
# Line 201 | Line 175 | conf_dns_callback(void *vptr, struct DNS
175   static void
176   conf_dns_lookup(struct AccessItem *aconf)
177   {
178 <  if (aconf->dns_query == NULL)
178 >  if (!aconf->dns_pending)
179    {
180 <    aconf->dns_query = MyMalloc(sizeof(struct DNSQuery));
181 <    aconf->dns_query->ptr = aconf;
208 <    aconf->dns_query->callback = conf_dns_callback;
209 <    gethost_byname(aconf->host, aconf->dns_query);
180 >    aconf->dns_pending = 1;
181 >    gethost_byname(conf_dns_callback, aconf, aconf->host);
182    }
183   }
184  
# Line 277 | Line 249 | make_conf_item(ConfType type)
249      aconf->status = status;
250      break;
251  
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
252    case ULINE_TYPE:
253      conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
254                                         sizeof(struct MatchItem));
# Line 306 | Line 266 | make_conf_item(ConfType type)
266                                         sizeof(struct MatchItem));
267      dlinkAdd(conf, &conf->node, &xconf_items);
268      break;
269 <
269 > #ifdef HAVE_LIBPCRE
270    case RXLINE_TYPE:
271      conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
272                                         sizeof(struct MatchItem));
# Line 320 | Line 280 | make_conf_item(ConfType type)
280      aconf->status = CONF_KLINE;
281      dlinkAdd(conf, &conf->node, &rkconf_items);
282      break;
283 <
283 > #endif
284    case CLUSTER_TYPE:
285      conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem));
286      dlinkAdd(conf, &conf->node, &cluster_items);
# Line 337 | Line 297 | make_conf_item(ConfType type)
297      dlinkAdd(conf, &conf->node, &nresv_items);
298      break;
299  
300 +  case SERVICE_TYPE:
301 +    status = CONF_SERVICE;
302 +    conf = MyMalloc(sizeof(struct ConfItem));
303 +    dlinkAdd(conf, &conf->node, &service_items);
304 +    break;
305 +
306    case CLASS_TYPE:
307 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
308 <                                       sizeof(struct ClassItem));
307 >    conf = MyMalloc(sizeof(struct ConfItem) +
308 >                           sizeof(struct ClassItem));
309      dlinkAdd(conf, &conf->node, &class_items);
310 <    aclass = (struct ClassItem *)map_to_conf(conf);
311 <    ConFreq(aclass)  = DEFAULT_CONNECTFREQUENCY;
312 <    PingFreq(aclass) = DEFAULT_PINGFREQUENCY;
313 <    MaxTotal(aclass) = MAXIMUM_LINKS_DEFAULT;
314 <    MaxSendq(aclass) = DEFAULT_SENDQ;
315 <    CurrUserCount(aclass) = 0;
310 >
311 >    aclass = map_to_conf(conf);
312 >    aclass->active = 1;
313 >    aclass->con_freq = DEFAULT_CONNECTFREQUENCY;
314 >    aclass->ping_freq = DEFAULT_PINGFREQUENCY;
315 >    aclass->max_total = MAXIMUM_LINKS_DEFAULT;
316 >    aclass->max_sendq = DEFAULT_SENDQ;
317 >
318      break;
319  
320    default:
# Line 357 | Line 325 | make_conf_item(ConfType type)
325    /* XXX Yes, this will core if default is hit. I want it to for now - db */
326    conf->type = type;
327  
328 <  return(conf);
328 >  return conf;
329   }
330  
331   void
332   delete_conf_item(struct ConfItem *conf)
333   {
334 +  dlink_node *m = NULL, *m_next = NULL;
335    struct MatchItem *match_item;
336    struct AccessItem *aconf;
337    ConfType type = conf->type;
# Line 381 | Line 350 | delete_conf_item(struct ConfItem *conf)
350    case SERVER_TYPE:
351      aconf = map_to_conf(conf);
352  
353 <    if (aconf->dns_query != NULL)
354 <    {
386 <      delete_resolver_queries(aconf->dns_query);
387 <      MyFree(aconf->dns_query);
388 <    }
353 >    if (aconf->dns_pending)
354 >      delete_resolver_queries(aconf);
355      if (aconf->passwd != NULL)
356        memset(aconf->passwd, 0, strlen(aconf->passwd));
357      if (aconf->spasswd != NULL)
# Line 398 | Line 364 | delete_conf_item(struct ConfItem *conf)
364      MyFree(aconf->oper_reason);
365      MyFree(aconf->user);
366      MyFree(aconf->host);
401    MyFree(aconf->fakename);
367   #ifdef HAVE_LIBCRYPTO
368 +    MyFree(aconf->cipher_list);
369 +
370      if (aconf->rsa_public_key)
371        RSA_free(aconf->rsa_public_key);
372      MyFree(aconf->rsa_public_key_file);
# Line 425 | Line 392 | delete_conf_item(struct ConfItem *conf)
392  
393      case SERVER_TYPE:
394        aconf = map_to_conf(conf);
395 +
396 +      DLINK_FOREACH_SAFE(m, m_next, aconf->hub_list.head)
397 +      {
398 +        MyFree(m->data);
399 +        free_dlink_node(m);
400 +      }
401 +
402 +      DLINK_FOREACH_SAFE(m, m_next, aconf->leaf_list.head)
403 +      {
404 +        MyFree(m->data);
405 +        free_dlink_node(m);  
406 +      }
407 +
408        if (!IsConfIllegal(aconf))
409          dlinkDelete(&conf->node, &server_items);
410        MyFree(conf);
# Line 435 | Line 415 | delete_conf_item(struct ConfItem *conf)
415      }
416      break;
417  
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
418    case ULINE_TYPE:
419      match_item = map_to_conf(conf);
420      MyFree(match_item->user);
# Line 478 | Line 434 | delete_conf_item(struct ConfItem *conf)
434      dlinkDelete(&conf->node, &xconf_items);
435      MyFree(conf);
436      break;
437 <
437 > #ifdef HAVE_LIBPCRE
438    case RKLINE_TYPE:
439      aconf = map_to_conf(conf);
440      MyFree(aconf->regexuser);
# Line 501 | Line 457 | delete_conf_item(struct ConfItem *conf)
457      dlinkDelete(&conf->node, &rxconf_items);
458      MyFree(conf);
459      break;
460 <
460 > #endif
461    case NRESV_TYPE:
462      match_item = map_to_conf(conf);
463      MyFree(match_item->user);
# Line 509 | Line 465 | delete_conf_item(struct ConfItem *conf)
465      MyFree(match_item->reason);
466      MyFree(match_item->oper_reason);
467      dlinkDelete(&conf->node, &nresv_items);
468 +
469 +    if (conf->flags & CONF_FLAGS_TEMPORARY)
470 +      if ((m = dlinkFindDelete(&temporary_resv, conf)) != NULL)
471 +        free_dlink_node(m);
472 +
473      MyFree(conf);
474      break;
475  
# Line 526 | Line 487 | delete_conf_item(struct ConfItem *conf)
487      break;
488  
489    case CRESV_TYPE:
490 +    if (conf->flags & CONF_FLAGS_TEMPORARY)
491 +      if ((m = dlinkFindDelete(&temporary_resv, conf)) != NULL)
492 +        free_dlink_node(m);
493 +
494      MyFree(conf);
495      break;
496  
# Line 534 | Line 499 | delete_conf_item(struct ConfItem *conf)
499      MyFree(conf);
500      break;
501  
502 +  case SERVICE_TYPE:
503 +    dlinkDelete(&conf->node, &service_items);
504 +    MyFree(conf);
505 +    break;
506 +
507    default:
508      break;
509    }
# Line 567 | Line 537 | static const unsigned int shared_bit_tab
537   * side effects -
538   */
539   void
540 < report_confitem_types(struct Client *source_p, ConfType type, int temp)
540 > report_confitem_types(struct Client *source_p, ConfType type)
541   {
542 <  dlink_node *ptr = NULL;
542 >  dlink_node *ptr = NULL, *dptr = NULL;
543    struct ConfItem *conf = NULL;
544    struct AccessItem *aconf = NULL;
545    struct MatchItem *matchitem = NULL;
# Line 618 | Line 588 | report_confitem_types(struct Client *sou
588      }
589      break;
590  
591 + #ifdef HAVE_LIBPCRE
592    case RXLINE_TYPE:
593      DLINK_FOREACH(ptr, rxconf_items.head)
594      {
# Line 626 | Line 597 | report_confitem_types(struct Client *sou
597  
598        sendto_one(source_p, form_str(RPL_STATSXLINE),
599                   me.name, source_p->name,
600 <                 matchitem->hold ? "xR": "XR", matchitem->count,
600 >                 "XR", matchitem->count,
601                   conf->name, matchitem->reason);
602      }
603      break;
604  
605    case RKLINE_TYPE:
635    p = temp ? "Rk" : "RK";
636
606      DLINK_FOREACH(ptr, rkconf_items.head)
607      {
608        aconf = map_to_conf((conf = ptr->data));
609  
641      if (temp && !(conf->flags & CONF_FLAGS_TEMPORARY))
642        continue;
643
610        sendto_one(source_p, form_str(RPL_STATSKLINE), me.name,
611 <                 source_p->name, p, aconf->host, aconf->user,
611 >                 source_p->name, "KR", aconf->host, aconf->user,
612                   aconf->reason, aconf->oper_reason ? aconf->oper_reason : "");
613      }
614      break;
615 + #endif
616  
617    case ULINE_TYPE:
618      DLINK_FOREACH(ptr, uconf_items.head)
# Line 690 | Line 657 | report_confitem_types(struct Client *sou
657        aconf = map_to_conf(conf);
658  
659        /* Don't allow non opers to see oper privs */
660 <      if (IsOper(source_p))
660 >      if (HasUMode(source_p, UMODE_OPER))
661          sendto_one(source_p, form_str(RPL_STATSOLINE),
662                     me.name, source_p->name, 'O', aconf->user, aconf->host,
663                     conf->name, oper_privs_as_string(aconf->port),
# Line 710 | Line 677 | report_confitem_types(struct Client *sou
677        classitem = map_to_conf(conf);
678        sendto_one(source_p, form_str(RPL_STATSYLINE),
679                   me.name, source_p->name, 'Y',
680 <                 conf->name, PingFreq(classitem),
681 <                 ConFreq(classitem),
682 <                 MaxTotal(classitem), MaxSendq(classitem));
680 >                 conf->name, classitem->ping_freq,
681 >                 classitem->con_freq,
682 >                 classitem->max_total, classitem->max_sendq,
683 >                 classitem->curr_user_count,
684 >                 classitem->number_per_cidr, classitem->cidr_bitlen_ipv4,
685 >                 classitem->number_per_cidr, classitem->cidr_bitlen_ipv6,
686 >                 classitem->active ? "active" : "disabled");
687      }
688      break;
689  
# Line 720 | Line 691 | report_confitem_types(struct Client *sou
691    case CLIENT_TYPE:
692      break;
693  
694 +  case SERVICE_TYPE:
695 +    DLINK_FOREACH(ptr, service_items.head)
696 +    {
697 +      conf = ptr->data;
698 +      sendto_one(source_p, form_str(RPL_STATSSERVICE),
699 +                 me.name, source_p->name, 'S', "*", conf->name, 0, 0);
700 +    }
701 +    break;
702 +
703    case SERVER_TYPE:
704      DLINK_FOREACH(ptr, server_items.head)
705      {
# Line 732 | Line 712 | report_confitem_types(struct Client *sou
712  
713        if (IsConfAllowAutoConn(aconf))
714          *p++ = 'A';
715 <      if (IsConfCryptLink(aconf))
716 <        *p++ = 'C';
737 <      if (IsConfLazyLink(aconf))
738 <        *p++ = 'L';
739 <      if (aconf->fakename)
740 <        *p++ = 'M';
715 >      if (IsConfSSL(aconf))
716 >        *p++ = 'S';
717        if (IsConfTopicBurst(aconf))
718          *p++ = 'T';
743      if (IsConfCompressed(aconf))
744        *p++ = 'Z';
719        if (buf[0] == '\0')
720          *p++ = '*';
721  
722        *p = '\0';
723  
724 <      /* Allow admins to see actual ips
725 <       * unless hide_server_ips is enabled
724 >      /*
725 >       * Allow admins to see actual ips unless hide_server_ips is enabled
726         */
727 <      if (!ConfigServerHide.hide_server_ips && IsAdmin(source_p))
727 >      if (!ConfigServerHide.hide_server_ips && HasUMode(source_p, UMODE_ADMIN))
728          sendto_one(source_p, form_str(RPL_STATSCLINE),
729                     me.name, source_p->name, 'C', aconf->host,
730                     buf, conf->name, aconf->port,
# Line 764 | Line 738 | report_confitem_types(struct Client *sou
738      break;
739  
740    case HUB_TYPE:
741 <    DLINK_FOREACH(ptr, hub_items.head)
741 >    DLINK_FOREACH(ptr, server_items.head)
742      {
743        conf = ptr->data;
744 <      matchitem = map_to_conf(conf);
745 <      sendto_one(source_p, form_str(RPL_STATSHLINE), me.name,
746 <                 source_p->name, 'H', matchitem->host, conf->name, 0, "*");
744 >      aconf = map_to_conf(conf);
745 >
746 >      DLINK_FOREACH(dptr, aconf->hub_list.head)
747 >        sendto_one(source_p, form_str(RPL_STATSHLINE), me.name,
748 >                   source_p->name, 'H', dptr->data, conf->name, 0, "*");
749      }
750      break;
751  
752    case LEAF_TYPE:
753 <    DLINK_FOREACH(ptr, leaf_items.head)
753 >    DLINK_FOREACH(ptr, server_items.head)
754      {
755        conf = ptr->data;
756 <      matchitem = map_to_conf(conf);
757 <      sendto_one(source_p, form_str(RPL_STATSLLINE), me.name,
758 <                 source_p->name, 'L', matchitem->host, conf->name, 0, "*");
756 >      aconf = map_to_conf(conf);
757 >
758 >      DLINK_FOREACH(dptr, aconf->leaf_list.head)
759 >        sendto_one(source_p, form_str(RPL_STATSLLINE), me.name,
760 >                   source_p->name, 'L', dptr->data, conf->name, 0, "*");
761      }
762      break;
763  
# Line 790 | Line 768 | report_confitem_types(struct Client *sou
768    case CRESV_TYPE:
769    case NRESV_TYPE:
770    case CLUSTER_TYPE:
771 +  default:
772      break;
773    }
774   }
# Line 816 | Line 795 | check_client(va_list args)
795  
796    /* I'm already in big trouble if source_p->localClient is NULL -db */
797    if ((i = verify_access(source_p, username)))
798 <  {
820 <    ilog(L_INFO, "Access denied: %s[%s]",
798 >    ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
799           source_p->name, source_p->sockhost);
822  }
800  
801    switch (i)
802    {
826    case IRCD_SOCKET_ERROR:
827      exit_client(source_p, &me, "Socket Error");
828      break;
829
803      case TOO_MANY:
804        sendto_realops_flags(UMODE_FULL, L_ALL,
805                             "Too many on IP for %s (%s).",
806                             get_client_name(source_p, SHOW_IP),
807                             source_p->sockhost);
808 <      ilog(L_INFO,"Too many connections on IP from %s.",
808 >      ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
809             get_client_name(source_p, SHOW_IP));
810 <      ServerStats->is_ref++;
810 >      ++ServerStats.is_ref;
811        exit_client(source_p, &me, "No more connections allowed on that IP");
812        break;
813  
# Line 843 | Line 816 | check_client(va_list args)
816                             "I-line is full for %s (%s).",
817                             get_client_name(source_p, SHOW_IP),
818                             source_p->sockhost);
819 <      ilog(L_INFO,"Too many connections from %s.",
819 >      ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
820             get_client_name(source_p, SHOW_IP));
821 <       ServerStats->is_ref++;
821 >      ++ServerStats.is_ref;
822        exit_client(source_p, &me,
823                  "No more connections allowed in your connection class");
824        break;
825  
826      case NOT_AUTHORIZED:
827 <    {
855 <      static char ipaddr[HOSTIPLEN];
856 <      ServerStats->is_ref++;
827 >      ++ServerStats.is_ref;
828        /* jdc - lists server name & port connections are on */
829        /*       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);
830        sendto_realops_flags(UMODE_UNAUTH, L_ALL,
831                             "Unauthorized client connection from %s [%s] on [%s/%u].",
832                             get_client_name(source_p, SHOW_IP),
833 <                           ipaddr,
833 >                           source_p->sockhost,
834                             source_p->localClient->listener->name,
835                             source_p->localClient->listener->port);
836 <      ilog(L_INFO,
836 >      ilog(LOG_TYPE_IRCD,
837            "Unauthorized client connection from %s on [%s/%u].",
838            get_client_name(source_p, SHOW_IP),
839            source_p->localClient->listener->name,
# Line 875 | Line 843 | check_client(va_list args)
843         * capture reject code here or rely on the connecting too fast code.
844         * - Dianora
845         */
846 <      if(REJECT_HOLD_TIME > 0)
846 >      if (REJECT_HOLD_TIME > 0)
847        {
848          sendto_one(source_p, ":%s NOTICE %s :You are not authorized to use this server",
849                     me.name, source_p->name);
# Line 885 | Line 853 | check_client(va_list args)
853        else
854          exit_client(source_p, &me, "You are not authorized to use this server");
855        break;
856 <    }
889 <
856 >
857     case BANNED_CLIENT:
858       /*
859        * Don't exit them immediately, play with them a bit.
# Line 899 | Line 866 | check_client(va_list args)
866       }
867       else
868         exit_client(source_p, &me, "Banned");
869 <     ServerStats->is_ref++;
869 >     ++ServerStats.is_ref;
870       break;
871  
872     case 0:
# Line 1016 | Line 983 | attach_iline(struct Client *client_p, st
983    ip_found->count++;
984    SetIpHash(client_p);
985  
986 <  aconf = (struct AccessItem *)map_to_conf(conf);
986 >  aconf = map_to_conf(conf);
987    if (aconf->class_ptr == NULL)
988      return NOT_AUTHORIZED;  /* If class is missing, this is best */
989  
990 <  aclass = (struct ClassItem *)map_to_conf(aconf->class_ptr);
990 >  aclass = map_to_conf(aconf->class_ptr);
991  
992    count_user_host(client_p->username, client_p->host,
993                    &global, &local, &ident);
# Line 1029 | Line 996 | attach_iline(struct Client *client_p, st
996     * setting a_limit_reached if any limit is reached.
997     * - Dianora
998     */
999 <  if (MaxTotal(aclass) != 0 && CurrUserCount(aclass) >= MaxTotal(aclass))
999 >  if (aclass->max_total != 0 && aclass->curr_user_count >= aclass->max_total)
1000      a_limit_reached = 1;
1001 <  else if (MaxPerIp(aclass) != 0 && ip_found->count >= MaxPerIp(aclass))
1001 >  else if (aclass->max_perip != 0 && ip_found->count > aclass->max_perip)
1002      a_limit_reached = 1;
1003 <  else if (MaxLocal(aclass) != 0 && local >= MaxLocal(aclass))
1003 >  else if (aclass->max_local != 0 && local >= aclass->max_local)
1004      a_limit_reached = 1;
1005 <  else if (MaxGlobal(aclass) != 0 && global >= MaxGlobal(aclass))
1005 >  else if (aclass->max_global != 0 && global >= aclass->max_global)
1006      a_limit_reached = 1;
1007 <  else if (MaxIdent(aclass) != 0 && ident >= MaxIdent(aclass) &&
1007 >  else if (aclass->max_ident != 0 && ident >= aclass->max_ident &&
1008             client_p->username[0] != '~')
1009      a_limit_reached = 1;
1010  
1011    if (a_limit_reached)
1012    {
1013      if (!IsConfExemptLimits(aconf))
1014 <      return TOO_MANY;  /* Already at maximum allowed */
1014 >      return TOO_MANY;   /* Already at maximum allowed */
1015  
1016      sendto_one(client_p,
1017                 ":%s NOTICE %s :*** Your connection class is full, "
# Line 1193 | Line 1160 | hash_ip(struct irc_ssaddr *addr)
1160    {
1161      struct sockaddr_in *v4 = (struct sockaddr_in *)addr;
1162      int hash;
1163 <    u_int32_t ip;
1163 >    uint32_t ip;
1164  
1165      ip   = ntohl(v4->sin_addr.s_addr);
1166      hash = ((ip >> 12) + ip) & (IP_HASH_SIZE-1);
# Line 1204 | Line 1171 | hash_ip(struct irc_ssaddr *addr)
1171    {
1172      int hash;
1173      struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr;
1174 <    u_int32_t *ip = (u_int32_t *)&v6->sin6_addr.s6_addr;
1174 >    uint32_t *ip = (uint32_t *)&v6->sin6_addr.s6_addr;
1175  
1176      hash  = ip[0] ^ ip[3];
1177      hash ^= hash >> 16;  
# Line 1228 | Line 1195 | hash_ip(struct irc_ssaddr *addr)
1195   * used in the hash.
1196   */
1197   void
1198 < count_ip_hash(int *number_ips_stored, unsigned long *mem_ips_stored)
1198 > count_ip_hash(unsigned int *number_ips_stored, uint64_t *mem_ips_stored)
1199   {
1200    struct ip_entry *ptr;
1201    int i;
# Line 1316 | Line 1283 | detach_conf(struct Client *client_p, Con
1283        case CLIENT_TYPE:
1284        case OPER_TYPE:
1285        case SERVER_TYPE:
1286 <        aconf = (struct AccessItem *)map_to_conf(conf);
1287 <        if ((aclass_conf = ClassPtr(aconf)) != NULL)
1286 >        aconf = map_to_conf(conf);
1287 >
1288 >        assert(aconf->clients > 0);
1289 >
1290 >        if ((aclass_conf = aconf->class_ptr) != NULL)
1291          {
1292 <          aclass = (struct ClassItem *)map_to_conf(aclass_conf);
1292 >          aclass = map_to_conf(aclass_conf);
1293 >
1294 >          assert(aclass->curr_user_count > 0);
1295  
1296            if (conf->type == CLIENT_TYPE)
1297              remove_from_cidr_check(&client_p->localClient->ip, aclass);
1298 <
1327 <          if (CurrUserCount(aclass) > 0)
1328 <            aclass->curr_user_count--;
1329 <          if (MaxTotal(aclass) < 0 && CurrUserCount(aclass) <= 0)
1298 >          if (--aclass->curr_user_count == 0 && aclass->active == 0)
1299              delete_conf_item(aclass_conf);
1300          }
1301  
1302 <        /* 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)
1302 >        if (--aconf->clients == 0 && IsConfIllegal(aconf))
1303            delete_conf_item(conf);
1304 +
1305          break;
1306        default:
1307          break;
# Line 1367 | Line 1328 | detach_conf(struct Client *client_p, Con
1328   int
1329   attach_conf(struct Client *client_p, struct ConfItem *conf)
1330   {
1331 <  struct AccessItem *aconf;
1332 <  struct MatchItem *match_item;
1331 >  struct AccessItem *aconf = map_to_conf(conf);
1332 >  struct ClassItem *aclass = map_to_conf(aconf->class_ptr);
1333  
1334    if (dlinkFind(&client_p->localClient->confs, conf) != NULL)
1335      return 1;
1336  
1337 <  if (conf->type == CLIENT_TYPE ||
1338 <      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;
1337 >  if (IsConfIllegal(aconf)) /* TBV: can't happen */
1338 >    return NOT_AUTHORIZED;
1339  
1340 <    if (conf->type == CLIENT_TYPE)
1341 <    {
1342 <      struct ClassItem *aclass;
1343 <      aclass = (struct ClassItem *)map_to_conf(aconf->class_ptr);
1340 >  if (conf->type == CLIENT_TYPE)
1341 >    if (cidr_limit_reached(IsConfExemptLimits(aconf),
1342 >                           &client_p->localClient->ip, aclass))
1343 >      return TOO_MANY;    /* Already at maximum allowed */
1344  
1345 <      if (cidr_limit_reached(IsConfExemptLimits(aconf),
1346 <                             &client_p->localClient->ip, aclass))
1392 <        return TOO_MANY;  /* Already at maximum allowed */
1393 <
1394 <      CurrUserCount(aclass)++;
1395 <    }
1396 <
1397 <    aconf->clients++;
1398 <  }
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 <  }
1345 >  aclass->curr_user_count++;
1346 >  aconf->clients++;
1347  
1348    dlinkAdd(conf, make_dlink_node(), &client_p->localClient->confs);
1349  
# Line 1432 | Line 1375 | attach_connect_block(struct Client *clie
1375    DLINK_FOREACH(ptr, server_items.head)
1376    {
1377      conf = ptr->data;
1378 <    aconf = (struct AccessItem *)map_to_conf(conf);
1378 >    aconf = map_to_conf(conf);
1379  
1380      if (match(conf->name, name) == 0 || match(aconf->host, host) == 0)
1381        continue;
# Line 1472 | Line 1415 | find_conf_exact(ConfType type, const cha
1415  
1416      if (conf->name == NULL)
1417        continue;
1418 <    aconf = (struct AccessItem *)map_to_conf(conf);
1418 >    aconf = map_to_conf(conf);
1419      if (aconf->host == NULL)
1420        continue;
1421      if (irccmp(conf->name, name) != 0)
# Line 1483 | Line 1426 | find_conf_exact(ConfType type, const cha
1426      ** socket host) matches *either* host or name field
1427      ** of the configuration.
1428      */
1429 <    if (!match(aconf->host, host) || !match(aconf->user,user)
1487 <        || irccmp(conf->name, name) )
1429 >    if (!match(aconf->host, host) || !match(aconf->user, user))
1430        continue;
1431      if (type == OPER_TYPE)
1432      {
1433 <      struct ClassItem *aclass;
1433 >      struct ClassItem *aclass = map_to_conf(aconf->class_ptr);
1434  
1435 <      aclass = (struct ClassItem *)aconf->class_ptr;
1494 <      if (aconf->clients < MaxTotal(aclass))
1495 <        return conf;
1496 <      else
1435 >      if (aconf->clients >= aclass->max_total)
1436          continue;
1437      }
1438 <    else
1439 <      return conf;
1438 >
1439 >    return conf;
1440    }
1441 +
1442    return NULL;
1443   }
1444  
# Line 1564 | Line 1504 | map_to_list(ConfType type)
1504    case SERVER_TYPE:
1505      return(&server_items);
1506      break;
1507 +  case SERVICE_TYPE:
1508 +    return(&service_items);
1509 +    break;
1510    case CLUSTER_TYPE:
1511      return(&cluster_items);
1512      break;
# Line 1599 | Line 1542 | find_matching_name_conf(ConfType type, c
1542  
1543    switch (type)
1544    {
1545 <    case RXLINE_TYPE:
1545 > #ifdef HAVE_LIBPCRE
1546 >  case RXLINE_TYPE:
1547        DLINK_FOREACH(ptr, list_p->head)
1548        {
1549          conf = ptr->data;
# Line 1609 | Line 1553 | find_matching_name_conf(ConfType type, c
1553            return conf;
1554        }
1555        break;
1556 + #endif
1557 +  case SERVICE_TYPE:
1558 +    DLINK_FOREACH(ptr, list_p->head)
1559 +    {
1560 +      conf = ptr->data;
1561 +
1562 +      if (EmptyString(conf->name))
1563 +        continue;
1564 +      if ((name != NULL) && !irccmp(name, conf->name))
1565 +        return conf;
1566 +    }
1567 +    break;
1568  
1569    case XLINE_TYPE:
1570    case ULINE_TYPE:
# Line 1663 | Line 1619 | find_matching_name_conf(ConfType type, c
1619   * side effects - looks for an exact match on name field
1620   */
1621   struct ConfItem *
1622 < find_exact_name_conf(ConfType type, const char *name,
1622 > find_exact_name_conf(ConfType type, const struct Client *who, const char *name,
1623                       const char *user, const char *host)
1624   {
1625    dlink_node *ptr = NULL;
# Line 1704 | Line 1660 | find_exact_name_conf(ConfType type, cons
1660      DLINK_FOREACH(ptr, list_p->head)
1661      {
1662        conf = ptr->data;
1663 <      aconf = (struct AccessItem *)map_to_conf(conf);
1663 >      aconf = map_to_conf(conf);
1664 >
1665        if (EmptyString(conf->name))
1666 <        continue;
1667 <    
1668 <      if (irccmp(conf->name, name) == 0)
1666 >        continue;
1667 >
1668 >      if (!irccmp(conf->name, name))
1669        {
1670 <        if ((user == NULL && (host == NULL)))
1671 <          return (conf);
1672 <        if (EmptyString(aconf->user) || EmptyString(aconf->host))
1673 <          return (conf);
1674 <        if (match(aconf->user, user) && match(aconf->host, host))
1675 <          return (conf);
1670 >        if (!who)
1671 >          return conf;
1672 >        if (EmptyString(aconf->user) || EmptyString(aconf->host))
1673 >          return conf;
1674 >        if (match(aconf->user, who->username))
1675 >        {
1676 >          switch (aconf->type)
1677 >          {
1678 >            case HM_HOST:
1679 >              if (match(aconf->host, who->host) || match(aconf->host, who->sockhost))
1680 >                return conf;
1681 >              break;
1682 >            case HM_IPV4:
1683 >              if (who->localClient->aftype == AF_INET)
1684 >                if (match_ipv4(&who->localClient->ip, &aconf->addr, aconf->bits))
1685 >                  return conf;
1686 >              break;
1687 > #ifdef IPV6
1688 >            case HM_IPV6:
1689 >              if (who->localClient->aftype == AF_INET6)
1690 >                if (match_ipv6(&who->localClient->ip, &aconf->addr, aconf->bits))
1691 >                  return conf;
1692 >              break;
1693 > #endif
1694 >            default:
1695 >              assert(0);
1696 >          }
1697 >        }
1698        }
1699      }
1700 +
1701      break;
1702  
1703    case SERVER_TYPE:
# Line 1773 | Line 1753 | rehash(int sig)
1753      sendto_realops_flags(UMODE_ALL, L_ALL,
1754                           "Got signal SIGHUP, reloading ircd.conf file");
1755  
1776 #ifndef _WIN32
1756    restart_resolver();
1757 < #endif
1757 >
1758    /* don't close listeners until we know we can go ahead with the rehash */
1759  
1760    /* Check to see if we magically got(or lost) IPv6 support */
# Line 1786 | Line 1765 | rehash(int sig)
1765    if (ServerInfo.description != NULL)
1766      strlcpy(me.info, ServerInfo.description, sizeof(me.info));
1767  
1789 #ifndef STATIC_MODULES
1768    load_conf_modules();
1791 #endif
1769  
1770    flush_deleted_I_P();
1771  
1772    rehashed_klines = 1;
1773 <
1773 > /* XXX */
1774    if (ConfigLoggingEntry.use_logging)
1775 <    reopen_log(logFileName);
1775 >    log_close_all();
1776  
1777    return(0);
1778   }
# Line 1834 | Line 1811 | set_default_conf(void)
1811    ServerInfo.specific_ipv6_vhost = 0;
1812  
1813    ServerInfo.max_clients = MAXCLIENTS_MAX;
1814 <  /* Don't reset hub, as that will break lazylinks */
1815 <  /* ServerInfo.hub = NO; */
1814 >
1815 >  ServerInfo.hub = 0;
1816    ServerInfo.dns_host.sin_addr.s_addr = 0;
1817    ServerInfo.dns_host.sin_port = 0;
1818    AdminInfo.name = NULL;
1819    AdminInfo.email = NULL;
1820    AdminInfo.description = NULL;
1821  
1822 <  set_log_level(L_NOTICE);
1822 >  log_close_all();
1823 >
1824    ConfigLoggingEntry.use_logging = 1;
1825 <  ConfigLoggingEntry.operlog[0] = '\0';
1826 <  ConfigLoggingEntry.userlog[0] = '\0';
1827 <  ConfigLoggingEntry.klinelog[0] = '\0';
1828 <  ConfigLoggingEntry.glinelog[0] = '\0';
1829 <  ConfigLoggingEntry.killlog[0] = '\0';
1830 <  ConfigLoggingEntry.operspylog[0] = '\0';
1831 <  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;
1825 >
1826 >  ConfigChannel.disable_fake_channels = 0;
1827 >  ConfigChannel.restrict_channels = 0;
1828 >  ConfigChannel.disable_local_channels = 0;
1829 >  ConfigChannel.use_invex = 1;
1830 >  ConfigChannel.use_except = 1;
1831 >  ConfigChannel.use_knock = 1;
1832    ConfigChannel.knock_delay = 300;
1833    ConfigChannel.knock_delay_channel = 60;
1834 <  ConfigChannel.max_chans_per_user = 15;
1835 <  ConfigChannel.quiet_on_ban = YES;
1834 >  ConfigChannel.max_chans_per_user = 25;
1835 >  ConfigChannel.max_chans_per_oper = 50;
1836 >  ConfigChannel.quiet_on_ban = 1;
1837    ConfigChannel.max_bans = 25;
1838    ConfigChannel.default_split_user_count = 0;
1839    ConfigChannel.default_split_server_count = 0;
1840 <  ConfigChannel.no_join_on_split = NO;
1841 <  ConfigChannel.no_create_on_split = NO;
1870 <  ConfigChannel.burst_topicwho = YES;
1840 >  ConfigChannel.no_join_on_split = 0;
1841 >  ConfigChannel.no_create_on_split = 0;
1842  
1843 <  ConfigServerHide.flatten_links = NO;
1843 >  ConfigServerHide.flatten_links = 0;
1844    ConfigServerHide.links_delay = 300;
1845 <  ConfigServerHide.hidden = NO;
1846 <  ConfigServerHide.disable_hidden = NO;
1847 <  ConfigServerHide.hide_servers = NO;
1845 >  ConfigServerHide.hidden = 0;
1846 >  ConfigServerHide.disable_hidden = 0;
1847 >  ConfigServerHide.hide_servers = 0;
1848    DupString(ConfigServerHide.hidden_name, NETWORK_NAME_DEFAULT);
1849 <  ConfigServerHide.hide_server_ips = NO;
1849 >  ConfigServerHide.hide_server_ips = 0;
1850  
1851 +  
1852 +  DupString(ConfigFileEntry.service_name, SERVICE_NAME_DEFAULT);
1853 +  ConfigFileEntry.max_watch = WATCHSIZE_DEFAULT;
1854    ConfigFileEntry.gline_min_cidr = 16;
1855    ConfigFileEntry.gline_min_cidr6 = 48;
1856 <  ConfigFileEntry.invisible_on_connect = YES;
1857 <  ConfigFileEntry.burst_away = NO;
1858 <  ConfigFileEntry.use_whois_actually = YES;
1859 <  ConfigFileEntry.tkline_expire_notices = YES;
1860 <  ConfigFileEntry.hide_spoof_ips = YES;
1861 <  ConfigFileEntry.ignore_bogus_ts = NO;
1862 <  ConfigFileEntry.disable_auth = NO;
1863 <  ConfigFileEntry.disable_remote = NO;
1856 >  ConfigFileEntry.invisible_on_connect = 1;
1857 >  ConfigFileEntry.burst_away = 0;
1858 >  ConfigFileEntry.use_whois_actually = 1;
1859 >  ConfigFileEntry.tkline_expire_notices = 1;
1860 >  ConfigFileEntry.hide_spoof_ips = 1;
1861 >  ConfigFileEntry.ignore_bogus_ts = 0;
1862 >  ConfigFileEntry.disable_auth = 0;
1863 >  ConfigFileEntry.disable_remote = 0;
1864    ConfigFileEntry.kill_chase_time_limit = 90;
1865 <  ConfigFileEntry.default_floodcount = 8; /* XXX */
1866 <  ConfigFileEntry.failed_oper_notice = YES;
1867 <  ConfigFileEntry.dots_in_ident = 0;      /* XXX */
1894 <  ConfigFileEntry.dot_in_ip6_addr = YES;
1865 >  ConfigFileEntry.default_floodcount = 8;
1866 >  ConfigFileEntry.failed_oper_notice = 1;
1867 >  ConfigFileEntry.dots_in_ident = 0;
1868    ConfigFileEntry.min_nonwildcard = 4;
1869    ConfigFileEntry.min_nonwildcard_simple = 3;
1870    ConfigFileEntry.max_accept = 20;
1871 <  ConfigFileEntry.anti_nick_flood = NO;   /* XXX */
1871 >  ConfigFileEntry.anti_nick_flood = 0;
1872    ConfigFileEntry.max_nick_time = 20;
1873    ConfigFileEntry.max_nick_changes = 5;
1874 <  ConfigFileEntry.anti_spam_exit_message_time = 0;  /* XXX */
1874 >  ConfigFileEntry.anti_spam_exit_message_time = 0;
1875    ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
1876 <  ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;  /* XXX */
1877 <  ConfigFileEntry.kline_with_reason = YES;
1876 >  ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
1877 >  ConfigFileEntry.kline_with_reason = 1;
1878    ConfigFileEntry.kline_reason = NULL;
1879 <  ConfigFileEntry.warn_no_nline = YES;
1880 <  ConfigFileEntry.stats_o_oper_only = NO; /* XXX */
1879 >  ConfigFileEntry.warn_no_nline = 1;
1880 >  ConfigFileEntry.stats_o_oper_only = 0;
1881    ConfigFileEntry.stats_k_oper_only = 1;  /* masked */
1882    ConfigFileEntry.stats_i_oper_only = 1;  /* masked */
1883 <  ConfigFileEntry.stats_P_oper_only = NO;
1883 >  ConfigFileEntry.stats_P_oper_only = 0;
1884    ConfigFileEntry.caller_id_wait = 60;
1885 <  ConfigFileEntry.opers_bypass_callerid = NO;
1885 >  ConfigFileEntry.opers_bypass_callerid = 0;
1886    ConfigFileEntry.pace_wait = 10;
1887    ConfigFileEntry.pace_wait_simple = 1;
1888 <  ConfigFileEntry.short_motd = NO;
1889 <  ConfigFileEntry.ping_cookie = NO;
1890 <  ConfigFileEntry.no_oper_flood = NO;     /* XXX */
1891 <  ConfigFileEntry.true_no_oper_flood = NO;  /* XXX */
1892 <  ConfigFileEntry.oper_pass_resv = YES;
1893 <  ConfigFileEntry.glines = NO;            /* XXX */
1894 <  ConfigFileEntry.gline_time = 12 * 3600; /* XXX */
1922 <  ConfigFileEntry.idletime = 0;
1888 >  ConfigFileEntry.short_motd = 0;
1889 >  ConfigFileEntry.ping_cookie = 0;
1890 >  ConfigFileEntry.no_oper_flood = 0;
1891 >  ConfigFileEntry.true_no_oper_flood = 0;
1892 >  ConfigFileEntry.oper_pass_resv = 1;
1893 >  ConfigFileEntry.glines = 0;
1894 >  ConfigFileEntry.gline_time = 12 * 3600;
1895    ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT;
1896    ConfigFileEntry.client_flood = CLIENT_FLOOD_DEFAULT;
1897 <  ConfigFileEntry.oper_only_umodes = UMODE_DEBUG;  /* XXX */
1898 <  ConfigFileEntry.oper_umodes = UMODE_LOCOPS | UMODE_SERVNOTICE |
1899 <    UMODE_OPERWALL | UMODE_WALLOP;        /* XXX */
1900 <  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;
1897 >  ConfigFileEntry.oper_only_umodes = UMODE_DEBUG;
1898 >  ConfigFileEntry.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE |
1899 >    UMODE_OPERWALL | UMODE_WALLOP;
1900 >  ConfigFileEntry.use_egd = 0;
1901    ConfigFileEntry.egdpool_path = NULL;
1942 #ifdef HAVE_LIBZ
1943  ConfigFileEntry.compression_level = 0;
1944 #endif
1902    ConfigFileEntry.throttle_time = 10;
1903   }
1904  
1948 /* read_conf()
1949 *
1950 * inputs       - file descriptor pointing to config file to use
1951 * output       - None
1952 * side effects - Read configuration file.
1953 */
1954 static void
1955 read_conf(FBFILE *file)
1956 {
1957  scount = lineno = 0;
1958
1959  set_default_conf(); /* Set default values prior to conf parsing */
1960  ypass = 1;
1961  yyparse();          /* pick up the classes first */
1962
1963  fbrewind(file);
1964
1965  ypass = 2;
1966  yyparse();          /* Load the values from the conf */
1967  validate_conf();    /* Check to make sure some values are still okay. */
1968                      /* Some global values are also loaded here. */
1969  check_class();      /* Make sure classes are valid */
1970 }
1971
1905   static void
1906   validate_conf(void)
1907   {
# Line 1978 | Line 1911 | validate_conf(void)
1911    if (ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN)
1912      ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
1913  
1981  if (ConfigFileEntry.servlink_path == NULL)
1982    DupString(ConfigFileEntry.servlink_path, SLPATH);
1983
1914    if (ServerInfo.network_name == NULL)
1915      DupString(ServerInfo.network_name,NETWORK_NAME_DEFAULT);
1916  
1917    if (ServerInfo.network_desc == NULL)
1918      DupString(ServerInfo.network_desc,NETWORK_DESC_DEFAULT);
1919  
1920 +  if (ConfigFileEntry.service_name == NULL)
1921 +    DupString(ConfigFileEntry.service_name, SERVICE_NAME_DEFAULT);
1922 +
1923    if ((ConfigFileEntry.client_flood < CLIENT_FLOOD_MIN) ||
1924        (ConfigFileEntry.client_flood > CLIENT_FLOOD_MAX))
1925      ConfigFileEntry.client_flood = CLIENT_FLOOD_MAX;
1926 +
1927 +  ConfigFileEntry.max_watch = IRCD_MAX(ConfigFileEntry.max_watch, WATCHSIZE_MIN);
1928 + }
1929 +
1930 + /* read_conf()
1931 + *
1932 + * inputs       - file descriptor pointing to config file to use
1933 + * output       - None
1934 + * side effects - Read configuration file.
1935 + */
1936 + static void
1937 + read_conf(FILE *file)
1938 + {
1939 +  lineno = 0;
1940 +
1941 +  set_default_conf(); /* Set default values prior to conf parsing */
1942 +  conf_parser_ctx.pass = 1;
1943 +  yyparse();          /* pick up the classes first */
1944 +
1945 +  rewind(file);
1946 +
1947 +  conf_parser_ctx.pass = 2;
1948 +  yyparse();          /* Load the values from the conf */
1949 +  validate_conf();    /* Check to make sure some values are still okay. */
1950 +                      /* Some global values are also loaded here. */
1951 +  check_class();      /* Make sure classes are valid */
1952   }
1953  
1954   /* lookup_confhost()
# Line 2005 | Line 1964 | lookup_confhost(struct ConfItem *conf)
1964  
1965    aconf = map_to_conf(conf);
1966  
1967 <  if (EmptyString(aconf->host) ||
2009 <      EmptyString(aconf->user))
1967 >  if (has_wildcards(aconf->host))
1968    {
1969 <    ilog(L_ERROR, "Host/server name error: (%s) (%s)",
1969 >    ilog(LOG_TYPE_IRCD, "Host/server name error: (%s) (%s)",
1970           aconf->host, conf->name);
1971      return;
1972    }
1973  
2016  if (strchr(aconf->host, '*') ||
2017      strchr(aconf->host, '?'))
2018    return;
2019
1974    /* Do name lookup now on hostnames given and store the
1975     * ip numbers in conf structure.
1976     */
# Line 2028 | Line 1982 | lookup_confhost(struct ConfItem *conf)
1982    /* Get us ready for a bind() and don't bother doing dns lookup */
1983    hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
1984  
1985 <  if (irc_getaddrinfo(aconf->host, NULL, &hints, &res))
1985 >  if (getaddrinfo(aconf->host, NULL, &hints, &res))
1986    {
1987      conf_dns_lookup(aconf);
1988      return;
# Line 2036 | Line 1990 | lookup_confhost(struct ConfItem *conf)
1990  
1991    assert(res != NULL);
1992  
1993 <  memcpy(&aconf->ipnum, res->ai_addr, res->ai_addrlen);
1994 <  aconf->ipnum.ss_len = res->ai_addrlen;
1995 <  aconf->ipnum.ss.ss_family = res->ai_family;
1996 <  irc_freeaddrinfo(res);
1993 >  memcpy(&aconf->addr, res->ai_addr, res->ai_addrlen);
1994 >  aconf->addr.ss_len = res->ai_addrlen;
1995 >  aconf->addr.ss.ss_family = res->ai_family;
1996 >  freeaddrinfo(res);
1997   }
1998  
1999   /* conf_connect_allowed()
# Line 2078 | Line 2032 | conf_connect_allowed(struct irc_ssaddr *
2032   static struct AccessItem *
2033   find_regexp_kline(const char *uhi[])
2034   {
2035 + #ifdef HAVE_LIBPCRE
2036    const dlink_node *ptr = NULL;
2037  
2038    DLINK_FOREACH(ptr, rkconf_items.head)
# Line 2092 | Line 2047 | find_regexp_kline(const char *uhi[])
2047           !ircd_pcre_exec(aptr->regexhost, uhi[2])))
2048        return aptr;
2049    }
2050 <
2050 > #endif
2051    return NULL;
2052   }
2053  
# Line 2115 | Line 2070 | find_kill(struct Client *client_p)
2070  
2071    assert(client_p != NULL);
2072  
2073 <  aconf = find_kline_conf(client_p->host, client_p->username,
2074 <                          &client_p->localClient->ip,
2075 <                          client_p->localClient->aftype);
2073 >  aconf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
2074 >                               CONF_KLINE, client_p->localClient->aftype,
2075 >                               client_p->username, NULL, 1);
2076    if (aconf == NULL)
2077      aconf = find_regexp_kline(uhi);
2078  
2079 <  if (aconf && (aconf->status & CONF_KLINE))
2125 <    return aconf;
2126 <
2127 <  return NULL;
2079 >  return aconf;
2080   }
2081  
2082   struct AccessItem *
# Line 2134 | Line 2086 | find_gline(struct Client *client_p)
2086  
2087    assert(client_p != NULL);
2088  
2089 <  aconf = find_gline_conf(client_p->host, client_p->username,
2090 <                          &client_p->localClient->ip,
2091 <                          client_p->localClient->aftype);
2092 <
2141 <  if (aconf && (aconf->status & CONF_GLINE))
2142 <    return aconf;
2143 <
2144 <  return NULL;
2089 >  aconf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
2090 >                               CONF_GLINE, client_p->localClient->aftype,
2091 >                               client_p->username, NULL, 1);
2092 >  return aconf;
2093   }
2094  
2095   /* add_temp_line()
# Line 2154 | Line 2102 | find_gline(struct Client *client_p)
2102   void
2103   add_temp_line(struct ConfItem *conf)
2104   {
2105 <  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)
2105 >  if (conf->type == XLINE_TYPE)
2106    {
2107      conf->flags |= CONF_FLAGS_TEMPORARY;
2108      dlinkAdd(conf, make_dlink_node(), &temporary_xlines);
2109    }
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  }
2110    else if ((conf->type == NRESV_TYPE) || (conf->type == CRESV_TYPE))
2111    {
2112      conf->flags |= CONF_FLAGS_TEMPORARY;
# Line 2211 | Line 2124 | add_temp_line(struct ConfItem *conf)
2124   void
2125   cleanup_tklines(void *notused)
2126   {
2127 <  expire_tklines(&temporary_glines);
2215 <  expire_tklines(&temporary_klines);
2216 <  expire_tklines(&temporary_dlines);
2127 >  hostmask_expire_temporary();
2128    expire_tklines(&temporary_xlines);
2218  expire_tklines(&temporary_rxlines);
2219  expire_tklines(&temporary_rklines);
2129    expire_tklines(&temporary_resv);
2130   }
2131  
# Line 2234 | Line 2143 | expire_tklines(dlink_list *tklist)
2143    struct ConfItem *conf;
2144    struct MatchItem *xconf;
2145    struct MatchItem *nconf;
2237  struct AccessItem *aconf;
2146    struct ResvChannel *cconf;
2147  
2148    DLINK_FOREACH_SAFE(ptr, next_ptr, tklist->head)
2149    {
2150      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        }
2151  
2152 <        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)
2152 >    if (conf->type == XLINE_TYPE)
2153      {
2154        xconf = (struct MatchItem *)map_to_conf(conf);
2155        if (xconf->hold <= CurrentTime)
2156        {
2157          if (ConfigFileEntry.tkline_expire_notices)
2158            sendto_realops_flags(UMODE_ALL, L_ALL,
2159 <                               "Temporary X-line for [%s] %sexpired", conf->name,
2282 <                               conf->type == RXLINE_TYPE ? "(REGEX) " : "");
2159 >                               "Temporary X-line for [%s] sexpired", conf->name);
2160          dlinkDelete(ptr, tklist);
2161          free_dlink_node(ptr);
2162          delete_conf_item(conf);
2163        }
2164      }
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    }
2165      else if (conf->type == NRESV_TYPE)
2166      {
2167        nconf = (struct MatchItem *)map_to_conf(conf);
# Line 2321 | Line 2183 | expire_tklines(dlink_list *tklist)
2183          if (ConfigFileEntry.tkline_expire_notices)
2184            sendto_realops_flags(UMODE_ALL, L_ALL,
2185                                 "Temporary RESV for [%s] expired", cconf->name);
2186 <        dlinkDelete(ptr, tklist);
2325 <        free_dlink_node(ptr);
2326 <        delete_conf_item(conf);
2186 >        delete_channel_resv(cconf);
2187        }
2188      }
2189    }
# Line 2338 | Line 2198 | expire_tklines(dlink_list *tklist)
2198   static const struct oper_privs
2199   {
2200    const unsigned int oprivs;
2341  const unsigned int hidden;
2201    const unsigned char c;
2202   } flag_list[] = {
2203 <  { OPER_FLAG_ADMIN,       OPER_FLAG_HIDDEN_ADMIN,  'A' },
2204 <  { OPER_FLAG_REMOTEBAN,   0,                       'B' },
2205 <  { OPER_FLAG_DIE,         0,                       'D' },
2206 <  { OPER_FLAG_GLINE,       0,                       'G' },
2207 <  { OPER_FLAG_REHASH,      0,                       'H' },
2208 <  { OPER_FLAG_K,           0,                       'K' },
2209 <  { OPER_FLAG_OPERWALL,    0,                       'L' },
2210 <  { OPER_FLAG_N,           0,                       'N' },
2211 <  { OPER_FLAG_GLOBAL_KILL, 0,                       'O' },
2212 <  { OPER_FLAG_REMOTE,      0,                       'R' },
2213 <  { OPER_FLAG_OPER_SPY,    0,                       'S' },
2214 <  { OPER_FLAG_UNKLINE,     0,                       'U' },
2215 <  { OPER_FLAG_X,           0,                       'X' },
2216 <  { 0, 0, '\0' }
2203 >  { OPER_FLAG_ADMIN,       'A' },
2204 >  { OPER_FLAG_REMOTEBAN,   'B' },
2205 >  { OPER_FLAG_DIE,         'D' },
2206 >  { OPER_FLAG_GLINE,       'G' },
2207 >  { OPER_FLAG_REHASH,      'H' },
2208 >  { OPER_FLAG_K,           'K' },
2209 >  { OPER_FLAG_OPERWALL,    'L' },
2210 >  { OPER_FLAG_N,           'N' },
2211 >  { OPER_FLAG_GLOBAL_KILL, 'O' },
2212 >  { OPER_FLAG_REMOTE,      'R' },
2213 >  { OPER_FLAG_OPER_SPY,    'S' },
2214 >  { OPER_FLAG_UNKLINE,     'U' },
2215 >  { OPER_FLAG_X,           'X' },
2216 >  { 0, '\0' }
2217   };
2218  
2219   char *
# Line 2366 | Line 2225 | oper_privs_as_string(const unsigned int
2225  
2226    for (; flag_list[i].oprivs; ++i)
2227    {
2228 <    if ((port & flag_list[i].oprivs) &&
2370 <        (port & flag_list[i].hidden) == 0)
2228 >    if (port & flag_list[i].oprivs)
2229        *privs_ptr++ = flag_list[i].c;
2230      else
2231        *privs_ptr++ = ToLowerTab[flag_list[i].c];
# Line 2384 | Line 2242 | oper_privs_as_string(const unsigned int
2242   *         "oper" is server name for remote opers
2243   * Side effects: None.
2244   */
2245 < char *
2245 > const char *
2246   get_oper_name(const struct Client *client_p)
2247   {
2248 <  dlink_node *cnode;
2391 <  struct ConfItem *conf;
2392 <  struct AccessItem *aconf;
2393 <
2248 >  dlink_node *cnode = NULL;
2249    /* +5 for !,@,{,} and null */
2250 <  static char buffer[NICKLEN+USERLEN+HOSTLEN+HOSTLEN+5];
2250 >  static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5];
2251  
2252    if (MyConnect(client_p))
2253    {
2254 <    DLINK_FOREACH(cnode, client_p->localClient->confs.head)
2254 >    if ((cnode = client_p->localClient->confs.head))
2255      {
2256 <      conf = cnode->data;
2257 <      aconf = map_to_conf(conf);
2256 >      struct ConfItem *conf = cnode->data;
2257 >      const struct AccessItem *aconf = map_to_conf(conf);
2258  
2259        if (IsConfOperator(aconf))
2260        {
2261 <        ircsprintf(buffer, "%s!%s@%s{%s}", client_p->name,
2262 <                   client_p->username, client_p->host,
2408 <                   conf->name);
2261 >        snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
2262 >                 client_p->username, client_p->host, conf->name);
2263          return buffer;
2264        }
2265      }
# Line 2416 | Line 2270 | get_oper_name(const struct Client *clien
2270      assert(0); /* Oper without oper conf! */
2271    }
2272  
2273 <  ircsprintf(buffer, "%s!%s@%s{%s}", client_p->name,
2274 <             client_p->username, client_p->host, client_p->servptr->name);
2273 >  snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
2274 >           client_p->username, client_p->host, client_p->servptr->name);
2275    return buffer;
2276   }
2277  
# Line 2434 | Line 2288 | read_conf_files(int cold)
2288    char chanmodes[32];
2289    char chanlimit[32];
2290  
2291 +  conf_parser_ctx.boot = cold;
2292    filename = get_conf_name(CONF_TYPE);
2293  
2294    /* We need to know the initial filename for the yyerror() to report
# Line 2444 | Line 2299 | read_conf_files(int cold)
2299    */
2300    strlcpy(conffilebuf, filename, sizeof(conffilebuf));
2301  
2302 <  if ((conf_fbfile_in = fbopen(filename, "r")) == NULL)
2302 >  if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL)
2303    {
2304      if (cold)
2305      {
2306 <      ilog(L_CRIT, "Unable to read configuration file '%s': %s",
2306 >      ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
2307             filename, strerror(errno));
2308        exit(-1);
2309      }
# Line 2464 | Line 2319 | read_conf_files(int cold)
2319    if (!cold)
2320      clear_out_old_conf();
2321  
2322 <  read_conf(conf_fbfile_in);
2323 <  fbclose(conf_fbfile_in);
2322 >  read_conf(conf_parser_ctx.conf_file);
2323 >  fclose(conf_parser_ctx.conf_file);
2324  
2325    add_isupport("NETWORK", ServerInfo.network_name, -1);
2326 <  ircsprintf(chanmodes, "b%s%s:%d", ConfigChannel.use_except ? "e" : "",
2327 <             ConfigChannel.use_invex ? "I" : "", ConfigChannel.max_bans);
2326 >  snprintf(chanmodes, sizeof(chanmodes), "b%s%s:%d",
2327 >           ConfigChannel.use_except ? "e" : "",
2328 >           ConfigChannel.use_invex ? "I" : "", ConfigChannel.max_bans);
2329    add_isupport("MAXLIST", chanmodes, -1);
2330    add_isupport("MAXTARGETS", NULL, ConfigFileEntry.max_targets);
2331 +
2332    if (ConfigChannel.disable_local_channels)
2333      add_isupport("CHANTYPES", "#", -1);
2334    else
2335      add_isupport("CHANTYPES", "#&", -1);
2336 <  ircsprintf(chanlimit, "%s:%d", ConfigChannel.disable_local_channels ? "#" : "#&",
2337 <             ConfigChannel.max_chans_per_user);
2336 >
2337 >  snprintf(chanlimit, sizeof(chanlimit), "%s:%d",
2338 >           ConfigChannel.disable_local_channels ? "#" : "#&",
2339 >           ConfigChannel.max_chans_per_user);
2340    add_isupport("CHANLIMIT", chanlimit, -1);
2341 <  ircsprintf(chanmodes, "%s%s%s", ConfigChannel.use_except ? "e" : "",
2342 <             ConfigChannel.use_invex ? "I" : "", "b,k,l,imnpst");
2341 >  snprintf(chanmodes, sizeof(chanmodes), "%s%s%s",
2342 >           ConfigChannel.use_except ? "e" : "",
2343 >           ConfigChannel.use_invex ? "I" : "", "b,k,l,imnprstORS");
2344    add_isupport("CHANNELLEN", NULL, LOCAL_CHANNELLEN);
2345 +
2346    if (ConfigChannel.use_except)
2347      add_isupport("EXCEPTS", "e", -1);
2348    if (ConfigChannel.use_invex)
# Line 2494 | Line 2355 | read_conf_files(int cold)
2355     */
2356    rebuild_isupport_message_line();
2357  
2358 <  parse_conf_file(KLINE_TYPE, cold);
2358 > #ifdef HAVE_LIBPCRE
2359    parse_conf_file(RKLINE_TYPE, cold);
2360 +  parse_conf_file(RXLINE_TYPE, cold);
2361 + #endif
2362 +  parse_conf_file(KLINE_TYPE, cold);
2363    parse_conf_file(DLINE_TYPE, cold);
2364    parse_conf_file(XLINE_TYPE, cold);
2501  parse_conf_file(RXLINE_TYPE, cold);
2365    parse_conf_file(NRESV_TYPE, cold);
2366    parse_conf_file(CRESV_TYPE, cold);
2367   }
# Line 2512 | Line 2375 | read_conf_files(int cold)
2375   static void
2376   parse_conf_file(int type, int cold)
2377   {
2378 <  FBFILE *file = NULL;
2378 >  FILE *file = NULL;
2379    const char *filename = get_conf_name(type);
2380  
2381 <  if ((file = fbopen(filename, "r")) == NULL)
2381 >  if ((file = fopen(filename, "r")) == NULL)
2382    {
2383      if (cold)
2384 <      ilog(L_ERROR, "Unable to read configuration file '%s': %s",
2384 >      ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
2385             filename, strerror(errno));
2386      else
2387        sendto_realops_flags(UMODE_ALL, L_ALL,
# Line 2528 | Line 2391 | parse_conf_file(int type, int cold)
2391    else
2392    {
2393      parse_csv_file(file, type);
2394 <    fbclose(file);
2394 >    fclose(file);
2395    }
2396   }
2397  
# Line 2547 | Line 2410 | clear_out_old_conf(void)
2410    struct ClassItem *cltmp;
2411    struct MatchItem *match_item;
2412    dlink_list *free_items [] = {
2413 <    &server_items,   &oconf_items,    &hub_items, &leaf_items,
2413 >    &server_items,   &oconf_items,
2414       &uconf_items,   &xconf_items, &rxconf_items, &rkconf_items,
2415 <     &nresv_items, &cluster_items,  &gdeny_items, NULL
2415 >     &nresv_items, &cluster_items,  &gdeny_items, &service_items, NULL
2416    };
2417  
2418    dlink_list ** iterator = free_items; /* C is dumb */
# Line 2566 | Line 2429 | clear_out_old_conf(void)
2429        /* XXX This is less than pretty */
2430        if (conf->type == SERVER_TYPE)
2431        {
2432 <        aconf = (struct AccessItem *)map_to_conf(conf);
2432 >        aconf = map_to_conf(conf);
2433 >
2434          if (aconf->clients != 0)
2435          {
2436            SetConfIllegal(aconf);
# Line 2579 | Line 2443 | clear_out_old_conf(void)
2443        }
2444        else if (conf->type == OPER_TYPE)
2445        {
2446 <        aconf = (struct AccessItem *)map_to_conf(conf);
2446 >        aconf = map_to_conf(conf);
2447 >
2448          if (aconf->clients != 0)
2449          {
2450            SetConfIllegal(aconf);
# Line 2590 | Line 2455 | clear_out_old_conf(void)
2455            delete_conf_item(conf);
2456          }
2457        }
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      }
2458        else if (conf->type == XLINE_TYPE  ||
2459                 conf->type == RXLINE_TYPE ||
2460                 conf->type == RKLINE_TYPE)
# Line 2615 | Line 2468 | clear_out_old_conf(void)
2468        }
2469        else
2470        {
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
2471            delete_conf_item(conf);
2472        }
2473      }
2474    }
2475  
2476 <  /* don't delete the class table, rather mark all entries
2476 >  /*
2477 >   * don't delete the class table, rather mark all entries
2478     * for deletion. The table is cleaned up by check_class. - avalon
2479     */
2480    DLINK_FOREACH(ptr, class_items.head)
2481    {
2482 <    conf = ptr->data;
2483 <    cltmp = (struct ClassItem *)map_to_conf(conf);
2482 >    cltmp = map_to_conf(ptr->data);
2483 >
2484      if (ptr != class_items.tail)  /* never mark the "default" class */
2485 <      MaxTotal(cltmp) = -1;
2485 >      cltmp->active = 0;
2486    }
2487  
2488    clear_out_address_conf();
2489  
2490    /* clean out module paths */
2649 #ifndef STATIC_MODULES
2491    mod_clear_paths();
2651 #endif
2492  
2493    /* clean out ServerInfo */
2494    MyFree(ServerInfo.description);
# Line 2668 | Line 2508 | clear_out_old_conf(void)
2508  
2509    MyFree(ServerInfo.rsa_private_key_file);
2510    ServerInfo.rsa_private_key_file = NULL;
2511 +
2512 +  if (ServerInfo.server_ctx)
2513 +    SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|
2514 +                                               SSL_OP_NO_SSLv3|
2515 +                                               SSL_OP_NO_TLSv1);
2516 +  if (ServerInfo.client_ctx)
2517 +    SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|
2518 +                                               SSL_OP_NO_SSLv3|
2519 +                                               SSL_OP_NO_TLSv1);
2520   #endif
2521  
2522    /* clean out old resvs from the conf */
# Line 2690 | Line 2539 | clear_out_old_conf(void)
2539     */
2540  
2541    /* clean out general */
2542 <  MyFree(ConfigFileEntry.servlink_path);
2543 <  ConfigFileEntry.servlink_path = NULL;
2544 < #ifdef HAVE_LIBCRYPTO
2696 <  ConfigFileEntry.default_cipher_preference = NULL;
2697 < #endif /* HAVE_LIBCRYPTO */
2542 >  MyFree(ConfigFileEntry.service_name);
2543 >  ConfigFileEntry.service_name = NULL;
2544 >
2545    delete_isupport("INVEX");
2546    delete_isupport("EXCEPTS");
2547   }
# Line 2805 | Line 2652 | get_conf_ping(struct ConfItem *conf, int
2652      if (aconf->class_ptr != NULL)
2653      {
2654        aclass = (struct ClassItem *)map_to_conf(aconf->class_ptr);
2655 <      *pingwarn = PingWarning(aclass);
2656 <      return PingFreq(aclass);
2655 >      *pingwarn = aclass->ping_warning;
2656 >      return aclass->ping_freq;
2657      }
2658    }
2659  
# Line 2822 | Line 2669 | get_conf_ping(struct ConfItem *conf, int
2669   const char *
2670   get_client_class(struct Client *target_p)
2671   {
2672 <  dlink_node *ptr;
2673 <  struct ConfItem *conf;
2827 <  struct AccessItem *aconf;
2672 >  dlink_node *cnode = NULL;
2673 >  struct AccessItem *aconf = NULL;
2674  
2675 <  if (target_p != NULL && !IsMe(target_p) &&
2676 <      target_p->localClient->confs.head != NULL)
2675 >  assert(!IsMe(target_p));
2676 >
2677 >  if ((cnode = target_p->localClient->confs.head))
2678    {
2679 <    DLINK_FOREACH(ptr, target_p->localClient->confs.head)
2833 <    {
2834 <      conf = ptr->data;
2679 >    struct ConfItem *conf = cnode->data;
2680  
2681 <      if (conf->type == CLIENT_TYPE || conf->type == SERVER_TYPE ||
2682 <          conf->type == OPER_TYPE)
2683 <      {
2684 <        aconf = (struct AccessItem *) map_to_conf(conf);
2685 <        if (aconf->class_ptr != NULL)
2686 <          return aconf->class_ptr->name;
2842 <      }
2843 <    }
2681 >    assert((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2682 >          (conf->type == OPER_TYPE));
2683 >
2684 >    aconf = map_to_conf(conf);
2685 >    if (aconf->class_ptr != NULL)
2686 >      return aconf->class_ptr->name;
2687    }
2688  
2689    return "default";
# Line 2856 | Line 2699 | get_client_class(struct Client *target_p
2699   int
2700   get_client_ping(struct Client *target_p, int *pingwarn)
2701   {
2702 <  int ping;
2703 <  struct ConfItem *conf;
2861 <  dlink_node *nlink;
2702 >  int ping = 0;
2703 >  dlink_node *cnode = NULL;
2704  
2705 <  if (target_p->localClient->confs.head != NULL)
2706 <    DLINK_FOREACH(nlink, target_p->localClient->confs.head)
2707 <    {
2866 <      conf = nlink->data;
2705 >  if ((cnode = target_p->localClient->confs.head))
2706 >  {
2707 >    struct ConfItem *conf = cnode->data;
2708  
2709 <      if ((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2710 <          (conf->type == OPER_TYPE))
2711 <      {
2712 <        ping = get_conf_ping(conf, pingwarn);
2713 <        if (ping > 0)
2714 <          return ping;
2715 <      }
2875 <    }
2709 >    assert((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2710 >          (conf->type == OPER_TYPE));
2711 >
2712 >    ping = get_conf_ping(conf, pingwarn);
2713 >    if (ping > 0)
2714 >      return ping;
2715 >  }
2716  
2717    *pingwarn = 0;
2718    return DEFAULT_PINGFREQUENCY;
# Line 2889 | Line 2729 | find_class(const char *classname)
2729   {
2730    struct ConfItem *conf;
2731  
2732 <  if ((conf = find_exact_name_conf(CLASS_TYPE, classname, NULL, NULL)) != NULL)
2733 <    return(conf);
2732 >  if ((conf = find_exact_name_conf(CLASS_TYPE, NULL, classname, NULL, NULL)) != NULL)
2733 >    return conf;
2734  
2735    return class_default;
2736   }
# Line 2904 | Line 2744 | find_class(const char *classname)
2744   void
2745   check_class(void)
2746   {
2747 <  dlink_node *ptr;
2908 <  dlink_node *next_ptr;
2909 <  struct ConfItem *conf;
2910 <  struct ClassItem *aclass;
2747 >  dlink_node *ptr = NULL, *next_ptr = NULL;
2748  
2749    DLINK_FOREACH_SAFE(ptr, next_ptr, class_items.head)
2750    {
2751 <    conf = ptr->data;
2915 <    aclass = (struct ClassItem *)map_to_conf(conf);
2751 >    struct ClassItem *aclass = map_to_conf(ptr->data);
2752  
2753 <    if (MaxTotal(aclass) < 0)
2753 >    if (!aclass->active && !aclass->curr_user_count)
2754      {
2755        destroy_cidr_class(aclass);
2756 <      if (CurrUserCount(aclass) > 0)
2921 <        dlinkDelete(&conf->node, &class_items);
2922 <      else
2923 <        delete_conf_item(conf);
2756 >      delete_conf_item(ptr->data);
2757      }
2758    }
2759   }
# Line 2937 | Line 2770 | init_class(void)
2770    struct ClassItem *aclass;
2771  
2772    class_default = make_conf_item(CLASS_TYPE);
2773 <  aclass = (struct ClassItem *)map_to_conf(class_default);
2773 >
2774 >  aclass = map_to_conf(class_default);
2775 >  aclass->active = 1;
2776    DupString(class_default->name, "default");
2777 <  ConFreq(aclass)  = DEFAULT_CONNECTFREQUENCY;
2778 <  PingFreq(aclass) = DEFAULT_PINGFREQUENCY;
2779 <  MaxTotal(aclass) = MAXIMUM_LINKS_DEFAULT;
2780 <  MaxSendq(aclass) = DEFAULT_SENDQ;
2777 >  aclass->con_freq  = DEFAULT_CONNECTFREQUENCY;
2778 >  aclass->ping_freq = DEFAULT_PINGFREQUENCY;
2779 >  aclass->max_total = MAXIMUM_LINKS_DEFAULT;
2780 >  aclass->max_sendq = DEFAULT_SENDQ;
2781  
2782    client_check_cb = register_callback("check_client", check_client);
2783   }
# Line 2953 | Line 2788 | init_class(void)
2788   * output       - sendq for this client as found from its class
2789   * side effects - NONE
2790   */
2791 < unsigned long
2791 > unsigned int
2792   get_sendq(struct Client *client_p)
2793   {
2794 <  unsigned long sendq = DEFAULT_SENDQ;
2795 <  dlink_node *ptr;
2961 <  struct ConfItem *conf;
2794 >  unsigned int sendq = DEFAULT_SENDQ;
2795 >  dlink_node *cnode;
2796    struct ConfItem *class_conf;
2797    struct ClassItem *aclass;
2798    struct AccessItem *aconf;
2799  
2800 <  if (client_p && !IsMe(client_p) && (client_p->localClient->confs.head))
2800 >  assert(!IsMe(client_p));
2801 >
2802 >  if ((cnode = client_p->localClient->confs.head))
2803    {
2804 <    DLINK_FOREACH(ptr, client_p->localClient->confs.head)
2805 <    {
2806 <      conf = ptr->data;
2807 <      if ((conf->type == SERVER_TYPE) || (conf->type == OPER_TYPE)
2808 <          || (conf->type == CLIENT_TYPE))
2809 <      {
2810 <        aconf = (struct AccessItem *)map_to_conf(conf);
2811 <        if ((class_conf = aconf->class_ptr) == NULL)
2812 <          continue;
2813 <        aclass = (struct ClassItem *)map_to_conf(class_conf);
2814 <        sendq = MaxSendq(aclass);
2815 <        return sendq;
2816 <      }
2981 <    }
2804 >    struct ConfItem *conf = cnode->data;
2805 >
2806 >    assert((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2807 >          (conf->type == OPER_TYPE));
2808 >
2809 >    aconf = map_to_conf(conf);
2810 >
2811 >    if ((class_conf = aconf->class_ptr) == NULL)
2812 >      return DEFAULT_SENDQ; /* TBV: shouldn't be possible at all */
2813 >
2814 >    aclass = map_to_conf(class_conf);
2815 >    sendq = aclass->max_sendq;
2816 >    return sendq;
2817    }
2818 +
2819    /* XXX return a default?
2820     * if here, then there wasn't an attached conf with a sendq
2821     * that is very bad -Dianora
# Line 2996 | Line 2832 | get_sendq(struct Client *client_p)
2832   void
2833   conf_add_class_to_conf(struct ConfItem *conf, const char *class_name)
2834   {
2835 <  struct AccessItem *aconf;
2836 <  struct ClassItem *aclass;
3001 <
3002 <  aconf = (struct AccessItem *)map_to_conf(conf);
2835 >  struct AccessItem *aconf = map_to_conf(conf);
2836 >  struct ClassItem *class = NULL;
2837  
2838    if (class_name == NULL)
2839    {
2840      aconf->class_ptr = class_default;
2841 +
2842      if (conf->type == CLIENT_TYPE)
2843        sendto_realops_flags(UMODE_ALL, L_ALL,
2844                             "Warning *** Defaulting to default class for %s@%s",
# Line 3014 | Line 2849 | conf_add_class_to_conf(struct ConfItem *
2849                             conf->name);
2850    }
2851    else
3017  {
2852      aconf->class_ptr = find_class(class_name);
3019  }
2853  
2854 <  if (aconf->class_ptr == NULL)
2854 >  if (aconf->class_ptr)
2855 >    class = map_to_conf(aconf->class_ptr);
2856 >
2857 >  if (aconf->class_ptr == NULL || !class->active)
2858    {
2859      if (conf->type == CLIENT_TYPE)
2860        sendto_realops_flags(UMODE_ALL, L_ALL,
# Line 3030 | Line 2866 | conf_add_class_to_conf(struct ConfItem *
2866                             conf->name);
2867      aconf->class_ptr = class_default;
2868    }
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  }
2869   }
2870  
3043 #define MAXCONFLINKS 150
3044
2871   /* conf_add_server()
2872   *
2873   * inputs       - pointer to config item
# Line 3050 | Line 2876 | conf_add_class_to_conf(struct ConfItem *
2876   * side effects - Add a connect block
2877   */
2878   int
2879 < conf_add_server(struct ConfItem *conf, unsigned int lcount, const char *class_name)
2879 > conf_add_server(struct ConfItem *conf, const char *class_name)
2880   {
2881 <  struct AccessItem *aconf;
3056 <  char *orig_host;
3057 <
3058 <  aconf = map_to_conf(conf);
2881 >  struct AccessItem *aconf = map_to_conf(conf);
2882  
2883    conf_add_class_to_conf(conf, class_name);
2884  
2885 <  if (lcount > MAXCONFLINKS || !aconf->host || !conf->name)
2885 >  if (!aconf->host || !conf->name)
2886    {
2887      sendto_realops_flags(UMODE_ALL, L_ALL, "Bad connect block");
2888 <    ilog(L_WARN, "Bad connect block");
2888 >    ilog(LOG_TYPE_IRCD, "Bad connect block");
2889      return -1;
2890    }
2891  
2892 <  if (EmptyString(aconf->passwd) && !IsConfCryptLink(aconf))
2892 >  if (EmptyString(aconf->passwd))
2893    {
2894      sendto_realops_flags(UMODE_ALL, L_ALL, "Bad connect block, name %s",
2895                           conf->name);
2896 <    ilog(L_WARN, "Bad connect block, host %s", conf->name);
2896 >    ilog(LOG_TYPE_IRCD, "Bad connect block, host %s", conf->name);
2897      return -1;
2898    }
2899  
3077  orig_host = aconf->host;
3078  split_nuh(orig_host, NULL, &aconf->user, &aconf->host);
3079  MyFree(orig_host);
2900    lookup_confhost(conf);
2901  
2902    return 0;
2903   }
2904  
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
2905   /* yyerror()
2906   *
2907   * inputs       - message from parser
# Line 3124 | Line 2913 | yyerror(const char *msg)
2913   {
2914    char newlinebuf[IRCD_BUFSIZE];
2915  
2916 <  if (ypass != 1)
2916 >  if (conf_parser_ctx.pass != 1)
2917      return;
2918  
2919    strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
2920    sendto_realops_flags(UMODE_ALL, L_ALL, "\"%s\", line %u: %s: %s",
2921                         conffilebuf, lineno + 1, msg, newlinebuf);
2922 <  ilog(L_WARN, "\"%s\", line %u: %s: %s",
2922 >  ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
2923         conffilebuf, lineno + 1, msg, newlinebuf);
2924   }
2925  
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
2926   /*
2927   * valid_tkline()
2928   *
# Line 3160 | Line 2934 | conf_yy_fatal_error(const char *msg)
2934   * Originally written by Dianora (Diane, db@db.net)
2935   */
2936   time_t
2937 < valid_tkline(char *p, int minutes)
2937 > valid_tkline(const char *p, int minutes)
2938   {
2939    time_t result = 0;
2940  
2941 <  while (*p)
2941 >  for (; *p; ++p)
2942    {
2943 <    if (IsDigit(*p))
3170 <    {
3171 <      result *= 10;
3172 <      result += ((*p) & 0xF);
3173 <      p++;
3174 <    }
3175 <    else
2943 >    if (!IsDigit(*p))
2944        return 0;
2945 +
2946 +    result *= 10;
2947 +    result += ((*p) & 0xF);
2948    }
2949  
2950 <  /* in the degenerate case where oper does a /quote kline 0 user@host :reason
2950 >  /*
2951 >   * In the degenerate case where oper does a /quote kline 0 user@host :reason
2952     * i.e. they specifically use 0, I am going to return 1 instead
2953     * as a return value of non-zero is used to flag it as a temporary kline
2954     */
3183
2955    if (result == 0)
2956      result = 1;
2957  
# Line 3281 | Line 3052 | valid_wild_card(struct Client *source_p,
3052   *                if target_server is NULL and an "ON" is found error
3053   *                is reported.
3054   *                if reason pointer is NULL ignore pointer,
3055 < *                this allows usee of parse_a_line in unkline etc.
3055 > *                this allows use of parse_a_line in unkline etc.
3056   *
3057   * - Dianora
3058   */
# Line 3351 | Line 3122 | parse_aline(const char *cmd, struct Clie
3122          return -1;
3123        }
3124  
3125 <      if (!IsOperRemoteBan(source_p))
3125 >      if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN))
3126        {
3127          sendto_one(source_p, form_str(ERR_NOPRIVS),
3128                     me.name, source_p->name, "remoteban");
# Line 3388 | Line 3159 | parse_aline(const char *cmd, struct Clie
3159        return -1;
3160      }
3161  
3162 <    if ((parse_flags & AWILD) && !valid_wild_card(source_p, YES, 2, *up_p, *h_p))
3162 >    if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 2, *up_p, *h_p))
3163        return -1;
3164    }
3165    else
3166 <    if ((parse_flags & AWILD) && !valid_wild_card(source_p, YES, 1, *up_p))
3166 >    if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 1, *up_p))
3167        return -1;
3168  
3169    if (reason != NULL)
3170    {
3171 <    if (parc != 0)
3171 >    if (parc != 0 && !EmptyString(*parv))
3172      {
3173        *reason = *parv;
3174 <      if (!valid_comment(source_p, *reason, YES))
3174 >      if (!valid_comment(source_p, *reason, 1))
3175          return -1;
3176      }
3177      else
# Line 3436 | Line 3207 | find_user_host(struct Client *source_p,
3207    {
3208      /* Explicit user@host mask given */
3209  
3210 <    if(hostp != NULL)                            /* I'm a little user@host */
3210 >    if (hostp != NULL)                            /* I'm a little user@host */
3211      {
3212        *(hostp++) = '\0';                       /* short and squat */
3213        if (*user_host_or_nick)
# Line 3531 | Line 3302 | match_conf_password(const char *password
3302   {
3303    const char *encr = NULL;
3304  
3305 <  if (password == NULL || aconf->passwd == NULL)
3305 >  if (EmptyString(password) || EmptyString(aconf->passwd))
3306      return 0;
3307  
3308    if (aconf->flags & CONF_FLAGS_ENCRYPTED)
3309 <  {
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 <  }
3309 >    encr = crypt(password, aconf->passwd);
3310    else
3311      encr = password;
3312  
# Line 3559 | Line 3319 | match_conf_password(const char *password
3319   * inputs       - client sending the cluster
3320   *              - command name "KLINE" "XLINE" etc.
3321   *              - capab -- CAP_KLN etc. from s_serv.h
3322 < *              - cluster type -- CLUSTER_KLINE etc. from s_conf.h
3322 > *              - cluster type -- CLUSTER_KLINE etc. from conf.h
3323   *              - pattern and args to send along
3324   * output       - none
3325   * side effects - Take source_p send the pattern with args given
# Line 3567 | Line 3327 | match_conf_password(const char *password
3327   */
3328   void
3329   cluster_a_line(struct Client *source_p, const char *command,
3330 <               int capab, int cluster_type, const char *pattern, ...)
3330 >               int capab, int cluster_type, const char *pattern, ...)
3331   {
3332    va_list args;
3333    char buffer[IRCD_BUFSIZE];
3334 <  struct ConfItem *conf;
3575 <  dlink_node *ptr;
3334 >  const dlink_node *ptr = NULL;
3335  
3336    va_start(args, pattern);
3337    vsnprintf(buffer, sizeof(buffer), pattern, args);
# Line 3580 | Line 3339 | cluster_a_line(struct Client *source_p,
3339  
3340    DLINK_FOREACH(ptr, cluster_items.head)
3341    {
3342 <    conf = ptr->data;
3342 >    const struct ConfItem *conf = ptr->data;
3343  
3344      if (conf->flags & cluster_type)
3586    {
3345        sendto_match_servs(source_p, conf->name, CAP_CLUSTER|capab,
3346                           "%s %s %s", command, conf->name, buffer);
3589    }
3347    }
3348   }
3349  
# Line 3618 | Line 3375 | cluster_a_line(struct Client *source_p,
3375   * @                            *       *       *
3376   * !                            *       *       *
3377   */
3621
3378   void
3379 < split_nuh(char *mask, char **nick, char **user, char **host)
3379 > split_nuh(struct split_nuh_item *const iptr)
3380   {
3381    char *p = NULL, *q = NULL;
3382  
3383 <  if ((p = strchr(mask, '!')) != NULL)
3383 >  if (iptr->nickptr)
3384 >    strlcpy(iptr->nickptr, "*", iptr->nicksize);
3385 >  if (iptr->userptr)
3386 >    strlcpy(iptr->userptr, "*", iptr->usersize);
3387 >  if (iptr->hostptr)
3388 >    strlcpy(iptr->hostptr, "*", iptr->hostsize);
3389 >
3390 >  if ((p = strchr(iptr->nuhmask, '!')))
3391    {
3392      *p = '\0';
3630    if (nick != NULL)
3631    {
3632      if (*mask != '\0')
3633        *nick = xstrldup(mask, NICKLEN);
3634      else
3635        DupString(*nick, "*");
3636    }
3393  
3394 <    if ((q = strchr(++p, '@')) != NULL)
3395 <    {
3396 <      *q = '\0';
3394 >    if (iptr->nickptr && *iptr->nuhmask != '\0')
3395 >      strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
3396 >
3397 >    if ((q = strchr(++p, '@'))) {
3398 >      *q++ = '\0';
3399  
3400        if (*p != '\0')
3401 <        *user = xstrldup(p, USERLEN+1);
3644 <      else
3645 <        DupString(*user, "*");
3401 >        strlcpy(iptr->userptr, p, iptr->usersize);
3402  
3403 <      if (*++q != '\0')
3404 <        *host = xstrldup(q, HOSTLEN+1);
3649 <      else
3650 <        DupString(*host, "*");
3403 >      if (*q != '\0')
3404 >        strlcpy(iptr->hostptr, q, iptr->hostsize);
3405      }
3406      else
3407      {
3408        if (*p != '\0')
3409 <        *user = xstrldup(p, USERLEN+1);
3656 <      else
3657 <        DupString(*user, "*");
3658 <
3659 <      DupString(*host, "*");
3409 >        strlcpy(iptr->userptr, p, iptr->usersize);
3410      }
3411    }
3412 <  else  /* No ! found so lets look for a user@host */
3412 >  else
3413    {
3414 <    if ((p = strchr(mask, '@')) != NULL)        /* if found a @ */
3414 >    /* No ! found so lets look for a user@host */
3415 >    if ((p = strchr(iptr->nuhmask, '@')))
3416      {
3417 <      if (nick != NULL)
3418 <        DupString(*nick, "*");
3668 <      *p = '\0';
3417 >      /* if found a @ */
3418 >      *p++ = '\0';
3419  
3420 <      if (*mask != '\0')
3421 <        *user = xstrldup(mask, USERLEN+1);
3672 <      else
3673 <        DupString(*user, "*");
3420 >      if (*iptr->nuhmask != '\0')
3421 >        strlcpy(iptr->userptr, iptr->nuhmask, iptr->usersize);
3422  
3423 <      if (*++p != '\0')
3424 <        *host = xstrldup(p, HOSTLEN+1);
3677 <      else
3678 <        DupString(*host, "*");
3423 >      if (*p != '\0')
3424 >        strlcpy(iptr->hostptr, p, iptr->hostsize);
3425      }
3426 <    else                                        /* no @ found */
3426 >    else
3427      {
3428 <      if (nick != NULL)
3429 <      {
3430 <        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 <      }
3428 >      /* no @ found */
3429 >      if (!iptr->nickptr || strpbrk(iptr->nuhmask, ".:"))
3430 >        strlcpy(iptr->hostptr, iptr->nuhmask, iptr->hostsize);
3431        else
3432 <      {
3699 <        DupString(*user, "*");
3700 <        *host = xstrldup(mask, HOSTLEN+1);
3701 <      }
3432 >        strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
3433      }
3434    }
3435   }
# Line 3725 | Line 3456 | flags_to_ascii(unsigned int flags, const
3456    {
3457      if (flags & mask)
3458        *p++ = bit_table[i];
3459 <    else if(lowerit)
3459 >    else if (lowerit)
3460        *p++ = ToLower(bit_table[i]);
3461    }
3462    *p = '\0';
# Line 3748 | Line 3479 | cidr_limit_reached(int over_rule,
3479    dlink_node *ptr = NULL;
3480    struct CidrItem *cidr;
3481  
3482 <  if (NumberPerCidr(aclass) <= 0)
3482 >  if (aclass->number_per_cidr <= 0)
3483      return 0;
3484  
3485    if (ip->ss.ss_family == AF_INET)
3486    {
3487 <    if (CidrBitlenIPV4(aclass) <= 0)
3487 >    if (aclass->cidr_bitlen_ipv4 <= 0)
3488        return 0;
3489  
3490      DLINK_FOREACH(ptr, aclass->list_ipv4.head)
3491      {
3492        cidr = ptr->data;
3493 <      if (match_ipv4(ip, &cidr->mask, CidrBitlenIPV4(aclass)))
3493 >      if (match_ipv4(ip, &cidr->mask, aclass->cidr_bitlen_ipv4))
3494        {
3495 <        if (!over_rule && (cidr->number_on_this_cidr >= NumberPerCidr(aclass)))
3495 >        if (!over_rule && (cidr->number_on_this_cidr >= aclass->number_per_cidr))
3496            return -1;
3497          cidr->number_on_this_cidr++;
3498          return 0;
# Line 3770 | Line 3501 | cidr_limit_reached(int over_rule,
3501      cidr = MyMalloc(sizeof(struct CidrItem));
3502      cidr->number_on_this_cidr = 1;
3503      cidr->mask = *ip;
3504 <    mask_addr(&cidr->mask, CidrBitlenIPV4(aclass));
3504 >    mask_addr(&cidr->mask, aclass->cidr_bitlen_ipv4);
3505      dlinkAdd(cidr, &cidr->node, &aclass->list_ipv4);
3506    }
3507   #ifdef IPV6
3508 <  else if (CidrBitlenIPV6(aclass) > 0)
3508 >  else if (aclass->cidr_bitlen_ipv6 > 0)
3509    {
3510      DLINK_FOREACH(ptr, aclass->list_ipv6.head)
3511      {
3512        cidr = ptr->data;
3513 <      if (match_ipv6(ip, &cidr->mask, CidrBitlenIPV6(aclass)))
3513 >      if (match_ipv6(ip, &cidr->mask, aclass->cidr_bitlen_ipv6))
3514        {
3515 <        if (!over_rule && (cidr->number_on_this_cidr >= NumberPerCidr(aclass)))
3515 >        if (!over_rule && (cidr->number_on_this_cidr >= aclass->number_per_cidr))
3516            return -1;
3517          cidr->number_on_this_cidr++;
3518          return 0;
# Line 3790 | Line 3521 | cidr_limit_reached(int over_rule,
3521      cidr = MyMalloc(sizeof(struct CidrItem));
3522      cidr->number_on_this_cidr = 1;
3523      cidr->mask = *ip;
3524 <    mask_addr(&cidr->mask, CidrBitlenIPV6(aclass));
3524 >    mask_addr(&cidr->mask, aclass->cidr_bitlen_ipv6);
3525      dlinkAdd(cidr, &cidr->node, &aclass->list_ipv6);
3526    }
3527   #endif
# Line 3812 | Line 3543 | remove_from_cidr_check(struct irc_ssaddr
3543    dlink_node *next_ptr = NULL;
3544    struct CidrItem *cidr;
3545  
3546 <  if (NumberPerCidr(aclass) == 0)
3546 >  if (aclass->number_per_cidr == 0)
3547      return;
3548  
3549    if (ip->ss.ss_family == AF_INET)
3550    {
3551 <    if (CidrBitlenIPV4(aclass) <= 0)
3551 >    if (aclass->cidr_bitlen_ipv4 <= 0)
3552        return;
3553  
3554      DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv4.head)
3555      {
3556        cidr = ptr->data;
3557 <      if (match_ipv4(ip, &cidr->mask, CidrBitlenIPV4(aclass)))
3557 >      if (match_ipv4(ip, &cidr->mask, aclass->cidr_bitlen_ipv4))
3558        {
3559          cidr->number_on_this_cidr--;
3560          if (cidr->number_on_this_cidr == 0)
# Line 3836 | Line 3567 | remove_from_cidr_check(struct irc_ssaddr
3567      }
3568    }
3569   #ifdef IPV6
3570 <  else if (CidrBitlenIPV6(aclass) > 0)
3570 >  else if (aclass->cidr_bitlen_ipv6 > 0)
3571    {
3572      DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv6.head)
3573      {
3574        cidr = ptr->data;
3575 <      if (match_ipv6(ip, &cidr->mask, CidrBitlenIPV6(aclass)))
3575 >      if (match_ipv6(ip, &cidr->mask, aclass->cidr_bitlen_ipv6))
3576        {
3577          cidr->number_on_this_cidr--;
3578          if (cidr->number_on_this_cidr == 0)
# Line 3904 | Line 3635 | rebuild_cidr_class(struct ConfItem *conf
3635   {
3636    struct ClassItem *old_class = map_to_conf(conf);
3637  
3638 <  if (NumberPerCidr(old_class) > 0 && NumberPerCidr(new_class) > 0)
3638 >  if (old_class->number_per_cidr > 0 && new_class->number_per_cidr > 0)
3639    {
3640 <    if (CidrBitlenIPV4(old_class) > 0 && CidrBitlenIPV4(new_class) > 0)
3640 >    if (old_class->cidr_bitlen_ipv4 > 0 && new_class->cidr_bitlen_ipv4 > 0)
3641        rebuild_cidr_list(AF_INET, conf, new_class,
3642                          &old_class->list_ipv4, &new_class->list_ipv4,
3643 <                        CidrBitlenIPV4(old_class) != CidrBitlenIPV4(new_class));
3643 >                        old_class->cidr_bitlen_ipv4 != new_class->cidr_bitlen_ipv4);
3644  
3645   #ifdef IPV6
3646 <    if (CidrBitlenIPV6(old_class) > 0 && CidrBitlenIPV6(new_class) > 0)
3646 >    if (old_class->cidr_bitlen_ipv6 > 0 && new_class->cidr_bitlen_ipv6 > 0)
3647        rebuild_cidr_list(AF_INET6, conf, new_class,
3648                          &old_class->list_ipv6, &new_class->list_ipv6,
3649 <                        CidrBitlenIPV6(old_class) != CidrBitlenIPV6(new_class));
3649 >                        old_class->cidr_bitlen_ipv6 != new_class->cidr_bitlen_ipv6);
3650   #endif
3651    }
3652  
# Line 3932 | Line 3663 | rebuild_cidr_class(struct ConfItem *conf
3663   static void
3664   destroy_cidr_list(dlink_list *list)
3665   {
3666 <  dlink_node *ptr = NULL;
3936 <  dlink_node *next_ptr = NULL;
3937 <  struct CidrItem *cidr;
3666 >  dlink_node *ptr = NULL, *next_ptr = NULL;
3667  
3668    DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
3669    {
3941    cidr = ptr->data;
3670      dlinkDelete(ptr, list);
3671 <    MyFree(cidr);
3671 >    MyFree(ptr->data);
3672    }
3673   }
3674  

Diff Legend

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