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

Comparing:
ircd-hybrid-8/src/s_conf.c (file contents), Revision 1157 by michael, Tue Aug 9 22:03:59 2011 UTC vs.
ircd-hybrid/trunk/src/conf.c (file contents), Revision 5776 by michael, Sat Apr 4 17:31:30 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 "balloc.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"
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"
39   #include "ircd.h"
40   #include "listener.h"
# Line 44 | Line 42
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"
49 #include "s_gline.h"
50 #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 + #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  
59 < struct Callback *client_check_cb = NULL;
60 < struct config_server_hide ConfigServerHide;
59 >
60 > struct config_channel_entry ConfigChannel;
61 > struct config_serverhide_entry ConfigServerHide;
62 > struct config_general_entry ConfigGeneral;
63 > struct config_log_entry ConfigLog = { .use_logging = 1 };
64 > struct config_serverinfo_entry ConfigServerInfo;
65 > struct config_admin_entry ConfigAdminInfo;
66 > struct conf_parser_context conf_parser_ctx;
67  
68   /* general conf items link list root, other than k lines etc. */
69 < dlink_list service_items = { NULL, NULL, 0 };
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 };
69 < dlink_list rxconf_items  = { NULL, NULL, 0 };
70 < dlink_list rkconf_items  = { NULL, NULL, 0 };
71 < dlink_list nresv_items   = { NULL, NULL, 0 };
72 < dlink_list class_items   = { NULL, NULL, 0 };
73 < dlink_list gdeny_items   = { NULL, NULL, 0 };
74 <
75 < dlink_list temporary_klines  = { NULL, NULL, 0 };
76 < dlink_list temporary_dlines  = { NULL, NULL, 0 };
77 < dlink_list temporary_xlines  = { NULL, NULL, 0 };
78 < dlink_list temporary_rklines = { NULL, NULL, 0 };
79 < dlink_list temporary_glines  = { NULL, NULL, 0 };
80 < dlink_list temporary_rxlines = { NULL, NULL, 0 };
81 < dlink_list temporary_resv = { NULL, NULL, 0 };
69 > dlink_list service_items;
70 > dlink_list server_items;
71 > dlink_list cluster_items;
72 > dlink_list oconf_items;
73 > dlink_list uconf_items;
74 > dlink_list xconf_items;
75 > dlink_list nresv_items;
76 > dlink_list cresv_items;
77  
78   extern unsigned int lineno;
79   extern char linebuf[];
80   extern char conffilebuf[IRCD_BUFSIZE];
86 extern char yytext[];
81   extern int yyparse(); /* defined in y.tab.c */
82  
89 struct conf_parser_context conf_parser_ctx = { 0, 0, NULL };
90
91 /* internally defined functions */
92 static void lookup_confhost(struct ConfItem *);
93 static void set_default_conf(void);
94 static void validate_conf(void);
95 static void read_conf(FBFILE *);
96 static void clear_out_old_conf(void);
97 static void flush_deleted_I_P(void);
98 static void expire_tklines(dlink_list *);
99 static void garbage_collect_ip_entries(void);
100 static int hash_ip(struct irc_ssaddr *);
101 static int verify_access(struct Client *, const char *);
102 static int attach_iline(struct Client *, struct ConfItem *);
103 static struct ip_entry *find_or_add_ip(struct irc_ssaddr *);
104 static void parse_conf_file(int, int);
105 static dlink_list *map_to_list(ConfType);
106 static struct AccessItem *find_regexp_kline(const char *[]);
107 static int find_user_host(struct Client *, char *, char *, char *, unsigned int);
108
109 /*
110 * bit_len
111 */
112 static int cidr_limit_reached(int, struct irc_ssaddr *, struct ClassItem *);
113 static void remove_from_cidr_check(struct irc_ssaddr *, struct ClassItem *);
114 static void destroy_cidr_class(struct ClassItem *);
115
116 static void flags_to_ascii(unsigned int, const unsigned int[], char *, int);
117
118 /* address of default class conf */
119 static struct ConfItem *class_default;
120
121 /* usually, with hash tables, you use a prime number...
122 * but in this case I am dealing with ip addresses,
123 * not ascii strings.
124 */
125 #define IP_HASH_SIZE 0x1000
126
127 struct ip_entry
128 {
129  struct irc_ssaddr ip;
130  int count;
131  time_t last_attempt;
132  struct ip_entry *next;
133 };
134
135 static struct ip_entry *ip_hash_table[IP_HASH_SIZE];
136 static BlockHeap *ip_entry_heap = NULL;
137 static int ip_entries_count = 0;
138
139
140 void *
141 map_to_conf(struct ConfItem *aconf)
142 {
143  void *conf;
144  conf = (void *)((uintptr_t)aconf +
145                  (uintptr_t)sizeof(struct ConfItem));
146  return(conf);
147 }
148
149 struct ConfItem *
150 unmap_conf_item(void *aconf)
151 {
152  struct ConfItem *conf;
153
154  conf = (struct ConfItem *)((uintptr_t)aconf -
155                             (uintptr_t)sizeof(struct ConfItem));
156  return(conf);
157 }
83  
84   /* conf_dns_callback()
85   *
86 < * inputs       - pointer to struct AccessItem
86 > * inputs       - pointer to struct MaskItem
87   *              - pointer to DNSReply reply
88   * output       - none
89   * side effects - called when resolver query finishes
# Line 167 | Line 92 | unmap_conf_item(void *aconf)
92   * if successful save hp in the conf item it was called with
93   */
94   static void
95 < conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name)
95 > conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name, size_t namelength)
96   {
97 <  struct AccessItem *aconf = vptr;
97 >  struct MaskItem *const conf = vptr;
98  
99 <  aconf->dns_pending = 0;
99 >  conf->dns_pending = 0;
100  
101 <  if (addr != NULL)
102 <    memcpy(&aconf->ipnum, addr, sizeof(aconf->ipnum));
101 >  if (addr)
102 >    memcpy(&conf->addr, addr, sizeof(conf->addr));
103    else
104 <    aconf->dns_failed = 1;
104 >    conf->dns_failed = 1;
105   }
106  
107   /* conf_dns_lookup()
# Line 186 | Line 111 | conf_dns_callback(void *vptr, const stru
111   * allocate a dns_query and start ns lookup.
112   */
113   static void
114 < conf_dns_lookup(struct AccessItem *aconf)
114 > conf_dns_lookup(struct MaskItem *conf)
115   {
116 <  if (!aconf->dns_pending)
117 <  {
118 <    aconf->dns_pending = 1;
119 <    gethost_byname(conf_dns_callback, aconf, aconf->host);
120 <  }
116 >  if (conf->dns_pending)
117 >    return;
118 >
119 >  conf->dns_pending = 1;
120 >
121 >  if (conf->aftype == AF_INET)
122 >    gethost_byname_type(conf_dns_callback, conf, conf->host, T_A);
123 >  else
124 >    gethost_byname_type(conf_dns_callback, conf, conf->host, T_AAAA);
125   }
126  
127 < /* make_conf_item()
127 > /* map_to_list()
128   *
129 < * inputs       - type of item
130 < * output       - pointer to new conf entry
131 < * side effects - none
129 > * inputs       - ConfType conf
130 > * output       - pointer to dlink_list to use
131 > * side effects - none
132   */
133 < struct ConfItem *
134 < make_conf_item(ConfType type)
133 > static dlink_list *
134 > map_to_list(enum maskitem_type type)
135   {
207  struct ConfItem *conf = NULL;
208  struct AccessItem *aconf = NULL;
209  struct ClassItem *aclass = NULL;
210  int status = 0;
211
136    switch (type)
137    {
138 <  case DLINE_TYPE:
139 <  case EXEMPTDLINE_TYPE:
216 <  case GLINE_TYPE:
217 <  case KLINE_TYPE:
218 <  case CLIENT_TYPE:
219 <  case OPER_TYPE:
220 <  case SERVER_TYPE:
221 <    conf = MyMalloc(sizeof(struct ConfItem) +
222 <                    sizeof(struct AccessItem));
223 <    aconf = map_to_conf(conf);
224 <    aconf->aftype = AF_INET;
225 <
226 <    /* Yes, sigh. switch on type again */
227 <    switch (type)
228 <    {
229 <    case EXEMPTDLINE_TYPE:
230 <      status = CONF_EXEMPTDLINE;
138 >    case CONF_XLINE:
139 >      return &xconf_items;
140        break;
141 <
142 <    case DLINE_TYPE:
234 <      status = CONF_DLINE;
141 >    case CONF_ULINE:
142 >      return &uconf_items;
143        break;
144 <
145 <    case KLINE_TYPE:
238 <      status = CONF_KLINE;
144 >    case CONF_NRESV:
145 >      return &nresv_items;
146        break;
147 <
148 <    case GLINE_TYPE:
242 <      status = CONF_GLINE;
147 >    case CONF_CRESV:
148 >      return &cresv_items;
149        break;
150 <
151 <    case CLIENT_TYPE:
246 <      status = CONF_CLIENT;
150 >    case CONF_OPER:
151 >      return &oconf_items;
152        break;
153 <
154 <    case OPER_TYPE:
250 <      status = CONF_OPERATOR;
251 <      dlinkAdd(conf, &conf->node, &oconf_items);
153 >    case CONF_SERVER:
154 >      return &server_items;
155        break;
156 <
157 <    case SERVER_TYPE:
255 <      status = CONF_SERVER;
256 <      dlinkAdd(conf, &conf->node, &server_items);
156 >    case CONF_SERVICE:
157 >      return &service_items;
158        break;
159 <
160 <    default:
159 >    case CONF_CLUSTER:
160 >      return &cluster_items;
161        break;
261    }
262    aconf->status = status;
263    break;
264
265  case LEAF_TYPE:
266    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
267                                       sizeof(struct MatchItem));
268    dlinkAdd(conf, &conf->node, &leaf_items);
269    break;
270
271  case HUB_TYPE:
272    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
273                                       sizeof(struct MatchItem));
274    dlinkAdd(conf, &conf->node, &hub_items);
275    break;
276
277  case ULINE_TYPE:
278    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
279                                       sizeof(struct MatchItem));
280    dlinkAdd(conf, &conf->node, &uconf_items);
281    break;
282
283  case GDENY_TYPE:
284    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
285                                       sizeof(struct AccessItem));
286    dlinkAdd(conf, &conf->node, &gdeny_items);
287    break;
288
289  case XLINE_TYPE:
290    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
291                                       sizeof(struct MatchItem));
292    dlinkAdd(conf, &conf->node, &xconf_items);
293    break;
294 #ifdef HAVE_LIBPCRE
295  case RXLINE_TYPE:
296    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
297                                       sizeof(struct MatchItem));
298    dlinkAdd(conf, &conf->node, &rxconf_items);
299    break;
300
301  case RKLINE_TYPE:
302    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
303                                       sizeof(struct AccessItem));
304    aconf = map_to_conf(conf);
305    aconf->status = CONF_KLINE;
306    dlinkAdd(conf, &conf->node, &rkconf_items);
307    break;
308 #endif
309  case CLUSTER_TYPE:
310    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem));
311    dlinkAdd(conf, &conf->node, &cluster_items);
312    break;
313
314  case CRESV_TYPE:
315    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
316                                       sizeof(struct ResvChannel));
317    break;
318
319  case NRESV_TYPE:
320    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
321                                       sizeof(struct MatchItem));
322    dlinkAdd(conf, &conf->node, &nresv_items);
323    break;
324
325  case SERVICE_TYPE:
326    status = CONF_SERVICE;
327    conf = MyMalloc(sizeof(struct ConfItem));
328    dlinkAdd(conf, &conf->node, &service_items);
329    break;
330
331  case CLASS_TYPE:
332    conf = MyMalloc(sizeof(struct ConfItem) +
333                           sizeof(struct ClassItem));
334    dlinkAdd(conf, &conf->node, &class_items);
335
336    aclass = map_to_conf(conf);
337    aclass->active = 1;
338    ConFreq(aclass) = DEFAULT_CONNECTFREQUENCY;
339    PingFreq(aclass) = DEFAULT_PINGFREQUENCY;
340    MaxTotal(aclass) = MAXIMUM_LINKS_DEFAULT;
341    MaxSendq(aclass) = DEFAULT_SENDQ;
342
343    break;
344
345  default:
346    conf = NULL;
347    break;
348  }
349
350  /* XXX Yes, this will core if default is hit. I want it to for now - db */
351  conf->type = type;
352
353  return conf;
354 }
355
356 void
357 delete_conf_item(struct ConfItem *conf)
358 {
359  dlink_node *m = NULL;
360  struct MatchItem *match_item;
361  struct AccessItem *aconf;
362  ConfType type = conf->type;
363
364  MyFree(conf->name);
365  conf->name = NULL;
366
367  switch(type)
368  {
369  case DLINE_TYPE:
370  case EXEMPTDLINE_TYPE:
371  case GLINE_TYPE:
372  case KLINE_TYPE:
373  case CLIENT_TYPE:
374  case OPER_TYPE:
375  case SERVER_TYPE:
376    aconf = map_to_conf(conf);
377
378    if (aconf->dns_pending)
379      delete_resolver_queries(aconf);
380    if (aconf->passwd != NULL)
381      memset(aconf->passwd, 0, strlen(aconf->passwd));
382    if (aconf->spasswd != NULL)
383      memset(aconf->spasswd, 0, strlen(aconf->spasswd));
384    aconf->class_ptr = NULL;
385
386    MyFree(aconf->passwd);
387    MyFree(aconf->spasswd);
388    MyFree(aconf->reason);
389    MyFree(aconf->oper_reason);
390    MyFree(aconf->user);
391    MyFree(aconf->host);
392 #ifdef HAVE_LIBCRYPTO
393    if (aconf->rsa_public_key)
394      RSA_free(aconf->rsa_public_key);
395    MyFree(aconf->rsa_public_key_file);
396 #endif
397
398    /* Yes, sigh. switch on type again */
399    switch(type)
400    {
401    case EXEMPTDLINE_TYPE:
402    case DLINE_TYPE:
403    case GLINE_TYPE:
404    case KLINE_TYPE:
405    case CLIENT_TYPE:
406      MyFree(conf);
407      break;
408
409    case OPER_TYPE:
410      aconf = map_to_conf(conf);
411      if (!IsConfIllegal(aconf))
412        dlinkDelete(&conf->node, &oconf_items);
413      MyFree(conf);
414      break;
415
416    case SERVER_TYPE:
417      aconf = map_to_conf(conf);
418      if (!IsConfIllegal(aconf))
419        dlinkDelete(&conf->node, &server_items);
420      MyFree(conf);
421      break;
422
162      default:
163 <      break;
425 <    }
426 <    break;
427 <
428 <  case HUB_TYPE:
429 <    match_item = map_to_conf(conf);
430 <    MyFree(match_item->user);
431 <    MyFree(match_item->host);
432 <    MyFree(match_item->reason);
433 <    MyFree(match_item->oper_reason);
434 <    /* If marked illegal, its already been pulled off of the hub_items list */
435 <    if (!match_item->illegal)
436 <      dlinkDelete(&conf->node, &hub_items);
437 <    MyFree(conf);
438 <    break;
439 <
440 <  case LEAF_TYPE:
441 <    match_item = map_to_conf(conf);
442 <    MyFree(match_item->user);
443 <    MyFree(match_item->host);
444 <    MyFree(match_item->reason);
445 <    MyFree(match_item->oper_reason);
446 <    /* If marked illegal, its already been pulled off of the leaf_items list */
447 <    if (!match_item->illegal)
448 <      dlinkDelete(&conf->node, &leaf_items);
449 <    MyFree(conf);
450 <    break;
451 <
452 <  case ULINE_TYPE:
453 <    match_item = map_to_conf(conf);
454 <    MyFree(match_item->user);
455 <    MyFree(match_item->host);
456 <    MyFree(match_item->reason);
457 <    MyFree(match_item->oper_reason);
458 <    dlinkDelete(&conf->node, &uconf_items);
459 <    MyFree(conf);
460 <    break;
461 <
462 <  case XLINE_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, &xconf_items);
469 <    MyFree(conf);
470 <    break;
471 < #ifdef HAVE_LIBPCRE
472 <  case RKLINE_TYPE:
473 <    aconf = map_to_conf(conf);
474 <    MyFree(aconf->regexuser);
475 <    MyFree(aconf->regexhost);
476 <    MyFree(aconf->user);
477 <    MyFree(aconf->host);
478 <    MyFree(aconf->reason);
479 <    MyFree(aconf->oper_reason);
480 <    dlinkDelete(&conf->node, &rkconf_items);
481 <    MyFree(conf);
482 <    break;
483 <
484 <  case RXLINE_TYPE:
485 <    MyFree(conf->regexpname);
486 <    match_item = map_to_conf(conf);
487 <    MyFree(match_item->user);
488 <    MyFree(match_item->host);
489 <    MyFree(match_item->reason);
490 <    MyFree(match_item->oper_reason);
491 <    dlinkDelete(&conf->node, &rxconf_items);
492 <    MyFree(conf);
493 <    break;
494 < #endif
495 <  case NRESV_TYPE:
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, &nresv_items);
502 <
503 <    if (conf->flags & CONF_FLAGS_TEMPORARY)
504 <      if ((m = dlinkFindDelete(&temporary_resv, conf)) != NULL)
505 <        free_dlink_node(m);
506 <
507 <    MyFree(conf);
508 <    break;
509 <
510 <  case GDENY_TYPE:
511 <    aconf = map_to_conf(conf);
512 <    MyFree(aconf->user);
513 <    MyFree(aconf->host);
514 <    dlinkDelete(&conf->node, &gdeny_items);
515 <    MyFree(conf);
516 <    break;
517 <
518 <  case CLUSTER_TYPE:
519 <    dlinkDelete(&conf->node, &cluster_items);
520 <    MyFree(conf);
521 <    break;
522 <
523 <  case CRESV_TYPE:
524 <    if (conf->flags & CONF_FLAGS_TEMPORARY)
525 <      if ((m = dlinkFindDelete(&temporary_resv, conf)) != NULL)
526 <        free_dlink_node(m);
527 <
528 <    MyFree(conf);
529 <    break;
530 <
531 <  case CLASS_TYPE:
532 <    dlinkDelete(&conf->node, &class_items);
533 <    MyFree(conf);
534 <    break;
535 <
536 <  case SERVICE_TYPE:
537 <    dlinkDelete(&conf->node, &service_items);
538 <    MyFree(conf);
539 <    break;
540 <
541 <  default:
542 <    break;
163 >      return NULL;
164    }
165   }
166  
167 < /* free_access_item()
168 < *
548 < * inputs       - pointer to conf to free
549 < * output       - none
550 < * side effects - crucial password fields are zeroed, conf is freed
551 < */
552 < void
553 < free_access_item(struct AccessItem *aconf)
167 > struct MaskItem *
168 > conf_make(enum maskitem_type type)
169   {
170 <  struct ConfItem *conf;
170 >  struct MaskItem *const conf = MyCalloc(sizeof(*conf));
171 >  dlink_list *list = NULL;
172  
173 <  if (aconf == NULL)
174 <    return;
175 <  conf = unmap_conf_item(aconf);
560 <  delete_conf_item(conf);
561 < }
173 >  conf->type   = type;
174 >  conf->active = 1;
175 >  conf->aftype = AF_INET;
176  
177 < static const unsigned int shared_bit_table[] =
178 <  { 'K', 'k', 'U', 'X', 'x', 'Y', 'Q', 'q', 'R', 'L', 0};
177 >  if ((list = map_to_list(type)))
178 >    dlinkAdd(conf, &conf->node, list);
179 >  return conf;
180 > }
181  
566 /* report_confitem_types()
567 *
568 * inputs       - pointer to client requesting confitem report
569 *              - ConfType to report
570 * output       - none
571 * side effects -
572 */
182   void
183 < report_confitem_types(struct Client *source_p, ConfType type, int temp)
183 > conf_free(struct MaskItem *conf)
184   {
185 <  dlink_node *ptr = NULL;
186 <  struct ConfItem *conf = NULL;
578 <  struct AccessItem *aconf = NULL;
579 <  struct MatchItem *matchitem = NULL;
580 <  struct ClassItem *classitem = NULL;
581 <  char buf[12];
582 <  char *p = NULL;
583 <  const char *pfx = NULL;
584 <
585 <  switch (type)
586 <  {
587 <  case GDENY_TYPE:
588 <    DLINK_FOREACH(ptr, gdeny_items.head)
589 <    {
590 <      conf = ptr->data;
591 <      aconf = map_to_conf(conf);
592 <
593 <      p = buf;
594 <
595 <      if (aconf->flags & GDENY_BLOCK)
596 <        *p++ = 'B';
597 <      else
598 <        *p++ = 'b';
599 <
600 <      if (aconf->flags & GDENY_REJECT)
601 <        *p++ = 'R';
602 <      else
603 <        *p++ = 'r';
604 <
605 <      *p = '\0';
606 <
607 <      sendto_one(source_p, ":%s %d %s V %s@%s %s %s",
608 <                 me.name, RPL_STATSDEBUG, source_p->name,
609 <                 aconf->user, aconf->host, conf->name, buf);
610 <    }
611 <    break;
612 <
613 <  case XLINE_TYPE:
614 <    DLINK_FOREACH(ptr, xconf_items.head)
615 <    {
616 <      conf = ptr->data;
617 <      matchitem = map_to_conf(conf);
618 <
619 <      sendto_one(source_p, form_str(RPL_STATSXLINE),
620 <                 me.name, source_p->name,
621 <                 matchitem->hold ? "x": "X", matchitem->count,
622 <                 conf->name, matchitem->reason);
623 <    }
624 <    break;
625 <
626 < #ifdef HAVE_LIBPCRE
627 <  case RXLINE_TYPE:
628 <    DLINK_FOREACH(ptr, rxconf_items.head)
629 <    {
630 <      conf = ptr->data;
631 <      matchitem = map_to_conf(conf);
632 <
633 <      sendto_one(source_p, form_str(RPL_STATSXLINE),
634 <                 me.name, source_p->name,
635 <                 matchitem->hold ? "xR": "XR", matchitem->count,
636 <                 conf->name, matchitem->reason);
637 <    }
638 <    break;
185 >  dlink_node *node = NULL, *node_next = NULL;
186 >  dlink_list *list = NULL;
187  
188 <  case RKLINE_TYPE:
189 <    pfx = temp ? "kR" : "KR";
188 >  if ((list = map_to_list(conf->type)))
189 >    dlinkFindDelete(list, conf);
190  
191 <    DLINK_FOREACH(ptr, rkconf_items.head)
644 <    {
645 <      aconf = map_to_conf((conf = ptr->data));
191 >  MyFree(conf->name);
192  
193 <      if (temp && !(conf->flags & CONF_FLAGS_TEMPORARY))
194 <        continue;
193 >  if (conf->dns_pending)
194 >    delete_resolver_queries(conf);
195 >  if (conf->passwd)
196 >    memset(conf->passwd, 0, strlen(conf->passwd));
197 >  if (conf->spasswd)
198 >    memset(conf->spasswd, 0, strlen(conf->spasswd));
199 >
200 >  conf->class = NULL;
201 >
202 >  MyFree(conf->passwd);
203 >  MyFree(conf->spasswd);
204 >  MyFree(conf->reason);
205 >  MyFree(conf->certfp);
206 >  MyFree(conf->whois);
207 >  MyFree(conf->user);
208 >  MyFree(conf->host);
209 > #ifdef HAVE_LIBCRYPTO
210 >  MyFree(conf->cipher_list);
211  
212 <      sendto_one(source_p, form_str(RPL_STATSKLINE), me.name,
213 <                 source_p->name, pfx, aconf->host, aconf->user,
652 <                 aconf->reason, aconf->oper_reason ? aconf->oper_reason : "");
653 <    }
654 <    break;
212 >  if (conf->rsa_public_key)
213 >    RSA_free(conf->rsa_public_key);
214   #endif
215 <
657 <  case ULINE_TYPE:
658 <    DLINK_FOREACH(ptr, uconf_items.head)
659 <    {
660 <      conf = ptr->data;
661 <      matchitem = map_to_conf(conf);
662 <
663 <      p = buf;
664 <
665 <      /* some of these are redundant for the sake of
666 <       * consistency with cluster{} flags
667 <       */
668 <      *p++ = 'c';
669 <      flags_to_ascii(matchitem->action, shared_bit_table, p, 0);
670 <
671 <      sendto_one(source_p, form_str(RPL_STATSULINE),
672 <                 me.name, source_p->name, conf->name,
673 <                 matchitem->user?matchitem->user: "*",
674 <                 matchitem->host?matchitem->host: "*", buf);
675 <    }
676 <
677 <    DLINK_FOREACH(ptr, cluster_items.head)
678 <    {
679 <      conf = ptr->data;
680 <
681 <      p = buf;
682 <
683 <      *p++ = 'C';
684 <      flags_to_ascii(conf->flags, shared_bit_table, p, 0);
685 <
686 <      sendto_one(source_p, form_str(RPL_STATSULINE),
687 <                 me.name, source_p->name, conf->name,
688 <                 "*", "*", buf);
689 <    }
690 <
691 <    break;
692 <
693 <  case OPER_TYPE:
694 <    DLINK_FOREACH(ptr, oconf_items.head)
695 <    {
696 <      conf = ptr->data;
697 <      aconf = map_to_conf(conf);
698 <
699 <      /* Don't allow non opers to see oper privs */
700 <      if (IsOper(source_p))
701 <        sendto_one(source_p, form_str(RPL_STATSOLINE),
702 <                   me.name, source_p->name, 'O', aconf->user, aconf->host,
703 <                   conf->name, oper_privs_as_string(aconf->port),
704 <                   aconf->class_ptr ? aconf->class_ptr->name : "<default>");
705 <      else
706 <        sendto_one(source_p, form_str(RPL_STATSOLINE),
707 <                   me.name, source_p->name, 'O', aconf->user, aconf->host,
708 <                   conf->name, "0",
709 <                   aconf->class_ptr ? aconf->class_ptr->name : "<default>");
710 <    }
711 <    break;
712 <
713 <  case CLASS_TYPE:
714 <    DLINK_FOREACH(ptr, class_items.head)
715 <    {
716 <      conf = ptr->data;
717 <      classitem = map_to_conf(conf);
718 <      sendto_one(source_p, form_str(RPL_STATSYLINE),
719 <                 me.name, source_p->name, 'Y',
720 <                 conf->name, PingFreq(classitem),
721 <                 ConFreq(classitem),
722 <                 MaxTotal(classitem), MaxSendq(classitem),
723 <                 CurrUserCount(classitem),
724 <                 classitem->active ? "active" : "disabled");
725 <    }
726 <    break;
727 <
728 <  case CONF_TYPE:
729 <  case CLIENT_TYPE:
730 <    break;
731 <
732 <  case SERVICE_TYPE: /* XXX TBD */
733 <    DLINK_FOREACH(ptr, service_items.head)
734 <    {
735 <      conf = ptr->data;
736 <    }
737 <    break;
738 <
739 <  case SERVER_TYPE:
740 <    DLINK_FOREACH(ptr, server_items.head)
741 <    {
742 <      p = buf;
743 <
744 <      conf = ptr->data;
745 <      aconf = map_to_conf(conf);
746 <
747 <      buf[0] = '\0';
748 <
749 <      if (IsConfAllowAutoConn(aconf))
750 <        *p++ = 'A';
751 <      if (IsConfCryptLink(aconf))
752 <        *p++ = 'C';
753 <      if (IsConfTopicBurst(aconf))
754 <        *p++ = 'T';
755 <      if (IsConfCompressed(aconf))
756 <        *p++ = 'Z';
757 <      if (buf[0] == '\0')
758 <        *p++ = '*';
759 <
760 <      *p = '\0';
761 <
762 <      /*
763 <       * Allow admins to see actual ips unless hide_server_ips is enabled
764 <       */
765 <      if (!ConfigServerHide.hide_server_ips && IsAdmin(source_p))
766 <        sendto_one(source_p, form_str(RPL_STATSCLINE),
767 <                   me.name, source_p->name, 'C', aconf->host,
768 <                   buf, conf->name, aconf->port,
769 <                   aconf->class_ptr ? aconf->class_ptr->name : "<default>");
770 <        else
771 <          sendto_one(source_p, form_str(RPL_STATSCLINE),
772 <                     me.name, source_p->name, 'C',
773 <                     "*@127.0.0.1", buf, conf->name, aconf->port,
774 <                     aconf->class_ptr ? aconf->class_ptr->name : "<default>");
775 <    }
776 <    break;
777 <
778 <  case HUB_TYPE:
779 <    DLINK_FOREACH(ptr, hub_items.head)
780 <    {
781 <      conf = ptr->data;
782 <      matchitem = map_to_conf(conf);
783 <      sendto_one(source_p, form_str(RPL_STATSHLINE), me.name,
784 <                 source_p->name, 'H', matchitem->host, conf->name, 0, "*");
785 <    }
786 <    break;
787 <
788 <  case LEAF_TYPE:
789 <    DLINK_FOREACH(ptr, leaf_items.head)
790 <    {
791 <      conf = ptr->data;
792 <      matchitem = map_to_conf(conf);
793 <      sendto_one(source_p, form_str(RPL_STATSLLINE), me.name,
794 <                 source_p->name, 'L', matchitem->host, conf->name, 0, "*");
795 <    }
796 <    break;
797 <
798 <  case GLINE_TYPE:
799 <  case KLINE_TYPE:
800 <  case DLINE_TYPE:
801 <  case EXEMPTDLINE_TYPE:
802 <  case CRESV_TYPE:
803 <  case NRESV_TYPE:
804 <  case CLUSTER_TYPE:
805 <  default:
806 <    break;
807 <  }
808 < }
809 <
810 < /* check_client()
811 < *
812 < * inputs       - pointer to client
813 < * output       - 0 = Success
814 < *                NOT_AUTHORIZED    (-1) = Access denied (no I line match)
815 < *                IRCD_SOCKET_ERROR (-2) = Bad socket.
816 < *                I_LINE_FULL       (-3) = I-line is full
817 < *                TOO_MANY          (-4) = Too many connections from hostname
818 < *                BANNED_CLIENT     (-5) = K-lined
819 < * side effects - Ordinary client access check.
820 < *                Look for conf lines which have the same
821 < *                status as the flags passed.
822 < */
823 < static void *
824 < check_client(va_list args)
825 < {
826 <  struct Client *source_p = va_arg(args, struct Client *);
827 <  const char *username = va_arg(args, const char *);
828 <  int i;
829 <
830 <  /* I'm already in big trouble if source_p->localClient is NULL -db */
831 <  if ((i = verify_access(source_p, username)))
832 <    ilog(L_INFO, "Access denied: %s[%s]",
833 <         source_p->name, source_p->sockhost);
834 <
835 <  switch (i)
215 >  DLINK_FOREACH_SAFE(node, node_next, conf->hub_list.head)
216    {
217 <    case TOO_MANY:
218 <      sendto_realops_flags(UMODE_FULL, L_ALL,
219 <                           "Too many on IP for %s (%s).",
840 <                           get_client_name(source_p, SHOW_IP),
841 <                           source_p->sockhost);
842 <      ilog(L_INFO,"Too many connections on IP from %s.",
843 <           get_client_name(source_p, SHOW_IP));
844 <      ++ServerStats.is_ref;
845 <      exit_client(source_p, &me, "No more connections allowed on that IP");
846 <      break;
847 <
848 <    case I_LINE_FULL:
849 <      sendto_realops_flags(UMODE_FULL, L_ALL,
850 <                           "I-line is full for %s (%s).",
851 <                           get_client_name(source_p, SHOW_IP),
852 <                           source_p->sockhost);
853 <      ilog(L_INFO,"Too many connections from %s.",
854 <           get_client_name(source_p, SHOW_IP));
855 <      ++ServerStats.is_ref;
856 <      exit_client(source_p, &me,
857 <                "No more connections allowed in your connection class");
858 <      break;
859 <
860 <    case NOT_AUTHORIZED:
861 <      ++ServerStats.is_ref;
862 <      /* jdc - lists server name & port connections are on */
863 <      /*       a purely cosmetical change */
864 <      sendto_realops_flags(UMODE_UNAUTH, L_ALL,
865 <                           "Unauthorized client connection from %s [%s] on [%s/%u].",
866 <                           get_client_name(source_p, SHOW_IP),
867 <                           source_p->sockhost,
868 <                           source_p->localClient->listener->name,
869 <                           source_p->localClient->listener->port);
870 <      ilog(L_INFO,
871 <          "Unauthorized client connection from %s on [%s/%u].",
872 <          get_client_name(source_p, SHOW_IP),
873 <          source_p->localClient->listener->name,
874 <          source_p->localClient->listener->port);
875 <
876 <      /* XXX It is prolematical whether it is better to use the
877 <       * capture reject code here or rely on the connecting too fast code.
878 <       * - Dianora
879 <       */
880 <      if (REJECT_HOLD_TIME > 0)
881 <      {
882 <        sendto_one(source_p, ":%s NOTICE %s :You are not authorized to use this server",
883 <                   me.name, source_p->name);
884 <        source_p->localClient->reject_delay = CurrentTime + REJECT_HOLD_TIME;
885 <        SetCaptured(source_p);
886 <      }
887 <      else
888 <        exit_client(source_p, &me, "You are not authorized to use this server");
889 <      break;
890 <
891 <   case BANNED_CLIENT:
892 <     /*
893 <      * Don't exit them immediately, play with them a bit.
894 <      * - Dianora
895 <      */
896 <     if (REJECT_HOLD_TIME > 0)
897 <     {
898 <       source_p->localClient->reject_delay = CurrentTime + REJECT_HOLD_TIME;
899 <       SetCaptured(source_p);
900 <     }
901 <     else
902 <       exit_client(source_p, &me, "Banned");
903 <     ++ServerStats.is_ref;
904 <     break;
905 <
906 <   case 0:
907 <   default:
908 <     break;
217 >    MyFree(node->data);
218 >    dlinkDelete(node, &conf->hub_list);
219 >    free_dlink_node(node);
220    }
221  
222 <  return (i < 0 ? NULL : source_p);
912 < }
913 <
914 < /* verify_access()
915 < *
916 < * inputs       - pointer to client to verify
917 < *              - pointer to proposed username
918 < * output       - 0 if success -'ve if not
919 < * side effect  - find the first (best) I line to attach.
920 < */
921 < static int
922 < verify_access(struct Client *client_p, const char *username)
923 < {
924 <  struct AccessItem *aconf = NULL, *rkconf = NULL;
925 <  struct ConfItem *conf = NULL;
926 <  char non_ident[USERLEN + 1] = { '~', '\0' };
927 <  const char *uhi[3];
928 <
929 <  if (IsGotId(client_p))
930 <  {
931 <    aconf = find_address_conf(client_p->host, client_p->username,
932 <                             &client_p->localClient->ip,
933 <                             client_p->localClient->aftype,
934 <                             client_p->localClient->passwd);
935 <  }
936 <  else
222 >  DLINK_FOREACH_SAFE(node, node_next, conf->leaf_list.head)
223    {
224 <    strlcpy(non_ident+1, username, sizeof(non_ident)-1);
225 <    aconf = find_address_conf(client_p->host,non_ident,
226 <                             &client_p->localClient->ip,
941 <                             client_p->localClient->aftype,
942 <                             client_p->localClient->passwd);
224 >    MyFree(node->data);
225 >    dlinkDelete(node, &conf->leaf_list);
226 >    free_dlink_node(node);
227    }
228  
229 <  uhi[0] = IsGotId(client_p) ? client_p->username : non_ident;
946 <  uhi[1] = client_p->host;
947 <  uhi[2] = client_p->sockhost;
948 <
949 <  rkconf = find_regexp_kline(uhi);
950 <
951 <  if (aconf != NULL)
229 >  DLINK_FOREACH_SAFE(node, node_next, conf->exempt_list.head)
230    {
231 <    if (IsConfClient(aconf) && !rkconf)
954 <    {
955 <      conf = unmap_conf_item(aconf);
956 <
957 <      if (IsConfRedir(aconf))
958 <      {
959 <        sendto_one(client_p, form_str(RPL_REDIR),
960 <                   me.name, client_p->name,
961 <                   conf->name ? conf->name : "",
962 <                   aconf->port);
963 <        return(NOT_AUTHORIZED);
964 <      }
965 <
966 <      if (IsConfDoIdentd(aconf))
967 <        SetNeedId(client_p);
231 >    struct exempt *exptr = node->data;
232  
233 <      /* Thanks for spoof idea amm */
234 <      if (IsConfDoSpoofIp(aconf))
235 <      {
236 <        conf = unmap_conf_item(aconf);
237 <
974 <        if (!ConfigFileEntry.hide_spoof_ips && IsConfSpoofNotice(aconf))
975 <          sendto_realops_flags(UMODE_ALL, L_ADMIN, "%s spoofing: %s as %s",
976 <                               client_p->name, client_p->host, conf->name);
977 <        strlcpy(client_p->host, conf->name, sizeof(client_p->host));
978 <        SetIPSpoof(client_p);
979 <      }
980 <
981 <      return(attach_iline(client_p, conf));
982 <    }
983 <    else if (rkconf || IsConfKill(aconf) || (ConfigFileEntry.glines && IsConfGline(aconf)))
984 <    {
985 <      /* XXX */
986 <      aconf = rkconf ? rkconf : aconf;
987 <      if (IsConfGline(aconf))
988 <        sendto_one(client_p, ":%s NOTICE %s :*** G-lined", me.name,
989 <                   client_p->name);
990 <      if (ConfigFileEntry.kline_with_reason)
991 <        sendto_one(client_p, ":%s NOTICE %s :*** Banned %s",
992 <                  me.name, client_p->name, aconf->reason);
993 <      return(BANNED_CLIENT);
994 <    }
233 >    dlinkDelete(node, &conf->exempt_list);
234 >    MyFree(exptr->name);
235 >    MyFree(exptr->user);
236 >    MyFree(exptr->host);
237 >    MyFree(exptr);
238    }
239  
240 <  return(NOT_AUTHORIZED);
240 >  MyFree(conf);
241   }
242  
243   /* attach_iline()
244   *
245 < * inputs       - client pointer
246 < *              - conf pointer
247 < * output       -
248 < * side effects - do actual attach
245 > * inputs       - client pointer
246 > *              - conf pointer
247 > * output       -
248 > * side effects - do actual attach
249   */
250   static int
251 < attach_iline(struct Client *client_p, struct ConfItem *conf)
251 > attach_iline(struct Client *client_p, struct MaskItem *conf)
252   {
253 <  struct AccessItem *aconf;
1011 <  struct ClassItem *aclass;
253 >  const struct ClassItem *const class = conf->class;
254    struct ip_entry *ip_found;
255    int a_limit_reached = 0;
256 <  int local = 0, global = 0, ident = 0;
256 >  unsigned int local = 0, global = 0, ident = 0;
257  
258 <  ip_found = find_or_add_ip(&client_p->localClient->ip);
258 >  ip_found = ipcache_find_or_add_address(&client_p->connection->ip);
259    ip_found->count++;
260 <  SetIpHash(client_p);
1019 <
1020 <  aconf = map_to_conf(conf);
1021 <  if (aconf->class_ptr == NULL)
1022 <    return NOT_AUTHORIZED;  /* If class is missing, this is best */
1023 <
1024 <  aclass = map_to_conf(aconf->class_ptr);
260 >  AddFlag(client_p, FLAGS_IPHASH);
261  
262    count_user_host(client_p->username, client_p->host,
263                    &global, &local, &ident);
# Line 1030 | Line 266 | attach_iline(struct Client *client_p, st
266     * setting a_limit_reached if any limit is reached.
267     * - Dianora
268     */
269 <  if (MaxTotal(aclass) != 0 && CurrUserCount(aclass) >= MaxTotal(aclass))
269 >  if (class->max_total && class->ref_count >= class->max_total)
270      a_limit_reached = 1;
271 <  else if (MaxPerIp(aclass) != 0 && ip_found->count > MaxPerIp(aclass))
271 >  else if (class->max_perip && ip_found->count > class->max_perip)
272      a_limit_reached = 1;
273 <  else if (MaxLocal(aclass) != 0 && local >= MaxLocal(aclass))
273 >  else if (class->max_local && local >= class->max_local)
274      a_limit_reached = 1;
275 <  else if (MaxGlobal(aclass) != 0 && global >= MaxGlobal(aclass))
275 >  else if (class->max_global && global >= class->max_global)
276      a_limit_reached = 1;
277 <  else if (MaxIdent(aclass) != 0 && ident >= MaxIdent(aclass) &&
277 >  else if (class->max_ident && ident >= class->max_ident &&
278             client_p->username[0] != '~')
279      a_limit_reached = 1;
280  
281    if (a_limit_reached)
282    {
283 <    if (!IsConfExemptLimits(aconf))
283 >    if (!IsConfExemptLimits(conf))
284        return TOO_MANY;   /* Already at maximum allowed */
285  
286 <    sendto_one(client_p,
287 <               ":%s NOTICE %s :*** Your connection class is full, "
1052 <               "but you have exceed_limit = yes;", me.name, client_p->name);
286 >    sendto_one_notice(client_p, &me, ":*** Your connection class is full, "
287 >                      "but you have exceed_limit = yes;");
288    }
289  
290    return attach_conf(client_p, conf);
291   }
292  
293 < /* init_ip_hash_table()
1059 < *
1060 < * inputs               - NONE
1061 < * output               - NONE
1062 < * side effects         - allocate memory for ip_entry(s)
1063 < *                      - clear the ip hash table
1064 < */
1065 < void
1066 < init_ip_hash_table(void)
1067 < {
1068 <  ip_entry_heap = BlockHeapCreate("ip", sizeof(struct ip_entry),
1069 <    2 * hard_fdlimit);
1070 <  memset(ip_hash_table, 0, sizeof(ip_hash_table));
1071 < }
1072 <
1073 < /* find_or_add_ip()
1074 < *
1075 < * inputs       - pointer to struct irc_ssaddr
1076 < * output       - pointer to a struct ip_entry
1077 < * side effects -
293 > /* verify_access()
294   *
295 < * If the ip # was not found, a new struct ip_entry is created, and the ip
296 < * count set to 0.
295 > * inputs       - pointer to client to verify
296 > * output       - 0 if success -'ve if not
297 > * side effect  - find the first (best) I line to attach.
298   */
299 < static struct ip_entry *
300 < find_or_add_ip(struct irc_ssaddr *ip_in)
299 > static int
300 > verify_access(struct Client *client_p)
301   {
302 <  struct ip_entry *ptr, *newptr;
1086 <  int hash_index = hash_ip(ip_in), res;
1087 <  struct sockaddr_in *v4 = (struct sockaddr_in *)ip_in, *ptr_v4;
1088 < #ifdef IPV6
1089 <  struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)ip_in, *ptr_v6;
1090 < #endif
302 >  struct MaskItem *conf = NULL;
303  
304 <  for (ptr = ip_hash_table[hash_index]; ptr; ptr = ptr->next)
304 >  if (IsGotId(client_p))
305    {
306 < #ifdef IPV6
307 <    if (ptr->ip.ss.ss_family != ip_in->ss.ss_family)
308 <      continue;
309 <    if (ip_in->ss.ss_family == AF_INET6)
1098 <    {
1099 <      ptr_v6 = (struct sockaddr_in6 *)&ptr->ip;
1100 <      res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr));
1101 <    }
1102 <    else
1103 < #endif
1104 <    {
1105 <      ptr_v4 = (struct sockaddr_in *)&ptr->ip;
1106 <      res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr));
1107 <    }
1108 <    if (res == 0)
1109 <    {
1110 <      /* Found entry already in hash, return it. */
1111 <      return ptr;
1112 <    }
306 >    conf = find_address_conf(client_p->host, client_p->username,
307 >                             &client_p->connection->ip,
308 >                             client_p->connection->aftype,
309 >                             client_p->connection->password);
310    }
311 +  else
312 +  {
313 +    char non_ident[USERLEN + 1] = "~";
314  
315 <  if (ip_entries_count >= 2 * hard_fdlimit)
316 <    garbage_collect_ip_entries();
317 <
318 <  newptr = BlockHeapAlloc(ip_entry_heap);
319 <  ip_entries_count++;
320 <  memcpy(&newptr->ip, ip_in, sizeof(struct irc_ssaddr));
315 >    strlcpy(non_ident + 1, client_p->username, sizeof(non_ident) - 1);
316 >    conf = find_address_conf(client_p->host, non_ident,
317 >                             &client_p->connection->ip,
318 >                             client_p->connection->aftype,
319 >                             client_p->connection->password);
320 >  }
321  
322 <  newptr->next = ip_hash_table[hash_index];
323 <  ip_hash_table[hash_index] = newptr;
322 >  if (conf)
323 >  {
324 >    if (IsConfClient(conf))
325 >    {
326 >      if (IsConfRedir(conf))
327 >      {
328 >        sendto_one_numeric(client_p, &me, RPL_REDIR,
329 >                           conf->name ? conf->name : "",
330 >                           conf->port);
331 >        return NOT_AUTHORIZED;
332 >      }
333  
334 <  return newptr;
335 < }
334 >      /* Thanks for spoof idea amm */
335 >      if (IsConfDoSpoofIp(conf))
336 >      {
337 >        if (IsConfSpoofNotice(conf))
338 >          sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, "%s spoofing: %s as %s",
339 >                               client_p->name, client_p->host, conf->name);
340  
341 < /* remove_one_ip()
342 < *
1130 < * inputs        - unsigned long IP address value
1131 < * output        - NONE
1132 < * side effects  - The ip address given, is looked up in ip hash table
1133 < *                 and number of ip#'s for that ip decremented.
1134 < *                 If ip # count reaches 0 and has expired,
1135 < *                 the struct ip_entry is returned to the ip_entry_heap
1136 < */
1137 < void
1138 < remove_one_ip(struct irc_ssaddr *ip_in)
1139 < {
1140 <  struct ip_entry *ptr;
1141 <  struct ip_entry *last_ptr = NULL;
1142 <  int hash_index = hash_ip(ip_in), res;
1143 <  struct sockaddr_in *v4 = (struct sockaddr_in *)ip_in, *ptr_v4;
1144 < #ifdef IPV6
1145 <  struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)ip_in, *ptr_v6;
1146 < #endif
341 >        strlcpy(client_p->host, conf->name, sizeof(client_p->host));
342 >      }
343  
344 <  for (ptr = ip_hash_table[hash_index]; ptr; ptr = ptr->next)
1149 <  {
1150 < #ifdef IPV6
1151 <    if (ptr->ip.ss.ss_family != ip_in->ss.ss_family)
1152 <      continue;
1153 <    if (ip_in->ss.ss_family == AF_INET6)
1154 <    {
1155 <      ptr_v6 = (struct sockaddr_in6 *)&ptr->ip;
1156 <      res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr));
344 >      return attach_iline(client_p, conf);
345      }
346 <    else
1159 < #endif
346 >    else if (IsConfKill(conf) || (ConfigGeneral.glines && IsConfGline(conf)))
347      {
348 <      ptr_v4 = (struct sockaddr_in *)&ptr->ip;
349 <      res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr));
1163 <    }
1164 <    if (res)
1165 <      continue;
1166 <    if (ptr->count > 0)
1167 <      ptr->count--;
1168 <    if (ptr->count == 0 &&
1169 <        (CurrentTime-ptr->last_attempt) >= ConfigFileEntry.throttle_time)
1170 <    {
1171 <      if (last_ptr != NULL)
1172 <        last_ptr->next = ptr->next;
1173 <      else
1174 <        ip_hash_table[hash_index] = ptr->next;
348 >      if (IsConfGline(conf))
349 >        sendto_one_notice(client_p, &me, ":*** G-lined");
350  
351 <      BlockHeapFree(ip_entry_heap, ptr);
352 <      ip_entries_count--;
1178 <      return;
351 >      sendto_one_notice(client_p, &me, ":*** Banned: %s", conf->reason);
352 >      return BANNED_CLIENT;
353      }
1180    last_ptr = ptr;
354    }
1182 }
355  
356 < /* hash_ip()
1185 < *
1186 < * input        - pointer to an irc_inaddr
1187 < * output       - integer value used as index into hash table
1188 < * side effects - hopefully, none
1189 < */
1190 < static int
1191 < hash_ip(struct irc_ssaddr *addr)
1192 < {
1193 <  if (addr->ss.ss_family == AF_INET)
1194 <  {
1195 <    struct sockaddr_in *v4 = (struct sockaddr_in *)addr;
1196 <    int hash;
1197 <    uint32_t ip;
1198 <
1199 <    ip   = ntohl(v4->sin_addr.s_addr);
1200 <    hash = ((ip >> 12) + ip) & (IP_HASH_SIZE-1);
1201 <    return hash;
1202 <  }
1203 < #ifdef IPV6
1204 <  else
1205 <  {
1206 <    int hash;
1207 <    struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr;
1208 <    uint32_t *ip = (uint32_t *)&v6->sin6_addr.s6_addr;
1209 <
1210 <    hash  = ip[0] ^ ip[3];
1211 <    hash ^= hash >> 16;  
1212 <    hash ^= hash >> 8;  
1213 <    hash  = hash & (IP_HASH_SIZE - 1);
1214 <    return hash;
1215 <  }
1216 < #else
1217 <  return 0;
1218 < #endif
356 >  return NOT_AUTHORIZED;
357   }
358  
359 < /* count_ip_hash()
1222 < *
1223 < * inputs        - pointer to counter of number of ips hashed
1224 < *               - pointer to memory used for ip hash
1225 < * output        - returned via pointers input
1226 < * side effects  - NONE
359 > /* check_client()
360   *
361 < * number of hashed ip #'s is counted up, plus the amount of memory
362 < * used in the hash.
361 > * inputs       - pointer to client
362 > * output       - 0 = Success
363 > *                NOT_AUTHORIZED    (-1) = Access denied (no I line match)
364 > *                IRCD_SOCKET_ERROR (-2) = Bad socket.
365 > *                I_LINE_FULL       (-3) = I-line is full
366 > *                TOO_MANY          (-4) = Too many connections from hostname
367 > *                BANNED_CLIENT     (-5) = K-lined
368 > * side effects - Ordinary client access check.
369 > *                Look for conf lines which have the same
370 > *                status as the flags passed.
371   */
372 < void
373 < count_ip_hash(unsigned int *number_ips_stored, uint64_t *mem_ips_stored)
372 > int
373 > check_client(struct Client *source_p)
374   {
1234  struct ip_entry *ptr;
375    int i;
376  
377 <  *number_ips_stored = 0;
378 <  *mem_ips_stored    = 0;
377 >  if ((i = verify_access(source_p)))
378 >    ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
379 >         source_p->name, source_p->sockhost);
380  
381 <  for (i = 0; i < IP_HASH_SIZE; i++)
381 >  switch (i)
382    {
383 <    for (ptr = ip_hash_table[i]; ptr; ptr = ptr->next)
384 <    {
385 <      *number_ips_stored += 1;
386 <      *mem_ips_stored += sizeof(struct ip_entry);
387 <    }
388 <  }
389 < }
383 >    case TOO_MANY:
384 >      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
385 >                           "Too many on IP for %s (%s).",
386 >                           get_client_name(source_p, SHOW_IP),
387 >                           source_p->sockhost);
388 >      ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
389 >           get_client_name(source_p, SHOW_IP));
390 >      ++ServerStats.is_ref;
391 >      exit_client(source_p, "No more connections allowed on that IP");
392 >      break;
393  
394 < /* garbage_collect_ip_entries()
395 < *
396 < * input        - NONE
397 < * output       - NONE
398 < * side effects - free up all ip entries with no connections
399 < */
400 < static void
401 < garbage_collect_ip_entries(void)
402 < {
403 <  struct ip_entry *ptr;
1260 <  struct ip_entry *last_ptr;
1261 <  struct ip_entry *next_ptr;
1262 <  int i;
394 >    case I_LINE_FULL:
395 >      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
396 >                           "auth {} block is full for %s (%s).",
397 >                           get_client_name(source_p, SHOW_IP),
398 >                           source_p->sockhost);
399 >      ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
400 >           get_client_name(source_p, SHOW_IP));
401 >      ++ServerStats.is_ref;
402 >      exit_client(source_p, "No more connections allowed in your connection class");
403 >      break;
404  
405 <  for (i = 0; i < IP_HASH_SIZE; i++)
406 <  {
407 <    last_ptr = NULL;
405 >    case NOT_AUTHORIZED:
406 >      /* jdc - lists server name & port connections are on */
407 >      /*       a purely cosmetical change */
408 >      sendto_realops_flags(UMODE_UNAUTH, L_ALL, SEND_NOTICE,
409 >                           "Unauthorized client connection from %s [%s] on [%s/%u].",
410 >                           get_client_name(source_p, SHOW_IP),
411 >                           source_p->sockhost,
412 >                           source_p->connection->listener->name,
413 >                           source_p->connection->listener->port);
414 >      ilog(LOG_TYPE_IRCD, "Unauthorized client connection from %s on [%s/%u].",
415 >           get_client_name(source_p, SHOW_IP),
416 >           source_p->connection->listener->name,
417 >           source_p->connection->listener->port);
418  
419 <    for (ptr = ip_hash_table[i]; ptr; ptr = next_ptr)
420 <    {
421 <      next_ptr = ptr->next;
419 >      ++ServerStats.is_ref;
420 >      exit_client(source_p, "You are not authorized to use this server");
421 >      break;
422  
423 <      if (ptr->count == 0 &&
424 <          (CurrentTime - ptr->last_attempt) >= ConfigFileEntry.throttle_time)
425 <      {
426 <        if (last_ptr != NULL)
427 <          last_ptr->next = ptr->next;
428 <        else
429 <          ip_hash_table[i] = ptr->next;
430 <        BlockHeapFree(ip_entry_heap, ptr);
1280 <        ip_entries_count--;
1281 <      }
1282 <      else
1283 <        last_ptr = ptr;
1284 <    }
423 >    case BANNED_CLIENT:
424 >      ++ServerStats.is_ref;
425 >      exit_client(source_p, "Banned");
426 >      break;
427 >
428 >    case 0:
429 >    default:
430 >      break;
431    }
432 +
433 +  return !(i < 0);
434   }
435  
436   /* detach_conf()
# Line 1293 | Line 441 | garbage_collect_ip_entries(void)
441   * side effects - Disassociate configuration from the client.
442   *                Also removes a class from the list if marked for deleting.
443   */
444 < int
445 < detach_conf(struct Client *client_p, ConfType type)
444 > void
445 > detach_conf(struct Client *client_p, enum maskitem_type type)
446   {
447 <  dlink_node *ptr, *next_ptr;
1300 <  struct ConfItem *conf;
1301 <  struct ClassItem *aclass;
1302 <  struct AccessItem *aconf;
1303 <  struct ConfItem *aclass_conf;
1304 <  struct MatchItem *match_item;
447 >  dlink_node *node = NULL, *node_next = NULL;
448  
449 <  DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->confs.head)
449 >  DLINK_FOREACH_SAFE(node, node_next, client_p->connection->confs.head)
450    {
451 <    conf = ptr->data;
1309 <
1310 <    if (type == CONF_TYPE || conf->type == type)
1311 <    {
1312 <      dlinkDelete(ptr, &client_p->localClient->confs);
1313 <      free_dlink_node(ptr);
1314 <
1315 <      switch (conf->type)
1316 <      {
1317 <      case CLIENT_TYPE:
1318 <      case OPER_TYPE:
1319 <      case SERVER_TYPE:
1320 <        aconf = map_to_conf(conf);
1321 <
1322 <        assert(aconf->clients > 0);
1323 <
1324 <        if ((aclass_conf = ClassPtr(aconf)) != NULL)
1325 <        {
1326 <          aclass = map_to_conf(aclass_conf);
451 >    struct MaskItem *conf = node->data;
452  
453 <          assert(aclass->curr_user_count > 0);
453 >    assert(conf->type & (CONF_CLIENT | CONF_OPER | CONF_SERVER));
454 >    assert(conf->ref_count > 0);
455 >    assert(conf->class->ref_count > 0);
456  
457 <          if (conf->type == CLIENT_TYPE)
458 <            remove_from_cidr_check(&client_p->localClient->ip, aclass);
1332 <          if (--aclass->curr_user_count == 0 && aclass->active == 0)
1333 <            delete_conf_item(aclass_conf);
1334 <        }
457 >    if (!(conf->type & type))
458 >      continue;
459  
460 <        if (--aconf->clients == 0 && IsConfIllegal(aconf))
461 <          delete_conf_item(conf);
460 >    dlinkDelete(node, &client_p->connection->confs);
461 >    free_dlink_node(node);
462  
463 <        break;
463 >    if (conf->type == CONF_CLIENT)
464 >      remove_from_cidr_check(&client_p->connection->ip, conf->class);
465  
466 <      case LEAF_TYPE:
467 <      case HUB_TYPE:
468 <        match_item = map_to_conf(conf);
469 <        if (match_item->ref_count == 0 && match_item->illegal)
1345 <          delete_conf_item(conf);
1346 <        break;
1347 <      default:
1348 <        break;
1349 <      }
1350 <
1351 <      if (type != CONF_TYPE)
1352 <        return 0;
466 >    if (--conf->class->ref_count == 0 && conf->class->active == 0)
467 >    {
468 >      class_free(conf->class);
469 >      conf->class = NULL;
470      }
1354  }
471  
472 <  return -1;
472 >    if (--conf->ref_count == 0 && conf->active == 0)
473 >      conf_free(conf);
474 >  }
475   }
476  
477   /* attach_conf()
# Line 1367 | Line 485 | detach_conf(struct Client *client_p, Con
485   *                attachment if there was an old one...
486   */
487   int
488 < attach_conf(struct Client *client_p, struct ConfItem *conf)
488 > attach_conf(struct Client *client_p, struct MaskItem *conf)
489   {
490 <  if (dlinkFind(&client_p->localClient->confs, conf) != NULL)
490 >  if (dlinkFind(&client_p->connection->confs, conf))
491      return 1;
492  
493 <  if (conf->type == CLIENT_TYPE ||
494 <      conf->type == SERVER_TYPE ||
495 <      conf->type == OPER_TYPE)
496 <  {
1379 <    struct AccessItem *aconf = map_to_conf(conf);
1380 <    struct ClassItem *aclass = map_to_conf(aconf->class_ptr);
1381 <
1382 <    if (IsConfIllegal(aconf))
1383 <      return NOT_AUTHORIZED;
1384 <
1385 <    if (conf->type == CLIENT_TYPE)
1386 <      if (cidr_limit_reached(IsConfExemptLimits(aconf),
1387 <                             &client_p->localClient->ip, aclass))
1388 <        return TOO_MANY;    /* Already at maximum allowed */
493 >  if (conf->type == CONF_CLIENT)
494 >    if (cidr_limit_reached(IsConfExemptLimits(conf),
495 >                           &client_p->connection->ip, conf->class))
496 >      return TOO_MANY;    /* Already at maximum allowed */
497  
498 <    CurrUserCount(aclass)++;
499 <    aconf->clients++;
1392 <  }
1393 <  else if (conf->type == HUB_TYPE || conf->type == LEAF_TYPE)
1394 <  {
1395 <    struct MatchItem *match_item = map_to_conf(conf);
1396 <    match_item->ref_count++;
1397 <  }
498 >  conf->class->ref_count++;
499 >  conf->ref_count++;
500  
501 <  dlinkAdd(conf, make_dlink_node(), &client_p->localClient->confs);
501 >  dlinkAdd(conf, make_dlink_node(), &client_p->connection->confs);
502  
503    return 0;
504   }
# Line 1413 | Line 515 | int
515   attach_connect_block(struct Client *client_p, const char *name,
516                       const char *host)
517   {
518 <  dlink_node *ptr;
1417 <  struct ConfItem *conf;
1418 <  struct AccessItem *aconf;
518 >  dlink_node *node = NULL;
519  
520 <  assert(client_p != NULL);
1421 <  assert(host != NULL);
520 >  assert(host);
521  
522 <  if (client_p == NULL || host == NULL)
1424 <    return 0;
1425 <
1426 <  DLINK_FOREACH(ptr, server_items.head)
522 >  DLINK_FOREACH(node, server_items.head)
523    {
524 <    conf = ptr->data;
1429 <    aconf = map_to_conf(conf);
524 >    struct MaskItem *conf = node->data;
525  
526 <    if (match(conf->name, name) == 0 || match(aconf->host, host) == 0)
526 >    if (match(conf->name, name) || match(conf->host, host))
527        continue;
528  
529      attach_conf(client_p, conf);
530 <    return -1;
530 >    return 1;
531    }
532  
533    return 0;
534   }
535  
1441 /* find_conf_exact()
1442 *
1443 * inputs       - type of ConfItem
1444 *              - pointer to name to find
1445 *              - pointer to username to find
1446 *              - pointer to host to find
1447 * output       - NULL or pointer to conf found
1448 * side effects - find a conf entry which matches the hostname
1449 *                and has the same name.
1450 */
1451 struct ConfItem *
1452 find_conf_exact(ConfType type, const char *name, const char *user,
1453                const char *host)
1454 {
1455  dlink_node *ptr;
1456  dlink_list *list_p;
1457  struct ConfItem *conf = NULL;
1458  struct AccessItem *aconf;
1459
1460  /* Only valid for OPER_TYPE and ...? */
1461  list_p = map_to_list(type);
1462
1463  DLINK_FOREACH(ptr, (*list_p).head)
1464  {
1465    conf = ptr->data;
1466
1467    if (conf->name == NULL)
1468      continue;
1469    aconf = map_to_conf(conf);
1470    if (aconf->host == NULL)
1471      continue;
1472    if (irccmp(conf->name, name) != 0)
1473      continue;
1474
1475    /*
1476    ** Accept if the *real* hostname (usually sockethost)
1477    ** socket host) matches *either* host or name field
1478    ** of the configuration.
1479    */
1480    if (!match(aconf->host, host) || !match(aconf->user, user))
1481      continue;
1482    if (type == OPER_TYPE)
1483    {
1484      struct ClassItem *aclass = map_to_conf(aconf->class_ptr);
1485
1486      if (aconf->clients >= MaxTotal(aclass))
1487        continue;
1488    }
1489
1490    return conf;
1491  }
1492
1493  return NULL;
1494 }
1495
536   /* find_conf_name()
537   *
538   * inputs       - pointer to conf link list to search
# Line 1502 | Line 542 | find_conf_exact(ConfType type, const cha
542   * side effects - find a conf entry which matches the name
543   *                and has the given mask.
544   */
545 < struct ConfItem *
546 < find_conf_name(dlink_list *list, const char *name, ConfType type)
545 > struct MaskItem *
546 > find_conf_name(dlink_list *list, const char *name, enum maskitem_type type)
547   {
548 <  dlink_node *ptr;
1509 <  struct ConfItem* conf;
548 >  dlink_node *node = NULL;
549  
550 <  DLINK_FOREACH(ptr, list->head)
550 >  DLINK_FOREACH(node, list->head)
551    {
552 <    conf = ptr->data;
553 <    
552 >    struct MaskItem *conf = node->data;
553 >
554      if (conf->type == type)
555      {
556 <      if (conf->name && (irccmp(conf->name, name) == 0 ||
557 <                         match(conf->name, name)))
1519 <      return conf;
556 >      if (conf->name && !irccmp(conf->name, name))
557 >        return conf;
558      }
559    }
560  
561    return NULL;
562   }
563  
1526 /* map_to_list()
1527 *
1528 * inputs       - ConfType conf
1529 * output       - pointer to dlink_list to use
1530 * side effects - none
1531 */
1532 static dlink_list *
1533 map_to_list(ConfType type)
1534 {
1535  switch(type)
1536  {
1537  case RXLINE_TYPE:
1538    return(&rxconf_items);
1539    break;
1540  case XLINE_TYPE:
1541    return(&xconf_items);
1542    break;
1543  case ULINE_TYPE:
1544    return(&uconf_items);
1545    break;
1546  case NRESV_TYPE:
1547    return(&nresv_items);
1548    break;
1549  case OPER_TYPE:
1550    return(&oconf_items);
1551    break;
1552  case CLASS_TYPE:
1553    return(&class_items);
1554    break;
1555  case SERVER_TYPE:
1556    return(&server_items);
1557    break;
1558  case CLUSTER_TYPE:
1559    return(&cluster_items);
1560    break;
1561  case CONF_TYPE:
1562  case GLINE_TYPE:
1563  case KLINE_TYPE:
1564  case DLINE_TYPE:
1565  case CRESV_TYPE:
1566  default:
1567    return NULL;
1568  }
1569 }
1570
564   /* find_matching_name_conf()
565   *
566   * inputs       - type of link list to look in
567   *              - pointer to name string to find
568   *              - pointer to user
569   *              - pointer to host
570 < *              - optional action to match on as well
571 < * output       - NULL or pointer to found struct MatchItem
570 > *              - optional flags to match on as well
571 > * output       - NULL or pointer to found struct MaskItem
572   * side effects - looks for a match on name field
573   */
574 < struct ConfItem *
575 < find_matching_name_conf(ConfType type, const char *name, const char *user,
576 <                        const char *host, int action)
577 < {
578 <  dlink_node *ptr=NULL;
579 <  struct ConfItem *conf=NULL;
580 <  struct AccessItem *aconf=NULL;
1588 <  struct MatchItem *match_item=NULL;
1589 <  dlink_list *list_p = map_to_list(type);
574 > struct MaskItem *
575 > find_matching_name_conf(enum maskitem_type type, const char *name, const char *user,
576 >                        const char *host, unsigned int flags)
577 > {
578 >  dlink_node *node = NULL;
579 >  dlink_list *list = map_to_list(type);
580 >  struct MaskItem *conf = NULL;
581  
582    switch (type)
583    {
584 < #ifdef HAVE_LIBPCRE
585 <  case RXLINE_TYPE:
1595 <      DLINK_FOREACH(ptr, list_p->head)
1596 <      {
1597 <        conf = ptr->data;
1598 <        assert(conf->regexpname);
1599 <
1600 <        if (!ircd_pcre_exec(conf->regexpname, name))
1601 <          return conf;
1602 <      }
1603 <      break;
1604 < #endif
1605 <  case SERVICE_TYPE:
1606 <    DLINK_FOREACH(ptr, list_p->head)
584 >  case CONF_SERVICE:
585 >    DLINK_FOREACH(node, list->head)
586      {
587 <      conf = ptr->data;
587 >      conf = node->data;
588  
589        if (EmptyString(conf->name))
590          continue;
591 <      if ((name != NULL) && !irccmp(name, conf->name))
591 >      if (name && !irccmp(name, conf->name))
592          return conf;
593      }
594      break;
595  
596 <  case XLINE_TYPE:
597 <  case ULINE_TYPE:
598 <  case NRESV_TYPE:
599 <    DLINK_FOREACH(ptr, list_p->head)
596 >  case CONF_XLINE:
597 >  case CONF_ULINE:
598 >  case CONF_NRESV:
599 >  case CONF_CRESV:
600 >    DLINK_FOREACH(node, list->head)
601      {
602 <      conf = ptr->data;
602 >      conf = node->data;
603  
1624      match_item = map_to_conf(conf);
604        if (EmptyString(conf->name))
605 <        continue;
606 <      if ((name != NULL) && match_esc(conf->name, name))
605 >        continue;
606 >      if (name && !match(conf->name, name))
607        {
608 <        if ((user == NULL && (host == NULL)))
609 <          return conf;
610 <        if ((match_item->action & action) != action)
608 >        if ((user == NULL && (host == NULL)))
609 >          return conf;
610 >        if ((conf->flags & flags) != flags)
611            continue;
612 <        if (EmptyString(match_item->user) || EmptyString(match_item->host))
613 <          return conf;
614 <        if (match(match_item->user, user) && match(match_item->host, host))
615 <          return conf;
612 >        if (EmptyString(conf->user) || EmptyString(conf->host))
613 >          return conf;
614 >        if (!match(conf->user, user) && !match(conf->host, host))
615 >          return conf;
616        }
617      }
618        break;
619  
620 <  case SERVER_TYPE:
621 <    DLINK_FOREACH(ptr, list_p->head)
620 >  case CONF_SERVER:
621 >    DLINK_FOREACH(node, list->head)
622      {
623 <      conf = ptr->data;
1645 <      aconf = map_to_conf(conf);
623 >      conf = node->data;
624  
625 <      if ((name != NULL) && match_esc(name, conf->name))
625 >      if (name && !match(name, conf->name))
626          return conf;
627 <      else if ((host != NULL) && match_esc(host, aconf->host))
627 >      if (host && !match(host, conf->host))
628          return conf;
629      }
630      break;
631 <  
631 >
632    default:
633      break;
634    }
# Line 1663 | Line 641 | find_matching_name_conf(ConfType type, c
641   *              - pointer to name string to find
642   *              - pointer to user
643   *              - pointer to host
644 < * output       - NULL or pointer to found struct MatchItem
644 > * output       - NULL or pointer to found struct MaskItem
645   * side effects - looks for an exact match on name field
646   */
647 < struct ConfItem *
648 < find_exact_name_conf(ConfType type, const char *name,
647 > struct MaskItem *
648 > find_exact_name_conf(enum maskitem_type type, const struct Client *who, const char *name,
649                       const char *user, const char *host)
650   {
651 <  dlink_node *ptr = NULL;
652 <  struct AccessItem *aconf;
653 <  struct ConfItem *conf;
1676 <  struct MatchItem *match_item;
1677 <  dlink_list *list_p;
1678 <
1679 <  list_p = map_to_list(type);
651 >  dlink_node *node = NULL;
652 >  dlink_list *list = map_to_list(type);
653 >  struct MaskItem *conf = NULL;
654  
655    switch(type)
656    {
657 <  case RXLINE_TYPE:
658 <  case XLINE_TYPE:
659 <  case ULINE_TYPE:
660 <  case NRESV_TYPE:
657 >  case CONF_XLINE:
658 >  case CONF_ULINE:
659 >  case CONF_NRESV:
660 >  case CONF_CRESV:
661  
662 <    DLINK_FOREACH(ptr, list_p->head)
662 >    DLINK_FOREACH(node, list->head)
663      {
664 <      conf = ptr->data;
665 <      match_item = (struct MatchItem *)map_to_conf(conf);
664 >      conf = node->data;
665 >
666        if (EmptyString(conf->name))
667 <        continue;
668 <    
667 >        continue;
668 >
669        if (irccmp(conf->name, name) == 0)
670        {
671 <        if ((user == NULL && (host == NULL)))
672 <          return (conf);
673 <        if (EmptyString(match_item->user) || EmptyString(match_item->host))
674 <          return (conf);
675 <        if (match(match_item->user, user) && match(match_item->host, host))
676 <          return (conf);
671 >        if ((user == NULL && (host == NULL)))
672 >          return conf;
673 >        if (EmptyString(conf->user) || EmptyString(conf->host))
674 >          return conf;
675 >        if (!match(conf->user, user) && !match(conf->host, host))
676 >          return conf;
677        }
678      }
679      break;
680  
681 <  case OPER_TYPE:
682 <    DLINK_FOREACH(ptr, list_p->head)
681 >  case CONF_OPER:
682 >    DLINK_FOREACH(node, list->head)
683      {
684 <      conf = ptr->data;
685 <      aconf = (struct AccessItem *)map_to_conf(conf);
684 >      conf = node->data;
685 >
686        if (EmptyString(conf->name))
687 <        continue;
688 <    
689 <      if (irccmp(conf->name, name) == 0)
687 >        continue;
688 >
689 >      if (!irccmp(conf->name, name))
690        {
691 <        if ((user == NULL && (host == NULL)))
692 <          return (conf);
693 <        if (EmptyString(aconf->user) || EmptyString(aconf->host))
694 <          return (conf);
695 <        if (match(aconf->user, user) && match(aconf->host, host))
696 <          return (conf);
691 >        if (!who)
692 >          return conf;
693 >        if (EmptyString(conf->user) || EmptyString(conf->host))
694 >          return NULL;
695 >        if (!match(conf->user, who->username))
696 >        {
697 >          switch (conf->htype)
698 >          {
699 >            case HM_HOST:
700 >              if (!match(conf->host, who->host) || !match(conf->host, who->sockhost))
701 >                if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
702 >                  return conf;
703 >              break;
704 >            case HM_IPV4:
705 >              if (who->connection->aftype == AF_INET)
706 >                if (match_ipv4(&who->connection->ip, &conf->addr, conf->bits))
707 >                  if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
708 >                    return conf;
709 >              break;
710 >            case HM_IPV6:
711 >              if (who->connection->aftype == AF_INET6)
712 >                if (match_ipv6(&who->connection->ip, &conf->addr, conf->bits))
713 >                  if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
714 >                    return conf;
715 >              break;
716 >            default:
717 >              assert(0);
718 >          }
719 >        }
720        }
721      }
722 +
723      break;
724  
725 <  case SERVER_TYPE:
726 <    DLINK_FOREACH(ptr, list_p->head)
725 >  case CONF_SERVER:
726 >    DLINK_FOREACH(node, list->head)
727      {
728 <      conf = ptr->data;
729 <      aconf = (struct AccessItem *)map_to_conf(conf);
728 >      conf = node->data;
729 >
730        if (EmptyString(conf->name))
731 <        continue;
732 <    
731 >        continue;
732 >
733        if (name == NULL)
734        {
735 <        if (EmptyString(aconf->host))
736 <          continue;
737 <        if (irccmp(aconf->host, host) == 0)
738 <          return(conf);
735 >        if (EmptyString(conf->host))
736 >          continue;
737 >        if (irccmp(conf->host, host) == 0)
738 >          return conf;
739        }
740        else if (irccmp(conf->name, name) == 0)
741 <      {
1744 <          return (conf);
1745 <      }
741 >        return conf;
742      }
1747    break;
743  
1749  case CLASS_TYPE:
1750    DLINK_FOREACH(ptr, list_p->head)
1751    {
1752      conf = ptr->data;
1753      if (EmptyString(conf->name))
1754        continue;
1755    
1756      if (irccmp(conf->name, name) == 0)
1757        return (conf);
1758    }
744      break;
745  
746    default:
747      break;
748    }
1764  return(NULL);
1765 }
1766
1767 /* rehash()
1768 *
1769 * Actual REHASH service routine. Called with sig == 0 if it has been called
1770 * as a result of an operator issuing this command, else assume it has been
1771 * called as a result of the server receiving a HUP signal.
1772 */
1773 int
1774 rehash(int sig)
1775 {
1776  if (sig != 0)
1777    sendto_realops_flags(UMODE_ALL, L_ALL,
1778                         "Got signal SIGHUP, reloading ircd.conf file");
1779
1780  restart_resolver();
1781
1782  /* don't close listeners until we know we can go ahead with the rehash */
1783
1784  /* Check to see if we magically got(or lost) IPv6 support */
1785  check_can_use_v6();
1786
1787  read_conf_files(0);
1788
1789  if (ServerInfo.description != NULL)
1790    strlcpy(me.info, ServerInfo.description, sizeof(me.info));
1791
1792  load_conf_modules();
1793
1794  flush_deleted_I_P();
1795
1796  rehashed_klines = 1;
749  
750 <  if (ConfigLoggingEntry.use_logging)
1799 <    reopen_log(logFileName);
1800 <
1801 <  return(0);
750 >  return NULL;
751   }
752  
753   /* set_default_conf()
# Line 1816 | Line 765 | set_default_conf(void)
765    /* verify init_class() ran, this should be an unnecessary check
766     * but its not much work.
767     */
768 <  assert(class_default == (struct ConfItem *) class_items.tail->data);
768 >  assert(class_default == class_get_list()->tail->data);
769  
770   #ifdef HAVE_LIBCRYPTO
771 <  ServerInfo.rsa_private_key = NULL;
772 <  ServerInfo.rsa_private_key_file = NULL;
771 > #if OPENSSL_VERSION_NUMBER >= 0x009080FFL && !defined(OPENSSL_NO_ECDH)
772 >  {
773 >    EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
774 >
775 >    if (key)
776 >    {
777 >      SSL_CTX_set_tmp_ecdh(ConfigServerInfo.server_ctx, key);
778 >      EC_KEY_free(key);
779 >    }
780 >  }
781 >
782 >  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE);
783 > #endif
784 >
785 >  SSL_CTX_set_cipher_list(ConfigServerInfo.server_ctx, "EECDH+HIGH:EDH+HIGH:HIGH:!aNULL");
786 >  ConfigServerInfo.message_digest_algorithm = EVP_sha256();
787 >  ConfigServerInfo.rsa_private_key = NULL;
788 >  ConfigServerInfo.rsa_private_key_file = NULL;
789   #endif
790  
791 <  /* ServerInfo.name is not rehashable */
792 <  /* ServerInfo.name = ServerInfo.name; */
793 <  ServerInfo.description = NULL;
794 <  DupString(ServerInfo.network_name, NETWORK_NAME_DEFAULT);
795 <  DupString(ServerInfo.network_desc, NETWORK_DESC_DEFAULT);
796 <
797 <  memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip));
798 <  ServerInfo.specific_ipv4_vhost = 0;
799 <  memset(&ServerInfo.ip6, 0, sizeof(ServerInfo.ip6));
800 <  ServerInfo.specific_ipv6_vhost = 0;
801 <
802 <  ServerInfo.max_clients = MAXCLIENTS_MAX;
803 <
804 <  ServerInfo.hub = 0;
805 <  ServerInfo.dns_host.sin_addr.s_addr = 0;
806 <  ServerInfo.dns_host.sin_port = 0;
807 <  AdminInfo.name = NULL;
808 <  AdminInfo.email = NULL;
809 <  AdminInfo.description = NULL;
810 <
811 <  set_log_level(L_NOTICE);
812 <  ConfigLoggingEntry.use_logging = 1;
813 <  ConfigLoggingEntry.operlog[0] = '\0';
814 <  ConfigLoggingEntry.userlog[0] = '\0';
815 <  ConfigLoggingEntry.klinelog[0] = '\0';
816 <  ConfigLoggingEntry.glinelog[0] = '\0';
817 <  ConfigLoggingEntry.killlog[0] = '\0';
818 <  ConfigLoggingEntry.operspylog[0] = '\0';
819 <  ConfigLoggingEntry.ioerrlog[0] = '\0';
1855 <  ConfigLoggingEntry.failed_operlog[0] = '\0';
1856 <
1857 <  ConfigChannel.disable_fake_channels = NO;
1858 <  ConfigChannel.restrict_channels = NO;
1859 <  ConfigChannel.disable_local_channels = NO;
1860 <  ConfigChannel.use_invex = YES;
1861 <  ConfigChannel.use_except = YES;
1862 <  ConfigChannel.use_knock = YES;
1863 <  ConfigChannel.knock_delay = 300;
791 >  /* ConfigServerInfo.name is not rehashable */
792 >  /* ConfigServerInfo.name = ConfigServerInfo.name; */
793 >  ConfigServerInfo.description = NULL;
794 >  ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
795 >  ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
796 >
797 >  memset(&ConfigServerInfo.ip, 0, sizeof(ConfigServerInfo.ip));
798 >  ConfigServerInfo.specific_ipv4_vhost = 0;
799 >  memset(&ConfigServerInfo.ip6, 0, sizeof(ConfigServerInfo.ip6));
800 >  ConfigServerInfo.specific_ipv6_vhost = 0;
801 >
802 >  ConfigServerInfo.default_max_clients = MAXCLIENTS_MAX;
803 >  ConfigServerInfo.max_nick_length = 9;
804 >  ConfigServerInfo.max_topic_length = 80;
805 >  ConfigServerInfo.hub = 0;
806 >
807 >  ConfigAdminInfo.name = NULL;
808 >  ConfigAdminInfo.email = NULL;
809 >  ConfigAdminInfo.description = NULL;
810 >
811 >  log_del_all();
812 >
813 >  ConfigLog.use_logging = 1;
814 >
815 >  ConfigChannel.disable_fake_channels = 0;
816 >  ConfigChannel.invite_client_count = 10;
817 >  ConfigChannel.invite_client_time = 300;
818 >  ConfigChannel.knock_client_count = 1;
819 >  ConfigChannel.knock_client_time = 300;
820    ConfigChannel.knock_delay_channel = 60;
821 <  ConfigChannel.max_chans_per_user = 15;
1866 <  ConfigChannel.quiet_on_ban = YES;
821 >  ConfigChannel.max_channels = 25;
822    ConfigChannel.max_bans = 25;
823 +  ConfigChannel.default_join_flood_count = 18;
824 +  ConfigChannel.default_join_flood_time = 6;
825    ConfigChannel.default_split_user_count = 0;
826    ConfigChannel.default_split_server_count = 0;
827 <  ConfigChannel.no_join_on_split = NO;
828 <  ConfigChannel.no_create_on_split = NO;
1872 <  ConfigChannel.burst_topicwho = YES;
827 >  ConfigChannel.no_join_on_split = 0;
828 >  ConfigChannel.no_create_on_split = 0;
829  
830 <  ConfigServerHide.flatten_links = NO;
830 >  ConfigServerHide.flatten_links = 0;
831    ConfigServerHide.links_delay = 300;
832 <  ConfigServerHide.hidden = NO;
833 <  ConfigServerHide.disable_hidden = NO;
834 <  ConfigServerHide.hide_servers = NO;
835 <  DupString(ConfigServerHide.hidden_name, NETWORK_NAME_DEFAULT);
836 <  ConfigServerHide.hide_server_ips = NO;
837 <
838 <  
839 <  DupString(ConfigFileEntry.service_name, SERVICE_NAME_DEFAULT);
840 <  ConfigFileEntry.max_watch = WATCHSIZE_DEFAULT;
841 <  ConfigFileEntry.gline_min_cidr = 16;
842 <  ConfigFileEntry.gline_min_cidr6 = 48;
843 <  ConfigFileEntry.invisible_on_connect = YES;
844 <  ConfigFileEntry.burst_away = NO;
845 <  ConfigFileEntry.use_whois_actually = YES;
846 <  ConfigFileEntry.tkline_expire_notices = YES;
847 <  ConfigFileEntry.hide_spoof_ips = YES;
848 <  ConfigFileEntry.ignore_bogus_ts = NO;
849 <  ConfigFileEntry.disable_auth = NO;
850 <  ConfigFileEntry.disable_remote = NO;
851 <  ConfigFileEntry.kill_chase_time_limit = 90;
852 <  ConfigFileEntry.default_floodcount = 8;
853 <  ConfigFileEntry.failed_oper_notice = YES;
854 <  ConfigFileEntry.dots_in_ident = 0;
855 <  ConfigFileEntry.min_nonwildcard = 4;
856 <  ConfigFileEntry.min_nonwildcard_simple = 3;
857 <  ConfigFileEntry.max_accept = 20;
858 <  ConfigFileEntry.anti_nick_flood = NO;
859 <  ConfigFileEntry.max_nick_time = 20;
860 <  ConfigFileEntry.max_nick_changes = 5;
861 <  ConfigFileEntry.anti_spam_exit_message_time = 0;
862 <  ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
863 <  ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
864 <  ConfigFileEntry.kline_with_reason = YES;
865 <  ConfigFileEntry.kline_reason = NULL;
866 <  ConfigFileEntry.warn_no_nline = YES;
867 <  ConfigFileEntry.stats_o_oper_only = NO;
868 <  ConfigFileEntry.stats_k_oper_only = 1;  /* masked */
869 <  ConfigFileEntry.stats_i_oper_only = 1;  /* masked */
870 <  ConfigFileEntry.stats_P_oper_only = NO;
871 <  ConfigFileEntry.caller_id_wait = 60;
872 <  ConfigFileEntry.opers_bypass_callerid = NO;
873 <  ConfigFileEntry.pace_wait = 10;
874 <  ConfigFileEntry.pace_wait_simple = 1;
875 <  ConfigFileEntry.short_motd = NO;
876 <  ConfigFileEntry.ping_cookie = NO;
877 <  ConfigFileEntry.no_oper_flood = NO;
878 <  ConfigFileEntry.true_no_oper_flood = NO;
879 <  ConfigFileEntry.oper_pass_resv = YES;
880 <  ConfigFileEntry.glines = NO;
881 <  ConfigFileEntry.gline_time = 12 * 3600;
882 <  ConfigFileEntry.idletime = 0;
883 <  ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT;
884 <  ConfigFileEntry.client_flood = CLIENT_FLOOD_DEFAULT;
885 <  ConfigFileEntry.oper_only_umodes = UMODE_DEBUG;
886 <  ConfigFileEntry.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE |
887 <    UMODE_OPERWALL | UMODE_WALLOP;
888 <  DupString(ConfigFileEntry.servlink_path, SLPATH);
889 < #ifdef HAVE_LIBCRYPTO
890 <  /* jdc -- This is our default value for a cipher.  According to the
891 <   *        CRYPTLINK document (doc/cryptlink.txt), BF/128 must be supported
892 <   *        under all circumstances if cryptlinks are enabled.  So,
893 <   *        this will be our default.
894 <   *
895 <   *        NOTE: I apologise for the hard-coded value of "1" (BF/128).
896 <   *              This should be moved into a find_cipher() routine.
897 <   */
898 <  ConfigFileEntry.default_cipher_preference = &CipherTable[1];
899 < #endif
900 <  ConfigFileEntry.use_egd = NO;
901 <  ConfigFileEntry.egdpool_path = NULL;
902 < #ifdef HAVE_LIBZ
903 <  ConfigFileEntry.compression_level = 0;
904 < #endif
905 <  ConfigFileEntry.throttle_time = 10;
832 >  ConfigServerHide.hidden = 0;
833 >  ConfigServerHide.hide_servers = 0;
834 >  ConfigServerHide.hide_services = 0;
835 >  ConfigServerHide.hidden_name = xstrdup(NETWORK_NAME_DEFAULT);
836 >  ConfigServerHide.hide_server_ips = 0;
837 >  ConfigServerHide.disable_remote_commands = 0;
838 >
839 >  ConfigGeneral.away_count = 2;
840 >  ConfigGeneral.away_time = 10;
841 >  ConfigGeneral.max_watch = WATCHSIZE_DEFAULT;
842 >  ConfigGeneral.cycle_on_host_change = 1;
843 >  ConfigGeneral.glines = 0;
844 >  ConfigGeneral.gline_time = 12 * 3600;
845 >  ConfigGeneral.gline_request_time = GLINE_REQUEST_EXPIRE_DEFAULT;
846 >  ConfigGeneral.gline_min_cidr = 16;
847 >  ConfigGeneral.gline_min_cidr6 = 48;
848 >  ConfigGeneral.invisible_on_connect = 1;
849 >  ConfigGeneral.tkline_expire_notices = 1;
850 >  ConfigGeneral.ignore_bogus_ts = 0;
851 >  ConfigGeneral.disable_auth = 0;
852 >  ConfigGeneral.kill_chase_time_limit = 90;
853 >  ConfigGeneral.default_floodcount = 8;
854 >  ConfigGeneral.failed_oper_notice = 1;
855 >  ConfigGeneral.dots_in_ident = 0;
856 >  ConfigGeneral.min_nonwildcard = 4;
857 >  ConfigGeneral.min_nonwildcard_simple = 3;
858 >  ConfigGeneral.max_accept = 20;
859 >  ConfigGeneral.anti_nick_flood = 0;
860 >  ConfigGeneral.max_nick_time = 20;
861 >  ConfigGeneral.max_nick_changes = 5;
862 >  ConfigGeneral.anti_spam_exit_message_time = 0;
863 >  ConfigGeneral.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
864 >  ConfigGeneral.ts_max_delta = TS_MAX_DELTA_DEFAULT;
865 >  ConfigGeneral.warn_no_connect_block = 1;
866 >  ConfigGeneral.stats_e_disabled = 0;
867 >  ConfigGeneral.stats_i_oper_only = 1;  /* 1 = masked */
868 >  ConfigGeneral.stats_k_oper_only = 1;  /* 1 = masked */
869 >  ConfigGeneral.stats_o_oper_only = 1;
870 >  ConfigGeneral.stats_m_oper_only = 1;
871 >  ConfigGeneral.stats_P_oper_only = 0;
872 >  ConfigGeneral.stats_u_oper_only = 0;
873 >  ConfigGeneral.caller_id_wait = 60;
874 >  ConfigGeneral.opers_bypass_callerid = 0;
875 >  ConfigGeneral.pace_wait = 10;
876 >  ConfigGeneral.pace_wait_simple = 1;
877 >  ConfigGeneral.short_motd = 0;
878 >  ConfigGeneral.ping_cookie = 0;
879 >  ConfigGeneral.no_oper_flood = 0;
880 >  ConfigGeneral.oper_pass_resv = 1;
881 >  ConfigGeneral.max_targets = MAX_TARGETS_DEFAULT;
882 >  ConfigGeneral.oper_only_umodes = UMODE_DEBUG | UMODE_LOCOPS | UMODE_HIDDEN | UMODE_FARCONNECT |
883 >                                   UMODE_UNAUTH | UMODE_EXTERNAL | UMODE_BOTS | UMODE_NCHANGE |
884 >                                   UMODE_SPY | UMODE_FULL | UMODE_SKILL | UMODE_REJ | UMODE_CCONN;
885 >  ConfigGeneral.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE | UMODE_WALLOP;
886 >  ConfigGeneral.throttle_count = 1;
887 >  ConfigGeneral.throttle_time = 1;
888 > }
889 >
890 > static void
891 > validate_conf(void)
892 > {
893 >  if (ConfigGeneral.ts_warn_delta < TS_WARN_DELTA_MIN)
894 >    ConfigGeneral.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
895 >
896 >  if (ConfigGeneral.ts_max_delta < TS_MAX_DELTA_MIN)
897 >    ConfigGeneral.ts_max_delta = TS_MAX_DELTA_DEFAULT;
898 >
899 >  if (EmptyString(ConfigServerInfo.network_name))
900 >    ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
901 >
902 >  if (EmptyString(ConfigServerInfo.network_desc))
903 >    ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
904 >
905 >  ConfigGeneral.max_watch = IRCD_MAX(ConfigGeneral.max_watch, WATCHSIZE_MIN);
906   }
907  
908 < /* read_conf()
908 > /* read_conf()
909   *
910   * inputs       - file descriptor pointing to config file to use
911   * output       - None
912   * side effects - Read configuration file.
913   */
914   static void
915 < read_conf(FBFILE *file)
915 > read_conf(FILE *file)
916   {
917    lineno = 0;
918  
919 <  set_default_conf(); /* Set default values prior to conf parsing */
919 >  set_default_conf();  /* Set default values prior to conf parsing */
920    conf_parser_ctx.pass = 1;
921 <  yyparse();          /* pick up the classes first */
921 >  yyparse();  /* Pick up the classes first */
922  
923 <  fbrewind(file);
923 >  rewind(file);
924  
925    conf_parser_ctx.pass = 2;
926 <  yyparse();          /* Load the values from the conf */
927 <  validate_conf();    /* Check to make sure some values are still okay. */
928 <                      /* Some global values are also loaded here. */
929 <  check_class();      /* Make sure classes are valid */
926 >  yyparse();  /* Load the values from the conf */
927 >  validate_conf();  /* Check to make sure some values are still okay. */
928 >                    /* Some global values are also loaded here. */
929 >  class_delete_marked();  /* Delete unused classes that are marked for deletion */
930   }
931  
932 < static void
933 < validate_conf(void)
932 > /* conf_rehash()
933 > *
934 > * Actual REHASH service routine. Called with sig == 0 if it has been called
935 > * as a result of an operator issuing this command, else assume it has been
936 > * called as a result of the server receiving a HUP signal.
937 > */
938 > void
939 > conf_rehash(int sig)
940   {
941 <  if (ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN)
942 <    ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
943 <
1982 <  if (ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN)
1983 <    ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
1984 <
1985 <  if (ConfigFileEntry.servlink_path == NULL)
1986 <    DupString(ConfigFileEntry.servlink_path, SLPATH);
1987 <
1988 <  if (ServerInfo.network_name == NULL)
1989 <    DupString(ServerInfo.network_name,NETWORK_NAME_DEFAULT);
941 >  if (sig)
942 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
943 >                         "Got signal SIGHUP, reloading configuration file(s)");
944  
945 <  if (ServerInfo.network_desc == NULL)
1992 <    DupString(ServerInfo.network_desc,NETWORK_DESC_DEFAULT);
945 >  restart_resolver();
946  
947 <  if (ConfigFileEntry.service_name == NULL)
1995 <    DupString(ConfigFileEntry.service_name, SERVICE_NAME_DEFAULT);
947 >  /* don't close listeners until we know we can go ahead with the rehash */
948  
949 <  if ((ConfigFileEntry.client_flood < CLIENT_FLOOD_MIN) ||
1998 <      (ConfigFileEntry.client_flood > CLIENT_FLOOD_MAX))
1999 <    ConfigFileEntry.client_flood = CLIENT_FLOOD_MAX;
949 >  read_conf_files(0);
950  
951 <  ConfigFileEntry.max_watch = IRCD_MAX(ConfigFileEntry.max_watch, WATCHSIZE_MIN);
951 >  load_conf_modules();
952 >  check_conf_klines();
953   }
954  
955   /* lookup_confhost()
# Line 2006 | Line 957 | validate_conf(void)
957   * start DNS lookups of all hostnames in the conf
958   * line and convert an IP addresses in a.b.c.d number for to IP#s.
959   */
960 < static void
961 < lookup_confhost(struct ConfItem *conf)
960 > void
961 > lookup_confhost(struct MaskItem *conf)
962   {
2012  struct AccessItem *aconf;
963    struct addrinfo hints, *res;
964  
965 <  aconf = map_to_conf(conf);
966 <
2017 <  if (EmptyString(aconf->host) ||
2018 <      EmptyString(aconf->user))
2019 <  {
2020 <    ilog(L_ERROR, "Host/server name error: (%s) (%s)",
2021 <         aconf->host, conf->name);
2022 <    return;
2023 <  }
2024 <
2025 <  if (strchr(aconf->host, '*') ||
2026 <      strchr(aconf->host, '?'))
2027 <    return;
2028 <
2029 <  /* Do name lookup now on hostnames given and store the
965 >  /*
966 >   * Do name lookup now on hostnames given and store the
967     * ip numbers in conf structure.
968     */
969    memset(&hints, 0, sizeof(hints));
# Line 2037 | Line 974 | lookup_confhost(struct ConfItem *conf)
974    /* Get us ready for a bind() and don't bother doing dns lookup */
975    hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
976  
977 <  if (getaddrinfo(aconf->host, NULL, &hints, &res))
977 >  if (getaddrinfo(conf->host, NULL, &hints, &res))
978    {
979 <    conf_dns_lookup(aconf);
979 >    conf_dns_lookup(conf);
980      return;
981    }
982  
983 <  assert(res != NULL);
983 >  assert(res);
984 >
985 >  memcpy(&conf->addr, res->ai_addr, res->ai_addrlen);
986 >  conf->addr.ss_len = res->ai_addrlen;
987 >  conf->addr.ss.ss_family = res->ai_family;
988  
2048  memcpy(&aconf->ipnum, res->ai_addr, res->ai_addrlen);
2049  aconf->ipnum.ss_len = res->ai_addrlen;
2050  aconf->ipnum.ss.ss_family = res->ai_family;
989    freeaddrinfo(res);
990   }
991  
# Line 2061 | Line 999 | lookup_confhost(struct ConfItem *conf)
999   int
1000   conf_connect_allowed(struct irc_ssaddr *addr, int aftype)
1001   {
1002 <  struct ip_entry *ip_found;
1003 <  struct AccessItem *aconf = find_dline_conf(addr, aftype);
1002 >  struct ip_entry *ip_found = NULL;
1003 >  struct MaskItem *const conf = find_dline_conf(addr, aftype);
1004  
1005    /* DLINE exempt also gets you out of static limits/pacing... */
1006 <  if (aconf && (aconf->status & CONF_EXEMPTDLINE))
1006 >  if (conf && (conf->type == CONF_EXEMPT))
1007      return 0;
1008  
1009 <  if (aconf != NULL)
1009 >  if (conf)
1010      return BANNED_CLIENT;
1011  
1012 <  ip_found = find_or_add_ip(addr);
1012 >  ip_found = ipcache_find_or_add_address(addr);
1013  
1014 <  if ((CurrentTime - ip_found->last_attempt) <
2077 <      ConfigFileEntry.throttle_time)
1014 >  if ((CurrentTime - ip_found->last_attempt) < ConfigGeneral.throttle_time)
1015    {
1016 <    ip_found->last_attempt = CurrentTime;
1017 <    return TOO_FAST;
1016 >    if (ip_found->connection_count >= ConfigGeneral.throttle_count)
1017 >      return TOO_FAST;
1018 >
1019 >    ++ip_found->connection_count;
1020    }
1021 +  else
1022 +    ip_found->connection_count = 1;
1023  
1024    ip_found->last_attempt = CurrentTime;
1025    return 0;
1026   }
1027  
1028 < static struct AccessItem *
2088 < find_regexp_kline(const char *uhi[])
2089 < {
2090 < #ifdef HAVE_LIBPCRE
2091 <  const dlink_node *ptr = NULL;
2092 <
2093 <  DLINK_FOREACH(ptr, rkconf_items.head)
2094 <  {
2095 <    struct AccessItem *aptr = map_to_conf(ptr->data);
2096 <
2097 <    assert(aptr->regexuser);
2098 <    assert(aptr->regexhost);
2099 <
2100 <    if (!ircd_pcre_exec(aptr->regexuser, uhi[0]) &&
2101 <        (!ircd_pcre_exec(aptr->regexhost, uhi[1]) ||
2102 <         !ircd_pcre_exec(aptr->regexhost, uhi[2])))
2103 <      return aptr;
2104 <  }
2105 < #endif
2106 <  return NULL;
2107 < }
2108 <
2109 < /* find_kill()
1028 > /* expire_tklines()
1029   *
1030 < * inputs       - pointer to client structure
1031 < * output       - pointer to struct AccessItem if found
1032 < * side effects - See if this user is klined already,
2114 < *                and if so, return struct AccessItem pointer
1030 > * inputs       - tkline list pointer
1031 > * output       - NONE
1032 > * side effects - expire tklines
1033   */
1034 < struct AccessItem *
1035 < find_kill(struct Client *client_p)
2118 < {
2119 <  struct AccessItem *aconf = NULL;
2120 <  const char *uhi[3];
2121 <
2122 <  uhi[0] = client_p->username;
2123 <  uhi[1] = client_p->host;
2124 <  uhi[2] = client_p->sockhost;
2125 <
2126 <  assert(client_p != NULL);
2127 <
2128 <  aconf = find_kline_conf(client_p->host, client_p->username,
2129 <                          &client_p->localClient->ip,
2130 <                          client_p->localClient->aftype);
2131 <  if (aconf == NULL)
2132 <    aconf = find_regexp_kline(uhi);
2133 <
2134 <  if (aconf && (aconf->status & CONF_KLINE))
2135 <    return aconf;
2136 <
2137 <  return NULL;
2138 < }
2139 <
2140 < struct AccessItem *
2141 < find_gline(struct Client *client_p)
1034 > static void
1035 > expire_tklines(dlink_list *list)
1036   {
1037 <  struct AccessItem *aconf;
1037 >  dlink_node *node = NULL, *node_next = NULL;
1038  
1039 <  assert(client_p != NULL);
1040 <
1041 <  aconf = find_gline_conf(client_p->host, client_p->username,
2148 <                          &client_p->localClient->ip,
2149 <                          client_p->localClient->aftype);
2150 <
2151 <  if (aconf && (aconf->status & CONF_GLINE))
2152 <    return aconf;
2153 <
2154 <  return NULL;
2155 < }
1039 >  DLINK_FOREACH_SAFE(node, node_next, list->head)
1040 >  {
1041 >    struct MaskItem *conf = node->data;
1042  
1043 < /* add_temp_line()
1044 < *
2159 < * inputs        - pointer to struct ConfItem
2160 < * output        - none
2161 < * Side effects  - links in given struct ConfItem into
2162 < *                 temporary *line link list
2163 < */
2164 < void
2165 < add_temp_line(struct ConfItem *conf)
2166 < {
2167 <  struct AccessItem *aconf;
1043 >    if (!conf->until || conf->until > CurrentTime)
1044 >      continue;
1045  
1046 <  if (conf->type == DLINE_TYPE)
1047 <  {
1048 <    aconf = map_to_conf(conf);
1049 <    SetConfTemporary(aconf);
1050 <    dlinkAdd(conf, &conf->node, &temporary_dlines);
1051 <    MyFree(aconf->user);
1052 <    aconf->user = NULL;
1053 <    add_conf_by_address(CONF_DLINE, aconf);
1054 <  }
1055 <  else if (conf->type == KLINE_TYPE)
1056 <  {
1057 <    aconf = map_to_conf(conf);
1058 <    SetConfTemporary(aconf);
1059 <    dlinkAdd(conf, &conf->node, &temporary_klines);
2183 <    add_conf_by_address(CONF_KILL, aconf);
2184 <  }
2185 <  else if (conf->type == GLINE_TYPE)
2186 <  {
2187 <    aconf = map_to_conf(conf);
2188 <    SetConfTemporary(aconf);
2189 <    dlinkAdd(conf, &conf->node, &temporary_glines);
2190 <    add_conf_by_address(CONF_GLINE, aconf);
2191 <  }
2192 <  else if (conf->type == XLINE_TYPE)
2193 <  {
2194 <    conf->flags |= CONF_FLAGS_TEMPORARY;
2195 <    dlinkAdd(conf, make_dlink_node(), &temporary_xlines);
2196 <  }
2197 <  else if (conf->type == RXLINE_TYPE)
2198 <  {
2199 <    conf->flags |= CONF_FLAGS_TEMPORARY;
2200 <    dlinkAdd(conf, make_dlink_node(), &temporary_rxlines);
2201 <  }
2202 <  else if (conf->type == RKLINE_TYPE)
2203 <  {
2204 <    conf->flags |= CONF_FLAGS_TEMPORARY;
2205 <    dlinkAdd(conf, make_dlink_node(), &temporary_rklines);
2206 <  }
2207 <  else if ((conf->type == NRESV_TYPE) || (conf->type == CRESV_TYPE))
2208 <  {
2209 <    conf->flags |= CONF_FLAGS_TEMPORARY;
2210 <    dlinkAdd(conf, make_dlink_node(), &temporary_resv);
1046 >    if (conf->type == CONF_XLINE)
1047 >    {
1048 >      if (ConfigGeneral.tkline_expire_notices)
1049 >        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1050 >                             "Temporary X-line for [%s] expired", conf->name);
1051 >      conf_free(conf);
1052 >    }
1053 >    else if (conf->type == CONF_NRESV || conf->type == CONF_CRESV)
1054 >    {
1055 >      if (ConfigGeneral.tkline_expire_notices)
1056 >        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1057 >                             "Temporary RESV for [%s] expired", conf->name);
1058 >      conf_free(conf);
1059 >    }
1060    }
1061   }
1062  
# Line 2219 | Line 1068 | add_temp_line(struct ConfItem *conf)
1068   *                This is an event started off in ircd.c
1069   */
1070   void
1071 < cleanup_tklines(void *notused)
1071 > cleanup_tklines(void *unused)
1072   {
1073 <  expire_tklines(&temporary_glines);
1074 <  expire_tklines(&temporary_klines);
1075 <  expire_tklines(&temporary_dlines);
1076 <  expire_tklines(&temporary_xlines);
2228 <  expire_tklines(&temporary_rxlines);
2229 <  expire_tklines(&temporary_rklines);
2230 <  expire_tklines(&temporary_resv);
2231 < }
2232 <
2233 < /* expire_tklines()
2234 < *
2235 < * inputs       - tkline list pointer
2236 < * output       - NONE
2237 < * side effects - expire tklines
2238 < */
2239 < static void
2240 < expire_tklines(dlink_list *tklist)
2241 < {
2242 <  dlink_node *ptr;
2243 <  dlink_node *next_ptr;
2244 <  struct ConfItem *conf;
2245 <  struct MatchItem *xconf;
2246 <  struct MatchItem *nconf;
2247 <  struct AccessItem *aconf;
2248 <  struct ResvChannel *cconf;
2249 <
2250 <  DLINK_FOREACH_SAFE(ptr, next_ptr, tklist->head)
2251 <  {
2252 <    conf = ptr->data;
2253 <    if (conf->type == GLINE_TYPE ||
2254 <        conf->type == KLINE_TYPE ||
2255 <        conf->type == DLINE_TYPE)
2256 <    {
2257 <      aconf = (struct AccessItem *)map_to_conf(conf);
2258 <      if (aconf->hold <= CurrentTime)
2259 <      {
2260 <        /* XXX - Do we want GLINE expiry notices?? */
2261 <        /* Alert opers that a TKline expired - Hwy */
2262 <        if (ConfigFileEntry.tkline_expire_notices)
2263 <        {
2264 <          if (aconf->status & CONF_KILL)
2265 <          {
2266 <            sendto_realops_flags(UMODE_ALL, L_ALL,
2267 <                                 "Temporary K-line for [%s@%s] expired",
2268 <                                 (aconf->user) ? aconf->user : "*",
2269 <                                 (aconf->host) ? aconf->host : "*");
2270 <          }
2271 <          else if (conf->type == DLINE_TYPE)
2272 <          {
2273 <            sendto_realops_flags(UMODE_ALL, L_ALL,
2274 <                                 "Temporary D-line for [%s] expired",
2275 <                                 (aconf->host) ? aconf->host : "*");
2276 <          }
2277 <        }
2278 <
2279 <        dlinkDelete(ptr, tklist);
2280 <        delete_one_address_conf(aconf->host, aconf);
2281 <      }
2282 <    }
2283 <    else if (conf->type == XLINE_TYPE ||
2284 <             conf->type == RXLINE_TYPE)
2285 <    {
2286 <      xconf = (struct MatchItem *)map_to_conf(conf);
2287 <      if (xconf->hold <= CurrentTime)
2288 <      {
2289 <        if (ConfigFileEntry.tkline_expire_notices)
2290 <          sendto_realops_flags(UMODE_ALL, L_ALL,
2291 <                               "Temporary X-line for [%s] %sexpired", conf->name,
2292 <                               conf->type == RXLINE_TYPE ? "(REGEX) " : "");
2293 <        dlinkDelete(ptr, tklist);
2294 <        free_dlink_node(ptr);
2295 <        delete_conf_item(conf);
2296 <      }
2297 <    }
2298 <    else if (conf->type == RKLINE_TYPE)
2299 <    {
2300 <      aconf = map_to_conf(conf);
2301 <      if (aconf->hold <= CurrentTime)
2302 <      {
2303 <        if (ConfigFileEntry.tkline_expire_notices)
2304 <           sendto_realops_flags(UMODE_ALL, L_ALL,
2305 <                                "Temporary K-line for [%s@%s] (REGEX) expired",
2306 <                                (aconf->user) ? aconf->user : "*",
2307 <                                (aconf->host) ? aconf->host : "*");
2308 <        dlinkDelete(ptr, tklist);
2309 <        free_dlink_node(ptr);
2310 <        delete_conf_item(conf);
2311 <      }
2312 <    }
2313 <    else if (conf->type == NRESV_TYPE)
2314 <    {
2315 <      nconf = (struct MatchItem *)map_to_conf(conf);
2316 <      if (nconf->hold <= CurrentTime)
2317 <      {
2318 <        if (ConfigFileEntry.tkline_expire_notices)
2319 <          sendto_realops_flags(UMODE_ALL, L_ALL,
2320 <                               "Temporary RESV for [%s] expired", conf->name);
2321 <        dlinkDelete(ptr, tklist);
2322 <        free_dlink_node(ptr);
2323 <        delete_conf_item(conf);
2324 <      }
2325 <    }
2326 <    else if (conf->type == CRESV_TYPE)
2327 <    {
2328 <      cconf = (struct ResvChannel *)map_to_conf(conf);
2329 <      if (cconf->hold <= CurrentTime)
2330 <      {
2331 <        if (ConfigFileEntry.tkline_expire_notices)
2332 <          sendto_realops_flags(UMODE_ALL, L_ALL,
2333 <                               "Temporary RESV for [%s] expired", cconf->name);
2334 <        delete_channel_resv(cconf);
2335 <      }
2336 <    }
2337 <  }
1073 >  hostmask_expire_temporary();
1074 >  expire_tklines(&xconf_items);
1075 >  expire_tklines(&nresv_items);
1076 >  expire_tklines(&cresv_items);
1077   }
1078  
1079   /* oper_privs_as_string()
# Line 2345 | Line 1084 | expire_tklines(dlink_list *tklist)
1084   */
1085   static const struct oper_privs
1086   {
1087 <  const unsigned int oprivs;
2349 <  const unsigned int hidden;
1087 >  const unsigned int flag;
1088    const unsigned char c;
1089   } flag_list[] = {
1090 <  { OPER_FLAG_ADMIN,       OPER_FLAG_HIDDEN_ADMIN,  'A' },
1091 <  { OPER_FLAG_REMOTEBAN,   0,                       'B' },
1092 <  { OPER_FLAG_DIE,         0,                       'D' },
1093 <  { OPER_FLAG_GLINE,       0,                       'G' },
1094 <  { OPER_FLAG_REHASH,      0,                       'H' },
1095 <  { OPER_FLAG_K,           0,                       'K' },
1096 <  { OPER_FLAG_OPERWALL,    0,                       'L' },
1097 <  { OPER_FLAG_N,           0,                       'N' },
1098 <  { OPER_FLAG_GLOBAL_KILL, 0,                       'O' },
1099 <  { OPER_FLAG_REMOTE,      0,                       'R' },
1100 <  { OPER_FLAG_OPER_SPY,    0,                       'S' },
1101 <  { OPER_FLAG_UNKLINE,     0,                       'U' },
1102 <  { OPER_FLAG_X,           0,                       'X' },
1103 <  { 0, 0, '\0' }
1090 >  { OPER_FLAG_ADMIN,          'A' },
1091 >  { OPER_FLAG_REMOTEBAN,      'B' },
1092 >  { OPER_FLAG_DIE,            'D' },
1093 >  { OPER_FLAG_GLINE,          'G' },
1094 >  { OPER_FLAG_REHASH,         'H' },
1095 >  { OPER_FLAG_KLINE,          'K' },
1096 >  { OPER_FLAG_KILL,           'N' },
1097 >  { OPER_FLAG_KILL_REMOTE,    'O' },
1098 >  { OPER_FLAG_CONNECT,        'P' },
1099 >  { OPER_FLAG_CONNECT_REMOTE, 'Q' },
1100 >  { OPER_FLAG_SQUIT,          'R' },
1101 >  { OPER_FLAG_SQUIT_REMOTE,   'S' },
1102 >  { OPER_FLAG_UNKLINE,        'U' },
1103 >  { OPER_FLAG_XLINE,          'X' },
1104 >  { 0, '\0' }
1105   };
1106  
1107 < char *
1107 > const char *
1108   oper_privs_as_string(const unsigned int port)
1109   {
1110 <  static char privs_out[16];
1110 >  static char privs_out[IRCD_BUFSIZE];
1111    char *privs_ptr = privs_out;
2373  unsigned int i = 0;
1112  
1113 <  for (; flag_list[i].oprivs; ++i)
1113 >  for (const struct oper_privs *opriv = flag_list; opriv->flag; ++opriv)
1114    {
1115 <    if ((port & flag_list[i].oprivs) &&
1116 <        (port & flag_list[i].hidden) == 0)
2379 <      *privs_ptr++ = flag_list[i].c;
1115 >    if (port & opriv->flag)
1116 >      *privs_ptr++ = opriv->c;
1117      else
1118 <      *privs_ptr++ = ToLowerTab[flag_list[i].c];
1118 >      *privs_ptr++ = ToLower(opriv->c);
1119    }
1120  
1121    *privs_ptr = '\0';
# Line 2387 | Line 1124 | oper_privs_as_string(const unsigned int
1124   }
1125  
1126   /*
1127 < * Input: A client to find the active oper{} name for.
1127 > * Input: A client to find the active operator {} name for.
1128   * Output: The nick!user@host{oper} of the oper.
1129   *         "oper" is server name for remote opers
1130   * Side effects: None.
1131   */
1132 < char *
1132 > const char *
1133   get_oper_name(const struct Client *client_p)
1134   {
1135 <  dlink_node *cnode;
2399 <  struct ConfItem *conf;
2400 <  struct AccessItem *aconf;
1135 >  static char buffer[IRCD_BUFSIZE];
1136  
1137 <  /* +5 for !,@,{,} and null */
1138 <  static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5];
1137 >  if (IsServer(client_p))
1138 >    return client_p->name;
1139  
1140    if (MyConnect(client_p))
1141    {
1142 <    DLINK_FOREACH(cnode, client_p->localClient->confs.head)
1142 >    const dlink_node *const node = client_p->connection->confs.head;
1143 >
1144 >    if (node)
1145      {
1146 <      conf = cnode->data;
2410 <      aconf = map_to_conf(conf);
1146 >      const struct MaskItem *const conf = node->data;
1147  
1148 <      if (IsConfOperator(aconf))
1148 >      if (conf->type == CONF_OPER)
1149        {
1150 <        snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1150 >        snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1151                   client_p->username, client_p->host, conf->name);
1152 <        return buffer;
1152 >        return buffer;
1153        }
1154      }
1155  
1156 <    /* Probably should assert here for now. If there is an oper out there
1157 <     * with no oper{} conf attached, it would be good for us to know...
1156 >    /*
1157 >     * Probably should assert here for now. If there is an oper out there
1158 >     * with no operator {} conf attached, it would be good for us to know...
1159       */
1160 <    assert(0); /* Oper without oper conf! */
1160 >    assert(0);  /* Oper without oper conf! */
1161    }
1162  
1163    snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1164 <           client_p->username, client_p->host, client_p->servptr->name);
1164 >           client_p->username, client_p->host, client_p->servptr->name);
1165    return buffer;
1166   }
1167  
2431 /* read_conf_files()
2432 *
2433 * inputs       - cold start YES or NO
2434 * output       - none
2435 * side effects - read all conf files needed, ircd.conf kline.conf etc.
2436 */
2437 void
2438 read_conf_files(int cold)
2439 {
2440  const char *filename;
2441  char chanmodes[32];
2442  char chanlimit[32];
2443
2444  conf_parser_ctx.boot = cold;
2445  filename = get_conf_name(CONF_TYPE);
2446
2447  /* We need to know the initial filename for the yyerror() to report
2448     FIXME: The full path is in conffilenamebuf first time since we
2449             dont know anything else
2450
2451     - Gozem 2002-07-21
2452  */
2453  strlcpy(conffilebuf, filename, sizeof(conffilebuf));
2454
2455  if ((conf_parser_ctx.conf_file = fbopen(filename, "r")) == NULL)
2456  {
2457    if (cold)
2458    {
2459      ilog(L_CRIT, "Unable to read configuration file '%s': %s",
2460           filename, strerror(errno));
2461      exit(-1);
2462    }
2463    else
2464    {
2465      sendto_realops_flags(UMODE_ALL, L_ALL,
2466                           "Unable to read configuration file '%s': %s",
2467                           filename, strerror(errno));
2468      return;
2469    }
2470  }
2471
2472  if (!cold)
2473    clear_out_old_conf();
2474
2475  read_conf(conf_parser_ctx.conf_file);
2476  fbclose(conf_parser_ctx.conf_file);
2477
2478  add_isupport("NETWORK", ServerInfo.network_name, -1);
2479  snprintf(chanmodes, sizeof(chanmodes), "b%s%s:%d",
2480           ConfigChannel.use_except ? "e" : "",
2481           ConfigChannel.use_invex ? "I" : "", ConfigChannel.max_bans);
2482  add_isupport("MAXLIST", chanmodes, -1);
2483  add_isupport("MAXTARGETS", NULL, ConfigFileEntry.max_targets);
2484
2485  if (ConfigChannel.disable_local_channels)
2486    add_isupport("CHANTYPES", "#", -1);
2487  else
2488    add_isupport("CHANTYPES", "#&", -1);
2489
2490  snprintf(chanlimit, sizeof(chanlimit), "%s:%d",
2491           ConfigChannel.disable_local_channels ? "#" : "#&",
2492           ConfigChannel.max_chans_per_user);
2493  add_isupport("CHANLIMIT", chanlimit, -1);
2494  snprintf(chanmodes, sizeof(chanmodes), "%s%s%s",
2495           ConfigChannel.use_except ? "e" : "",
2496           ConfigChannel.use_invex ? "I" : "", "b,k,l,imnpstOS");
2497  add_isupport("CHANNELLEN", NULL, LOCAL_CHANNELLEN);
2498
2499  if (ConfigChannel.use_except)
2500    add_isupport("EXCEPTS", "e", -1);
2501  if (ConfigChannel.use_invex)
2502    add_isupport("INVEX", "I", -1);
2503  add_isupport("CHANMODES", chanmodes, -1);
2504
2505  /*
2506   * message_locale may have changed.  rebuild isupport since it relies
2507   * on strlen(form_str(RPL_ISUPPORT))
2508   */
2509  rebuild_isupport_message_line();
2510
2511 #ifdef HAVE_LIBPCRE
2512  parse_conf_file(RKLINE_TYPE, cold);
2513  parse_conf_file(RXLINE_TYPE, cold);
2514 #endif
2515  parse_conf_file(KLINE_TYPE, cold);
2516  parse_conf_file(DLINE_TYPE, cold);
2517  parse_conf_file(XLINE_TYPE, cold);
2518  parse_conf_file(NRESV_TYPE, cold);
2519  parse_conf_file(CRESV_TYPE, cold);
2520 }
2521
2522 /* parse_conf_file()
2523 *
2524 * inputs       - type of conf file to parse
2525 * output       - none
2526 * side effects - conf file for givenconf type is opened and read then parsed
2527 */
2528 static void
2529 parse_conf_file(int type, int cold)
2530 {
2531  FBFILE *file = NULL;
2532  const char *filename = get_conf_name(type);
2533
2534  if ((file = fbopen(filename, "r")) == NULL)
2535  {
2536    if (cold)
2537      ilog(L_ERROR, "Unable to read configuration file '%s': %s",
2538           filename, strerror(errno));
2539    else
2540      sendto_realops_flags(UMODE_ALL, L_ALL,
2541                    "Unable to read configuration file '%s': %s",
2542                           filename, strerror(errno));
2543  }
2544  else
2545  {
2546    parse_csv_file(file, type);
2547    fbclose(file);
2548  }
2549 }
2550
1168   /* clear_out_old_conf()
1169   *
1170   * inputs       - none
# Line 2557 | Line 1174 | parse_conf_file(int type, int cold)
1174   static void
1175   clear_out_old_conf(void)
1176   {
1177 <  dlink_node *ptr = NULL, *next_ptr = NULL;
2561 <  struct ConfItem *conf;
2562 <  struct AccessItem *aconf;
2563 <  struct ClassItem *cltmp;
2564 <  struct MatchItem *match_item;
1177 >  dlink_node *node = NULL, *node_next = NULL;
1178    dlink_list *free_items [] = {
1179 <    &server_items,   &oconf_items,    &hub_items, &leaf_items,
1180 <     &uconf_items,   &xconf_items, &rxconf_items, &rkconf_items,
1181 <     &nresv_items, &cluster_items,  &gdeny_items, &service_items, NULL
1179 >    &server_items,   &oconf_items,
1180 >     &uconf_items,   &xconf_items,
1181 >     &nresv_items, &cluster_items,  &service_items, &cresv_items, NULL
1182    };
1183  
1184    dlink_list ** iterator = free_items; /* C is dumb */
# Line 2573 | Line 1186 | clear_out_old_conf(void)
1186    /* We only need to free anything allocated by yyparse() here.
1187     * Resetting structs, etc, is taken care of by set_default_conf().
1188     */
1189 <  
1190 <  for (; *iterator != NULL; iterator++)
1189 >
1190 >  for (; *iterator; iterator++)
1191    {
1192 <    DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head)
1192 >    DLINK_FOREACH_SAFE(node, node_next, (*iterator)->head)
1193      {
1194 <      conf = ptr->data;
2582 <      /* XXX This is less than pretty */
2583 <      if (conf->type == SERVER_TYPE)
2584 <      {
2585 <        aconf = map_to_conf(conf);
1194 >      struct MaskItem *conf = node->data;
1195  
1196 <        if (aconf->clients != 0)
1197 <        {
2589 <          SetConfIllegal(aconf);
2590 <          dlinkDelete(&conf->node, &server_items);
2591 <        }
2592 <        else
2593 <        {
2594 <          delete_conf_item(conf);
2595 <        }
2596 <      }
2597 <      else if (conf->type == OPER_TYPE)
2598 <      {
2599 <        aconf = map_to_conf(conf);
1196 >      conf->active = 0;
1197 >      dlinkDelete(&conf->node, *iterator);
1198  
1199 <        if (aconf->clients != 0)
1200 <        {
2603 <          SetConfIllegal(aconf);
2604 <          dlinkDelete(&conf->node, &oconf_items);
2605 <        }
2606 <        else
2607 <        {
2608 <          delete_conf_item(conf);
2609 <        }
2610 <      }
2611 <      else if (conf->type == CLIENT_TYPE)
1199 >      /* XXX This is less than pretty */
1200 >      if (conf->type == CONF_SERVER || conf->type == CONF_OPER)
1201        {
1202 <        aconf = map_to_conf(conf);
1203 <
2615 <        if (aconf->clients != 0)
2616 <        {
2617 <          SetConfIllegal(aconf);
2618 <        }
2619 <        else
2620 <        {
2621 <          delete_conf_item(conf);
2622 <        }
1202 >        if (!conf->ref_count)
1203 >          conf_free(conf);
1204        }
1205 <      else if (conf->type == XLINE_TYPE  ||
2625 <               conf->type == RXLINE_TYPE ||
2626 <               conf->type == RKLINE_TYPE)
1205 >      else if (conf->type == CONF_XLINE)
1206        {
1207 <        /* temporary (r)xlines are also on
1208 <         * the (r)xconf items list */
2630 <        if (conf->flags & CONF_FLAGS_TEMPORARY)
2631 <          continue;
2632 <
2633 <        delete_conf_item(conf);
1207 >        if (!conf->until)
1208 >          conf_free(conf);
1209        }
1210        else
1211 <      {
2637 <        if ((conf->type == LEAF_TYPE) || (conf->type == HUB_TYPE))
2638 <        {
2639 <          match_item = map_to_conf(conf);
2640 <          if (match_item->ref_count <= 0)
2641 <            delete_conf_item(conf);
2642 <          else
2643 <          {
2644 <            match_item->illegal = 1;
2645 <            dlinkDelete(&conf->node, *iterator);
2646 <          }
2647 <        }
2648 <        else
2649 <          delete_conf_item(conf);
2650 <      }
1211 >        conf_free(conf);
1212      }
1213    }
1214  
1215 +  motd_clear();
1216 +
1217    /*
1218 <   * don't delete the class table, rather mark all entries
1219 <   * for deletion. The table is cleaned up by check_class. - avalon
1218 >   * Don't delete the class table, rather mark all entries for deletion.
1219 >   * The table is cleaned up by class_delete_marked. - avalon
1220     */
1221 <  DLINK_FOREACH(ptr, class_items.head)
2659 <  {
2660 <    cltmp = map_to_conf(ptr->data);
2661 <
2662 <    if (ptr != class_items.tail)  /* never mark the "default" class */
2663 <      cltmp->active = 0;
2664 <  }
1221 >  class_mark_for_deletion();
1222  
1223    clear_out_address_conf();
1224  
1225 <  /* clean out module paths */
1225 >  /* Clean out module paths */
1226    mod_clear_paths();
1227  
1228 <  /* clean out ServerInfo */
1229 <  MyFree(ServerInfo.description);
1230 <  ServerInfo.description = NULL;
1231 <  MyFree(ServerInfo.network_name);
1232 <  ServerInfo.network_name = NULL;
1233 <  MyFree(ServerInfo.network_desc);
1234 <  ServerInfo.network_desc = NULL;
1235 <  MyFree(ConfigFileEntry.egdpool_path);
1236 <  ConfigFileEntry.egdpool_path = NULL;
1228 >  pseudo_clear();
1229 >
1230 >  /* Clean out ConfigServerInfo */
1231 >  MyFree(ConfigServerInfo.description);
1232 >  ConfigServerInfo.description = NULL;
1233 >  MyFree(ConfigServerInfo.network_name);
1234 >  ConfigServerInfo.network_name = NULL;
1235 >  MyFree(ConfigServerInfo.network_desc);
1236 >  ConfigServerInfo.network_desc = NULL;
1237   #ifdef HAVE_LIBCRYPTO
1238 <  if (ServerInfo.rsa_private_key != NULL)
1238 >  if (ConfigServerInfo.rsa_private_key)
1239    {
1240 <    RSA_free(ServerInfo.rsa_private_key);
1241 <    ServerInfo.rsa_private_key = NULL;
1240 >    RSA_free(ConfigServerInfo.rsa_private_key);
1241 >    ConfigServerInfo.rsa_private_key = NULL;
1242    }
1243  
1244 <  MyFree(ServerInfo.rsa_private_key_file);
1245 <  ServerInfo.rsa_private_key_file = NULL;
1244 >  MyFree(ConfigServerInfo.rsa_private_key_file);
1245 >  ConfigServerInfo.rsa_private_key_file = NULL;
1246   #endif
1247  
1248 <  /* clean out old resvs from the conf */
1249 <  clear_conf_resv();
1250 <
1251 <  /* clean out AdminInfo */
1252 <  MyFree(AdminInfo.name);
1253 <  AdminInfo.name = NULL;
1254 <  MyFree(AdminInfo.email);
2698 <  AdminInfo.email = NULL;
2699 <  MyFree(AdminInfo.description);
2700 <  AdminInfo.description = NULL;
1248 >  /* Clean out ConfigAdminInfo */
1249 >  MyFree(ConfigAdminInfo.name);
1250 >  ConfigAdminInfo.name = NULL;
1251 >  MyFree(ConfigAdminInfo.email);
1252 >  ConfigAdminInfo.email = NULL;
1253 >  MyFree(ConfigAdminInfo.description);
1254 >  ConfigAdminInfo.description = NULL;
1255  
1256 <  /* operator{} and class{} blocks are freed above */
2703 <  /* clean out listeners */
1256 >  /* Clean out listeners */
1257    close_listeners();
2705
2706  /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{},
2707   * exempt{} and gecos{} blocks are freed above too
2708   */
2709
2710  /* clean out general */
2711  MyFree(ConfigFileEntry.service_name);
2712  ConfigFileEntry.service_name = NULL;
2713
2714  MyFree(ConfigFileEntry.servlink_path);
2715  ConfigFileEntry.servlink_path = NULL;
2716 #ifdef HAVE_LIBCRYPTO
2717  ConfigFileEntry.default_cipher_preference = NULL;
2718 #endif /* HAVE_LIBCRYPTO */
2719  delete_isupport("INVEX");
2720  delete_isupport("EXCEPTS");
1258   }
1259  
1260 < /* flush_deleted_I_P()
1260 > /* read_conf_files()
1261   *
1262 < * inputs       - none
1262 > * inputs       - cold start YES or NO
1263   * output       - none
1264 < * side effects - This function removes I/P conf items
1264 > * side effects - read all conf files needed, ircd.conf kline.conf etc.
1265   */
1266 < static void
1267 < flush_deleted_I_P(void)
1266 > void
1267 > read_conf_files(int cold)
1268   {
1269 <  dlink_node *ptr;
1270 <  dlink_node *next_ptr;
1271 <  struct ConfItem *conf;
2735 <  struct AccessItem *aconf;
2736 <  dlink_list * free_items [] = {
2737 <    &server_items, &oconf_items, NULL
2738 <  };
2739 <  dlink_list ** iterator = free_items; /* C is dumb */
2740 <
2741 <  /* flush out deleted I and P lines
2742 <   * although still in use.
2743 <   */
2744 <  for (; *iterator != NULL; iterator++)
2745 <  {
2746 <    DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head)
2747 <    {
2748 <      conf = ptr->data;
2749 <      aconf = (struct AccessItem *)map_to_conf(conf);
2750 <
2751 <      if (IsConfIllegal(aconf))
2752 <      {
2753 <        dlinkDelete(ptr, *iterator);
1269 >  const char *filename = NULL;
1270 >  char chanmodes[IRCD_BUFSIZE] = "";
1271 >  char chanlimit[IRCD_BUFSIZE] = "";
1272  
1273 <        if (aconf->clients == 0)
1274 <          delete_conf_item(conf);
2757 <      }
2758 <    }
2759 <  }
2760 < }
2761 <
2762 < /* get_conf_name()
2763 < *
2764 < * inputs       - type of conf file to return name of file for
2765 < * output       - pointer to filename for type of conf
2766 < * side effects - none
2767 < */
2768 < const char *
2769 < get_conf_name(ConfType type)
2770 < {
2771 <  switch (type)
2772 <  {
2773 <    case CONF_TYPE:
2774 <      return ConfigFileEntry.configfile;
2775 <      break;
2776 <    case KLINE_TYPE:
2777 <      return ConfigFileEntry.klinefile;
2778 <      break;
2779 <    case RKLINE_TYPE:
2780 <      return ConfigFileEntry.rklinefile;
2781 <      break;
2782 <    case DLINE_TYPE:
2783 <      return ConfigFileEntry.dlinefile;
2784 <      break;
2785 <    case XLINE_TYPE:
2786 <      return ConfigFileEntry.xlinefile;
2787 <      break;
2788 <    case RXLINE_TYPE:
2789 <      return ConfigFileEntry.rxlinefile;
2790 <      break;
2791 <    case CRESV_TYPE:
2792 <      return ConfigFileEntry.cresvfile;
2793 <      break;
2794 <    case NRESV_TYPE:
2795 <      return ConfigFileEntry.nresvfile;
2796 <      break;
2797 <    case GLINE_TYPE:
2798 <      return ConfigFileEntry.glinefile;
2799 <      break;
2800 <
2801 <    default:
2802 <      return NULL;  /* This should NEVER HAPPEN since we call this function
2803 <                       only with the above values, this will cause us to core
2804 <                       at some point if this happens so we know where it was */
2805 <  }
2806 < }
1273 >  conf_parser_ctx.boot = cold;
1274 >  filename = ConfigGeneral.configfile;
1275  
1276 < #define BAD_PING (-1)
1276 >  /* We need to know the initial filename for the yyerror() to report
1277 >     FIXME: The full path is in conffilenamebuf first time since we
1278 >             don't know anything else
1279  
1280 < /* get_conf_ping()
1281 < *
1282 < * inputs       - pointer to struct AccessItem
2813 < *              - pointer to a variable that receives ping warning time
2814 < * output       - ping frequency
2815 < * side effects - NONE
2816 < */
2817 < static int
2818 < get_conf_ping(struct ConfItem *conf, int *pingwarn)
2819 < {
2820 <  struct ClassItem *aclass;
2821 <  struct AccessItem *aconf;
1280 >     - Gozem 2002-07-21
1281 >  */
1282 >  strlcpy(conffilebuf, filename, sizeof(conffilebuf));
1283  
1284 <  if (conf != NULL)
1284 >  if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL)
1285    {
1286 <    aconf = (struct AccessItem *)map_to_conf(conf);
2826 <    if (aconf->class_ptr != NULL)
1286 >    if (cold)
1287      {
1288 <      aclass = (struct ClassItem *)map_to_conf(aconf->class_ptr);
1289 <      *pingwarn = PingWarning(aclass);
1290 <      return PingFreq(aclass);
1288 >      ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
1289 >           filename, strerror(errno));
1290 >      exit(-1);
1291      }
1292 <  }
2833 <
2834 <  return BAD_PING;
2835 < }
2836 <
2837 < /* get_client_class()
2838 < *
2839 < * inputs       - pointer to client struct
2840 < * output       - pointer to name of class
2841 < * side effects - NONE
2842 < */
2843 < const char *
2844 < get_client_class(struct Client *target_p)
2845 < {
2846 <  dlink_node *ptr;
2847 <  struct ConfItem *conf;
2848 <  struct AccessItem *aconf;
2849 <
2850 <  if (target_p != NULL && !IsMe(target_p) &&
2851 <      target_p->localClient->confs.head != NULL)
2852 <  {
2853 <    DLINK_FOREACH(ptr, target_p->localClient->confs.head)
1292 >    else
1293      {
1294 <      conf = ptr->data;
1295 <
1296 <      if (conf->type == CLIENT_TYPE || conf->type == SERVER_TYPE ||
1297 <          conf->type == OPER_TYPE)
2859 <      {
2860 <        aconf = (struct AccessItem *) map_to_conf(conf);
2861 <        if (aconf->class_ptr != NULL)
2862 <          return aconf->class_ptr->name;
2863 <      }
1294 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1295 >                           "Unable to read configuration file '%s': %s",
1296 >                           filename, strerror(errno));
1297 >      return;
1298      }
1299    }
1300  
1301 <  return "default";
1302 < }
2869 <
2870 < /* get_client_ping()
2871 < *
2872 < * inputs       - pointer to client struct
2873 < *              - pointer to a variable that receives ping warning time
2874 < * output       - ping frequency
2875 < * side effects - NONE
2876 < */
2877 < int
2878 < get_client_ping(struct Client *target_p, int *pingwarn)
2879 < {
2880 <  int ping;
2881 <  struct ConfItem *conf;
2882 <  dlink_node *nlink;
2883 <
2884 <  if (target_p->localClient->confs.head != NULL)
2885 <    DLINK_FOREACH(nlink, target_p->localClient->confs.head)
2886 <    {
2887 <      conf = nlink->data;
2888 <
2889 <      if ((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2890 <          (conf->type == OPER_TYPE))
2891 <      {
2892 <        ping = get_conf_ping(conf, pingwarn);
2893 <        if (ping > 0)
2894 <          return ping;
2895 <      }
2896 <    }
2897 <
2898 <  *pingwarn = 0;
2899 <  return DEFAULT_PINGFREQUENCY;
2900 < }
2901 <
2902 < /* find_class()
2903 < *
2904 < * inputs       - string name of class
2905 < * output       - corresponding Class pointer
2906 < * side effects - NONE
2907 < */
2908 < struct ConfItem *
2909 < find_class(const char *classname)
2910 < {
2911 <  struct ConfItem *conf;
2912 <
2913 <  if ((conf = find_exact_name_conf(CLASS_TYPE, classname, NULL, NULL)) != NULL)
2914 <    return conf;
2915 <
2916 <  return class_default;
2917 < }
2918 <
2919 < /* check_class()
2920 < *
2921 < * inputs       - NONE
2922 < * output       - NONE
2923 < * side effects -
2924 < */
2925 < void
2926 < check_class(void)
2927 < {
2928 <  dlink_node *ptr = NULL, *next_ptr = NULL;
2929 <
2930 <  DLINK_FOREACH_SAFE(ptr, next_ptr, class_items.head)
2931 <  {
2932 <    struct ClassItem *aclass = map_to_conf(ptr->data);
2933 <
2934 <    if (!aclass->active && !CurrUserCount(aclass))
2935 <    {
2936 <      destroy_cidr_class(aclass);
2937 <      delete_conf_item(ptr->data);
2938 <    }
2939 <  }
2940 < }
1301 >  if (!cold)
1302 >    clear_out_old_conf();
1303  
1304 < /* init_class()
1305 < *
2944 < * inputs       - NONE
2945 < * output       - NONE
2946 < * side effects -
2947 < */
2948 < void
2949 < init_class(void)
2950 < {
2951 <  struct ClassItem *aclass;
1304 >  read_conf(conf_parser_ctx.conf_file);
1305 >  fclose(conf_parser_ctx.conf_file);
1306  
1307 <  class_default = make_conf_item(CLASS_TYPE);
1307 >  log_reopen_all();
1308  
1309 <  aclass = map_to_conf(class_default);
1310 <  aclass->active = 1;
2957 <  DupString(class_default->name, "default");
2958 <  ConFreq(aclass)  = DEFAULT_CONNECTFREQUENCY;
2959 <  PingFreq(aclass) = DEFAULT_PINGFREQUENCY;
2960 <  MaxTotal(aclass) = MAXIMUM_LINKS_DEFAULT;
2961 <  MaxSendq(aclass) = DEFAULT_SENDQ;
1309 >  add_isupport("NICKLEN", NULL, ConfigServerInfo.max_nick_length);
1310 >  add_isupport("NETWORK", ConfigServerInfo.network_name, -1);
1311  
1312 <  client_check_cb = register_callback("check_client", check_client);
1313 < }
1312 >  snprintf(chanmodes, sizeof(chanmodes), "beI:%d", ConfigChannel.max_bans);
1313 >  add_isupport("MAXLIST", chanmodes, -1);
1314 >  add_isupport("MAXTARGETS", NULL, ConfigGeneral.max_targets);
1315 >  add_isupport("CHANTYPES", "#", -1);
1316  
1317 < /* get_sendq()
1318 < *
1319 < * inputs       - pointer to client
1320 < * output       - sendq for this client as found from its class
1321 < * side effects - NONE
1322 < */
1323 < unsigned int
2973 < get_sendq(struct Client *client_p)
2974 < {
2975 <  unsigned int sendq = DEFAULT_SENDQ;
2976 <  dlink_node *ptr;
2977 <  struct ConfItem *conf;
2978 <  struct ConfItem *class_conf;
2979 <  struct ClassItem *aclass;
2980 <  struct AccessItem *aconf;
1317 >  snprintf(chanlimit, sizeof(chanlimit), "#:%d",
1318 >           ConfigChannel.max_channels);
1319 >  add_isupport("CHANLIMIT", chanlimit, -1);
1320 >  snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,cimnprstCMORS");
1321 >  add_isupport("CHANNELLEN", NULL, CHANNELLEN);
1322 >  add_isupport("TOPICLEN", NULL, ConfigServerInfo.max_topic_length);
1323 >  add_isupport("CHANMODES", chanmodes, -1);
1324  
1325 <  if (client_p && !IsMe(client_p) && (client_p->localClient->confs.head))
1326 <  {
1327 <    DLINK_FOREACH(ptr, client_p->localClient->confs.head)
2985 <    {
2986 <      conf = ptr->data;
2987 <      if ((conf->type == SERVER_TYPE) || (conf->type == OPER_TYPE)
2988 <          || (conf->type == CLIENT_TYPE))
2989 <      {
2990 <        aconf = (struct AccessItem *)map_to_conf(conf);
2991 <        if ((class_conf = aconf->class_ptr) == NULL)
2992 <          continue;
2993 <        aclass = (struct ClassItem *)map_to_conf(class_conf);
2994 <        sendq = MaxSendq(aclass);
2995 <        return sendq;
2996 <      }
2997 <    }
2998 <  }
2999 <  /* XXX return a default?
3000 <   * if here, then there wasn't an attached conf with a sendq
3001 <   * that is very bad -Dianora
1325 >  /*
1326 >   * message_locale may have changed.  rebuild isupport since it relies
1327 >   * on strlen(form_str(RPL_ISUPPORT))
1328     */
1329 <  return DEFAULT_SENDQ;
1329 >  rebuild_isupport_message_line();
1330   }
1331  
1332   /* conf_add_class_to_conf()
1333   *
1334   * inputs       - pointer to config item
1335   * output       - NONE
1336 < * side effects - Add a class pointer to a conf
1336 > * side effects - Add a class pointer to a conf
1337   */
1338   void
1339 < conf_add_class_to_conf(struct ConfItem *conf, const char *class_name)
1339 > conf_add_class_to_conf(struct MaskItem *conf, const char *class_name)
1340   {
1341 <  struct AccessItem *aconf = map_to_conf(conf);
3016 <  struct ClassItem *class = NULL;
3017 <
3018 <  if (class_name == NULL)
1341 >  if (class_name == NULL)
1342    {
1343 <    aconf->class_ptr = class_default;
1343 >    conf->class = class_default;
1344  
1345 <    if (conf->type == CLIENT_TYPE)
1346 <      sendto_realops_flags(UMODE_ALL, L_ALL,
1347 <                           "Warning *** Defaulting to default class for %s@%s",
1348 <                           aconf->user, aconf->host);
1345 >    if (conf->type == CONF_CLIENT || conf->type == CONF_OPER)
1346 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1347 >                           "Warning *** Defaulting to default class for %s@%s",
1348 >                           conf->user, conf->host);
1349      else
1350 <      sendto_realops_flags(UMODE_ALL, L_ALL,
1351 <                           "Warning *** Defaulting to default class for %s",
1352 <                           conf->name);
1350 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1351 >                           "Warning *** Defaulting to default class for %s",
1352 >                           conf->name);
1353    }
1354    else
1355 <    aconf->class_ptr = find_class(class_name);
3033 <
3034 <  if (aconf->class_ptr)
3035 <    class = map_to_conf(aconf->class_ptr);
1355 >    conf->class = class_find(class_name, 1);
1356  
1357 <  if (aconf->class_ptr == NULL || !class->active)
1357 >  if (conf->class == NULL)
1358    {
1359 <    if (conf->type == CLIENT_TYPE)
1360 <      sendto_realops_flags(UMODE_ALL, L_ALL,
1361 <                           "Warning *** Defaulting to default class for %s@%s",
1362 <                           aconf->user, aconf->host);
1359 >    if (conf->type == CONF_CLIENT || conf->type == CONF_OPER)
1360 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1361 >                           "Warning *** Defaulting to default class for %s@%s",
1362 >                           conf->user, conf->host);
1363      else
1364 <      sendto_realops_flags(UMODE_ALL, L_ALL,
1365 <                           "Warning *** Defaulting to default class for %s",
1366 <                           conf->name);
1367 <    aconf->class_ptr = class_default;
1364 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1365 >                           "Warning *** Defaulting to default class for %s",
1366 >                           conf->name);
1367 >    conf->class = class_default;
1368    }
1369   }
1370  
3051 /* conf_add_server()
3052 *
3053 * inputs       - pointer to config item
3054 *              - pointer to link count already on this conf
3055 * output       - NONE
3056 * side effects - Add a connect block
3057 */
3058 int
3059 conf_add_server(struct ConfItem *conf, const char *class_name)
3060 {
3061  struct AccessItem *aconf;
3062  struct split_nuh_item nuh;
3063  char conf_user[USERLEN + 1];
3064  char conf_host[HOSTLEN + 1];
3065
3066  aconf = map_to_conf(conf);
3067
3068  conf_add_class_to_conf(conf, class_name);
3069
3070  if (!aconf->host || !conf->name)
3071  {
3072    sendto_realops_flags(UMODE_ALL, L_ALL, "Bad connect block");
3073    ilog(L_WARN, "Bad connect block");
3074    return -1;
3075  }
3076
3077  if (EmptyString(aconf->passwd) && !IsConfCryptLink(aconf))
3078  {
3079    sendto_realops_flags(UMODE_ALL, L_ALL, "Bad connect block, name %s",
3080                         conf->name);
3081    ilog(L_WARN, "Bad connect block, host %s", conf->name);
3082    return -1;
3083  }
3084
3085  nuh.nuhmask  = aconf->host;
3086  nuh.nickptr  = NULL;
3087  nuh.userptr  = conf_user;
3088  nuh.hostptr  = conf_host;
3089
3090  nuh.nicksize = 0;
3091  nuh.usersize = sizeof(conf_user);
3092  nuh.hostsize = sizeof(conf_host);
3093
3094  split_nuh(&nuh);
3095
3096  MyFree(aconf->host);
3097  aconf->host = NULL;
3098
3099  DupString(aconf->user, conf_user); /* somehow username checking for servers
3100                                 got lost in H6/7, will have to be re-added */
3101  DupString(aconf->host, conf_host);
3102
3103  lookup_confhost(conf);
3104
3105  return 0;
3106 }
3107
1371   /* yyerror()
1372   *
1373   * inputs       - message from parser
# Line 3120 | Line 1383 | yyerror(const char *msg)
1383      return;
1384  
1385    strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1386 <  sendto_realops_flags(UMODE_ALL, L_ALL, "\"%s\", line %u: %s: %s",
1386 >  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1387 >                       "\"%s\", line %u: %s: %s",
1388                         conffilebuf, lineno + 1, msg, newlinebuf);
1389 <  ilog(L_WARN, "\"%s\", line %u: %s: %s",
1389 >  ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1390         conffilebuf, lineno + 1, msg, newlinebuf);
1391   }
1392  
1393 < int
1394 < conf_fbgets(char *lbuf, unsigned int max_size, FBFILE *fb)
1393 > void
1394 > conf_error_report(const char *msg)
1395   {
1396 <  if (fbgets(lbuf, max_size, fb) == NULL)
3133 <    return 0;
3134 <
3135 <  return strlen(lbuf);
3136 < }
1396 >  char newlinebuf[IRCD_BUFSIZE];
1397  
1398 < int
1399 < conf_yy_fatal_error(const char *msg)
1400 < {
1401 <  return 0;
1398 >  strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1399 >  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1400 >                       "\"%s\", line %u: %s: %s",
1401 >                       conffilebuf, lineno + 1, msg, newlinebuf);
1402 >  ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1403 >       conffilebuf, lineno + 1, msg, newlinebuf);
1404   }
1405  
1406   /*
1407   * valid_tkline()
1408 < *
1408 > *
1409   * inputs       - pointer to ascii string to check
1410   *              - whether the specified time is in seconds or minutes
1411   * output       - -1 not enough parameters
# Line 3152 | Line 1414 | conf_yy_fatal_error(const char *msg)
1414   * Originally written by Dianora (Diane, db@db.net)
1415   */
1416   time_t
1417 < valid_tkline(const char *p, int minutes)
1417 > valid_tkline(const char *data, const int minutes)
1418   {
1419 +  const unsigned char *p = (const unsigned char *)data;
1420 +  unsigned char tmpch = '\0';
1421    time_t result = 0;
1422  
1423 <  for (; *p; ++p)
1423 >  while ((tmpch = *p++))
1424    {
1425 <    if (!IsDigit(*p))
1425 >    if (!IsDigit(tmpch))
1426        return 0;
1427  
1428      result *= 10;
1429 <    result += ((*p) & 0xF);
1429 >    result += (tmpch & 0xF);
1430    }
1431  
1432    /*
1433 <   * In the degenerate case where oper does a /quote kline 0 user@host :reason
1434 <   * i.e. they specifically use 0, I am going to return 1 instead
1435 <   * as a return value of non-zero is used to flag it as a temporary kline
1433 >   * In the degenerate case where oper does a /quote kline 0 user@host :reason
1434 >   * i.e. they specifically use 0, I am going to return 1 instead as a return
1435 >   * value of non-zero is used to flag it as a temporary kline
1436     */
1437    if (result == 0)
1438      result = 1;
1439  
1440 <  /*
1440 >  /*
1441     * If the incoming time is in seconds convert it to minutes for the purpose
1442     * of this calculation
1443     */
1444    if (!minutes)
1445 <    result = result / (time_t)60;
1445 >    result = result / 60;
1446  
1447    if (result > MAX_TDKLINE_TIME)
1448      result = MAX_TDKLINE_TIME;
1449  
1450 <  result = result * (time_t)60;  /* turn it into seconds */
1450 >  result = result * 60;  /* Turn it into seconds */
1451  
1452    return result;
1453   }
1454  
1455 + /* valid_wild_card_simple()
1456 + *
1457 + * inputs       - data to check for sufficient non-wildcard characters
1458 + * outputs      - 1 if valid, else 0
1459 + * side effects - none
1460 + */
1461 + int
1462 + valid_wild_card_simple(const char *data)
1463 + {
1464 +  const unsigned char *p = (const unsigned char *)data;
1465 +  unsigned char tmpch = '\0';
1466 +  unsigned int nonwild = 0;
1467 +
1468 +  while ((tmpch = *p++))
1469 +  {
1470 +    if (tmpch == '\\' && *p)
1471 +    {
1472 +      ++p;
1473 +      if (++nonwild >= ConfigGeneral.min_nonwildcard_simple)
1474 +        return 1;
1475 +    }
1476 +    else if (!IsMWildChar(tmpch))
1477 +    {
1478 +      if (++nonwild >= ConfigGeneral.min_nonwildcard_simple)
1479 +        return 1;
1480 +    }
1481 +  }
1482 +
1483 +  return 0;
1484 + }
1485 +
1486   /* valid_wild_card()
1487   *
1488   * input        - pointer to client
# Line 3199 | Line 1494 | valid_tkline(const char *p, int minutes)
1494   int
1495   valid_wild_card(struct Client *source_p, int warn, int count, ...)
1496   {
1497 <  char *p;
1498 <  char tmpch;
3204 <  int nonwild = 0;
1497 >  unsigned char tmpch = '\0';
1498 >  unsigned int nonwild = 0;
1499    va_list args;
1500  
1501    /*
# Line 3220 | Line 1514 | valid_wild_card(struct Client *source_p,
1514  
1515    while (count--)
1516    {
1517 <    p = va_arg(args, char *);
1517 >    const unsigned char *p = va_arg(args, const unsigned char *);
1518      if (p == NULL)
1519        continue;
1520  
# Line 3232 | Line 1526 | valid_wild_card(struct Client *source_p,
1526           * If we find enough non-wild characters, we can
1527           * break - no point in searching further.
1528           */
1529 <        if (++nonwild >= ConfigFileEntry.min_nonwildcard)
1529 >        if (++nonwild >= ConfigGeneral.min_nonwildcard)
1530 >        {
1531 >          va_end(args);
1532            return 1;
1533 +        }
1534        }
1535      }
1536    }
1537  
1538    if (warn)
1539 <    sendto_one(source_p, ":%s NOTICE %s :Please include at least %d non-wildcard characters with the mask",
1540 <               me.name, source_p->name, ConfigFileEntry.min_nonwildcard);
1539 >    sendto_one_notice(source_p, &me,
1540 >                      ":Please include at least %u non-wildcard characters with the mask",
1541 >                      ConfigGeneral.min_nonwildcard);
1542 >  va_end(args);
1543 >  return 0;
1544 > }
1545 >
1546 > /* find_user_host()
1547 > *
1548 > * inputs       - pointer to client placing kline
1549 > *              - pointer to user_host_or_nick
1550 > *              - pointer to user buffer
1551 > *              - pointer to host buffer
1552 > * output       - 0 if not ok to kline, 1 to kline i.e. if valid user host
1553 > * side effects -
1554 > */
1555 > static int
1556 > find_user_host(struct Client *source_p, char *user_host_or_nick,
1557 >               char *luser, char *lhost, unsigned int flags)
1558 > {
1559 >  struct Client *target_p = NULL;
1560 >  char *hostp = NULL;
1561 >
1562 >  if (lhost == NULL)
1563 >  {
1564 >    strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
1565 >    return 1;
1566 >  }
1567 >
1568 >  if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
1569 >  {
1570 >    /* Explicit user@host mask given */
1571 >    if (hostp)                            /* I'm a little user@host */
1572 >    {
1573 >      *(hostp++) = '\0';                       /* short and squat */
1574 >
1575 >      if (*user_host_or_nick)
1576 >        strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
1577 >      else
1578 >        strcpy(luser, "*");
1579 >
1580 >      if (*hostp)
1581 >        strlcpy(lhost, hostp, HOSTLEN + 1);    /* here is my host */
1582 >      else
1583 >        strcpy(lhost, "*");
1584 >    }
1585 >    else
1586 >    {
1587 >      luser[0] = '*';             /* no @ found, assume its *@somehost */
1588 >      luser[1] = '\0';
1589 >      strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
1590 >    }
1591 >
1592 >    return 1;
1593 >  }
1594 >  else
1595 >  {
1596 >    /* Try to find user@host mask from nick */
1597 >    /* Okay to use source_p as the first param, because source_p == client_p */
1598 >    if ((target_p =
1599 >        find_chasing(source_p, user_host_or_nick)) == NULL)
1600 >      return 0;  /* find_chasing sends ERR_NOSUCHNICK */
1601 >
1602 >    if (IsExemptKline(target_p))
1603 >    {
1604 >      if (IsClient(source_p))
1605 >        sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
1606 >      return 0;
1607 >    }
1608 >
1609 >    /*
1610 >     * Turn the "user" bit into "*user", blow away '~'
1611 >     * if found in original user name (non-idented)
1612 >     */
1613 >    strlcpy(luser, target_p->username, USERLEN*4 + 1);
1614 >
1615 >    if (target_p->username[0] == '~')
1616 >      luser[0] = '*';
1617 >
1618 >    if (!strcmp(target_p->sockhost, "0"))
1619 >      strlcpy(lhost, target_p->host, HOSTLEN*4 + 1);
1620 >    else
1621 >      strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
1622 >    return 1;
1623 >  }
1624 >
1625    return 0;
1626   }
1627  
# Line 3254 | Line 1635 | valid_wild_card(struct Client *source_p,
1635   *              - parse_flags bit map of things to test
1636   *              - pointer to user or string to parse into
1637   *              - pointer to host or NULL to parse into if non NULL
1638 < *              - pointer to optional tkline time or NULL
1638 > *              - pointer to optional tkline time or NULL
1639   *              - pointer to target_server to parse into if non NULL
1640   *              - pointer to reason to parse into
1641   *
1642 < * output       - 1 if valid, -1 if not valid
1642 > * output       - 1 if valid, 0 if not valid
1643   * side effects - A generalised k/d/x etc. line parser,
1644   *               "ALINE [time] user@host|string [ON] target :reason"
1645   *                will parse returning a parsed user, host if
# Line 3276 | Line 1657 | valid_wild_card(struct Client *source_p,
1657   */
1658   int
1659   parse_aline(const char *cmd, struct Client *source_p,
1660 <            int parc, char **parv,
1661 <            int parse_flags, char **up_p, char **h_p, time_t *tkline_time,
1662 <            char **target_server, char **reason)
1660 >            int parc, char **parv,
1661 >            int parse_flags, char **up_p, char **h_p, time_t *tkline_time,
1662 >            char **target_server, char **reason)
1663   {
1664    int found_tkline_time=0;
1665 <  static char def_reason[] = "No Reason";
1665 >  static char def_reason[] = CONF_NOREASON;
1666    static char user[USERLEN*4+1];
1667    static char host[HOSTLEN*4+1];
1668  
# Line 3290 | Line 1671 | parse_aline(const char *cmd, struct Clie
1671  
1672    found_tkline_time = valid_tkline(*parv, TK_MINUTES);
1673  
1674 <  if (found_tkline_time != 0)
1674 >  if (found_tkline_time)
1675    {
1676      parv++;
1677      parc--;
1678  
1679 <    if (tkline_time != NULL)
1679 >    if (tkline_time)
1680        *tkline_time = found_tkline_time;
1681      else
1682      {
1683 <      sendto_one(source_p, ":%s NOTICE %s :temp_line not supported by %s",
1684 <                 me.name, source_p->name, cmd);
3304 <      return -1;
1683 >      sendto_one_notice(source_p, &me, ":temp_line not supported by %s", cmd);
1684 >      return 0;
1685      }
1686    }
1687  
1688    if (parc == 0)
1689    {
1690 <    sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1691 <               me.name, source_p->name, cmd);
3312 <    return -1;
1690 >    sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1691 >    return 0;
1692    }
1693  
1694    if (h_p == NULL)
# Line 3317 | Line 1696 | parse_aline(const char *cmd, struct Clie
1696    else
1697    {
1698      if (find_user_host(source_p, *parv, user, host, parse_flags) == 0)
1699 <      return -1;
1699 >      return 0;
1700  
1701      *up_p = user;
1702      *h_p = host;
1703    }
1704 <
1704 >
1705    parc--;
1706    parv++;
1707  
1708 <  if (parc != 0)
1708 >  if (parc)
1709    {
1710      if (irccmp(*parv, "ON") == 0)
1711      {
# Line 3335 | Line 1714 | parse_aline(const char *cmd, struct Clie
1714  
1715        if (target_server == NULL)
1716        {
1717 <        sendto_one(source_p, ":%s NOTICE %s :ON server not supported by %s",
1718 <                   me.name, source_p->name, cmd);
3340 <        return -1;
1717 >        sendto_one_notice(source_p, &me, ":ON server not supported by %s", cmd);
1718 >        return 0;
1719        }
1720  
1721 <      if (!IsOperRemoteBan(source_p))
1721 >      if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN))
1722        {
1723 <        sendto_one(source_p, form_str(ERR_NOPRIVS),
1724 <                   me.name, source_p->name, "remoteban");
3347 <        return -1;
1723 >        sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "remoteban");
1724 >        return 0;
1725        }
1726  
1727        if (parc == 0 || EmptyString(*parv))
1728        {
1729 <        sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1730 <                   me.name, source_p->name, cmd);
3354 <        return -1;
1729 >        sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1730 >        return 0;
1731        }
1732  
1733        *target_server = *parv;
# Line 3363 | Line 1739 | parse_aline(const char *cmd, struct Clie
1739        /* Make sure target_server *is* NULL if no ON server found
1740         * caller probably NULL'd it first, but no harm to do it again -db
1741         */
1742 <      if (target_server != NULL)
1743 <        *target_server = NULL;
1742 >      if (target_server)
1743 >        *target_server = NULL;
1744      }
1745    }
1746  
1747 <  if (h_p != NULL)
1747 >  if (h_p)
1748    {
1749 <    if (strchr(user, '!') != NULL)
1749 >    if (strchr(user, '!'))
1750      {
1751 <      sendto_one(source_p, ":%s NOTICE %s :Invalid character '!' in kline",
1752 <                 me.name, source_p->name);
3377 <      return -1;
1751 >      sendto_one_notice(source_p, &me, ":Invalid character '!' in kline");
1752 >      return 0;
1753      }
1754  
1755 <    if ((parse_flags & AWILD) && !valid_wild_card(source_p, YES, 2, *up_p, *h_p))
1756 <      return -1;
1755 >    if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 2, *up_p, *h_p))
1756 >      return 0;
1757    }
1758    else
1759 <    if ((parse_flags & AWILD) && !valid_wild_card(source_p, YES, 1, *up_p))
1760 <      return -1;
1759 >    if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 1, *up_p))
1760 >      return 0;
1761  
1762 <  if (reason != NULL)
1762 >  if (reason)
1763    {
1764 <    if (parc != 0 && !EmptyString(*parv))
1764 >    if (parc && !EmptyString(*parv))
1765      {
1766        *reason = *parv;
1767 <      if (!valid_comment(source_p, *reason, YES))
1768 <        return -1;
1767 >
1768 >      if (!valid_comment(source_p, *reason, 1))
1769 >        return 0;
1770      }
1771      else
1772        *reason = def_reason;
# Line 3399 | Line 1775 | parse_aline(const char *cmd, struct Clie
1775    return 1;
1776   }
1777  
3402 /* find_user_host()
3403 *
3404 * inputs       - pointer to client placing kline
3405 *              - pointer to user_host_or_nick
3406 *              - pointer to user buffer
3407 *              - pointer to host buffer
3408 * output       - 0 if not ok to kline, 1 to kline i.e. if valid user host
3409 * side effects -
3410 */
3411 static int
3412 find_user_host(struct Client *source_p, char *user_host_or_nick,
3413               char *luser, char *lhost, unsigned int flags)
3414 {
3415  struct Client *target_p = NULL;
3416  char *hostp = NULL;
3417
3418  if (lhost == NULL)
3419  {
3420    strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
3421    return 1;
3422  }
3423
3424  if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
3425  {
3426    /* Explicit user@host mask given */
3427
3428    if (hostp != NULL)                            /* I'm a little user@host */
3429    {
3430      *(hostp++) = '\0';                       /* short and squat */
3431      if (*user_host_or_nick)
3432        strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
3433      else
3434        strcpy(luser, "*");
3435      if (*hostp)
3436        strlcpy(lhost, hostp, HOSTLEN + 1);    /* here is my host */
3437      else
3438        strcpy(lhost, "*");
3439    }
3440    else
3441    {
3442      luser[0] = '*';             /* no @ found, assume its *@somehost */
3443      luser[1] = '\0';    
3444      strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
3445    }
3446    
3447    return 1;
3448  }
3449  else if (!(flags & NOUSERLOOKUP))
3450  {
3451    /* Try to find user@host mask from nick */
3452    /* Okay to use source_p as the first param, because source_p == client_p */
3453    if ((target_p =
3454        find_chasing(source_p, source_p, user_host_or_nick, NULL)) == NULL)
3455      return 0;
3456
3457    if (IsExemptKline(target_p))
3458    {
3459      if (!IsServer(source_p))
3460        sendto_one(source_p,
3461                   ":%s NOTICE %s :%s is E-lined",
3462                   me.name, source_p->name, target_p->name);
3463      return 0;
3464    }
3465
3466    /*
3467     * turn the "user" bit into "*user", blow away '~'
3468     * if found in original user name (non-idented)
3469     */
3470    strlcpy(luser, target_p->username, USERLEN*4 + 1);
3471
3472    if (target_p->username[0] == '~')
3473      luser[0] = '*';
3474
3475    if (target_p->sockhost[0] == '\0' ||
3476        (target_p->sockhost[0] == '0' && target_p->sockhost[1] == '\0'))
3477      strlcpy(lhost, target_p->host, HOSTLEN*4 + 1);
3478    else
3479      strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
3480    return 1;
3481  }
3482
3483  return 0;
3484 }
3485
1778   /* valid_comment()
1779   *
1780   * inputs       - pointer to client
# Line 3494 | Line 1786 | find_user_host(struct Client *source_p,
1786   int
1787   valid_comment(struct Client *source_p, char *comment, int warn)
1788   {
3497  if (strchr(comment, '"'))
3498  {
3499    if (warn)
3500      sendto_one(source_p, ":%s NOTICE %s :Invalid character '\"' in comment",
3501                 me.name, source_p->name);
3502    return 0;
3503  }
3504
1789    if (strlen(comment) > REASONLEN)
1790      comment[REASONLEN-1] = '\0';
1791  
# Line 3516 | Line 1800 | valid_comment(struct Client *source_p, c
1800   * side effects - none
1801   */
1802   int
1803 < match_conf_password(const char *password, const struct AccessItem *aconf)
1803 > match_conf_password(const char *password, const struct MaskItem *conf)
1804   {
1805    const char *encr = NULL;
1806  
1807 <  if (password == NULL || aconf->passwd == NULL)
1807 >  if (EmptyString(password) || EmptyString(conf->passwd))
1808      return 0;
1809  
1810 <  if (aconf->flags & CONF_FLAGS_ENCRYPTED)
1811 <  {
3528 <    /* use first two chars of the password they send in as salt */
3529 <    /* If the password in the conf is MD5, and ircd is linked
3530 <     * to scrypt on FreeBSD, or the standard crypt library on
3531 <     * glibc Linux, then this code will work fine on generating
3532 <     * the proper encrypted hash for comparison.
3533 <     */
3534 <    if (*aconf->passwd)
3535 <      encr = crypt(password, aconf->passwd);
3536 <    else
3537 <      encr = "";
3538 <  }
1810 >  if (conf->flags & CONF_FLAGS_ENCRYPTED)
1811 >    encr = crypt(password, conf->passwd);
1812    else
1813      encr = password;
1814  
1815 <  return !strcmp(encr, aconf->passwd);
1815 >  return encr && !strcmp(encr, conf->passwd);
1816   }
1817  
1818   /*
# Line 3547 | Line 1820 | match_conf_password(const char *password
1820   *
1821   * inputs       - client sending the cluster
1822   *              - command name "KLINE" "XLINE" etc.
1823 < *              - capab -- CAP_KLN etc. from s_serv.h
1824 < *              - cluster type -- CLUSTER_KLINE etc. from s_conf.h
1823 > *              - capab -- CAP_KLN etc. from server.h
1824 > *              - cluster type -- CLUSTER_KLINE etc. from conf.h
1825   *              - pattern and args to send along
1826   * output       - none
1827   * side effects - Take source_p send the pattern with args given
1828   *                along to all servers that match capab and cluster type
1829   */
1830   void
1831 < cluster_a_line(struct Client *source_p, const char *command,
1832 <               int capab, int cluster_type, const char *pattern, ...)
1831 > cluster_a_line(struct Client *source_p, const char *command, unsigned int capab,
1832 >               unsigned int cluster_type, const char *pattern, ...)
1833   {
1834    va_list args;
1835 <  char buffer[IRCD_BUFSIZE];
1836 <  const dlink_node *ptr = NULL;
1835 >  char buffer[IRCD_BUFSIZE] = "";
1836 >  const dlink_node *node = NULL;
1837  
1838    va_start(args, pattern);
1839    vsnprintf(buffer, sizeof(buffer), pattern, args);
1840    va_end(args);
1841  
1842 <  DLINK_FOREACH(ptr, cluster_items.head)
1842 >  DLINK_FOREACH(node, cluster_items.head)
1843    {
1844 <    const struct ConfItem *conf = ptr->data;
1844 >    const struct MaskItem *conf = node->data;
1845  
1846      if (conf->flags & cluster_type)
1847 <      sendto_match_servs(source_p, conf->name, CAP_CLUSTER|capab,
1848 <                         "%s %s %s", command, conf->name, buffer);
1847 >      sendto_match_servs(source_p, conf->name, CAP_CLUSTER | capab,
1848 >                         "%s %s %s", command, conf->name, buffer);
1849    }
1850   }
1851  
# Line 3611 | Line 1884 | split_nuh(struct split_nuh_item *const i
1884  
1885    if (iptr->nickptr)
1886      strlcpy(iptr->nickptr, "*", iptr->nicksize);
1887 +
1888    if (iptr->userptr)
1889      strlcpy(iptr->userptr, "*", iptr->usersize);
1890 +
1891    if (iptr->hostptr)
1892      strlcpy(iptr->hostptr, "*", iptr->hostsize);
1893  
# Line 3620 | Line 1895 | split_nuh(struct split_nuh_item *const i
1895    {
1896      *p = '\0';
1897  
1898 <    if (iptr->nickptr && *iptr->nuhmask != '\0')
1898 >    if (iptr->nickptr && *iptr->nuhmask)
1899        strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
1900  
1901 <    if ((q = strchr(++p, '@'))) {
1901 >    if ((q = strchr(++p, '@')))
1902 >    {
1903        *q++ = '\0';
1904  
1905 <      if (*p != '\0')
1905 >      if (*p)
1906          strlcpy(iptr->userptr, p, iptr->usersize);
1907  
1908 <      if (*q != '\0')
1908 >      if (*q)
1909          strlcpy(iptr->hostptr, q, iptr->hostsize);
1910      }
1911      else
1912      {
1913 <      if (*p != '\0')
1913 >      if (*p)
1914          strlcpy(iptr->userptr, p, iptr->usersize);
1915      }
1916    }
# Line 3646 | Line 1922 | split_nuh(struct split_nuh_item *const i
1922        /* if found a @ */
1923        *p++ = '\0';
1924  
1925 <      if (*iptr->nuhmask != '\0')
1925 >      if (*iptr->nuhmask)
1926          strlcpy(iptr->userptr, iptr->nuhmask, iptr->usersize);
1927  
1928 <      if (*p != '\0')
1928 >      if (*p)
1929          strlcpy(iptr->hostptr, p, iptr->hostsize);
1930      }
1931      else
1932      {
1933 <      /* no @ found */
1933 >      /* No @ found */
1934        if (!iptr->nickptr || strpbrk(iptr->nuhmask, ".:"))
1935          strlcpy(iptr->hostptr, iptr->nuhmask, iptr->hostsize);
1936        else
# Line 3662 | Line 1938 | split_nuh(struct split_nuh_item *const i
1938      }
1939    }
1940   }
3665
3666 /*
3667 * flags_to_ascii
3668 *
3669 * inputs       - flags is a bitmask
3670 *              - pointer to table of ascii letters corresponding
3671 *                to each bit
3672 *              - flag 1 for convert ToLower if bit missing
3673 *                0 if ignore.
3674 * output       - none
3675 * side effects - string pointed to by p has bitmap chars written to it
3676 */
3677 static void
3678 flags_to_ascii(unsigned int flags, const unsigned int bit_table[], char *p,
3679               int lowerit)
3680 {
3681  unsigned int mask = 1;
3682  int i = 0;
3683
3684  for (mask = 1; (mask != 0) && (bit_table[i] != 0); mask <<= 1, i++)
3685  {
3686    if (flags & mask)
3687      *p++ = bit_table[i];
3688    else if (lowerit)
3689      *p++ = ToLower(bit_table[i]);
3690  }
3691  *p = '\0';
3692 }
3693
3694 /*
3695 * cidr_limit_reached
3696 *
3697 * inputs       - int flag allowing over_rule of limits
3698 *              - pointer to the ip to be added
3699 *              - pointer to the class
3700 * output       - non zero if limit reached
3701 *                0 if limit not reached
3702 * side effects -
3703 */
3704 static int
3705 cidr_limit_reached(int over_rule,
3706                   struct irc_ssaddr *ip, struct ClassItem *aclass)
3707 {
3708  dlink_node *ptr = NULL;
3709  struct CidrItem *cidr;
3710
3711  if (NumberPerCidr(aclass) <= 0)
3712    return 0;
3713
3714  if (ip->ss.ss_family == AF_INET)
3715  {
3716    if (CidrBitlenIPV4(aclass) <= 0)
3717      return 0;
3718
3719    DLINK_FOREACH(ptr, aclass->list_ipv4.head)
3720    {
3721      cidr = ptr->data;
3722      if (match_ipv4(ip, &cidr->mask, CidrBitlenIPV4(aclass)))
3723      {
3724        if (!over_rule && (cidr->number_on_this_cidr >= NumberPerCidr(aclass)))
3725          return -1;
3726        cidr->number_on_this_cidr++;
3727        return 0;
3728      }
3729    }
3730    cidr = MyMalloc(sizeof(struct CidrItem));
3731    cidr->number_on_this_cidr = 1;
3732    cidr->mask = *ip;
3733    mask_addr(&cidr->mask, CidrBitlenIPV4(aclass));
3734    dlinkAdd(cidr, &cidr->node, &aclass->list_ipv4);
3735  }
3736 #ifdef IPV6
3737  else if (CidrBitlenIPV6(aclass) > 0)
3738  {
3739    DLINK_FOREACH(ptr, aclass->list_ipv6.head)
3740    {
3741      cidr = ptr->data;
3742      if (match_ipv6(ip, &cidr->mask, CidrBitlenIPV6(aclass)))
3743      {
3744        if (!over_rule && (cidr->number_on_this_cidr >= NumberPerCidr(aclass)))
3745          return -1;
3746        cidr->number_on_this_cidr++;
3747        return 0;
3748      }
3749    }
3750    cidr = MyMalloc(sizeof(struct CidrItem));
3751    cidr->number_on_this_cidr = 1;
3752    cidr->mask = *ip;
3753    mask_addr(&cidr->mask, CidrBitlenIPV6(aclass));
3754    dlinkAdd(cidr, &cidr->node, &aclass->list_ipv6);
3755  }
3756 #endif
3757  return 0;
3758 }
3759
3760 /*
3761 * remove_from_cidr_check
3762 *
3763 * inputs       - pointer to the ip to be removed
3764 *              - pointer to the class
3765 * output       - NONE
3766 * side effects -
3767 */
3768 static void
3769 remove_from_cidr_check(struct irc_ssaddr *ip, struct ClassItem *aclass)
3770 {
3771  dlink_node *ptr = NULL;
3772  dlink_node *next_ptr = NULL;
3773  struct CidrItem *cidr;
3774
3775  if (NumberPerCidr(aclass) == 0)
3776    return;
3777
3778  if (ip->ss.ss_family == AF_INET)
3779  {
3780    if (CidrBitlenIPV4(aclass) <= 0)
3781      return;
3782
3783    DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv4.head)
3784    {
3785      cidr = ptr->data;
3786      if (match_ipv4(ip, &cidr->mask, CidrBitlenIPV4(aclass)))
3787      {
3788        cidr->number_on_this_cidr--;
3789        if (cidr->number_on_this_cidr == 0)
3790        {
3791          dlinkDelete(ptr, &aclass->list_ipv4);
3792          MyFree(cidr);
3793          return;
3794        }
3795      }
3796    }
3797  }
3798 #ifdef IPV6
3799  else if (CidrBitlenIPV6(aclass) > 0)
3800  {
3801    DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv6.head)
3802    {
3803      cidr = ptr->data;
3804      if (match_ipv6(ip, &cidr->mask, CidrBitlenIPV6(aclass)))
3805      {
3806        cidr->number_on_this_cidr--;
3807        if (cidr->number_on_this_cidr == 0)
3808        {
3809          dlinkDelete(ptr, &aclass->list_ipv6);
3810          MyFree(cidr);
3811          return;
3812        }
3813      }
3814    }
3815  }
3816 #endif
3817 }
3818
3819 static void
3820 rebuild_cidr_list(int aftype, struct ConfItem *oldcl, struct ClassItem *newcl,
3821                  dlink_list *old_list, dlink_list *new_list, int changed)
3822 {
3823  dlink_node *ptr;
3824  struct Client *client_p;
3825  struct ConfItem *conf;
3826  struct AccessItem *aconf;
3827
3828  if (!changed)
3829  {
3830    *new_list = *old_list;
3831    old_list->head = old_list->tail = NULL;
3832    old_list->length = 0;
3833    return;
3834  }
3835
3836  DLINK_FOREACH(ptr, local_client_list.head)
3837  {
3838    client_p = ptr->data;
3839    if (client_p->localClient->aftype != aftype)
3840      continue;
3841    if (dlink_list_length(&client_p->localClient->confs) == 0)
3842      continue;
3843
3844    conf = client_p->localClient->confs.tail->data;
3845    if (conf->type == CLIENT_TYPE)
3846    {
3847      aconf = map_to_conf(conf);
3848      if (aconf->class_ptr == oldcl)
3849        cidr_limit_reached(1, &client_p->localClient->ip, newcl);
3850    }
3851  }
3852 }
3853
3854 /*
3855 * rebuild_cidr_class
3856 *
3857 * inputs       - pointer to old conf
3858 *              - pointer to new_class
3859 * output       - none
3860 * side effects - rebuilds the class link list of cidr blocks
3861 */
3862 void
3863 rebuild_cidr_class(struct ConfItem *conf, struct ClassItem *new_class)
3864 {
3865  struct ClassItem *old_class = map_to_conf(conf);
3866
3867  if (NumberPerCidr(old_class) > 0 && NumberPerCidr(new_class) > 0)
3868  {
3869    if (CidrBitlenIPV4(old_class) > 0 && CidrBitlenIPV4(new_class) > 0)
3870      rebuild_cidr_list(AF_INET, conf, new_class,
3871                        &old_class->list_ipv4, &new_class->list_ipv4,
3872                        CidrBitlenIPV4(old_class) != CidrBitlenIPV4(new_class));
3873
3874 #ifdef IPV6
3875    if (CidrBitlenIPV6(old_class) > 0 && CidrBitlenIPV6(new_class) > 0)
3876      rebuild_cidr_list(AF_INET6, conf, new_class,
3877                        &old_class->list_ipv6, &new_class->list_ipv6,
3878                        CidrBitlenIPV6(old_class) != CidrBitlenIPV6(new_class));
3879 #endif
3880  }
3881
3882  destroy_cidr_class(old_class);
3883 }
3884
3885 /*
3886 * destroy_cidr_list
3887 *
3888 * inputs       - pointer to class dlink list of cidr blocks
3889 * output       - none
3890 * side effects - completely destroys the class link list of cidr blocks
3891 */
3892 static void
3893 destroy_cidr_list(dlink_list *list)
3894 {
3895  dlink_node *ptr = NULL, *next_ptr = NULL;
3896
3897  DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
3898  {
3899    dlinkDelete(ptr, list);
3900    MyFree(ptr->data);
3901  }
3902 }
3903
3904 /*
3905 * destroy_cidr_class
3906 *
3907 * inputs       - pointer to class
3908 * output       - none
3909 * side effects - completely destroys the class link list of cidr blocks
3910 */
3911 static void
3912 destroy_cidr_class(struct ClassItem *aclass)
3913 {
3914  destroy_cidr_list(&aclass->list_ipv4);
3915  destroy_cidr_list(&aclass->list_ipv6);
3916 }

Diff Legend

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