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

Comparing:
ircd-hybrid-8/src/conf.c (file contents), Revision 1518 by michael, Sun Sep 2 16:50:40 2012 UTC vs.
ircd-hybrid/trunk/src/conf.c (file contents), Revision 8314 by michael, Wed Feb 28 17:47:23 2018 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  conf.c: Configuration file functions.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-2018 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 16 | Line 15
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18 < *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file conf.c
23 > * \brief Configuration file functions.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
28   #include "list.h"
29   #include "ircd_defs.h"
28 #include "balloc.h"
30   #include "conf.h"
31 < #include "s_serv.h"
32 < #include "resv.h"
31 > #include "conf_cluster.h"
32 > #include "conf_gecos.h"
33 > #include "conf_pseudo.h"
34 > #include "conf_resv.h"
35 > #include "conf_service.h"
36 > #include "conf_shared.h"
37 > #include "server.h"
38   #include "channel.h"
39   #include "client.h"
40   #include "event.h"
35 #include "hook.h"
41   #include "irc_string.h"
42   #include "s_bsd.h"
43   #include "ircd.h"
# Line 43 | Line 48
48   #include "fdlist.h"
49   #include "log.h"
50   #include "send.h"
46 #include "s_gline.h"
51   #include "memory.h"
52 < #include "irc_res.h"
52 > #include "res.h"
53   #include "userhost.h"
54 < #include "s_user.h"
54 > #include "user.h"
55   #include "channel_mode.h"
56   #include "parse.h"
57 < #include "s_misc.h"
58 <
59 < struct Callback *client_check_cb = NULL;
60 < struct config_server_hide ConfigServerHide;
57 > #include "misc.h"
58 > #include "conf_db.h"
59 > #include "conf_class.h"
60 > #include "motd.h"
61 > #include "ipcache.h"
62 > #include "isupport.h"
63 > #include "whowas.h"
64 >
65 >
66 > struct config_channel_entry ConfigChannel;
67 > struct config_serverhide_entry ConfigServerHide;
68 > struct config_general_entry ConfigGeneral;
69 > struct config_log_entry ConfigLog = { .use_logging = 1 };
70 > struct config_serverinfo_entry ConfigServerInfo;
71 > struct config_admin_entry ConfigAdminInfo;
72 > struct conf_parser_context conf_parser_ctx;
73  
74   /* general conf items link list root, other than k lines etc. */
75 < dlink_list service_items = { NULL, NULL, 0 };
76 < dlink_list server_items  = { NULL, NULL, 0 };
61 < dlink_list cluster_items = { NULL, NULL, 0 };
62 < dlink_list oconf_items   = { NULL, NULL, 0 };
63 < dlink_list uconf_items   = { NULL, NULL, 0 };
64 < dlink_list xconf_items   = { NULL, NULL, 0 };
65 < dlink_list rxconf_items  = { NULL, NULL, 0 };
66 < dlink_list rkconf_items  = { NULL, NULL, 0 };
67 < dlink_list nresv_items   = { NULL, NULL, 0 };
68 < dlink_list class_items   = { NULL, NULL, 0 };
69 <
70 < dlink_list temporary_xlines  = { NULL, NULL, 0 };
71 < dlink_list temporary_resv = { NULL, NULL, 0 };
75 > dlink_list connect_items;
76 > dlink_list operator_items;
77  
78   extern unsigned int lineno;
79   extern char linebuf[];
80   extern char conffilebuf[IRCD_BUFSIZE];
81   extern int yyparse(); /* defined in y.tab.c */
82  
78 struct conf_parser_context conf_parser_ctx = { 0, 0, NULL };
79
80 /* internally defined functions */
81 static void read_conf(FILE *);
82 static void clear_out_old_conf(void);
83 static void flush_deleted_I_P(void);
84 static void expire_tklines(dlink_list *);
85 static void garbage_collect_ip_entries(void);
86 static int hash_ip(struct irc_ssaddr *);
87 static int verify_access(struct Client *, const char *);
88 static int attach_iline(struct Client *, struct ConfItem *);
89 static struct ip_entry *find_or_add_ip(struct irc_ssaddr *);
90 static void parse_conf_file(int, int);
91 static dlink_list *map_to_list(ConfType);
92 static struct AccessItem *find_regexp_kline(const char *[]);
93 static int find_user_host(struct Client *, char *, char *, char *, unsigned int);
94
95 /*
96 * bit_len
97 */
98 static int cidr_limit_reached(int, struct irc_ssaddr *, struct ClassItem *);
99 static void remove_from_cidr_check(struct irc_ssaddr *, struct ClassItem *);
100 static void destroy_cidr_class(struct ClassItem *);
101
102 static void flags_to_ascii(unsigned int, const unsigned int[], char *, int);
103
104 /* address of default class conf */
105 static struct ConfItem *class_default;
106
107 /* usually, with hash tables, you use a prime number...
108 * but in this case I am dealing with ip addresses,
109 * not ascii strings.
110 */
111 #define IP_HASH_SIZE 0x1000
112
113 struct ip_entry
114 {
115  struct irc_ssaddr ip;
116  int count;
117  time_t last_attempt;
118  struct ip_entry *next;
119 };
120
121 static struct ip_entry *ip_hash_table[IP_HASH_SIZE];
122 static BlockHeap *ip_entry_heap = NULL;
123 static int ip_entries_count = 0;
124
125
126 void *
127 map_to_conf(struct ConfItem *aconf)
128 {
129  void *conf;
130  conf = (void *)((uintptr_t)aconf +
131                  (uintptr_t)sizeof(struct ConfItem));
132  return(conf);
133 }
134
135 struct ConfItem *
136 unmap_conf_item(void *aconf)
137 {
138  struct ConfItem *conf;
139
140  conf = (struct ConfItem *)((uintptr_t)aconf -
141                             (uintptr_t)sizeof(struct ConfItem));
142  return(conf);
143 }
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 153 | 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->addr, addr, sizeof(aconf->addr));
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 172 | 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   {
193  struct ConfItem *conf = NULL;
194  struct AccessItem *aconf = NULL;
195  struct ClassItem *aclass = NULL;
196  int status = 0;
197
136    switch (type)
137    {
138 <  case DLINE_TYPE:
139 <  case EXEMPTDLINE_TYPE:
202 <  case GLINE_TYPE:
203 <  case KLINE_TYPE:
204 <  case CLIENT_TYPE:
205 <  case OPER_TYPE:
206 <  case SERVER_TYPE:
207 <    conf = MyMalloc(sizeof(struct ConfItem) +
208 <                    sizeof(struct AccessItem));
209 <    aconf = map_to_conf(conf);
210 <    aconf->aftype = AF_INET;
211 <
212 <    /* Yes, sigh. switch on type again */
213 <    switch (type)
214 <    {
215 <    case EXEMPTDLINE_TYPE:
216 <      status = CONF_EXEMPTDLINE;
138 >    case CONF_OPER:
139 >      return &operator_items;
140        break;
141 <
142 <    case DLINE_TYPE:
220 <      status = CONF_DLINE;
221 <      break;
222 <
223 <    case KLINE_TYPE:
224 <      status = CONF_KLINE;
225 <      break;
226 <
227 <    case GLINE_TYPE:
228 <      status = CONF_GLINE;
141 >    case CONF_SERVER:
142 >      return &connect_items;
143        break;
230
231    case CLIENT_TYPE:
232      status = CONF_CLIENT;
233      break;
234
235    case OPER_TYPE:
236      status = CONF_OPERATOR;
237      dlinkAdd(conf, &conf->node, &oconf_items);
238      break;
239
240    case SERVER_TYPE:
241      status = CONF_SERVER;
242      dlinkAdd(conf, &conf->node, &server_items);
243      break;
244
144      default:
145 <      break;
247 <    }
248 <    aconf->status = status;
249 <    break;
250 <
251 <  case ULINE_TYPE:
252 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
253 <                                       sizeof(struct MatchItem));
254 <    dlinkAdd(conf, &conf->node, &uconf_items);
255 <    break;
256 <
257 <  case XLINE_TYPE:
258 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
259 <                                       sizeof(struct MatchItem));
260 <    dlinkAdd(conf, &conf->node, &xconf_items);
261 <    break;
262 < #ifdef HAVE_LIBPCRE
263 <  case RXLINE_TYPE:
264 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
265 <                                       sizeof(struct MatchItem));
266 <    dlinkAdd(conf, &conf->node, &rxconf_items);
267 <    break;
268 <
269 <  case RKLINE_TYPE:
270 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
271 <                                       sizeof(struct AccessItem));
272 <    aconf = map_to_conf(conf);
273 <    aconf->status = CONF_KLINE;
274 <    dlinkAdd(conf, &conf->node, &rkconf_items);
275 <    break;
276 < #endif
277 <  case CLUSTER_TYPE:
278 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem));
279 <    dlinkAdd(conf, &conf->node, &cluster_items);
280 <    break;
281 <
282 <  case CRESV_TYPE:
283 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
284 <                                       sizeof(struct ResvChannel));
285 <    break;
286 <
287 <  case NRESV_TYPE:
288 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
289 <                                       sizeof(struct MatchItem));
290 <    dlinkAdd(conf, &conf->node, &nresv_items);
291 <    break;
292 <
293 <  case SERVICE_TYPE:
294 <    status = CONF_SERVICE;
295 <    conf = MyMalloc(sizeof(struct ConfItem));
296 <    dlinkAdd(conf, &conf->node, &service_items);
297 <    break;
298 <
299 <  case CLASS_TYPE:
300 <    conf = MyMalloc(sizeof(struct ConfItem) +
301 <                           sizeof(struct ClassItem));
302 <    dlinkAdd(conf, &conf->node, &class_items);
303 <
304 <    aclass = map_to_conf(conf);
305 <    aclass->active = 1;
306 <    aclass->con_freq = DEFAULT_CONNECTFREQUENCY;
307 <    aclass->ping_freq = DEFAULT_PINGFREQUENCY;
308 <    aclass->max_total = MAXIMUM_LINKS_DEFAULT;
309 <    aclass->max_sendq = DEFAULT_SENDQ;
310 <    aclass->max_recvq = DEFAULT_RECVQ;
311 <
312 <    break;
313 <
314 <  default:
315 <    conf = NULL;
316 <    break;
145 >      return NULL;
146    }
318
319  /* XXX Yes, this will core if default is hit. I want it to for now - db */
320  conf->type = type;
321
322  return conf;
147   }
148  
149 < void
150 < delete_conf_item(struct ConfItem *conf)
149 > struct MaskItem *
150 > conf_make(enum maskitem_type type)
151   {
152 <  dlink_node *m = NULL, *m_next = NULL;
153 <  struct MatchItem *match_item;
330 <  struct AccessItem *aconf;
331 <  ConfType type = conf->type;
332 <
333 <  MyFree(conf->name);
334 <  conf->name = NULL;
335 <
336 <  switch(type)
337 <  {
338 <  case DLINE_TYPE:
339 <  case EXEMPTDLINE_TYPE:
340 <  case GLINE_TYPE:
341 <  case KLINE_TYPE:
342 <  case CLIENT_TYPE:
343 <  case OPER_TYPE:
344 <  case SERVER_TYPE:
345 <    aconf = map_to_conf(conf);
346 <
347 <    if (aconf->dns_pending)
348 <      delete_resolver_queries(aconf);
349 <    if (aconf->passwd != NULL)
350 <      memset(aconf->passwd, 0, strlen(aconf->passwd));
351 <    if (aconf->spasswd != NULL)
352 <      memset(aconf->spasswd, 0, strlen(aconf->spasswd));
353 <    aconf->class_ptr = NULL;
354 <
355 <    MyFree(aconf->passwd);
356 <    MyFree(aconf->spasswd);
357 <    MyFree(aconf->reason);
358 <    MyFree(aconf->oper_reason);
359 <    MyFree(aconf->user);
360 <    MyFree(aconf->host);
361 < #ifdef HAVE_LIBCRYPTO
362 <    MyFree(aconf->cipher_list);
363 <
364 <    if (aconf->rsa_public_key)
365 <      RSA_free(aconf->rsa_public_key);
366 <    MyFree(aconf->rsa_public_key_file);
367 < #endif
368 <
369 <    /* Yes, sigh. switch on type again */
370 <    switch(type)
371 <    {
372 <    case EXEMPTDLINE_TYPE:
373 <    case DLINE_TYPE:
374 <    case GLINE_TYPE:
375 <    case KLINE_TYPE:
376 <    case CLIENT_TYPE:
377 <      MyFree(conf);
378 <      break;
379 <
380 <    case OPER_TYPE:
381 <      aconf = map_to_conf(conf);
382 <      if (!IsConfIllegal(aconf))
383 <        dlinkDelete(&conf->node, &oconf_items);
384 <      MyFree(conf);
385 <      break;
386 <
387 <    case SERVER_TYPE:
388 <      aconf = map_to_conf(conf);
389 <
390 <      DLINK_FOREACH_SAFE(m, m_next, aconf->hub_list.head)
391 <      {
392 <        MyFree(m->data);
393 <        free_dlink_node(m);
394 <      }
395 <
396 <      DLINK_FOREACH_SAFE(m, m_next, aconf->leaf_list.head)
397 <      {
398 <        MyFree(m->data);
399 <        free_dlink_node(m);  
400 <      }
152 >  struct MaskItem *const conf = xcalloc(sizeof(*conf));
153 >  dlink_list *list = NULL;
154  
155 <      if (!IsConfIllegal(aconf))
156 <        dlinkDelete(&conf->node, &server_items);
157 <      MyFree(conf);
405 <      break;
406 <
407 <    default:
408 <      break;
409 <    }
410 <    break;
411 <
412 <  case ULINE_TYPE:
413 <    match_item = map_to_conf(conf);
414 <    MyFree(match_item->user);
415 <    MyFree(match_item->host);
416 <    MyFree(match_item->reason);
417 <    MyFree(match_item->oper_reason);
418 <    dlinkDelete(&conf->node, &uconf_items);
419 <    MyFree(conf);
420 <    break;
421 <
422 <  case XLINE_TYPE:
423 <    match_item = map_to_conf(conf);
424 <    MyFree(match_item->user);
425 <    MyFree(match_item->host);
426 <    MyFree(match_item->reason);
427 <    MyFree(match_item->oper_reason);
428 <    dlinkDelete(&conf->node, &xconf_items);
429 <    MyFree(conf);
430 <    break;
431 < #ifdef HAVE_LIBPCRE
432 <  case RKLINE_TYPE:
433 <    aconf = map_to_conf(conf);
434 <    MyFree(aconf->regexuser);
435 <    MyFree(aconf->regexhost);
436 <    MyFree(aconf->user);
437 <    MyFree(aconf->host);
438 <    MyFree(aconf->reason);
439 <    MyFree(aconf->oper_reason);
440 <    dlinkDelete(&conf->node, &rkconf_items);
441 <    MyFree(conf);
442 <    break;
443 <
444 <  case RXLINE_TYPE:
445 <    MyFree(conf->regexpname);
446 <    match_item = map_to_conf(conf);
447 <    MyFree(match_item->user);
448 <    MyFree(match_item->host);
449 <    MyFree(match_item->reason);
450 <    MyFree(match_item->oper_reason);
451 <    dlinkDelete(&conf->node, &rxconf_items);
452 <    MyFree(conf);
453 <    break;
454 < #endif
455 <  case NRESV_TYPE:
456 <    match_item = map_to_conf(conf);
457 <    MyFree(match_item->user);
458 <    MyFree(match_item->host);
459 <    MyFree(match_item->reason);
460 <    MyFree(match_item->oper_reason);
461 <    dlinkDelete(&conf->node, &nresv_items);
462 <
463 <    if (conf->flags & CONF_FLAGS_TEMPORARY)
464 <      if ((m = dlinkFindDelete(&temporary_resv, conf)) != NULL)
465 <        free_dlink_node(m);
466 <
467 <    MyFree(conf);
468 <    break;
469 <
470 <  case CLUSTER_TYPE:
471 <    dlinkDelete(&conf->node, &cluster_items);
472 <    MyFree(conf);
473 <    break;
474 <
475 <  case CRESV_TYPE:
476 <    if (conf->flags & CONF_FLAGS_TEMPORARY)
477 <      if ((m = dlinkFindDelete(&temporary_resv, conf)) != NULL)
478 <        free_dlink_node(m);
479 <
480 <    MyFree(conf);
481 <    break;
482 <
483 <  case CLASS_TYPE:
484 <    dlinkDelete(&conf->node, &class_items);
485 <    MyFree(conf);
486 <    break;
487 <
488 <  case SERVICE_TYPE:
489 <    dlinkDelete(&conf->node, &service_items);
490 <    MyFree(conf);
491 <    break;
492 <
493 <  default:
494 <    break;
495 <  }
496 < }
155 >  conf->type   = type;
156 >  conf->active = 1;
157 >  conf->aftype = AF_INET;
158  
159 < /* free_access_item()
160 < *
161 < * inputs       - pointer to conf to free
501 < * output       - none
502 < * side effects - crucial password fields are zeroed, conf is freed
503 < */
504 < void
505 < free_access_item(struct AccessItem *aconf)
506 < {
507 <  struct ConfItem *conf;
508 <
509 <  if (aconf == NULL)
510 <    return;
511 <  conf = unmap_conf_item(aconf);
512 <  delete_conf_item(conf);
159 >  if ((list = map_to_list(type)))
160 >    dlinkAdd(conf, &conf->node, list);
161 >  return conf;
162   }
163  
515 static const unsigned int shared_bit_table[] =
516  { 'K', 'k', 'U', 'X', 'x', 'Y', 'Q', 'q', 'R', 'L', 0};
517
518 /* report_confitem_types()
519 *
520 * inputs       - pointer to client requesting confitem report
521 *              - ConfType to report
522 * output       - none
523 * side effects -
524 */
164   void
165 < report_confitem_types(struct Client *source_p, ConfType type)
527 < {
528 <  dlink_node *ptr = NULL, *dptr = NULL;
529 <  struct ConfItem *conf = NULL;
530 <  struct AccessItem *aconf = NULL;
531 <  struct MatchItem *matchitem = NULL;
532 <  struct ClassItem *classitem = NULL;
533 <  char buf[12];
534 <  char *p = NULL;
535 <
536 <  switch (type)
537 <  {
538 <  case XLINE_TYPE:
539 <    DLINK_FOREACH(ptr, xconf_items.head)
540 <    {
541 <      conf = ptr->data;
542 <      matchitem = map_to_conf(conf);
543 <
544 <      sendto_one(source_p, form_str(RPL_STATSXLINE),
545 <                 me.name, source_p->name,
546 <                 matchitem->hold ? "x": "X", matchitem->count,
547 <                 conf->name, matchitem->reason);
548 <    }
549 <    break;
550 <
551 < #ifdef HAVE_LIBPCRE
552 <  case RXLINE_TYPE:
553 <    DLINK_FOREACH(ptr, rxconf_items.head)
554 <    {
555 <      conf = ptr->data;
556 <      matchitem = map_to_conf(conf);
557 <
558 <      sendto_one(source_p, form_str(RPL_STATSXLINE),
559 <                 me.name, source_p->name,
560 <                 "XR", matchitem->count,
561 <                 conf->name, matchitem->reason);
562 <    }
563 <    break;
564 <
565 <  case RKLINE_TYPE:
566 <    DLINK_FOREACH(ptr, rkconf_items.head)
567 <    {
568 <      aconf = map_to_conf((conf = ptr->data));
569 <
570 <      sendto_one(source_p, form_str(RPL_STATSKLINE), me.name,
571 <                 source_p->name, "KR", aconf->host, aconf->user,
572 <                 aconf->reason, aconf->oper_reason ? aconf->oper_reason : "");
573 <    }
574 <    break;
575 < #endif
576 <
577 <  case ULINE_TYPE:
578 <    DLINK_FOREACH(ptr, uconf_items.head)
579 <    {
580 <      conf = ptr->data;
581 <      matchitem = map_to_conf(conf);
582 <
583 <      p = buf;
584 <
585 <      /* some of these are redundant for the sake of
586 <       * consistency with cluster{} flags
587 <       */
588 <      *p++ = 'c';
589 <      flags_to_ascii(matchitem->action, shared_bit_table, p, 0);
590 <
591 <      sendto_one(source_p, form_str(RPL_STATSULINE),
592 <                 me.name, source_p->name, conf->name,
593 <                 matchitem->user?matchitem->user: "*",
594 <                 matchitem->host?matchitem->host: "*", buf);
595 <    }
596 <
597 <    DLINK_FOREACH(ptr, cluster_items.head)
598 <    {
599 <      conf = ptr->data;
600 <
601 <      p = buf;
602 <
603 <      *p++ = 'C';
604 <      flags_to_ascii(conf->flags, shared_bit_table, p, 0);
605 <
606 <      sendto_one(source_p, form_str(RPL_STATSULINE),
607 <                 me.name, source_p->name, conf->name,
608 <                 "*", "*", buf);
609 <    }
610 <
611 <    break;
612 <
613 <  case OPER_TYPE:
614 <    DLINK_FOREACH(ptr, oconf_items.head)
615 <    {
616 <      conf = ptr->data;
617 <      aconf = map_to_conf(conf);
618 <
619 <      /* Don't allow non opers to see oper privs */
620 <      if (HasUMode(source_p, UMODE_OPER))
621 <        sendto_one(source_p, form_str(RPL_STATSOLINE),
622 <                   me.name, source_p->name, 'O', aconf->user, aconf->host,
623 <                   conf->name, oper_privs_as_string(aconf->port),
624 <                   aconf->class_ptr ? aconf->class_ptr->name : "<default>");
625 <      else
626 <        sendto_one(source_p, form_str(RPL_STATSOLINE),
627 <                   me.name, source_p->name, 'O', aconf->user, aconf->host,
628 <                   conf->name, "0",
629 <                   aconf->class_ptr ? aconf->class_ptr->name : "<default>");
630 <    }
631 <    break;
632 <
633 <  case CLASS_TYPE:
634 <    DLINK_FOREACH(ptr, class_items.head)
635 <    {
636 <      conf = ptr->data;
637 <      classitem = map_to_conf(conf);
638 <      sendto_one(source_p, form_str(RPL_STATSYLINE),
639 <                 me.name, source_p->name, 'Y',
640 <                 conf->name, classitem->ping_freq,
641 <                 classitem->con_freq,
642 <                 classitem->max_total, classitem->max_sendq,
643 <                 classitem->max_recvq,
644 <                 classitem->curr_user_count,
645 <                 classitem->number_per_cidr, classitem->cidr_bitlen_ipv4,
646 <                 classitem->number_per_cidr, classitem->cidr_bitlen_ipv6,
647 <                 classitem->active ? "active" : "disabled");
648 <    }
649 <    break;
650 <
651 <  case CONF_TYPE:
652 <  case CLIENT_TYPE:
653 <    break;
654 <
655 <  case SERVICE_TYPE:
656 <    DLINK_FOREACH(ptr, service_items.head)
657 <    {
658 <      conf = ptr->data;
659 <      sendto_one(source_p, form_str(RPL_STATSSERVICE),
660 <                 me.name, source_p->name, 'S', "*", conf->name, 0, 0);
661 <    }
662 <    break;
663 <
664 <  case SERVER_TYPE:
665 <    DLINK_FOREACH(ptr, server_items.head)
666 <    {
667 <      p = buf;
668 <
669 <      conf = ptr->data;
670 <      aconf = map_to_conf(conf);
671 <
672 <      buf[0] = '\0';
673 <
674 <      if (IsConfAllowAutoConn(aconf))
675 <        *p++ = 'A';
676 <      if (IsConfSSL(aconf))
677 <        *p++ = 'S';
678 <      if (IsConfTopicBurst(aconf))
679 <        *p++ = 'T';
680 <      if (buf[0] == '\0')
681 <        *p++ = '*';
682 <
683 <      *p = '\0';
684 <
685 <      /*
686 <       * Allow admins to see actual ips unless hide_server_ips is enabled
687 <       */
688 <      if (!ConfigServerHide.hide_server_ips && HasUMode(source_p, UMODE_ADMIN))
689 <        sendto_one(source_p, form_str(RPL_STATSCLINE),
690 <                   me.name, source_p->name, 'C', aconf->host,
691 <                   buf, conf->name, aconf->port,
692 <                   aconf->class_ptr ? aconf->class_ptr->name : "<default>");
693 <        else
694 <          sendto_one(source_p, form_str(RPL_STATSCLINE),
695 <                     me.name, source_p->name, 'C',
696 <                     "*@127.0.0.1", buf, conf->name, aconf->port,
697 <                     aconf->class_ptr ? aconf->class_ptr->name : "<default>");
698 <    }
699 <    break;
700 <
701 <  case HUB_TYPE:
702 <    DLINK_FOREACH(ptr, server_items.head)
703 <    {
704 <      conf = ptr->data;
705 <      aconf = map_to_conf(conf);
706 <
707 <      DLINK_FOREACH(dptr, aconf->hub_list.head)
708 <        sendto_one(source_p, form_str(RPL_STATSHLINE), me.name,
709 <                   source_p->name, 'H', dptr->data, conf->name, 0, "*");
710 <    }
711 <    break;
712 <
713 <  case LEAF_TYPE:
714 <    DLINK_FOREACH(ptr, server_items.head)
715 <    {
716 <      conf = ptr->data;
717 <      aconf = map_to_conf(conf);
718 <
719 <      DLINK_FOREACH(dptr, aconf->leaf_list.head)
720 <        sendto_one(source_p, form_str(RPL_STATSLLINE), me.name,
721 <                   source_p->name, 'L', dptr->data, conf->name, 0, "*");
722 <    }
723 <    break;
724 <
725 <  case GLINE_TYPE:
726 <  case KLINE_TYPE:
727 <  case DLINE_TYPE:
728 <  case EXEMPTDLINE_TYPE:
729 <  case CRESV_TYPE:
730 <  case NRESV_TYPE:
731 <  case CLUSTER_TYPE:
732 <  default:
733 <    break;
734 <  }
735 < }
736 <
737 < /* check_client()
738 < *
739 < * inputs       - pointer to client
740 < * output       - 0 = Success
741 < *                NOT_AUTHORIZED    (-1) = Access denied (no I line match)
742 < *                IRCD_SOCKET_ERROR (-2) = Bad socket.
743 < *                I_LINE_FULL       (-3) = I-line is full
744 < *                TOO_MANY          (-4) = Too many connections from hostname
745 < *                BANNED_CLIENT     (-5) = K-lined
746 < * side effects - Ordinary client access check.
747 < *                Look for conf lines which have the same
748 < *                status as the flags passed.
749 < */
750 < static void *
751 < check_client(va_list args)
165 > conf_free(struct MaskItem *conf)
166   {
167 <  struct Client *source_p = va_arg(args, struct Client *);
168 <  const char *username = va_arg(args, const char *);
755 <  int i;
756 <
757 <  /* I'm already in big trouble if source_p->localClient is NULL -db */
758 <  if ((i = verify_access(source_p, username)))
759 <    ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
760 <         source_p->name, source_p->sockhost);
167 >  dlink_node *node = NULL, *node_next = NULL;
168 >  dlink_list *list = NULL;
169  
170 <  switch (i)
171 <  {
764 <    case TOO_MANY:
765 <      sendto_realops_flags(UMODE_FULL, L_ALL,
766 <                           "Too many on IP for %s (%s).",
767 <                           get_client_name(source_p, SHOW_IP),
768 <                           source_p->sockhost);
769 <      ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
770 <           get_client_name(source_p, SHOW_IP));
771 <      ++ServerStats.is_ref;
772 <      exit_client(source_p, &me, "No more connections allowed on that IP");
773 <      break;
170 >  if ((list = map_to_list(conf->type)))
171 >    dlinkFindDelete(list, conf);
172  
173 <    case I_LINE_FULL:
776 <      sendto_realops_flags(UMODE_FULL, L_ALL,
777 <                           "I-line is full for %s (%s).",
778 <                           get_client_name(source_p, SHOW_IP),
779 <                           source_p->sockhost);
780 <      ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
781 <           get_client_name(source_p, SHOW_IP));
782 <      ++ServerStats.is_ref;
783 <      exit_client(source_p, &me,
784 <                "No more connections allowed in your connection class");
785 <      break;
173 >  xfree(conf->name);
174  
175 <    case NOT_AUTHORIZED:
176 <      ++ServerStats.is_ref;
177 <      /* jdc - lists server name & port connections are on */
178 <      /*       a purely cosmetical change */
179 <      sendto_realops_flags(UMODE_UNAUTH, L_ALL,
180 <                           "Unauthorized client connection from %s [%s] on [%s/%u].",
793 <                           get_client_name(source_p, SHOW_IP),
794 <                           source_p->sockhost,
795 <                           source_p->localClient->listener->name,
796 <                           source_p->localClient->listener->port);
797 <      ilog(LOG_TYPE_IRCD,
798 <          "Unauthorized client connection from %s on [%s/%u].",
799 <          get_client_name(source_p, SHOW_IP),
800 <          source_p->localClient->listener->name,
801 <          source_p->localClient->listener->port);
802 <
803 <      /* XXX It is prolematical whether it is better to use the
804 <       * capture reject code here or rely on the connecting too fast code.
805 <       * - Dianora
806 <       */
807 <      if (REJECT_HOLD_TIME > 0)
808 <      {
809 <        sendto_one(source_p, ":%s NOTICE %s :You are not authorized to use this server",
810 <                   me.name, source_p->name);
811 <        source_p->localClient->reject_delay = CurrentTime + REJECT_HOLD_TIME;
812 <        SetCaptured(source_p);
813 <      }
814 <      else
815 <        exit_client(source_p, &me, "You are not authorized to use this server");
816 <      break;
175 >  if (conf->dns_pending)
176 >    delete_resolver_queries(conf);
177 >  if (conf->passwd)
178 >    memset(conf->passwd, 0, strlen(conf->passwd));
179 >  if (conf->spasswd)
180 >    memset(conf->spasswd, 0, strlen(conf->spasswd));
181  
182 <   case BANNED_CLIENT:
819 <     /*
820 <      * Don't exit them immediately, play with them a bit.
821 <      * - Dianora
822 <      */
823 <     if (REJECT_HOLD_TIME > 0)
824 <     {
825 <       source_p->localClient->reject_delay = CurrentTime + REJECT_HOLD_TIME;
826 <       SetCaptured(source_p);
827 <     }
828 <     else
829 <       exit_client(source_p, &me, "Banned");
830 <     ++ServerStats.is_ref;
831 <     break;
832 <
833 <   case 0:
834 <   default:
835 <     break;
836 <  }
182 >  conf->class = NULL;
183  
184 <  return (i < 0 ? NULL : source_p);
185 < }
184 >  xfree(conf->passwd);
185 >  xfree(conf->spasswd);
186 >  xfree(conf->reason);
187 >  xfree(conf->certfp);
188 >  xfree(conf->whois);
189 >  xfree(conf->user);
190 >  xfree(conf->host);
191 >  xfree(conf->cipher_list);
192  
193 < /* verify_access()
842 < *
843 < * inputs       - pointer to client to verify
844 < *              - pointer to proposed username
845 < * output       - 0 if success -'ve if not
846 < * side effect  - find the first (best) I line to attach.
847 < */
848 < static int
849 < verify_access(struct Client *client_p, const char *username)
850 < {
851 <  struct AccessItem *aconf = NULL, *rkconf = NULL;
852 <  struct ConfItem *conf = NULL;
853 <  char non_ident[USERLEN + 1] = { '~', '\0' };
854 <  const char *uhi[3];
855 <
856 <  if (IsGotId(client_p))
857 <  {
858 <    aconf = find_address_conf(client_p->host, client_p->username,
859 <                             &client_p->localClient->ip,
860 <                             client_p->localClient->aftype,
861 <                             client_p->localClient->passwd);
862 <  }
863 <  else
193 >  DLINK_FOREACH_SAFE(node, node_next, conf->hub_list.head)
194    {
195 <    strlcpy(non_ident+1, username, sizeof(non_ident)-1);
196 <    aconf = find_address_conf(client_p->host,non_ident,
197 <                             &client_p->localClient->ip,
868 <                             client_p->localClient->aftype,
869 <                             client_p->localClient->passwd);
195 >    xfree(node->data);
196 >    dlinkDelete(node, &conf->hub_list);
197 >    free_dlink_node(node);
198    }
199  
200 <  uhi[0] = IsGotId(client_p) ? client_p->username : non_ident;
873 <  uhi[1] = client_p->host;
874 <  uhi[2] = client_p->sockhost;
875 <
876 <  rkconf = find_regexp_kline(uhi);
877 <
878 <  if (aconf != NULL)
200 >  DLINK_FOREACH_SAFE(node, node_next, conf->leaf_list.head)
201    {
202 <    if (IsConfClient(aconf) && !rkconf)
203 <    {
204 <      conf = unmap_conf_item(aconf);
883 <
884 <      if (IsConfRedir(aconf))
885 <      {
886 <        sendto_one(client_p, form_str(RPL_REDIR),
887 <                   me.name, client_p->name,
888 <                   conf->name ? conf->name : "",
889 <                   aconf->port);
890 <        return(NOT_AUTHORIZED);
891 <      }
892 <
893 <      if (IsConfDoIdentd(aconf))
894 <        SetNeedId(client_p);
895 <
896 <      /* Thanks for spoof idea amm */
897 <      if (IsConfDoSpoofIp(aconf))
898 <      {
899 <        conf = unmap_conf_item(aconf);
900 <
901 <        if (!ConfigFileEntry.hide_spoof_ips && IsConfSpoofNotice(aconf))
902 <          sendto_realops_flags(UMODE_ALL, L_ADMIN, "%s spoofing: %s as %s",
903 <                               client_p->name, client_p->host, conf->name);
904 <        strlcpy(client_p->host, conf->name, sizeof(client_p->host));
905 <        SetIPSpoof(client_p);
906 <      }
907 <
908 <      return(attach_iline(client_p, conf));
909 <    }
910 <    else if (rkconf || IsConfKill(aconf) || (ConfigFileEntry.glines && IsConfGline(aconf)))
911 <    {
912 <      /* XXX */
913 <      aconf = rkconf ? rkconf : aconf;
914 <      if (IsConfGline(aconf))
915 <        sendto_one(client_p, ":%s NOTICE %s :*** G-lined", me.name,
916 <                   client_p->name);
917 <      if (ConfigFileEntry.kline_with_reason)
918 <        sendto_one(client_p, ":%s NOTICE %s :*** Banned %s",
919 <                  me.name, client_p->name, aconf->reason);
920 <      return(BANNED_CLIENT);
921 <    }
202 >    xfree(node->data);
203 >    dlinkDelete(node, &conf->leaf_list);
204 >    free_dlink_node(node);
205    }
206  
207 <  return(NOT_AUTHORIZED);
207 >  xfree(conf);
208   }
209  
210   /* attach_iline()
211   *
212 < * inputs       - client pointer
213 < *              - conf pointer
214 < * output       -
215 < * side effects - do actual attach
212 > * inputs       - client pointer
213 > *              - conf pointer
214 > * output       -
215 > * side effects - do actual attach
216   */
217   static int
218 < attach_iline(struct Client *client_p, struct ConfItem *conf)
218 > attach_iline(struct Client *client_p, struct MaskItem *conf)
219   {
220 <  struct AccessItem *aconf;
938 <  struct ClassItem *aclass;
220 >  const struct ClassItem *const class = conf->class;
221    struct ip_entry *ip_found;
222    int a_limit_reached = 0;
223 <  int local = 0, global = 0, ident = 0;
223 >  unsigned int local = 0, global = 0;
224  
225 <  ip_found = find_or_add_ip(&client_p->localClient->ip);
225 >  ip_found = ipcache_find_or_add_address(&client_p->connection->ip);
226    ip_found->count++;
227 <  SetIpHash(client_p);
946 <
947 <  aconf = map_to_conf(conf);
948 <  if (aconf->class_ptr == NULL)
949 <    return NOT_AUTHORIZED;  /* If class is missing, this is best */
227 >  AddFlag(client_p, FLAGS_IPHASH);
228  
229 <  aclass = map_to_conf(aconf->class_ptr);
952 <
953 <  count_user_host(client_p->username, client_p->host,
954 <                  &global, &local, &ident);
229 >  userhost_count(client_p->sockhost, &global, &local);
230  
231    /* XXX blah. go down checking the various silly limits
232     * setting a_limit_reached if any limit is reached.
233     * - Dianora
234     */
235 <  if (aclass->max_total != 0 && aclass->curr_user_count >= aclass->max_total)
961 <    a_limit_reached = 1;
962 <  else if (aclass->max_perip != 0 && ip_found->count > aclass->max_perip)
235 >  if (class->max_total && class->ref_count >= class->max_total)
236      a_limit_reached = 1;
237 <  else if (aclass->max_local != 0 && local >= aclass->max_local)
237 >  else if (class->max_perip && ip_found->count > class->max_perip)
238      a_limit_reached = 1;
239 <  else if (aclass->max_global != 0 && global >= aclass->max_global)
239 >  else if (class->max_local && local >= class->max_local) /* XXX: redundant */
240      a_limit_reached = 1;
241 <  else if (aclass->max_ident != 0 && ident >= aclass->max_ident &&
969 <           client_p->username[0] != '~')
241 >  else if (class->max_global && global >= class->max_global)
242      a_limit_reached = 1;
243  
244    if (a_limit_reached)
245    {
246 <    if (!IsConfExemptLimits(aconf))
246 >    if (!IsConfExemptLimits(conf))
247        return TOO_MANY;   /* Already at maximum allowed */
248  
249 <    sendto_one(client_p,
250 <               ":%s NOTICE %s :*** Your connection class is full, "
979 <               "but you have exceed_limit = yes;", me.name, client_p->name);
249 >    sendto_one_notice(client_p, &me, ":*** Your connection class is full, "
250 >                      "but you have exceed_limit = yes;");
251    }
252  
253    return attach_conf(client_p, conf);
254   }
255  
256 < /* init_ip_hash_table()
986 < *
987 < * inputs               - NONE
988 < * output               - NONE
989 < * side effects         - allocate memory for ip_entry(s)
990 < *                      - clear the ip hash table
991 < */
992 < void
993 < init_ip_hash_table(void)
994 < {
995 <  ip_entry_heap = BlockHeapCreate("ip", sizeof(struct ip_entry),
996 <    2 * hard_fdlimit);
997 <  memset(ip_hash_table, 0, sizeof(ip_hash_table));
998 < }
999 <
1000 < /* find_or_add_ip()
1001 < *
1002 < * inputs       - pointer to struct irc_ssaddr
1003 < * output       - pointer to a struct ip_entry
1004 < * side effects -
256 > /* verify_access()
257   *
258 < * If the ip # was not found, a new struct ip_entry is created, and the ip
259 < * count set to 0.
258 > * inputs       - pointer to client to verify
259 > * output       - 0 if success -'ve if not
260 > * side effect  - find the first (best) I line to attach.
261   */
262 < static struct ip_entry *
263 < find_or_add_ip(struct irc_ssaddr *ip_in)
262 > static int
263 > verify_access(struct Client *client_p)
264   {
265 <  struct ip_entry *ptr, *newptr;
1013 <  int hash_index = hash_ip(ip_in), res;
1014 <  struct sockaddr_in *v4 = (struct sockaddr_in *)ip_in, *ptr_v4;
1015 < #ifdef IPV6
1016 <  struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)ip_in, *ptr_v6;
1017 < #endif
265 >  struct MaskItem *conf = NULL;
266  
267 <  for (ptr = ip_hash_table[hash_index]; ptr; ptr = ptr->next)
267 >  if (HasFlag(client_p, FLAGS_GOTID))
268    {
269 < #ifdef IPV6
270 <    if (ptr->ip.ss.ss_family != ip_in->ss.ss_family)
271 <      continue;
272 <    if (ip_in->ss.ss_family == AF_INET6)
1025 <    {
1026 <      ptr_v6 = (struct sockaddr_in6 *)&ptr->ip;
1027 <      res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr));
1028 <    }
1029 <    else
1030 < #endif
1031 <    {
1032 <      ptr_v4 = (struct sockaddr_in *)&ptr->ip;
1033 <      res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr));
1034 <    }
1035 <    if (res == 0)
1036 <    {
1037 <      /* Found entry already in hash, return it. */
1038 <      return ptr;
1039 <    }
269 >    conf = find_address_conf(client_p->host, client_p->username,
270 >                             &client_p->connection->ip,
271 >                             client_p->connection->aftype,
272 >                             client_p->connection->password);
273    }
274 +  else
275 +  {
276 +    char non_ident[USERLEN + 1] = "~";
277  
278 <  if (ip_entries_count >= 2 * hard_fdlimit)
279 <    garbage_collect_ip_entries();
280 <
281 <  newptr = BlockHeapAlloc(ip_entry_heap);
282 <  ip_entries_count++;
283 <  memcpy(&newptr->ip, ip_in, sizeof(struct irc_ssaddr));
1048 <
1049 <  newptr->next = ip_hash_table[hash_index];
1050 <  ip_hash_table[hash_index] = newptr;
278 >    strlcpy(non_ident + 1, client_p->username, sizeof(non_ident) - 1);
279 >    conf = find_address_conf(client_p->host, non_ident,
280 >                             &client_p->connection->ip,
281 >                             client_p->connection->aftype,
282 >                             client_p->connection->password);
283 >  }
284  
285 <  return newptr;
286 < }
285 >  if (!conf)
286 >    return NOT_AUTHORIZED;
287  
288 < /* remove_one_ip()
1056 < *
1057 < * inputs        - unsigned long IP address value
1058 < * output        - NONE
1059 < * side effects  - The ip address given, is looked up in ip hash table
1060 < *                 and number of ip#'s for that ip decremented.
1061 < *                 If ip # count reaches 0 and has expired,
1062 < *                 the struct ip_entry is returned to the ip_entry_heap
1063 < */
1064 < void
1065 < remove_one_ip(struct irc_ssaddr *ip_in)
1066 < {
1067 <  struct ip_entry *ptr;
1068 <  struct ip_entry *last_ptr = NULL;
1069 <  int hash_index = hash_ip(ip_in), res;
1070 <  struct sockaddr_in *v4 = (struct sockaddr_in *)ip_in, *ptr_v4;
1071 < #ifdef IPV6
1072 <  struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)ip_in, *ptr_v6;
1073 < #endif
288 >  assert(IsConfClient(conf) || IsConfKill(conf));
289  
290 <  for (ptr = ip_hash_table[hash_index]; ptr; ptr = ptr->next)
290 >  if (IsConfClient(conf))
291    {
292 < #ifdef IPV6
1078 <    if (ptr->ip.ss.ss_family != ip_in->ss.ss_family)
1079 <      continue;
1080 <    if (ip_in->ss.ss_family == AF_INET6)
292 >    if (IsConfRedir(conf))
293      {
294 <      ptr_v6 = (struct sockaddr_in6 *)&ptr->ip;
295 <      res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr));
294 >      sendto_one_numeric(client_p, &me, RPL_REDIR,
295 >                         conf->name ? conf->name : "",
296 >                         conf->port);
297 >      return NOT_AUTHORIZED;
298      }
299 <    else
300 < #endif
1087 <    {
1088 <      ptr_v4 = (struct sockaddr_in *)&ptr->ip;
1089 <      res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr));
1090 <    }
1091 <    if (res)
1092 <      continue;
1093 <    if (ptr->count > 0)
1094 <      ptr->count--;
1095 <    if (ptr->count == 0 &&
1096 <        (CurrentTime-ptr->last_attempt) >= ConfigFileEntry.throttle_time)
299 >
300 >    if (IsConfDoSpoofIp(conf))
301      {
302 <      if (last_ptr != NULL)
303 <        last_ptr->next = ptr->next;
304 <      else
1101 <        ip_hash_table[hash_index] = ptr->next;
302 >      if (IsConfSpoofNotice(conf))
303 >        sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, "%s spoofing: %s as %s",
304 >                             client_p->name, client_p->host, conf->name);
305  
306 <      BlockHeapFree(ip_entry_heap, ptr);
1104 <      ip_entries_count--;
1105 <      return;
306 >      strlcpy(client_p->host, conf->name, sizeof(client_p->host));
307      }
1107    last_ptr = ptr;
1108  }
1109 }
308  
309 < /* hash_ip()
1112 < *
1113 < * input        - pointer to an irc_inaddr
1114 < * output       - integer value used as index into hash table
1115 < * side effects - hopefully, none
1116 < */
1117 < static int
1118 < hash_ip(struct irc_ssaddr *addr)
1119 < {
1120 <  if (addr->ss.ss_family == AF_INET)
1121 <  {
1122 <    struct sockaddr_in *v4 = (struct sockaddr_in *)addr;
1123 <    int hash;
1124 <    uint32_t ip;
1125 <
1126 <    ip   = ntohl(v4->sin_addr.s_addr);
1127 <    hash = ((ip >> 12) + ip) & (IP_HASH_SIZE-1);
1128 <    return hash;
309 >    return attach_iline(client_p, conf);
310    }
311 < #ifdef IPV6
312 <  else
313 <  {
1133 <    int hash;
1134 <    struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr;
1135 <    uint32_t *ip = (uint32_t *)&v6->sin6_addr.s6_addr;
1136 <
1137 <    hash  = ip[0] ^ ip[3];
1138 <    hash ^= hash >> 16;  
1139 <    hash ^= hash >> 8;  
1140 <    hash  = hash & (IP_HASH_SIZE - 1);
1141 <    return hash;
1142 <  }
1143 < #else
1144 <  return 0;
1145 < #endif
311 >
312 >  sendto_one_notice(client_p, &me, ":*** Banned: %s", conf->reason);
313 >  return BANNED_CLIENT;
314   }
315  
316 < /* count_ip_hash()
1149 < *
1150 < * inputs        - pointer to counter of number of ips hashed
1151 < *               - pointer to memory used for ip hash
1152 < * output        - returned via pointers input
1153 < * side effects  - NONE
316 > /* check_client()
317   *
318 < * number of hashed ip #'s is counted up, plus the amount of memory
319 < * used in the hash.
318 > * inputs       - pointer to client
319 > * output       - 0 = Success
320 > *                NOT_AUTHORIZED    (-1) = Access denied (no I line match)
321 > *                IRCD_SOCKET_ERROR (-2) = Bad socket.
322 > *                I_LINE_FULL       (-3) = I-line is full
323 > *                TOO_MANY          (-4) = Too many connections from hostname
324 > *                BANNED_CLIENT     (-5) = K-lined
325 > * side effects - Ordinary client access check.
326 > *                Look for conf lines which have the same
327 > *                status as the flags passed.
328   */
329 < void
330 < count_ip_hash(unsigned int *number_ips_stored, uint64_t *mem_ips_stored)
329 > int
330 > check_client(struct Client *source_p)
331   {
1161  struct ip_entry *ptr;
332    int i;
333  
334 <  *number_ips_stored = 0;
335 <  *mem_ips_stored    = 0;
334 >  if ((i = verify_access(source_p)))
335 >    ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
336 >         source_p->name, source_p->sockhost);
337  
338 <  for (i = 0; i < IP_HASH_SIZE; i++)
338 >  switch (i)
339    {
340 <    for (ptr = ip_hash_table[i]; ptr; ptr = ptr->next)
341 <    {
342 <      *number_ips_stored += 1;
343 <      *mem_ips_stored += sizeof(struct ip_entry);
344 <    }
345 <  }
346 < }
340 >    case TOO_MANY:
341 >      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
342 >                           "Too many on IP for %s (%s).",
343 >                           client_get_name(source_p, SHOW_IP),
344 >                           source_p->sockhost);
345 >      ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
346 >           client_get_name(source_p, SHOW_IP));
347 >      ++ServerStats.is_ref;
348 >      exit_client(source_p, "No more connections allowed on that IP");
349 >      break;
350  
351 < /* garbage_collect_ip_entries()
352 < *
353 < * input        - NONE
354 < * output       - NONE
355 < * side effects - free up all ip entries with no connections
356 < */
357 < static void
358 < garbage_collect_ip_entries(void)
359 < {
360 <  struct ip_entry *ptr;
1187 <  struct ip_entry *last_ptr;
1188 <  struct ip_entry *next_ptr;
1189 <  int i;
351 >    case I_LINE_FULL:
352 >      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
353 >                           "auth {} block is full for %s (%s).",
354 >                           client_get_name(source_p, SHOW_IP),
355 >                           source_p->sockhost);
356 >      ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
357 >           client_get_name(source_p, SHOW_IP));
358 >      ++ServerStats.is_ref;
359 >      exit_client(source_p, "No more connections allowed in your connection class");
360 >      break;
361  
362 <  for (i = 0; i < IP_HASH_SIZE; i++)
363 <  {
364 <    last_ptr = NULL;
362 >    case NOT_AUTHORIZED:
363 >      /* jdc - lists server name & port connections are on */
364 >      /*       a purely cosmetical change */
365 >      sendto_realops_flags(UMODE_UNAUTH, L_ALL, SEND_NOTICE,
366 >                           "Unauthorized client connection from %s on [%s/%u].",
367 >                           client_get_name(source_p, SHOW_IP),
368 >                           source_p->connection->listener->name,
369 >                           source_p->connection->listener->port);
370 >      ilog(LOG_TYPE_IRCD, "Unauthorized client connection from %s on [%s/%u].",
371 >           client_get_name(source_p, SHOW_IP),
372 >           source_p->connection->listener->name,
373 >           source_p->connection->listener->port);
374  
375 <    for (ptr = ip_hash_table[i]; ptr; ptr = next_ptr)
376 <    {
377 <      next_ptr = ptr->next;
375 >      ++ServerStats.is_ref;
376 >      exit_client(source_p, "You are not authorized to use this server");
377 >      break;
378  
379 <      if (ptr->count == 0 &&
380 <          (CurrentTime - ptr->last_attempt) >= ConfigFileEntry.throttle_time)
381 <      {
382 <        if (last_ptr != NULL)
383 <          last_ptr->next = ptr->next;
384 <        else
385 <          ip_hash_table[i] = ptr->next;
386 <        BlockHeapFree(ip_entry_heap, ptr);
1207 <        ip_entries_count--;
1208 <      }
1209 <      else
1210 <        last_ptr = ptr;
1211 <    }
379 >    case BANNED_CLIENT:
380 >      ++ServerStats.is_ref;
381 >      exit_client(source_p, "Banned");
382 >      break;
383 >
384 >    case 0:
385 >    default:
386 >      break;
387    }
388 +
389 +  return !(i < 0);
390   }
391  
392   /* detach_conf()
# Line 1220 | Line 397 | garbage_collect_ip_entries(void)
397   * side effects - Disassociate configuration from the client.
398   *                Also removes a class from the list if marked for deleting.
399   */
400 < int
401 < detach_conf(struct Client *client_p, ConfType type)
400 > void
401 > detach_conf(struct Client *client_p, enum maskitem_type type)
402   {
403 <  dlink_node *ptr, *next_ptr;
1227 <  struct ConfItem *conf;
1228 <  struct ClassItem *aclass;
1229 <  struct AccessItem *aconf;
1230 <  struct ConfItem *aclass_conf;
1231 <  struct MatchItem *match_item;
403 >  dlink_node *node = NULL, *node_next = NULL;
404  
405 <  DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->confs.head)
405 >  DLINK_FOREACH_SAFE(node, node_next, client_p->connection->confs.head)
406    {
407 <    conf = ptr->data;
1236 <
1237 <    if (type == CONF_TYPE || conf->type == type)
1238 <    {
1239 <      dlinkDelete(ptr, &client_p->localClient->confs);
1240 <      free_dlink_node(ptr);
1241 <
1242 <      switch (conf->type)
1243 <      {
1244 <      case CLIENT_TYPE:
1245 <      case OPER_TYPE:
1246 <      case SERVER_TYPE:
1247 <        aconf = map_to_conf(conf);
1248 <
1249 <        assert(aconf->clients > 0);
1250 <
1251 <        if ((aclass_conf = aconf->class_ptr) != NULL)
1252 <        {
1253 <          aclass = map_to_conf(aclass_conf);
407 >    struct MaskItem *conf = node->data;
408  
409 <          assert(aclass->curr_user_count > 0);
409 >    assert(conf->type & (CONF_CLIENT | CONF_OPER | CONF_SERVER));
410 >    assert(conf->ref_count > 0);
411 >    assert(conf->class->ref_count > 0);
412  
413 <          if (conf->type == CLIENT_TYPE)
414 <            remove_from_cidr_check(&client_p->localClient->ip, aclass);
1259 <          if (--aclass->curr_user_count == 0 && aclass->active == 0)
1260 <            delete_conf_item(aclass_conf);
1261 <        }
413 >    if (!(conf->type & type))
414 >      continue;
415  
416 <        if (--aconf->clients == 0 && IsConfIllegal(aconf))
417 <          delete_conf_item(conf);
416 >    dlinkDelete(node, &client_p->connection->confs);
417 >    free_dlink_node(node);
418  
419 <        break;
420 <      default:
1268 <        break;
1269 <      }
419 >    if (conf->type == CONF_CLIENT)
420 >      remove_from_cidr_check(&client_p->connection->ip, conf->class);
421  
422 <      if (type != CONF_TYPE)
423 <        return 0;
422 >    if (--conf->class->ref_count == 0 && conf->class->active == 0)
423 >    {
424 >      class_free(conf->class);
425 >      conf->class = NULL;
426      }
1274  }
427  
428 <  return -1;
428 >    if (--conf->ref_count == 0 && conf->active == 0)
429 >      conf_free(conf);
430 >  }
431   }
432  
433   /* attach_conf()
# Line 1287 | Line 441 | detach_conf(struct Client *client_p, Con
441   *                attachment if there was an old one...
442   */
443   int
444 < attach_conf(struct Client *client_p, struct ConfItem *conf)
444 > attach_conf(struct Client *client_p, struct MaskItem *conf)
445   {
446 <  struct AccessItem *aconf = map_to_conf(conf);
1293 <  struct ClassItem *aclass = map_to_conf(aconf->class_ptr);
1294 <
1295 <  if (dlinkFind(&client_p->localClient->confs, conf) != NULL)
446 >  if (dlinkFind(&client_p->connection->confs, conf))
447      return 1;
448  
449 <  if (IsConfIllegal(aconf)) /* TBV: can't happen */
450 <    return NOT_AUTHORIZED;
451 <
1301 <  if (conf->type == CLIENT_TYPE)
1302 <    if (cidr_limit_reached(IsConfExemptLimits(aconf),
1303 <                           &client_p->localClient->ip, aclass))
449 >  if (conf->type == CONF_CLIENT)
450 >    if (cidr_limit_reached(IsConfExemptLimits(conf),
451 >                           &client_p->connection->ip, conf->class))
452        return TOO_MANY;    /* Already at maximum allowed */
453  
454 <  aclass->curr_user_count++;
455 <  aconf->clients++;
454 >  conf->class->ref_count++;
455 >  conf->ref_count++;
456  
457 <  dlinkAdd(conf, make_dlink_node(), &client_p->localClient->confs);
457 >  dlinkAdd(conf, make_dlink_node(), &client_p->connection->confs);
458  
459    return 0;
460   }
# Line 1323 | Line 471 | int
471   attach_connect_block(struct Client *client_p, const char *name,
472                       const char *host)
473   {
474 <  dlink_node *ptr;
1327 <  struct ConfItem *conf;
1328 <  struct AccessItem *aconf;
1329 <
1330 <  assert(client_p != NULL);
1331 <  assert(host != NULL);
474 >  dlink_node *node = NULL;
475  
476 <  if (client_p == NULL || host == NULL)
1334 <    return 0;
476 >  assert(host);
477  
478 <  DLINK_FOREACH(ptr, server_items.head)
478 >  DLINK_FOREACH(node, connect_items.head)
479    {
480 <    conf = ptr->data;
1339 <    aconf = map_to_conf(conf);
480 >    struct MaskItem *conf = node->data;
481  
482 <    if (match(conf->name, name) == 0 || match(aconf->host, host) == 0)
482 >    if (irccmp(conf->name, name) ||
483 >        irccmp(conf->host, host))
484        continue;
485  
486      attach_conf(client_p, conf);
487 <    return -1;
487 >    return 1;
488    }
489  
490    return 0;
491   }
492  
1351 /* find_conf_exact()
1352 *
1353 * inputs       - type of ConfItem
1354 *              - pointer to name to find
1355 *              - pointer to username to find
1356 *              - pointer to host to find
1357 * output       - NULL or pointer to conf found
1358 * side effects - find a conf entry which matches the hostname
1359 *                and has the same name.
1360 */
1361 struct ConfItem *
1362 find_conf_exact(ConfType type, const char *name, const char *user,
1363                const char *host)
1364 {
1365  dlink_node *ptr;
1366  dlink_list *list_p;
1367  struct ConfItem *conf = NULL;
1368  struct AccessItem *aconf;
1369
1370  /* Only valid for OPER_TYPE and ...? */
1371  list_p = map_to_list(type);
1372
1373  DLINK_FOREACH(ptr, (*list_p).head)
1374  {
1375    conf = ptr->data;
1376
1377    if (conf->name == NULL)
1378      continue;
1379    aconf = map_to_conf(conf);
1380    if (aconf->host == NULL)
1381      continue;
1382    if (irccmp(conf->name, name) != 0)
1383      continue;
1384
1385    /*
1386    ** Accept if the *real* hostname (usually sockethost)
1387    ** socket host) matches *either* host or name field
1388    ** of the configuration.
1389    */
1390    if (!match(aconf->host, host) || !match(aconf->user, user))
1391      continue;
1392    if (type == OPER_TYPE)
1393    {
1394      struct ClassItem *aclass = map_to_conf(aconf->class_ptr);
1395
1396      if (aconf->clients >= aclass->max_total)
1397        continue;
1398    }
1399
1400    return conf;
1401  }
1402
1403  return NULL;
1404 }
1405
493   /* find_conf_name()
494   *
495   * inputs       - pointer to conf link list to search
# Line 1412 | Line 499 | find_conf_exact(ConfType type, const cha
499   * side effects - find a conf entry which matches the name
500   *                and has the given mask.
501   */
502 < struct ConfItem *
503 < find_conf_name(dlink_list *list, const char *name, ConfType type)
502 > struct MaskItem *
503 > find_conf_name(dlink_list *list, const char *name, enum maskitem_type type)
504   {
505 <  dlink_node *ptr;
1419 <  struct ConfItem* conf;
505 >  dlink_node *node = NULL;
506  
507 <  DLINK_FOREACH(ptr, list->head)
507 >  DLINK_FOREACH(node, list->head)
508    {
509 <    conf = ptr->data;
510 <    
509 >    struct MaskItem *conf = node->data;
510 >
511      if (conf->type == type)
512      {
513 <      if (conf->name && (irccmp(conf->name, name) == 0 ||
514 <                         match(conf->name, name)))
1429 <      return conf;
513 >      if (conf->name && !irccmp(conf->name, name))
514 >        return conf;
515      }
516    }
517  
518    return NULL;
519   }
520  
1436 /* map_to_list()
1437 *
1438 * inputs       - ConfType conf
1439 * output       - pointer to dlink_list to use
1440 * side effects - none
1441 */
1442 static dlink_list *
1443 map_to_list(ConfType type)
1444 {
1445  switch(type)
1446  {
1447  case RXLINE_TYPE:
1448    return(&rxconf_items);
1449    break;
1450  case XLINE_TYPE:
1451    return(&xconf_items);
1452    break;
1453  case ULINE_TYPE:
1454    return(&uconf_items);
1455    break;
1456  case NRESV_TYPE:
1457    return(&nresv_items);
1458    break;
1459  case OPER_TYPE:
1460    return(&oconf_items);
1461    break;
1462  case CLASS_TYPE:
1463    return(&class_items);
1464    break;
1465  case SERVER_TYPE:
1466    return(&server_items);
1467    break;
1468  case SERVICE_TYPE:
1469    return(&service_items);
1470    break;
1471  case CLUSTER_TYPE:
1472    return(&cluster_items);
1473    break;
1474  case CONF_TYPE:
1475  case GLINE_TYPE:
1476  case KLINE_TYPE:
1477  case DLINE_TYPE:
1478  case CRESV_TYPE:
1479  default:
1480    return NULL;
1481  }
1482 }
1483
521   /* find_matching_name_conf()
522   *
523   * inputs       - type of link list to look in
524   *              - pointer to name string to find
525   *              - pointer to user
526   *              - pointer to host
527 < *              - optional action to match on as well
528 < * output       - NULL or pointer to found struct MatchItem
527 > *              - optional flags to match on as well
528 > * output       - NULL or pointer to found struct MaskItem
529   * side effects - looks for a match on name field
530   */
531 < struct ConfItem *
532 < find_matching_name_conf(ConfType type, const char *name, const char *user,
533 <                        const char *host, int action)
534 < {
1498 <  dlink_node *ptr=NULL;
1499 <  struct ConfItem *conf=NULL;
1500 <  struct AccessItem *aconf=NULL;
1501 <  struct MatchItem *match_item=NULL;
1502 <  dlink_list *list_p = map_to_list(type);
531 > struct MaskItem *
532 > connect_find(const char *name, const char *host, int (*compare)(const char *, const char *))
533 > {
534 >  dlink_node *node = NULL;
535  
536 <  switch (type)
536 >  DLINK_FOREACH(node, connect_items.head)
537    {
538 < #ifdef HAVE_LIBPCRE
1507 <  case RXLINE_TYPE:
1508 <      DLINK_FOREACH(ptr, list_p->head)
1509 <      {
1510 <        conf = ptr->data;
1511 <        assert(conf->regexpname);
538 >    struct MaskItem *conf = node->data;
539  
540 <        if (!ircd_pcre_exec(conf->regexpname, name))
541 <          return conf;
542 <      }
543 <      break;
1517 < #endif
1518 <  case SERVICE_TYPE:
1519 <    DLINK_FOREACH(ptr, list_p->head)
1520 <    {
1521 <      conf = ptr->data;
1522 <
1523 <      if (EmptyString(conf->name))
1524 <        continue;
1525 <      if ((name != NULL) && !irccmp(name, conf->name))
1526 <        return conf;
1527 <    }
1528 <    break;
1529 <
1530 <  case XLINE_TYPE:
1531 <  case ULINE_TYPE:
1532 <  case NRESV_TYPE:
1533 <    DLINK_FOREACH(ptr, list_p->head)
1534 <    {
1535 <      conf = ptr->data;
1536 <
1537 <      match_item = map_to_conf(conf);
1538 <      if (EmptyString(conf->name))
1539 <        continue;
1540 <      if ((name != NULL) && match_esc(conf->name, name))
1541 <      {
1542 <        if ((user == NULL && (host == NULL)))
1543 <          return conf;
1544 <        if ((match_item->action & action) != action)
1545 <          continue;
1546 <        if (EmptyString(match_item->user) || EmptyString(match_item->host))
1547 <          return conf;
1548 <        if (match(match_item->user, user) && match(match_item->host, host))
1549 <          return conf;
1550 <      }
1551 <    }
1552 <      break;
1553 <
1554 <  case SERVER_TYPE:
1555 <    DLINK_FOREACH(ptr, list_p->head)
1556 <    {
1557 <      conf = ptr->data;
1558 <      aconf = map_to_conf(conf);
1559 <
1560 <      if ((name != NULL) && match_esc(name, conf->name))
1561 <        return conf;
1562 <      else if ((host != NULL) && match_esc(host, aconf->host))
1563 <        return conf;
1564 <    }
1565 <    break;
1566 <  
1567 <  default:
1568 <    break;
540 >    if (name && !compare(name, conf->name))
541 >      return conf;
542 >    if (host && !compare(host, conf->host))
543 >      return conf;
544    }
545 +
546    return NULL;
547   }
548  
# Line 1576 | Line 552 | find_matching_name_conf(ConfType type, c
552   *              - pointer to name string to find
553   *              - pointer to user
554   *              - pointer to host
555 < * output       - NULL or pointer to found struct MatchItem
555 > * output       - NULL or pointer to found struct MaskItem
556   * side effects - looks for an exact match on name field
557   */
558 < struct ConfItem *
559 < find_exact_name_conf(ConfType type, const struct Client *who, const char *name,
560 <                     const char *user, const char *host)
561 < {
1586 <  dlink_node *ptr = NULL;
1587 <  struct AccessItem *aconf;
1588 <  struct ConfItem *conf;
1589 <  struct MatchItem *match_item;
1590 <  dlink_list *list_p;
1591 <
1592 <  list_p = map_to_list(type);
1593 <
1594 <  switch(type)
1595 <  {
1596 <  case RXLINE_TYPE:
1597 <  case XLINE_TYPE:
1598 <  case ULINE_TYPE:
1599 <  case NRESV_TYPE:
1600 <
1601 <    DLINK_FOREACH(ptr, list_p->head)
1602 <    {
1603 <      conf = ptr->data;
1604 <      match_item = (struct MatchItem *)map_to_conf(conf);
1605 <      if (EmptyString(conf->name))
1606 <        continue;
1607 <    
1608 <      if (irccmp(conf->name, name) == 0)
1609 <      {
1610 <        if ((user == NULL && (host == NULL)))
1611 <          return (conf);
1612 <        if (EmptyString(match_item->user) || EmptyString(match_item->host))
1613 <          return (conf);
1614 <        if (match(match_item->user, user) && match(match_item->host, host))
1615 <          return (conf);
1616 <      }
1617 <    }
1618 <    break;
558 > struct MaskItem *
559 > operator_find(const struct Client *who, const char *name)
560 > {
561 >  dlink_node *node = NULL;
562  
563 <  case OPER_TYPE:
564 <    DLINK_FOREACH(ptr, list_p->head)
565 <    {
1623 <      conf = ptr->data;
1624 <      aconf = map_to_conf(conf);
563 >  DLINK_FOREACH(node, operator_items.head)
564 >  {
565 >    struct MaskItem *conf = node->data;
566  
567 <      if (EmptyString(conf->name))
568 <        continue;
567 >    if (!irccmp(conf->name, name))
568 >    {
569 >      if (!who)
570 >        return conf;
571  
572 <      if (!irccmp(conf->name, name))
572 >      if (!match(conf->user, who->username))
573        {
574 <        if (!who)
1632 <          return conf;
1633 <        if (EmptyString(aconf->user) || EmptyString(aconf->host))
1634 <          return conf;
1635 <        if (match(aconf->user, who->username))
574 >        switch (conf->htype)
575          {
576 <          switch (aconf->type)
577 <          {
578 <            case HM_HOST:
1640 <              if (match(aconf->host, who->host) || match(aconf->host, who->sockhost))
576 >          case HM_HOST:
577 >            if (!match(conf->host, who->host) || !match(conf->host, who->sockhost))
578 >              if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
579                  return conf;
580 <              break;
581 <            case HM_IPV4:
582 <              if (who->localClient->aftype == AF_INET)
583 <                if (match_ipv4(&who->localClient->ip, &aconf->addr, aconf->bits))
580 >            break;
581 >          case HM_IPV4:
582 >            if (who->connection->aftype == AF_INET)
583 >              if (match_ipv4(&who->connection->ip, &conf->addr, conf->bits))
584 >                if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
585                    return conf;
586 <              break;
587 < #ifdef IPV6
588 <            case HM_IPV6:
589 <              if (who->localClient->aftype == AF_INET6)
590 <                if (match_ipv6(&who->localClient->ip, &aconf->addr, aconf->bits))
586 >            break;
587 >          case HM_IPV6:
588 >            if (who->connection->aftype == AF_INET6)
589 >              if (match_ipv6(&who->connection->ip, &conf->addr, conf->bits))
590 >                if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
591                    return conf;
592 <              break;
593 < #endif
594 <            default:
1656 <              assert(0);
1657 <          }
592 >            break;
593 >          default:
594 >            assert(0);
595          }
596        }
597      }
1661
1662    break;
1663
1664  case SERVER_TYPE:
1665    DLINK_FOREACH(ptr, list_p->head)
1666    {
1667      conf = ptr->data;
1668      aconf = (struct AccessItem *)map_to_conf(conf);
1669      if (EmptyString(conf->name))
1670        continue;
1671    
1672      if (name == NULL)
1673      {
1674        if (EmptyString(aconf->host))
1675          continue;
1676        if (irccmp(aconf->host, host) == 0)
1677          return(conf);
1678      }
1679      else if (irccmp(conf->name, name) == 0)
1680      {
1681          return (conf);
1682      }
1683    }
1684    break;
1685
1686  case CLASS_TYPE:
1687    DLINK_FOREACH(ptr, list_p->head)
1688    {
1689      conf = ptr->data;
1690      if (EmptyString(conf->name))
1691        continue;
1692    
1693      if (irccmp(conf->name, name) == 0)
1694        return (conf);
1695    }
1696    break;
1697
1698  default:
1699    break;
598    }
1701  return(NULL);
1702 }
1703
1704 /* rehash()
1705 *
1706 * Actual REHASH service routine. Called with sig == 0 if it has been called
1707 * as a result of an operator issuing this command, else assume it has been
1708 * called as a result of the server receiving a HUP signal.
1709 */
1710 int
1711 rehash(int sig)
1712 {
1713  if (sig != 0)
1714    sendto_realops_flags(UMODE_ALL, L_ALL,
1715                         "Got signal SIGHUP, reloading ircd.conf file");
599  
600 <  restart_resolver();
1718 <
1719 <  /* don't close listeners until we know we can go ahead with the rehash */
1720 <
1721 <  /* Check to see if we magically got(or lost) IPv6 support */
1722 <  check_can_use_v6();
1723 <
1724 <  read_conf_files(0);
1725 <
1726 <  if (ServerInfo.description != NULL)
1727 <    strlcpy(me.info, ServerInfo.description, sizeof(me.info));
1728 <
1729 <  load_conf_modules();
1730 <
1731 <  flush_deleted_I_P();
1732 <
1733 <  rehashed_klines = 1;
1734 < /* XXX */
1735 <  if (ConfigLoggingEntry.use_logging)
1736 <    log_close_all();
1737 <
1738 <  return(0);
600 >  return NULL;
601   }
602  
603   /* set_default_conf()
# Line 1753 | Line 615 | set_default_conf(void)
615    /* verify init_class() ran, this should be an unnecessary check
616     * but its not much work.
617     */
618 <  assert(class_default == (struct ConfItem *) class_items.tail->data);
618 >  assert(class_default == class_get_list()->tail->data);
619  
620 < #ifdef HAVE_LIBCRYPTO
621 <  ServerInfo.rsa_private_key = NULL;
1760 <  ServerInfo.rsa_private_key_file = NULL;
1761 < #endif
1762 <
1763 <  /* ServerInfo.name is not rehashable */
1764 <  /* ServerInfo.name = ServerInfo.name; */
1765 <  ServerInfo.description = NULL;
1766 <  DupString(ServerInfo.network_name, NETWORK_NAME_DEFAULT);
1767 <  DupString(ServerInfo.network_desc, NETWORK_DESC_DEFAULT);
1768 <
1769 <  memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip));
1770 <  ServerInfo.specific_ipv4_vhost = 0;
1771 <  memset(&ServerInfo.ip6, 0, sizeof(ServerInfo.ip6));
1772 <  ServerInfo.specific_ipv6_vhost = 0;
1773 <
1774 <  ServerInfo.max_clients = MAXCLIENTS_MAX;
1775 <
1776 <  ServerInfo.hub = 0;
1777 <  ServerInfo.dns_host.sin_addr.s_addr = 0;
1778 <  ServerInfo.dns_host.sin_port = 0;
1779 <  AdminInfo.name = NULL;
1780 <  AdminInfo.email = NULL;
1781 <  AdminInfo.description = NULL;
620 >  ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
621 >  ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
622  
623 <  log_close_all();
623 >  memset(&ConfigServerInfo.ip, 0, sizeof(ConfigServerInfo.ip));
624 >  ConfigServerInfo.specific_ipv4_vhost = 0;
625 >  memset(&ConfigServerInfo.ip6, 0, sizeof(ConfigServerInfo.ip6));
626 >  ConfigServerInfo.specific_ipv6_vhost = 0;
627  
628 <  ConfigLoggingEntry.use_logging = 1;
628 >  ConfigServerInfo.default_max_clients = MAXCLIENTS_MAX;
629 >  ConfigServerInfo.max_nick_length = 9;
630 >  ConfigServerInfo.max_topic_length = 80;
631 >  ConfigServerInfo.hub = 0;
632 >
633 >  log_del_all();
634 >
635 >  ConfigLog.use_logging = 1;
636  
637    ConfigChannel.disable_fake_channels = 0;
638 <  ConfigChannel.restrict_channels = 0;
639 <  ConfigChannel.knock_delay = 300;
638 >  ConfigChannel.invite_client_count = 10;
639 >  ConfigChannel.invite_client_time = 300;
640 >  ConfigChannel.invite_delay_channel = 5;
641 >  ConfigChannel.invite_expire_time = 1800;
642 >  ConfigChannel.knock_client_count = 1;
643 >  ConfigChannel.knock_client_time = 300;
644    ConfigChannel.knock_delay_channel = 60;
645 <  ConfigChannel.max_chans_per_user = 25;
646 <  ConfigChannel.max_chans_per_oper = 50;
647 <  ConfigChannel.quiet_on_ban = 1;
648 <  ConfigChannel.max_bans = 25;
649 <  ConfigChannel.default_split_user_count = 0;
650 <  ConfigChannel.default_split_server_count = 0;
1797 <  ConfigChannel.no_join_on_split = 0;
1798 <  ConfigChannel.no_create_on_split = 0;
645 >  ConfigChannel.max_channels = 25;
646 >  ConfigChannel.max_invites = 20;
647 >  ConfigChannel.max_bans = 100;
648 >  ConfigChannel.max_bans_large = 500;
649 >  ConfigChannel.default_join_flood_count = 18;
650 >  ConfigChannel.default_join_flood_time = 6;
651  
652    ConfigServerHide.flatten_links = 0;
653 <  ConfigServerHide.links_delay = 300;
653 >  ConfigServerHide.flatten_links_delay = 300;
654    ConfigServerHide.hidden = 0;
655    ConfigServerHide.hide_servers = 0;
656 <  DupString(ConfigServerHide.hidden_name, NETWORK_NAME_DEFAULT);
656 >  ConfigServerHide.hide_services = 0;
657 >  ConfigServerHide.hidden_name = xstrdup(NETWORK_NAME_DEFAULT);
658    ConfigServerHide.hide_server_ips = 0;
659 +  ConfigServerHide.disable_remote_commands = 0;
660  
661 <  
662 <  DupString(ConfigFileEntry.service_name, SERVICE_NAME_DEFAULT);
663 <  ConfigFileEntry.max_watch = WATCHSIZE_DEFAULT;
664 <  ConfigFileEntry.glines = 0;
665 <  ConfigFileEntry.gline_time = 12 * 3600;
666 <  ConfigFileEntry.gline_request_time = GLINE_REQUEST_EXPIRE_DEFAULT;
667 <  ConfigFileEntry.gline_min_cidr = 16;
668 <  ConfigFileEntry.gline_min_cidr6 = 48;
669 <  ConfigFileEntry.invisible_on_connect = 1;
670 <  ConfigFileEntry.burst_away = 0;
671 <  ConfigFileEntry.use_whois_actually = 1;
672 <  ConfigFileEntry.tkline_expire_notices = 1;
673 <  ConfigFileEntry.hide_spoof_ips = 1;
674 <  ConfigFileEntry.ignore_bogus_ts = 0;
675 <  ConfigFileEntry.disable_auth = 0;
676 <  ConfigFileEntry.disable_remote = 0;
677 <  ConfigFileEntry.kill_chase_time_limit = 90;
678 <  ConfigFileEntry.default_floodcount = 8;
679 <  ConfigFileEntry.failed_oper_notice = 1;
680 <  ConfigFileEntry.dots_in_ident = 0;
681 <  ConfigFileEntry.min_nonwildcard = 4;
682 <  ConfigFileEntry.min_nonwildcard_simple = 3;
683 <  ConfigFileEntry.max_accept = 20;
684 <  ConfigFileEntry.anti_nick_flood = 0;
685 <  ConfigFileEntry.max_nick_time = 20;
686 <  ConfigFileEntry.max_nick_changes = 5;
687 <  ConfigFileEntry.anti_spam_exit_message_time = 0;
688 <  ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
689 <  ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
690 <  ConfigFileEntry.kline_with_reason = 1;
691 <  ConfigFileEntry.kline_reason = NULL;
692 <  ConfigFileEntry.warn_no_nline = 1;
693 <  ConfigFileEntry.stats_o_oper_only = 0;
694 <  ConfigFileEntry.stats_k_oper_only = 1;  /* masked */
695 <  ConfigFileEntry.stats_i_oper_only = 1;  /* masked */
696 <  ConfigFileEntry.stats_P_oper_only = 0;
697 <  ConfigFileEntry.caller_id_wait = 60;
698 <  ConfigFileEntry.opers_bypass_callerid = 0;
699 <  ConfigFileEntry.pace_wait = 10;
700 <  ConfigFileEntry.pace_wait_simple = 1;
701 <  ConfigFileEntry.short_motd = 0;
702 <  ConfigFileEntry.ping_cookie = 0;
703 <  ConfigFileEntry.no_oper_flood = 0;
704 <  ConfigFileEntry.true_no_oper_flood = 0;
705 <  ConfigFileEntry.oper_pass_resv = 1;
706 <  ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT;
707 <  ConfigFileEntry.oper_only_umodes = UMODE_DEBUG;
708 <  ConfigFileEntry.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE |
709 <    UMODE_OPERWALL | UMODE_WALLOP;
1856 <  ConfigFileEntry.use_egd = 0;
1857 <  ConfigFileEntry.egdpool_path = NULL;
1858 <  ConfigFileEntry.throttle_time = 10;
661 >  ConfigGeneral.away_count = 2;
662 >  ConfigGeneral.away_time = 10;
663 >  ConfigGeneral.max_watch = 50;
664 >  ConfigGeneral.whowas_history_length = 15000;
665 >  ConfigGeneral.cycle_on_host_change = 1;
666 >  ConfigGeneral.dline_min_cidr = 16;
667 >  ConfigGeneral.dline_min_cidr6 = 48;
668 >  ConfigGeneral.kline_min_cidr = 16;
669 >  ConfigGeneral.kline_min_cidr6 = 48;
670 >  ConfigGeneral.invisible_on_connect = 1;
671 >  ConfigGeneral.tkline_expire_notices = 1;
672 >  ConfigGeneral.ignore_bogus_ts = 0;
673 >  ConfigGeneral.disable_auth = 0;
674 >  ConfigGeneral.kill_chase_time_limit = 90;
675 >  ConfigGeneral.default_floodcount = 8;
676 >  ConfigGeneral.default_floodtime = 1;
677 >  ConfigGeneral.failed_oper_notice = 1;
678 >  ConfigGeneral.dots_in_ident = 0;
679 >  ConfigGeneral.min_nonwildcard = 4;
680 >  ConfigGeneral.min_nonwildcard_simple = 3;
681 >  ConfigGeneral.max_accept = 50;
682 >  ConfigGeneral.anti_nick_flood = 0;
683 >  ConfigGeneral.max_nick_time = 20;
684 >  ConfigGeneral.max_nick_changes = 5;
685 >  ConfigGeneral.anti_spam_exit_message_time = 0;
686 >  ConfigGeneral.ts_warn_delta = 30;
687 >  ConfigGeneral.ts_max_delta = 600;
688 >  ConfigGeneral.warn_no_connect_block = 1;
689 >  ConfigGeneral.stats_e_disabled = 0;
690 >  ConfigGeneral.stats_i_oper_only = 1;  /* 1 = masked */
691 >  ConfigGeneral.stats_k_oper_only = 1;  /* 1 = masked */
692 >  ConfigGeneral.stats_o_oper_only = 1;
693 >  ConfigGeneral.stats_m_oper_only = 1;
694 >  ConfigGeneral.stats_P_oper_only = 0;
695 >  ConfigGeneral.stats_u_oper_only = 0;
696 >  ConfigGeneral.caller_id_wait = 60;
697 >  ConfigGeneral.opers_bypass_callerid = 1;
698 >  ConfigGeneral.pace_wait = 10;
699 >  ConfigGeneral.pace_wait_simple = 1;
700 >  ConfigGeneral.short_motd = 0;
701 >  ConfigGeneral.ping_cookie = 0;
702 >  ConfigGeneral.no_oper_flood = 0;
703 >  ConfigGeneral.max_targets = MAX_TARGETS_DEFAULT;
704 >  ConfigGeneral.oper_only_umodes = UMODE_DEBUG | UMODE_LOCOPS | UMODE_HIDDEN | UMODE_FARCONNECT |
705 >                                   UMODE_UNAUTH | UMODE_EXTERNAL | UMODE_BOTS | UMODE_NCHANGE |
706 >                                   UMODE_SPY | UMODE_FULL | UMODE_SKILL | UMODE_REJ | UMODE_CCONN;
707 >  ConfigGeneral.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE | UMODE_WALLOP;
708 >  ConfigGeneral.throttle_count = 1;
709 >  ConfigGeneral.throttle_time = 1;
710   }
711  
712   static void
713   validate_conf(void)
714   {
715 <  if (ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN)
716 <    ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
1866 <
1867 <  if (ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN)
1868 <    ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
1869 <
1870 <  if (ServerInfo.network_name == NULL)
1871 <    DupString(ServerInfo.network_name,NETWORK_NAME_DEFAULT);
715 >  if (EmptyString(ConfigServerInfo.network_name))
716 >    ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
717  
718 <  if (ServerInfo.network_desc == NULL)
719 <    DupString(ServerInfo.network_desc,NETWORK_DESC_DEFAULT);
1875 <
1876 <  if (ConfigFileEntry.service_name == NULL)
1877 <    DupString(ConfigFileEntry.service_name, SERVICE_NAME_DEFAULT);
1878 <
1879 <  ConfigFileEntry.max_watch = IRCD_MAX(ConfigFileEntry.max_watch, WATCHSIZE_MIN);
718 >  if (EmptyString(ConfigServerInfo.network_desc))
719 >    ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
720   }
721  
722 < /* read_conf()
722 > /* read_conf()
723   *
724   * inputs       - file descriptor pointing to config file to use
725   * output       - None
# Line 1888 | Line 728 | validate_conf(void)
728   static void
729   read_conf(FILE *file)
730   {
731 <  lineno = 0;
731 >  lineno = 1;
732  
733 <  set_default_conf(); /* Set default values prior to conf parsing */
733 >  set_default_conf();  /* Set default values prior to conf parsing */
734    conf_parser_ctx.pass = 1;
735 <  yyparse();          /* pick up the classes first */
735 >  yyparse();  /* Pick up the classes first */
736  
737    rewind(file);
738  
739    conf_parser_ctx.pass = 2;
740 <  yyparse();          /* Load the values from the conf */
741 <  validate_conf();    /* Check to make sure some values are still okay. */
742 <                      /* Some global values are also loaded here. */
743 <  check_class();      /* Make sure classes are valid */
740 >  yyparse();  /* Load the values from the conf */
741 >  validate_conf();  /* Check to make sure some values are still okay. */
742 >                    /* Some global values are also loaded here. */
743 >  whowas_trim();  /* Attempt to trim whowas list if necessary */
744 >  class_delete_marked();  /* Delete unused classes that are marked for deletion */
745 > }
746 >
747 > /* conf_rehash()
748 > *
749 > * Actual REHASH service routine. Called with sig == 0 if it has been called
750 > * as a result of an operator issuing this command, else assume it has been
751 > * called as a result of the server receiving a HUP signal.
752 > */
753 > void
754 > conf_rehash(int sig)
755 > {
756 >  if (sig)
757 >  {
758 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
759 >                         "Got signal SIGHUP, reloading configuration file(s)");
760 >    ilog(LOG_TYPE_IRCD, "Got signal SIGHUP, reloading configuration file(s)");
761 >  }
762 >
763 >  restart_resolver();
764 >
765 >  /* don't close listeners until we know we can go ahead with the rehash */
766 >
767 >  read_conf_files(0);
768 >
769 >  load_conf_modules();
770 >  check_conf_klines();
771   }
772  
773   /* lookup_confhost()
# Line 1908 | Line 775 | read_conf(FILE *file)
775   * start DNS lookups of all hostnames in the conf
776   * line and convert an IP addresses in a.b.c.d number for to IP#s.
777   */
778 < static void
779 < lookup_confhost(struct ConfItem *conf)
778 > void
779 > lookup_confhost(struct MaskItem *conf)
780   {
1914  struct AccessItem *aconf;
781    struct addrinfo hints, *res;
782  
783 <  aconf = map_to_conf(conf);
784 <
1919 <  if (has_wildcards(aconf->host))
1920 <  {
1921 <    ilog(LOG_TYPE_IRCD, "Host/server name error: (%s) (%s)",
1922 <         aconf->host, conf->name);
1923 <    return;
1924 <  }
1925 <
1926 <  /* Do name lookup now on hostnames given and store the
783 >  /*
784 >   * Do name lookup now on hostnames given and store the
785     * ip numbers in conf structure.
786     */
787    memset(&hints, 0, sizeof(hints));
# Line 1934 | Line 792 | lookup_confhost(struct ConfItem *conf)
792    /* Get us ready for a bind() and don't bother doing dns lookup */
793    hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
794  
795 <  if (getaddrinfo(aconf->host, NULL, &hints, &res))
795 >  if (getaddrinfo(conf->host, NULL, &hints, &res))
796    {
797 <    conf_dns_lookup(aconf);
797 >    conf_dns_lookup(conf);
798      return;
799    }
800  
801 <  assert(res != NULL);
801 >  assert(res);
802 >
803 >  memcpy(&conf->addr, res->ai_addr, res->ai_addrlen);
804 >  conf->addr.ss_len = res->ai_addrlen;
805 >  conf->addr.ss.ss_family = res->ai_family;
806  
1945  memcpy(&aconf->addr, res->ai_addr, res->ai_addrlen);
1946  aconf->addr.ss_len = res->ai_addrlen;
1947  aconf->addr.ss.ss_family = res->ai_family;
807    freeaddrinfo(res);
808   }
809  
# Line 1958 | Line 817 | lookup_confhost(struct ConfItem *conf)
817   int
818   conf_connect_allowed(struct irc_ssaddr *addr, int aftype)
819   {
820 <  struct ip_entry *ip_found;
821 <  struct AccessItem *aconf = find_dline_conf(addr, aftype);
1963 <
1964 <  /* DLINE exempt also gets you out of static limits/pacing... */
1965 <  if (aconf && (aconf->status & CONF_EXEMPTDLINE))
1966 <    return 0;
820 >  struct ip_entry *ip_found = NULL;
821 >  const struct MaskItem *conf = find_dline_conf(addr, aftype);
822  
823 <  if (aconf != NULL)
1969 <    return BANNED_CLIENT;
1970 <
1971 <  ip_found = find_or_add_ip(addr);
1972 <
1973 <  if ((CurrentTime - ip_found->last_attempt) <
1974 <      ConfigFileEntry.throttle_time)
823 >  if (conf)
824    {
825 <    ip_found->last_attempt = CurrentTime;
826 <    return TOO_FAST;
825 >    /* DLINE exempt also gets you out of static limits/pacing... */
826 >    if (conf->type == CONF_EXEMPT)
827 >      return 0;
828 >    return BANNED_CLIENT;
829    }
830  
831 <  ip_found->last_attempt = CurrentTime;
1981 <  return 0;
1982 < }
1983 <
1984 < static struct AccessItem *
1985 < find_regexp_kline(const char *uhi[])
1986 < {
1987 < #ifdef HAVE_LIBPCRE
1988 <  const dlink_node *ptr = NULL;
831 >  ip_found = ipcache_find_or_add_address(addr);
832  
833 <  DLINK_FOREACH(ptr, rkconf_items.head)
833 >  if ((CurrentTime - ip_found->last_attempt) < ConfigGeneral.throttle_time)
834    {
835 <    struct AccessItem *aptr = map_to_conf(ptr->data);
836 <
1994 <    assert(aptr->regexuser);
1995 <    assert(aptr->regexhost);
835 >    if (ip_found->connection_count >= ConfigGeneral.throttle_count)
836 >      return TOO_FAST;
837  
838 <    if (!ircd_pcre_exec(aptr->regexuser, uhi[0]) &&
1998 <        (!ircd_pcre_exec(aptr->regexhost, uhi[1]) ||
1999 <         !ircd_pcre_exec(aptr->regexhost, uhi[2])))
2000 <      return aptr;
838 >    ++ip_found->connection_count;
839    }
840 < #endif
841 <  return NULL;
2004 < }
2005 <
2006 < /* find_kill()
2007 < *
2008 < * inputs       - pointer to client structure
2009 < * output       - pointer to struct AccessItem if found
2010 < * side effects - See if this user is klined already,
2011 < *                and if so, return struct AccessItem pointer
2012 < */
2013 < struct AccessItem *
2014 < find_kill(struct Client *client_p)
2015 < {
2016 <  struct AccessItem *aconf = NULL;
2017 <  const char *uhi[3];
2018 <
2019 <  uhi[0] = client_p->username;
2020 <  uhi[1] = client_p->host;
2021 <  uhi[2] = client_p->sockhost;
2022 <
2023 <  assert(client_p != NULL);
2024 <
2025 <  aconf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
2026 <                               CONF_KLINE, client_p->localClient->aftype,
2027 <                               client_p->username, NULL, 1);
2028 <  if (aconf == NULL)
2029 <    aconf = find_regexp_kline(uhi);
2030 <
2031 <  return aconf;
2032 < }
2033 <
2034 < struct AccessItem *
2035 < find_gline(struct Client *client_p)
2036 < {
2037 <  struct AccessItem *aconf;
2038 <
2039 <  assert(client_p != NULL);
2040 <
2041 <  aconf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
2042 <                               CONF_GLINE, client_p->localClient->aftype,
2043 <                               client_p->username, NULL, 1);
2044 <  return aconf;
2045 < }
840 >  else
841 >    ip_found->connection_count = 1;
842  
843 < /* add_temp_line()
844 < *
2049 < * inputs        - pointer to struct ConfItem
2050 < * output        - none
2051 < * Side effects  - links in given struct ConfItem into
2052 < *                 temporary *line link list
2053 < */
2054 < void
2055 < add_temp_line(struct ConfItem *conf)
2056 < {
2057 <  if (conf->type == XLINE_TYPE)
2058 <  {
2059 <    conf->flags |= CONF_FLAGS_TEMPORARY;
2060 <    dlinkAdd(conf, make_dlink_node(), &temporary_xlines);
2061 <  }
2062 <  else if ((conf->type == NRESV_TYPE) || (conf->type == CRESV_TYPE))
2063 <  {
2064 <    conf->flags |= CONF_FLAGS_TEMPORARY;
2065 <    dlinkAdd(conf, make_dlink_node(), &temporary_resv);
2066 <  }
843 >  ip_found->last_attempt = CurrentTime;
844 >  return 0;
845   }
846  
847   /* cleanup_tklines()
# Line 2074 | Line 852 | add_temp_line(struct ConfItem *conf)
852   *                This is an event started off in ircd.c
853   */
854   void
855 < cleanup_tklines(void *notused)
855 > cleanup_tklines(void *unused)
856   {
857    hostmask_expire_temporary();
858 <  expire_tklines(&temporary_xlines);
859 <  expire_tklines(&temporary_resv);
2082 < }
2083 <
2084 < /* expire_tklines()
2085 < *
2086 < * inputs       - tkline list pointer
2087 < * output       - NONE
2088 < * side effects - expire tklines
2089 < */
2090 < static void
2091 < expire_tklines(dlink_list *tklist)
2092 < {
2093 <  dlink_node *ptr;
2094 <  dlink_node *next_ptr;
2095 <  struct ConfItem *conf;
2096 <  struct MatchItem *xconf;
2097 <  struct MatchItem *nconf;
2098 <  struct ResvChannel *cconf;
2099 <
2100 <  DLINK_FOREACH_SAFE(ptr, next_ptr, tklist->head)
2101 <  {
2102 <    conf = ptr->data;
2103 <
2104 <    if (conf->type == XLINE_TYPE)
2105 <    {
2106 <      xconf = (struct MatchItem *)map_to_conf(conf);
2107 <      if (xconf->hold <= CurrentTime)
2108 <      {
2109 <        if (ConfigFileEntry.tkline_expire_notices)
2110 <          sendto_realops_flags(UMODE_ALL, L_ALL,
2111 <                               "Temporary X-line for [%s] sexpired", conf->name);
2112 <        dlinkDelete(ptr, tklist);
2113 <        free_dlink_node(ptr);
2114 <        delete_conf_item(conf);
2115 <      }
2116 <    }
2117 <    else if (conf->type == NRESV_TYPE)
2118 <    {
2119 <      nconf = (struct MatchItem *)map_to_conf(conf);
2120 <      if (nconf->hold <= CurrentTime)
2121 <      {
2122 <        if (ConfigFileEntry.tkline_expire_notices)
2123 <          sendto_realops_flags(UMODE_ALL, L_ALL,
2124 <                               "Temporary RESV for [%s] expired", conf->name);
2125 <        dlinkDelete(ptr, tklist);
2126 <        free_dlink_node(ptr);
2127 <        delete_conf_item(conf);
2128 <      }
2129 <    }
2130 <    else if (conf->type == CRESV_TYPE)
2131 <    {
2132 <      cconf = (struct ResvChannel *)map_to_conf(conf);
2133 <      if (cconf->hold <= CurrentTime)
2134 <      {
2135 <        if (ConfigFileEntry.tkline_expire_notices)
2136 <          sendto_realops_flags(UMODE_ALL, L_ALL,
2137 <                               "Temporary RESV for [%s] expired", cconf->name);
2138 <        delete_channel_resv(cconf);
2139 <      }
2140 <    }
2141 <  }
858 >  gecos_expire();
859 >  resv_expire();
860   }
861  
862   /* oper_privs_as_string()
# Line 2147 | Line 865 | expire_tklines(dlink_list *tklist)
865   * output        - pointer to static string showing oper privs
866   * side effects  - return as string, the oper privs as derived from port
867   */
868 < static const struct oper_privs
868 > static const struct oper_flags
869   {
870 <  const unsigned int oprivs;
870 >  const unsigned int flag;
871    const unsigned char c;
872 < } flag_list[] = {
873 <  { OPER_FLAG_ADMIN,       'A' },
874 <  { OPER_FLAG_REMOTEBAN,   'B' },
875 <  { OPER_FLAG_DIE,         'D' },
876 <  { OPER_FLAG_GLINE,       'G' },
877 <  { OPER_FLAG_REHASH,      'H' },
878 <  { OPER_FLAG_K,           'K' },
879 <  { OPER_FLAG_OPERWALL,    'L' },
880 <  { OPER_FLAG_N,           'N' },
881 <  { OPER_FLAG_GLOBAL_KILL, 'O' },
882 <  { OPER_FLAG_REMOTE,      'R' },
883 <  { OPER_FLAG_OPER_SPY,    'S' },
884 <  { OPER_FLAG_UNKLINE,     'U' },
885 <  { OPER_FLAG_X,           'X' },
872 > } flag_table[] = {
873 >  { OPER_FLAG_ADMIN,          'A' },
874 >  { OPER_FLAG_CLOSE,          'B' },
875 >  { OPER_FLAG_CONNECT,        'C' },
876 >  { OPER_FLAG_CONNECT_REMOTE, 'D' },
877 >  { OPER_FLAG_DIE,            'E' },
878 >  { OPER_FLAG_DLINE,          'F' },
879 >  { OPER_FLAG_GLOBOPS,        'G' },
880 >  { OPER_FLAG_JOIN_RESV,      'H' },
881 >  { OPER_FLAG_KILL,           'I' },
882 >  { OPER_FLAG_KILL_REMOTE,    'J' },
883 >  { OPER_FLAG_KLINE,          'K' },
884 >  { OPER_FLAG_LOCOPS,         'L' },
885 >  { OPER_FLAG_MODULE,         'M' },
886 >  { OPER_FLAG_NICK_RESV,      'N' },
887 >  { OPER_FLAG_OPME,           'O' },
888 >  { OPER_FLAG_REHASH,         'P' },
889 >  { OPER_FLAG_REMOTEBAN,      'Q' },
890 >  { OPER_FLAG_RESTART,        'R' },
891 >  { OPER_FLAG_RESV,           'S' },
892 >  { OPER_FLAG_SET,            'T' },
893 >  { OPER_FLAG_SQUIT,          'U' },
894 >  { OPER_FLAG_SQUIT_REMOTE,   'V' },
895 >  { OPER_FLAG_UNDLINE,        'W' },
896 >  { OPER_FLAG_UNKLINE,        'X' },
897 >  { OPER_FLAG_UNRESV,         'Y' },
898 >  { OPER_FLAG_UNXLINE,        'Z' },
899 >  { OPER_FLAG_WALLOPS,        'a' },
900 >  { OPER_FLAG_XLINE,          'b' },
901    { 0, '\0' }
902   };
903  
904 < char *
905 < oper_privs_as_string(const unsigned int port)
904 > const char *
905 > oper_privs_as_string(const unsigned int flags)
906   {
907 <  static char privs_out[16];
908 <  char *privs_ptr = privs_out;
2176 <  unsigned int i = 0;
907 >  static char buf[sizeof(flag_table) / sizeof(flag_table[0])];
908 >  char *p = buf;
909  
910 <  for (; flag_list[i].oprivs; ++i)
911 <  {
912 <    if (port & flag_list[i].oprivs)
2181 <      *privs_ptr++ = flag_list[i].c;
2182 <    else
2183 <      *privs_ptr++ = ToLowerTab[flag_list[i].c];
2184 <  }
910 >  for (const struct oper_flags *tab = flag_table; tab->flag; ++tab)
911 >    if (flags & tab->flag)
912 >      *p++ = tab->c;
913  
914 <  *privs_ptr = '\0';
914 >  if (p == buf)
915 >    *p++ = '0';
916 >
917 >  *p = '\0';
918  
919 <  return privs_out;
919 >  return buf;
920   }
921  
922   /*
923 < * Input: A client to find the active oper{} name for.
923 > * Input: A client to find the active operator {} name for.
924   * Output: The nick!user@host{oper} of the oper.
925   *         "oper" is server name for remote opers
926   * Side effects: None.
# Line 2197 | Line 928 | oper_privs_as_string(const unsigned int
928   const char *
929   get_oper_name(const struct Client *client_p)
930   {
931 <  dlink_node *cnode = NULL;
932 <  /* +5 for !,@,{,} and null */
933 <  static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5];
931 >  static char buffer[IRCD_BUFSIZE];
932 >
933 >  if (IsServer(client_p))
934 >    return client_p->name;
935  
936    if (MyConnect(client_p))
937    {
938 <    if ((cnode = client_p->localClient->confs.head))
938 >    const dlink_node *const node = client_p->connection->confs.head;
939 >
940 >    if (node)
941      {
942 <      struct ConfItem *conf = cnode->data;
2209 <      const struct AccessItem *aconf = map_to_conf(conf);
942 >      const struct MaskItem *const conf = node->data;
943  
944 <      if (IsConfOperator(aconf))
944 >      if (conf->type == CONF_OPER)
945        {
946 <        snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
946 >        snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
947                   client_p->username, client_p->host, conf->name);
948 <        return buffer;
948 >        return buffer;
949        }
950      }
951  
952 <    /* Probably should assert here for now. If there is an oper out there
953 <     * with no oper{} conf attached, it would be good for us to know...
952 >    /*
953 >     * Probably should assert here for now. If there is an oper out there
954 >     * with no operator {} conf attached, it would be good for us to know...
955       */
956 <    assert(0); /* Oper without oper conf! */
956 >    assert(0);  /* Oper without oper conf! */
957    }
958  
959    snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
960 <           client_p->username, client_p->host, client_p->servptr->name);
960 >           client_p->username, client_p->host, client_p->servptr->name);
961    return buffer;
962   }
963  
2230 /* read_conf_files()
2231 *
2232 * inputs       - cold start YES or NO
2233 * output       - none
2234 * side effects - read all conf files needed, ircd.conf kline.conf etc.
2235 */
2236 void
2237 read_conf_files(int cold)
2238 {
2239  const char *filename;
2240  char chanmodes[32];
2241  char chanlimit[32];
2242
2243  conf_parser_ctx.boot = cold;
2244  filename = get_conf_name(CONF_TYPE);
2245
2246  /* We need to know the initial filename for the yyerror() to report
2247     FIXME: The full path is in conffilenamebuf first time since we
2248             dont know anything else
2249
2250     - Gozem 2002-07-21
2251  */
2252  strlcpy(conffilebuf, filename, sizeof(conffilebuf));
2253
2254  if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL)
2255  {
2256    if (cold)
2257    {
2258      ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
2259           filename, strerror(errno));
2260      exit(-1);
2261    }
2262    else
2263    {
2264      sendto_realops_flags(UMODE_ALL, L_ALL,
2265                           "Unable to read configuration file '%s': %s",
2266                           filename, strerror(errno));
2267      return;
2268    }
2269  }
2270
2271  if (!cold)
2272    clear_out_old_conf();
2273
2274  read_conf(conf_parser_ctx.conf_file);
2275  fclose(conf_parser_ctx.conf_file);
2276
2277  add_isupport("NETWORK", ServerInfo.network_name, -1);
2278  snprintf(chanmodes, sizeof(chanmodes), "beI:%d",
2279           ConfigChannel.max_bans);
2280  add_isupport("MAXLIST", chanmodes, -1);
2281  add_isupport("MAXTARGETS", NULL, ConfigFileEntry.max_targets);
2282
2283  add_isupport("CHANTYPES", "#", -1);
2284
2285  snprintf(chanlimit, sizeof(chanlimit), "#:%d",
2286           ConfigChannel.max_chans_per_user);
2287  add_isupport("CHANLIMIT", chanlimit, -1);
2288  snprintf(chanmodes, sizeof(chanmodes), "%s",
2289           "beI,k,l,imnprstORS");
2290  add_isupport("CHANNELLEN", NULL, LOCAL_CHANNELLEN);
2291
2292  add_isupport("EXCEPTS", "e", -1);
2293  add_isupport("INVEX", "I", -1);
2294  add_isupport("CHANMODES", chanmodes, -1);
2295
2296  /*
2297   * message_locale may have changed.  rebuild isupport since it relies
2298   * on strlen(form_str(RPL_ISUPPORT))
2299   */
2300  rebuild_isupport_message_line();
2301
2302 #ifdef HAVE_LIBPCRE
2303  parse_conf_file(RKLINE_TYPE, cold);
2304  parse_conf_file(RXLINE_TYPE, cold);
2305 #endif
2306  parse_conf_file(KLINE_TYPE, cold);
2307  parse_conf_file(DLINE_TYPE, cold);
2308  parse_conf_file(XLINE_TYPE, cold);
2309  parse_conf_file(NRESV_TYPE, cold);
2310  parse_conf_file(CRESV_TYPE, cold);
2311 }
2312
2313 /* parse_conf_file()
2314 *
2315 * inputs       - type of conf file to parse
2316 * output       - none
2317 * side effects - conf file for givenconf type is opened and read then parsed
2318 */
2319 static void
2320 parse_conf_file(int type, int cold)
2321 {
2322  FILE *file = NULL;
2323  const char *filename = get_conf_name(type);
2324
2325  if ((file = fopen(filename, "r")) == NULL)
2326  {
2327    if (cold)
2328      ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
2329           filename, strerror(errno));
2330    else
2331      sendto_realops_flags(UMODE_ALL, L_ALL,
2332                    "Unable to read configuration file '%s': %s",
2333                           filename, strerror(errno));
2334  }
2335  else
2336  {
2337    parse_csv_file(file, type);
2338    fclose(file);
2339  }
2340 }
2341
964   /* clear_out_old_conf()
965   *
966   * inputs       - none
# Line 2348 | Line 970 | parse_conf_file(int type, int cold)
970   static void
971   clear_out_old_conf(void)
972   {
973 <  dlink_node *ptr = NULL, *next_ptr = NULL;
2352 <  struct ConfItem *conf;
2353 <  struct AccessItem *aconf;
2354 <  struct ClassItem *cltmp;
2355 <  struct MatchItem *match_item;
973 >  dlink_node *node = NULL, *node_next = NULL;
974    dlink_list *free_items [] = {
975 <    &server_items,   &oconf_items,
2358 <     &uconf_items,   &xconf_items, &rxconf_items, &rkconf_items,
2359 <     &nresv_items, &cluster_items,  &service_items, NULL
975 >    &connect_items, &operator_items, NULL
976    };
977  
978    dlink_list ** iterator = free_items; /* C is dumb */
# Line 2364 | Line 980 | clear_out_old_conf(void)
980    /* We only need to free anything allocated by yyparse() here.
981     * Resetting structs, etc, is taken care of by set_default_conf().
982     */
983 <  
984 <  for (; *iterator != NULL; iterator++)
983 >
984 >  for (; *iterator; iterator++)
985    {
986 <    DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head)
986 >    DLINK_FOREACH_SAFE(node, node_next, (*iterator)->head)
987      {
988 <      conf = ptr->data;
2373 <      /* XXX This is less than pretty */
2374 <      if (conf->type == SERVER_TYPE)
2375 <      {
2376 <        aconf = map_to_conf(conf);
988 >      struct MaskItem *conf = node->data;
989  
990 <        if (aconf->clients != 0)
991 <        {
2380 <          SetConfIllegal(aconf);
2381 <          dlinkDelete(&conf->node, &server_items);
2382 <        }
2383 <        else
2384 <        {
2385 <          delete_conf_item(conf);
2386 <        }
2387 <      }
2388 <      else if (conf->type == OPER_TYPE)
2389 <      {
2390 <        aconf = map_to_conf(conf);
2391 <
2392 <        if (aconf->clients != 0)
2393 <        {
2394 <          SetConfIllegal(aconf);
2395 <          dlinkDelete(&conf->node, &oconf_items);
2396 <        }
2397 <        else
2398 <        {
2399 <          delete_conf_item(conf);
2400 <        }
2401 <      }
2402 <      else if (conf->type == XLINE_TYPE  ||
2403 <               conf->type == RXLINE_TYPE ||
2404 <               conf->type == RKLINE_TYPE)
2405 <      {
2406 <        /* temporary (r)xlines are also on
2407 <         * the (r)xconf items list */
2408 <        if (conf->flags & CONF_FLAGS_TEMPORARY)
2409 <          continue;
990 >      conf->active = 0;
991 >      dlinkDelete(&conf->node, *iterator);
992  
993 <        delete_conf_item(conf);
994 <      }
2413 <      else
2414 <      {
2415 <          delete_conf_item(conf);
2416 <      }
993 >      if (!conf->ref_count)
994 >        conf_free(conf);
995      }
996    }
997  
998    /*
999 <   * don't delete the class table, rather mark all entries
1000 <   * for deletion. The table is cleaned up by check_class. - avalon
999 >   * Don't delete the class table, rather mark all entries for deletion.
1000 >   * The table is cleaned up by class_delete_marked. - avalon
1001     */
1002 <  DLINK_FOREACH(ptr, class_items.head)
2425 <  {
2426 <    cltmp = map_to_conf(ptr->data);
2427 <
2428 <    if (ptr != class_items.tail)  /* never mark the "default" class */
2429 <      cltmp->active = 0;
2430 <  }
1002 >  class_mark_for_deletion();
1003  
1004    clear_out_address_conf();
1005  
1006 <  /* clean out module paths */
2435 <  mod_clear_paths();
2436 <
2437 <  /* clean out ServerInfo */
2438 <  MyFree(ServerInfo.description);
2439 <  ServerInfo.description = NULL;
2440 <  MyFree(ServerInfo.network_name);
2441 <  ServerInfo.network_name = NULL;
2442 <  MyFree(ServerInfo.network_desc);
2443 <  ServerInfo.network_desc = NULL;
2444 <  MyFree(ConfigFileEntry.egdpool_path);
2445 <  ConfigFileEntry.egdpool_path = NULL;
2446 < #ifdef HAVE_LIBCRYPTO
2447 <  if (ServerInfo.rsa_private_key != NULL)
2448 <  {
2449 <    RSA_free(ServerInfo.rsa_private_key);
2450 <    ServerInfo.rsa_private_key = NULL;
2451 <  }
2452 <
2453 <  MyFree(ServerInfo.rsa_private_key_file);
2454 <  ServerInfo.rsa_private_key_file = NULL;
2455 <
2456 <  if (ServerInfo.server_ctx)
2457 <    SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|
2458 <                                               SSL_OP_NO_SSLv3|
2459 <                                               SSL_OP_NO_TLSv1);
2460 <  if (ServerInfo.client_ctx)
2461 <    SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|
2462 <                                               SSL_OP_NO_SSLv3|
2463 <                                               SSL_OP_NO_TLSv1);
2464 < #endif
2465 <
2466 <  /* clean out old resvs from the conf */
2467 <  clear_conf_resv();
2468 <
2469 <  /* clean out AdminInfo */
2470 <  MyFree(AdminInfo.name);
2471 <  AdminInfo.name = NULL;
2472 <  MyFree(AdminInfo.email);
2473 <  AdminInfo.email = NULL;
2474 <  MyFree(AdminInfo.description);
2475 <  AdminInfo.description = NULL;
2476 <
2477 <  /* operator{} and class{} blocks are freed above */
2478 <  /* clean out listeners */
2479 <  close_listeners();
2480 <
2481 <  /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{},
2482 <   * exempt{} and gecos{} blocks are freed above too
2483 <   */
2484 <
2485 <  /* clean out general */
2486 <  MyFree(ConfigFileEntry.service_name);
2487 <  ConfigFileEntry.service_name = NULL;
1006 >  modules_conf_clear();  /* Clear modules {} items */
1007  
1008 <  delete_isupport("INVEX");
2490 <  delete_isupport("EXCEPTS");
2491 < }
1008 >  motd_clear();  /* Clear motd {} items and re-cache default motd */
1009  
1010 < /* flush_deleted_I_P()
2494 < *
2495 < * inputs       - none
2496 < * output       - none
2497 < * side effects - This function removes I/P conf items
2498 < */
2499 < static void
2500 < flush_deleted_I_P(void)
2501 < {
2502 <  dlink_node *ptr;
2503 <  dlink_node *next_ptr;
2504 <  struct ConfItem *conf;
2505 <  struct AccessItem *aconf;
2506 <  dlink_list * free_items [] = {
2507 <    &server_items, &oconf_items, NULL
2508 <  };
2509 <  dlink_list ** iterator = free_items; /* C is dumb */
1010 >  cluster_clear();  /* Clear cluster {} items */
1011  
1012 <  /* flush out deleted I and P lines
2512 <   * although still in use.
2513 <   */
2514 <  for (; *iterator != NULL; iterator++)
2515 <  {
2516 <    DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head)
2517 <    {
2518 <      conf = ptr->data;
2519 <      aconf = (struct AccessItem *)map_to_conf(conf);
1012 >  gecos_clear();  /* Clear gecos {} items */
1013  
1014 <      if (IsConfIllegal(aconf))
1015 <      {
1016 <        dlinkDelete(ptr, *iterator);
1014 >  resv_clear();  /* Clear resv {} items */
1015 >
1016 >  service_clear();  /* Clear service {} items */
1017 >
1018 >  shared_clear();  /* Clear shared {} items */
1019 >
1020 >  pseudo_clear();  /* Clear pseudo {} items */
1021 >
1022 >  /* Clean out ConfigServerInfo */
1023 >  xfree(ConfigServerInfo.description);
1024 >  ConfigServerInfo.description = NULL;
1025 >  xfree(ConfigServerInfo.network_name);
1026 >  ConfigServerInfo.network_name = NULL;
1027 >  xfree(ConfigServerInfo.network_desc);
1028 >  ConfigServerInfo.network_desc = NULL;
1029 >  xfree(ConfigServerInfo.rsa_private_key_file);
1030 >  ConfigServerInfo.rsa_private_key_file = NULL;
1031 >  xfree(ConfigServerInfo.ssl_certificate_file);
1032 >  ConfigServerInfo.ssl_certificate_file = NULL;
1033 >  xfree(ConfigServerInfo.ssl_dh_param_file);
1034 >  ConfigServerInfo.ssl_dh_param_file = NULL;
1035 >  xfree(ConfigServerInfo.ssl_dh_elliptic_curve);
1036 >  ConfigServerInfo.ssl_dh_elliptic_curve = NULL;
1037 >  xfree(ConfigServerInfo.ssl_cipher_list);
1038 >  ConfigServerInfo.ssl_cipher_list = NULL;
1039 >  xfree(ConfigServerInfo.ssl_message_digest_algorithm);
1040 >  ConfigServerInfo.ssl_message_digest_algorithm = NULL;
1041 >
1042 >  /* Clean out ConfigAdminInfo */
1043 >  xfree(ConfigAdminInfo.name);
1044 >  ConfigAdminInfo.name = NULL;
1045 >  xfree(ConfigAdminInfo.email);
1046 >  ConfigAdminInfo.email = NULL;
1047 >  xfree(ConfigAdminInfo.description);
1048 >  ConfigAdminInfo.description = NULL;
1049  
1050 <        if (aconf->clients == 0)
1051 <          delete_conf_item(conf);
2527 <      }
2528 <    }
2529 <  }
2530 < }
1050 >  xfree(ConfigServerHide.flatten_links_file);
1051 >  ConfigServerHide.flatten_links_file = NULL;
1052  
1053 < /* get_conf_name()
1054 < *
2534 < * inputs       - type of conf file to return name of file for
2535 < * output       - pointer to filename for type of conf
2536 < * side effects - none
2537 < */
2538 < const char *
2539 < get_conf_name(ConfType type)
2540 < {
2541 <  switch (type)
2542 <  {
2543 <    case CONF_TYPE:
2544 <      return ConfigFileEntry.configfile;
2545 <      break;
2546 <    case KLINE_TYPE:
2547 <      return ConfigFileEntry.klinefile;
2548 <      break;
2549 <    case DLINE_TYPE:
2550 <      return ConfigFileEntry.dlinefile;
2551 <      break;
2552 <    case XLINE_TYPE:
2553 <      return ConfigFileEntry.xlinefile;
2554 <      break;
2555 <    case CRESV_TYPE:
2556 <      return ConfigFileEntry.cresvfile;
2557 <      break;
2558 <    case NRESV_TYPE:
2559 <      return ConfigFileEntry.nresvfile;
2560 <      break;
2561 <    default:
2562 <      return NULL;  /* This should NEVER HAPPEN since we call this function
2563 <                       only with the above values, this will cause us to core
2564 <                       at some point if this happens so we know where it was */
2565 <  }
1053 >  /* Clean out listeners */
1054 >  listener_close_marked();
1055   }
1056  
1057 < #define BAD_PING (-1)
1058 <
2570 < /* get_conf_ping()
2571 < *
2572 < * inputs       - pointer to struct AccessItem
2573 < *              - pointer to a variable that receives ping warning time
2574 < * output       - ping frequency
2575 < * side effects - NONE
2576 < */
2577 < static int
2578 < get_conf_ping(struct ConfItem *conf, int *pingwarn)
1057 > static void
1058 > conf_handle_tls(int cold)
1059   {
1060 <  struct ClassItem *aclass;
2581 <  struct AccessItem *aconf;
2582 <
2583 <  if (conf != NULL)
1060 >  if (!tls_new_cred())
1061    {
1062 <    aconf = (struct AccessItem *)map_to_conf(conf);
2586 <    if (aconf->class_ptr != NULL)
1062 >    if (cold)
1063      {
1064 <      aclass = (struct ClassItem *)map_to_conf(aconf->class_ptr);
1065 <      *pingwarn = aclass->ping_warning;
2590 <      return aclass->ping_freq;
1064 >      ilog(LOG_TYPE_IRCD, "Error while initializing TLS");
1065 >      exit(EXIT_FAILURE);
1066      }
1067 <  }
2593 <
2594 <  return BAD_PING;
2595 < }
2596 <
2597 < /* get_client_class()
2598 < *
2599 < * inputs       - pointer to client struct
2600 < * output       - pointer to name of class
2601 < * side effects - NONE
2602 < */
2603 < const char *
2604 < get_client_class(struct Client *target_p)
2605 < {
2606 <  dlink_node *cnode = NULL;
2607 <  struct AccessItem *aconf = NULL;
2608 <
2609 <  assert(!IsMe(target_p));
2610 <
2611 <  if ((cnode = target_p->localClient->confs.head))
2612 <  {
2613 <    struct ConfItem *conf = cnode->data;
2614 <
2615 <    assert((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2616 <          (conf->type == OPER_TYPE));
2617 <
2618 <    aconf = map_to_conf(conf);
2619 <    if (aconf->class_ptr != NULL)
2620 <      return aconf->class_ptr->name;
2621 <  }
2622 <
2623 <  return "default";
2624 < }
2625 <
2626 < /* get_client_ping()
2627 < *
2628 < * inputs       - pointer to client struct
2629 < *              - pointer to a variable that receives ping warning time
2630 < * output       - ping frequency
2631 < * side effects - NONE
2632 < */
2633 < int
2634 < get_client_ping(struct Client *target_p, int *pingwarn)
2635 < {
2636 <  int ping = 0;
2637 <  dlink_node *cnode = NULL;
2638 <
2639 <  if ((cnode = target_p->localClient->confs.head))
2640 <  {
2641 <    struct ConfItem *conf = cnode->data;
2642 <
2643 <    assert((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2644 <          (conf->type == OPER_TYPE));
2645 <
2646 <    ping = get_conf_ping(conf, pingwarn);
2647 <    if (ping > 0)
2648 <      return ping;
2649 <  }
2650 <
2651 <  *pingwarn = 0;
2652 <  return DEFAULT_PINGFREQUENCY;
2653 < }
2654 <
2655 < /* find_class()
2656 < *
2657 < * inputs       - string name of class
2658 < * output       - corresponding Class pointer
2659 < * side effects - NONE
2660 < */
2661 < struct ConfItem *
2662 < find_class(const char *classname)
2663 < {
2664 <  struct ConfItem *conf;
2665 <
2666 <  if ((conf = find_exact_name_conf(CLASS_TYPE, NULL, classname, NULL, NULL)) != NULL)
2667 <    return conf;
2668 <
2669 <  return class_default;
2670 < }
2671 <
2672 < /* check_class()
2673 < *
2674 < * inputs       - NONE
2675 < * output       - NONE
2676 < * side effects -
2677 < */
2678 < void
2679 < check_class(void)
2680 < {
2681 <  dlink_node *ptr = NULL, *next_ptr = NULL;
2682 <
2683 <  DLINK_FOREACH_SAFE(ptr, next_ptr, class_items.head)
2684 <  {
2685 <    struct ClassItem *aclass = map_to_conf(ptr->data);
2686 <
2687 <    if (!aclass->active && !aclass->curr_user_count)
1067 >    else
1068      {
1069 <      destroy_cidr_class(aclass);
1070 <      delete_conf_item(ptr->data);
1069 >      /* Failed to load new settings/certs, old ones remain active */
1070 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
1071 >                           "Error reloading TLS settings, check the ircd log"); // report_crypto_errors logs this
1072      }
1073    }
1074   }
1075  
1076 < /* init_class()
1076 > /* read_conf_files()
1077   *
1078 < * inputs       - NONE
1079 < * output       - NONE
1080 < * side effects -
1078 > * inputs       - cold start YES or NO
1079 > * output       - none
1080 > * side effects - read all conf files needed, ircd.conf kline.conf etc.
1081   */
1082   void
1083 < init_class(void)
1083 > read_conf_files(int cold)
1084   {
1085 <  struct ClassItem *aclass;
1085 >  const char *filename = NULL;
1086 >  char chanmodes[IRCD_BUFSIZE] = "";
1087 >  char chanlimit[IRCD_BUFSIZE] = "";
1088  
1089 <  class_default = make_conf_item(CLASS_TYPE);
1090 <
2708 <  aclass = map_to_conf(class_default);
2709 <  aclass->active = 1;
2710 <  DupString(class_default->name, "default");
2711 <  aclass->con_freq  = DEFAULT_CONNECTFREQUENCY;
2712 <  aclass->ping_freq = DEFAULT_PINGFREQUENCY;
2713 <  aclass->max_total = MAXIMUM_LINKS_DEFAULT;
2714 <  aclass->max_sendq = DEFAULT_SENDQ;
2715 <  aclass->max_recvq = DEFAULT_RECVQ;
2716 <
2717 <  client_check_cb = register_callback("check_client", check_client);
2718 < }
1089 >  conf_parser_ctx.boot = cold;
1090 >  filename = ConfigGeneral.configfile;
1091  
1092 < /* get_sendq()
1093 < *
1094 < * inputs       - pointer to client
2723 < * output       - sendq for this client as found from its class
2724 < * side effects - NONE
2725 < */
2726 < unsigned int
2727 < get_sendq(struct Client *client_p)
2728 < {
2729 <  unsigned int sendq = DEFAULT_SENDQ;
2730 <  dlink_node *cnode;
2731 <  struct ConfItem *class_conf;
2732 <  struct ClassItem *aclass;
2733 <  struct AccessItem *aconf;
1092 >  /* We need to know the initial filename for the yyerror() to report
1093 >     FIXME: The full path is in conffilenamebuf first time since we
1094 >             don't know anything else
1095  
1096 <  assert(!IsMe(client_p));
1096 >     - Gozem 2002-07-21
1097 >  */
1098 >  strlcpy(conffilebuf, filename, sizeof(conffilebuf));
1099  
1100 <  if ((cnode = client_p->localClient->confs.head))
1100 >  if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL)
1101    {
1102 <    struct ConfItem *conf = cnode->data;
1103 <
1104 <    assert((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
1105 <          (conf->type == OPER_TYPE));
1106 <
1107 <    aconf = map_to_conf(conf);
1108 <
1109 <    if ((class_conf = aconf->class_ptr) == NULL)
1110 <      return DEFAULT_SENDQ; /* TBV: shouldn't be possible at all */
1111 <
1112 <    aclass = map_to_conf(class_conf);
1113 <    sendq = aclass->max_sendq;
1114 <    return sendq;
1102 >    if (cold)
1103 >    {
1104 >      ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
1105 >           filename, strerror(errno));
1106 >      exit(EXIT_FAILURE);
1107 >    }
1108 >    else
1109 >    {
1110 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1111 >                           "Unable to read configuration file '%s': %s",
1112 >                           filename, strerror(errno));
1113 >      return;
1114 >    }
1115    }
1116  
1117 <  /* XXX return a default?
1118 <   * if here, then there wasn't an attached conf with a sendq
2756 <   * that is very bad -Dianora
2757 <   */
2758 <  return DEFAULT_SENDQ;
2759 < }
2760 <
2761 < unsigned int
2762 < get_recvq(struct Client *client_p)
2763 < {
2764 <  unsigned int recvq = DEFAULT_RECVQ;
2765 <  dlink_node *cnode;
2766 <  struct ConfItem *class_conf;
2767 <  struct ClassItem *aclass;
2768 <  struct AccessItem *aconf;
2769 <
2770 <  assert(!IsMe(client_p));
2771 <
2772 <  if ((cnode = client_p->localClient->confs.head))
2773 <  {
2774 <    struct ConfItem *conf = cnode->data;
2775 <
2776 <    assert((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2777 <          (conf->type == OPER_TYPE));
1117 >  if (!cold)
1118 >    clear_out_old_conf();
1119  
1120 <    aconf = map_to_conf(conf);
1120 >  read_conf(conf_parser_ctx.conf_file);
1121 >  fclose(conf_parser_ctx.conf_file);
1122  
1123 <    if ((class_conf = aconf->class_ptr) == NULL)
1124 <      return DEFAULT_RECVQ; /* TBV: shouldn't be possible at all */
1123 >  log_reopen_all();
1124 >  conf_handle_tls(cold);
1125  
1126 <    aclass = map_to_conf(class_conf);
1127 <    recvq = aclass->max_recvq;
2786 <    return recvq;
2787 <  }
1126 >  isupport_add("NICKLEN", NULL, ConfigServerInfo.max_nick_length);
1127 >  isupport_add("NETWORK", ConfigServerInfo.network_name, -1);
1128  
1129 <  /* XXX return a default?
1130 <   * if here, then there wasn't an attached conf with a recvq
1131 <   * that is very bad -Dianora
1132 <   */
1133 <  return DEFAULT_RECVQ;
1129 >  snprintf(chanmodes, sizeof(chanmodes), "beI:%u", ConfigChannel.max_bans);
1130 >  isupport_add("MAXLIST", chanmodes, -1);
1131 >  isupport_add("MAXTARGETS", NULL, ConfigGeneral.max_targets);
1132 >  isupport_add("CHANTYPES", "#", -1);
1133 >
1134 >  snprintf(chanlimit, sizeof(chanlimit), "#:%u",
1135 >           ConfigChannel.max_channels);
1136 >  isupport_add("CHANLIMIT", chanlimit, -1);
1137 >  snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,cimnprstuCLMORST");
1138 >  isupport_add("CHANNELLEN", NULL, CHANNELLEN);
1139 >  isupport_add("TOPICLEN", NULL, ConfigServerInfo.max_topic_length);
1140 >  isupport_add("CHANMODES", chanmodes, -1);
1141   }
1142  
1143   /* conf_add_class_to_conf()
1144   *
1145   * inputs       - pointer to config item
1146   * output       - NONE
1147 < * side effects - Add a class pointer to a conf
1147 > * side effects - Add a class pointer to a conf
1148   */
1149   void
1150 < conf_add_class_to_conf(struct ConfItem *conf, const char *class_name)
1150 > conf_add_class_to_conf(struct MaskItem *conf, const char *name)
1151   {
1152 <  struct AccessItem *aconf = map_to_conf(conf);
2806 <  struct ClassItem *class = NULL;
2807 <
2808 <  if (class_name == NULL)
1152 >  if (EmptyString(name) || (conf->class = class_find(name, 1)) == NULL)
1153    {
1154 <    aconf->class_ptr = class_default;
1154 >    conf->class = class_default;
1155  
1156 <    if (conf->type == CLIENT_TYPE)
1157 <      sendto_realops_flags(UMODE_ALL, L_ALL,
1158 <                           "Warning *** Defaulting to default class for %s@%s",
1159 <                           aconf->user, aconf->host);
1156 >    if (conf->type == CONF_CLIENT || conf->type == CONF_OPER)
1157 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1158 >                           "Warning *** Defaulting to default class for %s@%s",
1159 >                           conf->user, conf->host);
1160      else
1161 <      sendto_realops_flags(UMODE_ALL, L_ALL,
1162 <                           "Warning *** Defaulting to default class for %s",
1163 <                           conf->name);
2820 <  }
2821 <  else
2822 <    aconf->class_ptr = find_class(class_name);
2823 <
2824 <  if (aconf->class_ptr)
2825 <    class = map_to_conf(aconf->class_ptr);
2826 <
2827 <  if (aconf->class_ptr == NULL || !class->active)
2828 <  {
2829 <    if (conf->type == CLIENT_TYPE)
2830 <      sendto_realops_flags(UMODE_ALL, L_ALL,
2831 <                           "Warning *** Defaulting to default class for %s@%s",
2832 <                           aconf->user, aconf->host);
2833 <    else
2834 <      sendto_realops_flags(UMODE_ALL, L_ALL,
2835 <                           "Warning *** Defaulting to default class for %s",
2836 <                           conf->name);
2837 <    aconf->class_ptr = class_default;
1161 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1162 >                           "Warning *** Defaulting to default class for %s",
1163 >                           conf->name);
1164    }
1165   }
1166  
2841 /* conf_add_server()
2842 *
2843 * inputs       - pointer to config item
2844 *              - pointer to link count already on this conf
2845 * output       - NONE
2846 * side effects - Add a connect block
2847 */
2848 int
2849 conf_add_server(struct ConfItem *conf, const char *class_name)
2850 {
2851  struct AccessItem *aconf = map_to_conf(conf);
2852
2853  conf_add_class_to_conf(conf, class_name);
2854
2855  if (!aconf->host || !conf->name)
2856  {
2857    sendto_realops_flags(UMODE_ALL, L_ALL, "Bad connect block");
2858    ilog(LOG_TYPE_IRCD, "Bad connect block");
2859    return -1;
2860  }
2861
2862  if (EmptyString(aconf->passwd))
2863  {
2864    sendto_realops_flags(UMODE_ALL, L_ALL, "Bad connect block, name %s",
2865                         conf->name);
2866    ilog(LOG_TYPE_IRCD, "Bad connect block, host %s", conf->name);
2867    return -1;
2868  }
2869
2870  lookup_confhost(conf);
2871
2872  return 0;
2873 }
2874
1167   /* yyerror()
1168   *
1169   * inputs       - message from parser
# Line 2881 | Line 1173 | conf_add_server(struct ConfItem *conf, c
1173   void
1174   yyerror(const char *msg)
1175   {
2884  char newlinebuf[IRCD_BUFSIZE];
2885
1176    if (conf_parser_ctx.pass != 1)
1177      return;
1178  
1179 <  strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1180 <  sendto_realops_flags(UMODE_ALL, L_ALL, "\"%s\", line %u: %s: %s",
1181 <                       conffilebuf, lineno + 1, msg, newlinebuf);
1179 >  const char *p = stripws(linebuf);
1180 >  sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1181 >                       "\"%s\", line %u: %s: %s",
1182 >                       conffilebuf, lineno, msg, p);
1183    ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1184 <       conffilebuf, lineno + 1, msg, newlinebuf);
1184 >       conffilebuf, lineno, msg, p);
1185 > }
1186 >
1187 > void
1188 > conf_error_report(const char *msg)
1189 > {
1190 >  const char *p = stripws(linebuf);
1191 >  sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1192 >                       "\"%s\", line %u: %s: %s",
1193 >                       conffilebuf, lineno, msg, p);
1194 >  ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1195 >       conffilebuf, lineno, msg, p);
1196   }
1197  
1198   /*
1199   * valid_tkline()
1200 < *
1200 > *
1201   * inputs       - pointer to ascii string to check
1202   *              - whether the specified time is in seconds or minutes
1203   * output       - -1 not enough parameters
# Line 2903 | Line 1205 | yyerror(const char *msg)
1205   * side effects - none
1206   * Originally written by Dianora (Diane, db@db.net)
1207   */
1208 < time_t
1209 < valid_tkline(const char *p, int minutes)
1208 > uintmax_t
1209 > valid_tkline(const char *data, const int minutes)
1210   {
1211 <  time_t result = 0;
1211 >  const unsigned char *p = (const unsigned char *)data;
1212 >  unsigned char tmpch = '\0';
1213 >  uintmax_t result = 0;
1214  
1215 <  for (; *p; ++p)
1215 >  while ((tmpch = *p++))
1216    {
1217 <    if (!IsDigit(*p))
1217 >    if (!IsDigit(tmpch))
1218        return 0;
1219  
1220      result *= 10;
1221 <    result += ((*p) & 0xF);
1221 >    result += (tmpch & 0xF);
1222    }
1223  
1224    /*
1225 <   * In the degenerate case where oper does a /quote kline 0 user@host :reason
1226 <   * i.e. they specifically use 0, I am going to return 1 instead
1227 <   * as a return value of non-zero is used to flag it as a temporary kline
1225 >   * In the degenerate case where oper does a /quote kline 0 user@host :reason
1226 >   * i.e. they specifically use 0, I am going to return 1 instead as a return
1227 >   * value of non-zero is used to flag it as a temporary kline
1228     */
1229    if (result == 0)
1230      result = 1;
1231  
1232 <  /*
1232 >  /*
1233     * If the incoming time is in seconds convert it to minutes for the purpose
1234     * of this calculation
1235     */
1236    if (!minutes)
1237 <    result = result / (time_t)60;
1237 >    result = result / 60;
1238  
1239    if (result > MAX_TDKLINE_TIME)
1240      result = MAX_TDKLINE_TIME;
1241  
1242 <  result = result * (time_t)60;  /* turn it into seconds */
1242 >  result = result * 60;  /* Turn it into seconds */
1243  
1244    return result;
1245   }
1246  
1247 + /* valid_wild_card_simple()
1248 + *
1249 + * inputs       - data to check for sufficient non-wildcard characters
1250 + * outputs      - 1 if valid, else 0
1251 + * side effects - none
1252 + */
1253 + int
1254 + valid_wild_card_simple(const char *data)
1255 + {
1256 +  const unsigned char *p = (const unsigned char *)data;
1257 +  unsigned char tmpch = '\0';
1258 +  unsigned int nonwild = 0, wild = 0;
1259 +
1260 +  while ((tmpch = *p++))
1261 +  {
1262 +    if (tmpch == '\\' && *p)
1263 +    {
1264 +      ++p;
1265 +      if (++nonwild >= ConfigGeneral.min_nonwildcard_simple)
1266 +        return 1;
1267 +    }
1268 +    else if (!IsMWildChar(tmpch))
1269 +    {
1270 +      if (++nonwild >= ConfigGeneral.min_nonwildcard_simple)
1271 +        return 1;
1272 +    }
1273 +    else
1274 +      ++wild;
1275 +  }
1276 +
1277 +  return !wild;
1278 + }
1279 +
1280   /* valid_wild_card()
1281   *
1282   * input        - pointer to client
# Line 2949 | Line 1286 | valid_tkline(const char *p, int minutes)
1286   * side effects - NOTICE is given to source_p if warn is 1
1287   */
1288   int
1289 < valid_wild_card(struct Client *source_p, int warn, int count, ...)
1289 > valid_wild_card(int count, ...)
1290   {
1291 <  char *p;
1292 <  char tmpch;
2956 <  int nonwild = 0;
1291 >  unsigned char tmpch = '\0';
1292 >  unsigned int nonwild = 0;
1293    va_list args;
1294  
1295    /*
# Line 2972 | Line 1308 | valid_wild_card(struct Client *source_p,
1308  
1309    while (count--)
1310    {
1311 <    p = va_arg(args, char *);
1311 >    const unsigned char *p = va_arg(args, const unsigned char *);
1312      if (p == NULL)
1313        continue;
1314  
# Line 2984 | Line 1320 | valid_wild_card(struct Client *source_p,
1320           * If we find enough non-wild characters, we can
1321           * break - no point in searching further.
1322           */
1323 <        if (++nonwild >= ConfigFileEntry.min_nonwildcard)
1323 >        if (++nonwild >= ConfigGeneral.min_nonwildcard)
1324 >        {
1325 >          va_end(args);
1326            return 1;
1327 +        }
1328        }
1329      }
1330    }
1331  
1332 <  if (warn)
1333 <    sendto_one(source_p, ":%s NOTICE %s :Please include at least %d non-wildcard characters with the mask",
1334 <               me.name, source_p->name, ConfigFileEntry.min_nonwildcard);
1332 >  va_end(args);
1333 >  return 0;
1334 > }
1335 >
1336 > /* find_user_host()
1337 > *
1338 > * inputs       - pointer to client placing kline
1339 > *              - pointer to user_host_or_nick
1340 > *              - pointer to user buffer
1341 > *              - pointer to host buffer
1342 > * output       - 0 if not ok to kline, 1 to kline i.e. if valid user host
1343 > * side effects -
1344 > */
1345 > static int
1346 > find_user_host(struct Client *source_p, char *user_host_or_nick,
1347 >               char *luser, char *lhost)
1348 > {
1349 >  struct Client *target_p = NULL;
1350 >  char *hostp = NULL;
1351 >
1352 >  if (lhost == NULL)
1353 >  {
1354 >    strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
1355 >    return 1;
1356 >  }
1357 >
1358 >  if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
1359 >  {
1360 >    /* Explicit user@host mask given */
1361 >    if (hostp)                            /* I'm a little user@host */
1362 >    {
1363 >      *(hostp++) = '\0';                       /* short and squat */
1364 >
1365 >      if (*user_host_or_nick)
1366 >        strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
1367 >      else
1368 >        strcpy(luser, "*");
1369 >
1370 >      if (*hostp)
1371 >        strlcpy(lhost, hostp, HOSTLEN + 1);    /* here is my host */
1372 >      else
1373 >        strcpy(lhost, "*");
1374 >    }
1375 >    else
1376 >    {
1377 >      luser[0] = '*';             /* no @ found, assume its *@somehost */
1378 >      luser[1] = '\0';
1379 >      strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
1380 >    }
1381 >
1382 >    return 1;
1383 >  }
1384 >  else
1385 >  {
1386 >    /* Try to find user@host mask from nick */
1387 >    /* Okay to use source_p as the first param, because source_p == client_p */
1388 >    if ((target_p =
1389 >        find_chasing(source_p, user_host_or_nick)) == NULL)
1390 >      return 0;  /* find_chasing sends ERR_NOSUCHNICK */
1391 >
1392 >    if (HasFlag(target_p, FLAGS_EXEMPTKLINE))
1393 >    {
1394 >      if (IsClient(source_p))
1395 >        sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
1396 >      return 0;
1397 >    }
1398 >
1399 >    /*
1400 >     * Turn the "user" bit into "*user", blow away '~'
1401 >     * if found in original user name (non-idented)
1402 >     */
1403 >    strlcpy(luser, target_p->username, USERLEN*4 + 1);
1404 >
1405 >    if (target_p->username[0] == '~')
1406 >      luser[0] = '*';
1407 >
1408 >    strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
1409 >    return 1;
1410 >  }
1411 >
1412    return 0;
1413   }
1414  
# Line 3006 | Line 1422 | valid_wild_card(struct Client *source_p,
1422   *              - parse_flags bit map of things to test
1423   *              - pointer to user or string to parse into
1424   *              - pointer to host or NULL to parse into if non NULL
1425 < *              - pointer to optional tkline time or NULL
1425 > *              - pointer to optional tkline time or NULL
1426   *              - pointer to target_server to parse into if non NULL
1427   *              - pointer to reason to parse into
1428   *
1429 < * output       - 1 if valid, -1 if not valid
1429 > * output       - 1 if valid, 0 if not valid
1430   * side effects - A generalised k/d/x etc. line parser,
1431   *               "ALINE [time] user@host|string [ON] target :reason"
1432   *                will parse returning a parsed user, host if
# Line 3028 | Line 1444 | valid_wild_card(struct Client *source_p,
1444   */
1445   int
1446   parse_aline(const char *cmd, struct Client *source_p,
1447 <            int parc, char **parv,
1448 <            int parse_flags, char **up_p, char **h_p, time_t *tkline_time,
1449 <            char **target_server, char **reason)
1447 >            int parc, char **parv,
1448 >            char **up_p, char **h_p, uintmax_t *tkline_time,
1449 >            char **target_server, char **reason)
1450   {
1451 <  int found_tkline_time=0;
1452 <  static char def_reason[] = "No Reason";
1451 >  uintmax_t found_tkline_time=0;
1452 >  static char default_reason[] = CONF_NOREASON;
1453    static char user[USERLEN*4+1];
1454    static char host[HOSTLEN*4+1];
1455  
# Line 3042 | Line 1458 | parse_aline(const char *cmd, struct Clie
1458  
1459    found_tkline_time = valid_tkline(*parv, TK_MINUTES);
1460  
1461 <  if (found_tkline_time != 0)
1461 >  if (found_tkline_time)
1462    {
1463      parv++;
1464      parc--;
1465  
1466 <    if (tkline_time != NULL)
1466 >    if (tkline_time)
1467        *tkline_time = found_tkline_time;
1468      else
1469      {
1470 <      sendto_one(source_p, ":%s NOTICE %s :temp_line not supported by %s",
1471 <                 me.name, source_p->name, cmd);
3056 <      return -1;
1470 >      sendto_one_notice(source_p, &me, ":temp_line not supported by %s", cmd);
1471 >      return 0;
1472      }
1473    }
1474  
1475    if (parc == 0)
1476    {
1477 <    sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1478 <               me.name, source_p->name, cmd);
3064 <    return -1;
1477 >    sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1478 >    return 0;
1479    }
1480  
1481    if (h_p == NULL)
1482      *up_p = *parv;
1483    else
1484    {
1485 <    if (find_user_host(source_p, *parv, user, host, parse_flags) == 0)
1486 <      return -1;
1485 >    if (find_user_host(source_p, *parv, user, host) == 0)
1486 >      return 0;
1487  
1488      *up_p = user;
1489      *h_p = host;
1490    }
1491 <
1491 >
1492    parc--;
1493    parv++;
1494  
1495 <  if (parc != 0)
1495 >  if (parc)
1496    {
1497      if (irccmp(*parv, "ON") == 0)
1498      {
1499        parc--;
1500        parv++;
1501  
3088      if (target_server == NULL)
3089      {
3090        sendto_one(source_p, ":%s NOTICE %s :ON server not supported by %s",
3091                   me.name, source_p->name, cmd);
3092        return -1;
3093      }
3094
1502        if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN))
1503        {
1504 <        sendto_one(source_p, form_str(ERR_NOPRIVS),
1505 <                   me.name, source_p->name, "remoteban");
3099 <        return -1;
1504 >        sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "remoteban");
1505 >        return 0;
1506        }
1507  
1508        if (parc == 0 || EmptyString(*parv))
1509        {
1510 <        sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1511 <                   me.name, source_p->name, cmd);
3106 <        return -1;
1510 >        sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1511 >        return 0;
1512        }
1513  
1514        *target_server = *parv;
# Line 3115 | Line 1520 | parse_aline(const char *cmd, struct Clie
1520        /* Make sure target_server *is* NULL if no ON server found
1521         * caller probably NULL'd it first, but no harm to do it again -db
1522         */
1523 <      if (target_server != NULL)
1524 <        *target_server = NULL;
3120 <    }
3121 <  }
3122 <
3123 <  if (h_p != NULL)
3124 <  {
3125 <    if (strchr(user, '!') != NULL)
3126 <    {
3127 <      sendto_one(source_p, ":%s NOTICE %s :Invalid character '!' in kline",
3128 <                 me.name, source_p->name);
3129 <      return -1;
1523 >      if (target_server)
1524 >        *target_server = NULL;
1525      }
3131
3132    if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 2, *up_p, *h_p))
3133      return -1;
1526    }
3135  else
3136    if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 1, *up_p))
3137      return -1;
1527  
1528 <  if (reason != NULL)
1528 >  if (reason)
1529    {
1530 <    if (parc != 0 && !EmptyString(*parv))
3142 <    {
1530 >    if (parc && !EmptyString(*parv))
1531        *reason = *parv;
3144      if (!valid_comment(source_p, *reason, 1))
3145        return -1;
3146    }
1532      else
1533 <      *reason = def_reason;
1533 >      *reason = default_reason;
1534    }
1535  
1536    return 1;
1537   }
1538  
3154 /* find_user_host()
3155 *
3156 * inputs       - pointer to client placing kline
3157 *              - pointer to user_host_or_nick
3158 *              - pointer to user buffer
3159 *              - pointer to host buffer
3160 * output       - 0 if not ok to kline, 1 to kline i.e. if valid user host
3161 * side effects -
3162 */
3163 static int
3164 find_user_host(struct Client *source_p, char *user_host_or_nick,
3165               char *luser, char *lhost, unsigned int flags)
3166 {
3167  struct Client *target_p = NULL;
3168  char *hostp = NULL;
3169
3170  if (lhost == NULL)
3171  {
3172    strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
3173    return 1;
3174  }
3175
3176  if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
3177  {
3178    /* Explicit user@host mask given */
3179
3180    if (hostp != NULL)                            /* I'm a little user@host */
3181    {
3182      *(hostp++) = '\0';                       /* short and squat */
3183      if (*user_host_or_nick)
3184        strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
3185      else
3186        strcpy(luser, "*");
3187      if (*hostp)
3188        strlcpy(lhost, hostp, HOSTLEN + 1);    /* here is my host */
3189      else
3190        strcpy(lhost, "*");
3191    }
3192    else
3193    {
3194      luser[0] = '*';             /* no @ found, assume its *@somehost */
3195      luser[1] = '\0';    
3196      strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
3197    }
3198    
3199    return 1;
3200  }
3201  else
3202  {
3203    /* Try to find user@host mask from nick */
3204    /* Okay to use source_p as the first param, because source_p == client_p */
3205    if ((target_p =
3206        find_chasing(source_p, source_p, user_host_or_nick, NULL)) == NULL)
3207      return 0;
3208
3209    if (IsExemptKline(target_p))
3210    {
3211      if (!IsServer(source_p))
3212        sendto_one(source_p,
3213                   ":%s NOTICE %s :%s is E-lined",
3214                   me.name, source_p->name, target_p->name);
3215      return 0;
3216    }
3217
3218    /*
3219     * turn the "user" bit into "*user", blow away '~'
3220     * if found in original user name (non-idented)
3221     */
3222    strlcpy(luser, target_p->username, USERLEN*4 + 1);
3223
3224    if (target_p->username[0] == '~')
3225      luser[0] = '*';
3226
3227    if (target_p->sockhost[0] == '\0' ||
3228        (target_p->sockhost[0] == '0' && target_p->sockhost[1] == '\0'))
3229      strlcpy(lhost, target_p->host, HOSTLEN*4 + 1);
3230    else
3231      strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
3232    return 1;
3233  }
3234
3235  return 0;
3236 }
3237
3238 /* valid_comment()
3239 *
3240 * inputs       - pointer to client
3241 *              - pointer to comment
3242 * output       - 0 if no valid comment,
3243 *              - 1 if valid
3244 * side effects - truncates reason where necessary
3245 */
3246 int
3247 valid_comment(struct Client *source_p, char *comment, int warn)
3248 {
3249  if (strchr(comment, '"'))
3250  {
3251    if (warn)
3252      sendto_one(source_p, ":%s NOTICE %s :Invalid character '\"' in comment",
3253                 me.name, source_p->name);
3254    return 0;
3255  }
3256
3257  if (strlen(comment) > REASONLEN)
3258    comment[REASONLEN-1] = '\0';
3259
3260  return 1;
3261 }
3262
1539   /* match_conf_password()
1540   *
1541   * inputs       - pointer to given password
# Line 3268 | Line 1544 | valid_comment(struct Client *source_p, c
1544   * side effects - none
1545   */
1546   int
1547 < match_conf_password(const char *password, const struct AccessItem *aconf)
1547 > match_conf_password(const char *password, const struct MaskItem *conf)
1548   {
1549    const char *encr = NULL;
1550  
1551 <  if (EmptyString(password) || EmptyString(aconf->passwd))
1551 >  if (EmptyString(password) || EmptyString(conf->passwd))
1552      return 0;
1553  
1554 <  if (aconf->flags & CONF_FLAGS_ENCRYPTED)
1555 <    encr = crypt(password, aconf->passwd);
1554 >  if (conf->flags & CONF_FLAGS_ENCRYPTED)
1555 >    encr = crypt(password, conf->passwd);
1556    else
1557      encr = password;
1558  
1559 <  return !strcmp(encr, aconf->passwd);
3284 < }
3285 <
3286 < /*
3287 < * cluster_a_line
3288 < *
3289 < * inputs       - client sending the cluster
3290 < *              - command name "KLINE" "XLINE" etc.
3291 < *              - capab -- CAP_KLN etc. from s_serv.h
3292 < *              - cluster type -- CLUSTER_KLINE etc. from conf.h
3293 < *              - pattern and args to send along
3294 < * output       - none
3295 < * side effects - Take source_p send the pattern with args given
3296 < *                along to all servers that match capab and cluster type
3297 < */
3298 < void
3299 < cluster_a_line(struct Client *source_p, const char *command,
3300 <               int capab, int cluster_type, const char *pattern, ...)
3301 < {
3302 <  va_list args;
3303 <  char buffer[IRCD_BUFSIZE];
3304 <  const dlink_node *ptr = NULL;
3305 <
3306 <  va_start(args, pattern);
3307 <  vsnprintf(buffer, sizeof(buffer), pattern, args);
3308 <  va_end(args);
3309 <
3310 <  DLINK_FOREACH(ptr, cluster_items.head)
3311 <  {
3312 <    const struct ConfItem *conf = ptr->data;
3313 <
3314 <    if (conf->flags & cluster_type)
3315 <      sendto_match_servs(source_p, conf->name, CAP_CLUSTER|capab,
3316 <                         "%s %s %s", command, conf->name, buffer);
3317 <  }
1559 >  return encr && !strcmp(encr, conf->passwd);
1560   }
1561  
1562   /*
# Line 3352 | Line 1594 | split_nuh(struct split_nuh_item *const i
1594  
1595    if (iptr->nickptr)
1596      strlcpy(iptr->nickptr, "*", iptr->nicksize);
1597 +
1598    if (iptr->userptr)
1599      strlcpy(iptr->userptr, "*", iptr->usersize);
1600 +
1601    if (iptr->hostptr)
1602      strlcpy(iptr->hostptr, "*", iptr->hostsize);
1603  
# Line 3361 | Line 1605 | split_nuh(struct split_nuh_item *const i
1605    {
1606      *p = '\0';
1607  
1608 <    if (iptr->nickptr && *iptr->nuhmask != '\0')
1608 >    if (iptr->nickptr && *iptr->nuhmask)
1609        strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
1610  
1611 <    if ((q = strchr(++p, '@'))) {
1611 >    if ((q = strchr(++p, '@')))
1612 >    {
1613        *q++ = '\0';
1614  
1615 <      if (*p != '\0')
1615 >      if (*p)
1616          strlcpy(iptr->userptr, p, iptr->usersize);
1617  
1618 <      if (*q != '\0')
1618 >      if (*q)
1619          strlcpy(iptr->hostptr, q, iptr->hostsize);
1620      }
1621      else
1622      {
1623 <      if (*p != '\0')
1623 >      if (*p)
1624          strlcpy(iptr->userptr, p, iptr->usersize);
1625      }
1626    }
# Line 3387 | Line 1632 | split_nuh(struct split_nuh_item *const i
1632        /* if found a @ */
1633        *p++ = '\0';
1634  
1635 <      if (*iptr->nuhmask != '\0')
1635 >      if (*iptr->nuhmask)
1636          strlcpy(iptr->userptr, iptr->nuhmask, iptr->usersize);
1637  
1638 <      if (*p != '\0')
1638 >      if (*p)
1639          strlcpy(iptr->hostptr, p, iptr->hostsize);
1640      }
1641      else
1642      {
1643 <      /* no @ found */
1643 >      /* No @ found */
1644        if (!iptr->nickptr || strpbrk(iptr->nuhmask, ".:"))
1645          strlcpy(iptr->hostptr, iptr->nuhmask, iptr->hostsize);
1646        else
# Line 3403 | Line 1648 | split_nuh(struct split_nuh_item *const i
1648      }
1649    }
1650   }
3406
3407 /*
3408 * flags_to_ascii
3409 *
3410 * inputs       - flags is a bitmask
3411 *              - pointer to table of ascii letters corresponding
3412 *                to each bit
3413 *              - flag 1 for convert ToLower if bit missing
3414 *                0 if ignore.
3415 * output       - none
3416 * side effects - string pointed to by p has bitmap chars written to it
3417 */
3418 static void
3419 flags_to_ascii(unsigned int flags, const unsigned int bit_table[], char *p,
3420               int lowerit)
3421 {
3422  unsigned int mask = 1;
3423  int i = 0;
3424
3425  for (mask = 1; (mask != 0) && (bit_table[i] != 0); mask <<= 1, i++)
3426  {
3427    if (flags & mask)
3428      *p++ = bit_table[i];
3429    else if (lowerit)
3430      *p++ = ToLower(bit_table[i]);
3431  }
3432  *p = '\0';
3433 }
3434
3435 /*
3436 * cidr_limit_reached
3437 *
3438 * inputs       - int flag allowing over_rule of limits
3439 *              - pointer to the ip to be added
3440 *              - pointer to the class
3441 * output       - non zero if limit reached
3442 *                0 if limit not reached
3443 * side effects -
3444 */
3445 static int
3446 cidr_limit_reached(int over_rule,
3447                   struct irc_ssaddr *ip, struct ClassItem *aclass)
3448 {
3449  dlink_node *ptr = NULL;
3450  struct CidrItem *cidr;
3451
3452  if (aclass->number_per_cidr <= 0)
3453    return 0;
3454
3455  if (ip->ss.ss_family == AF_INET)
3456  {
3457    if (aclass->cidr_bitlen_ipv4 <= 0)
3458      return 0;
3459
3460    DLINK_FOREACH(ptr, aclass->list_ipv4.head)
3461    {
3462      cidr = ptr->data;
3463      if (match_ipv4(ip, &cidr->mask, aclass->cidr_bitlen_ipv4))
3464      {
3465        if (!over_rule && (cidr->number_on_this_cidr >= aclass->number_per_cidr))
3466          return -1;
3467        cidr->number_on_this_cidr++;
3468        return 0;
3469      }
3470    }
3471    cidr = MyMalloc(sizeof(struct CidrItem));
3472    cidr->number_on_this_cidr = 1;
3473    cidr->mask = *ip;
3474    mask_addr(&cidr->mask, aclass->cidr_bitlen_ipv4);
3475    dlinkAdd(cidr, &cidr->node, &aclass->list_ipv4);
3476  }
3477 #ifdef IPV6
3478  else if (aclass->cidr_bitlen_ipv6 > 0)
3479  {
3480    DLINK_FOREACH(ptr, aclass->list_ipv6.head)
3481    {
3482      cidr = ptr->data;
3483      if (match_ipv6(ip, &cidr->mask, aclass->cidr_bitlen_ipv6))
3484      {
3485        if (!over_rule && (cidr->number_on_this_cidr >= aclass->number_per_cidr))
3486          return -1;
3487        cidr->number_on_this_cidr++;
3488        return 0;
3489      }
3490    }
3491    cidr = MyMalloc(sizeof(struct CidrItem));
3492    cidr->number_on_this_cidr = 1;
3493    cidr->mask = *ip;
3494    mask_addr(&cidr->mask, aclass->cidr_bitlen_ipv6);
3495    dlinkAdd(cidr, &cidr->node, &aclass->list_ipv6);
3496  }
3497 #endif
3498  return 0;
3499 }
3500
3501 /*
3502 * remove_from_cidr_check
3503 *
3504 * inputs       - pointer to the ip to be removed
3505 *              - pointer to the class
3506 * output       - NONE
3507 * side effects -
3508 */
3509 static void
3510 remove_from_cidr_check(struct irc_ssaddr *ip, struct ClassItem *aclass)
3511 {
3512  dlink_node *ptr = NULL;
3513  dlink_node *next_ptr = NULL;
3514  struct CidrItem *cidr;
3515
3516  if (aclass->number_per_cidr == 0)
3517    return;
3518
3519  if (ip->ss.ss_family == AF_INET)
3520  {
3521    if (aclass->cidr_bitlen_ipv4 <= 0)
3522      return;
3523
3524    DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv4.head)
3525    {
3526      cidr = ptr->data;
3527      if (match_ipv4(ip, &cidr->mask, aclass->cidr_bitlen_ipv4))
3528      {
3529        cidr->number_on_this_cidr--;
3530        if (cidr->number_on_this_cidr == 0)
3531        {
3532          dlinkDelete(ptr, &aclass->list_ipv4);
3533          MyFree(cidr);
3534          return;
3535        }
3536      }
3537    }
3538  }
3539 #ifdef IPV6
3540  else if (aclass->cidr_bitlen_ipv6 > 0)
3541  {
3542    DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv6.head)
3543    {
3544      cidr = ptr->data;
3545      if (match_ipv6(ip, &cidr->mask, aclass->cidr_bitlen_ipv6))
3546      {
3547        cidr->number_on_this_cidr--;
3548        if (cidr->number_on_this_cidr == 0)
3549        {
3550          dlinkDelete(ptr, &aclass->list_ipv6);
3551          MyFree(cidr);
3552          return;
3553        }
3554      }
3555    }
3556  }
3557 #endif
3558 }
3559
3560 static void
3561 rebuild_cidr_list(int aftype, struct ConfItem *oldcl, struct ClassItem *newcl,
3562                  dlink_list *old_list, dlink_list *new_list, int changed)
3563 {
3564  dlink_node *ptr;
3565  struct Client *client_p;
3566  struct ConfItem *conf;
3567  struct AccessItem *aconf;
3568
3569  if (!changed)
3570  {
3571    *new_list = *old_list;
3572    old_list->head = old_list->tail = NULL;
3573    old_list->length = 0;
3574    return;
3575  }
3576
3577  DLINK_FOREACH(ptr, local_client_list.head)
3578  {
3579    client_p = ptr->data;
3580    if (client_p->localClient->aftype != aftype)
3581      continue;
3582    if (dlink_list_length(&client_p->localClient->confs) == 0)
3583      continue;
3584
3585    conf = client_p->localClient->confs.tail->data;
3586    if (conf->type == CLIENT_TYPE)
3587    {
3588      aconf = map_to_conf(conf);
3589      if (aconf->class_ptr == oldcl)
3590        cidr_limit_reached(1, &client_p->localClient->ip, newcl);
3591    }
3592  }
3593 }
3594
3595 /*
3596 * rebuild_cidr_class
3597 *
3598 * inputs       - pointer to old conf
3599 *              - pointer to new_class
3600 * output       - none
3601 * side effects - rebuilds the class link list of cidr blocks
3602 */
3603 void
3604 rebuild_cidr_class(struct ConfItem *conf, struct ClassItem *new_class)
3605 {
3606  struct ClassItem *old_class = map_to_conf(conf);
3607
3608  if (old_class->number_per_cidr > 0 && new_class->number_per_cidr > 0)
3609  {
3610    if (old_class->cidr_bitlen_ipv4 > 0 && new_class->cidr_bitlen_ipv4 > 0)
3611      rebuild_cidr_list(AF_INET, conf, new_class,
3612                        &old_class->list_ipv4, &new_class->list_ipv4,
3613                        old_class->cidr_bitlen_ipv4 != new_class->cidr_bitlen_ipv4);
3614
3615 #ifdef IPV6
3616    if (old_class->cidr_bitlen_ipv6 > 0 && new_class->cidr_bitlen_ipv6 > 0)
3617      rebuild_cidr_list(AF_INET6, conf, new_class,
3618                        &old_class->list_ipv6, &new_class->list_ipv6,
3619                        old_class->cidr_bitlen_ipv6 != new_class->cidr_bitlen_ipv6);
3620 #endif
3621  }
3622
3623  destroy_cidr_class(old_class);
3624 }
3625
3626 /*
3627 * destroy_cidr_list
3628 *
3629 * inputs       - pointer to class dlink list of cidr blocks
3630 * output       - none
3631 * side effects - completely destroys the class link list of cidr blocks
3632 */
3633 static void
3634 destroy_cidr_list(dlink_list *list)
3635 {
3636  dlink_node *ptr = NULL, *next_ptr = NULL;
3637
3638  DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
3639  {
3640    dlinkDelete(ptr, list);
3641    MyFree(ptr->data);
3642  }
3643 }
3644
3645 /*
3646 * destroy_cidr_class
3647 *
3648 * inputs       - pointer to class
3649 * output       - none
3650 * side effects - completely destroys the class link list of cidr blocks
3651 */
3652 static void
3653 destroy_cidr_class(struct ClassItem *aclass)
3654 {
3655  destroy_cidr_list(&aclass->list_ipv4);
3656  destroy_cidr_list(&aclass->list_ipv6);
3657 }

Comparing:
ircd-hybrid-8/src/conf.c (property svn:keywords), Revision 1518 by michael, Sun Sep 2 16:50:40 2012 UTC vs.
ircd-hybrid/trunk/src/conf.c (property svn:keywords), Revision 8314 by michael, Wed Feb 28 17:47:23 2018 UTC

# Line 1 | Line 1
1 < Id Revision
1 > Id

Diff Legend

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