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 1368 by michael, Wed Apr 25 16:42:06 2012 UTC vs.
ircd-hybrid/trunk/src/conf.c (file contents), Revision 6367 by michael, Wed Aug 19 10:25:00 2015 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  conf.c: Configuration file functions.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-2015 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 16 | Line 15
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18 < *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file conf.c
23 > * \brief Configuration file functions.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
28   #include "list.h"
29   #include "ircd_defs.h"
28 #include "balloc.h"
30   #include "conf.h"
31 < #include "s_serv.h"
31 > #include "conf_pseudo.h"
32 > #include "server.h"
33   #include "resv.h"
34   #include "channel.h"
35   #include "client.h"
36   #include "event.h"
35 #include "hook.h"
37   #include "irc_string.h"
38   #include "s_bsd.h"
39   #include "ircd.h"
# Line 43 | Line 44
44   #include "fdlist.h"
45   #include "log.h"
46   #include "send.h"
46 #include "s_gline.h"
47   #include "memory.h"
48 < #include "irc_res.h"
48 > #include "res.h"
49   #include "userhost.h"
50 < #include "s_user.h"
50 > #include "user.h"
51   #include "channel_mode.h"
52   #include "parse.h"
53 < #include "s_misc.h"
53 > #include "misc.h"
54 > #include "conf_db.h"
55 > #include "conf_class.h"
56 > #include "motd.h"
57 > #include "ipcache.h"
58 > #include "isupport.h"
59  
60 < struct Callback *client_check_cb = NULL;
61 < struct config_server_hide ConfigServerHide;
60 >
61 > struct config_channel_entry ConfigChannel;
62 > struct config_serverhide_entry ConfigServerHide;
63 > struct config_general_entry ConfigGeneral;
64 > struct config_log_entry ConfigLog = { .use_logging = 1 };
65 > struct config_serverinfo_entry ConfigServerInfo;
66 > struct config_admin_entry ConfigAdminInfo;
67 > struct conf_parser_context conf_parser_ctx;
68  
69   /* general conf items link list root, other than k lines etc. */
70 < dlink_list service_items = { NULL, NULL, 0 };
71 < dlink_list server_items  = { NULL, NULL, 0 };
72 < dlink_list cluster_items = { NULL, NULL, 0 };
73 < dlink_list hub_items     = { NULL, NULL, 0 };
74 < dlink_list leaf_items    = { NULL, NULL, 0 };
75 < dlink_list oconf_items   = { NULL, NULL, 0 };
76 < dlink_list uconf_items   = { NULL, NULL, 0 };
77 < dlink_list xconf_items   = { NULL, NULL, 0 };
67 < dlink_list rxconf_items  = { NULL, NULL, 0 };
68 < dlink_list rkconf_items  = { NULL, NULL, 0 };
69 < 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_klines  = { NULL, NULL, 0 };
74 < dlink_list temporary_dlines  = { NULL, NULL, 0 };
75 < dlink_list temporary_xlines  = { NULL, NULL, 0 };
76 < dlink_list temporary_glines  = { NULL, NULL, 0 };
77 < dlink_list temporary_resv = { NULL, NULL, 0 };
70 > dlink_list service_items;
71 > dlink_list server_items;
72 > dlink_list cluster_items;
73 > dlink_list oconf_items;
74 > dlink_list uconf_items;
75 > dlink_list xconf_items;
76 > dlink_list nresv_items;
77 > dlink_list cresv_items;
78  
79   extern unsigned int lineno;
80   extern char linebuf[];
81   extern char conffilebuf[IRCD_BUFSIZE];
82   extern int yyparse(); /* defined in y.tab.c */
83  
84 struct conf_parser_context conf_parser_ctx = { 0, 0, NULL };
85
86 /* internally defined functions */
87 static void read_conf(FILE *);
88 static void clear_out_old_conf(void);
89 static void flush_deleted_I_P(void);
90 static void expire_tklines(dlink_list *);
91 static void garbage_collect_ip_entries(void);
92 static int hash_ip(struct irc_ssaddr *);
93 static int verify_access(struct Client *, const char *);
94 static int attach_iline(struct Client *, struct ConfItem *);
95 static struct ip_entry *find_or_add_ip(struct irc_ssaddr *);
96 static void parse_conf_file(int, int);
97 static dlink_list *map_to_list(ConfType);
98 static struct AccessItem *find_regexp_kline(const char *[]);
99 static int find_user_host(struct Client *, char *, char *, char *, unsigned int);
100
101 /*
102 * bit_len
103 */
104 static int cidr_limit_reached(int, struct irc_ssaddr *, struct ClassItem *);
105 static void remove_from_cidr_check(struct irc_ssaddr *, struct ClassItem *);
106 static void destroy_cidr_class(struct ClassItem *);
107
108 static void flags_to_ascii(unsigned int, const unsigned int[], char *, int);
109
110 /* address of default class conf */
111 static struct ConfItem *class_default;
112
113 /* usually, with hash tables, you use a prime number...
114 * but in this case I am dealing with ip addresses,
115 * not ascii strings.
116 */
117 #define IP_HASH_SIZE 0x1000
118
119 struct ip_entry
120 {
121  struct irc_ssaddr ip;
122  int count;
123  time_t last_attempt;
124  struct ip_entry *next;
125 };
126
127 static struct ip_entry *ip_hash_table[IP_HASH_SIZE];
128 static BlockHeap *ip_entry_heap = NULL;
129 static int ip_entries_count = 0;
130
131
132 void *
133 map_to_conf(struct ConfItem *aconf)
134 {
135  void *conf;
136  conf = (void *)((uintptr_t)aconf +
137                  (uintptr_t)sizeof(struct ConfItem));
138  return(conf);
139 }
140
141 struct ConfItem *
142 unmap_conf_item(void *aconf)
143 {
144  struct ConfItem *conf;
145
146  conf = (struct ConfItem *)((uintptr_t)aconf -
147                             (uintptr_t)sizeof(struct ConfItem));
148  return(conf);
149 }
84  
85   /* conf_dns_callback()
86   *
87 < * inputs       - pointer to struct AccessItem
87 > * inputs       - pointer to struct MaskItem
88   *              - pointer to DNSReply reply
89   * output       - none
90   * side effects - called when resolver query finishes
# Line 159 | Line 93 | unmap_conf_item(void *aconf)
93   * if successful save hp in the conf item it was called with
94   */
95   static void
96 < conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name)
96 > conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name, size_t namelength)
97   {
98 <  struct AccessItem *aconf = vptr;
98 >  struct MaskItem *const conf = vptr;
99  
100 <  aconf->dns_pending = 0;
100 >  conf->dns_pending = 0;
101  
102 <  if (addr != NULL)
103 <    memcpy(&aconf->ipnum, addr, sizeof(aconf->ipnum));
102 >  if (addr)
103 >    memcpy(&conf->addr, addr, sizeof(conf->addr));
104    else
105 <    aconf->dns_failed = 1;
105 >    conf->dns_failed = 1;
106   }
107  
108   /* conf_dns_lookup()
# Line 178 | Line 112 | conf_dns_callback(void *vptr, const stru
112   * allocate a dns_query and start ns lookup.
113   */
114   static void
115 < conf_dns_lookup(struct AccessItem *aconf)
115 > conf_dns_lookup(struct MaskItem *conf)
116   {
117 <  if (!aconf->dns_pending)
118 <  {
119 <    aconf->dns_pending = 1;
120 <    gethost_byname(conf_dns_callback, aconf, aconf->host);
121 <  }
117 >  if (conf->dns_pending)
118 >    return;
119 >
120 >  conf->dns_pending = 1;
121 >
122 >  if (conf->aftype == AF_INET)
123 >    gethost_byname_type(conf_dns_callback, conf, conf->host, T_A);
124 >  else
125 >    gethost_byname_type(conf_dns_callback, conf, conf->host, T_AAAA);
126   }
127  
128 < /* make_conf_item()
128 > /* map_to_list()
129   *
130 < * inputs       - type of item
131 < * output       - pointer to new conf entry
132 < * side effects - none
130 > * inputs       - ConfType conf
131 > * output       - pointer to dlink_list to use
132 > * side effects - none
133   */
134 < struct ConfItem *
135 < make_conf_item(ConfType type)
134 > static dlink_list *
135 > map_to_list(enum maskitem_type type)
136   {
199  struct ConfItem *conf = NULL;
200  struct AccessItem *aconf = NULL;
201  struct ClassItem *aclass = NULL;
202  int status = 0;
203
137    switch (type)
138    {
139 <  case DLINE_TYPE:
140 <  case EXEMPTDLINE_TYPE:
208 <  case GLINE_TYPE:
209 <  case KLINE_TYPE:
210 <  case CLIENT_TYPE:
211 <  case OPER_TYPE:
212 <  case SERVER_TYPE:
213 <    conf = MyMalloc(sizeof(struct ConfItem) +
214 <                    sizeof(struct AccessItem));
215 <    aconf = map_to_conf(conf);
216 <    aconf->aftype = AF_INET;
217 <
218 <    /* Yes, sigh. switch on type again */
219 <    switch (type)
220 <    {
221 <    case EXEMPTDLINE_TYPE:
222 <      status = CONF_EXEMPTDLINE;
139 >    case CONF_XLINE:
140 >      return &xconf_items;
141        break;
142 <
143 <    case DLINE_TYPE:
226 <      status = CONF_DLINE;
142 >    case CONF_ULINE:
143 >      return &uconf_items;
144        break;
145 <
146 <    case KLINE_TYPE:
230 <      status = CONF_KLINE;
231 <      break;
232 <
233 <    case GLINE_TYPE:
234 <      status = CONF_GLINE;
235 <      break;
236 <
237 <    case CLIENT_TYPE:
238 <      status = CONF_CLIENT;
145 >    case CONF_NRESV:
146 >      return &nresv_items;
147        break;
148 <
149 <    case OPER_TYPE:
242 <      status = CONF_OPERATOR;
243 <      dlinkAdd(conf, &conf->node, &oconf_items);
244 <      break;
245 <
246 <    case SERVER_TYPE:
247 <      status = CONF_SERVER;
248 <      dlinkAdd(conf, &conf->node, &server_items);
148 >    case CONF_CRESV:
149 >      return &cresv_items;
150        break;
151 <
152 <    default:
151 >    case CONF_OPER:
152 >      return &oconf_items;
153        break;
154 <    }
155 <    aconf->status = status;
255 <    break;
256 <
257 <  case LEAF_TYPE:
258 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
259 <                                       sizeof(struct MatchItem));
260 <    dlinkAdd(conf, &conf->node, &leaf_items);
261 <    break;
262 <
263 <  case HUB_TYPE:
264 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
265 <                                       sizeof(struct MatchItem));
266 <    dlinkAdd(conf, &conf->node, &hub_items);
267 <    break;
268 <
269 <  case ULINE_TYPE:
270 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
271 <                                       sizeof(struct MatchItem));
272 <    dlinkAdd(conf, &conf->node, &uconf_items);
273 <    break;
274 <
275 <  case GDENY_TYPE:
276 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
277 <                                       sizeof(struct AccessItem));
278 <    dlinkAdd(conf, &conf->node, &gdeny_items);
279 <    break;
280 <
281 <  case XLINE_TYPE:
282 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
283 <                                       sizeof(struct MatchItem));
284 <    dlinkAdd(conf, &conf->node, &xconf_items);
285 <    break;
286 < #ifdef HAVE_LIBPCRE
287 <  case RXLINE_TYPE:
288 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
289 <                                       sizeof(struct MatchItem));
290 <    dlinkAdd(conf, &conf->node, &rxconf_items);
291 <    break;
292 <
293 <  case RKLINE_TYPE:
294 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
295 <                                       sizeof(struct AccessItem));
296 <    aconf = map_to_conf(conf);
297 <    aconf->status = CONF_KLINE;
298 <    dlinkAdd(conf, &conf->node, &rkconf_items);
299 <    break;
300 < #endif
301 <  case CLUSTER_TYPE:
302 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem));
303 <    dlinkAdd(conf, &conf->node, &cluster_items);
304 <    break;
305 <
306 <  case CRESV_TYPE:
307 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
308 <                                       sizeof(struct ResvChannel));
309 <    break;
310 <
311 <  case NRESV_TYPE:
312 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
313 <                                       sizeof(struct MatchItem));
314 <    dlinkAdd(conf, &conf->node, &nresv_items);
315 <    break;
316 <
317 <  case SERVICE_TYPE:
318 <    status = CONF_SERVICE;
319 <    conf = MyMalloc(sizeof(struct ConfItem));
320 <    dlinkAdd(conf, &conf->node, &service_items);
321 <    break;
322 <
323 <  case CLASS_TYPE:
324 <    conf = MyMalloc(sizeof(struct ConfItem) +
325 <                           sizeof(struct ClassItem));
326 <    dlinkAdd(conf, &conf->node, &class_items);
327 <
328 <    aclass = map_to_conf(conf);
329 <    aclass->active = 1;
330 <    ConFreq(aclass) = DEFAULT_CONNECTFREQUENCY;
331 <    PingFreq(aclass) = DEFAULT_PINGFREQUENCY;
332 <    MaxTotal(aclass) = MAXIMUM_LINKS_DEFAULT;
333 <    MaxSendq(aclass) = DEFAULT_SENDQ;
334 <
335 <    break;
336 <
337 <  default:
338 <    conf = NULL;
339 <    break;
340 <  }
341 <
342 <  /* XXX Yes, this will core if default is hit. I want it to for now - db */
343 <  conf->type = type;
344 <
345 <  return conf;
346 < }
347 <
348 < void
349 < delete_conf_item(struct ConfItem *conf)
350 < {
351 <  dlink_node *m = NULL;
352 <  struct MatchItem *match_item;
353 <  struct AccessItem *aconf;
354 <  ConfType type = conf->type;
355 <
356 <  MyFree(conf->name);
357 <  conf->name = NULL;
358 <
359 <  switch(type)
360 <  {
361 <  case DLINE_TYPE:
362 <  case EXEMPTDLINE_TYPE:
363 <  case GLINE_TYPE:
364 <  case KLINE_TYPE:
365 <  case CLIENT_TYPE:
366 <  case OPER_TYPE:
367 <  case SERVER_TYPE:
368 <    aconf = map_to_conf(conf);
369 <
370 <    if (aconf->dns_pending)
371 <      delete_resolver_queries(aconf);
372 <    if (aconf->passwd != NULL)
373 <      memset(aconf->passwd, 0, strlen(aconf->passwd));
374 <    if (aconf->spasswd != NULL)
375 <      memset(aconf->spasswd, 0, strlen(aconf->spasswd));
376 <    aconf->class_ptr = NULL;
377 <
378 <    MyFree(aconf->passwd);
379 <    MyFree(aconf->spasswd);
380 <    MyFree(aconf->reason);
381 <    MyFree(aconf->oper_reason);
382 <    MyFree(aconf->user);
383 <    MyFree(aconf->host);
384 <    MyFree(aconf->cipher_list);
385 < #ifdef HAVE_LIBCRYPTO
386 <    if (aconf->rsa_public_key)
387 <      RSA_free(aconf->rsa_public_key);
388 <    MyFree(aconf->rsa_public_key_file);
389 < #endif
390 <
391 <    /* Yes, sigh. switch on type again */
392 <    switch(type)
393 <    {
394 <    case EXEMPTDLINE_TYPE:
395 <    case DLINE_TYPE:
396 <    case GLINE_TYPE:
397 <    case KLINE_TYPE:
398 <    case CLIENT_TYPE:
399 <      MyFree(conf);
154 >    case CONF_SERVER:
155 >      return &server_items;
156        break;
157 <
158 <    case OPER_TYPE:
403 <      aconf = map_to_conf(conf);
404 <      if (!IsConfIllegal(aconf))
405 <        dlinkDelete(&conf->node, &oconf_items);
406 <      MyFree(conf);
157 >    case CONF_SERVICE:
158 >      return &service_items;
159        break;
160 <
161 <    case SERVER_TYPE:
410 <      aconf = map_to_conf(conf);
411 <      if (!IsConfIllegal(aconf))
412 <        dlinkDelete(&conf->node, &server_items);
413 <      MyFree(conf);
160 >    case CONF_CLUSTER:
161 >      return &cluster_items;
162        break;
415
163      default:
164 <      break;
418 <    }
419 <    break;
420 <
421 <  case HUB_TYPE:
422 <    match_item = map_to_conf(conf);
423 <    MyFree(match_item->user);
424 <    MyFree(match_item->host);
425 <    MyFree(match_item->reason);
426 <    MyFree(match_item->oper_reason);
427 <    /* If marked illegal, its already been pulled off of the hub_items list */
428 <    if (!match_item->illegal)
429 <      dlinkDelete(&conf->node, &hub_items);
430 <    MyFree(conf);
431 <    break;
432 <
433 <  case LEAF_TYPE:
434 <    match_item = map_to_conf(conf);
435 <    MyFree(match_item->user);
436 <    MyFree(match_item->host);
437 <    MyFree(match_item->reason);
438 <    MyFree(match_item->oper_reason);
439 <    /* If marked illegal, its already been pulled off of the leaf_items list */
440 <    if (!match_item->illegal)
441 <      dlinkDelete(&conf->node, &leaf_items);
442 <    MyFree(conf);
443 <    break;
444 <
445 <  case ULINE_TYPE:
446 <    match_item = map_to_conf(conf);
447 <    MyFree(match_item->user);
448 <    MyFree(match_item->host);
449 <    MyFree(match_item->reason);
450 <    MyFree(match_item->oper_reason);
451 <    dlinkDelete(&conf->node, &uconf_items);
452 <    MyFree(conf);
453 <    break;
454 <
455 <  case XLINE_TYPE:
456 <    match_item = map_to_conf(conf);
457 <    MyFree(match_item->user);
458 <    MyFree(match_item->host);
459 <    MyFree(match_item->reason);
460 <    MyFree(match_item->oper_reason);
461 <    dlinkDelete(&conf->node, &xconf_items);
462 <    MyFree(conf);
463 <    break;
464 < #ifdef HAVE_LIBPCRE
465 <  case RKLINE_TYPE:
466 <    aconf = map_to_conf(conf);
467 <    MyFree(aconf->regexuser);
468 <    MyFree(aconf->regexhost);
469 <    MyFree(aconf->user);
470 <    MyFree(aconf->host);
471 <    MyFree(aconf->reason);
472 <    MyFree(aconf->oper_reason);
473 <    dlinkDelete(&conf->node, &rkconf_items);
474 <    MyFree(conf);
475 <    break;
476 <
477 <  case RXLINE_TYPE:
478 <    MyFree(conf->regexpname);
479 <    match_item = map_to_conf(conf);
480 <    MyFree(match_item->user);
481 <    MyFree(match_item->host);
482 <    MyFree(match_item->reason);
483 <    MyFree(match_item->oper_reason);
484 <    dlinkDelete(&conf->node, &rxconf_items);
485 <    MyFree(conf);
486 <    break;
487 < #endif
488 <  case NRESV_TYPE:
489 <    match_item = map_to_conf(conf);
490 <    MyFree(match_item->user);
491 <    MyFree(match_item->host);
492 <    MyFree(match_item->reason);
493 <    MyFree(match_item->oper_reason);
494 <    dlinkDelete(&conf->node, &nresv_items);
495 <
496 <    if (conf->flags & CONF_FLAGS_TEMPORARY)
497 <      if ((m = dlinkFindDelete(&temporary_resv, conf)) != NULL)
498 <        free_dlink_node(m);
499 <
500 <    MyFree(conf);
501 <    break;
502 <
503 <  case GDENY_TYPE:
504 <    aconf = map_to_conf(conf);
505 <    MyFree(aconf->user);
506 <    MyFree(aconf->host);
507 <    dlinkDelete(&conf->node, &gdeny_items);
508 <    MyFree(conf);
509 <    break;
510 <
511 <  case CLUSTER_TYPE:
512 <    dlinkDelete(&conf->node, &cluster_items);
513 <    MyFree(conf);
514 <    break;
515 <
516 <  case CRESV_TYPE:
517 <    if (conf->flags & CONF_FLAGS_TEMPORARY)
518 <      if ((m = dlinkFindDelete(&temporary_resv, conf)) != NULL)
519 <        free_dlink_node(m);
520 <
521 <    MyFree(conf);
522 <    break;
523 <
524 <  case CLASS_TYPE:
525 <    dlinkDelete(&conf->node, &class_items);
526 <    MyFree(conf);
527 <    break;
528 <
529 <  case SERVICE_TYPE:
530 <    dlinkDelete(&conf->node, &service_items);
531 <    MyFree(conf);
532 <    break;
533 <
534 <  default:
535 <    break;
164 >      return NULL;
165    }
166   }
167  
168 < /* free_access_item()
169 < *
541 < * inputs       - pointer to conf to free
542 < * output       - none
543 < * side effects - crucial password fields are zeroed, conf is freed
544 < */
545 < void
546 < free_access_item(struct AccessItem *aconf)
168 > struct MaskItem *
169 > conf_make(enum maskitem_type type)
170   {
171 <  struct ConfItem *conf;
171 >  struct MaskItem *const conf = MyCalloc(sizeof(*conf));
172 >  dlink_list *list = NULL;
173  
174 <  if (aconf == NULL)
175 <    return;
176 <  conf = unmap_conf_item(aconf);
553 <  delete_conf_item(conf);
554 < }
174 >  conf->type   = type;
175 >  conf->active = 1;
176 >  conf->aftype = AF_INET;
177  
178 < static const unsigned int shared_bit_table[] =
179 <  { 'K', 'k', 'U', 'X', 'x', 'Y', 'Q', 'q', 'R', 'L', 0};
178 >  if ((list = map_to_list(type)))
179 >    dlinkAdd(conf, &conf->node, list);
180 >  return conf;
181 > }
182  
559 /* report_confitem_types()
560 *
561 * inputs       - pointer to client requesting confitem report
562 *              - ConfType to report
563 * output       - none
564 * side effects -
565 */
183   void
184 < report_confitem_types(struct Client *source_p, ConfType type)
184 > conf_free(struct MaskItem *conf)
185   {
186 <  dlink_node *ptr = NULL;
187 <  struct ConfItem *conf = NULL;
571 <  struct AccessItem *aconf = NULL;
572 <  struct MatchItem *matchitem = NULL;
573 <  struct ClassItem *classitem = NULL;
574 <  char buf[12];
575 <  char *p = NULL;
576 <
577 <  switch (type)
578 <  {
579 <  case GDENY_TYPE:
580 <    DLINK_FOREACH(ptr, gdeny_items.head)
581 <    {
582 <      conf = ptr->data;
583 <      aconf = map_to_conf(conf);
584 <
585 <      p = buf;
586 <
587 <      if (aconf->flags & GDENY_BLOCK)
588 <        *p++ = 'B';
589 <      else
590 <        *p++ = 'b';
591 <
592 <      if (aconf->flags & GDENY_REJECT)
593 <        *p++ = 'R';
594 <      else
595 <        *p++ = 'r';
596 <
597 <      *p = '\0';
598 <
599 <      sendto_one(source_p, ":%s %d %s V %s@%s %s %s",
600 <                 me.name, RPL_STATSDEBUG, source_p->name,
601 <                 aconf->user, aconf->host, conf->name, buf);
602 <    }
603 <    break;
186 >  dlink_node *node = NULL, *node_next = NULL;
187 >  dlink_list *list = NULL;
188  
189 <  case XLINE_TYPE:
190 <    DLINK_FOREACH(ptr, xconf_items.head)
607 <    {
608 <      conf = ptr->data;
609 <      matchitem = map_to_conf(conf);
610 <
611 <      sendto_one(source_p, form_str(RPL_STATSXLINE),
612 <                 me.name, source_p->name,
613 <                 matchitem->hold ? "x": "X", matchitem->count,
614 <                 conf->name, matchitem->reason);
615 <    }
616 <    break;
189 >  if ((list = map_to_list(conf->type)))
190 >    dlinkFindDelete(list, conf);
191  
192 < #ifdef HAVE_LIBPCRE
619 <  case RXLINE_TYPE:
620 <    DLINK_FOREACH(ptr, rxconf_items.head)
621 <    {
622 <      conf = ptr->data;
623 <      matchitem = map_to_conf(conf);
624 <
625 <      sendto_one(source_p, form_str(RPL_STATSXLINE),
626 <                 me.name, source_p->name,
627 <                 "XR", matchitem->count,
628 <                 conf->name, matchitem->reason);
629 <    }
630 <    break;
192 >  MyFree(conf->name);
193  
194 <  case RKLINE_TYPE:
195 <    DLINK_FOREACH(ptr, rkconf_items.head)
196 <    {
197 <      aconf = map_to_conf((conf = ptr->data));
194 >  if (conf->dns_pending)
195 >    delete_resolver_queries(conf);
196 >  if (conf->passwd)
197 >    memset(conf->passwd, 0, strlen(conf->passwd));
198 >  if (conf->spasswd)
199 >    memset(conf->spasswd, 0, strlen(conf->spasswd));
200 >
201 >  conf->class = NULL;
202 >
203 >  MyFree(conf->passwd);
204 >  MyFree(conf->spasswd);
205 >  MyFree(conf->reason);
206 >  MyFree(conf->certfp);
207 >  MyFree(conf->whois);
208 >  MyFree(conf->user);
209 >  MyFree(conf->host);
210 > #ifdef HAVE_LIBCRYPTO
211 >  MyFree(conf->cipher_list);
212  
213 <      sendto_one(source_p, form_str(RPL_STATSKLINE), me.name,
214 <                 source_p->name, "KR", aconf->host, aconf->user,
639 <                 aconf->reason, aconf->oper_reason ? aconf->oper_reason : "");
640 <    }
641 <    break;
213 >  if (conf->rsa_public_key)
214 >    RSA_free(conf->rsa_public_key);
215   #endif
216 <
644 <  case ULINE_TYPE:
645 <    DLINK_FOREACH(ptr, uconf_items.head)
646 <    {
647 <      conf = ptr->data;
648 <      matchitem = map_to_conf(conf);
649 <
650 <      p = buf;
651 <
652 <      /* some of these are redundant for the sake of
653 <       * consistency with cluster{} flags
654 <       */
655 <      *p++ = 'c';
656 <      flags_to_ascii(matchitem->action, shared_bit_table, p, 0);
657 <
658 <      sendto_one(source_p, form_str(RPL_STATSULINE),
659 <                 me.name, source_p->name, conf->name,
660 <                 matchitem->user?matchitem->user: "*",
661 <                 matchitem->host?matchitem->host: "*", buf);
662 <    }
663 <
664 <    DLINK_FOREACH(ptr, cluster_items.head)
665 <    {
666 <      conf = ptr->data;
667 <
668 <      p = buf;
669 <
670 <      *p++ = 'C';
671 <      flags_to_ascii(conf->flags, shared_bit_table, p, 0);
672 <
673 <      sendto_one(source_p, form_str(RPL_STATSULINE),
674 <                 me.name, source_p->name, conf->name,
675 <                 "*", "*", buf);
676 <    }
677 <
678 <    break;
679 <
680 <  case OPER_TYPE:
681 <    DLINK_FOREACH(ptr, oconf_items.head)
682 <    {
683 <      conf = ptr->data;
684 <      aconf = map_to_conf(conf);
685 <
686 <      /* Don't allow non opers to see oper privs */
687 <      if (HasUMode(source_p, UMODE_OPER))
688 <        sendto_one(source_p, form_str(RPL_STATSOLINE),
689 <                   me.name, source_p->name, 'O', aconf->user, aconf->host,
690 <                   conf->name, oper_privs_as_string(aconf->port),
691 <                   aconf->class_ptr ? aconf->class_ptr->name : "<default>");
692 <      else
693 <        sendto_one(source_p, form_str(RPL_STATSOLINE),
694 <                   me.name, source_p->name, 'O', aconf->user, aconf->host,
695 <                   conf->name, "0",
696 <                   aconf->class_ptr ? aconf->class_ptr->name : "<default>");
697 <    }
698 <    break;
699 <
700 <  case CLASS_TYPE:
701 <    DLINK_FOREACH(ptr, class_items.head)
702 <    {
703 <      conf = ptr->data;
704 <      classitem = map_to_conf(conf);
705 <      sendto_one(source_p, form_str(RPL_STATSYLINE),
706 <                 me.name, source_p->name, 'Y',
707 <                 conf->name, PingFreq(classitem),
708 <                 ConFreq(classitem),
709 <                 MaxTotal(classitem), MaxSendq(classitem),
710 <                 CurrUserCount(classitem),
711 <                 classitem->active ? "active" : "disabled");
712 <    }
713 <    break;
714 <
715 <  case CONF_TYPE:
716 <  case CLIENT_TYPE:
717 <    break;
718 <
719 <  case SERVICE_TYPE:
720 <    DLINK_FOREACH(ptr, service_items.head)
721 <    {
722 <      conf = ptr->data;
723 <      sendto_one(source_p, form_str(RPL_STATSSERVICE),
724 <                 me.name, source_p->name, 'S', "*", conf->name, 0, 0);
725 <    }
726 <    break;
727 <
728 <  case SERVER_TYPE:
729 <    DLINK_FOREACH(ptr, server_items.head)
730 <    {
731 <      p = buf;
732 <
733 <      conf = ptr->data;
734 <      aconf = map_to_conf(conf);
735 <
736 <      buf[0] = '\0';
737 <
738 <      if (IsConfAllowAutoConn(aconf))
739 <        *p++ = 'A';
740 <      if (IsConfSSL(aconf))
741 <        *p++ = 'S';
742 <      if (IsConfTopicBurst(aconf))
743 <        *p++ = 'T';
744 <      if (buf[0] == '\0')
745 <        *p++ = '*';
746 <
747 <      *p = '\0';
748 <
749 <      /*
750 <       * Allow admins to see actual ips unless hide_server_ips is enabled
751 <       */
752 <      if (!ConfigServerHide.hide_server_ips && HasUMode(source_p, UMODE_ADMIN))
753 <        sendto_one(source_p, form_str(RPL_STATSCLINE),
754 <                   me.name, source_p->name, 'C', aconf->host,
755 <                   buf, conf->name, aconf->port,
756 <                   aconf->class_ptr ? aconf->class_ptr->name : "<default>");
757 <        else
758 <          sendto_one(source_p, form_str(RPL_STATSCLINE),
759 <                     me.name, source_p->name, 'C',
760 <                     "*@127.0.0.1", buf, conf->name, aconf->port,
761 <                     aconf->class_ptr ? aconf->class_ptr->name : "<default>");
762 <    }
763 <    break;
764 <
765 <  case HUB_TYPE:
766 <    DLINK_FOREACH(ptr, hub_items.head)
767 <    {
768 <      conf = ptr->data;
769 <      matchitem = map_to_conf(conf);
770 <      sendto_one(source_p, form_str(RPL_STATSHLINE), me.name,
771 <                 source_p->name, 'H', matchitem->host, conf->name, 0, "*");
772 <    }
773 <    break;
774 <
775 <  case LEAF_TYPE:
776 <    DLINK_FOREACH(ptr, leaf_items.head)
777 <    {
778 <      conf = ptr->data;
779 <      matchitem = map_to_conf(conf);
780 <      sendto_one(source_p, form_str(RPL_STATSLLINE), me.name,
781 <                 source_p->name, 'L', matchitem->host, conf->name, 0, "*");
782 <    }
783 <    break;
784 <
785 <  case GLINE_TYPE:
786 <  case KLINE_TYPE:
787 <  case DLINE_TYPE:
788 <  case EXEMPTDLINE_TYPE:
789 <  case CRESV_TYPE:
790 <  case NRESV_TYPE:
791 <  case CLUSTER_TYPE:
792 <  default:
793 <    break;
794 <  }
795 < }
796 <
797 < /* check_client()
798 < *
799 < * inputs       - pointer to client
800 < * output       - 0 = Success
801 < *                NOT_AUTHORIZED    (-1) = Access denied (no I line match)
802 < *                IRCD_SOCKET_ERROR (-2) = Bad socket.
803 < *                I_LINE_FULL       (-3) = I-line is full
804 < *                TOO_MANY          (-4) = Too many connections from hostname
805 < *                BANNED_CLIENT     (-5) = K-lined
806 < * side effects - Ordinary client access check.
807 < *                Look for conf lines which have the same
808 < *                status as the flags passed.
809 < */
810 < static void *
811 < check_client(va_list args)
812 < {
813 <  struct Client *source_p = va_arg(args, struct Client *);
814 <  const char *username = va_arg(args, const char *);
815 <  int i;
816 <
817 <  /* I'm already in big trouble if source_p->localClient is NULL -db */
818 <  if ((i = verify_access(source_p, username)))
819 <    ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
820 <         source_p->name, source_p->sockhost);
821 <
822 <  switch (i)
216 >  DLINK_FOREACH_SAFE(node, node_next, conf->hub_list.head)
217    {
218 <    case TOO_MANY:
219 <      sendto_realops_flags(UMODE_FULL, L_ALL,
220 <                           "Too many on IP for %s (%s).",
827 <                           get_client_name(source_p, SHOW_IP),
828 <                           source_p->sockhost);
829 <      ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
830 <           get_client_name(source_p, SHOW_IP));
831 <      ++ServerStats.is_ref;
832 <      exit_client(source_p, &me, "No more connections allowed on that IP");
833 <      break;
834 <
835 <    case I_LINE_FULL:
836 <      sendto_realops_flags(UMODE_FULL, L_ALL,
837 <                           "I-line is full for %s (%s).",
838 <                           get_client_name(source_p, SHOW_IP),
839 <                           source_p->sockhost);
840 <      ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
841 <           get_client_name(source_p, SHOW_IP));
842 <      ++ServerStats.is_ref;
843 <      exit_client(source_p, &me,
844 <                "No more connections allowed in your connection class");
845 <      break;
846 <
847 <    case NOT_AUTHORIZED:
848 <      ++ServerStats.is_ref;
849 <      /* jdc - lists server name & port connections are on */
850 <      /*       a purely cosmetical change */
851 <      sendto_realops_flags(UMODE_UNAUTH, L_ALL,
852 <                           "Unauthorized client connection from %s [%s] on [%s/%u].",
853 <                           get_client_name(source_p, SHOW_IP),
854 <                           source_p->sockhost,
855 <                           source_p->localClient->listener->name,
856 <                           source_p->localClient->listener->port);
857 <      ilog(LOG_TYPE_IRCD,
858 <          "Unauthorized client connection from %s on [%s/%u].",
859 <          get_client_name(source_p, SHOW_IP),
860 <          source_p->localClient->listener->name,
861 <          source_p->localClient->listener->port);
862 <
863 <      /* XXX It is prolematical whether it is better to use the
864 <       * capture reject code here or rely on the connecting too fast code.
865 <       * - Dianora
866 <       */
867 <      if (REJECT_HOLD_TIME > 0)
868 <      {
869 <        sendto_one(source_p, ":%s NOTICE %s :You are not authorized to use this server",
870 <                   me.name, source_p->name);
871 <        source_p->localClient->reject_delay = CurrentTime + REJECT_HOLD_TIME;
872 <        SetCaptured(source_p);
873 <      }
874 <      else
875 <        exit_client(source_p, &me, "You are not authorized to use this server");
876 <      break;
877 <
878 <   case BANNED_CLIENT:
879 <     /*
880 <      * Don't exit them immediately, play with them a bit.
881 <      * - Dianora
882 <      */
883 <     if (REJECT_HOLD_TIME > 0)
884 <     {
885 <       source_p->localClient->reject_delay = CurrentTime + REJECT_HOLD_TIME;
886 <       SetCaptured(source_p);
887 <     }
888 <     else
889 <       exit_client(source_p, &me, "Banned");
890 <     ++ServerStats.is_ref;
891 <     break;
892 <
893 <   case 0:
894 <   default:
895 <     break;
218 >    MyFree(node->data);
219 >    dlinkDelete(node, &conf->hub_list);
220 >    free_dlink_node(node);
221    }
222  
223 <  return (i < 0 ? NULL : source_p);
899 < }
900 <
901 < /* verify_access()
902 < *
903 < * inputs       - pointer to client to verify
904 < *              - pointer to proposed username
905 < * output       - 0 if success -'ve if not
906 < * side effect  - find the first (best) I line to attach.
907 < */
908 < static int
909 < verify_access(struct Client *client_p, const char *username)
910 < {
911 <  struct AccessItem *aconf = NULL, *rkconf = NULL;
912 <  struct ConfItem *conf = NULL;
913 <  char non_ident[USERLEN + 1] = { '~', '\0' };
914 <  const char *uhi[3];
915 <
916 <  if (IsGotId(client_p))
917 <  {
918 <    aconf = find_address_conf(client_p->host, client_p->username,
919 <                             &client_p->localClient->ip,
920 <                             client_p->localClient->aftype,
921 <                             client_p->localClient->passwd);
922 <  }
923 <  else
223 >  DLINK_FOREACH_SAFE(node, node_next, conf->leaf_list.head)
224    {
225 <    strlcpy(non_ident+1, username, sizeof(non_ident)-1);
226 <    aconf = find_address_conf(client_p->host,non_ident,
227 <                             &client_p->localClient->ip,
928 <                             client_p->localClient->aftype,
929 <                             client_p->localClient->passwd);
225 >    MyFree(node->data);
226 >    dlinkDelete(node, &conf->leaf_list);
227 >    free_dlink_node(node);
228    }
229  
230 <  uhi[0] = IsGotId(client_p) ? client_p->username : non_ident;
933 <  uhi[1] = client_p->host;
934 <  uhi[2] = client_p->sockhost;
935 <
936 <  rkconf = find_regexp_kline(uhi);
937 <
938 <  if (aconf != NULL)
230 >  DLINK_FOREACH_SAFE(node, node_next, conf->exempt_list.head)
231    {
232 <    if (IsConfClient(aconf) && !rkconf)
941 <    {
942 <      conf = unmap_conf_item(aconf);
943 <
944 <      if (IsConfRedir(aconf))
945 <      {
946 <        sendto_one(client_p, form_str(RPL_REDIR),
947 <                   me.name, client_p->name,
948 <                   conf->name ? conf->name : "",
949 <                   aconf->port);
950 <        return(NOT_AUTHORIZED);
951 <      }
952 <
953 <      if (IsConfDoIdentd(aconf))
954 <        SetNeedId(client_p);
232 >    struct exempt *exptr = node->data;
233  
234 <      /* Thanks for spoof idea amm */
235 <      if (IsConfDoSpoofIp(aconf))
236 <      {
237 <        conf = unmap_conf_item(aconf);
238 <
961 <        if (!ConfigFileEntry.hide_spoof_ips && IsConfSpoofNotice(aconf))
962 <          sendto_realops_flags(UMODE_ALL, L_ADMIN, "%s spoofing: %s as %s",
963 <                               client_p->name, client_p->host, conf->name);
964 <        strlcpy(client_p->host, conf->name, sizeof(client_p->host));
965 <        SetIPSpoof(client_p);
966 <      }
967 <
968 <      return(attach_iline(client_p, conf));
969 <    }
970 <    else if (rkconf || IsConfKill(aconf) || (ConfigFileEntry.glines && IsConfGline(aconf)))
971 <    {
972 <      /* XXX */
973 <      aconf = rkconf ? rkconf : aconf;
974 <      if (IsConfGline(aconf))
975 <        sendto_one(client_p, ":%s NOTICE %s :*** G-lined", me.name,
976 <                   client_p->name);
977 <      if (ConfigFileEntry.kline_with_reason)
978 <        sendto_one(client_p, ":%s NOTICE %s :*** Banned %s",
979 <                  me.name, client_p->name, aconf->reason);
980 <      return(BANNED_CLIENT);
981 <    }
234 >    dlinkDelete(node, &conf->exempt_list);
235 >    MyFree(exptr->name);
236 >    MyFree(exptr->user);
237 >    MyFree(exptr->host);
238 >    MyFree(exptr);
239    }
240  
241 <  return(NOT_AUTHORIZED);
241 >  MyFree(conf);
242   }
243  
244   /* attach_iline()
245   *
246 < * inputs       - client pointer
247 < *              - conf pointer
248 < * output       -
249 < * side effects - do actual attach
246 > * inputs       - client pointer
247 > *              - conf pointer
248 > * output       -
249 > * side effects - do actual attach
250   */
251   static int
252 < attach_iline(struct Client *client_p, struct ConfItem *conf)
252 > attach_iline(struct Client *client_p, struct MaskItem *conf)
253   {
254 <  struct AccessItem *aconf;
998 <  struct ClassItem *aclass;
254 >  const struct ClassItem *const class = conf->class;
255    struct ip_entry *ip_found;
256    int a_limit_reached = 0;
257 <  int local = 0, global = 0, ident = 0;
257 >  unsigned int local = 0, global = 0, ident = 0;
258  
259 <  ip_found = find_or_add_ip(&client_p->localClient->ip);
259 >  ip_found = ipcache_find_or_add_address(&client_p->connection->ip);
260    ip_found->count++;
261 <  SetIpHash(client_p);
1006 <
1007 <  aconf = map_to_conf(conf);
1008 <  if (aconf->class_ptr == NULL)
1009 <    return NOT_AUTHORIZED;  /* If class is missing, this is best */
1010 <
1011 <  aclass = map_to_conf(aconf->class_ptr);
261 >  AddFlag(client_p, FLAGS_IPHASH);
262  
263    count_user_host(client_p->username, client_p->host,
264                    &global, &local, &ident);
# Line 1017 | Line 267 | attach_iline(struct Client *client_p, st
267     * setting a_limit_reached if any limit is reached.
268     * - Dianora
269     */
270 <  if (MaxTotal(aclass) != 0 && CurrUserCount(aclass) >= MaxTotal(aclass))
270 >  if (class->max_total && class->ref_count >= class->max_total)
271      a_limit_reached = 1;
272 <  else if (MaxPerIp(aclass) != 0 && ip_found->count > MaxPerIp(aclass))
272 >  else if (class->max_perip && ip_found->count > class->max_perip)
273      a_limit_reached = 1;
274 <  else if (MaxLocal(aclass) != 0 && local >= MaxLocal(aclass))
274 >  else if (class->max_local && local >= class->max_local)
275      a_limit_reached = 1;
276 <  else if (MaxGlobal(aclass) != 0 && global >= MaxGlobal(aclass))
276 >  else if (class->max_global && global >= class->max_global)
277      a_limit_reached = 1;
278 <  else if (MaxIdent(aclass) != 0 && ident >= MaxIdent(aclass) &&
278 >  else if (class->max_ident && ident >= class->max_ident &&
279             client_p->username[0] != '~')
280      a_limit_reached = 1;
281  
282    if (a_limit_reached)
283    {
284 <    if (!IsConfExemptLimits(aconf))
284 >    if (!IsConfExemptLimits(conf))
285        return TOO_MANY;   /* Already at maximum allowed */
286  
287 <    sendto_one(client_p,
288 <               ":%s NOTICE %s :*** Your connection class is full, "
1039 <               "but you have exceed_limit = yes;", me.name, client_p->name);
287 >    sendto_one_notice(client_p, &me, ":*** Your connection class is full, "
288 >                      "but you have exceed_limit = yes;");
289    }
290  
291    return attach_conf(client_p, conf);
292   }
293  
294 < /* init_ip_hash_table()
1046 < *
1047 < * inputs               - NONE
1048 < * output               - NONE
1049 < * side effects         - allocate memory for ip_entry(s)
1050 < *                      - clear the ip hash table
1051 < */
1052 < void
1053 < init_ip_hash_table(void)
1054 < {
1055 <  ip_entry_heap = BlockHeapCreate("ip", sizeof(struct ip_entry),
1056 <    2 * hard_fdlimit);
1057 <  memset(ip_hash_table, 0, sizeof(ip_hash_table));
1058 < }
1059 <
1060 < /* find_or_add_ip()
1061 < *
1062 < * inputs       - pointer to struct irc_ssaddr
1063 < * output       - pointer to a struct ip_entry
1064 < * side effects -
294 > /* verify_access()
295   *
296 < * If the ip # was not found, a new struct ip_entry is created, and the ip
297 < * count set to 0.
296 > * inputs       - pointer to client to verify
297 > * output       - 0 if success -'ve if not
298 > * side effect  - find the first (best) I line to attach.
299   */
300 < static struct ip_entry *
301 < find_or_add_ip(struct irc_ssaddr *ip_in)
300 > static int
301 > verify_access(struct Client *client_p)
302   {
303 <  struct ip_entry *ptr, *newptr;
1073 <  int hash_index = hash_ip(ip_in), res;
1074 <  struct sockaddr_in *v4 = (struct sockaddr_in *)ip_in, *ptr_v4;
1075 < #ifdef IPV6
1076 <  struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)ip_in, *ptr_v6;
1077 < #endif
303 >  struct MaskItem *conf = NULL;
304  
305 <  for (ptr = ip_hash_table[hash_index]; ptr; ptr = ptr->next)
305 >  if (HasFlag(client_p, FLAGS_GOTID))
306    {
307 < #ifdef IPV6
308 <    if (ptr->ip.ss.ss_family != ip_in->ss.ss_family)
309 <      continue;
310 <    if (ip_in->ss.ss_family == AF_INET6)
1085 <    {
1086 <      ptr_v6 = (struct sockaddr_in6 *)&ptr->ip;
1087 <      res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr));
1088 <    }
1089 <    else
1090 < #endif
1091 <    {
1092 <      ptr_v4 = (struct sockaddr_in *)&ptr->ip;
1093 <      res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr));
1094 <    }
1095 <    if (res == 0)
1096 <    {
1097 <      /* Found entry already in hash, return it. */
1098 <      return ptr;
1099 <    }
307 >    conf = find_address_conf(client_p->host, client_p->username,
308 >                             &client_p->connection->ip,
309 >                             client_p->connection->aftype,
310 >                             client_p->connection->password);
311    }
312 +  else
313 +  {
314 +    char non_ident[USERLEN + 1] = "~";
315  
316 <  if (ip_entries_count >= 2 * hard_fdlimit)
317 <    garbage_collect_ip_entries();
318 <
319 <  newptr = BlockHeapAlloc(ip_entry_heap);
320 <  ip_entries_count++;
321 <  memcpy(&newptr->ip, ip_in, sizeof(struct irc_ssaddr));
316 >    strlcpy(non_ident + 1, client_p->username, sizeof(non_ident) - 1);
317 >    conf = find_address_conf(client_p->host, non_ident,
318 >                             &client_p->connection->ip,
319 >                             client_p->connection->aftype,
320 >                             client_p->connection->password);
321 >  }
322  
323 <  newptr->next = ip_hash_table[hash_index];
324 <  ip_hash_table[hash_index] = newptr;
323 >  if (!conf)
324 >    return NOT_AUTHORIZED;
325  
326 <  return newptr;
1113 < }
326 >  assert(IsConfClient(conf) || IsConfKill(conf));
327  
328 < /* remove_one_ip()
1116 < *
1117 < * inputs        - unsigned long IP address value
1118 < * output        - NONE
1119 < * side effects  - The ip address given, is looked up in ip hash table
1120 < *                 and number of ip#'s for that ip decremented.
1121 < *                 If ip # count reaches 0 and has expired,
1122 < *                 the struct ip_entry is returned to the ip_entry_heap
1123 < */
1124 < void
1125 < remove_one_ip(struct irc_ssaddr *ip_in)
1126 < {
1127 <  struct ip_entry *ptr;
1128 <  struct ip_entry *last_ptr = NULL;
1129 <  int hash_index = hash_ip(ip_in), res;
1130 <  struct sockaddr_in *v4 = (struct sockaddr_in *)ip_in, *ptr_v4;
1131 < #ifdef IPV6
1132 <  struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)ip_in, *ptr_v6;
1133 < #endif
1134 <
1135 <  for (ptr = ip_hash_table[hash_index]; ptr; ptr = ptr->next)
328 >  if (IsConfClient(conf))
329    {
330 < #ifdef IPV6
1138 <    if (ptr->ip.ss.ss_family != ip_in->ss.ss_family)
1139 <      continue;
1140 <    if (ip_in->ss.ss_family == AF_INET6)
1141 <    {
1142 <      ptr_v6 = (struct sockaddr_in6 *)&ptr->ip;
1143 <      res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr));
1144 <    }
1145 <    else
1146 < #endif
330 >    if (IsConfRedir(conf))
331      {
332 <      ptr_v4 = (struct sockaddr_in *)&ptr->ip;
333 <      res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr));
332 >      sendto_one_numeric(client_p, &me, RPL_REDIR,
333 >                         conf->name ? conf->name : "",
334 >                         conf->port);
335 >      return NOT_AUTHORIZED;
336      }
337 <    if (res)
338 <      continue;
1153 <    if (ptr->count > 0)
1154 <      ptr->count--;
1155 <    if (ptr->count == 0 &&
1156 <        (CurrentTime-ptr->last_attempt) >= ConfigFileEntry.throttle_time)
337 >
338 >    if (IsConfDoSpoofIp(conf))
339      {
340 <      if (last_ptr != NULL)
341 <        last_ptr->next = ptr->next;
342 <      else
1161 <        ip_hash_table[hash_index] = ptr->next;
340 >      if (IsConfSpoofNotice(conf))
341 >        sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, "%s spoofing: %s as %s",
342 >                             client_p->name, client_p->host, conf->name);
343  
344 <      BlockHeapFree(ip_entry_heap, ptr);
1164 <      ip_entries_count--;
1165 <      return;
344 >      strlcpy(client_p->host, conf->name, sizeof(client_p->host));
345      }
1167    last_ptr = ptr;
1168  }
1169 }
346  
347 < /* hash_ip()
1172 < *
1173 < * input        - pointer to an irc_inaddr
1174 < * output       - integer value used as index into hash table
1175 < * side effects - hopefully, none
1176 < */
1177 < static int
1178 < hash_ip(struct irc_ssaddr *addr)
1179 < {
1180 <  if (addr->ss.ss_family == AF_INET)
1181 <  {
1182 <    struct sockaddr_in *v4 = (struct sockaddr_in *)addr;
1183 <    int hash;
1184 <    uint32_t ip;
1185 <
1186 <    ip   = ntohl(v4->sin_addr.s_addr);
1187 <    hash = ((ip >> 12) + ip) & (IP_HASH_SIZE-1);
1188 <    return hash;
347 >    return attach_iline(client_p, conf);
348    }
349 < #ifdef IPV6
350 <  else
351 <  {
1193 <    int hash;
1194 <    struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr;
1195 <    uint32_t *ip = (uint32_t *)&v6->sin6_addr.s6_addr;
1196 <
1197 <    hash  = ip[0] ^ ip[3];
1198 <    hash ^= hash >> 16;  
1199 <    hash ^= hash >> 8;  
1200 <    hash  = hash & (IP_HASH_SIZE - 1);
1201 <    return hash;
1202 <  }
1203 < #else
1204 <  return 0;
1205 < #endif
349 >
350 >  sendto_one_notice(client_p, &me, ":*** Banned: %s", conf->reason);
351 >  return BANNED_CLIENT;
352   }
353  
354 < /* count_ip_hash()
1209 < *
1210 < * inputs        - pointer to counter of number of ips hashed
1211 < *               - pointer to memory used for ip hash
1212 < * output        - returned via pointers input
1213 < * side effects  - NONE
354 > /* check_client()
355   *
356 < * number of hashed ip #'s is counted up, plus the amount of memory
357 < * used in the hash.
356 > * inputs       - pointer to client
357 > * output       - 0 = Success
358 > *                NOT_AUTHORIZED    (-1) = Access denied (no I line match)
359 > *                IRCD_SOCKET_ERROR (-2) = Bad socket.
360 > *                I_LINE_FULL       (-3) = I-line is full
361 > *                TOO_MANY          (-4) = Too many connections from hostname
362 > *                BANNED_CLIENT     (-5) = K-lined
363 > * side effects - Ordinary client access check.
364 > *                Look for conf lines which have the same
365 > *                status as the flags passed.
366   */
367 < void
368 < count_ip_hash(unsigned int *number_ips_stored, uint64_t *mem_ips_stored)
367 > int
368 > check_client(struct Client *source_p)
369   {
1221  struct ip_entry *ptr;
370    int i;
371  
372 <  *number_ips_stored = 0;
373 <  *mem_ips_stored    = 0;
372 >  if ((i = verify_access(source_p)))
373 >    ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
374 >         source_p->name, source_p->sockhost);
375  
376 <  for (i = 0; i < IP_HASH_SIZE; i++)
376 >  switch (i)
377    {
378 <    for (ptr = ip_hash_table[i]; ptr; ptr = ptr->next)
379 <    {
380 <      *number_ips_stored += 1;
381 <      *mem_ips_stored += sizeof(struct ip_entry);
382 <    }
383 <  }
384 < }
378 >    case TOO_MANY:
379 >      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
380 >                           "Too many on IP for %s (%s).",
381 >                           get_client_name(source_p, SHOW_IP),
382 >                           source_p->sockhost);
383 >      ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
384 >           get_client_name(source_p, SHOW_IP));
385 >      ++ServerStats.is_ref;
386 >      exit_client(source_p, "No more connections allowed on that IP");
387 >      break;
388  
389 < /* garbage_collect_ip_entries()
390 < *
391 < * input        - NONE
392 < * output       - NONE
393 < * side effects - free up all ip entries with no connections
394 < */
395 < static void
396 < garbage_collect_ip_entries(void)
397 < {
398 <  struct ip_entry *ptr;
1247 <  struct ip_entry *last_ptr;
1248 <  struct ip_entry *next_ptr;
1249 <  int i;
389 >    case I_LINE_FULL:
390 >      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
391 >                           "auth {} block is full for %s (%s).",
392 >                           get_client_name(source_p, SHOW_IP),
393 >                           source_p->sockhost);
394 >      ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
395 >           get_client_name(source_p, SHOW_IP));
396 >      ++ServerStats.is_ref;
397 >      exit_client(source_p, "No more connections allowed in your connection class");
398 >      break;
399  
400 <  for (i = 0; i < IP_HASH_SIZE; i++)
401 <  {
402 <    last_ptr = NULL;
400 >    case NOT_AUTHORIZED:
401 >      /* jdc - lists server name & port connections are on */
402 >      /*       a purely cosmetical change */
403 >      sendto_realops_flags(UMODE_UNAUTH, L_ALL, SEND_NOTICE,
404 >                           "Unauthorized client connection from %s [%s] on [%s/%u].",
405 >                           get_client_name(source_p, SHOW_IP),
406 >                           source_p->sockhost,
407 >                           source_p->connection->listener->name,
408 >                           source_p->connection->listener->port);
409 >      ilog(LOG_TYPE_IRCD, "Unauthorized client connection from %s on [%s/%u].",
410 >           get_client_name(source_p, SHOW_IP),
411 >           source_p->connection->listener->name,
412 >           source_p->connection->listener->port);
413  
414 <    for (ptr = ip_hash_table[i]; ptr; ptr = next_ptr)
415 <    {
416 <      next_ptr = ptr->next;
414 >      ++ServerStats.is_ref;
415 >      exit_client(source_p, "You are not authorized to use this server");
416 >      break;
417  
418 <      if (ptr->count == 0 &&
419 <          (CurrentTime - ptr->last_attempt) >= ConfigFileEntry.throttle_time)
420 <      {
421 <        if (last_ptr != NULL)
422 <          last_ptr->next = ptr->next;
423 <        else
424 <          ip_hash_table[i] = ptr->next;
425 <        BlockHeapFree(ip_entry_heap, ptr);
1267 <        ip_entries_count--;
1268 <      }
1269 <      else
1270 <        last_ptr = ptr;
1271 <    }
418 >    case BANNED_CLIENT:
419 >      ++ServerStats.is_ref;
420 >      exit_client(source_p, "Banned");
421 >      break;
422 >
423 >    case 0:
424 >    default:
425 >      break;
426    }
427 +
428 +  return !(i < 0);
429   }
430  
431   /* detach_conf()
# Line 1280 | Line 436 | garbage_collect_ip_entries(void)
436   * side effects - Disassociate configuration from the client.
437   *                Also removes a class from the list if marked for deleting.
438   */
439 < int
440 < detach_conf(struct Client *client_p, ConfType type)
439 > void
440 > detach_conf(struct Client *client_p, enum maskitem_type type)
441   {
442 <  dlink_node *ptr, *next_ptr;
1287 <  struct ConfItem *conf;
1288 <  struct ClassItem *aclass;
1289 <  struct AccessItem *aconf;
1290 <  struct ConfItem *aclass_conf;
1291 <  struct MatchItem *match_item;
442 >  dlink_node *node = NULL, *node_next = NULL;
443  
444 <  DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->confs.head)
444 >  DLINK_FOREACH_SAFE(node, node_next, client_p->connection->confs.head)
445    {
446 <    conf = ptr->data;
1296 <
1297 <    if (type == CONF_TYPE || conf->type == type)
1298 <    {
1299 <      dlinkDelete(ptr, &client_p->localClient->confs);
1300 <      free_dlink_node(ptr);
1301 <
1302 <      switch (conf->type)
1303 <      {
1304 <      case CLIENT_TYPE:
1305 <      case OPER_TYPE:
1306 <      case SERVER_TYPE:
1307 <        aconf = map_to_conf(conf);
1308 <
1309 <        assert(aconf->clients > 0);
1310 <
1311 <        if ((aclass_conf = ClassPtr(aconf)) != NULL)
1312 <        {
1313 <          aclass = map_to_conf(aclass_conf);
1314 <
1315 <          assert(aclass->curr_user_count > 0);
446 >    struct MaskItem *conf = node->data;
447  
448 <          if (conf->type == CLIENT_TYPE)
449 <            remove_from_cidr_check(&client_p->localClient->ip, aclass);
450 <          if (--aclass->curr_user_count == 0 && aclass->active == 0)
1320 <            delete_conf_item(aclass_conf);
1321 <        }
448 >    assert(conf->type & (CONF_CLIENT | CONF_OPER | CONF_SERVER));
449 >    assert(conf->ref_count > 0);
450 >    assert(conf->class->ref_count > 0);
451  
452 <        if (--aconf->clients == 0 && IsConfIllegal(aconf))
453 <          delete_conf_item(conf);
452 >    if (!(conf->type & type))
453 >      continue;
454  
455 <        break;
455 >    dlinkDelete(node, &client_p->connection->confs);
456 >    free_dlink_node(node);
457  
458 <      case LEAF_TYPE:
459 <      case HUB_TYPE:
1330 <        match_item = map_to_conf(conf);
1331 <        if (match_item->ref_count == 0 && match_item->illegal)
1332 <          delete_conf_item(conf);
1333 <        break;
1334 <      default:
1335 <        break;
1336 <      }
458 >    if (conf->type == CONF_CLIENT)
459 >      remove_from_cidr_check(&client_p->connection->ip, conf->class);
460  
461 <      if (type != CONF_TYPE)
462 <        return 0;
461 >    if (--conf->class->ref_count == 0 && conf->class->active == 0)
462 >    {
463 >      class_free(conf->class);
464 >      conf->class = NULL;
465      }
1341  }
466  
467 <  return -1;
467 >    if (--conf->ref_count == 0 && conf->active == 0)
468 >      conf_free(conf);
469 >  }
470   }
471  
472   /* attach_conf()
# Line 1354 | Line 480 | detach_conf(struct Client *client_p, Con
480   *                attachment if there was an old one...
481   */
482   int
483 < attach_conf(struct Client *client_p, struct ConfItem *conf)
483 > attach_conf(struct Client *client_p, struct MaskItem *conf)
484   {
485 <  if (dlinkFind(&client_p->localClient->confs, conf) != NULL)
485 >  if (dlinkFind(&client_p->connection->confs, conf))
486      return 1;
487  
488 <  if (conf->type == CLIENT_TYPE ||
489 <      conf->type == SERVER_TYPE ||
490 <      conf->type == OPER_TYPE)
491 <  {
1366 <    struct AccessItem *aconf = map_to_conf(conf);
1367 <    struct ClassItem *aclass = map_to_conf(aconf->class_ptr);
488 >  if (conf->type == CONF_CLIENT)
489 >    if (cidr_limit_reached(IsConfExemptLimits(conf),
490 >                           &client_p->connection->ip, conf->class))
491 >      return TOO_MANY;    /* Already at maximum allowed */
492  
493 <    if (IsConfIllegal(aconf))
494 <      return NOT_AUTHORIZED;
493 >  conf->class->ref_count++;
494 >  conf->ref_count++;
495  
496 <    if (conf->type == CLIENT_TYPE)
1373 <      if (cidr_limit_reached(IsConfExemptLimits(aconf),
1374 <                             &client_p->localClient->ip, aclass))
1375 <        return TOO_MANY;    /* Already at maximum allowed */
1376 <
1377 <    CurrUserCount(aclass)++;
1378 <    aconf->clients++;
1379 <  }
1380 <  else if (conf->type == HUB_TYPE || conf->type == LEAF_TYPE)
1381 <  {
1382 <    struct MatchItem *match_item = map_to_conf(conf);
1383 <    match_item->ref_count++;
1384 <  }
1385 <
1386 <  dlinkAdd(conf, make_dlink_node(), &client_p->localClient->confs);
496 >  dlinkAdd(conf, make_dlink_node(), &client_p->connection->confs);
497  
498    return 0;
499   }
# Line 1400 | Line 510 | int
510   attach_connect_block(struct Client *client_p, const char *name,
511                       const char *host)
512   {
513 <  dlink_node *ptr;
1404 <  struct ConfItem *conf;
1405 <  struct AccessItem *aconf;
513 >  dlink_node *node = NULL;
514  
515 <  assert(client_p != NULL);
1408 <  assert(host != NULL);
515 >  assert(host);
516  
517 <  if (client_p == NULL || host == NULL)
1411 <    return 0;
1412 <
1413 <  DLINK_FOREACH(ptr, server_items.head)
517 >  DLINK_FOREACH(node, server_items.head)
518    {
519 <    conf = ptr->data;
1416 <    aconf = map_to_conf(conf);
519 >    struct MaskItem *conf = node->data;
520  
521 <    if (match(conf->name, name) == 0 || match(aconf->host, host) == 0)
521 >    if (match(conf->name, name) || match(conf->host, host))
522        continue;
523  
524      attach_conf(client_p, conf);
525 <    return -1;
525 >    return 1;
526    }
527  
528    return 0;
529   }
530  
1428 /* find_conf_exact()
1429 *
1430 * inputs       - type of ConfItem
1431 *              - pointer to name to find
1432 *              - pointer to username to find
1433 *              - pointer to host to find
1434 * output       - NULL or pointer to conf found
1435 * side effects - find a conf entry which matches the hostname
1436 *                and has the same name.
1437 */
1438 struct ConfItem *
1439 find_conf_exact(ConfType type, const char *name, const char *user,
1440                const char *host)
1441 {
1442  dlink_node *ptr;
1443  dlink_list *list_p;
1444  struct ConfItem *conf = NULL;
1445  struct AccessItem *aconf;
1446
1447  /* Only valid for OPER_TYPE and ...? */
1448  list_p = map_to_list(type);
1449
1450  DLINK_FOREACH(ptr, (*list_p).head)
1451  {
1452    conf = ptr->data;
1453
1454    if (conf->name == NULL)
1455      continue;
1456    aconf = map_to_conf(conf);
1457    if (aconf->host == NULL)
1458      continue;
1459    if (irccmp(conf->name, name) != 0)
1460      continue;
1461
1462    /*
1463    ** Accept if the *real* hostname (usually sockethost)
1464    ** socket host) matches *either* host or name field
1465    ** of the configuration.
1466    */
1467    if (!match(aconf->host, host) || !match(aconf->user, user))
1468      continue;
1469    if (type == OPER_TYPE)
1470    {
1471      struct ClassItem *aclass = map_to_conf(aconf->class_ptr);
1472
1473      if (aconf->clients >= MaxTotal(aclass))
1474        continue;
1475    }
1476
1477    return conf;
1478  }
1479
1480  return NULL;
1481 }
1482
531   /* find_conf_name()
532   *
533   * inputs       - pointer to conf link list to search
# Line 1489 | Line 537 | find_conf_exact(ConfType type, const cha
537   * side effects - find a conf entry which matches the name
538   *                and has the given mask.
539   */
540 < struct ConfItem *
541 < find_conf_name(dlink_list *list, const char *name, ConfType type)
540 > struct MaskItem *
541 > find_conf_name(dlink_list *list, const char *name, enum maskitem_type type)
542   {
543 <  dlink_node *ptr;
1496 <  struct ConfItem* conf;
543 >  dlink_node *node = NULL;
544  
545 <  DLINK_FOREACH(ptr, list->head)
545 >  DLINK_FOREACH(node, list->head)
546    {
547 <    conf = ptr->data;
548 <    
547 >    struct MaskItem *conf = node->data;
548 >
549      if (conf->type == type)
550      {
551 <      if (conf->name && (irccmp(conf->name, name) == 0 ||
552 <                         match(conf->name, name)))
1506 <      return conf;
551 >      if (conf->name && !irccmp(conf->name, name))
552 >        return conf;
553      }
554    }
555  
556    return NULL;
557   }
558  
1513 /* map_to_list()
1514 *
1515 * inputs       - ConfType conf
1516 * output       - pointer to dlink_list to use
1517 * side effects - none
1518 */
1519 static dlink_list *
1520 map_to_list(ConfType type)
1521 {
1522  switch(type)
1523  {
1524  case RXLINE_TYPE:
1525    return(&rxconf_items);
1526    break;
1527  case XLINE_TYPE:
1528    return(&xconf_items);
1529    break;
1530  case ULINE_TYPE:
1531    return(&uconf_items);
1532    break;
1533  case NRESV_TYPE:
1534    return(&nresv_items);
1535    break;
1536  case OPER_TYPE:
1537    return(&oconf_items);
1538    break;
1539  case CLASS_TYPE:
1540    return(&class_items);
1541    break;
1542  case SERVER_TYPE:
1543    return(&server_items);
1544    break;
1545  case SERVICE_TYPE:
1546    return(&service_items);
1547    break;
1548  case CLUSTER_TYPE:
1549    return(&cluster_items);
1550    break;
1551  case CONF_TYPE:
1552  case GLINE_TYPE:
1553  case KLINE_TYPE:
1554  case DLINE_TYPE:
1555  case CRESV_TYPE:
1556  default:
1557    return NULL;
1558  }
1559 }
1560
559   /* find_matching_name_conf()
560   *
561   * inputs       - type of link list to look in
562   *              - pointer to name string to find
563   *              - pointer to user
564   *              - pointer to host
565 < *              - optional action to match on as well
566 < * output       - NULL or pointer to found struct MatchItem
565 > *              - optional flags to match on as well
566 > * output       - NULL or pointer to found struct MaskItem
567   * side effects - looks for a match on name field
568   */
569 < struct ConfItem *
570 < find_matching_name_conf(ConfType type, const char *name, const char *user,
571 <                        const char *host, int action)
572 < {
573 <  dlink_node *ptr=NULL;
574 <  struct ConfItem *conf=NULL;
575 <  struct AccessItem *aconf=NULL;
1578 <  struct MatchItem *match_item=NULL;
1579 <  dlink_list *list_p = map_to_list(type);
569 > struct MaskItem *
570 > find_matching_name_conf(enum maskitem_type type, const char *name, const char *user,
571 >                        const char *host, unsigned int flags)
572 > {
573 >  dlink_node *node = NULL;
574 >  dlink_list *list = map_to_list(type);
575 >  struct MaskItem *conf = NULL;
576  
577    switch (type)
578    {
579 < #ifdef HAVE_LIBPCRE
580 <  case RXLINE_TYPE:
1585 <      DLINK_FOREACH(ptr, list_p->head)
1586 <      {
1587 <        conf = ptr->data;
1588 <        assert(conf->regexpname);
1589 <
1590 <        if (!ircd_pcre_exec(conf->regexpname, name))
1591 <          return conf;
1592 <      }
1593 <      break;
1594 < #endif
1595 <  case SERVICE_TYPE:
1596 <    DLINK_FOREACH(ptr, list_p->head)
579 >  case CONF_SERVICE:
580 >    DLINK_FOREACH(node, list->head)
581      {
582 <      conf = ptr->data;
582 >      conf = node->data;
583  
584        if (EmptyString(conf->name))
585          continue;
586 <      if ((name != NULL) && !irccmp(name, conf->name))
586 >      if (name && !irccmp(name, conf->name))
587          return conf;
588      }
589      break;
590  
591 <  case XLINE_TYPE:
592 <  case ULINE_TYPE:
593 <  case NRESV_TYPE:
594 <    DLINK_FOREACH(ptr, list_p->head)
591 >  case CONF_XLINE:
592 >  case CONF_ULINE:
593 >  case CONF_NRESV:
594 >  case CONF_CRESV:
595 >    DLINK_FOREACH(node, list->head)
596      {
597 <      conf = ptr->data;
597 >      conf = node->data;
598  
1614      match_item = map_to_conf(conf);
599        if (EmptyString(conf->name))
600 <        continue;
601 <      if ((name != NULL) && match_esc(conf->name, name))
600 >        continue;
601 >      if (name && !match(conf->name, name))
602        {
603 <        if ((user == NULL && (host == NULL)))
604 <          return conf;
605 <        if ((match_item->action & action) != action)
603 >        if ((user == NULL && (host == NULL)))
604 >          return conf;
605 >        if ((conf->flags & flags) != flags)
606            continue;
607 <        if (EmptyString(match_item->user) || EmptyString(match_item->host))
608 <          return conf;
609 <        if (match(match_item->user, user) && match(match_item->host, host))
610 <          return conf;
607 >        if (EmptyString(conf->user) || EmptyString(conf->host))
608 >          return conf;
609 >        if (!match(conf->user, user) && !match(conf->host, host))
610 >          return conf;
611        }
612      }
613        break;
614  
615 <  case SERVER_TYPE:
616 <    DLINK_FOREACH(ptr, list_p->head)
615 >  case CONF_SERVER:
616 >    DLINK_FOREACH(node, list->head)
617      {
618 <      conf = ptr->data;
1635 <      aconf = map_to_conf(conf);
618 >      conf = node->data;
619  
620 <      if ((name != NULL) && match_esc(name, conf->name))
620 >      if (name && !match(name, conf->name))
621          return conf;
622 <      else if ((host != NULL) && match_esc(host, aconf->host))
622 >      if (host && !match(host, conf->host))
623          return conf;
624      }
625      break;
626 <  
626 >
627    default:
628      break;
629    }
# Line 1653 | Line 636 | find_matching_name_conf(ConfType type, c
636   *              - pointer to name string to find
637   *              - pointer to user
638   *              - pointer to host
639 < * output       - NULL or pointer to found struct MatchItem
639 > * output       - NULL or pointer to found struct MaskItem
640   * side effects - looks for an exact match on name field
641   */
642 < struct ConfItem *
643 < find_exact_name_conf(ConfType type, const struct Client *who, const char *name,
642 > struct MaskItem *
643 > find_exact_name_conf(enum maskitem_type type, const struct Client *who, const char *name,
644                       const char *user, const char *host)
645   {
646 <  dlink_node *ptr = NULL;
647 <  struct AccessItem *aconf;
648 <  struct ConfItem *conf;
1666 <  struct MatchItem *match_item;
1667 <  dlink_list *list_p;
1668 <
1669 <  list_p = map_to_list(type);
646 >  dlink_node *node = NULL;
647 >  dlink_list *list = map_to_list(type);
648 >  struct MaskItem *conf = NULL;
649  
650    switch(type)
651    {
652 <  case RXLINE_TYPE:
653 <  case XLINE_TYPE:
654 <  case ULINE_TYPE:
655 <  case NRESV_TYPE:
652 >  case CONF_XLINE:
653 >  case CONF_ULINE:
654 >  case CONF_NRESV:
655 >  case CONF_CRESV:
656  
657 <    DLINK_FOREACH(ptr, list_p->head)
657 >    DLINK_FOREACH(node, list->head)
658      {
659 <      conf = ptr->data;
660 <      match_item = (struct MatchItem *)map_to_conf(conf);
659 >      conf = node->data;
660 >
661        if (EmptyString(conf->name))
662 <        continue;
663 <    
662 >        continue;
663 >
664        if (irccmp(conf->name, name) == 0)
665        {
666 <        if ((user == NULL && (host == NULL)))
667 <          return (conf);
668 <        if (EmptyString(match_item->user) || EmptyString(match_item->host))
669 <          return (conf);
670 <        if (match(match_item->user, user) && match(match_item->host, host))
671 <          return (conf);
666 >        if ((user == NULL && (host == NULL)))
667 >          return conf;
668 >        if (EmptyString(conf->user) || EmptyString(conf->host))
669 >          return conf;
670 >        if (!match(conf->user, user) && !match(conf->host, host))
671 >          return conf;
672        }
673      }
674      break;
675  
676 <  case OPER_TYPE:
677 <    DLINK_FOREACH(ptr, list_p->head)
676 >  case CONF_OPER:
677 >    DLINK_FOREACH(node, list->head)
678      {
679 <      conf = ptr->data;
1701 <      aconf = map_to_conf(conf);
679 >      conf = node->data;
680  
681        if (EmptyString(conf->name))
682          continue;
# Line 1707 | Line 685 | find_exact_name_conf(ConfType type, cons
685        {
686          if (!who)
687            return conf;
688 <        if (EmptyString(aconf->user) || EmptyString(aconf->host))
689 <          return conf;
690 <        if (match(aconf->user, who->username))
688 >        if (EmptyString(conf->user) || EmptyString(conf->host))
689 >          return NULL;
690 >        if (!match(conf->user, who->username))
691          {
692 <          switch (aconf->type)
692 >          switch (conf->htype)
693            {
694              case HM_HOST:
695 <              if (match(aconf->host, who->host) || match(aconf->host, who->sockhost))
696 <                return conf;
695 >              if (!match(conf->host, who->host) || !match(conf->host, who->sockhost))
696 >                if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
697 >                  return conf;
698                break;
699              case HM_IPV4:
700 <              if (who->localClient->aftype == AF_INET)
701 <                if (match_ipv4(&who->localClient->ip, &aconf->ipnum, aconf->bits))
702 <                  return conf;
700 >              if (who->connection->aftype == AF_INET)
701 >                if (match_ipv4(&who->connection->ip, &conf->addr, conf->bits))
702 >                  if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
703 >                    return conf;
704                break;
1725 #ifdef IPV6
705              case HM_IPV6:
706 <              if (who->localClient->aftype == AF_INET6)
707 <                if (match_ipv6(&who->localClient->ip, &aconf->ipnum, aconf->bits))
708 <                  return conf;
706 >              if (who->connection->aftype == AF_INET6)
707 >                if (match_ipv6(&who->connection->ip, &conf->addr, conf->bits))
708 >                  if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
709 >                    return conf;
710                break;
1731 #endif
711              default:
712                assert(0);
713            }
# Line 1738 | Line 717 | find_exact_name_conf(ConfType type, cons
717  
718      break;
719  
720 <  case SERVER_TYPE:
721 <    DLINK_FOREACH(ptr, list_p->head)
720 >  case CONF_SERVER:
721 >    DLINK_FOREACH(node, list->head)
722      {
723 <      conf = ptr->data;
724 <      aconf = (struct AccessItem *)map_to_conf(conf);
723 >      conf = node->data;
724 >
725        if (EmptyString(conf->name))
726 <        continue;
727 <    
726 >        continue;
727 >
728        if (name == NULL)
729        {
730 <        if (EmptyString(aconf->host))
731 <          continue;
732 <        if (irccmp(aconf->host, host) == 0)
733 <          return(conf);
730 >        if (EmptyString(conf->host))
731 >          continue;
732 >        if (irccmp(conf->host, host) == 0)
733 >          return conf;
734        }
735        else if (irccmp(conf->name, name) == 0)
736 <      {
1758 <          return (conf);
1759 <      }
736 >        return conf;
737      }
1761    break;
738  
1763  case CLASS_TYPE:
1764    DLINK_FOREACH(ptr, list_p->head)
1765    {
1766      conf = ptr->data;
1767      if (EmptyString(conf->name))
1768        continue;
1769    
1770      if (irccmp(conf->name, name) == 0)
1771        return (conf);
1772    }
739      break;
740  
741    default:
742      break;
743    }
1778  return(NULL);
1779 }
744  
745 < /* rehash()
1782 < *
1783 < * Actual REHASH service routine. Called with sig == 0 if it has been called
1784 < * as a result of an operator issuing this command, else assume it has been
1785 < * called as a result of the server receiving a HUP signal.
1786 < */
1787 < int
1788 < rehash(int sig)
1789 < {
1790 <  if (sig != 0)
1791 <    sendto_realops_flags(UMODE_ALL, L_ALL,
1792 <                         "Got signal SIGHUP, reloading ircd.conf file");
1793 <
1794 <  restart_resolver();
1795 <
1796 <  /* don't close listeners until we know we can go ahead with the rehash */
1797 <
1798 <  /* Check to see if we magically got(or lost) IPv6 support */
1799 <  check_can_use_v6();
1800 <
1801 <  read_conf_files(0);
1802 <
1803 <  if (ServerInfo.description != NULL)
1804 <    strlcpy(me.info, ServerInfo.description, sizeof(me.info));
1805 <
1806 <  load_conf_modules();
1807 <
1808 <  flush_deleted_I_P();
1809 <
1810 <  rehashed_klines = 1;
1811 < /* XXX */
1812 <  if (ConfigLoggingEntry.use_logging)
1813 <    log_close_all();
1814 <
1815 <  return(0);
745 >  return NULL;
746   }
747  
748   /* set_default_conf()
# Line 1830 | Line 760 | set_default_conf(void)
760    /* verify init_class() ran, this should be an unnecessary check
761     * but its not much work.
762     */
763 <  assert(class_default == (struct ConfItem *) class_items.tail->data);
763 >  assert(class_default == class_get_list()->tail->data);
764  
765   #ifdef HAVE_LIBCRYPTO
766 <  ServerInfo.rsa_private_key = NULL;
767 <  ServerInfo.rsa_private_key_file = NULL;
766 > #if OPENSSL_VERSION_NUMBER >= 0x009080FFL && !defined(OPENSSL_NO_ECDH)
767 >  {
768 >    EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
769 >
770 >    if (key)
771 >    {
772 >      SSL_CTX_set_tmp_ecdh(ConfigServerInfo.server_ctx, key);
773 >      EC_KEY_free(key);
774 >    }
775 >  }
776 >
777 >  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE);
778   #endif
779  
780 <  /* ServerInfo.name is not rehashable */
781 <  /* ServerInfo.name = ServerInfo.name; */
782 <  ServerInfo.description = NULL;
783 <  DupString(ServerInfo.network_name, NETWORK_NAME_DEFAULT);
784 <  DupString(ServerInfo.network_desc, NETWORK_DESC_DEFAULT);
785 <
786 <  memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip));
787 <  ServerInfo.specific_ipv4_vhost = 0;
788 <  memset(&ServerInfo.ip6, 0, sizeof(ServerInfo.ip6));
789 <  ServerInfo.specific_ipv6_vhost = 0;
790 <
791 <  ServerInfo.max_clients = MAXCLIENTS_MAX;
792 <
793 <  ServerInfo.hub = 0;
794 <  ServerInfo.dns_host.sin_addr.s_addr = 0;
795 <  ServerInfo.dns_host.sin_port = 0;
796 <  AdminInfo.name = NULL;
797 <  AdminInfo.email = NULL;
798 <  AdminInfo.description = NULL;
780 >  SSL_CTX_set_cipher_list(ConfigServerInfo.server_ctx, "EECDH+HIGH:EDH+HIGH:HIGH:!aNULL");
781 >  ConfigServerInfo.message_digest_algorithm = EVP_sha256();
782 >  ConfigServerInfo.rsa_private_key = NULL;
783 >  ConfigServerInfo.rsa_private_key_file = NULL;
784 > #endif
785 >
786 >  /* ConfigServerInfo.name is not rehashable */
787 >  /* ConfigServerInfo.name = ConfigServerInfo.name; */
788 >  ConfigServerInfo.description = NULL;
789 >  ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
790 >  ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
791 >
792 >  memset(&ConfigServerInfo.ip, 0, sizeof(ConfigServerInfo.ip));
793 >  ConfigServerInfo.specific_ipv4_vhost = 0;
794 >  memset(&ConfigServerInfo.ip6, 0, sizeof(ConfigServerInfo.ip6));
795 >  ConfigServerInfo.specific_ipv6_vhost = 0;
796 >
797 >  ConfigServerInfo.default_max_clients = MAXCLIENTS_MAX;
798 >  ConfigServerInfo.max_nick_length = 9;
799 >  ConfigServerInfo.max_topic_length = 80;
800 >  ConfigServerInfo.hub = 0;
801 >
802 >  ConfigAdminInfo.name = NULL;
803 >  ConfigAdminInfo.email = NULL;
804 >  ConfigAdminInfo.description = NULL;
805  
806 <  log_close_all();
806 >  log_del_all();
807  
808 <  ConfigLoggingEntry.use_logging = 1;
808 >  ConfigLog.use_logging = 1;
809  
810    ConfigChannel.disable_fake_channels = 0;
811 <  ConfigChannel.restrict_channels = 0;
812 <  ConfigChannel.disable_local_channels = 0;
813 <  ConfigChannel.use_invex = 1;
814 <  ConfigChannel.use_except = 1;
1869 <  ConfigChannel.use_knock = 1;
1870 <  ConfigChannel.knock_delay = 300;
811 >  ConfigChannel.invite_client_count = 10;
812 >  ConfigChannel.invite_client_time = 300;
813 >  ConfigChannel.knock_client_count = 1;
814 >  ConfigChannel.knock_client_time = 300;
815    ConfigChannel.knock_delay_channel = 60;
816 <  ConfigChannel.max_chans_per_user = 15;
1873 <  ConfigChannel.quiet_on_ban = 1;
816 >  ConfigChannel.max_channels = 25;
817    ConfigChannel.max_bans = 25;
818 +  ConfigChannel.default_join_flood_count = 18;
819 +  ConfigChannel.default_join_flood_time = 6;
820    ConfigChannel.default_split_user_count = 0;
821    ConfigChannel.default_split_server_count = 0;
822    ConfigChannel.no_join_on_split = 0;
823    ConfigChannel.no_create_on_split = 0;
1879  ConfigChannel.burst_topicwho = 1;
824  
825    ConfigServerHide.flatten_links = 0;
826    ConfigServerHide.links_delay = 300;
827    ConfigServerHide.hidden = 0;
1884  ConfigServerHide.disable_hidden = 0;
828    ConfigServerHide.hide_servers = 0;
829 <  DupString(ConfigServerHide.hidden_name, NETWORK_NAME_DEFAULT);
829 >  ConfigServerHide.hide_services = 0;
830 >  ConfigServerHide.hidden_name = xstrdup(NETWORK_NAME_DEFAULT);
831    ConfigServerHide.hide_server_ips = 0;
832 +  ConfigServerHide.disable_remote_commands = 0;
833  
834 <  
835 <  DupString(ConfigFileEntry.service_name, SERVICE_NAME_DEFAULT);
836 <  ConfigFileEntry.max_watch = WATCHSIZE_DEFAULT;
837 <  ConfigFileEntry.gline_min_cidr = 16;
838 <  ConfigFileEntry.gline_min_cidr6 = 48;
839 <  ConfigFileEntry.invisible_on_connect = 1;
840 <  ConfigFileEntry.burst_away = 0;
841 <  ConfigFileEntry.use_whois_actually = 1;
842 <  ConfigFileEntry.tkline_expire_notices = 1;
843 <  ConfigFileEntry.hide_spoof_ips = 1;
844 <  ConfigFileEntry.ignore_bogus_ts = 0;
845 <  ConfigFileEntry.disable_auth = 0;
846 <  ConfigFileEntry.disable_remote = 0;
847 <  ConfigFileEntry.kill_chase_time_limit = 90;
848 <  ConfigFileEntry.default_floodcount = 8;
849 <  ConfigFileEntry.failed_oper_notice = 1;
850 <  ConfigFileEntry.dots_in_ident = 0;
851 <  ConfigFileEntry.min_nonwildcard = 4;
852 <  ConfigFileEntry.min_nonwildcard_simple = 3;
853 <  ConfigFileEntry.max_accept = 20;
854 <  ConfigFileEntry.anti_nick_flood = 0;
855 <  ConfigFileEntry.max_nick_time = 20;
856 <  ConfigFileEntry.max_nick_changes = 5;
857 <  ConfigFileEntry.anti_spam_exit_message_time = 0;
858 <  ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
859 <  ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
860 <  ConfigFileEntry.kline_with_reason = 1;
861 <  ConfigFileEntry.kline_reason = NULL;
862 <  ConfigFileEntry.warn_no_nline = 1;
863 <  ConfigFileEntry.stats_o_oper_only = 0;
864 <  ConfigFileEntry.stats_k_oper_only = 1;  /* masked */
865 <  ConfigFileEntry.stats_i_oper_only = 1;  /* masked */
866 <  ConfigFileEntry.stats_P_oper_only = 0;
867 <  ConfigFileEntry.caller_id_wait = 60;
868 <  ConfigFileEntry.opers_bypass_callerid = 0;
869 <  ConfigFileEntry.pace_wait = 10;
870 <  ConfigFileEntry.pace_wait_simple = 1;
871 <  ConfigFileEntry.short_motd = 0;
872 <  ConfigFileEntry.ping_cookie = 0;
873 <  ConfigFileEntry.no_oper_flood = 0;
874 <  ConfigFileEntry.true_no_oper_flood = 0;
875 <  ConfigFileEntry.oper_pass_resv = 1;
876 <  ConfigFileEntry.glines = 0;
877 <  ConfigFileEntry.gline_time = 12 * 3600;
878 <  ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT;
879 <  ConfigFileEntry.client_flood = CLIENT_FLOOD_DEFAULT;
880 <  ConfigFileEntry.oper_only_umodes = UMODE_DEBUG;
881 <  ConfigFileEntry.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE |
1937 <    UMODE_OPERWALL | UMODE_WALLOP;
1938 <  ConfigFileEntry.use_egd = 0;
1939 <  ConfigFileEntry.egdpool_path = NULL;
1940 <  ConfigFileEntry.throttle_time = 10;
834 >  ConfigGeneral.away_count = 2;
835 >  ConfigGeneral.away_time = 10;
836 >  ConfigGeneral.max_watch = WATCHSIZE_DEFAULT;
837 >  ConfigGeneral.cycle_on_host_change = 1;
838 >  ConfigGeneral.dline_min_cidr = 16;
839 >  ConfigGeneral.dline_min_cidr6 = 48;
840 >  ConfigGeneral.kline_min_cidr = 16;
841 >  ConfigGeneral.kline_min_cidr6 = 48;
842 >  ConfigGeneral.invisible_on_connect = 1;
843 >  ConfigGeneral.tkline_expire_notices = 1;
844 >  ConfigGeneral.ignore_bogus_ts = 0;
845 >  ConfigGeneral.disable_auth = 0;
846 >  ConfigGeneral.kill_chase_time_limit = 90;
847 >  ConfigGeneral.default_floodcount = 8;
848 >  ConfigGeneral.failed_oper_notice = 1;
849 >  ConfigGeneral.dots_in_ident = 0;
850 >  ConfigGeneral.min_nonwildcard = 4;
851 >  ConfigGeneral.min_nonwildcard_simple = 3;
852 >  ConfigGeneral.max_accept = 20;
853 >  ConfigGeneral.anti_nick_flood = 0;
854 >  ConfigGeneral.max_nick_time = 20;
855 >  ConfigGeneral.max_nick_changes = 5;
856 >  ConfigGeneral.anti_spam_exit_message_time = 0;
857 >  ConfigGeneral.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
858 >  ConfigGeneral.ts_max_delta = TS_MAX_DELTA_DEFAULT;
859 >  ConfigGeneral.warn_no_connect_block = 1;
860 >  ConfigGeneral.stats_e_disabled = 0;
861 >  ConfigGeneral.stats_i_oper_only = 1;  /* 1 = masked */
862 >  ConfigGeneral.stats_k_oper_only = 1;  /* 1 = masked */
863 >  ConfigGeneral.stats_o_oper_only = 1;
864 >  ConfigGeneral.stats_m_oper_only = 1;
865 >  ConfigGeneral.stats_P_oper_only = 0;
866 >  ConfigGeneral.stats_u_oper_only = 0;
867 >  ConfigGeneral.caller_id_wait = 60;
868 >  ConfigGeneral.opers_bypass_callerid = 0;
869 >  ConfigGeneral.pace_wait = 10;
870 >  ConfigGeneral.pace_wait_simple = 1;
871 >  ConfigGeneral.short_motd = 0;
872 >  ConfigGeneral.ping_cookie = 0;
873 >  ConfigGeneral.no_oper_flood = 0;
874 >  ConfigGeneral.oper_pass_resv = 1;
875 >  ConfigGeneral.max_targets = MAX_TARGETS_DEFAULT;
876 >  ConfigGeneral.oper_only_umodes = UMODE_DEBUG | UMODE_LOCOPS | UMODE_HIDDEN | UMODE_FARCONNECT |
877 >                                   UMODE_UNAUTH | UMODE_EXTERNAL | UMODE_BOTS | UMODE_NCHANGE |
878 >                                   UMODE_SPY | UMODE_FULL | UMODE_SKILL | UMODE_REJ | UMODE_CCONN;
879 >  ConfigGeneral.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE | UMODE_WALLOP;
880 >  ConfigGeneral.throttle_count = 1;
881 >  ConfigGeneral.throttle_time = 1;
882   }
883  
884   static void
885   validate_conf(void)
886   {
887 <  if (ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN)
888 <    ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
1948 <
1949 <  if (ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN)
1950 <    ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
887 >  if (ConfigGeneral.ts_warn_delta < TS_WARN_DELTA_MIN)
888 >    ConfigGeneral.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
889  
890 <  if (ServerInfo.network_name == NULL)
891 <    DupString(ServerInfo.network_name,NETWORK_NAME_DEFAULT);
890 >  if (ConfigGeneral.ts_max_delta < TS_MAX_DELTA_MIN)
891 >    ConfigGeneral.ts_max_delta = TS_MAX_DELTA_DEFAULT;
892  
893 <  if (ServerInfo.network_desc == NULL)
894 <    DupString(ServerInfo.network_desc,NETWORK_DESC_DEFAULT);
893 >  if (EmptyString(ConfigServerInfo.network_name))
894 >    ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
895  
896 <  if (ConfigFileEntry.service_name == NULL)
897 <    DupString(ConfigFileEntry.service_name, SERVICE_NAME_DEFAULT);
896 >  if (EmptyString(ConfigServerInfo.network_desc))
897 >    ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
898  
899 <  if ((ConfigFileEntry.client_flood < CLIENT_FLOOD_MIN) ||
1962 <      (ConfigFileEntry.client_flood > CLIENT_FLOOD_MAX))
1963 <    ConfigFileEntry.client_flood = CLIENT_FLOOD_MAX;
1964 <
1965 <  ConfigFileEntry.max_watch = IRCD_MAX(ConfigFileEntry.max_watch, WATCHSIZE_MIN);
899 >  ConfigGeneral.max_watch = IRCD_MAX(ConfigGeneral.max_watch, WATCHSIZE_MIN);
900   }
901  
902 < /* read_conf()
902 > /* read_conf()
903   *
904   * inputs       - file descriptor pointing to config file to use
905   * output       - None
# Line 1976 | Line 910 | read_conf(FILE *file)
910   {
911    lineno = 0;
912  
913 <  set_default_conf(); /* Set default values prior to conf parsing */
913 >  set_default_conf();  /* Set default values prior to conf parsing */
914    conf_parser_ctx.pass = 1;
915 <  yyparse();          /* pick up the classes first */
915 >  yyparse();  /* Pick up the classes first */
916  
917    rewind(file);
918  
919    conf_parser_ctx.pass = 2;
920 <  yyparse();          /* Load the values from the conf */
921 <  validate_conf();    /* Check to make sure some values are still okay. */
922 <                      /* Some global values are also loaded here. */
923 <  check_class();      /* Make sure classes are valid */
920 >  yyparse();  /* Load the values from the conf */
921 >  validate_conf();  /* Check to make sure some values are still okay. */
922 >                    /* Some global values are also loaded here. */
923 >  class_delete_marked();  /* Delete unused classes that are marked for deletion */
924 > }
925 >
926 > /* conf_rehash()
927 > *
928 > * Actual REHASH service routine. Called with sig == 0 if it has been called
929 > * as a result of an operator issuing this command, else assume it has been
930 > * called as a result of the server receiving a HUP signal.
931 > */
932 > void
933 > conf_rehash(int sig)
934 > {
935 >  if (sig)
936 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
937 >                         "Got signal SIGHUP, reloading configuration file(s)");
938 >
939 >  restart_resolver();
940 >
941 >  /* don't close listeners until we know we can go ahead with the rehash */
942 >
943 >  read_conf_files(0);
944 >
945 >  load_conf_modules();
946 >  check_conf_klines();
947   }
948  
949   /* lookup_confhost()
# Line 1994 | Line 951 | read_conf(FILE *file)
951   * start DNS lookups of all hostnames in the conf
952   * line and convert an IP addresses in a.b.c.d number for to IP#s.
953   */
954 < static void
955 < lookup_confhost(struct ConfItem *conf)
954 > void
955 > lookup_confhost(struct MaskItem *conf)
956   {
2000  struct AccessItem *aconf;
957    struct addrinfo hints, *res;
958  
959 <  aconf = map_to_conf(conf);
960 <
2005 <  if (EmptyString(aconf->host) ||
2006 <      EmptyString(aconf->user))
2007 <  {
2008 <    ilog(LOG_TYPE_IRCD, "Host/server name error: (%s) (%s)",
2009 <         aconf->host, conf->name);
2010 <    return;
2011 <  }
2012 <
2013 <  if (strchr(aconf->host, '*') ||
2014 <      strchr(aconf->host, '?'))
2015 <    return;
2016 <
2017 <  /* Do name lookup now on hostnames given and store the
959 >  /*
960 >   * Do name lookup now on hostnames given and store the
961     * ip numbers in conf structure.
962     */
963    memset(&hints, 0, sizeof(hints));
# Line 2025 | Line 968 | lookup_confhost(struct ConfItem *conf)
968    /* Get us ready for a bind() and don't bother doing dns lookup */
969    hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
970  
971 <  if (getaddrinfo(aconf->host, NULL, &hints, &res))
971 >  if (getaddrinfo(conf->host, NULL, &hints, &res))
972    {
973 <    conf_dns_lookup(aconf);
973 >    conf_dns_lookup(conf);
974      return;
975    }
976  
977 <  assert(res != NULL);
977 >  assert(res);
978 >
979 >  memcpy(&conf->addr, res->ai_addr, res->ai_addrlen);
980 >  conf->addr.ss_len = res->ai_addrlen;
981 >  conf->addr.ss.ss_family = res->ai_family;
982  
2036  memcpy(&aconf->ipnum, res->ai_addr, res->ai_addrlen);
2037  aconf->ipnum.ss_len = res->ai_addrlen;
2038  aconf->ipnum.ss.ss_family = res->ai_family;
983    freeaddrinfo(res);
984   }
985  
# Line 2049 | Line 993 | lookup_confhost(struct ConfItem *conf)
993   int
994   conf_connect_allowed(struct irc_ssaddr *addr, int aftype)
995   {
996 <  struct ip_entry *ip_found;
997 <  struct AccessItem *aconf = find_dline_conf(addr, aftype);
996 >  struct ip_entry *ip_found = NULL;
997 >  struct MaskItem *const conf = find_dline_conf(addr, aftype);
998  
999    /* DLINE exempt also gets you out of static limits/pacing... */
1000 <  if (aconf && (aconf->status & CONF_EXEMPTDLINE))
1000 >  if (conf && (conf->type == CONF_EXEMPT))
1001      return 0;
1002  
1003 <  if (aconf != NULL)
1003 >  if (conf)
1004      return BANNED_CLIENT;
1005  
1006 <  ip_found = find_or_add_ip(addr);
1006 >  ip_found = ipcache_find_or_add_address(addr);
1007  
1008 <  if ((CurrentTime - ip_found->last_attempt) <
2065 <      ConfigFileEntry.throttle_time)
1008 >  if ((CurrentTime - ip_found->last_attempt) < ConfigGeneral.throttle_time)
1009    {
1010 <    ip_found->last_attempt = CurrentTime;
1011 <    return TOO_FAST;
1010 >    if (ip_found->connection_count >= ConfigGeneral.throttle_count)
1011 >      return TOO_FAST;
1012 >
1013 >    ++ip_found->connection_count;
1014    }
1015 +  else
1016 +    ip_found->connection_count = 1;
1017  
1018    ip_found->last_attempt = CurrentTime;
1019    return 0;
1020   }
1021  
1022 < static struct AccessItem *
2076 < find_regexp_kline(const char *uhi[])
2077 < {
2078 < #ifdef HAVE_LIBPCRE
2079 <  const dlink_node *ptr = NULL;
2080 <
2081 <  DLINK_FOREACH(ptr, rkconf_items.head)
2082 <  {
2083 <    struct AccessItem *aptr = map_to_conf(ptr->data);
2084 <
2085 <    assert(aptr->regexuser);
2086 <    assert(aptr->regexhost);
2087 <
2088 <    if (!ircd_pcre_exec(aptr->regexuser, uhi[0]) &&
2089 <        (!ircd_pcre_exec(aptr->regexhost, uhi[1]) ||
2090 <         !ircd_pcre_exec(aptr->regexhost, uhi[2])))
2091 <      return aptr;
2092 <  }
2093 < #endif
2094 <  return NULL;
2095 < }
2096 <
2097 < /* find_kill()
1022 > /* expire_tklines()
1023   *
1024 < * inputs       - pointer to client structure
1025 < * output       - pointer to struct AccessItem if found
1026 < * side effects - See if this user is klined already,
2102 < *                and if so, return struct AccessItem pointer
1024 > * inputs       - tkline list pointer
1025 > * output       - NONE
1026 > * side effects - expire tklines
1027   */
1028 < struct AccessItem *
1029 < find_kill(struct Client *client_p)
2106 < {
2107 <  struct AccessItem *aconf = NULL;
2108 <  const char *uhi[3];
2109 <
2110 <  uhi[0] = client_p->username;
2111 <  uhi[1] = client_p->host;
2112 <  uhi[2] = client_p->sockhost;
2113 <
2114 <  assert(client_p != NULL);
2115 <
2116 <  aconf = find_kline_conf(client_p->host, client_p->username,
2117 <                          &client_p->localClient->ip,
2118 <                          client_p->localClient->aftype);
2119 <  if (aconf == NULL)
2120 <    aconf = find_regexp_kline(uhi);
2121 <
2122 <  if (aconf && (aconf->status & CONF_KLINE))
2123 <    return aconf;
2124 <
2125 <  return NULL;
2126 < }
2127 <
2128 < struct AccessItem *
2129 < find_gline(struct Client *client_p)
1028 > static void
1029 > expire_tklines(dlink_list *list)
1030   {
1031 <  struct AccessItem *aconf;
2132 <
2133 <  assert(client_p != NULL);
1031 >  dlink_node *node = NULL, *node_next = NULL;
1032  
1033 <  aconf = find_gline_conf(client_p->host, client_p->username,
1034 <                          &client_p->localClient->ip,
1035 <                          client_p->localClient->aftype);
2138 <
2139 <  if (aconf && (aconf->status & CONF_GLINE))
2140 <    return aconf;
2141 <
2142 <  return NULL;
2143 < }
1033 >  DLINK_FOREACH_SAFE(node, node_next, list->head)
1034 >  {
1035 >    struct MaskItem *conf = node->data;
1036  
1037 < /* add_temp_line()
1038 < *
2147 < * inputs        - pointer to struct ConfItem
2148 < * output        - none
2149 < * Side effects  - links in given struct ConfItem into
2150 < *                 temporary *line link list
2151 < */
2152 < void
2153 < add_temp_line(struct ConfItem *conf)
2154 < {
2155 <  struct AccessItem *aconf;
1037 >    if (!conf->until || conf->until > CurrentTime)
1038 >      continue;
1039  
1040 <  if (conf->type == DLINE_TYPE)
1041 <  {
1042 <    aconf = map_to_conf(conf);
1043 <    SetConfTemporary(aconf);
2161 <    dlinkAdd(conf, &conf->node, &temporary_dlines);
2162 <    MyFree(aconf->user);
2163 <    aconf->user = NULL;
2164 <    add_conf_by_address(CONF_DLINE, aconf);
2165 <  }
2166 <  else if (conf->type == KLINE_TYPE)
2167 <  {
2168 <    aconf = map_to_conf(conf);
2169 <    SetConfTemporary(aconf);
2170 <    dlinkAdd(conf, &conf->node, &temporary_klines);
2171 <    add_conf_by_address(CONF_KILL, aconf);
2172 <  }
2173 <  else if (conf->type == GLINE_TYPE)
2174 <  {
2175 <    aconf = map_to_conf(conf);
2176 <    SetConfTemporary(aconf);
2177 <    dlinkAdd(conf, &conf->node, &temporary_glines);
2178 <    add_conf_by_address(CONF_GLINE, aconf);
2179 <  }
2180 <  else if (conf->type == XLINE_TYPE)
2181 <  {
2182 <    conf->flags |= CONF_FLAGS_TEMPORARY;
2183 <    dlinkAdd(conf, make_dlink_node(), &temporary_xlines);
2184 <  }
2185 <  else if ((conf->type == NRESV_TYPE) || (conf->type == CRESV_TYPE))
2186 <  {
2187 <    conf->flags |= CONF_FLAGS_TEMPORARY;
2188 <    dlinkAdd(conf, make_dlink_node(), &temporary_resv);
1040 >    if (ConfigGeneral.tkline_expire_notices)
1041 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "Temporary %s for [%s] expired",
1042 >                           (conf->type == CONF_XLINE) ? "X-line" : "RESV", conf->name);
1043 >    conf_free(conf);
1044    }
1045   }
1046  
# Line 2197 | Line 1052 | add_temp_line(struct ConfItem *conf)
1052   *                This is an event started off in ircd.c
1053   */
1054   void
1055 < cleanup_tklines(void *notused)
1055 > cleanup_tklines(void *unused)
1056   {
1057 <  expire_tklines(&temporary_glines);
1058 <  expire_tklines(&temporary_klines);
1059 <  expire_tklines(&temporary_dlines);
1060 <  expire_tklines(&temporary_xlines);
2206 <  expire_tklines(&temporary_resv);
2207 < }
2208 <
2209 < /* expire_tklines()
2210 < *
2211 < * inputs       - tkline list pointer
2212 < * output       - NONE
2213 < * side effects - expire tklines
2214 < */
2215 < static void
2216 < expire_tklines(dlink_list *tklist)
2217 < {
2218 <  dlink_node *ptr;
2219 <  dlink_node *next_ptr;
2220 <  struct ConfItem *conf;
2221 <  struct MatchItem *xconf;
2222 <  struct MatchItem *nconf;
2223 <  struct AccessItem *aconf;
2224 <  struct ResvChannel *cconf;
2225 <
2226 <  DLINK_FOREACH_SAFE(ptr, next_ptr, tklist->head)
2227 <  {
2228 <    conf = ptr->data;
2229 <    if (conf->type == GLINE_TYPE ||
2230 <        conf->type == KLINE_TYPE ||
2231 <        conf->type == DLINE_TYPE)
2232 <    {
2233 <      aconf = (struct AccessItem *)map_to_conf(conf);
2234 <      if (aconf->hold <= CurrentTime)
2235 <      {
2236 <        /* XXX - Do we want GLINE expiry notices?? */
2237 <        /* Alert opers that a TKline expired - Hwy */
2238 <        if (ConfigFileEntry.tkline_expire_notices)
2239 <        {
2240 <          if (aconf->status & CONF_KILL)
2241 <          {
2242 <            sendto_realops_flags(UMODE_ALL, L_ALL,
2243 <                                 "Temporary K-line for [%s@%s] expired",
2244 <                                 (aconf->user) ? aconf->user : "*",
2245 <                                 (aconf->host) ? aconf->host : "*");
2246 <          }
2247 <          else if (conf->type == DLINE_TYPE)
2248 <          {
2249 <            sendto_realops_flags(UMODE_ALL, L_ALL,
2250 <                                 "Temporary D-line for [%s] expired",
2251 <                                 (aconf->host) ? aconf->host : "*");
2252 <          }
2253 <        }
2254 <
2255 <        dlinkDelete(ptr, tklist);
2256 <        delete_one_address_conf(aconf->host, aconf);
2257 <      }
2258 <    }
2259 <    else if (conf->type == XLINE_TYPE ||
2260 <             conf->type == RXLINE_TYPE)
2261 <    {
2262 <      xconf = (struct MatchItem *)map_to_conf(conf);
2263 <      if (xconf->hold <= CurrentTime)
2264 <      {
2265 <        if (ConfigFileEntry.tkline_expire_notices)
2266 <          sendto_realops_flags(UMODE_ALL, L_ALL,
2267 <                               "Temporary X-line for [%s] %sexpired", conf->name,
2268 <                               conf->type == RXLINE_TYPE ? "(REGEX) " : "");
2269 <        dlinkDelete(ptr, tklist);
2270 <        free_dlink_node(ptr);
2271 <        delete_conf_item(conf);
2272 <      }
2273 <    }
2274 <    else if (conf->type == RKLINE_TYPE)
2275 <    {
2276 <      aconf = map_to_conf(conf);
2277 <      if (aconf->hold <= CurrentTime)
2278 <      {
2279 <        if (ConfigFileEntry.tkline_expire_notices)
2280 <           sendto_realops_flags(UMODE_ALL, L_ALL,
2281 <                                "Temporary K-line for [%s@%s] (REGEX) expired",
2282 <                                (aconf->user) ? aconf->user : "*",
2283 <                                (aconf->host) ? aconf->host : "*");
2284 <        dlinkDelete(ptr, tklist);
2285 <        free_dlink_node(ptr);
2286 <        delete_conf_item(conf);
2287 <      }
2288 <    }
2289 <    else if (conf->type == NRESV_TYPE)
2290 <    {
2291 <      nconf = (struct MatchItem *)map_to_conf(conf);
2292 <      if (nconf->hold <= CurrentTime)
2293 <      {
2294 <        if (ConfigFileEntry.tkline_expire_notices)
2295 <          sendto_realops_flags(UMODE_ALL, L_ALL,
2296 <                               "Temporary RESV for [%s] expired", conf->name);
2297 <        dlinkDelete(ptr, tklist);
2298 <        free_dlink_node(ptr);
2299 <        delete_conf_item(conf);
2300 <      }
2301 <    }
2302 <    else if (conf->type == CRESV_TYPE)
2303 <    {
2304 <      cconf = (struct ResvChannel *)map_to_conf(conf);
2305 <      if (cconf->hold <= CurrentTime)
2306 <      {
2307 <        if (ConfigFileEntry.tkline_expire_notices)
2308 <          sendto_realops_flags(UMODE_ALL, L_ALL,
2309 <                               "Temporary RESV for [%s] expired", cconf->name);
2310 <        delete_channel_resv(cconf);
2311 <      }
2312 <    }
2313 <  }
1057 >  hostmask_expire_temporary();
1058 >  expire_tklines(&xconf_items);
1059 >  expire_tklines(&nresv_items);
1060 >  expire_tklines(&cresv_items);
1061   }
1062  
1063   /* oper_privs_as_string()
# Line 2321 | Line 1068 | expire_tklines(dlink_list *tklist)
1068   */
1069   static const struct oper_privs
1070   {
1071 <  const unsigned int oprivs;
1071 >  const unsigned int flag;
1072    const unsigned char c;
1073   } flag_list[] = {
1074 <  { OPER_FLAG_ADMIN,       'A' },
1075 <  { OPER_FLAG_REMOTEBAN,   'B' },
1076 <  { OPER_FLAG_DIE,         'D' },
1077 <  { OPER_FLAG_GLINE,       'G' },
1078 <  { OPER_FLAG_REHASH,      'H' },
1079 <  { OPER_FLAG_K,           'K' },
1080 <  { OPER_FLAG_OPERWALL,    'L' },
1081 <  { OPER_FLAG_N,           'N' },
1082 <  { OPER_FLAG_GLOBAL_KILL, 'O' },
1083 <  { OPER_FLAG_REMOTE,      'R' },
1084 <  { OPER_FLAG_OPER_SPY,    'S' },
1085 <  { OPER_FLAG_UNKLINE,     'U' },
1086 <  { OPER_FLAG_X,           'X' },
1074 >  { OPER_FLAG_ADMIN,          'A' },
1075 >  { OPER_FLAG_REMOTEBAN,      'B' },
1076 >  { OPER_FLAG_DIE,            'D' },
1077 >  { OPER_FLAG_REHASH,         'H' },
1078 >  { OPER_FLAG_KLINE,          'K' },
1079 >  { OPER_FLAG_KILL,           'N' },
1080 >  { OPER_FLAG_KILL_REMOTE,    'O' },
1081 >  { OPER_FLAG_CONNECT,        'P' },
1082 >  { OPER_FLAG_CONNECT_REMOTE, 'Q' },
1083 >  { OPER_FLAG_SQUIT,          'R' },
1084 >  { OPER_FLAG_SQUIT_REMOTE,   'S' },
1085 >  { OPER_FLAG_UNKLINE,        'U' },
1086 >  { OPER_FLAG_XLINE,          'X' },
1087    { 0, '\0' }
1088   };
1089  
1090 < char *
1090 > const char *
1091   oper_privs_as_string(const unsigned int port)
1092   {
1093 <  static char privs_out[16];
1093 >  static char privs_out[IRCD_BUFSIZE];
1094    char *privs_ptr = privs_out;
2348  unsigned int i = 0;
1095  
1096 <  for (; flag_list[i].oprivs; ++i)
1096 >  for (const struct oper_privs *opriv = flag_list; opriv->flag; ++opriv)
1097    {
1098 <    if (port & flag_list[i].oprivs)
1099 <      *privs_ptr++ = flag_list[i].c;
1098 >    if (port & opriv->flag)
1099 >      *privs_ptr++ = opriv->c;
1100      else
1101 <      *privs_ptr++ = ToLowerTab[flag_list[i].c];
1101 >      *privs_ptr++ = ToLower(opriv->c);
1102    }
1103  
1104    *privs_ptr = '\0';
# Line 2361 | Line 1107 | oper_privs_as_string(const unsigned int
1107   }
1108  
1109   /*
1110 < * Input: A client to find the active oper{} name for.
1110 > * Input: A client to find the active operator {} name for.
1111   * Output: The nick!user@host{oper} of the oper.
1112   *         "oper" is server name for remote opers
1113   * Side effects: None.
# Line 2369 | Line 1115 | oper_privs_as_string(const unsigned int
1115   const char *
1116   get_oper_name(const struct Client *client_p)
1117   {
1118 <  dlink_node *cnode = NULL;
1119 <  /* +5 for !,@,{,} and null */
1120 <  static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5];
1118 >  static char buffer[IRCD_BUFSIZE];
1119 >
1120 >  if (IsServer(client_p))
1121 >    return client_p->name;
1122  
1123    if (MyConnect(client_p))
1124    {
1125 <    if ((cnode = client_p->localClient->confs.head))
1125 >    const dlink_node *const node = client_p->connection->confs.head;
1126 >
1127 >    if (node)
1128      {
1129 <      struct ConfItem *conf = cnode->data;
2381 <      const struct AccessItem *aconf = map_to_conf(conf);
1129 >      const struct MaskItem *const conf = node->data;
1130  
1131 <      if (IsConfOperator(aconf))
1131 >      if (conf->type == CONF_OPER)
1132        {
1133 <        snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1133 >        snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1134                   client_p->username, client_p->host, conf->name);
1135 <        return buffer;
1135 >        return buffer;
1136        }
1137      }
1138  
1139 <    /* Probably should assert here for now. If there is an oper out there
1140 <     * with no oper{} conf attached, it would be good for us to know...
1139 >    /*
1140 >     * Probably should assert here for now. If there is an oper out there
1141 >     * with no operator {} conf attached, it would be good for us to know...
1142       */
1143 <    assert(0); /* Oper without oper conf! */
1143 >    assert(0);  /* Oper without oper conf! */
1144    }
1145  
1146    snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1147 <           client_p->username, client_p->host, client_p->servptr->name);
1147 >           client_p->username, client_p->host, client_p->servptr->name);
1148    return buffer;
1149   }
1150  
2402 /* read_conf_files()
2403 *
2404 * inputs       - cold start YES or NO
2405 * output       - none
2406 * side effects - read all conf files needed, ircd.conf kline.conf etc.
2407 */
2408 void
2409 read_conf_files(int cold)
2410 {
2411  const char *filename;
2412  char chanmodes[32];
2413  char chanlimit[32];
2414
2415  conf_parser_ctx.boot = cold;
2416  filename = get_conf_name(CONF_TYPE);
2417
2418  /* We need to know the initial filename for the yyerror() to report
2419     FIXME: The full path is in conffilenamebuf first time since we
2420             dont know anything else
2421
2422     - Gozem 2002-07-21
2423  */
2424  strlcpy(conffilebuf, filename, sizeof(conffilebuf));
2425
2426  if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL)
2427  {
2428    if (cold)
2429    {
2430      ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
2431           filename, strerror(errno));
2432      exit(-1);
2433    }
2434    else
2435    {
2436      sendto_realops_flags(UMODE_ALL, L_ALL,
2437                           "Unable to read configuration file '%s': %s",
2438                           filename, strerror(errno));
2439      return;
2440    }
2441  }
2442
2443  if (!cold)
2444    clear_out_old_conf();
2445
2446  read_conf(conf_parser_ctx.conf_file);
2447  fclose(conf_parser_ctx.conf_file);
2448
2449  add_isupport("NETWORK", ServerInfo.network_name, -1);
2450  snprintf(chanmodes, sizeof(chanmodes), "b%s%s:%d",
2451           ConfigChannel.use_except ? "e" : "",
2452           ConfigChannel.use_invex ? "I" : "", ConfigChannel.max_bans);
2453  add_isupport("MAXLIST", chanmodes, -1);
2454  add_isupport("MAXTARGETS", NULL, ConfigFileEntry.max_targets);
2455
2456  if (ConfigChannel.disable_local_channels)
2457    add_isupport("CHANTYPES", "#", -1);
2458  else
2459    add_isupport("CHANTYPES", "#&", -1);
2460
2461  snprintf(chanlimit, sizeof(chanlimit), "%s:%d",
2462           ConfigChannel.disable_local_channels ? "#" : "#&",
2463           ConfigChannel.max_chans_per_user);
2464  add_isupport("CHANLIMIT", chanlimit, -1);
2465  snprintf(chanmodes, sizeof(chanmodes), "%s%s%s",
2466           ConfigChannel.use_except ? "e" : "",
2467           ConfigChannel.use_invex ? "I" : "", "b,k,l,imnprstORS");
2468  add_isupport("CHANNELLEN", NULL, LOCAL_CHANNELLEN);
2469
2470  if (ConfigChannel.use_except)
2471    add_isupport("EXCEPTS", "e", -1);
2472  if (ConfigChannel.use_invex)
2473    add_isupport("INVEX", "I", -1);
2474  add_isupport("CHANMODES", chanmodes, -1);
2475
2476  /*
2477   * message_locale may have changed.  rebuild isupport since it relies
2478   * on strlen(form_str(RPL_ISUPPORT))
2479   */
2480  rebuild_isupport_message_line();
2481
2482 #ifdef HAVE_LIBPCRE
2483  parse_conf_file(RKLINE_TYPE, cold);
2484  parse_conf_file(RXLINE_TYPE, cold);
2485 #endif
2486  parse_conf_file(KLINE_TYPE, cold);
2487  parse_conf_file(DLINE_TYPE, cold);
2488  parse_conf_file(XLINE_TYPE, cold);
2489  parse_conf_file(NRESV_TYPE, cold);
2490  parse_conf_file(CRESV_TYPE, cold);
2491 }
2492
2493 /* parse_conf_file()
2494 *
2495 * inputs       - type of conf file to parse
2496 * output       - none
2497 * side effects - conf file for givenconf type is opened and read then parsed
2498 */
2499 static void
2500 parse_conf_file(int type, int cold)
2501 {
2502  FILE *file = NULL;
2503  const char *filename = get_conf_name(type);
2504
2505  if ((file = fopen(filename, "r")) == NULL)
2506  {
2507    if (cold)
2508      ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
2509           filename, strerror(errno));
2510    else
2511      sendto_realops_flags(UMODE_ALL, L_ALL,
2512                    "Unable to read configuration file '%s': %s",
2513                           filename, strerror(errno));
2514  }
2515  else
2516  {
2517    parse_csv_file(file, type);
2518    fclose(file);
2519  }
2520 }
2521
1151   /* clear_out_old_conf()
1152   *
1153   * inputs       - none
# Line 2528 | Line 1157 | parse_conf_file(int type, int cold)
1157   static void
1158   clear_out_old_conf(void)
1159   {
1160 <  dlink_node *ptr = NULL, *next_ptr = NULL;
2532 <  struct ConfItem *conf;
2533 <  struct AccessItem *aconf;
2534 <  struct ClassItem *cltmp;
2535 <  struct MatchItem *match_item;
1160 >  dlink_node *node = NULL, *node_next = NULL;
1161    dlink_list *free_items [] = {
1162 <    &server_items,   &oconf_items,    &hub_items, &leaf_items,
1163 <     &uconf_items,   &xconf_items, &rxconf_items, &rkconf_items,
1164 <     &nresv_items, &cluster_items,  &gdeny_items, &service_items, NULL
1162 >    &server_items,   &oconf_items,
1163 >     &uconf_items,   &xconf_items,
1164 >     &nresv_items, &cluster_items,  &service_items, &cresv_items, NULL
1165    };
1166  
1167    dlink_list ** iterator = free_items; /* C is dumb */
# Line 2544 | Line 1169 | clear_out_old_conf(void)
1169    /* We only need to free anything allocated by yyparse() here.
1170     * Resetting structs, etc, is taken care of by set_default_conf().
1171     */
1172 <  
1173 <  for (; *iterator != NULL; iterator++)
1172 >
1173 >  for (; *iterator; iterator++)
1174    {
1175 <    DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head)
1175 >    DLINK_FOREACH_SAFE(node, node_next, (*iterator)->head)
1176      {
1177 <      conf = ptr->data;
2553 <      /* XXX This is less than pretty */
2554 <      if (conf->type == SERVER_TYPE)
2555 <      {
2556 <        aconf = map_to_conf(conf);
1177 >      struct MaskItem *conf = node->data;
1178  
1179 <        if (aconf->clients != 0)
2559 <        {
2560 <          SetConfIllegal(aconf);
2561 <          dlinkDelete(&conf->node, &server_items);
2562 <        }
2563 <        else
2564 <        {
2565 <          delete_conf_item(conf);
2566 <        }
2567 <      }
2568 <      else if (conf->type == OPER_TYPE)
2569 <      {
2570 <        aconf = map_to_conf(conf);
1179 >      conf->active = 0;
1180  
1181 <        if (aconf->clients != 0)
2573 <        {
2574 <          SetConfIllegal(aconf);
2575 <          dlinkDelete(&conf->node, &oconf_items);
2576 <        }
2577 <        else
2578 <        {
2579 <          delete_conf_item(conf);
2580 <        }
2581 <      }
2582 <      else if (conf->type == CLIENT_TYPE)
1181 >      if (!IsConfDatabase(conf))
1182        {
1183 <        aconf = map_to_conf(conf);
1183 >        dlinkDelete(&conf->node, *iterator);
1184  
1185 <        if (aconf->clients != 0)
1186 <        {
2588 <          SetConfIllegal(aconf);
2589 <        }
2590 <        else
2591 <        {
2592 <          delete_conf_item(conf);
2593 <        }
2594 <      }
2595 <      else if (conf->type == XLINE_TYPE  ||
2596 <               conf->type == RXLINE_TYPE ||
2597 <               conf->type == RKLINE_TYPE)
2598 <      {
2599 <        /* temporary (r)xlines are also on
2600 <         * the (r)xconf items list */
2601 <        if (conf->flags & CONF_FLAGS_TEMPORARY)
2602 <          continue;
2603 <
2604 <        delete_conf_item(conf);
2605 <      }
2606 <      else
2607 <      {
2608 <        if ((conf->type == LEAF_TYPE) || (conf->type == HUB_TYPE))
2609 <        {
2610 <          match_item = map_to_conf(conf);
2611 <          if (match_item->ref_count <= 0)
2612 <            delete_conf_item(conf);
2613 <          else
2614 <          {
2615 <            match_item->illegal = 1;
2616 <            dlinkDelete(&conf->node, *iterator);
2617 <          }
2618 <        }
2619 <        else
2620 <          delete_conf_item(conf);
1185 >        if (!conf->ref_count)
1186 >          conf_free(conf);
1187        }
1188      }
1189    }
1190  
1191 +  motd_clear();
1192 +
1193    /*
1194 <   * don't delete the class table, rather mark all entries
1195 <   * for deletion. The table is cleaned up by check_class. - avalon
1194 >   * Don't delete the class table, rather mark all entries for deletion.
1195 >   * The table is cleaned up by class_delete_marked. - avalon
1196     */
1197 <  DLINK_FOREACH(ptr, class_items.head)
2630 <  {
2631 <    cltmp = map_to_conf(ptr->data);
2632 <
2633 <    if (ptr != class_items.tail)  /* never mark the "default" class */
2634 <      cltmp->active = 0;
2635 <  }
1197 >  class_mark_for_deletion();
1198  
1199    clear_out_address_conf();
1200  
1201 <  /* clean out module paths */
1201 >  /* Clean out module paths */
1202    mod_clear_paths();
1203  
1204 <  /* clean out ServerInfo */
1205 <  MyFree(ServerInfo.description);
1206 <  ServerInfo.description = NULL;
1207 <  MyFree(ServerInfo.network_name);
1208 <  ServerInfo.network_name = NULL;
1209 <  MyFree(ServerInfo.network_desc);
1210 <  ServerInfo.network_desc = NULL;
1211 <  MyFree(ConfigFileEntry.egdpool_path);
1212 <  ConfigFileEntry.egdpool_path = NULL;
1204 >  pseudo_clear();
1205 >
1206 >  /* Clean out ConfigServerInfo */
1207 >  MyFree(ConfigServerInfo.description);
1208 >  ConfigServerInfo.description = NULL;
1209 >  MyFree(ConfigServerInfo.network_name);
1210 >  ConfigServerInfo.network_name = NULL;
1211 >  MyFree(ConfigServerInfo.network_desc);
1212 >  ConfigServerInfo.network_desc = NULL;
1213   #ifdef HAVE_LIBCRYPTO
1214 <  if (ServerInfo.rsa_private_key != NULL)
1214 >  if (ConfigServerInfo.rsa_private_key)
1215    {
1216 <    RSA_free(ServerInfo.rsa_private_key);
1217 <    ServerInfo.rsa_private_key = NULL;
1216 >    RSA_free(ConfigServerInfo.rsa_private_key);
1217 >    ConfigServerInfo.rsa_private_key = NULL;
1218    }
1219  
1220 <  MyFree(ServerInfo.rsa_private_key_file);
1221 <  ServerInfo.rsa_private_key_file = NULL;
2660 <
2661 <  if (ServerInfo.server_ctx)
2662 <    SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|
2663 <                                               SSL_OP_NO_SSLv3|
2664 <                                               SSL_OP_NO_TLSv1);
2665 <  if (ServerInfo.client_ctx)
2666 <    SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|
2667 <                                               SSL_OP_NO_SSLv3|
2668 <                                               SSL_OP_NO_TLSv1);
1220 >  MyFree(ConfigServerInfo.rsa_private_key_file);
1221 >  ConfigServerInfo.rsa_private_key_file = NULL;
1222   #endif
1223  
1224 <  /* clean out old resvs from the conf */
1225 <  clear_conf_resv();
1226 <
1227 <  /* clean out AdminInfo */
1228 <  MyFree(AdminInfo.name);
1229 <  AdminInfo.name = NULL;
1230 <  MyFree(AdminInfo.email);
2678 <  AdminInfo.email = NULL;
2679 <  MyFree(AdminInfo.description);
2680 <  AdminInfo.description = NULL;
2681 <
2682 <  /* operator{} and class{} blocks are freed above */
2683 <  /* clean out listeners */
2684 <  close_listeners();
2685 <
2686 <  /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{},
2687 <   * exempt{} and gecos{} blocks are freed above too
2688 <   */
2689 <
2690 <  /* clean out general */
2691 <  MyFree(ConfigFileEntry.service_name);
2692 <  ConfigFileEntry.service_name = NULL;
1224 >  /* Clean out ConfigAdminInfo */
1225 >  MyFree(ConfigAdminInfo.name);
1226 >  ConfigAdminInfo.name = NULL;
1227 >  MyFree(ConfigAdminInfo.email);
1228 >  ConfigAdminInfo.email = NULL;
1229 >  MyFree(ConfigAdminInfo.description);
1230 >  ConfigAdminInfo.description = NULL;
1231  
1232 <  delete_isupport("INVEX");
1233 <  delete_isupport("EXCEPTS");
1232 >  /* Clean out listeners */
1233 >  listener_close_marked();
1234   }
1235  
1236 < /* flush_deleted_I_P()
1236 > /* read_conf_files()
1237   *
1238 < * inputs       - none
1238 > * inputs       - cold start YES or NO
1239   * output       - none
1240 < * side effects - This function removes I/P conf items
2703 < */
2704 < static void
2705 < flush_deleted_I_P(void)
2706 < {
2707 <  dlink_node *ptr;
2708 <  dlink_node *next_ptr;
2709 <  struct ConfItem *conf;
2710 <  struct AccessItem *aconf;
2711 <  dlink_list * free_items [] = {
2712 <    &server_items, &oconf_items, NULL
2713 <  };
2714 <  dlink_list ** iterator = free_items; /* C is dumb */
2715 <
2716 <  /* flush out deleted I and P lines
2717 <   * although still in use.
2718 <   */
2719 <  for (; *iterator != NULL; iterator++)
2720 <  {
2721 <    DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head)
2722 <    {
2723 <      conf = ptr->data;
2724 <      aconf = (struct AccessItem *)map_to_conf(conf);
2725 <
2726 <      if (IsConfIllegal(aconf))
2727 <      {
2728 <        dlinkDelete(ptr, *iterator);
2729 <
2730 <        if (aconf->clients == 0)
2731 <          delete_conf_item(conf);
2732 <      }
2733 <    }
2734 <  }
2735 < }
2736 <
2737 < /* get_conf_name()
2738 < *
2739 < * inputs       - type of conf file to return name of file for
2740 < * output       - pointer to filename for type of conf
2741 < * side effects - none
2742 < */
2743 < const char *
2744 < get_conf_name(ConfType type)
2745 < {
2746 <  switch (type)
2747 <  {
2748 <    case CONF_TYPE:
2749 <      return ConfigFileEntry.configfile;
2750 <      break;
2751 <    case KLINE_TYPE:
2752 <      return ConfigFileEntry.klinefile;
2753 <      break;
2754 <    case RKLINE_TYPE:
2755 <      return ConfigFileEntry.rklinefile;
2756 <      break;
2757 <    case DLINE_TYPE:
2758 <      return ConfigFileEntry.dlinefile;
2759 <      break;
2760 <    case XLINE_TYPE:
2761 <      return ConfigFileEntry.xlinefile;
2762 <      break;
2763 <    case RXLINE_TYPE:
2764 <      return ConfigFileEntry.rxlinefile;
2765 <      break;
2766 <    case CRESV_TYPE:
2767 <      return ConfigFileEntry.cresvfile;
2768 <      break;
2769 <    case NRESV_TYPE:
2770 <      return ConfigFileEntry.nresvfile;
2771 <      break;
2772 <    case GLINE_TYPE:
2773 <      return ConfigFileEntry.glinefile;
2774 <      break;
2775 <
2776 <    default:
2777 <      return NULL;  /* This should NEVER HAPPEN since we call this function
2778 <                       only with the above values, this will cause us to core
2779 <                       at some point if this happens so we know where it was */
2780 <  }
2781 < }
2782 <
2783 < #define BAD_PING (-1)
2784 <
2785 < /* get_conf_ping()
2786 < *
2787 < * inputs       - pointer to struct AccessItem
2788 < *              - pointer to a variable that receives ping warning time
2789 < * output       - ping frequency
2790 < * side effects - NONE
1240 > * side effects - read all conf files needed, ircd.conf kline.conf etc.
1241   */
1242 < static int
1243 < get_conf_ping(struct ConfItem *conf, int *pingwarn)
1242 > void
1243 > read_conf_files(int cold)
1244   {
1245 <  struct ClassItem *aclass;
1246 <  struct AccessItem *aconf;
1245 >  const char *filename = NULL;
1246 >  char chanmodes[IRCD_BUFSIZE] = "";
1247 >  char chanlimit[IRCD_BUFSIZE] = "";
1248  
1249 <  if (conf != NULL)
1250 <  {
2800 <    aconf = (struct AccessItem *)map_to_conf(conf);
2801 <    if (aconf->class_ptr != NULL)
2802 <    {
2803 <      aclass = (struct ClassItem *)map_to_conf(aconf->class_ptr);
2804 <      *pingwarn = PingWarning(aclass);
2805 <      return PingFreq(aclass);
2806 <    }
2807 <  }
1249 >  conf_parser_ctx.boot = cold;
1250 >  filename = ConfigGeneral.configfile;
1251  
1252 <  return BAD_PING;
1253 < }
1252 >  /* We need to know the initial filename for the yyerror() to report
1253 >     FIXME: The full path is in conffilenamebuf first time since we
1254 >             don't know anything else
1255  
1256 < /* get_client_class()
1257 < *
1258 < * inputs       - pointer to client struct
2815 < * output       - pointer to name of class
2816 < * side effects - NONE
2817 < */
2818 < const char *
2819 < get_client_class(struct Client *target_p)
2820 < {
2821 <  dlink_node *ptr;
2822 <  struct ConfItem *conf;
2823 <  struct AccessItem *aconf;
1256 >     - Gozem 2002-07-21
1257 >  */
1258 >  strlcpy(conffilebuf, filename, sizeof(conffilebuf));
1259  
1260 <  if (target_p != NULL && !IsMe(target_p) &&
2826 <      target_p->localClient->confs.head != NULL)
1260 >  if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL)
1261    {
1262 <    DLINK_FOREACH(ptr, target_p->localClient->confs.head)
2829 <    {
2830 <      conf = ptr->data;
2831 <
2832 <      if (conf->type == CLIENT_TYPE || conf->type == SERVER_TYPE ||
2833 <          conf->type == OPER_TYPE)
2834 <      {
2835 <        aconf = (struct AccessItem *) map_to_conf(conf);
2836 <        if (aconf->class_ptr != NULL)
2837 <          return aconf->class_ptr->name;
2838 <      }
2839 <    }
2840 <  }
2841 <
2842 <  return "default";
2843 < }
2844 <
2845 < /* get_client_ping()
2846 < *
2847 < * inputs       - pointer to client struct
2848 < *              - pointer to a variable that receives ping warning time
2849 < * output       - ping frequency
2850 < * side effects - NONE
2851 < */
2852 < int
2853 < get_client_ping(struct Client *target_p, int *pingwarn)
2854 < {
2855 <  int ping;
2856 <  struct ConfItem *conf;
2857 <  dlink_node *nlink;
2858 <
2859 <  if (target_p->localClient->confs.head != NULL)
2860 <    DLINK_FOREACH(nlink, target_p->localClient->confs.head)
1262 >    if (cold)
1263      {
1264 <      conf = nlink->data;
1265 <
1266 <      if ((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2865 <          (conf->type == OPER_TYPE))
2866 <      {
2867 <        ping = get_conf_ping(conf, pingwarn);
2868 <        if (ping > 0)
2869 <          return ping;
2870 <      }
1264 >      ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
1265 >           filename, strerror(errno));
1266 >      exit(-1);
1267      }
1268 <
2873 <  *pingwarn = 0;
2874 <  return DEFAULT_PINGFREQUENCY;
2875 < }
2876 <
2877 < /* find_class()
2878 < *
2879 < * inputs       - string name of class
2880 < * output       - corresponding Class pointer
2881 < * side effects - NONE
2882 < */
2883 < struct ConfItem *
2884 < find_class(const char *classname)
2885 < {
2886 <  struct ConfItem *conf;
2887 <
2888 <  if ((conf = find_exact_name_conf(CLASS_TYPE, NULL, classname, NULL, NULL)) != NULL)
2889 <    return conf;
2890 <
2891 <  return class_default;
2892 < }
2893 <
2894 < /* check_class()
2895 < *
2896 < * inputs       - NONE
2897 < * output       - NONE
2898 < * side effects -
2899 < */
2900 < void
2901 < check_class(void)
2902 < {
2903 <  dlink_node *ptr = NULL, *next_ptr = NULL;
2904 <
2905 <  DLINK_FOREACH_SAFE(ptr, next_ptr, class_items.head)
2906 <  {
2907 <    struct ClassItem *aclass = map_to_conf(ptr->data);
2908 <
2909 <    if (!aclass->active && !CurrUserCount(aclass))
1268 >    else
1269      {
1270 <      destroy_cidr_class(aclass);
1271 <      delete_conf_item(ptr->data);
1270 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1271 >                           "Unable to read configuration file '%s': %s",
1272 >                           filename, strerror(errno));
1273 >      return;
1274      }
1275    }
2915 }
1276  
1277 < /* init_class()
1278 < *
2919 < * inputs       - NONE
2920 < * output       - NONE
2921 < * side effects -
2922 < */
2923 < void
2924 < init_class(void)
2925 < {
2926 <  struct ClassItem *aclass;
1277 >  if (!cold)
1278 >    clear_out_old_conf();
1279  
1280 <  class_default = make_conf_item(CLASS_TYPE);
1280 >  read_conf(conf_parser_ctx.conf_file);
1281 >  fclose(conf_parser_ctx.conf_file);
1282  
1283 <  aclass = map_to_conf(class_default);
2931 <  aclass->active = 1;
2932 <  DupString(class_default->name, "default");
2933 <  ConFreq(aclass)  = DEFAULT_CONNECTFREQUENCY;
2934 <  PingFreq(aclass) = DEFAULT_PINGFREQUENCY;
2935 <  MaxTotal(aclass) = MAXIMUM_LINKS_DEFAULT;
2936 <  MaxSendq(aclass) = DEFAULT_SENDQ;
1283 >  log_reopen_all();
1284  
1285 <  client_check_cb = register_callback("check_client", check_client);
1286 < }
1285 >  isupport_add("NICKLEN", NULL, ConfigServerInfo.max_nick_length);
1286 >  isupport_add("NETWORK", ConfigServerInfo.network_name, -1);
1287  
1288 < /* get_sendq()
1289 < *
1290 < * inputs       - pointer to client
1291 < * output       - sendq for this client as found from its class
1292 < * side effects - NONE
1293 < */
1294 < unsigned int
1295 < get_sendq(struct Client *client_p)
1296 < {
1297 <  unsigned int sendq = DEFAULT_SENDQ;
1298 <  dlink_node *ptr;
1299 <  struct ConfItem *conf;
2953 <  struct ConfItem *class_conf;
2954 <  struct ClassItem *aclass;
2955 <  struct AccessItem *aconf;
1288 >  snprintf(chanmodes, sizeof(chanmodes), "beI:%d", ConfigChannel.max_bans);
1289 >  isupport_add("MAXLIST", chanmodes, -1);
1290 >  isupport_add("MAXTARGETS", NULL, ConfigGeneral.max_targets);
1291 >  isupport_add("CHANTYPES", "#", -1);
1292 >
1293 >  snprintf(chanlimit, sizeof(chanlimit), "#:%d",
1294 >           ConfigChannel.max_channels);
1295 >  isupport_add("CHANLIMIT", chanlimit, -1);
1296 >  snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,cimnprstCMORS");
1297 >  isupport_add("CHANNELLEN", NULL, CHANNELLEN);
1298 >  isupport_add("TOPICLEN", NULL, ConfigServerInfo.max_topic_length);
1299 >  isupport_add("CHANMODES", chanmodes, -1);
1300  
1301 <  if (client_p && !IsMe(client_p) && (client_p->localClient->confs.head))
1302 <  {
1303 <    DLINK_FOREACH(ptr, client_p->localClient->confs.head)
2960 <    {
2961 <      conf = ptr->data;
2962 <      if ((conf->type == SERVER_TYPE) || (conf->type == OPER_TYPE)
2963 <          || (conf->type == CLIENT_TYPE))
2964 <      {
2965 <        aconf = (struct AccessItem *)map_to_conf(conf);
2966 <        if ((class_conf = aconf->class_ptr) == NULL)
2967 <          continue;
2968 <        aclass = (struct ClassItem *)map_to_conf(class_conf);
2969 <        sendq = MaxSendq(aclass);
2970 <        return sendq;
2971 <      }
2972 <    }
2973 <  }
2974 <  /* XXX return a default?
2975 <   * if here, then there wasn't an attached conf with a sendq
2976 <   * that is very bad -Dianora
1301 >  /*
1302 >   * message_locale may have changed.  rebuild isupport since it relies
1303 >   * on strlen(form_str(RPL_ISUPPORT))
1304     */
1305 <  return DEFAULT_SENDQ;
1305 >  isupport_rebuild();
1306   }
1307  
1308   /* conf_add_class_to_conf()
1309   *
1310   * inputs       - pointer to config item
1311   * output       - NONE
1312 < * side effects - Add a class pointer to a conf
1312 > * side effects - Add a class pointer to a conf
1313   */
1314   void
1315 < conf_add_class_to_conf(struct ConfItem *conf, const char *class_name)
1315 > conf_add_class_to_conf(struct MaskItem *conf, const char *name)
1316   {
1317 <  struct AccessItem *aconf = map_to_conf(conf);
2991 <  struct ClassItem *class = NULL;
2992 <
2993 <  if (class_name == NULL)
1317 >  if (EmptyString(name) || (conf->class = class_find(name, 1)) == NULL)
1318    {
1319 <    aconf->class_ptr = class_default;
1319 >    conf->class = class_default;
1320  
1321 <    if (conf->type == CLIENT_TYPE)
1322 <      sendto_realops_flags(UMODE_ALL, L_ALL,
1323 <                           "Warning *** Defaulting to default class for %s@%s",
1324 <                           aconf->user, aconf->host);
1321 >    if (conf->type == CONF_CLIENT || conf->type == CONF_OPER)
1322 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1323 >                           "Warning *** Defaulting to default class for %s@%s",
1324 >                           conf->user, conf->host);
1325      else
1326 <      sendto_realops_flags(UMODE_ALL, L_ALL,
1327 <                           "Warning *** Defaulting to default class for %s",
1328 <                           conf->name);
3005 <  }
3006 <  else
3007 <    aconf->class_ptr = find_class(class_name);
3008 <
3009 <  if (aconf->class_ptr)
3010 <    class = map_to_conf(aconf->class_ptr);
3011 <
3012 <  if (aconf->class_ptr == NULL || !class->active)
3013 <  {
3014 <    if (conf->type == CLIENT_TYPE)
3015 <      sendto_realops_flags(UMODE_ALL, L_ALL,
3016 <                           "Warning *** Defaulting to default class for %s@%s",
3017 <                           aconf->user, aconf->host);
3018 <    else
3019 <      sendto_realops_flags(UMODE_ALL, L_ALL,
3020 <                           "Warning *** Defaulting to default class for %s",
3021 <                           conf->name);
3022 <    aconf->class_ptr = class_default;
1326 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1327 >                           "Warning *** Defaulting to default class for %s",
1328 >                           conf->name);
1329    }
1330   }
1331  
3026 /* conf_add_server()
3027 *
3028 * inputs       - pointer to config item
3029 *              - pointer to link count already on this conf
3030 * output       - NONE
3031 * side effects - Add a connect block
3032 */
3033 int
3034 conf_add_server(struct ConfItem *conf, const char *class_name)
3035 {
3036  struct AccessItem *aconf = map_to_conf(conf);
3037
3038  conf_add_class_to_conf(conf, class_name);
3039
3040  if (!aconf->host || !conf->name)
3041  {
3042    sendto_realops_flags(UMODE_ALL, L_ALL, "Bad connect block");
3043    ilog(LOG_TYPE_IRCD, "Bad connect block");
3044    return -1;
3045  }
3046
3047  if (EmptyString(aconf->passwd))
3048  {
3049    sendto_realops_flags(UMODE_ALL, L_ALL, "Bad connect block, name %s",
3050                         conf->name);
3051    ilog(LOG_TYPE_IRCD, "Bad connect block, host %s", conf->name);
3052    return -1;
3053  }
3054
3055  lookup_confhost(conf);
3056
3057  return 0;
3058 }
3059
1332   /* yyerror()
1333   *
1334   * inputs       - message from parser
# Line 3072 | Line 1344 | yyerror(const char *msg)
1344      return;
1345  
1346    strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1347 <  sendto_realops_flags(UMODE_ALL, L_ALL, "\"%s\", line %u: %s: %s",
1347 >  sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1348 >                       "\"%s\", line %u: %s: %s",
1349 >                       conffilebuf, lineno + 1, msg, newlinebuf);
1350 >  ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1351 >       conffilebuf, lineno + 1, msg, newlinebuf);
1352 > }
1353 >
1354 > void
1355 > conf_error_report(const char *msg)
1356 > {
1357 >  char newlinebuf[IRCD_BUFSIZE];
1358 >
1359 >  strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1360 >  sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1361 >                       "\"%s\", line %u: %s: %s",
1362                         conffilebuf, lineno + 1, msg, newlinebuf);
1363    ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1364         conffilebuf, lineno + 1, msg, newlinebuf);
# Line 3080 | Line 1366 | yyerror(const char *msg)
1366  
1367   /*
1368   * valid_tkline()
1369 < *
1369 > *
1370   * inputs       - pointer to ascii string to check
1371   *              - whether the specified time is in seconds or minutes
1372   * output       - -1 not enough parameters
# Line 3089 | Line 1375 | yyerror(const char *msg)
1375   * Originally written by Dianora (Diane, db@db.net)
1376   */
1377   time_t
1378 < valid_tkline(const char *p, int minutes)
1378 > valid_tkline(const char *data, const int minutes)
1379   {
1380 +  const unsigned char *p = (const unsigned char *)data;
1381 +  unsigned char tmpch = '\0';
1382    time_t result = 0;
1383  
1384 <  for (; *p; ++p)
1384 >  while ((tmpch = *p++))
1385    {
1386 <    if (!IsDigit(*p))
1386 >    if (!IsDigit(tmpch))
1387        return 0;
1388  
1389      result *= 10;
1390 <    result += ((*p) & 0xF);
1390 >    result += (tmpch & 0xF);
1391    }
1392  
1393    /*
1394 <   * In the degenerate case where oper does a /quote kline 0 user@host :reason
1395 <   * i.e. they specifically use 0, I am going to return 1 instead
1396 <   * as a return value of non-zero is used to flag it as a temporary kline
1394 >   * In the degenerate case where oper does a /quote kline 0 user@host :reason
1395 >   * i.e. they specifically use 0, I am going to return 1 instead as a return
1396 >   * value of non-zero is used to flag it as a temporary kline
1397     */
1398    if (result == 0)
1399      result = 1;
1400  
1401 <  /*
1401 >  /*
1402     * If the incoming time is in seconds convert it to minutes for the purpose
1403     * of this calculation
1404     */
1405    if (!minutes)
1406 <    result = result / (time_t)60;
1406 >    result = result / 60;
1407  
1408    if (result > MAX_TDKLINE_TIME)
1409      result = MAX_TDKLINE_TIME;
1410  
1411 <  result = result * (time_t)60;  /* turn it into seconds */
1411 >  result = result * 60;  /* Turn it into seconds */
1412  
1413    return result;
1414   }
1415  
1416 + /* valid_wild_card_simple()
1417 + *
1418 + * inputs       - data to check for sufficient non-wildcard characters
1419 + * outputs      - 1 if valid, else 0
1420 + * side effects - none
1421 + */
1422 + int
1423 + valid_wild_card_simple(const char *data)
1424 + {
1425 +  const unsigned char *p = (const unsigned char *)data;
1426 +  unsigned char tmpch = '\0';
1427 +  unsigned int nonwild = 0, wild = 0;
1428 +
1429 +  while ((tmpch = *p++))
1430 +  {
1431 +    if (tmpch == '\\' && *p)
1432 +    {
1433 +      ++p;
1434 +      if (++nonwild >= ConfigGeneral.min_nonwildcard_simple)
1435 +        return 1;
1436 +    }
1437 +    else if (!IsMWildChar(tmpch))
1438 +    {
1439 +      if (++nonwild >= ConfigGeneral.min_nonwildcard_simple)
1440 +        return 1;
1441 +    }
1442 +    else
1443 +      ++wild;
1444 +  }
1445 +
1446 +  return !wild;
1447 + }
1448 +
1449   /* valid_wild_card()
1450   *
1451   * input        - pointer to client
# Line 3134 | Line 1455 | valid_tkline(const char *p, int minutes)
1455   * side effects - NOTICE is given to source_p if warn is 1
1456   */
1457   int
1458 < valid_wild_card(struct Client *source_p, int warn, int count, ...)
1458 > valid_wild_card(struct Client *source_p, int count, ...)
1459   {
1460 <  char *p;
1461 <  char tmpch;
3141 <  int nonwild = 0;
1460 >  unsigned char tmpch = '\0';
1461 >  unsigned int nonwild = 0;
1462    va_list args;
1463  
1464    /*
# Line 3157 | Line 1477 | valid_wild_card(struct Client *source_p,
1477  
1478    while (count--)
1479    {
1480 <    p = va_arg(args, char *);
1480 >    const unsigned char *p = va_arg(args, const unsigned char *);
1481      if (p == NULL)
1482        continue;
1483  
# Line 3169 | Line 1489 | valid_wild_card(struct Client *source_p,
1489           * If we find enough non-wild characters, we can
1490           * break - no point in searching further.
1491           */
1492 <        if (++nonwild >= ConfigFileEntry.min_nonwildcard)
1492 >        if (++nonwild >= ConfigGeneral.min_nonwildcard)
1493 >        {
1494 >          va_end(args);
1495            return 1;
1496 +        }
1497        }
1498      }
1499    }
1500  
1501 <  if (warn)
1502 <    sendto_one(source_p, ":%s NOTICE %s :Please include at least %d non-wildcard characters with the mask",
1503 <               me.name, source_p->name, ConfigFileEntry.min_nonwildcard);
1501 >  if (IsClient(source_p))
1502 >    sendto_one_notice(source_p, &me,
1503 >                      ":Please include at least %u non-wildcard characters with the mask",
1504 >                      ConfigGeneral.min_nonwildcard);
1505 >  va_end(args);
1506 >  return 0;
1507 > }
1508 >
1509 > /* find_user_host()
1510 > *
1511 > * inputs       - pointer to client placing kline
1512 > *              - pointer to user_host_or_nick
1513 > *              - pointer to user buffer
1514 > *              - pointer to host buffer
1515 > * output       - 0 if not ok to kline, 1 to kline i.e. if valid user host
1516 > * side effects -
1517 > */
1518 > static int
1519 > find_user_host(struct Client *source_p, char *user_host_or_nick,
1520 >               char *luser, char *lhost)
1521 > {
1522 >  struct Client *target_p = NULL;
1523 >  char *hostp = NULL;
1524 >
1525 >  if (lhost == NULL)
1526 >  {
1527 >    strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
1528 >    return 1;
1529 >  }
1530 >
1531 >  if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
1532 >  {
1533 >    /* Explicit user@host mask given */
1534 >    if (hostp)                            /* I'm a little user@host */
1535 >    {
1536 >      *(hostp++) = '\0';                       /* short and squat */
1537 >
1538 >      if (*user_host_or_nick)
1539 >        strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
1540 >      else
1541 >        strcpy(luser, "*");
1542 >
1543 >      if (*hostp)
1544 >        strlcpy(lhost, hostp, HOSTLEN + 1);    /* here is my host */
1545 >      else
1546 >        strcpy(lhost, "*");
1547 >    }
1548 >    else
1549 >    {
1550 >      luser[0] = '*';             /* no @ found, assume its *@somehost */
1551 >      luser[1] = '\0';
1552 >      strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
1553 >    }
1554 >
1555 >    return 1;
1556 >  }
1557 >  else
1558 >  {
1559 >    /* Try to find user@host mask from nick */
1560 >    /* Okay to use source_p as the first param, because source_p == client_p */
1561 >    if ((target_p =
1562 >        find_chasing(source_p, user_host_or_nick)) == NULL)
1563 >      return 0;  /* find_chasing sends ERR_NOSUCHNICK */
1564 >
1565 >    if (HasFlag(target_p, FLAGS_EXEMPTKLINE))
1566 >    {
1567 >      if (IsClient(source_p))
1568 >        sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
1569 >      return 0;
1570 >    }
1571 >
1572 >    /*
1573 >     * Turn the "user" bit into "*user", blow away '~'
1574 >     * if found in original user name (non-idented)
1575 >     */
1576 >    strlcpy(luser, target_p->username, USERLEN*4 + 1);
1577 >
1578 >    if (target_p->username[0] == '~')
1579 >      luser[0] = '*';
1580 >
1581 >    if (!strcmp(target_p->sockhost, "0"))
1582 >      strlcpy(lhost, target_p->host, HOSTLEN*4 + 1);
1583 >    else
1584 >      strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
1585 >    return 1;
1586 >  }
1587 >
1588    return 0;
1589   }
1590  
# Line 3191 | Line 1598 | valid_wild_card(struct Client *source_p,
1598   *              - parse_flags bit map of things to test
1599   *              - pointer to user or string to parse into
1600   *              - pointer to host or NULL to parse into if non NULL
1601 < *              - pointer to optional tkline time or NULL
1601 > *              - pointer to optional tkline time or NULL
1602   *              - pointer to target_server to parse into if non NULL
1603   *              - pointer to reason to parse into
1604   *
1605 < * output       - 1 if valid, -1 if not valid
1605 > * output       - 1 if valid, 0 if not valid
1606   * side effects - A generalised k/d/x etc. line parser,
1607   *               "ALINE [time] user@host|string [ON] target :reason"
1608   *                will parse returning a parsed user, host if
# Line 3213 | Line 1620 | valid_wild_card(struct Client *source_p,
1620   */
1621   int
1622   parse_aline(const char *cmd, struct Client *source_p,
1623 <            int parc, char **parv,
1624 <            int parse_flags, char **up_p, char **h_p, time_t *tkline_time,
1625 <            char **target_server, char **reason)
1623 >            int parc, char **parv,
1624 >            int parse_flags, char **up_p, char **h_p, time_t *tkline_time,
1625 >            char **target_server, char **reason)
1626   {
1627    int found_tkline_time=0;
1628 <  static char def_reason[] = "No Reason";
1628 >  static char default_reason[] = CONF_NOREASON;
1629    static char user[USERLEN*4+1];
1630    static char host[HOSTLEN*4+1];
1631  
# Line 3227 | Line 1634 | parse_aline(const char *cmd, struct Clie
1634  
1635    found_tkline_time = valid_tkline(*parv, TK_MINUTES);
1636  
1637 <  if (found_tkline_time != 0)
1637 >  if (found_tkline_time)
1638    {
1639      parv++;
1640      parc--;
1641  
1642 <    if (tkline_time != NULL)
1642 >    if (tkline_time)
1643        *tkline_time = found_tkline_time;
1644      else
1645      {
1646 <      sendto_one(source_p, ":%s NOTICE %s :temp_line not supported by %s",
1647 <                 me.name, source_p->name, cmd);
3241 <      return -1;
1646 >      sendto_one_notice(source_p, &me, ":temp_line not supported by %s", cmd);
1647 >      return 0;
1648      }
1649    }
1650  
1651    if (parc == 0)
1652    {
1653 <    sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1654 <               me.name, source_p->name, cmd);
3249 <    return -1;
1653 >    sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1654 >    return 0;
1655    }
1656  
1657    if (h_p == NULL)
1658      *up_p = *parv;
1659    else
1660    {
1661 <    if (find_user_host(source_p, *parv, user, host, parse_flags) == 0)
1662 <      return -1;
1661 >    if (find_user_host(source_p, *parv, user, host) == 0)
1662 >      return 0;
1663  
1664      *up_p = user;
1665      *h_p = host;
1666    }
1667 <
1667 >
1668    parc--;
1669    parv++;
1670  
1671 <  if (parc != 0)
1671 >  if (parc)
1672    {
1673      if (irccmp(*parv, "ON") == 0)
1674      {
1675        parc--;
1676        parv++;
1677  
3273      if (target_server == NULL)
3274      {
3275        sendto_one(source_p, ":%s NOTICE %s :ON server not supported by %s",
3276                   me.name, source_p->name, cmd);
3277        return -1;
3278      }
3279
1678        if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN))
1679        {
1680 <        sendto_one(source_p, form_str(ERR_NOPRIVS),
1681 <                   me.name, source_p->name, "remoteban");
3284 <        return -1;
1680 >        sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "remoteban");
1681 >        return 0;
1682        }
1683  
1684        if (parc == 0 || EmptyString(*parv))
1685        {
1686 <        sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1687 <                   me.name, source_p->name, cmd);
3291 <        return -1;
1686 >        sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1687 >        return 0;
1688        }
1689  
1690        *target_server = *parv;
# Line 3300 | Line 1696 | parse_aline(const char *cmd, struct Clie
1696        /* Make sure target_server *is* NULL if no ON server found
1697         * caller probably NULL'd it first, but no harm to do it again -db
1698         */
1699 <      if (target_server != NULL)
1700 <        *target_server = NULL;
1699 >      if (target_server)
1700 >        *target_server = NULL;
1701      }
1702    }
1703  
1704 <  if (h_p != NULL)
1704 >  if (h_p)
1705    {
1706 <    if (strchr(user, '!') != NULL)
1706 >    if (strchr(user, '!'))
1707      {
1708 <      sendto_one(source_p, ":%s NOTICE %s :Invalid character '!' in kline",
1709 <                 me.name, source_p->name);
3314 <      return -1;
1708 >      sendto_one_notice(source_p, &me, ":Invalid character '!' in kline");
1709 >      return 0;
1710      }
1711  
1712 <    if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 2, *up_p, *h_p))
1713 <      return -1;
1712 >    if ((parse_flags & AWILD) && !valid_wild_card(source_p, 2, *up_p, *h_p))
1713 >      return 0;
1714    }
1715    else
1716 <    if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 1, *up_p))
1717 <      return -1;
1716 >    if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, *up_p))
1717 >      return 0;
1718  
1719 <  if (reason != NULL)
1719 >  if (reason)
1720    {
1721 <    if (parc != 0 && !EmptyString(*parv))
3327 <    {
1721 >    if (parc && !EmptyString(*parv))
1722        *reason = *parv;
3329      if (!valid_comment(source_p, *reason, 1))
3330        return -1;
3331    }
1723      else
1724 <      *reason = def_reason;
1724 >      *reason = default_reason;
1725    }
1726  
1727    return 1;
1728   }
1729  
3339 /* find_user_host()
3340 *
3341 * inputs       - pointer to client placing kline
3342 *              - pointer to user_host_or_nick
3343 *              - pointer to user buffer
3344 *              - pointer to host buffer
3345 * output       - 0 if not ok to kline, 1 to kline i.e. if valid user host
3346 * side effects -
3347 */
3348 static int
3349 find_user_host(struct Client *source_p, char *user_host_or_nick,
3350               char *luser, char *lhost, unsigned int flags)
3351 {
3352  struct Client *target_p = NULL;
3353  char *hostp = NULL;
3354
3355  if (lhost == NULL)
3356  {
3357    strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
3358    return 1;
3359  }
3360
3361  if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
3362  {
3363    /* Explicit user@host mask given */
3364
3365    if (hostp != NULL)                            /* I'm a little user@host */
3366    {
3367      *(hostp++) = '\0';                       /* short and squat */
3368      if (*user_host_or_nick)
3369        strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
3370      else
3371        strcpy(luser, "*");
3372      if (*hostp)
3373        strlcpy(lhost, hostp, HOSTLEN + 1);    /* here is my host */
3374      else
3375        strcpy(lhost, "*");
3376    }
3377    else
3378    {
3379      luser[0] = '*';             /* no @ found, assume its *@somehost */
3380      luser[1] = '\0';    
3381      strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
3382    }
3383    
3384    return 1;
3385  }
3386  else if (!(flags & NOUSERLOOKUP))
3387  {
3388    /* Try to find user@host mask from nick */
3389    /* Okay to use source_p as the first param, because source_p == client_p */
3390    if ((target_p =
3391        find_chasing(source_p, source_p, user_host_or_nick, NULL)) == NULL)
3392      return 0;
3393
3394    if (IsExemptKline(target_p))
3395    {
3396      if (!IsServer(source_p))
3397        sendto_one(source_p,
3398                   ":%s NOTICE %s :%s is E-lined",
3399                   me.name, source_p->name, target_p->name);
3400      return 0;
3401    }
3402
3403    /*
3404     * turn the "user" bit into "*user", blow away '~'
3405     * if found in original user name (non-idented)
3406     */
3407    strlcpy(luser, target_p->username, USERLEN*4 + 1);
3408
3409    if (target_p->username[0] == '~')
3410      luser[0] = '*';
3411
3412    if (target_p->sockhost[0] == '\0' ||
3413        (target_p->sockhost[0] == '0' && target_p->sockhost[1] == '\0'))
3414      strlcpy(lhost, target_p->host, HOSTLEN*4 + 1);
3415    else
3416      strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
3417    return 1;
3418  }
3419
3420  return 0;
3421 }
3422
3423 /* valid_comment()
3424 *
3425 * inputs       - pointer to client
3426 *              - pointer to comment
3427 * output       - 0 if no valid comment,
3428 *              - 1 if valid
3429 * side effects - truncates reason where necessary
3430 */
3431 int
3432 valid_comment(struct Client *source_p, char *comment, int warn)
3433 {
3434  if (strchr(comment, '"'))
3435  {
3436    if (warn)
3437      sendto_one(source_p, ":%s NOTICE %s :Invalid character '\"' in comment",
3438                 me.name, source_p->name);
3439    return 0;
3440  }
3441
3442  if (strlen(comment) > REASONLEN)
3443    comment[REASONLEN-1] = '\0';
3444
3445  return 1;
3446 }
3447
1730   /* match_conf_password()
1731   *
1732   * inputs       - pointer to given password
# Line 3453 | Line 1735 | valid_comment(struct Client *source_p, c
1735   * side effects - none
1736   */
1737   int
1738 < match_conf_password(const char *password, const struct AccessItem *aconf)
1738 > match_conf_password(const char *password, const struct MaskItem *conf)
1739   {
1740    const char *encr = NULL;
1741  
1742 <  if (password == NULL || aconf->passwd == NULL)
1742 >  if (EmptyString(password) || EmptyString(conf->passwd))
1743      return 0;
1744  
1745 <  if (aconf->flags & CONF_FLAGS_ENCRYPTED)
1746 <  {
3465 <    /* use first two chars of the password they send in as salt */
3466 <    /* If the password in the conf is MD5, and ircd is linked
3467 <     * to scrypt on FreeBSD, or the standard crypt library on
3468 <     * glibc Linux, then this code will work fine on generating
3469 <     * the proper encrypted hash for comparison.
3470 <     */
3471 <    if (*aconf->passwd)
3472 <      encr = crypt(password, aconf->passwd);
3473 <    else
3474 <      encr = "";
3475 <  }
1745 >  if (conf->flags & CONF_FLAGS_ENCRYPTED)
1746 >    encr = crypt(password, conf->passwd);
1747    else
1748      encr = password;
1749  
1750 <  return !strcmp(encr, aconf->passwd);
1750 >  return encr && !strcmp(encr, conf->passwd);
1751   }
1752  
1753   /*
# Line 3484 | Line 1755 | match_conf_password(const char *password
1755   *
1756   * inputs       - client sending the cluster
1757   *              - command name "KLINE" "XLINE" etc.
1758 < *              - capab -- CAP_KLN etc. from s_serv.h
1758 > *              - capab -- CAPAB_KLN etc. from server.h
1759   *              - cluster type -- CLUSTER_KLINE etc. from conf.h
1760   *              - pattern and args to send along
1761   * output       - none
# Line 3492 | Line 1763 | match_conf_password(const char *password
1763   *                along to all servers that match capab and cluster type
1764   */
1765   void
1766 < cluster_a_line(struct Client *source_p, const char *command,
1767 <               int capab, int cluster_type, const char *pattern, ...)
1766 > cluster_a_line(struct Client *source_p, const char *command, unsigned int capab,
1767 >               unsigned int cluster_type, const char *pattern, ...)
1768   {
1769    va_list args;
1770 <  char buffer[IRCD_BUFSIZE];
1771 <  const dlink_node *ptr = NULL;
1770 >  char buffer[IRCD_BUFSIZE] = "";
1771 >  const dlink_node *node = NULL;
1772  
1773    va_start(args, pattern);
1774    vsnprintf(buffer, sizeof(buffer), pattern, args);
1775    va_end(args);
1776  
1777 <  DLINK_FOREACH(ptr, cluster_items.head)
1777 >  DLINK_FOREACH(node, cluster_items.head)
1778    {
1779 <    const struct ConfItem *conf = ptr->data;
1779 >    const struct MaskItem *conf = node->data;
1780  
1781      if (conf->flags & cluster_type)
1782 <      sendto_match_servs(source_p, conf->name, CAP_CLUSTER|capab,
1783 <                         "%s %s %s", command, conf->name, buffer);
1782 >      sendto_match_servs(source_p, conf->name, CAPAB_CLUSTER | capab,
1783 >                         "%s %s %s", command, conf->name, buffer);
1784    }
1785   }
1786  
# Line 3548 | Line 1819 | split_nuh(struct split_nuh_item *const i
1819  
1820    if (iptr->nickptr)
1821      strlcpy(iptr->nickptr, "*", iptr->nicksize);
1822 +
1823    if (iptr->userptr)
1824      strlcpy(iptr->userptr, "*", iptr->usersize);
1825 +
1826    if (iptr->hostptr)
1827      strlcpy(iptr->hostptr, "*", iptr->hostsize);
1828  
# Line 3557 | Line 1830 | split_nuh(struct split_nuh_item *const i
1830    {
1831      *p = '\0';
1832  
1833 <    if (iptr->nickptr && *iptr->nuhmask != '\0')
1833 >    if (iptr->nickptr && *iptr->nuhmask)
1834        strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
1835  
1836 <    if ((q = strchr(++p, '@'))) {
1836 >    if ((q = strchr(++p, '@')))
1837 >    {
1838        *q++ = '\0';
1839  
1840 <      if (*p != '\0')
1840 >      if (*p)
1841          strlcpy(iptr->userptr, p, iptr->usersize);
1842  
1843 <      if (*q != '\0')
1843 >      if (*q)
1844          strlcpy(iptr->hostptr, q, iptr->hostsize);
1845      }
1846      else
1847      {
1848 <      if (*p != '\0')
1848 >      if (*p)
1849          strlcpy(iptr->userptr, p, iptr->usersize);
1850      }
1851    }
# Line 3583 | Line 1857 | split_nuh(struct split_nuh_item *const i
1857        /* if found a @ */
1858        *p++ = '\0';
1859  
1860 <      if (*iptr->nuhmask != '\0')
1860 >      if (*iptr->nuhmask)
1861          strlcpy(iptr->userptr, iptr->nuhmask, iptr->usersize);
1862  
1863 <      if (*p != '\0')
1863 >      if (*p)
1864          strlcpy(iptr->hostptr, p, iptr->hostsize);
1865      }
1866      else
1867      {
1868 <      /* no @ found */
1868 >      /* No @ found */
1869        if (!iptr->nickptr || strpbrk(iptr->nuhmask, ".:"))
1870          strlcpy(iptr->hostptr, iptr->nuhmask, iptr->hostsize);
1871        else
# Line 3599 | Line 1873 | split_nuh(struct split_nuh_item *const i
1873      }
1874    }
1875   }
3602
3603 /*
3604 * flags_to_ascii
3605 *
3606 * inputs       - flags is a bitmask
3607 *              - pointer to table of ascii letters corresponding
3608 *                to each bit
3609 *              - flag 1 for convert ToLower if bit missing
3610 *                0 if ignore.
3611 * output       - none
3612 * side effects - string pointed to by p has bitmap chars written to it
3613 */
3614 static void
3615 flags_to_ascii(unsigned int flags, const unsigned int bit_table[], char *p,
3616               int lowerit)
3617 {
3618  unsigned int mask = 1;
3619  int i = 0;
3620
3621  for (mask = 1; (mask != 0) && (bit_table[i] != 0); mask <<= 1, i++)
3622  {
3623    if (flags & mask)
3624      *p++ = bit_table[i];
3625    else if (lowerit)
3626      *p++ = ToLower(bit_table[i]);
3627  }
3628  *p = '\0';
3629 }
3630
3631 /*
3632 * cidr_limit_reached
3633 *
3634 * inputs       - int flag allowing over_rule of limits
3635 *              - pointer to the ip to be added
3636 *              - pointer to the class
3637 * output       - non zero if limit reached
3638 *                0 if limit not reached
3639 * side effects -
3640 */
3641 static int
3642 cidr_limit_reached(int over_rule,
3643                   struct irc_ssaddr *ip, struct ClassItem *aclass)
3644 {
3645  dlink_node *ptr = NULL;
3646  struct CidrItem *cidr;
3647
3648  if (NumberPerCidr(aclass) <= 0)
3649    return 0;
3650
3651  if (ip->ss.ss_family == AF_INET)
3652  {
3653    if (CidrBitlenIPV4(aclass) <= 0)
3654      return 0;
3655
3656    DLINK_FOREACH(ptr, aclass->list_ipv4.head)
3657    {
3658      cidr = ptr->data;
3659      if (match_ipv4(ip, &cidr->mask, CidrBitlenIPV4(aclass)))
3660      {
3661        if (!over_rule && (cidr->number_on_this_cidr >= NumberPerCidr(aclass)))
3662          return -1;
3663        cidr->number_on_this_cidr++;
3664        return 0;
3665      }
3666    }
3667    cidr = MyMalloc(sizeof(struct CidrItem));
3668    cidr->number_on_this_cidr = 1;
3669    cidr->mask = *ip;
3670    mask_addr(&cidr->mask, CidrBitlenIPV4(aclass));
3671    dlinkAdd(cidr, &cidr->node, &aclass->list_ipv4);
3672  }
3673 #ifdef IPV6
3674  else if (CidrBitlenIPV6(aclass) > 0)
3675  {
3676    DLINK_FOREACH(ptr, aclass->list_ipv6.head)
3677    {
3678      cidr = ptr->data;
3679      if (match_ipv6(ip, &cidr->mask, CidrBitlenIPV6(aclass)))
3680      {
3681        if (!over_rule && (cidr->number_on_this_cidr >= NumberPerCidr(aclass)))
3682          return -1;
3683        cidr->number_on_this_cidr++;
3684        return 0;
3685      }
3686    }
3687    cidr = MyMalloc(sizeof(struct CidrItem));
3688    cidr->number_on_this_cidr = 1;
3689    cidr->mask = *ip;
3690    mask_addr(&cidr->mask, CidrBitlenIPV6(aclass));
3691    dlinkAdd(cidr, &cidr->node, &aclass->list_ipv6);
3692  }
3693 #endif
3694  return 0;
3695 }
3696
3697 /*
3698 * remove_from_cidr_check
3699 *
3700 * inputs       - pointer to the ip to be removed
3701 *              - pointer to the class
3702 * output       - NONE
3703 * side effects -
3704 */
3705 static void
3706 remove_from_cidr_check(struct irc_ssaddr *ip, struct ClassItem *aclass)
3707 {
3708  dlink_node *ptr = NULL;
3709  dlink_node *next_ptr = NULL;
3710  struct CidrItem *cidr;
3711
3712  if (NumberPerCidr(aclass) == 0)
3713    return;
3714
3715  if (ip->ss.ss_family == AF_INET)
3716  {
3717    if (CidrBitlenIPV4(aclass) <= 0)
3718      return;
3719
3720    DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv4.head)
3721    {
3722      cidr = ptr->data;
3723      if (match_ipv4(ip, &cidr->mask, CidrBitlenIPV4(aclass)))
3724      {
3725        cidr->number_on_this_cidr--;
3726        if (cidr->number_on_this_cidr == 0)
3727        {
3728          dlinkDelete(ptr, &aclass->list_ipv4);
3729          MyFree(cidr);
3730          return;
3731        }
3732      }
3733    }
3734  }
3735 #ifdef IPV6
3736  else if (CidrBitlenIPV6(aclass) > 0)
3737  {
3738    DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv6.head)
3739    {
3740      cidr = ptr->data;
3741      if (match_ipv6(ip, &cidr->mask, CidrBitlenIPV6(aclass)))
3742      {
3743        cidr->number_on_this_cidr--;
3744        if (cidr->number_on_this_cidr == 0)
3745        {
3746          dlinkDelete(ptr, &aclass->list_ipv6);
3747          MyFree(cidr);
3748          return;
3749        }
3750      }
3751    }
3752  }
3753 #endif
3754 }
3755
3756 static void
3757 rebuild_cidr_list(int aftype, struct ConfItem *oldcl, struct ClassItem *newcl,
3758                  dlink_list *old_list, dlink_list *new_list, int changed)
3759 {
3760  dlink_node *ptr;
3761  struct Client *client_p;
3762  struct ConfItem *conf;
3763  struct AccessItem *aconf;
3764
3765  if (!changed)
3766  {
3767    *new_list = *old_list;
3768    old_list->head = old_list->tail = NULL;
3769    old_list->length = 0;
3770    return;
3771  }
3772
3773  DLINK_FOREACH(ptr, local_client_list.head)
3774  {
3775    client_p = ptr->data;
3776    if (client_p->localClient->aftype != aftype)
3777      continue;
3778    if (dlink_list_length(&client_p->localClient->confs) == 0)
3779      continue;
3780
3781    conf = client_p->localClient->confs.tail->data;
3782    if (conf->type == CLIENT_TYPE)
3783    {
3784      aconf = map_to_conf(conf);
3785      if (aconf->class_ptr == oldcl)
3786        cidr_limit_reached(1, &client_p->localClient->ip, newcl);
3787    }
3788  }
3789 }
3790
3791 /*
3792 * rebuild_cidr_class
3793 *
3794 * inputs       - pointer to old conf
3795 *              - pointer to new_class
3796 * output       - none
3797 * side effects - rebuilds the class link list of cidr blocks
3798 */
3799 void
3800 rebuild_cidr_class(struct ConfItem *conf, struct ClassItem *new_class)
3801 {
3802  struct ClassItem *old_class = map_to_conf(conf);
3803
3804  if (NumberPerCidr(old_class) > 0 && NumberPerCidr(new_class) > 0)
3805  {
3806    if (CidrBitlenIPV4(old_class) > 0 && CidrBitlenIPV4(new_class) > 0)
3807      rebuild_cidr_list(AF_INET, conf, new_class,
3808                        &old_class->list_ipv4, &new_class->list_ipv4,
3809                        CidrBitlenIPV4(old_class) != CidrBitlenIPV4(new_class));
3810
3811 #ifdef IPV6
3812    if (CidrBitlenIPV6(old_class) > 0 && CidrBitlenIPV6(new_class) > 0)
3813      rebuild_cidr_list(AF_INET6, conf, new_class,
3814                        &old_class->list_ipv6, &new_class->list_ipv6,
3815                        CidrBitlenIPV6(old_class) != CidrBitlenIPV6(new_class));
3816 #endif
3817  }
3818
3819  destroy_cidr_class(old_class);
3820 }
3821
3822 /*
3823 * destroy_cidr_list
3824 *
3825 * inputs       - pointer to class dlink list of cidr blocks
3826 * output       - none
3827 * side effects - completely destroys the class link list of cidr blocks
3828 */
3829 static void
3830 destroy_cidr_list(dlink_list *list)
3831 {
3832  dlink_node *ptr = NULL, *next_ptr = NULL;
3833
3834  DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
3835  {
3836    dlinkDelete(ptr, list);
3837    MyFree(ptr->data);
3838  }
3839 }
3840
3841 /*
3842 * destroy_cidr_class
3843 *
3844 * inputs       - pointer to class
3845 * output       - none
3846 * side effects - completely destroys the class link list of cidr blocks
3847 */
3848 static void
3849 destroy_cidr_class(struct ClassItem *aclass)
3850 {
3851  destroy_cidr_list(&aclass->list_ipv4);
3852  destroy_cidr_list(&aclass->list_ipv6);
3853 }

Diff Legend

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