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 1503 by michael, Tue Aug 14 09:05:58 2012 UTC

# Line 1 | Line 1
1   /*
2   *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  s_conf.c: Configuration file functions.
3 > *  conf.c: Configuration file functions.
4   *
5   *  Copyright (C) 2002 by the past and present ircd coders, and others.
6   *
# Line 23 | Line 23
23   */
24  
25   #include "stdinc.h"
26 + #include "list.h"
27   #include "ircd_defs.h"
28 < #include "tools.h"
29 < #include "s_conf.h"
28 > #include "balloc.h"
29 > #include "conf.h"
30   #include "s_serv.h"
31   #include "resv.h"
31 #include "s_stats.h"
32   #include "channel.h"
33   #include "client.h"
34 #include "common.h"
34   #include "event.h"
36 #include "hash.h"
35   #include "hook.h"
36   #include "irc_string.h"
39 #include "sprintf_irc.h"
37   #include "s_bsd.h"
41 #include "irc_getnameinfo.h"
42 #include "irc_getaddrinfo.h"
38   #include "ircd.h"
44 #include "list.h"
39   #include "listener.h"
40   #include "hostmask.h"
41   #include "modules.h"
42   #include "numeric.h"
43   #include "fdlist.h"
44 < #include "s_log.h"
44 > #include "log.h"
45   #include "send.h"
46   #include "s_gline.h"
53 #include "fileio.h"
47   #include "memory.h"
48   #include "irc_res.h"
49   #include "userhost.h"
50   #include "s_user.h"
51   #include "channel_mode.h"
52 + #include "parse.h"
53 + #include "s_misc.h"
54  
55   struct Callback *client_check_cb = NULL;
56   struct config_server_hide ConfigServerHide;
57  
58   /* general conf items link list root, other than k lines etc. */
59 + dlink_list service_items = { NULL, NULL, 0 };
60   dlink_list server_items  = { NULL, NULL, 0 };
61   dlink_list cluster_items = { NULL, NULL, 0 };
66 dlink_list hub_items     = { NULL, NULL, 0 };
67 dlink_list leaf_items    = { NULL, NULL, 0 };
62   dlink_list oconf_items   = { NULL, NULL, 0 };
63   dlink_list uconf_items   = { NULL, NULL, 0 };
64   dlink_list xconf_items   = { NULL, NULL, 0 };
# Line 72 | Line 66 | dlink_list rxconf_items  = { NULL, NULL,
66   dlink_list rkconf_items  = { NULL, NULL, 0 };
67   dlink_list nresv_items   = { NULL, NULL, 0 };
68   dlink_list class_items   = { NULL, NULL, 0 };
75 dlink_list gdeny_items   = { NULL, NULL, 0 };
69  
77 dlink_list temporary_klines  = { NULL, NULL, 0 };
78 dlink_list temporary_dlines  = { NULL, NULL, 0 };
70   dlink_list temporary_xlines  = { NULL, NULL, 0 };
80 dlink_list temporary_rklines = { NULL, NULL, 0 };
81 dlink_list temporary_glines  = { NULL, NULL, 0 };
82 dlink_list temporary_rxlines = { NULL, NULL, 0 };
71   dlink_list temporary_resv = { NULL, NULL, 0 };
72  
73   extern unsigned int lineno;
74   extern char linebuf[];
75   extern char conffilebuf[IRCD_BUFSIZE];
88 extern char yytext[];
76   extern int yyparse(); /* defined in y.tab.c */
77 < unsigned int scount = 0; /* used by yyparse(), etc */
78 < int ypass  = 1; /* used by yyparse()      */
77 >
78 > struct conf_parser_context conf_parser_ctx = { 0, 0, NULL };
79  
80   /* internally defined functions */
81 < static void lookup_confhost(struct ConfItem *);
95 < static void set_default_conf(void);
96 < static void validate_conf(void);
97 < static void read_conf(FBFILE *);
81 > static void read_conf(FILE *);
82   static void clear_out_old_conf(void);
83   static void flush_deleted_I_P(void);
84   static void expire_tklines(dlink_list *);
# Line 117 | Line 101 | static void destroy_cidr_class(struct Cl
101  
102   static void flags_to_ascii(unsigned int, const unsigned int[], char *, int);
103  
120 FBFILE *conf_fbfile_in = NULL;
121
104   /* address of default class conf */
105   static struct ConfItem *class_default;
106  
# Line 141 | Line 123 | static BlockHeap *ip_entry_heap = NULL;
123   static int ip_entries_count = 0;
124  
125  
126 < inline void *
126 > void *
127   map_to_conf(struct ConfItem *aconf)
128   {
129    void *conf;
130 <  conf = (void *)((unsigned long)aconf +
131 <                  (unsigned long)sizeof(struct ConfItem));
130 >  conf = (void *)((uintptr_t)aconf +
131 >                  (uintptr_t)sizeof(struct ConfItem));
132    return(conf);
133   }
134  
135 < inline struct ConfItem *
135 > struct ConfItem *
136   unmap_conf_item(void *aconf)
137   {
138    struct ConfItem *conf;
139  
140 <  conf = (struct ConfItem *)((unsigned long)aconf -
141 <                             (unsigned long)sizeof(struct ConfItem));
140 >  conf = (struct ConfItem *)((uintptr_t)aconf -
141 >                             (uintptr_t)sizeof(struct ConfItem));
142    return(conf);
143   }
144  
# Line 171 | Line 153 | unmap_conf_item(void *aconf)
153   * if successful save hp in the conf item it was called with
154   */
155   static void
156 < conf_dns_callback(void *vptr, struct DNSReply *reply)
156 > conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name)
157   {
158 <  struct AccessItem *aconf = (struct AccessItem *)vptr;
177 <  struct ConfItem *conf;
158 >  struct AccessItem *aconf = vptr;
159  
160 <  MyFree(aconf->dns_query);
180 <  aconf->dns_query = NULL;
160 >  aconf->dns_pending = 0;
161  
162 <  if (reply != NULL)
163 <    memcpy(&aconf->ipnum, &reply->addr, sizeof(reply->addr));
164 <  else {
165 <    ilog(L_NOTICE, "Host not found: %s, ignoring connect{} block",
186 <         aconf->host);
187 <    conf = unmap_conf_item(aconf);
188 <    sendto_realops_flags(UMODE_ALL, L_ALL,
189 <                         "Ignoring connect{} block for %s - host not found",
190 <                         conf->name);
191 <    delete_conf_item(conf);
192 <  }
162 >  if (addr != NULL)
163 >    memcpy(&aconf->addr, addr, sizeof(aconf->addr));
164 >  else
165 >    aconf->dns_failed = 1;
166   }
167  
168   /* conf_dns_lookup()
# Line 201 | Line 174 | conf_dns_callback(void *vptr, struct DNS
174   static void
175   conf_dns_lookup(struct AccessItem *aconf)
176   {
177 <  if (aconf->dns_query == NULL)
177 >  if (!aconf->dns_pending)
178    {
179 <    aconf->dns_query = MyMalloc(sizeof(struct DNSQuery));
180 <    aconf->dns_query->ptr = aconf;
208 <    aconf->dns_query->callback = conf_dns_callback;
209 <    gethost_byname(aconf->host, aconf->dns_query);
179 >    aconf->dns_pending = 1;
180 >    gethost_byname(conf_dns_callback, aconf, aconf->host);
181    }
182   }
183  
# Line 277 | Line 248 | make_conf_item(ConfType type)
248      aconf->status = status;
249      break;
250  
280  case LEAF_TYPE:
281    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
282                                       sizeof(struct MatchItem));
283    dlinkAdd(conf, &conf->node, &leaf_items);
284    break;
285
286  case HUB_TYPE:
287    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
288                                       sizeof(struct MatchItem));
289    dlinkAdd(conf, &conf->node, &hub_items);
290    break;
291
251    case ULINE_TYPE:
252      conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
253                                         sizeof(struct MatchItem));
254      dlinkAdd(conf, &conf->node, &uconf_items);
255      break;
256  
298  case GDENY_TYPE:
299    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
300                                       sizeof(struct AccessItem));
301    dlinkAdd(conf, &conf->node, &gdeny_items);
302    break;
303
257    case XLINE_TYPE:
258      conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
259                                         sizeof(struct MatchItem));
260      dlinkAdd(conf, &conf->node, &xconf_items);
261      break;
262 <
262 > #ifdef HAVE_LIBPCRE
263    case RXLINE_TYPE:
264      conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
265                                         sizeof(struct MatchItem));
# Line 320 | Line 273 | make_conf_item(ConfType type)
273      aconf->status = CONF_KLINE;
274      dlinkAdd(conf, &conf->node, &rkconf_items);
275      break;
276 <
276 > #endif
277    case CLUSTER_TYPE:
278      conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem));
279      dlinkAdd(conf, &conf->node, &cluster_items);
# Line 337 | Line 290 | make_conf_item(ConfType type)
290      dlinkAdd(conf, &conf->node, &nresv_items);
291      break;
292  
293 +  case SERVICE_TYPE:
294 +    status = CONF_SERVICE;
295 +    conf = MyMalloc(sizeof(struct ConfItem));
296 +    dlinkAdd(conf, &conf->node, &service_items);
297 +    break;
298 +
299    case CLASS_TYPE:
300 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
301 <                                       sizeof(struct ClassItem));
300 >    conf = MyMalloc(sizeof(struct ConfItem) +
301 >                           sizeof(struct ClassItem));
302      dlinkAdd(conf, &conf->node, &class_items);
303 <    aclass = (struct ClassItem *)map_to_conf(conf);
304 <    ConFreq(aclass)  = DEFAULT_CONNECTFREQUENCY;
305 <    PingFreq(aclass) = DEFAULT_PINGFREQUENCY;
306 <    MaxTotal(aclass) = MAXIMUM_LINKS_DEFAULT;
307 <    MaxSendq(aclass) = DEFAULT_SENDQ;
308 <    CurrUserCount(aclass) = 0;
303 >
304 >    aclass = map_to_conf(conf);
305 >    aclass->active = 1;
306 >    aclass->con_freq = DEFAULT_CONNECTFREQUENCY;
307 >    aclass->ping_freq = DEFAULT_PINGFREQUENCY;
308 >    aclass->max_total = MAXIMUM_LINKS_DEFAULT;
309 >    aclass->max_sendq = DEFAULT_SENDQ;
310 >
311      break;
312  
313    default:
# Line 357 | Line 318 | make_conf_item(ConfType type)
318    /* XXX Yes, this will core if default is hit. I want it to for now - db */
319    conf->type = type;
320  
321 <  return(conf);
321 >  return conf;
322   }
323  
324   void
325   delete_conf_item(struct ConfItem *conf)
326   {
327 +  dlink_node *m = NULL, *m_next = NULL;
328    struct MatchItem *match_item;
329    struct AccessItem *aconf;
330    ConfType type = conf->type;
# Line 381 | Line 343 | delete_conf_item(struct ConfItem *conf)
343    case SERVER_TYPE:
344      aconf = map_to_conf(conf);
345  
346 <    if (aconf->dns_query != NULL)
347 <    {
386 <      delete_resolver_queries(aconf->dns_query);
387 <      MyFree(aconf->dns_query);
388 <    }
346 >    if (aconf->dns_pending)
347 >      delete_resolver_queries(aconf);
348      if (aconf->passwd != NULL)
349        memset(aconf->passwd, 0, strlen(aconf->passwd));
350      if (aconf->spasswd != NULL)
# Line 398 | Line 357 | delete_conf_item(struct ConfItem *conf)
357      MyFree(aconf->oper_reason);
358      MyFree(aconf->user);
359      MyFree(aconf->host);
401    MyFree(aconf->fakename);
360   #ifdef HAVE_LIBCRYPTO
361 +    MyFree(aconf->cipher_list);
362 +
363      if (aconf->rsa_public_key)
364        RSA_free(aconf->rsa_public_key);
365      MyFree(aconf->rsa_public_key_file);
# Line 425 | Line 385 | delete_conf_item(struct ConfItem *conf)
385  
386      case SERVER_TYPE:
387        aconf = map_to_conf(conf);
388 +
389 +      DLINK_FOREACH_SAFE(m, m_next, aconf->hub_list.head)
390 +      {
391 +        MyFree(m->data);
392 +        free_dlink_node(m);
393 +      }
394 +
395 +      DLINK_FOREACH_SAFE(m, m_next, aconf->leaf_list.head)
396 +      {
397 +        MyFree(m->data);
398 +        free_dlink_node(m);  
399 +      }
400 +
401        if (!IsConfIllegal(aconf))
402          dlinkDelete(&conf->node, &server_items);
403        MyFree(conf);
# Line 435 | Line 408 | delete_conf_item(struct ConfItem *conf)
408      }
409      break;
410  
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
411    case ULINE_TYPE:
412      match_item = map_to_conf(conf);
413      MyFree(match_item->user);
# Line 478 | Line 427 | delete_conf_item(struct ConfItem *conf)
427      dlinkDelete(&conf->node, &xconf_items);
428      MyFree(conf);
429      break;
430 <
430 > #ifdef HAVE_LIBPCRE
431    case RKLINE_TYPE:
432      aconf = map_to_conf(conf);
433      MyFree(aconf->regexuser);
# Line 501 | Line 450 | delete_conf_item(struct ConfItem *conf)
450      dlinkDelete(&conf->node, &rxconf_items);
451      MyFree(conf);
452      break;
453 <
453 > #endif
454    case NRESV_TYPE:
455      match_item = map_to_conf(conf);
456      MyFree(match_item->user);
# Line 509 | Line 458 | delete_conf_item(struct ConfItem *conf)
458      MyFree(match_item->reason);
459      MyFree(match_item->oper_reason);
460      dlinkDelete(&conf->node, &nresv_items);
512    MyFree(conf);
513    break;
461  
462 <  case GDENY_TYPE:
463 <    aconf = map_to_conf(conf);
464 <    MyFree(aconf->user);
465 <    MyFree(aconf->host);
519 <    dlinkDelete(&conf->node, &gdeny_items);
462 >    if (conf->flags & CONF_FLAGS_TEMPORARY)
463 >      if ((m = dlinkFindDelete(&temporary_resv, conf)) != NULL)
464 >        free_dlink_node(m);
465 >
466      MyFree(conf);
467      break;
468  
# Line 526 | Line 472 | delete_conf_item(struct ConfItem *conf)
472      break;
473  
474    case CRESV_TYPE:
475 +    if (conf->flags & CONF_FLAGS_TEMPORARY)
476 +      if ((m = dlinkFindDelete(&temporary_resv, conf)) != NULL)
477 +        free_dlink_node(m);
478 +
479      MyFree(conf);
480      break;
481  
# Line 534 | Line 484 | delete_conf_item(struct ConfItem *conf)
484      MyFree(conf);
485      break;
486  
487 +  case SERVICE_TYPE:
488 +    dlinkDelete(&conf->node, &service_items);
489 +    MyFree(conf);
490 +    break;
491 +
492    default:
493      break;
494    }
# Line 567 | Line 522 | static const unsigned int shared_bit_tab
522   * side effects -
523   */
524   void
525 < report_confitem_types(struct Client *source_p, ConfType type, int temp)
525 > report_confitem_types(struct Client *source_p, ConfType type)
526   {
527 <  dlink_node *ptr = NULL;
527 >  dlink_node *ptr = NULL, *dptr = NULL;
528    struct ConfItem *conf = NULL;
529    struct AccessItem *aconf = NULL;
530    struct MatchItem *matchitem = NULL;
# Line 579 | Line 534 | report_confitem_types(struct Client *sou
534  
535    switch (type)
536    {
582  case GDENY_TYPE:
583    DLINK_FOREACH(ptr, gdeny_items.head)
584    {
585      conf = ptr->data;
586      aconf = map_to_conf(conf);
587
588      p = buf;
589
590      if (aconf->flags & GDENY_BLOCK)
591        *p++ = 'B';
592      else
593        *p++ = 'b';
594
595      if (aconf->flags & GDENY_REJECT)
596        *p++ = 'R';
597      else
598        *p++ = 'r';
599
600      *p = '\0';
601
602      sendto_one(source_p, ":%s %d %s V %s@%s %s %s",
603                 me.name, RPL_STATSDEBUG, source_p->name,
604                 aconf->user, aconf->host, conf->name, buf);
605    }
606    break;
607
537    case XLINE_TYPE:
538      DLINK_FOREACH(ptr, xconf_items.head)
539      {
# Line 618 | Line 547 | report_confitem_types(struct Client *sou
547      }
548      break;
549  
550 + #ifdef HAVE_LIBPCRE
551    case RXLINE_TYPE:
552      DLINK_FOREACH(ptr, rxconf_items.head)
553      {
# Line 626 | Line 556 | report_confitem_types(struct Client *sou
556  
557        sendto_one(source_p, form_str(RPL_STATSXLINE),
558                   me.name, source_p->name,
559 <                 matchitem->hold ? "xR": "XR", matchitem->count,
559 >                 "XR", matchitem->count,
560                   conf->name, matchitem->reason);
561      }
562      break;
563  
564    case RKLINE_TYPE:
635    p = temp ? "Rk" : "RK";
636
565      DLINK_FOREACH(ptr, rkconf_items.head)
566      {
567        aconf = map_to_conf((conf = ptr->data));
568  
641      if (temp && !(conf->flags & CONF_FLAGS_TEMPORARY))
642        continue;
643
569        sendto_one(source_p, form_str(RPL_STATSKLINE), me.name,
570 <                 source_p->name, p, aconf->host, aconf->user,
570 >                 source_p->name, "KR", aconf->host, aconf->user,
571                   aconf->reason, aconf->oper_reason ? aconf->oper_reason : "");
572      }
573      break;
574 + #endif
575  
576    case ULINE_TYPE:
577      DLINK_FOREACH(ptr, uconf_items.head)
# Line 690 | Line 616 | report_confitem_types(struct Client *sou
616        aconf = map_to_conf(conf);
617  
618        /* Don't allow non opers to see oper privs */
619 <      if (IsOper(source_p))
619 >      if (HasUMode(source_p, UMODE_OPER))
620          sendto_one(source_p, form_str(RPL_STATSOLINE),
621                     me.name, source_p->name, 'O', aconf->user, aconf->host,
622                     conf->name, oper_privs_as_string(aconf->port),
# Line 710 | Line 636 | report_confitem_types(struct Client *sou
636        classitem = map_to_conf(conf);
637        sendto_one(source_p, form_str(RPL_STATSYLINE),
638                   me.name, source_p->name, 'Y',
639 <                 conf->name, PingFreq(classitem),
640 <                 ConFreq(classitem),
641 <                 MaxTotal(classitem), MaxSendq(classitem));
639 >                 conf->name, classitem->ping_freq,
640 >                 classitem->con_freq,
641 >                 classitem->max_total, classitem->max_sendq,
642 >                 classitem->curr_user_count,
643 >                 classitem->number_per_cidr, classitem->cidr_bitlen_ipv4,
644 >                 classitem->number_per_cidr, classitem->cidr_bitlen_ipv6,
645 >                 classitem->active ? "active" : "disabled");
646      }
647      break;
648  
# Line 720 | Line 650 | report_confitem_types(struct Client *sou
650    case CLIENT_TYPE:
651      break;
652  
653 +  case SERVICE_TYPE:
654 +    DLINK_FOREACH(ptr, service_items.head)
655 +    {
656 +      conf = ptr->data;
657 +      sendto_one(source_p, form_str(RPL_STATSSERVICE),
658 +                 me.name, source_p->name, 'S', "*", conf->name, 0, 0);
659 +    }
660 +    break;
661 +
662    case SERVER_TYPE:
663      DLINK_FOREACH(ptr, server_items.head)
664      {
# Line 732 | Line 671 | report_confitem_types(struct Client *sou
671  
672        if (IsConfAllowAutoConn(aconf))
673          *p++ = 'A';
674 <      if (IsConfCryptLink(aconf))
675 <        *p++ = 'C';
737 <      if (IsConfLazyLink(aconf))
738 <        *p++ = 'L';
739 <      if (aconf->fakename)
740 <        *p++ = 'M';
674 >      if (IsConfSSL(aconf))
675 >        *p++ = 'S';
676        if (IsConfTopicBurst(aconf))
677          *p++ = 'T';
743      if (IsConfCompressed(aconf))
744        *p++ = 'Z';
678        if (buf[0] == '\0')
679          *p++ = '*';
680  
681        *p = '\0';
682  
683 <      /* Allow admins to see actual ips
684 <       * unless hide_server_ips is enabled
683 >      /*
684 >       * Allow admins to see actual ips unless hide_server_ips is enabled
685         */
686 <      if (!ConfigServerHide.hide_server_ips && IsAdmin(source_p))
686 >      if (!ConfigServerHide.hide_server_ips && HasUMode(source_p, UMODE_ADMIN))
687          sendto_one(source_p, form_str(RPL_STATSCLINE),
688                     me.name, source_p->name, 'C', aconf->host,
689                     buf, conf->name, aconf->port,
# Line 764 | Line 697 | report_confitem_types(struct Client *sou
697      break;
698  
699    case HUB_TYPE:
700 <    DLINK_FOREACH(ptr, hub_items.head)
700 >    DLINK_FOREACH(ptr, server_items.head)
701      {
702        conf = ptr->data;
703 <      matchitem = map_to_conf(conf);
704 <      sendto_one(source_p, form_str(RPL_STATSHLINE), me.name,
705 <                 source_p->name, 'H', matchitem->host, conf->name, 0, "*");
703 >      aconf = map_to_conf(conf);
704 >
705 >      DLINK_FOREACH(dptr, aconf->hub_list.head)
706 >        sendto_one(source_p, form_str(RPL_STATSHLINE), me.name,
707 >                   source_p->name, 'H', dptr->data, conf->name, 0, "*");
708      }
709      break;
710  
711    case LEAF_TYPE:
712 <    DLINK_FOREACH(ptr, leaf_items.head)
712 >    DLINK_FOREACH(ptr, server_items.head)
713      {
714        conf = ptr->data;
715 <      matchitem = map_to_conf(conf);
716 <      sendto_one(source_p, form_str(RPL_STATSLLINE), me.name,
717 <                 source_p->name, 'L', matchitem->host, conf->name, 0, "*");
715 >      aconf = map_to_conf(conf);
716 >
717 >      DLINK_FOREACH(dptr, aconf->leaf_list.head)
718 >        sendto_one(source_p, form_str(RPL_STATSLLINE), me.name,
719 >                   source_p->name, 'L', dptr->data, conf->name, 0, "*");
720      }
721      break;
722  
# Line 790 | Line 727 | report_confitem_types(struct Client *sou
727    case CRESV_TYPE:
728    case NRESV_TYPE:
729    case CLUSTER_TYPE:
730 +  default:
731      break;
732    }
733   }
# Line 816 | Line 754 | check_client(va_list args)
754  
755    /* I'm already in big trouble if source_p->localClient is NULL -db */
756    if ((i = verify_access(source_p, username)))
757 <  {
820 <    ilog(L_INFO, "Access denied: %s[%s]",
757 >    ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
758           source_p->name, source_p->sockhost);
822  }
759  
760    switch (i)
761    {
826    case IRCD_SOCKET_ERROR:
827      exit_client(source_p, &me, "Socket Error");
828      break;
829
762      case TOO_MANY:
763        sendto_realops_flags(UMODE_FULL, L_ALL,
764                             "Too many on IP for %s (%s).",
765                             get_client_name(source_p, SHOW_IP),
766                             source_p->sockhost);
767 <      ilog(L_INFO,"Too many connections on IP from %s.",
767 >      ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
768             get_client_name(source_p, SHOW_IP));
769 <      ServerStats->is_ref++;
769 >      ++ServerStats.is_ref;
770        exit_client(source_p, &me, "No more connections allowed on that IP");
771        break;
772  
# Line 843 | Line 775 | check_client(va_list args)
775                             "I-line is full for %s (%s).",
776                             get_client_name(source_p, SHOW_IP),
777                             source_p->sockhost);
778 <      ilog(L_INFO,"Too many connections from %s.",
778 >      ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
779             get_client_name(source_p, SHOW_IP));
780 <       ServerStats->is_ref++;
780 >      ++ServerStats.is_ref;
781        exit_client(source_p, &me,
782                  "No more connections allowed in your connection class");
783        break;
784  
785      case NOT_AUTHORIZED:
786 <    {
855 <      static char ipaddr[HOSTIPLEN];
856 <      ServerStats->is_ref++;
786 >      ++ServerStats.is_ref;
787        /* jdc - lists server name & port connections are on */
788        /*       a purely cosmetical change */
859      irc_getnameinfo((struct sockaddr*)&source_p->localClient->ip,
860            source_p->localClient->ip.ss_len, ipaddr, HOSTIPLEN, NULL, 0,
861            NI_NUMERICHOST);
789        sendto_realops_flags(UMODE_UNAUTH, L_ALL,
790                             "Unauthorized client connection from %s [%s] on [%s/%u].",
791                             get_client_name(source_p, SHOW_IP),
792 <                           ipaddr,
792 >                           source_p->sockhost,
793                             source_p->localClient->listener->name,
794                             source_p->localClient->listener->port);
795 <      ilog(L_INFO,
795 >      ilog(LOG_TYPE_IRCD,
796            "Unauthorized client connection from %s on [%s/%u].",
797            get_client_name(source_p, SHOW_IP),
798            source_p->localClient->listener->name,
# Line 875 | Line 802 | check_client(va_list args)
802         * capture reject code here or rely on the connecting too fast code.
803         * - Dianora
804         */
805 <      if(REJECT_HOLD_TIME > 0)
805 >      if (REJECT_HOLD_TIME > 0)
806        {
807          sendto_one(source_p, ":%s NOTICE %s :You are not authorized to use this server",
808                     me.name, source_p->name);
# Line 885 | Line 812 | check_client(va_list args)
812        else
813          exit_client(source_p, &me, "You are not authorized to use this server");
814        break;
815 <    }
889 <
815 >
816     case BANNED_CLIENT:
817       /*
818        * Don't exit them immediately, play with them a bit.
# Line 899 | Line 825 | check_client(va_list args)
825       }
826       else
827         exit_client(source_p, &me, "Banned");
828 <     ServerStats->is_ref++;
828 >     ++ServerStats.is_ref;
829       break;
830  
831     case 0:
# Line 1016 | Line 942 | attach_iline(struct Client *client_p, st
942    ip_found->count++;
943    SetIpHash(client_p);
944  
945 <  aconf = (struct AccessItem *)map_to_conf(conf);
945 >  aconf = map_to_conf(conf);
946    if (aconf->class_ptr == NULL)
947      return NOT_AUTHORIZED;  /* If class is missing, this is best */
948  
949 <  aclass = (struct ClassItem *)map_to_conf(aconf->class_ptr);
949 >  aclass = map_to_conf(aconf->class_ptr);
950  
951    count_user_host(client_p->username, client_p->host,
952                    &global, &local, &ident);
# Line 1029 | Line 955 | attach_iline(struct Client *client_p, st
955     * setting a_limit_reached if any limit is reached.
956     * - Dianora
957     */
958 <  if (MaxTotal(aclass) != 0 && CurrUserCount(aclass) >= MaxTotal(aclass))
958 >  if (aclass->max_total != 0 && aclass->curr_user_count >= aclass->max_total)
959      a_limit_reached = 1;
960 <  else if (MaxPerIp(aclass) != 0 && ip_found->count >= MaxPerIp(aclass))
960 >  else if (aclass->max_perip != 0 && ip_found->count > aclass->max_perip)
961      a_limit_reached = 1;
962 <  else if (MaxLocal(aclass) != 0 && local >= MaxLocal(aclass))
962 >  else if (aclass->max_local != 0 && local >= aclass->max_local)
963      a_limit_reached = 1;
964 <  else if (MaxGlobal(aclass) != 0 && global >= MaxGlobal(aclass))
964 >  else if (aclass->max_global != 0 && global >= aclass->max_global)
965      a_limit_reached = 1;
966 <  else if (MaxIdent(aclass) != 0 && ident >= MaxIdent(aclass) &&
966 >  else if (aclass->max_ident != 0 && ident >= aclass->max_ident &&
967             client_p->username[0] != '~')
968      a_limit_reached = 1;
969  
970    if (a_limit_reached)
971    {
972      if (!IsConfExemptLimits(aconf))
973 <      return TOO_MANY;  /* Already at maximum allowed */
973 >      return TOO_MANY;   /* Already at maximum allowed */
974  
975      sendto_one(client_p,
976                 ":%s NOTICE %s :*** Your connection class is full, "
# Line 1193 | Line 1119 | hash_ip(struct irc_ssaddr *addr)
1119    {
1120      struct sockaddr_in *v4 = (struct sockaddr_in *)addr;
1121      int hash;
1122 <    u_int32_t ip;
1122 >    uint32_t ip;
1123  
1124      ip   = ntohl(v4->sin_addr.s_addr);
1125      hash = ((ip >> 12) + ip) & (IP_HASH_SIZE-1);
# Line 1204 | Line 1130 | hash_ip(struct irc_ssaddr *addr)
1130    {
1131      int hash;
1132      struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr;
1133 <    u_int32_t *ip = (u_int32_t *)&v6->sin6_addr.s6_addr;
1133 >    uint32_t *ip = (uint32_t *)&v6->sin6_addr.s6_addr;
1134  
1135      hash  = ip[0] ^ ip[3];
1136      hash ^= hash >> 16;  
# Line 1228 | Line 1154 | hash_ip(struct irc_ssaddr *addr)
1154   * used in the hash.
1155   */
1156   void
1157 < count_ip_hash(int *number_ips_stored, unsigned long *mem_ips_stored)
1157 > count_ip_hash(unsigned int *number_ips_stored, uint64_t *mem_ips_stored)
1158   {
1159    struct ip_entry *ptr;
1160    int i;
# Line 1316 | Line 1242 | detach_conf(struct Client *client_p, Con
1242        case CLIENT_TYPE:
1243        case OPER_TYPE:
1244        case SERVER_TYPE:
1245 <        aconf = (struct AccessItem *)map_to_conf(conf);
1246 <        if ((aclass_conf = ClassPtr(aconf)) != NULL)
1245 >        aconf = map_to_conf(conf);
1246 >
1247 >        assert(aconf->clients > 0);
1248 >
1249 >        if ((aclass_conf = aconf->class_ptr) != NULL)
1250          {
1251 <          aclass = (struct ClassItem *)map_to_conf(aclass_conf);
1251 >          aclass = map_to_conf(aclass_conf);
1252 >
1253 >          assert(aclass->curr_user_count > 0);
1254  
1255            if (conf->type == CLIENT_TYPE)
1256              remove_from_cidr_check(&client_p->localClient->ip, aclass);
1257 <
1327 <          if (CurrUserCount(aclass) > 0)
1328 <            aclass->curr_user_count--;
1329 <          if (MaxTotal(aclass) < 0 && CurrUserCount(aclass) <= 0)
1257 >          if (--aclass->curr_user_count == 0 && aclass->active == 0)
1258              delete_conf_item(aclass_conf);
1259          }
1260  
1261 <        /* 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)
1261 >        if (--aconf->clients == 0 && IsConfIllegal(aconf))
1262            delete_conf_item(conf);
1263 +
1264          break;
1265        default:
1266          break;
# Line 1367 | Line 1287 | detach_conf(struct Client *client_p, Con
1287   int
1288   attach_conf(struct Client *client_p, struct ConfItem *conf)
1289   {
1290 <  struct AccessItem *aconf;
1291 <  struct MatchItem *match_item;
1290 >  struct AccessItem *aconf = map_to_conf(conf);
1291 >  struct ClassItem *aclass = map_to_conf(aconf->class_ptr);
1292  
1293    if (dlinkFind(&client_p->localClient->confs, conf) != NULL)
1294      return 1;
1295  
1296 <  if (conf->type == CLIENT_TYPE ||
1297 <      conf->type == SERVER_TYPE ||
1378 <      conf->type == OPER_TYPE)
1379 <  {
1380 <    aconf = (struct AccessItem *)map_to_conf(conf);
1296 >  if (IsConfIllegal(aconf)) /* TBV: can't happen */
1297 >    return NOT_AUTHORIZED;
1298  
1299 <    if (IsConfIllegal(aconf))
1300 <      return NOT_AUTHORIZED;
1299 >  if (conf->type == CLIENT_TYPE)
1300 >    if (cidr_limit_reached(IsConfExemptLimits(aconf),
1301 >                           &client_p->localClient->ip, aclass))
1302 >      return TOO_MANY;    /* Already at maximum allowed */
1303  
1304 <    if (conf->type == CLIENT_TYPE)
1305 <    {
1387 <      struct ClassItem *aclass;
1388 <      aclass = (struct ClassItem *)map_to_conf(aconf->class_ptr);
1389 <
1390 <      if (cidr_limit_reached(IsConfExemptLimits(aconf),
1391 <                             &client_p->localClient->ip, aclass))
1392 <        return TOO_MANY;  /* Already at maximum allowed */
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 <  }
1304 >  aclass->curr_user_count++;
1305 >  aconf->clients++;
1306  
1307    dlinkAdd(conf, make_dlink_node(), &client_p->localClient->confs);
1308  
# Line 1432 | Line 1334 | attach_connect_block(struct Client *clie
1334    DLINK_FOREACH(ptr, server_items.head)
1335    {
1336      conf = ptr->data;
1337 <    aconf = (struct AccessItem *)map_to_conf(conf);
1337 >    aconf = map_to_conf(conf);
1338  
1339      if (match(conf->name, name) == 0 || match(aconf->host, host) == 0)
1340        continue;
# Line 1472 | Line 1374 | find_conf_exact(ConfType type, const cha
1374  
1375      if (conf->name == NULL)
1376        continue;
1377 <    aconf = (struct AccessItem *)map_to_conf(conf);
1377 >    aconf = map_to_conf(conf);
1378      if (aconf->host == NULL)
1379        continue;
1380      if (irccmp(conf->name, name) != 0)
# Line 1483 | Line 1385 | find_conf_exact(ConfType type, const cha
1385      ** socket host) matches *either* host or name field
1386      ** of the configuration.
1387      */
1388 <    if (!match(aconf->host, host) || !match(aconf->user,user)
1487 <        || irccmp(conf->name, name) )
1388 >    if (!match(aconf->host, host) || !match(aconf->user, user))
1389        continue;
1390      if (type == OPER_TYPE)
1391      {
1392 <      struct ClassItem *aclass;
1392 >      struct ClassItem *aclass = map_to_conf(aconf->class_ptr);
1393  
1394 <      aclass = (struct ClassItem *)aconf->class_ptr;
1494 <      if (aconf->clients < MaxTotal(aclass))
1495 <        return conf;
1496 <      else
1394 >      if (aconf->clients >= aclass->max_total)
1395          continue;
1396      }
1397 <    else
1398 <      return conf;
1397 >
1398 >    return conf;
1399    }
1400 +
1401    return NULL;
1402   }
1403  
# Line 1564 | Line 1463 | map_to_list(ConfType type)
1463    case SERVER_TYPE:
1464      return(&server_items);
1465      break;
1466 +  case SERVICE_TYPE:
1467 +    return(&service_items);
1468 +    break;
1469    case CLUSTER_TYPE:
1470      return(&cluster_items);
1471      break;
# Line 1599 | Line 1501 | find_matching_name_conf(ConfType type, c
1501  
1502    switch (type)
1503    {
1504 <    case RXLINE_TYPE:
1504 > #ifdef HAVE_LIBPCRE
1505 >  case RXLINE_TYPE:
1506        DLINK_FOREACH(ptr, list_p->head)
1507        {
1508          conf = ptr->data;
# Line 1609 | Line 1512 | find_matching_name_conf(ConfType type, c
1512            return conf;
1513        }
1514        break;
1515 + #endif
1516 +  case SERVICE_TYPE:
1517 +    DLINK_FOREACH(ptr, list_p->head)
1518 +    {
1519 +      conf = ptr->data;
1520 +
1521 +      if (EmptyString(conf->name))
1522 +        continue;
1523 +      if ((name != NULL) && !irccmp(name, conf->name))
1524 +        return conf;
1525 +    }
1526 +    break;
1527  
1528    case XLINE_TYPE:
1529    case ULINE_TYPE:
# Line 1663 | Line 1578 | find_matching_name_conf(ConfType type, c
1578   * side effects - looks for an exact match on name field
1579   */
1580   struct ConfItem *
1581 < find_exact_name_conf(ConfType type, const char *name,
1581 > find_exact_name_conf(ConfType type, const struct Client *who, const char *name,
1582                       const char *user, const char *host)
1583   {
1584    dlink_node *ptr = NULL;
# Line 1704 | Line 1619 | find_exact_name_conf(ConfType type, cons
1619      DLINK_FOREACH(ptr, list_p->head)
1620      {
1621        conf = ptr->data;
1622 <      aconf = (struct AccessItem *)map_to_conf(conf);
1622 >      aconf = map_to_conf(conf);
1623 >
1624        if (EmptyString(conf->name))
1625 <        continue;
1626 <    
1627 <      if (irccmp(conf->name, name) == 0)
1625 >        continue;
1626 >
1627 >      if (!irccmp(conf->name, name))
1628        {
1629 <        if ((user == NULL && (host == NULL)))
1630 <          return (conf);
1631 <        if (EmptyString(aconf->user) || EmptyString(aconf->host))
1632 <          return (conf);
1633 <        if (match(aconf->user, user) && match(aconf->host, host))
1634 <          return (conf);
1629 >        if (!who)
1630 >          return conf;
1631 >        if (EmptyString(aconf->user) || EmptyString(aconf->host))
1632 >          return conf;
1633 >        if (match(aconf->user, who->username))
1634 >        {
1635 >          switch (aconf->type)
1636 >          {
1637 >            case HM_HOST:
1638 >              if (match(aconf->host, who->host) || match(aconf->host, who->sockhost))
1639 >                return conf;
1640 >              break;
1641 >            case HM_IPV4:
1642 >              if (who->localClient->aftype == AF_INET)
1643 >                if (match_ipv4(&who->localClient->ip, &aconf->addr, aconf->bits))
1644 >                  return conf;
1645 >              break;
1646 > #ifdef IPV6
1647 >            case HM_IPV6:
1648 >              if (who->localClient->aftype == AF_INET6)
1649 >                if (match_ipv6(&who->localClient->ip, &aconf->addr, aconf->bits))
1650 >                  return conf;
1651 >              break;
1652 > #endif
1653 >            default:
1654 >              assert(0);
1655 >          }
1656 >        }
1657        }
1658      }
1659 +
1660      break;
1661  
1662    case SERVER_TYPE:
# Line 1773 | Line 1712 | rehash(int sig)
1712      sendto_realops_flags(UMODE_ALL, L_ALL,
1713                           "Got signal SIGHUP, reloading ircd.conf file");
1714  
1776 #ifndef _WIN32
1715    restart_resolver();
1716 < #endif
1716 >
1717    /* don't close listeners until we know we can go ahead with the rehash */
1718  
1719    /* Check to see if we magically got(or lost) IPv6 support */
# Line 1786 | Line 1724 | rehash(int sig)
1724    if (ServerInfo.description != NULL)
1725      strlcpy(me.info, ServerInfo.description, sizeof(me.info));
1726  
1789 #ifndef STATIC_MODULES
1727    load_conf_modules();
1791 #endif
1728  
1729    flush_deleted_I_P();
1730  
1731    rehashed_klines = 1;
1732 <
1732 > /* XXX */
1733    if (ConfigLoggingEntry.use_logging)
1734 <    reopen_log(logFileName);
1734 >    log_close_all();
1735  
1736    return(0);
1737   }
# Line 1834 | Line 1770 | set_default_conf(void)
1770    ServerInfo.specific_ipv6_vhost = 0;
1771  
1772    ServerInfo.max_clients = MAXCLIENTS_MAX;
1773 <  /* Don't reset hub, as that will break lazylinks */
1774 <  /* ServerInfo.hub = NO; */
1773 >
1774 >  ServerInfo.hub = 0;
1775    ServerInfo.dns_host.sin_addr.s_addr = 0;
1776    ServerInfo.dns_host.sin_port = 0;
1777    AdminInfo.name = NULL;
1778    AdminInfo.email = NULL;
1779    AdminInfo.description = NULL;
1780  
1781 <  set_log_level(L_NOTICE);
1781 >  log_close_all();
1782 >
1783    ConfigLoggingEntry.use_logging = 1;
1784 <  ConfigLoggingEntry.operlog[0] = '\0';
1785 <  ConfigLoggingEntry.userlog[0] = '\0';
1786 <  ConfigLoggingEntry.klinelog[0] = '\0';
1850 <  ConfigLoggingEntry.glinelog[0] = '\0';
1851 <  ConfigLoggingEntry.killlog[0] = '\0';
1852 <  ConfigLoggingEntry.operspylog[0] = '\0';
1853 <  ConfigLoggingEntry.ioerrlog[0] = '\0';
1854 <  ConfigLoggingEntry.failed_operlog[0] = '\0';
1855 <
1856 <  ConfigChannel.restrict_channels = NO;
1857 <  ConfigChannel.disable_local_channels = NO;
1858 <  ConfigChannel.use_invex = YES;
1859 <  ConfigChannel.use_except = YES;
1860 <  ConfigChannel.use_knock = YES;
1784 >
1785 >  ConfigChannel.disable_fake_channels = 0;
1786 >  ConfigChannel.restrict_channels = 0;
1787    ConfigChannel.knock_delay = 300;
1788    ConfigChannel.knock_delay_channel = 60;
1789 <  ConfigChannel.max_chans_per_user = 15;
1790 <  ConfigChannel.quiet_on_ban = YES;
1789 >  ConfigChannel.max_chans_per_user = 25;
1790 >  ConfigChannel.max_chans_per_oper = 50;
1791 >  ConfigChannel.quiet_on_ban = 1;
1792    ConfigChannel.max_bans = 25;
1793    ConfigChannel.default_split_user_count = 0;
1794    ConfigChannel.default_split_server_count = 0;
1795 <  ConfigChannel.no_join_on_split = NO;
1796 <  ConfigChannel.no_create_on_split = NO;
1870 <  ConfigChannel.burst_topicwho = YES;
1795 >  ConfigChannel.no_join_on_split = 0;
1796 >  ConfigChannel.no_create_on_split = 0;
1797  
1798 <  ConfigServerHide.flatten_links = NO;
1798 >  ConfigServerHide.flatten_links = 0;
1799    ConfigServerHide.links_delay = 300;
1800 <  ConfigServerHide.hidden = NO;
1801 <  ConfigServerHide.disable_hidden = NO;
1876 <  ConfigServerHide.hide_servers = NO;
1800 >  ConfigServerHide.hidden = 0;
1801 >  ConfigServerHide.hide_servers = 0;
1802    DupString(ConfigServerHide.hidden_name, NETWORK_NAME_DEFAULT);
1803 <  ConfigServerHide.hide_server_ips = NO;
1803 >  ConfigServerHide.hide_server_ips = 0;
1804  
1805 +  
1806 +  DupString(ConfigFileEntry.service_name, SERVICE_NAME_DEFAULT);
1807 +  ConfigFileEntry.max_watch = WATCHSIZE_DEFAULT;
1808 +  ConfigFileEntry.glines = 0;
1809 +  ConfigFileEntry.gline_time = 12 * 3600;
1810 +  ConfigFileEntry.gline_request_time = GLINE_REQUEST_EXPIRE_DEFAULT;
1811    ConfigFileEntry.gline_min_cidr = 16;
1812    ConfigFileEntry.gline_min_cidr6 = 48;
1813 <  ConfigFileEntry.invisible_on_connect = YES;
1814 <  ConfigFileEntry.burst_away = NO;
1815 <  ConfigFileEntry.use_whois_actually = YES;
1816 <  ConfigFileEntry.tkline_expire_notices = YES;
1817 <  ConfigFileEntry.hide_spoof_ips = YES;
1818 <  ConfigFileEntry.ignore_bogus_ts = NO;
1819 <  ConfigFileEntry.disable_auth = NO;
1820 <  ConfigFileEntry.disable_remote = NO;
1813 >  ConfigFileEntry.invisible_on_connect = 1;
1814 >  ConfigFileEntry.burst_away = 0;
1815 >  ConfigFileEntry.use_whois_actually = 1;
1816 >  ConfigFileEntry.tkline_expire_notices = 1;
1817 >  ConfigFileEntry.hide_spoof_ips = 1;
1818 >  ConfigFileEntry.ignore_bogus_ts = 0;
1819 >  ConfigFileEntry.disable_auth = 0;
1820 >  ConfigFileEntry.disable_remote = 0;
1821    ConfigFileEntry.kill_chase_time_limit = 90;
1822 <  ConfigFileEntry.default_floodcount = 8; /* XXX */
1823 <  ConfigFileEntry.failed_oper_notice = YES;
1824 <  ConfigFileEntry.dots_in_ident = 0;      /* XXX */
1894 <  ConfigFileEntry.dot_in_ip6_addr = YES;
1822 >  ConfigFileEntry.default_floodcount = 8;
1823 >  ConfigFileEntry.failed_oper_notice = 1;
1824 >  ConfigFileEntry.dots_in_ident = 0;
1825    ConfigFileEntry.min_nonwildcard = 4;
1826    ConfigFileEntry.min_nonwildcard_simple = 3;
1827    ConfigFileEntry.max_accept = 20;
1828 <  ConfigFileEntry.anti_nick_flood = NO;   /* XXX */
1828 >  ConfigFileEntry.anti_nick_flood = 0;
1829    ConfigFileEntry.max_nick_time = 20;
1830    ConfigFileEntry.max_nick_changes = 5;
1831 <  ConfigFileEntry.anti_spam_exit_message_time = 0;  /* XXX */
1831 >  ConfigFileEntry.anti_spam_exit_message_time = 0;
1832    ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
1833 <  ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;  /* XXX */
1834 <  ConfigFileEntry.kline_with_reason = YES;
1833 >  ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
1834 >  ConfigFileEntry.kline_with_reason = 1;
1835    ConfigFileEntry.kline_reason = NULL;
1836 <  ConfigFileEntry.warn_no_nline = YES;
1837 <  ConfigFileEntry.stats_o_oper_only = NO; /* XXX */
1836 >  ConfigFileEntry.warn_no_nline = 1;
1837 >  ConfigFileEntry.stats_o_oper_only = 0;
1838    ConfigFileEntry.stats_k_oper_only = 1;  /* masked */
1839    ConfigFileEntry.stats_i_oper_only = 1;  /* masked */
1840 <  ConfigFileEntry.stats_P_oper_only = NO;
1840 >  ConfigFileEntry.stats_P_oper_only = 0;
1841    ConfigFileEntry.caller_id_wait = 60;
1842 <  ConfigFileEntry.opers_bypass_callerid = NO;
1842 >  ConfigFileEntry.opers_bypass_callerid = 0;
1843    ConfigFileEntry.pace_wait = 10;
1844    ConfigFileEntry.pace_wait_simple = 1;
1845 <  ConfigFileEntry.short_motd = NO;
1846 <  ConfigFileEntry.ping_cookie = NO;
1847 <  ConfigFileEntry.no_oper_flood = NO;     /* XXX */
1848 <  ConfigFileEntry.true_no_oper_flood = NO;  /* XXX */
1849 <  ConfigFileEntry.oper_pass_resv = YES;
1920 <  ConfigFileEntry.glines = NO;            /* XXX */
1921 <  ConfigFileEntry.gline_time = 12 * 3600; /* XXX */
1922 <  ConfigFileEntry.idletime = 0;
1845 >  ConfigFileEntry.short_motd = 0;
1846 >  ConfigFileEntry.ping_cookie = 0;
1847 >  ConfigFileEntry.no_oper_flood = 0;
1848 >  ConfigFileEntry.true_no_oper_flood = 0;
1849 >  ConfigFileEntry.oper_pass_resv = 1;
1850    ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT;
1851    ConfigFileEntry.client_flood = CLIENT_FLOOD_DEFAULT;
1852 <  ConfigFileEntry.oper_only_umodes = UMODE_DEBUG;  /* XXX */
1853 <  ConfigFileEntry.oper_umodes = UMODE_LOCOPS | UMODE_SERVNOTICE |
1854 <    UMODE_OPERWALL | UMODE_WALLOP;        /* XXX */
1855 <  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;
1852 >  ConfigFileEntry.oper_only_umodes = UMODE_DEBUG;
1853 >  ConfigFileEntry.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE |
1854 >    UMODE_OPERWALL | UMODE_WALLOP;
1855 >  ConfigFileEntry.use_egd = 0;
1856    ConfigFileEntry.egdpool_path = NULL;
1942 #ifdef HAVE_LIBZ
1943  ConfigFileEntry.compression_level = 0;
1944 #endif
1857    ConfigFileEntry.throttle_time = 10;
1858   }
1859  
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
1860   static void
1861   validate_conf(void)
1862   {
# Line 1978 | Line 1866 | validate_conf(void)
1866    if (ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN)
1867      ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
1868  
1981  if (ConfigFileEntry.servlink_path == NULL)
1982    DupString(ConfigFileEntry.servlink_path, SLPATH);
1983
1869    if (ServerInfo.network_name == NULL)
1870      DupString(ServerInfo.network_name,NETWORK_NAME_DEFAULT);
1871  
1872    if (ServerInfo.network_desc == NULL)
1873      DupString(ServerInfo.network_desc,NETWORK_DESC_DEFAULT);
1874  
1875 +  if (ConfigFileEntry.service_name == NULL)
1876 +    DupString(ConfigFileEntry.service_name, SERVICE_NAME_DEFAULT);
1877 +
1878    if ((ConfigFileEntry.client_flood < CLIENT_FLOOD_MIN) ||
1879        (ConfigFileEntry.client_flood > CLIENT_FLOOD_MAX))
1880      ConfigFileEntry.client_flood = CLIENT_FLOOD_MAX;
1881 +
1882 +  ConfigFileEntry.max_watch = IRCD_MAX(ConfigFileEntry.max_watch, WATCHSIZE_MIN);
1883 + }
1884 +
1885 + /* read_conf()
1886 + *
1887 + * inputs       - file descriptor pointing to config file to use
1888 + * output       - None
1889 + * side effects - Read configuration file.
1890 + */
1891 + static void
1892 + read_conf(FILE *file)
1893 + {
1894 +  lineno = 0;
1895 +
1896 +  set_default_conf(); /* Set default values prior to conf parsing */
1897 +  conf_parser_ctx.pass = 1;
1898 +  yyparse();          /* pick up the classes first */
1899 +
1900 +  rewind(file);
1901 +
1902 +  conf_parser_ctx.pass = 2;
1903 +  yyparse();          /* Load the values from the conf */
1904 +  validate_conf();    /* Check to make sure some values are still okay. */
1905 +                      /* Some global values are also loaded here. */
1906 +  check_class();      /* Make sure classes are valid */
1907   }
1908  
1909   /* lookup_confhost()
# Line 2005 | Line 1919 | lookup_confhost(struct ConfItem *conf)
1919  
1920    aconf = map_to_conf(conf);
1921  
1922 <  if (EmptyString(aconf->host) ||
2009 <      EmptyString(aconf->user))
1922 >  if (has_wildcards(aconf->host))
1923    {
1924 <    ilog(L_ERROR, "Host/server name error: (%s) (%s)",
1924 >    ilog(LOG_TYPE_IRCD, "Host/server name error: (%s) (%s)",
1925           aconf->host, conf->name);
1926      return;
1927    }
1928  
2016  if (strchr(aconf->host, '*') ||
2017      strchr(aconf->host, '?'))
2018    return;
2019
1929    /* Do name lookup now on hostnames given and store the
1930     * ip numbers in conf structure.
1931     */
# Line 2028 | Line 1937 | lookup_confhost(struct ConfItem *conf)
1937    /* Get us ready for a bind() and don't bother doing dns lookup */
1938    hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
1939  
1940 <  if (irc_getaddrinfo(aconf->host, NULL, &hints, &res))
1940 >  if (getaddrinfo(aconf->host, NULL, &hints, &res))
1941    {
1942      conf_dns_lookup(aconf);
1943      return;
# Line 2036 | Line 1945 | lookup_confhost(struct ConfItem *conf)
1945  
1946    assert(res != NULL);
1947  
1948 <  memcpy(&aconf->ipnum, res->ai_addr, res->ai_addrlen);
1949 <  aconf->ipnum.ss_len = res->ai_addrlen;
1950 <  aconf->ipnum.ss.ss_family = res->ai_family;
1951 <  irc_freeaddrinfo(res);
1948 >  memcpy(&aconf->addr, res->ai_addr, res->ai_addrlen);
1949 >  aconf->addr.ss_len = res->ai_addrlen;
1950 >  aconf->addr.ss.ss_family = res->ai_family;
1951 >  freeaddrinfo(res);
1952   }
1953  
1954   /* conf_connect_allowed()
# Line 2078 | Line 1987 | conf_connect_allowed(struct irc_ssaddr *
1987   static struct AccessItem *
1988   find_regexp_kline(const char *uhi[])
1989   {
1990 + #ifdef HAVE_LIBPCRE
1991    const dlink_node *ptr = NULL;
1992  
1993    DLINK_FOREACH(ptr, rkconf_items.head)
# Line 2092 | Line 2002 | find_regexp_kline(const char *uhi[])
2002           !ircd_pcre_exec(aptr->regexhost, uhi[2])))
2003        return aptr;
2004    }
2005 <
2005 > #endif
2006    return NULL;
2007   }
2008  
# Line 2115 | Line 2025 | find_kill(struct Client *client_p)
2025  
2026    assert(client_p != NULL);
2027  
2028 <  aconf = find_kline_conf(client_p->host, client_p->username,
2029 <                          &client_p->localClient->ip,
2030 <                          client_p->localClient->aftype);
2028 >  aconf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
2029 >                               CONF_KLINE, client_p->localClient->aftype,
2030 >                               client_p->username, NULL, 1);
2031    if (aconf == NULL)
2032      aconf = find_regexp_kline(uhi);
2033  
2034 <  if (aconf && (aconf->status & CONF_KLINE))
2125 <    return aconf;
2126 <
2127 <  return NULL;
2034 >  return aconf;
2035   }
2036  
2037   struct AccessItem *
# Line 2134 | Line 2041 | find_gline(struct Client *client_p)
2041  
2042    assert(client_p != NULL);
2043  
2044 <  aconf = find_gline_conf(client_p->host, client_p->username,
2045 <                          &client_p->localClient->ip,
2046 <                          client_p->localClient->aftype);
2047 <
2141 <  if (aconf && (aconf->status & CONF_GLINE))
2142 <    return aconf;
2143 <
2144 <  return NULL;
2044 >  aconf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
2045 >                               CONF_GLINE, client_p->localClient->aftype,
2046 >                               client_p->username, NULL, 1);
2047 >  return aconf;
2048   }
2049  
2050   /* add_temp_line()
# Line 2154 | Line 2057 | find_gline(struct Client *client_p)
2057   void
2058   add_temp_line(struct ConfItem *conf)
2059   {
2060 <  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)
2060 >  if (conf->type == XLINE_TYPE)
2061    {
2062      conf->flags |= CONF_FLAGS_TEMPORARY;
2063      dlinkAdd(conf, make_dlink_node(), &temporary_xlines);
2064    }
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  }
2065    else if ((conf->type == NRESV_TYPE) || (conf->type == CRESV_TYPE))
2066    {
2067      conf->flags |= CONF_FLAGS_TEMPORARY;
# Line 2211 | Line 2079 | add_temp_line(struct ConfItem *conf)
2079   void
2080   cleanup_tklines(void *notused)
2081   {
2082 <  expire_tklines(&temporary_glines);
2215 <  expire_tklines(&temporary_klines);
2216 <  expire_tklines(&temporary_dlines);
2082 >  hostmask_expire_temporary();
2083    expire_tklines(&temporary_xlines);
2218  expire_tklines(&temporary_rxlines);
2219  expire_tklines(&temporary_rklines);
2084    expire_tklines(&temporary_resv);
2085   }
2086  
# Line 2234 | Line 2098 | expire_tklines(dlink_list *tklist)
2098    struct ConfItem *conf;
2099    struct MatchItem *xconf;
2100    struct MatchItem *nconf;
2237  struct AccessItem *aconf;
2101    struct ResvChannel *cconf;
2102  
2103    DLINK_FOREACH_SAFE(ptr, next_ptr, tklist->head)
2104    {
2105      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        }
2106  
2107 <        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)
2107 >    if (conf->type == XLINE_TYPE)
2108      {
2109        xconf = (struct MatchItem *)map_to_conf(conf);
2110        if (xconf->hold <= CurrentTime)
2111        {
2112          if (ConfigFileEntry.tkline_expire_notices)
2113            sendto_realops_flags(UMODE_ALL, L_ALL,
2114 <                               "Temporary X-line for [%s] %sexpired", conf->name,
2282 <                               conf->type == RXLINE_TYPE ? "(REGEX) " : "");
2114 >                               "Temporary X-line for [%s] sexpired", conf->name);
2115          dlinkDelete(ptr, tklist);
2116          free_dlink_node(ptr);
2117          delete_conf_item(conf);
2118        }
2119      }
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    }
2120      else if (conf->type == NRESV_TYPE)
2121      {
2122        nconf = (struct MatchItem *)map_to_conf(conf);
# Line 2321 | Line 2138 | expire_tklines(dlink_list *tklist)
2138          if (ConfigFileEntry.tkline_expire_notices)
2139            sendto_realops_flags(UMODE_ALL, L_ALL,
2140                                 "Temporary RESV for [%s] expired", cconf->name);
2141 <        dlinkDelete(ptr, tklist);
2325 <        free_dlink_node(ptr);
2326 <        delete_conf_item(conf);
2141 >        delete_channel_resv(cconf);
2142        }
2143      }
2144    }
# Line 2338 | Line 2153 | expire_tklines(dlink_list *tklist)
2153   static const struct oper_privs
2154   {
2155    const unsigned int oprivs;
2341  const unsigned int hidden;
2156    const unsigned char c;
2157   } flag_list[] = {
2158 <  { OPER_FLAG_ADMIN,       OPER_FLAG_HIDDEN_ADMIN,  'A' },
2159 <  { OPER_FLAG_REMOTEBAN,   0,                       'B' },
2160 <  { OPER_FLAG_DIE,         0,                       'D' },
2161 <  { OPER_FLAG_GLINE,       0,                       'G' },
2162 <  { OPER_FLAG_REHASH,      0,                       'H' },
2163 <  { OPER_FLAG_K,           0,                       'K' },
2164 <  { OPER_FLAG_OPERWALL,    0,                       'L' },
2165 <  { OPER_FLAG_N,           0,                       'N' },
2166 <  { OPER_FLAG_GLOBAL_KILL, 0,                       'O' },
2167 <  { OPER_FLAG_REMOTE,      0,                       'R' },
2168 <  { OPER_FLAG_OPER_SPY,    0,                       'S' },
2169 <  { OPER_FLAG_UNKLINE,     0,                       'U' },
2170 <  { OPER_FLAG_X,           0,                       'X' },
2171 <  { 0, 0, '\0' }
2158 >  { OPER_FLAG_ADMIN,       'A' },
2159 >  { OPER_FLAG_REMOTEBAN,   'B' },
2160 >  { OPER_FLAG_DIE,         'D' },
2161 >  { OPER_FLAG_GLINE,       'G' },
2162 >  { OPER_FLAG_REHASH,      'H' },
2163 >  { OPER_FLAG_K,           'K' },
2164 >  { OPER_FLAG_OPERWALL,    'L' },
2165 >  { OPER_FLAG_N,           'N' },
2166 >  { OPER_FLAG_GLOBAL_KILL, 'O' },
2167 >  { OPER_FLAG_REMOTE,      'R' },
2168 >  { OPER_FLAG_OPER_SPY,    'S' },
2169 >  { OPER_FLAG_UNKLINE,     'U' },
2170 >  { OPER_FLAG_X,           'X' },
2171 >  { 0, '\0' }
2172   };
2173  
2174   char *
# Line 2366 | Line 2180 | oper_privs_as_string(const unsigned int
2180  
2181    for (; flag_list[i].oprivs; ++i)
2182    {
2183 <    if ((port & flag_list[i].oprivs) &&
2370 <        (port & flag_list[i].hidden) == 0)
2183 >    if (port & flag_list[i].oprivs)
2184        *privs_ptr++ = flag_list[i].c;
2185      else
2186        *privs_ptr++ = ToLowerTab[flag_list[i].c];
# Line 2384 | Line 2197 | oper_privs_as_string(const unsigned int
2197   *         "oper" is server name for remote opers
2198   * Side effects: None.
2199   */
2200 < char *
2200 > const char *
2201   get_oper_name(const struct Client *client_p)
2202   {
2203 <  dlink_node *cnode;
2391 <  struct ConfItem *conf;
2392 <  struct AccessItem *aconf;
2393 <
2203 >  dlink_node *cnode = NULL;
2204    /* +5 for !,@,{,} and null */
2205 <  static char buffer[NICKLEN+USERLEN+HOSTLEN+HOSTLEN+5];
2205 >  static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5];
2206  
2207    if (MyConnect(client_p))
2208    {
2209 <    DLINK_FOREACH(cnode, client_p->localClient->confs.head)
2209 >    if ((cnode = client_p->localClient->confs.head))
2210      {
2211 <      conf = cnode->data;
2212 <      aconf = map_to_conf(conf);
2211 >      struct ConfItem *conf = cnode->data;
2212 >      const struct AccessItem *aconf = map_to_conf(conf);
2213  
2214        if (IsConfOperator(aconf))
2215        {
2216 <        ircsprintf(buffer, "%s!%s@%s{%s}", client_p->name,
2217 <                   client_p->username, client_p->host,
2408 <                   conf->name);
2216 >        snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
2217 >                 client_p->username, client_p->host, conf->name);
2218          return buffer;
2219        }
2220      }
# Line 2416 | Line 2225 | get_oper_name(const struct Client *clien
2225      assert(0); /* Oper without oper conf! */
2226    }
2227  
2228 <  ircsprintf(buffer, "%s!%s@%s{%s}", client_p->name,
2229 <             client_p->username, client_p->host, client_p->servptr->name);
2228 >  snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
2229 >           client_p->username, client_p->host, client_p->servptr->name);
2230    return buffer;
2231   }
2232  
# Line 2434 | Line 2243 | read_conf_files(int cold)
2243    char chanmodes[32];
2244    char chanlimit[32];
2245  
2246 +  conf_parser_ctx.boot = cold;
2247    filename = get_conf_name(CONF_TYPE);
2248  
2249    /* We need to know the initial filename for the yyerror() to report
# Line 2444 | Line 2254 | read_conf_files(int cold)
2254    */
2255    strlcpy(conffilebuf, filename, sizeof(conffilebuf));
2256  
2257 <  if ((conf_fbfile_in = fbopen(filename, "r")) == NULL)
2257 >  if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL)
2258    {
2259      if (cold)
2260      {
2261 <      ilog(L_CRIT, "Unable to read configuration file '%s': %s",
2261 >      ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
2262             filename, strerror(errno));
2263        exit(-1);
2264      }
# Line 2464 | Line 2274 | read_conf_files(int cold)
2274    if (!cold)
2275      clear_out_old_conf();
2276  
2277 <  read_conf(conf_fbfile_in);
2278 <  fbclose(conf_fbfile_in);
2277 >  read_conf(conf_parser_ctx.conf_file);
2278 >  fclose(conf_parser_ctx.conf_file);
2279  
2280    add_isupport("NETWORK", ServerInfo.network_name, -1);
2281 <  ircsprintf(chanmodes, "b%s%s:%d", ConfigChannel.use_except ? "e" : "",
2282 <             ConfigChannel.use_invex ? "I" : "", ConfigChannel.max_bans);
2281 >  snprintf(chanmodes, sizeof(chanmodes), "beI:%d",
2282 >           ConfigChannel.max_bans);
2283    add_isupport("MAXLIST", chanmodes, -1);
2284    add_isupport("MAXTARGETS", NULL, ConfigFileEntry.max_targets);
2285 <  if (ConfigChannel.disable_local_channels)
2286 <    add_isupport("CHANTYPES", "#", -1);
2287 <  else
2288 <    add_isupport("CHANTYPES", "#&", -1);
2289 <  ircsprintf(chanlimit, "%s:%d", ConfigChannel.disable_local_channels ? "#" : "#&",
2480 <             ConfigChannel.max_chans_per_user);
2285 >
2286 >  add_isupport("CHANTYPES", "#", -1);
2287 >
2288 >  snprintf(chanlimit, sizeof(chanlimit), "#:%d",
2289 >           ConfigChannel.max_chans_per_user);
2290    add_isupport("CHANLIMIT", chanlimit, -1);
2291 <  ircsprintf(chanmodes, "%s%s%s", ConfigChannel.use_except ? "e" : "",
2292 <             ConfigChannel.use_invex ? "I" : "", "b,k,l,imnpst");
2291 >  snprintf(chanmodes, sizeof(chanmodes), "%s",
2292 >           "beI,k,l,imnprstORS");
2293    add_isupport("CHANNELLEN", NULL, LOCAL_CHANNELLEN);
2294 <  if (ConfigChannel.use_except)
2295 <    add_isupport("EXCEPTS", "e", -1);
2296 <  if (ConfigChannel.use_invex)
2488 <    add_isupport("INVEX", "I", -1);
2294 >
2295 >  add_isupport("EXCEPTS", "e", -1);
2296 >  add_isupport("INVEX", "I", -1);
2297    add_isupport("CHANMODES", chanmodes, -1);
2298  
2299    /*
# Line 2494 | Line 2302 | read_conf_files(int cold)
2302     */
2303    rebuild_isupport_message_line();
2304  
2305 <  parse_conf_file(KLINE_TYPE, cold);
2305 > #ifdef HAVE_LIBPCRE
2306    parse_conf_file(RKLINE_TYPE, cold);
2307 +  parse_conf_file(RXLINE_TYPE, cold);
2308 + #endif
2309 +  parse_conf_file(KLINE_TYPE, cold);
2310    parse_conf_file(DLINE_TYPE, cold);
2311    parse_conf_file(XLINE_TYPE, cold);
2501  parse_conf_file(RXLINE_TYPE, cold);
2312    parse_conf_file(NRESV_TYPE, cold);
2313    parse_conf_file(CRESV_TYPE, cold);
2314   }
# Line 2512 | Line 2322 | read_conf_files(int cold)
2322   static void
2323   parse_conf_file(int type, int cold)
2324   {
2325 <  FBFILE *file = NULL;
2325 >  FILE *file = NULL;
2326    const char *filename = get_conf_name(type);
2327  
2328 <  if ((file = fbopen(filename, "r")) == NULL)
2328 >  if ((file = fopen(filename, "r")) == NULL)
2329    {
2330      if (cold)
2331 <      ilog(L_ERROR, "Unable to read configuration file '%s': %s",
2331 >      ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
2332             filename, strerror(errno));
2333      else
2334        sendto_realops_flags(UMODE_ALL, L_ALL,
# Line 2528 | Line 2338 | parse_conf_file(int type, int cold)
2338    else
2339    {
2340      parse_csv_file(file, type);
2341 <    fbclose(file);
2341 >    fclose(file);
2342    }
2343   }
2344  
# Line 2547 | Line 2357 | clear_out_old_conf(void)
2357    struct ClassItem *cltmp;
2358    struct MatchItem *match_item;
2359    dlink_list *free_items [] = {
2360 <    &server_items,   &oconf_items,    &hub_items, &leaf_items,
2360 >    &server_items,   &oconf_items,
2361       &uconf_items,   &xconf_items, &rxconf_items, &rkconf_items,
2362 <     &nresv_items, &cluster_items,  &gdeny_items, NULL
2362 >     &nresv_items, &cluster_items,  &service_items, NULL
2363    };
2364  
2365    dlink_list ** iterator = free_items; /* C is dumb */
# Line 2566 | Line 2376 | clear_out_old_conf(void)
2376        /* XXX This is less than pretty */
2377        if (conf->type == SERVER_TYPE)
2378        {
2379 <        aconf = (struct AccessItem *)map_to_conf(conf);
2379 >        aconf = map_to_conf(conf);
2380 >
2381          if (aconf->clients != 0)
2382          {
2383            SetConfIllegal(aconf);
# Line 2579 | Line 2390 | clear_out_old_conf(void)
2390        }
2391        else if (conf->type == OPER_TYPE)
2392        {
2393 <        aconf = (struct AccessItem *)map_to_conf(conf);
2393 >        aconf = map_to_conf(conf);
2394 >
2395          if (aconf->clients != 0)
2396          {
2397            SetConfIllegal(aconf);
# Line 2590 | Line 2402 | clear_out_old_conf(void)
2402            delete_conf_item(conf);
2403          }
2404        }
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      }
2405        else if (conf->type == XLINE_TYPE  ||
2406                 conf->type == RXLINE_TYPE ||
2407                 conf->type == RKLINE_TYPE)
# Line 2615 | Line 2415 | clear_out_old_conf(void)
2415        }
2416        else
2417        {
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
2418            delete_conf_item(conf);
2419        }
2420      }
2421    }
2422  
2423 <  /* don't delete the class table, rather mark all entries
2423 >  /*
2424 >   * don't delete the class table, rather mark all entries
2425     * for deletion. The table is cleaned up by check_class. - avalon
2426     */
2427    DLINK_FOREACH(ptr, class_items.head)
2428    {
2429 <    conf = ptr->data;
2430 <    cltmp = (struct ClassItem *)map_to_conf(conf);
2429 >    cltmp = map_to_conf(ptr->data);
2430 >
2431      if (ptr != class_items.tail)  /* never mark the "default" class */
2432 <      MaxTotal(cltmp) = -1;
2432 >      cltmp->active = 0;
2433    }
2434  
2435    clear_out_address_conf();
2436  
2437    /* clean out module paths */
2649 #ifndef STATIC_MODULES
2438    mod_clear_paths();
2651 #endif
2439  
2440    /* clean out ServerInfo */
2441    MyFree(ServerInfo.description);
# Line 2668 | Line 2455 | clear_out_old_conf(void)
2455  
2456    MyFree(ServerInfo.rsa_private_key_file);
2457    ServerInfo.rsa_private_key_file = NULL;
2458 +
2459 +  if (ServerInfo.server_ctx)
2460 +    SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|
2461 +                                               SSL_OP_NO_SSLv3|
2462 +                                               SSL_OP_NO_TLSv1);
2463 +  if (ServerInfo.client_ctx)
2464 +    SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|
2465 +                                               SSL_OP_NO_SSLv3|
2466 +                                               SSL_OP_NO_TLSv1);
2467   #endif
2468  
2469    /* clean out old resvs from the conf */
# Line 2690 | Line 2486 | clear_out_old_conf(void)
2486     */
2487  
2488    /* clean out general */
2489 <  MyFree(ConfigFileEntry.servlink_path);
2490 <  ConfigFileEntry.servlink_path = NULL;
2491 < #ifdef HAVE_LIBCRYPTO
2696 <  ConfigFileEntry.default_cipher_preference = NULL;
2697 < #endif /* HAVE_LIBCRYPTO */
2489 >  MyFree(ConfigFileEntry.service_name);
2490 >  ConfigFileEntry.service_name = NULL;
2491 >
2492    delete_isupport("INVEX");
2493    delete_isupport("EXCEPTS");
2494   }
# Line 2773 | Line 2567 | get_conf_name(ConfType type)
2567      case NRESV_TYPE:
2568        return ConfigFileEntry.nresvfile;
2569        break;
2776    case GLINE_TYPE:
2777      return ConfigFileEntry.glinefile;
2778      break;
2779
2570      default:
2571        return NULL;  /* This should NEVER HAPPEN since we call this function
2572                         only with the above values, this will cause us to core
# Line 2805 | Line 2595 | get_conf_ping(struct ConfItem *conf, int
2595      if (aconf->class_ptr != NULL)
2596      {
2597        aclass = (struct ClassItem *)map_to_conf(aconf->class_ptr);
2598 <      *pingwarn = PingWarning(aclass);
2599 <      return PingFreq(aclass);
2598 >      *pingwarn = aclass->ping_warning;
2599 >      return aclass->ping_freq;
2600      }
2601    }
2602  
# Line 2822 | Line 2612 | get_conf_ping(struct ConfItem *conf, int
2612   const char *
2613   get_client_class(struct Client *target_p)
2614   {
2615 <  dlink_node *ptr;
2616 <  struct ConfItem *conf;
2617 <  struct AccessItem *aconf;
2615 >  dlink_node *cnode = NULL;
2616 >  struct AccessItem *aconf = NULL;
2617 >
2618 >  assert(!IsMe(target_p));
2619  
2620 <  if (target_p != NULL && !IsMe(target_p) &&
2830 <      target_p->localClient->confs.head != NULL)
2620 >  if ((cnode = target_p->localClient->confs.head))
2621    {
2622 <    DLINK_FOREACH(ptr, target_p->localClient->confs.head)
2833 <    {
2834 <      conf = ptr->data;
2622 >    struct ConfItem *conf = cnode->data;
2623  
2624 <      if (conf->type == CLIENT_TYPE || conf->type == SERVER_TYPE ||
2625 <          conf->type == OPER_TYPE)
2626 <      {
2627 <        aconf = (struct AccessItem *) map_to_conf(conf);
2628 <        if (aconf->class_ptr != NULL)
2629 <          return aconf->class_ptr->name;
2842 <      }
2843 <    }
2624 >    assert((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2625 >          (conf->type == OPER_TYPE));
2626 >
2627 >    aconf = map_to_conf(conf);
2628 >    if (aconf->class_ptr != NULL)
2629 >      return aconf->class_ptr->name;
2630    }
2631  
2632    return "default";
# Line 2856 | Line 2642 | get_client_class(struct Client *target_p
2642   int
2643   get_client_ping(struct Client *target_p, int *pingwarn)
2644   {
2645 <  int ping;
2646 <  struct ConfItem *conf;
2861 <  dlink_node *nlink;
2645 >  int ping = 0;
2646 >  dlink_node *cnode = NULL;
2647  
2648 <  if (target_p->localClient->confs.head != NULL)
2649 <    DLINK_FOREACH(nlink, target_p->localClient->confs.head)
2650 <    {
2866 <      conf = nlink->data;
2648 >  if ((cnode = target_p->localClient->confs.head))
2649 >  {
2650 >    struct ConfItem *conf = cnode->data;
2651  
2652 <      if ((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2653 <          (conf->type == OPER_TYPE))
2654 <      {
2655 <        ping = get_conf_ping(conf, pingwarn);
2656 <        if (ping > 0)
2657 <          return ping;
2658 <      }
2875 <    }
2652 >    assert((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2653 >          (conf->type == OPER_TYPE));
2654 >
2655 >    ping = get_conf_ping(conf, pingwarn);
2656 >    if (ping > 0)
2657 >      return ping;
2658 >  }
2659  
2660    *pingwarn = 0;
2661    return DEFAULT_PINGFREQUENCY;
# Line 2889 | Line 2672 | find_class(const char *classname)
2672   {
2673    struct ConfItem *conf;
2674  
2675 <  if ((conf = find_exact_name_conf(CLASS_TYPE, classname, NULL, NULL)) != NULL)
2676 <    return(conf);
2675 >  if ((conf = find_exact_name_conf(CLASS_TYPE, NULL, classname, NULL, NULL)) != NULL)
2676 >    return conf;
2677  
2678    return class_default;
2679   }
# Line 2904 | Line 2687 | find_class(const char *classname)
2687   void
2688   check_class(void)
2689   {
2690 <  dlink_node *ptr;
2908 <  dlink_node *next_ptr;
2909 <  struct ConfItem *conf;
2910 <  struct ClassItem *aclass;
2690 >  dlink_node *ptr = NULL, *next_ptr = NULL;
2691  
2692    DLINK_FOREACH_SAFE(ptr, next_ptr, class_items.head)
2693    {
2694 <    conf = ptr->data;
2915 <    aclass = (struct ClassItem *)map_to_conf(conf);
2694 >    struct ClassItem *aclass = map_to_conf(ptr->data);
2695  
2696 <    if (MaxTotal(aclass) < 0)
2696 >    if (!aclass->active && !aclass->curr_user_count)
2697      {
2698        destroy_cidr_class(aclass);
2699 <      if (CurrUserCount(aclass) > 0)
2921 <        dlinkDelete(&conf->node, &class_items);
2922 <      else
2923 <        delete_conf_item(conf);
2699 >      delete_conf_item(ptr->data);
2700      }
2701    }
2702   }
# Line 2937 | Line 2713 | init_class(void)
2713    struct ClassItem *aclass;
2714  
2715    class_default = make_conf_item(CLASS_TYPE);
2716 <  aclass = (struct ClassItem *)map_to_conf(class_default);
2716 >
2717 >  aclass = map_to_conf(class_default);
2718 >  aclass->active = 1;
2719    DupString(class_default->name, "default");
2720 <  ConFreq(aclass)  = DEFAULT_CONNECTFREQUENCY;
2721 <  PingFreq(aclass) = DEFAULT_PINGFREQUENCY;
2722 <  MaxTotal(aclass) = MAXIMUM_LINKS_DEFAULT;
2723 <  MaxSendq(aclass) = DEFAULT_SENDQ;
2720 >  aclass->con_freq  = DEFAULT_CONNECTFREQUENCY;
2721 >  aclass->ping_freq = DEFAULT_PINGFREQUENCY;
2722 >  aclass->max_total = MAXIMUM_LINKS_DEFAULT;
2723 >  aclass->max_sendq = DEFAULT_SENDQ;
2724  
2725    client_check_cb = register_callback("check_client", check_client);
2726   }
# Line 2953 | Line 2731 | init_class(void)
2731   * output       - sendq for this client as found from its class
2732   * side effects - NONE
2733   */
2734 < unsigned long
2734 > unsigned int
2735   get_sendq(struct Client *client_p)
2736   {
2737 <  unsigned long sendq = DEFAULT_SENDQ;
2738 <  dlink_node *ptr;
2961 <  struct ConfItem *conf;
2737 >  unsigned int sendq = DEFAULT_SENDQ;
2738 >  dlink_node *cnode;
2739    struct ConfItem *class_conf;
2740    struct ClassItem *aclass;
2741    struct AccessItem *aconf;
2742  
2743 <  if (client_p && !IsMe(client_p) && (client_p->localClient->confs.head))
2743 >  assert(!IsMe(client_p));
2744 >
2745 >  if ((cnode = client_p->localClient->confs.head))
2746    {
2747 <    DLINK_FOREACH(ptr, client_p->localClient->confs.head)
2748 <    {
2749 <      conf = ptr->data;
2750 <      if ((conf->type == SERVER_TYPE) || (conf->type == OPER_TYPE)
2751 <          || (conf->type == CLIENT_TYPE))
2752 <      {
2753 <        aconf = (struct AccessItem *)map_to_conf(conf);
2754 <        if ((class_conf = aconf->class_ptr) == NULL)
2755 <          continue;
2756 <        aclass = (struct ClassItem *)map_to_conf(class_conf);
2757 <        sendq = MaxSendq(aclass);
2758 <        return sendq;
2759 <      }
2981 <    }
2747 >    struct ConfItem *conf = cnode->data;
2748 >
2749 >    assert((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2750 >          (conf->type == OPER_TYPE));
2751 >
2752 >    aconf = map_to_conf(conf);
2753 >
2754 >    if ((class_conf = aconf->class_ptr) == NULL)
2755 >      return DEFAULT_SENDQ; /* TBV: shouldn't be possible at all */
2756 >
2757 >    aclass = map_to_conf(class_conf);
2758 >    sendq = aclass->max_sendq;
2759 >    return sendq;
2760    }
2761 +
2762    /* XXX return a default?
2763     * if here, then there wasn't an attached conf with a sendq
2764     * that is very bad -Dianora
# Line 2996 | Line 2775 | get_sendq(struct Client *client_p)
2775   void
2776   conf_add_class_to_conf(struct ConfItem *conf, const char *class_name)
2777   {
2778 <  struct AccessItem *aconf;
2779 <  struct ClassItem *aclass;
3001 <
3002 <  aconf = (struct AccessItem *)map_to_conf(conf);
2778 >  struct AccessItem *aconf = map_to_conf(conf);
2779 >  struct ClassItem *class = NULL;
2780  
2781    if (class_name == NULL)
2782    {
2783      aconf->class_ptr = class_default;
2784 +
2785      if (conf->type == CLIENT_TYPE)
2786        sendto_realops_flags(UMODE_ALL, L_ALL,
2787                             "Warning *** Defaulting to default class for %s@%s",
# Line 3014 | Line 2792 | conf_add_class_to_conf(struct ConfItem *
2792                             conf->name);
2793    }
2794    else
3017  {
2795      aconf->class_ptr = find_class(class_name);
3019  }
2796  
2797 <  if (aconf->class_ptr == NULL)
2797 >  if (aconf->class_ptr)
2798 >    class = map_to_conf(aconf->class_ptr);
2799 >
2800 >  if (aconf->class_ptr == NULL || !class->active)
2801    {
2802      if (conf->type == CLIENT_TYPE)
2803        sendto_realops_flags(UMODE_ALL, L_ALL,
# Line 3030 | Line 2809 | conf_add_class_to_conf(struct ConfItem *
2809                             conf->name);
2810      aconf->class_ptr = class_default;
2811    }
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  }
2812   }
2813  
3043 #define MAXCONFLINKS 150
3044
2814   /* conf_add_server()
2815   *
2816   * inputs       - pointer to config item
# Line 3050 | Line 2819 | conf_add_class_to_conf(struct ConfItem *
2819   * side effects - Add a connect block
2820   */
2821   int
2822 < conf_add_server(struct ConfItem *conf, unsigned int lcount, const char *class_name)
2822 > conf_add_server(struct ConfItem *conf, const char *class_name)
2823   {
2824 <  struct AccessItem *aconf;
3056 <  char *orig_host;
3057 <
3058 <  aconf = map_to_conf(conf);
2824 >  struct AccessItem *aconf = map_to_conf(conf);
2825  
2826    conf_add_class_to_conf(conf, class_name);
2827  
2828 <  if (lcount > MAXCONFLINKS || !aconf->host || !conf->name)
2828 >  if (!aconf->host || !conf->name)
2829    {
2830      sendto_realops_flags(UMODE_ALL, L_ALL, "Bad connect block");
2831 <    ilog(L_WARN, "Bad connect block");
2831 >    ilog(LOG_TYPE_IRCD, "Bad connect block");
2832      return -1;
2833    }
2834  
2835 <  if (EmptyString(aconf->passwd) && !IsConfCryptLink(aconf))
2835 >  if (EmptyString(aconf->passwd))
2836    {
2837      sendto_realops_flags(UMODE_ALL, L_ALL, "Bad connect block, name %s",
2838                           conf->name);
2839 <    ilog(L_WARN, "Bad connect block, host %s", conf->name);
2839 >    ilog(LOG_TYPE_IRCD, "Bad connect block, host %s", conf->name);
2840      return -1;
2841    }
2842  
3077  orig_host = aconf->host;
3078  split_nuh(orig_host, NULL, &aconf->user, &aconf->host);
3079  MyFree(orig_host);
2843    lookup_confhost(conf);
2844  
2845    return 0;
2846   }
2847  
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
2848   /* yyerror()
2849   *
2850   * inputs       - message from parser
# Line 3124 | Line 2856 | yyerror(const char *msg)
2856   {
2857    char newlinebuf[IRCD_BUFSIZE];
2858  
2859 <  if (ypass != 1)
2859 >  if (conf_parser_ctx.pass != 1)
2860      return;
2861  
2862    strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
2863    sendto_realops_flags(UMODE_ALL, L_ALL, "\"%s\", line %u: %s: %s",
2864                         conffilebuf, lineno + 1, msg, newlinebuf);
2865 <  ilog(L_WARN, "\"%s\", line %u: %s: %s",
2865 >  ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
2866         conffilebuf, lineno + 1, msg, newlinebuf);
2867   }
2868  
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
2869   /*
2870   * valid_tkline()
2871   *
# Line 3160 | Line 2877 | conf_yy_fatal_error(const char *msg)
2877   * Originally written by Dianora (Diane, db@db.net)
2878   */
2879   time_t
2880 < valid_tkline(char *p, int minutes)
2880 > valid_tkline(const char *p, int minutes)
2881   {
2882    time_t result = 0;
2883  
2884 <  while (*p)
2884 >  for (; *p; ++p)
2885    {
2886 <    if (IsDigit(*p))
3170 <    {
3171 <      result *= 10;
3172 <      result += ((*p) & 0xF);
3173 <      p++;
3174 <    }
3175 <    else
2886 >    if (!IsDigit(*p))
2887        return 0;
2888 +
2889 +    result *= 10;
2890 +    result += ((*p) & 0xF);
2891    }
2892  
2893 <  /* in the degenerate case where oper does a /quote kline 0 user@host :reason
2893 >  /*
2894 >   * In the degenerate case where oper does a /quote kline 0 user@host :reason
2895     * i.e. they specifically use 0, I am going to return 1 instead
2896     * as a return value of non-zero is used to flag it as a temporary kline
2897     */
3183
2898    if (result == 0)
2899      result = 1;
2900  
# Line 3281 | Line 2995 | valid_wild_card(struct Client *source_p,
2995   *                if target_server is NULL and an "ON" is found error
2996   *                is reported.
2997   *                if reason pointer is NULL ignore pointer,
2998 < *                this allows usee of parse_a_line in unkline etc.
2998 > *                this allows use of parse_a_line in unkline etc.
2999   *
3000   * - Dianora
3001   */
# Line 3351 | Line 3065 | parse_aline(const char *cmd, struct Clie
3065          return -1;
3066        }
3067  
3068 <      if (!IsOperRemoteBan(source_p))
3068 >      if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN))
3069        {
3070          sendto_one(source_p, form_str(ERR_NOPRIVS),
3071                     me.name, source_p->name, "remoteban");
# Line 3388 | Line 3102 | parse_aline(const char *cmd, struct Clie
3102        return -1;
3103      }
3104  
3105 <    if ((parse_flags & AWILD) && !valid_wild_card(source_p, YES, 2, *up_p, *h_p))
3105 >    if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 2, *up_p, *h_p))
3106        return -1;
3107    }
3108    else
3109 <    if ((parse_flags & AWILD) && !valid_wild_card(source_p, YES, 1, *up_p))
3109 >    if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 1, *up_p))
3110        return -1;
3111  
3112    if (reason != NULL)
3113    {
3114 <    if (parc != 0)
3114 >    if (parc != 0 && !EmptyString(*parv))
3115      {
3116        *reason = *parv;
3117 <      if (!valid_comment(source_p, *reason, YES))
3117 >      if (!valid_comment(source_p, *reason, 1))
3118          return -1;
3119      }
3120      else
# Line 3436 | Line 3150 | find_user_host(struct Client *source_p,
3150    {
3151      /* Explicit user@host mask given */
3152  
3153 <    if(hostp != NULL)                            /* I'm a little user@host */
3153 >    if (hostp != NULL)                            /* I'm a little user@host */
3154      {
3155        *(hostp++) = '\0';                       /* short and squat */
3156        if (*user_host_or_nick)
# Line 3531 | Line 3245 | match_conf_password(const char *password
3245   {
3246    const char *encr = NULL;
3247  
3248 <  if (password == NULL || aconf->passwd == NULL)
3248 >  if (EmptyString(password) || EmptyString(aconf->passwd))
3249      return 0;
3250  
3251    if (aconf->flags & CONF_FLAGS_ENCRYPTED)
3252 <  {
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 <  }
3252 >    encr = crypt(password, aconf->passwd);
3253    else
3254      encr = password;
3255  
# Line 3559 | Line 3262 | match_conf_password(const char *password
3262   * inputs       - client sending the cluster
3263   *              - command name "KLINE" "XLINE" etc.
3264   *              - capab -- CAP_KLN etc. from s_serv.h
3265 < *              - cluster type -- CLUSTER_KLINE etc. from s_conf.h
3265 > *              - cluster type -- CLUSTER_KLINE etc. from conf.h
3266   *              - pattern and args to send along
3267   * output       - none
3268   * side effects - Take source_p send the pattern with args given
# Line 3567 | Line 3270 | match_conf_password(const char *password
3270   */
3271   void
3272   cluster_a_line(struct Client *source_p, const char *command,
3273 <               int capab, int cluster_type, const char *pattern, ...)
3273 >               int capab, int cluster_type, const char *pattern, ...)
3274   {
3275    va_list args;
3276    char buffer[IRCD_BUFSIZE];
3277 <  struct ConfItem *conf;
3575 <  dlink_node *ptr;
3277 >  const dlink_node *ptr = NULL;
3278  
3279    va_start(args, pattern);
3280    vsnprintf(buffer, sizeof(buffer), pattern, args);
# Line 3580 | Line 3282 | cluster_a_line(struct Client *source_p,
3282  
3283    DLINK_FOREACH(ptr, cluster_items.head)
3284    {
3285 <    conf = ptr->data;
3285 >    const struct ConfItem *conf = ptr->data;
3286  
3287      if (conf->flags & cluster_type)
3586    {
3288        sendto_match_servs(source_p, conf->name, CAP_CLUSTER|capab,
3289                           "%s %s %s", command, conf->name, buffer);
3589    }
3290    }
3291   }
3292  
# Line 3618 | Line 3318 | cluster_a_line(struct Client *source_p,
3318   * @                            *       *       *
3319   * !                            *       *       *
3320   */
3621
3321   void
3322 < split_nuh(char *mask, char **nick, char **user, char **host)
3322 > split_nuh(struct split_nuh_item *const iptr)
3323   {
3324    char *p = NULL, *q = NULL;
3325  
3326 <  if ((p = strchr(mask, '!')) != NULL)
3326 >  if (iptr->nickptr)
3327 >    strlcpy(iptr->nickptr, "*", iptr->nicksize);
3328 >  if (iptr->userptr)
3329 >    strlcpy(iptr->userptr, "*", iptr->usersize);
3330 >  if (iptr->hostptr)
3331 >    strlcpy(iptr->hostptr, "*", iptr->hostsize);
3332 >
3333 >  if ((p = strchr(iptr->nuhmask, '!')))
3334    {
3335      *p = '\0';
3630    if (nick != NULL)
3631    {
3632      if (*mask != '\0')
3633        *nick = xstrldup(mask, NICKLEN);
3634      else
3635        DupString(*nick, "*");
3636    }
3336  
3337 <    if ((q = strchr(++p, '@')) != NULL)
3338 <    {
3339 <      *q = '\0';
3337 >    if (iptr->nickptr && *iptr->nuhmask != '\0')
3338 >      strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
3339 >
3340 >    if ((q = strchr(++p, '@'))) {
3341 >      *q++ = '\0';
3342  
3343        if (*p != '\0')
3344 <        *user = xstrldup(p, USERLEN+1);
3644 <      else
3645 <        DupString(*user, "*");
3344 >        strlcpy(iptr->userptr, p, iptr->usersize);
3345  
3346 <      if (*++q != '\0')
3347 <        *host = xstrldup(q, HOSTLEN+1);
3649 <      else
3650 <        DupString(*host, "*");
3346 >      if (*q != '\0')
3347 >        strlcpy(iptr->hostptr, q, iptr->hostsize);
3348      }
3349      else
3350      {
3351        if (*p != '\0')
3352 <        *user = xstrldup(p, USERLEN+1);
3656 <      else
3657 <        DupString(*user, "*");
3658 <
3659 <      DupString(*host, "*");
3352 >        strlcpy(iptr->userptr, p, iptr->usersize);
3353      }
3354    }
3355 <  else  /* No ! found so lets look for a user@host */
3355 >  else
3356    {
3357 <    if ((p = strchr(mask, '@')) != NULL)        /* if found a @ */
3357 >    /* No ! found so lets look for a user@host */
3358 >    if ((p = strchr(iptr->nuhmask, '@')))
3359      {
3360 <      if (nick != NULL)
3361 <        DupString(*nick, "*");
3668 <      *p = '\0';
3360 >      /* if found a @ */
3361 >      *p++ = '\0';
3362  
3363 <      if (*mask != '\0')
3364 <        *user = xstrldup(mask, USERLEN+1);
3672 <      else
3673 <        DupString(*user, "*");
3363 >      if (*iptr->nuhmask != '\0')
3364 >        strlcpy(iptr->userptr, iptr->nuhmask, iptr->usersize);
3365  
3366 <      if (*++p != '\0')
3367 <        *host = xstrldup(p, HOSTLEN+1);
3677 <      else
3678 <        DupString(*host, "*");
3366 >      if (*p != '\0')
3367 >        strlcpy(iptr->hostptr, p, iptr->hostsize);
3368      }
3369 <    else                                        /* no @ found */
3369 >    else
3370      {
3371 <      if (nick != NULL)
3372 <      {
3373 <        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 <      }
3371 >      /* no @ found */
3372 >      if (!iptr->nickptr || strpbrk(iptr->nuhmask, ".:"))
3373 >        strlcpy(iptr->hostptr, iptr->nuhmask, iptr->hostsize);
3374        else
3375 <      {
3699 <        DupString(*user, "*");
3700 <        *host = xstrldup(mask, HOSTLEN+1);
3701 <      }
3375 >        strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
3376      }
3377    }
3378   }
# Line 3725 | Line 3399 | flags_to_ascii(unsigned int flags, const
3399    {
3400      if (flags & mask)
3401        *p++ = bit_table[i];
3402 <    else if(lowerit)
3402 >    else if (lowerit)
3403        *p++ = ToLower(bit_table[i]);
3404    }
3405    *p = '\0';
# Line 3748 | Line 3422 | cidr_limit_reached(int over_rule,
3422    dlink_node *ptr = NULL;
3423    struct CidrItem *cidr;
3424  
3425 <  if (NumberPerCidr(aclass) <= 0)
3425 >  if (aclass->number_per_cidr <= 0)
3426      return 0;
3427  
3428    if (ip->ss.ss_family == AF_INET)
3429    {
3430 <    if (CidrBitlenIPV4(aclass) <= 0)
3430 >    if (aclass->cidr_bitlen_ipv4 <= 0)
3431        return 0;
3432  
3433      DLINK_FOREACH(ptr, aclass->list_ipv4.head)
3434      {
3435        cidr = ptr->data;
3436 <      if (match_ipv4(ip, &cidr->mask, CidrBitlenIPV4(aclass)))
3436 >      if (match_ipv4(ip, &cidr->mask, aclass->cidr_bitlen_ipv4))
3437        {
3438 <        if (!over_rule && (cidr->number_on_this_cidr >= NumberPerCidr(aclass)))
3438 >        if (!over_rule && (cidr->number_on_this_cidr >= aclass->number_per_cidr))
3439            return -1;
3440          cidr->number_on_this_cidr++;
3441          return 0;
# Line 3770 | Line 3444 | cidr_limit_reached(int over_rule,
3444      cidr = MyMalloc(sizeof(struct CidrItem));
3445      cidr->number_on_this_cidr = 1;
3446      cidr->mask = *ip;
3447 <    mask_addr(&cidr->mask, CidrBitlenIPV4(aclass));
3447 >    mask_addr(&cidr->mask, aclass->cidr_bitlen_ipv4);
3448      dlinkAdd(cidr, &cidr->node, &aclass->list_ipv4);
3449    }
3450   #ifdef IPV6
3451 <  else if (CidrBitlenIPV6(aclass) > 0)
3451 >  else if (aclass->cidr_bitlen_ipv6 > 0)
3452    {
3453      DLINK_FOREACH(ptr, aclass->list_ipv6.head)
3454      {
3455        cidr = ptr->data;
3456 <      if (match_ipv6(ip, &cidr->mask, CidrBitlenIPV6(aclass)))
3456 >      if (match_ipv6(ip, &cidr->mask, aclass->cidr_bitlen_ipv6))
3457        {
3458 <        if (!over_rule && (cidr->number_on_this_cidr >= NumberPerCidr(aclass)))
3458 >        if (!over_rule && (cidr->number_on_this_cidr >= aclass->number_per_cidr))
3459            return -1;
3460          cidr->number_on_this_cidr++;
3461          return 0;
# Line 3790 | Line 3464 | cidr_limit_reached(int over_rule,
3464      cidr = MyMalloc(sizeof(struct CidrItem));
3465      cidr->number_on_this_cidr = 1;
3466      cidr->mask = *ip;
3467 <    mask_addr(&cidr->mask, CidrBitlenIPV6(aclass));
3467 >    mask_addr(&cidr->mask, aclass->cidr_bitlen_ipv6);
3468      dlinkAdd(cidr, &cidr->node, &aclass->list_ipv6);
3469    }
3470   #endif
# Line 3812 | Line 3486 | remove_from_cidr_check(struct irc_ssaddr
3486    dlink_node *next_ptr = NULL;
3487    struct CidrItem *cidr;
3488  
3489 <  if (NumberPerCidr(aclass) == 0)
3489 >  if (aclass->number_per_cidr == 0)
3490      return;
3491  
3492    if (ip->ss.ss_family == AF_INET)
3493    {
3494 <    if (CidrBitlenIPV4(aclass) <= 0)
3494 >    if (aclass->cidr_bitlen_ipv4 <= 0)
3495        return;
3496  
3497      DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv4.head)
3498      {
3499        cidr = ptr->data;
3500 <      if (match_ipv4(ip, &cidr->mask, CidrBitlenIPV4(aclass)))
3500 >      if (match_ipv4(ip, &cidr->mask, aclass->cidr_bitlen_ipv4))
3501        {
3502          cidr->number_on_this_cidr--;
3503          if (cidr->number_on_this_cidr == 0)
# Line 3836 | Line 3510 | remove_from_cidr_check(struct irc_ssaddr
3510      }
3511    }
3512   #ifdef IPV6
3513 <  else if (CidrBitlenIPV6(aclass) > 0)
3513 >  else if (aclass->cidr_bitlen_ipv6 > 0)
3514    {
3515      DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv6.head)
3516      {
3517        cidr = ptr->data;
3518 <      if (match_ipv6(ip, &cidr->mask, CidrBitlenIPV6(aclass)))
3518 >      if (match_ipv6(ip, &cidr->mask, aclass->cidr_bitlen_ipv6))
3519        {
3520          cidr->number_on_this_cidr--;
3521          if (cidr->number_on_this_cidr == 0)
# Line 3904 | Line 3578 | rebuild_cidr_class(struct ConfItem *conf
3578   {
3579    struct ClassItem *old_class = map_to_conf(conf);
3580  
3581 <  if (NumberPerCidr(old_class) > 0 && NumberPerCidr(new_class) > 0)
3581 >  if (old_class->number_per_cidr > 0 && new_class->number_per_cidr > 0)
3582    {
3583 <    if (CidrBitlenIPV4(old_class) > 0 && CidrBitlenIPV4(new_class) > 0)
3583 >    if (old_class->cidr_bitlen_ipv4 > 0 && new_class->cidr_bitlen_ipv4 > 0)
3584        rebuild_cidr_list(AF_INET, conf, new_class,
3585                          &old_class->list_ipv4, &new_class->list_ipv4,
3586 <                        CidrBitlenIPV4(old_class) != CidrBitlenIPV4(new_class));
3586 >                        old_class->cidr_bitlen_ipv4 != new_class->cidr_bitlen_ipv4);
3587  
3588   #ifdef IPV6
3589 <    if (CidrBitlenIPV6(old_class) > 0 && CidrBitlenIPV6(new_class) > 0)
3589 >    if (old_class->cidr_bitlen_ipv6 > 0 && new_class->cidr_bitlen_ipv6 > 0)
3590        rebuild_cidr_list(AF_INET6, conf, new_class,
3591                          &old_class->list_ipv6, &new_class->list_ipv6,
3592 <                        CidrBitlenIPV6(old_class) != CidrBitlenIPV6(new_class));
3592 >                        old_class->cidr_bitlen_ipv6 != new_class->cidr_bitlen_ipv6);
3593   #endif
3594    }
3595  
# Line 3932 | Line 3606 | rebuild_cidr_class(struct ConfItem *conf
3606   static void
3607   destroy_cidr_list(dlink_list *list)
3608   {
3609 <  dlink_node *ptr = NULL;
3936 <  dlink_node *next_ptr = NULL;
3937 <  struct CidrItem *cidr;
3609 >  dlink_node *ptr = NULL, *next_ptr = NULL;
3610  
3611    DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
3612    {
3941    cidr = ptr->data;
3613      dlinkDelete(ptr, list);
3614 <    MyFree(cidr);
3614 >    MyFree(ptr->data);
3615    }
3616   }
3617  

Diff Legend

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