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-8/src/conf.c (file contents), Revision 1518 by michael, Sun Sep 2 16:50:40 2012 UTC vs.
ircd-hybrid/trunk/src/conf.c (file contents), Revision 2275 by michael, Tue Jun 18 16:30:11 2013 UTC

# Line 25 | Line 25
25   #include "stdinc.h"
26   #include "list.h"
27   #include "ircd_defs.h"
28 – #include "balloc.h"
28   #include "conf.h"
29   #include "s_serv.h"
30   #include "resv.h"
# Line 45 | Line 44
44   #include "send.h"
45   #include "s_gline.h"
46   #include "memory.h"
47 + #include "mempool.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 + #include "conf_db.h"
55 + #include "conf_class.h"
56 + #include "motd.h"
57  
55 – struct Callback *client_check_cb = NULL;
58   struct config_server_hide ConfigServerHide;
59  
60   /* general conf items link list root, other than k lines etc. */
# Line 62 | Line 64 | dlink_list cluster_items = { NULL, NULL,
64   dlink_list oconf_items   = { NULL, NULL, 0 };
65   dlink_list uconf_items   = { NULL, NULL, 0 };
66   dlink_list xconf_items   = { NULL, NULL, 0 };
65 – dlink_list rxconf_items  = { NULL, NULL, 0 };
66 – dlink_list rkconf_items  = { NULL, NULL, 0 };
67   dlink_list nresv_items   = { NULL, NULL, 0 };
68 < dlink_list class_items   = { NULL, NULL, 0 };
69 <
70 < dlink_list temporary_xlines  = { NULL, NULL, 0 };
71 < dlink_list temporary_resv = { NULL, NULL, 0 };
68 > dlink_list cresv_items = { NULL, NULL, 0 };
69  
70   extern unsigned int lineno;
71   extern char linebuf[];
# Line 80 | Line 77 | struct conf_parser_context conf_parser_c
77   /* internally defined functions */
78   static void read_conf(FILE *);
79   static void clear_out_old_conf(void);
83 – static void flush_deleted_I_P(void);
80   static void expire_tklines(dlink_list *);
81   static void garbage_collect_ip_entries(void);
82   static int hash_ip(struct irc_ssaddr *);
83 < static int verify_access(struct Client *, const char *);
84 < static int attach_iline(struct Client *, struct ConfItem *);
83 > static int verify_access(struct Client *);
84 > static int attach_iline(struct Client *, struct MaskItem *);
85   static struct ip_entry *find_or_add_ip(struct irc_ssaddr *);
86 < static void parse_conf_file(int, int);
91 < static dlink_list *map_to_list(ConfType);
92 < static struct AccessItem *find_regexp_kline(const char *[]);
86 > static dlink_list *map_to_list(enum maskitem_type);
87   static int find_user_host(struct Client *, char *, char *, char *, unsigned int);
88  
95 – /*
96 – * bit_len
97 – */
98 – static int cidr_limit_reached(int, struct irc_ssaddr *, struct ClassItem *);
99 – static void remove_from_cidr_check(struct irc_ssaddr *, struct ClassItem *);
100 – static void destroy_cidr_class(struct ClassItem *);
101 –
102 – static void flags_to_ascii(unsigned int, const unsigned int[], char *, int);
103 –
104 – /* address of default class conf */
105 – static struct ConfItem *class_default;
89  
90   /* usually, with hash tables, you use a prime number...
91   * but in this case I am dealing with ip addresses,
# Line 113 | Line 96 | static struct ConfItem *class_default;
96   struct ip_entry
97   {
98    struct irc_ssaddr ip;
99 <  int count;
99 >  unsigned int count;
100    time_t last_attempt;
101    struct ip_entry *next;
102   };
103  
104   static struct ip_entry *ip_hash_table[IP_HASH_SIZE];
105 < static BlockHeap *ip_entry_heap = NULL;
105 > static mp_pool_t *ip_entry_pool = NULL;
106   static int ip_entries_count = 0;
107  
108  
126 – void *
127 – map_to_conf(struct ConfItem *aconf)
128 – {
129 –  void *conf;
130 –  conf = (void *)((uintptr_t)aconf +
131 –                  (uintptr_t)sizeof(struct ConfItem));
132 –  return(conf);
133 – }
134 –
135 – struct ConfItem *
136 – unmap_conf_item(void *aconf)
137 – {
138 –  struct ConfItem *conf;
139 –
140 –  conf = (struct ConfItem *)((uintptr_t)aconf -
141 –                             (uintptr_t)sizeof(struct ConfItem));
142 –  return(conf);
143 – }
144 –
109   /* conf_dns_callback()
110   *
111 < * inputs       - pointer to struct AccessItem
111 > * inputs       - pointer to struct MaskItem
112   *              - pointer to DNSReply reply
113   * output       - none
114   * side effects - called when resolver query finishes
# Line 155 | Line 119 | unmap_conf_item(void *aconf)
119   static void
120   conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name)
121   {
122 <  struct AccessItem *aconf = vptr;
122 >  struct MaskItem *conf = vptr;
123  
124 <  aconf->dns_pending = 0;
124 >  conf->dns_pending = 0;
125  
126    if (addr != NULL)
127 <    memcpy(&aconf->addr, addr, sizeof(aconf->addr));
127 >    memcpy(&conf->addr, addr, sizeof(conf->addr));
128    else
129 <    aconf->dns_failed = 1;
129 >    conf->dns_failed = 1;
130   }
131  
132   /* conf_dns_lookup()
# Line 172 | Line 136 | conf_dns_callback(void *vptr, const stru
136   * allocate a dns_query and start ns lookup.
137   */
138   static void
139 < conf_dns_lookup(struct AccessItem *aconf)
139 > conf_dns_lookup(struct MaskItem *conf)
140   {
141 <  if (!aconf->dns_pending)
141 >  if (!conf->dns_pending)
142    {
143 <    aconf->dns_pending = 1;
144 <    gethost_byname(conf_dns_callback, aconf, aconf->host);
143 >    conf->dns_pending = 1;
144 >    gethost_byname(conf_dns_callback, conf, conf->host);
145    }
146   }
147  
148 < /* make_conf_item()
149 < *
186 < * inputs       - type of item
187 < * output       - pointer to new conf entry
188 < * side effects - none
189 < */
190 < struct ConfItem *
191 < make_conf_item(ConfType type)
148 > struct MaskItem *
149 > conf_make(enum maskitem_type type)
150   {
151 <  struct ConfItem *conf = NULL;
152 <  struct AccessItem *aconf = NULL;
195 <  struct ClassItem *aclass = NULL;
196 <  int status = 0;
197 <
198 <  switch (type)
199 <  {
200 <  case DLINE_TYPE:
201 <  case EXEMPTDLINE_TYPE:
202 <  case GLINE_TYPE:
203 <  case KLINE_TYPE:
204 <  case CLIENT_TYPE:
205 <  case OPER_TYPE:
206 <  case SERVER_TYPE:
207 <    conf = MyMalloc(sizeof(struct ConfItem) +
208 <                    sizeof(struct AccessItem));
209 <    aconf = map_to_conf(conf);
210 <    aconf->aftype = AF_INET;
211 <
212 <    /* Yes, sigh. switch on type again */
213 <    switch (type)
214 <    {
215 <    case EXEMPTDLINE_TYPE:
216 <      status = CONF_EXEMPTDLINE;
217 <      break;
218 <
219 <    case DLINE_TYPE:
220 <      status = CONF_DLINE;
221 <      break;
222 <
223 <    case KLINE_TYPE:
224 <      status = CONF_KLINE;
225 <      break;
226 <
227 <    case GLINE_TYPE:
228 <      status = CONF_GLINE;
229 <      break;
230 <
231 <    case CLIENT_TYPE:
232 <      status = CONF_CLIENT;
233 <      break;
234 <
235 <    case OPER_TYPE:
236 <      status = CONF_OPERATOR;
237 <      dlinkAdd(conf, &conf->node, &oconf_items);
238 <      break;
239 <
240 <    case SERVER_TYPE:
241 <      status = CONF_SERVER;
242 <      dlinkAdd(conf, &conf->node, &server_items);
243 <      break;
244 <
245 <    default:
246 <      break;
247 <    }
248 <    aconf->status = status;
249 <    break;
250 <
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 <
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 < #ifdef HAVE_LIBPCRE
263 <  case RXLINE_TYPE:
264 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
265 <                                       sizeof(struct MatchItem));
266 <    dlinkAdd(conf, &conf->node, &rxconf_items);
267 <    break;
268 <
269 <  case RKLINE_TYPE:
270 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
271 <                                       sizeof(struct AccessItem));
272 <    aconf = map_to_conf(conf);
273 <    aconf->status = CONF_KLINE;
274 <    dlinkAdd(conf, &conf->node, &rkconf_items);
275 <    break;
276 < #endif
277 <  case CLUSTER_TYPE:
278 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem));
279 <    dlinkAdd(conf, &conf->node, &cluster_items);
280 <    break;
281 <
282 <  case CRESV_TYPE:
283 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
284 <                                       sizeof(struct ResvChannel));
285 <    break;
286 <
287 <  case NRESV_TYPE:
288 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
289 <                                       sizeof(struct MatchItem));
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 = MyMalloc(sizeof(struct ConfItem) +
301 <                           sizeof(struct ClassItem));
302 <    dlinkAdd(conf, &conf->node, &class_items);
303 <
304 <    aclass = map_to_conf(conf);
305 <    aclass->active = 1;
306 <    aclass->con_freq = DEFAULT_CONNECTFREQUENCY;
307 <    aclass->ping_freq = DEFAULT_PINGFREQUENCY;
308 <    aclass->max_total = MAXIMUM_LINKS_DEFAULT;
309 <    aclass->max_sendq = DEFAULT_SENDQ;
310 <    aclass->max_recvq = DEFAULT_RECVQ;
151 >  struct MaskItem *conf = MyMalloc(sizeof(*conf));
152 >  dlink_list *list = NULL;
153  
154 <    break;
155 <
156 <  default:
315 <    conf = NULL;
316 <    break;
317 <  }
318 <
319 <  /* XXX Yes, this will core if default is hit. I want it to for now - db */
320 <  conf->type = type;
154 >  conf->type   = type;
155 >  conf->active = 1;
156 >  conf->aftype = AF_INET;
157  
158 +  if ((list = map_to_list(type)))
159 +    dlinkAdd(conf, &conf->node, list);
160    return conf;
161   }
162  
163   void
164 < delete_conf_item(struct ConfItem *conf)
164 > conf_free(struct MaskItem *conf)
165   {
166 <  dlink_node *m = NULL, *m_next = NULL;
167 <  struct MatchItem *match_item;
168 <  struct AccessItem *aconf;
169 <  ConfType type = conf->type;
166 >  dlink_node *ptr = NULL, *ptr_next = NULL;
167 >  dlink_list *list = NULL;
168 >
169 >  if (conf->node.next)
170 >    if ((list = map_to_list(conf->type)))
171 >      dlinkDelete(&conf->node, list);
172  
173    MyFree(conf->name);
334 –  conf->name = NULL;
174  
175 <  switch(type)
176 <  {
177 <  case DLINE_TYPE:
178 <  case EXEMPTDLINE_TYPE:
179 <  case GLINE_TYPE:
180 <  case KLINE_TYPE:
181 <  case CLIENT_TYPE:
182 <  case OPER_TYPE:
183 <  case SERVER_TYPE:
184 <    aconf = map_to_conf(conf);
185 <
186 <    if (aconf->dns_pending)
187 <      delete_resolver_queries(aconf);
188 <    if (aconf->passwd != NULL)
189 <      memset(aconf->passwd, 0, strlen(aconf->passwd));
351 <    if (aconf->spasswd != NULL)
352 <      memset(aconf->spasswd, 0, strlen(aconf->spasswd));
353 <    aconf->class_ptr = NULL;
354 <
355 <    MyFree(aconf->passwd);
356 <    MyFree(aconf->spasswd);
357 <    MyFree(aconf->reason);
358 <    MyFree(aconf->oper_reason);
359 <    MyFree(aconf->user);
360 <    MyFree(aconf->host);
175 >  if (conf->dns_pending)
176 >    delete_resolver_queries(conf);
177 >  if (conf->passwd != NULL)
178 >    memset(conf->passwd, 0, strlen(conf->passwd));
179 >  if (conf->spasswd != NULL)
180 >    memset(conf->spasswd, 0, strlen(conf->spasswd));
181 >
182 >  conf->class = NULL;
183 >
184 >  MyFree(conf->passwd);
185 >  MyFree(conf->spasswd);
186 >  MyFree(conf->reason);
187 >  MyFree(conf->certfp);
188 >  MyFree(conf->user);
189 >  MyFree(conf->host);
190   #ifdef HAVE_LIBCRYPTO
191 <    MyFree(aconf->cipher_list);
191 >  MyFree(conf->cipher_list);
192  
193 <    if (aconf->rsa_public_key)
194 <      RSA_free(aconf->rsa_public_key);
366 <    MyFree(aconf->rsa_public_key_file);
193 >  if (conf->rsa_public_key)
194 >    RSA_free(conf->rsa_public_key);
195   #endif
196 <
197 <    /* Yes, sigh. switch on type again */
198 <    switch(type)
199 <    {
372 <    case EXEMPTDLINE_TYPE:
373 <    case DLINE_TYPE:
374 <    case GLINE_TYPE:
375 <    case KLINE_TYPE:
376 <    case CLIENT_TYPE:
377 <      MyFree(conf);
378 <      break;
379 <
380 <    case OPER_TYPE:
381 <      aconf = map_to_conf(conf);
382 <      if (!IsConfIllegal(aconf))
383 <        dlinkDelete(&conf->node, &oconf_items);
384 <      MyFree(conf);
385 <      break;
386 <
387 <    case SERVER_TYPE:
388 <      aconf = map_to_conf(conf);
389 <
390 <      DLINK_FOREACH_SAFE(m, m_next, aconf->hub_list.head)
391 <      {
392 <        MyFree(m->data);
393 <        free_dlink_node(m);
394 <      }
395 <
396 <      DLINK_FOREACH_SAFE(m, m_next, aconf->leaf_list.head)
397 <      {
398 <        MyFree(m->data);
399 <        free_dlink_node(m);  
400 <      }
401 <
402 <      if (!IsConfIllegal(aconf))
403 <        dlinkDelete(&conf->node, &server_items);
404 <      MyFree(conf);
405 <      break;
406 <
407 <    default:
408 <      break;
409 <    }
410 <    break;
411 <
412 <  case ULINE_TYPE:
413 <    match_item = map_to_conf(conf);
414 <    MyFree(match_item->user);
415 <    MyFree(match_item->host);
416 <    MyFree(match_item->reason);
417 <    MyFree(match_item->oper_reason);
418 <    dlinkDelete(&conf->node, &uconf_items);
419 <    MyFree(conf);
420 <    break;
421 <
422 <  case XLINE_TYPE:
423 <    match_item = map_to_conf(conf);
424 <    MyFree(match_item->user);
425 <    MyFree(match_item->host);
426 <    MyFree(match_item->reason);
427 <    MyFree(match_item->oper_reason);
428 <    dlinkDelete(&conf->node, &xconf_items);
429 <    MyFree(conf);
430 <    break;
431 < #ifdef HAVE_LIBPCRE
432 <  case RKLINE_TYPE:
433 <    aconf = map_to_conf(conf);
434 <    MyFree(aconf->regexuser);
435 <    MyFree(aconf->regexhost);
436 <    MyFree(aconf->user);
437 <    MyFree(aconf->host);
438 <    MyFree(aconf->reason);
439 <    MyFree(aconf->oper_reason);
440 <    dlinkDelete(&conf->node, &rkconf_items);
441 <    MyFree(conf);
442 <    break;
443 <
444 <  case RXLINE_TYPE:
445 <    MyFree(conf->regexpname);
446 <    match_item = map_to_conf(conf);
447 <    MyFree(match_item->user);
448 <    MyFree(match_item->host);
449 <    MyFree(match_item->reason);
450 <    MyFree(match_item->oper_reason);
451 <    dlinkDelete(&conf->node, &rxconf_items);
452 <    MyFree(conf);
453 <    break;
454 < #endif
455 <  case NRESV_TYPE:
456 <    match_item = map_to_conf(conf);
457 <    MyFree(match_item->user);
458 <    MyFree(match_item->host);
459 <    MyFree(match_item->reason);
460 <    MyFree(match_item->oper_reason);
461 <    dlinkDelete(&conf->node, &nresv_items);
462 <
463 <    if (conf->flags & CONF_FLAGS_TEMPORARY)
464 <      if ((m = dlinkFindDelete(&temporary_resv, conf)) != NULL)
465 <        free_dlink_node(m);
466 <
467 <    MyFree(conf);
468 <    break;
469 <
470 <  case CLUSTER_TYPE:
471 <    dlinkDelete(&conf->node, &cluster_items);
472 <    MyFree(conf);
473 <    break;
474 <
475 <  case CRESV_TYPE:
476 <    if (conf->flags & CONF_FLAGS_TEMPORARY)
477 <      if ((m = dlinkFindDelete(&temporary_resv, conf)) != NULL)
478 <        free_dlink_node(m);
479 <
480 <    MyFree(conf);
481 <    break;
482 <
483 <  case CLASS_TYPE:
484 <    dlinkDelete(&conf->node, &class_items);
485 <    MyFree(conf);
486 <    break;
487 <
488 <  case SERVICE_TYPE:
489 <    dlinkDelete(&conf->node, &service_items);
490 <    MyFree(conf);
491 <    break;
492 <
493 <  default:
494 <    break;
196 >  DLINK_FOREACH_SAFE(ptr, ptr_next, conf->hub_list.head)
197 >  {
198 >    MyFree(ptr->data);
199 >    free_dlink_node(ptr);
200    }
496 – }
201  
202 < /* free_access_item()
499 < *
500 < * inputs       - pointer to conf to free
501 < * output       - none
502 < * side effects - crucial password fields are zeroed, conf is freed
503 < */
504 < void
505 < free_access_item(struct AccessItem *aconf)
506 < {
507 <  struct ConfItem *conf;
508 <
509 <  if (aconf == NULL)
510 <    return;
511 <  conf = unmap_conf_item(aconf);
512 <  delete_conf_item(conf);
513 < }
514 <
515 < static const unsigned int shared_bit_table[] =
516 <  { 'K', 'k', 'U', 'X', 'x', 'Y', 'Q', 'q', 'R', 'L', 0};
517 <
518 < /* report_confitem_types()
519 < *
520 < * inputs       - pointer to client requesting confitem report
521 < *              - ConfType to report
522 < * output       - none
523 < * side effects -
524 < */
525 < void
526 < report_confitem_types(struct Client *source_p, ConfType type)
527 < {
528 <  dlink_node *ptr = NULL, *dptr = NULL;
529 <  struct ConfItem *conf = NULL;
530 <  struct AccessItem *aconf = NULL;
531 <  struct MatchItem *matchitem = NULL;
532 <  struct ClassItem *classitem = NULL;
533 <  char buf[12];
534 <  char *p = NULL;
535 <
536 <  switch (type)
202 >  DLINK_FOREACH_SAFE(ptr, ptr_next, conf->leaf_list.head)
203    {
204 <  case XLINE_TYPE:
205 <    DLINK_FOREACH(ptr, xconf_items.head)
206 <    {
541 <      conf = ptr->data;
542 <      matchitem = map_to_conf(conf);
543 <
544 <      sendto_one(source_p, form_str(RPL_STATSXLINE),
545 <                 me.name, source_p->name,
546 <                 matchitem->hold ? "x": "X", matchitem->count,
547 <                 conf->name, matchitem->reason);
548 <    }
549 <    break;
550 <
551 < #ifdef HAVE_LIBPCRE
552 <  case RXLINE_TYPE:
553 <    DLINK_FOREACH(ptr, rxconf_items.head)
554 <    {
555 <      conf = ptr->data;
556 <      matchitem = map_to_conf(conf);
557 <
558 <      sendto_one(source_p, form_str(RPL_STATSXLINE),
559 <                 me.name, source_p->name,
560 <                 "XR", matchitem->count,
561 <                 conf->name, matchitem->reason);
562 <    }
563 <    break;
564 <
565 <  case RKLINE_TYPE:
566 <    DLINK_FOREACH(ptr, rkconf_items.head)
567 <    {
568 <      aconf = map_to_conf((conf = ptr->data));
569 <
570 <      sendto_one(source_p, form_str(RPL_STATSKLINE), me.name,
571 <                 source_p->name, "KR", aconf->host, aconf->user,
572 <                 aconf->reason, aconf->oper_reason ? aconf->oper_reason : "");
573 <    }
574 <    break;
575 < #endif
576 <
577 <  case ULINE_TYPE:
578 <    DLINK_FOREACH(ptr, uconf_items.head)
579 <    {
580 <      conf = ptr->data;
581 <      matchitem = map_to_conf(conf);
582 <
583 <      p = buf;
584 <
585 <      /* some of these are redundant for the sake of
586 <       * consistency with cluster{} flags
587 <       */
588 <      *p++ = 'c';
589 <      flags_to_ascii(matchitem->action, shared_bit_table, p, 0);
590 <
591 <      sendto_one(source_p, form_str(RPL_STATSULINE),
592 <                 me.name, source_p->name, conf->name,
593 <                 matchitem->user?matchitem->user: "*",
594 <                 matchitem->host?matchitem->host: "*", buf);
595 <    }
596 <
597 <    DLINK_FOREACH(ptr, cluster_items.head)
598 <    {
599 <      conf = ptr->data;
600 <
601 <      p = buf;
602 <
603 <      *p++ = 'C';
604 <      flags_to_ascii(conf->flags, shared_bit_table, p, 0);
605 <
606 <      sendto_one(source_p, form_str(RPL_STATSULINE),
607 <                 me.name, source_p->name, conf->name,
608 <                 "*", "*", buf);
609 <    }
610 <
611 <    break;
612 <
613 <  case OPER_TYPE:
614 <    DLINK_FOREACH(ptr, oconf_items.head)
615 <    {
616 <      conf = ptr->data;
617 <      aconf = map_to_conf(conf);
618 <
619 <      /* Don't allow non opers to see oper privs */
620 <      if (HasUMode(source_p, UMODE_OPER))
621 <        sendto_one(source_p, form_str(RPL_STATSOLINE),
622 <                   me.name, source_p->name, 'O', aconf->user, aconf->host,
623 <                   conf->name, oper_privs_as_string(aconf->port),
624 <                   aconf->class_ptr ? aconf->class_ptr->name : "<default>");
625 <      else
626 <        sendto_one(source_p, form_str(RPL_STATSOLINE),
627 <                   me.name, source_p->name, 'O', aconf->user, aconf->host,
628 <                   conf->name, "0",
629 <                   aconf->class_ptr ? aconf->class_ptr->name : "<default>");
630 <    }
631 <    break;
632 <
633 <  case CLASS_TYPE:
634 <    DLINK_FOREACH(ptr, class_items.head)
635 <    {
636 <      conf = ptr->data;
637 <      classitem = map_to_conf(conf);
638 <      sendto_one(source_p, form_str(RPL_STATSYLINE),
639 <                 me.name, source_p->name, 'Y',
640 <                 conf->name, classitem->ping_freq,
641 <                 classitem->con_freq,
642 <                 classitem->max_total, classitem->max_sendq,
643 <                 classitem->max_recvq,
644 <                 classitem->curr_user_count,
645 <                 classitem->number_per_cidr, classitem->cidr_bitlen_ipv4,
646 <                 classitem->number_per_cidr, classitem->cidr_bitlen_ipv6,
647 <                 classitem->active ? "active" : "disabled");
648 <    }
649 <    break;
650 <
651 <  case CONF_TYPE:
652 <  case CLIENT_TYPE:
653 <    break;
654 <
655 <  case SERVICE_TYPE:
656 <    DLINK_FOREACH(ptr, service_items.head)
657 <    {
658 <      conf = ptr->data;
659 <      sendto_one(source_p, form_str(RPL_STATSSERVICE),
660 <                 me.name, source_p->name, 'S', "*", conf->name, 0, 0);
661 <    }
662 <    break;
663 <
664 <  case SERVER_TYPE:
665 <    DLINK_FOREACH(ptr, server_items.head)
666 <    {
667 <      p = buf;
668 <
669 <      conf = ptr->data;
670 <      aconf = map_to_conf(conf);
671 <
672 <      buf[0] = '\0';
673 <
674 <      if (IsConfAllowAutoConn(aconf))
675 <        *p++ = 'A';
676 <      if (IsConfSSL(aconf))
677 <        *p++ = 'S';
678 <      if (IsConfTopicBurst(aconf))
679 <        *p++ = 'T';
680 <      if (buf[0] == '\0')
681 <        *p++ = '*';
682 <
683 <      *p = '\0';
684 <
685 <      /*
686 <       * Allow admins to see actual ips unless hide_server_ips is enabled
687 <       */
688 <      if (!ConfigServerHide.hide_server_ips && HasUMode(source_p, UMODE_ADMIN))
689 <        sendto_one(source_p, form_str(RPL_STATSCLINE),
690 <                   me.name, source_p->name, 'C', aconf->host,
691 <                   buf, conf->name, aconf->port,
692 <                   aconf->class_ptr ? aconf->class_ptr->name : "<default>");
693 <        else
694 <          sendto_one(source_p, form_str(RPL_STATSCLINE),
695 <                     me.name, source_p->name, 'C',
696 <                     "*@127.0.0.1", buf, conf->name, aconf->port,
697 <                     aconf->class_ptr ? aconf->class_ptr->name : "<default>");
698 <    }
699 <    break;
700 <
701 <  case HUB_TYPE:
702 <    DLINK_FOREACH(ptr, server_items.head)
703 <    {
704 <      conf = ptr->data;
705 <      aconf = map_to_conf(conf);
706 <
707 <      DLINK_FOREACH(dptr, aconf->hub_list.head)
708 <        sendto_one(source_p, form_str(RPL_STATSHLINE), me.name,
709 <                   source_p->name, 'H', dptr->data, conf->name, 0, "*");
710 <    }
711 <    break;
712 <
713 <  case LEAF_TYPE:
714 <    DLINK_FOREACH(ptr, server_items.head)
715 <    {
716 <      conf = ptr->data;
717 <      aconf = map_to_conf(conf);
204 >    MyFree(ptr->data);
205 >    free_dlink_node(ptr);
206 >  }
207  
208 <      DLINK_FOREACH(dptr, aconf->leaf_list.head)
209 <        sendto_one(source_p, form_str(RPL_STATSLLINE), me.name,
210 <                   source_p->name, 'L', dptr->data, conf->name, 0, "*");
722 <    }
723 <    break;
208 >  DLINK_FOREACH_SAFE(ptr, ptr_next, conf->exempt_list.head)
209 >  {
210 >    struct exempt *exptr = ptr->data;
211  
212 <  case GLINE_TYPE:
213 <  case KLINE_TYPE:
214 <  case DLINE_TYPE:
215 <  case EXEMPTDLINE_TYPE:
729 <  case CRESV_TYPE:
730 <  case NRESV_TYPE:
731 <  case CLUSTER_TYPE:
732 <  default:
733 <    break;
212 >    MyFree(exptr->name);
213 >    MyFree(exptr->user);
214 >    MyFree(exptr->host);
215 >    MyFree(exptr);
216    }
217 +
218 +  MyFree(conf);
219   }
220  
221   /* check_client()
# Line 747 | Line 231 | report_confitem_types(struct Client *sou
231   *                Look for conf lines which have the same
232   *                status as the flags passed.
233   */
234 < static void *
235 < check_client(va_list args)
234 > int
235 > check_client(struct Client *source_p)
236   {
753 –  struct Client *source_p = va_arg(args, struct Client *);
754 –  const char *username = va_arg(args, const char *);
237    int i;
238  
239 <  /* I'm already in big trouble if source_p->localClient is NULL -db */
758 <  if ((i = verify_access(source_p, username)))
239 >  if ((i = verify_access(source_p)))
240      ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
241           source_p->name, source_p->sockhost);
242  
243    switch (i)
244    {
245      case TOO_MANY:
246 <      sendto_realops_flags(UMODE_FULL, L_ALL,
246 >      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
247                             "Too many on IP for %s (%s).",
248 <                           get_client_name(source_p, SHOW_IP),
249 <                           source_p->sockhost);
248 >                           get_client_name(source_p, SHOW_IP),
249 >                           source_p->sockhost);
250        ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
251 <           get_client_name(source_p, SHOW_IP));
251 >           get_client_name(source_p, SHOW_IP));
252        ++ServerStats.is_ref;
253        exit_client(source_p, &me, "No more connections allowed on that IP");
254        break;
255  
256      case I_LINE_FULL:
257 <      sendto_realops_flags(UMODE_FULL, L_ALL,
258 <                           "I-line is full for %s (%s).",
259 <                           get_client_name(source_p, SHOW_IP),
260 <                           source_p->sockhost);
257 >      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
258 >                           "auth{} block is full for %s (%s).",
259 >                           get_client_name(source_p, SHOW_IP),
260 >                           source_p->sockhost);
261        ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
262 <           get_client_name(source_p, SHOW_IP));
262 >           get_client_name(source_p, SHOW_IP));
263        ++ServerStats.is_ref;
264        exit_client(source_p, &me,
265 <                "No more connections allowed in your connection class");
265 >                  "No more connections allowed in your connection class");
266        break;
267  
268      case NOT_AUTHORIZED:
269        ++ServerStats.is_ref;
270        /* jdc - lists server name & port connections are on */
271        /*       a purely cosmetical change */
272 <      sendto_realops_flags(UMODE_UNAUTH, L_ALL,
273 <                           "Unauthorized client connection from %s [%s] on [%s/%u].",
274 <                           get_client_name(source_p, SHOW_IP),
275 <                           source_p->sockhost,
276 <                           source_p->localClient->listener->name,
277 <                           source_p->localClient->listener->port);
272 >      sendto_realops_flags(UMODE_UNAUTH, L_ALL, SEND_NOTICE,
273 >                           "Unauthorized client connection from %s [%s] on [%s/%u].",
274 >                           get_client_name(source_p, SHOW_IP),
275 >                           source_p->sockhost,
276 >                           source_p->localClient->listener->name,
277 >                           source_p->localClient->listener->port);
278        ilog(LOG_TYPE_IRCD,
279 <          "Unauthorized client connection from %s on [%s/%u].",
280 <          get_client_name(source_p, SHOW_IP),
281 <          source_p->localClient->listener->name,
282 <          source_p->localClient->listener->port);
283 <
284 <      /* XXX It is prolematical whether it is better to use the
804 <       * capture reject code here or rely on the connecting too fast code.
805 <       * - Dianora
806 <       */
807 <      if (REJECT_HOLD_TIME > 0)
808 <      {
809 <        sendto_one(source_p, ":%s NOTICE %s :You are not authorized to use this server",
810 <                   me.name, source_p->name);
811 <        source_p->localClient->reject_delay = CurrentTime + REJECT_HOLD_TIME;
812 <        SetCaptured(source_p);
813 <      }
814 <      else
815 <        exit_client(source_p, &me, "You are not authorized to use this server");
279 >           "Unauthorized client connection from %s on [%s/%u].",
280 >           get_client_name(source_p, SHOW_IP),
281 >           source_p->localClient->listener->name,
282 >           source_p->localClient->listener->port);
283 >
284 >      exit_client(source_p, &me, "You are not authorized to use this server");
285        break;
286  
287     case BANNED_CLIENT:
288 <     /*
820 <      * Don't exit them immediately, play with them a bit.
821 <      * - Dianora
822 <      */
823 <     if (REJECT_HOLD_TIME > 0)
824 <     {
825 <       source_p->localClient->reject_delay = CurrentTime + REJECT_HOLD_TIME;
826 <       SetCaptured(source_p);
827 <     }
828 <     else
829 <       exit_client(source_p, &me, "Banned");
288 >     exit_client(source_p, &me, "Banned");
289       ++ServerStats.is_ref;
290       break;
291  
# Line 835 | Line 294 | check_client(va_list args)
294       break;
295    }
296  
297 <  return (i < 0 ? NULL : source_p);
297 >  return (i < 0 ? 0 : 1);
298   }
299  
300   /* verify_access()
301   *
302   * inputs       - pointer to client to verify
844 – *              - pointer to proposed username
303   * output       - 0 if success -'ve if not
304   * side effect  - find the first (best) I line to attach.
305   */
306   static int
307 < verify_access(struct Client *client_p, const char *username)
307 > verify_access(struct Client *client_p)
308   {
309 <  struct AccessItem *aconf = NULL, *rkconf = NULL;
852 <  struct ConfItem *conf = NULL;
309 >  struct MaskItem *conf = NULL;
310    char non_ident[USERLEN + 1] = { '~', '\0' };
854 –  const char *uhi[3];
311  
312    if (IsGotId(client_p))
313    {
314 <    aconf = find_address_conf(client_p->host, client_p->username,
315 <                             &client_p->localClient->ip,
316 <                             client_p->localClient->aftype,
314 >    conf = find_address_conf(client_p->host, client_p->username,
315 >                             &client_p->localClient->ip,
316 >                             client_p->localClient->aftype,
317                               client_p->localClient->passwd);
318    }
319    else
320    {
321 <    strlcpy(non_ident+1, username, sizeof(non_ident)-1);
322 <    aconf = find_address_conf(client_p->host,non_ident,
323 <                             &client_p->localClient->ip,
324 <                             client_p->localClient->aftype,
325 <                             client_p->localClient->passwd);
321 >    strlcpy(non_ident + 1, client_p->username, sizeof(non_ident) - 1);
322 >    conf = find_address_conf(client_p->host,non_ident,
323 >                             &client_p->localClient->ip,
324 >                             client_p->localClient->aftype,
325 >                             client_p->localClient->passwd);
326    }
327  
328 <  uhi[0] = IsGotId(client_p) ? client_p->username : non_ident;
873 <  uhi[1] = client_p->host;
874 <  uhi[2] = client_p->sockhost;
875 <
876 <  rkconf = find_regexp_kline(uhi);
877 <
878 <  if (aconf != NULL)
328 >  if (conf != NULL)
329    {
330 <    if (IsConfClient(aconf) && !rkconf)
330 >    if (IsConfClient(conf))
331      {
332 <      conf = unmap_conf_item(aconf);
883 <
884 <      if (IsConfRedir(aconf))
332 >      if (IsConfRedir(conf))
333        {
334          sendto_one(client_p, form_str(RPL_REDIR),
335                     me.name, client_p->name,
336                     conf->name ? conf->name : "",
337 <                   aconf->port);
338 <        return(NOT_AUTHORIZED);
337 >                   conf->port);
338 >        return NOT_AUTHORIZED;
339        }
340  
341 <      if (IsConfDoIdentd(aconf))
342 <        SetNeedId(client_p);
341 >      if (IsConfDoIdentd(conf))
342 >        SetNeedId(client_p);
343  
344        /* Thanks for spoof idea amm */
345 <      if (IsConfDoSpoofIp(aconf))
345 >      if (IsConfDoSpoofIp(conf))
346        {
347 <        conf = unmap_conf_item(aconf);
348 <
349 <        if (!ConfigFileEntry.hide_spoof_ips && IsConfSpoofNotice(aconf))
902 <          sendto_realops_flags(UMODE_ALL, L_ADMIN, "%s spoofing: %s as %s",
347 >        if (!ConfigFileEntry.hide_spoof_ips && IsConfSpoofNotice(conf))
348 >          sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
349 >                               "%s spoofing: %s as %s",
350                                 client_p->name, client_p->host, conf->name);
351          strlcpy(client_p->host, conf->name, sizeof(client_p->host));
352 <        SetIPSpoof(client_p);
352 >        AddFlag(client_p, FLAGS_IP_SPOOFING | FLAGS_AUTH_SPOOF);
353        }
354  
355 <      return(attach_iline(client_p, conf));
355 >      return attach_iline(client_p, conf);
356      }
357 <    else if (rkconf || IsConfKill(aconf) || (ConfigFileEntry.glines && IsConfGline(aconf)))
357 >    else if (IsConfKill(conf) || (ConfigFileEntry.glines && IsConfGline(conf)))
358      {
359 <      /* XXX */
913 <      aconf = rkconf ? rkconf : aconf;
914 <      if (IsConfGline(aconf))
359 >      if (IsConfGline(conf))
360          sendto_one(client_p, ":%s NOTICE %s :*** G-lined", me.name,
361                     client_p->name);
362 <      if (ConfigFileEntry.kline_with_reason)
363 <        sendto_one(client_p, ":%s NOTICE %s :*** Banned %s",
364 <                  me.name, client_p->name, aconf->reason);
920 <      return(BANNED_CLIENT);
362 >      sendto_one(client_p, ":%s NOTICE %s :*** Banned: %s",
363 >                 me.name, client_p->name, conf->reason);
364 >      return BANNED_CLIENT;
365      }
366    }
367  
368 <  return(NOT_AUTHORIZED);
368 >  return NOT_AUTHORIZED;
369   }
370  
371   /* attach_iline()
# Line 932 | Line 376 | verify_access(struct Client *client_p, c
376   * side effects - do actual attach
377   */
378   static int
379 < attach_iline(struct Client *client_p, struct ConfItem *conf)
379 > attach_iline(struct Client *client_p, struct MaskItem *conf)
380   {
381 <  struct AccessItem *aconf;
938 <  struct ClassItem *aclass;
381 >  struct ClassItem *class = NULL;
382    struct ip_entry *ip_found;
383    int a_limit_reached = 0;
384 <  int local = 0, global = 0, ident = 0;
384 >  unsigned int local = 0, global = 0, ident = 0;
385  
386    ip_found = find_or_add_ip(&client_p->localClient->ip);
387    ip_found->count++;
388    SetIpHash(client_p);
389  
390 <  aconf = map_to_conf(conf);
948 <  if (aconf->class_ptr == NULL)
390 >  if (conf->class == NULL)
391      return NOT_AUTHORIZED;  /* If class is missing, this is best */
392  
393 <  aclass = map_to_conf(aconf->class_ptr);
393 >  class = conf->class;
394  
395    count_user_host(client_p->username, client_p->host,
396                    &global, &local, &ident);
# Line 957 | Line 399 | attach_iline(struct Client *client_p, st
399     * setting a_limit_reached if any limit is reached.
400     * - Dianora
401     */
402 <  if (aclass->max_total != 0 && aclass->curr_user_count >= aclass->max_total)
402 >  if (class->max_total != 0 && class->ref_count >= class->max_total)
403      a_limit_reached = 1;
404 <  else if (aclass->max_perip != 0 && ip_found->count > aclass->max_perip)
404 >  else if (class->max_perip != 0 && ip_found->count > class->max_perip)
405      a_limit_reached = 1;
406 <  else if (aclass->max_local != 0 && local >= aclass->max_local)
406 >  else if (class->max_local != 0 && local >= class->max_local)
407      a_limit_reached = 1;
408 <  else if (aclass->max_global != 0 && global >= aclass->max_global)
408 >  else if (class->max_global != 0 && global >= class->max_global)
409      a_limit_reached = 1;
410 <  else if (aclass->max_ident != 0 && ident >= aclass->max_ident &&
410 >  else if (class->max_ident != 0 && ident >= class->max_ident &&
411             client_p->username[0] != '~')
412      a_limit_reached = 1;
413  
414    if (a_limit_reached)
415    {
416 <    if (!IsConfExemptLimits(aconf))
416 >    if (!IsConfExemptLimits(conf))
417        return TOO_MANY;   /* Already at maximum allowed */
418  
419      sendto_one(client_p,
# Line 992 | Line 434 | attach_iline(struct Client *client_p, st
434   void
435   init_ip_hash_table(void)
436   {
437 <  ip_entry_heap = BlockHeapCreate("ip", sizeof(struct ip_entry),
996 <    2 * hard_fdlimit);
437 >  ip_entry_pool = mp_pool_new(sizeof(struct ip_entry), MP_CHUNK_SIZE_IP_ENTRY);
438    memset(ip_hash_table, 0, sizeof(ip_hash_table));
439   }
440  
# Line 1042 | Line 483 | find_or_add_ip(struct irc_ssaddr *ip_in)
483    if (ip_entries_count >= 2 * hard_fdlimit)
484      garbage_collect_ip_entries();
485  
486 <  newptr = BlockHeapAlloc(ip_entry_heap);
486 >  newptr = mp_pool_get(ip_entry_pool);
487 >  memset(newptr, 0, sizeof(*newptr));
488    ip_entries_count++;
489    memcpy(&newptr->ip, ip_in, sizeof(struct irc_ssaddr));
490  
# Line 1093 | Line 535 | remove_one_ip(struct irc_ssaddr *ip_in)
535      if (ptr->count > 0)
536        ptr->count--;
537      if (ptr->count == 0 &&
538 <        (CurrentTime-ptr->last_attempt) >= ConfigFileEntry.throttle_time)
538 >        (CurrentTime-ptr->last_attempt) >= ConfigFileEntry.throttle_time)
539      {
540        if (last_ptr != NULL)
541 <        last_ptr->next = ptr->next;
541 >        last_ptr->next = ptr->next;
542        else
543 <        ip_hash_table[hash_index] = ptr->next;
543 >        ip_hash_table[hash_index] = ptr->next;
544  
545 <      BlockHeapFree(ip_entry_heap, ptr);
545 >      mp_pool_release(ptr);
546        ip_entries_count--;
547        return;
548      }
# Line 1203 | Line 645 | garbage_collect_ip_entries(void)
645            last_ptr->next = ptr->next;
646          else
647            ip_hash_table[i] = ptr->next;
648 <        BlockHeapFree(ip_entry_heap, ptr);
648 >        mp_pool_release(ptr);
649          ip_entries_count--;
650        }
651        else
# Line 1220 | Line 662 | garbage_collect_ip_entries(void)
662   * side effects - Disassociate configuration from the client.
663   *                Also removes a class from the list if marked for deleting.
664   */
665 < int
666 < detach_conf(struct Client *client_p, ConfType type)
665 > void
666 > detach_conf(struct Client *client_p, enum maskitem_type type)
667   {
668 <  dlink_node *ptr, *next_ptr;
1227 <  struct ConfItem *conf;
1228 <  struct ClassItem *aclass;
1229 <  struct AccessItem *aconf;
1230 <  struct ConfItem *aclass_conf;
1231 <  struct MatchItem *match_item;
668 >  dlink_node *ptr = NULL, *next_ptr = NULL;
669  
670    DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->confs.head)
671    {
672 <    conf = ptr->data;
672 >    struct MaskItem *conf = ptr->data;
673  
674 <    if (type == CONF_TYPE || conf->type == type)
675 <    {
676 <      dlinkDelete(ptr, &client_p->localClient->confs);
1240 <      free_dlink_node(ptr);
1241 <
1242 <      switch (conf->type)
1243 <      {
1244 <      case CLIENT_TYPE:
1245 <      case OPER_TYPE:
1246 <      case SERVER_TYPE:
1247 <        aconf = map_to_conf(conf);
674 >    assert(conf->type & (CONF_CLIENT | CONF_OPER | CONF_SERVER));
675 >    assert(conf->ref_count > 0);
676 >    assert(conf->class->ref_count > 0);
677  
678 <        assert(aconf->clients > 0);
679 <
1251 <        if ((aclass_conf = aconf->class_ptr) != NULL)
1252 <        {
1253 <          aclass = map_to_conf(aclass_conf);
1254 <
1255 <          assert(aclass->curr_user_count > 0);
678 >    if (!(conf->type & type))
679 >      continue;
680  
681 <          if (conf->type == CLIENT_TYPE)
682 <            remove_from_cidr_check(&client_p->localClient->ip, aclass);
1259 <          if (--aclass->curr_user_count == 0 && aclass->active == 0)
1260 <            delete_conf_item(aclass_conf);
1261 <        }
681 >    dlinkDelete(ptr, &client_p->localClient->confs);
682 >    free_dlink_node(ptr);
683  
684 <        if (--aconf->clients == 0 && IsConfIllegal(aconf))
685 <          delete_conf_item(conf);
684 >    if (conf->type & CONF_CLIENT)
685 >      remove_from_cidr_check(&client_p->localClient->ip, conf->class);
686  
687 <        break;
688 <      default:
689 <        break;
690 <      }
1270 <
1271 <      if (type != CONF_TYPE)
1272 <        return 0;
687 >    if (--conf->class->ref_count == 0 && conf->class->active == 0)
688 >    {
689 >      class_free(conf->class);
690 >      conf->class = NULL;
691      }
1274 –  }
692  
693 <  return -1;
693 >    if (--conf->ref_count == 0 && conf->active == 0)
694 >      conf_free(conf);
695 >  }
696   }
697  
698   /* attach_conf()
# Line 1287 | Line 706 | detach_conf(struct Client *client_p, Con
706   *                attachment if there was an old one...
707   */
708   int
709 < attach_conf(struct Client *client_p, struct ConfItem *conf)
709 > attach_conf(struct Client *client_p, struct MaskItem *conf)
710   {
1292 –  struct AccessItem *aconf = map_to_conf(conf);
1293 –  struct ClassItem *aclass = map_to_conf(aconf->class_ptr);
1294 –
711    if (dlinkFind(&client_p->localClient->confs, conf) != NULL)
712      return 1;
713  
714 <  if (IsConfIllegal(aconf)) /* TBV: can't happen */
715 <    return NOT_AUTHORIZED;
716 <
1301 <  if (conf->type == CLIENT_TYPE)
1302 <    if (cidr_limit_reached(IsConfExemptLimits(aconf),
1303 <                           &client_p->localClient->ip, aclass))
714 >  if (conf->type == CONF_CLIENT)
715 >    if (cidr_limit_reached(IsConfExemptLimits(conf),
716 >                           &client_p->localClient->ip, conf->class))
717        return TOO_MANY;    /* Already at maximum allowed */
718  
719 <  aclass->curr_user_count++;
720 <  aconf->clients++;
719 >  conf->class->ref_count++;
720 >  conf->ref_count++;
721  
722    dlinkAdd(conf, make_dlink_node(), &client_p->localClient->confs);
723  
# Line 1324 | Line 737 | attach_connect_block(struct Client *clie
737                       const char *host)
738   {
739    dlink_node *ptr;
740 <  struct ConfItem *conf;
1328 <  struct AccessItem *aconf;
740 >  struct MaskItem *conf = NULL;
741  
742    assert(client_p != NULL);
743    assert(host != NULL);
# Line 1336 | Line 748 | attach_connect_block(struct Client *clie
748    DLINK_FOREACH(ptr, server_items.head)
749    {
750      conf = ptr->data;
1339 –    aconf = map_to_conf(conf);
751  
752 <    if (match(conf->name, name) == 0 || match(aconf->host, host) == 0)
752 >    if (match(conf->name, name) || match(conf->host, host))
753        continue;
754  
755      attach_conf(client_p, conf);
# Line 1348 | Line 759 | attach_connect_block(struct Client *clie
759    return 0;
760   }
761  
1351 – /* find_conf_exact()
1352 – *
1353 – * inputs       - type of ConfItem
1354 – *              - pointer to name to find
1355 – *              - pointer to username to find
1356 – *              - pointer to host to find
1357 – * output       - NULL or pointer to conf found
1358 – * side effects - find a conf entry which matches the hostname
1359 – *                and has the same name.
1360 – */
1361 – struct ConfItem *
1362 – find_conf_exact(ConfType type, const char *name, const char *user,
1363 –                const char *host)
1364 – {
1365 –  dlink_node *ptr;
1366 –  dlink_list *list_p;
1367 –  struct ConfItem *conf = NULL;
1368 –  struct AccessItem *aconf;
1369 –
1370 –  /* Only valid for OPER_TYPE and ...? */
1371 –  list_p = map_to_list(type);
1372 –
1373 –  DLINK_FOREACH(ptr, (*list_p).head)
1374 –  {
1375 –    conf = ptr->data;
1376 –
1377 –    if (conf->name == NULL)
1378 –      continue;
1379 –    aconf = map_to_conf(conf);
1380 –    if (aconf->host == NULL)
1381 –      continue;
1382 –    if (irccmp(conf->name, name) != 0)
1383 –      continue;
1384 –
1385 –    /*
1386 –    ** Accept if the *real* hostname (usually sockethost)
1387 –    ** socket host) matches *either* host or name field
1388 –    ** of the configuration.
1389 –    */
1390 –    if (!match(aconf->host, host) || !match(aconf->user, user))
1391 –      continue;
1392 –    if (type == OPER_TYPE)
1393 –    {
1394 –      struct ClassItem *aclass = map_to_conf(aconf->class_ptr);
1395 –
1396 –      if (aconf->clients >= aclass->max_total)
1397 –        continue;
1398 –    }
1399 –
1400 –    return conf;
1401 –  }
1402 –
1403 –  return NULL;
1404 – }
1405 –
762   /* find_conf_name()
763   *
764   * inputs       - pointer to conf link list to search
# Line 1412 | Line 768 | find_conf_exact(ConfType type, const cha
768   * side effects - find a conf entry which matches the name
769   *                and has the given mask.
770   */
771 < struct ConfItem *
772 < find_conf_name(dlink_list *list, const char *name, ConfType type)
771 > struct MaskItem *
772 > find_conf_name(dlink_list *list, const char *name, enum maskitem_type type)
773   {
774    dlink_node *ptr;
775 <  struct ConfItem* conf;
775 >  struct MaskItem* conf;
776  
777    DLINK_FOREACH(ptr, list->head)
778    {
# Line 1425 | Line 781 | find_conf_name(dlink_list *list, const c
781      if (conf->type == type)
782      {
783        if (conf->name && (irccmp(conf->name, name) == 0 ||
784 <                         match(conf->name, name)))
784 >                         !match(conf->name, name)))
785        return conf;
786      }
787    }
# Line 1440 | Line 796 | find_conf_name(dlink_list *list, const c
796   * side effects - none
797   */
798   static dlink_list *
799 < map_to_list(ConfType type)
799 > map_to_list(enum maskitem_type type)
800   {
801    switch(type)
802    {
803 <  case RXLINE_TYPE:
1448 <    return(&rxconf_items);
1449 <    break;
1450 <  case XLINE_TYPE:
803 >  case CONF_XLINE:
804      return(&xconf_items);
805      break;
806 <  case ULINE_TYPE:
806 >  case CONF_ULINE:
807      return(&uconf_items);
808      break;
809 <  case NRESV_TYPE:
809 >  case CONF_NRESV:
810      return(&nresv_items);
811      break;
812 <  case OPER_TYPE:
812 >  case CONF_CRESV:
813 >    return(&cresv_items);
814 >  case CONF_OPER:
815      return(&oconf_items);
816      break;
817 <  case CLASS_TYPE:
1463 <    return(&class_items);
1464 <    break;
1465 <  case SERVER_TYPE:
817 >  case CONF_SERVER:
818      return(&server_items);
819      break;
820 <  case SERVICE_TYPE:
820 >  case CONF_SERVICE:
821      return(&service_items);
822      break;
823 <  case CLUSTER_TYPE:
823 >  case CONF_CLUSTER:
824      return(&cluster_items);
825      break;
1474 –  case CONF_TYPE:
1475 –  case GLINE_TYPE:
1476 –  case KLINE_TYPE:
1477 –  case DLINE_TYPE:
1478 –  case CRESV_TYPE:
826    default:
827      return NULL;
828    }
# Line 1487 | Line 834 | map_to_list(ConfType type)
834   *              - pointer to name string to find
835   *              - pointer to user
836   *              - pointer to host
837 < *              - optional action to match on as well
838 < * output       - NULL or pointer to found struct MatchItem
837 > *              - optional flags to match on as well
838 > * output       - NULL or pointer to found struct MaskItem
839   * side effects - looks for a match on name field
840   */
841 < struct ConfItem *
842 < find_matching_name_conf(ConfType type, const char *name, const char *user,
843 <                        const char *host, int action)
841 > struct MaskItem *
842 > find_matching_name_conf(enum maskitem_type type, const char *name, const char *user,
843 >                        const char *host, unsigned int flags)
844   {
845    dlink_node *ptr=NULL;
846 <  struct ConfItem *conf=NULL;
1500 <  struct AccessItem *aconf=NULL;
1501 <  struct MatchItem *match_item=NULL;
846 >  struct MaskItem *conf=NULL;
847    dlink_list *list_p = map_to_list(type);
848  
849    switch (type)
850    {
851 < #ifdef HAVE_LIBPCRE
1507 <  case RXLINE_TYPE:
1508 <      DLINK_FOREACH(ptr, list_p->head)
1509 <      {
1510 <        conf = ptr->data;
1511 <        assert(conf->regexpname);
1512 <
1513 <        if (!ircd_pcre_exec(conf->regexpname, name))
1514 <          return conf;
1515 <      }
1516 <      break;
1517 < #endif
1518 <  case SERVICE_TYPE:
851 >  case CONF_SERVICE:
852      DLINK_FOREACH(ptr, list_p->head)
853      {
854        conf = ptr->data;
# Line 1527 | Line 860 | find_matching_name_conf(ConfType type, c
860      }
861      break;
862  
863 <  case XLINE_TYPE:
864 <  case ULINE_TYPE:
865 <  case NRESV_TYPE:
863 >  case CONF_XLINE:
864 >  case CONF_ULINE:
865 >  case CONF_NRESV:
866 >  case CONF_CRESV:
867      DLINK_FOREACH(ptr, list_p->head)
868      {
869        conf = ptr->data;
870  
1537 –      match_item = map_to_conf(conf);
871        if (EmptyString(conf->name))
872 <        continue;
873 <      if ((name != NULL) && match_esc(conf->name, name))
872 >        continue;
873 >      if ((name != NULL) && !match(conf->name, name))
874        {
875 <        if ((user == NULL && (host == NULL)))
876 <          return conf;
877 <        if ((match_item->action & action) != action)
875 >        if ((user == NULL && (host == NULL)))
876 >          return conf;
877 >        if ((conf->flags & flags) != flags)
878            continue;
879 <        if (EmptyString(match_item->user) || EmptyString(match_item->host))
880 <          return conf;
881 <        if (match(match_item->user, user) && match(match_item->host, host))
882 <          return conf;
879 >        if (EmptyString(conf->user) || EmptyString(conf->host))
880 >          return conf;
881 >        if (!match(conf->user, user) && !match(conf->host, host))
882 >          return conf;
883        }
884      }
885        break;
886  
887 <  case SERVER_TYPE:
887 >  case CONF_SERVER:
888      DLINK_FOREACH(ptr, list_p->head)
889      {
890        conf = ptr->data;
1558 –      aconf = map_to_conf(conf);
891  
892 <      if ((name != NULL) && match_esc(name, conf->name))
892 >      if ((name != NULL) && !match(name, conf->name))
893          return conf;
894 <      else if ((host != NULL) && match_esc(host, aconf->host))
894 >      else if ((host != NULL) && !match(host, conf->host))
895          return conf;
896      }
897      break;
# Line 1576 | Line 908 | find_matching_name_conf(ConfType type, c
908   *              - pointer to name string to find
909   *              - pointer to user
910   *              - pointer to host
911 < * output       - NULL or pointer to found struct MatchItem
911 > * output       - NULL or pointer to found struct MaskItem
912   * side effects - looks for an exact match on name field
913   */
914 < struct ConfItem *
915 < find_exact_name_conf(ConfType type, const struct Client *who, const char *name,
914 > struct MaskItem *
915 > find_exact_name_conf(enum maskitem_type type, const struct Client *who, const char *name,
916                       const char *user, const char *host)
917   {
918    dlink_node *ptr = NULL;
919 <  struct AccessItem *aconf;
920 <  struct ConfItem *conf;
1589 <  struct MatchItem *match_item;
1590 <  dlink_list *list_p;
1591 <
1592 <  list_p = map_to_list(type);
919 >  struct MaskItem *conf;
920 >  dlink_list *list_p = map_to_list(type);
921  
922    switch(type)
923    {
924 <  case RXLINE_TYPE:
925 <  case XLINE_TYPE:
926 <  case ULINE_TYPE:
927 <  case NRESV_TYPE:
924 >  case CONF_XLINE:
925 >  case CONF_ULINE:
926 >  case CONF_NRESV:
927 >  case CONF_CRESV:
928  
929      DLINK_FOREACH(ptr, list_p->head)
930      {
931        conf = ptr->data;
932 <      match_item = (struct MatchItem *)map_to_conf(conf);
932 >
933        if (EmptyString(conf->name))
934 <        continue;
934 >        continue;
935      
936        if (irccmp(conf->name, name) == 0)
937        {
938 <        if ((user == NULL && (host == NULL)))
939 <          return (conf);
940 <        if (EmptyString(match_item->user) || EmptyString(match_item->host))
941 <          return (conf);
942 <        if (match(match_item->user, user) && match(match_item->host, host))
943 <          return (conf);
938 >        if ((user == NULL && (host == NULL)))
939 >          return conf;
940 >        if (EmptyString(conf->user) || EmptyString(conf->host))
941 >          return conf;
942 >        if (!match(conf->user, user) && !match(conf->host, host))
943 >          return conf;
944        }
945      }
946      break;
947  
948 <  case OPER_TYPE:
948 >  case CONF_OPER:
949      DLINK_FOREACH(ptr, list_p->head)
950      {
951        conf = ptr->data;
1624 –      aconf = map_to_conf(conf);
952  
953        if (EmptyString(conf->name))
954          continue;
# Line 1630 | Line 957 | find_exact_name_conf(ConfType type, cons
957        {
958          if (!who)
959            return conf;
960 <        if (EmptyString(aconf->user) || EmptyString(aconf->host))
961 <          return conf;
962 <        if (match(aconf->user, who->username))
960 >        if (EmptyString(conf->user) || EmptyString(conf->host))
961 >          return NULL;
962 >        if (!match(conf->user, who->username))
963          {
964 <          switch (aconf->type)
964 >          switch (conf->htype)
965            {
966              case HM_HOST:
967 <              if (match(aconf->host, who->host) || match(aconf->host, who->sockhost))
968 <                return conf;
967 >              if (!match(conf->host, who->host) || !match(conf->host, who->sockhost))
968 >                if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
969 >                  return conf;
970                break;
971              case HM_IPV4:
972                if (who->localClient->aftype == AF_INET)
973 <                if (match_ipv4(&who->localClient->ip, &aconf->addr, aconf->bits))
974 <                  return conf;
973 >                if (match_ipv4(&who->localClient->ip, &conf->addr, conf->bits))
974 >                  if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
975 >                    return conf;
976                break;
977   #ifdef IPV6
978              case HM_IPV6:
979                if (who->localClient->aftype == AF_INET6)
980 <                if (match_ipv6(&who->localClient->ip, &aconf->addr, aconf->bits))
981 <                  return conf;
980 >                if (match_ipv6(&who->localClient->ip, &conf->addr, conf->bits))
981 >                  if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
982 >                    return conf;
983                break;
984   #endif
985              default:
# Line 1661 | Line 991 | find_exact_name_conf(ConfType type, cons
991  
992      break;
993  
994 <  case SERVER_TYPE:
994 >  case CONF_SERVER:
995      DLINK_FOREACH(ptr, list_p->head)
996      {
997        conf = ptr->data;
998 <      aconf = (struct AccessItem *)map_to_conf(conf);
998 >
999        if (EmptyString(conf->name))
1000 <        continue;
1000 >        continue;
1001      
1002        if (name == NULL)
1003        {
1004 <        if (EmptyString(aconf->host))
1005 <          continue;
1006 <        if (irccmp(aconf->host, host) == 0)
1007 <          return(conf);
1004 >        if (EmptyString(conf->host))
1005 >          continue;
1006 >        if (irccmp(conf->host, host) == 0)
1007 >          return conf;
1008        }
1009        else if (irccmp(conf->name, name) == 0)
1010 <      {
1681 <          return (conf);
1682 <      }
1010 >        return conf;
1011      }
1684 –    break;
1012  
1686 –  case CLASS_TYPE:
1687 –    DLINK_FOREACH(ptr, list_p->head)
1688 –    {
1689 –      conf = ptr->data;
1690 –      if (EmptyString(conf->name))
1691 –        continue;
1692 –    
1693 –      if (irccmp(conf->name, name) == 0)
1694 –        return (conf);
1695 –    }
1013      break;
1014  
1015    default:
1016      break;
1017    }
1018 <  return(NULL);
1018 >
1019 >  return NULL;
1020   }
1021  
1022   /* rehash()
# Line 1711 | Line 1029 | int
1029   rehash(int sig)
1030   {
1031    if (sig != 0)
1032 <    sendto_realops_flags(UMODE_ALL, L_ALL,
1032 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1033                           "Got signal SIGHUP, reloading ircd.conf file");
1034  
1035    restart_resolver();
# Line 1728 | Line 1046 | rehash(int sig)
1046  
1047    load_conf_modules();
1048  
1731 –  flush_deleted_I_P();
1732 –
1049    rehashed_klines = 1;
1734 – /* XXX */
1735 –  if (ConfigLoggingEntry.use_logging)
1736 –    log_close_all();
1050  
1051 <  return(0);
1051 >  return 0;
1052   }
1053  
1054   /* set_default_conf()
# Line 1753 | Line 1066 | set_default_conf(void)
1066    /* verify init_class() ran, this should be an unnecessary check
1067     * but its not much work.
1068     */
1069 <  assert(class_default == (struct ConfItem *) class_items.tail->data);
1069 >  assert(class_default == class_get_list()->tail->data);
1070  
1071   #ifdef HAVE_LIBCRYPTO
1072    ServerInfo.rsa_private_key = NULL;
# Line 1763 | Line 1076 | set_default_conf(void)
1076    /* ServerInfo.name is not rehashable */
1077    /* ServerInfo.name = ServerInfo.name; */
1078    ServerInfo.description = NULL;
1079 <  DupString(ServerInfo.network_name, NETWORK_NAME_DEFAULT);
1080 <  DupString(ServerInfo.network_desc, NETWORK_DESC_DEFAULT);
1079 >  ServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
1080 >  ServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
1081  
1082    memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip));
1083    ServerInfo.specific_ipv4_vhost = 0;
# Line 1772 | Line 1085 | set_default_conf(void)
1085    ServerInfo.specific_ipv6_vhost = 0;
1086  
1087    ServerInfo.max_clients = MAXCLIENTS_MAX;
1088 +  ServerInfo.max_nick_length = 9;
1089 +  ServerInfo.max_topic_length = 80;
1090  
1091    ServerInfo.hub = 0;
1092    ServerInfo.dns_host.sin_addr.s_addr = 0;
# Line 1780 | Line 1095 | set_default_conf(void)
1095    AdminInfo.email = NULL;
1096    AdminInfo.description = NULL;
1097  
1098 <  log_close_all();
1098 >  log_del_all();
1099  
1100    ConfigLoggingEntry.use_logging = 1;
1101  
1102    ConfigChannel.disable_fake_channels = 0;
1788 –  ConfigChannel.restrict_channels = 0;
1103    ConfigChannel.knock_delay = 300;
1104    ConfigChannel.knock_delay_channel = 60;
1105    ConfigChannel.max_chans_per_user = 25;
1106    ConfigChannel.max_chans_per_oper = 50;
1793 –  ConfigChannel.quiet_on_ban = 1;
1107    ConfigChannel.max_bans = 25;
1108    ConfigChannel.default_split_user_count = 0;
1109    ConfigChannel.default_split_server_count = 0;
# Line 1801 | Line 1114 | set_default_conf(void)
1114    ConfigServerHide.links_delay = 300;
1115    ConfigServerHide.hidden = 0;
1116    ConfigServerHide.hide_servers = 0;
1117 <  DupString(ConfigServerHide.hidden_name, NETWORK_NAME_DEFAULT);
1117 >  ConfigServerHide.hide_services = 0;
1118 >  ConfigServerHide.hidden_name = xstrdup(NETWORK_NAME_DEFAULT);
1119    ConfigServerHide.hide_server_ips = 0;
1120 +  ConfigServerHide.disable_remote_commands = 0;
1121  
1122    
1123 <  DupString(ConfigFileEntry.service_name, SERVICE_NAME_DEFAULT);
1123 >  ConfigFileEntry.service_name = xstrdup(SERVICE_NAME_DEFAULT);
1124    ConfigFileEntry.max_watch = WATCHSIZE_DEFAULT;
1125    ConfigFileEntry.glines = 0;
1126    ConfigFileEntry.gline_time = 12 * 3600;
# Line 1813 | Line 1128 | set_default_conf(void)
1128    ConfigFileEntry.gline_min_cidr = 16;
1129    ConfigFileEntry.gline_min_cidr6 = 48;
1130    ConfigFileEntry.invisible_on_connect = 1;
1816 –  ConfigFileEntry.burst_away = 0;
1817 –  ConfigFileEntry.use_whois_actually = 1;
1131    ConfigFileEntry.tkline_expire_notices = 1;
1132    ConfigFileEntry.hide_spoof_ips = 1;
1133    ConfigFileEntry.ignore_bogus_ts = 0;
1134    ConfigFileEntry.disable_auth = 0;
1822 –  ConfigFileEntry.disable_remote = 0;
1135    ConfigFileEntry.kill_chase_time_limit = 90;
1136    ConfigFileEntry.default_floodcount = 8;
1137    ConfigFileEntry.failed_oper_notice = 1;
# Line 1833 | Line 1145 | set_default_conf(void)
1145    ConfigFileEntry.anti_spam_exit_message_time = 0;
1146    ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
1147    ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
1836 –  ConfigFileEntry.kline_with_reason = 1;
1837 –  ConfigFileEntry.kline_reason = NULL;
1148    ConfigFileEntry.warn_no_nline = 1;
1149    ConfigFileEntry.stats_o_oper_only = 0;
1150    ConfigFileEntry.stats_k_oper_only = 1;  /* masked */
1151    ConfigFileEntry.stats_i_oper_only = 1;  /* masked */
1152    ConfigFileEntry.stats_P_oper_only = 0;
1153 +  ConfigFileEntry.stats_u_oper_only = 0;
1154    ConfigFileEntry.caller_id_wait = 60;
1155    ConfigFileEntry.opers_bypass_callerid = 0;
1156    ConfigFileEntry.pace_wait = 10;
# Line 1868 | Line 1179 | validate_conf(void)
1179      ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
1180  
1181    if (ServerInfo.network_name == NULL)
1182 <    DupString(ServerInfo.network_name,NETWORK_NAME_DEFAULT);
1182 >    ServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
1183  
1184    if (ServerInfo.network_desc == NULL)
1185 <    DupString(ServerInfo.network_desc,NETWORK_DESC_DEFAULT);
1185 >    ServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
1186  
1187    if (ConfigFileEntry.service_name == NULL)
1188 <    DupString(ConfigFileEntry.service_name, SERVICE_NAME_DEFAULT);
1188 >    ConfigFileEntry.service_name = xstrdup(SERVICE_NAME_DEFAULT);
1189  
1190    ConfigFileEntry.max_watch = IRCD_MAX(ConfigFileEntry.max_watch, WATCHSIZE_MIN);
1191   }
# Line 1892 | Line 1203 | read_conf(FILE *file)
1203  
1204    set_default_conf(); /* Set default values prior to conf parsing */
1205    conf_parser_ctx.pass = 1;
1206 <  yyparse();          /* pick up the classes first */
1206 >  yyparse();          /* pick up the classes first */
1207  
1208    rewind(file);
1209  
# Line 1900 | Line 1211 | read_conf(FILE *file)
1211    yyparse();          /* Load the values from the conf */
1212    validate_conf();    /* Check to make sure some values are still okay. */
1213                        /* Some global values are also loaded here. */
1214 <  check_class();      /* Make sure classes are valid */
1214 >  class_delete_marked();      /* Make sure classes are valid */
1215   }
1216  
1217   /* lookup_confhost()
# Line 1908 | Line 1219 | read_conf(FILE *file)
1219   * start DNS lookups of all hostnames in the conf
1220   * line and convert an IP addresses in a.b.c.d number for to IP#s.
1221   */
1222 < static void
1223 < lookup_confhost(struct ConfItem *conf)
1222 > void
1223 > lookup_confhost(struct MaskItem *conf)
1224   {
1914 –  struct AccessItem *aconf;
1225    struct addrinfo hints, *res;
1226  
1917 –  aconf = map_to_conf(conf);
1918 –
1919 –  if (has_wildcards(aconf->host))
1920 –  {
1921 –    ilog(LOG_TYPE_IRCD, "Host/server name error: (%s) (%s)",
1922 –         aconf->host, conf->name);
1923 –    return;
1924 –  }
1925 –
1227    /* Do name lookup now on hostnames given and store the
1228     * ip numbers in conf structure.
1229     */
# Line 1934 | Line 1235 | lookup_confhost(struct ConfItem *conf)
1235    /* Get us ready for a bind() and don't bother doing dns lookup */
1236    hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
1237  
1238 <  if (getaddrinfo(aconf->host, NULL, &hints, &res))
1238 >  if (getaddrinfo(conf->host, NULL, &hints, &res))
1239    {
1240 <    conf_dns_lookup(aconf);
1240 >    conf_dns_lookup(conf);
1241      return;
1242    }
1243  
1244    assert(res != NULL);
1245  
1246 <  memcpy(&aconf->addr, res->ai_addr, res->ai_addrlen);
1247 <  aconf->addr.ss_len = res->ai_addrlen;
1248 <  aconf->addr.ss.ss_family = res->ai_family;
1246 >  memcpy(&conf->addr, res->ai_addr, res->ai_addrlen);
1247 >  conf->addr.ss_len = res->ai_addrlen;
1248 >  conf->addr.ss.ss_family = res->ai_family;
1249 >
1250    freeaddrinfo(res);
1251   }
1252  
# Line 1959 | Line 1261 | int
1261   conf_connect_allowed(struct irc_ssaddr *addr, int aftype)
1262   {
1263    struct ip_entry *ip_found;
1264 <  struct AccessItem *aconf = find_dline_conf(addr, aftype);
1264 >  struct MaskItem *conf = find_dline_conf(addr, aftype);
1265  
1266    /* DLINE exempt also gets you out of static limits/pacing... */
1267 <  if (aconf && (aconf->status & CONF_EXEMPTDLINE))
1267 >  if (conf && (conf->type == CONF_EXEMPT))
1268      return 0;
1269  
1270 <  if (aconf != NULL)
1270 >  if (conf != NULL)
1271      return BANNED_CLIENT;
1272  
1273    ip_found = find_or_add_ip(addr);
# Line 1981 | Line 1283 | conf_connect_allowed(struct irc_ssaddr *
1283    return 0;
1284   }
1285  
1984 – static struct AccessItem *
1985 – find_regexp_kline(const char *uhi[])
1986 – {
1987 – #ifdef HAVE_LIBPCRE
1988 –  const dlink_node *ptr = NULL;
1989 –
1990 –  DLINK_FOREACH(ptr, rkconf_items.head)
1991 –  {
1992 –    struct AccessItem *aptr = map_to_conf(ptr->data);
1993 –
1994 –    assert(aptr->regexuser);
1995 –    assert(aptr->regexhost);
1996 –
1997 –    if (!ircd_pcre_exec(aptr->regexuser, uhi[0]) &&
1998 –        (!ircd_pcre_exec(aptr->regexhost, uhi[1]) ||
1999 –         !ircd_pcre_exec(aptr->regexhost, uhi[2])))
2000 –      return aptr;
2001 –  }
2002 – #endif
2003 –  return NULL;
2004 – }
2005 –
1286   /* find_kill()
1287   *
1288   * inputs       - pointer to client structure
1289 < * output       - pointer to struct AccessItem if found
1289 > * output       - pointer to struct MaskItem if found
1290   * side effects - See if this user is klined already,
1291 < *                and if so, return struct AccessItem pointer
1291 > *                and if so, return struct MaskItem pointer
1292   */
1293 < struct AccessItem *
1293 > struct MaskItem *
1294   find_kill(struct Client *client_p)
1295   {
1296 <  struct AccessItem *aconf = NULL;
2017 <  const char *uhi[3];
2018 <
2019 <  uhi[0] = client_p->username;
2020 <  uhi[1] = client_p->host;
2021 <  uhi[2] = client_p->sockhost;
1296 >  struct MaskItem *conf = NULL;
1297  
1298    assert(client_p != NULL);
1299  
1300 <  aconf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
1301 <                               CONF_KLINE, client_p->localClient->aftype,
1302 <                               client_p->username, NULL, 1);
1303 <  if (aconf == NULL)
2029 <    aconf = find_regexp_kline(uhi);
2030 <
2031 <  return aconf;
1300 >  conf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
1301 >                              CONF_KLINE, client_p->localClient->aftype,
1302 >                              client_p->username, NULL, 1);
1303 >  return conf;
1304   }
1305  
1306 < struct AccessItem *
1306 > struct MaskItem *
1307   find_gline(struct Client *client_p)
1308   {
1309 <  struct AccessItem *aconf;
1309 >  struct MaskItem *conf;
1310  
1311    assert(client_p != NULL);
1312  
1313 <  aconf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
1314 <                               CONF_GLINE, client_p->localClient->aftype,
1315 <                               client_p->username, NULL, 1);
1316 <  return aconf;
2045 < }
2046 <
2047 < /* add_temp_line()
2048 < *
2049 < * inputs        - pointer to struct ConfItem
2050 < * output        - none
2051 < * Side effects  - links in given struct ConfItem into
2052 < *                 temporary *line link list
2053 < */
2054 < void
2055 < add_temp_line(struct ConfItem *conf)
2056 < {
2057 <  if (conf->type == XLINE_TYPE)
2058 <  {
2059 <    conf->flags |= CONF_FLAGS_TEMPORARY;
2060 <    dlinkAdd(conf, make_dlink_node(), &temporary_xlines);
2061 <  }
2062 <  else if ((conf->type == NRESV_TYPE) || (conf->type == CRESV_TYPE))
2063 <  {
2064 <    conf->flags |= CONF_FLAGS_TEMPORARY;
2065 <    dlinkAdd(conf, make_dlink_node(), &temporary_resv);
2066 <  }
1313 >  conf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
1314 >                              CONF_GLINE, client_p->localClient->aftype,
1315 >                              client_p->username, NULL, 1);
1316 >  return conf;
1317   }
1318  
1319   /* cleanup_tklines()
# Line 2077 | Line 1327 | void
1327   cleanup_tklines(void *notused)
1328   {
1329    hostmask_expire_temporary();
1330 <  expire_tklines(&temporary_xlines);
1331 <  expire_tklines(&temporary_resv);
1330 >  expire_tklines(&xconf_items);
1331 >  expire_tklines(&nresv_items);
1332 >  expire_tklines(&cresv_items);
1333   }
1334  
1335   /* expire_tklines()
# Line 2092 | Line 1343 | expire_tklines(dlink_list *tklist)
1343   {
1344    dlink_node *ptr;
1345    dlink_node *next_ptr;
1346 <  struct ConfItem *conf;
2096 <  struct MatchItem *xconf;
2097 <  struct MatchItem *nconf;
2098 <  struct ResvChannel *cconf;
1346 >  struct MaskItem *conf;
1347  
1348    DLINK_FOREACH_SAFE(ptr, next_ptr, tklist->head)
1349    {
1350      conf = ptr->data;
1351  
1352 <    if (conf->type == XLINE_TYPE)
1352 >    if (!conf->until || conf->until > CurrentTime)
1353 >      continue;
1354 >
1355 >    if (conf->type == CONF_XLINE)
1356      {
1357 <      xconf = (struct MatchItem *)map_to_conf(conf);
1358 <      if (xconf->hold <= CurrentTime)
1359 <      {
1360 <        if (ConfigFileEntry.tkline_expire_notices)
2110 <          sendto_realops_flags(UMODE_ALL, L_ALL,
2111 <                               "Temporary X-line for [%s] sexpired", conf->name);
2112 <        dlinkDelete(ptr, tklist);
2113 <        free_dlink_node(ptr);
2114 <        delete_conf_item(conf);
2115 <      }
1357 >      if (ConfigFileEntry.tkline_expire_notices)
1358 >        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1359 >                               "Temporary X-line for [%s] expired", conf->name);
1360 >      conf_free(conf);
1361      }
1362 <    else if (conf->type == NRESV_TYPE)
1362 >    else if (conf->type == CONF_NRESV || conf->type == CONF_CRESV)
1363      {
1364 <      nconf = (struct MatchItem *)map_to_conf(conf);
1365 <      if (nconf->hold <= CurrentTime)
2121 <      {
2122 <        if (ConfigFileEntry.tkline_expire_notices)
2123 <          sendto_realops_flags(UMODE_ALL, L_ALL,
1364 >      if (ConfigFileEntry.tkline_expire_notices)
1365 >        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1366                                 "Temporary RESV for [%s] expired", conf->name);
1367 <        dlinkDelete(ptr, tklist);
2126 <        free_dlink_node(ptr);
2127 <        delete_conf_item(conf);
2128 <      }
2129 <    }
2130 <    else if (conf->type == CRESV_TYPE)
2131 <    {
2132 <      cconf = (struct ResvChannel *)map_to_conf(conf);
2133 <      if (cconf->hold <= CurrentTime)
2134 <      {
2135 <        if (ConfigFileEntry.tkline_expire_notices)
2136 <          sendto_realops_flags(UMODE_ALL, L_ALL,
2137 <                               "Temporary RESV for [%s] expired", cconf->name);
2138 <        delete_channel_resv(cconf);
2139 <      }
1367 >      conf_free(conf);
1368      }
1369    }
1370   }
# Line 2149 | Line 1377 | expire_tklines(dlink_list *tklist)
1377   */
1378   static const struct oper_privs
1379   {
1380 <  const unsigned int oprivs;
1380 >  const unsigned int flag;
1381    const unsigned char c;
1382   } flag_list[] = {
1383 <  { OPER_FLAG_ADMIN,       'A' },
1384 <  { OPER_FLAG_REMOTEBAN,   'B' },
1385 <  { OPER_FLAG_DIE,         'D' },
1386 <  { OPER_FLAG_GLINE,       'G' },
1387 <  { OPER_FLAG_REHASH,      'H' },
1388 <  { OPER_FLAG_K,           'K' },
1389 <  { OPER_FLAG_OPERWALL,    'L' },
1390 <  { OPER_FLAG_N,           'N' },
1391 <  { OPER_FLAG_GLOBAL_KILL, 'O' },
1392 <  { OPER_FLAG_REMOTE,      'R' },
1393 <  { OPER_FLAG_OPER_SPY,    'S' },
1394 <  { OPER_FLAG_UNKLINE,     'U' },
1395 <  { OPER_FLAG_X,           'X' },
1383 >  { OPER_FLAG_ADMIN,          'A' },
1384 >  { OPER_FLAG_REMOTEBAN,      'B' },
1385 >  { OPER_FLAG_DIE,            'D' },
1386 >  { OPER_FLAG_GLINE,          'G' },
1387 >  { OPER_FLAG_REHASH,         'H' },
1388 >  { OPER_FLAG_K,              'K' },
1389 >  { OPER_FLAG_OPERWALL,       'L' },
1390 >  { OPER_FLAG_KILL,           'N' },
1391 >  { OPER_FLAG_KILL_REMOTE,    'O' },
1392 >  { OPER_FLAG_CONNECT,        'P' },
1393 >  { OPER_FLAG_CONNECT_REMOTE, 'Q' },
1394 >  { OPER_FLAG_SQUIT,          'R' },
1395 >  { OPER_FLAG_SQUIT_REMOTE,   'S' },
1396 >  { OPER_FLAG_UNKLINE,        'U' },
1397 >  { OPER_FLAG_X,              'X' },
1398    { 0, '\0' }
1399   };
1400  
# Line 2173 | Line 1403 | oper_privs_as_string(const unsigned int
1403   {
1404    static char privs_out[16];
1405    char *privs_ptr = privs_out;
1406 <  unsigned int i = 0;
1406 >  const struct oper_privs *opriv = flag_list;
1407  
1408 <  for (; flag_list[i].oprivs; ++i)
1408 >  for (; opriv->flag; ++opriv)
1409    {
1410 <    if (port & flag_list[i].oprivs)
1411 <      *privs_ptr++ = flag_list[i].c;
1410 >    if (port & opriv->flag)
1411 >      *privs_ptr++ = opriv->c;
1412      else
1413 <      *privs_ptr++ = ToLowerTab[flag_list[i].c];
1413 >      *privs_ptr++ = ToLower(opriv->c);
1414    }
1415  
1416    *privs_ptr = '\0';
# Line 2205 | Line 1435 | get_oper_name(const struct Client *clien
1435    {
1436      if ((cnode = client_p->localClient->confs.head))
1437      {
1438 <      struct ConfItem *conf = cnode->data;
2209 <      const struct AccessItem *aconf = map_to_conf(conf);
1438 >      struct MaskItem *conf = cnode->data;
1439  
1440 <      if (IsConfOperator(aconf))
1440 >      if (IsConfOperator(conf))
1441        {
1442 <        snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1442 >        snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1443                   client_p->username, client_p->host, conf->name);
1444 <        return buffer;
1444 >        return buffer;
1445        }
1446      }
1447  
# Line 2223 | Line 1452 | get_oper_name(const struct Client *clien
1452    }
1453  
1454    snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1455 <           client_p->username, client_p->host, client_p->servptr->name);
1455 >           client_p->username, client_p->host, client_p->servptr->name);
1456    return buffer;
1457   }
1458  
# Line 2241 | Line 1470 | read_conf_files(int cold)
1470    char chanlimit[32];
1471  
1472    conf_parser_ctx.boot = cold;
1473 <  filename = get_conf_name(CONF_TYPE);
1473 >  filename = ConfigFileEntry.configfile;
1474  
1475    /* We need to know the initial filename for the yyerror() to report
1476       FIXME: The full path is in conffilenamebuf first time since we
# Line 2261 | Line 1490 | read_conf_files(int cold)
1490      }
1491      else
1492      {
1493 <      sendto_realops_flags(UMODE_ALL, L_ALL,
1494 <                           "Unable to read configuration file '%s': %s",
1495 <                           filename, strerror(errno));
1493 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1494 >                           "Unable to read configuration file '%s': %s",
1495 >                           filename, strerror(errno));
1496        return;
1497      }
1498    }
# Line 2274 | Line 1503 | read_conf_files(int cold)
1503    read_conf(conf_parser_ctx.conf_file);
1504    fclose(conf_parser_ctx.conf_file);
1505  
1506 +  log_reopen_all();
1507 +
1508 +  add_isupport("NICKLEN", NULL, ServerInfo.max_nick_length);
1509    add_isupport("NETWORK", ServerInfo.network_name, -1);
1510 <  snprintf(chanmodes, sizeof(chanmodes), "beI:%d",
1511 <           ConfigChannel.max_bans);
1510 >
1511 >  snprintf(chanmodes, sizeof(chanmodes), "beI:%d", ConfigChannel.max_bans);
1512    add_isupport("MAXLIST", chanmodes, -1);
1513    add_isupport("MAXTARGETS", NULL, ConfigFileEntry.max_targets);
2282 –
1514    add_isupport("CHANTYPES", "#", -1);
1515  
1516    snprintf(chanlimit, sizeof(chanlimit), "#:%d",
1517 <           ConfigChannel.max_chans_per_user);
1517 >           ConfigChannel.max_chans_per_user);
1518    add_isupport("CHANLIMIT", chanlimit, -1);
1519 <  snprintf(chanmodes, sizeof(chanmodes), "%s",
2289 <           "beI,k,l,imnprstORS");
1519 >  snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,imnprstORS");
1520    add_isupport("CHANNELLEN", NULL, LOCAL_CHANNELLEN);
1521 <
2292 <  add_isupport("EXCEPTS", "e", -1);
2293 <  add_isupport("INVEX", "I", -1);
1521 >  add_isupport("TOPICLEN", NULL, ServerInfo.max_topic_length);
1522    add_isupport("CHANMODES", chanmodes, -1);
1523  
1524    /*
# Line 2298 | Line 1526 | read_conf_files(int cold)
1526     * on strlen(form_str(RPL_ISUPPORT))
1527     */
1528    rebuild_isupport_message_line();
2301 –
2302 – #ifdef HAVE_LIBPCRE
2303 –  parse_conf_file(RKLINE_TYPE, cold);
2304 –  parse_conf_file(RXLINE_TYPE, cold);
2305 – #endif
2306 –  parse_conf_file(KLINE_TYPE, cold);
2307 –  parse_conf_file(DLINE_TYPE, cold);
2308 –  parse_conf_file(XLINE_TYPE, cold);
2309 –  parse_conf_file(NRESV_TYPE, cold);
2310 –  parse_conf_file(CRESV_TYPE, cold);
2311 – }
2312 –
2313 – /* parse_conf_file()
2314 – *
2315 – * inputs       - type of conf file to parse
2316 – * output       - none
2317 – * side effects - conf file for givenconf type is opened and read then parsed
2318 – */
2319 – static void
2320 – parse_conf_file(int type, int cold)
2321 – {
2322 –  FILE *file = NULL;
2323 –  const char *filename = get_conf_name(type);
2324 –
2325 –  if ((file = fopen(filename, "r")) == NULL)
2326 –  {
2327 –    if (cold)
2328 –      ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
2329 –           filename, strerror(errno));
2330 –    else
2331 –      sendto_realops_flags(UMODE_ALL, L_ALL,
2332 –                    "Unable to read configuration file '%s': %s",
2333 –                           filename, strerror(errno));
2334 –  }
2335 –  else
2336 –  {
2337 –    parse_csv_file(file, type);
2338 –    fclose(file);
2339 –  }
1529   }
1530  
1531   /* clear_out_old_conf()
# Line 2349 | Line 1538 | static void
1538   clear_out_old_conf(void)
1539   {
1540    dlink_node *ptr = NULL, *next_ptr = NULL;
1541 <  struct ConfItem *conf;
2353 <  struct AccessItem *aconf;
2354 <  struct ClassItem *cltmp;
2355 <  struct MatchItem *match_item;
1541 >  struct MaskItem *conf;
1542    dlink_list *free_items [] = {
1543      &server_items,   &oconf_items,
1544 <     &uconf_items,   &xconf_items, &rxconf_items, &rkconf_items,
1545 <     &nresv_items, &cluster_items,  &service_items, NULL
1544 >     &uconf_items,   &xconf_items,
1545 >     &nresv_items, &cluster_items,  &service_items, &cresv_items, NULL
1546    };
1547  
1548    dlink_list ** iterator = free_items; /* C is dumb */
# Line 2370 | Line 1556 | clear_out_old_conf(void)
1556      DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head)
1557      {
1558        conf = ptr->data;
2373 –      /* XXX This is less than pretty */
2374 –      if (conf->type == SERVER_TYPE)
2375 –      {
2376 –        aconf = map_to_conf(conf);
1559  
1560 <        if (aconf->clients != 0)
2379 <        {
2380 <          SetConfIllegal(aconf);
2381 <          dlinkDelete(&conf->node, &server_items);
2382 <        }
2383 <        else
2384 <        {
2385 <          delete_conf_item(conf);
2386 <        }
2387 <      }
2388 <      else if (conf->type == OPER_TYPE)
2389 <      {
2390 <        aconf = map_to_conf(conf);
1560 >      dlinkDelete(&conf->node, map_to_list(conf->type));
1561  
1562 <        if (aconf->clients != 0)
1563 <        {
2394 <          SetConfIllegal(aconf);
2395 <          dlinkDelete(&conf->node, &oconf_items);
2396 <        }
2397 <        else
2398 <        {
2399 <          delete_conf_item(conf);
2400 <        }
2401 <      }
2402 <      else if (conf->type == XLINE_TYPE  ||
2403 <               conf->type == RXLINE_TYPE ||
2404 <               conf->type == RKLINE_TYPE)
1562 >      /* XXX This is less than pretty */
1563 >      if (conf->type == CONF_SERVER || conf->type == CONF_OPER)
1564        {
1565 <        /* temporary (r)xlines are also on
1566 <         * the (r)xconf items list */
2408 <        if (conf->flags & CONF_FLAGS_TEMPORARY)
2409 <          continue;
2410 <
2411 <        delete_conf_item(conf);
1565 >        if (!conf->ref_count)
1566 >          conf_free(conf);
1567        }
1568 <      else
1568 >      else if (conf->type == CONF_XLINE)
1569        {
1570 <          delete_conf_item(conf);
1570 >        if (!conf->until)
1571 >          conf_free(conf);
1572        }
1573 +      else
1574 +        conf_free(conf);
1575      }
1576    }
1577  
1578 +  motd_clear();
1579 +
1580    /*
1581     * don't delete the class table, rather mark all entries
1582 <   * for deletion. The table is cleaned up by check_class. - avalon
1582 >   * for deletion. The table is cleaned up by class_delete_marked. - avalon
1583     */
1584 <  DLINK_FOREACH(ptr, class_items.head)
2425 <  {
2426 <    cltmp = map_to_conf(ptr->data);
2427 <
2428 <    if (ptr != class_items.tail)  /* never mark the "default" class */
2429 <      cltmp->active = 0;
2430 <  }
1584 >  class_mark_for_deletion();
1585  
1586    clear_out_address_conf();
1587  
# Line 2463 | Line 1617 | clear_out_old_conf(void)
1617                                                 SSL_OP_NO_TLSv1);
1618   #endif
1619  
2466 –  /* clean out old resvs from the conf */
2467 –  clear_conf_resv();
2468 –
1620    /* clean out AdminInfo */
1621    MyFree(AdminInfo.name);
1622    AdminInfo.name = NULL;
# Line 2474 | Line 1625 | clear_out_old_conf(void)
1625    MyFree(AdminInfo.description);
1626    AdminInfo.description = NULL;
1627  
2477 –  /* operator{} and class{} blocks are freed above */
1628    /* clean out listeners */
1629    close_listeners();
1630  
2481 –  /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{},
2482 –   * exempt{} and gecos{} blocks are freed above too
2483 –   */
2484 –
1631    /* clean out general */
1632    MyFree(ConfigFileEntry.service_name);
1633    ConfigFileEntry.service_name = NULL;
2488 –
2489 –  delete_isupport("INVEX");
2490 –  delete_isupport("EXCEPTS");
2491 – }
2492 –
2493 – /* flush_deleted_I_P()
2494 – *
2495 – * inputs       - none
2496 – * output       - none
2497 – * side effects - This function removes I/P conf items
2498 – */
2499 – static void
2500 – flush_deleted_I_P(void)
2501 – {
2502 –  dlink_node *ptr;
2503 –  dlink_node *next_ptr;
2504 –  struct ConfItem *conf;
2505 –  struct AccessItem *aconf;
2506 –  dlink_list * free_items [] = {
2507 –    &server_items, &oconf_items, NULL
2508 –  };
2509 –  dlink_list ** iterator = free_items; /* C is dumb */
2510 –
2511 –  /* flush out deleted I and P lines
2512 –   * although still in use.
2513 –   */
2514 –  for (; *iterator != NULL; iterator++)
2515 –  {
2516 –    DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head)
2517 –    {
2518 –      conf = ptr->data;
2519 –      aconf = (struct AccessItem *)map_to_conf(conf);
2520 –
2521 –      if (IsConfIllegal(aconf))
2522 –      {
2523 –        dlinkDelete(ptr, *iterator);
2524 –
2525 –        if (aconf->clients == 0)
2526 –          delete_conf_item(conf);
2527 –      }
2528 –    }
2529 –  }
2530 – }
2531 –
2532 – /* get_conf_name()
2533 – *
2534 – * inputs       - type of conf file to return name of file for
2535 – * output       - pointer to filename for type of conf
2536 – * side effects - none
2537 – */
2538 – const char *
2539 – get_conf_name(ConfType type)
2540 – {
2541 –  switch (type)
2542 –  {
2543 –    case CONF_TYPE:
2544 –      return ConfigFileEntry.configfile;
2545 –      break;
2546 –    case KLINE_TYPE:
2547 –      return ConfigFileEntry.klinefile;
2548 –      break;
2549 –    case DLINE_TYPE:
2550 –      return ConfigFileEntry.dlinefile;
2551 –      break;
2552 –    case XLINE_TYPE:
2553 –      return ConfigFileEntry.xlinefile;
2554 –      break;
2555 –    case CRESV_TYPE:
2556 –      return ConfigFileEntry.cresvfile;
2557 –      break;
2558 –    case NRESV_TYPE:
2559 –      return ConfigFileEntry.nresvfile;
2560 –      break;
2561 –    default:
2562 –      return NULL;  /* This should NEVER HAPPEN since we call this function
2563 –                       only with the above values, this will cause us to core
2564 –                       at some point if this happens so we know where it was */
2565 –  }
2566 – }
2567 –
2568 – #define BAD_PING (-1)
2569 –
2570 – /* get_conf_ping()
2571 – *
2572 – * inputs       - pointer to struct AccessItem
2573 – *              - pointer to a variable that receives ping warning time
2574 – * output       - ping frequency
2575 – * side effects - NONE
2576 – */
2577 – static int
2578 – get_conf_ping(struct ConfItem *conf, int *pingwarn)
2579 – {
2580 –  struct ClassItem *aclass;
2581 –  struct AccessItem *aconf;
2582 –
2583 –  if (conf != NULL)
2584 –  {
2585 –    aconf = (struct AccessItem *)map_to_conf(conf);
2586 –    if (aconf->class_ptr != NULL)
2587 –    {
2588 –      aclass = (struct ClassItem *)map_to_conf(aconf->class_ptr);
2589 –      *pingwarn = aclass->ping_warning;
2590 –      return aclass->ping_freq;
2591 –    }
2592 –  }
2593 –
2594 –  return BAD_PING;
2595 – }
2596 –
2597 – /* get_client_class()
2598 – *
2599 – * inputs       - pointer to client struct
2600 – * output       - pointer to name of class
2601 – * side effects - NONE
2602 – */
2603 – const char *
2604 – get_client_class(struct Client *target_p)
2605 – {
2606 –  dlink_node *cnode = NULL;
2607 –  struct AccessItem *aconf = NULL;
2608 –
2609 –  assert(!IsMe(target_p));
2610 –
2611 –  if ((cnode = target_p->localClient->confs.head))
2612 –  {
2613 –    struct ConfItem *conf = cnode->data;
2614 –
2615 –    assert((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2616 –          (conf->type == OPER_TYPE));
2617 –
2618 –    aconf = map_to_conf(conf);
2619 –    if (aconf->class_ptr != NULL)
2620 –      return aconf->class_ptr->name;
2621 –  }
2622 –
2623 –  return "default";
2624 – }
2625 –
2626 – /* get_client_ping()
2627 – *
2628 – * inputs       - pointer to client struct
2629 – *              - pointer to a variable that receives ping warning time
2630 – * output       - ping frequency
2631 – * side effects - NONE
2632 – */
2633 – int
2634 – get_client_ping(struct Client *target_p, int *pingwarn)
2635 – {
2636 –  int ping = 0;
2637 –  dlink_node *cnode = NULL;
2638 –
2639 –  if ((cnode = target_p->localClient->confs.head))
2640 –  {
2641 –    struct ConfItem *conf = cnode->data;
2642 –
2643 –    assert((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2644 –          (conf->type == OPER_TYPE));
2645 –
2646 –    ping = get_conf_ping(conf, pingwarn);
2647 –    if (ping > 0)
2648 –      return ping;
2649 –  }
2650 –
2651 –  *pingwarn = 0;
2652 –  return DEFAULT_PINGFREQUENCY;
2653 – }
2654 –
2655 – /* find_class()
2656 – *
2657 – * inputs       - string name of class
2658 – * output       - corresponding Class pointer
2659 – * side effects - NONE
2660 – */
2661 – struct ConfItem *
2662 – find_class(const char *classname)
2663 – {
2664 –  struct ConfItem *conf;
2665 –
2666 –  if ((conf = find_exact_name_conf(CLASS_TYPE, NULL, classname, NULL, NULL)) != NULL)
2667 –    return conf;
2668 –
2669 –  return class_default;
2670 – }
2671 –
2672 – /* check_class()
2673 – *
2674 – * inputs       - NONE
2675 – * output       - NONE
2676 – * side effects -
2677 – */
2678 – void
2679 – check_class(void)
2680 – {
2681 –  dlink_node *ptr = NULL, *next_ptr = NULL;
2682 –
2683 –  DLINK_FOREACH_SAFE(ptr, next_ptr, class_items.head)
2684 –  {
2685 –    struct ClassItem *aclass = map_to_conf(ptr->data);
2686 –
2687 –    if (!aclass->active && !aclass->curr_user_count)
2688 –    {
2689 –      destroy_cidr_class(aclass);
2690 –      delete_conf_item(ptr->data);
2691 –    }
2692 –  }
2693 – }
2694 –
2695 – /* init_class()
2696 – *
2697 – * inputs       - NONE
2698 – * output       - NONE
2699 – * side effects -
2700 – */
2701 – void
2702 – init_class(void)
2703 – {
2704 –  struct ClassItem *aclass;
2705 –
2706 –  class_default = make_conf_item(CLASS_TYPE);
2707 –
2708 –  aclass = map_to_conf(class_default);
2709 –  aclass->active = 1;
2710 –  DupString(class_default->name, "default");
2711 –  aclass->con_freq  = DEFAULT_CONNECTFREQUENCY;
2712 –  aclass->ping_freq = DEFAULT_PINGFREQUENCY;
2713 –  aclass->max_total = MAXIMUM_LINKS_DEFAULT;
2714 –  aclass->max_sendq = DEFAULT_SENDQ;
2715 –  aclass->max_recvq = DEFAULT_RECVQ;
2716 –
2717 –  client_check_cb = register_callback("check_client", check_client);
2718 – }
2719 –
2720 – /* get_sendq()
2721 – *
2722 – * inputs       - pointer to client
2723 – * output       - sendq for this client as found from its class
2724 – * side effects - NONE
2725 – */
2726 – unsigned int
2727 – get_sendq(struct Client *client_p)
2728 – {
2729 –  unsigned int sendq = DEFAULT_SENDQ;
2730 –  dlink_node *cnode;
2731 –  struct ConfItem *class_conf;
2732 –  struct ClassItem *aclass;
2733 –  struct AccessItem *aconf;
2734 –
2735 –  assert(!IsMe(client_p));
2736 –
2737 –  if ((cnode = client_p->localClient->confs.head))
2738 –  {
2739 –    struct ConfItem *conf = cnode->data;
2740 –
2741 –    assert((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2742 –          (conf->type == OPER_TYPE));
2743 –
2744 –    aconf = map_to_conf(conf);
2745 –
2746 –    if ((class_conf = aconf->class_ptr) == NULL)
2747 –      return DEFAULT_SENDQ; /* TBV: shouldn't be possible at all */
2748 –
2749 –    aclass = map_to_conf(class_conf);
2750 –    sendq = aclass->max_sendq;
2751 –    return sendq;
2752 –  }
2753 –
2754 –  /* XXX return a default?
2755 –   * if here, then there wasn't an attached conf with a sendq
2756 –   * that is very bad -Dianora
2757 –   */
2758 –  return DEFAULT_SENDQ;
2759 – }
2760 –
2761 – unsigned int
2762 – get_recvq(struct Client *client_p)
2763 – {
2764 –  unsigned int recvq = DEFAULT_RECVQ;
2765 –  dlink_node *cnode;
2766 –  struct ConfItem *class_conf;
2767 –  struct ClassItem *aclass;
2768 –  struct AccessItem *aconf;
2769 –
2770 –  assert(!IsMe(client_p));
2771 –
2772 –  if ((cnode = client_p->localClient->confs.head))
2773 –  {
2774 –    struct ConfItem *conf = cnode->data;
2775 –
2776 –    assert((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2777 –          (conf->type == OPER_TYPE));
2778 –
2779 –    aconf = map_to_conf(conf);
2780 –
2781 –    if ((class_conf = aconf->class_ptr) == NULL)
2782 –      return DEFAULT_RECVQ; /* TBV: shouldn't be possible at all */
2783 –
2784 –    aclass = map_to_conf(class_conf);
2785 –    recvq = aclass->max_recvq;
2786 –    return recvq;
2787 –  }
2788 –
2789 –  /* XXX return a default?
2790 –   * if here, then there wasn't an attached conf with a recvq
2791 –   * that is very bad -Dianora
2792 –   */
2793 –  return DEFAULT_RECVQ;
1634   }
1635  
1636   /* conf_add_class_to_conf()
# Line 2800 | Line 1640 | get_recvq(struct Client *client_p)
1640   * side effects - Add a class pointer to a conf
1641   */
1642   void
1643 < conf_add_class_to_conf(struct ConfItem *conf, const char *class_name)
1643 > conf_add_class_to_conf(struct MaskItem *conf, const char *class_name)
1644   {
2805 –  struct AccessItem *aconf = map_to_conf(conf);
2806 –  struct ClassItem *class = NULL;
2807 –
1645    if (class_name == NULL)
1646    {
1647 <    aconf->class_ptr = class_default;
1647 >    conf->class = class_default;
1648  
1649 <    if (conf->type == CLIENT_TYPE)
1650 <      sendto_realops_flags(UMODE_ALL, L_ALL,
1651 <                           "Warning *** Defaulting to default class for %s@%s",
1652 <                           aconf->user, aconf->host);
1649 >    if (conf->type == CONF_CLIENT)
1650 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1651 >                           "Warning *** Defaulting to default class for %s@%s",
1652 >                           conf->user, conf->host);
1653      else
1654 <      sendto_realops_flags(UMODE_ALL, L_ALL,
1655 <                           "Warning *** Defaulting to default class for %s",
1656 <                           conf->name);
1654 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1655 >                           "Warning *** Defaulting to default class for %s",
1656 >                           conf->name);
1657    }
1658    else
1659 <    aconf->class_ptr = find_class(class_name);
1659 >    conf->class = class_find(class_name, 1);
1660  
1661 <  if (aconf->class_ptr)
2825 <    class = map_to_conf(aconf->class_ptr);
2826 <
2827 <  if (aconf->class_ptr == NULL || !class->active)
1661 >  if (conf->class == NULL)
1662    {
1663 <    if (conf->type == CLIENT_TYPE)
1664 <      sendto_realops_flags(UMODE_ALL, L_ALL,
1665 <                           "Warning *** Defaulting to default class for %s@%s",
1666 <                           aconf->user, aconf->host);
1663 >    if (conf->type == CONF_CLIENT)
1664 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1665 >                           "Warning *** Defaulting to default class for %s@%s",
1666 >                           conf->user, conf->host);
1667      else
1668 <      sendto_realops_flags(UMODE_ALL, L_ALL,
1669 <                           "Warning *** Defaulting to default class for %s",
1670 <                           conf->name);
1671 <    aconf->class_ptr = class_default;
1668 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1669 >                           "Warning *** Defaulting to default class for %s",
1670 >                           conf->name);
1671 >    conf->class = class_default;
1672    }
1673   }
1674  
2841 – /* conf_add_server()
2842 – *
2843 – * inputs       - pointer to config item
2844 – *              - pointer to link count already on this conf
2845 – * output       - NONE
2846 – * side effects - Add a connect block
2847 – */
2848 – int
2849 – conf_add_server(struct ConfItem *conf, const char *class_name)
2850 – {
2851 –  struct AccessItem *aconf = map_to_conf(conf);
2852 –
2853 –  conf_add_class_to_conf(conf, class_name);
2854 –
2855 –  if (!aconf->host || !conf->name)
2856 –  {
2857 –    sendto_realops_flags(UMODE_ALL, L_ALL, "Bad connect block");
2858 –    ilog(LOG_TYPE_IRCD, "Bad connect block");
2859 –    return -1;
2860 –  }
2861 –
2862 –  if (EmptyString(aconf->passwd))
2863 –  {
2864 –    sendto_realops_flags(UMODE_ALL, L_ALL, "Bad connect block, name %s",
2865 –                         conf->name);
2866 –    ilog(LOG_TYPE_IRCD, "Bad connect block, host %s", conf->name);
2867 –    return -1;
2868 –  }
2869 –
2870 –  lookup_confhost(conf);
2871 –
2872 –  return 0;
2873 – }
2874 –
1675   /* yyerror()
1676   *
1677   * inputs       - message from parser
# Line 2887 | Line 1687 | yyerror(const char *msg)
1687      return;
1688  
1689    strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1690 <  sendto_realops_flags(UMODE_ALL, L_ALL, "\"%s\", line %u: %s: %s",
1690 >  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1691 >                       "\"%s\", line %u: %s: %s",
1692 >                       conffilebuf, lineno + 1, msg, newlinebuf);
1693 >  ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1694 >       conffilebuf, lineno + 1, msg, newlinebuf);
1695 > }
1696 >
1697 > void
1698 > conf_error_report(const char *msg)
1699 > {
1700 >  char newlinebuf[IRCD_BUFSIZE];
1701 >
1702 >  strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1703 >  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1704 >                       "\"%s\", line %u: %s: %s",
1705                         conffilebuf, lineno + 1, msg, newlinebuf);
1706    ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1707         conffilebuf, lineno + 1, msg, newlinebuf);
# Line 2914 | Line 1728 | valid_tkline(const char *p, int minutes)
1728        return 0;
1729  
1730      result *= 10;
1731 <    result += ((*p) & 0xF);
1731 >    result += (*p & 0xF);
1732    }
1733  
1734    /*
# Line 2940 | Line 1754 | valid_tkline(const char *p, int minutes)
1754    return result;
1755   }
1756  
1757 + /* valid_wild_card_simple()
1758 + *
1759 + * inputs       - data to check for sufficient non-wildcard characters
1760 + * outputs      - 1 if valid, else 0
1761 + * side effects - none
1762 + */
1763 + int
1764 + valid_wild_card_simple(const char *data)
1765 + {
1766 +  const unsigned char *p = (const unsigned char *)data;
1767 +  unsigned char tmpch = '\0';
1768 +  int nonwild = 0;
1769 +
1770 +  while ((tmpch = *p++))
1771 +  {
1772 +    if (tmpch == '\\')
1773 +    {
1774 +      ++p;
1775 +      if (++nonwild >= ConfigFileEntry.min_nonwildcard_simple)
1776 +        return 1;
1777 +    }
1778 +    else if (!IsMWildChar(tmpch))
1779 +    {
1780 +      if (++nonwild >= ConfigFileEntry.min_nonwildcard_simple)
1781 +        return 1;
1782 +    }
1783 +  }
1784 +
1785 +  return 0;
1786 + }
1787 +
1788   /* valid_wild_card()
1789   *
1790   * input        - pointer to client
# Line 2951 | Line 1796 | valid_tkline(const char *p, int minutes)
1796   int
1797   valid_wild_card(struct Client *source_p, int warn, int count, ...)
1798   {
2954 –  char *p;
1799    char tmpch;
1800    int nonwild = 0;
1801    va_list args;
# Line 2972 | Line 1816 | valid_wild_card(struct Client *source_p,
1816  
1817    while (count--)
1818    {
1819 <    p = va_arg(args, char *);
1819 >    const char *p = va_arg(args, const char *);
1820      if (p == NULL)
1821        continue;
1822  
# Line 3028 | Line 1872 | valid_wild_card(struct Client *source_p,
1872   */
1873   int
1874   parse_aline(const char *cmd, struct Client *source_p,
1875 <            int parc, char **parv,
1876 <            int parse_flags, char **up_p, char **h_p, time_t *tkline_time,
1877 <            char **target_server, char **reason)
1875 >            int parc, char **parv,
1876 >            int parse_flags, char **up_p, char **h_p, time_t *tkline_time,
1877 >            char **target_server, char **reason)
1878   {
1879    int found_tkline_time=0;
1880    static char def_reason[] = "No Reason";
# Line 3052 | Line 1896 | parse_aline(const char *cmd, struct Clie
1896      else
1897      {
1898        sendto_one(source_p, ":%s NOTICE %s :temp_line not supported by %s",
1899 <                 me.name, source_p->name, cmd);
1899 >                 me.name, source_p->name, cmd);
1900        return -1;
1901      }
1902    }
# Line 3087 | Line 1931 | parse_aline(const char *cmd, struct Clie
1931  
1932        if (target_server == NULL)
1933        {
1934 <        sendto_one(source_p, ":%s NOTICE %s :ON server not supported by %s",
1935 <                   me.name, source_p->name, cmd);
1936 <        return -1;
1934 >        sendto_one(source_p, ":%s NOTICE %s :ON server not supported by %s",
1935 >                   me.name, source_p->name, cmd);
1936 >        return -1;
1937        }
1938  
1939        if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN))
# Line 3101 | Line 1945 | parse_aline(const char *cmd, struct Clie
1945  
1946        if (parc == 0 || EmptyString(*parv))
1947        {
1948 <        sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1949 <                   me.name, source_p->name, cmd);
1950 <        return -1;
1948 >        sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1949 >                   me.name, source_p->name, cmd);
1950 >        return -1;
1951        }
1952  
1953        *target_server = *parv;
# Line 3116 | Line 1960 | parse_aline(const char *cmd, struct Clie
1960         * caller probably NULL'd it first, but no harm to do it again -db
1961         */
1962        if (target_server != NULL)
1963 <        *target_server = NULL;
1963 >        *target_server = NULL;
1964      }
1965    }
1966  
# Line 3142 | Line 1986 | parse_aline(const char *cmd, struct Clie
1986      {
1987        *reason = *parv;
1988        if (!valid_comment(source_p, *reason, 1))
1989 <        return -1;
1989 >        return -1;
1990      }
1991      else
1992        *reason = def_reason;
# Line 3181 | Line 2025 | find_user_host(struct Client *source_p,
2025      {
2026        *(hostp++) = '\0';                       /* short and squat */
2027        if (*user_host_or_nick)
2028 <        strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
2028 >        strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
2029        else
2030 <        strcpy(luser, "*");
2030 >        strcpy(luser, "*");
2031 >
2032        if (*hostp)
2033 <        strlcpy(lhost, hostp, HOSTLEN + 1);    /* here is my host */
2033 >        strlcpy(lhost, hostp, HOSTLEN + 1);    /* here is my host */
2034        else
2035 <        strcpy(lhost, "*");
2035 >        strcpy(lhost, "*");
2036      }
2037      else
2038      {
2039        luser[0] = '*';             /* no @ found, assume its *@somehost */
2040 <      luser[1] = '\0';    
2040 >      luser[1] = '\0';
2041        strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
2042      }
2043      
# Line 3209 | Line 2054 | find_user_host(struct Client *source_p,
2054      if (IsExemptKline(target_p))
2055      {
2056        if (!IsServer(source_p))
2057 <        sendto_one(source_p,
2058 <                   ":%s NOTICE %s :%s is E-lined",
2059 <                   me.name, source_p->name, target_p->name);
2057 >        sendto_one(source_p,
2058 >                   ":%s NOTICE %s :%s is E-lined",
2059 >                   me.name, source_p->name, target_p->name);
2060        return 0;
2061      }
2062  
# Line 3246 | Line 2091 | find_user_host(struct Client *source_p,
2091   int
2092   valid_comment(struct Client *source_p, char *comment, int warn)
2093   {
3249 –  if (strchr(comment, '"'))
3250 –  {
3251 –    if (warn)
3252 –      sendto_one(source_p, ":%s NOTICE %s :Invalid character '\"' in comment",
3253 –                 me.name, source_p->name);
3254 –    return 0;
3255 –  }
3256 –
2094    if (strlen(comment) > REASONLEN)
2095      comment[REASONLEN-1] = '\0';
2096  
# Line 3268 | Line 2105 | valid_comment(struct Client *source_p, c
2105   * side effects - none
2106   */
2107   int
2108 < match_conf_password(const char *password, const struct AccessItem *aconf)
2108 > match_conf_password(const char *password, const struct MaskItem *conf)
2109   {
2110    const char *encr = NULL;
2111  
2112 <  if (EmptyString(password) || EmptyString(aconf->passwd))
2112 >  if (EmptyString(password) || EmptyString(conf->passwd))
2113      return 0;
2114  
2115 <  if (aconf->flags & CONF_FLAGS_ENCRYPTED)
2116 <    encr = crypt(password, aconf->passwd);
2115 >  if (conf->flags & CONF_FLAGS_ENCRYPTED)
2116 >    encr = crypt(password, conf->passwd);
2117    else
2118      encr = password;
2119  
2120 <  return !strcmp(encr, aconf->passwd);
2120 >  return !strcmp(encr, conf->passwd);
2121   }
2122  
2123   /*
# Line 3309 | Line 2146 | cluster_a_line(struct Client *source_p,
2146  
2147    DLINK_FOREACH(ptr, cluster_items.head)
2148    {
2149 <    const struct ConfItem *conf = ptr->data;
2149 >    const struct MaskItem *conf = ptr->data;
2150  
2151      if (conf->flags & cluster_type)
2152        sendto_match_servs(source_p, conf->name, CAP_CLUSTER|capab,
2153 <                         "%s %s %s", command, conf->name, buffer);
2153 >                         "%s %s %s", command, conf->name, buffer);
2154    }
2155   }
2156  
# Line 3403 | Line 2240 | split_nuh(struct split_nuh_item *const i
2240      }
2241    }
2242   }
3406 –
3407 – /*
3408 – * flags_to_ascii
3409 – *
3410 – * inputs       - flags is a bitmask
3411 – *              - pointer to table of ascii letters corresponding
3412 – *                to each bit
3413 – *              - flag 1 for convert ToLower if bit missing
3414 – *                0 if ignore.
3415 – * output       - none
3416 – * side effects - string pointed to by p has bitmap chars written to it
3417 – */
3418 – static void
3419 – flags_to_ascii(unsigned int flags, const unsigned int bit_table[], char *p,
3420 –               int lowerit)
3421 – {
3422 –  unsigned int mask = 1;
3423 –  int i = 0;
3424 –
3425 –  for (mask = 1; (mask != 0) && (bit_table[i] != 0); mask <<= 1, i++)
3426 –  {
3427 –    if (flags & mask)
3428 –      *p++ = bit_table[i];
3429 –    else if (lowerit)
3430 –      *p++ = ToLower(bit_table[i]);
3431 –  }
3432 –  *p = '\0';
3433 – }
3434 –
3435 – /*
3436 – * cidr_limit_reached
3437 – *
3438 – * inputs       - int flag allowing over_rule of limits
3439 – *              - pointer to the ip to be added
3440 – *              - pointer to the class
3441 – * output       - non zero if limit reached
3442 – *                0 if limit not reached
3443 – * side effects -
3444 – */
3445 – static int
3446 – cidr_limit_reached(int over_rule,
3447 –                   struct irc_ssaddr *ip, struct ClassItem *aclass)
3448 – {
3449 –  dlink_node *ptr = NULL;
3450 –  struct CidrItem *cidr;
3451 –
3452 –  if (aclass->number_per_cidr <= 0)
3453 –    return 0;
3454 –
3455 –  if (ip->ss.ss_family == AF_INET)
3456 –  {
3457 –    if (aclass->cidr_bitlen_ipv4 <= 0)
3458 –      return 0;
3459 –
3460 –    DLINK_FOREACH(ptr, aclass->list_ipv4.head)
3461 –    {
3462 –      cidr = ptr->data;
3463 –      if (match_ipv4(ip, &cidr->mask, aclass->cidr_bitlen_ipv4))
3464 –      {
3465 –        if (!over_rule && (cidr->number_on_this_cidr >= aclass->number_per_cidr))
3466 –          return -1;
3467 –        cidr->number_on_this_cidr++;
3468 –        return 0;
3469 –      }
3470 –    }
3471 –    cidr = MyMalloc(sizeof(struct CidrItem));
3472 –    cidr->number_on_this_cidr = 1;
3473 –    cidr->mask = *ip;
3474 –    mask_addr(&cidr->mask, aclass->cidr_bitlen_ipv4);
3475 –    dlinkAdd(cidr, &cidr->node, &aclass->list_ipv4);
3476 –  }
3477 – #ifdef IPV6
3478 –  else if (aclass->cidr_bitlen_ipv6 > 0)
3479 –  {
3480 –    DLINK_FOREACH(ptr, aclass->list_ipv6.head)
3481 –    {
3482 –      cidr = ptr->data;
3483 –      if (match_ipv6(ip, &cidr->mask, aclass->cidr_bitlen_ipv6))
3484 –      {
3485 –        if (!over_rule && (cidr->number_on_this_cidr >= aclass->number_per_cidr))
3486 –          return -1;
3487 –        cidr->number_on_this_cidr++;
3488 –        return 0;
3489 –      }
3490 –    }
3491 –    cidr = MyMalloc(sizeof(struct CidrItem));
3492 –    cidr->number_on_this_cidr = 1;
3493 –    cidr->mask = *ip;
3494 –    mask_addr(&cidr->mask, aclass->cidr_bitlen_ipv6);
3495 –    dlinkAdd(cidr, &cidr->node, &aclass->list_ipv6);
3496 –  }
3497 – #endif
3498 –  return 0;
3499 – }
3500 –
3501 – /*
3502 – * remove_from_cidr_check
3503 – *
3504 – * inputs       - pointer to the ip to be removed
3505 – *              - pointer to the class
3506 – * output       - NONE
3507 – * side effects -
3508 – */
3509 – static void
3510 – remove_from_cidr_check(struct irc_ssaddr *ip, struct ClassItem *aclass)
3511 – {
3512 –  dlink_node *ptr = NULL;
3513 –  dlink_node *next_ptr = NULL;
3514 –  struct CidrItem *cidr;
3515 –
3516 –  if (aclass->number_per_cidr == 0)
3517 –    return;
3518 –
3519 –  if (ip->ss.ss_family == AF_INET)
3520 –  {
3521 –    if (aclass->cidr_bitlen_ipv4 <= 0)
3522 –      return;
3523 –
3524 –    DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv4.head)
3525 –    {
3526 –      cidr = ptr->data;
3527 –      if (match_ipv4(ip, &cidr->mask, aclass->cidr_bitlen_ipv4))
3528 –      {
3529 –        cidr->number_on_this_cidr--;
3530 –        if (cidr->number_on_this_cidr == 0)
3531 –        {
3532 –          dlinkDelete(ptr, &aclass->list_ipv4);
3533 –          MyFree(cidr);
3534 –          return;
3535 –        }
3536 –      }
3537 –    }
3538 –  }
3539 – #ifdef IPV6
3540 –  else if (aclass->cidr_bitlen_ipv6 > 0)
3541 –  {
3542 –    DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv6.head)
3543 –    {
3544 –      cidr = ptr->data;
3545 –      if (match_ipv6(ip, &cidr->mask, aclass->cidr_bitlen_ipv6))
3546 –      {
3547 –        cidr->number_on_this_cidr--;
3548 –        if (cidr->number_on_this_cidr == 0)
3549 –        {
3550 –          dlinkDelete(ptr, &aclass->list_ipv6);
3551 –          MyFree(cidr);
3552 –          return;
3553 –        }
3554 –      }
3555 –    }
3556 –  }
3557 – #endif
3558 – }
3559 –
3560 – static void
3561 – rebuild_cidr_list(int aftype, struct ConfItem *oldcl, struct ClassItem *newcl,
3562 –                  dlink_list *old_list, dlink_list *new_list, int changed)
3563 – {
3564 –  dlink_node *ptr;
3565 –  struct Client *client_p;
3566 –  struct ConfItem *conf;
3567 –  struct AccessItem *aconf;
3568 –
3569 –  if (!changed)
3570 –  {
3571 –    *new_list = *old_list;
3572 –    old_list->head = old_list->tail = NULL;
3573 –    old_list->length = 0;
3574 –    return;
3575 –  }
3576 –
3577 –  DLINK_FOREACH(ptr, local_client_list.head)
3578 –  {
3579 –    client_p = ptr->data;
3580 –    if (client_p->localClient->aftype != aftype)
3581 –      continue;
3582 –    if (dlink_list_length(&client_p->localClient->confs) == 0)
3583 –      continue;
3584 –
3585 –    conf = client_p->localClient->confs.tail->data;
3586 –    if (conf->type == CLIENT_TYPE)
3587 –    {
3588 –      aconf = map_to_conf(conf);
3589 –      if (aconf->class_ptr == oldcl)
3590 –        cidr_limit_reached(1, &client_p->localClient->ip, newcl);
3591 –    }
3592 –  }
3593 – }
3594 –
3595 – /*
3596 – * rebuild_cidr_class
3597 – *
3598 – * inputs       - pointer to old conf
3599 – *              - pointer to new_class
3600 – * output       - none
3601 – * side effects - rebuilds the class link list of cidr blocks
3602 – */
3603 – void
3604 – rebuild_cidr_class(struct ConfItem *conf, struct ClassItem *new_class)
3605 – {
3606 –  struct ClassItem *old_class = map_to_conf(conf);
3607 –
3608 –  if (old_class->number_per_cidr > 0 && new_class->number_per_cidr > 0)
3609 –  {
3610 –    if (old_class->cidr_bitlen_ipv4 > 0 && new_class->cidr_bitlen_ipv4 > 0)
3611 –      rebuild_cidr_list(AF_INET, conf, new_class,
3612 –                        &old_class->list_ipv4, &new_class->list_ipv4,
3613 –                        old_class->cidr_bitlen_ipv4 != new_class->cidr_bitlen_ipv4);
3614 –
3615 – #ifdef IPV6
3616 –    if (old_class->cidr_bitlen_ipv6 > 0 && new_class->cidr_bitlen_ipv6 > 0)
3617 –      rebuild_cidr_list(AF_INET6, conf, new_class,
3618 –                        &old_class->list_ipv6, &new_class->list_ipv6,
3619 –                        old_class->cidr_bitlen_ipv6 != new_class->cidr_bitlen_ipv6);
3620 – #endif
3621 –  }
3622 –
3623 –  destroy_cidr_class(old_class);
3624 – }
3625 –
3626 – /*
3627 – * destroy_cidr_list
3628 – *
3629 – * inputs       - pointer to class dlink list of cidr blocks
3630 – * output       - none
3631 – * side effects - completely destroys the class link list of cidr blocks
3632 – */
3633 – static void
3634 – destroy_cidr_list(dlink_list *list)
3635 – {
3636 –  dlink_node *ptr = NULL, *next_ptr = NULL;
3637 –
3638 –  DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
3639 –  {
3640 –    dlinkDelete(ptr, list);
3641 –    MyFree(ptr->data);
3642 –  }
3643 – }
3644 –
3645 – /*
3646 – * destroy_cidr_class
3647 – *
3648 – * inputs       - pointer to class
3649 – * output       - none
3650 – * side effects - completely destroys the class link list of cidr blocks
3651 – */
3652 – static void
3653 – destroy_cidr_class(struct ClassItem *aclass)
3654 – {
3655 –  destroy_cidr_list(&aclass->list_ipv4);
3656 –  destroy_cidr_list(&aclass->list_ipv6);
3657 – }

Diff Legend

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