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 1495 by michael, Sun Aug 5 09:35:42 2012 UTC vs.
ircd-hybrid/trunk/src/conf.c (file contents), Revision 3347 by michael, Sun Apr 20 14:03:06 2014 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  conf.c: Configuration file functions.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-2014 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 18 | Line 17
17   *  along with this program; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file conf.c
23 > * \brief Configuration file functions.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
28   #include "list.h"
29   #include "ircd_defs.h"
28 – #include "balloc.h"
30   #include "conf.h"
31 < #include "s_serv.h"
31 > #include "server.h"
32   #include "resv.h"
33   #include "channel.h"
34   #include "client.h"
35   #include "event.h"
35 – #include "hook.h"
36   #include "irc_string.h"
37   #include "s_bsd.h"
38   #include "ircd.h"
# Line 43 | Line 43
43   #include "fdlist.h"
44   #include "log.h"
45   #include "send.h"
46 – #include "s_gline.h"
46   #include "memory.h"
47 < #include "irc_res.h"
47 > #include "mempool.h"
48 > #include "res.h"
49   #include "userhost.h"
50 < #include "s_user.h"
50 > #include "user.h"
51   #include "channel_mode.h"
52   #include "parse.h"
53 < #include "s_misc.h"
53 > #include "misc.h"
54 > #include "conf_db.h"
55 > #include "conf_class.h"
56 > #include "motd.h"
57  
58 < struct Callback *client_check_cb = NULL;
58 >
59 > struct config_channel_entry ConfigChannel;
60   struct config_server_hide ConfigServerHide;
61 + struct config_file_entry ConfigFileEntry;
62 + struct logging_entry ConfigLoggingEntry = { .use_logging = 1 };
63 + struct server_info ServerInfo;
64 + struct admin_info AdminInfo;
65  
66   /* general conf items link list root, other than k lines etc. */
67   dlink_list service_items = { NULL, NULL, 0 };
# Line 62 | Line 70 | dlink_list cluster_items = { NULL, NULL,
70   dlink_list oconf_items   = { NULL, NULL, 0 };
71   dlink_list uconf_items   = { NULL, NULL, 0 };
72   dlink_list xconf_items   = { NULL, NULL, 0 };
65 – dlink_list rxconf_items  = { NULL, NULL, 0 };
66 – dlink_list rkconf_items  = { NULL, NULL, 0 };
73   dlink_list nresv_items   = { NULL, NULL, 0 };
74 < dlink_list class_items   = { NULL, NULL, 0 };
69 <
70 < dlink_list temporary_xlines  = { NULL, NULL, 0 };
71 < dlink_list temporary_resv = { NULL, NULL, 0 };
74 > dlink_list cresv_items = { NULL, NULL, 0 };
75  
76   extern unsigned int lineno;
77   extern char linebuf[];
# Line 80 | Line 83 | struct conf_parser_context conf_parser_c
83   /* internally defined functions */
84   static void read_conf(FILE *);
85   static void clear_out_old_conf(void);
83 – static void flush_deleted_I_P(void);
86   static void expire_tklines(dlink_list *);
87   static void garbage_collect_ip_entries(void);
88   static int hash_ip(struct irc_ssaddr *);
89 < static int verify_access(struct Client *, const char *);
90 < static int attach_iline(struct Client *, struct ConfItem *);
89 > static int verify_access(struct Client *);
90 > static int attach_iline(struct Client *, struct MaskItem *);
91   static struct ip_entry *find_or_add_ip(struct irc_ssaddr *);
92 < static void parse_conf_file(int, int);
91 < static dlink_list *map_to_list(ConfType);
92 < static struct AccessItem *find_regexp_kline(const char *[]);
92 > static dlink_list *map_to_list(enum maskitem_type);
93   static int find_user_host(struct Client *, char *, char *, char *, unsigned int);
94  
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;
95  
96   /* usually, with hash tables, you use a prime number...
97   * but in this case I am dealing with ip addresses,
# Line 113 | Line 102 | static struct ConfItem *class_default;
102   struct ip_entry
103   {
104    struct irc_ssaddr ip;
105 <  int count;
105 >  unsigned int count;
106    time_t last_attempt;
107    struct ip_entry *next;
108   };
109  
110   static struct ip_entry *ip_hash_table[IP_HASH_SIZE];
111 < static BlockHeap *ip_entry_heap = NULL;
111 > static mp_pool_t *ip_entry_pool = NULL;
112   static int ip_entries_count = 0;
113  
114  
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 –
115   /* conf_dns_callback()
116   *
117 < * inputs       - pointer to struct AccessItem
117 > * inputs       - pointer to struct MaskItem
118   *              - pointer to DNSReply reply
119   * output       - none
120   * side effects - called when resolver query finishes
# Line 155 | Line 125 | unmap_conf_item(void *aconf)
125   static void
126   conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name)
127   {
128 <  struct AccessItem *aconf = vptr;
128 >  struct MaskItem *conf = vptr;
129  
130 <  aconf->dns_pending = 0;
130 >  conf->dns_pending = 0;
131  
132 <  if (addr != NULL)
133 <    memcpy(&aconf->addr, addr, sizeof(aconf->addr));
132 >  if (addr)
133 >    memcpy(&conf->addr, addr, sizeof(conf->addr));
134    else
135 <    aconf->dns_failed = 1;
135 >    conf->dns_failed = 1;
136   }
137  
138   /* conf_dns_lookup()
# Line 172 | Line 142 | conf_dns_callback(void *vptr, const stru
142   * allocate a dns_query and start ns lookup.
143   */
144   static void
145 < conf_dns_lookup(struct AccessItem *aconf)
145 > conf_dns_lookup(struct MaskItem *conf)
146   {
147 <  if (!aconf->dns_pending)
147 >  if (!conf->dns_pending)
148    {
149 <    aconf->dns_pending = 1;
150 <    gethost_byname(conf_dns_callback, aconf, aconf->host);
149 >    conf->dns_pending = 1;
150 >    gethost_byname(conf_dns_callback, conf, conf->host);
151    }
152   }
153  
154 < /* make_conf_item()
155 < *
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)
154 > struct MaskItem *
155 > conf_make(enum maskitem_type type)
156   {
157 <  struct ConfItem *conf = NULL;
158 <  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;
157 >  struct MaskItem *conf = MyMalloc(sizeof(*conf));
158 >  dlink_list *list = NULL;
159  
160 <    case GLINE_TYPE:
161 <      status = CONF_GLINE;
162 <      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 <
311 <    break;
312 <
313 <  default:
314 <    conf = NULL;
315 <    break;
316 <  }
317 <
318 <  /* XXX Yes, this will core if default is hit. I want it to for now - db */
319 <  conf->type = type;
160 >  conf->type   = type;
161 >  conf->active = 1;
162 >  conf->aftype = AF_INET;
163  
164 +  if ((list = map_to_list(type)))
165 +    dlinkAdd(conf, &conf->node, list);
166    return conf;
167   }
168  
169   void
170 < delete_conf_item(struct ConfItem *conf)
170 > conf_free(struct MaskItem *conf)
171   {
172 <  dlink_node *m = NULL, *m_next = NULL;
173 <  struct MatchItem *match_item;
174 <  struct AccessItem *aconf;
175 <  ConfType type = conf->type;
172 >  dlink_node *ptr = NULL, *ptr_next = NULL;
173 >  dlink_list *list = NULL;
174 >
175 >  if (conf->node.next)
176 >    if ((list = map_to_list(conf->type)))
177 >      dlinkDelete(&conf->node, list);
178  
179    MyFree(conf->name);
333 –  conf->name = NULL;
180  
181 <  switch(type)
182 <  {
183 <  case DLINE_TYPE:
184 <  case EXEMPTDLINE_TYPE:
185 <  case GLINE_TYPE:
186 <  case KLINE_TYPE:
187 <  case CLIENT_TYPE:
188 <  case OPER_TYPE:
189 <  case SERVER_TYPE:
190 <    aconf = map_to_conf(conf);
191 <
192 <    if (aconf->dns_pending)
193 <      delete_resolver_queries(aconf);
194 <    if (aconf->passwd != NULL)
195 <      memset(aconf->passwd, 0, strlen(aconf->passwd));
350 <    if (aconf->spasswd != NULL)
351 <      memset(aconf->spasswd, 0, strlen(aconf->spasswd));
352 <    aconf->class_ptr = NULL;
353 <
354 <    MyFree(aconf->passwd);
355 <    MyFree(aconf->spasswd);
356 <    MyFree(aconf->reason);
357 <    MyFree(aconf->oper_reason);
358 <    MyFree(aconf->user);
359 <    MyFree(aconf->host);
181 >  if (conf->dns_pending)
182 >    delete_resolver_queries(conf);
183 >  if (conf->passwd)
184 >    memset(conf->passwd, 0, strlen(conf->passwd));
185 >  if (conf->spasswd)
186 >    memset(conf->spasswd, 0, strlen(conf->spasswd));
187 >
188 >  conf->class = NULL;
189 >
190 >  MyFree(conf->passwd);
191 >  MyFree(conf->spasswd);
192 >  MyFree(conf->reason);
193 >  MyFree(conf->certfp);
194 >  MyFree(conf->user);
195 >  MyFree(conf->host);
196   #ifdef HAVE_LIBCRYPTO
197 <    MyFree(aconf->cipher_list);
362 <
363 <    if (aconf->rsa_public_key)
364 <      RSA_free(aconf->rsa_public_key);
365 <    MyFree(aconf->rsa_public_key_file);
366 < #endif
367 <
368 <    /* Yes, sigh. switch on type again */
369 <    switch(type)
370 <    {
371 <    case EXEMPTDLINE_TYPE:
372 <    case DLINE_TYPE:
373 <    case GLINE_TYPE:
374 <    case KLINE_TYPE:
375 <    case CLIENT_TYPE:
376 <      MyFree(conf);
377 <      break;
378 <
379 <    case OPER_TYPE:
380 <      aconf = map_to_conf(conf);
381 <      if (!IsConfIllegal(aconf))
382 <        dlinkDelete(&conf->node, &oconf_items);
383 <      MyFree(conf);
384 <      break;
385 <
386 <    case SERVER_TYPE:
387 <      aconf = map_to_conf(conf);
388 <
389 <      DLINK_FOREACH_SAFE(m, m_next, aconf->hub_list.head)
390 <      {
391 <        MyFree(m->data);
392 <        free_dlink_node(m);
393 <      }
394 <
395 <      DLINK_FOREACH_SAFE(m, m_next, aconf->leaf_list.head)
396 <      {
397 <        MyFree(m->data);
398 <        free_dlink_node(m);  
399 <      }
400 <
401 <      if (!IsConfIllegal(aconf))
402 <        dlinkDelete(&conf->node, &server_items);
403 <      MyFree(conf);
404 <      break;
405 <
406 <    default:
407 <      break;
408 <    }
409 <    break;
410 <
411 <  case ULINE_TYPE:
412 <    match_item = map_to_conf(conf);
413 <    MyFree(match_item->user);
414 <    MyFree(match_item->host);
415 <    MyFree(match_item->reason);
416 <    MyFree(match_item->oper_reason);
417 <    dlinkDelete(&conf->node, &uconf_items);
418 <    MyFree(conf);
419 <    break;
420 <
421 <  case XLINE_TYPE:
422 <    match_item = map_to_conf(conf);
423 <    MyFree(match_item->user);
424 <    MyFree(match_item->host);
425 <    MyFree(match_item->reason);
426 <    MyFree(match_item->oper_reason);
427 <    dlinkDelete(&conf->node, &xconf_items);
428 <    MyFree(conf);
429 <    break;
430 < #ifdef HAVE_LIBPCRE
431 <  case RKLINE_TYPE:
432 <    aconf = map_to_conf(conf);
433 <    MyFree(aconf->regexuser);
434 <    MyFree(aconf->regexhost);
435 <    MyFree(aconf->user);
436 <    MyFree(aconf->host);
437 <    MyFree(aconf->reason);
438 <    MyFree(aconf->oper_reason);
439 <    dlinkDelete(&conf->node, &rkconf_items);
440 <    MyFree(conf);
441 <    break;
197 >  MyFree(conf->cipher_list);
198  
199 <  case RXLINE_TYPE:
200 <    MyFree(conf->regexpname);
445 <    match_item = map_to_conf(conf);
446 <    MyFree(match_item->user);
447 <    MyFree(match_item->host);
448 <    MyFree(match_item->reason);
449 <    MyFree(match_item->oper_reason);
450 <    dlinkDelete(&conf->node, &rxconf_items);
451 <    MyFree(conf);
452 <    break;
199 >  if (conf->rsa_public_key)
200 >    RSA_free(conf->rsa_public_key);
201   #endif
202 <  case NRESV_TYPE:
203 <    match_item = map_to_conf(conf);
204 <    MyFree(match_item->user);
205 <    MyFree(match_item->host);
206 <    MyFree(match_item->reason);
459 <    MyFree(match_item->oper_reason);
460 <    dlinkDelete(&conf->node, &nresv_items);
461 <
462 <    if (conf->flags & CONF_FLAGS_TEMPORARY)
463 <      if ((m = dlinkFindDelete(&temporary_resv, conf)) != NULL)
464 <        free_dlink_node(m);
465 <
466 <    MyFree(conf);
467 <    break;
468 <
469 <  case CLUSTER_TYPE:
470 <    dlinkDelete(&conf->node, &cluster_items);
471 <    MyFree(conf);
472 <    break;
473 <
474 <  case CRESV_TYPE:
475 <    if (conf->flags & CONF_FLAGS_TEMPORARY)
476 <      if ((m = dlinkFindDelete(&temporary_resv, conf)) != NULL)
477 <        free_dlink_node(m);
478 <
479 <    MyFree(conf);
480 <    break;
481 <
482 <  case CLASS_TYPE:
483 <    dlinkDelete(&conf->node, &class_items);
484 <    MyFree(conf);
485 <    break;
486 <
487 <  case SERVICE_TYPE:
488 <    dlinkDelete(&conf->node, &service_items);
489 <    MyFree(conf);
490 <    break;
491 <
492 <  default:
493 <    break;
202 >  DLINK_FOREACH_SAFE(ptr, ptr_next, conf->hub_list.head)
203 >  {
204 >    MyFree(ptr->data);
205 >    dlinkDelete(ptr, &conf->hub_list);
206 >    free_dlink_node(ptr);
207    }
495 – }
496 –
497 – /* free_access_item()
498 – *
499 – * inputs       - pointer to conf to free
500 – * output       - none
501 – * side effects - crucial password fields are zeroed, conf is freed
502 – */
503 – void
504 – free_access_item(struct AccessItem *aconf)
505 – {
506 –  struct ConfItem *conf;
507 –
508 –  if (aconf == NULL)
509 –    return;
510 –  conf = unmap_conf_item(aconf);
511 –  delete_conf_item(conf);
512 – }
513 –
514 – static const unsigned int shared_bit_table[] =
515 –  { 'K', 'k', 'U', 'X', 'x', 'Y', 'Q', 'q', 'R', 'L', 0};
516 –
517 – /* report_confitem_types()
518 – *
519 – * inputs       - pointer to client requesting confitem report
520 – *              - ConfType to report
521 – * output       - none
522 – * side effects -
523 – */
524 – void
525 – report_confitem_types(struct Client *source_p, ConfType type)
526 – {
527 –  dlink_node *ptr = NULL, *dptr = NULL;
528 –  struct ConfItem *conf = NULL;
529 –  struct AccessItem *aconf = NULL;
530 –  struct MatchItem *matchitem = NULL;
531 –  struct ClassItem *classitem = NULL;
532 –  char buf[12];
533 –  char *p = NULL;
208  
209 <  switch (type)
209 >  DLINK_FOREACH_SAFE(ptr, ptr_next, conf->leaf_list.head)
210    {
211 <  case XLINE_TYPE:
212 <    DLINK_FOREACH(ptr, xconf_items.head)
213 <    {
214 <      conf = ptr->data;
541 <      matchitem = map_to_conf(conf);
542 <
543 <      sendto_one(source_p, form_str(RPL_STATSXLINE),
544 <                 me.name, source_p->name,
545 <                 matchitem->hold ? "x": "X", matchitem->count,
546 <                 conf->name, matchitem->reason);
547 <    }
548 <    break;
549 <
550 < #ifdef HAVE_LIBPCRE
551 <  case RXLINE_TYPE:
552 <    DLINK_FOREACH(ptr, rxconf_items.head)
553 <    {
554 <      conf = ptr->data;
555 <      matchitem = map_to_conf(conf);
556 <
557 <      sendto_one(source_p, form_str(RPL_STATSXLINE),
558 <                 me.name, source_p->name,
559 <                 "XR", matchitem->count,
560 <                 conf->name, matchitem->reason);
561 <    }
562 <    break;
563 <
564 <  case RKLINE_TYPE:
565 <    DLINK_FOREACH(ptr, rkconf_items.head)
566 <    {
567 <      aconf = map_to_conf((conf = ptr->data));
568 <
569 <      sendto_one(source_p, form_str(RPL_STATSKLINE), me.name,
570 <                 source_p->name, "KR", aconf->host, aconf->user,
571 <                 aconf->reason, aconf->oper_reason ? aconf->oper_reason : "");
572 <    }
573 <    break;
574 < #endif
575 <
576 <  case ULINE_TYPE:
577 <    DLINK_FOREACH(ptr, uconf_items.head)
578 <    {
579 <      conf = ptr->data;
580 <      matchitem = map_to_conf(conf);
581 <
582 <      p = buf;
583 <
584 <      /* some of these are redundant for the sake of
585 <       * consistency with cluster{} flags
586 <       */
587 <      *p++ = 'c';
588 <      flags_to_ascii(matchitem->action, shared_bit_table, p, 0);
589 <
590 <      sendto_one(source_p, form_str(RPL_STATSULINE),
591 <                 me.name, source_p->name, conf->name,
592 <                 matchitem->user?matchitem->user: "*",
593 <                 matchitem->host?matchitem->host: "*", buf);
594 <    }
595 <
596 <    DLINK_FOREACH(ptr, cluster_items.head)
597 <    {
598 <      conf = ptr->data;
599 <
600 <      p = buf;
601 <
602 <      *p++ = 'C';
603 <      flags_to_ascii(conf->flags, shared_bit_table, p, 0);
604 <
605 <      sendto_one(source_p, form_str(RPL_STATSULINE),
606 <                 me.name, source_p->name, conf->name,
607 <                 "*", "*", buf);
608 <    }
609 <
610 <    break;
611 <
612 <  case OPER_TYPE:
613 <    DLINK_FOREACH(ptr, oconf_items.head)
614 <    {
615 <      conf = ptr->data;
616 <      aconf = map_to_conf(conf);
617 <
618 <      /* Don't allow non opers to see oper privs */
619 <      if (HasUMode(source_p, UMODE_OPER))
620 <        sendto_one(source_p, form_str(RPL_STATSOLINE),
621 <                   me.name, source_p->name, 'O', aconf->user, aconf->host,
622 <                   conf->name, oper_privs_as_string(aconf->port),
623 <                   aconf->class_ptr ? aconf->class_ptr->name : "<default>");
624 <      else
625 <        sendto_one(source_p, form_str(RPL_STATSOLINE),
626 <                   me.name, source_p->name, 'O', aconf->user, aconf->host,
627 <                   conf->name, "0",
628 <                   aconf->class_ptr ? aconf->class_ptr->name : "<default>");
629 <    }
630 <    break;
631 <
632 <  case CLASS_TYPE:
633 <    DLINK_FOREACH(ptr, class_items.head)
634 <    {
635 <      conf = ptr->data;
636 <      classitem = map_to_conf(conf);
637 <      sendto_one(source_p, form_str(RPL_STATSYLINE),
638 <                 me.name, source_p->name, 'Y',
639 <                 conf->name, classitem->ping_freq,
640 <                 classitem->con_freq,
641 <                 classitem->max_total, classitem->max_sendq,
642 <                 classitem->curr_user_count,
643 <                 classitem->number_per_cidr, classitem->cidr_bitlen_ipv4,
644 <                 classitem->number_per_cidr, classitem->cidr_bitlen_ipv6,
645 <                 classitem->active ? "active" : "disabled");
646 <    }
647 <    break;
648 <
649 <  case CONF_TYPE:
650 <  case CLIENT_TYPE:
651 <    break;
652 <
653 <  case SERVICE_TYPE:
654 <    DLINK_FOREACH(ptr, service_items.head)
655 <    {
656 <      conf = ptr->data;
657 <      sendto_one(source_p, form_str(RPL_STATSSERVICE),
658 <                 me.name, source_p->name, 'S', "*", conf->name, 0, 0);
659 <    }
660 <    break;
661 <
662 <  case SERVER_TYPE:
663 <    DLINK_FOREACH(ptr, server_items.head)
664 <    {
665 <      p = buf;
666 <
667 <      conf = ptr->data;
668 <      aconf = map_to_conf(conf);
669 <
670 <      buf[0] = '\0';
671 <
672 <      if (IsConfAllowAutoConn(aconf))
673 <        *p++ = 'A';
674 <      if (IsConfSSL(aconf))
675 <        *p++ = 'S';
676 <      if (IsConfTopicBurst(aconf))
677 <        *p++ = 'T';
678 <      if (buf[0] == '\0')
679 <        *p++ = '*';
680 <
681 <      *p = '\0';
682 <
683 <      /*
684 <       * Allow admins to see actual ips unless hide_server_ips is enabled
685 <       */
686 <      if (!ConfigServerHide.hide_server_ips && HasUMode(source_p, UMODE_ADMIN))
687 <        sendto_one(source_p, form_str(RPL_STATSCLINE),
688 <                   me.name, source_p->name, 'C', aconf->host,
689 <                   buf, conf->name, aconf->port,
690 <                   aconf->class_ptr ? aconf->class_ptr->name : "<default>");
691 <        else
692 <          sendto_one(source_p, form_str(RPL_STATSCLINE),
693 <                     me.name, source_p->name, 'C',
694 <                     "*@127.0.0.1", buf, conf->name, aconf->port,
695 <                     aconf->class_ptr ? aconf->class_ptr->name : "<default>");
696 <    }
697 <    break;
698 <
699 <  case HUB_TYPE:
700 <    DLINK_FOREACH(ptr, server_items.head)
701 <    {
702 <      conf = ptr->data;
703 <      aconf = map_to_conf(conf);
704 <
705 <      DLINK_FOREACH(dptr, aconf->hub_list.head)
706 <        sendto_one(source_p, form_str(RPL_STATSHLINE), me.name,
707 <                   source_p->name, 'H', dptr->data, conf->name, 0, "*");
708 <    }
709 <    break;
710 <
711 <  case LEAF_TYPE:
712 <    DLINK_FOREACH(ptr, server_items.head)
713 <    {
714 <      conf = ptr->data;
715 <      aconf = map_to_conf(conf);
211 >    MyFree(ptr->data);
212 >    dlinkDelete(ptr, &conf->leaf_list);
213 >    free_dlink_node(ptr);
214 >  }
215  
216 <      DLINK_FOREACH(dptr, aconf->leaf_list.head)
217 <        sendto_one(source_p, form_str(RPL_STATSLLINE), me.name,
218 <                   source_p->name, 'L', dptr->data, conf->name, 0, "*");
720 <    }
721 <    break;
216 >  DLINK_FOREACH_SAFE(ptr, ptr_next, conf->exempt_list.head)
217 >  {
218 >    struct exempt *exptr = ptr->data;
219  
220 <  case GLINE_TYPE:
221 <  case KLINE_TYPE:
222 <  case DLINE_TYPE:
223 <  case EXEMPTDLINE_TYPE:
224 <  case CRESV_TYPE:
728 <  case NRESV_TYPE:
729 <  case CLUSTER_TYPE:
730 <  default:
731 <    break;
220 >    dlinkDelete(ptr, &conf->exempt_list);
221 >    MyFree(exptr->name);
222 >    MyFree(exptr->user);
223 >    MyFree(exptr->host);
224 >    MyFree(exptr);
225    }
226 +
227 +  MyFree(conf);
228   }
229  
230   /* check_client()
# Line 745 | Line 240 | report_confitem_types(struct Client *sou
240   *                Look for conf lines which have the same
241   *                status as the flags passed.
242   */
243 < static void *
244 < check_client(va_list args)
243 > int
244 > check_client(struct Client *source_p)
245   {
751 –  struct Client *source_p = va_arg(args, struct Client *);
752 –  const char *username = va_arg(args, const char *);
246    int i;
247 <
248 <  /* I'm already in big trouble if source_p->localClient is NULL -db */
249 <  if ((i = verify_access(source_p, username)))
757 <    ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
247 >
248 >  if ((i = verify_access(source_p)))
249 >    ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
250           source_p->name, source_p->sockhost);
251  
252    switch (i)
253    {
254      case TOO_MANY:
255 <      sendto_realops_flags(UMODE_FULL, L_ALL,
255 >      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
256                             "Too many on IP for %s (%s).",
257 <                           get_client_name(source_p, SHOW_IP),
258 <                           source_p->sockhost);
257 >                           get_client_name(source_p, SHOW_IP),
258 >                           source_p->sockhost);
259        ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
260 <           get_client_name(source_p, SHOW_IP));
260 >           get_client_name(source_p, SHOW_IP));
261        ++ServerStats.is_ref;
262 <      exit_client(source_p, &me, "No more connections allowed on that IP");
262 >      exit_client(source_p, "No more connections allowed on that IP");
263        break;
264  
265      case I_LINE_FULL:
266 <      sendto_realops_flags(UMODE_FULL, L_ALL,
267 <                           "I-line is full for %s (%s).",
268 <                           get_client_name(source_p, SHOW_IP),
269 <                           source_p->sockhost);
266 >      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
267 >                           "auth{} block is full for %s (%s).",
268 >                           get_client_name(source_p, SHOW_IP),
269 >                           source_p->sockhost);
270        ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
271 <           get_client_name(source_p, SHOW_IP));
271 >           get_client_name(source_p, SHOW_IP));
272        ++ServerStats.is_ref;
273 <      exit_client(source_p, &me,
782 <                "No more connections allowed in your connection class");
273 >      exit_client(source_p, "No more connections allowed in your connection class");
274        break;
275  
276      case NOT_AUTHORIZED:
277        ++ServerStats.is_ref;
278        /* jdc - lists server name & port connections are on */
279        /*       a purely cosmetical change */
280 <      sendto_realops_flags(UMODE_UNAUTH, L_ALL,
281 <                           "Unauthorized client connection from %s [%s] on [%s/%u].",
282 <                           get_client_name(source_p, SHOW_IP),
283 <                           source_p->sockhost,
284 <                           source_p->localClient->listener->name,
285 <                           source_p->localClient->listener->port);
280 >      sendto_realops_flags(UMODE_UNAUTH, L_ALL, SEND_NOTICE,
281 >                           "Unauthorized client connection from %s [%s] on [%s/%u].",
282 >                           get_client_name(source_p, SHOW_IP),
283 >                           source_p->sockhost,
284 >                           source_p->localClient->listener->name,
285 >                           source_p->localClient->listener->port);
286        ilog(LOG_TYPE_IRCD,
287 <          "Unauthorized client connection from %s on [%s/%u].",
288 <          get_client_name(source_p, SHOW_IP),
289 <          source_p->localClient->listener->name,
290 <          source_p->localClient->listener->port);
291 <
292 <      /* XXX It is prolematical whether it is better to use the
802 <       * capture reject code here or rely on the connecting too fast code.
803 <       * - Dianora
804 <       */
805 <      if (REJECT_HOLD_TIME > 0)
806 <      {
807 <        sendto_one(source_p, ":%s NOTICE %s :You are not authorized to use this server",
808 <                   me.name, source_p->name);
809 <        source_p->localClient->reject_delay = CurrentTime + REJECT_HOLD_TIME;
810 <        SetCaptured(source_p);
811 <      }
812 <      else
813 <        exit_client(source_p, &me, "You are not authorized to use this server");
287 >           "Unauthorized client connection from %s on [%s/%u].",
288 >           get_client_name(source_p, SHOW_IP),
289 >           source_p->localClient->listener->name,
290 >           source_p->localClient->listener->port);
291 >
292 >      exit_client(source_p, "You are not authorized to use this server");
293        break;
294  
295     case BANNED_CLIENT:
296 <     /*
818 <      * Don't exit them immediately, play with them a bit.
819 <      * - Dianora
820 <      */
821 <     if (REJECT_HOLD_TIME > 0)
822 <     {
823 <       source_p->localClient->reject_delay = CurrentTime + REJECT_HOLD_TIME;
824 <       SetCaptured(source_p);
825 <     }
826 <     else
827 <       exit_client(source_p, &me, "Banned");
296 >     exit_client(source_p, "Banned");
297       ++ServerStats.is_ref;
298       break;
299  
# Line 833 | Line 302 | check_client(va_list args)
302       break;
303    }
304  
305 <  return (i < 0 ? NULL : source_p);
305 >  return (i < 0 ? 0 : 1);
306   }
307  
308   /* verify_access()
309   *
310   * inputs       - pointer to client to verify
842 – *              - pointer to proposed username
311   * output       - 0 if success -'ve if not
312   * side effect  - find the first (best) I line to attach.
313   */
314   static int
315 < verify_access(struct Client *client_p, const char *username)
315 > verify_access(struct Client *client_p)
316   {
317 <  struct AccessItem *aconf = NULL, *rkconf = NULL;
318 <  struct ConfItem *conf = NULL;
851 <  char non_ident[USERLEN + 1] = { '~', '\0' };
852 <  const char *uhi[3];
317 >  struct MaskItem *conf = NULL;
318 >  char non_ident[USERLEN + 1] = "~";
319  
320    if (IsGotId(client_p))
321    {
322 <    aconf = find_address_conf(client_p->host, client_p->username,
323 <                             &client_p->localClient->ip,
324 <                             client_p->localClient->aftype,
322 >    conf = find_address_conf(client_p->host, client_p->username,
323 >                             &client_p->localClient->ip,
324 >                             client_p->localClient->aftype,
325                               client_p->localClient->passwd);
326    }
327    else
328    {
329 <    strlcpy(non_ident+1, username, sizeof(non_ident)-1);
330 <    aconf = find_address_conf(client_p->host,non_ident,
331 <                             &client_p->localClient->ip,
332 <                             client_p->localClient->aftype,
333 <                             client_p->localClient->passwd);
329 >    strlcpy(non_ident + 1, client_p->username, sizeof(non_ident) - 1);
330 >    conf = find_address_conf(client_p->host,non_ident,
331 >                             &client_p->localClient->ip,
332 >                             client_p->localClient->aftype,
333 >                             client_p->localClient->passwd);
334    }
335  
336 <  uhi[0] = IsGotId(client_p) ? client_p->username : non_ident;
871 <  uhi[1] = client_p->host;
872 <  uhi[2] = client_p->sockhost;
873 <
874 <  rkconf = find_regexp_kline(uhi);
875 <
876 <  if (aconf != NULL)
336 >  if (conf)
337    {
338 <    if (IsConfClient(aconf) && !rkconf)
338 >    if (IsConfClient(conf))
339      {
340 <      conf = unmap_conf_item(aconf);
881 <
882 <      if (IsConfRedir(aconf))
340 >      if (IsConfRedir(conf))
341        {
342 <        sendto_one(client_p, form_str(RPL_REDIR),
343 <                   me.name, client_p->name,
344 <                   conf->name ? conf->name : "",
345 <                   aconf->port);
888 <        return(NOT_AUTHORIZED);
342 >        sendto_one_numeric(client_p, &me, RPL_REDIR,
343 >                           conf->name ? conf->name : "",
344 >                           conf->port);
345 >        return NOT_AUTHORIZED;
346        }
347  
348 <      if (IsConfDoIdentd(aconf))
349 <        SetNeedId(client_p);
348 >      if (IsConfDoIdentd(conf))
349 >        SetNeedId(client_p);
350  
351        /* Thanks for spoof idea amm */
352 <      if (IsConfDoSpoofIp(aconf))
352 >      if (IsConfDoSpoofIp(conf))
353        {
354 <        conf = unmap_conf_item(aconf);
355 <
356 <        if (!ConfigFileEntry.hide_spoof_ips && IsConfSpoofNotice(aconf))
900 <          sendto_realops_flags(UMODE_ALL, L_ADMIN, "%s spoofing: %s as %s",
354 >        if (!ConfigFileEntry.hide_spoof_ips && IsConfSpoofNotice(conf))
355 >          sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
356 >                               "%s spoofing: %s as %s",
357                                 client_p->name, client_p->host, conf->name);
358          strlcpy(client_p->host, conf->name, sizeof(client_p->host));
359 <        SetIPSpoof(client_p);
359 >        AddFlag(client_p, FLAGS_IP_SPOOFING | FLAGS_AUTH_SPOOF);
360        }
361  
362 <      return(attach_iline(client_p, conf));
362 >      return attach_iline(client_p, conf);
363      }
364 <    else if (rkconf || IsConfKill(aconf) || (ConfigFileEntry.glines && IsConfGline(aconf)))
364 >    else if (IsConfKill(conf) || (ConfigFileEntry.glines && IsConfGline(conf)))
365      {
366 <      /* XXX */
367 <      aconf = rkconf ? rkconf : aconf;
368 <      if (IsConfGline(aconf))
369 <        sendto_one(client_p, ":%s NOTICE %s :*** G-lined", me.name,
914 <                   client_p->name);
915 <      if (ConfigFileEntry.kline_with_reason)
916 <        sendto_one(client_p, ":%s NOTICE %s :*** Banned %s",
917 <                  me.name, client_p->name, aconf->reason);
918 <      return(BANNED_CLIENT);
366 >      if (IsConfGline(conf))
367 >        sendto_one_notice(client_p, &me, ":*** G-lined");
368 >      sendto_one_notice(client_p, &me, ":*** Banned: %s", conf->reason);
369 >      return BANNED_CLIENT;
370      }
371    }
372  
373 <  return(NOT_AUTHORIZED);
373 >  return NOT_AUTHORIZED;
374   }
375  
376   /* attach_iline()
# Line 930 | Line 381 | verify_access(struct Client *client_p, c
381   * side effects - do actual attach
382   */
383   static int
384 < attach_iline(struct Client *client_p, struct ConfItem *conf)
384 > attach_iline(struct Client *client_p, struct MaskItem *conf)
385   {
386 <  struct AccessItem *aconf;
936 <  struct ClassItem *aclass;
386 >  struct ClassItem *class = NULL;
387    struct ip_entry *ip_found;
388    int a_limit_reached = 0;
389 <  int local = 0, global = 0, ident = 0;
389 >  unsigned int local = 0, global = 0, ident = 0;
390 >
391 >  assert(conf->class);
392  
393    ip_found = find_or_add_ip(&client_p->localClient->ip);
394    ip_found->count++;
395    SetIpHash(client_p);
396  
397 <  aconf = map_to_conf(conf);
946 <  if (aconf->class_ptr == NULL)
947 <    return NOT_AUTHORIZED;  /* If class is missing, this is best */
948 <
949 <  aclass = map_to_conf(aconf->class_ptr);
397 >  class = conf->class;
398  
399    count_user_host(client_p->username, client_p->host,
400                    &global, &local, &ident);
# Line 955 | Line 403 | attach_iline(struct Client *client_p, st
403     * setting a_limit_reached if any limit is reached.
404     * - Dianora
405     */
406 <  if (aclass->max_total != 0 && aclass->curr_user_count >= aclass->max_total)
406 >  if (class->max_total != 0 && class->ref_count >= class->max_total)
407      a_limit_reached = 1;
408 <  else if (aclass->max_perip != 0 && ip_found->count > aclass->max_perip)
408 >  else if (class->max_perip != 0 && ip_found->count > class->max_perip)
409      a_limit_reached = 1;
410 <  else if (aclass->max_local != 0 && local >= aclass->max_local)
410 >  else if (class->max_local != 0 && local >= class->max_local)
411      a_limit_reached = 1;
412 <  else if (aclass->max_global != 0 && global >= aclass->max_global)
412 >  else if (class->max_global != 0 && global >= class->max_global)
413      a_limit_reached = 1;
414 <  else if (aclass->max_ident != 0 && ident >= aclass->max_ident &&
414 >  else if (class->max_ident != 0 && ident >= class->max_ident &&
415             client_p->username[0] != '~')
416      a_limit_reached = 1;
417  
418    if (a_limit_reached)
419    {
420 <    if (!IsConfExemptLimits(aconf))
420 >    if (!IsConfExemptLimits(conf))
421        return TOO_MANY;   /* Already at maximum allowed */
422  
423 <    sendto_one(client_p,
424 <               ":%s NOTICE %s :*** Your connection class is full, "
977 <               "but you have exceed_limit = yes;", me.name, client_p->name);
423 >    sendto_one_notice(client_p, &me, ":*** Your connection class is full, "
424 >                      "but you have exceed_limit = yes;");
425    }
426  
427    return attach_conf(client_p, conf);
# Line 990 | Line 437 | attach_iline(struct Client *client_p, st
437   void
438   init_ip_hash_table(void)
439   {
440 <  ip_entry_heap = BlockHeapCreate("ip", sizeof(struct ip_entry),
994 <    2 * hard_fdlimit);
440 >  ip_entry_pool = mp_pool_new(sizeof(struct ip_entry), MP_CHUNK_SIZE_IP_ENTRY);
441    memset(ip_hash_table, 0, sizeof(ip_hash_table));
442   }
443  
# Line 1040 | Line 486 | find_or_add_ip(struct irc_ssaddr *ip_in)
486    if (ip_entries_count >= 2 * hard_fdlimit)
487      garbage_collect_ip_entries();
488  
489 <  newptr = BlockHeapAlloc(ip_entry_heap);
489 >  newptr = mp_pool_get(ip_entry_pool);
490 >  memset(newptr, 0, sizeof(*newptr));
491    ip_entries_count++;
492    memcpy(&newptr->ip, ip_in, sizeof(struct irc_ssaddr));
493  
# Line 1091 | Line 538 | remove_one_ip(struct irc_ssaddr *ip_in)
538      if (ptr->count > 0)
539        ptr->count--;
540      if (ptr->count == 0 &&
541 <        (CurrentTime-ptr->last_attempt) >= ConfigFileEntry.throttle_time)
541 >        (CurrentTime-ptr->last_attempt) >= ConfigFileEntry.throttle_time)
542      {
543        if (last_ptr != NULL)
544 <        last_ptr->next = ptr->next;
544 >        last_ptr->next = ptr->next;
545        else
546 <        ip_hash_table[hash_index] = ptr->next;
546 >        ip_hash_table[hash_index] = ptr->next;
547  
548 <      BlockHeapFree(ip_entry_heap, ptr);
548 >      mp_pool_release(ptr);
549        ip_entries_count--;
550        return;
551      }
# Line 1133 | Line 580 | hash_ip(struct irc_ssaddr *addr)
580      uint32_t *ip = (uint32_t *)&v6->sin6_addr.s6_addr;
581  
582      hash  = ip[0] ^ ip[3];
583 <    hash ^= hash >> 16;  
584 <    hash ^= hash >> 8;  
583 >    hash ^= hash >> 16;
584 >    hash ^= hash >> 8;
585      hash  = hash & (IP_HASH_SIZE - 1);
586      return hash;
587    }
# Line 1145 | Line 592 | hash_ip(struct irc_ssaddr *addr)
592  
593   /* count_ip_hash()
594   *
595 < * inputs        - pointer to counter of number of ips hashed
595 > * inputs        - pointer to counter of number of ips hashed
596   *               - pointer to memory used for ip hash
597   * output        - returned via pointers input
598   * side effects  - NONE
# Line 1201 | Line 648 | garbage_collect_ip_entries(void)
648            last_ptr->next = ptr->next;
649          else
650            ip_hash_table[i] = ptr->next;
651 <        BlockHeapFree(ip_entry_heap, ptr);
651 >        mp_pool_release(ptr);
652          ip_entries_count--;
653        }
654        else
# Line 1218 | Line 665 | garbage_collect_ip_entries(void)
665   * side effects - Disassociate configuration from the client.
666   *                Also removes a class from the list if marked for deleting.
667   */
668 < int
669 < detach_conf(struct Client *client_p, ConfType type)
668 > void
669 > detach_conf(struct Client *client_p, enum maskitem_type type)
670   {
671 <  dlink_node *ptr, *next_ptr;
1225 <  struct ConfItem *conf;
1226 <  struct ClassItem *aclass;
1227 <  struct AccessItem *aconf;
1228 <  struct ConfItem *aclass_conf;
1229 <  struct MatchItem *match_item;
671 >  dlink_node *ptr = NULL, *ptr_next = NULL;
672  
673 <  DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->confs.head)
673 >  DLINK_FOREACH_SAFE(ptr, ptr_next, client_p->localClient->confs.head)
674    {
675 <    conf = ptr->data;
675 >    struct MaskItem *conf = ptr->data;
676  
677 <    if (type == CONF_TYPE || conf->type == type)
678 <    {
679 <      dlinkDelete(ptr, &client_p->localClient->confs);
1238 <      free_dlink_node(ptr);
677 >    assert(conf->type & (CONF_CLIENT | CONF_OPER | CONF_SERVER));
678 >    assert(conf->ref_count > 0);
679 >    assert(conf->class->ref_count > 0);
680  
681 <      switch (conf->type)
682 <      {
1242 <      case CLIENT_TYPE:
1243 <      case OPER_TYPE:
1244 <      case SERVER_TYPE:
1245 <        aconf = map_to_conf(conf);
1246 <
1247 <        assert(aconf->clients > 0);
1248 <
1249 <        if ((aclass_conf = aconf->class_ptr) != NULL)
1250 <        {
1251 <          aclass = map_to_conf(aclass_conf);
1252 <
1253 <          assert(aclass->curr_user_count > 0);
1254 <
1255 <          if (conf->type == CLIENT_TYPE)
1256 <            remove_from_cidr_check(&client_p->localClient->ip, aclass);
1257 <          if (--aclass->curr_user_count == 0 && aclass->active == 0)
1258 <            delete_conf_item(aclass_conf);
1259 <        }
681 >    if (!(conf->type & type))
682 >      continue;
683  
684 <        if (--aconf->clients == 0 && IsConfIllegal(aconf))
685 <          delete_conf_item(conf);
684 >    dlinkDelete(ptr, &client_p->localClient->confs);
685 >    free_dlink_node(ptr);
686  
687 <        break;
688 <      default:
1266 <        break;
1267 <      }
687 >    if (conf->type == CONF_CLIENT)
688 >      remove_from_cidr_check(&client_p->localClient->ip, conf->class);
689  
690 <      if (type != CONF_TYPE)
691 <        return 0;
690 >    if (--conf->class->ref_count == 0 && conf->class->active == 0)
691 >    {
692 >      class_free(conf->class);
693 >      conf->class = NULL;
694      }
1272 –  }
695  
696 <  return -1;
696 >    if (--conf->ref_count == 0 && conf->active == 0)
697 >      conf_free(conf);
698 >  }
699   }
700  
701   /* attach_conf()
# Line 1285 | Line 709 | detach_conf(struct Client *client_p, Con
709   *                attachment if there was an old one...
710   */
711   int
712 < attach_conf(struct Client *client_p, struct ConfItem *conf)
712 > attach_conf(struct Client *client_p, struct MaskItem *conf)
713   {
714 <  struct AccessItem *aconf = map_to_conf(conf);
1291 <  struct ClassItem *aclass = map_to_conf(aconf->class_ptr);
1292 <
1293 <  if (dlinkFind(&client_p->localClient->confs, conf) != NULL)
714 >  if (dlinkFind(&client_p->localClient->confs, conf))
715      return 1;
716  
717 <  if (IsConfIllegal(aconf)) /* TBV: can't happen */
718 <    return NOT_AUTHORIZED;
719 <
1299 <  if (conf->type == CLIENT_TYPE)
1300 <    if (cidr_limit_reached(IsConfExemptLimits(aconf),
1301 <                           &client_p->localClient->ip, aclass))
717 >  if (conf->type == CONF_CLIENT)
718 >    if (cidr_limit_reached(IsConfExemptLimits(conf),
719 >                           &client_p->localClient->ip, conf->class))
720        return TOO_MANY;    /* Already at maximum allowed */
721  
722 <  aclass->curr_user_count++;
723 <  aconf->clients++;
722 >  conf->class->ref_count++;
723 >  conf->ref_count++;
724  
725    dlinkAdd(conf, make_dlink_node(), &client_p->localClient->confs);
726  
# Line 1322 | Line 740 | attach_connect_block(struct Client *clie
740                       const char *host)
741   {
742    dlink_node *ptr;
743 <  struct ConfItem *conf;
1326 <  struct AccessItem *aconf;
743 >  struct MaskItem *conf = NULL;
744  
745    assert(client_p != NULL);
746    assert(host != NULL);
# Line 1334 | Line 751 | attach_connect_block(struct Client *clie
751    DLINK_FOREACH(ptr, server_items.head)
752    {
753      conf = ptr->data;
1337 –    aconf = map_to_conf(conf);
754  
755 <    if (match(conf->name, name) == 0 || match(aconf->host, host) == 0)
755 >    if (match(conf->name, name) || match(conf->host, host))
756        continue;
757  
758      attach_conf(client_p, conf);
# Line 1346 | Line 762 | attach_connect_block(struct Client *clie
762    return 0;
763   }
764  
1349 – /* find_conf_exact()
1350 – *
1351 – * inputs       - type of ConfItem
1352 – *              - pointer to name to find
1353 – *              - pointer to username to find
1354 – *              - pointer to host to find
1355 – * output       - NULL or pointer to conf found
1356 – * side effects - find a conf entry which matches the hostname
1357 – *                and has the same name.
1358 – */
1359 – struct ConfItem *
1360 – find_conf_exact(ConfType type, const char *name, const char *user,
1361 –                const char *host)
1362 – {
1363 –  dlink_node *ptr;
1364 –  dlink_list *list_p;
1365 –  struct ConfItem *conf = NULL;
1366 –  struct AccessItem *aconf;
1367 –
1368 –  /* Only valid for OPER_TYPE and ...? */
1369 –  list_p = map_to_list(type);
1370 –
1371 –  DLINK_FOREACH(ptr, (*list_p).head)
1372 –  {
1373 –    conf = ptr->data;
1374 –
1375 –    if (conf->name == NULL)
1376 –      continue;
1377 –    aconf = map_to_conf(conf);
1378 –    if (aconf->host == NULL)
1379 –      continue;
1380 –    if (irccmp(conf->name, name) != 0)
1381 –      continue;
1382 –
1383 –    /*
1384 –    ** Accept if the *real* hostname (usually sockethost)
1385 –    ** socket host) matches *either* host or name field
1386 –    ** of the configuration.
1387 –    */
1388 –    if (!match(aconf->host, host) || !match(aconf->user, user))
1389 –      continue;
1390 –    if (type == OPER_TYPE)
1391 –    {
1392 –      struct ClassItem *aclass = map_to_conf(aconf->class_ptr);
1393 –
1394 –      if (aconf->clients >= aclass->max_total)
1395 –        continue;
1396 –    }
1397 –
1398 –    return conf;
1399 –  }
1400 –
1401 –  return NULL;
1402 – }
1403 –
765   /* find_conf_name()
766   *
767   * inputs       - pointer to conf link list to search
# Line 1410 | Line 771 | find_conf_exact(ConfType type, const cha
771   * side effects - find a conf entry which matches the name
772   *                and has the given mask.
773   */
774 < struct ConfItem *
775 < find_conf_name(dlink_list *list, const char *name, ConfType type)
774 > struct MaskItem *
775 > find_conf_name(dlink_list *list, const char *name, enum maskitem_type type)
776   {
777    dlink_node *ptr;
778 <  struct ConfItem* conf;
778 >  struct MaskItem* conf;
779  
780    DLINK_FOREACH(ptr, list->head)
781    {
782      conf = ptr->data;
783 <    
783 >
784      if (conf->type == type)
785      {
786        if (conf->name && (irccmp(conf->name, name) == 0 ||
787 <                         match(conf->name, name)))
787 >                         !match(conf->name, name)))
788        return conf;
789      }
790    }
# Line 1438 | Line 799 | find_conf_name(dlink_list *list, const c
799   * side effects - none
800   */
801   static dlink_list *
802 < map_to_list(ConfType type)
802 > map_to_list(enum maskitem_type type)
803   {
804    switch(type)
805    {
806 <  case RXLINE_TYPE:
1446 <    return(&rxconf_items);
1447 <    break;
1448 <  case XLINE_TYPE:
806 >  case CONF_XLINE:
807      return(&xconf_items);
808      break;
809 <  case ULINE_TYPE:
809 >  case CONF_ULINE:
810      return(&uconf_items);
811      break;
812 <  case NRESV_TYPE:
812 >  case CONF_NRESV:
813      return(&nresv_items);
814      break;
815 <  case OPER_TYPE:
815 >  case CONF_CRESV:
816 >    return(&cresv_items);
817 >  case CONF_OPER:
818      return(&oconf_items);
819      break;
820 <  case CLASS_TYPE:
1461 <    return(&class_items);
1462 <    break;
1463 <  case SERVER_TYPE:
820 >  case CONF_SERVER:
821      return(&server_items);
822      break;
823 <  case SERVICE_TYPE:
823 >  case CONF_SERVICE:
824      return(&service_items);
825      break;
826 <  case CLUSTER_TYPE:
826 >  case CONF_CLUSTER:
827      return(&cluster_items);
828      break;
1472 –  case CONF_TYPE:
1473 –  case GLINE_TYPE:
1474 –  case KLINE_TYPE:
1475 –  case DLINE_TYPE:
1476 –  case CRESV_TYPE:
829    default:
830      return NULL;
831    }
# Line 1485 | Line 837 | map_to_list(ConfType type)
837   *              - pointer to name string to find
838   *              - pointer to user
839   *              - pointer to host
840 < *              - optional action to match on as well
841 < * output       - NULL or pointer to found struct MatchItem
840 > *              - optional flags to match on as well
841 > * output       - NULL or pointer to found struct MaskItem
842   * side effects - looks for a match on name field
843   */
844 < struct ConfItem *
845 < find_matching_name_conf(ConfType type, const char *name, const char *user,
846 <                        const char *host, int action)
844 > struct MaskItem *
845 > find_matching_name_conf(enum maskitem_type type, const char *name, const char *user,
846 >                        const char *host, unsigned int flags)
847   {
848    dlink_node *ptr=NULL;
849 <  struct ConfItem *conf=NULL;
1498 <  struct AccessItem *aconf=NULL;
1499 <  struct MatchItem *match_item=NULL;
849 >  struct MaskItem *conf=NULL;
850    dlink_list *list_p = map_to_list(type);
851  
852    switch (type)
853    {
854 < #ifdef HAVE_LIBPCRE
1505 <  case RXLINE_TYPE:
1506 <      DLINK_FOREACH(ptr, list_p->head)
1507 <      {
1508 <        conf = ptr->data;
1509 <        assert(conf->regexpname);
1510 <
1511 <        if (!ircd_pcre_exec(conf->regexpname, name))
1512 <          return conf;
1513 <      }
1514 <      break;
1515 < #endif
1516 <  case SERVICE_TYPE:
854 >  case CONF_SERVICE:
855      DLINK_FOREACH(ptr, list_p->head)
856      {
857        conf = ptr->data;
# Line 1525 | Line 863 | find_matching_name_conf(ConfType type, c
863      }
864      break;
865  
866 <  case XLINE_TYPE:
867 <  case ULINE_TYPE:
868 <  case NRESV_TYPE:
866 >  case CONF_XLINE:
867 >  case CONF_ULINE:
868 >  case CONF_NRESV:
869 >  case CONF_CRESV:
870      DLINK_FOREACH(ptr, list_p->head)
871      {
872        conf = ptr->data;
873  
1535 –      match_item = map_to_conf(conf);
874        if (EmptyString(conf->name))
875 <        continue;
876 <      if ((name != NULL) && match_esc(conf->name, name))
875 >        continue;
876 >      if ((name != NULL) && !match(conf->name, name))
877        {
878 <        if ((user == NULL && (host == NULL)))
879 <          return conf;
880 <        if ((match_item->action & action) != action)
878 >        if ((user == NULL && (host == NULL)))
879 >          return conf;
880 >        if ((conf->flags & flags) != flags)
881            continue;
882 <        if (EmptyString(match_item->user) || EmptyString(match_item->host))
883 <          return conf;
884 <        if (match(match_item->user, user) && match(match_item->host, host))
885 <          return conf;
882 >        if (EmptyString(conf->user) || EmptyString(conf->host))
883 >          return conf;
884 >        if (!match(conf->user, user) && !match(conf->host, host))
885 >          return conf;
886        }
887      }
888        break;
889  
890 <  case SERVER_TYPE:
890 >  case CONF_SERVER:
891      DLINK_FOREACH(ptr, list_p->head)
892      {
893        conf = ptr->data;
1556 –      aconf = map_to_conf(conf);
894  
895 <      if ((name != NULL) && match_esc(name, conf->name))
895 >      if ((name != NULL) && !match(name, conf->name))
896          return conf;
897 <      else if ((host != NULL) && match_esc(host, aconf->host))
897 >      else if ((host != NULL) && !match(host, conf->host))
898          return conf;
899      }
900      break;
901 <  
901 >
902    default:
903      break;
904    }
# Line 1574 | Line 911 | find_matching_name_conf(ConfType type, c
911   *              - pointer to name string to find
912   *              - pointer to user
913   *              - pointer to host
914 < * output       - NULL or pointer to found struct MatchItem
914 > * output       - NULL or pointer to found struct MaskItem
915   * side effects - looks for an exact match on name field
916   */
917 < struct ConfItem *
918 < find_exact_name_conf(ConfType type, const struct Client *who, const char *name,
917 > struct MaskItem *
918 > find_exact_name_conf(enum maskitem_type type, const struct Client *who, const char *name,
919                       const char *user, const char *host)
920   {
921    dlink_node *ptr = NULL;
922 <  struct AccessItem *aconf;
923 <  struct ConfItem *conf;
1587 <  struct MatchItem *match_item;
1588 <  dlink_list *list_p;
1589 <
1590 <  list_p = map_to_list(type);
922 >  struct MaskItem *conf;
923 >  dlink_list *list_p = map_to_list(type);
924  
925    switch(type)
926    {
927 <  case RXLINE_TYPE:
928 <  case XLINE_TYPE:
929 <  case ULINE_TYPE:
930 <  case NRESV_TYPE:
927 >  case CONF_XLINE:
928 >  case CONF_ULINE:
929 >  case CONF_NRESV:
930 >  case CONF_CRESV:
931  
932      DLINK_FOREACH(ptr, list_p->head)
933      {
934        conf = ptr->data;
935 <      match_item = (struct MatchItem *)map_to_conf(conf);
935 >
936        if (EmptyString(conf->name))
937 <        continue;
938 <    
937 >        continue;
938 >
939        if (irccmp(conf->name, name) == 0)
940        {
941 <        if ((user == NULL && (host == NULL)))
942 <          return (conf);
943 <        if (EmptyString(match_item->user) || EmptyString(match_item->host))
944 <          return (conf);
945 <        if (match(match_item->user, user) && match(match_item->host, host))
946 <          return (conf);
941 >        if ((user == NULL && (host == NULL)))
942 >          return conf;
943 >        if (EmptyString(conf->user) || EmptyString(conf->host))
944 >          return conf;
945 >        if (!match(conf->user, user) && !match(conf->host, host))
946 >          return conf;
947        }
948      }
949      break;
950  
951 <  case OPER_TYPE:
951 >  case CONF_OPER:
952      DLINK_FOREACH(ptr, list_p->head)
953      {
954        conf = ptr->data;
1622 –      aconf = map_to_conf(conf);
955  
956        if (EmptyString(conf->name))
957          continue;
# Line 1628 | Line 960 | find_exact_name_conf(ConfType type, cons
960        {
961          if (!who)
962            return conf;
963 <        if (EmptyString(aconf->user) || EmptyString(aconf->host))
964 <          return conf;
965 <        if (match(aconf->user, who->username))
963 >        if (EmptyString(conf->user) || EmptyString(conf->host))
964 >          return NULL;
965 >        if (!match(conf->user, who->username))
966          {
967 <          switch (aconf->type)
967 >          switch (conf->htype)
968            {
969              case HM_HOST:
970 <              if (match(aconf->host, who->host) || match(aconf->host, who->sockhost))
971 <                return conf;
970 >              if (!match(conf->host, who->host) || !match(conf->host, who->sockhost))
971 >                if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
972 >                  return conf;
973                break;
974              case HM_IPV4:
975                if (who->localClient->aftype == AF_INET)
976 <                if (match_ipv4(&who->localClient->ip, &aconf->addr, aconf->bits))
977 <                  return conf;
976 >                if (match_ipv4(&who->localClient->ip, &conf->addr, conf->bits))
977 >                  if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
978 >                    return conf;
979                break;
980   #ifdef IPV6
981              case HM_IPV6:
982                if (who->localClient->aftype == AF_INET6)
983 <                if (match_ipv6(&who->localClient->ip, &aconf->addr, aconf->bits))
984 <                  return conf;
983 >                if (match_ipv6(&who->localClient->ip, &conf->addr, conf->bits))
984 >                  if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
985 >                    return conf;
986                break;
987   #endif
988              default:
# Line 1659 | Line 994 | find_exact_name_conf(ConfType type, cons
994  
995      break;
996  
997 <  case SERVER_TYPE:
997 >  case CONF_SERVER:
998      DLINK_FOREACH(ptr, list_p->head)
999      {
1000        conf = ptr->data;
1001 <      aconf = (struct AccessItem *)map_to_conf(conf);
1001 >
1002        if (EmptyString(conf->name))
1003 <        continue;
1004 <    
1003 >        continue;
1004 >
1005        if (name == NULL)
1006        {
1007 <        if (EmptyString(aconf->host))
1008 <          continue;
1009 <        if (irccmp(aconf->host, host) == 0)
1010 <          return(conf);
1007 >        if (EmptyString(conf->host))
1008 >          continue;
1009 >        if (irccmp(conf->host, host) == 0)
1010 >          return conf;
1011        }
1012        else if (irccmp(conf->name, name) == 0)
1013 <      {
1679 <          return (conf);
1680 <      }
1013 >        return conf;
1014      }
1682 –    break;
1015  
1684 –  case CLASS_TYPE:
1685 –    DLINK_FOREACH(ptr, list_p->head)
1686 –    {
1687 –      conf = ptr->data;
1688 –      if (EmptyString(conf->name))
1689 –        continue;
1690 –    
1691 –      if (irccmp(conf->name, name) == 0)
1692 –        return (conf);
1693 –    }
1016      break;
1017  
1018    default:
1019      break;
1020    }
1021 <  return(NULL);
1021 >
1022 >  return NULL;
1023   }
1024  
1025   /* rehash()
# Line 1708 | Line 1031 | find_exact_name_conf(ConfType type, cons
1031   int
1032   rehash(int sig)
1033   {
1034 <  if (sig != 0)
1035 <    sendto_realops_flags(UMODE_ALL, L_ALL,
1036 <                         "Got signal SIGHUP, reloading ircd.conf file");
1034 >  if (sig)
1035 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1036 >                         "Got signal SIGHUP, reloading configuration file(s)");
1037  
1038    restart_resolver();
1039  
# Line 1721 | Line 1044 | rehash(int sig)
1044  
1045    read_conf_files(0);
1046  
1047 <  if (ServerInfo.description != NULL)
1047 >  if (ServerInfo.description)
1048      strlcpy(me.info, ServerInfo.description, sizeof(me.info));
1049  
1050    load_conf_modules();
1051  
1729 –  flush_deleted_I_P();
1730 –
1052    rehashed_klines = 1;
1732 – /* XXX */
1733 –  if (ConfigLoggingEntry.use_logging)
1734 –    log_close_all();
1053  
1054 <  return(0);
1054 >  return 0;
1055   }
1056  
1057   /* set_default_conf()
# Line 1751 | Line 1069 | set_default_conf(void)
1069    /* verify init_class() ran, this should be an unnecessary check
1070     * but its not much work.
1071     */
1072 <  assert(class_default == (struct ConfItem *) class_items.tail->data);
1072 >  assert(class_default == class_get_list()->tail->data);
1073  
1074   #ifdef HAVE_LIBCRYPTO
1075    ServerInfo.rsa_private_key = NULL;
# Line 1761 | Line 1079 | set_default_conf(void)
1079    /* ServerInfo.name is not rehashable */
1080    /* ServerInfo.name = ServerInfo.name; */
1081    ServerInfo.description = NULL;
1082 <  DupString(ServerInfo.network_name, NETWORK_NAME_DEFAULT);
1083 <  DupString(ServerInfo.network_desc, NETWORK_DESC_DEFAULT);
1082 >  ServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
1083 >  ServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
1084  
1085    memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip));
1086    ServerInfo.specific_ipv4_vhost = 0;
# Line 1770 | Line 1088 | set_default_conf(void)
1088    ServerInfo.specific_ipv6_vhost = 0;
1089  
1090    ServerInfo.max_clients = MAXCLIENTS_MAX;
1091 +  ServerInfo.max_nick_length = 9;
1092 +  ServerInfo.max_topic_length = 80;
1093  
1094    ServerInfo.hub = 0;
1095    ServerInfo.dns_host.sin_addr.s_addr = 0;
# Line 1778 | Line 1098 | set_default_conf(void)
1098    AdminInfo.email = NULL;
1099    AdminInfo.description = NULL;
1100  
1101 <  log_close_all();
1101 >  log_del_all();
1102  
1103    ConfigLoggingEntry.use_logging = 1;
1104  
1105    ConfigChannel.disable_fake_channels = 0;
1786 –  ConfigChannel.restrict_channels = 0;
1106    ConfigChannel.knock_delay = 300;
1107    ConfigChannel.knock_delay_channel = 60;
1108    ConfigChannel.max_chans_per_user = 25;
1109    ConfigChannel.max_chans_per_oper = 50;
1791 –  ConfigChannel.quiet_on_ban = 1;
1110    ConfigChannel.max_bans = 25;
1111    ConfigChannel.default_split_user_count = 0;
1112    ConfigChannel.default_split_server_count = 0;
# Line 1799 | Line 1117 | set_default_conf(void)
1117    ConfigServerHide.links_delay = 300;
1118    ConfigServerHide.hidden = 0;
1119    ConfigServerHide.hide_servers = 0;
1120 <  DupString(ConfigServerHide.hidden_name, NETWORK_NAME_DEFAULT);
1120 >  ConfigServerHide.hide_services = 0;
1121 >  ConfigServerHide.hidden_name = xstrdup(NETWORK_NAME_DEFAULT);
1122    ConfigServerHide.hide_server_ips = 0;
1123 +  ConfigServerHide.disable_remote_commands = 0;
1124  
1125 <  
1806 <  DupString(ConfigFileEntry.service_name, SERVICE_NAME_DEFAULT);
1125 >  ConfigFileEntry.service_name = xstrdup(SERVICE_NAME_DEFAULT);
1126    ConfigFileEntry.max_watch = WATCHSIZE_DEFAULT;
1127 +  ConfigFileEntry.cycle_on_host_change = 1;
1128    ConfigFileEntry.glines = 0;
1129    ConfigFileEntry.gline_time = 12 * 3600;
1130    ConfigFileEntry.gline_request_time = GLINE_REQUEST_EXPIRE_DEFAULT;
1131    ConfigFileEntry.gline_min_cidr = 16;
1132    ConfigFileEntry.gline_min_cidr6 = 48;
1133    ConfigFileEntry.invisible_on_connect = 1;
1814 –  ConfigFileEntry.burst_away = 0;
1815 –  ConfigFileEntry.use_whois_actually = 1;
1134    ConfigFileEntry.tkline_expire_notices = 1;
1135    ConfigFileEntry.hide_spoof_ips = 1;
1136    ConfigFileEntry.ignore_bogus_ts = 0;
1137    ConfigFileEntry.disable_auth = 0;
1820 –  ConfigFileEntry.disable_remote = 0;
1138    ConfigFileEntry.kill_chase_time_limit = 90;
1139    ConfigFileEntry.default_floodcount = 8;
1140    ConfigFileEntry.failed_oper_notice = 1;
# Line 1831 | Line 1148 | set_default_conf(void)
1148    ConfigFileEntry.anti_spam_exit_message_time = 0;
1149    ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
1150    ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
1834 –  ConfigFileEntry.kline_with_reason = 1;
1835 –  ConfigFileEntry.kline_reason = NULL;
1151    ConfigFileEntry.warn_no_nline = 1;
1152    ConfigFileEntry.stats_o_oper_only = 0;
1153    ConfigFileEntry.stats_k_oper_only = 1;  /* masked */
1154    ConfigFileEntry.stats_i_oper_only = 1;  /* masked */
1155    ConfigFileEntry.stats_P_oper_only = 0;
1156 +  ConfigFileEntry.stats_u_oper_only = 0;
1157    ConfigFileEntry.caller_id_wait = 60;
1158    ConfigFileEntry.opers_bypass_callerid = 0;
1159    ConfigFileEntry.pace_wait = 10;
# Line 1848 | Line 1164 | set_default_conf(void)
1164    ConfigFileEntry.true_no_oper_flood = 0;
1165    ConfigFileEntry.oper_pass_resv = 1;
1166    ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT;
1851 –  ConfigFileEntry.client_flood = CLIENT_FLOOD_DEFAULT;
1167    ConfigFileEntry.oper_only_umodes = UMODE_DEBUG;
1168    ConfigFileEntry.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE |
1169      UMODE_OPERWALL | UMODE_WALLOP;
# Line 1867 | Line 1182 | validate_conf(void)
1182      ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
1183  
1184    if (ServerInfo.network_name == NULL)
1185 <    DupString(ServerInfo.network_name,NETWORK_NAME_DEFAULT);
1185 >    ServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
1186  
1187    if (ServerInfo.network_desc == NULL)
1188 <    DupString(ServerInfo.network_desc,NETWORK_DESC_DEFAULT);
1188 >    ServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
1189  
1190    if (ConfigFileEntry.service_name == NULL)
1191 <    DupString(ConfigFileEntry.service_name, SERVICE_NAME_DEFAULT);
1877 <
1878 <  if ((ConfigFileEntry.client_flood < CLIENT_FLOOD_MIN) ||
1879 <      (ConfigFileEntry.client_flood > CLIENT_FLOOD_MAX))
1880 <    ConfigFileEntry.client_flood = CLIENT_FLOOD_MAX;
1191 >    ConfigFileEntry.service_name = xstrdup(SERVICE_NAME_DEFAULT);
1192  
1193    ConfigFileEntry.max_watch = IRCD_MAX(ConfigFileEntry.max_watch, WATCHSIZE_MIN);
1194   }
1195  
1196 < /* read_conf()
1196 > /* read_conf()
1197   *
1198   * inputs       - file descriptor pointing to config file to use
1199   * output       - None
# Line 1895 | Line 1206 | read_conf(FILE *file)
1206  
1207    set_default_conf(); /* Set default values prior to conf parsing */
1208    conf_parser_ctx.pass = 1;
1209 <  yyparse();          /* pick up the classes first */
1209 >  yyparse();          /* pick up the classes first */
1210  
1211    rewind(file);
1212  
# Line 1903 | Line 1214 | read_conf(FILE *file)
1214    yyparse();          /* Load the values from the conf */
1215    validate_conf();    /* Check to make sure some values are still okay. */
1216                        /* Some global values are also loaded here. */
1217 <  check_class();      /* Make sure classes are valid */
1217 >  class_delete_marked();      /* Make sure classes are valid */
1218   }
1219  
1220   /* lookup_confhost()
# Line 1911 | Line 1222 | read_conf(FILE *file)
1222   * start DNS lookups of all hostnames in the conf
1223   * line and convert an IP addresses in a.b.c.d number for to IP#s.
1224   */
1225 < static void
1226 < lookup_confhost(struct ConfItem *conf)
1225 > void
1226 > lookup_confhost(struct MaskItem *conf)
1227   {
1917 –  struct AccessItem *aconf;
1228    struct addrinfo hints, *res;
1229  
1920 –  aconf = map_to_conf(conf);
1921 –
1922 –  if (has_wildcards(aconf->host))
1923 –  {
1924 –    ilog(LOG_TYPE_IRCD, "Host/server name error: (%s) (%s)",
1925 –         aconf->host, conf->name);
1926 –    return;
1927 –  }
1928 –
1230    /* Do name lookup now on hostnames given and store the
1231     * ip numbers in conf structure.
1232     */
# Line 1937 | Line 1238 | lookup_confhost(struct ConfItem *conf)
1238    /* Get us ready for a bind() and don't bother doing dns lookup */
1239    hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
1240  
1241 <  if (getaddrinfo(aconf->host, NULL, &hints, &res))
1241 >  if (getaddrinfo(conf->host, NULL, &hints, &res))
1242    {
1243 <    conf_dns_lookup(aconf);
1243 >    conf_dns_lookup(conf);
1244      return;
1245    }
1246  
1247 <  assert(res != NULL);
1247 >  assert(res);
1248 >
1249 >  memcpy(&conf->addr, res->ai_addr, res->ai_addrlen);
1250 >  conf->addr.ss_len = res->ai_addrlen;
1251 >  conf->addr.ss.ss_family = res->ai_family;
1252  
1948 –  memcpy(&aconf->addr, res->ai_addr, res->ai_addrlen);
1949 –  aconf->addr.ss_len = res->ai_addrlen;
1950 –  aconf->addr.ss.ss_family = res->ai_family;
1253    freeaddrinfo(res);
1254   }
1255  
# Line 1962 | Line 1264 | int
1264   conf_connect_allowed(struct irc_ssaddr *addr, int aftype)
1265   {
1266    struct ip_entry *ip_found;
1267 <  struct AccessItem *aconf = find_dline_conf(addr, aftype);
1267 >  struct MaskItem *conf = find_dline_conf(addr, aftype);
1268  
1269    /* DLINE exempt also gets you out of static limits/pacing... */
1270 <  if (aconf && (aconf->status & CONF_EXEMPTDLINE))
1270 >  if (conf && (conf->type == CONF_EXEMPT))
1271      return 0;
1272  
1273 <  if (aconf != NULL)
1273 >  if (conf)
1274      return BANNED_CLIENT;
1275  
1276    ip_found = find_or_add_ip(addr);
# Line 1984 | Line 1286 | conf_connect_allowed(struct irc_ssaddr *
1286    return 0;
1287   }
1288  
1987 – static struct AccessItem *
1988 – find_regexp_kline(const char *uhi[])
1989 – {
1990 – #ifdef HAVE_LIBPCRE
1991 –  const dlink_node *ptr = NULL;
1992 –
1993 –  DLINK_FOREACH(ptr, rkconf_items.head)
1994 –  {
1995 –    struct AccessItem *aptr = map_to_conf(ptr->data);
1996 –
1997 –    assert(aptr->regexuser);
1998 –    assert(aptr->regexhost);
1999 –
2000 –    if (!ircd_pcre_exec(aptr->regexuser, uhi[0]) &&
2001 –        (!ircd_pcre_exec(aptr->regexhost, uhi[1]) ||
2002 –         !ircd_pcre_exec(aptr->regexhost, uhi[2])))
2003 –      return aptr;
2004 –  }
2005 – #endif
2006 –  return NULL;
2007 – }
2008 –
2009 – /* find_kill()
2010 – *
2011 – * inputs       - pointer to client structure
2012 – * output       - pointer to struct AccessItem if found
2013 – * side effects - See if this user is klined already,
2014 – *                and if so, return struct AccessItem pointer
2015 – */
2016 – struct AccessItem *
2017 – find_kill(struct Client *client_p)
2018 – {
2019 –  struct AccessItem *aconf = NULL;
2020 –  const char *uhi[3];
2021 –
2022 –  uhi[0] = client_p->username;
2023 –  uhi[1] = client_p->host;
2024 –  uhi[2] = client_p->sockhost;
2025 –
2026 –  assert(client_p != NULL);
2027 –
2028 –  aconf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
2029 –                               CONF_KLINE, client_p->localClient->aftype,
2030 –                               client_p->username, NULL, 1);
2031 –  if (aconf == NULL)
2032 –    aconf = find_regexp_kline(uhi);
2033 –
2034 –  return aconf;
2035 – }
2036 –
2037 – struct AccessItem *
2038 – find_gline(struct Client *client_p)
2039 – {
2040 –  struct AccessItem *aconf;
2041 –
2042 –  assert(client_p != NULL);
2043 –
2044 –  aconf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
2045 –                               CONF_GLINE, client_p->localClient->aftype,
2046 –                               client_p->username, NULL, 1);
2047 –  return aconf;
2048 – }
2049 –
2050 – /* add_temp_line()
2051 – *
2052 – * inputs        - pointer to struct ConfItem
2053 – * output        - none
2054 – * Side effects  - links in given struct ConfItem into
2055 – *                 temporary *line link list
2056 – */
2057 – void
2058 – add_temp_line(struct ConfItem *conf)
2059 – {
2060 –  if (conf->type == XLINE_TYPE)
2061 –  {
2062 –    conf->flags |= CONF_FLAGS_TEMPORARY;
2063 –    dlinkAdd(conf, make_dlink_node(), &temporary_xlines);
2064 –  }
2065 –  else if ((conf->type == NRESV_TYPE) || (conf->type == CRESV_TYPE))
2066 –  {
2067 –    conf->flags |= CONF_FLAGS_TEMPORARY;
2068 –    dlinkAdd(conf, make_dlink_node(), &temporary_resv);
2069 –  }
2070 – }
2071 –
1289   /* cleanup_tklines()
1290   *
1291   * inputs       - NONE
# Line 2080 | Line 1297 | void
1297   cleanup_tklines(void *notused)
1298   {
1299    hostmask_expire_temporary();
1300 <  expire_tklines(&temporary_xlines);
1301 <  expire_tklines(&temporary_resv);
1300 >  expire_tklines(&xconf_items);
1301 >  expire_tklines(&nresv_items);
1302 >  expire_tklines(&cresv_items);
1303   }
1304  
1305   /* expire_tklines()
# Line 2093 | Line 1311 | cleanup_tklines(void *notused)
1311   static void
1312   expire_tklines(dlink_list *tklist)
1313   {
1314 <  dlink_node *ptr;
1315 <  dlink_node *next_ptr;
2098 <  struct ConfItem *conf;
2099 <  struct MatchItem *xconf;
2100 <  struct MatchItem *nconf;
2101 <  struct ResvChannel *cconf;
1314 >  dlink_node *ptr = NULL, *ptr_next = NULL;
1315 >  struct MaskItem *conf = NULL;
1316  
1317 <  DLINK_FOREACH_SAFE(ptr, next_ptr, tklist->head)
1317 >  DLINK_FOREACH_SAFE(ptr, ptr_next, tklist->head)
1318    {
1319      conf = ptr->data;
1320  
1321 <    if (conf->type == XLINE_TYPE)
1321 >    if (!conf->until || conf->until > CurrentTime)
1322 >      continue;
1323 >
1324 >    if (conf->type == CONF_XLINE)
1325      {
1326 <      xconf = (struct MatchItem *)map_to_conf(conf);
1327 <      if (xconf->hold <= CurrentTime)
1328 <      {
1329 <        if (ConfigFileEntry.tkline_expire_notices)
2113 <          sendto_realops_flags(UMODE_ALL, L_ALL,
2114 <                               "Temporary X-line for [%s] sexpired", conf->name);
2115 <        dlinkDelete(ptr, tklist);
2116 <        free_dlink_node(ptr);
2117 <        delete_conf_item(conf);
2118 <      }
1326 >      if (ConfigFileEntry.tkline_expire_notices)
1327 >        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1328 >                               "Temporary X-line for [%s] expired", conf->name);
1329 >      conf_free(conf);
1330      }
1331 <    else if (conf->type == NRESV_TYPE)
1331 >    else if (conf->type == CONF_NRESV || conf->type == CONF_CRESV)
1332      {
1333 <      nconf = (struct MatchItem *)map_to_conf(conf);
1334 <      if (nconf->hold <= CurrentTime)
2124 <      {
2125 <        if (ConfigFileEntry.tkline_expire_notices)
2126 <          sendto_realops_flags(UMODE_ALL, L_ALL,
1333 >      if (ConfigFileEntry.tkline_expire_notices)
1334 >        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1335                                 "Temporary RESV for [%s] expired", conf->name);
1336 <        dlinkDelete(ptr, tklist);
2129 <        free_dlink_node(ptr);
2130 <        delete_conf_item(conf);
2131 <      }
2132 <    }
2133 <    else if (conf->type == CRESV_TYPE)
2134 <    {
2135 <      cconf = (struct ResvChannel *)map_to_conf(conf);
2136 <      if (cconf->hold <= CurrentTime)
2137 <      {
2138 <        if (ConfigFileEntry.tkline_expire_notices)
2139 <          sendto_realops_flags(UMODE_ALL, L_ALL,
2140 <                               "Temporary RESV for [%s] expired", cconf->name);
2141 <        delete_channel_resv(cconf);
2142 <      }
1336 >      conf_free(conf);
1337      }
1338    }
1339   }
# Line 2152 | Line 1346 | expire_tklines(dlink_list *tklist)
1346   */
1347   static const struct oper_privs
1348   {
1349 <  const unsigned int oprivs;
1349 >  const unsigned int flag;
1350    const unsigned char c;
1351   } flag_list[] = {
1352 <  { OPER_FLAG_ADMIN,       'A' },
1353 <  { OPER_FLAG_REMOTEBAN,   'B' },
1354 <  { OPER_FLAG_DIE,         'D' },
1355 <  { OPER_FLAG_GLINE,       'G' },
1356 <  { OPER_FLAG_REHASH,      'H' },
1357 <  { OPER_FLAG_K,           'K' },
1358 <  { OPER_FLAG_OPERWALL,    'L' },
1359 <  { OPER_FLAG_N,           'N' },
1360 <  { OPER_FLAG_GLOBAL_KILL, 'O' },
1361 <  { OPER_FLAG_REMOTE,      'R' },
1362 <  { OPER_FLAG_OPER_SPY,    'S' },
1363 <  { OPER_FLAG_UNKLINE,     'U' },
1364 <  { OPER_FLAG_X,           'X' },
1352 >  { OPER_FLAG_ADMIN,          'A' },
1353 >  { OPER_FLAG_REMOTEBAN,      'B' },
1354 >  { OPER_FLAG_DIE,            'D' },
1355 >  { OPER_FLAG_GLINE,          'G' },
1356 >  { OPER_FLAG_REHASH,         'H' },
1357 >  { OPER_FLAG_K,              'K' },
1358 >  { OPER_FLAG_OPERWALL,       'L' },
1359 >  { OPER_FLAG_KILL,           'N' },
1360 >  { OPER_FLAG_KILL_REMOTE,    'O' },
1361 >  { OPER_FLAG_CONNECT,        'P' },
1362 >  { OPER_FLAG_CONNECT_REMOTE, 'Q' },
1363 >  { OPER_FLAG_SQUIT,          'R' },
1364 >  { OPER_FLAG_SQUIT_REMOTE,   'S' },
1365 >  { OPER_FLAG_UNKLINE,        'U' },
1366 >  { OPER_FLAG_XLINE,          'X' },
1367    { 0, '\0' }
1368   };
1369  
1370   char *
1371   oper_privs_as_string(const unsigned int port)
1372   {
1373 <  static char privs_out[16];
1373 >  static char privs_out[IRCD_BUFSIZE];
1374    char *privs_ptr = privs_out;
2179 –  unsigned int i = 0;
1375  
1376 <  for (; flag_list[i].oprivs; ++i)
1376 >  for (const struct oper_privs *opriv = flag_list; opriv->flag; ++opriv)
1377    {
1378 <    if (port & flag_list[i].oprivs)
1379 <      *privs_ptr++ = flag_list[i].c;
1378 >    if (port & opriv->flag)
1379 >      *privs_ptr++ = opriv->c;
1380      else
1381 <      *privs_ptr++ = ToLowerTab[flag_list[i].c];
1381 >      *privs_ptr++ = ToLower(opriv->c);
1382    }
1383  
1384    *privs_ptr = '\0';
# Line 2200 | Line 1395 | oper_privs_as_string(const unsigned int
1395   const char *
1396   get_oper_name(const struct Client *client_p)
1397   {
1398 <  dlink_node *cnode = NULL;
1398 >  const dlink_node *cnode = NULL;
1399    /* +5 for !,@,{,} and null */
1400    static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5];
1401  
# Line 2208 | Line 1403 | get_oper_name(const struct Client *clien
1403    {
1404      if ((cnode = client_p->localClient->confs.head))
1405      {
1406 <      struct ConfItem *conf = cnode->data;
2212 <      const struct AccessItem *aconf = map_to_conf(conf);
1406 >      const struct MaskItem *conf = cnode->data;
1407  
1408 <      if (IsConfOperator(aconf))
1408 >      if (IsConfOperator(conf))
1409        {
1410 <        snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1410 >        snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1411                   client_p->username, client_p->host, conf->name);
1412 <        return buffer;
1412 >        return buffer;
1413        }
1414      }
1415  
1416 <    /* Probably should assert here for now. If there is an oper out there
1416 >    /* Probably should assert here for now. If there is an oper out there
1417       * with no oper{} conf attached, it would be good for us to know...
1418       */
1419      assert(0); /* Oper without oper conf! */
1420    }
1421  
1422    snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1423 <           client_p->username, client_p->host, client_p->servptr->name);
1423 >           client_p->username, client_p->host, client_p->servptr->name);
1424    return buffer;
1425   }
1426  
# Line 2240 | Line 1434 | void
1434   read_conf_files(int cold)
1435   {
1436    const char *filename;
1437 <  char chanmodes[32];
1438 <  char chanlimit[32];
1437 >  char chanmodes[IRCD_BUFSIZE];
1438 >  char chanlimit[IRCD_BUFSIZE];
1439  
1440    conf_parser_ctx.boot = cold;
1441 <  filename = get_conf_name(CONF_TYPE);
1441 >  filename = ConfigFileEntry.configfile;
1442  
1443    /* We need to know the initial filename for the yyerror() to report
1444       FIXME: The full path is in conffilenamebuf first time since we
1445               dont know anything else
1446  
1447 <     - Gozem 2002-07-21
1447 >     - Gozem 2002-07-21
1448    */
1449    strlcpy(conffilebuf, filename, sizeof(conffilebuf));
1450  
# Line 2264 | Line 1458 | read_conf_files(int cold)
1458      }
1459      else
1460      {
1461 <      sendto_realops_flags(UMODE_ALL, L_ALL,
1462 <                           "Unable to read configuration file '%s': %s",
1463 <                           filename, strerror(errno));
1461 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1462 >                           "Unable to read configuration file '%s': %s",
1463 >                           filename, strerror(errno));
1464        return;
1465      }
1466    }
# Line 2277 | Line 1471 | read_conf_files(int cold)
1471    read_conf(conf_parser_ctx.conf_file);
1472    fclose(conf_parser_ctx.conf_file);
1473  
1474 +  log_reopen_all();
1475 +
1476 +  add_isupport("NICKLEN", NULL, ServerInfo.max_nick_length);
1477    add_isupport("NETWORK", ServerInfo.network_name, -1);
1478 <  snprintf(chanmodes, sizeof(chanmodes), "beI:%d",
1479 <           ConfigChannel.max_bans);
1478 >
1479 >  snprintf(chanmodes, sizeof(chanmodes), "beI:%d", ConfigChannel.max_bans);
1480    add_isupport("MAXLIST", chanmodes, -1);
1481    add_isupport("MAXTARGETS", NULL, ConfigFileEntry.max_targets);
2285 –
1482    add_isupport("CHANTYPES", "#", -1);
1483  
1484    snprintf(chanlimit, sizeof(chanlimit), "#:%d",
1485 <           ConfigChannel.max_chans_per_user);
1485 >           ConfigChannel.max_chans_per_user);
1486    add_isupport("CHANLIMIT", chanlimit, -1);
1487 <  snprintf(chanmodes, sizeof(chanmodes), "%s",
2292 <           "beI,k,l,imnprstORS");
1487 >  snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,imnprstORS");
1488    add_isupport("CHANNELLEN", NULL, LOCAL_CHANNELLEN);
1489 <
2295 <  add_isupport("EXCEPTS", "e", -1);
2296 <  add_isupport("INVEX", "I", -1);
1489 >  add_isupport("TOPICLEN", NULL, ServerInfo.max_topic_length);
1490    add_isupport("CHANMODES", chanmodes, -1);
1491  
1492    /*
# Line 2301 | Line 1494 | read_conf_files(int cold)
1494     * on strlen(form_str(RPL_ISUPPORT))
1495     */
1496    rebuild_isupport_message_line();
2304 –
2305 – #ifdef HAVE_LIBPCRE
2306 –  parse_conf_file(RKLINE_TYPE, cold);
2307 –  parse_conf_file(RXLINE_TYPE, cold);
2308 – #endif
2309 –  parse_conf_file(KLINE_TYPE, cold);
2310 –  parse_conf_file(DLINE_TYPE, cold);
2311 –  parse_conf_file(XLINE_TYPE, cold);
2312 –  parse_conf_file(NRESV_TYPE, cold);
2313 –  parse_conf_file(CRESV_TYPE, cold);
2314 – }
2315 –
2316 – /* parse_conf_file()
2317 – *
2318 – * inputs       - type of conf file to parse
2319 – * output       - none
2320 – * side effects - conf file for givenconf type is opened and read then parsed
2321 – */
2322 – static void
2323 – parse_conf_file(int type, int cold)
2324 – {
2325 –  FILE *file = NULL;
2326 –  const char *filename = get_conf_name(type);
2327 –
2328 –  if ((file = fopen(filename, "r")) == NULL)
2329 –  {
2330 –    if (cold)
2331 –      ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
2332 –           filename, strerror(errno));
2333 –    else
2334 –      sendto_realops_flags(UMODE_ALL, L_ALL,
2335 –                    "Unable to read configuration file '%s': %s",
2336 –                           filename, strerror(errno));
2337 –  }
2338 –  else
2339 –  {
2340 –    parse_csv_file(file, type);
2341 –    fclose(file);
2342 –  }
1497   }
1498  
1499   /* clear_out_old_conf()
# Line 2352 | Line 1506 | static void
1506   clear_out_old_conf(void)
1507   {
1508    dlink_node *ptr = NULL, *next_ptr = NULL;
1509 <  struct ConfItem *conf;
2356 <  struct AccessItem *aconf;
2357 <  struct ClassItem *cltmp;
2358 <  struct MatchItem *match_item;
1509 >  struct MaskItem *conf;
1510    dlink_list *free_items [] = {
1511      &server_items,   &oconf_items,
1512 <     &uconf_items,   &xconf_items, &rxconf_items, &rkconf_items,
1513 <     &nresv_items, &cluster_items,  &service_items, NULL
1512 >     &uconf_items,   &xconf_items,
1513 >     &nresv_items, &cluster_items,  &service_items, &cresv_items, NULL
1514    };
1515  
1516    dlink_list ** iterator = free_items; /* C is dumb */
# Line 2367 | Line 1518 | clear_out_old_conf(void)
1518    /* We only need to free anything allocated by yyparse() here.
1519     * Resetting structs, etc, is taken care of by set_default_conf().
1520     */
1521 <  
1521 >
1522    for (; *iterator != NULL; iterator++)
1523    {
1524      DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head)
1525      {
1526        conf = ptr->data;
2376 –      /* XXX This is less than pretty */
2377 –      if (conf->type == SERVER_TYPE)
2378 –      {
2379 –        aconf = map_to_conf(conf);
1527  
1528 <        if (aconf->clients != 0)
2382 <        {
2383 <          SetConfIllegal(aconf);
2384 <          dlinkDelete(&conf->node, &server_items);
2385 <        }
2386 <        else
2387 <        {
2388 <          delete_conf_item(conf);
2389 <        }
2390 <      }
2391 <      else if (conf->type == OPER_TYPE)
2392 <      {
2393 <        aconf = map_to_conf(conf);
1528 >      dlinkDelete(&conf->node, map_to_list(conf->type));
1529  
1530 <        if (aconf->clients != 0)
1531 <        {
2397 <          SetConfIllegal(aconf);
2398 <          dlinkDelete(&conf->node, &oconf_items);
2399 <        }
2400 <        else
2401 <        {
2402 <          delete_conf_item(conf);
2403 <        }
2404 <      }
2405 <      else if (conf->type == XLINE_TYPE  ||
2406 <               conf->type == RXLINE_TYPE ||
2407 <               conf->type == RKLINE_TYPE)
1530 >      /* XXX This is less than pretty */
1531 >      if (conf->type == CONF_SERVER || conf->type == CONF_OPER)
1532        {
1533 <        /* temporary (r)xlines are also on
1534 <         * the (r)xconf items list */
2411 <        if (conf->flags & CONF_FLAGS_TEMPORARY)
2412 <          continue;
2413 <
2414 <        delete_conf_item(conf);
1533 >        if (!conf->ref_count)
1534 >          conf_free(conf);
1535        }
1536 <      else
1536 >      else if (conf->type == CONF_XLINE)
1537        {
1538 <          delete_conf_item(conf);
1538 >        if (!conf->until)
1539 >          conf_free(conf);
1540        }
1541 +      else
1542 +        conf_free(conf);
1543      }
1544    }
1545  
1546 +  motd_clear();
1547 +
1548    /*
1549     * don't delete the class table, rather mark all entries
1550 <   * for deletion. The table is cleaned up by check_class. - avalon
1550 >   * for deletion. The table is cleaned up by class_delete_marked. - avalon
1551     */
1552 <  DLINK_FOREACH(ptr, class_items.head)
2428 <  {
2429 <    cltmp = map_to_conf(ptr->data);
2430 <
2431 <    if (ptr != class_items.tail)  /* never mark the "default" class */
2432 <      cltmp->active = 0;
2433 <  }
1552 >  class_mark_for_deletion();
1553  
1554    clear_out_address_conf();
1555  
# Line 2447 | Line 1566 | clear_out_old_conf(void)
1566    MyFree(ConfigFileEntry.egdpool_path);
1567    ConfigFileEntry.egdpool_path = NULL;
1568   #ifdef HAVE_LIBCRYPTO
1569 <  if (ServerInfo.rsa_private_key != NULL)
1569 >  if (ServerInfo.rsa_private_key)
1570    {
1571      RSA_free(ServerInfo.rsa_private_key);
1572      ServerInfo.rsa_private_key = NULL;
# Line 2466 | Line 1585 | clear_out_old_conf(void)
1585                                                 SSL_OP_NO_TLSv1);
1586   #endif
1587  
2469 –  /* clean out old resvs from the conf */
2470 –  clear_conf_resv();
2471 –
1588    /* clean out AdminInfo */
1589    MyFree(AdminInfo.name);
1590    AdminInfo.name = NULL;
# Line 2477 | Line 1593 | clear_out_old_conf(void)
1593    MyFree(AdminInfo.description);
1594    AdminInfo.description = NULL;
1595  
2480 –  /* operator{} and class{} blocks are freed above */
1596    /* clean out listeners */
1597    close_listeners();
1598  
2484 –  /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{},
2485 –   * exempt{} and gecos{} blocks are freed above too
2486 –   */
2487 –
1599    /* clean out general */
1600    MyFree(ConfigFileEntry.service_name);
1601    ConfigFileEntry.service_name = NULL;
2491 –
2492 –  delete_isupport("INVEX");
2493 –  delete_isupport("EXCEPTS");
2494 – }
2495 –
2496 – /* flush_deleted_I_P()
2497 – *
2498 – * inputs       - none
2499 – * output       - none
2500 – * side effects - This function removes I/P conf items
2501 – */
2502 – static void
2503 – flush_deleted_I_P(void)
2504 – {
2505 –  dlink_node *ptr;
2506 –  dlink_node *next_ptr;
2507 –  struct ConfItem *conf;
2508 –  struct AccessItem *aconf;
2509 –  dlink_list * free_items [] = {
2510 –    &server_items, &oconf_items, NULL
2511 –  };
2512 –  dlink_list ** iterator = free_items; /* C is dumb */
2513 –
2514 –  /* flush out deleted I and P lines
2515 –   * although still in use.
2516 –   */
2517 –  for (; *iterator != NULL; iterator++)
2518 –  {
2519 –    DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head)
2520 –    {
2521 –      conf = ptr->data;
2522 –      aconf = (struct AccessItem *)map_to_conf(conf);
2523 –
2524 –      if (IsConfIllegal(aconf))
2525 –      {
2526 –        dlinkDelete(ptr, *iterator);
2527 –
2528 –        if (aconf->clients == 0)
2529 –          delete_conf_item(conf);
2530 –      }
2531 –    }
2532 –  }
2533 – }
2534 –
2535 – /* get_conf_name()
2536 – *
2537 – * inputs       - type of conf file to return name of file for
2538 – * output       - pointer to filename for type of conf
2539 – * side effects - none
2540 – */
2541 – const char *
2542 – get_conf_name(ConfType type)
2543 – {
2544 –  switch (type)
2545 –  {
2546 –    case CONF_TYPE:
2547 –      return ConfigFileEntry.configfile;
2548 –      break;
2549 –    case KLINE_TYPE:
2550 –      return ConfigFileEntry.klinefile;
2551 –      break;
2552 –    case RKLINE_TYPE:
2553 –      return ConfigFileEntry.rklinefile;
2554 –      break;
2555 –    case DLINE_TYPE:
2556 –      return ConfigFileEntry.dlinefile;
2557 –      break;
2558 –    case XLINE_TYPE:
2559 –      return ConfigFileEntry.xlinefile;
2560 –      break;
2561 –    case RXLINE_TYPE:
2562 –      return ConfigFileEntry.rxlinefile;
2563 –      break;
2564 –    case CRESV_TYPE:
2565 –      return ConfigFileEntry.cresvfile;
2566 –      break;
2567 –    case NRESV_TYPE:
2568 –      return ConfigFileEntry.nresvfile;
2569 –      break;
2570 –    case GLINE_TYPE:
2571 –      return ConfigFileEntry.glinefile;
2572 –      break;
2573 –
2574 –    default:
2575 –      return NULL;  /* This should NEVER HAPPEN since we call this function
2576 –                       only with the above values, this will cause us to core
2577 –                       at some point if this happens so we know where it was */
2578 –  }
2579 – }
2580 –
2581 – #define BAD_PING (-1)
2582 –
2583 – /* get_conf_ping()
2584 – *
2585 – * inputs       - pointer to struct AccessItem
2586 – *              - pointer to a variable that receives ping warning time
2587 – * output       - ping frequency
2588 – * side effects - NONE
2589 – */
2590 – static int
2591 – get_conf_ping(struct ConfItem *conf, int *pingwarn)
2592 – {
2593 –  struct ClassItem *aclass;
2594 –  struct AccessItem *aconf;
2595 –
2596 –  if (conf != NULL)
2597 –  {
2598 –    aconf = (struct AccessItem *)map_to_conf(conf);
2599 –    if (aconf->class_ptr != NULL)
2600 –    {
2601 –      aclass = (struct ClassItem *)map_to_conf(aconf->class_ptr);
2602 –      *pingwarn = aclass->ping_warning;
2603 –      return aclass->ping_freq;
2604 –    }
2605 –  }
2606 –
2607 –  return BAD_PING;
2608 – }
2609 –
2610 – /* get_client_class()
2611 – *
2612 – * inputs       - pointer to client struct
2613 – * output       - pointer to name of class
2614 – * side effects - NONE
2615 – */
2616 – const char *
2617 – get_client_class(struct Client *target_p)
2618 – {
2619 –  dlink_node *cnode = NULL;
2620 –  struct AccessItem *aconf = NULL;
2621 –
2622 –  assert(!IsMe(target_p));
2623 –
2624 –  if ((cnode = target_p->localClient->confs.head))
2625 –  {
2626 –    struct ConfItem *conf = cnode->data;
2627 –
2628 –    assert((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2629 –          (conf->type == OPER_TYPE));
2630 –
2631 –    aconf = map_to_conf(conf);
2632 –    if (aconf->class_ptr != NULL)
2633 –      return aconf->class_ptr->name;
2634 –  }
2635 –
2636 –  return "default";
2637 – }
2638 –
2639 – /* get_client_ping()
2640 – *
2641 – * inputs       - pointer to client struct
2642 – *              - pointer to a variable that receives ping warning time
2643 – * output       - ping frequency
2644 – * side effects - NONE
2645 – */
2646 – int
2647 – get_client_ping(struct Client *target_p, int *pingwarn)
2648 – {
2649 –  int ping = 0;
2650 –  dlink_node *cnode = NULL;
2651 –
2652 –  if ((cnode = target_p->localClient->confs.head))
2653 –  {
2654 –    struct ConfItem *conf = cnode->data;
2655 –
2656 –    assert((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2657 –          (conf->type == OPER_TYPE));
2658 –
2659 –    ping = get_conf_ping(conf, pingwarn);
2660 –    if (ping > 0)
2661 –      return ping;
2662 –  }
2663 –
2664 –  *pingwarn = 0;
2665 –  return DEFAULT_PINGFREQUENCY;
2666 – }
2667 –
2668 – /* find_class()
2669 – *
2670 – * inputs       - string name of class
2671 – * output       - corresponding Class pointer
2672 – * side effects - NONE
2673 – */
2674 – struct ConfItem *
2675 – find_class(const char *classname)
2676 – {
2677 –  struct ConfItem *conf;
2678 –
2679 –  if ((conf = find_exact_name_conf(CLASS_TYPE, NULL, classname, NULL, NULL)) != NULL)
2680 –    return conf;
2681 –
2682 –  return class_default;
2683 – }
2684 –
2685 – /* check_class()
2686 – *
2687 – * inputs       - NONE
2688 – * output       - NONE
2689 – * side effects -
2690 – */
2691 – void
2692 – check_class(void)
2693 – {
2694 –  dlink_node *ptr = NULL, *next_ptr = NULL;
2695 –
2696 –  DLINK_FOREACH_SAFE(ptr, next_ptr, class_items.head)
2697 –  {
2698 –    struct ClassItem *aclass = map_to_conf(ptr->data);
2699 –
2700 –    if (!aclass->active && !aclass->curr_user_count)
2701 –    {
2702 –      destroy_cidr_class(aclass);
2703 –      delete_conf_item(ptr->data);
2704 –    }
2705 –  }
2706 – }
2707 –
2708 – /* init_class()
2709 – *
2710 – * inputs       - NONE
2711 – * output       - NONE
2712 – * side effects -
2713 – */
2714 – void
2715 – init_class(void)
2716 – {
2717 –  struct ClassItem *aclass;
2718 –
2719 –  class_default = make_conf_item(CLASS_TYPE);
2720 –
2721 –  aclass = map_to_conf(class_default);
2722 –  aclass->active = 1;
2723 –  DupString(class_default->name, "default");
2724 –  aclass->con_freq  = DEFAULT_CONNECTFREQUENCY;
2725 –  aclass->ping_freq = DEFAULT_PINGFREQUENCY;
2726 –  aclass->max_total = MAXIMUM_LINKS_DEFAULT;
2727 –  aclass->max_sendq = DEFAULT_SENDQ;
2728 –
2729 –  client_check_cb = register_callback("check_client", check_client);
2730 – }
2731 –
2732 – /* get_sendq()
2733 – *
2734 – * inputs       - pointer to client
2735 – * output       - sendq for this client as found from its class
2736 – * side effects - NONE
2737 – */
2738 – unsigned int
2739 – get_sendq(struct Client *client_p)
2740 – {
2741 –  unsigned int sendq = DEFAULT_SENDQ;
2742 –  dlink_node *cnode;
2743 –  struct ConfItem *class_conf;
2744 –  struct ClassItem *aclass;
2745 –  struct AccessItem *aconf;
2746 –
2747 –  assert(!IsMe(client_p));
2748 –
2749 –  if ((cnode = client_p->localClient->confs.head))
2750 –  {
2751 –    struct ConfItem *conf = cnode->data;
2752 –
2753 –    assert((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2754 –          (conf->type == OPER_TYPE));
2755 –
2756 –    aconf = map_to_conf(conf);
2757 –
2758 –    if ((class_conf = aconf->class_ptr) == NULL)
2759 –      return DEFAULT_SENDQ; /* TBV: shouldn't be possible at all */
2760 –
2761 –    aclass = map_to_conf(class_conf);
2762 –    sendq = aclass->max_sendq;
2763 –    return sendq;
2764 –  }
2765 –
2766 –  /* XXX return a default?
2767 –   * if here, then there wasn't an attached conf with a sendq
2768 –   * that is very bad -Dianora
2769 –   */
2770 –  return DEFAULT_SENDQ;
1602   }
1603  
1604   /* conf_add_class_to_conf()
1605   *
1606   * inputs       - pointer to config item
1607   * output       - NONE
1608 < * side effects - Add a class pointer to a conf
1608 > * side effects - Add a class pointer to a conf
1609   */
1610   void
1611 < conf_add_class_to_conf(struct ConfItem *conf, const char *class_name)
1611 > conf_add_class_to_conf(struct MaskItem *conf, const char *class_name)
1612   {
1613 <  struct AccessItem *aconf = map_to_conf(conf);
2783 <  struct ClassItem *class = NULL;
2784 <
2785 <  if (class_name == NULL)
1613 >  if (class_name == NULL)
1614    {
1615 <    aconf->class_ptr = class_default;
1615 >    conf->class = class_default;
1616  
1617 <    if (conf->type == CLIENT_TYPE)
1618 <      sendto_realops_flags(UMODE_ALL, L_ALL,
1619 <                           "Warning *** Defaulting to default class for %s@%s",
1620 <                           aconf->user, aconf->host);
1617 >    if (conf->type == CONF_CLIENT)
1618 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1619 >                           "Warning *** Defaulting to default class for %s@%s",
1620 >                           conf->user, conf->host);
1621      else
1622 <      sendto_realops_flags(UMODE_ALL, L_ALL,
1623 <                           "Warning *** Defaulting to default class for %s",
1624 <                           conf->name);
1622 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1623 >                           "Warning *** Defaulting to default class for %s",
1624 >                           conf->name);
1625    }
1626    else
1627 <    aconf->class_ptr = find_class(class_name);
1627 >    conf->class = class_find(class_name, 1);
1628  
1629 <  if (aconf->class_ptr)
2802 <    class = map_to_conf(aconf->class_ptr);
2803 <
2804 <  if (aconf->class_ptr == NULL || !class->active)
1629 >  if (conf->class == NULL)
1630    {
1631 <    if (conf->type == CLIENT_TYPE)
1632 <      sendto_realops_flags(UMODE_ALL, L_ALL,
1633 <                           "Warning *** Defaulting to default class for %s@%s",
1634 <                           aconf->user, aconf->host);
1631 >    if (conf->type == CONF_CLIENT)
1632 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1633 >                           "Warning *** Defaulting to default class for %s@%s",
1634 >                           conf->user, conf->host);
1635      else
1636 <      sendto_realops_flags(UMODE_ALL, L_ALL,
1637 <                           "Warning *** Defaulting to default class for %s",
1638 <                           conf->name);
1639 <    aconf->class_ptr = class_default;
1636 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1637 >                           "Warning *** Defaulting to default class for %s",
1638 >                           conf->name);
1639 >    conf->class = class_default;
1640    }
1641   }
1642  
2818 – /* conf_add_server()
2819 – *
2820 – * inputs       - pointer to config item
2821 – *              - pointer to link count already on this conf
2822 – * output       - NONE
2823 – * side effects - Add a connect block
2824 – */
2825 – int
2826 – conf_add_server(struct ConfItem *conf, const char *class_name)
2827 – {
2828 –  struct AccessItem *aconf = map_to_conf(conf);
2829 –
2830 –  conf_add_class_to_conf(conf, class_name);
2831 –
2832 –  if (!aconf->host || !conf->name)
2833 –  {
2834 –    sendto_realops_flags(UMODE_ALL, L_ALL, "Bad connect block");
2835 –    ilog(LOG_TYPE_IRCD, "Bad connect block");
2836 –    return -1;
2837 –  }
2838 –
2839 –  if (EmptyString(aconf->passwd))
2840 –  {
2841 –    sendto_realops_flags(UMODE_ALL, L_ALL, "Bad connect block, name %s",
2842 –                         conf->name);
2843 –    ilog(LOG_TYPE_IRCD, "Bad connect block, host %s", conf->name);
2844 –    return -1;
2845 –  }
2846 –
2847 –  lookup_confhost(conf);
2848 –
2849 –  return 0;
2850 – }
2851 –
1643   /* yyerror()
1644   *
1645   * inputs       - message from parser
# Line 2864 | Line 1655 | yyerror(const char *msg)
1655      return;
1656  
1657    strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1658 <  sendto_realops_flags(UMODE_ALL, L_ALL, "\"%s\", line %u: %s: %s",
1658 >  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1659 >                       "\"%s\", line %u: %s: %s",
1660 >                       conffilebuf, lineno + 1, msg, newlinebuf);
1661 >  ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1662 >       conffilebuf, lineno + 1, msg, newlinebuf);
1663 > }
1664 >
1665 > void
1666 > conf_error_report(const char *msg)
1667 > {
1668 >  char newlinebuf[IRCD_BUFSIZE];
1669 >
1670 >  strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1671 >  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1672 >                       "\"%s\", line %u: %s: %s",
1673                         conffilebuf, lineno + 1, msg, newlinebuf);
1674    ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1675         conffilebuf, lineno + 1, msg, newlinebuf);
# Line 2872 | Line 1677 | yyerror(const char *msg)
1677  
1678   /*
1679   * valid_tkline()
1680 < *
1680 > *
1681   * inputs       - pointer to ascii string to check
1682   *              - whether the specified time is in seconds or minutes
1683   * output       - -1 not enough parameters
# Line 2881 | Line 1686 | yyerror(const char *msg)
1686   * Originally written by Dianora (Diane, db@db.net)
1687   */
1688   time_t
1689 < valid_tkline(const char *p, int minutes)
1689 > valid_tkline(const char *data, const int minutes)
1690   {
1691 +  const unsigned char *p = (const unsigned char *)data;
1692 +  unsigned char tmpch = '\0';
1693    time_t result = 0;
1694  
1695 <  for (; *p; ++p)
1695 >  while ((tmpch = *p++))
1696    {
1697 <    if (!IsDigit(*p))
1697 >    if (!IsDigit(tmpch))
1698        return 0;
1699  
1700      result *= 10;
1701 <    result += ((*p) & 0xF);
1701 >    result += (tmpch & 0xF);
1702    }
1703  
1704    /*
1705 <   * In the degenerate case where oper does a /quote kline 0 user@host :reason
1705 >   * In the degenerate case where oper does a /quote kline 0 user@host :reason
1706     * i.e. they specifically use 0, I am going to return 1 instead
1707     * as a return value of non-zero is used to flag it as a temporary kline
1708     */
1709    if (result == 0)
1710      result = 1;
1711  
1712 <  /*
1712 >  /*
1713     * If the incoming time is in seconds convert it to minutes for the purpose
1714     * of this calculation
1715     */
1716    if (!minutes)
1717 <    result = result / (time_t)60;
1717 >    result = result / 60;
1718  
1719    if (result > MAX_TDKLINE_TIME)
1720      result = MAX_TDKLINE_TIME;
1721  
1722 <  result = result * (time_t)60;  /* turn it into seconds */
1722 >  result = result * 60;  /* turn it into seconds */
1723  
1724    return result;
1725   }
1726  
1727 + /* valid_wild_card_simple()
1728 + *
1729 + * inputs       - data to check for sufficient non-wildcard characters
1730 + * outputs      - 1 if valid, else 0
1731 + * side effects - none
1732 + */
1733 + int
1734 + valid_wild_card_simple(const char *data)
1735 + {
1736 +  const unsigned char *p = (const unsigned char *)data;
1737 +  unsigned char tmpch = '\0';
1738 +  int nonwild = 0;
1739 +
1740 +  while ((tmpch = *p++))
1741 +  {
1742 +    if (tmpch == '\\')
1743 +    {
1744 +      ++p;
1745 +      if (++nonwild >= ConfigFileEntry.min_nonwildcard_simple)
1746 +        return 1;
1747 +    }
1748 +    else if (!IsMWildChar(tmpch))
1749 +    {
1750 +      if (++nonwild >= ConfigFileEntry.min_nonwildcard_simple)
1751 +        return 1;
1752 +    }
1753 +  }
1754 +
1755 +  return 0;
1756 + }
1757 +
1758   /* valid_wild_card()
1759   *
1760   * input        - pointer to client
# Line 2928 | Line 1766 | valid_tkline(const char *p, int minutes)
1766   int
1767   valid_wild_card(struct Client *source_p, int warn, int count, ...)
1768   {
2931 –  char *p;
1769    char tmpch;
1770    int nonwild = 0;
1771    va_list args;
# Line 2949 | Line 1786 | valid_wild_card(struct Client *source_p,
1786  
1787    while (count--)
1788    {
1789 <    p = va_arg(args, char *);
1789 >    const char *p = va_arg(args, const char *);
1790      if (p == NULL)
1791        continue;
1792  
# Line 2962 | Line 1799 | valid_wild_card(struct Client *source_p,
1799           * break - no point in searching further.
1800           */
1801          if (++nonwild >= ConfigFileEntry.min_nonwildcard)
1802 +        {
1803 +          va_end(args);
1804            return 1;
1805 +        }
1806        }
1807      }
1808    }
1809  
1810    if (warn)
1811 <    sendto_one(source_p, ":%s NOTICE %s :Please include at least %d non-wildcard characters with the mask",
1812 <               me.name, source_p->name, ConfigFileEntry.min_nonwildcard);
1811 >    sendto_one_notice(source_p, &me,
1812 >                      ":Please include at least %d non-wildcard characters with the mask",
1813 >                      ConfigFileEntry.min_nonwildcard);
1814 >  va_end(args);
1815    return 0;
1816   }
1817  
# Line 2983 | Line 1825 | valid_wild_card(struct Client *source_p,
1825   *              - parse_flags bit map of things to test
1826   *              - pointer to user or string to parse into
1827   *              - pointer to host or NULL to parse into if non NULL
1828 < *              - pointer to optional tkline time or NULL
1828 > *              - pointer to optional tkline time or NULL
1829   *              - pointer to target_server to parse into if non NULL
1830   *              - pointer to reason to parse into
1831   *
# Line 3005 | Line 1847 | valid_wild_card(struct Client *source_p,
1847   */
1848   int
1849   parse_aline(const char *cmd, struct Client *source_p,
1850 <            int parc, char **parv,
1851 <            int parse_flags, char **up_p, char **h_p, time_t *tkline_time,
1852 <            char **target_server, char **reason)
1850 >            int parc, char **parv,
1851 >            int parse_flags, char **up_p, char **h_p, time_t *tkline_time,
1852 >            char **target_server, char **reason)
1853   {
1854    int found_tkline_time=0;
1855    static char def_reason[] = "No Reason";
# Line 3028 | Line 1870 | parse_aline(const char *cmd, struct Clie
1870        *tkline_time = found_tkline_time;
1871      else
1872      {
1873 <      sendto_one(source_p, ":%s NOTICE %s :temp_line not supported by %s",
3032 <                 me.name, source_p->name, cmd);
1873 >      sendto_one_notice(source_p, &me, ":temp_line not supported by %s", cmd);
1874        return -1;
1875      }
1876    }
1877  
1878    if (parc == 0)
1879    {
1880 <    sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
3040 <               me.name, source_p->name, cmd);
1880 >    sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1881      return -1;
1882    }
1883  
# Line 3051 | Line 1891 | parse_aline(const char *cmd, struct Clie
1891      *up_p = user;
1892      *h_p = host;
1893    }
1894 <
1894 >
1895    parc--;
1896    parv++;
1897  
# Line 3064 | Line 1904 | parse_aline(const char *cmd, struct Clie
1904  
1905        if (target_server == NULL)
1906        {
1907 <        sendto_one(source_p, ":%s NOTICE %s :ON server not supported by %s",
1908 <                   me.name, source_p->name, cmd);
3069 <        return -1;
1907 >        sendto_one_notice(source_p, &me, ":ON server not supported by %s", cmd);
1908 >        return -1;
1909        }
1910  
1911        if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN))
1912        {
1913 <        sendto_one(source_p, form_str(ERR_NOPRIVS),
3075 <                   me.name, source_p->name, "remoteban");
1913 >        sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "remoteban");
1914          return -1;
1915        }
1916  
1917        if (parc == 0 || EmptyString(*parv))
1918        {
1919 <        sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1920 <                   me.name, source_p->name, cmd);
3083 <        return -1;
1919 >        sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1920 >        return -1;
1921        }
1922  
1923        *target_server = *parv;
# Line 3093 | Line 1930 | parse_aline(const char *cmd, struct Clie
1930         * caller probably NULL'd it first, but no harm to do it again -db
1931         */
1932        if (target_server != NULL)
1933 <        *target_server = NULL;
1933 >        *target_server = NULL;
1934      }
1935    }
1936  
# Line 3101 | Line 1938 | parse_aline(const char *cmd, struct Clie
1938    {
1939      if (strchr(user, '!') != NULL)
1940      {
1941 <      sendto_one(source_p, ":%s NOTICE %s :Invalid character '!' in kline",
3105 <                 me.name, source_p->name);
1941 >      sendto_one_notice(source_p, &me, ":Invalid character '!' in kline");
1942        return -1;
1943      }
1944  
# Line 3119 | Line 1955 | parse_aline(const char *cmd, struct Clie
1955      {
1956        *reason = *parv;
1957        if (!valid_comment(source_p, *reason, 1))
1958 <        return -1;
1958 >        return -1;
1959      }
1960      else
1961        *reason = def_reason;
# Line 3158 | Line 1994 | find_user_host(struct Client *source_p,
1994      {
1995        *(hostp++) = '\0';                       /* short and squat */
1996        if (*user_host_or_nick)
1997 <        strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
1997 >        strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
1998        else
1999 <        strcpy(luser, "*");
1999 >        strcpy(luser, "*");
2000 >
2001        if (*hostp)
2002 <        strlcpy(lhost, hostp, HOSTLEN + 1);    /* here is my host */
2002 >        strlcpy(lhost, hostp, HOSTLEN + 1);    /* here is my host */
2003        else
2004 <        strcpy(lhost, "*");
2004 >        strcpy(lhost, "*");
2005      }
2006      else
2007      {
2008        luser[0] = '*';             /* no @ found, assume its *@somehost */
2009 <      luser[1] = '\0';    
2009 >      luser[1] = '\0';
2010        strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
2011      }
2012 <    
2012 >
2013      return 1;
2014    }
2015 <  else if (!(flags & NOUSERLOOKUP))
2015 >  else
2016    {
2017      /* Try to find user@host mask from nick */
2018      /* Okay to use source_p as the first param, because source_p == client_p */
2019 <    if ((target_p =
2020 <        find_chasing(source_p, source_p, user_host_or_nick, NULL)) == NULL)
2019 >    if ((target_p =
2020 >        find_chasing(source_p, user_host_or_nick)) == NULL)
2021        return 0;
2022  
2023      if (IsExemptKline(target_p))
2024      {
2025        if (!IsServer(source_p))
2026 <        sendto_one(source_p,
3190 <                   ":%s NOTICE %s :%s is E-lined",
3191 <                   me.name, source_p->name, target_p->name);
2026 >        sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
2027        return 0;
2028      }
2029  
# Line 3223 | Line 2058 | find_user_host(struct Client *source_p,
2058   int
2059   valid_comment(struct Client *source_p, char *comment, int warn)
2060   {
3226 –  if (strchr(comment, '"'))
3227 –  {
3228 –    if (warn)
3229 –      sendto_one(source_p, ":%s NOTICE %s :Invalid character '\"' in comment",
3230 –                 me.name, source_p->name);
3231 –    return 0;
3232 –  }
3233 –
2061    if (strlen(comment) > REASONLEN)
2062      comment[REASONLEN-1] = '\0';
2063  
# Line 3245 | Line 2072 | valid_comment(struct Client *source_p, c
2072   * side effects - none
2073   */
2074   int
2075 < match_conf_password(const char *password, const struct AccessItem *aconf)
2075 > match_conf_password(const char *password, const struct MaskItem *conf)
2076   {
2077    const char *encr = NULL;
2078  
2079 <  if (EmptyString(password) || EmptyString(aconf->passwd))
2079 >  if (EmptyString(password) || EmptyString(conf->passwd))
2080      return 0;
2081  
2082 <  if (aconf->flags & CONF_FLAGS_ENCRYPTED)
2083 <    encr = crypt(password, aconf->passwd);
2082 >  if (conf->flags & CONF_FLAGS_ENCRYPTED)
2083 >    encr = crypt(password, conf->passwd);
2084    else
2085      encr = password;
2086  
2087 <  return !strcmp(encr, aconf->passwd);
2087 >  return encr && !strcmp(encr, conf->passwd);
2088   }
2089  
2090   /*
# Line 3265 | Line 2092 | match_conf_password(const char *password
2092   *
2093   * inputs       - client sending the cluster
2094   *              - command name "KLINE" "XLINE" etc.
2095 < *              - capab -- CAP_KLN etc. from s_serv.h
2095 > *              - capab -- CAP_KLN etc. from server.h
2096   *              - cluster type -- CLUSTER_KLINE etc. from conf.h
2097   *              - pattern and args to send along
2098   * output       - none
# Line 3286 | Line 2113 | cluster_a_line(struct Client *source_p,
2113  
2114    DLINK_FOREACH(ptr, cluster_items.head)
2115    {
2116 <    const struct ConfItem *conf = ptr->data;
2116 >    const struct MaskItem *conf = ptr->data;
2117  
2118      if (conf->flags & cluster_type)
2119        sendto_match_servs(source_p, conf->name, CAP_CLUSTER|capab,
2120 <                         "%s %s %s", command, conf->name, buffer);
2120 >                         "%s %s %s", command, conf->name, buffer);
2121    }
2122   }
2123  
# Line 3341 | Line 2168 | split_nuh(struct split_nuh_item *const i
2168      if (iptr->nickptr && *iptr->nuhmask != '\0')
2169        strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
2170  
2171 <    if ((q = strchr(++p, '@'))) {
2171 >    if ((q = strchr(++p, '@')))
2172 >    {
2173        *q++ = '\0';
2174  
2175        if (*p != '\0')
# Line 3380 | Line 2208 | split_nuh(struct split_nuh_item *const i
2208      }
2209    }
2210   }
3383 –
3384 – /*
3385 – * flags_to_ascii
3386 – *
3387 – * inputs       - flags is a bitmask
3388 – *              - pointer to table of ascii letters corresponding
3389 – *                to each bit
3390 – *              - flag 1 for convert ToLower if bit missing
3391 – *                0 if ignore.
3392 – * output       - none
3393 – * side effects - string pointed to by p has bitmap chars written to it
3394 – */
3395 – static void
3396 – flags_to_ascii(unsigned int flags, const unsigned int bit_table[], char *p,
3397 –               int lowerit)
3398 – {
3399 –  unsigned int mask = 1;
3400 –  int i = 0;
3401 –
3402 –  for (mask = 1; (mask != 0) && (bit_table[i] != 0); mask <<= 1, i++)
3403 –  {
3404 –    if (flags & mask)
3405 –      *p++ = bit_table[i];
3406 –    else if (lowerit)
3407 –      *p++ = ToLower(bit_table[i]);
3408 –  }
3409 –  *p = '\0';
3410 – }
3411 –
3412 – /*
3413 – * cidr_limit_reached
3414 – *
3415 – * inputs       - int flag allowing over_rule of limits
3416 – *              - pointer to the ip to be added
3417 – *              - pointer to the class
3418 – * output       - non zero if limit reached
3419 – *                0 if limit not reached
3420 – * side effects -
3421 – */
3422 – static int
3423 – cidr_limit_reached(int over_rule,
3424 –                   struct irc_ssaddr *ip, struct ClassItem *aclass)
3425 – {
3426 –  dlink_node *ptr = NULL;
3427 –  struct CidrItem *cidr;
3428 –
3429 –  if (aclass->number_per_cidr <= 0)
3430 –    return 0;
3431 –
3432 –  if (ip->ss.ss_family == AF_INET)
3433 –  {
3434 –    if (aclass->cidr_bitlen_ipv4 <= 0)
3435 –      return 0;
3436 –
3437 –    DLINK_FOREACH(ptr, aclass->list_ipv4.head)
3438 –    {
3439 –      cidr = ptr->data;
3440 –      if (match_ipv4(ip, &cidr->mask, aclass->cidr_bitlen_ipv4))
3441 –      {
3442 –        if (!over_rule && (cidr->number_on_this_cidr >= aclass->number_per_cidr))
3443 –          return -1;
3444 –        cidr->number_on_this_cidr++;
3445 –        return 0;
3446 –      }
3447 –    }
3448 –    cidr = MyMalloc(sizeof(struct CidrItem));
3449 –    cidr->number_on_this_cidr = 1;
3450 –    cidr->mask = *ip;
3451 –    mask_addr(&cidr->mask, aclass->cidr_bitlen_ipv4);
3452 –    dlinkAdd(cidr, &cidr->node, &aclass->list_ipv4);
3453 –  }
3454 – #ifdef IPV6
3455 –  else if (aclass->cidr_bitlen_ipv6 > 0)
3456 –  {
3457 –    DLINK_FOREACH(ptr, aclass->list_ipv6.head)
3458 –    {
3459 –      cidr = ptr->data;
3460 –      if (match_ipv6(ip, &cidr->mask, aclass->cidr_bitlen_ipv6))
3461 –      {
3462 –        if (!over_rule && (cidr->number_on_this_cidr >= aclass->number_per_cidr))
3463 –          return -1;
3464 –        cidr->number_on_this_cidr++;
3465 –        return 0;
3466 –      }
3467 –    }
3468 –    cidr = MyMalloc(sizeof(struct CidrItem));
3469 –    cidr->number_on_this_cidr = 1;
3470 –    cidr->mask = *ip;
3471 –    mask_addr(&cidr->mask, aclass->cidr_bitlen_ipv6);
3472 –    dlinkAdd(cidr, &cidr->node, &aclass->list_ipv6);
3473 –  }
3474 – #endif
3475 –  return 0;
3476 – }
3477 –
3478 – /*
3479 – * remove_from_cidr_check
3480 – *
3481 – * inputs       - pointer to the ip to be removed
3482 – *              - pointer to the class
3483 – * output       - NONE
3484 – * side effects -
3485 – */
3486 – static void
3487 – remove_from_cidr_check(struct irc_ssaddr *ip, struct ClassItem *aclass)
3488 – {
3489 –  dlink_node *ptr = NULL;
3490 –  dlink_node *next_ptr = NULL;
3491 –  struct CidrItem *cidr;
3492 –
3493 –  if (aclass->number_per_cidr == 0)
3494 –    return;
3495 –
3496 –  if (ip->ss.ss_family == AF_INET)
3497 –  {
3498 –    if (aclass->cidr_bitlen_ipv4 <= 0)
3499 –      return;
3500 –
3501 –    DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv4.head)
3502 –    {
3503 –      cidr = ptr->data;
3504 –      if (match_ipv4(ip, &cidr->mask, aclass->cidr_bitlen_ipv4))
3505 –      {
3506 –        cidr->number_on_this_cidr--;
3507 –        if (cidr->number_on_this_cidr == 0)
3508 –        {
3509 –          dlinkDelete(ptr, &aclass->list_ipv4);
3510 –          MyFree(cidr);
3511 –          return;
3512 –        }
3513 –      }
3514 –    }
3515 –  }
3516 – #ifdef IPV6
3517 –  else if (aclass->cidr_bitlen_ipv6 > 0)
3518 –  {
3519 –    DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv6.head)
3520 –    {
3521 –      cidr = ptr->data;
3522 –      if (match_ipv6(ip, &cidr->mask, aclass->cidr_bitlen_ipv6))
3523 –      {
3524 –        cidr->number_on_this_cidr--;
3525 –        if (cidr->number_on_this_cidr == 0)
3526 –        {
3527 –          dlinkDelete(ptr, &aclass->list_ipv6);
3528 –          MyFree(cidr);
3529 –          return;
3530 –        }
3531 –      }
3532 –    }
3533 –  }
3534 – #endif
3535 – }
3536 –
3537 – static void
3538 – rebuild_cidr_list(int aftype, struct ConfItem *oldcl, struct ClassItem *newcl,
3539 –                  dlink_list *old_list, dlink_list *new_list, int changed)
3540 – {
3541 –  dlink_node *ptr;
3542 –  struct Client *client_p;
3543 –  struct ConfItem *conf;
3544 –  struct AccessItem *aconf;
3545 –
3546 –  if (!changed)
3547 –  {
3548 –    *new_list = *old_list;
3549 –    old_list->head = old_list->tail = NULL;
3550 –    old_list->length = 0;
3551 –    return;
3552 –  }
3553 –
3554 –  DLINK_FOREACH(ptr, local_client_list.head)
3555 –  {
3556 –    client_p = ptr->data;
3557 –    if (client_p->localClient->aftype != aftype)
3558 –      continue;
3559 –    if (dlink_list_length(&client_p->localClient->confs) == 0)
3560 –      continue;
3561 –
3562 –    conf = client_p->localClient->confs.tail->data;
3563 –    if (conf->type == CLIENT_TYPE)
3564 –    {
3565 –      aconf = map_to_conf(conf);
3566 –      if (aconf->class_ptr == oldcl)
3567 –        cidr_limit_reached(1, &client_p->localClient->ip, newcl);
3568 –    }
3569 –  }
3570 – }
3571 –
3572 – /*
3573 – * rebuild_cidr_class
3574 – *
3575 – * inputs       - pointer to old conf
3576 – *              - pointer to new_class
3577 – * output       - none
3578 – * side effects - rebuilds the class link list of cidr blocks
3579 – */
3580 – void
3581 – rebuild_cidr_class(struct ConfItem *conf, struct ClassItem *new_class)
3582 – {
3583 –  struct ClassItem *old_class = map_to_conf(conf);
3584 –
3585 –  if (old_class->number_per_cidr > 0 && new_class->number_per_cidr > 0)
3586 –  {
3587 –    if (old_class->cidr_bitlen_ipv4 > 0 && new_class->cidr_bitlen_ipv4 > 0)
3588 –      rebuild_cidr_list(AF_INET, conf, new_class,
3589 –                        &old_class->list_ipv4, &new_class->list_ipv4,
3590 –                        old_class->cidr_bitlen_ipv4 != new_class->cidr_bitlen_ipv4);
3591 –
3592 – #ifdef IPV6
3593 –    if (old_class->cidr_bitlen_ipv6 > 0 && new_class->cidr_bitlen_ipv6 > 0)
3594 –      rebuild_cidr_list(AF_INET6, conf, new_class,
3595 –                        &old_class->list_ipv6, &new_class->list_ipv6,
3596 –                        old_class->cidr_bitlen_ipv6 != new_class->cidr_bitlen_ipv6);
3597 – #endif
3598 –  }
3599 –
3600 –  destroy_cidr_class(old_class);
3601 – }
3602 –
3603 – /*
3604 – * destroy_cidr_list
3605 – *
3606 – * inputs       - pointer to class dlink list of cidr blocks
3607 – * output       - none
3608 – * side effects - completely destroys the class link list of cidr blocks
3609 – */
3610 – static void
3611 – destroy_cidr_list(dlink_list *list)
3612 – {
3613 –  dlink_node *ptr = NULL, *next_ptr = NULL;
3614 –
3615 –  DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
3616 –  {
3617 –    dlinkDelete(ptr, list);
3618 –    MyFree(ptr->data);
3619 –  }
3620 – }
3621 –
3622 – /*
3623 – * destroy_cidr_class
3624 – *
3625 – * inputs       - pointer to class
3626 – * output       - none
3627 – * side effects - completely destroys the class link list of cidr blocks
3628 – */
3629 – static void
3630 – destroy_cidr_class(struct ClassItem *aclass)
3631 – {
3632 –  destroy_cidr_list(&aclass->list_ipv4);
3633 –  destroy_cidr_list(&aclass->list_ipv6);
3634 – }

Diff Legend

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