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-7.2/src/s_conf.c (file contents), Revision 201 by adx, Tue Nov 1 11:41:52 2005 UTC vs.
ircd-hybrid/trunk/src/conf.c (file contents), Revision 6441 by michael, Thu Aug 27 17:04:15 2015 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  s_conf.c: Configuration file functions.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-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"
30 < #include "tools.h"
31 < #include "s_conf.h"
32 < #include "s_serv.h"
30 > #include "conf.h"
31 > #include "conf_pseudo.h"
32 > #include "server.h"
33   #include "resv.h"
31 #include "s_stats.h"
34   #include "channel.h"
35   #include "client.h"
34 #include "common.h"
36   #include "event.h"
36 #include "hash.h"
37 #include "hook.h"
37   #include "irc_string.h"
39 #include "sprintf_irc.h"
38   #include "s_bsd.h"
41 #include "irc_getnameinfo.h"
42 #include "irc_getaddrinfo.h"
39   #include "ircd.h"
44 #include "list.h"
40   #include "listener.h"
41   #include "hostmask.h"
42   #include "modules.h"
43   #include "numeric.h"
44   #include "fdlist.h"
45 < #include "s_log.h"
45 > #include "log.h"
46   #include "send.h"
52 #include "s_gline.h"
53 #include "fileio.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 <
53 < struct Callback *client_check_cb = NULL;
54 < struct config_server_hide ConfigServerHide;
52 > #include "parse.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 >
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 server_items  = { NULL, NULL, 0 };
71 < dlink_list cluster_items = { NULL, NULL, 0 };
72 < dlink_list hub_items     = { NULL, NULL, 0 };
73 < dlink_list leaf_items    = { NULL, NULL, 0 };
74 < dlink_list oconf_items   = { NULL, NULL, 0 };
75 < dlink_list uconf_items   = { NULL, NULL, 0 };
76 < dlink_list xconf_items   = { NULL, NULL, 0 };
77 < dlink_list rxconf_items  = { NULL, NULL, 0 };
72 < dlink_list rkconf_items  = { NULL, NULL, 0 };
73 < dlink_list nresv_items   = { NULL, NULL, 0 };
74 < dlink_list class_items   = { NULL, NULL, 0 };
75 < dlink_list gdeny_items   = { NULL, NULL, 0 };
76 <
77 < dlink_list temporary_klines  = { NULL, NULL, 0 };
78 < dlink_list temporary_dlines  = { NULL, NULL, 0 };
79 < dlink_list temporary_xlines  = { NULL, NULL, 0 };
80 < dlink_list temporary_rklines = { NULL, NULL, 0 };
81 < dlink_list temporary_glines  = { NULL, NULL, 0 };
82 < dlink_list temporary_rxlines = { NULL, NULL, 0 };
83 < 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];
88 extern char yytext[];
82   extern int yyparse(); /* defined in y.tab.c */
90 unsigned int scount = 0; /* used by yyparse(), etc */
91 int ypass  = 1; /* used by yyparse()      */
92
93 /* internally defined functions */
94 static void lookup_confhost(struct ConfItem *);
95 static void set_default_conf(void);
96 static void validate_conf(void);
97 static void read_conf(FBFILE *);
98 static void clear_out_old_conf(void);
99 static void flush_deleted_I_P(void);
100 static void expire_tklines(dlink_list *);
101 static void garbage_collect_ip_entries(void);
102 static int hash_ip(struct irc_ssaddr *);
103 static int verify_access(struct Client *, const char *);
104 static int attach_iline(struct Client *, struct ConfItem *);
105 static struct ip_entry *find_or_add_ip(struct irc_ssaddr *);
106 static void parse_conf_file(int, int);
107 static dlink_list *map_to_list(ConfType);
108 static struct AccessItem *find_regexp_kline(const char *[]);
109 static int find_user_host(struct Client *, char *, char *, char *, unsigned int);
110
111 /*
112 * bit_len
113 */
114 static int cidr_limit_reached(int, struct irc_ssaddr *, struct ClassItem *);
115 static void remove_from_cidr_check(struct irc_ssaddr *, struct ClassItem *);
116 static void destroy_cidr_class(struct ClassItem *);
117
118 static void flags_to_ascii(unsigned int, const unsigned int[], char *, int);
119
120 FBFILE *conf_fbfile_in = NULL;
121
122 /* address of default class conf */
123 static struct ConfItem *class_default;
124
125 /* usually, with hash tables, you use a prime number...
126 * but in this case I am dealing with ip addresses,
127 * not ascii strings.
128 */
129 #define IP_HASH_SIZE 0x1000
130
131 struct ip_entry
132 {
133  struct irc_ssaddr ip;
134  int count;
135  time_t last_attempt;
136  struct ip_entry *next;
137 };
138
139 static struct ip_entry *ip_hash_table[IP_HASH_SIZE];
140 static BlockHeap *ip_entry_heap = NULL;
141 static int ip_entries_count = 0;
142
83  
144 inline void *
145 map_to_conf(struct ConfItem *aconf)
146 {
147  void *conf;
148  conf = (void *)((unsigned long)aconf +
149                  (unsigned long)sizeof(struct ConfItem));
150  return(conf);
151 }
152
153 inline struct ConfItem *
154 unmap_conf_item(void *aconf)
155 {
156  struct ConfItem *conf;
157
158  conf = (struct ConfItem *)((unsigned long)aconf -
159                             (unsigned long)sizeof(struct ConfItem));
160  return(conf);
161 }
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 171 | 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, struct DNSReply *reply)
96 > conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name, size_t namelength)
97   {
98 <  struct AccessItem *aconf = (struct AccessItem *)vptr;
177 <  struct ConfItem *conf;
98 >  struct MaskItem *const conf = vptr;
99  
100 <  MyFree(aconf->dns_query);
180 <  aconf->dns_query = NULL;
100 >  conf->dns_pending = 0;
101  
102 <  if (reply != NULL)
103 <    memcpy(&aconf->ipnum, &reply->addr, sizeof(reply->addr));
104 <  else {
105 <    ilog(L_NOTICE, "Host not found: %s, ignoring connect{} block",
186 <         aconf->host);
187 <    conf = unmap_conf_item(aconf);
188 <    sendto_realops_flags(UMODE_ALL, L_ALL,
189 <                         "Ignoring connect{} block for %s - host not found",
190 <                         conf->name);
191 <    delete_conf_item(conf);
192 <  }
102 >  if (addr)
103 >    memcpy(&conf->addr, addr, sizeof(conf->addr));
104 >  else
105 >    conf->dns_failed = 1;
106   }
107  
108   /* conf_dns_lookup()
# Line 199 | Line 112 | conf_dns_callback(void *vptr, struct DNS
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_query == NULL)
118 <  {
119 <    aconf->dns_query = MyMalloc(sizeof(struct DNSQuery));
120 <    aconf->dns_query->ptr = aconf;
121 <    aconf->dns_query->callback = conf_dns_callback;
122 <    gethost_byname(aconf->host, aconf->dns_query);
123 <  }
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   {
222  struct ConfItem *conf = NULL;
223  struct AccessItem *aconf = NULL;
224  struct ClassItem *aclass = NULL;
225  int status = 0;
226
137    switch (type)
138    {
139 <  case DLINE_TYPE:
140 <  case EXEMPTDLINE_TYPE:
231 <  case GLINE_TYPE:
232 <  case KLINE_TYPE:
233 <  case CLIENT_TYPE:
234 <  case OPER_TYPE:
235 <  case SERVER_TYPE:
236 <    conf = MyMalloc(sizeof(struct ConfItem) +
237 <                    sizeof(struct AccessItem));
238 <    aconf = map_to_conf(conf);
239 <    aconf->aftype = AF_INET;
240 <
241 <    /* Yes, sigh. switch on type again */
242 <    switch (type)
243 <    {
244 <    case EXEMPTDLINE_TYPE:
245 <      status = CONF_EXEMPTDLINE;
139 >    case CONF_XLINE:
140 >      return &xconf_items;
141        break;
142 <
143 <    case DLINE_TYPE:
249 <      status = CONF_DLINE;
142 >    case CONF_ULINE:
143 >      return &uconf_items;
144        break;
145 <
146 <    case KLINE_TYPE:
253 <      status = CONF_KLINE;
145 >    case CONF_NRESV:
146 >      return &nresv_items;
147        break;
148 <
149 <    case GLINE_TYPE:
257 <      status = CONF_GLINE;
148 >    case CONF_CRESV:
149 >      return &cresv_items;
150        break;
151 <
152 <    case CLIENT_TYPE:
261 <      status = CONF_CLIENT;
151 >    case CONF_OPER:
152 >      return &oconf_items;
153        break;
154 <
155 <    case OPER_TYPE:
265 <      status = CONF_OPERATOR;
266 <      dlinkAdd(conf, &conf->node, &oconf_items);
154 >    case CONF_SERVER:
155 >      return &server_items;
156        break;
157 <
158 <    case SERVER_TYPE:
270 <      status = CONF_SERVER;
271 <      dlinkAdd(conf, &conf->node, &server_items);
157 >    case CONF_SERVICE:
158 >      return &service_items;
159        break;
160 <
161 <    default:
160 >    case CONF_CLUSTER:
161 >      return &cluster_items;
162        break;
276    }
277    aconf->status = status;
278    break;
279
280  case LEAF_TYPE:
281    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
282                                       sizeof(struct MatchItem));
283    dlinkAdd(conf, &conf->node, &leaf_items);
284    break;
285
286  case HUB_TYPE:
287    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
288                                       sizeof(struct MatchItem));
289    dlinkAdd(conf, &conf->node, &hub_items);
290    break;
291
292  case ULINE_TYPE:
293    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
294                                       sizeof(struct MatchItem));
295    dlinkAdd(conf, &conf->node, &uconf_items);
296    break;
297
298  case GDENY_TYPE:
299    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
300                                       sizeof(struct AccessItem));
301    dlinkAdd(conf, &conf->node, &gdeny_items);
302    break;
303
304  case XLINE_TYPE:
305    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
306                                       sizeof(struct MatchItem));
307    dlinkAdd(conf, &conf->node, &xconf_items);
308    break;
309
310  case RXLINE_TYPE:
311    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
312                                       sizeof(struct MatchItem));
313    dlinkAdd(conf, &conf->node, &rxconf_items);
314    break;
315
316  case RKLINE_TYPE:
317    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
318                                       sizeof(struct AccessItem));
319    aconf = map_to_conf(conf);
320    aconf->status = CONF_KLINE;
321    dlinkAdd(conf, &conf->node, &rkconf_items);
322    break;
323
324  case CLUSTER_TYPE:
325    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem));
326    dlinkAdd(conf, &conf->node, &cluster_items);
327    break;
328
329  case CRESV_TYPE:
330    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
331                                       sizeof(struct ResvChannel));
332    break;
333
334  case NRESV_TYPE:
335    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
336                                       sizeof(struct MatchItem));
337    dlinkAdd(conf, &conf->node, &nresv_items);
338    break;
339
340  case CLASS_TYPE:
341    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
342                                       sizeof(struct ClassItem));
343    dlinkAdd(conf, &conf->node, &class_items);
344    aclass = (struct ClassItem *)map_to_conf(conf);
345    ConFreq(aclass)  = DEFAULT_CONNECTFREQUENCY;
346    PingFreq(aclass) = DEFAULT_PINGFREQUENCY;
347    MaxTotal(aclass) = MAXIMUM_LINKS_DEFAULT;
348    MaxSendq(aclass) = DEFAULT_SENDQ;
349    CurrUserCount(aclass) = 0;
350    break;
351
352  default:
353    conf = NULL;
354    break;
355  }
356
357  /* XXX Yes, this will core if default is hit. I want it to for now - db */
358  conf->type = type;
359
360  return(conf);
361 }
362
363 void
364 delete_conf_item(struct ConfItem *conf)
365 {
366  struct MatchItem *match_item;
367  struct AccessItem *aconf;
368  ConfType type = conf->type;
369
370  MyFree(conf->name);
371  conf->name = NULL;
372
373  switch(type)
374  {
375  case DLINE_TYPE:
376  case EXEMPTDLINE_TYPE:
377  case GLINE_TYPE:
378  case KLINE_TYPE:
379  case CLIENT_TYPE:
380  case OPER_TYPE:
381  case SERVER_TYPE:
382    aconf = map_to_conf(conf);
383
384    if (aconf->dns_query != NULL)
385    {
386      delete_resolver_queries(aconf->dns_query);
387      MyFree(aconf->dns_query);
388    }
389    if (aconf->passwd != NULL)
390      memset(aconf->passwd, 0, strlen(aconf->passwd));
391    if (aconf->spasswd != NULL)
392      memset(aconf->spasswd, 0, strlen(aconf->spasswd));
393    aconf->class_ptr = NULL;
394
395    MyFree(aconf->passwd);
396    MyFree(aconf->spasswd);
397    MyFree(aconf->reason);
398    MyFree(aconf->oper_reason);
399    MyFree(aconf->user);
400    MyFree(aconf->host);
401    MyFree(aconf->fakename);
402 #ifdef HAVE_LIBCRYPTO
403    if (aconf->rsa_public_key)
404      RSA_free(aconf->rsa_public_key);
405    MyFree(aconf->rsa_public_key_file);
406 #endif
407
408    /* Yes, sigh. switch on type again */
409    switch(type)
410    {
411    case EXEMPTDLINE_TYPE:
412    case DLINE_TYPE:
413    case GLINE_TYPE:
414    case KLINE_TYPE:
415    case CLIENT_TYPE:
416      MyFree(conf);
417      break;
418
419    case OPER_TYPE:
420      aconf = map_to_conf(conf);
421      if (!IsConfIllegal(aconf))
422        dlinkDelete(&conf->node, &oconf_items);
423      MyFree(conf);
424      break;
425
426    case SERVER_TYPE:
427      aconf = map_to_conf(conf);
428      if (!IsConfIllegal(aconf))
429        dlinkDelete(&conf->node, &server_items);
430      MyFree(conf);
431      break;
432
163      default:
164 <      break;
435 <    }
436 <    break;
437 <
438 <  case HUB_TYPE:
439 <    match_item = map_to_conf(conf);
440 <    MyFree(match_item->user);
441 <    MyFree(match_item->host);
442 <    MyFree(match_item->reason);
443 <    MyFree(match_item->oper_reason);
444 <    /* If marked illegal, its already been pulled off of the hub_items list */
445 <    if (!match_item->illegal)
446 <      dlinkDelete(&conf->node, &hub_items);
447 <    MyFree(conf);
448 <    break;
449 <
450 <  case LEAF_TYPE:
451 <    match_item = map_to_conf(conf);
452 <    MyFree(match_item->user);
453 <    MyFree(match_item->host);
454 <    MyFree(match_item->reason);
455 <    MyFree(match_item->oper_reason);
456 <    /* If marked illegal, its already been pulled off of the leaf_items list */
457 <    if (!match_item->illegal)
458 <      dlinkDelete(&conf->node, &leaf_items);
459 <    MyFree(conf);
460 <    break;
461 <
462 <  case ULINE_TYPE:
463 <    match_item = map_to_conf(conf);
464 <    MyFree(match_item->user);
465 <    MyFree(match_item->host);
466 <    MyFree(match_item->reason);
467 <    MyFree(match_item->oper_reason);
468 <    dlinkDelete(&conf->node, &uconf_items);
469 <    MyFree(conf);
470 <    break;
471 <
472 <  case XLINE_TYPE:
473 <    match_item = map_to_conf(conf);
474 <    MyFree(match_item->user);
475 <    MyFree(match_item->host);
476 <    MyFree(match_item->reason);
477 <    MyFree(match_item->oper_reason);
478 <    dlinkDelete(&conf->node, &xconf_items);
479 <    MyFree(conf);
480 <    break;
481 <
482 <  case RKLINE_TYPE:
483 <    aconf = map_to_conf(conf);
484 <    MyFree(aconf->regexuser);
485 <    MyFree(aconf->regexhost);
486 <    MyFree(aconf->user);
487 <    MyFree(aconf->host);
488 <    MyFree(aconf->reason);
489 <    MyFree(aconf->oper_reason);
490 <    dlinkDelete(&conf->node, &rkconf_items);
491 <    MyFree(conf);
492 <    break;
493 <
494 <  case RXLINE_TYPE:
495 <    MyFree(conf->regexpname);
496 <    match_item = map_to_conf(conf);
497 <    MyFree(match_item->user);
498 <    MyFree(match_item->host);
499 <    MyFree(match_item->reason);
500 <    MyFree(match_item->oper_reason);
501 <    dlinkDelete(&conf->node, &rxconf_items);
502 <    MyFree(conf);
503 <    break;
504 <
505 <  case NRESV_TYPE:
506 <    match_item = map_to_conf(conf);
507 <    MyFree(match_item->user);
508 <    MyFree(match_item->host);
509 <    MyFree(match_item->reason);
510 <    MyFree(match_item->oper_reason);
511 <    dlinkDelete(&conf->node, &nresv_items);
512 <    MyFree(conf);
513 <    break;
514 <
515 <  case GDENY_TYPE:
516 <    aconf = map_to_conf(conf);
517 <    MyFree(aconf->user);
518 <    MyFree(aconf->host);
519 <    dlinkDelete(&conf->node, &gdeny_items);
520 <    MyFree(conf);
521 <    break;
522 <
523 <  case CLUSTER_TYPE:
524 <    dlinkDelete(&conf->node, &cluster_items);
525 <    MyFree(conf);
526 <    break;
527 <
528 <  case CRESV_TYPE:
529 <    MyFree(conf);
530 <    break;
531 <
532 <  case CLASS_TYPE:
533 <    dlinkDelete(&conf->node, &class_items);
534 <    MyFree(conf);
535 <    break;
536 <
537 <  default:
538 <    break;
164 >      return NULL;
165    }
166   }
167  
168 < /* free_access_item()
169 < *
544 < * inputs       - pointer to conf to free
545 < * output       - none
546 < * side effects - crucial password fields are zeroed, conf is freed
547 < */
548 < void
549 < 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);
556 <  delete_conf_item(conf);
557 < }
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  
562 /* report_confitem_types()
563 *
564 * inputs       - pointer to client requesting confitem report
565 *              - ConfType to report
566 * output       - none
567 * side effects -
568 */
183   void
184 < report_confitem_types(struct Client *source_p, ConfType type, int temp)
184 > conf_free(struct MaskItem *conf)
185   {
186 <  dlink_node *ptr = NULL;
187 <  struct ConfItem *conf = NULL;
574 <  struct AccessItem *aconf = NULL;
575 <  struct MatchItem *matchitem = NULL;
576 <  struct ClassItem *classitem = NULL;
577 <  char buf[12];
578 <  char *p = NULL;
186 >  dlink_node *node = NULL, *node_next = NULL;
187 >  dlink_list *list = NULL;
188  
189 <  switch (type)
190 <  {
582 <  case GDENY_TYPE:
583 <    DLINK_FOREACH(ptr, gdeny_items.head)
584 <    {
585 <      conf = ptr->data;
586 <      aconf = map_to_conf(conf);
587 <
588 <      p = buf;
589 <
590 <      if (aconf->flags & GDENY_BLOCK)
591 <        *p++ = 'B';
592 <      else
593 <        *p++ = 'b';
594 <
595 <      if (aconf->flags & GDENY_REJECT)
596 <        *p++ = 'R';
597 <      else
598 <        *p++ = 'r';
599 <
600 <      *p = '\0';
601 <
602 <      sendto_one(source_p, ":%s %d %s V %s@%s %s %s",
603 <                 me.name, RPL_STATSDEBUG, source_p->name,
604 <                 aconf->user, aconf->host, conf->name, buf);
605 <    }
606 <    break;
189 >  if ((list = map_to_list(conf->type)))
190 >    dlinkFindDelete(list, conf);
191  
192 <  case XLINE_TYPE:
609 <    DLINK_FOREACH(ptr, xconf_items.head)
610 <    {
611 <      conf = ptr->data;
612 <      matchitem = map_to_conf(conf);
613 <
614 <      sendto_one(source_p, form_str(RPL_STATSXLINE),
615 <                 me.name, source_p->name,
616 <                 matchitem->hold ? "x": "X", matchitem->count,
617 <                 conf->name, matchitem->reason);
618 <    }
619 <    break;
620 <
621 <  case RXLINE_TYPE:
622 <    DLINK_FOREACH(ptr, rxconf_items.head)
623 <    {
624 <      conf = ptr->data;
625 <      matchitem = map_to_conf(conf);
626 <
627 <      sendto_one(source_p, form_str(RPL_STATSXLINE),
628 <                 me.name, source_p->name,
629 <                 matchitem->hold ? "xR": "XR", matchitem->count,
630 <                 conf->name, matchitem->reason);
631 <    }
632 <    break;
633 <
634 <  case RKLINE_TYPE:
635 <    p = temp ? "Rk" : "RK";
636 <
637 <    DLINK_FOREACH(ptr, rkconf_items.head)
638 <    {
639 <      aconf = map_to_conf((conf = ptr->data));
640 <
641 <      if (temp && !(conf->flags & CONF_FLAGS_TEMPORARY))
642 <        continue;
643 <
644 <      sendto_one(source_p, form_str(RPL_STATSKLINE), me.name,
645 <                 source_p->name, p, aconf->host, aconf->user,
646 <                 aconf->reason, aconf->oper_reason ? aconf->oper_reason : "");
647 <    }
648 <    break;
649 <
650 <  case ULINE_TYPE:
651 <    DLINK_FOREACH(ptr, uconf_items.head)
652 <    {
653 <      conf = ptr->data;
654 <      matchitem = map_to_conf(conf);
655 <
656 <      p = buf;
657 <
658 <      /* some of these are redundant for the sake of
659 <       * consistency with cluster{} flags
660 <       */
661 <      *p++ = 'c';
662 <      flags_to_ascii(matchitem->action, shared_bit_table, p, 0);
663 <
664 <      sendto_one(source_p, form_str(RPL_STATSULINE),
665 <                 me.name, source_p->name, conf->name,
666 <                 matchitem->user?matchitem->user: "*",
667 <                 matchitem->host?matchitem->host: "*", buf);
668 <    }
669 <
670 <    DLINK_FOREACH(ptr, cluster_items.head)
671 <    {
672 <      conf = ptr->data;
673 <
674 <      p = buf;
675 <
676 <      *p++ = 'C';
677 <      flags_to_ascii(conf->flags, shared_bit_table, p, 0);
678 <
679 <      sendto_one(source_p, form_str(RPL_STATSULINE),
680 <                 me.name, source_p->name, conf->name,
681 <                 "*", "*", buf);
682 <    }
683 <
684 <    break;
685 <
686 <  case OPER_TYPE:
687 <    DLINK_FOREACH(ptr, oconf_items.head)
688 <    {
689 <      conf = ptr->data;
690 <      aconf = map_to_conf(conf);
691 <
692 <      /* Don't allow non opers to see oper privs */
693 <      if (IsOper(source_p))
694 <        sendto_one(source_p, form_str(RPL_STATSOLINE),
695 <                   me.name, source_p->name, 'O', aconf->user, aconf->host,
696 <                   conf->name, oper_privs_as_string(aconf->port),
697 <                   aconf->class_ptr ? aconf->class_ptr->name : "<default>");
698 <      else
699 <        sendto_one(source_p, form_str(RPL_STATSOLINE),
700 <                   me.name, source_p->name, 'O', aconf->user, aconf->host,
701 <                   conf->name, "0",
702 <                   aconf->class_ptr ? aconf->class_ptr->name : "<default>");
703 <    }
704 <    break;
705 <
706 <  case CLASS_TYPE:
707 <    DLINK_FOREACH(ptr, class_items.head)
708 <    {
709 <      conf = ptr->data;
710 <      classitem = map_to_conf(conf);
711 <      sendto_one(source_p, form_str(RPL_STATSYLINE),
712 <                 me.name, source_p->name, 'Y',
713 <                 conf->name, PingFreq(classitem),
714 <                 ConFreq(classitem),
715 <                 MaxTotal(classitem), MaxSendq(classitem));
716 <    }
717 <    break;
718 <
719 <  case CONF_TYPE:
720 <  case CLIENT_TYPE:
721 <    break;
722 <
723 <  case SERVER_TYPE:
724 <    DLINK_FOREACH(ptr, server_items.head)
725 <    {
726 <      p = buf;
727 <
728 <      conf = ptr->data;
729 <      aconf = map_to_conf(conf);
730 <
731 <      buf[0] = '\0';
732 <
733 <      if (IsConfAllowAutoConn(aconf))
734 <        *p++ = 'A';
735 <      if (IsConfCryptLink(aconf))
736 <        *p++ = 'C';
737 <      if (IsConfLazyLink(aconf))
738 <        *p++ = 'L';
739 <      if (aconf->fakename)
740 <        *p++ = 'M';
741 <      if (IsConfTopicBurst(aconf))
742 <        *p++ = 'T';
743 <      if (IsConfCompressed(aconf))
744 <        *p++ = 'Z';
745 <      if (buf[0] == '\0')
746 <        *p++ = '*';
747 <
748 <      *p = '\0';
749 <
750 <      /* Allow admins to see actual ips
751 <       * unless hide_server_ips is enabled
752 <       */
753 <      if (!ConfigServerHide.hide_server_ips && IsAdmin(source_p))
754 <        sendto_one(source_p, form_str(RPL_STATSCLINE),
755 <                   me.name, source_p->name, 'C', aconf->host,
756 <                   buf, conf->name, aconf->port,
757 <                   aconf->class_ptr ? aconf->class_ptr->name : "<default>");
758 <        else
759 <          sendto_one(source_p, form_str(RPL_STATSCLINE),
760 <                     me.name, source_p->name, 'C',
761 <                     "*@127.0.0.1", buf, conf->name, aconf->port,
762 <                     aconf->class_ptr ? aconf->class_ptr->name : "<default>");
763 <    }
764 <    break;
765 <
766 <  case HUB_TYPE:
767 <    DLINK_FOREACH(ptr, hub_items.head)
768 <    {
769 <      conf = ptr->data;
770 <      matchitem = map_to_conf(conf);
771 <      sendto_one(source_p, form_str(RPL_STATSHLINE), me.name,
772 <                 source_p->name, 'H', matchitem->host, conf->name, 0, "*");
773 <    }
774 <    break;
775 <
776 <  case LEAF_TYPE:
777 <    DLINK_FOREACH(ptr, leaf_items.head)
778 <    {
779 <      conf = ptr->data;
780 <      matchitem = map_to_conf(conf);
781 <      sendto_one(source_p, form_str(RPL_STATSLLINE), me.name,
782 <                 source_p->name, 'L', matchitem->host, conf->name, 0, "*");
783 <    }
784 <    break;
785 <
786 <  case GLINE_TYPE:
787 <  case KLINE_TYPE:
788 <  case DLINE_TYPE:
789 <  case EXEMPTDLINE_TYPE:
790 <  case CRESV_TYPE:
791 <  case NRESV_TYPE:
792 <  case CLUSTER_TYPE:
793 <    break;
794 <  }
795 < }
192 >  MyFree(conf->name);
193  
194 < /* check_client()
195 < *
196 < * inputs       - pointer to client
197 < * output       - 0 = Success
198 < *                NOT_AUTHORIZED    (-1) = Access denied (no I line match)
199 < *                IRCD_SOCKET_ERROR (-2) = Bad socket.
200 < *                I_LINE_FULL       (-3) = I-line is full
201 < *                TOO_MANY          (-4) = Too many connections from hostname
202 < *                BANNED_CLIENT     (-5) = K-lined
203 < * side effects - Ordinary client access check.
204 < *                Look for conf lines which have the same
205 < *                status as the flags passed.
206 < */
207 < static void *
208 < check_client(va_list args)
209 < {
210 <  struct Client *source_p = va_arg(args, struct Client *);
211 <  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 <  {
820 <    ilog(L_INFO, "Access denied: %s[%s]",
821 <         source_p->name, source_p->sockhost);
822 <  }
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 <  switch (i)
213 >  if (conf->rsa_public_key)
214 >    RSA_free(conf->rsa_public_key);
215 > #endif
216 >  DLINK_FOREACH_SAFE(node, node_next, conf->hub_list.head)
217    {
218 <    case IRCD_SOCKET_ERROR:
219 <      exit_client(source_p, &me, "Socket Error");
220 <      break;
829 <
830 <    case TOO_MANY:
831 <      sendto_realops_flags(UMODE_FULL, L_ALL,
832 <                           "Too many on IP for %s (%s).",
833 <                           get_client_name(source_p, SHOW_IP),
834 <                           source_p->sockhost);
835 <      ilog(L_INFO,"Too many connections on IP from %s.",
836 <           get_client_name(source_p, SHOW_IP));
837 <      ServerStats->is_ref++;
838 <      exit_client(source_p, &me, "No more connections allowed on that IP");
839 <      break;
840 <
841 <    case I_LINE_FULL:
842 <      sendto_realops_flags(UMODE_FULL, L_ALL,
843 <                           "I-line is full for %s (%s).",
844 <                           get_client_name(source_p, SHOW_IP),
845 <                           source_p->sockhost);
846 <      ilog(L_INFO,"Too many connections from %s.",
847 <           get_client_name(source_p, SHOW_IP));
848 <       ServerStats->is_ref++;
849 <      exit_client(source_p, &me,
850 <                "No more connections allowed in your connection class");
851 <      break;
852 <
853 <    case NOT_AUTHORIZED:
854 <    {
855 <      static char ipaddr[HOSTIPLEN];
856 <      ServerStats->is_ref++;
857 <      /* jdc - lists server name & port connections are on */
858 <      /*       a purely cosmetical change */
859 <      irc_getnameinfo((struct sockaddr*)&source_p->localClient->ip,
860 <            source_p->localClient->ip.ss_len, ipaddr, HOSTIPLEN, NULL, 0,
861 <            NI_NUMERICHOST);
862 <      sendto_realops_flags(UMODE_UNAUTH, L_ALL,
863 <                           "Unauthorized client connection from %s [%s] on [%s/%u].",
864 <                           get_client_name(source_p, SHOW_IP),
865 <                           ipaddr,
866 <                           source_p->localClient->listener->name,
867 <                           source_p->localClient->listener->port);
868 <      ilog(L_INFO,
869 <          "Unauthorized client connection from %s on [%s/%u].",
870 <          get_client_name(source_p, SHOW_IP),
871 <          source_p->localClient->listener->name,
872 <          source_p->localClient->listener->port);
873 <
874 <      /* XXX It is prolematical whether it is better to use the
875 <       * capture reject code here or rely on the connecting too fast code.
876 <       * - Dianora
877 <       */
878 <      if(REJECT_HOLD_TIME > 0)
879 <      {
880 <        sendto_one(source_p, ":%s NOTICE %s :You are not authorized to use this server",
881 <                   me.name, source_p->name);
882 <        source_p->localClient->reject_delay = CurrentTime + REJECT_HOLD_TIME;
883 <        SetCaptured(source_p);
884 <      }
885 <      else
886 <        exit_client(source_p, &me, "You are not authorized to use this server");
887 <      break;
888 <    }
889 <
890 <   case BANNED_CLIENT:
891 <     /*
892 <      * Don't exit them immediately, play with them a bit.
893 <      * - Dianora
894 <      */
895 <     if (REJECT_HOLD_TIME > 0)
896 <     {
897 <       source_p->localClient->reject_delay = CurrentTime + REJECT_HOLD_TIME;
898 <       SetCaptured(source_p);
899 <     }
900 <     else
901 <       exit_client(source_p, &me, "Banned");
902 <     ServerStats->is_ref++;
903 <     break;
904 <
905 <   case 0:
906 <   default:
907 <     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);
911 < }
912 <
913 < /* verify_access()
914 < *
915 < * inputs       - pointer to client to verify
916 < *              - pointer to proposed username
917 < * output       - 0 if success -'ve if not
918 < * side effect  - find the first (best) I line to attach.
919 < */
920 < static int
921 < verify_access(struct Client *client_p, const char *username)
922 < {
923 <  struct AccessItem *aconf = NULL, *rkconf = NULL;
924 <  struct ConfItem *conf = NULL;
925 <  char non_ident[USERLEN + 1] = { '~', '\0' };
926 <  const char *uhi[3];
927 <
928 <  if (IsGotId(client_p))
929 <  {
930 <    aconf = find_address_conf(client_p->host, client_p->username,
931 <                             &client_p->localClient->ip,
932 <                             client_p->localClient->aftype,
933 <                             client_p->localClient->passwd);
934 <  }
935 <  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,
940 <                             client_p->localClient->aftype,
941 <                             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;
945 <  uhi[1] = client_p->host;
946 <  uhi[2] = client_p->sockhost;
947 <
948 <  rkconf = find_regexp_kline(uhi);
949 <
950 <  if (aconf != NULL)
230 >  DLINK_FOREACH_SAFE(node, node_next, conf->exempt_list.head)
231    {
232 <    if (IsConfClient(aconf) && !rkconf)
953 <    {
954 <      conf = unmap_conf_item(aconf);
955 <
956 <      if (IsConfRedir(aconf))
957 <      {
958 <        sendto_one(client_p, form_str(RPL_REDIR),
959 <                   me.name, client_p->name,
960 <                   conf->name ? conf->name : "",
961 <                   aconf->port);
962 <        return(NOT_AUTHORIZED);
963 <      }
964 <
965 <      if (IsConfDoIdentd(aconf))
966 <        SetNeedId(client_p);
967 <
968 <      /* Thanks for spoof idea amm */
969 <      if (IsConfDoSpoofIp(aconf))
970 <      {
971 <        conf = unmap_conf_item(aconf);
972 <
973 <        if (!ConfigFileEntry.hide_spoof_ips && IsConfSpoofNotice(aconf))
974 <          sendto_realops_flags(UMODE_ALL, L_ADMIN, "%s spoofing: %s as %s",
975 <                               client_p->name, client_p->host, conf->name);
976 <        strlcpy(client_p->host, conf->name, sizeof(client_p->host));
977 <        SetIPSpoof(client_p);
978 <      }
232 >    struct exempt *exptr = node->data;
233  
234 <      return(attach_iline(client_p, conf));
235 <    }
236 <    else if (rkconf || IsConfKill(aconf) || (ConfigFileEntry.glines && IsConfGline(aconf)))
237 <    {
238 <      /* XXX */
985 <      aconf = rkconf ? rkconf : aconf;
986 <      if (IsConfGline(aconf))
987 <        sendto_one(client_p, ":%s NOTICE %s :*** G-lined", me.name,
988 <                   client_p->name);
989 <      if (ConfigFileEntry.kline_with_reason)
990 <        sendto_one(client_p, ":%s NOTICE %s :*** Banned %s",
991 <                  me.name, client_p->name, aconf->reason);
992 <      return(BANNED_CLIENT);
993 <    }
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;
1010 <  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);
261 >  AddFlag(client_p, FLAGS_IPHASH);
262  
263 <  aconf = (struct AccessItem *)map_to_conf(conf);
264 <  if (aconf->class_ptr == NULL)
1021 <    return NOT_AUTHORIZED;  /* If class is missing, this is best */
1022 <
1023 <  aclass = (struct ClassItem *)map_to_conf(aconf->class_ptr);
1024 <
1025 <  count_user_host(client_p->username, client_p->host,
1026 <                  &global, &local, &ident);
263 >  userhost_count(client_p->username, client_p->host,
264 >                 &global, &local, &ident);
265  
266    /* XXX blah. go down checking the various silly limits
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))
285 <      return TOO_MANY;  /* Already at maximum allowed */
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, "
1051 <               "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()
1058 < *
1059 < * inputs               - NONE
1060 < * output               - NONE
1061 < * side effects         - allocate memory for ip_entry(s)
1062 < *                      - clear the ip hash table
1063 < */
1064 < void
1065 < init_ip_hash_table(void)
1066 < {
1067 <  ip_entry_heap = BlockHeapCreate("ip", sizeof(struct ip_entry),
1068 <    2 * hard_fdlimit);
1069 <  memset(ip_hash_table, 0, sizeof(ip_hash_table));
1070 < }
1071 <
1072 < /* find_or_add_ip()
1073 < *
1074 < * inputs       - pointer to struct irc_ssaddr
1075 < * output       - pointer to a struct ip_entry
1076 < * 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;
1085 <  int hash_index = hash_ip(ip_in), res;
1086 <  struct sockaddr_in *v4 = (struct sockaddr_in *)ip_in, *ptr_v4;
1087 < #ifdef IPV6
1088 <  struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)ip_in, *ptr_v6;
1089 < #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)
1097 <    {
1098 <      ptr_v6 = (struct sockaddr_in6 *)&ptr->ip;
1099 <      res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr));
1100 <    }
1101 <    else
1102 < #endif
1103 <    {
1104 <      ptr_v4 = (struct sockaddr_in *)&ptr->ip;
1105 <      res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr));
1106 <    }
1107 <    if (res == 0)
1108 <    {
1109 <      /* Found entry already in hash, return it. */
1110 <      return ptr;
1111 <    }
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));
1120 <
1121 <  newptr->next = ip_hash_table[hash_index];
1122 <  ip_hash_table[hash_index] = newptr;
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 <  return newptr;
324 < }
323 >  if (!conf)
324 >    return NOT_AUTHORIZED;
325  
326 < /* remove_one_ip()
1128 < *
1129 < * inputs        - unsigned long IP address value
1130 < * output        - NONE
1131 < * side effects  - The ip address given, is looked up in ip hash table
1132 < *                 and number of ip#'s for that ip decremented.
1133 < *                 If ip # count reaches 0 and has expired,
1134 < *                 the struct ip_entry is returned to the ip_entry_heap
1135 < */
1136 < void
1137 < remove_one_ip(struct irc_ssaddr *ip_in)
1138 < {
1139 <  struct ip_entry *ptr;
1140 <  struct ip_entry *last_ptr = NULL;
1141 <  int hash_index = hash_ip(ip_in), res;
1142 <  struct sockaddr_in *v4 = (struct sockaddr_in *)ip_in, *ptr_v4;
1143 < #ifdef IPV6
1144 <  struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)ip_in, *ptr_v6;
1145 < #endif
326 >  assert(IsConfClient(conf) || IsConfKill(conf));
327  
328 <  for (ptr = ip_hash_table[hash_index]; ptr; ptr = ptr->next)
328 >  if (IsConfClient(conf))
329    {
330 < #ifdef IPV6
1150 <    if (ptr->ip.ss.ss_family != ip_in->ss.ss_family)
1151 <      continue;
1152 <    if (ip_in->ss.ss_family == AF_INET6)
330 >    if (IsConfRedir(conf))
331      {
332 <      ptr_v6 = (struct sockaddr_in6 *)&ptr->ip;
333 <      res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr));
334 <    }
335 <    else
1158 < #endif
1159 <    {
1160 <      ptr_v4 = (struct sockaddr_in *)&ptr->ip;
1161 <      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;
1165 <    if (ptr->count > 0)
1166 <      ptr->count--;
1167 <    if (ptr->count == 0 &&
1168 <        (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
1173 <        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);
1176 <      ip_entries_count--;
1177 <      return;
344 >      strlcpy(client_p->host, conf->name, sizeof(client_p->host));
345      }
1179    last_ptr = ptr;
1180  }
1181 }
1182
1183 /* hash_ip()
1184 *
1185 * input        - pointer to an irc_inaddr
1186 * output       - integer value used as index into hash table
1187 * side effects - hopefully, none
1188 */
1189 static int
1190 hash_ip(struct irc_ssaddr *addr)
1191 {
1192  if (addr->ss.ss_family == AF_INET)
1193  {
1194    struct sockaddr_in *v4 = (struct sockaddr_in *)addr;
1195    int hash;
1196    u_int32_t ip;
346  
347 <    ip   = ntohl(v4->sin_addr.s_addr);
1199 <    hash = ((ip >> 12) + ip) & (IP_HASH_SIZE-1);
1200 <    return hash;
1201 <  }
1202 < #ifdef IPV6
1203 <  else
1204 <  {
1205 <    int hash;
1206 <    struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr;
1207 <    u_int32_t *ip = (u_int32_t *)&v6->sin6_addr.s6_addr;
1208 <
1209 <    hash  = ip[0] ^ ip[3];
1210 <    hash ^= hash >> 16;  
1211 <    hash ^= hash >> 8;  
1212 <    hash  = hash & (IP_HASH_SIZE - 1);
1213 <    return hash;
347 >    return attach_iline(client_p, conf);
348    }
349 < #else
350 <  return 0;
351 < #endif
349 >
350 >  sendto_one_notice(client_p, &me, ":*** Banned: %s", conf->reason);
351 >  return BANNED_CLIENT;
352   }
353  
354 < /* count_ip_hash()
1221 < *
1222 < * inputs        - pointer to counter of number of ips hashed
1223 < *               - pointer to memory used for ip hash
1224 < * output        - returned via pointers input
1225 < * 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(int *number_ips_stored, unsigned long *mem_ips_stored)
367 > int
368 > check_client(struct Client *source_p)
369   {
1233  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 < }
385 <
386 < /* garbage_collect_ip_entries()
387 < *
1251 < * input        - NONE
1252 < * output       - NONE
1253 < * side effects - free up all ip entries with no connections
1254 < */
1255 < static void
1256 < garbage_collect_ip_entries(void)
1257 < {
1258 <  struct ip_entry *ptr;
1259 <  struct ip_entry *last_ptr;
1260 <  struct ip_entry *next_ptr;
1261 <  int i;
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 <  for (i = 0; i < IP_HASH_SIZE; i++)
390 <  {
391 <    last_ptr = NULL;
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 (ptr = ip_hash_table[i]; ptr; ptr = next_ptr)
401 <    {
402 <      next_ptr = ptr->next;
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 >      ++ServerStats.is_ref;
415 >      exit_client(source_p, "You are not authorized to use this server");
416 >      break;
417 >
418 >    case BANNED_CLIENT:
419 >      ++ServerStats.is_ref;
420 >      exit_client(source_p, "Banned");
421 >      break;
422  
423 <      if (ptr->count == 0 &&
424 <          (CurrentTime - ptr->last_attempt) >= ConfigFileEntry.throttle_time)
425 <      {
1274 <        if (last_ptr != NULL)
1275 <          last_ptr->next = ptr->next;
1276 <        else
1277 <          ip_hash_table[i] = ptr->next;
1278 <        BlockHeapFree(ip_entry_heap, ptr);
1279 <        ip_entries_count--;
1280 <      }
1281 <      else
1282 <        last_ptr = ptr;
1283 <    }
423 >    case 0:
424 >    default:
425 >      break;
426    }
427 +
428 +  return !(i < 0);
429   }
430  
431   /* detach_conf()
# Line 1292 | 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;
1299 <  struct ConfItem *conf;
1300 <  struct ClassItem *aclass;
1301 <  struct AccessItem *aconf;
1302 <  struct ConfItem *aclass_conf;
1303 <  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;
446 >    struct MaskItem *conf = node->data;
447  
448 <    if (type == CONF_TYPE || conf->type == type)
449 <    {
450 <      dlinkDelete(ptr, &client_p->localClient->confs);
1312 <      free_dlink_node(ptr);
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 <      switch (conf->type)
453 <      {
1316 <      case CLIENT_TYPE:
1317 <      case OPER_TYPE:
1318 <      case SERVER_TYPE:
1319 <        aconf = (struct AccessItem *)map_to_conf(conf);
1320 <        if ((aclass_conf = ClassPtr(aconf)) != NULL)
1321 <        {
1322 <          aclass = (struct ClassItem *)map_to_conf(aclass_conf);
452 >    if (!(conf->type & type))
453 >      continue;
454  
455 <          if (conf->type == CLIENT_TYPE)
456 <            remove_from_cidr_check(&client_p->localClient->ip, aclass);
455 >    dlinkDelete(node, &client_p->connection->confs);
456 >    free_dlink_node(node);
457  
458 <          if (CurrUserCount(aclass) > 0)
459 <            aclass->curr_user_count--;
1329 <          if (MaxTotal(aclass) < 0 && CurrUserCount(aclass) <= 0)
1330 <            delete_conf_item(aclass_conf);
1331 <        }
458 >    if (conf->type == CONF_CLIENT)
459 >      remove_from_cidr_check(&client_p->connection->ip, conf->class);
460  
461 <        /* Please, no ioccc entries - Dianora */
462 <        if (aconf->clients > 0)
463 <          --aconf->clients;
464 <        if (aconf->clients == 0 && IsConfIllegal(aconf))
1337 <          delete_conf_item(conf);
1338 <        break;
1339 <      case LEAF_TYPE:
1340 <      case HUB_TYPE:
1341 <        match_item = (struct MatchItem *)map_to_conf(conf);
1342 <        if (match_item->ref_count == 0 && match_item->illegal)
1343 <          delete_conf_item(conf);
1344 <        break;
1345 <      default:
1346 <        break;
1347 <      }
1348 <
1349 <      if (type != CONF_TYPE)
1350 <        return 0;
461 >    if (--conf->class->ref_count == 0 && conf->class->active == 0)
462 >    {
463 >      class_free(conf->class);
464 >      conf->class = NULL;
465      }
1352  }
466  
467 <  return -1;
467 >    if (--conf->ref_count == 0 && conf->active == 0)
468 >      conf_free(conf);
469 >  }
470   }
471  
472   /* attach_conf()
# Line 1365 | 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 <  struct AccessItem *aconf;
1371 <  struct MatchItem *match_item;
1372 <
1373 <  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 <  {
1380 <    aconf = (struct AccessItem *)map_to_conf(conf);
1381 <
1382 <    if (IsConfIllegal(aconf))
1383 <      return NOT_AUTHORIZED;
1384 <
1385 <    if (conf->type == CLIENT_TYPE)
1386 <    {
1387 <      struct ClassItem *aclass;
1388 <      aclass = (struct ClassItem *)map_to_conf(aconf->class_ptr);
1389 <
1390 <      if (cidr_limit_reached(IsConfExemptLimits(aconf),
1391 <                             &client_p->localClient->ip, aclass))
1392 <        return TOO_MANY;  /* Already at maximum allowed */
1393 <
1394 <      CurrUserCount(aclass)++;
1395 <    }
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 <    aconf->clients++;
494 <  }
1399 <  else if (conf->type == HUB_TYPE || conf->type == LEAF_TYPE)
1400 <  {
1401 <    match_item = (struct MatchItem *)map_to_conf(conf);
1402 <    match_item->ref_count++;
1403 <  }
493 >  conf->class->ref_count++;
494 >  conf->ref_count++;
495  
496 <  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 1419 | Line 510 | int
510   attach_connect_block(struct Client *client_p, const char *name,
511                       const char *host)
512   {
513 <  dlink_node *ptr;
1423 <  struct ConfItem *conf;
1424 <  struct AccessItem *aconf;
1425 <
1426 <  assert(client_p != NULL);
1427 <  assert(host != NULL);
513 >  dlink_node *node = NULL;
514  
515 <  if (client_p == NULL || host == NULL)
1430 <    return 0;
515 >  assert(host);
516  
517 <  DLINK_FOREACH(ptr, server_items.head)
517 >  DLINK_FOREACH(node, server_items.head)
518    {
519 <    conf = ptr->data;
1435 <    aconf = (struct AccessItem *)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  
1447 /* find_conf_exact()
1448 *
1449 * inputs       - type of ConfItem
1450 *              - pointer to name to find
1451 *              - pointer to username to find
1452 *              - pointer to host to find
1453 * output       - NULL or pointer to conf found
1454 * side effects - find a conf entry which matches the hostname
1455 *                and has the same name.
1456 */
1457 struct ConfItem *
1458 find_conf_exact(ConfType type, const char *name, const char *user,
1459                const char *host)
1460 {
1461  dlink_node *ptr;
1462  dlink_list *list_p;
1463  struct ConfItem *conf = NULL;
1464  struct AccessItem *aconf;
1465
1466  /* Only valid for OPER_TYPE and ...? */
1467  list_p = map_to_list(type);
1468
1469  DLINK_FOREACH(ptr, (*list_p).head)
1470  {
1471    conf = ptr->data;
1472
1473    if (conf->name == NULL)
1474      continue;
1475    aconf = (struct AccessItem *)map_to_conf(conf);
1476    if (aconf->host == NULL)
1477      continue;
1478    if (irccmp(conf->name, name) != 0)
1479      continue;
1480
1481    /*
1482    ** Accept if the *real* hostname (usually sockethost)
1483    ** socket host) matches *either* host or name field
1484    ** of the configuration.
1485    */
1486    if (!match(aconf->host, host) || !match(aconf->user,user)
1487        || irccmp(conf->name, name) )
1488      continue;
1489    if (type == OPER_TYPE)
1490    {
1491      struct ClassItem *aclass;
1492
1493      aclass = (struct ClassItem *)aconf->class_ptr;
1494      if (aconf->clients < MaxTotal(aclass))
1495        return conf;
1496      else
1497        continue;
1498    }
1499    else
1500      return conf;
1501  }
1502  return NULL;
1503 }
1504
531   /* find_conf_name()
532   *
533   * inputs       - pointer to conf link list to search
# Line 1511 | 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;
1518 <  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)))
1528 <      return conf;
551 >      if (conf->name && !irccmp(conf->name, name))
552 >        return conf;
553      }
554    }
555  
556    return NULL;
557   }
558  
1535 /* map_to_list()
1536 *
1537 * inputs       - ConfType conf
1538 * output       - pointer to dlink_list to use
1539 * side effects - none
1540 */
1541 static dlink_list *
1542 map_to_list(ConfType type)
1543 {
1544  switch(type)
1545  {
1546  case RXLINE_TYPE:
1547    return(&rxconf_items);
1548    break;
1549  case XLINE_TYPE:
1550    return(&xconf_items);
1551    break;
1552  case ULINE_TYPE:
1553    return(&uconf_items);
1554    break;
1555  case NRESV_TYPE:
1556    return(&nresv_items);
1557    break;
1558  case OPER_TYPE:
1559    return(&oconf_items);
1560    break;
1561  case CLASS_TYPE:
1562    return(&class_items);
1563    break;
1564  case SERVER_TYPE:
1565    return(&server_items);
1566    break;
1567  case CLUSTER_TYPE:
1568    return(&cluster_items);
1569    break;
1570  case CONF_TYPE:
1571  case GLINE_TYPE:
1572  case KLINE_TYPE:
1573  case DLINE_TYPE:
1574  case CRESV_TYPE:
1575  default:
1576    return NULL;
1577  }
1578 }
1579
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;
1597 <  struct MatchItem *match_item=NULL;
1598 <  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 <    case RXLINE_TYPE:
580 <      DLINK_FOREACH(ptr, list_p->head)
581 <      {
582 <        conf = ptr->data;
1606 <        assert(conf->regexpname);
579 >  case CONF_SERVICE:
580 >    DLINK_FOREACH(node, list->head)
581 >    {
582 >      conf = node->data;
583  
584 <        if (!ircd_pcre_exec(conf->regexpname, name))
585 <          return conf;
586 <      }
587 <      break;
584 >      if (EmptyString(conf->name))
585 >        continue;
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  
1620      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;
1641 <      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 1659 | 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 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;
1672 <  struct MatchItem *match_item;
1673 <  dlink_list *list_p;
1674 <
1675 <  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;
680 <      aconf = (struct AccessItem *)map_to_conf(conf);
679 >      conf = node->data;
680 >
681        if (EmptyString(conf->name))
682 <        continue;
683 <    
684 <      if (irccmp(conf->name, name) == 0)
682 >        continue;
683 >
684 >      if (!irccmp(conf->name, name))
685        {
686 <        if ((user == NULL && (host == NULL)))
687 <          return (conf);
688 <        if (EmptyString(aconf->user) || EmptyString(aconf->host))
689 <          return (conf);
690 <        if (match(aconf->user, user) && match(aconf->host, host))
691 <          return (conf);
686 >        if (!who)
687 >          return conf;
688 >        if (EmptyString(conf->user) || EmptyString(conf->host))
689 >          return NULL;
690 >        if (!match(conf->user, who->username))
691 >        {
692 >          switch (conf->htype)
693 >          {
694 >            case HM_HOST:
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->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;
705 >            case HM_IPV6:
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;
711 >            default:
712 >              assert(0);
713 >          }
714 >        }
715        }
716      }
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 <      {
1740 <          return (conf);
1741 <      }
736 >        return conf;
737      }
1743    break;
738  
1745  case CLASS_TYPE:
1746    DLINK_FOREACH(ptr, list_p->head)
1747    {
1748      conf = ptr->data;
1749      if (EmptyString(conf->name))
1750        continue;
1751    
1752      if (irccmp(conf->name, name) == 0)
1753        return (conf);
1754    }
739      break;
740  
741    default:
742      break;
743    }
1760  return(NULL);
1761 }
1762
1763 /* rehash()
1764 *
1765 * Actual REHASH service routine. Called with sig == 0 if it has been called
1766 * as a result of an operator issuing this command, else assume it has been
1767 * called as a result of the server receiving a HUP signal.
1768 */
1769 int
1770 rehash(int sig)
1771 {
1772  if (sig != 0)
1773    sendto_realops_flags(UMODE_ALL, L_ALL,
1774                         "Got signal SIGHUP, reloading ircd.conf file");
1775
1776 #ifndef _WIN32
1777  restart_resolver();
1778 #endif
1779  /* don't close listeners until we know we can go ahead with the rehash */
1780
1781  /* Check to see if we magically got(or lost) IPv6 support */
1782  check_can_use_v6();
1783
1784  read_conf_files(0);
1785
1786  if (ServerInfo.description != NULL)
1787    strlcpy(me.info, ServerInfo.description, sizeof(me.info));
1788
1789 #ifndef STATIC_MODULES
1790  load_conf_modules();
1791 #endif
744  
745 <  flush_deleted_I_P();
1794 <
1795 <  rehashed_klines = 1;
1796 <
1797 <  if (ConfigLoggingEntry.use_logging)
1798 <    reopen_log(logFileName);
1799 <
1800 <  return(0);
745 >  return NULL;
746   }
747  
748   /* set_default_conf()
# Line 1815 | 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 <  /* Don't reset hub, as that will break lazylinks */
793 <  /* ServerInfo.hub = NO; */
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;
799 <
800 <  set_log_level(L_NOTICE);
801 <  ConfigLoggingEntry.use_logging = 1;
802 <  ConfigLoggingEntry.operlog[0] = '\0';
803 <  ConfigLoggingEntry.userlog[0] = '\0';
804 <  ConfigLoggingEntry.klinelog[0] = '\0';
805 <  ConfigLoggingEntry.glinelog[0] = '\0';
806 <  ConfigLoggingEntry.killlog[0] = '\0';
807 <  ConfigLoggingEntry.operspylog[0] = '\0';
808 <  ConfigLoggingEntry.ioerrlog[0] = '\0';
809 <  ConfigLoggingEntry.failed_operlog[0] = '\0';
810 <
811 <  ConfigChannel.restrict_channels = NO;
812 <  ConfigChannel.disable_local_channels = NO;
813 <  ConfigChannel.use_invex = YES;
814 <  ConfigChannel.use_except = YES;
1860 <  ConfigChannel.use_knock = YES;
1861 <  ConfigChannel.knock_delay = 300;
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_del_all();
807 >
808 >  ConfigLog.use_logging = 1;
809 >
810 >  ConfigChannel.disable_fake_channels = 0;
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;
1864 <  ConfigChannel.quiet_on_ban = YES;
816 >  ConfigChannel.max_channels = 25;
817    ConfigChannel.max_bans = 25;
818 <  ConfigChannel.default_split_user_count = 0;
819 <  ConfigChannel.default_split_server_count = 0;
1868 <  ConfigChannel.no_join_on_split = NO;
1869 <  ConfigChannel.no_create_on_split = NO;
1870 <  ConfigChannel.burst_topicwho = YES;
818 >  ConfigChannel.default_join_flood_count = 18;
819 >  ConfigChannel.default_join_flood_time = 6;
820  
821 <  ConfigServerHide.flatten_links = NO;
821 >  ConfigServerHide.flatten_links = 0;
822    ConfigServerHide.links_delay = 300;
823 <  ConfigServerHide.hidden = NO;
824 <  ConfigServerHide.disable_hidden = NO;
825 <  ConfigServerHide.hide_servers = NO;
826 <  DupString(ConfigServerHide.hidden_name, NETWORK_NAME_DEFAULT);
827 <  ConfigServerHide.hide_server_ips = NO;
828 <
829 <  ConfigFileEntry.gline_min_cidr = 16;
830 <  ConfigFileEntry.gline_min_cidr6 = 48;
831 <  ConfigFileEntry.invisible_on_connect = YES;
832 <  ConfigFileEntry.burst_away = NO;
833 <  ConfigFileEntry.use_whois_actually = YES;
834 <  ConfigFileEntry.tkline_expire_notices = YES;
835 <  ConfigFileEntry.hide_spoof_ips = YES;
836 <  ConfigFileEntry.ignore_bogus_ts = NO;
837 <  ConfigFileEntry.disable_auth = NO;
838 <  ConfigFileEntry.disable_remote = NO;
839 <  ConfigFileEntry.kill_chase_time_limit = 90;
840 <  ConfigFileEntry.default_floodcount = 8; /* XXX */
841 <  ConfigFileEntry.failed_oper_notice = YES;
842 <  ConfigFileEntry.dots_in_ident = 0;      /* XXX */
843 <  ConfigFileEntry.dot_in_ip6_addr = YES;
844 <  ConfigFileEntry.min_nonwildcard = 4;
845 <  ConfigFileEntry.min_nonwildcard_simple = 3;
846 <  ConfigFileEntry.max_accept = 20;
847 <  ConfigFileEntry.anti_nick_flood = NO;   /* XXX */
848 <  ConfigFileEntry.max_nick_time = 20;
849 <  ConfigFileEntry.max_nick_changes = 5;
850 <  ConfigFileEntry.anti_spam_exit_message_time = 0;  /* XXX */
851 <  ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
852 <  ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;  /* XXX */
853 <  ConfigFileEntry.kline_with_reason = YES;
854 <  ConfigFileEntry.kline_reason = NULL;
855 <  ConfigFileEntry.warn_no_nline = YES;
856 <  ConfigFileEntry.stats_o_oper_only = NO; /* XXX */
857 <  ConfigFileEntry.stats_k_oper_only = 1;  /* masked */
858 <  ConfigFileEntry.stats_i_oper_only = 1;  /* masked */
859 <  ConfigFileEntry.stats_P_oper_only = NO;
860 <  ConfigFileEntry.caller_id_wait = 60;
861 <  ConfigFileEntry.opers_bypass_callerid = NO;
862 <  ConfigFileEntry.pace_wait = 10;
863 <  ConfigFileEntry.pace_wait_simple = 1;
864 <  ConfigFileEntry.short_motd = NO;
865 <  ConfigFileEntry.ping_cookie = NO;
866 <  ConfigFileEntry.no_oper_flood = NO;     /* XXX */
867 <  ConfigFileEntry.true_no_oper_flood = NO;  /* XXX */
868 <  ConfigFileEntry.oper_pass_resv = YES;
869 <  ConfigFileEntry.glines = NO;            /* XXX */
870 <  ConfigFileEntry.gline_time = 12 * 3600; /* XXX */
871 <  ConfigFileEntry.idletime = 0;
872 <  ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT;
873 <  ConfigFileEntry.client_flood = CLIENT_FLOOD_DEFAULT;
874 <  ConfigFileEntry.oper_only_umodes = UMODE_DEBUG;  /* XXX */
875 <  ConfigFileEntry.oper_umodes = UMODE_LOCOPS | UMODE_SERVNOTICE |
876 <    UMODE_OPERWALL | UMODE_WALLOP;        /* XXX */
877 <  DupString(ConfigFileEntry.servlink_path, SLPATH);
1929 < #ifdef HAVE_LIBCRYPTO
1930 <  /* jdc -- This is our default value for a cipher.  According to the
1931 <   *        CRYPTLINK document (doc/cryptlink.txt), BF/128 must be supported
1932 <   *        under all circumstances if cryptlinks are enabled.  So,
1933 <   *        this will be our default.
1934 <   *
1935 <   *        NOTE: I apologise for the hard-coded value of "1" (BF/128).
1936 <   *              This should be moved into a find_cipher() routine.
1937 <   */
1938 <  ConfigFileEntry.default_cipher_preference = &CipherTable[1];
1939 < #endif
1940 <  ConfigFileEntry.use_egd = NO;
1941 <  ConfigFileEntry.egdpool_path = NULL;
1942 < #ifdef HAVE_LIBZ
1943 <  ConfigFileEntry.compression_level = 0;
1944 < #endif
1945 <  ConfigFileEntry.throttle_time = 10;
823 >  ConfigServerHide.hidden = 0;
824 >  ConfigServerHide.hide_servers = 0;
825 >  ConfigServerHide.hide_services = 0;
826 >  ConfigServerHide.hidden_name = xstrdup(NETWORK_NAME_DEFAULT);
827 >  ConfigServerHide.hide_server_ips = 0;
828 >  ConfigServerHide.disable_remote_commands = 0;
829 >
830 >  ConfigGeneral.away_count = 2;
831 >  ConfigGeneral.away_time = 10;
832 >  ConfigGeneral.max_watch = WATCHSIZE_DEFAULT;
833 >  ConfigGeneral.cycle_on_host_change = 1;
834 >  ConfigGeneral.dline_min_cidr = 16;
835 >  ConfigGeneral.dline_min_cidr6 = 48;
836 >  ConfigGeneral.kline_min_cidr = 16;
837 >  ConfigGeneral.kline_min_cidr6 = 48;
838 >  ConfigGeneral.invisible_on_connect = 1;
839 >  ConfigGeneral.tkline_expire_notices = 1;
840 >  ConfigGeneral.ignore_bogus_ts = 0;
841 >  ConfigGeneral.disable_auth = 0;
842 >  ConfigGeneral.kill_chase_time_limit = 90;
843 >  ConfigGeneral.default_floodcount = 8;
844 >  ConfigGeneral.failed_oper_notice = 1;
845 >  ConfigGeneral.dots_in_ident = 0;
846 >  ConfigGeneral.min_nonwildcard = 4;
847 >  ConfigGeneral.min_nonwildcard_simple = 3;
848 >  ConfigGeneral.max_accept = 20;
849 >  ConfigGeneral.anti_nick_flood = 0;
850 >  ConfigGeneral.max_nick_time = 20;
851 >  ConfigGeneral.max_nick_changes = 5;
852 >  ConfigGeneral.anti_spam_exit_message_time = 0;
853 >  ConfigGeneral.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
854 >  ConfigGeneral.ts_max_delta = TS_MAX_DELTA_DEFAULT;
855 >  ConfigGeneral.warn_no_connect_block = 1;
856 >  ConfigGeneral.stats_e_disabled = 0;
857 >  ConfigGeneral.stats_i_oper_only = 1;  /* 1 = masked */
858 >  ConfigGeneral.stats_k_oper_only = 1;  /* 1 = masked */
859 >  ConfigGeneral.stats_o_oper_only = 1;
860 >  ConfigGeneral.stats_m_oper_only = 1;
861 >  ConfigGeneral.stats_P_oper_only = 0;
862 >  ConfigGeneral.stats_u_oper_only = 0;
863 >  ConfigGeneral.caller_id_wait = 60;
864 >  ConfigGeneral.opers_bypass_callerid = 0;
865 >  ConfigGeneral.pace_wait = 10;
866 >  ConfigGeneral.pace_wait_simple = 1;
867 >  ConfigGeneral.short_motd = 0;
868 >  ConfigGeneral.ping_cookie = 0;
869 >  ConfigGeneral.no_oper_flood = 0;
870 >  ConfigGeneral.oper_pass_resv = 1;
871 >  ConfigGeneral.max_targets = MAX_TARGETS_DEFAULT;
872 >  ConfigGeneral.oper_only_umodes = UMODE_DEBUG | UMODE_LOCOPS | UMODE_HIDDEN | UMODE_FARCONNECT |
873 >                                   UMODE_UNAUTH | UMODE_EXTERNAL | UMODE_BOTS | UMODE_NCHANGE |
874 >                                   UMODE_SPY | UMODE_FULL | UMODE_SKILL | UMODE_REJ | UMODE_CCONN;
875 >  ConfigGeneral.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE | UMODE_WALLOP;
876 >  ConfigGeneral.throttle_count = 1;
877 >  ConfigGeneral.throttle_time = 1;
878   }
879  
880 < /* read_conf()
880 > static void
881 > validate_conf(void)
882 > {
883 >  if (ConfigGeneral.ts_warn_delta < TS_WARN_DELTA_MIN)
884 >    ConfigGeneral.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
885 >
886 >  if (ConfigGeneral.ts_max_delta < TS_MAX_DELTA_MIN)
887 >    ConfigGeneral.ts_max_delta = TS_MAX_DELTA_DEFAULT;
888 >
889 >  if (EmptyString(ConfigServerInfo.network_name))
890 >    ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
891 >
892 >  if (EmptyString(ConfigServerInfo.network_desc))
893 >    ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
894 >
895 >  ConfigGeneral.max_watch = IRCD_MAX(ConfigGeneral.max_watch, WATCHSIZE_MIN);
896 > }
897 >
898 > /* read_conf()
899   *
900   * inputs       - file descriptor pointing to config file to use
901   * output       - None
902   * side effects - Read configuration file.
903   */
904   static void
905 < read_conf(FBFILE *file)
905 > read_conf(FILE *file)
906   {
907 <  scount = lineno = 0;
907 >  lineno = 0;
908  
909 <  set_default_conf(); /* Set default values prior to conf parsing */
910 <  ypass = 1;
911 <  yyparse();          /* pick up the classes first */
909 >  set_default_conf();  /* Set default values prior to conf parsing */
910 >  conf_parser_ctx.pass = 1;
911 >  yyparse();  /* Pick up the classes first */
912  
913 <  fbrewind(file);
913 >  rewind(file);
914  
915 <  ypass = 2;
916 <  yyparse();          /* Load the values from the conf */
917 <  validate_conf();    /* Check to make sure some values are still okay. */
918 <                      /* Some global values are also loaded here. */
919 <  check_class();      /* Make sure classes are valid */
915 >  conf_parser_ctx.pass = 2;
916 >  yyparse();  /* Load the values from the conf */
917 >  validate_conf();  /* Check to make sure some values are still okay. */
918 >                    /* Some global values are also loaded here. */
919 >  class_delete_marked();  /* Delete unused classes that are marked for deletion */
920   }
921  
922 < static void
923 < validate_conf(void)
922 > /* conf_rehash()
923 > *
924 > * Actual REHASH service routine. Called with sig == 0 if it has been called
925 > * as a result of an operator issuing this command, else assume it has been
926 > * called as a result of the server receiving a HUP signal.
927 > */
928 > void
929 > conf_rehash(int sig)
930   {
931 <  if (ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN)
932 <    ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
933 <
1978 <  if (ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN)
1979 <    ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
931 >  if (sig)
932 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
933 >                         "Got signal SIGHUP, reloading configuration file(s)");
934  
935 <  if (ConfigFileEntry.servlink_path == NULL)
1982 <    DupString(ConfigFileEntry.servlink_path, SLPATH);
935 >  restart_resolver();
936  
937 <  if (ServerInfo.network_name == NULL)
1985 <    DupString(ServerInfo.network_name,NETWORK_NAME_DEFAULT);
937 >  /* don't close listeners until we know we can go ahead with the rehash */
938  
939 <  if (ServerInfo.network_desc == NULL)
1988 <    DupString(ServerInfo.network_desc,NETWORK_DESC_DEFAULT);
939 >  read_conf_files(0);
940  
941 <  if ((ConfigFileEntry.client_flood < CLIENT_FLOOD_MIN) ||
942 <      (ConfigFileEntry.client_flood > CLIENT_FLOOD_MAX))
1992 <    ConfigFileEntry.client_flood = CLIENT_FLOOD_MAX;
941 >  load_conf_modules();
942 >  check_conf_klines();
943   }
944  
945   /* lookup_confhost()
# Line 1997 | Line 947 | validate_conf(void)
947   * start DNS lookups of all hostnames in the conf
948   * line and convert an IP addresses in a.b.c.d number for to IP#s.
949   */
950 < static void
951 < lookup_confhost(struct ConfItem *conf)
950 > void
951 > lookup_confhost(struct MaskItem *conf)
952   {
2003  struct AccessItem *aconf;
953    struct addrinfo hints, *res;
954  
955 <  aconf = map_to_conf(conf);
956 <
2008 <  if (EmptyString(aconf->host) ||
2009 <      EmptyString(aconf->user))
2010 <  {
2011 <    ilog(L_ERROR, "Host/server name error: (%s) (%s)",
2012 <         aconf->host, conf->name);
2013 <    return;
2014 <  }
2015 <
2016 <  if (strchr(aconf->host, '*') ||
2017 <      strchr(aconf->host, '?'))
2018 <    return;
2019 <
2020 <  /* Do name lookup now on hostnames given and store the
955 >  /*
956 >   * Do name lookup now on hostnames given and store the
957     * ip numbers in conf structure.
958     */
959    memset(&hints, 0, sizeof(hints));
# Line 2028 | Line 964 | lookup_confhost(struct ConfItem *conf)
964    /* Get us ready for a bind() and don't bother doing dns lookup */
965    hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
966  
967 <  if (irc_getaddrinfo(aconf->host, NULL, &hints, &res))
967 >  if (getaddrinfo(conf->host, NULL, &hints, &res))
968    {
969 <    conf_dns_lookup(aconf);
969 >    conf_dns_lookup(conf);
970      return;
971    }
972  
973 <  assert(res != NULL);
973 >  assert(res);
974 >
975 >  memcpy(&conf->addr, res->ai_addr, res->ai_addrlen);
976 >  conf->addr.ss_len = res->ai_addrlen;
977 >  conf->addr.ss.ss_family = res->ai_family;
978  
979 <  memcpy(&aconf->ipnum, res->ai_addr, res->ai_addrlen);
2040 <  aconf->ipnum.ss_len = res->ai_addrlen;
2041 <  aconf->ipnum.ss.ss_family = res->ai_family;
2042 <  irc_freeaddrinfo(res);
979 >  freeaddrinfo(res);
980   }
981  
982   /* conf_connect_allowed()
# Line 2052 | Line 989 | lookup_confhost(struct ConfItem *conf)
989   int
990   conf_connect_allowed(struct irc_ssaddr *addr, int aftype)
991   {
992 <  struct ip_entry *ip_found;
993 <  struct AccessItem *aconf = find_dline_conf(addr, aftype);
992 >  struct ip_entry *ip_found = NULL;
993 >  struct MaskItem *const conf = find_dline_conf(addr, aftype);
994  
995    /* DLINE exempt also gets you out of static limits/pacing... */
996 <  if (aconf && (aconf->status & CONF_EXEMPTDLINE))
996 >  if (conf && (conf->type == CONF_EXEMPT))
997      return 0;
998  
999 <  if (aconf != NULL)
999 >  if (conf)
1000      return BANNED_CLIENT;
1001  
1002 <  ip_found = find_or_add_ip(addr);
1002 >  ip_found = ipcache_find_or_add_address(addr);
1003  
1004 <  if ((CurrentTime - ip_found->last_attempt) <
2068 <      ConfigFileEntry.throttle_time)
1004 >  if ((CurrentTime - ip_found->last_attempt) < ConfigGeneral.throttle_time)
1005    {
1006 <    ip_found->last_attempt = CurrentTime;
1007 <    return TOO_FAST;
1006 >    if (ip_found->connection_count >= ConfigGeneral.throttle_count)
1007 >      return TOO_FAST;
1008 >
1009 >    ++ip_found->connection_count;
1010    }
1011 +  else
1012 +    ip_found->connection_count = 1;
1013  
1014    ip_found->last_attempt = CurrentTime;
1015    return 0;
1016   }
1017  
1018 < static struct AccessItem *
2079 < find_regexp_kline(const char *uhi[])
2080 < {
2081 <  const dlink_node *ptr = NULL;
2082 <
2083 <  DLINK_FOREACH(ptr, rkconf_items.head)
2084 <  {
2085 <    struct AccessItem *aptr = map_to_conf(ptr->data);
2086 <
2087 <    assert(aptr->regexuser);
2088 <    assert(aptr->regexhost);
2089 <
2090 <    if (!ircd_pcre_exec(aptr->regexuser, uhi[0]) &&
2091 <        (!ircd_pcre_exec(aptr->regexhost, uhi[1]) ||
2092 <         !ircd_pcre_exec(aptr->regexhost, uhi[2])))
2093 <      return aptr;
2094 <  }
2095 <
2096 <  return NULL;
2097 < }
2098 <
2099 < /* find_kill()
1018 > /* expire_tklines()
1019   *
1020 < * inputs       - pointer to client structure
1021 < * output       - pointer to struct AccessItem if found
1022 < * side effects - See if this user is klined already,
2104 < *                and if so, return struct AccessItem pointer
1020 > * inputs       - tkline list pointer
1021 > * output       - NONE
1022 > * side effects - expire tklines
1023   */
1024 < struct AccessItem *
1025 < find_kill(struct Client *client_p)
2108 < {
2109 <  struct AccessItem *aconf = NULL;
2110 <  const char *uhi[3];
2111 <
2112 <  uhi[0] = client_p->username;
2113 <  uhi[1] = client_p->host;
2114 <  uhi[2] = client_p->sockhost;
2115 <
2116 <  assert(client_p != NULL);
2117 <
2118 <  aconf = find_kline_conf(client_p->host, client_p->username,
2119 <                          &client_p->localClient->ip,
2120 <                          client_p->localClient->aftype);
2121 <  if (aconf == NULL)
2122 <    aconf = find_regexp_kline(uhi);
2123 <
2124 <  if (aconf && (aconf->status & CONF_KLINE))
2125 <    return aconf;
2126 <
2127 <  return NULL;
2128 < }
2129 <
2130 < struct AccessItem *
2131 < find_gline(struct Client *client_p)
1024 > static void
1025 > expire_tklines(dlink_list *list)
1026   {
1027 <  struct AccessItem *aconf;
2134 <
2135 <  assert(client_p != NULL);
2136 <
2137 <  aconf = find_gline_conf(client_p->host, client_p->username,
2138 <                          &client_p->localClient->ip,
2139 <                          client_p->localClient->aftype);
1027 >  dlink_node *node = NULL, *node_next = NULL;
1028  
1029 <  if (aconf && (aconf->status & CONF_GLINE))
1030 <    return aconf;
1031 <
2144 <  return NULL;
2145 < }
1029 >  DLINK_FOREACH_SAFE(node, node_next, list->head)
1030 >  {
1031 >    struct MaskItem *conf = node->data;
1032  
1033 < /* add_temp_line()
1034 < *
2149 < * inputs        - pointer to struct ConfItem
2150 < * output        - none
2151 < * Side effects  - links in given struct ConfItem into
2152 < *                 temporary *line link list
2153 < */
2154 < void
2155 < add_temp_line(struct ConfItem *conf)
2156 < {
2157 <  struct AccessItem *aconf;
1033 >    if (!conf->until || conf->until > CurrentTime)
1034 >      continue;
1035  
1036 <  if (conf->type == DLINE_TYPE)
1037 <  {
1038 <    aconf = map_to_conf(conf);
1039 <    SetConfTemporary(aconf);
2163 <    dlinkAdd(conf, &conf->node, &temporary_dlines);
2164 <    MyFree(aconf->user);
2165 <    aconf->user = NULL;
2166 <    add_conf_by_address(CONF_DLINE, aconf);
2167 <  }
2168 <  else if (conf->type == KLINE_TYPE)
2169 <  {
2170 <    aconf = map_to_conf(conf);
2171 <    SetConfTemporary(aconf);
2172 <    dlinkAdd(conf, &conf->node, &temporary_klines);
2173 <    add_conf_by_address(CONF_KILL, aconf);
2174 <  }
2175 <  else if (conf->type == GLINE_TYPE)
2176 <  {
2177 <    aconf = map_to_conf(conf);
2178 <    SetConfTemporary(aconf);
2179 <    dlinkAdd(conf, &conf->node, &temporary_glines);
2180 <    add_conf_by_address(CONF_GLINE, aconf);
2181 <  }
2182 <  else if (conf->type == XLINE_TYPE)
2183 <  {
2184 <    conf->flags |= CONF_FLAGS_TEMPORARY;
2185 <    dlinkAdd(conf, make_dlink_node(), &temporary_xlines);
2186 <  }
2187 <  else if (conf->type == RXLINE_TYPE)
2188 <  {
2189 <    conf->flags |= CONF_FLAGS_TEMPORARY;
2190 <    dlinkAdd(conf, make_dlink_node(), &temporary_rxlines);
2191 <  }
2192 <  else if (conf->type == RKLINE_TYPE)
2193 <  {
2194 <    conf->flags |= CONF_FLAGS_TEMPORARY;
2195 <    dlinkAdd(conf, make_dlink_node(), &temporary_rklines);
2196 <  }
2197 <  else if ((conf->type == NRESV_TYPE) || (conf->type == CRESV_TYPE))
2198 <  {
2199 <    conf->flags |= CONF_FLAGS_TEMPORARY;
2200 <    dlinkAdd(conf, make_dlink_node(), &temporary_resv);
1036 >    if (ConfigGeneral.tkline_expire_notices)
1037 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "Temporary %s for [%s] expired",
1038 >                           (conf->type == CONF_XLINE) ? "X-line" : "RESV", conf->name);
1039 >    conf_free(conf);
1040    }
1041   }
1042  
# Line 2209 | Line 1048 | add_temp_line(struct ConfItem *conf)
1048   *                This is an event started off in ircd.c
1049   */
1050   void
1051 < cleanup_tklines(void *notused)
2213 < {
2214 <  expire_tklines(&temporary_glines);
2215 <  expire_tklines(&temporary_klines);
2216 <  expire_tklines(&temporary_dlines);
2217 <  expire_tklines(&temporary_xlines);
2218 <  expire_tklines(&temporary_rxlines);
2219 <  expire_tklines(&temporary_rklines);
2220 <  expire_tklines(&temporary_resv);
2221 < }
2222 <
2223 < /* expire_tklines()
2224 < *
2225 < * inputs       - tkline list pointer
2226 < * output       - NONE
2227 < * side effects - expire tklines
2228 < */
2229 < static void
2230 < expire_tklines(dlink_list *tklist)
1051 > cleanup_tklines(void *unused)
1052   {
1053 <  dlink_node *ptr;
1054 <  dlink_node *next_ptr;
1055 <  struct ConfItem *conf;
1056 <  struct MatchItem *xconf;
2236 <  struct MatchItem *nconf;
2237 <  struct AccessItem *aconf;
2238 <  struct ResvChannel *cconf;
2239 <
2240 <  DLINK_FOREACH_SAFE(ptr, next_ptr, tklist->head)
2241 <  {
2242 <    conf = ptr->data;
2243 <    if (conf->type == GLINE_TYPE ||
2244 <        conf->type == KLINE_TYPE ||
2245 <        conf->type == DLINE_TYPE)
2246 <    {
2247 <      aconf = (struct AccessItem *)map_to_conf(conf);
2248 <      if (aconf->hold <= CurrentTime)
2249 <      {
2250 <        /* XXX - Do we want GLINE expiry notices?? */
2251 <        /* Alert opers that a TKline expired - Hwy */
2252 <        if (ConfigFileEntry.tkline_expire_notices)
2253 <        {
2254 <          if (aconf->status & CONF_KILL)
2255 <          {
2256 <            sendto_realops_flags(UMODE_ALL, L_ALL,
2257 <                                 "Temporary K-line for [%s@%s] expired",
2258 <                                 (aconf->user) ? aconf->user : "*",
2259 <                                 (aconf->host) ? aconf->host : "*");
2260 <          }
2261 <          else if (conf->type == DLINE_TYPE)
2262 <          {
2263 <            sendto_realops_flags(UMODE_ALL, L_ALL,
2264 <                                 "Temporary D-line for [%s] expired",
2265 <                                 (aconf->host) ? aconf->host : "*");
2266 <          }
2267 <        }
2268 <
2269 <        delete_one_address_conf(aconf->host, aconf);
2270 <        dlinkDelete(ptr, tklist);
2271 <      }
2272 <    }
2273 <    else if (conf->type == XLINE_TYPE ||
2274 <             conf->type == RXLINE_TYPE)
2275 <    {
2276 <      xconf = (struct MatchItem *)map_to_conf(conf);
2277 <      if (xconf->hold <= CurrentTime)
2278 <      {
2279 <        if (ConfigFileEntry.tkline_expire_notices)
2280 <          sendto_realops_flags(UMODE_ALL, L_ALL,
2281 <                               "Temporary X-line for [%s] %sexpired", conf->name,
2282 <                               conf->type == RXLINE_TYPE ? "(REGEX) " : "");
2283 <        dlinkDelete(ptr, tklist);
2284 <        free_dlink_node(ptr);
2285 <        delete_conf_item(conf);
2286 <      }
2287 <    }
2288 <    else if (conf->type == RKLINE_TYPE)
2289 <    {
2290 <      aconf = map_to_conf(conf);
2291 <      if (aconf->hold <= CurrentTime)
2292 <      {
2293 <        if (ConfigFileEntry.tkline_expire_notices)
2294 <           sendto_realops_flags(UMODE_ALL, L_ALL,
2295 <                                "Temporary K-line for [%s@%s] (REGEX) expired",
2296 <                                (aconf->user) ? aconf->user : "*",
2297 <                                (aconf->host) ? aconf->host : "*");
2298 <        dlinkDelete(ptr, tklist);
2299 <        free_dlink_node(ptr);
2300 <        delete_conf_item(conf);
2301 <      }
2302 <    }
2303 <    else if (conf->type == NRESV_TYPE)
2304 <    {
2305 <      nconf = (struct MatchItem *)map_to_conf(conf);
2306 <      if (nconf->hold <= CurrentTime)
2307 <      {
2308 <        if (ConfigFileEntry.tkline_expire_notices)
2309 <          sendto_realops_flags(UMODE_ALL, L_ALL,
2310 <                               "Temporary RESV for [%s] expired", conf->name);
2311 <        dlinkDelete(ptr, tklist);
2312 <        free_dlink_node(ptr);
2313 <        delete_conf_item(conf);
2314 <      }
2315 <    }
2316 <    else if (conf->type == CRESV_TYPE)
2317 <    {
2318 <      cconf = (struct ResvChannel *)map_to_conf(conf);
2319 <      if (cconf->hold <= CurrentTime)
2320 <      {
2321 <        if (ConfigFileEntry.tkline_expire_notices)
2322 <          sendto_realops_flags(UMODE_ALL, L_ALL,
2323 <                               "Temporary RESV for [%s] expired", cconf->name);
2324 <        dlinkDelete(ptr, tklist);
2325 <        free_dlink_node(ptr);
2326 <        delete_conf_item(conf);
2327 <      }
2328 <    }
2329 <  }
1053 >  hostmask_expire_temporary();
1054 >  expire_tklines(&xconf_items);
1055 >  expire_tklines(&nresv_items);
1056 >  expire_tklines(&cresv_items);
1057   }
1058  
1059   /* oper_privs_as_string()
# Line 2337 | Line 1064 | expire_tklines(dlink_list *tklist)
1064   */
1065   static const struct oper_privs
1066   {
1067 <  const unsigned int oprivs;
2341 <  const unsigned int hidden;
1067 >  const unsigned int flag;
1068    const unsigned char c;
1069   } flag_list[] = {
1070 <  { OPER_FLAG_ADMIN,       OPER_FLAG_HIDDEN_ADMIN,  'A' },
1071 <  { OPER_FLAG_REMOTEBAN,   0,                       'B' },
1072 <  { OPER_FLAG_DIE,         0,                       'D' },
1073 <  { OPER_FLAG_GLINE,       0,                       'G' },
1074 <  { OPER_FLAG_REHASH,      0,                       'H' },
1075 <  { OPER_FLAG_K,           0,                       'K' },
1076 <  { OPER_FLAG_OPERWALL,    0,                       'L' },
1077 <  { OPER_FLAG_N,           0,                       'N' },
1078 <  { OPER_FLAG_GLOBAL_KILL, 0,                       'O' },
1079 <  { OPER_FLAG_REMOTE,      0,                       'R' },
1080 <  { OPER_FLAG_OPER_SPY,    0,                       'S' },
1081 <  { OPER_FLAG_UNKLINE,     0,                       'U' },
1082 <  { OPER_FLAG_X,           0,                       'X' },
1083 <  { 0, 0, '\0' }
1070 >  { OPER_FLAG_ADMIN,          'A' },
1071 >  { OPER_FLAG_REMOTEBAN,      'B' },
1072 >  { OPER_FLAG_DIE,            'D' },
1073 >  { OPER_FLAG_REHASH,         'H' },
1074 >  { OPER_FLAG_KLINE,          'K' },
1075 >  { OPER_FLAG_KILL,           'N' },
1076 >  { OPER_FLAG_KILL_REMOTE,    'O' },
1077 >  { OPER_FLAG_CONNECT,        'P' },
1078 >  { OPER_FLAG_CONNECT_REMOTE, 'Q' },
1079 >  { OPER_FLAG_SQUIT,          'R' },
1080 >  { OPER_FLAG_SQUIT_REMOTE,   'S' },
1081 >  { OPER_FLAG_UNKLINE,        'U' },
1082 >  { OPER_FLAG_XLINE,          'X' },
1083 >  { 0, '\0' }
1084   };
1085  
1086 < char *
1086 > const char *
1087   oper_privs_as_string(const unsigned int port)
1088   {
1089 <  static char privs_out[16];
1089 >  static char privs_out[IRCD_BUFSIZE];
1090    char *privs_ptr = privs_out;
2365  unsigned int i = 0;
1091  
1092 <  for (; flag_list[i].oprivs; ++i)
1092 >  for (const struct oper_privs *opriv = flag_list; opriv->flag; ++opriv)
1093    {
1094 <    if ((port & flag_list[i].oprivs) &&
1095 <        (port & flag_list[i].hidden) == 0)
2371 <      *privs_ptr++ = flag_list[i].c;
1094 >    if (port & opriv->flag)
1095 >      *privs_ptr++ = opriv->c;
1096      else
1097 <      *privs_ptr++ = ToLowerTab[flag_list[i].c];
1097 >      *privs_ptr++ = ToLower(opriv->c);
1098    }
1099  
1100    *privs_ptr = '\0';
# Line 2379 | Line 1103 | oper_privs_as_string(const unsigned int
1103   }
1104  
1105   /*
1106 < * Input: A client to find the active oper{} name for.
1106 > * Input: A client to find the active operator {} name for.
1107   * Output: The nick!user@host{oper} of the oper.
1108   *         "oper" is server name for remote opers
1109   * Side effects: None.
1110   */
1111 < char *
1111 > const char *
1112   get_oper_name(const struct Client *client_p)
1113   {
1114 <  dlink_node *cnode;
2391 <  struct ConfItem *conf;
2392 <  struct AccessItem *aconf;
1114 >  static char buffer[IRCD_BUFSIZE];
1115  
1116 <  /* +5 for !,@,{,} and null */
1117 <  static char buffer[NICKLEN+USERLEN+HOSTLEN+HOSTLEN+5];
1116 >  if (IsServer(client_p))
1117 >    return client_p->name;
1118  
1119    if (MyConnect(client_p))
1120    {
1121 <    DLINK_FOREACH(cnode, client_p->localClient->confs.head)
1121 >    const dlink_node *const node = client_p->connection->confs.head;
1122 >
1123 >    if (node)
1124      {
1125 <      conf = cnode->data;
2402 <      aconf = map_to_conf(conf);
1125 >      const struct MaskItem *const conf = node->data;
1126  
1127 <      if (IsConfOperator(aconf))
1127 >      if (conf->type == CONF_OPER)
1128        {
1129 <        ircsprintf(buffer, "%s!%s@%s{%s}", client_p->name,
1130 <                   client_p->username, client_p->host,
1131 <                   conf->name);
2409 <        return buffer;
1129 >        snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1130 >                 client_p->username, client_p->host, conf->name);
1131 >        return buffer;
1132        }
1133      }
1134  
1135 <    /* Probably should assert here for now. If there is an oper out there
1136 <     * with no oper{} conf attached, it would be good for us to know...
1135 >    /*
1136 >     * Probably should assert here for now. If there is an oper out there
1137 >     * with no operator {} conf attached, it would be good for us to know...
1138       */
1139 <    assert(0); /* Oper without oper conf! */
1139 >    assert(0);  /* Oper without oper conf! */
1140    }
1141  
1142 <  ircsprintf(buffer, "%s!%s@%s{%s}", client_p->name,
1143 <             client_p->username, client_p->host, client_p->servptr->name);
1142 >  snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1143 >           client_p->username, client_p->host, client_p->servptr->name);
1144    return buffer;
1145   }
1146  
2424 /* read_conf_files()
2425 *
2426 * inputs       - cold start YES or NO
2427 * output       - none
2428 * side effects - read all conf files needed, ircd.conf kline.conf etc.
2429 */
2430 void
2431 read_conf_files(int cold)
2432 {
2433  const char *filename;
2434  char chanmodes[32];
2435  char chanlimit[32];
2436
2437  filename = get_conf_name(CONF_TYPE);
2438
2439  /* We need to know the initial filename for the yyerror() to report
2440     FIXME: The full path is in conffilenamebuf first time since we
2441             dont know anything else
2442
2443     - Gozem 2002-07-21
2444  */
2445  strlcpy(conffilebuf, filename, sizeof(conffilebuf));
2446
2447  if ((conf_fbfile_in = fbopen(filename, "r")) == NULL)
2448  {
2449    if (cold)
2450    {
2451      ilog(L_CRIT, "Unable to read configuration file '%s': %s",
2452           filename, strerror(errno));
2453      exit(-1);
2454    }
2455    else
2456    {
2457      sendto_realops_flags(UMODE_ALL, L_ALL,
2458                           "Unable to read configuration file '%s': %s",
2459                           filename, strerror(errno));
2460      return;
2461    }
2462  }
2463
2464  if (!cold)
2465    clear_out_old_conf();
2466
2467  read_conf(conf_fbfile_in);
2468  fbclose(conf_fbfile_in);
2469
2470  add_isupport("NETWORK", ServerInfo.network_name, -1);
2471  ircsprintf(chanmodes, "b%s%s:%d", ConfigChannel.use_except ? "e" : "",
2472             ConfigChannel.use_invex ? "I" : "", ConfigChannel.max_bans);
2473  add_isupport("MAXLIST", chanmodes, -1);
2474  add_isupport("MAXTARGETS", NULL, ConfigFileEntry.max_targets);
2475  if (ConfigChannel.disable_local_channels)
2476    add_isupport("CHANTYPES", "#", -1);
2477  else
2478    add_isupport("CHANTYPES", "#&", -1);
2479  ircsprintf(chanlimit, "%s:%d", ConfigChannel.disable_local_channels ? "#" : "#&",
2480             ConfigChannel.max_chans_per_user);
2481  add_isupport("CHANLIMIT", chanlimit, -1);
2482  ircsprintf(chanmodes, "%s%s%s", ConfigChannel.use_except ? "e" : "",
2483             ConfigChannel.use_invex ? "I" : "", "b,k,l,imnpst");
2484  add_isupport("CHANNELLEN", NULL, LOCAL_CHANNELLEN);
2485  if (ConfigChannel.use_except)
2486    add_isupport("EXCEPTS", "e", -1);
2487  if (ConfigChannel.use_invex)
2488    add_isupport("INVEX", "I", -1);
2489  add_isupport("CHANMODES", chanmodes, -1);
2490
2491  /*
2492   * message_locale may have changed.  rebuild isupport since it relies
2493   * on strlen(form_str(RPL_ISUPPORT))
2494   */
2495  rebuild_isupport_message_line();
2496
2497  parse_conf_file(KLINE_TYPE, cold);
2498  parse_conf_file(RKLINE_TYPE, cold);
2499  parse_conf_file(DLINE_TYPE, cold);
2500  parse_conf_file(XLINE_TYPE, cold);
2501  parse_conf_file(RXLINE_TYPE, cold);
2502  parse_conf_file(NRESV_TYPE, cold);
2503  parse_conf_file(CRESV_TYPE, cold);
2504 }
2505
2506 /* parse_conf_file()
2507 *
2508 * inputs       - type of conf file to parse
2509 * output       - none
2510 * side effects - conf file for givenconf type is opened and read then parsed
2511 */
2512 static void
2513 parse_conf_file(int type, int cold)
2514 {
2515  FBFILE *file = NULL;
2516  const char *filename = get_conf_name(type);
2517
2518  if ((file = fbopen(filename, "r")) == NULL)
2519  {
2520    if (cold)
2521      ilog(L_ERROR, "Unable to read configuration file '%s': %s",
2522           filename, strerror(errno));
2523    else
2524      sendto_realops_flags(UMODE_ALL, L_ALL,
2525                    "Unable to read configuration file '%s': %s",
2526                           filename, strerror(errno));
2527  }
2528  else
2529  {
2530    parse_csv_file(file, type);
2531    fbclose(file);
2532  }
2533 }
2534
1147   /* clear_out_old_conf()
1148   *
1149   * inputs       - none
# Line 2541 | Line 1153 | parse_conf_file(int type, int cold)
1153   static void
1154   clear_out_old_conf(void)
1155   {
1156 <  dlink_node *ptr = NULL, *next_ptr = NULL;
2545 <  struct ConfItem *conf;
2546 <  struct AccessItem *aconf;
2547 <  struct ClassItem *cltmp;
2548 <  struct MatchItem *match_item;
1156 >  dlink_node *node = NULL, *node_next = NULL;
1157    dlink_list *free_items [] = {
1158 <    &server_items,   &oconf_items,    &hub_items, &leaf_items,
1159 <     &uconf_items,   &xconf_items, &rxconf_items, &rkconf_items,
1160 <     &nresv_items, &cluster_items,  &gdeny_items, NULL
1158 >    &server_items,   &oconf_items,
1159 >     &uconf_items,   &xconf_items,
1160 >     &nresv_items, &cluster_items,  &service_items, &cresv_items, NULL
1161    };
1162  
1163    dlink_list ** iterator = free_items; /* C is dumb */
# Line 2557 | Line 1165 | clear_out_old_conf(void)
1165    /* We only need to free anything allocated by yyparse() here.
1166     * Resetting structs, etc, is taken care of by set_default_conf().
1167     */
1168 <  
1169 <  for (; *iterator != NULL; iterator++)
1168 >
1169 >  for (; *iterator; iterator++)
1170    {
1171 <    DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head)
1171 >    DLINK_FOREACH_SAFE(node, node_next, (*iterator)->head)
1172      {
1173 <      conf = ptr->data;
2566 <      /* XXX This is less than pretty */
2567 <      if (conf->type == SERVER_TYPE)
2568 <      {
2569 <        aconf = (struct AccessItem *)map_to_conf(conf);
2570 <        if (aconf->clients != 0)
2571 <        {
2572 <          SetConfIllegal(aconf);
2573 <          dlinkDelete(&conf->node, &server_items);
2574 <        }
2575 <        else
2576 <        {
2577 <          delete_conf_item(conf);
2578 <        }
2579 <      }
2580 <      else if (conf->type == OPER_TYPE)
2581 <      {
2582 <        aconf = (struct AccessItem *)map_to_conf(conf);
2583 <        if (aconf->clients != 0)
2584 <        {
2585 <          SetConfIllegal(aconf);
2586 <          dlinkDelete(&conf->node, &oconf_items);
2587 <        }
2588 <        else
2589 <        {
2590 <          delete_conf_item(conf);
2591 <        }
2592 <      }
2593 <      else if (conf->type == CLIENT_TYPE)
2594 <      {
2595 <        aconf = (struct AccessItem *)map_to_conf(conf);
2596 <        if (aconf->clients != 0)
2597 <        {
2598 <          SetConfIllegal(aconf);
2599 <        }
2600 <        else
2601 <        {
2602 <          delete_conf_item(conf);
2603 <        }
2604 <      }
2605 <      else if (conf->type == XLINE_TYPE  ||
2606 <               conf->type == RXLINE_TYPE ||
2607 <               conf->type == RKLINE_TYPE)
2608 <      {
2609 <        /* temporary (r)xlines are also on
2610 <         * the (r)xconf items list */
2611 <        if (conf->flags & CONF_FLAGS_TEMPORARY)
2612 <          continue;
1173 >      struct MaskItem *conf = node->data;
1174  
1175 <        delete_conf_item(conf);
1176 <      }
1177 <      else
1175 >      conf->active = 0;
1176 >
1177 >      if (!IsConfDatabase(conf))
1178        {
1179 <        if ((conf->type == LEAF_TYPE) || (conf->type == HUB_TYPE))
1180 <        {
1181 <          match_item = (struct MatchItem *)map_to_conf(conf);
1182 <          if ((match_item->ref_count <= 0))
2622 <            delete_conf_item(conf);
2623 <          else
2624 <          {
2625 <            match_item->illegal = 1;
2626 <            dlinkDelete(&conf->node, *iterator);
2627 <          }
2628 <        }
2629 <        else
2630 <          delete_conf_item(conf);
1179 >        dlinkDelete(&conf->node, *iterator);
1180 >
1181 >        if (!conf->ref_count)
1182 >          conf_free(conf);
1183        }
1184      }
1185    }
1186  
1187 <  /* don't delete the class table, rather mark all entries
1188 <   * for deletion. The table is cleaned up by check_class. - avalon
1187 >  motd_clear();
1188 >
1189 >  /*
1190 >   * Don't delete the class table, rather mark all entries for deletion.
1191 >   * The table is cleaned up by class_delete_marked. - avalon
1192     */
1193 <  DLINK_FOREACH(ptr, class_items.head)
2639 <  {
2640 <    conf = ptr->data;
2641 <    cltmp = (struct ClassItem *)map_to_conf(conf);
2642 <    if (ptr != class_items.tail)  /* never mark the "default" class */
2643 <      MaxTotal(cltmp) = -1;
2644 <  }
1193 >  class_mark_for_deletion();
1194  
1195    clear_out_address_conf();
1196  
1197 <  /* clean out module paths */
2649 < #ifndef STATIC_MODULES
1197 >  /* Clean out module paths */
1198    mod_clear_paths();
2651 #endif
1199  
1200 <  /* clean out ServerInfo */
1201 <  MyFree(ServerInfo.description);
1202 <  ServerInfo.description = NULL;
1203 <  MyFree(ServerInfo.network_name);
1204 <  ServerInfo.network_name = NULL;
1205 <  MyFree(ServerInfo.network_desc);
1206 <  ServerInfo.network_desc = NULL;
1207 <  MyFree(ConfigFileEntry.egdpool_path);
1208 <  ConfigFileEntry.egdpool_path = NULL;
1200 >  pseudo_clear();
1201 >
1202 >  /* Clean out ConfigServerInfo */
1203 >  MyFree(ConfigServerInfo.description);
1204 >  ConfigServerInfo.description = NULL;
1205 >  MyFree(ConfigServerInfo.network_name);
1206 >  ConfigServerInfo.network_name = NULL;
1207 >  MyFree(ConfigServerInfo.network_desc);
1208 >  ConfigServerInfo.network_desc = NULL;
1209   #ifdef HAVE_LIBCRYPTO
1210 <  if (ServerInfo.rsa_private_key != NULL)
1210 >  if (ConfigServerInfo.rsa_private_key)
1211    {
1212 <    RSA_free(ServerInfo.rsa_private_key);
1213 <    ServerInfo.rsa_private_key = NULL;
1212 >    RSA_free(ConfigServerInfo.rsa_private_key);
1213 >    ConfigServerInfo.rsa_private_key = NULL;
1214    }
1215  
1216 <  MyFree(ServerInfo.rsa_private_key_file);
1217 <  ServerInfo.rsa_private_key_file = NULL;
1216 >  MyFree(ConfigServerInfo.rsa_private_key_file);
1217 >  ConfigServerInfo.rsa_private_key_file = NULL;
1218   #endif
1219  
1220 <  /* clean out old resvs from the conf */
1221 <  clear_conf_resv();
1220 >  /* Clean out ConfigAdminInfo */
1221 >  MyFree(ConfigAdminInfo.name);
1222 >  ConfigAdminInfo.name = NULL;
1223 >  MyFree(ConfigAdminInfo.email);
1224 >  ConfigAdminInfo.email = NULL;
1225 >  MyFree(ConfigAdminInfo.description);
1226 >  ConfigAdminInfo.description = NULL;
1227  
1228 <  /* clean out AdminInfo */
1229 <  MyFree(AdminInfo.name);
2678 <  AdminInfo.name = NULL;
2679 <  MyFree(AdminInfo.email);
2680 <  AdminInfo.email = NULL;
2681 <  MyFree(AdminInfo.description);
2682 <  AdminInfo.description = NULL;
2683 <
2684 <  /* operator{} and class{} blocks are freed above */
2685 <  /* clean out listeners */
2686 <  close_listeners();
2687 <
2688 <  /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{},
2689 <   * exempt{} and gecos{} blocks are freed above too
2690 <   */
2691 <
2692 <  /* clean out general */
2693 <  MyFree(ConfigFileEntry.servlink_path);
2694 <  ConfigFileEntry.servlink_path = NULL;
2695 < #ifdef HAVE_LIBCRYPTO
2696 <  ConfigFileEntry.default_cipher_preference = NULL;
2697 < #endif /* HAVE_LIBCRYPTO */
2698 <  delete_isupport("INVEX");
2699 <  delete_isupport("EXCEPTS");
1228 >  /* Clean out listeners */
1229 >  listener_close_marked();
1230   }
1231  
1232 < /* flush_deleted_I_P()
1232 > /* read_conf_files()
1233   *
1234 < * inputs       - none
1234 > * inputs       - cold start YES or NO
1235   * output       - none
1236 < * side effects - This function removes I/P conf items
2707 < */
2708 < static void
2709 < flush_deleted_I_P(void)
2710 < {
2711 <  dlink_node *ptr;
2712 <  dlink_node *next_ptr;
2713 <  struct ConfItem *conf;
2714 <  struct AccessItem *aconf;
2715 <  dlink_list * free_items [] = {
2716 <    &server_items, &oconf_items, NULL
2717 <  };
2718 <  dlink_list ** iterator = free_items; /* C is dumb */
2719 <
2720 <  /* flush out deleted I and P lines
2721 <   * although still in use.
2722 <   */
2723 <  for (; *iterator != NULL; iterator++)
2724 <  {
2725 <    DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head)
2726 <    {
2727 <      conf = ptr->data;
2728 <      aconf = (struct AccessItem *)map_to_conf(conf);
2729 <
2730 <      if (IsConfIllegal(aconf))
2731 <      {
2732 <        dlinkDelete(ptr, *iterator);
2733 <
2734 <        if (aconf->clients == 0)
2735 <          delete_conf_item(conf);
2736 <      }
2737 <    }
2738 <  }
2739 < }
2740 <
2741 < /* get_conf_name()
2742 < *
2743 < * inputs       - type of conf file to return name of file for
2744 < * output       - pointer to filename for type of conf
2745 < * side effects - none
1236 > * side effects - read all conf files needed, ircd.conf kline.conf etc.
1237   */
1238 < const char *
1239 < get_conf_name(ConfType type)
1238 > void
1239 > read_conf_files(int cold)
1240   {
1241 <  switch (type)
1242 <  {
1243 <    case CONF_TYPE:
2753 <      return ConfigFileEntry.configfile;
2754 <      break;
2755 <    case KLINE_TYPE:
2756 <      return ConfigFileEntry.klinefile;
2757 <      break;
2758 <    case RKLINE_TYPE:
2759 <      return ConfigFileEntry.rklinefile;
2760 <      break;
2761 <    case DLINE_TYPE:
2762 <      return ConfigFileEntry.dlinefile;
2763 <      break;
2764 <    case XLINE_TYPE:
2765 <      return ConfigFileEntry.xlinefile;
2766 <      break;
2767 <    case RXLINE_TYPE:
2768 <      return ConfigFileEntry.rxlinefile;
2769 <      break;
2770 <    case CRESV_TYPE:
2771 <      return ConfigFileEntry.cresvfile;
2772 <      break;
2773 <    case NRESV_TYPE:
2774 <      return ConfigFileEntry.nresvfile;
2775 <      break;
2776 <    case GLINE_TYPE:
2777 <      return ConfigFileEntry.glinefile;
2778 <      break;
1241 >  const char *filename = NULL;
1242 >  char chanmodes[IRCD_BUFSIZE] = "";
1243 >  char chanlimit[IRCD_BUFSIZE] = "";
1244  
1245 <    default:
1246 <      return NULL;  /* This should NEVER HAPPEN since we call this function
2782 <                       only with the above values, this will cause us to core
2783 <                       at some point if this happens so we know where it was */
2784 <  }
2785 < }
1245 >  conf_parser_ctx.boot = cold;
1246 >  filename = ConfigGeneral.configfile;
1247  
1248 < #define BAD_PING (-1)
1248 >  /* We need to know the initial filename for the yyerror() to report
1249 >     FIXME: The full path is in conffilenamebuf first time since we
1250 >             don't know anything else
1251  
1252 < /* get_conf_ping()
1253 < *
1254 < * inputs       - pointer to struct AccessItem
2792 < *              - pointer to a variable that receives ping warning time
2793 < * output       - ping frequency
2794 < * side effects - NONE
2795 < */
2796 < static int
2797 < get_conf_ping(struct ConfItem *conf, int *pingwarn)
2798 < {
2799 <  struct ClassItem *aclass;
2800 <  struct AccessItem *aconf;
1252 >     - Gozem 2002-07-21
1253 >  */
1254 >  strlcpy(conffilebuf, filename, sizeof(conffilebuf));
1255  
1256 <  if (conf != NULL)
1256 >  if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL)
1257    {
1258 <    aconf = (struct AccessItem *)map_to_conf(conf);
2805 <    if (aconf->class_ptr != NULL)
1258 >    if (cold)
1259      {
1260 <      aclass = (struct ClassItem *)map_to_conf(aconf->class_ptr);
1261 <      *pingwarn = PingWarning(aclass);
1262 <      return PingFreq(aclass);
1260 >      ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
1261 >           filename, strerror(errno));
1262 >      exit(-1);
1263      }
1264 <  }
2812 <
2813 <  return BAD_PING;
2814 < }
2815 <
2816 < /* get_client_class()
2817 < *
2818 < * inputs       - pointer to client struct
2819 < * output       - pointer to name of class
2820 < * side effects - NONE
2821 < */
2822 < const char *
2823 < get_client_class(struct Client *target_p)
2824 < {
2825 <  dlink_node *ptr;
2826 <  struct ConfItem *conf;
2827 <  struct AccessItem *aconf;
2828 <
2829 <  if (target_p != NULL && !IsMe(target_p) &&
2830 <      target_p->localClient->confs.head != NULL)
2831 <  {
2832 <    DLINK_FOREACH(ptr, target_p->localClient->confs.head)
1264 >    else
1265      {
1266 <      conf = ptr->data;
1267 <
1268 <      if (conf->type == CLIENT_TYPE || conf->type == SERVER_TYPE ||
1269 <          conf->type == OPER_TYPE)
2838 <      {
2839 <        aconf = (struct AccessItem *) map_to_conf(conf);
2840 <        if (aconf->class_ptr != NULL)
2841 <          return aconf->class_ptr->name;
2842 <      }
1266 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1267 >                           "Unable to read configuration file '%s': %s",
1268 >                           filename, strerror(errno));
1269 >      return;
1270      }
1271    }
1272  
1273 <  return "default";
1274 < }
2848 <
2849 < /* get_client_ping()
2850 < *
2851 < * inputs       - pointer to client struct
2852 < *              - pointer to a variable that receives ping warning time
2853 < * output       - ping frequency
2854 < * side effects - NONE
2855 < */
2856 < int
2857 < get_client_ping(struct Client *target_p, int *pingwarn)
2858 < {
2859 <  int ping;
2860 <  struct ConfItem *conf;
2861 <  dlink_node *nlink;
2862 <
2863 <  if (target_p->localClient->confs.head != NULL)
2864 <    DLINK_FOREACH(nlink, target_p->localClient->confs.head)
2865 <    {
2866 <      conf = nlink->data;
2867 <
2868 <      if ((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2869 <          (conf->type == OPER_TYPE))
2870 <      {
2871 <        ping = get_conf_ping(conf, pingwarn);
2872 <        if (ping > 0)
2873 <          return ping;
2874 <      }
2875 <    }
2876 <
2877 <  *pingwarn = 0;
2878 <  return DEFAULT_PINGFREQUENCY;
2879 < }
2880 <
2881 < /* find_class()
2882 < *
2883 < * inputs       - string name of class
2884 < * output       - corresponding Class pointer
2885 < * side effects - NONE
2886 < */
2887 < struct ConfItem *
2888 < find_class(const char *classname)
2889 < {
2890 <  struct ConfItem *conf;
2891 <
2892 <  if ((conf = find_exact_name_conf(CLASS_TYPE, classname, NULL, NULL)) != NULL)
2893 <    return(conf);
2894 <
2895 <  return class_default;
2896 < }
2897 <
2898 < /* check_class()
2899 < *
2900 < * inputs       - NONE
2901 < * output       - NONE
2902 < * side effects -
2903 < */
2904 < void
2905 < check_class(void)
2906 < {
2907 <  dlink_node *ptr;
2908 <  dlink_node *next_ptr;
2909 <  struct ConfItem *conf;
2910 <  struct ClassItem *aclass;
2911 <
2912 <  DLINK_FOREACH_SAFE(ptr, next_ptr, class_items.head)
2913 <  {
2914 <    conf = ptr->data;
2915 <    aclass = (struct ClassItem *)map_to_conf(conf);
2916 <
2917 <    if (MaxTotal(aclass) < 0)
2918 <    {
2919 <      destroy_cidr_class(aclass);
2920 <      if (CurrUserCount(aclass) > 0)
2921 <        dlinkDelete(&conf->node, &class_items);
2922 <      else
2923 <        delete_conf_item(conf);
2924 <    }
2925 <  }
2926 < }
1273 >  if (!cold)
1274 >    clear_out_old_conf();
1275  
1276 < /* init_class()
1277 < *
2930 < * inputs       - NONE
2931 < * output       - NONE
2932 < * side effects -
2933 < */
2934 < void
2935 < init_class(void)
2936 < {
2937 <  struct ClassItem *aclass;
1276 >  read_conf(conf_parser_ctx.conf_file);
1277 >  fclose(conf_parser_ctx.conf_file);
1278  
1279 <  class_default = make_conf_item(CLASS_TYPE);
2940 <  aclass = (struct ClassItem *)map_to_conf(class_default);
2941 <  DupString(class_default->name, "default");
2942 <  ConFreq(aclass)  = DEFAULT_CONNECTFREQUENCY;
2943 <  PingFreq(aclass) = DEFAULT_PINGFREQUENCY;
2944 <  MaxTotal(aclass) = MAXIMUM_LINKS_DEFAULT;
2945 <  MaxSendq(aclass) = DEFAULT_SENDQ;
1279 >  log_reopen_all();
1280  
1281 <  client_check_cb = register_callback("check_client", check_client);
1282 < }
1281 >  isupport_add("NICKLEN", NULL, ConfigServerInfo.max_nick_length);
1282 >  isupport_add("NETWORK", ConfigServerInfo.network_name, -1);
1283  
1284 < /* get_sendq()
1285 < *
1286 < * inputs       - pointer to client
1287 < * output       - sendq for this client as found from its class
1288 < * side effects - NONE
1289 < */
1290 < unsigned long
1291 < get_sendq(struct Client *client_p)
1292 < {
1293 <  unsigned long sendq = DEFAULT_SENDQ;
1294 <  dlink_node *ptr;
1295 <  struct ConfItem *conf;
2962 <  struct ConfItem *class_conf;
2963 <  struct ClassItem *aclass;
2964 <  struct AccessItem *aconf;
1284 >  snprintf(chanmodes, sizeof(chanmodes), "beI:%d", ConfigChannel.max_bans);
1285 >  isupport_add("MAXLIST", chanmodes, -1);
1286 >  isupport_add("MAXTARGETS", NULL, ConfigGeneral.max_targets);
1287 >  isupport_add("CHANTYPES", "#", -1);
1288 >
1289 >  snprintf(chanlimit, sizeof(chanlimit), "#:%d",
1290 >           ConfigChannel.max_channels);
1291 >  isupport_add("CHANLIMIT", chanlimit, -1);
1292 >  snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,cimnprstCMORS");
1293 >  isupport_add("CHANNELLEN", NULL, CHANNELLEN);
1294 >  isupport_add("TOPICLEN", NULL, ConfigServerInfo.max_topic_length);
1295 >  isupport_add("CHANMODES", chanmodes, -1);
1296  
1297 <  if (client_p && !IsMe(client_p) && (client_p->localClient->confs.head))
1298 <  {
1299 <    DLINK_FOREACH(ptr, client_p->localClient->confs.head)
2969 <    {
2970 <      conf = ptr->data;
2971 <      if ((conf->type == SERVER_TYPE) || (conf->type == OPER_TYPE)
2972 <          || (conf->type == CLIENT_TYPE))
2973 <      {
2974 <        aconf = (struct AccessItem *)map_to_conf(conf);
2975 <        if ((class_conf = aconf->class_ptr) == NULL)
2976 <          continue;
2977 <        aclass = (struct ClassItem *)map_to_conf(class_conf);
2978 <        sendq = MaxSendq(aclass);
2979 <        return sendq;
2980 <      }
2981 <    }
2982 <  }
2983 <  /* XXX return a default?
2984 <   * if here, then there wasn't an attached conf with a sendq
2985 <   * that is very bad -Dianora
1297 >  /*
1298 >   * message_locale may have changed.  rebuild isupport since it relies
1299 >   * on strlen(form_str(RPL_ISUPPORT))
1300     */
1301 <  return DEFAULT_SENDQ;
1301 >  isupport_rebuild();
1302   }
1303  
1304   /* conf_add_class_to_conf()
1305   *
1306   * inputs       - pointer to config item
1307   * output       - NONE
1308 < * side effects - Add a class pointer to a conf
1308 > * side effects - Add a class pointer to a conf
1309   */
1310   void
1311 < conf_add_class_to_conf(struct ConfItem *conf, const char *class_name)
1311 > conf_add_class_to_conf(struct MaskItem *conf, const char *name)
1312   {
1313 <  struct AccessItem *aconf;
3000 <  struct ClassItem *aclass;
3001 <
3002 <  aconf = (struct AccessItem *)map_to_conf(conf);
3003 <
3004 <  if (class_name == NULL)
3005 <  {
3006 <    aconf->class_ptr = class_default;
3007 <    if (conf->type == CLIENT_TYPE)
3008 <      sendto_realops_flags(UMODE_ALL, L_ALL,
3009 <                           "Warning *** Defaulting to default class for %s@%s",
3010 <                           aconf->user, aconf->host);
3011 <    else
3012 <      sendto_realops_flags(UMODE_ALL, L_ALL,
3013 <                           "Warning *** Defaulting to default class for %s",
3014 <                           conf->name);
3015 <  }
3016 <  else
1313 >  if (EmptyString(name) || (conf->class = class_find(name, 1)) == NULL)
1314    {
1315 <    aconf->class_ptr = find_class(class_name);
3019 <  }
1315 >    conf->class = class_default;
1316  
1317 <  if (aconf->class_ptr == NULL)
1318 <  {
1319 <    if (conf->type == CLIENT_TYPE)
1320 <      sendto_realops_flags(UMODE_ALL, L_ALL,
3025 <                           "Warning *** Defaulting to default class for %s@%s",
3026 <                           aconf->user, aconf->host);
1317 >    if (conf->type == CONF_CLIENT || conf->type == CONF_OPER)
1318 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1319 >                           "Warning *** Defaulting to default class for %s@%s",
1320 >                           conf->user, conf->host);
1321      else
1322 <      sendto_realops_flags(UMODE_ALL, L_ALL,
1323 <                           "Warning *** Defaulting to default class for %s",
1324 <                           conf->name);
3031 <    aconf->class_ptr = class_default;
3032 <  }
3033 <  else
3034 <  {
3035 <    aclass = (struct ClassItem *)map_to_conf(aconf->class_ptr);
3036 <    if (MaxTotal(aclass) < 0)
3037 <    {
3038 <      aconf->class_ptr = class_default;
3039 <    }
3040 <  }
3041 < }
3042 <
3043 < #define MAXCONFLINKS 150
3044 <
3045 < /* conf_add_server()
3046 < *
3047 < * inputs       - pointer to config item
3048 < *              - pointer to link count already on this conf
3049 < * output       - NONE
3050 < * side effects - Add a connect block
3051 < */
3052 < int
3053 < conf_add_server(struct ConfItem *conf, unsigned int lcount, const char *class_name)
3054 < {
3055 <  struct AccessItem *aconf;
3056 <  char *orig_host;
3057 <
3058 <  aconf = map_to_conf(conf);
3059 <
3060 <  conf_add_class_to_conf(conf, class_name);
3061 <
3062 <  if (lcount > MAXCONFLINKS || !aconf->host || !conf->name)
3063 <  {
3064 <    sendto_realops_flags(UMODE_ALL, L_ALL, "Bad connect block");
3065 <    ilog(L_WARN, "Bad connect block");
3066 <    return -1;
3067 <  }
3068 <
3069 <  if (EmptyString(aconf->passwd) && !IsConfCryptLink(aconf))
3070 <  {
3071 <    sendto_realops_flags(UMODE_ALL, L_ALL, "Bad connect block, name %s",
3072 <                         conf->name);
3073 <    ilog(L_WARN, "Bad connect block, host %s", conf->name);
3074 <    return -1;
3075 <  }
3076 <
3077 <  orig_host = aconf->host;
3078 <  split_nuh(orig_host, NULL, &aconf->user, &aconf->host);
3079 <  MyFree(orig_host);
3080 <  lookup_confhost(conf);
3081 <
3082 <  return 0;
3083 < }
3084 <
3085 < /* conf_add_d_conf()
3086 < *
3087 < * inputs       - pointer to config item
3088 < * output       - NONE
3089 < * side effects - Add a d/D line
3090 < */
3091 < void
3092 < conf_add_d_conf(struct AccessItem *aconf)
3093 < {
3094 <  if (aconf->host == NULL)
3095 <    return;
3096 <
3097 <  aconf->user = NULL;
3098 <
3099 <  /* XXX - Should 'd' ever be in the old conf? For new conf we don't
3100 <   *       need this anyway, so I will disable it for now... -A1kmm
3101 <   */
3102 <  if (parse_netmask(aconf->host, NULL, NULL) == HM_HOST)
3103 <  {
3104 <    ilog(L_WARN, "Invalid Dline %s ignored", aconf->host);
3105 <    free_access_item(aconf);
3106 <  }
3107 <  else
3108 <  {
3109 <    /* XXX ensure user is NULL */
3110 <    MyFree(aconf->user);
3111 <    aconf->user = NULL;
3112 <    add_conf_by_address(CONF_DLINE, aconf);
1322 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1323 >                           "Warning *** Defaulting to default class for %s",
1324 >                           conf->name);
1325    }
1326   }
1327  
# Line 3124 | Line 1336 | yyerror(const char *msg)
1336   {
1337    char newlinebuf[IRCD_BUFSIZE];
1338  
1339 <  if (ypass != 1)
1339 >  if (conf_parser_ctx.pass != 1)
1340      return;
1341  
1342    strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1343 <  sendto_realops_flags(UMODE_ALL, L_ALL, "\"%s\", line %u: %s: %s",
1343 >  sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1344 >                       "\"%s\", line %u: %s: %s",
1345                         conffilebuf, lineno + 1, msg, newlinebuf);
1346 <  ilog(L_WARN, "\"%s\", line %u: %s: %s",
1346 >  ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1347         conffilebuf, lineno + 1, msg, newlinebuf);
1348   }
1349  
1350 < int
1351 < conf_fbgets(char *lbuf, unsigned int max_size, FBFILE *fb)
1350 > void
1351 > conf_error_report(const char *msg)
1352   {
1353 <  if (fbgets(lbuf, max_size, fb) == NULL)
3141 <    return 0;
3142 <
3143 <  return strlen(lbuf);
3144 < }
1353 >  char newlinebuf[IRCD_BUFSIZE];
1354  
1355 < int
1356 < conf_yy_fatal_error(const char *msg)
1357 < {
1358 <  return 0;
1355 >  strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1356 >  sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1357 >                       "\"%s\", line %u: %s: %s",
1358 >                       conffilebuf, lineno + 1, msg, newlinebuf);
1359 >  ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1360 >       conffilebuf, lineno + 1, msg, newlinebuf);
1361   }
1362  
1363   /*
1364   * valid_tkline()
1365 < *
1365 > *
1366   * inputs       - pointer to ascii string to check
1367   *              - whether the specified time is in seconds or minutes
1368   * output       - -1 not enough parameters
# Line 3160 | Line 1371 | conf_yy_fatal_error(const char *msg)
1371   * Originally written by Dianora (Diane, db@db.net)
1372   */
1373   time_t
1374 < valid_tkline(char *p, int minutes)
1374 > valid_tkline(const char *data, const int minutes)
1375   {
1376 +  const unsigned char *p = (const unsigned char *)data;
1377 +  unsigned char tmpch = '\0';
1378    time_t result = 0;
1379  
1380 <  while (*p)
1380 >  while ((tmpch = *p++))
1381    {
1382 <    if (IsDigit(*p))
3170 <    {
3171 <      result *= 10;
3172 <      result += ((*p) & 0xF);
3173 <      p++;
3174 <    }
3175 <    else
1382 >    if (!IsDigit(tmpch))
1383        return 0;
1384 +
1385 +    result *= 10;
1386 +    result += (tmpch & 0xF);
1387    }
1388  
1389 <  /* in the degenerate case where oper does a /quote kline 0 user@host :reason
1390 <   * i.e. they specifically use 0, I am going to return 1 instead
1391 <   * as a return value of non-zero is used to flag it as a temporary kline
1389 >  /*
1390 >   * In the degenerate case where oper does a /quote kline 0 user@host :reason
1391 >   * i.e. they specifically use 0, I am going to return 1 instead as a return
1392 >   * value of non-zero is used to flag it as a temporary kline
1393     */
3183
1394    if (result == 0)
1395      result = 1;
1396  
1397 <  /*
1397 >  /*
1398     * If the incoming time is in seconds convert it to minutes for the purpose
1399     * of this calculation
1400     */
1401    if (!minutes)
1402 <    result = result / (time_t)60;
1402 >    result = result / 60;
1403  
1404    if (result > MAX_TDKLINE_TIME)
1405      result = MAX_TDKLINE_TIME;
1406  
1407 <  result = result * (time_t)60;  /* turn it into seconds */
1407 >  result = result * 60;  /* Turn it into seconds */
1408  
1409    return result;
1410   }
1411  
1412 + /* valid_wild_card_simple()
1413 + *
1414 + * inputs       - data to check for sufficient non-wildcard characters
1415 + * outputs      - 1 if valid, else 0
1416 + * side effects - none
1417 + */
1418 + int
1419 + valid_wild_card_simple(const char *data)
1420 + {
1421 +  const unsigned char *p = (const unsigned char *)data;
1422 +  unsigned char tmpch = '\0';
1423 +  unsigned int nonwild = 0, wild = 0;
1424 +
1425 +  while ((tmpch = *p++))
1426 +  {
1427 +    if (tmpch == '\\' && *p)
1428 +    {
1429 +      ++p;
1430 +      if (++nonwild >= ConfigGeneral.min_nonwildcard_simple)
1431 +        return 1;
1432 +    }
1433 +    else if (!IsMWildChar(tmpch))
1434 +    {
1435 +      if (++nonwild >= ConfigGeneral.min_nonwildcard_simple)
1436 +        return 1;
1437 +    }
1438 +    else
1439 +      ++wild;
1440 +  }
1441 +
1442 +  return !wild;
1443 + }
1444 +
1445   /* valid_wild_card()
1446   *
1447   * input        - pointer to client
# Line 3208 | Line 1451 | valid_tkline(char *p, int minutes)
1451   * side effects - NOTICE is given to source_p if warn is 1
1452   */
1453   int
1454 < valid_wild_card(struct Client *source_p, int warn, int count, ...)
1454 > valid_wild_card(struct Client *source_p, int count, ...)
1455   {
1456 <  char *p;
1457 <  char tmpch;
3215 <  int nonwild = 0;
1456 >  unsigned char tmpch = '\0';
1457 >  unsigned int nonwild = 0;
1458    va_list args;
1459  
1460    /*
# Line 3231 | Line 1473 | valid_wild_card(struct Client *source_p,
1473  
1474    while (count--)
1475    {
1476 <    p = va_arg(args, char *);
1476 >    const unsigned char *p = va_arg(args, const unsigned char *);
1477      if (p == NULL)
1478        continue;
1479  
# Line 3243 | Line 1485 | valid_wild_card(struct Client *source_p,
1485           * If we find enough non-wild characters, we can
1486           * break - no point in searching further.
1487           */
1488 <        if (++nonwild >= ConfigFileEntry.min_nonwildcard)
1488 >        if (++nonwild >= ConfigGeneral.min_nonwildcard)
1489 >        {
1490 >          va_end(args);
1491            return 1;
1492 +        }
1493        }
1494      }
1495    }
1496  
1497 <  if (warn)
1498 <    sendto_one(source_p, ":%s NOTICE %s :Please include at least %d non-wildcard characters with the mask",
1499 <               me.name, source_p->name, ConfigFileEntry.min_nonwildcard);
1497 >  if (IsClient(source_p))
1498 >    sendto_one_notice(source_p, &me,
1499 >                      ":Please include at least %u non-wildcard characters with the mask",
1500 >                      ConfigGeneral.min_nonwildcard);
1501 >  va_end(args);
1502 >  return 0;
1503 > }
1504 >
1505 > /* find_user_host()
1506 > *
1507 > * inputs       - pointer to client placing kline
1508 > *              - pointer to user_host_or_nick
1509 > *              - pointer to user buffer
1510 > *              - pointer to host buffer
1511 > * output       - 0 if not ok to kline, 1 to kline i.e. if valid user host
1512 > * side effects -
1513 > */
1514 > static int
1515 > find_user_host(struct Client *source_p, char *user_host_or_nick,
1516 >               char *luser, char *lhost)
1517 > {
1518 >  struct Client *target_p = NULL;
1519 >  char *hostp = NULL;
1520 >
1521 >  if (lhost == NULL)
1522 >  {
1523 >    strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
1524 >    return 1;
1525 >  }
1526 >
1527 >  if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
1528 >  {
1529 >    /* Explicit user@host mask given */
1530 >    if (hostp)                            /* I'm a little user@host */
1531 >    {
1532 >      *(hostp++) = '\0';                       /* short and squat */
1533 >
1534 >      if (*user_host_or_nick)
1535 >        strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
1536 >      else
1537 >        strcpy(luser, "*");
1538 >
1539 >      if (*hostp)
1540 >        strlcpy(lhost, hostp, HOSTLEN + 1);    /* here is my host */
1541 >      else
1542 >        strcpy(lhost, "*");
1543 >    }
1544 >    else
1545 >    {
1546 >      luser[0] = '*';             /* no @ found, assume its *@somehost */
1547 >      luser[1] = '\0';
1548 >      strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
1549 >    }
1550 >
1551 >    return 1;
1552 >  }
1553 >  else
1554 >  {
1555 >    /* Try to find user@host mask from nick */
1556 >    /* Okay to use source_p as the first param, because source_p == client_p */
1557 >    if ((target_p =
1558 >        find_chasing(source_p, user_host_or_nick)) == NULL)
1559 >      return 0;  /* find_chasing sends ERR_NOSUCHNICK */
1560 >
1561 >    if (HasFlag(target_p, FLAGS_EXEMPTKLINE))
1562 >    {
1563 >      if (IsClient(source_p))
1564 >        sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
1565 >      return 0;
1566 >    }
1567 >
1568 >    /*
1569 >     * Turn the "user" bit into "*user", blow away '~'
1570 >     * if found in original user name (non-idented)
1571 >     */
1572 >    strlcpy(luser, target_p->username, USERLEN*4 + 1);
1573 >
1574 >    if (target_p->username[0] == '~')
1575 >      luser[0] = '*';
1576 >
1577 >    if (!strcmp(target_p->sockhost, "0"))
1578 >      strlcpy(lhost, target_p->host, HOSTLEN*4 + 1);
1579 >    else
1580 >      strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
1581 >    return 1;
1582 >  }
1583 >
1584    return 0;
1585   }
1586  
# Line 3265 | Line 1594 | valid_wild_card(struct Client *source_p,
1594   *              - parse_flags bit map of things to test
1595   *              - pointer to user or string to parse into
1596   *              - pointer to host or NULL to parse into if non NULL
1597 < *              - pointer to optional tkline time or NULL
1597 > *              - pointer to optional tkline time or NULL
1598   *              - pointer to target_server to parse into if non NULL
1599   *              - pointer to reason to parse into
1600   *
1601 < * output       - 1 if valid, -1 if not valid
1601 > * output       - 1 if valid, 0 if not valid
1602   * side effects - A generalised k/d/x etc. line parser,
1603   *               "ALINE [time] user@host|string [ON] target :reason"
1604   *                will parse returning a parsed user, host if
# Line 3281 | Line 1610 | valid_wild_card(struct Client *source_p,
1610   *                if target_server is NULL and an "ON" is found error
1611   *                is reported.
1612   *                if reason pointer is NULL ignore pointer,
1613 < *                this allows usee of parse_a_line in unkline etc.
1613 > *                this allows use of parse_a_line in unkline etc.
1614   *
1615   * - Dianora
1616   */
1617   int
1618   parse_aline(const char *cmd, struct Client *source_p,
1619 <            int parc, char **parv,
1620 <            int parse_flags, char **up_p, char **h_p, time_t *tkline_time,
1621 <            char **target_server, char **reason)
1619 >            int parc, char **parv,
1620 >            int parse_flags, char **up_p, char **h_p, time_t *tkline_time,
1621 >            char **target_server, char **reason)
1622   {
1623    int found_tkline_time=0;
1624 <  static char def_reason[] = "No Reason";
1624 >  static char default_reason[] = CONF_NOREASON;
1625    static char user[USERLEN*4+1];
1626    static char host[HOSTLEN*4+1];
1627  
# Line 3301 | Line 1630 | parse_aline(const char *cmd, struct Clie
1630  
1631    found_tkline_time = valid_tkline(*parv, TK_MINUTES);
1632  
1633 <  if (found_tkline_time != 0)
1633 >  if (found_tkline_time)
1634    {
1635      parv++;
1636      parc--;
1637  
1638 <    if (tkline_time != NULL)
1638 >    if (tkline_time)
1639        *tkline_time = found_tkline_time;
1640      else
1641      {
1642 <      sendto_one(source_p, ":%s NOTICE %s :temp_line not supported by %s",
1643 <                 me.name, source_p->name, cmd);
3315 <      return -1;
1642 >      sendto_one_notice(source_p, &me, ":temp_line not supported by %s", cmd);
1643 >      return 0;
1644      }
1645    }
1646  
1647    if (parc == 0)
1648    {
1649 <    sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1650 <               me.name, source_p->name, cmd);
3323 <    return -1;
1649 >    sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1650 >    return 0;
1651    }
1652  
1653    if (h_p == NULL)
1654      *up_p = *parv;
1655    else
1656    {
1657 <    if (find_user_host(source_p, *parv, user, host, parse_flags) == 0)
1658 <      return -1;
1657 >    if (find_user_host(source_p, *parv, user, host) == 0)
1658 >      return 0;
1659  
1660      *up_p = user;
1661      *h_p = host;
1662    }
1663 <
1663 >
1664    parc--;
1665    parv++;
1666  
1667 <  if (parc != 0)
1667 >  if (parc)
1668    {
1669      if (irccmp(*parv, "ON") == 0)
1670      {
1671        parc--;
1672        parv++;
1673  
1674 <      if (target_server == NULL)
1674 >      if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN))
1675        {
1676 <        sendto_one(source_p, ":%s NOTICE %s :ON server not supported by %s",
1677 <                   me.name, source_p->name, cmd);
3351 <        return -1;
3352 <      }
3353 <
3354 <      if (!IsOperRemoteBan(source_p))
3355 <      {
3356 <        sendto_one(source_p, form_str(ERR_NOPRIVS),
3357 <                   me.name, source_p->name, "remoteban");
3358 <        return -1;
1676 >        sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "remoteban");
1677 >        return 0;
1678        }
1679  
1680        if (parc == 0 || EmptyString(*parv))
1681        {
1682 <        sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1683 <                   me.name, source_p->name, cmd);
3365 <        return -1;
1682 >        sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1683 >        return 0;
1684        }
1685  
1686        *target_server = *parv;
# Line 3374 | Line 1692 | parse_aline(const char *cmd, struct Clie
1692        /* Make sure target_server *is* NULL if no ON server found
1693         * caller probably NULL'd it first, but no harm to do it again -db
1694         */
1695 <      if (target_server != NULL)
1696 <        *target_server = NULL;
1695 >      if (target_server)
1696 >        *target_server = NULL;
1697      }
1698    }
1699  
1700 <  if (h_p != NULL)
1700 >  if (h_p)
1701    {
1702 <    if (strchr(user, '!') != NULL)
1702 >    if (strchr(user, '!'))
1703      {
1704 <      sendto_one(source_p, ":%s NOTICE %s :Invalid character '!' in kline",
1705 <                 me.name, source_p->name);
3388 <      return -1;
1704 >      sendto_one_notice(source_p, &me, ":Invalid character '!' in kline");
1705 >      return 0;
1706      }
1707  
1708 <    if ((parse_flags & AWILD) && !valid_wild_card(source_p, YES, 2, *up_p, *h_p))
1709 <      return -1;
1708 >    if ((parse_flags & AWILD) && !valid_wild_card(source_p, 2, *up_p, *h_p))
1709 >      return 0;
1710    }
1711    else
1712 <    if ((parse_flags & AWILD) && !valid_wild_card(source_p, YES, 1, *up_p))
1713 <      return -1;
1712 >    if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, *up_p))
1713 >      return 0;
1714  
1715 <  if (reason != NULL)
1715 >  if (reason)
1716    {
1717 <    if (parc != 0)
3401 <    {
1717 >    if (parc && !EmptyString(*parv))
1718        *reason = *parv;
3403      if (!valid_comment(source_p, *reason, YES))
3404        return -1;
3405    }
1719      else
1720 <      *reason = def_reason;
1720 >      *reason = default_reason;
1721    }
1722  
1723    return 1;
1724   }
1725  
3413 /* find_user_host()
3414 *
3415 * inputs       - pointer to client placing kline
3416 *              - pointer to user_host_or_nick
3417 *              - pointer to user buffer
3418 *              - pointer to host buffer
3419 * output       - 0 if not ok to kline, 1 to kline i.e. if valid user host
3420 * side effects -
3421 */
3422 static int
3423 find_user_host(struct Client *source_p, char *user_host_or_nick,
3424               char *luser, char *lhost, unsigned int flags)
3425 {
3426  struct Client *target_p = NULL;
3427  char *hostp = NULL;
3428
3429  if (lhost == NULL)
3430  {
3431    strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
3432    return 1;
3433  }
3434
3435  if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
3436  {
3437    /* Explicit user@host mask given */
3438
3439    if(hostp != NULL)                            /* I'm a little user@host */
3440    {
3441      *(hostp++) = '\0';                       /* short and squat */
3442      if (*user_host_or_nick)
3443        strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
3444      else
3445        strcpy(luser, "*");
3446      if (*hostp)
3447        strlcpy(lhost, hostp, HOSTLEN + 1);    /* here is my host */
3448      else
3449        strcpy(lhost, "*");
3450    }
3451    else
3452    {
3453      luser[0] = '*';             /* no @ found, assume its *@somehost */
3454      luser[1] = '\0';    
3455      strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
3456    }
3457    
3458    return 1;
3459  }
3460  else if (!(flags & NOUSERLOOKUP))
3461  {
3462    /* Try to find user@host mask from nick */
3463    /* Okay to use source_p as the first param, because source_p == client_p */
3464    if ((target_p =
3465        find_chasing(source_p, source_p, user_host_or_nick, NULL)) == NULL)
3466      return 0;
3467
3468    if (IsExemptKline(target_p))
3469    {
3470      if (!IsServer(source_p))
3471        sendto_one(source_p,
3472                   ":%s NOTICE %s :%s is E-lined",
3473                   me.name, source_p->name, target_p->name);
3474      return 0;
3475    }
3476
3477    /*
3478     * turn the "user" bit into "*user", blow away '~'
3479     * if found in original user name (non-idented)
3480     */
3481    strlcpy(luser, target_p->username, USERLEN*4 + 1);
3482
3483    if (target_p->username[0] == '~')
3484      luser[0] = '*';
3485
3486    if (target_p->sockhost[0] == '\0' ||
3487        (target_p->sockhost[0] == '0' && target_p->sockhost[1] == '\0'))
3488      strlcpy(lhost, target_p->host, HOSTLEN*4 + 1);
3489    else
3490      strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
3491    return 1;
3492  }
3493
3494  return 0;
3495 }
3496
3497 /* valid_comment()
3498 *
3499 * inputs       - pointer to client
3500 *              - pointer to comment
3501 * output       - 0 if no valid comment,
3502 *              - 1 if valid
3503 * side effects - truncates reason where necessary
3504 */
3505 int
3506 valid_comment(struct Client *source_p, char *comment, int warn)
3507 {
3508  if (strchr(comment, '"'))
3509  {
3510    if (warn)
3511      sendto_one(source_p, ":%s NOTICE %s :Invalid character '\"' in comment",
3512                 me.name, source_p->name);
3513    return 0;
3514  }
3515
3516  if (strlen(comment) > REASONLEN)
3517    comment[REASONLEN-1] = '\0';
3518
3519  return 1;
3520 }
3521
1726   /* match_conf_password()
1727   *
1728   * inputs       - pointer to given password
# Line 3527 | Line 1731 | valid_comment(struct Client *source_p, c
1731   * side effects - none
1732   */
1733   int
1734 < match_conf_password(const char *password, const struct AccessItem *aconf)
1734 > match_conf_password(const char *password, const struct MaskItem *conf)
1735   {
1736    const char *encr = NULL;
1737  
1738 <  if (password == NULL || aconf->passwd == NULL)
1738 >  if (EmptyString(password) || EmptyString(conf->passwd))
1739      return 0;
1740  
1741 <  if (aconf->flags & CONF_FLAGS_ENCRYPTED)
1742 <  {
3539 <    /* use first two chars of the password they send in as salt */
3540 <    /* If the password in the conf is MD5, and ircd is linked
3541 <     * to scrypt on FreeBSD, or the standard crypt library on
3542 <     * glibc Linux, then this code will work fine on generating
3543 <     * the proper encrypted hash for comparison.
3544 <     */
3545 <    if (*aconf->passwd)
3546 <      encr = crypt(password, aconf->passwd);
3547 <    else
3548 <      encr = "";
3549 <  }
1741 >  if (conf->flags & CONF_FLAGS_ENCRYPTED)
1742 >    encr = crypt(password, conf->passwd);
1743    else
1744      encr = password;
1745  
1746 <  return !strcmp(encr, aconf->passwd);
1746 >  return encr && !strcmp(encr, conf->passwd);
1747   }
1748  
1749   /*
# Line 3558 | Line 1751 | match_conf_password(const char *password
1751   *
1752   * inputs       - client sending the cluster
1753   *              - command name "KLINE" "XLINE" etc.
1754 < *              - capab -- CAP_KLN etc. from s_serv.h
1755 < *              - cluster type -- CLUSTER_KLINE etc. from s_conf.h
1754 > *              - capab -- CAPAB_KLN etc. from server.h
1755 > *              - cluster type -- CLUSTER_KLINE etc. from conf.h
1756   *              - pattern and args to send along
1757   * output       - none
1758   * side effects - Take source_p send the pattern with args given
1759   *                along to all servers that match capab and cluster type
1760   */
1761   void
1762 < cluster_a_line(struct Client *source_p, const char *command,
1763 <               int capab, int cluster_type, const char *pattern, ...)
1762 > cluster_a_line(struct Client *source_p, const char *command, unsigned int capab,
1763 >               unsigned int cluster_type, const char *pattern, ...)
1764   {
1765    va_list args;
1766 <  char buffer[IRCD_BUFSIZE];
1767 <  struct ConfItem *conf;
3575 <  dlink_node *ptr;
1766 >  char buffer[IRCD_BUFSIZE] = "";
1767 >  const dlink_node *node = NULL;
1768  
1769    va_start(args, pattern);
1770    vsnprintf(buffer, sizeof(buffer), pattern, args);
1771    va_end(args);
1772  
1773 <  DLINK_FOREACH(ptr, cluster_items.head)
1773 >  DLINK_FOREACH(node, cluster_items.head)
1774    {
1775 <    conf = ptr->data;
1775 >    const struct MaskItem *conf = node->data;
1776  
1777      if (conf->flags & cluster_type)
1778 <    {
1779 <      sendto_match_servs(source_p, conf->name, CAP_CLUSTER|capab,
3588 <                         "%s %s %s", command, conf->name, buffer);
3589 <    }
1778 >      sendto_match_servs(source_p, conf->name, CAPAB_CLUSTER | capab,
1779 >                         "%s %s %s", command, conf->name, buffer);
1780    }
1781   }
1782  
# Line 3618 | Line 1808 | cluster_a_line(struct Client *source_p,
1808   * @                            *       *       *
1809   * !                            *       *       *
1810   */
3621
1811   void
1812 < split_nuh(char *mask, char **nick, char **user, char **host)
1812 > split_nuh(struct split_nuh_item *const iptr)
1813   {
1814    char *p = NULL, *q = NULL;
1815  
1816 <  if ((p = strchr(mask, '!')) != NULL)
1817 <  {
3629 <    *p = '\0';
3630 <    if (nick != NULL)
3631 <    {
3632 <      if (*mask != '\0')
3633 <        *nick = xstrldup(mask, NICKLEN);
3634 <      else
3635 <        DupString(*nick, "*");
3636 <    }
1816 >  if (iptr->nickptr)
1817 >    strlcpy(iptr->nickptr, "*", iptr->nicksize);
1818  
1819 <    if ((q = strchr(++p, '@')) != NULL)
1820 <    {
3640 <      *q = '\0';
1819 >  if (iptr->userptr)
1820 >    strlcpy(iptr->userptr, "*", iptr->usersize);
1821  
1822 <      if (*p != '\0')
1823 <        *user = xstrldup(p, USERLEN+1);
3644 <      else
3645 <        DupString(*user, "*");
1822 >  if (iptr->hostptr)
1823 >    strlcpy(iptr->hostptr, "*", iptr->hostsize);
1824  
1825 <      if (*++q != '\0')
3648 <        *host = xstrldup(q, HOSTLEN+1);
3649 <      else
3650 <        DupString(*host, "*");
3651 <    }
3652 <    else
3653 <    {
3654 <      if (*p != '\0')
3655 <        *user = xstrldup(p, USERLEN+1);
3656 <      else
3657 <        DupString(*user, "*");
3658 <
3659 <      DupString(*host, "*");
3660 <    }
3661 <  }
3662 <  else  /* No ! found so lets look for a user@host */
1825 >  if ((p = strchr(iptr->nuhmask, '!')))
1826    {
1827 <    if ((p = strchr(mask, '@')) != NULL)        /* if found a @ */
3665 <    {
3666 <      if (nick != NULL)
3667 <        DupString(*nick, "*");
3668 <      *p = '\0';
1827 >    *p = '\0';
1828  
1829 <      if (*mask != '\0')
1830 <        *user = xstrldup(mask, USERLEN+1);
3672 <      else
3673 <        DupString(*user, "*");
1829 >    if (iptr->nickptr && *iptr->nuhmask)
1830 >      strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
1831  
1832 <      if (*++p != '\0')
3676 <        *host = xstrldup(p, HOSTLEN+1);
3677 <      else
3678 <        DupString(*host, "*");
3679 <    }
3680 <    else                                        /* no @ found */
1832 >    if ((q = strchr(++p, '@')))
1833      {
1834 <      if (nick != NULL)
3683 <      {
3684 <        if (strpbrk(mask, ".:"))
3685 <        {
3686 <          DupString(*nick, "*");
3687 <          *host = xstrldup(mask, HOSTLEN+1);
3688 <        }
3689 <        else
3690 <        {
3691 <          *nick = xstrldup(mask, NICKLEN);
3692 <          DupString(*host, "*");
3693 <        }
1834 >      *q++ = '\0';
1835  
1836 <        DupString(*user, "*");
1837 <      }
3697 <      else
3698 <      {
3699 <        DupString(*user, "*");
3700 <        *host = xstrldup(mask, HOSTLEN+1);
3701 <      }
3702 <    }
3703 <  }
3704 < }
1836 >      if (*p)
1837 >        strlcpy(iptr->userptr, p, iptr->usersize);
1838  
1839 < /*
1840 < * flags_to_ascii
3708 < *
3709 < * inputs       - flags is a bitmask
3710 < *              - pointer to table of ascii letters corresponding
3711 < *                to each bit
3712 < *              - flag 1 for convert ToLower if bit missing
3713 < *                0 if ignore.
3714 < * output       - none
3715 < * side effects - string pointed to by p has bitmap chars written to it
3716 < */
3717 < static void
3718 < flags_to_ascii(unsigned int flags, const unsigned int bit_table[], char *p,
3719 <               int lowerit)
3720 < {
3721 <  unsigned int mask = 1;
3722 <  int i = 0;
3723 <
3724 <  for (mask = 1; (mask != 0) && (bit_table[i] != 0); mask <<= 1, i++)
3725 <  {
3726 <    if (flags & mask)
3727 <      *p++ = bit_table[i];
3728 <    else if(lowerit)
3729 <      *p++ = ToLower(bit_table[i]);
3730 <  }
3731 <  *p = '\0';
3732 < }
3733 <
3734 < /*
3735 < * cidr_limit_reached
3736 < *
3737 < * inputs       - int flag allowing over_rule of limits
3738 < *              - pointer to the ip to be added
3739 < *              - pointer to the class
3740 < * output       - non zero if limit reached
3741 < *                0 if limit not reached
3742 < * side effects -
3743 < */
3744 < static int
3745 < cidr_limit_reached(int over_rule,
3746 <                   struct irc_ssaddr *ip, struct ClassItem *aclass)
3747 < {
3748 <  dlink_node *ptr = NULL;
3749 <  struct CidrItem *cidr;
3750 <
3751 <  if (NumberPerCidr(aclass) <= 0)
3752 <    return 0;
3753 <
3754 <  if (ip->ss.ss_family == AF_INET)
3755 <  {
3756 <    if (CidrBitlenIPV4(aclass) <= 0)
3757 <      return 0;
3758 <
3759 <    DLINK_FOREACH(ptr, aclass->list_ipv4.head)
3760 <    {
3761 <      cidr = ptr->data;
3762 <      if (match_ipv4(ip, &cidr->mask, CidrBitlenIPV4(aclass)))
3763 <      {
3764 <        if (!over_rule && (cidr->number_on_this_cidr >= NumberPerCidr(aclass)))
3765 <          return -1;
3766 <        cidr->number_on_this_cidr++;
3767 <        return 0;
3768 <      }
3769 <    }
3770 <    cidr = MyMalloc(sizeof(struct CidrItem));
3771 <    cidr->number_on_this_cidr = 1;
3772 <    cidr->mask = *ip;
3773 <    mask_addr(&cidr->mask, CidrBitlenIPV4(aclass));
3774 <    dlinkAdd(cidr, &cidr->node, &aclass->list_ipv4);
3775 <  }
3776 < #ifdef IPV6
3777 <  else if (CidrBitlenIPV6(aclass) > 0)
3778 <  {
3779 <    DLINK_FOREACH(ptr, aclass->list_ipv6.head)
3780 <    {
3781 <      cidr = ptr->data;
3782 <      if (match_ipv6(ip, &cidr->mask, CidrBitlenIPV6(aclass)))
3783 <      {
3784 <        if (!over_rule && (cidr->number_on_this_cidr >= NumberPerCidr(aclass)))
3785 <          return -1;
3786 <        cidr->number_on_this_cidr++;
3787 <        return 0;
3788 <      }
1839 >      if (*q)
1840 >        strlcpy(iptr->hostptr, q, iptr->hostsize);
1841      }
1842 <    cidr = MyMalloc(sizeof(struct CidrItem));
3791 <    cidr->number_on_this_cidr = 1;
3792 <    cidr->mask = *ip;
3793 <    mask_addr(&cidr->mask, CidrBitlenIPV6(aclass));
3794 <    dlinkAdd(cidr, &cidr->node, &aclass->list_ipv6);
3795 <  }
3796 < #endif
3797 <  return 0;
3798 < }
3799 <
3800 < /*
3801 < * remove_from_cidr_check
3802 < *
3803 < * inputs       - pointer to the ip to be removed
3804 < *              - pointer to the class
3805 < * output       - NONE
3806 < * side effects -
3807 < */
3808 < static void
3809 < remove_from_cidr_check(struct irc_ssaddr *ip, struct ClassItem *aclass)
3810 < {
3811 <  dlink_node *ptr = NULL;
3812 <  dlink_node *next_ptr = NULL;
3813 <  struct CidrItem *cidr;
3814 <
3815 <  if (NumberPerCidr(aclass) == 0)
3816 <    return;
3817 <
3818 <  if (ip->ss.ss_family == AF_INET)
3819 <  {
3820 <    if (CidrBitlenIPV4(aclass) <= 0)
3821 <      return;
3822 <
3823 <    DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv4.head)
1842 >    else
1843      {
1844 <      cidr = ptr->data;
1845 <      if (match_ipv4(ip, &cidr->mask, CidrBitlenIPV4(aclass)))
3827 <      {
3828 <        cidr->number_on_this_cidr--;
3829 <        if (cidr->number_on_this_cidr == 0)
3830 <        {
3831 <          dlinkDelete(ptr, &aclass->list_ipv4);
3832 <          MyFree(cidr);
3833 <          return;
3834 <        }
3835 <      }
1844 >      if (*p)
1845 >        strlcpy(iptr->userptr, p, iptr->usersize);
1846      }
1847    }
1848 < #ifdef IPV6
3839 <  else if (CidrBitlenIPV6(aclass) > 0)
1848 >  else
1849    {
1850 <    DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv6.head)
1850 >    /* No ! found so lets look for a user@host */
1851 >    if ((p = strchr(iptr->nuhmask, '@')))
1852      {
1853 <      cidr = ptr->data;
1854 <      if (match_ipv6(ip, &cidr->mask, CidrBitlenIPV6(aclass)))
3845 <      {
3846 <        cidr->number_on_this_cidr--;
3847 <        if (cidr->number_on_this_cidr == 0)
3848 <        {
3849 <          dlinkDelete(ptr, &aclass->list_ipv6);
3850 <          MyFree(cidr);
3851 <          return;
3852 <        }
3853 <      }
3854 <    }
3855 <  }
3856 < #endif
3857 < }
3858 <
3859 < static void
3860 < rebuild_cidr_list(int aftype, struct ConfItem *oldcl, struct ClassItem *newcl,
3861 <                  dlink_list *old_list, dlink_list *new_list, int changed)
3862 < {
3863 <  dlink_node *ptr;
3864 <  struct Client *client_p;
3865 <  struct ConfItem *conf;
3866 <  struct AccessItem *aconf;
3867 <
3868 <  if (!changed)
3869 <  {
3870 <    *new_list = *old_list;
3871 <    old_list->head = old_list->tail = NULL;
3872 <    old_list->length = 0;
3873 <    return;
3874 <  }
1853 >      /* if found a @ */
1854 >      *p++ = '\0';
1855  
1856 <  DLINK_FOREACH(ptr, local_client_list.head)
1857 <  {
3878 <    client_p = ptr->data;
3879 <    if (client_p->localClient->aftype != aftype)
3880 <      continue;
3881 <    if (dlink_list_length(&client_p->localClient->confs) == 0)
3882 <      continue;
1856 >      if (*iptr->nuhmask)
1857 >        strlcpy(iptr->userptr, iptr->nuhmask, iptr->usersize);
1858  
1859 <    conf = client_p->localClient->confs.tail->data;
1860 <    if (conf->type == CLIENT_TYPE)
1859 >      if (*p)
1860 >        strlcpy(iptr->hostptr, p, iptr->hostsize);
1861 >    }
1862 >    else
1863      {
1864 <      aconf = map_to_conf(conf);
1865 <      if (aconf->class_ptr == oldcl)
1866 <        cidr_limit_reached(1, &client_p->localClient->ip, newcl);
1864 >      /* No @ found */
1865 >      if (!iptr->nickptr || strpbrk(iptr->nuhmask, ".:"))
1866 >        strlcpy(iptr->hostptr, iptr->nuhmask, iptr->hostsize);
1867 >      else
1868 >        strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
1869      }
1870    }
1871   }
3893
3894 /*
3895 * rebuild_cidr_class
3896 *
3897 * inputs       - pointer to old conf
3898 *              - pointer to new_class
3899 * output       - none
3900 * side effects - rebuilds the class link list of cidr blocks
3901 */
3902 void
3903 rebuild_cidr_class(struct ConfItem *conf, struct ClassItem *new_class)
3904 {
3905  struct ClassItem *old_class = map_to_conf(conf);
3906
3907  if (NumberPerCidr(old_class) > 0 && NumberPerCidr(new_class) > 0)
3908  {
3909    if (CidrBitlenIPV4(old_class) > 0 && CidrBitlenIPV4(new_class) > 0)
3910      rebuild_cidr_list(AF_INET, conf, new_class,
3911                        &old_class->list_ipv4, &new_class->list_ipv4,
3912                        CidrBitlenIPV4(old_class) != CidrBitlenIPV4(new_class));
3913
3914 #ifdef IPV6
3915    if (CidrBitlenIPV6(old_class) > 0 && CidrBitlenIPV6(new_class) > 0)
3916      rebuild_cidr_list(AF_INET6, conf, new_class,
3917                        &old_class->list_ipv6, &new_class->list_ipv6,
3918                        CidrBitlenIPV6(old_class) != CidrBitlenIPV6(new_class));
3919 #endif
3920  }
3921
3922  destroy_cidr_class(old_class);
3923 }
3924
3925 /*
3926 * destroy_cidr_list
3927 *
3928 * inputs       - pointer to class dlink list of cidr blocks
3929 * output       - none
3930 * side effects - completely destroys the class link list of cidr blocks
3931 */
3932 static void
3933 destroy_cidr_list(dlink_list *list)
3934 {
3935  dlink_node *ptr = NULL;
3936  dlink_node *next_ptr = NULL;
3937  struct CidrItem *cidr;
3938
3939  DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
3940  {
3941    cidr = ptr->data;
3942    dlinkDelete(ptr, list);
3943    MyFree(cidr);
3944  }
3945 }
3946
3947 /*
3948 * destroy_cidr_class
3949 *
3950 * inputs       - pointer to class
3951 * output       - none
3952 * side effects - completely destroys the class link list of cidr blocks
3953 */
3954 static void
3955 destroy_cidr_class(struct ClassItem *aclass)
3956 {
3957  destroy_cidr_list(&aclass->list_ipv4);
3958  destroy_cidr_list(&aclass->list_ipv6);
3959 }

Diff Legend

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