ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
(Generate patch)

Comparing:
ircd-hybrid-8/src/conf.c (file contents), Revision 1381 by michael, Tue May 1 08:21:27 2012 UTC vs.
ircd-hybrid/trunk/src/conf.c (file contents), Revision 1751 by michael, Wed Jan 16 18:30:52 2013 UTC

# Line 25 | Line 25
25   #include "stdinc.h"
26   #include "list.h"
27   #include "ircd_defs.h"
28 #include "balloc.h"
28   #include "conf.h"
29   #include "s_serv.h"
30   #include "resv.h"
# Line 45 | Line 44
44   #include "send.h"
45   #include "s_gline.h"
46   #include "memory.h"
47 + #include "mempool.h"
48   #include "irc_res.h"
49   #include "userhost.h"
50   #include "s_user.h"
51   #include "channel_mode.h"
52   #include "parse.h"
53   #include "s_misc.h"
54 + #include "conf_db.h"
55 + #include "conf_class.h"
56  
55 struct Callback *client_check_cb = NULL;
57   struct config_server_hide ConfigServerHide;
58  
59   /* general conf items link list root, other than k lines etc. */
60   dlink_list service_items = { NULL, NULL, 0 };
61   dlink_list server_items  = { NULL, NULL, 0 };
62   dlink_list cluster_items = { NULL, NULL, 0 };
62 dlink_list hub_items     = { NULL, NULL, 0 };
63 dlink_list leaf_items    = { NULL, NULL, 0 };
63   dlink_list oconf_items   = { NULL, NULL, 0 };
64   dlink_list uconf_items   = { NULL, NULL, 0 };
65   dlink_list xconf_items   = { NULL, NULL, 0 };
66   dlink_list rxconf_items  = { NULL, NULL, 0 };
67   dlink_list rkconf_items  = { NULL, NULL, 0 };
68   dlink_list nresv_items   = { NULL, NULL, 0 };
70 dlink_list class_items   = { NULL, NULL, 0 };
71 dlink_list gdeny_items   = { NULL, NULL, 0 };
72
73 dlink_list temporary_xlines  = { NULL, NULL, 0 };
69   dlink_list temporary_resv = { NULL, NULL, 0 };
70  
71   extern unsigned int lineno;
# Line 83 | Line 78 | struct conf_parser_context conf_parser_c
78   /* internally defined functions */
79   static void read_conf(FILE *);
80   static void clear_out_old_conf(void);
86 static void flush_deleted_I_P(void);
81   static void expire_tklines(dlink_list *);
82   static void garbage_collect_ip_entries(void);
83   static int hash_ip(struct irc_ssaddr *);
84 < static int verify_access(struct Client *, const char *);
85 < static int attach_iline(struct Client *, struct ConfItem *);
84 > static int verify_access(struct Client *);
85 > static int attach_iline(struct Client *, struct MaskItem *);
86   static struct ip_entry *find_or_add_ip(struct irc_ssaddr *);
87 < static void parse_conf_file(int, int);
88 < static dlink_list *map_to_list(ConfType);
95 < static struct AccessItem *find_regexp_kline(const char *[]);
87 > static dlink_list *map_to_list(enum maskitem_type);
88 > static struct MaskItem *find_regexp_kline(const char *[]);
89   static int find_user_host(struct Client *, char *, char *, char *, unsigned int);
90  
98 /*
99 * bit_len
100 */
101 static int cidr_limit_reached(int, struct irc_ssaddr *, struct ClassItem *);
102 static void remove_from_cidr_check(struct irc_ssaddr *, struct ClassItem *);
103 static void destroy_cidr_class(struct ClassItem *);
104
105 static void flags_to_ascii(unsigned int, const unsigned int[], char *, int);
106
107 /* address of default class conf */
108 static struct ConfItem *class_default;
91  
92   /* usually, with hash tables, you use a prime number...
93   * but in this case I am dealing with ip addresses,
# Line 116 | Line 98 | static struct ConfItem *class_default;
98   struct ip_entry
99   {
100    struct irc_ssaddr ip;
101 <  int count;
101 >  unsigned int count;
102    time_t last_attempt;
103    struct ip_entry *next;
104   };
105  
106   static struct ip_entry *ip_hash_table[IP_HASH_SIZE];
107 < static BlockHeap *ip_entry_heap = NULL;
107 > static mp_pool_t *ip_entry_pool = NULL;
108   static int ip_entries_count = 0;
109  
110  
129 void *
130 map_to_conf(struct ConfItem *aconf)
131 {
132  void *conf;
133  conf = (void *)((uintptr_t)aconf +
134                  (uintptr_t)sizeof(struct ConfItem));
135  return(conf);
136 }
137
138 struct ConfItem *
139 unmap_conf_item(void *aconf)
140 {
141  struct ConfItem *conf;
142
143  conf = (struct ConfItem *)((uintptr_t)aconf -
144                             (uintptr_t)sizeof(struct ConfItem));
145  return(conf);
146 }
147
111   /* conf_dns_callback()
112   *
113 < * inputs       - pointer to struct AccessItem
113 > * inputs       - pointer to struct MaskItem
114   *              - pointer to DNSReply reply
115   * output       - none
116   * side effects - called when resolver query finishes
# Line 158 | Line 121 | unmap_conf_item(void *aconf)
121   static void
122   conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name)
123   {
124 <  struct AccessItem *aconf = vptr;
124 >  struct MaskItem *conf = vptr;
125  
126 <  aconf->dns_pending = 0;
126 >  conf->dns_pending = 0;
127  
128    if (addr != NULL)
129 <    memcpy(&aconf->ipnum, addr, sizeof(aconf->ipnum));
129 >    memcpy(&conf->addr, addr, sizeof(conf->addr));
130    else
131 <    aconf->dns_failed = 1;
131 >    conf->dns_failed = 1;
132   }
133  
134   /* conf_dns_lookup()
# Line 175 | Line 138 | conf_dns_callback(void *vptr, const stru
138   * allocate a dns_query and start ns lookup.
139   */
140   static void
141 < conf_dns_lookup(struct AccessItem *aconf)
141 > conf_dns_lookup(struct MaskItem *conf)
142   {
143 <  if (!aconf->dns_pending)
143 >  if (!conf->dns_pending)
144    {
145 <    aconf->dns_pending = 1;
146 <    gethost_byname(conf_dns_callback, aconf, aconf->host);
145 >    conf->dns_pending = 1;
146 >    gethost_byname(conf_dns_callback, conf, conf->host);
147    }
148   }
149  
150 < /* make_conf_item()
151 < *
189 < * inputs       - type of item
190 < * output       - pointer to new conf entry
191 < * side effects - none
192 < */
193 < struct ConfItem *
194 < make_conf_item(ConfType type)
150 > struct MaskItem *
151 > conf_make(enum maskitem_type type)
152   {
153 <  struct ConfItem *conf = NULL;
154 <  struct AccessItem *aconf = NULL;
198 <  struct ClassItem *aclass = NULL;
199 <  int status = 0;
153 >  struct MaskItem *conf = MyMalloc(sizeof(*conf));
154 >  dlink_list *list = NULL;
155  
156 <  switch (type)
157 <  {
158 <  case DLINE_TYPE:
204 <  case EXEMPTDLINE_TYPE:
205 <  case GLINE_TYPE:
206 <  case KLINE_TYPE:
207 <  case CLIENT_TYPE:
208 <  case OPER_TYPE:
209 <  case SERVER_TYPE:
210 <    conf = MyMalloc(sizeof(struct ConfItem) +
211 <                    sizeof(struct AccessItem));
212 <    aconf = map_to_conf(conf);
213 <    aconf->aftype = AF_INET;
214 <
215 <    /* Yes, sigh. switch on type again */
216 <    switch (type)
217 <    {
218 <    case EXEMPTDLINE_TYPE:
219 <      status = CONF_EXEMPTDLINE;
220 <      break;
221 <
222 <    case DLINE_TYPE:
223 <      status = CONF_DLINE;
224 <      break;
225 <
226 <    case KLINE_TYPE:
227 <      status = CONF_KLINE;
228 <      break;
229 <
230 <    case GLINE_TYPE:
231 <      status = CONF_GLINE;
232 <      break;
233 <
234 <    case CLIENT_TYPE:
235 <      status = CONF_CLIENT;
236 <      break;
237 <
238 <    case OPER_TYPE:
239 <      status = CONF_OPERATOR;
240 <      dlinkAdd(conf, &conf->node, &oconf_items);
241 <      break;
242 <
243 <    case SERVER_TYPE:
244 <      status = CONF_SERVER;
245 <      dlinkAdd(conf, &conf->node, &server_items);
246 <      break;
247 <
248 <    default:
249 <      break;
250 <    }
251 <    aconf->status = status;
252 <    break;
253 <
254 <  case LEAF_TYPE:
255 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
256 <                                       sizeof(struct MatchItem));
257 <    dlinkAdd(conf, &conf->node, &leaf_items);
258 <    break;
259 <
260 <  case HUB_TYPE:
261 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
262 <                                       sizeof(struct MatchItem));
263 <    dlinkAdd(conf, &conf->node, &hub_items);
264 <    break;
265 <
266 <  case ULINE_TYPE:
267 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
268 <                                       sizeof(struct MatchItem));
269 <    dlinkAdd(conf, &conf->node, &uconf_items);
270 <    break;
271 <
272 <  case GDENY_TYPE:
273 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
274 <                                       sizeof(struct AccessItem));
275 <    dlinkAdd(conf, &conf->node, &gdeny_items);
276 <    break;
277 <
278 <  case XLINE_TYPE:
279 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
280 <                                       sizeof(struct MatchItem));
281 <    dlinkAdd(conf, &conf->node, &xconf_items);
282 <    break;
283 < #ifdef HAVE_LIBPCRE
284 <  case RXLINE_TYPE:
285 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
286 <                                       sizeof(struct MatchItem));
287 <    dlinkAdd(conf, &conf->node, &rxconf_items);
288 <    break;
289 <
290 <  case RKLINE_TYPE:
291 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
292 <                                       sizeof(struct AccessItem));
293 <    aconf = map_to_conf(conf);
294 <    aconf->status = CONF_KLINE;
295 <    dlinkAdd(conf, &conf->node, &rkconf_items);
296 <    break;
297 < #endif
298 <  case CLUSTER_TYPE:
299 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem));
300 <    dlinkAdd(conf, &conf->node, &cluster_items);
301 <    break;
302 <
303 <  case CRESV_TYPE:
304 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
305 <                                       sizeof(struct ResvChannel));
306 <    break;
307 <
308 <  case NRESV_TYPE:
309 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
310 <                                       sizeof(struct MatchItem));
311 <    dlinkAdd(conf, &conf->node, &nresv_items);
312 <    break;
313 <
314 <  case SERVICE_TYPE:
315 <    status = CONF_SERVICE;
316 <    conf = MyMalloc(sizeof(struct ConfItem));
317 <    dlinkAdd(conf, &conf->node, &service_items);
318 <    break;
319 <
320 <  case CLASS_TYPE:
321 <    conf = MyMalloc(sizeof(struct ConfItem) +
322 <                           sizeof(struct ClassItem));
323 <    dlinkAdd(conf, &conf->node, &class_items);
324 <
325 <    aclass = map_to_conf(conf);
326 <    aclass->active = 1;
327 <    aclass->con_freq = DEFAULT_CONNECTFREQUENCY;
328 <    aclass->ping_freq = DEFAULT_PINGFREQUENCY;
329 <    aclass->max_total = MAXIMUM_LINKS_DEFAULT;
330 <    aclass->max_sendq = DEFAULT_SENDQ;
331 <
332 <    break;
333 <
334 <  default:
335 <    conf = NULL;
336 <    break;
337 <  }
338 <
339 <  /* XXX Yes, this will core if default is hit. I want it to for now - db */
340 <  conf->type = type;
156 >  conf->type   = type;
157 >  conf->active = 1;
158 >  conf->aftype = AF_INET;
159  
160 +  if ((list = map_to_list(type)))
161 +    dlinkAdd(conf, &conf->node, list);
162    return conf;
163   }
164  
165   void
166 < delete_conf_item(struct ConfItem *conf)
166 > conf_free(struct MaskItem *conf)
167   {
168 <  dlink_node *m = NULL;
169 <  struct MatchItem *match_item;
170 <  struct AccessItem *aconf;
171 <  ConfType type = conf->type;
168 >  dlink_node *ptr = NULL, *ptr_next = NULL;
169 >  dlink_list *list = NULL;
170 >
171 >  if (conf->node.next)
172 >    if ((list = map_to_list(conf->type)))
173 >      dlinkDelete(&conf->node, list);
174  
175    MyFree(conf->name);
354  conf->name = NULL;
176  
177 <  switch(type)
178 <  {
179 <  case DLINE_TYPE:
180 <  case EXEMPTDLINE_TYPE:
181 <  case GLINE_TYPE:
182 <  case KLINE_TYPE:
183 <  case CLIENT_TYPE:
184 <  case OPER_TYPE:
185 <  case SERVER_TYPE:
186 <    aconf = map_to_conf(conf);
187 <
188 <    if (aconf->dns_pending)
189 <      delete_resolver_queries(aconf);
190 <    if (aconf->passwd != NULL)
191 <      memset(aconf->passwd, 0, strlen(aconf->passwd));
192 <    if (aconf->spasswd != NULL)
372 <      memset(aconf->spasswd, 0, strlen(aconf->spasswd));
373 <    aconf->class_ptr = NULL;
374 <
375 <    MyFree(aconf->passwd);
376 <    MyFree(aconf->spasswd);
377 <    MyFree(aconf->reason);
378 <    MyFree(aconf->oper_reason);
379 <    MyFree(aconf->user);
380 <    MyFree(aconf->host);
381 <    MyFree(aconf->cipher_list);
177 >  if (conf->dns_pending)
178 >    delete_resolver_queries(conf);
179 >  if (conf->passwd != NULL)
180 >    memset(conf->passwd, 0, strlen(conf->passwd));
181 >  if (conf->spasswd != NULL)
182 >    memset(conf->spasswd, 0, strlen(conf->spasswd));
183 >
184 >  conf->class = NULL;
185 >
186 >  MyFree(conf->passwd);
187 >  MyFree(conf->spasswd);
188 >  MyFree(conf->reason);
189 >  MyFree(conf->user);
190 >  MyFree(conf->host);
191 >  MyFree(conf->regexuser);
192 >  MyFree(conf->regexhost);
193   #ifdef HAVE_LIBCRYPTO
194 <    if (aconf->rsa_public_key)
384 <      RSA_free(aconf->rsa_public_key);
385 <    MyFree(aconf->rsa_public_key_file);
386 < #endif
387 <
388 <    /* Yes, sigh. switch on type again */
389 <    switch(type)
390 <    {
391 <    case EXEMPTDLINE_TYPE:
392 <    case DLINE_TYPE:
393 <    case GLINE_TYPE:
394 <    case KLINE_TYPE:
395 <    case CLIENT_TYPE:
396 <      MyFree(conf);
397 <      break;
398 <
399 <    case OPER_TYPE:
400 <      aconf = map_to_conf(conf);
401 <      if (!IsConfIllegal(aconf))
402 <        dlinkDelete(&conf->node, &oconf_items);
403 <      MyFree(conf);
404 <      break;
405 <
406 <    case SERVER_TYPE:
407 <      aconf = map_to_conf(conf);
408 <      if (!IsConfIllegal(aconf))
409 <        dlinkDelete(&conf->node, &server_items);
410 <      MyFree(conf);
411 <      break;
412 <
413 <    default:
414 <      break;
415 <    }
416 <    break;
194 >  MyFree(conf->cipher_list);
195  
196 <  case HUB_TYPE:
197 <    match_item = map_to_conf(conf);
420 <    MyFree(match_item->user);
421 <    MyFree(match_item->host);
422 <    MyFree(match_item->reason);
423 <    MyFree(match_item->oper_reason);
424 <    /* If marked illegal, its already been pulled off of the hub_items list */
425 <    if (!match_item->illegal)
426 <      dlinkDelete(&conf->node, &hub_items);
427 <    MyFree(conf);
428 <    break;
429 <
430 <  case LEAF_TYPE:
431 <    match_item = map_to_conf(conf);
432 <    MyFree(match_item->user);
433 <    MyFree(match_item->host);
434 <    MyFree(match_item->reason);
435 <    MyFree(match_item->oper_reason);
436 <    /* If marked illegal, its already been pulled off of the leaf_items list */
437 <    if (!match_item->illegal)
438 <      dlinkDelete(&conf->node, &leaf_items);
439 <    MyFree(conf);
440 <    break;
441 <
442 <  case ULINE_TYPE:
443 <    match_item = map_to_conf(conf);
444 <    MyFree(match_item->user);
445 <    MyFree(match_item->host);
446 <    MyFree(match_item->reason);
447 <    MyFree(match_item->oper_reason);
448 <    dlinkDelete(&conf->node, &uconf_items);
449 <    MyFree(conf);
450 <    break;
451 <
452 <  case XLINE_TYPE:
453 <    match_item = map_to_conf(conf);
454 <    MyFree(match_item->user);
455 <    MyFree(match_item->host);
456 <    MyFree(match_item->reason);
457 <    MyFree(match_item->oper_reason);
458 <    dlinkDelete(&conf->node, &xconf_items);
459 <    MyFree(conf);
460 <    break;
461 < #ifdef HAVE_LIBPCRE
462 <  case RKLINE_TYPE:
463 <    aconf = map_to_conf(conf);
464 <    MyFree(aconf->regexuser);
465 <    MyFree(aconf->regexhost);
466 <    MyFree(aconf->user);
467 <    MyFree(aconf->host);
468 <    MyFree(aconf->reason);
469 <    MyFree(aconf->oper_reason);
470 <    dlinkDelete(&conf->node, &rkconf_items);
471 <    MyFree(conf);
472 <    break;
473 <
474 <  case RXLINE_TYPE:
475 <    MyFree(conf->regexpname);
476 <    match_item = map_to_conf(conf);
477 <    MyFree(match_item->user);
478 <    MyFree(match_item->host);
479 <    MyFree(match_item->reason);
480 <    MyFree(match_item->oper_reason);
481 <    dlinkDelete(&conf->node, &rxconf_items);
482 <    MyFree(conf);
483 <    break;
196 >  if (conf->rsa_public_key)
197 >    RSA_free(conf->rsa_public_key);
198   #endif
199 <  case NRESV_TYPE:
200 <    match_item = map_to_conf(conf);
201 <    MyFree(match_item->user);
202 <    MyFree(match_item->host);
489 <    MyFree(match_item->reason);
490 <    MyFree(match_item->oper_reason);
491 <    dlinkDelete(&conf->node, &nresv_items);
492 <
493 <    if (conf->flags & CONF_FLAGS_TEMPORARY)
494 <      if ((m = dlinkFindDelete(&temporary_resv, conf)) != NULL)
495 <        free_dlink_node(m);
496 <
497 <    MyFree(conf);
498 <    break;
499 <
500 <  case GDENY_TYPE:
501 <    aconf = map_to_conf(conf);
502 <    MyFree(aconf->user);
503 <    MyFree(aconf->host);
504 <    dlinkDelete(&conf->node, &gdeny_items);
505 <    MyFree(conf);
506 <    break;
507 <
508 <  case CLUSTER_TYPE:
509 <    dlinkDelete(&conf->node, &cluster_items);
510 <    MyFree(conf);
511 <    break;
512 <
513 <  case CRESV_TYPE:
514 <    if (conf->flags & CONF_FLAGS_TEMPORARY)
515 <      if ((m = dlinkFindDelete(&temporary_resv, conf)) != NULL)
516 <        free_dlink_node(m);
517 <
518 <    MyFree(conf);
519 <    break;
520 <
521 <  case CLASS_TYPE:
522 <    dlinkDelete(&conf->node, &class_items);
523 <    MyFree(conf);
524 <    break;
525 <
526 <  case SERVICE_TYPE:
527 <    dlinkDelete(&conf->node, &service_items);
528 <    MyFree(conf);
529 <    break;
530 <
531 <  default:
532 <    break;
199 >  DLINK_FOREACH_SAFE(ptr, ptr_next, conf->hub_list.head)
200 >  {
201 >    MyFree(ptr->data);
202 >    free_dlink_node(ptr);
203    }
534 }
204  
205 < /* free_access_item()
206 < *
207 < * inputs       - pointer to conf to free
208 < * output       - none
209 < * side effects - crucial password fields are zeroed, conf is freed
541 < */
542 < void
543 < free_access_item(struct AccessItem *aconf)
544 < {
545 <  struct ConfItem *conf;
205 >  DLINK_FOREACH_SAFE(ptr, ptr_next, conf->leaf_list.head)
206 >  {
207 >    MyFree(ptr->data);
208 >    free_dlink_node(ptr);
209 >  }
210  
211 <  if (aconf == NULL)
548 <    return;
549 <  conf = unmap_conf_item(aconf);
550 <  delete_conf_item(conf);
211 >  MyFree(conf);
212   }
213  
214 < static const unsigned int shared_bit_table[] =
215 <  { 'K', 'k', 'U', 'X', 'x', 'Y', 'Q', 'q', 'R', 'L', 0};
214 > static const struct shared_flags
215 > {
216 >  const unsigned int type;
217 >  const unsigned char letter;
218 > } flag_table[] = {
219 >  { SHARED_KLINE,   'K' },
220 >  { SHARED_UNKLINE, 'U' },
221 >  { SHARED_XLINE,   'X' },
222 >  { SHARED_UNXLINE, 'Y' },
223 >  { SHARED_RESV,    'Q' },
224 >  { SHARED_UNRESV,  'R' },
225 >  { SHARED_LOCOPS,  'L' },
226 >  { SHARED_DLINE,   'D' },
227 >  { SHARED_UNDLINE, 'E' },
228 >  { 0, '\0' }
229 > };
230  
231 < /* report_confitem_types()
557 < *
231 > /*
232   * inputs       - pointer to client requesting confitem report
233   *              - ConfType to report
234   * output       - none
235   * side effects -
236   */
237   void
238 < report_confitem_types(struct Client *source_p, ConfType type)
238 > report_confitem_types(struct Client *source_p, enum maskitem_type type)
239   {
240 <  dlink_node *ptr = NULL;
241 <  struct ConfItem *conf = NULL;
242 <  struct AccessItem *aconf = NULL;
243 <  struct MatchItem *matchitem = NULL;
570 <  struct ClassItem *classitem = NULL;
240 >  dlink_node *ptr = NULL, *dptr = NULL;
241 >  struct MaskItem *conf = NULL;
242 >  const struct ClassItem *class = NULL;
243 >  const struct shared_flags *shared = NULL;
244    char buf[12];
245    char *p = NULL;
246  
247    switch (type)
248    {
249 <  case GDENY_TYPE:
577 <    DLINK_FOREACH(ptr, gdeny_items.head)
578 <    {
579 <      conf = ptr->data;
580 <      aconf = map_to_conf(conf);
581 <
582 <      p = buf;
583 <
584 <      if (aconf->flags & GDENY_BLOCK)
585 <        *p++ = 'B';
586 <      else
587 <        *p++ = 'b';
588 <
589 <      if (aconf->flags & GDENY_REJECT)
590 <        *p++ = 'R';
591 <      else
592 <        *p++ = 'r';
593 <
594 <      *p = '\0';
595 <
596 <      sendto_one(source_p, ":%s %d %s V %s@%s %s %s",
597 <                 me.name, RPL_STATSDEBUG, source_p->name,
598 <                 aconf->user, aconf->host, conf->name, buf);
599 <    }
600 <    break;
601 <
602 <  case XLINE_TYPE:
249 >  case CONF_XLINE:
250      DLINK_FOREACH(ptr, xconf_items.head)
251      {
252        conf = ptr->data;
606      matchitem = map_to_conf(conf);
253  
254        sendto_one(source_p, form_str(RPL_STATSXLINE),
255                   me.name, source_p->name,
256 <                 matchitem->hold ? "x": "X", matchitem->count,
257 <                 conf->name, matchitem->reason);
256 >                 conf->until ? "x": "X", conf->count,
257 >                 conf->name, conf->reason);
258      }
259      break;
260  
261   #ifdef HAVE_LIBPCRE
262 <  case RXLINE_TYPE:
262 >  case CONF_RXLINE:
263      DLINK_FOREACH(ptr, rxconf_items.head)
264      {
265        conf = ptr->data;
620      matchitem = map_to_conf(conf);
266  
267        sendto_one(source_p, form_str(RPL_STATSXLINE),
268                   me.name, source_p->name,
269 <                 "XR", matchitem->count,
270 <                 conf->name, matchitem->reason);
269 >                 "XR", conf->count,
270 >                 conf->name, conf->reason);
271      }
272      break;
273  
274 <  case RKLINE_TYPE:
274 >  case CONF_RKLINE:
275      DLINK_FOREACH(ptr, rkconf_items.head)
276      {
277 <      aconf = map_to_conf((conf = ptr->data));
277 >      conf = ptr->data;
278  
279        sendto_one(source_p, form_str(RPL_STATSKLINE), me.name,
280 <                 source_p->name, "KR", aconf->host, aconf->user,
281 <                 aconf->reason, aconf->oper_reason ? aconf->oper_reason : "");
280 >                 source_p->name, "KR", conf->host, conf->user,
281 >                 conf->reason);
282      }
283      break;
284   #endif
285  
286 <  case ULINE_TYPE:
286 >  case CONF_ULINE:
287 >    shared = flag_table;
288      DLINK_FOREACH(ptr, uconf_items.head)
289      {
290        conf = ptr->data;
645      matchitem = map_to_conf(conf);
291  
292        p = buf;
293  
649      /* some of these are redundant for the sake of
650       * consistency with cluster{} flags
651       */
294        *p++ = 'c';
295 <      flags_to_ascii(matchitem->action, shared_bit_table, p, 0);
295 >      for (; shared->type; ++shared)
296 >        if (shared->type & conf->flags)
297 >          *p++ = shared->letter;
298 >        else
299 >          *p++ = ToLower(shared->letter);
300  
301        sendto_one(source_p, form_str(RPL_STATSULINE),
302                   me.name, source_p->name, conf->name,
303 <                 matchitem->user?matchitem->user: "*",
304 <                 matchitem->host?matchitem->host: "*", buf);
303 >                 conf->user?conf->user: "*",
304 >                 conf->host?conf->host: "*", buf);
305      }
306  
307 +    shared = flag_table;
308      DLINK_FOREACH(ptr, cluster_items.head)
309      {
310        conf = ptr->data;
# Line 665 | Line 312 | report_confitem_types(struct Client *sou
312        p = buf;
313  
314        *p++ = 'C';
315 <      flags_to_ascii(conf->flags, shared_bit_table, p, 0);
315 >      for (; shared->type; ++shared)
316 >        if (shared->type & conf->flags)
317 >          *p++ = shared->letter;
318 >        else
319 >          *p++ = ToLower(shared->letter);
320  
321        sendto_one(source_p, form_str(RPL_STATSULINE),
322                   me.name, source_p->name, conf->name,
# Line 674 | Line 325 | report_confitem_types(struct Client *sou
325  
326      break;
327  
328 <  case OPER_TYPE:
328 >  case CONF_OPER:
329      DLINK_FOREACH(ptr, oconf_items.head)
330      {
331        conf = ptr->data;
681      aconf = map_to_conf(conf);
332  
333        /* Don't allow non opers to see oper privs */
334        if (HasUMode(source_p, UMODE_OPER))
335          sendto_one(source_p, form_str(RPL_STATSOLINE),
336 <                   me.name, source_p->name, 'O', aconf->user, aconf->host,
337 <                   conf->name, oper_privs_as_string(aconf->port),
338 <                   aconf->class_ptr ? aconf->class_ptr->name : "<default>");
336 >                   me.name, source_p->name, 'O', conf->user, conf->host,
337 >                   conf->name, oper_privs_as_string(conf->port),
338 >                   conf->class ? conf->class->name : "<default>");
339        else
340          sendto_one(source_p, form_str(RPL_STATSOLINE),
341 <                   me.name, source_p->name, 'O', aconf->user, aconf->host,
341 >                   me.name, source_p->name, 'O', conf->user, conf->host,
342                     conf->name, "0",
343 <                   aconf->class_ptr ? aconf->class_ptr->name : "<default>");
343 >                   conf->class ? conf->class->name : "<default>");
344      }
345      break;
346  
347 <  case CLASS_TYPE:
348 <    DLINK_FOREACH(ptr, class_items.head)
347 >  case CONF_CLASS:
348 >    DLINK_FOREACH(ptr, class_get_list()->head)
349      {
350 <      conf = ptr->data;
701 <      classitem = map_to_conf(conf);
350 >      class = ptr->data;
351        sendto_one(source_p, form_str(RPL_STATSYLINE),
352                   me.name, source_p->name, 'Y',
353 <                 conf->name, classitem->ping_freq,
354 <                 classitem->con_freq,
355 <                 classitem->max_total, classitem->max_sendq,
356 <                 classitem->curr_user_count,
357 <                 classitem->active ? "active" : "disabled");
353 >                 class->name, class->ping_freq,
354 >                 class->con_freq,
355 >                 class->max_total, class->max_sendq,
356 >                 class->max_recvq,
357 >                 class->ref_count,
358 >                 class->number_per_cidr, class->cidr_bitlen_ipv4,
359 >                 class->number_per_cidr, class->cidr_bitlen_ipv6,
360 >                 class->active ? "active" : "disabled");
361      }
362      break;
363  
364 <  case CONF_TYPE:
713 <  case CLIENT_TYPE:
714 <    break;
715 <
716 <  case SERVICE_TYPE:
364 >  case CONF_SERVICE:
365      DLINK_FOREACH(ptr, service_items.head)
366      {
367        conf = ptr->data;
# Line 722 | Line 370 | report_confitem_types(struct Client *sou
370      }
371      break;
372  
373 <  case SERVER_TYPE:
373 >  case CONF_SERVER:
374      DLINK_FOREACH(ptr, server_items.head)
375      {
376        p = buf;
729
377        conf = ptr->data;
731      aconf = map_to_conf(conf);
378  
379        buf[0] = '\0';
380  
381 <      if (IsConfAllowAutoConn(aconf))
381 >      if (IsConfAllowAutoConn(conf))
382          *p++ = 'A';
383 <      if (IsConfSSL(aconf))
383 >      if (IsConfSSL(conf))
384          *p++ = 'S';
739      if (IsConfTopicBurst(aconf))
740        *p++ = 'T';
385        if (buf[0] == '\0')
386          *p++ = '*';
387  
# Line 748 | Line 392 | report_confitem_types(struct Client *sou
392         */
393        if (!ConfigServerHide.hide_server_ips && HasUMode(source_p, UMODE_ADMIN))
394          sendto_one(source_p, form_str(RPL_STATSCLINE),
395 <                   me.name, source_p->name, 'C', aconf->host,
396 <                   buf, conf->name, aconf->port,
397 <                   aconf->class_ptr ? aconf->class_ptr->name : "<default>");
395 >                   me.name, source_p->name, 'C', conf->host,
396 >                   buf, conf->name, conf->port,
397 >                   conf->class ? conf->class->name : "<default>");
398          else
399            sendto_one(source_p, form_str(RPL_STATSCLINE),
400                       me.name, source_p->name, 'C',
401 <                     "*@127.0.0.1", buf, conf->name, aconf->port,
402 <                     aconf->class_ptr ? aconf->class_ptr->name : "<default>");
401 >                     "*@127.0.0.1", buf, conf->name, conf->port,
402 >                     conf->class ? conf->class->name : "<default>");
403      }
404      break;
405  
406 <  case HUB_TYPE:
407 <    DLINK_FOREACH(ptr, hub_items.head)
406 >  case CONF_HUB:
407 >    DLINK_FOREACH(ptr, server_items.head)
408      {
409        conf = ptr->data;
410 <      matchitem = map_to_conf(conf);
411 <      sendto_one(source_p, form_str(RPL_STATSHLINE), me.name,
412 <                 source_p->name, 'H', matchitem->host, conf->name, 0, "*");
410 >
411 >      DLINK_FOREACH(dptr, conf->hub_list.head)
412 >        sendto_one(source_p, form_str(RPL_STATSHLINE), me.name,
413 >                   source_p->name, 'H', dptr->data, conf->name, 0, "*");
414      }
770    break;
415  
416 <  case LEAF_TYPE:
773 <    DLINK_FOREACH(ptr, leaf_items.head)
416 >    DLINK_FOREACH(ptr, server_items.head)
417      {
418        conf = ptr->data;
419 <      matchitem = map_to_conf(conf);
420 <      sendto_one(source_p, form_str(RPL_STATSLLINE), me.name,
421 <                 source_p->name, 'L', matchitem->host, conf->name, 0, "*");
419 >
420 >      DLINK_FOREACH(dptr, conf->leaf_list.head)
421 >        sendto_one(source_p, form_str(RPL_STATSLLINE), me.name,
422 >                   source_p->name, 'L', dptr->data, conf->name, 0, "*");
423      }
424 +
425      break;
426  
782  case GLINE_TYPE:
783  case KLINE_TYPE:
784  case DLINE_TYPE:
785  case EXEMPTDLINE_TYPE:
786  case CRESV_TYPE:
787  case NRESV_TYPE:
788  case CLUSTER_TYPE:
427    default:
428      break;
429    }
# Line 804 | Line 442 | report_confitem_types(struct Client *sou
442   *                Look for conf lines which have the same
443   *                status as the flags passed.
444   */
445 < static void *
446 < check_client(va_list args)
445 > int
446 > check_client(struct Client *source_p)
447   {
810  struct Client *source_p = va_arg(args, struct Client *);
811  const char *username = va_arg(args, const char *);
448    int i;
449  
450 <  /* I'm already in big trouble if source_p->localClient is NULL -db */
815 <  if ((i = verify_access(source_p, username)))
450 >  if ((i = verify_access(source_p)))
451      ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
452           source_p->name, source_p->sockhost);
453  
454    switch (i)
455    {
456      case TOO_MANY:
457 <      sendto_realops_flags(UMODE_FULL, L_ALL,
457 >      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
458                             "Too many on IP for %s (%s).",
459                             get_client_name(source_p, SHOW_IP),
460                             source_p->sockhost);
# Line 830 | Line 465 | check_client(va_list args)
465        break;
466  
467      case I_LINE_FULL:
468 <      sendto_realops_flags(UMODE_FULL, L_ALL,
469 <                           "I-line is full for %s (%s).",
468 >      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
469 >                           "auth{} block is full for %s (%s).",
470                             get_client_name(source_p, SHOW_IP),
471                             source_p->sockhost);
472        ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
# Line 845 | Line 480 | check_client(va_list args)
480        ++ServerStats.is_ref;
481        /* jdc - lists server name & port connections are on */
482        /*       a purely cosmetical change */
483 <      sendto_realops_flags(UMODE_UNAUTH, L_ALL,
483 >      sendto_realops_flags(UMODE_UNAUTH, L_ALL, SEND_NOTICE,
484                             "Unauthorized client connection from %s [%s] on [%s/%u].",
485                             get_client_name(source_p, SHOW_IP),
486                             source_p->sockhost,
# Line 857 | Line 492 | check_client(va_list args)
492            source_p->localClient->listener->name,
493            source_p->localClient->listener->port);
494  
495 <      /* XXX It is prolematical whether it is better to use the
861 <       * capture reject code here or rely on the connecting too fast code.
862 <       * - Dianora
863 <       */
864 <      if (REJECT_HOLD_TIME > 0)
865 <      {
866 <        sendto_one(source_p, ":%s NOTICE %s :You are not authorized to use this server",
867 <                   me.name, source_p->name);
868 <        source_p->localClient->reject_delay = CurrentTime + REJECT_HOLD_TIME;
869 <        SetCaptured(source_p);
870 <      }
871 <      else
872 <        exit_client(source_p, &me, "You are not authorized to use this server");
495 >      exit_client(source_p, &me, "You are not authorized to use this server");
496        break;
497  
498     case BANNED_CLIENT:
499 <     /*
877 <      * Don't exit them immediately, play with them a bit.
878 <      * - Dianora
879 <      */
880 <     if (REJECT_HOLD_TIME > 0)
881 <     {
882 <       source_p->localClient->reject_delay = CurrentTime + REJECT_HOLD_TIME;
883 <       SetCaptured(source_p);
884 <     }
885 <     else
886 <       exit_client(source_p, &me, "Banned");
499 >     exit_client(source_p, &me, "Banned");
500       ++ServerStats.is_ref;
501       break;
502  
# Line 892 | Line 505 | check_client(va_list args)
505       break;
506    }
507  
508 <  return (i < 0 ? NULL : source_p);
508 >  return (i < 0 ? 0 : 1);
509   }
510  
511   /* verify_access()
512   *
513   * inputs       - pointer to client to verify
901 *              - pointer to proposed username
514   * output       - 0 if success -'ve if not
515   * side effect  - find the first (best) I line to attach.
516   */
517   static int
518 < verify_access(struct Client *client_p, const char *username)
518 > verify_access(struct Client *client_p)
519   {
520 <  struct AccessItem *aconf = NULL, *rkconf = NULL;
909 <  struct ConfItem *conf = NULL;
520 >  struct MaskItem *conf = NULL, *rkconf = NULL;
521    char non_ident[USERLEN + 1] = { '~', '\0' };
522    const char *uhi[3];
523  
524    if (IsGotId(client_p))
525    {
526 <    aconf = find_address_conf(client_p->host, client_p->username,
526 >    conf = find_address_conf(client_p->host, client_p->username,
527                               &client_p->localClient->ip,
528                               client_p->localClient->aftype,
529                               client_p->localClient->passwd);
530    }
531    else
532    {
533 <    strlcpy(non_ident+1, username, sizeof(non_ident)-1);
534 <    aconf = find_address_conf(client_p->host,non_ident,
533 >    strlcpy(non_ident+1, client_p->username, sizeof(non_ident)-1);
534 >    conf = find_address_conf(client_p->host,non_ident,
535                               &client_p->localClient->ip,
536                               client_p->localClient->aftype,
537                               client_p->localClient->passwd);
# Line 932 | Line 543 | verify_access(struct Client *client_p, c
543  
544    rkconf = find_regexp_kline(uhi);
545  
546 <  if (aconf != NULL)
546 >  if (conf != NULL)
547    {
548 <    if (IsConfClient(aconf) && !rkconf)
548 >    if (IsConfClient(conf) && !rkconf)
549      {
550 <      conf = unmap_conf_item(aconf);
940 <
941 <      if (IsConfRedir(aconf))
550 >      if (IsConfRedir(conf))
551        {
552          sendto_one(client_p, form_str(RPL_REDIR),
553                     me.name, client_p->name,
554                     conf->name ? conf->name : "",
555 <                   aconf->port);
555 >                   conf->port);
556          return(NOT_AUTHORIZED);
557        }
558  
559 <      if (IsConfDoIdentd(aconf))
559 >      if (IsConfDoIdentd(conf))
560          SetNeedId(client_p);
561  
562        /* Thanks for spoof idea amm */
563 <      if (IsConfDoSpoofIp(aconf))
563 >      if (IsConfDoSpoofIp(conf))
564        {
565 <        conf = unmap_conf_item(aconf);
566 <
567 <        if (!ConfigFileEntry.hide_spoof_ips && IsConfSpoofNotice(aconf))
959 <          sendto_realops_flags(UMODE_ALL, L_ADMIN, "%s spoofing: %s as %s",
565 >        if (!ConfigFileEntry.hide_spoof_ips && IsConfSpoofNotice(conf))
566 >          sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
567 >                               "%s spoofing: %s as %s",
568                                 client_p->name, client_p->host, conf->name);
569          strlcpy(client_p->host, conf->name, sizeof(client_p->host));
570          SetIPSpoof(client_p);
# Line 964 | Line 572 | verify_access(struct Client *client_p, c
572  
573        return(attach_iline(client_p, conf));
574      }
575 <    else if (rkconf || IsConfKill(aconf) || (ConfigFileEntry.glines && IsConfGline(aconf)))
575 >    else if (rkconf || IsConfKill(conf) || (ConfigFileEntry.glines && IsConfGline(conf)))
576      {
577        /* XXX */
578 <      aconf = rkconf ? rkconf : aconf;
579 <      if (IsConfGline(aconf))
578 >      conf = rkconf ? rkconf : conf;
579 >      if (IsConfGline(conf))
580          sendto_one(client_p, ":%s NOTICE %s :*** G-lined", me.name,
581                     client_p->name);
582 <      if (ConfigFileEntry.kline_with_reason)
583 <        sendto_one(client_p, ":%s NOTICE %s :*** Banned %s",
976 <                  me.name, client_p->name, aconf->reason);
582 >      sendto_one(client_p, ":%s NOTICE %s :*** Banned: %s",
583 >                 me.name, client_p->name, conf->reason);
584        return(BANNED_CLIENT);
585      }
586    }
# Line 989 | Line 596 | verify_access(struct Client *client_p, c
596   * side effects - do actual attach
597   */
598   static int
599 < attach_iline(struct Client *client_p, struct ConfItem *conf)
599 > attach_iline(struct Client *client_p, struct MaskItem *conf)
600   {
601 <  struct AccessItem *aconf;
995 <  struct ClassItem *aclass;
601 >  struct ClassItem *class = NULL;
602    struct ip_entry *ip_found;
603    int a_limit_reached = 0;
604 <  int local = 0, global = 0, ident = 0;
604 >  unsigned int local = 0, global = 0, ident = 0;
605  
606    ip_found = find_or_add_ip(&client_p->localClient->ip);
607    ip_found->count++;
608    SetIpHash(client_p);
609  
610 <  aconf = map_to_conf(conf);
1005 <  if (aconf->class_ptr == NULL)
610 >  if (conf->class == NULL)
611      return NOT_AUTHORIZED;  /* If class is missing, this is best */
612  
613 <  aclass = map_to_conf(aconf->class_ptr);
613 >  class = conf->class;
614  
615    count_user_host(client_p->username, client_p->host,
616                    &global, &local, &ident);
# Line 1014 | Line 619 | attach_iline(struct Client *client_p, st
619     * setting a_limit_reached if any limit is reached.
620     * - Dianora
621     */
622 <  if (aclass->max_total != 0 && aclass->curr_user_count >= aclass->max_total)
622 >  if (class->max_total != 0 && class->ref_count >= class->max_total)
623      a_limit_reached = 1;
624 <  else if (aclass->max_perip != 0 && ip_found->count > aclass->max_perip)
624 >  else if (class->max_perip != 0 && ip_found->count > class->max_perip)
625      a_limit_reached = 1;
626 <  else if (aclass->max_local != 0 && local >= aclass->max_local)
626 >  else if (class->max_local != 0 && local >= class->max_local)
627      a_limit_reached = 1;
628 <  else if (aclass->max_global != 0 && global >= aclass->max_global)
628 >  else if (class->max_global != 0 && global >= class->max_global)
629      a_limit_reached = 1;
630 <  else if (aclass->max_ident != 0 && ident >= aclass->max_ident &&
630 >  else if (class->max_ident != 0 && ident >= class->max_ident &&
631             client_p->username[0] != '~')
632      a_limit_reached = 1;
633  
634    if (a_limit_reached)
635    {
636 <    if (!IsConfExemptLimits(aconf))
636 >    if (!IsConfExemptLimits(conf))
637        return TOO_MANY;   /* Already at maximum allowed */
638  
639      sendto_one(client_p,
# Line 1049 | Line 654 | attach_iline(struct Client *client_p, st
654   void
655   init_ip_hash_table(void)
656   {
657 <  ip_entry_heap = BlockHeapCreate("ip", sizeof(struct ip_entry),
657 >  ip_entry_pool = mp_pool_new(sizeof(struct ip_entry),
658      2 * hard_fdlimit);
659    memset(ip_hash_table, 0, sizeof(ip_hash_table));
660   }
# Line 1099 | Line 704 | find_or_add_ip(struct irc_ssaddr *ip_in)
704    if (ip_entries_count >= 2 * hard_fdlimit)
705      garbage_collect_ip_entries();
706  
707 <  newptr = BlockHeapAlloc(ip_entry_heap);
707 >  newptr = mp_pool_get(ip_entry_pool);
708 >  memset(newptr, 0, sizeof(*newptr));
709    ip_entries_count++;
710    memcpy(&newptr->ip, ip_in, sizeof(struct irc_ssaddr));
711  
# Line 1157 | Line 763 | remove_one_ip(struct irc_ssaddr *ip_in)
763        else
764          ip_hash_table[hash_index] = ptr->next;
765  
766 <      BlockHeapFree(ip_entry_heap, ptr);
766 >      mp_pool_release(ptr);
767        ip_entries_count--;
768        return;
769      }
# Line 1260 | Line 866 | garbage_collect_ip_entries(void)
866            last_ptr->next = ptr->next;
867          else
868            ip_hash_table[i] = ptr->next;
869 <        BlockHeapFree(ip_entry_heap, ptr);
869 >        mp_pool_release(ptr);
870          ip_entries_count--;
871        }
872        else
# Line 1277 | Line 883 | garbage_collect_ip_entries(void)
883   * side effects - Disassociate configuration from the client.
884   *                Also removes a class from the list if marked for deleting.
885   */
886 < int
887 < detach_conf(struct Client *client_p, ConfType type)
886 > void
887 > detach_conf(struct Client *client_p, enum maskitem_type type)
888   {
889 <  dlink_node *ptr, *next_ptr;
1284 <  struct ConfItem *conf;
1285 <  struct ClassItem *aclass;
1286 <  struct AccessItem *aconf;
1287 <  struct ConfItem *aclass_conf;
1288 <  struct MatchItem *match_item;
889 >  dlink_node *ptr = NULL, *next_ptr = NULL;
890  
891    DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->confs.head)
892    {
893 <    conf = ptr->data;
1293 <
1294 <    if (type == CONF_TYPE || conf->type == type)
1295 <    {
1296 <      dlinkDelete(ptr, &client_p->localClient->confs);
1297 <      free_dlink_node(ptr);
1298 <
1299 <      switch (conf->type)
1300 <      {
1301 <      case CLIENT_TYPE:
1302 <      case OPER_TYPE:
1303 <      case SERVER_TYPE:
1304 <        aconf = map_to_conf(conf);
1305 <
1306 <        assert(aconf->clients > 0);
1307 <
1308 <        if ((aclass_conf = aconf->class_ptr) != NULL)
1309 <        {
1310 <          aclass = map_to_conf(aclass_conf);
1311 <
1312 <          assert(aclass->curr_user_count > 0);
893 >    struct MaskItem *conf = ptr->data;
894  
895 <          if (conf->type == CLIENT_TYPE)
896 <            remove_from_cidr_check(&client_p->localClient->ip, aclass);
897 <          if (--aclass->curr_user_count == 0 && aclass->active == 0)
1317 <            delete_conf_item(aclass_conf);
1318 <        }
895 >    assert(conf->type & (CONF_CLIENT | CONF_OPER | CONF_SERVER));
896 >    assert(conf->ref_count > 0);
897 >    assert(conf->class->ref_count > 0);
898  
899 <        if (--aconf->clients == 0 && IsConfIllegal(aconf))
900 <          delete_conf_item(conf);
899 >    if (!(conf->type & type))
900 >      continue;
901  
902 <        break;
902 >    dlinkDelete(ptr, &client_p->localClient->confs);
903 >    free_dlink_node(ptr);
904  
905 <      case LEAF_TYPE:
906 <      case HUB_TYPE:
1327 <        match_item = map_to_conf(conf);
1328 <        if (match_item->ref_count == 0 && match_item->illegal)
1329 <          delete_conf_item(conf);
1330 <        break;
1331 <      default:
1332 <        break;
1333 <      }
905 >    if (conf->type == CONF_CLIENT)
906 >      remove_from_cidr_check(&client_p->localClient->ip, conf->class);
907  
908 <      if (type != CONF_TYPE)
909 <        return 0;
908 >    if (--conf->class->ref_count == 0 && conf->class->active == 0)
909 >    {
910 >      class_free(conf->class);
911 >      conf->class = NULL;
912      }
1338  }
913  
914 <  return -1;
914 >    if (--conf->ref_count == 0 && conf->active == 0)
915 >      conf_free(conf);
916 >  }
917   }
918  
919   /* attach_conf()
# Line 1351 | Line 927 | detach_conf(struct Client *client_p, Con
927   *                attachment if there was an old one...
928   */
929   int
930 < attach_conf(struct Client *client_p, struct ConfItem *conf)
930 > attach_conf(struct Client *client_p, struct MaskItem *conf)
931   {
932    if (dlinkFind(&client_p->localClient->confs, conf) != NULL)
933      return 1;
934  
935 <  if (conf->type == CLIENT_TYPE ||
936 <      conf->type == SERVER_TYPE ||
937 <      conf->type == OPER_TYPE)
938 <  {
1363 <    struct AccessItem *aconf = map_to_conf(conf);
1364 <    struct ClassItem *aclass = map_to_conf(aconf->class_ptr);
1365 <
1366 <    if (IsConfIllegal(aconf))
1367 <      return NOT_AUTHORIZED;
935 >  if (conf->type == CONF_CLIENT)
936 >    if (cidr_limit_reached(IsConfExemptLimits(conf),
937 >                           &client_p->localClient->ip, conf->class))
938 >      return TOO_MANY;    /* Already at maximum allowed */
939  
940 <    if (conf->type == CLIENT_TYPE)
941 <      if (cidr_limit_reached(IsConfExemptLimits(aconf),
1371 <                             &client_p->localClient->ip, aclass))
1372 <        return TOO_MANY;    /* Already at maximum allowed */
1373 <
1374 <    aclass->curr_user_count++;
1375 <    aconf->clients++;
1376 <  }
1377 <  else if (conf->type == HUB_TYPE || conf->type == LEAF_TYPE)
1378 <  {
1379 <    struct MatchItem *match_item = map_to_conf(conf);
1380 <    match_item->ref_count++;
1381 <  }
940 >  conf->class->ref_count++;
941 >  conf->ref_count++;
942  
943    dlinkAdd(conf, make_dlink_node(), &client_p->localClient->confs);
944  
# Line 1398 | Line 958 | attach_connect_block(struct Client *clie
958                       const char *host)
959   {
960    dlink_node *ptr;
961 <  struct ConfItem *conf;
1402 <  struct AccessItem *aconf;
961 >  struct MaskItem *conf = NULL;
962  
963    assert(client_p != NULL);
964    assert(host != NULL);
# Line 1410 | Line 969 | attach_connect_block(struct Client *clie
969    DLINK_FOREACH(ptr, server_items.head)
970    {
971      conf = ptr->data;
1413    aconf = map_to_conf(conf);
972  
973 <    if (match(conf->name, name) == 0 || match(aconf->host, host) == 0)
973 >    if (match(conf->name, name) || match(conf->host, host))
974        continue;
975  
976      attach_conf(client_p, conf);
# Line 1422 | Line 980 | attach_connect_block(struct Client *clie
980    return 0;
981   }
982  
1425 /* find_conf_exact()
1426 *
1427 * inputs       - type of ConfItem
1428 *              - pointer to name to find
1429 *              - pointer to username to find
1430 *              - pointer to host to find
1431 * output       - NULL or pointer to conf found
1432 * side effects - find a conf entry which matches the hostname
1433 *                and has the same name.
1434 */
1435 struct ConfItem *
1436 find_conf_exact(ConfType type, const char *name, const char *user,
1437                const char *host)
1438 {
1439  dlink_node *ptr;
1440  dlink_list *list_p;
1441  struct ConfItem *conf = NULL;
1442  struct AccessItem *aconf;
1443
1444  /* Only valid for OPER_TYPE and ...? */
1445  list_p = map_to_list(type);
1446
1447  DLINK_FOREACH(ptr, (*list_p).head)
1448  {
1449    conf = ptr->data;
1450
1451    if (conf->name == NULL)
1452      continue;
1453    aconf = map_to_conf(conf);
1454    if (aconf->host == NULL)
1455      continue;
1456    if (irccmp(conf->name, name) != 0)
1457      continue;
1458
1459    /*
1460    ** Accept if the *real* hostname (usually sockethost)
1461    ** socket host) matches *either* host or name field
1462    ** of the configuration.
1463    */
1464    if (!match(aconf->host, host) || !match(aconf->user, user))
1465      continue;
1466    if (type == OPER_TYPE)
1467    {
1468      struct ClassItem *aclass = map_to_conf(aconf->class_ptr);
1469
1470      if (aconf->clients >= aclass->max_total)
1471        continue;
1472    }
1473
1474    return conf;
1475  }
1476
1477  return NULL;
1478 }
1479
983   /* find_conf_name()
984   *
985   * inputs       - pointer to conf link list to search
# Line 1486 | Line 989 | find_conf_exact(ConfType type, const cha
989   * side effects - find a conf entry which matches the name
990   *                and has the given mask.
991   */
992 < struct ConfItem *
993 < find_conf_name(dlink_list *list, const char *name, ConfType type)
992 > struct MaskItem *
993 > find_conf_name(dlink_list *list, const char *name, enum maskitem_type type)
994   {
995    dlink_node *ptr;
996 <  struct ConfItem* conf;
996 >  struct MaskItem* conf;
997  
998    DLINK_FOREACH(ptr, list->head)
999    {
# Line 1499 | Line 1002 | find_conf_name(dlink_list *list, const c
1002      if (conf->type == type)
1003      {
1004        if (conf->name && (irccmp(conf->name, name) == 0 ||
1005 <                         match(conf->name, name)))
1005 >                         !match(conf->name, name)))
1006        return conf;
1007      }
1008    }
# Line 1514 | Line 1017 | find_conf_name(dlink_list *list, const c
1017   * side effects - none
1018   */
1019   static dlink_list *
1020 < map_to_list(ConfType type)
1020 > map_to_list(enum maskitem_type type)
1021   {
1022    switch(type)
1023    {
1024 <  case RXLINE_TYPE:
1024 >  case CONF_RKLINE:
1025 >    return(&rkconf_items);
1026 >    break;
1027 >  case CONF_RXLINE:
1028      return(&rxconf_items);
1029      break;
1030 <  case XLINE_TYPE:
1030 >  case CONF_XLINE:
1031      return(&xconf_items);
1032      break;
1033 <  case ULINE_TYPE:
1033 >  case CONF_ULINE:
1034      return(&uconf_items);
1035      break;
1036 <  case NRESV_TYPE:
1036 >  case CONF_NRESV:
1037      return(&nresv_items);
1038      break;
1039 <  case OPER_TYPE:
1039 >  case CONF_OPER:
1040      return(&oconf_items);
1041      break;
1042 <  case CLASS_TYPE:
1537 <    return(&class_items);
1538 <    break;
1539 <  case SERVER_TYPE:
1042 >  case CONF_SERVER:
1043      return(&server_items);
1044      break;
1045 <  case SERVICE_TYPE:
1045 >  case CONF_SERVICE:
1046      return(&service_items);
1047      break;
1048 <  case CLUSTER_TYPE:
1048 >  case CONF_CLUSTER:
1049      return(&cluster_items);
1050      break;
1548  case CONF_TYPE:
1549  case GLINE_TYPE:
1550  case KLINE_TYPE:
1551  case DLINE_TYPE:
1552  case CRESV_TYPE:
1051    default:
1052      return NULL;
1053    }
# Line 1561 | Line 1059 | map_to_list(ConfType type)
1059   *              - pointer to name string to find
1060   *              - pointer to user
1061   *              - pointer to host
1062 < *              - optional action to match on as well
1063 < * output       - NULL or pointer to found struct MatchItem
1062 > *              - optional flags to match on as well
1063 > * output       - NULL or pointer to found struct MaskItem
1064   * side effects - looks for a match on name field
1065   */
1066 < struct ConfItem *
1067 < find_matching_name_conf(ConfType type, const char *name, const char *user,
1068 <                        const char *host, int action)
1066 > struct MaskItem *
1067 > find_matching_name_conf(enum maskitem_type type, const char *name, const char *user,
1068 >                        const char *host, unsigned int flags)
1069   {
1070    dlink_node *ptr=NULL;
1071 <  struct ConfItem *conf=NULL;
1574 <  struct AccessItem *aconf=NULL;
1575 <  struct MatchItem *match_item=NULL;
1071 >  struct MaskItem *conf=NULL;
1072    dlink_list *list_p = map_to_list(type);
1073  
1074    switch (type)
1075    {
1076   #ifdef HAVE_LIBPCRE
1077 <  case RXLINE_TYPE:
1077 >  case CONF_RXLINE:
1078        DLINK_FOREACH(ptr, list_p->head)
1079        {
1080          conf = ptr->data;
1081 <        assert(conf->regexpname);
1081 >        assert(conf->regexuser);
1082  
1083 <        if (!ircd_pcre_exec(conf->regexpname, name))
1083 >        if (!ircd_pcre_exec(conf->regexuser, name))
1084            return conf;
1085        }
1086        break;
1087   #endif
1088 <  case SERVICE_TYPE:
1088 >  case CONF_SERVICE:
1089      DLINK_FOREACH(ptr, list_p->head)
1090      {
1091        conf = ptr->data;
# Line 1601 | Line 1097 | find_matching_name_conf(ConfType type, c
1097      }
1098      break;
1099  
1100 <  case XLINE_TYPE:
1101 <  case ULINE_TYPE:
1102 <  case NRESV_TYPE:
1100 >  case CONF_XLINE:
1101 >  case CONF_ULINE:
1102 >  case CONF_NRESV:
1103      DLINK_FOREACH(ptr, list_p->head)
1104      {
1105        conf = ptr->data;
1106  
1611      match_item = map_to_conf(conf);
1107        if (EmptyString(conf->name))
1108          continue;
1109 <      if ((name != NULL) && match_esc(conf->name, name))
1109 >      if ((name != NULL) && !match(conf->name, name))
1110        {
1111          if ((user == NULL && (host == NULL)))
1112            return conf;
1113 <        if ((match_item->action & action) != action)
1113 >        if ((conf->flags & flags) != flags)
1114            continue;
1115 <        if (EmptyString(match_item->user) || EmptyString(match_item->host))
1115 >        if (EmptyString(conf->user) || EmptyString(conf->host))
1116            return conf;
1117 <        if (match(match_item->user, user) && match(match_item->host, host))
1117 >        if (!match(conf->user, user) && !match(conf->host, host))
1118            return conf;
1119        }
1120      }
1121        break;
1122  
1123 <  case SERVER_TYPE:
1123 >  case CONF_SERVER:
1124      DLINK_FOREACH(ptr, list_p->head)
1125      {
1126        conf = ptr->data;
1632      aconf = map_to_conf(conf);
1127  
1128 <      if ((name != NULL) && match_esc(name, conf->name))
1128 >      if ((name != NULL) && !match(name, conf->name))
1129          return conf;
1130 <      else if ((host != NULL) && match_esc(host, aconf->host))
1130 >      else if ((host != NULL) && !match(host, conf->host))
1131          return conf;
1132      }
1133      break;
# Line 1650 | Line 1144 | find_matching_name_conf(ConfType type, c
1144   *              - pointer to name string to find
1145   *              - pointer to user
1146   *              - pointer to host
1147 < * output       - NULL or pointer to found struct MatchItem
1147 > * output       - NULL or pointer to found struct MaskItem
1148   * side effects - looks for an exact match on name field
1149   */
1150 < struct ConfItem *
1151 < find_exact_name_conf(ConfType type, const struct Client *who, const char *name,
1150 > struct MaskItem *
1151 > find_exact_name_conf(enum maskitem_type type, const struct Client *who, const char *name,
1152                       const char *user, const char *host)
1153   {
1154    dlink_node *ptr = NULL;
1155 <  struct AccessItem *aconf;
1156 <  struct ConfItem *conf;
1663 <  struct MatchItem *match_item;
1664 <  dlink_list *list_p;
1665 <
1666 <  list_p = map_to_list(type);
1155 >  struct MaskItem *conf;
1156 >  dlink_list *list_p = map_to_list(type);
1157  
1158    switch(type)
1159    {
1160 <  case RXLINE_TYPE:
1161 <  case XLINE_TYPE:
1162 <  case ULINE_TYPE:
1163 <  case NRESV_TYPE:
1160 >  case CONF_RXLINE:
1161 >  case CONF_XLINE:
1162 >  case CONF_ULINE:
1163 >  case CONF_NRESV:
1164  
1165      DLINK_FOREACH(ptr, list_p->head)
1166      {
1167        conf = ptr->data;
1168 <      match_item = (struct MatchItem *)map_to_conf(conf);
1168 >
1169        if (EmptyString(conf->name))
1170          continue;
1171      
# Line 1683 | Line 1173 | find_exact_name_conf(ConfType type, cons
1173        {
1174          if ((user == NULL && (host == NULL)))
1175            return (conf);
1176 <        if (EmptyString(match_item->user) || EmptyString(match_item->host))
1176 >        if (EmptyString(conf->user) || EmptyString(conf->host))
1177            return (conf);
1178 <        if (match(match_item->user, user) && match(match_item->host, host))
1178 >        if (!match(conf->user, user) && !match(conf->host, host))
1179            return (conf);
1180        }
1181      }
1182      break;
1183  
1184 <  case OPER_TYPE:
1184 >  case CONF_OPER:
1185      DLINK_FOREACH(ptr, list_p->head)
1186      {
1187        conf = ptr->data;
1698      aconf = map_to_conf(conf);
1188  
1189        if (EmptyString(conf->name))
1190          continue;
# Line 1704 | Line 1193 | find_exact_name_conf(ConfType type, cons
1193        {
1194          if (!who)
1195            return conf;
1196 <        if (EmptyString(aconf->user) || EmptyString(aconf->host))
1197 <          return conf;
1198 <        if (match(aconf->user, who->username))
1196 >        if (EmptyString(conf->user) || EmptyString(conf->host))
1197 >          return NULL;
1198 >        if (!match(conf->user, who->username))
1199          {
1200 <          switch (aconf->type)
1200 >          switch (conf->htype)
1201            {
1202              case HM_HOST:
1203 <              if (match(aconf->host, who->host) || match(aconf->host, who->sockhost))
1204 <                return conf;
1203 >              if (!match(conf->host, who->host) || !match(conf->host, who->sockhost))
1204 >                if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
1205 >                  return conf;
1206                break;
1207              case HM_IPV4:
1208                if (who->localClient->aftype == AF_INET)
1209 <                if (match_ipv4(&who->localClient->ip, &aconf->ipnum, aconf->bits))
1210 <                  return conf;
1209 >                if (match_ipv4(&who->localClient->ip, &conf->addr, conf->bits))
1210 >                  if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
1211 >                    return conf;
1212                break;
1213   #ifdef IPV6
1214              case HM_IPV6:
1215                if (who->localClient->aftype == AF_INET6)
1216 <                if (match_ipv6(&who->localClient->ip, &aconf->ipnum, aconf->bits))
1217 <                  return conf;
1216 >                if (match_ipv6(&who->localClient->ip, &conf->addr, conf->bits))
1217 >                  if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
1218 >                    return conf;
1219                break;
1220   #endif
1221              default:
# Line 1735 | Line 1227 | find_exact_name_conf(ConfType type, cons
1227  
1228      break;
1229  
1230 <  case SERVER_TYPE:
1230 >  case CONF_SERVER:
1231      DLINK_FOREACH(ptr, list_p->head)
1232      {
1233        conf = ptr->data;
1234 <      aconf = (struct AccessItem *)map_to_conf(conf);
1234 >
1235        if (EmptyString(conf->name))
1236          continue;
1237      
1238        if (name == NULL)
1239        {
1240 <        if (EmptyString(aconf->host))
1240 >        if (EmptyString(conf->host))
1241            continue;
1242 <        if (irccmp(aconf->host, host) == 0)
1242 >        if (irccmp(conf->host, host) == 0)
1243            return(conf);
1244        }
1245        else if (irccmp(conf->name, name) == 0)
# Line 1757 | Line 1249 | find_exact_name_conf(ConfType type, cons
1249      }
1250      break;
1251  
1760  case CLASS_TYPE:
1761    DLINK_FOREACH(ptr, list_p->head)
1762    {
1763      conf = ptr->data;
1764      if (EmptyString(conf->name))
1765        continue;
1766    
1767      if (irccmp(conf->name, name) == 0)
1768        return (conf);
1769    }
1770    break;
1771
1252    default:
1253      break;
1254    }
# Line 1785 | Line 1265 | int
1265   rehash(int sig)
1266   {
1267    if (sig != 0)
1268 <    sendto_realops_flags(UMODE_ALL, L_ALL,
1268 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1269                           "Got signal SIGHUP, reloading ircd.conf file");
1270  
1271    restart_resolver();
# Line 1802 | Line 1282 | rehash(int sig)
1282  
1283    load_conf_modules();
1284  
1805  flush_deleted_I_P();
1806
1285    rehashed_klines = 1;
1286   /* XXX */
1287    if (ConfigLoggingEntry.use_logging)
# Line 1827 | Line 1305 | set_default_conf(void)
1305    /* verify init_class() ran, this should be an unnecessary check
1306     * but its not much work.
1307     */
1308 <  assert(class_default == (struct ConfItem *) class_items.tail->data);
1308 >  assert(class_default == class_get_list()->tail->data);
1309  
1310   #ifdef HAVE_LIBCRYPTO
1311    ServerInfo.rsa_private_key = NULL;
# Line 1837 | Line 1315 | set_default_conf(void)
1315    /* ServerInfo.name is not rehashable */
1316    /* ServerInfo.name = ServerInfo.name; */
1317    ServerInfo.description = NULL;
1318 <  DupString(ServerInfo.network_name, NETWORK_NAME_DEFAULT);
1319 <  DupString(ServerInfo.network_desc, NETWORK_DESC_DEFAULT);
1318 >  ServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
1319 >  ServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
1320  
1321    memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip));
1322    ServerInfo.specific_ipv4_vhost = 0;
# Line 1846 | Line 1324 | set_default_conf(void)
1324    ServerInfo.specific_ipv6_vhost = 0;
1325  
1326    ServerInfo.max_clients = MAXCLIENTS_MAX;
1327 +  ServerInfo.max_nick_length = 9;
1328 +  ServerInfo.max_topic_length = 80;
1329  
1330    ServerInfo.hub = 0;
1331    ServerInfo.dns_host.sin_addr.s_addr = 0;
# Line 1860 | Line 1340 | set_default_conf(void)
1340  
1341    ConfigChannel.disable_fake_channels = 0;
1342    ConfigChannel.restrict_channels = 0;
1863  ConfigChannel.disable_local_channels = 0;
1864  ConfigChannel.use_invex = 1;
1865  ConfigChannel.use_except = 1;
1866  ConfigChannel.use_knock = 1;
1343    ConfigChannel.knock_delay = 300;
1344    ConfigChannel.knock_delay_channel = 60;
1345 <  ConfigChannel.max_chans_per_user = 15;
1345 >  ConfigChannel.max_chans_per_user = 25;
1346 >  ConfigChannel.max_chans_per_oper = 50;
1347    ConfigChannel.quiet_on_ban = 1;
1348    ConfigChannel.max_bans = 25;
1349    ConfigChannel.default_split_user_count = 0;
1350    ConfigChannel.default_split_server_count = 0;
1351    ConfigChannel.no_join_on_split = 0;
1352    ConfigChannel.no_create_on_split = 0;
1876  ConfigChannel.burst_topicwho = 1;
1353  
1354    ConfigServerHide.flatten_links = 0;
1355    ConfigServerHide.links_delay = 300;
1356    ConfigServerHide.hidden = 0;
1881  ConfigServerHide.disable_hidden = 0;
1357    ConfigServerHide.hide_servers = 0;
1358 <  DupString(ConfigServerHide.hidden_name, NETWORK_NAME_DEFAULT);
1358 >  ConfigServerHide.hidden_name = xstrdup(NETWORK_NAME_DEFAULT);
1359    ConfigServerHide.hide_server_ips = 0;
1360  
1361    
1362 <  DupString(ConfigFileEntry.service_name, SERVICE_NAME_DEFAULT);
1362 >  ConfigFileEntry.service_name = xstrdup(SERVICE_NAME_DEFAULT);
1363    ConfigFileEntry.max_watch = WATCHSIZE_DEFAULT;
1364 +  ConfigFileEntry.glines = 0;
1365 +  ConfigFileEntry.gline_time = 12 * 3600;
1366 +  ConfigFileEntry.gline_request_time = GLINE_REQUEST_EXPIRE_DEFAULT;
1367    ConfigFileEntry.gline_min_cidr = 16;
1368    ConfigFileEntry.gline_min_cidr6 = 48;
1369    ConfigFileEntry.invisible_on_connect = 1;
1892  ConfigFileEntry.burst_away = 0;
1893  ConfigFileEntry.use_whois_actually = 1;
1370    ConfigFileEntry.tkline_expire_notices = 1;
1371    ConfigFileEntry.hide_spoof_ips = 1;
1372    ConfigFileEntry.ignore_bogus_ts = 0;
# Line 1909 | Line 1385 | set_default_conf(void)
1385    ConfigFileEntry.anti_spam_exit_message_time = 0;
1386    ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
1387    ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
1912  ConfigFileEntry.kline_with_reason = 1;
1913  ConfigFileEntry.kline_reason = NULL;
1388    ConfigFileEntry.warn_no_nline = 1;
1389    ConfigFileEntry.stats_o_oper_only = 0;
1390    ConfigFileEntry.stats_k_oper_only = 1;  /* masked */
# Line 1925 | Line 1399 | set_default_conf(void)
1399    ConfigFileEntry.no_oper_flood = 0;
1400    ConfigFileEntry.true_no_oper_flood = 0;
1401    ConfigFileEntry.oper_pass_resv = 1;
1928  ConfigFileEntry.glines = 0;
1929  ConfigFileEntry.gline_time = 12 * 3600;
1402    ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT;
1931  ConfigFileEntry.client_flood = CLIENT_FLOOD_DEFAULT;
1403    ConfigFileEntry.oper_only_umodes = UMODE_DEBUG;
1404    ConfigFileEntry.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE |
1405      UMODE_OPERWALL | UMODE_WALLOP;
# Line 1947 | Line 1418 | validate_conf(void)
1418      ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
1419  
1420    if (ServerInfo.network_name == NULL)
1421 <    DupString(ServerInfo.network_name,NETWORK_NAME_DEFAULT);
1421 >    ServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
1422  
1423    if (ServerInfo.network_desc == NULL)
1424 <    DupString(ServerInfo.network_desc,NETWORK_DESC_DEFAULT);
1424 >    ServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
1425  
1426    if (ConfigFileEntry.service_name == NULL)
1427 <    DupString(ConfigFileEntry.service_name, SERVICE_NAME_DEFAULT);
1957 <
1958 <  if ((ConfigFileEntry.client_flood < CLIENT_FLOOD_MIN) ||
1959 <      (ConfigFileEntry.client_flood > CLIENT_FLOOD_MAX))
1960 <    ConfigFileEntry.client_flood = CLIENT_FLOOD_MAX;
1427 >    ConfigFileEntry.service_name = xstrdup(SERVICE_NAME_DEFAULT);
1428  
1429    ConfigFileEntry.max_watch = IRCD_MAX(ConfigFileEntry.max_watch, WATCHSIZE_MIN);
1430   }
# Line 1983 | Line 1450 | read_conf(FILE *file)
1450    yyparse();          /* Load the values from the conf */
1451    validate_conf();    /* Check to make sure some values are still okay. */
1452                        /* Some global values are also loaded here. */
1453 <  check_class();      /* Make sure classes are valid */
1453 >  class_delete_marked();      /* Make sure classes are valid */
1454   }
1455  
1456   /* lookup_confhost()
# Line 1991 | Line 1458 | read_conf(FILE *file)
1458   * start DNS lookups of all hostnames in the conf
1459   * line and convert an IP addresses in a.b.c.d number for to IP#s.
1460   */
1461 < static void
1462 < lookup_confhost(struct ConfItem *conf)
1461 > void
1462 > lookup_confhost(struct MaskItem *conf)
1463   {
1997  struct AccessItem *aconf;
1464    struct addrinfo hints, *res;
1465  
2000  aconf = map_to_conf(conf);
2001
2002  if (EmptyString(aconf->host) ||
2003      EmptyString(aconf->user))
2004  {
2005    ilog(LOG_TYPE_IRCD, "Host/server name error: (%s) (%s)",
2006         aconf->host, conf->name);
2007    return;
2008  }
2009
2010  if (strchr(aconf->host, '*') ||
2011      strchr(aconf->host, '?'))
2012    return;
2013
1466    /* Do name lookup now on hostnames given and store the
1467     * ip numbers in conf structure.
1468     */
# Line 2022 | Line 1474 | lookup_confhost(struct ConfItem *conf)
1474    /* Get us ready for a bind() and don't bother doing dns lookup */
1475    hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
1476  
1477 <  if (getaddrinfo(aconf->host, NULL, &hints, &res))
1477 >  if (getaddrinfo(conf->host, NULL, &hints, &res))
1478    {
1479 <    conf_dns_lookup(aconf);
1479 >    conf_dns_lookup(conf);
1480      return;
1481    }
1482  
1483    assert(res != NULL);
1484  
1485 <  memcpy(&aconf->ipnum, res->ai_addr, res->ai_addrlen);
1486 <  aconf->ipnum.ss_len = res->ai_addrlen;
1487 <  aconf->ipnum.ss.ss_family = res->ai_family;
1485 >  memcpy(&conf->addr, res->ai_addr, res->ai_addrlen);
1486 >  conf->addr.ss_len = res->ai_addrlen;
1487 >  conf->addr.ss.ss_family = res->ai_family;
1488 >
1489    freeaddrinfo(res);
1490   }
1491  
# Line 2047 | Line 1500 | int
1500   conf_connect_allowed(struct irc_ssaddr *addr, int aftype)
1501   {
1502    struct ip_entry *ip_found;
1503 <  struct AccessItem *aconf = find_dline_conf(addr, aftype);
1503 >  struct MaskItem *conf = find_dline_conf(addr, aftype);
1504  
1505    /* DLINE exempt also gets you out of static limits/pacing... */
1506 <  if (aconf && (aconf->status & CONF_EXEMPTDLINE))
1506 >  if (conf && (conf->type == CONF_EXEMPT))
1507      return 0;
1508  
1509 <  if (aconf != NULL)
1509 >  if (conf != NULL)
1510      return BANNED_CLIENT;
1511  
1512    ip_found = find_or_add_ip(addr);
# Line 2069 | Line 1522 | conf_connect_allowed(struct irc_ssaddr *
1522    return 0;
1523   }
1524  
1525 < static struct AccessItem *
1525 > static struct MaskItem *
1526   find_regexp_kline(const char *uhi[])
1527   {
1528   #ifdef HAVE_LIBPCRE
# Line 2077 | Line 1530 | find_regexp_kline(const char *uhi[])
1530  
1531    DLINK_FOREACH(ptr, rkconf_items.head)
1532    {
1533 <    struct AccessItem *aptr = map_to_conf(ptr->data);
1533 >    struct MaskItem *aptr = ptr->data;
1534  
1535      assert(aptr->regexuser);
1536      assert(aptr->regexhost);
# Line 2094 | Line 1547 | find_regexp_kline(const char *uhi[])
1547   /* find_kill()
1548   *
1549   * inputs       - pointer to client structure
1550 < * output       - pointer to struct AccessItem if found
1550 > * output       - pointer to struct MaskItem if found
1551   * side effects - See if this user is klined already,
1552 < *                and if so, return struct AccessItem pointer
1552 > *                and if so, return struct MaskItem pointer
1553   */
1554 < struct AccessItem *
1554 > struct MaskItem *
1555   find_kill(struct Client *client_p)
1556   {
1557 <  struct AccessItem *aconf = NULL;
1557 >  struct MaskItem *conf = NULL;
1558    const char *uhi[3];
1559  
1560    uhi[0] = client_p->username;
# Line 2110 | Line 1563 | find_kill(struct Client *client_p)
1563  
1564    assert(client_p != NULL);
1565  
1566 <  aconf = find_kline_conf(client_p->host, client_p->username,
1567 <                          &client_p->localClient->ip,
1568 <                          client_p->localClient->aftype);
1569 <  if (aconf == NULL)
1570 <    aconf = find_regexp_kline(uhi);
2118 <
2119 <  if (aconf && (aconf->status & CONF_KLINE))
2120 <    return aconf;
1566 >  conf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
1567 >                              CONF_KLINE, client_p->localClient->aftype,
1568 >                              client_p->username, NULL, 1);
1569 >  if (conf == NULL)
1570 >    conf = find_regexp_kline(uhi);
1571  
1572 <  return NULL;
1572 >  return conf;
1573   }
1574  
1575 < struct AccessItem *
1575 > struct MaskItem *
1576   find_gline(struct Client *client_p)
1577   {
1578 <  struct AccessItem *aconf;
1578 >  struct MaskItem *conf;
1579  
1580    assert(client_p != NULL);
1581  
1582 <  aconf = find_gline_conf(client_p->host, client_p->username,
1583 <                          &client_p->localClient->ip,
1584 <                          client_p->localClient->aftype);
1585 <
2136 <  if (aconf && (aconf->status & CONF_GLINE))
2137 <    return aconf;
2138 <
2139 <  return NULL;
2140 < }
2141 <
2142 < /* add_temp_line()
2143 < *
2144 < * inputs        - pointer to struct ConfItem
2145 < * output        - none
2146 < * Side effects  - links in given struct ConfItem into
2147 < *                 temporary *line link list
2148 < */
2149 < void
2150 < add_temp_line(struct ConfItem *conf)
2151 < {
2152 <  if (conf->type == XLINE_TYPE)
2153 <  {
2154 <    conf->flags |= CONF_FLAGS_TEMPORARY;
2155 <    dlinkAdd(conf, make_dlink_node(), &temporary_xlines);
2156 <  }
2157 <  else if ((conf->type == NRESV_TYPE) || (conf->type == CRESV_TYPE))
2158 <  {
2159 <    conf->flags |= CONF_FLAGS_TEMPORARY;
2160 <    dlinkAdd(conf, make_dlink_node(), &temporary_resv);
2161 <  }
1582 >  conf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
1583 >                              CONF_GLINE, client_p->localClient->aftype,
1584 >                              client_p->username, NULL, 1);
1585 >  return conf;
1586   }
1587  
1588   /* cleanup_tklines()
# Line 2172 | Line 1596 | void
1596   cleanup_tklines(void *notused)
1597   {
1598    hostmask_expire_temporary();
1599 <  expire_tklines(&temporary_xlines);
1600 <  expire_tklines(&temporary_resv);
1599 >  expire_tklines(&xconf_items);
1600 >  expire_tklines(&nresv_items);
1601 >  expire_tklines(&resv_channel_list);
1602   }
1603  
1604   /* expire_tklines()
# Line 2187 | Line 1612 | expire_tklines(dlink_list *tklist)
1612   {
1613    dlink_node *ptr;
1614    dlink_node *next_ptr;
1615 <  struct ConfItem *conf;
2191 <  struct MatchItem *xconf;
2192 <  struct MatchItem *nconf;
2193 <  struct ResvChannel *cconf;
1615 >  struct MaskItem *conf;
1616  
1617    DLINK_FOREACH_SAFE(ptr, next_ptr, tklist->head)
1618    {
1619      conf = ptr->data;
1620  
1621 <    if (conf->type == XLINE_TYPE)
1621 >    if (!conf->until || conf->until > CurrentTime)
1622 >      continue;
1623 >
1624 >    if (conf->type == CONF_XLINE)
1625      {
1626 <      xconf = (struct MatchItem *)map_to_conf(conf);
1627 <      if (xconf->hold <= CurrentTime)
1628 <      {
1629 <        if (ConfigFileEntry.tkline_expire_notices)
2205 <          sendto_realops_flags(UMODE_ALL, L_ALL,
2206 <                               "Temporary X-line for [%s] sexpired", conf->name);
2207 <        dlinkDelete(ptr, tklist);
2208 <        free_dlink_node(ptr);
2209 <        delete_conf_item(conf);
2210 <      }
1626 >      if (ConfigFileEntry.tkline_expire_notices)
1627 >        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1628 >                               "Temporary X-line for [%s] expired", conf->name);
1629 >      conf_free(conf);
1630      }
1631 <    else if (conf->type == NRESV_TYPE)
1631 >    else if (conf->type == CONF_NRESV)
1632      {
1633 <      nconf = (struct MatchItem *)map_to_conf(conf);
1634 <      if (nconf->hold <= CurrentTime)
2216 <      {
2217 <        if (ConfigFileEntry.tkline_expire_notices)
2218 <          sendto_realops_flags(UMODE_ALL, L_ALL,
1633 >      if (ConfigFileEntry.tkline_expire_notices)
1634 >        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1635                                 "Temporary RESV for [%s] expired", conf->name);
1636 <        dlinkDelete(ptr, tklist);
2221 <        free_dlink_node(ptr);
2222 <        delete_conf_item(conf);
2223 <      }
1636 >      conf_free(conf);
1637      }
1638 <    else if (conf->type == CRESV_TYPE)
1638 >    else if (conf->type == CONF_CRESV)
1639      {
1640 <      cconf = (struct ResvChannel *)map_to_conf(conf);
1641 <      if (cconf->hold <= CurrentTime)
1642 <      {
1643 <        if (ConfigFileEntry.tkline_expire_notices)
2231 <          sendto_realops_flags(UMODE_ALL, L_ALL,
2232 <                               "Temporary RESV for [%s] expired", cconf->name);
2233 <        delete_channel_resv(cconf);
2234 <      }
1640 >      if (ConfigFileEntry.tkline_expire_notices)
1641 >        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1642 >                               "Temporary RESV for [%s] expired", conf->name);
1643 >      delete_channel_resv(conf);
1644      }
1645    }
1646   }
# Line 2244 | Line 1653 | expire_tklines(dlink_list *tklist)
1653   */
1654   static const struct oper_privs
1655   {
1656 <  const unsigned int oprivs;
1656 >  const unsigned int flag;
1657    const unsigned char c;
1658   } flag_list[] = {
1659    { OPER_FLAG_ADMIN,       'A' },
# Line 2268 | Line 1677 | oper_privs_as_string(const unsigned int
1677   {
1678    static char privs_out[16];
1679    char *privs_ptr = privs_out;
1680 <  unsigned int i = 0;
1680 >  const struct oper_privs *opriv = flag_list;
1681  
1682 <  for (; flag_list[i].oprivs; ++i)
1682 >  for (; opriv->flag; ++opriv)
1683    {
1684 <    if (port & flag_list[i].oprivs)
1685 <      *privs_ptr++ = flag_list[i].c;
1684 >    if (port & opriv->flag)
1685 >      *privs_ptr++ = opriv->c;
1686      else
1687 <      *privs_ptr++ = ToLowerTab[flag_list[i].c];
1687 >      *privs_ptr++ = ToLower(opriv->c);
1688    }
1689  
1690    *privs_ptr = '\0';
# Line 2300 | Line 1709 | get_oper_name(const struct Client *clien
1709    {
1710      if ((cnode = client_p->localClient->confs.head))
1711      {
1712 <      struct ConfItem *conf = cnode->data;
2304 <      const struct AccessItem *aconf = map_to_conf(conf);
1712 >      struct MaskItem *conf = cnode->data;
1713  
1714 <      if (IsConfOperator(aconf))
1714 >      if (IsConfOperator(conf))
1715        {
1716          snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1717                   client_p->username, client_p->host, conf->name);
# Line 2336 | Line 1744 | read_conf_files(int cold)
1744    char chanlimit[32];
1745  
1746    conf_parser_ctx.boot = cold;
1747 <  filename = get_conf_name(CONF_TYPE);
1747 >  filename = ConfigFileEntry.configfile;
1748  
1749    /* We need to know the initial filename for the yyerror() to report
1750       FIXME: The full path is in conffilenamebuf first time since we
# Line 2356 | Line 1764 | read_conf_files(int cold)
1764      }
1765      else
1766      {
1767 <      sendto_realops_flags(UMODE_ALL, L_ALL,
1767 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1768                             "Unable to read configuration file '%s': %s",
1769                             filename, strerror(errno));
1770        return;
# Line 2369 | Line 1777 | read_conf_files(int cold)
1777    read_conf(conf_parser_ctx.conf_file);
1778    fclose(conf_parser_ctx.conf_file);
1779  
1780 +  add_isupport("NICKLEN", NULL, ServerInfo.max_nick_length);
1781    add_isupport("NETWORK", ServerInfo.network_name, -1);
1782 <  snprintf(chanmodes, sizeof(chanmodes), "b%s%s:%d",
1783 <           ConfigChannel.use_except ? "e" : "",
2375 <           ConfigChannel.use_invex ? "I" : "", ConfigChannel.max_bans);
1782 >
1783 >  snprintf(chanmodes, sizeof(chanmodes), "beI:%d", ConfigChannel.max_bans);
1784    add_isupport("MAXLIST", chanmodes, -1);
1785    add_isupport("MAXTARGETS", NULL, ConfigFileEntry.max_targets);
1786 +  add_isupport("CHANTYPES", "#", -1);
1787  
1788 <  if (ConfigChannel.disable_local_channels)
1789 <    add_isupport("CHANTYPES", "#", -1);
2381 <  else
2382 <    add_isupport("CHANTYPES", "#&", -1);
2383 <
2384 <  snprintf(chanlimit, sizeof(chanlimit), "%s:%d",
2385 <           ConfigChannel.disable_local_channels ? "#" : "#&",
2386 <           ConfigChannel.max_chans_per_user);
1788 >  snprintf(chanlimit, sizeof(chanlimit), "#:%d",
1789 >           ConfigChannel.max_chans_per_user);
1790    add_isupport("CHANLIMIT", chanlimit, -1);
1791 <  snprintf(chanmodes, sizeof(chanmodes), "%s%s%s",
2389 <           ConfigChannel.use_except ? "e" : "",
2390 <           ConfigChannel.use_invex ? "I" : "", "b,k,l,imnprstORS");
1791 >  snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,imnprstORS");
1792    add_isupport("CHANNELLEN", NULL, LOCAL_CHANNELLEN);
1793 <
1794 <  if (ConfigChannel.use_except)
1795 <    add_isupport("EXCEPTS", "e", -1);
2395 <  if (ConfigChannel.use_invex)
2396 <    add_isupport("INVEX", "I", -1);
1793 >  add_isupport("TOPICLEN", NULL, ServerInfo.max_topic_length);
1794 >  add_isupport("EXCEPTS", "e", -1);
1795 >  add_isupport("INVEX", "I", -1);
1796    add_isupport("CHANMODES", chanmodes, -1);
1797  
1798    /*
# Line 2401 | Line 1800 | read_conf_files(int cold)
1800     * on strlen(form_str(RPL_ISUPPORT))
1801     */
1802    rebuild_isupport_message_line();
2404
2405 #ifdef HAVE_LIBPCRE
2406  parse_conf_file(RKLINE_TYPE, cold);
2407  parse_conf_file(RXLINE_TYPE, cold);
2408 #endif
2409  parse_conf_file(KLINE_TYPE, cold);
2410  parse_conf_file(DLINE_TYPE, cold);
2411  parse_conf_file(XLINE_TYPE, cold);
2412  parse_conf_file(NRESV_TYPE, cold);
2413  parse_conf_file(CRESV_TYPE, cold);
2414 }
2415
2416 /* parse_conf_file()
2417 *
2418 * inputs       - type of conf file to parse
2419 * output       - none
2420 * side effects - conf file for givenconf type is opened and read then parsed
2421 */
2422 static void
2423 parse_conf_file(int type, int cold)
2424 {
2425  FILE *file = NULL;
2426  const char *filename = get_conf_name(type);
2427
2428  if ((file = fopen(filename, "r")) == NULL)
2429  {
2430    if (cold)
2431      ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
2432           filename, strerror(errno));
2433    else
2434      sendto_realops_flags(UMODE_ALL, L_ALL,
2435                    "Unable to read configuration file '%s': %s",
2436                           filename, strerror(errno));
2437  }
2438  else
2439  {
2440    parse_csv_file(file, type);
2441    fclose(file);
2442  }
1803   }
1804  
1805   /* clear_out_old_conf()
# Line 2452 | Line 1812 | static void
1812   clear_out_old_conf(void)
1813   {
1814    dlink_node *ptr = NULL, *next_ptr = NULL;
1815 <  struct ConfItem *conf;
2456 <  struct AccessItem *aconf;
2457 <  struct ClassItem *cltmp;
2458 <  struct MatchItem *match_item;
1815 >  struct MaskItem *conf;
1816    dlink_list *free_items [] = {
1817 <    &server_items,   &oconf_items,    &hub_items, &leaf_items,
1817 >    &server_items,   &oconf_items,
1818       &uconf_items,   &xconf_items, &rxconf_items, &rkconf_items,
1819 <     &nresv_items, &cluster_items,  &gdeny_items, &service_items, NULL
1819 >     &nresv_items, &cluster_items,  &service_items, NULL
1820    };
1821  
1822    dlink_list ** iterator = free_items; /* C is dumb */
# Line 2473 | Line 1830 | clear_out_old_conf(void)
1830      DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head)
1831      {
1832        conf = ptr->data;
2476      /* XXX This is less than pretty */
2477      if (conf->type == SERVER_TYPE)
2478      {
2479        aconf = map_to_conf(conf);
1833  
1834 <        if (aconf->clients != 0)
2482 <        {
2483 <          SetConfIllegal(aconf);
2484 <          dlinkDelete(&conf->node, &server_items);
2485 <        }
2486 <        else
2487 <        {
2488 <          delete_conf_item(conf);
2489 <        }
2490 <      }
2491 <      else if (conf->type == OPER_TYPE)
2492 <      {
2493 <        aconf = map_to_conf(conf);
1834 >      dlinkDelete(&conf->node, map_to_list(conf->type));
1835  
1836 <        if (aconf->clients != 0)
1837 <        {
2497 <          SetConfIllegal(aconf);
2498 <          dlinkDelete(&conf->node, &oconf_items);
2499 <        }
2500 <        else
2501 <        {
2502 <          delete_conf_item(conf);
2503 <        }
2504 <      }
2505 <      else if (conf->type == XLINE_TYPE  ||
2506 <               conf->type == RXLINE_TYPE ||
2507 <               conf->type == RKLINE_TYPE)
1836 >      /* XXX This is less than pretty */
1837 >      if (conf->type == CONF_SERVER || conf->type == CONF_OPER)
1838        {
1839 <        /* temporary (r)xlines are also on
1840 <         * the (r)xconf items list */
2511 <        if (conf->flags & CONF_FLAGS_TEMPORARY)
2512 <          continue;
2513 <
2514 <        delete_conf_item(conf);
1839 >        if (!conf->ref_count)
1840 >          conf_free(conf);
1841        }
1842 <      else
1842 >      else if (conf->type == CONF_XLINE  ||
1843 >               conf->type == CONF_RXLINE ||
1844 >               conf->type == CONF_RKLINE)
1845        {
1846 <        if ((conf->type == LEAF_TYPE) || (conf->type == HUB_TYPE))
1847 <        {
2520 <          match_item = map_to_conf(conf);
2521 <          if (match_item->ref_count <= 0)
2522 <            delete_conf_item(conf);
2523 <          else
2524 <          {
2525 <            match_item->illegal = 1;
2526 <            dlinkDelete(&conf->node, *iterator);
2527 <          }
2528 <        }
2529 <        else
2530 <          delete_conf_item(conf);
1846 >        if (!conf->until)
1847 >          conf_free(conf);
1848        }
1849 +      else
1850 +        conf_free(conf);
1851      }
1852    }
1853  
1854    /*
1855     * don't delete the class table, rather mark all entries
1856 <   * for deletion. The table is cleaned up by check_class. - avalon
1856 >   * for deletion. The table is cleaned up by class_delete_marked. - avalon
1857     */
1858 <  DLINK_FOREACH(ptr, class_items.head)
2540 <  {
2541 <    cltmp = map_to_conf(ptr->data);
2542 <
2543 <    if (ptr != class_items.tail)  /* never mark the "default" class */
2544 <      cltmp->active = 0;
2545 <  }
1858 >  class_mark_for_deletion();
1859  
1860    clear_out_address_conf();
1861  
# Line 2589 | Line 1902 | clear_out_old_conf(void)
1902    MyFree(AdminInfo.description);
1903    AdminInfo.description = NULL;
1904  
2592  /* operator{} and class{} blocks are freed above */
1905    /* clean out listeners */
1906    close_listeners();
1907  
2596  /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{},
2597   * exempt{} and gecos{} blocks are freed above too
2598   */
2599
1908    /* clean out general */
1909    MyFree(ConfigFileEntry.service_name);
1910    ConfigFileEntry.service_name = NULL;
# Line 2605 | Line 1913 | clear_out_old_conf(void)
1913    delete_isupport("EXCEPTS");
1914   }
1915  
2608 /* flush_deleted_I_P()
2609 *
2610 * inputs       - none
2611 * output       - none
2612 * side effects - This function removes I/P conf items
2613 */
2614 static void
2615 flush_deleted_I_P(void)
2616 {
2617  dlink_node *ptr;
2618  dlink_node *next_ptr;
2619  struct ConfItem *conf;
2620  struct AccessItem *aconf;
2621  dlink_list * free_items [] = {
2622    &server_items, &oconf_items, NULL
2623  };
2624  dlink_list ** iterator = free_items; /* C is dumb */
2625
2626  /* flush out deleted I and P lines
2627   * although still in use.
2628   */
2629  for (; *iterator != NULL; iterator++)
2630  {
2631    DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head)
2632    {
2633      conf = ptr->data;
2634      aconf = (struct AccessItem *)map_to_conf(conf);
2635
2636      if (IsConfIllegal(aconf))
2637      {
2638        dlinkDelete(ptr, *iterator);
2639
2640        if (aconf->clients == 0)
2641          delete_conf_item(conf);
2642      }
2643    }
2644  }
2645 }
2646
2647 /* get_conf_name()
2648 *
2649 * inputs       - type of conf file to return name of file for
2650 * output       - pointer to filename for type of conf
2651 * side effects - none
2652 */
2653 const char *
2654 get_conf_name(ConfType type)
2655 {
2656  switch (type)
2657  {
2658    case CONF_TYPE:
2659      return ConfigFileEntry.configfile;
2660      break;
2661    case KLINE_TYPE:
2662      return ConfigFileEntry.klinefile;
2663      break;
2664    case RKLINE_TYPE:
2665      return ConfigFileEntry.rklinefile;
2666      break;
2667    case DLINE_TYPE:
2668      return ConfigFileEntry.dlinefile;
2669      break;
2670    case XLINE_TYPE:
2671      return ConfigFileEntry.xlinefile;
2672      break;
2673    case RXLINE_TYPE:
2674      return ConfigFileEntry.rxlinefile;
2675      break;
2676    case CRESV_TYPE:
2677      return ConfigFileEntry.cresvfile;
2678      break;
2679    case NRESV_TYPE:
2680      return ConfigFileEntry.nresvfile;
2681      break;
2682    case GLINE_TYPE:
2683      return ConfigFileEntry.glinefile;
2684      break;
2685
2686    default:
2687      return NULL;  /* This should NEVER HAPPEN since we call this function
2688                       only with the above values, this will cause us to core
2689                       at some point if this happens so we know where it was */
2690  }
2691 }
2692
2693 #define BAD_PING (-1)
2694
2695 /* get_conf_ping()
2696 *
2697 * inputs       - pointer to struct AccessItem
2698 *              - pointer to a variable that receives ping warning time
2699 * output       - ping frequency
2700 * side effects - NONE
2701 */
2702 static int
2703 get_conf_ping(struct ConfItem *conf, int *pingwarn)
2704 {
2705  struct ClassItem *aclass;
2706  struct AccessItem *aconf;
2707
2708  if (conf != NULL)
2709  {
2710    aconf = (struct AccessItem *)map_to_conf(conf);
2711    if (aconf->class_ptr != NULL)
2712    {
2713      aclass = (struct ClassItem *)map_to_conf(aconf->class_ptr);
2714      *pingwarn = aclass->ping_warning;
2715      return aclass->ping_freq;
2716    }
2717  }
2718
2719  return BAD_PING;
2720 }
2721
2722 /* get_client_class()
2723 *
2724 * inputs       - pointer to client struct
2725 * output       - pointer to name of class
2726 * side effects - NONE
2727 */
2728 const char *
2729 get_client_class(struct Client *target_p)
2730 {
2731  dlink_node *ptr;
2732  struct ConfItem *conf;
2733  struct AccessItem *aconf;
2734
2735  if (target_p != NULL && !IsMe(target_p) &&
2736      target_p->localClient->confs.head != NULL)
2737  {
2738    DLINK_FOREACH(ptr, target_p->localClient->confs.head)
2739    {
2740      conf = ptr->data;
2741
2742      if (conf->type == CLIENT_TYPE || conf->type == SERVER_TYPE ||
2743          conf->type == OPER_TYPE)
2744      {
2745        aconf = (struct AccessItem *) map_to_conf(conf);
2746        if (aconf->class_ptr != NULL)
2747          return aconf->class_ptr->name;
2748      }
2749    }
2750  }
2751
2752  return "default";
2753 }
2754
2755 /* get_client_ping()
2756 *
2757 * inputs       - pointer to client struct
2758 *              - pointer to a variable that receives ping warning time
2759 * output       - ping frequency
2760 * side effects - NONE
2761 */
2762 int
2763 get_client_ping(struct Client *target_p, int *pingwarn)
2764 {
2765  int ping;
2766  struct ConfItem *conf;
2767  dlink_node *nlink;
2768
2769  if (target_p->localClient->confs.head != NULL)
2770    DLINK_FOREACH(nlink, target_p->localClient->confs.head)
2771    {
2772      conf = nlink->data;
2773
2774      if ((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2775          (conf->type == OPER_TYPE))
2776      {
2777        ping = get_conf_ping(conf, pingwarn);
2778        if (ping > 0)
2779          return ping;
2780      }
2781    }
2782
2783  *pingwarn = 0;
2784  return DEFAULT_PINGFREQUENCY;
2785 }
2786
2787 /* find_class()
2788 *
2789 * inputs       - string name of class
2790 * output       - corresponding Class pointer
2791 * side effects - NONE
2792 */
2793 struct ConfItem *
2794 find_class(const char *classname)
2795 {
2796  struct ConfItem *conf;
2797
2798  if ((conf = find_exact_name_conf(CLASS_TYPE, NULL, classname, NULL, NULL)) != NULL)
2799    return conf;
2800
2801  return class_default;
2802 }
2803
2804 /* check_class()
2805 *
2806 * inputs       - NONE
2807 * output       - NONE
2808 * side effects -
2809 */
2810 void
2811 check_class(void)
2812 {
2813  dlink_node *ptr = NULL, *next_ptr = NULL;
2814
2815  DLINK_FOREACH_SAFE(ptr, next_ptr, class_items.head)
2816  {
2817    struct ClassItem *aclass = map_to_conf(ptr->data);
2818
2819    if (!aclass->active && !aclass->curr_user_count)
2820    {
2821      destroy_cidr_class(aclass);
2822      delete_conf_item(ptr->data);
2823    }
2824  }
2825 }
2826
2827 /* init_class()
2828 *
2829 * inputs       - NONE
2830 * output       - NONE
2831 * side effects -
2832 */
2833 void
2834 init_class(void)
2835 {
2836  struct ClassItem *aclass;
2837
2838  class_default = make_conf_item(CLASS_TYPE);
2839
2840  aclass = map_to_conf(class_default);
2841  aclass->active = 1;
2842  DupString(class_default->name, "default");
2843  aclass->con_freq  = DEFAULT_CONNECTFREQUENCY;
2844  aclass->ping_freq = DEFAULT_PINGFREQUENCY;
2845  aclass->max_total = MAXIMUM_LINKS_DEFAULT;
2846  aclass->max_sendq = DEFAULT_SENDQ;
2847
2848  client_check_cb = register_callback("check_client", check_client);
2849 }
2850
2851 /* get_sendq()
2852 *
2853 * inputs       - pointer to client
2854 * output       - sendq for this client as found from its class
2855 * side effects - NONE
2856 */
2857 unsigned int
2858 get_sendq(struct Client *client_p)
2859 {
2860  unsigned int sendq = DEFAULT_SENDQ;
2861  dlink_node *ptr;
2862  struct ConfItem *conf;
2863  struct ConfItem *class_conf;
2864  struct ClassItem *aclass;
2865  struct AccessItem *aconf;
2866
2867  if (client_p && !IsMe(client_p) && (client_p->localClient->confs.head))
2868  {
2869    DLINK_FOREACH(ptr, client_p->localClient->confs.head)
2870    {
2871      conf = ptr->data;
2872      if ((conf->type == SERVER_TYPE) || (conf->type == OPER_TYPE)
2873          || (conf->type == CLIENT_TYPE))
2874      {
2875        aconf = (struct AccessItem *)map_to_conf(conf);
2876        if ((class_conf = aconf->class_ptr) == NULL)
2877          continue;
2878        aclass = (struct ClassItem *)map_to_conf(class_conf);
2879        sendq = aclass->max_sendq;
2880        return sendq;
2881      }
2882    }
2883  }
2884  /* XXX return a default?
2885   * if here, then there wasn't an attached conf with a sendq
2886   * that is very bad -Dianora
2887   */
2888  return DEFAULT_SENDQ;
2889 }
2890
1916   /* conf_add_class_to_conf()
1917   *
1918   * inputs       - pointer to config item
# Line 2895 | Line 1920 | get_sendq(struct Client *client_p)
1920   * side effects - Add a class pointer to a conf
1921   */
1922   void
1923 < conf_add_class_to_conf(struct ConfItem *conf, const char *class_name)
1923 > conf_add_class_to_conf(struct MaskItem *conf, const char *class_name)
1924   {
2900  struct AccessItem *aconf = map_to_conf(conf);
2901  struct ClassItem *class = NULL;
2902
1925    if (class_name == NULL)
1926    {
1927 <    aconf->class_ptr = class_default;
1927 >    conf->class = class_default;
1928  
1929 <    if (conf->type == CLIENT_TYPE)
1930 <      sendto_realops_flags(UMODE_ALL, L_ALL,
1929 >    if (conf->type == CONF_CLIENT)
1930 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1931                             "Warning *** Defaulting to default class for %s@%s",
1932 <                           aconf->user, aconf->host);
1932 >                           conf->user, conf->host);
1933      else
1934 <      sendto_realops_flags(UMODE_ALL, L_ALL,
1934 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1935                             "Warning *** Defaulting to default class for %s",
1936                             conf->name);
1937    }
1938    else
1939 <    aconf->class_ptr = find_class(class_name);
2918 <
2919 <  if (aconf->class_ptr)
2920 <    class = map_to_conf(aconf->class_ptr);
1939 >    conf->class = class_find(class_name, 1);
1940  
1941 <  if (aconf->class_ptr == NULL || !class->active)
1941 >  if (conf->class == NULL)
1942    {
1943 <    if (conf->type == CLIENT_TYPE)
1944 <      sendto_realops_flags(UMODE_ALL, L_ALL,
1943 >    if (conf->type == CONF_CLIENT)
1944 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1945                             "Warning *** Defaulting to default class for %s@%s",
1946 <                           aconf->user, aconf->host);
1946 >                           conf->user, conf->host);
1947      else
1948 <      sendto_realops_flags(UMODE_ALL, L_ALL,
1948 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1949                             "Warning *** Defaulting to default class for %s",
1950                             conf->name);
1951 <    aconf->class_ptr = class_default;
2933 <  }
2934 < }
2935 <
2936 < /* conf_add_server()
2937 < *
2938 < * inputs       - pointer to config item
2939 < *              - pointer to link count already on this conf
2940 < * output       - NONE
2941 < * side effects - Add a connect block
2942 < */
2943 < int
2944 < conf_add_server(struct ConfItem *conf, const char *class_name)
2945 < {
2946 <  struct AccessItem *aconf = map_to_conf(conf);
2947 <
2948 <  conf_add_class_to_conf(conf, class_name);
2949 <
2950 <  if (!aconf->host || !conf->name)
2951 <  {
2952 <    sendto_realops_flags(UMODE_ALL, L_ALL, "Bad connect block");
2953 <    ilog(LOG_TYPE_IRCD, "Bad connect block");
2954 <    return -1;
2955 <  }
2956 <
2957 <  if (EmptyString(aconf->passwd))
2958 <  {
2959 <    sendto_realops_flags(UMODE_ALL, L_ALL, "Bad connect block, name %s",
2960 <                         conf->name);
2961 <    ilog(LOG_TYPE_IRCD, "Bad connect block, host %s", conf->name);
2962 <    return -1;
1951 >    conf->class = class_default;
1952    }
2964
2965  lookup_confhost(conf);
2966
2967  return 0;
1953   }
1954  
1955   /* yyerror()
# Line 2982 | Line 1967 | yyerror(const char *msg)
1967      return;
1968  
1969    strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1970 <  sendto_realops_flags(UMODE_ALL, L_ALL, "\"%s\", line %u: %s: %s",
1970 >  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1971 >                       "\"%s\", line %u: %s: %s",
1972 >                       conffilebuf, lineno + 1, msg, newlinebuf);
1973 >  ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1974 >       conffilebuf, lineno + 1, msg, newlinebuf);
1975 > }
1976 >
1977 > void
1978 > conf_error_report(const char *msg)
1979 > {
1980 >  char newlinebuf[IRCD_BUFSIZE];
1981 >
1982 >  strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1983 >  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1984 >                       "\"%s\", line %u: %s: %s",
1985                         conffilebuf, lineno + 1, msg, newlinebuf);
1986    ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1987         conffilebuf, lineno + 1, msg, newlinebuf);
# Line 3293 | Line 2292 | find_user_host(struct Client *source_p,
2292      
2293      return 1;
2294    }
2295 <  else if (!(flags & NOUSERLOOKUP))
2295 >  else
2296    {
2297      /* Try to find user@host mask from nick */
2298      /* Okay to use source_p as the first param, because source_p == client_p */
# Line 3341 | Line 2340 | find_user_host(struct Client *source_p,
2340   int
2341   valid_comment(struct Client *source_p, char *comment, int warn)
2342   {
3344  if (strchr(comment, '"'))
3345  {
3346    if (warn)
3347      sendto_one(source_p, ":%s NOTICE %s :Invalid character '\"' in comment",
3348                 me.name, source_p->name);
3349    return 0;
3350  }
3351
2343    if (strlen(comment) > REASONLEN)
2344      comment[REASONLEN-1] = '\0';
2345  
# Line 3363 | Line 2354 | valid_comment(struct Client *source_p, c
2354   * side effects - none
2355   */
2356   int
2357 < match_conf_password(const char *password, const struct AccessItem *aconf)
2357 > match_conf_password(const char *password, const struct MaskItem *conf)
2358   {
2359    const char *encr = NULL;
2360  
2361 <  if (password == NULL || aconf->passwd == NULL)
2361 >  if (EmptyString(password) || EmptyString(conf->passwd))
2362      return 0;
2363  
2364 <  if (aconf->flags & CONF_FLAGS_ENCRYPTED)
2365 <  {
3375 <    /* use first two chars of the password they send in as salt */
3376 <    /* If the password in the conf is MD5, and ircd is linked
3377 <     * to scrypt on FreeBSD, or the standard crypt library on
3378 <     * glibc Linux, then this code will work fine on generating
3379 <     * the proper encrypted hash for comparison.
3380 <     */
3381 <    if (*aconf->passwd)
3382 <      encr = crypt(password, aconf->passwd);
3383 <    else
3384 <      encr = "";
3385 <  }
2364 >  if (conf->flags & CONF_FLAGS_ENCRYPTED)
2365 >    encr = crypt(password, conf->passwd);
2366    else
2367      encr = password;
2368  
2369 <  return !strcmp(encr, aconf->passwd);
2369 >  return !strcmp(encr, conf->passwd);
2370   }
2371  
2372   /*
# Line 3415 | Line 2395 | cluster_a_line(struct Client *source_p,
2395  
2396    DLINK_FOREACH(ptr, cluster_items.head)
2397    {
2398 <    const struct ConfItem *conf = ptr->data;
2398 >    const struct MaskItem *conf = ptr->data;
2399  
2400      if (conf->flags & cluster_type)
2401        sendto_match_servs(source_p, conf->name, CAP_CLUSTER|capab,
# Line 3509 | Line 2489 | split_nuh(struct split_nuh_item *const i
2489      }
2490    }
2491   }
3512
3513 /*
3514 * flags_to_ascii
3515 *
3516 * inputs       - flags is a bitmask
3517 *              - pointer to table of ascii letters corresponding
3518 *                to each bit
3519 *              - flag 1 for convert ToLower if bit missing
3520 *                0 if ignore.
3521 * output       - none
3522 * side effects - string pointed to by p has bitmap chars written to it
3523 */
3524 static void
3525 flags_to_ascii(unsigned int flags, const unsigned int bit_table[], char *p,
3526               int lowerit)
3527 {
3528  unsigned int mask = 1;
3529  int i = 0;
3530
3531  for (mask = 1; (mask != 0) && (bit_table[i] != 0); mask <<= 1, i++)
3532  {
3533    if (flags & mask)
3534      *p++ = bit_table[i];
3535    else if (lowerit)
3536      *p++ = ToLower(bit_table[i]);
3537  }
3538  *p = '\0';
3539 }
3540
3541 /*
3542 * cidr_limit_reached
3543 *
3544 * inputs       - int flag allowing over_rule of limits
3545 *              - pointer to the ip to be added
3546 *              - pointer to the class
3547 * output       - non zero if limit reached
3548 *                0 if limit not reached
3549 * side effects -
3550 */
3551 static int
3552 cidr_limit_reached(int over_rule,
3553                   struct irc_ssaddr *ip, struct ClassItem *aclass)
3554 {
3555  dlink_node *ptr = NULL;
3556  struct CidrItem *cidr;
3557
3558  if (aclass->number_per_cidr <= 0)
3559    return 0;
3560
3561  if (ip->ss.ss_family == AF_INET)
3562  {
3563    if (aclass->cidr_bitlen_ipv4 <= 0)
3564      return 0;
3565
3566    DLINK_FOREACH(ptr, aclass->list_ipv4.head)
3567    {
3568      cidr = ptr->data;
3569      if (match_ipv4(ip, &cidr->mask, aclass->cidr_bitlen_ipv4))
3570      {
3571        if (!over_rule && (cidr->number_on_this_cidr >= aclass->number_per_cidr))
3572          return -1;
3573        cidr->number_on_this_cidr++;
3574        return 0;
3575      }
3576    }
3577    cidr = MyMalloc(sizeof(struct CidrItem));
3578    cidr->number_on_this_cidr = 1;
3579    cidr->mask = *ip;
3580    mask_addr(&cidr->mask, aclass->cidr_bitlen_ipv4);
3581    dlinkAdd(cidr, &cidr->node, &aclass->list_ipv4);
3582  }
3583 #ifdef IPV6
3584  else if (aclass->cidr_bitlen_ipv6 > 0)
3585  {
3586    DLINK_FOREACH(ptr, aclass->list_ipv6.head)
3587    {
3588      cidr = ptr->data;
3589      if (match_ipv6(ip, &cidr->mask, aclass->cidr_bitlen_ipv6))
3590      {
3591        if (!over_rule && (cidr->number_on_this_cidr >= aclass->number_per_cidr))
3592          return -1;
3593        cidr->number_on_this_cidr++;
3594        return 0;
3595      }
3596    }
3597    cidr = MyMalloc(sizeof(struct CidrItem));
3598    cidr->number_on_this_cidr = 1;
3599    cidr->mask = *ip;
3600    mask_addr(&cidr->mask, aclass->cidr_bitlen_ipv6);
3601    dlinkAdd(cidr, &cidr->node, &aclass->list_ipv6);
3602  }
3603 #endif
3604  return 0;
3605 }
3606
3607 /*
3608 * remove_from_cidr_check
3609 *
3610 * inputs       - pointer to the ip to be removed
3611 *              - pointer to the class
3612 * output       - NONE
3613 * side effects -
3614 */
3615 static void
3616 remove_from_cidr_check(struct irc_ssaddr *ip, struct ClassItem *aclass)
3617 {
3618  dlink_node *ptr = NULL;
3619  dlink_node *next_ptr = NULL;
3620  struct CidrItem *cidr;
3621
3622  if (aclass->number_per_cidr == 0)
3623    return;
3624
3625  if (ip->ss.ss_family == AF_INET)
3626  {
3627    if (aclass->cidr_bitlen_ipv4 <= 0)
3628      return;
3629
3630    DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv4.head)
3631    {
3632      cidr = ptr->data;
3633      if (match_ipv4(ip, &cidr->mask, aclass->cidr_bitlen_ipv4))
3634      {
3635        cidr->number_on_this_cidr--;
3636        if (cidr->number_on_this_cidr == 0)
3637        {
3638          dlinkDelete(ptr, &aclass->list_ipv4);
3639          MyFree(cidr);
3640          return;
3641        }
3642      }
3643    }
3644  }
3645 #ifdef IPV6
3646  else if (aclass->cidr_bitlen_ipv6 > 0)
3647  {
3648    DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv6.head)
3649    {
3650      cidr = ptr->data;
3651      if (match_ipv6(ip, &cidr->mask, aclass->cidr_bitlen_ipv6))
3652      {
3653        cidr->number_on_this_cidr--;
3654        if (cidr->number_on_this_cidr == 0)
3655        {
3656          dlinkDelete(ptr, &aclass->list_ipv6);
3657          MyFree(cidr);
3658          return;
3659        }
3660      }
3661    }
3662  }
3663 #endif
3664 }
3665
3666 static void
3667 rebuild_cidr_list(int aftype, struct ConfItem *oldcl, struct ClassItem *newcl,
3668                  dlink_list *old_list, dlink_list *new_list, int changed)
3669 {
3670  dlink_node *ptr;
3671  struct Client *client_p;
3672  struct ConfItem *conf;
3673  struct AccessItem *aconf;
3674
3675  if (!changed)
3676  {
3677    *new_list = *old_list;
3678    old_list->head = old_list->tail = NULL;
3679    old_list->length = 0;
3680    return;
3681  }
3682
3683  DLINK_FOREACH(ptr, local_client_list.head)
3684  {
3685    client_p = ptr->data;
3686    if (client_p->localClient->aftype != aftype)
3687      continue;
3688    if (dlink_list_length(&client_p->localClient->confs) == 0)
3689      continue;
3690
3691    conf = client_p->localClient->confs.tail->data;
3692    if (conf->type == CLIENT_TYPE)
3693    {
3694      aconf = map_to_conf(conf);
3695      if (aconf->class_ptr == oldcl)
3696        cidr_limit_reached(1, &client_p->localClient->ip, newcl);
3697    }
3698  }
3699 }
3700
3701 /*
3702 * rebuild_cidr_class
3703 *
3704 * inputs       - pointer to old conf
3705 *              - pointer to new_class
3706 * output       - none
3707 * side effects - rebuilds the class link list of cidr blocks
3708 */
3709 void
3710 rebuild_cidr_class(struct ConfItem *conf, struct ClassItem *new_class)
3711 {
3712  struct ClassItem *old_class = map_to_conf(conf);
3713
3714  if (old_class->number_per_cidr > 0 && new_class->number_per_cidr > 0)
3715  {
3716    if (old_class->cidr_bitlen_ipv4 > 0 && new_class->cidr_bitlen_ipv4 > 0)
3717      rebuild_cidr_list(AF_INET, conf, new_class,
3718                        &old_class->list_ipv4, &new_class->list_ipv4,
3719                        old_class->cidr_bitlen_ipv4 != new_class->cidr_bitlen_ipv4);
3720
3721 #ifdef IPV6
3722    if (old_class->cidr_bitlen_ipv6 > 0 && new_class->cidr_bitlen_ipv6 > 0)
3723      rebuild_cidr_list(AF_INET6, conf, new_class,
3724                        &old_class->list_ipv6, &new_class->list_ipv6,
3725                        old_class->cidr_bitlen_ipv6 != new_class->cidr_bitlen_ipv6);
3726 #endif
3727  }
3728
3729  destroy_cidr_class(old_class);
3730 }
3731
3732 /*
3733 * destroy_cidr_list
3734 *
3735 * inputs       - pointer to class dlink list of cidr blocks
3736 * output       - none
3737 * side effects - completely destroys the class link list of cidr blocks
3738 */
3739 static void
3740 destroy_cidr_list(dlink_list *list)
3741 {
3742  dlink_node *ptr = NULL, *next_ptr = NULL;
3743
3744  DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
3745  {
3746    dlinkDelete(ptr, list);
3747    MyFree(ptr->data);
3748  }
3749 }
3750
3751 /*
3752 * destroy_cidr_class
3753 *
3754 * inputs       - pointer to class
3755 * output       - none
3756 * side effects - completely destroys the class link list of cidr blocks
3757 */
3758 static void
3759 destroy_cidr_class(struct ClassItem *aclass)
3760 {
3761  destroy_cidr_list(&aclass->list_ipv4);
3762  destroy_cidr_list(&aclass->list_ipv6);
3763 }

Diff Legend

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