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/s_conf.c (file contents), Revision 1294 by michael, Wed Feb 22 20:48:30 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 < *  s_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"
30 < #include "balloc.h"
31 < #include "s_conf.h"
30 < #include "s_serv.h"
30 > #include "conf.h"
31 > #include "server.h"
32   #include "resv.h"
33   #include "channel.h"
34   #include "client.h"
35   #include "event.h"
35 – #include "hash.h"
36 – #include "hook.h"
36   #include "irc_string.h"
38 – #include "sprintf_irc.h"
37   #include "s_bsd.h"
38   #include "ircd.h"
39   #include "listener.h"
# Line 43 | Line 41
41   #include "modules.h"
42   #include "numeric.h"
43   #include "fdlist.h"
44 < #include "s_log.h"
44 > #include "log.h"
45   #include "send.h"
48 – #include "s_gline.h"
49 – #include "fileio.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  
59 < struct Callback *client_check_cb = NULL;
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 };
68   dlink_list server_items  = { NULL, NULL, 0 };
69   dlink_list cluster_items = { NULL, NULL, 0 };
65 – dlink_list hub_items     = { NULL, NULL, 0 };
66 – dlink_list leaf_items    = { NULL, NULL, 0 };
70   dlink_list oconf_items   = { NULL, NULL, 0 };
71   dlink_list uconf_items   = { NULL, NULL, 0 };
72   dlink_list xconf_items   = { NULL, NULL, 0 };
70 – dlink_list rxconf_items  = { NULL, NULL, 0 };
71 – dlink_list rkconf_items  = { NULL, NULL, 0 };
73   dlink_list nresv_items   = { NULL, NULL, 0 };
74 < dlink_list class_items   = { NULL, NULL, 0 };
74 < dlink_list gdeny_items   = { NULL, NULL, 0 };
75 <
76 < dlink_list temporary_klines  = { NULL, NULL, 0 };
77 < dlink_list temporary_dlines  = { NULL, NULL, 0 };
78 < dlink_list temporary_xlines  = { NULL, NULL, 0 };
79 < dlink_list temporary_rklines = { NULL, NULL, 0 };
80 < dlink_list temporary_glines  = { NULL, NULL, 0 };
81 < dlink_list temporary_rxlines = { NULL, NULL, 0 };
82 < 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[];
78   extern char conffilebuf[IRCD_BUFSIZE];
87 – extern char yytext[];
79   extern int yyparse(); /* defined in y.tab.c */
80  
81   struct conf_parser_context conf_parser_ctx = { 0, 0, NULL };
82  
83   /* internally defined functions */
84 < static void lookup_confhost(struct ConfItem *);
94 < static void set_default_conf(void);
95 < static void validate_conf(void);
96 < static void read_conf(FBFILE *);
84 > static void read_conf(FILE *);
85   static void clear_out_old_conf(void);
98 – 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);
106 < static dlink_list *map_to_list(ConfType);
107 < 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  
110 – /*
111 – * bit_len
112 – */
113 – static int cidr_limit_reached(int, struct irc_ssaddr *, struct ClassItem *);
114 – static void remove_from_cidr_check(struct irc_ssaddr *, struct ClassItem *);
115 – static void destroy_cidr_class(struct ClassItem *);
116 –
117 – static void flags_to_ascii(unsigned int, const unsigned int[], char *, int);
118 –
119 – /* address of default class conf */
120 – 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 128 | 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  
141 – void *
142 – map_to_conf(struct ConfItem *aconf)
143 – {
144 –  void *conf;
145 –  conf = (void *)((uintptr_t)aconf +
146 –                  (uintptr_t)sizeof(struct ConfItem));
147 –  return(conf);
148 – }
149 –
150 – struct ConfItem *
151 – unmap_conf_item(void *aconf)
152 – {
153 –  struct ConfItem *conf;
154 –
155 –  conf = (struct ConfItem *)((uintptr_t)aconf -
156 –                             (uintptr_t)sizeof(struct ConfItem));
157 –  return(conf);
158 – }
159 –
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 170 | 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->ipnum, addr, sizeof(aconf->ipnum));
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 187 | 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 < *
201 < * inputs       - type of item
202 < * output       - pointer to new conf entry
203 < * side effects - none
204 < */
205 < struct ConfItem *
206 < 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;
210 <  struct ClassItem *aclass = NULL;
211 <  int status = 0;
212 <
213 <  switch (type)
214 <  {
215 <  case DLINE_TYPE:
216 <  case EXEMPTDLINE_TYPE:
217 <  case GLINE_TYPE:
218 <  case KLINE_TYPE:
219 <  case CLIENT_TYPE:
220 <  case OPER_TYPE:
221 <  case SERVER_TYPE:
222 <    conf = MyMalloc(sizeof(struct ConfItem) +
223 <                    sizeof(struct AccessItem));
224 <    aconf = map_to_conf(conf);
225 <    aconf->aftype = AF_INET;
226 <
227 <    /* Yes, sigh. switch on type again */
228 <    switch (type)
229 <    {
230 <    case EXEMPTDLINE_TYPE:
231 <      status = CONF_EXEMPTDLINE;
232 <      break;
233 <
234 <    case DLINE_TYPE:
235 <      status = CONF_DLINE;
236 <      break;
157 >  struct MaskItem *conf = MyMalloc(sizeof(*conf));
158 >  dlink_list *list = NULL;
159  
160 <    case KLINE_TYPE:
161 <      status = CONF_KLINE;
162 <      break;
241 <
242 <    case GLINE_TYPE:
243 <      status = CONF_GLINE;
244 <      break;
245 <
246 <    case CLIENT_TYPE:
247 <      status = CONF_CLIENT;
248 <      break;
249 <
250 <    case OPER_TYPE:
251 <      status = CONF_OPERATOR;
252 <      dlinkAdd(conf, &conf->node, &oconf_items);
253 <      break;
254 <
255 <    case SERVER_TYPE:
256 <      status = CONF_SERVER;
257 <      dlinkAdd(conf, &conf->node, &server_items);
258 <      break;
259 <
260 <    default:
261 <      break;
262 <    }
263 <    aconf->status = status;
264 <    break;
265 <
266 <  case LEAF_TYPE:
267 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
268 <                                       sizeof(struct MatchItem));
269 <    dlinkAdd(conf, &conf->node, &leaf_items);
270 <    break;
271 <
272 <  case HUB_TYPE:
273 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
274 <                                       sizeof(struct MatchItem));
275 <    dlinkAdd(conf, &conf->node, &hub_items);
276 <    break;
277 <
278 <  case ULINE_TYPE:
279 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
280 <                                       sizeof(struct MatchItem));
281 <    dlinkAdd(conf, &conf->node, &uconf_items);
282 <    break;
283 <
284 <  case GDENY_TYPE:
285 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
286 <                                       sizeof(struct AccessItem));
287 <    dlinkAdd(conf, &conf->node, &gdeny_items);
288 <    break;
289 <
290 <  case XLINE_TYPE:
291 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
292 <                                       sizeof(struct MatchItem));
293 <    dlinkAdd(conf, &conf->node, &xconf_items);
294 <    break;
295 < #ifdef HAVE_LIBPCRE
296 <  case RXLINE_TYPE:
297 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
298 <                                       sizeof(struct MatchItem));
299 <    dlinkAdd(conf, &conf->node, &rxconf_items);
300 <    break;
301 <
302 <  case RKLINE_TYPE:
303 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
304 <                                       sizeof(struct AccessItem));
305 <    aconf = map_to_conf(conf);
306 <    aconf->status = CONF_KLINE;
307 <    dlinkAdd(conf, &conf->node, &rkconf_items);
308 <    break;
309 < #endif
310 <  case CLUSTER_TYPE:
311 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem));
312 <    dlinkAdd(conf, &conf->node, &cluster_items);
313 <    break;
314 <
315 <  case CRESV_TYPE:
316 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
317 <                                       sizeof(struct ResvChannel));
318 <    break;
319 <
320 <  case NRESV_TYPE:
321 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
322 <                                       sizeof(struct MatchItem));
323 <    dlinkAdd(conf, &conf->node, &nresv_items);
324 <    break;
325 <
326 <  case SERVICE_TYPE:
327 <    status = CONF_SERVICE;
328 <    conf = MyMalloc(sizeof(struct ConfItem));
329 <    dlinkAdd(conf, &conf->node, &service_items);
330 <    break;
331 <
332 <  case CLASS_TYPE:
333 <    conf = MyMalloc(sizeof(struct ConfItem) +
334 <                           sizeof(struct ClassItem));
335 <    dlinkAdd(conf, &conf->node, &class_items);
336 <
337 <    aclass = map_to_conf(conf);
338 <    aclass->active = 1;
339 <    ConFreq(aclass) = DEFAULT_CONNECTFREQUENCY;
340 <    PingFreq(aclass) = DEFAULT_PINGFREQUENCY;
341 <    MaxTotal(aclass) = MAXIMUM_LINKS_DEFAULT;
342 <    MaxSendq(aclass) = DEFAULT_SENDQ;
343 <
344 <    break;
345 <
346 <  default:
347 <    conf = NULL;
348 <    break;
349 <  }
350 <
351 <  /* XXX Yes, this will core if default is hit. I want it to for now - db */
352 <  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;
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);
366 –  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));
383 <    if (aconf->spasswd != NULL)
384 <      memset(aconf->spasswd, 0, strlen(aconf->spasswd));
385 <    aconf->class_ptr = NULL;
386 <
387 <    MyFree(aconf->passwd);
388 <    MyFree(aconf->spasswd);
389 <    MyFree(aconf->reason);
390 <    MyFree(aconf->oper_reason);
391 <    MyFree(aconf->user);
392 <    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 <    if (aconf->rsa_public_key)
395 <      RSA_free(aconf->rsa_public_key);
396 <    MyFree(aconf->rsa_public_key_file);
397 < #endif
197 >  MyFree(conf->cipher_list);
198  
199 <    /* Yes, sigh. switch on type again */
200 <    switch(type)
401 <    {
402 <    case EXEMPTDLINE_TYPE:
403 <    case DLINE_TYPE:
404 <    case GLINE_TYPE:
405 <    case KLINE_TYPE:
406 <    case CLIENT_TYPE:
407 <      MyFree(conf);
408 <      break;
409 <
410 <    case OPER_TYPE:
411 <      aconf = map_to_conf(conf);
412 <      if (!IsConfIllegal(aconf))
413 <        dlinkDelete(&conf->node, &oconf_items);
414 <      MyFree(conf);
415 <      break;
416 <
417 <    case SERVER_TYPE:
418 <      aconf = map_to_conf(conf);
419 <      if (!IsConfIllegal(aconf))
420 <        dlinkDelete(&conf->node, &server_items);
421 <      MyFree(conf);
422 <      break;
423 <
424 <    default:
425 <      break;
426 <    }
427 <    break;
428 <
429 <  case HUB_TYPE:
430 <    match_item = map_to_conf(conf);
431 <    MyFree(match_item->user);
432 <    MyFree(match_item->host);
433 <    MyFree(match_item->reason);
434 <    MyFree(match_item->oper_reason);
435 <    /* If marked illegal, its already been pulled off of the hub_items list */
436 <    if (!match_item->illegal)
437 <      dlinkDelete(&conf->node, &hub_items);
438 <    MyFree(conf);
439 <    break;
440 <
441 <  case LEAF_TYPE:
442 <    match_item = map_to_conf(conf);
443 <    MyFree(match_item->user);
444 <    MyFree(match_item->host);
445 <    MyFree(match_item->reason);
446 <    MyFree(match_item->oper_reason);
447 <    /* If marked illegal, its already been pulled off of the leaf_items list */
448 <    if (!match_item->illegal)
449 <      dlinkDelete(&conf->node, &leaf_items);
450 <    MyFree(conf);
451 <    break;
452 <
453 <  case ULINE_TYPE:
454 <    match_item = map_to_conf(conf);
455 <    MyFree(match_item->user);
456 <    MyFree(match_item->host);
457 <    MyFree(match_item->reason);
458 <    MyFree(match_item->oper_reason);
459 <    dlinkDelete(&conf->node, &uconf_items);
460 <    MyFree(conf);
461 <    break;
462 <
463 <  case XLINE_TYPE:
464 <    match_item = map_to_conf(conf);
465 <    MyFree(match_item->user);
466 <    MyFree(match_item->host);
467 <    MyFree(match_item->reason);
468 <    MyFree(match_item->oper_reason);
469 <    dlinkDelete(&conf->node, &xconf_items);
470 <    MyFree(conf);
471 <    break;
472 < #ifdef HAVE_LIBPCRE
473 <  case RKLINE_TYPE:
474 <    aconf = map_to_conf(conf);
475 <    MyFree(aconf->regexuser);
476 <    MyFree(aconf->regexhost);
477 <    MyFree(aconf->user);
478 <    MyFree(aconf->host);
479 <    MyFree(aconf->reason);
480 <    MyFree(aconf->oper_reason);
481 <    dlinkDelete(&conf->node, &rkconf_items);
482 <    MyFree(conf);
483 <    break;
484 <
485 <  case RXLINE_TYPE:
486 <    MyFree(conf->regexpname);
487 <    match_item = map_to_conf(conf);
488 <    MyFree(match_item->user);
489 <    MyFree(match_item->host);
490 <    MyFree(match_item->reason);
491 <    MyFree(match_item->oper_reason);
492 <    dlinkDelete(&conf->node, &rxconf_items);
493 <    MyFree(conf);
494 <    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);
501 <    MyFree(match_item->oper_reason);
502 <    dlinkDelete(&conf->node, &nresv_items);
503 <
504 <    if (conf->flags & CONF_FLAGS_TEMPORARY)
505 <      if ((m = dlinkFindDelete(&temporary_resv, conf)) != NULL)
506 <        free_dlink_node(m);
507 <
508 <    MyFree(conf);
509 <    break;
510 <
511 <  case GDENY_TYPE:
512 <    aconf = map_to_conf(conf);
513 <    MyFree(aconf->user);
514 <    MyFree(aconf->host);
515 <    dlinkDelete(&conf->node, &gdeny_items);
516 <    MyFree(conf);
517 <    break;
518 <
519 <  case CLUSTER_TYPE:
520 <    dlinkDelete(&conf->node, &cluster_items);
521 <    MyFree(conf);
522 <    break;
523 <
524 <  case CRESV_TYPE:
525 <    if (conf->flags & CONF_FLAGS_TEMPORARY)
526 <      if ((m = dlinkFindDelete(&temporary_resv, conf)) != NULL)
527 <        free_dlink_node(m);
528 <
529 <    MyFree(conf);
530 <    break;
531 <
532 <  case CLASS_TYPE:
533 <    dlinkDelete(&conf->node, &class_items);
534 <    MyFree(conf);
535 <    break;
536 <
537 <  case SERVICE_TYPE:
538 <    dlinkDelete(&conf->node, &service_items);
539 <    MyFree(conf);
540 <    break;
541 <
542 <  default:
543 <    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    }
545 – }
546 –
547 – /* free_access_item()
548 – *
549 – * inputs       - pointer to conf to free
550 – * output       - none
551 – * side effects - crucial password fields are zeroed, conf is freed
552 – */
553 – void
554 – free_access_item(struct AccessItem *aconf)
555 – {
556 –  struct ConfItem *conf;
208  
209 <  if (aconf == NULL)
559 <    return;
560 <  conf = unmap_conf_item(aconf);
561 <  delete_conf_item(conf);
562 < }
563 <
564 < static const unsigned int shared_bit_table[] =
565 <  { 'K', 'k', 'U', 'X', 'x', 'Y', 'Q', 'q', 'R', 'L', 0};
566 <
567 < /* report_confitem_types()
568 < *
569 < * inputs       - pointer to client requesting confitem report
570 < *              - ConfType to report
571 < * output       - none
572 < * side effects -
573 < */
574 < void
575 < report_confitem_types(struct Client *source_p, ConfType type, int temp)
576 < {
577 <  dlink_node *ptr = NULL;
578 <  struct ConfItem *conf = NULL;
579 <  struct AccessItem *aconf = NULL;
580 <  struct MatchItem *matchitem = NULL;
581 <  struct ClassItem *classitem = NULL;
582 <  char buf[12];
583 <  char *p = NULL;
584 <  const char *pfx = NULL;
585 <
586 <  switch (type)
209 >  DLINK_FOREACH_SAFE(ptr, ptr_next, conf->leaf_list.head)
210    {
211 <  case GDENY_TYPE:
212 <    DLINK_FOREACH(ptr, gdeny_items.head)
213 <    {
214 <      conf = ptr->data;
592 <      aconf = map_to_conf(conf);
593 <
594 <      p = buf;
595 <
596 <      if (aconf->flags & GDENY_BLOCK)
597 <        *p++ = 'B';
598 <      else
599 <        *p++ = 'b';
600 <
601 <      if (aconf->flags & GDENY_REJECT)
602 <        *p++ = 'R';
603 <      else
604 <        *p++ = 'r';
605 <
606 <      *p = '\0';
607 <
608 <      sendto_one(source_p, ":%s %d %s V %s@%s %s %s",
609 <                 me.name, RPL_STATSDEBUG, source_p->name,
610 <                 aconf->user, aconf->host, conf->name, buf);
611 <    }
612 <    break;
613 <
614 <  case XLINE_TYPE:
615 <    DLINK_FOREACH(ptr, xconf_items.head)
616 <    {
617 <      conf = ptr->data;
618 <      matchitem = map_to_conf(conf);
619 <
620 <      sendto_one(source_p, form_str(RPL_STATSXLINE),
621 <                 me.name, source_p->name,
622 <                 matchitem->hold ? "x": "X", matchitem->count,
623 <                 conf->name, matchitem->reason);
624 <    }
625 <    break;
626 <
627 < #ifdef HAVE_LIBPCRE
628 <  case RXLINE_TYPE:
629 <    DLINK_FOREACH(ptr, rxconf_items.head)
630 <    {
631 <      conf = ptr->data;
632 <      matchitem = map_to_conf(conf);
633 <
634 <      sendto_one(source_p, form_str(RPL_STATSXLINE),
635 <                 me.name, source_p->name,
636 <                 matchitem->hold ? "xR": "XR", matchitem->count,
637 <                 conf->name, matchitem->reason);
638 <    }
639 <    break;
640 <
641 <  case RKLINE_TYPE:
642 <    pfx = temp ? "kR" : "KR";
643 <
644 <    DLINK_FOREACH(ptr, rkconf_items.head)
645 <    {
646 <      aconf = map_to_conf((conf = ptr->data));
647 <
648 <      if (temp && !(conf->flags & CONF_FLAGS_TEMPORARY))
649 <        continue;
650 <
651 <      sendto_one(source_p, form_str(RPL_STATSKLINE), me.name,
652 <                 source_p->name, pfx, aconf->host, aconf->user,
653 <                 aconf->reason, aconf->oper_reason ? aconf->oper_reason : "");
654 <    }
655 <    break;
656 < #endif
657 <
658 <  case ULINE_TYPE:
659 <    DLINK_FOREACH(ptr, uconf_items.head)
660 <    {
661 <      conf = ptr->data;
662 <      matchitem = map_to_conf(conf);
663 <
664 <      p = buf;
665 <
666 <      /* some of these are redundant for the sake of
667 <       * consistency with cluster{} flags
668 <       */
669 <      *p++ = 'c';
670 <      flags_to_ascii(matchitem->action, shared_bit_table, p, 0);
671 <
672 <      sendto_one(source_p, form_str(RPL_STATSULINE),
673 <                 me.name, source_p->name, conf->name,
674 <                 matchitem->user?matchitem->user: "*",
675 <                 matchitem->host?matchitem->host: "*", buf);
676 <    }
677 <
678 <    DLINK_FOREACH(ptr, cluster_items.head)
679 <    {
680 <      conf = ptr->data;
681 <
682 <      p = buf;
683 <
684 <      *p++ = 'C';
685 <      flags_to_ascii(conf->flags, shared_bit_table, p, 0);
686 <
687 <      sendto_one(source_p, form_str(RPL_STATSULINE),
688 <                 me.name, source_p->name, conf->name,
689 <                 "*", "*", buf);
690 <    }
691 <
692 <    break;
693 <
694 <  case OPER_TYPE:
695 <    DLINK_FOREACH(ptr, oconf_items.head)
696 <    {
697 <      conf = ptr->data;
698 <      aconf = map_to_conf(conf);
699 <
700 <      /* Don't allow non opers to see oper privs */
701 <      if (HasUMode(source_p, UMODE_OPER))
702 <        sendto_one(source_p, form_str(RPL_STATSOLINE),
703 <                   me.name, source_p->name, 'O', aconf->user, aconf->host,
704 <                   conf->name, oper_privs_as_string(aconf->port),
705 <                   aconf->class_ptr ? aconf->class_ptr->name : "<default>");
706 <      else
707 <        sendto_one(source_p, form_str(RPL_STATSOLINE),
708 <                   me.name, source_p->name, 'O', aconf->user, aconf->host,
709 <                   conf->name, "0",
710 <                   aconf->class_ptr ? aconf->class_ptr->name : "<default>");
711 <    }
712 <    break;
713 <
714 <  case CLASS_TYPE:
715 <    DLINK_FOREACH(ptr, class_items.head)
716 <    {
717 <      conf = ptr->data;
718 <      classitem = map_to_conf(conf);
719 <      sendto_one(source_p, form_str(RPL_STATSYLINE),
720 <                 me.name, source_p->name, 'Y',
721 <                 conf->name, PingFreq(classitem),
722 <                 ConFreq(classitem),
723 <                 MaxTotal(classitem), MaxSendq(classitem),
724 <                 CurrUserCount(classitem),
725 <                 classitem->active ? "active" : "disabled");
726 <    }
727 <    break;
728 <
729 <  case CONF_TYPE:
730 <  case CLIENT_TYPE:
731 <    break;
732 <
733 <  case SERVICE_TYPE:
734 <    DLINK_FOREACH(ptr, service_items.head)
735 <    {
736 <      conf = ptr->data;
737 <      sendto_one(source_p, form_str(RPL_STATSSERVICE),
738 <                 me.name, source_p->name, 'S', "*", conf->name, 0, 0);
739 <    }
740 <    break;
741 <
742 <  case SERVER_TYPE:
743 <    DLINK_FOREACH(ptr, server_items.head)
744 <    {
745 <      p = buf;
746 <
747 <      conf = ptr->data;
748 <      aconf = map_to_conf(conf);
749 <
750 <      buf[0] = '\0';
751 <
752 <      if (IsConfAllowAutoConn(aconf))
753 <        *p++ = 'A';
754 <      if (IsConfCryptLink(aconf))
755 <        *p++ = 'C';
756 <      if (IsConfTopicBurst(aconf))
757 <        *p++ = 'T';
758 <      if (IsConfCompressed(aconf))
759 <        *p++ = 'Z';
760 <      if (buf[0] == '\0')
761 <        *p++ = '*';
762 <
763 <      *p = '\0';
764 <
765 <      /*
766 <       * Allow admins to see actual ips unless hide_server_ips is enabled
767 <       */
768 <      if (!ConfigServerHide.hide_server_ips && HasUMode(source_p, UMODE_ADMIN))
769 <        sendto_one(source_p, form_str(RPL_STATSCLINE),
770 <                   me.name, source_p->name, 'C', aconf->host,
771 <                   buf, conf->name, aconf->port,
772 <                   aconf->class_ptr ? aconf->class_ptr->name : "<default>");
773 <        else
774 <          sendto_one(source_p, form_str(RPL_STATSCLINE),
775 <                     me.name, source_p->name, 'C',
776 <                     "*@127.0.0.1", buf, conf->name, aconf->port,
777 <                     aconf->class_ptr ? aconf->class_ptr->name : "<default>");
778 <    }
779 <    break;
780 <
781 <  case HUB_TYPE:
782 <    DLINK_FOREACH(ptr, hub_items.head)
783 <    {
784 <      conf = ptr->data;
785 <      matchitem = map_to_conf(conf);
786 <      sendto_one(source_p, form_str(RPL_STATSHLINE), me.name,
787 <                 source_p->name, 'H', matchitem->host, conf->name, 0, "*");
788 <    }
789 <    break;
211 >    MyFree(ptr->data);
212 >    dlinkDelete(ptr, &conf->leaf_list);
213 >    free_dlink_node(ptr);
214 >  }
215  
216 <  case LEAF_TYPE:
217 <    DLINK_FOREACH(ptr, leaf_items.head)
218 <    {
794 <      conf = ptr->data;
795 <      matchitem = map_to_conf(conf);
796 <      sendto_one(source_p, form_str(RPL_STATSLLINE), me.name,
797 <                 source_p->name, 'L', matchitem->host, conf->name, 0, "*");
798 <    }
799 <    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:
806 <  case NRESV_TYPE:
807 <  case CLUSTER_TYPE:
808 <  default:
809 <    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 823 | 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   {
829 –  struct Client *source_p = va_arg(args, struct Client *);
830 –  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)))
835 <    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,
860 <                "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
880 <       * capture reject code here or rely on the connecting too fast code.
881 <       * - Dianora
882 <       */
883 <      if (REJECT_HOLD_TIME > 0)
884 <      {
885 <        sendto_one(source_p, ":%s NOTICE %s :You are not authorized to use this server",
886 <                   me.name, source_p->name);
887 <        source_p->localClient->reject_delay = CurrentTime + REJECT_HOLD_TIME;
888 <        SetCaptured(source_p);
889 <      }
890 <      else
891 <        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 <     /*
896 <      * Don't exit them immediately, play with them a bit.
897 <      * - Dianora
898 <      */
899 <     if (REJECT_HOLD_TIME > 0)
900 <     {
901 <       source_p->localClient->reject_delay = CurrentTime + REJECT_HOLD_TIME;
902 <       SetCaptured(source_p);
903 <     }
904 <     else
905 <       exit_client(source_p, &me, "Banned");
296 >     exit_client(source_p, "Banned");
297       ++ServerStats.is_ref;
298       break;
299  
# Line 911 | 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
920 – *              - 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;
929 <  char non_ident[USERLEN + 1] = { '~', '\0' };
930 <  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;
949 <  uhi[1] = client_p->host;
950 <  uhi[2] = client_p->sockhost;
951 <
952 <  rkconf = find_regexp_kline(uhi);
953 <
954 <  if (aconf != NULL)
336 >  if (conf)
337    {
338 <    if (IsConfClient(aconf) && !rkconf)
338 >    if (IsConfClient(conf))
339      {
340 <      conf = unmap_conf_item(aconf);
959 <
960 <      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);
966 <        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))
978 <          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,
992 <                   client_p->name);
993 <      if (ConfigFileEntry.kline_with_reason)
994 <        sendto_one(client_p, ":%s NOTICE %s :*** Banned %s",
995 <                  me.name, client_p->name, aconf->reason);
996 <      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 1008 | 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;
1014 <  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);
1024 <  if (aconf->class_ptr == NULL)
1025 <    return NOT_AUTHORIZED;  /* If class is missing, this is best */
1026 <
1027 <  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 1033 | Line 403 | attach_iline(struct Client *client_p, st
403     * setting a_limit_reached if any limit is reached.
404     * - Dianora
405     */
406 <  if (MaxTotal(aclass) != 0 && CurrUserCount(aclass) >= MaxTotal(aclass))
406 >  if (class->max_total != 0 && class->ref_count >= class->max_total)
407      a_limit_reached = 1;
408 <  else if (MaxPerIp(aclass) != 0 && ip_found->count > MaxPerIp(aclass))
408 >  else if (class->max_perip != 0 && ip_found->count > class->max_perip)
409      a_limit_reached = 1;
410 <  else if (MaxLocal(aclass) != 0 && local >= MaxLocal(aclass))
410 >  else if (class->max_local != 0 && local >= class->max_local)
411      a_limit_reached = 1;
412 <  else if (MaxGlobal(aclass) != 0 && global >= MaxGlobal(aclass))
412 >  else if (class->max_global != 0 && global >= class->max_global)
413      a_limit_reached = 1;
414 <  else if (MaxIdent(aclass) != 0 && ident >= MaxIdent(aclass) &&
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, "
1055 <               "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 1068 | 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),
1072 <    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 1118 | 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 1169 | 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 1211 | 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 1223 | 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 1279 | 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 1296 | 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;
1303 <  struct ConfItem *conf;
1304 <  struct ClassItem *aclass;
1305 <  struct AccessItem *aconf;
1306 <  struct ConfItem *aclass_conf;
1307 <  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);
1316 <      free_dlink_node(ptr);
1317 <
1318 <      switch (conf->type)
1319 <      {
1320 <      case CLIENT_TYPE:
1321 <      case OPER_TYPE:
1322 <      case SERVER_TYPE:
1323 <        aconf = map_to_conf(conf);
1324 <
1325 <        assert(aconf->clients > 0);
1326 <
1327 <        if ((aclass_conf = ClassPtr(aconf)) != NULL)
1328 <        {
1329 <          aclass = map_to_conf(aclass_conf);
1330 <
1331 <          assert(aclass->curr_user_count > 0);
1332 <
1333 <          if (conf->type == CLIENT_TYPE)
1334 <            remove_from_cidr_check(&client_p->localClient->ip, aclass);
1335 <          if (--aclass->curr_user_count == 0 && aclass->active == 0)
1336 <            delete_conf_item(aclass_conf);
1337 <        }
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 <        if (--aconf->clients == 0 && IsConfIllegal(aconf))
682 <          delete_conf_item(conf);
681 >    if (!(conf->type & type))
682 >      continue;
683  
684 <        break;
684 >    dlinkDelete(ptr, &client_p->localClient->confs);
685 >    free_dlink_node(ptr);
686  
687 <      case LEAF_TYPE:
688 <      case HUB_TYPE:
1346 <        match_item = map_to_conf(conf);
1347 <        if (match_item->ref_count == 0 && match_item->illegal)
1348 <          delete_conf_item(conf);
1349 <        break;
1350 <      default:
1351 <        break;
1352 <      }
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      }
1357 –  }
695  
696 <  return -1;
696 >    if (--conf->ref_count == 0 && conf->active == 0)
697 >      conf_free(conf);
698 >  }
699   }
700  
701   /* attach_conf()
# Line 1370 | 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 <  if (dlinkFind(&client_p->localClient->confs, conf) != NULL)
714 >  if (dlinkFind(&client_p->localClient->confs, conf))
715      return 1;
716  
717 <  if (conf->type == CLIENT_TYPE ||
718 <      conf->type == SERVER_TYPE ||
719 <      conf->type == OPER_TYPE)
720 <  {
1382 <    struct AccessItem *aconf = map_to_conf(conf);
1383 <    struct ClassItem *aclass = map_to_conf(aconf->class_ptr);
1384 <
1385 <    if (IsConfIllegal(aconf))
1386 <      return NOT_AUTHORIZED;
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 <    if (conf->type == CLIENT_TYPE)
723 <      if (cidr_limit_reached(IsConfExemptLimits(aconf),
1390 <                             &client_p->localClient->ip, aclass))
1391 <        return TOO_MANY;    /* Already at maximum allowed */
1392 <
1393 <    CurrUserCount(aclass)++;
1394 <    aconf->clients++;
1395 <  }
1396 <  else if (conf->type == HUB_TYPE || conf->type == LEAF_TYPE)
1397 <  {
1398 <    struct MatchItem *match_item = map_to_conf(conf);
1399 <    match_item->ref_count++;
1400 <  }
722 >  conf->class->ref_count++;
723 >  conf->ref_count++;
724  
725    dlinkAdd(conf, make_dlink_node(), &client_p->localClient->confs);
726  
# Line 1417 | Line 740 | attach_connect_block(struct Client *clie
740                       const char *host)
741   {
742    dlink_node *ptr;
743 <  struct ConfItem *conf;
1421 <  struct AccessItem *aconf;
743 >  struct MaskItem *conf = NULL;
744  
745    assert(client_p != NULL);
746    assert(host != NULL);
# Line 1429 | Line 751 | attach_connect_block(struct Client *clie
751    DLINK_FOREACH(ptr, server_items.head)
752    {
753      conf = ptr->data;
1432 –    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 1441 | Line 762 | attach_connect_block(struct Client *clie
762    return 0;
763   }
764  
1444 – /* find_conf_exact()
1445 – *
1446 – * inputs       - type of ConfItem
1447 – *              - pointer to name to find
1448 – *              - pointer to username to find
1449 – *              - pointer to host to find
1450 – * output       - NULL or pointer to conf found
1451 – * side effects - find a conf entry which matches the hostname
1452 – *                and has the same name.
1453 – */
1454 – struct ConfItem *
1455 – find_conf_exact(ConfType type, const char *name, const char *user,
1456 –                const char *host)
1457 – {
1458 –  dlink_node *ptr;
1459 –  dlink_list *list_p;
1460 –  struct ConfItem *conf = NULL;
1461 –  struct AccessItem *aconf;
1462 –
1463 –  /* Only valid for OPER_TYPE and ...? */
1464 –  list_p = map_to_list(type);
1465 –
1466 –  DLINK_FOREACH(ptr, (*list_p).head)
1467 –  {
1468 –    conf = ptr->data;
1469 –
1470 –    if (conf->name == NULL)
1471 –      continue;
1472 –    aconf = map_to_conf(conf);
1473 –    if (aconf->host == NULL)
1474 –      continue;
1475 –    if (irccmp(conf->name, name) != 0)
1476 –      continue;
1477 –
1478 –    /*
1479 –    ** Accept if the *real* hostname (usually sockethost)
1480 –    ** socket host) matches *either* host or name field
1481 –    ** of the configuration.
1482 –    */
1483 –    if (!match(aconf->host, host) || !match(aconf->user, user))
1484 –      continue;
1485 –    if (type == OPER_TYPE)
1486 –    {
1487 –      struct ClassItem *aclass = map_to_conf(aconf->class_ptr);
1488 –
1489 –      if (aconf->clients >= MaxTotal(aclass))
1490 –        continue;
1491 –    }
1492 –
1493 –    return conf;
1494 –  }
1495 –
1496 –  return NULL;
1497 – }
1498 –
765   /* find_conf_name()
766   *
767   * inputs       - pointer to conf link list to search
# Line 1505 | 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 1533 | 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:
1541 <    return(&rxconf_items);
1542 <    break;
1543 <  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:
1556 <    return(&class_items);
1557 <    break;
1558 <  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;
1567 –  case CONF_TYPE:
1568 –  case GLINE_TYPE:
1569 –  case KLINE_TYPE:
1570 –  case DLINE_TYPE:
1571 –  case CRESV_TYPE:
829    default:
830      return NULL;
831    }
# Line 1580 | 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;
1593 <  struct AccessItem *aconf=NULL;
1594 <  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
1600 <  case RXLINE_TYPE:
1601 <      DLINK_FOREACH(ptr, list_p->head)
1602 <      {
1603 <        conf = ptr->data;
1604 <        assert(conf->regexpname);
1605 <
1606 <        if (!ircd_pcre_exec(conf->regexpname, name))
1607 <          return conf;
1608 <      }
1609 <      break;
1610 < #endif
1611 <  case SERVICE_TYPE:
854 >  case CONF_SERVICE:
855      DLINK_FOREACH(ptr, list_p->head)
856      {
857        conf = ptr->data;
# Line 1620 | 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  
1630 –      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;
1651 –      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 1669 | 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;
1682 <  struct MatchItem *match_item;
1683 <  dlink_list *list_p;
1684 <
1685 <  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;
1717 –      aconf = map_to_conf(conf);
955  
956        if (EmptyString(conf->name))
957          continue;
# Line 1723 | 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->ipnum, 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->ipnum, 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 1754 | 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 <      {
1774 <          return (conf);
1775 <      }
1013 >        return conf;
1014      }
1777 –    break;
1015  
1779 –  case CLASS_TYPE:
1780 –    DLINK_FOREACH(ptr, list_p->head)
1781 –    {
1782 –      conf = ptr->data;
1783 –      if (EmptyString(conf->name))
1784 –        continue;
1785 –    
1786 –      if (irccmp(conf->name, name) == 0)
1787 –        return (conf);
1788 –    }
1016      break;
1017  
1018    default:
1019      break;
1020    }
1021 <  return(NULL);
1021 >
1022 >  return NULL;
1023   }
1024  
1025   /* rehash()
# Line 1803 | 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 1816 | 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  
1824 –  flush_deleted_I_P();
1825 –
1052    rehashed_klines = 1;
1827 – /* XXX */
1828 –  if (ConfigLoggingEntry.use_logging)
1829 –    log_close_all();
1053  
1054 <  return(0);
1054 >  return 0;
1055   }
1056  
1057   /* set_default_conf()
# Line 1846 | 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 1856 | 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 1865 | 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 1873 | 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;
1879 –  ConfigLoggingEntry.timestamp = 1;
1104  
1105    ConfigChannel.disable_fake_channels = 0;
1882 –  ConfigChannel.restrict_channels = 0;
1883 –  ConfigChannel.disable_local_channels = 0;
1884 –  ConfigChannel.use_invex = 1;
1885 –  ConfigChannel.use_except = 1;
1886 –  ConfigChannel.use_knock = 1;
1106    ConfigChannel.knock_delay = 300;
1107    ConfigChannel.knock_delay_channel = 60;
1108 <  ConfigChannel.max_chans_per_user = 15;
1109 <  ConfigChannel.quiet_on_ban = 1;
1108 >  ConfigChannel.max_chans_per_user = 25;
1109 >  ConfigChannel.max_chans_per_oper = 50;
1110    ConfigChannel.max_bans = 25;
1111    ConfigChannel.default_split_user_count = 0;
1112    ConfigChannel.default_split_server_count = 0;
1113    ConfigChannel.no_join_on_split = 0;
1114    ConfigChannel.no_create_on_split = 0;
1896 –  ConfigChannel.burst_topicwho = 1;
1115  
1116    ConfigServerHide.flatten_links = 0;
1117    ConfigServerHide.links_delay = 300;
1118    ConfigServerHide.hidden = 0;
1901 –  ConfigServerHide.disable_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 <  
1907 <  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;
1912 –  ConfigFileEntry.burst_away = 0;
1913 –  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;
1918 –  ConfigFileEntry.disable_remote = 0;
1138    ConfigFileEntry.kill_chase_time_limit = 90;
1139    ConfigFileEntry.default_floodcount = 8;
1140    ConfigFileEntry.failed_oper_notice = 1;
# Line 1929 | 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;
1932 –  ConfigFileEntry.kline_with_reason = 1;
1933 –  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 1945 | Line 1163 | set_default_conf(void)
1163    ConfigFileEntry.no_oper_flood = 0;
1164    ConfigFileEntry.true_no_oper_flood = 0;
1165    ConfigFileEntry.oper_pass_resv = 1;
1948 –  ConfigFileEntry.glines = 0;
1949 –  ConfigFileEntry.gline_time = 12 * 3600;
1166    ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT;
1951 –  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;
1955 –  DupString(ConfigFileEntry.servlink_path, SLPATH);
1956 – #ifdef HAVE_LIBCRYPTO
1957 –  /* jdc -- This is our default value for a cipher.  According to the
1958 –   *        CRYPTLINK document (doc/cryptlink.txt), BF/128 must be supported
1959 –   *        under all circumstances if cryptlinks are enabled.  So,
1960 –   *        this will be our default.
1961 –   *
1962 –   *        NOTE: I apologise for the hard-coded value of "1" (BF/128).
1963 –   *              This should be moved into a find_cipher() routine.
1964 –   */
1965 –  ConfigFileEntry.default_cipher_preference = &CipherTable[1];
1966 – #endif
1170    ConfigFileEntry.use_egd = 0;
1171    ConfigFileEntry.egdpool_path = NULL;
1969 – #ifdef HAVE_LIBZ
1970 –  ConfigFileEntry.compression_level = 0;
1971 – #endif
1172    ConfigFileEntry.throttle_time = 10;
1173   }
1174  
1175 < /* read_conf()
1175 > static void
1176 > validate_conf(void)
1177 > {
1178 >  if (ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN)
1179 >    ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
1180 >
1181 >  if (ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN)
1182 >    ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
1183 >
1184 >  if (ServerInfo.network_name == NULL)
1185 >    ServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
1186 >
1187 >  if (ServerInfo.network_desc == NULL)
1188 >    ServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
1189 >
1190 >  if (ConfigFileEntry.service_name == NULL)
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()
1197   *
1198   * inputs       - file descriptor pointing to config file to use
1199   * output       - None
1200   * side effects - Read configuration file.
1201   */
1202   static void
1203 < read_conf(FBFILE *file)
1203 > read_conf(FILE *file)
1204   {
1205    lineno = 0;
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 <  fbrewind(file);
1211 >  rewind(file);
1212  
1213    conf_parser_ctx.pass = 2;
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 */
1997 < }
1998 <
1999 < static void
2000 < validate_conf(void)
2001 < {
2002 <  if (ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN)
2003 <    ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
2004 <
2005 <  if (ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN)
2006 <    ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
2007 <
2008 <  if (ConfigFileEntry.servlink_path == NULL)
2009 <    DupString(ConfigFileEntry.servlink_path, SLPATH);
2010 <
2011 <  if (ServerInfo.network_name == NULL)
2012 <    DupString(ServerInfo.network_name,NETWORK_NAME_DEFAULT);
2013 <
2014 <  if (ServerInfo.network_desc == NULL)
2015 <    DupString(ServerInfo.network_desc,NETWORK_DESC_DEFAULT);
2016 <
2017 <  if (ConfigFileEntry.service_name == NULL)
2018 <    DupString(ConfigFileEntry.service_name, SERVICE_NAME_DEFAULT);
2019 <
2020 <  if ((ConfigFileEntry.client_flood < CLIENT_FLOOD_MIN) ||
2021 <      (ConfigFileEntry.client_flood > CLIENT_FLOOD_MAX))
2022 <    ConfigFileEntry.client_flood = CLIENT_FLOOD_MAX;
2023 <
2024 <  ConfigFileEntry.max_watch = IRCD_MAX(ConfigFileEntry.max_watch, WATCHSIZE_MIN);
1217 >  class_delete_marked();      /* Make sure classes are valid */
1218   }
1219  
1220   /* lookup_confhost()
# Line 2029 | Line 1222 | validate_conf(void)
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   {
2035 –  struct AccessItem *aconf;
1228    struct addrinfo hints, *res;
1229  
2038 –  aconf = map_to_conf(conf);
2039 –
2040 –  if (EmptyString(aconf->host) ||
2041 –      EmptyString(aconf->user))
2042 –  {
2043 –    ilog(LOG_TYPE_IRCD, "Host/server name error: (%s) (%s)",
2044 –         aconf->host, conf->name);
2045 –    return;
2046 –  }
2047 –
2048 –  if (strchr(aconf->host, '*') ||
2049 –      strchr(aconf->host, '?'))
2050 –    return;
2051 –
1230    /* Do name lookup now on hostnames given and store the
1231     * ip numbers in conf structure.
1232     */
# Line 2060 | 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  
2071 –  memcpy(&aconf->ipnum, res->ai_addr, res->ai_addrlen);
2072 –  aconf->ipnum.ss_len = res->ai_addrlen;
2073 –  aconf->ipnum.ss.ss_family = res->ai_family;
1253    freeaddrinfo(res);
1254   }
1255  
# Line 2085 | 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 2107 | Line 1286 | conf_connect_allowed(struct irc_ssaddr *
1286    return 0;
1287   }
1288  
2110 – static struct AccessItem *
2111 – find_regexp_kline(const char *uhi[])
2112 – {
2113 – #ifdef HAVE_LIBPCRE
2114 –  const dlink_node *ptr = NULL;
2115 –
2116 –  DLINK_FOREACH(ptr, rkconf_items.head)
2117 –  {
2118 –    struct AccessItem *aptr = map_to_conf(ptr->data);
2119 –
2120 –    assert(aptr->regexuser);
2121 –    assert(aptr->regexhost);
2122 –
2123 –    if (!ircd_pcre_exec(aptr->regexuser, uhi[0]) &&
2124 –        (!ircd_pcre_exec(aptr->regexhost, uhi[1]) ||
2125 –         !ircd_pcre_exec(aptr->regexhost, uhi[2])))
2126 –      return aptr;
2127 –  }
2128 – #endif
2129 –  return NULL;
2130 – }
2131 –
2132 – /* find_kill()
2133 – *
2134 – * inputs       - pointer to client structure
2135 – * output       - pointer to struct AccessItem if found
2136 – * side effects - See if this user is klined already,
2137 – *                and if so, return struct AccessItem pointer
2138 – */
2139 – struct AccessItem *
2140 – find_kill(struct Client *client_p)
2141 – {
2142 –  struct AccessItem *aconf = NULL;
2143 –  const char *uhi[3];
2144 –
2145 –  uhi[0] = client_p->username;
2146 –  uhi[1] = client_p->host;
2147 –  uhi[2] = client_p->sockhost;
2148 –
2149 –  assert(client_p != NULL);
2150 –
2151 –  aconf = find_kline_conf(client_p->host, client_p->username,
2152 –                          &client_p->localClient->ip,
2153 –                          client_p->localClient->aftype);
2154 –  if (aconf == NULL)
2155 –    aconf = find_regexp_kline(uhi);
2156 –
2157 –  if (aconf && (aconf->status & CONF_KLINE))
2158 –    return aconf;
2159 –
2160 –  return NULL;
2161 – }
2162 –
2163 – struct AccessItem *
2164 – find_gline(struct Client *client_p)
2165 – {
2166 –  struct AccessItem *aconf;
2167 –
2168 –  assert(client_p != NULL);
2169 –
2170 –  aconf = find_gline_conf(client_p->host, client_p->username,
2171 –                          &client_p->localClient->ip,
2172 –                          client_p->localClient->aftype);
2173 –
2174 –  if (aconf && (aconf->status & CONF_GLINE))
2175 –    return aconf;
2176 –
2177 –  return NULL;
2178 – }
2179 –
2180 – /* add_temp_line()
2181 – *
2182 – * inputs        - pointer to struct ConfItem
2183 – * output        - none
2184 – * Side effects  - links in given struct ConfItem into
2185 – *                 temporary *line link list
2186 – */
2187 – void
2188 – add_temp_line(struct ConfItem *conf)
2189 – {
2190 –  struct AccessItem *aconf;
2191 –
2192 –  if (conf->type == DLINE_TYPE)
2193 –  {
2194 –    aconf = map_to_conf(conf);
2195 –    SetConfTemporary(aconf);
2196 –    dlinkAdd(conf, &conf->node, &temporary_dlines);
2197 –    MyFree(aconf->user);
2198 –    aconf->user = NULL;
2199 –    add_conf_by_address(CONF_DLINE, aconf);
2200 –  }
2201 –  else if (conf->type == KLINE_TYPE)
2202 –  {
2203 –    aconf = map_to_conf(conf);
2204 –    SetConfTemporary(aconf);
2205 –    dlinkAdd(conf, &conf->node, &temporary_klines);
2206 –    add_conf_by_address(CONF_KILL, aconf);
2207 –  }
2208 –  else if (conf->type == GLINE_TYPE)
2209 –  {
2210 –    aconf = map_to_conf(conf);
2211 –    SetConfTemporary(aconf);
2212 –    dlinkAdd(conf, &conf->node, &temporary_glines);
2213 –    add_conf_by_address(CONF_GLINE, aconf);
2214 –  }
2215 –  else if (conf->type == XLINE_TYPE)
2216 –  {
2217 –    conf->flags |= CONF_FLAGS_TEMPORARY;
2218 –    dlinkAdd(conf, make_dlink_node(), &temporary_xlines);
2219 –  }
2220 –  else if (conf->type == RXLINE_TYPE)
2221 –  {
2222 –    conf->flags |= CONF_FLAGS_TEMPORARY;
2223 –    dlinkAdd(conf, make_dlink_node(), &temporary_rxlines);
2224 –  }
2225 –  else if (conf->type == RKLINE_TYPE)
2226 –  {
2227 –    conf->flags |= CONF_FLAGS_TEMPORARY;
2228 –    dlinkAdd(conf, make_dlink_node(), &temporary_rklines);
2229 –  }
2230 –  else if ((conf->type == NRESV_TYPE) || (conf->type == CRESV_TYPE))
2231 –  {
2232 –    conf->flags |= CONF_FLAGS_TEMPORARY;
2233 –    dlinkAdd(conf, make_dlink_node(), &temporary_resv);
2234 –  }
2235 – }
2236 –
1289   /* cleanup_tklines()
1290   *
1291   * inputs       - NONE
# Line 2244 | Line 1296 | add_temp_line(struct ConfItem *conf)
1296   void
1297   cleanup_tklines(void *notused)
1298   {
1299 <  expire_tklines(&temporary_glines);
1300 <  expire_tklines(&temporary_klines);
1301 <  expire_tklines(&temporary_dlines);
1302 <  expire_tklines(&temporary_xlines);
2251 <  expire_tklines(&temporary_rxlines);
2252 <  expire_tklines(&temporary_rklines);
2253 <  expire_tklines(&temporary_resv);
1299 >  hostmask_expire_temporary();
1300 >  expire_tklines(&xconf_items);
1301 >  expire_tklines(&nresv_items);
1302 >  expire_tklines(&cresv_items);
1303   }
1304  
1305   /* expire_tklines()
# Line 2262 | 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;
2267 <  struct ConfItem *conf;
2268 <  struct MatchItem *xconf;
2269 <  struct MatchItem *nconf;
2270 <  struct AccessItem *aconf;
2271 <  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;
2276 –    if (conf->type == GLINE_TYPE ||
2277 –        conf->type == KLINE_TYPE ||
2278 –        conf->type == DLINE_TYPE)
2279 –    {
2280 –      aconf = (struct AccessItem *)map_to_conf(conf);
2281 –      if (aconf->hold <= CurrentTime)
2282 –      {
2283 –        /* XXX - Do we want GLINE expiry notices?? */
2284 –        /* Alert opers that a TKline expired - Hwy */
2285 –        if (ConfigFileEntry.tkline_expire_notices)
2286 –        {
2287 –          if (aconf->status & CONF_KILL)
2288 –          {
2289 –            sendto_realops_flags(UMODE_ALL, L_ALL,
2290 –                                 "Temporary K-line for [%s@%s] expired",
2291 –                                 (aconf->user) ? aconf->user : "*",
2292 –                                 (aconf->host) ? aconf->host : "*");
2293 –          }
2294 –          else if (conf->type == DLINE_TYPE)
2295 –          {
2296 –            sendto_realops_flags(UMODE_ALL, L_ALL,
2297 –                                 "Temporary D-line for [%s] expired",
2298 –                                 (aconf->host) ? aconf->host : "*");
2299 –          }
2300 –        }
1320  
1321 <        dlinkDelete(ptr, tklist);
1322 <        delete_one_address_conf(aconf->host, aconf);
1323 <      }
1324 <    }
2306 <    else if (conf->type == XLINE_TYPE ||
2307 <             conf->type == RXLINE_TYPE)
2308 <    {
2309 <      xconf = (struct MatchItem *)map_to_conf(conf);
2310 <      if (xconf->hold <= CurrentTime)
2311 <      {
2312 <        if (ConfigFileEntry.tkline_expire_notices)
2313 <          sendto_realops_flags(UMODE_ALL, L_ALL,
2314 <                               "Temporary X-line for [%s] %sexpired", conf->name,
2315 <                               conf->type == RXLINE_TYPE ? "(REGEX) " : "");
2316 <        dlinkDelete(ptr, tklist);
2317 <        free_dlink_node(ptr);
2318 <        delete_conf_item(conf);
2319 <      }
2320 <    }
2321 <    else if (conf->type == RKLINE_TYPE)
1321 >    if (!conf->until || conf->until > CurrentTime)
1322 >      continue;
1323 >
1324 >    if (conf->type == CONF_XLINE)
1325      {
1326 <      aconf = map_to_conf(conf);
1327 <      if (aconf->hold <= CurrentTime)
1328 <      {
1329 <        if (ConfigFileEntry.tkline_expire_notices)
2327 <           sendto_realops_flags(UMODE_ALL, L_ALL,
2328 <                                "Temporary K-line for [%s@%s] (REGEX) expired",
2329 <                                (aconf->user) ? aconf->user : "*",
2330 <                                (aconf->host) ? aconf->host : "*");
2331 <        dlinkDelete(ptr, tklist);
2332 <        free_dlink_node(ptr);
2333 <        delete_conf_item(conf);
2334 <      }
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)
2340 <      {
2341 <        if (ConfigFileEntry.tkline_expire_notices)
2342 <          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);
2345 <        free_dlink_node(ptr);
2346 <        delete_conf_item(conf);
2347 <      }
2348 <    }
2349 <    else if (conf->type == CRESV_TYPE)
2350 <    {
2351 <      cconf = (struct ResvChannel *)map_to_conf(conf);
2352 <      if (cconf->hold <= CurrentTime)
2353 <      {
2354 <        if (ConfigFileEntry.tkline_expire_notices)
2355 <          sendto_realops_flags(UMODE_ALL, L_ALL,
2356 <                               "Temporary RESV for [%s] expired", cconf->name);
2357 <        delete_channel_resv(cconf);
2358 <      }
1336 >      conf_free(conf);
1337      }
1338    }
1339   }
# Line 2368 | 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;
2395 –  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 2413 | Line 1392 | oper_privs_as_string(const unsigned int
1392   *         "oper" is server name for remote opers
1393   * Side effects: None.
1394   */
1395 < char *
1395 > const char *
1396   get_oper_name(const struct Client *client_p)
1397   {
1398 <  dlink_node *cnode;
2420 <  struct ConfItem *conf;
2421 <  struct AccessItem *aconf;
2422 <
1398 >  const dlink_node *cnode = NULL;
1399    /* +5 for !,@,{,} and null */
1400    static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5];
1401  
1402    if (MyConnect(client_p))
1403    {
1404 <    DLINK_FOREACH(cnode, client_p->localClient->confs.head)
1404 >    if ((cnode = client_p->localClient->confs.head))
1405      {
1406 <      conf = cnode->data;
2431 <      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 2459 | 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  
1451 <  if ((conf_parser_ctx.conf_file = fbopen(filename, "r")) == NULL)
1451 >  if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL)
1452    {
1453      if (cold)
1454      {
# Line 2483 | 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 2494 | Line 1469 | read_conf_files(int cold)
1469      clear_out_old_conf();
1470  
1471    read_conf(conf_parser_ctx.conf_file);
1472 <  fbclose(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), "b%s%s:%d",
1479 <           ConfigChannel.use_except ? "e" : "",
2502 <           ConfigChannel.use_invex ? "I" : "", 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);
1482 +  add_isupport("CHANTYPES", "#", -1);
1483  
1484 <  if (ConfigChannel.disable_local_channels)
1485 <    add_isupport("CHANTYPES", "#", -1);
2508 <  else
2509 <    add_isupport("CHANTYPES", "#&", -1);
2510 <
2511 <  snprintf(chanlimit, sizeof(chanlimit), "%s:%d",
2512 <           ConfigChannel.disable_local_channels ? "#" : "#&",
2513 <           ConfigChannel.max_chans_per_user);
1484 >  snprintf(chanlimit, sizeof(chanlimit), "#:%d",
1485 >           ConfigChannel.max_chans_per_user);
1486    add_isupport("CHANLIMIT", chanlimit, -1);
1487 <  snprintf(chanmodes, sizeof(chanmodes), "%s%s%s",
2516 <           ConfigChannel.use_except ? "e" : "",
2517 <           ConfigChannel.use_invex ? "I" : "", "b,k,l,imnprstORS");
1487 >  snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,imnprstORS");
1488    add_isupport("CHANNELLEN", NULL, LOCAL_CHANNELLEN);
1489 <
2520 <  if (ConfigChannel.use_except)
2521 <    add_isupport("EXCEPTS", "e", -1);
2522 <  if (ConfigChannel.use_invex)
2523 <    add_isupport("INVEX", "I", -1);
1489 >  add_isupport("TOPICLEN", NULL, ServerInfo.max_topic_length);
1490    add_isupport("CHANMODES", chanmodes, -1);
1491  
1492    /*
# Line 2528 | Line 1494 | read_conf_files(int cold)
1494     * on strlen(form_str(RPL_ISUPPORT))
1495     */
1496    rebuild_isupport_message_line();
2531 –
2532 – #ifdef HAVE_LIBPCRE
2533 –  parse_conf_file(RKLINE_TYPE, cold);
2534 –  parse_conf_file(RXLINE_TYPE, cold);
2535 – #endif
2536 –  parse_conf_file(KLINE_TYPE, cold);
2537 –  parse_conf_file(DLINE_TYPE, cold);
2538 –  parse_conf_file(XLINE_TYPE, cold);
2539 –  parse_conf_file(NRESV_TYPE, cold);
2540 –  parse_conf_file(CRESV_TYPE, cold);
2541 – }
2542 –
2543 – /* parse_conf_file()
2544 – *
2545 – * inputs       - type of conf file to parse
2546 – * output       - none
2547 – * side effects - conf file for givenconf type is opened and read then parsed
2548 – */
2549 – static void
2550 – parse_conf_file(int type, int cold)
2551 – {
2552 –  FBFILE *file = NULL;
2553 –  const char *filename = get_conf_name(type);
2554 –
2555 –  if ((file = fbopen(filename, "r")) == NULL)
2556 –  {
2557 –    if (cold)
2558 –      ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
2559 –           filename, strerror(errno));
2560 –    else
2561 –      sendto_realops_flags(UMODE_ALL, L_ALL,
2562 –                    "Unable to read configuration file '%s': %s",
2563 –                           filename, strerror(errno));
2564 –  }
2565 –  else
2566 –  {
2567 –    parse_csv_file(file, type);
2568 –    fbclose(file);
2569 –  }
1497   }
1498  
1499   /* clear_out_old_conf()
# Line 2579 | Line 1506 | static void
1506   clear_out_old_conf(void)
1507   {
1508    dlink_node *ptr = NULL, *next_ptr = NULL;
1509 <  struct ConfItem *conf;
2583 <  struct AccessItem *aconf;
2584 <  struct ClassItem *cltmp;
2585 <  struct MatchItem *match_item;
1509 >  struct MaskItem *conf;
1510    dlink_list *free_items [] = {
1511 <    &server_items,   &oconf_items,    &hub_items, &leaf_items,
1512 <     &uconf_items,   &xconf_items, &rxconf_items, &rkconf_items,
1513 <     &nresv_items, &cluster_items,  &gdeny_items, &service_items, NULL
1511 >    &server_items,   &oconf_items,
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 2594 | 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;
2603 –      /* XXX This is less than pretty */
2604 –      if (conf->type == SERVER_TYPE)
2605 –      {
2606 –        aconf = map_to_conf(conf);
1527  
1528 <        if (aconf->clients != 0)
2609 <        {
2610 <          SetConfIllegal(aconf);
2611 <          dlinkDelete(&conf->node, &server_items);
2612 <        }
2613 <        else
2614 <        {
2615 <          delete_conf_item(conf);
2616 <        }
2617 <      }
2618 <      else if (conf->type == OPER_TYPE)
2619 <      {
2620 <        aconf = map_to_conf(conf);
1528 >      dlinkDelete(&conf->node, map_to_list(conf->type));
1529  
1530 <        if (aconf->clients != 0)
1531 <        {
2624 <          SetConfIllegal(aconf);
2625 <          dlinkDelete(&conf->node, &oconf_items);
2626 <        }
2627 <        else
2628 <        {
2629 <          delete_conf_item(conf);
2630 <        }
2631 <      }
2632 <      else if (conf->type == CLIENT_TYPE)
1530 >      /* XXX This is less than pretty */
1531 >      if (conf->type == CONF_SERVER || conf->type == CONF_OPER)
1532        {
1533 <        aconf = map_to_conf(conf);
1534 <
2636 <        if (aconf->clients != 0)
2637 <        {
2638 <          SetConfIllegal(aconf);
2639 <        }
2640 <        else
2641 <        {
2642 <          delete_conf_item(conf);
2643 <        }
1533 >        if (!conf->ref_count)
1534 >          conf_free(conf);
1535        }
1536 <      else if (conf->type == XLINE_TYPE  ||
2646 <               conf->type == RXLINE_TYPE ||
2647 <               conf->type == RKLINE_TYPE)
1536 >      else if (conf->type == CONF_XLINE)
1537        {
1538 <        /* temporary (r)xlines are also on
1539 <         * the (r)xconf items list */
2651 <        if (conf->flags & CONF_FLAGS_TEMPORARY)
2652 <          continue;
2653 <
2654 <        delete_conf_item(conf);
1538 >        if (!conf->until)
1539 >          conf_free(conf);
1540        }
1541        else
1542 <      {
2658 <        if ((conf->type == LEAF_TYPE) || (conf->type == HUB_TYPE))
2659 <        {
2660 <          match_item = map_to_conf(conf);
2661 <          if (match_item->ref_count <= 0)
2662 <            delete_conf_item(conf);
2663 <          else
2664 <          {
2665 <            match_item->illegal = 1;
2666 <            dlinkDelete(&conf->node, *iterator);
2667 <          }
2668 <        }
2669 <        else
2670 <          delete_conf_item(conf);
2671 <      }
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)
2680 <  {
2681 <    cltmp = map_to_conf(ptr->data);
2682 <
2683 <    if (ptr != class_items.tail)  /* never mark the "default" class */
2684 <      cltmp->active = 0;
2685 <  }
1552 >  class_mark_for_deletion();
1553  
1554    clear_out_address_conf();
1555  
# Line 2699 | 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 2707 | Line 1574 | clear_out_old_conf(void)
1574  
1575    MyFree(ServerInfo.rsa_private_key_file);
1576    ServerInfo.rsa_private_key_file = NULL;
2710 – #endif
1577  
1578 <  /* clean out old resvs from the conf */
1579 <  clear_conf_resv();
1578 >  if (ServerInfo.server_ctx)
1579 >    SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|
1580 >                                               SSL_OP_NO_SSLv3|
1581 >                                               SSL_OP_NO_TLSv1);
1582 >  if (ServerInfo.client_ctx)
1583 >    SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|
1584 >                                               SSL_OP_NO_SSLv3|
1585 >                                               SSL_OP_NO_TLSv1);
1586 > #endif
1587  
1588    /* clean out AdminInfo */
1589    MyFree(AdminInfo.name);
# Line 2720 | Line 1593 | clear_out_old_conf(void)
1593    MyFree(AdminInfo.description);
1594    AdminInfo.description = NULL;
1595  
2723 –  /* operator{} and class{} blocks are freed above */
1596    /* clean out listeners */
1597    close_listeners();
1598  
2727 –  /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{},
2728 –   * exempt{} and gecos{} blocks are freed above too
2729 –   */
2730 –
1599    /* clean out general */
1600    MyFree(ConfigFileEntry.service_name);
1601    ConfigFileEntry.service_name = NULL;
2734 –
2735 –  MyFree(ConfigFileEntry.servlink_path);
2736 –  ConfigFileEntry.servlink_path = NULL;
2737 – #ifdef HAVE_LIBCRYPTO
2738 –  ConfigFileEntry.default_cipher_preference = NULL;
2739 – #endif /* HAVE_LIBCRYPTO */
2740 –  delete_isupport("INVEX");
2741 –  delete_isupport("EXCEPTS");
2742 – }
2743 –
2744 – /* flush_deleted_I_P()
2745 – *
2746 – * inputs       - none
2747 – * output       - none
2748 – * side effects - This function removes I/P conf items
2749 – */
2750 – static void
2751 – flush_deleted_I_P(void)
2752 – {
2753 –  dlink_node *ptr;
2754 –  dlink_node *next_ptr;
2755 –  struct ConfItem *conf;
2756 –  struct AccessItem *aconf;
2757 –  dlink_list * free_items [] = {
2758 –    &server_items, &oconf_items, NULL
2759 –  };
2760 –  dlink_list ** iterator = free_items; /* C is dumb */
2761 –
2762 –  /* flush out deleted I and P lines
2763 –   * although still in use.
2764 –   */
2765 –  for (; *iterator != NULL; iterator++)
2766 –  {
2767 –    DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head)
2768 –    {
2769 –      conf = ptr->data;
2770 –      aconf = (struct AccessItem *)map_to_conf(conf);
2771 –
2772 –      if (IsConfIllegal(aconf))
2773 –      {
2774 –        dlinkDelete(ptr, *iterator);
2775 –
2776 –        if (aconf->clients == 0)
2777 –          delete_conf_item(conf);
2778 –      }
2779 –    }
2780 –  }
2781 – }
2782 –
2783 – /* get_conf_name()
2784 – *
2785 – * inputs       - type of conf file to return name of file for
2786 – * output       - pointer to filename for type of conf
2787 – * side effects - none
2788 – */
2789 – const char *
2790 – get_conf_name(ConfType type)
2791 – {
2792 –  switch (type)
2793 –  {
2794 –    case CONF_TYPE:
2795 –      return ConfigFileEntry.configfile;
2796 –      break;
2797 –    case KLINE_TYPE:
2798 –      return ConfigFileEntry.klinefile;
2799 –      break;
2800 –    case RKLINE_TYPE:
2801 –      return ConfigFileEntry.rklinefile;
2802 –      break;
2803 –    case DLINE_TYPE:
2804 –      return ConfigFileEntry.dlinefile;
2805 –      break;
2806 –    case XLINE_TYPE:
2807 –      return ConfigFileEntry.xlinefile;
2808 –      break;
2809 –    case RXLINE_TYPE:
2810 –      return ConfigFileEntry.rxlinefile;
2811 –      break;
2812 –    case CRESV_TYPE:
2813 –      return ConfigFileEntry.cresvfile;
2814 –      break;
2815 –    case NRESV_TYPE:
2816 –      return ConfigFileEntry.nresvfile;
2817 –      break;
2818 –    case GLINE_TYPE:
2819 –      return ConfigFileEntry.glinefile;
2820 –      break;
2821 –
2822 –    default:
2823 –      return NULL;  /* This should NEVER HAPPEN since we call this function
2824 –                       only with the above values, this will cause us to core
2825 –                       at some point if this happens so we know where it was */
2826 –  }
2827 – }
2828 –
2829 – #define BAD_PING (-1)
2830 –
2831 – /* get_conf_ping()
2832 – *
2833 – * inputs       - pointer to struct AccessItem
2834 – *              - pointer to a variable that receives ping warning time
2835 – * output       - ping frequency
2836 – * side effects - NONE
2837 – */
2838 – static int
2839 – get_conf_ping(struct ConfItem *conf, int *pingwarn)
2840 – {
2841 –  struct ClassItem *aclass;
2842 –  struct AccessItem *aconf;
2843 –
2844 –  if (conf != NULL)
2845 –  {
2846 –    aconf = (struct AccessItem *)map_to_conf(conf);
2847 –    if (aconf->class_ptr != NULL)
2848 –    {
2849 –      aclass = (struct ClassItem *)map_to_conf(aconf->class_ptr);
2850 –      *pingwarn = PingWarning(aclass);
2851 –      return PingFreq(aclass);
2852 –    }
2853 –  }
2854 –
2855 –  return BAD_PING;
2856 – }
2857 –
2858 – /* get_client_class()
2859 – *
2860 – * inputs       - pointer to client struct
2861 – * output       - pointer to name of class
2862 – * side effects - NONE
2863 – */
2864 – const char *
2865 – get_client_class(struct Client *target_p)
2866 – {
2867 –  dlink_node *ptr;
2868 –  struct ConfItem *conf;
2869 –  struct AccessItem *aconf;
2870 –
2871 –  if (target_p != NULL && !IsMe(target_p) &&
2872 –      target_p->localClient->confs.head != NULL)
2873 –  {
2874 –    DLINK_FOREACH(ptr, target_p->localClient->confs.head)
2875 –    {
2876 –      conf = ptr->data;
2877 –
2878 –      if (conf->type == CLIENT_TYPE || conf->type == SERVER_TYPE ||
2879 –          conf->type == OPER_TYPE)
2880 –      {
2881 –        aconf = (struct AccessItem *) map_to_conf(conf);
2882 –        if (aconf->class_ptr != NULL)
2883 –          return aconf->class_ptr->name;
2884 –      }
2885 –    }
2886 –  }
2887 –
2888 –  return "default";
2889 – }
2890 –
2891 – /* get_client_ping()
2892 – *
2893 – * inputs       - pointer to client struct
2894 – *              - pointer to a variable that receives ping warning time
2895 – * output       - ping frequency
2896 – * side effects - NONE
2897 – */
2898 – int
2899 – get_client_ping(struct Client *target_p, int *pingwarn)
2900 – {
2901 –  int ping;
2902 –  struct ConfItem *conf;
2903 –  dlink_node *nlink;
2904 –
2905 –  if (target_p->localClient->confs.head != NULL)
2906 –    DLINK_FOREACH(nlink, target_p->localClient->confs.head)
2907 –    {
2908 –      conf = nlink->data;
2909 –
2910 –      if ((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2911 –          (conf->type == OPER_TYPE))
2912 –      {
2913 –        ping = get_conf_ping(conf, pingwarn);
2914 –        if (ping > 0)
2915 –          return ping;
2916 –      }
2917 –    }
2918 –
2919 –  *pingwarn = 0;
2920 –  return DEFAULT_PINGFREQUENCY;
2921 – }
2922 –
2923 – /* find_class()
2924 – *
2925 – * inputs       - string name of class
2926 – * output       - corresponding Class pointer
2927 – * side effects - NONE
2928 – */
2929 – struct ConfItem *
2930 – find_class(const char *classname)
2931 – {
2932 –  struct ConfItem *conf;
2933 –
2934 –  if ((conf = find_exact_name_conf(CLASS_TYPE, NULL, classname, NULL, NULL)) != NULL)
2935 –    return conf;
2936 –
2937 –  return class_default;
2938 – }
2939 –
2940 – /* check_class()
2941 – *
2942 – * inputs       - NONE
2943 – * output       - NONE
2944 – * side effects -
2945 – */
2946 – void
2947 – check_class(void)
2948 – {
2949 –  dlink_node *ptr = NULL, *next_ptr = NULL;
2950 –
2951 –  DLINK_FOREACH_SAFE(ptr, next_ptr, class_items.head)
2952 –  {
2953 –    struct ClassItem *aclass = map_to_conf(ptr->data);
2954 –
2955 –    if (!aclass->active && !CurrUserCount(aclass))
2956 –    {
2957 –      destroy_cidr_class(aclass);
2958 –      delete_conf_item(ptr->data);
2959 –    }
2960 –  }
2961 – }
2962 –
2963 – /* init_class()
2964 – *
2965 – * inputs       - NONE
2966 – * output       - NONE
2967 – * side effects -
2968 – */
2969 – void
2970 – init_class(void)
2971 – {
2972 –  struct ClassItem *aclass;
2973 –
2974 –  class_default = make_conf_item(CLASS_TYPE);
2975 –
2976 –  aclass = map_to_conf(class_default);
2977 –  aclass->active = 1;
2978 –  DupString(class_default->name, "default");
2979 –  ConFreq(aclass)  = DEFAULT_CONNECTFREQUENCY;
2980 –  PingFreq(aclass) = DEFAULT_PINGFREQUENCY;
2981 –  MaxTotal(aclass) = MAXIMUM_LINKS_DEFAULT;
2982 –  MaxSendq(aclass) = DEFAULT_SENDQ;
2983 –
2984 –  client_check_cb = register_callback("check_client", check_client);
2985 – }
2986 –
2987 – /* get_sendq()
2988 – *
2989 – * inputs       - pointer to client
2990 – * output       - sendq for this client as found from its class
2991 – * side effects - NONE
2992 – */
2993 – unsigned int
2994 – get_sendq(struct Client *client_p)
2995 – {
2996 –  unsigned int sendq = DEFAULT_SENDQ;
2997 –  dlink_node *ptr;
2998 –  struct ConfItem *conf;
2999 –  struct ConfItem *class_conf;
3000 –  struct ClassItem *aclass;
3001 –  struct AccessItem *aconf;
3002 –
3003 –  if (client_p && !IsMe(client_p) && (client_p->localClient->confs.head))
3004 –  {
3005 –    DLINK_FOREACH(ptr, client_p->localClient->confs.head)
3006 –    {
3007 –      conf = ptr->data;
3008 –      if ((conf->type == SERVER_TYPE) || (conf->type == OPER_TYPE)
3009 –          || (conf->type == CLIENT_TYPE))
3010 –      {
3011 –        aconf = (struct AccessItem *)map_to_conf(conf);
3012 –        if ((class_conf = aconf->class_ptr) == NULL)
3013 –          continue;
3014 –        aclass = (struct ClassItem *)map_to_conf(class_conf);
3015 –        sendq = MaxSendq(aclass);
3016 –        return sendq;
3017 –      }
3018 –    }
3019 –  }
3020 –  /* XXX return a default?
3021 –   * if here, then there wasn't an attached conf with a sendq
3022 –   * that is very bad -Dianora
3023 –   */
3024 –  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);
3037 <  struct ClassItem *class = NULL;
3038 <
3039 <  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)
3056 <    class = map_to_conf(aconf->class_ptr);
3057 <
3058 <  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  
3072 – /* conf_add_server()
3073 – *
3074 – * inputs       - pointer to config item
3075 – *              - pointer to link count already on this conf
3076 – * output       - NONE
3077 – * side effects - Add a connect block
3078 – */
3079 – int
3080 – conf_add_server(struct ConfItem *conf, const char *class_name)
3081 – {
3082 –  struct AccessItem *aconf;
3083 –  struct split_nuh_item nuh;
3084 –  char conf_user[USERLEN + 1];
3085 –  char conf_host[HOSTLEN + 1];
3086 –
3087 –  aconf = map_to_conf(conf);
3088 –
3089 –  conf_add_class_to_conf(conf, class_name);
3090 –
3091 –  if (!aconf->host || !conf->name)
3092 –  {
3093 –    sendto_realops_flags(UMODE_ALL, L_ALL, "Bad connect block");
3094 –    ilog(LOG_TYPE_IRCD, "Bad connect block");
3095 –    return -1;
3096 –  }
3097 –
3098 –  if (EmptyString(aconf->passwd) && !IsConfCryptLink(aconf))
3099 –  {
3100 –    sendto_realops_flags(UMODE_ALL, L_ALL, "Bad connect block, name %s",
3101 –                         conf->name);
3102 –    ilog(LOG_TYPE_IRCD, "Bad connect block, host %s", conf->name);
3103 –    return -1;
3104 –  }
3105 –
3106 –  nuh.nuhmask  = aconf->host;
3107 –  nuh.nickptr  = NULL;
3108 –  nuh.userptr  = conf_user;
3109 –  nuh.hostptr  = conf_host;
3110 –
3111 –  nuh.nicksize = 0;
3112 –  nuh.usersize = sizeof(conf_user);
3113 –  nuh.hostsize = sizeof(conf_host);
3114 –
3115 –  split_nuh(&nuh);
3116 –
3117 –  MyFree(aconf->host);
3118 –  aconf->host = NULL;
3119 –
3120 –  DupString(aconf->user, conf_user); /* somehow username checking for servers
3121 –                                 got lost in H6/7, will have to be re-added */
3122 –  DupString(aconf->host, conf_host);
3123 –
3124 –  lookup_confhost(conf);
3125 –
3126 –  return 0;
3127 – }
3128 –
1643   /* yyerror()
1644   *
1645   * inputs       - message from parser
# Line 3141 | 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 < int
1666 < conf_fbgets(char *lbuf, unsigned int max_size, FBFILE *fb)
1665 > void
1666 > conf_error_report(const char *msg)
1667   {
1668 <  if (fbgets(lbuf, max_size, fb) == NULL)
3154 <    return 0;
3155 <
3156 <  return strlen(lbuf);
3157 < }
1668 >  char newlinebuf[IRCD_BUFSIZE];
1669  
1670 < int
1671 < conf_yy_fatal_error(const char *msg)
1672 < {
1673 <  return 0;
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);
1676   }
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 3173 | Line 1686 | conf_yy_fatal_error(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 3220 | Line 1766 | valid_tkline(const char *p, int minutes)
1766   int
1767   valid_wild_card(struct Client *source_p, int warn, int count, ...)
1768   {
3223 –  char *p;
1769    char tmpch;
1770    int nonwild = 0;
1771    va_list args;
# Line 3241 | 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 3254 | 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 3275 | 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 3297 | 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 3320 | 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",
3324 <                 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),
3332 <               me.name, source_p->name, cmd);
1880 >    sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1881      return -1;
1882    }
1883  
# Line 3343 | 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 3356 | 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);
3361 <        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),
3367 <                   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);
3375 <        return -1;
1919 >        sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1920 >        return -1;
1921        }
1922  
1923        *target_server = *parv;
# Line 3385 | 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 3393 | 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",
3397 <                 me.name, source_p->name);
1941 >      sendto_one_notice(source_p, &me, ":Invalid character '!' in kline");
1942        return -1;
1943      }
1944  
# Line 3411 | 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 3450 | 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,
3482 <                   ":%s NOTICE %s :%s is E-lined",
3483 <                   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 3515 | Line 2058 | find_user_host(struct Client *source_p,
2058   int
2059   valid_comment(struct Client *source_p, char *comment, int warn)
2060   {
3518 –  if (strchr(comment, '"'))
3519 –  {
3520 –    if (warn)
3521 –      sendto_one(source_p, ":%s NOTICE %s :Invalid character '\"' in comment",
3522 –                 me.name, source_p->name);
3523 –    return 0;
3524 –  }
3525 –
2061    if (strlen(comment) > REASONLEN)
2062      comment[REASONLEN-1] = '\0';
2063  
# Line 3537 | 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 (password == NULL || aconf->passwd == NULL)
2079 >  if (EmptyString(password) || EmptyString(conf->passwd))
2080      return 0;
2081  
2082 <  if (aconf->flags & CONF_FLAGS_ENCRYPTED)
2083 <  {
3549 <    /* use first two chars of the password they send in as salt */
3550 <    /* If the password in the conf is MD5, and ircd is linked
3551 <     * to scrypt on FreeBSD, or the standard crypt library on
3552 <     * glibc Linux, then this code will work fine on generating
3553 <     * the proper encrypted hash for comparison.
3554 <     */
3555 <    if (*aconf->passwd)
3556 <      encr = crypt(password, aconf->passwd);
3557 <    else
3558 <      encr = "";
3559 <  }
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 3568 | 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
2096 < *              - cluster type -- CLUSTER_KLINE etc. from s_conf.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
2099   * side effects - Take source_p send the pattern with args given
# Line 3589 | 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 3644 | 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 3683 | Line 2208 | split_nuh(struct split_nuh_item *const i
2208      }
2209    }
2210   }
3686 –
3687 – /*
3688 – * flags_to_ascii
3689 – *
3690 – * inputs       - flags is a bitmask
3691 – *              - pointer to table of ascii letters corresponding
3692 – *                to each bit
3693 – *              - flag 1 for convert ToLower if bit missing
3694 – *                0 if ignore.
3695 – * output       - none
3696 – * side effects - string pointed to by p has bitmap chars written to it
3697 – */
3698 – static void
3699 – flags_to_ascii(unsigned int flags, const unsigned int bit_table[], char *p,
3700 –               int lowerit)
3701 – {
3702 –  unsigned int mask = 1;
3703 –  int i = 0;
3704 –
3705 –  for (mask = 1; (mask != 0) && (bit_table[i] != 0); mask <<= 1, i++)
3706 –  {
3707 –    if (flags & mask)
3708 –      *p++ = bit_table[i];
3709 –    else if (lowerit)
3710 –      *p++ = ToLower(bit_table[i]);
3711 –  }
3712 –  *p = '\0';
3713 – }
3714 –
3715 – /*
3716 – * cidr_limit_reached
3717 – *
3718 – * inputs       - int flag allowing over_rule of limits
3719 – *              - pointer to the ip to be added
3720 – *              - pointer to the class
3721 – * output       - non zero if limit reached
3722 – *                0 if limit not reached
3723 – * side effects -
3724 – */
3725 – static int
3726 – cidr_limit_reached(int over_rule,
3727 –                   struct irc_ssaddr *ip, struct ClassItem *aclass)
3728 – {
3729 –  dlink_node *ptr = NULL;
3730 –  struct CidrItem *cidr;
3731 –
3732 –  if (NumberPerCidr(aclass) <= 0)
3733 –    return 0;
3734 –
3735 –  if (ip->ss.ss_family == AF_INET)
3736 –  {
3737 –    if (CidrBitlenIPV4(aclass) <= 0)
3738 –      return 0;
3739 –
3740 –    DLINK_FOREACH(ptr, aclass->list_ipv4.head)
3741 –    {
3742 –      cidr = ptr->data;
3743 –      if (match_ipv4(ip, &cidr->mask, CidrBitlenIPV4(aclass)))
3744 –      {
3745 –        if (!over_rule && (cidr->number_on_this_cidr >= NumberPerCidr(aclass)))
3746 –          return -1;
3747 –        cidr->number_on_this_cidr++;
3748 –        return 0;
3749 –      }
3750 –    }
3751 –    cidr = MyMalloc(sizeof(struct CidrItem));
3752 –    cidr->number_on_this_cidr = 1;
3753 –    cidr->mask = *ip;
3754 –    mask_addr(&cidr->mask, CidrBitlenIPV4(aclass));
3755 –    dlinkAdd(cidr, &cidr->node, &aclass->list_ipv4);
3756 –  }
3757 – #ifdef IPV6
3758 –  else if (CidrBitlenIPV6(aclass) > 0)
3759 –  {
3760 –    DLINK_FOREACH(ptr, aclass->list_ipv6.head)
3761 –    {
3762 –      cidr = ptr->data;
3763 –      if (match_ipv6(ip, &cidr->mask, CidrBitlenIPV6(aclass)))
3764 –      {
3765 –        if (!over_rule && (cidr->number_on_this_cidr >= NumberPerCidr(aclass)))
3766 –          return -1;
3767 –        cidr->number_on_this_cidr++;
3768 –        return 0;
3769 –      }
3770 –    }
3771 –    cidr = MyMalloc(sizeof(struct CidrItem));
3772 –    cidr->number_on_this_cidr = 1;
3773 –    cidr->mask = *ip;
3774 –    mask_addr(&cidr->mask, CidrBitlenIPV6(aclass));
3775 –    dlinkAdd(cidr, &cidr->node, &aclass->list_ipv6);
3776 –  }
3777 – #endif
3778 –  return 0;
3779 – }
3780 –
3781 – /*
3782 – * remove_from_cidr_check
3783 – *
3784 – * inputs       - pointer to the ip to be removed
3785 – *              - pointer to the class
3786 – * output       - NONE
3787 – * side effects -
3788 – */
3789 – static void
3790 – remove_from_cidr_check(struct irc_ssaddr *ip, struct ClassItem *aclass)
3791 – {
3792 –  dlink_node *ptr = NULL;
3793 –  dlink_node *next_ptr = NULL;
3794 –  struct CidrItem *cidr;
3795 –
3796 –  if (NumberPerCidr(aclass) == 0)
3797 –    return;
3798 –
3799 –  if (ip->ss.ss_family == AF_INET)
3800 –  {
3801 –    if (CidrBitlenIPV4(aclass) <= 0)
3802 –      return;
3803 –
3804 –    DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv4.head)
3805 –    {
3806 –      cidr = ptr->data;
3807 –      if (match_ipv4(ip, &cidr->mask, CidrBitlenIPV4(aclass)))
3808 –      {
3809 –        cidr->number_on_this_cidr--;
3810 –        if (cidr->number_on_this_cidr == 0)
3811 –        {
3812 –          dlinkDelete(ptr, &aclass->list_ipv4);
3813 –          MyFree(cidr);
3814 –          return;
3815 –        }
3816 –      }
3817 –    }
3818 –  }
3819 – #ifdef IPV6
3820 –  else if (CidrBitlenIPV6(aclass) > 0)
3821 –  {
3822 –    DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv6.head)
3823 –    {
3824 –      cidr = ptr->data;
3825 –      if (match_ipv6(ip, &cidr->mask, CidrBitlenIPV6(aclass)))
3826 –      {
3827 –        cidr->number_on_this_cidr--;
3828 –        if (cidr->number_on_this_cidr == 0)
3829 –        {
3830 –          dlinkDelete(ptr, &aclass->list_ipv6);
3831 –          MyFree(cidr);
3832 –          return;
3833 –        }
3834 –      }
3835 –    }
3836 –  }
3837 – #endif
3838 – }
3839 –
3840 – static void
3841 – rebuild_cidr_list(int aftype, struct ConfItem *oldcl, struct ClassItem *newcl,
3842 –                  dlink_list *old_list, dlink_list *new_list, int changed)
3843 – {
3844 –  dlink_node *ptr;
3845 –  struct Client *client_p;
3846 –  struct ConfItem *conf;
3847 –  struct AccessItem *aconf;
3848 –
3849 –  if (!changed)
3850 –  {
3851 –    *new_list = *old_list;
3852 –    old_list->head = old_list->tail = NULL;
3853 –    old_list->length = 0;
3854 –    return;
3855 –  }
3856 –
3857 –  DLINK_FOREACH(ptr, local_client_list.head)
3858 –  {
3859 –    client_p = ptr->data;
3860 –    if (client_p->localClient->aftype != aftype)
3861 –      continue;
3862 –    if (dlink_list_length(&client_p->localClient->confs) == 0)
3863 –      continue;
3864 –
3865 –    conf = client_p->localClient->confs.tail->data;
3866 –    if (conf->type == CLIENT_TYPE)
3867 –    {
3868 –      aconf = map_to_conf(conf);
3869 –      if (aconf->class_ptr == oldcl)
3870 –        cidr_limit_reached(1, &client_p->localClient->ip, newcl);
3871 –    }
3872 –  }
3873 – }
3874 –
3875 – /*
3876 – * rebuild_cidr_class
3877 – *
3878 – * inputs       - pointer to old conf
3879 – *              - pointer to new_class
3880 – * output       - none
3881 – * side effects - rebuilds the class link list of cidr blocks
3882 – */
3883 – void
3884 – rebuild_cidr_class(struct ConfItem *conf, struct ClassItem *new_class)
3885 – {
3886 –  struct ClassItem *old_class = map_to_conf(conf);
3887 –
3888 –  if (NumberPerCidr(old_class) > 0 && NumberPerCidr(new_class) > 0)
3889 –  {
3890 –    if (CidrBitlenIPV4(old_class) > 0 && CidrBitlenIPV4(new_class) > 0)
3891 –      rebuild_cidr_list(AF_INET, conf, new_class,
3892 –                        &old_class->list_ipv4, &new_class->list_ipv4,
3893 –                        CidrBitlenIPV4(old_class) != CidrBitlenIPV4(new_class));
3894 –
3895 – #ifdef IPV6
3896 –    if (CidrBitlenIPV6(old_class) > 0 && CidrBitlenIPV6(new_class) > 0)
3897 –      rebuild_cidr_list(AF_INET6, conf, new_class,
3898 –                        &old_class->list_ipv6, &new_class->list_ipv6,
3899 –                        CidrBitlenIPV6(old_class) != CidrBitlenIPV6(new_class));
3900 – #endif
3901 –  }
3902 –
3903 –  destroy_cidr_class(old_class);
3904 – }
3905 –
3906 – /*
3907 – * destroy_cidr_list
3908 – *
3909 – * inputs       - pointer to class dlink list of cidr blocks
3910 – * output       - none
3911 – * side effects - completely destroys the class link list of cidr blocks
3912 – */
3913 – static void
3914 – destroy_cidr_list(dlink_list *list)
3915 – {
3916 –  dlink_node *ptr = NULL, *next_ptr = NULL;
3917 –
3918 –  DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
3919 –  {
3920 –    dlinkDelete(ptr, list);
3921 –    MyFree(ptr->data);
3922 –  }
3923 – }
3924 –
3925 – /*
3926 – * destroy_cidr_class
3927 – *
3928 – * inputs       - pointer to class
3929 – * output       - none
3930 – * side effects - completely destroys the class link list of cidr blocks
3931 – */
3932 – static void
3933 – destroy_cidr_class(struct ClassItem *aclass)
3934 – {
3935 –  destroy_cidr_list(&aclass->list_ipv4);
3936 –  destroy_cidr_list(&aclass->list_ipv6);
3937 – }

Diff Legend

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