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

Comparing:
ircd-hybrid-8/src/s_conf.c (file contents), Revision 1175 by michael, Sun Aug 14 10:47:48 2011 UTC vs.
ircd-hybrid/branches/8.2.x/src/conf.c (file contents), Revision 7725 by michael, Mon Sep 26 14:59:44 2016 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  s_conf.c: Configuration file functions.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-2016 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 16 | Line 15
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18 < *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file conf.c
23 > * \brief Configuration file functions.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
28   #include "list.h"
29   #include "ircd_defs.h"
30 < #include "balloc.h"
31 < #include "s_conf.h"
32 < #include "s_serv.h"
33 < #include "resv.h"
30 > #include "conf.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"
34 #include "common.h"
40   #include "event.h"
36 #include "hash.h"
37 #include "hook.h"
41   #include "irc_string.h"
39 #include "sprintf_irc.h"
42   #include "s_bsd.h"
43   #include "ircd.h"
44   #include "listener.h"
# Line 44 | Line 46
46   #include "modules.h"
47   #include "numeric.h"
48   #include "fdlist.h"
49 < #include "s_log.h"
49 > #include "log.h"
50   #include "send.h"
49 #include "s_gline.h"
50 #include "fileio.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 <
57 < struct Callback *client_check_cb = NULL;
58 < struct config_server_hide ConfigServerHide;
56 > #include "parse.h"
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 };
63 < dlink_list cluster_items = { NULL, NULL, 0 };
64 < dlink_list hub_items     = { NULL, NULL, 0 };
65 < dlink_list leaf_items    = { NULL, NULL, 0 };
66 < dlink_list oconf_items   = { NULL, NULL, 0 };
67 < dlink_list uconf_items   = { NULL, NULL, 0 };
68 < dlink_list xconf_items   = { NULL, NULL, 0 };
69 < dlink_list rxconf_items  = { NULL, NULL, 0 };
70 < dlink_list rkconf_items  = { NULL, NULL, 0 };
71 < dlink_list nresv_items   = { NULL, NULL, 0 };
72 < dlink_list class_items   = { NULL, NULL, 0 };
73 < dlink_list gdeny_items   = { NULL, NULL, 0 };
74 <
75 < dlink_list temporary_klines  = { NULL, NULL, 0 };
76 < dlink_list temporary_dlines  = { NULL, NULL, 0 };
77 < dlink_list temporary_xlines  = { NULL, NULL, 0 };
78 < dlink_list temporary_rklines = { NULL, NULL, 0 };
79 < dlink_list temporary_glines  = { NULL, NULL, 0 };
80 < dlink_list temporary_rxlines = { NULL, NULL, 0 };
81 < dlink_list temporary_resv = { NULL, NULL, 0 };
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];
86 extern char yytext[];
81   extern int yyparse(); /* defined in y.tab.c */
82  
89 struct conf_parser_context conf_parser_ctx = { 0, 0, NULL };
90
91 /* internally defined functions */
92 static void lookup_confhost(struct ConfItem *);
93 static void set_default_conf(void);
94 static void validate_conf(void);
95 static void read_conf(FBFILE *);
96 static void clear_out_old_conf(void);
97 static void flush_deleted_I_P(void);
98 static void expire_tklines(dlink_list *);
99 static void garbage_collect_ip_entries(void);
100 static int hash_ip(struct irc_ssaddr *);
101 static int verify_access(struct Client *, const char *);
102 static int attach_iline(struct Client *, struct ConfItem *);
103 static struct ip_entry *find_or_add_ip(struct irc_ssaddr *);
104 static void parse_conf_file(int, int);
105 static dlink_list *map_to_list(ConfType);
106 static struct AccessItem *find_regexp_kline(const char *[]);
107 static int find_user_host(struct Client *, char *, char *, char *, unsigned int);
108
109 /*
110 * bit_len
111 */
112 static int cidr_limit_reached(int, struct irc_ssaddr *, struct ClassItem *);
113 static void remove_from_cidr_check(struct irc_ssaddr *, struct ClassItem *);
114 static void destroy_cidr_class(struct ClassItem *);
115
116 static void flags_to_ascii(unsigned int, const unsigned int[], char *, int);
117
118 /* address of default class conf */
119 static struct ConfItem *class_default;
120
121 /* usually, with hash tables, you use a prime number...
122 * but in this case I am dealing with ip addresses,
123 * not ascii strings.
124 */
125 #define IP_HASH_SIZE 0x1000
126
127 struct ip_entry
128 {
129  struct irc_ssaddr ip;
130  int count;
131  time_t last_attempt;
132  struct ip_entry *next;
133 };
134
135 static struct ip_entry *ip_hash_table[IP_HASH_SIZE];
136 static BlockHeap *ip_entry_heap = NULL;
137 static int ip_entries_count = 0;
138
139
140 void *
141 map_to_conf(struct ConfItem *aconf)
142 {
143  void *conf;
144  conf = (void *)((uintptr_t)aconf +
145                  (uintptr_t)sizeof(struct ConfItem));
146  return(conf);
147 }
148
149 struct ConfItem *
150 unmap_conf_item(void *aconf)
151 {
152  struct ConfItem *conf;
153
154  conf = (struct ConfItem *)((uintptr_t)aconf -
155                             (uintptr_t)sizeof(struct ConfItem));
156  return(conf);
157 }
83  
84   /* conf_dns_callback()
85   *
86 < * inputs       - pointer to struct AccessItem
86 > * inputs       - pointer to struct MaskItem
87   *              - pointer to DNSReply reply
88   * output       - none
89   * side effects - called when resolver query finishes
# Line 167 | Line 92 | unmap_conf_item(void *aconf)
92   * if successful save hp in the conf item it was called with
93   */
94   static void
95 < conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name)
95 > conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name, size_t namelength)
96   {
97 <  struct AccessItem *aconf = vptr;
97 >  struct MaskItem *const conf = vptr;
98  
99 <  aconf->dns_pending = 0;
99 >  conf->dns_pending = 0;
100  
101 <  if (addr != NULL)
102 <    memcpy(&aconf->ipnum, addr, sizeof(aconf->ipnum));
101 >  if (addr)
102 >    memcpy(&conf->addr, addr, sizeof(conf->addr));
103    else
104 <    aconf->dns_failed = 1;
104 >    conf->dns_failed = 1;
105   }
106  
107   /* conf_dns_lookup()
# Line 186 | Line 111 | conf_dns_callback(void *vptr, const stru
111   * allocate a dns_query and start ns lookup.
112   */
113   static void
114 < conf_dns_lookup(struct AccessItem *aconf)
114 > conf_dns_lookup(struct MaskItem *conf)
115   {
116 <  if (!aconf->dns_pending)
117 <  {
118 <    aconf->dns_pending = 1;
119 <    gethost_byname(conf_dns_callback, aconf, aconf->host);
120 <  }
116 >  if (conf->dns_pending)
117 >    return;
118 >
119 >  conf->dns_pending = 1;
120 >
121 >  if (conf->aftype == AF_INET)
122 >    gethost_byname_type(conf_dns_callback, conf, conf->host, T_A);
123 >  else
124 >    gethost_byname_type(conf_dns_callback, conf, conf->host, T_AAAA);
125   }
126  
127 < /* make_conf_item()
127 > /* map_to_list()
128   *
129 < * inputs       - type of item
130 < * output       - pointer to new conf entry
131 < * side effects - none
129 > * inputs       - ConfType conf
130 > * output       - pointer to dlink_list to use
131 > * side effects - none
132   */
133 < struct ConfItem *
134 < make_conf_item(ConfType type)
133 > static dlink_list *
134 > map_to_list(enum maskitem_type type)
135   {
207  struct ConfItem *conf = NULL;
208  struct AccessItem *aconf = NULL;
209  struct ClassItem *aclass = NULL;
210  int status = 0;
211
136    switch (type)
137    {
138 <  case DLINE_TYPE:
139 <  case EXEMPTDLINE_TYPE:
216 <  case GLINE_TYPE:
217 <  case KLINE_TYPE:
218 <  case CLIENT_TYPE:
219 <  case OPER_TYPE:
220 <  case SERVER_TYPE:
221 <    conf = MyMalloc(sizeof(struct ConfItem) +
222 <                    sizeof(struct AccessItem));
223 <    aconf = map_to_conf(conf);
224 <    aconf->aftype = AF_INET;
225 <
226 <    /* Yes, sigh. switch on type again */
227 <    switch (type)
228 <    {
229 <    case EXEMPTDLINE_TYPE:
230 <      status = CONF_EXEMPTDLINE;
231 <      break;
232 <
233 <    case DLINE_TYPE:
234 <      status = CONF_DLINE;
235 <      break;
236 <
237 <    case KLINE_TYPE:
238 <      status = CONF_KLINE;
239 <      break;
240 <
241 <    case GLINE_TYPE:
242 <      status = CONF_GLINE;
243 <      break;
244 <
245 <    case CLIENT_TYPE:
246 <      status = CONF_CLIENT;
138 >    case CONF_OPER:
139 >      return &operator_items;
140        break;
141 <
142 <    case OPER_TYPE:
250 <      status = CONF_OPERATOR;
251 <      dlinkAdd(conf, &conf->node, &oconf_items);
252 <      break;
253 <
254 <    case SERVER_TYPE:
255 <      status = CONF_SERVER;
256 <      dlinkAdd(conf, &conf->node, &server_items);
141 >    case CONF_SERVER:
142 >      return &connect_items;
143        break;
258
144      default:
145 <      break;
261 <    }
262 <    aconf->status = status;
263 <    break;
264 <
265 <  case LEAF_TYPE:
266 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
267 <                                       sizeof(struct MatchItem));
268 <    dlinkAdd(conf, &conf->node, &leaf_items);
269 <    break;
270 <
271 <  case HUB_TYPE:
272 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
273 <                                       sizeof(struct MatchItem));
274 <    dlinkAdd(conf, &conf->node, &hub_items);
275 <    break;
276 <
277 <  case ULINE_TYPE:
278 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
279 <                                       sizeof(struct MatchItem));
280 <    dlinkAdd(conf, &conf->node, &uconf_items);
281 <    break;
282 <
283 <  case GDENY_TYPE:
284 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
285 <                                       sizeof(struct AccessItem));
286 <    dlinkAdd(conf, &conf->node, &gdeny_items);
287 <    break;
288 <
289 <  case XLINE_TYPE:
290 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
291 <                                       sizeof(struct MatchItem));
292 <    dlinkAdd(conf, &conf->node, &xconf_items);
293 <    break;
294 < #ifdef HAVE_LIBPCRE
295 <  case RXLINE_TYPE:
296 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
297 <                                       sizeof(struct MatchItem));
298 <    dlinkAdd(conf, &conf->node, &rxconf_items);
299 <    break;
300 <
301 <  case RKLINE_TYPE:
302 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
303 <                                       sizeof(struct AccessItem));
304 <    aconf = map_to_conf(conf);
305 <    aconf->status = CONF_KLINE;
306 <    dlinkAdd(conf, &conf->node, &rkconf_items);
307 <    break;
308 < #endif
309 <  case CLUSTER_TYPE:
310 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem));
311 <    dlinkAdd(conf, &conf->node, &cluster_items);
312 <    break;
313 <
314 <  case CRESV_TYPE:
315 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
316 <                                       sizeof(struct ResvChannel));
317 <    break;
318 <
319 <  case NRESV_TYPE:
320 <    conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) +
321 <                                       sizeof(struct MatchItem));
322 <    dlinkAdd(conf, &conf->node, &nresv_items);
323 <    break;
324 <
325 <  case SERVICE_TYPE:
326 <    status = CONF_SERVICE;
327 <    conf = MyMalloc(sizeof(struct ConfItem));
328 <    dlinkAdd(conf, &conf->node, &service_items);
329 <    break;
330 <
331 <  case CLASS_TYPE:
332 <    conf = MyMalloc(sizeof(struct ConfItem) +
333 <                           sizeof(struct ClassItem));
334 <    dlinkAdd(conf, &conf->node, &class_items);
335 <
336 <    aclass = map_to_conf(conf);
337 <    aclass->active = 1;
338 <    ConFreq(aclass) = DEFAULT_CONNECTFREQUENCY;
339 <    PingFreq(aclass) = DEFAULT_PINGFREQUENCY;
340 <    MaxTotal(aclass) = MAXIMUM_LINKS_DEFAULT;
341 <    MaxSendq(aclass) = DEFAULT_SENDQ;
342 <
343 <    break;
344 <
345 <  default:
346 <    conf = NULL;
347 <    break;
145 >      return NULL;
146    }
349
350  /* XXX Yes, this will core if default is hit. I want it to for now - db */
351  conf->type = type;
352
353  return conf;
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;
153 <  struct MatchItem *match_item;
361 <  struct AccessItem *aconf;
362 <  ConfType type = conf->type;
363 <
364 <  MyFree(conf->name);
365 <  conf->name = NULL;
366 <
367 <  switch(type)
368 <  {
369 <  case DLINE_TYPE:
370 <  case EXEMPTDLINE_TYPE:
371 <  case GLINE_TYPE:
372 <  case KLINE_TYPE:
373 <  case CLIENT_TYPE:
374 <  case OPER_TYPE:
375 <  case SERVER_TYPE:
376 <    aconf = map_to_conf(conf);
377 <
378 <    if (aconf->dns_pending)
379 <      delete_resolver_queries(aconf);
380 <    if (aconf->passwd != NULL)
381 <      memset(aconf->passwd, 0, strlen(aconf->passwd));
382 <    if (aconf->spasswd != NULL)
383 <      memset(aconf->spasswd, 0, strlen(aconf->spasswd));
384 <    aconf->class_ptr = NULL;
385 <
386 <    MyFree(aconf->passwd);
387 <    MyFree(aconf->spasswd);
388 <    MyFree(aconf->reason);
389 <    MyFree(aconf->oper_reason);
390 <    MyFree(aconf->user);
391 <    MyFree(aconf->host);
392 < #ifdef HAVE_LIBCRYPTO
393 <    if (aconf->rsa_public_key)
394 <      RSA_free(aconf->rsa_public_key);
395 <    MyFree(aconf->rsa_public_key_file);
396 < #endif
152 >  struct MaskItem *const conf = xcalloc(sizeof(*conf));
153 >  dlink_list *list = NULL;
154  
155 <    /* Yes, sigh. switch on type again */
156 <    switch(type)
157 <    {
401 <    case EXEMPTDLINE_TYPE:
402 <    case DLINE_TYPE:
403 <    case GLINE_TYPE:
404 <    case KLINE_TYPE:
405 <    case CLIENT_TYPE:
406 <      MyFree(conf);
407 <      break;
408 <
409 <    case OPER_TYPE:
410 <      aconf = map_to_conf(conf);
411 <      if (!IsConfIllegal(aconf))
412 <        dlinkDelete(&conf->node, &oconf_items);
413 <      MyFree(conf);
414 <      break;
155 >  conf->type   = type;
156 >  conf->active = 1;
157 >  conf->aftype = AF_INET;
158  
159 <    case SERVER_TYPE:
160 <      aconf = map_to_conf(conf);
161 <      if (!IsConfIllegal(aconf))
419 <        dlinkDelete(&conf->node, &server_items);
420 <      MyFree(conf);
421 <      break;
422 <
423 <    default:
424 <      break;
425 <    }
426 <    break;
427 <
428 <  case HUB_TYPE:
429 <    match_item = map_to_conf(conf);
430 <    MyFree(match_item->user);
431 <    MyFree(match_item->host);
432 <    MyFree(match_item->reason);
433 <    MyFree(match_item->oper_reason);
434 <    /* If marked illegal, its already been pulled off of the hub_items list */
435 <    if (!match_item->illegal)
436 <      dlinkDelete(&conf->node, &hub_items);
437 <    MyFree(conf);
438 <    break;
439 <
440 <  case LEAF_TYPE:
441 <    match_item = map_to_conf(conf);
442 <    MyFree(match_item->user);
443 <    MyFree(match_item->host);
444 <    MyFree(match_item->reason);
445 <    MyFree(match_item->oper_reason);
446 <    /* If marked illegal, its already been pulled off of the leaf_items list */
447 <    if (!match_item->illegal)
448 <      dlinkDelete(&conf->node, &leaf_items);
449 <    MyFree(conf);
450 <    break;
451 <
452 <  case ULINE_TYPE:
453 <    match_item = map_to_conf(conf);
454 <    MyFree(match_item->user);
455 <    MyFree(match_item->host);
456 <    MyFree(match_item->reason);
457 <    MyFree(match_item->oper_reason);
458 <    dlinkDelete(&conf->node, &uconf_items);
459 <    MyFree(conf);
460 <    break;
461 <
462 <  case XLINE_TYPE:
463 <    match_item = map_to_conf(conf);
464 <    MyFree(match_item->user);
465 <    MyFree(match_item->host);
466 <    MyFree(match_item->reason);
467 <    MyFree(match_item->oper_reason);
468 <    dlinkDelete(&conf->node, &xconf_items);
469 <    MyFree(conf);
470 <    break;
471 < #ifdef HAVE_LIBPCRE
472 <  case RKLINE_TYPE:
473 <    aconf = map_to_conf(conf);
474 <    MyFree(aconf->regexuser);
475 <    MyFree(aconf->regexhost);
476 <    MyFree(aconf->user);
477 <    MyFree(aconf->host);
478 <    MyFree(aconf->reason);
479 <    MyFree(aconf->oper_reason);
480 <    dlinkDelete(&conf->node, &rkconf_items);
481 <    MyFree(conf);
482 <    break;
483 <
484 <  case RXLINE_TYPE:
485 <    MyFree(conf->regexpname);
486 <    match_item = map_to_conf(conf);
487 <    MyFree(match_item->user);
488 <    MyFree(match_item->host);
489 <    MyFree(match_item->reason);
490 <    MyFree(match_item->oper_reason);
491 <    dlinkDelete(&conf->node, &rxconf_items);
492 <    MyFree(conf);
493 <    break;
494 < #endif
495 <  case NRESV_TYPE:
496 <    match_item = map_to_conf(conf);
497 <    MyFree(match_item->user);
498 <    MyFree(match_item->host);
499 <    MyFree(match_item->reason);
500 <    MyFree(match_item->oper_reason);
501 <    dlinkDelete(&conf->node, &nresv_items);
502 <
503 <    if (conf->flags & CONF_FLAGS_TEMPORARY)
504 <      if ((m = dlinkFindDelete(&temporary_resv, conf)) != NULL)
505 <        free_dlink_node(m);
506 <
507 <    MyFree(conf);
508 <    break;
509 <
510 <  case GDENY_TYPE:
511 <    aconf = map_to_conf(conf);
512 <    MyFree(aconf->user);
513 <    MyFree(aconf->host);
514 <    dlinkDelete(&conf->node, &gdeny_items);
515 <    MyFree(conf);
516 <    break;
517 <
518 <  case CLUSTER_TYPE:
519 <    dlinkDelete(&conf->node, &cluster_items);
520 <    MyFree(conf);
521 <    break;
522 <
523 <  case CRESV_TYPE:
524 <    if (conf->flags & CONF_FLAGS_TEMPORARY)
525 <      if ((m = dlinkFindDelete(&temporary_resv, conf)) != NULL)
526 <        free_dlink_node(m);
527 <
528 <    MyFree(conf);
529 <    break;
530 <
531 <  case CLASS_TYPE:
532 <    dlinkDelete(&conf->node, &class_items);
533 <    MyFree(conf);
534 <    break;
535 <
536 <  case SERVICE_TYPE:
537 <    dlinkDelete(&conf->node, &service_items);
538 <    MyFree(conf);
539 <    break;
540 <
541 <  default:
542 <    break;
543 <  }
544 < }
545 <
546 < /* free_access_item()
547 < *
548 < * inputs       - pointer to conf to free
549 < * output       - none
550 < * side effects - crucial password fields are zeroed, conf is freed
551 < */
552 < void
553 < free_access_item(struct AccessItem *aconf)
554 < {
555 <  struct ConfItem *conf;
556 <
557 <  if (aconf == NULL)
558 <    return;
559 <  conf = unmap_conf_item(aconf);
560 <  delete_conf_item(conf);
159 >  if ((list = map_to_list(type)))
160 >    dlinkAdd(conf, &conf->node, list);
161 >  return conf;
162   }
163  
563 static const unsigned int shared_bit_table[] =
564  { 'K', 'k', 'U', 'X', 'x', 'Y', 'Q', 'q', 'R', 'L', 0};
565
566 /* report_confitem_types()
567 *
568 * inputs       - pointer to client requesting confitem report
569 *              - ConfType to report
570 * output       - none
571 * side effects -
572 */
164   void
165 < report_confitem_types(struct Client *source_p, ConfType type, int temp)
575 < {
576 <  dlink_node *ptr = NULL;
577 <  struct ConfItem *conf = NULL;
578 <  struct AccessItem *aconf = NULL;
579 <  struct MatchItem *matchitem = NULL;
580 <  struct ClassItem *classitem = NULL;
581 <  char buf[12];
582 <  char *p = NULL;
583 <  const char *pfx = NULL;
584 <
585 <  switch (type)
586 <  {
587 <  case GDENY_TYPE:
588 <    DLINK_FOREACH(ptr, gdeny_items.head)
589 <    {
590 <      conf = ptr->data;
591 <      aconf = map_to_conf(conf);
592 <
593 <      p = buf;
594 <
595 <      if (aconf->flags & GDENY_BLOCK)
596 <        *p++ = 'B';
597 <      else
598 <        *p++ = 'b';
599 <
600 <      if (aconf->flags & GDENY_REJECT)
601 <        *p++ = 'R';
602 <      else
603 <        *p++ = 'r';
604 <
605 <      *p = '\0';
606 <
607 <      sendto_one(source_p, ":%s %d %s V %s@%s %s %s",
608 <                 me.name, RPL_STATSDEBUG, source_p->name,
609 <                 aconf->user, aconf->host, conf->name, buf);
610 <    }
611 <    break;
612 <
613 <  case XLINE_TYPE:
614 <    DLINK_FOREACH(ptr, xconf_items.head)
615 <    {
616 <      conf = ptr->data;
617 <      matchitem = map_to_conf(conf);
618 <
619 <      sendto_one(source_p, form_str(RPL_STATSXLINE),
620 <                 me.name, source_p->name,
621 <                 matchitem->hold ? "x": "X", matchitem->count,
622 <                 conf->name, matchitem->reason);
623 <    }
624 <    break;
625 <
626 < #ifdef HAVE_LIBPCRE
627 <  case RXLINE_TYPE:
628 <    DLINK_FOREACH(ptr, rxconf_items.head)
629 <    {
630 <      conf = ptr->data;
631 <      matchitem = map_to_conf(conf);
632 <
633 <      sendto_one(source_p, form_str(RPL_STATSXLINE),
634 <                 me.name, source_p->name,
635 <                 matchitem->hold ? "xR": "XR", matchitem->count,
636 <                 conf->name, matchitem->reason);
637 <    }
638 <    break;
639 <
640 <  case RKLINE_TYPE:
641 <    pfx = temp ? "kR" : "KR";
642 <
643 <    DLINK_FOREACH(ptr, rkconf_items.head)
644 <    {
645 <      aconf = map_to_conf((conf = ptr->data));
646 <
647 <      if (temp && !(conf->flags & CONF_FLAGS_TEMPORARY))
648 <        continue;
649 <
650 <      sendto_one(source_p, form_str(RPL_STATSKLINE), me.name,
651 <                 source_p->name, pfx, aconf->host, aconf->user,
652 <                 aconf->reason, aconf->oper_reason ? aconf->oper_reason : "");
653 <    }
654 <    break;
655 < #endif
656 <
657 <  case ULINE_TYPE:
658 <    DLINK_FOREACH(ptr, uconf_items.head)
659 <    {
660 <      conf = ptr->data;
661 <      matchitem = map_to_conf(conf);
662 <
663 <      p = buf;
664 <
665 <      /* some of these are redundant for the sake of
666 <       * consistency with cluster{} flags
667 <       */
668 <      *p++ = 'c';
669 <      flags_to_ascii(matchitem->action, shared_bit_table, p, 0);
670 <
671 <      sendto_one(source_p, form_str(RPL_STATSULINE),
672 <                 me.name, source_p->name, conf->name,
673 <                 matchitem->user?matchitem->user: "*",
674 <                 matchitem->host?matchitem->host: "*", buf);
675 <    }
676 <
677 <    DLINK_FOREACH(ptr, cluster_items.head)
678 <    {
679 <      conf = ptr->data;
680 <
681 <      p = buf;
682 <
683 <      *p++ = 'C';
684 <      flags_to_ascii(conf->flags, shared_bit_table, p, 0);
685 <
686 <      sendto_one(source_p, form_str(RPL_STATSULINE),
687 <                 me.name, source_p->name, conf->name,
688 <                 "*", "*", buf);
689 <    }
690 <
691 <    break;
692 <
693 <  case OPER_TYPE:
694 <    DLINK_FOREACH(ptr, oconf_items.head)
695 <    {
696 <      conf = ptr->data;
697 <      aconf = map_to_conf(conf);
698 <
699 <      /* Don't allow non opers to see oper privs */
700 <      if (IsOper(source_p))
701 <        sendto_one(source_p, form_str(RPL_STATSOLINE),
702 <                   me.name, source_p->name, 'O', aconf->user, aconf->host,
703 <                   conf->name, oper_privs_as_string(aconf->port),
704 <                   aconf->class_ptr ? aconf->class_ptr->name : "<default>");
705 <      else
706 <        sendto_one(source_p, form_str(RPL_STATSOLINE),
707 <                   me.name, source_p->name, 'O', aconf->user, aconf->host,
708 <                   conf->name, "0",
709 <                   aconf->class_ptr ? aconf->class_ptr->name : "<default>");
710 <    }
711 <    break;
712 <
713 <  case CLASS_TYPE:
714 <    DLINK_FOREACH(ptr, class_items.head)
715 <    {
716 <      conf = ptr->data;
717 <      classitem = map_to_conf(conf);
718 <      sendto_one(source_p, form_str(RPL_STATSYLINE),
719 <                 me.name, source_p->name, 'Y',
720 <                 conf->name, PingFreq(classitem),
721 <                 ConFreq(classitem),
722 <                 MaxTotal(classitem), MaxSendq(classitem),
723 <                 CurrUserCount(classitem),
724 <                 classitem->active ? "active" : "disabled");
725 <    }
726 <    break;
727 <
728 <  case CONF_TYPE:
729 <  case CLIENT_TYPE:
730 <    break;
731 <
732 <  case SERVICE_TYPE:
733 <    DLINK_FOREACH(ptr, service_items.head)
734 <    {
735 <      conf = ptr->data;
736 <      sendto_one(source_p, form_str(RPL_STATSSERVICE),
737 <                 me.name, source_p->name, 'S', "*", conf->name, 0, 0);
738 <    }
739 <    break;
740 <
741 <  case SERVER_TYPE:
742 <    DLINK_FOREACH(ptr, server_items.head)
743 <    {
744 <      p = buf;
745 <
746 <      conf = ptr->data;
747 <      aconf = map_to_conf(conf);
748 <
749 <      buf[0] = '\0';
750 <
751 <      if (IsConfAllowAutoConn(aconf))
752 <        *p++ = 'A';
753 <      if (IsConfCryptLink(aconf))
754 <        *p++ = 'C';
755 <      if (IsConfTopicBurst(aconf))
756 <        *p++ = 'T';
757 <      if (IsConfCompressed(aconf))
758 <        *p++ = 'Z';
759 <      if (buf[0] == '\0')
760 <        *p++ = '*';
761 <
762 <      *p = '\0';
763 <
764 <      /*
765 <       * Allow admins to see actual ips unless hide_server_ips is enabled
766 <       */
767 <      if (!ConfigServerHide.hide_server_ips && IsAdmin(source_p))
768 <        sendto_one(source_p, form_str(RPL_STATSCLINE),
769 <                   me.name, source_p->name, 'C', aconf->host,
770 <                   buf, conf->name, aconf->port,
771 <                   aconf->class_ptr ? aconf->class_ptr->name : "<default>");
772 <        else
773 <          sendto_one(source_p, form_str(RPL_STATSCLINE),
774 <                     me.name, source_p->name, 'C',
775 <                     "*@127.0.0.1", buf, conf->name, aconf->port,
776 <                     aconf->class_ptr ? aconf->class_ptr->name : "<default>");
777 <    }
778 <    break;
779 <
780 <  case HUB_TYPE:
781 <    DLINK_FOREACH(ptr, hub_items.head)
782 <    {
783 <      conf = ptr->data;
784 <      matchitem = map_to_conf(conf);
785 <      sendto_one(source_p, form_str(RPL_STATSHLINE), me.name,
786 <                 source_p->name, 'H', matchitem->host, conf->name, 0, "*");
787 <    }
788 <    break;
789 <
790 <  case LEAF_TYPE:
791 <    DLINK_FOREACH(ptr, leaf_items.head)
792 <    {
793 <      conf = ptr->data;
794 <      matchitem = map_to_conf(conf);
795 <      sendto_one(source_p, form_str(RPL_STATSLLINE), me.name,
796 <                 source_p->name, 'L', matchitem->host, conf->name, 0, "*");
797 <    }
798 <    break;
799 <
800 <  case GLINE_TYPE:
801 <  case KLINE_TYPE:
802 <  case DLINE_TYPE:
803 <  case EXEMPTDLINE_TYPE:
804 <  case CRESV_TYPE:
805 <  case NRESV_TYPE:
806 <  case CLUSTER_TYPE:
807 <  default:
808 <    break;
809 <  }
810 < }
811 <
812 < /* check_client()
813 < *
814 < * inputs       - pointer to client
815 < * output       - 0 = Success
816 < *                NOT_AUTHORIZED    (-1) = Access denied (no I line match)
817 < *                IRCD_SOCKET_ERROR (-2) = Bad socket.
818 < *                I_LINE_FULL       (-3) = I-line is full
819 < *                TOO_MANY          (-4) = Too many connections from hostname
820 < *                BANNED_CLIENT     (-5) = K-lined
821 < * side effects - Ordinary client access check.
822 < *                Look for conf lines which have the same
823 < *                status as the flags passed.
824 < */
825 < static void *
826 < 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 *);
830 <  int i;
831 <
832 <  /* I'm already in big trouble if source_p->localClient is NULL -db */
833 <  if ((i = verify_access(source_p, username)))
834 <    ilog(L_INFO, "Access denied: %s[%s]",
835 <         source_p->name, source_p->sockhost);
167 >  dlink_node *node = NULL, *node_next = NULL;
168 >  dlink_list *list = NULL;
169  
170 <  switch (i)
171 <  {
839 <    case TOO_MANY:
840 <      sendto_realops_flags(UMODE_FULL, L_ALL,
841 <                           "Too many on IP for %s (%s).",
842 <                           get_client_name(source_p, SHOW_IP),
843 <                           source_p->sockhost);
844 <      ilog(L_INFO,"Too many connections on IP from %s.",
845 <           get_client_name(source_p, SHOW_IP));
846 <      ++ServerStats.is_ref;
847 <      exit_client(source_p, &me, "No more connections allowed on that IP");
848 <      break;
170 >  if ((list = map_to_list(conf->type)))
171 >    dlinkFindDelete(list, conf);
172  
173 <    case I_LINE_FULL:
851 <      sendto_realops_flags(UMODE_FULL, L_ALL,
852 <                           "I-line is full for %s (%s).",
853 <                           get_client_name(source_p, SHOW_IP),
854 <                           source_p->sockhost);
855 <      ilog(L_INFO,"Too many connections from %s.",
856 <           get_client_name(source_p, SHOW_IP));
857 <      ++ServerStats.is_ref;
858 <      exit_client(source_p, &me,
859 <                "No more connections allowed in your connection class");
860 <      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].",
868 <                           get_client_name(source_p, SHOW_IP),
869 <                           source_p->sockhost,
870 <                           source_p->localClient->listener->name,
871 <                           source_p->localClient->listener->port);
872 <      ilog(L_INFO,
873 <          "Unauthorized client connection from %s on [%s/%u].",
874 <          get_client_name(source_p, SHOW_IP),
875 <          source_p->localClient->listener->name,
876 <          source_p->localClient->listener->port);
877 <
878 <      /* XXX It is prolematical whether it is better to use the
879 <       * capture reject code here or rely on the connecting too fast code.
880 <       * - Dianora
881 <       */
882 <      if (REJECT_HOLD_TIME > 0)
883 <      {
884 <        sendto_one(source_p, ":%s NOTICE %s :You are not authorized to use this server",
885 <                   me.name, source_p->name);
886 <        source_p->localClient->reject_delay = CurrentTime + REJECT_HOLD_TIME;
887 <        SetCaptured(source_p);
888 <      }
889 <      else
890 <        exit_client(source_p, &me, "You are not authorized to use this server");
891 <      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:
894 <     /*
895 <      * Don't exit them immediately, play with them a bit.
896 <      * - Dianora
897 <      */
898 <     if (REJECT_HOLD_TIME > 0)
899 <     {
900 <       source_p->localClient->reject_delay = CurrentTime + REJECT_HOLD_TIME;
901 <       SetCaptured(source_p);
902 <     }
903 <     else
904 <       exit_client(source_p, &me, "Banned");
905 <     ++ServerStats.is_ref;
906 <     break;
907 <
908 <   case 0:
909 <   default:
910 <     break;
911 <  }
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()
917 < *
918 < * inputs       - pointer to client to verify
919 < *              - pointer to proposed username
920 < * output       - 0 if success -'ve if not
921 < * side effect  - find the first (best) I line to attach.
922 < */
923 < static int
924 < verify_access(struct Client *client_p, const char *username)
925 < {
926 <  struct AccessItem *aconf = NULL, *rkconf = NULL;
927 <  struct ConfItem *conf = NULL;
928 <  char non_ident[USERLEN + 1] = { '~', '\0' };
929 <  const char *uhi[3];
930 <
931 <  if (IsGotId(client_p))
932 <  {
933 <    aconf = find_address_conf(client_p->host, client_p->username,
934 <                             &client_p->localClient->ip,
935 <                             client_p->localClient->aftype,
936 <                             client_p->localClient->passwd);
937 <  }
938 <  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,
943 <                             client_p->localClient->aftype,
944 <                             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;
948 <  uhi[1] = client_p->host;
949 <  uhi[2] = client_p->sockhost;
950 <
951 <  rkconf = find_regexp_kline(uhi);
952 <
953 <  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);
958 <
959 <      if (IsConfRedir(aconf))
960 <      {
961 <        sendto_one(client_p, form_str(RPL_REDIR),
962 <                   me.name, client_p->name,
963 <                   conf->name ? conf->name : "",
964 <                   aconf->port);
965 <        return(NOT_AUTHORIZED);
966 <      }
967 <
968 <      if (IsConfDoIdentd(aconf))
969 <        SetNeedId(client_p);
970 <
971 <      /* Thanks for spoof idea amm */
972 <      if (IsConfDoSpoofIp(aconf))
973 <      {
974 <        conf = unmap_conf_item(aconf);
975 <
976 <        if (!ConfigFileEntry.hide_spoof_ips && IsConfSpoofNotice(aconf))
977 <          sendto_realops_flags(UMODE_ALL, L_ADMIN, "%s spoofing: %s as %s",
978 <                               client_p->name, client_p->host, conf->name);
979 <        strlcpy(client_p->host, conf->name, sizeof(client_p->host));
980 <        SetIPSpoof(client_p);
981 <      }
982 <
983 <      return(attach_iline(client_p, conf));
984 <    }
985 <    else if (rkconf || IsConfKill(aconf) || (ConfigFileEntry.glines && IsConfGline(aconf)))
986 <    {
987 <      /* XXX */
988 <      aconf = rkconf ? rkconf : aconf;
989 <      if (IsConfGline(aconf))
990 <        sendto_one(client_p, ":%s NOTICE %s :*** G-lined", me.name,
991 <                   client_p->name);
992 <      if (ConfigFileEntry.kline_with_reason)
993 <        sendto_one(client_p, ":%s NOTICE %s :*** Banned %s",
994 <                  me.name, client_p->name, aconf->reason);
995 <      return(BANNED_CLIENT);
996 <    }
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;
1013 <  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);
1021 <
1022 <  aconf = map_to_conf(conf);
1023 <  if (aconf->class_ptr == NULL)
1024 <    return NOT_AUTHORIZED;  /* If class is missing, this is best */
1025 <
1026 <  aclass = map_to_conf(aconf->class_ptr);
227 >  AddFlag(client_p, FLAGS_IPHASH);
228  
229 <  count_user_host(client_p->username, client_p->host,
1029 <                  &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 (MaxTotal(aclass) != 0 && CurrUserCount(aclass) >= MaxTotal(aclass))
235 >  if (class->max_total && class->ref_count >= class->max_total)
236      a_limit_reached = 1;
237 <  else if (MaxPerIp(aclass) != 0 && ip_found->count > MaxPerIp(aclass))
237 >  else if (class->max_perip && ip_found->count > class->max_perip)
238      a_limit_reached = 1;
239 <  else if (MaxLocal(aclass) != 0 && local >= MaxLocal(aclass))
239 >  else if (class->max_local && local >= class->max_local) /* XXX: redundant */
240      a_limit_reached = 1;
241 <  else if (MaxGlobal(aclass) != 0 && global >= MaxGlobal(aclass))
1042 <    a_limit_reached = 1;
1043 <  else if (MaxIdent(aclass) != 0 && ident >= MaxIdent(aclass) &&
1044 <           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, "
1054 <               "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()
1061 < *
1062 < * inputs               - NONE
1063 < * output               - NONE
1064 < * side effects         - allocate memory for ip_entry(s)
1065 < *                      - clear the ip hash table
1066 < */
1067 < void
1068 < init_ip_hash_table(void)
1069 < {
1070 <  ip_entry_heap = BlockHeapCreate("ip", sizeof(struct ip_entry),
1071 <    2 * hard_fdlimit);
1072 <  memset(ip_hash_table, 0, sizeof(ip_hash_table));
1073 < }
1074 <
1075 < /* find_or_add_ip()
1076 < *
1077 < * inputs       - pointer to struct irc_ssaddr
1078 < * output       - pointer to a struct ip_entry
1079 < * 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;
1088 <  int hash_index = hash_ip(ip_in), res;
1089 <  struct sockaddr_in *v4 = (struct sockaddr_in *)ip_in, *ptr_v4;
1090 < #ifdef IPV6
1091 <  struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)ip_in, *ptr_v6;
1092 < #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)
1100 <    {
1101 <      ptr_v6 = (struct sockaddr_in6 *)&ptr->ip;
1102 <      res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr));
1103 <    }
1104 <    else
1105 < #endif
1106 <    {
1107 <      ptr_v4 = (struct sockaddr_in *)&ptr->ip;
1108 <      res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr));
1109 <    }
1110 <    if (res == 0)
1111 <    {
1112 <      /* Found entry already in hash, return it. */
1113 <      return ptr;
1114 <    }
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));
1123 <
1124 <  newptr->next = ip_hash_table[hash_index];
1125 <  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()
1131 < *
1132 < * inputs        - unsigned long IP address value
1133 < * output        - NONE
1134 < * side effects  - The ip address given, is looked up in ip hash table
1135 < *                 and number of ip#'s for that ip decremented.
1136 < *                 If ip # count reaches 0 and has expired,
1137 < *                 the struct ip_entry is returned to the ip_entry_heap
1138 < */
1139 < void
1140 < remove_one_ip(struct irc_ssaddr *ip_in)
1141 < {
1142 <  struct ip_entry *ptr;
1143 <  struct ip_entry *last_ptr = NULL;
1144 <  int hash_index = hash_ip(ip_in), res;
1145 <  struct sockaddr_in *v4 = (struct sockaddr_in *)ip_in, *ptr_v4;
1146 < #ifdef IPV6
1147 <  struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)ip_in, *ptr_v6;
1148 < #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
1153 <    if (ptr->ip.ss.ss_family != ip_in->ss.ss_family)
1154 <      continue;
1155 <    if (ip_in->ss.ss_family == AF_INET6)
1156 <    {
1157 <      ptr_v6 = (struct sockaddr_in6 *)&ptr->ip;
1158 <      res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr));
1159 <    }
1160 <    else
1161 < #endif
292 >    if (IsConfRedir(conf))
293      {
294 <      ptr_v4 = (struct sockaddr_in *)&ptr->ip;
295 <      res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr));
294 >      sendto_one_numeric(client_p, &me, RPL_REDIR,
295 >                         conf->name ? conf->name : "",
296 >                         conf->port);
297 >      return NOT_AUTHORIZED;
298      }
299 <    if (res)
300 <      continue;
1168 <    if (ptr->count > 0)
1169 <      ptr->count--;
1170 <    if (ptr->count == 0 &&
1171 <        (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
1176 <        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);
1179 <      ip_entries_count--;
1180 <      return;
306 >      strlcpy(client_p->host, conf->name, sizeof(client_p->host));
307      }
1182    last_ptr = ptr;
1183  }
1184 }
1185
1186 /* hash_ip()
1187 *
1188 * input        - pointer to an irc_inaddr
1189 * output       - integer value used as index into hash table
1190 * side effects - hopefully, none
1191 */
1192 static int
1193 hash_ip(struct irc_ssaddr *addr)
1194 {
1195  if (addr->ss.ss_family == AF_INET)
1196  {
1197    struct sockaddr_in *v4 = (struct sockaddr_in *)addr;
1198    int hash;
1199    uint32_t ip;
308  
309 <    ip   = ntohl(v4->sin_addr.s_addr);
1202 <    hash = ((ip >> 12) + ip) & (IP_HASH_SIZE-1);
1203 <    return hash;
309 >    return attach_iline(client_p, conf);
310    }
311 < #ifdef IPV6
312 <  else
313 <  {
1208 <    int hash;
1209 <    struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr;
1210 <    uint32_t *ip = (uint32_t *)&v6->sin6_addr.s6_addr;
1211 <
1212 <    hash  = ip[0] ^ ip[3];
1213 <    hash ^= hash >> 16;  
1214 <    hash ^= hash >> 8;  
1215 <    hash  = hash & (IP_HASH_SIZE - 1);
1216 <    return hash;
1217 <  }
1218 < #else
1219 <  return 0;
1220 < #endif
311 >
312 >  sendto_one_notice(client_p, &me, ":*** Banned: %s", conf->reason);
313 >  return BANNED_CLIENT;
314   }
315  
316 < /* count_ip_hash()
1224 < *
1225 < * inputs        - pointer to counter of number of ips hashed
1226 < *               - pointer to memory used for ip hash
1227 < * output        - returned via pointers input
1228 < * 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   {
1236  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 >                           get_client_name(source_p, SHOW_IP),
344 >                           source_p->sockhost);
345 >      ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
346 >           get_client_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;
1262 <  struct ip_entry *last_ptr;
1263 <  struct ip_entry *next_ptr;
1264 <  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 >                           get_client_name(source_p, SHOW_IP),
355 >                           source_p->sockhost);
356 >      ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
357 >           get_client_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 >                           get_client_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 >           get_client_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);
1282 <        ip_entries_count--;
1283 <      }
1284 <      else
1285 <        last_ptr = ptr;
1286 <    }
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 1295 | 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;
1302 <  struct ConfItem *conf;
1303 <  struct ClassItem *aclass;
1304 <  struct AccessItem *aconf;
1305 <  struct ConfItem *aclass_conf;
1306 <  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;
1311 <
1312 <    if (type == CONF_TYPE || conf->type == type)
1313 <    {
1314 <      dlinkDelete(ptr, &client_p->localClient->confs);
1315 <      free_dlink_node(ptr);
1316 <
1317 <      switch (conf->type)
1318 <      {
1319 <      case CLIENT_TYPE:
1320 <      case OPER_TYPE:
1321 <      case SERVER_TYPE:
1322 <        aconf = map_to_conf(conf);
1323 <
1324 <        assert(aconf->clients > 0);
407 >    struct MaskItem *conf = node->data;
408  
409 <        if ((aclass_conf = ClassPtr(aconf)) != NULL)
410 <        {
411 <          aclass = map_to_conf(aclass_conf);
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 <          assert(aclass->curr_user_count > 0);
414 <
1332 <          if (conf->type == CLIENT_TYPE)
1333 <            remove_from_cidr_check(&client_p->localClient->ip, aclass);
1334 <          if (--aclass->curr_user_count == 0 && aclass->active == 0)
1335 <            delete_conf_item(aclass_conf);
1336 <        }
1337 <
1338 <        if (--aconf->clients == 0 && IsConfIllegal(aconf))
1339 <          delete_conf_item(conf);
413 >    if (!(conf->type & type))
414 >      continue;
415  
416 <        break;
416 >    dlinkDelete(node, &client_p->connection->confs);
417 >    free_dlink_node(node);
418  
419 <      case LEAF_TYPE:
420 <      case HUB_TYPE:
1345 <        match_item = map_to_conf(conf);
1346 <        if (match_item->ref_count == 0 && match_item->illegal)
1347 <          delete_conf_item(conf);
1348 <        break;
1349 <      default:
1350 <        break;
1351 <      }
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      }
1356  }
427  
428 <  return -1;
428 >    if (--conf->ref_count == 0 && conf->active == 0)
429 >      conf_free(conf);
430 >  }
431   }
432  
433   /* attach_conf()
# Line 1369 | 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 <  if (dlinkFind(&client_p->localClient->confs, conf) != NULL)
446 >  if (dlinkFind(&client_p->connection->confs, conf))
447      return 1;
448  
449 <  if (conf->type == CLIENT_TYPE ||
450 <      conf->type == SERVER_TYPE ||
451 <      conf->type == OPER_TYPE)
452 <  {
1381 <    struct AccessItem *aconf = map_to_conf(conf);
1382 <    struct ClassItem *aclass = map_to_conf(aconf->class_ptr);
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 <    if (IsConfIllegal(aconf))
455 <      return NOT_AUTHORIZED;
1386 <
1387 <    if (conf->type == CLIENT_TYPE)
1388 <      if (cidr_limit_reached(IsConfExemptLimits(aconf),
1389 <                             &client_p->localClient->ip, aclass))
1390 <        return TOO_MANY;    /* Already at maximum allowed */
1391 <
1392 <    CurrUserCount(aclass)++;
1393 <    aconf->clients++;
1394 <  }
1395 <  else if (conf->type == HUB_TYPE || conf->type == LEAF_TYPE)
1396 <  {
1397 <    struct MatchItem *match_item = map_to_conf(conf);
1398 <    match_item->ref_count++;
1399 <  }
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 1415 | Line 471 | int
471   attach_connect_block(struct Client *client_p, const char *name,
472                       const char *host)
473   {
474 <  dlink_node *ptr;
1419 <  struct ConfItem *conf;
1420 <  struct AccessItem *aconf;
1421 <
1422 <  assert(client_p != NULL);
1423 <  assert(host != NULL);
474 >  dlink_node *node = NULL;
475  
476 <  if (client_p == NULL || host == NULL)
1426 <    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;
1431 <    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  
1443 /* find_conf_exact()
1444 *
1445 * inputs       - type of ConfItem
1446 *              - pointer to name to find
1447 *              - pointer to username to find
1448 *              - pointer to host to find
1449 * output       - NULL or pointer to conf found
1450 * side effects - find a conf entry which matches the hostname
1451 *                and has the same name.
1452 */
1453 struct ConfItem *
1454 find_conf_exact(ConfType type, const char *name, const char *user,
1455                const char *host)
1456 {
1457  dlink_node *ptr;
1458  dlink_list *list_p;
1459  struct ConfItem *conf = NULL;
1460  struct AccessItem *aconf;
1461
1462  /* Only valid for OPER_TYPE and ...? */
1463  list_p = map_to_list(type);
1464
1465  DLINK_FOREACH(ptr, (*list_p).head)
1466  {
1467    conf = ptr->data;
1468
1469    if (conf->name == NULL)
1470      continue;
1471    aconf = map_to_conf(conf);
1472    if (aconf->host == NULL)
1473      continue;
1474    if (irccmp(conf->name, name) != 0)
1475      continue;
1476
1477    /*
1478    ** Accept if the *real* hostname (usually sockethost)
1479    ** socket host) matches *either* host or name field
1480    ** of the configuration.
1481    */
1482    if (!match(aconf->host, host) || !match(aconf->user, user))
1483      continue;
1484    if (type == OPER_TYPE)
1485    {
1486      struct ClassItem *aclass = map_to_conf(aconf->class_ptr);
1487
1488      if (aconf->clients >= MaxTotal(aclass))
1489        continue;
1490    }
1491
1492    return conf;
1493  }
1494
1495  return NULL;
1496 }
1497
493   /* find_conf_name()
494   *
495   * inputs       - pointer to conf link list to search
# Line 1504 | 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;
1511 <  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)))
1521 <      return conf;
513 >      if (conf->name && !irccmp(conf->name, name))
514 >        return conf;
515      }
516    }
517  
518    return NULL;
519   }
520  
1528 /* map_to_list()
1529 *
1530 * inputs       - ConfType conf
1531 * output       - pointer to dlink_list to use
1532 * side effects - none
1533 */
1534 static dlink_list *
1535 map_to_list(ConfType type)
1536 {
1537  switch(type)
1538  {
1539  case RXLINE_TYPE:
1540    return(&rxconf_items);
1541    break;
1542  case XLINE_TYPE:
1543    return(&xconf_items);
1544    break;
1545  case ULINE_TYPE:
1546    return(&uconf_items);
1547    break;
1548  case NRESV_TYPE:
1549    return(&nresv_items);
1550    break;
1551  case OPER_TYPE:
1552    return(&oconf_items);
1553    break;
1554  case CLASS_TYPE:
1555    return(&class_items);
1556    break;
1557  case SERVER_TYPE:
1558    return(&server_items);
1559    break;
1560  case SERVICE_TYPE:
1561    return(&service_items);
1562    break;
1563  case CLUSTER_TYPE:
1564    return(&cluster_items);
1565    break;
1566  case CONF_TYPE:
1567  case GLINE_TYPE:
1568  case KLINE_TYPE:
1569  case DLINE_TYPE:
1570  case CRESV_TYPE:
1571  default:
1572    return NULL;
1573  }
1574 }
1575
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 < {
1590 <  dlink_node *ptr=NULL;
1591 <  struct ConfItem *conf=NULL;
1592 <  struct AccessItem *aconf=NULL;
1593 <  struct MatchItem *match_item=NULL;
1594 <  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
1599 <  case RXLINE_TYPE:
1600 <      DLINK_FOREACH(ptr, list_p->head)
1601 <      {
1602 <        conf = ptr->data;
1603 <        assert(conf->regexpname);
538 >    struct MaskItem *conf = node->data;
539  
540 <        if (!ircd_pcre_exec(conf->regexpname, name))
541 <          return conf;
542 <      }
543 <      break;
1609 < #endif
1610 <  case SERVICE_TYPE:
1611 <    DLINK_FOREACH(ptr, list_p->head)
1612 <    {
1613 <      conf = ptr->data;
1614 <
1615 <      if (EmptyString(conf->name))
1616 <        continue;
1617 <      if ((name != NULL) && !irccmp(name, conf->name))
1618 <        return conf;
1619 <    }
1620 <    break;
1621 <
1622 <  case XLINE_TYPE:
1623 <  case ULINE_TYPE:
1624 <  case NRESV_TYPE:
1625 <    DLINK_FOREACH(ptr, list_p->head)
1626 <    {
1627 <      conf = ptr->data;
1628 <
1629 <      match_item = map_to_conf(conf);
1630 <      if (EmptyString(conf->name))
1631 <        continue;
1632 <      if ((name != NULL) && match_esc(conf->name, name))
1633 <      {
1634 <        if ((user == NULL && (host == NULL)))
1635 <          return conf;
1636 <        if ((match_item->action & action) != action)
1637 <          continue;
1638 <        if (EmptyString(match_item->user) || EmptyString(match_item->host))
1639 <          return conf;
1640 <        if (match(match_item->user, user) && match(match_item->host, host))
1641 <          return conf;
1642 <      }
1643 <    }
1644 <      break;
1645 <
1646 <  case SERVER_TYPE:
1647 <    DLINK_FOREACH(ptr, list_p->head)
1648 <    {
1649 <      conf = ptr->data;
1650 <      aconf = map_to_conf(conf);
1651 <
1652 <      if ((name != NULL) && match_esc(name, conf->name))
1653 <        return conf;
1654 <      else if ((host != NULL) && match_esc(host, aconf->host))
1655 <        return conf;
1656 <    }
1657 <    break;
1658 <  
1659 <  default:
1660 <    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 1668 | 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 char *name,
560 <                     const char *user, const char *host)
561 < {
1678 <  dlink_node *ptr = NULL;
1679 <  struct AccessItem *aconf;
1680 <  struct ConfItem *conf;
1681 <  struct MatchItem *match_item;
1682 <  dlink_list *list_p;
1683 <
1684 <  list_p = map_to_list(type);
1685 <
1686 <  switch(type)
1687 <  {
1688 <  case RXLINE_TYPE:
1689 <  case XLINE_TYPE:
1690 <  case ULINE_TYPE:
1691 <  case NRESV_TYPE:
1692 <
1693 <    DLINK_FOREACH(ptr, list_p->head)
1694 <    {
1695 <      conf = ptr->data;
1696 <      match_item = (struct MatchItem *)map_to_conf(conf);
1697 <      if (EmptyString(conf->name))
1698 <        continue;
1699 <    
1700 <      if (irccmp(conf->name, name) == 0)
1701 <      {
1702 <        if ((user == NULL && (host == NULL)))
1703 <          return (conf);
1704 <        if (EmptyString(match_item->user) || EmptyString(match_item->host))
1705 <          return (conf);
1706 <        if (match(match_item->user, user) && match(match_item->host, host))
1707 <          return (conf);
1708 <      }
1709 <    }
1710 <    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 <    {
1715 <      conf = ptr->data;
1716 <      aconf = (struct AccessItem *)map_to_conf(conf);
1717 <      if (EmptyString(conf->name))
1718 <        continue;
1719 <    
1720 <      if (irccmp(conf->name, name) == 0)
1721 <      {
1722 <        if ((user == NULL && (host == NULL)))
1723 <          return (conf);
1724 <        if (EmptyString(aconf->user) || EmptyString(aconf->host))
1725 <          return (conf);
1726 <        if (match(aconf->user, user) && match(aconf->host, host))
1727 <          return (conf);
1728 <      }
1729 <    }
1730 <    break;
563 >  DLINK_FOREACH(node, operator_items.head)
564 >  {
565 >    struct MaskItem *conf = node->data;
566  
567 <  case SERVER_TYPE:
1733 <    DLINK_FOREACH(ptr, list_p->head)
567 >    if (!irccmp(conf->name, name))
568      {
569 <      conf = ptr->data;
570 <      aconf = (struct AccessItem *)map_to_conf(conf);
571 <      if (EmptyString(conf->name))
572 <        continue;
1739 <    
1740 <      if (name == NULL)
1741 <      {
1742 <        if (EmptyString(aconf->host))
1743 <          continue;
1744 <        if (irccmp(aconf->host, host) == 0)
1745 <          return(conf);
1746 <      }
1747 <      else if (irccmp(conf->name, name) == 0)
569 >      if (!who)
570 >        return conf;
571 >
572 >      if (!match(conf->user, who->username))
573        {
574 <          return (conf);
574 >        switch (conf->htype)
575 >        {
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->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 >          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 >          default:
594 >            assert(0);
595 >        }
596        }
597      }
1752    break;
1753
1754  case CLASS_TYPE:
1755    DLINK_FOREACH(ptr, list_p->head)
1756    {
1757      conf = ptr->data;
1758      if (EmptyString(conf->name))
1759        continue;
1760    
1761      if (irccmp(conf->name, name) == 0)
1762        return (conf);
1763    }
1764    break;
1765
1766  default:
1767    break;
598    }
1769  return(NULL);
1770 }
599  
600 < /* rehash()
1773 < *
1774 < * Actual REHASH service routine. Called with sig == 0 if it has been called
1775 < * as a result of an operator issuing this command, else assume it has been
1776 < * called as a result of the server receiving a HUP signal.
1777 < */
1778 < int
1779 < rehash(int sig)
1780 < {
1781 <  if (sig != 0)
1782 <    sendto_realops_flags(UMODE_ALL, L_ALL,
1783 <                         "Got signal SIGHUP, reloading ircd.conf file");
1784 <
1785 <  restart_resolver();
1786 <
1787 <  /* don't close listeners until we know we can go ahead with the rehash */
1788 <
1789 <  /* Check to see if we magically got(or lost) IPv6 support */
1790 <  check_can_use_v6();
1791 <
1792 <  read_conf_files(0);
1793 <
1794 <  if (ServerInfo.description != NULL)
1795 <    strlcpy(me.info, ServerInfo.description, sizeof(me.info));
1796 <
1797 <  load_conf_modules();
1798 <
1799 <  flush_deleted_I_P();
1800 <
1801 <  rehashed_klines = 1;
1802 <
1803 <  if (ConfigLoggingEntry.use_logging)
1804 <    reopen_log(logFileName);
1805 <
1806 <  return(0);
600 >  return NULL;
601   }
602  
603   /* set_default_conf()
# Line 1821 | 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;
1828 <  ServerInfo.rsa_private_key_file = NULL;
1829 < #endif
620 >  ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
621 >  ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
622  
623 <  /* ServerInfo.name is not rehashable */
624 <  /* ServerInfo.name = ServerInfo.name; */
625 <  ServerInfo.description = NULL;
626 <  DupString(ServerInfo.network_name, NETWORK_NAME_DEFAULT);
627 <  DupString(ServerInfo.network_desc, NETWORK_DESC_DEFAULT);
628 <
629 <  memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip));
630 <  ServerInfo.specific_ipv4_vhost = 0;
631 <  memset(&ServerInfo.ip6, 0, sizeof(ServerInfo.ip6));
632 <  ServerInfo.specific_ipv6_vhost = 0;
633 <
634 <  ServerInfo.max_clients = MAXCLIENTS_MAX;
635 <
636 <  ServerInfo.hub = 0;
637 <  ServerInfo.dns_host.sin_addr.s_addr = 0;
638 <  ServerInfo.dns_host.sin_port = 0;
639 <  AdminInfo.name = NULL;
640 <  AdminInfo.email = NULL;
641 <  AdminInfo.description = NULL;
642 <
643 <  set_log_level(L_NOTICE);
1852 <  ConfigLoggingEntry.use_logging = 1;
1853 <  ConfigLoggingEntry.operlog[0] = '\0';
1854 <  ConfigLoggingEntry.userlog[0] = '\0';
1855 <  ConfigLoggingEntry.klinelog[0] = '\0';
1856 <  ConfigLoggingEntry.glinelog[0] = '\0';
1857 <  ConfigLoggingEntry.killlog[0] = '\0';
1858 <  ConfigLoggingEntry.operspylog[0] = '\0';
1859 <  ConfigLoggingEntry.ioerrlog[0] = '\0';
1860 <  ConfigLoggingEntry.failed_operlog[0] = '\0';
1861 <
1862 <  ConfigChannel.disable_fake_channels = NO;
1863 <  ConfigChannel.restrict_channels = NO;
1864 <  ConfigChannel.disable_local_channels = NO;
1865 <  ConfigChannel.use_invex = YES;
1866 <  ConfigChannel.use_except = YES;
1867 <  ConfigChannel.use_knock = YES;
1868 <  ConfigChannel.knock_delay = 300;
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 >  ConfigServerInfo.default_max_clients = MAXCLIENTS_MAX;
629 >  ConfigServerInfo.max_nick_length = 9;
630 >  ConfigServerInfo.max_topic_length = 80;
631 >  ConfigServerInfo.hub = 0;
632 >  ConfigServerInfo.libgeoip_database_options = 0;
633 >
634 >  log_del_all();
635 >
636 >  ConfigLog.use_logging = 1;
637 >
638 >  ConfigChannel.disable_fake_channels = 0;
639 >  ConfigChannel.invite_client_count = 10;
640 >  ConfigChannel.invite_client_time = 300;
641 >  ConfigChannel.invite_delay_channel = 5;
642 >  ConfigChannel.knock_client_count = 1;
643 >  ConfigChannel.knock_client_time = 300;
644    ConfigChannel.knock_delay_channel = 60;
645 <  ConfigChannel.max_chans_per_user = 15;
1871 <  ConfigChannel.quiet_on_ban = YES;
645 >  ConfigChannel.max_channels = 25;
646    ConfigChannel.max_bans = 25;
647 <  ConfigChannel.default_split_user_count = 0;
648 <  ConfigChannel.default_split_server_count = 0;
649 <  ConfigChannel.no_join_on_split = NO;
650 <  ConfigChannel.no_create_on_split = NO;
651 <  ConfigChannel.burst_topicwho = YES;
652 <
653 <  ConfigServerHide.flatten_links = NO;
654 <  ConfigServerHide.links_delay = 300;
655 <  ConfigServerHide.hidden = NO;
656 <  ConfigServerHide.disable_hidden = NO;
657 <  ConfigServerHide.hide_servers = NO;
658 <  DupString(ConfigServerHide.hidden_name, NETWORK_NAME_DEFAULT);
659 <  ConfigServerHide.hide_server_ips = NO;
660 <
661 <  
662 <  DupString(ConfigFileEntry.service_name, SERVICE_NAME_DEFAULT);
663 <  ConfigFileEntry.max_watch = WATCHSIZE_DEFAULT;
664 <  ConfigFileEntry.gline_min_cidr = 16;
665 <  ConfigFileEntry.gline_min_cidr6 = 48;
666 <  ConfigFileEntry.invisible_on_connect = YES;
667 <  ConfigFileEntry.burst_away = NO;
668 <  ConfigFileEntry.use_whois_actually = YES;
669 <  ConfigFileEntry.tkline_expire_notices = YES;
670 <  ConfigFileEntry.hide_spoof_ips = YES;
671 <  ConfigFileEntry.ignore_bogus_ts = NO;
672 <  ConfigFileEntry.disable_auth = NO;
673 <  ConfigFileEntry.disable_remote = NO;
674 <  ConfigFileEntry.kill_chase_time_limit = 90;
675 <  ConfigFileEntry.default_floodcount = 8;
676 <  ConfigFileEntry.failed_oper_notice = YES;
677 <  ConfigFileEntry.dots_in_ident = 0;
678 <  ConfigFileEntry.min_nonwildcard = 4;
679 <  ConfigFileEntry.min_nonwildcard_simple = 3;
680 <  ConfigFileEntry.max_accept = 20;
681 <  ConfigFileEntry.anti_nick_flood = NO;
682 <  ConfigFileEntry.max_nick_time = 20;
683 <  ConfigFileEntry.max_nick_changes = 5;
684 <  ConfigFileEntry.anti_spam_exit_message_time = 0;
685 <  ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
686 <  ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
687 <  ConfigFileEntry.kline_with_reason = YES;
688 <  ConfigFileEntry.kline_reason = NULL;
689 <  ConfigFileEntry.warn_no_nline = YES;
690 <  ConfigFileEntry.stats_o_oper_only = NO;
691 <  ConfigFileEntry.stats_k_oper_only = 1;  /* masked */
692 <  ConfigFileEntry.stats_i_oper_only = 1;  /* masked */
693 <  ConfigFileEntry.stats_P_oper_only = NO;
694 <  ConfigFileEntry.caller_id_wait = 60;
695 <  ConfigFileEntry.opers_bypass_callerid = NO;
696 <  ConfigFileEntry.pace_wait = 10;
697 <  ConfigFileEntry.pace_wait_simple = 1;
698 <  ConfigFileEntry.short_motd = NO;
699 <  ConfigFileEntry.ping_cookie = NO;
700 <  ConfigFileEntry.no_oper_flood = NO;
701 <  ConfigFileEntry.true_no_oper_flood = NO;
702 <  ConfigFileEntry.oper_pass_resv = YES;
703 <  ConfigFileEntry.glines = NO;
704 <  ConfigFileEntry.gline_time = 12 * 3600;
705 <  ConfigFileEntry.idletime = 0;
706 <  ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT;
1933 <  ConfigFileEntry.client_flood = CLIENT_FLOOD_DEFAULT;
1934 <  ConfigFileEntry.oper_only_umodes = UMODE_DEBUG;
1935 <  ConfigFileEntry.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE |
1936 <    UMODE_OPERWALL | UMODE_WALLOP;
1937 <  DupString(ConfigFileEntry.servlink_path, SLPATH);
1938 < #ifdef HAVE_LIBCRYPTO
1939 <  /* jdc -- This is our default value for a cipher.  According to the
1940 <   *        CRYPTLINK document (doc/cryptlink.txt), BF/128 must be supported
1941 <   *        under all circumstances if cryptlinks are enabled.  So,
1942 <   *        this will be our default.
1943 <   *
1944 <   *        NOTE: I apologise for the hard-coded value of "1" (BF/128).
1945 <   *              This should be moved into a find_cipher() routine.
1946 <   */
1947 <  ConfigFileEntry.default_cipher_preference = &CipherTable[1];
1948 < #endif
1949 <  ConfigFileEntry.use_egd = NO;
1950 <  ConfigFileEntry.egdpool_path = NULL;
1951 < #ifdef HAVE_LIBZ
1952 <  ConfigFileEntry.compression_level = 0;
1953 < #endif
1954 <  ConfigFileEntry.throttle_time = 10;
647 >  ConfigChannel.default_join_flood_count = 18;
648 >  ConfigChannel.default_join_flood_time = 6;
649 >
650 >  ConfigServerHide.flatten_links = 0;
651 >  ConfigServerHide.flatten_links_delay = 300;
652 >  ConfigServerHide.hidden = 0;
653 >  ConfigServerHide.hide_servers = 0;
654 >  ConfigServerHide.hide_services = 0;
655 >  ConfigServerHide.hidden_name = xstrdup(NETWORK_NAME_DEFAULT);
656 >  ConfigServerHide.hide_server_ips = 0;
657 >  ConfigServerHide.disable_remote_commands = 0;
658 >
659 >  ConfigGeneral.away_count = 2;
660 >  ConfigGeneral.away_time = 10;
661 >  ConfigGeneral.max_watch = 50;
662 >  ConfigGeneral.whowas_history_length = 15000;
663 >  ConfigGeneral.cycle_on_host_change = 1;
664 >  ConfigGeneral.dline_min_cidr = 16;
665 >  ConfigGeneral.dline_min_cidr6 = 48;
666 >  ConfigGeneral.kline_min_cidr = 16;
667 >  ConfigGeneral.kline_min_cidr6 = 48;
668 >  ConfigGeneral.invisible_on_connect = 1;
669 >  ConfigGeneral.tkline_expire_notices = 1;
670 >  ConfigGeneral.ignore_bogus_ts = 0;
671 >  ConfigGeneral.disable_auth = 0;
672 >  ConfigGeneral.kill_chase_time_limit = 90;
673 >  ConfigGeneral.default_floodcount = 8;
674 >  ConfigGeneral.failed_oper_notice = 1;
675 >  ConfigGeneral.dots_in_ident = 0;
676 >  ConfigGeneral.min_nonwildcard = 4;
677 >  ConfigGeneral.min_nonwildcard_simple = 3;
678 >  ConfigGeneral.max_accept = 50;
679 >  ConfigGeneral.anti_nick_flood = 0;
680 >  ConfigGeneral.max_nick_time = 20;
681 >  ConfigGeneral.max_nick_changes = 5;
682 >  ConfigGeneral.anti_spam_exit_message_time = 0;
683 >  ConfigGeneral.ts_warn_delta = 30;
684 >  ConfigGeneral.ts_max_delta = 600;
685 >  ConfigGeneral.warn_no_connect_block = 1;
686 >  ConfigGeneral.stats_e_disabled = 0;
687 >  ConfigGeneral.stats_i_oper_only = 1;  /* 1 = masked */
688 >  ConfigGeneral.stats_k_oper_only = 1;  /* 1 = masked */
689 >  ConfigGeneral.stats_o_oper_only = 1;
690 >  ConfigGeneral.stats_m_oper_only = 1;
691 >  ConfigGeneral.stats_P_oper_only = 0;
692 >  ConfigGeneral.stats_u_oper_only = 0;
693 >  ConfigGeneral.caller_id_wait = 60;
694 >  ConfigGeneral.opers_bypass_callerid = 0;
695 >  ConfigGeneral.pace_wait = 10;
696 >  ConfigGeneral.pace_wait_simple = 1;
697 >  ConfigGeneral.short_motd = 0;
698 >  ConfigGeneral.ping_cookie = 0;
699 >  ConfigGeneral.no_oper_flood = 0;
700 >  ConfigGeneral.max_targets = MAX_TARGETS_DEFAULT;
701 >  ConfigGeneral.oper_only_umodes = UMODE_DEBUG | UMODE_LOCOPS | UMODE_HIDDEN | UMODE_FARCONNECT |
702 >                                   UMODE_UNAUTH | UMODE_EXTERNAL | UMODE_BOTS | UMODE_NCHANGE |
703 >                                   UMODE_SPY | UMODE_FULL | UMODE_SKILL | UMODE_REJ | UMODE_CCONN;
704 >  ConfigGeneral.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE | UMODE_WALLOP;
705 >  ConfigGeneral.throttle_count = 1;
706 >  ConfigGeneral.throttle_time = 1;
707   }
708  
709 < /* read_conf()
709 > static void
710 > validate_conf(void)
711 > {
712 >  if (EmptyString(ConfigServerInfo.network_name))
713 >    ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
714 >
715 >  if (EmptyString(ConfigServerInfo.network_desc))
716 >    ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
717 > }
718 >
719 > /* read_conf()
720   *
721   * inputs       - file descriptor pointing to config file to use
722   * output       - None
723   * side effects - Read configuration file.
724   */
725   static void
726 < read_conf(FBFILE *file)
726 > read_conf(FILE *file)
727   {
728    lineno = 0;
729  
730 <  set_default_conf(); /* Set default values prior to conf parsing */
730 >  set_default_conf();  /* Set default values prior to conf parsing */
731    conf_parser_ctx.pass = 1;
732 <  yyparse();          /* pick up the classes first */
732 >  yyparse();  /* Pick up the classes first */
733  
734 <  fbrewind(file);
734 >  rewind(file);
735  
736    conf_parser_ctx.pass = 2;
737 <  yyparse();          /* Load the values from the conf */
738 <  validate_conf();    /* Check to make sure some values are still okay. */
739 <                      /* Some global values are also loaded here. */
740 <  check_class();      /* Make sure classes are valid */
737 >  yyparse();  /* Load the values from the conf */
738 >  validate_conf();  /* Check to make sure some values are still okay. */
739 >                    /* Some global values are also loaded here. */
740 >  whowas_trim();  /* Attempt to trim whowas list if necessary */
741 >  class_delete_marked();  /* Delete unused classes that are marked for deletion */
742   }
743  
744 < static void
745 < validate_conf(void)
744 > /* conf_rehash()
745 > *
746 > * Actual REHASH service routine. Called with sig == 0 if it has been called
747 > * as a result of an operator issuing this command, else assume it has been
748 > * called as a result of the server receiving a HUP signal.
749 > */
750 > void
751 > conf_rehash(int sig)
752   {
753 <  if (ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN)
754 <    ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
755 <
756 <  if (ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN)
757 <    ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
758 <
1990 <  if (ConfigFileEntry.servlink_path == NULL)
1991 <    DupString(ConfigFileEntry.servlink_path, SLPATH);
1992 <
1993 <  if (ServerInfo.network_name == NULL)
1994 <    DupString(ServerInfo.network_name,NETWORK_NAME_DEFAULT);
753 >  if (sig)
754 >  {
755 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
756 >                         "Got signal SIGHUP, reloading configuration file(s)");
757 >    ilog(LOG_TYPE_IRCD, "Got signal SIGHUP, reloading configuration file(s)");
758 >  }
759  
760 <  if (ServerInfo.network_desc == NULL)
1997 <    DupString(ServerInfo.network_desc,NETWORK_DESC_DEFAULT);
760 >  restart_resolver();
761  
762 <  if (ConfigFileEntry.service_name == NULL)
2000 <    DupString(ConfigFileEntry.service_name, SERVICE_NAME_DEFAULT);
762 >  /* don't close listeners until we know we can go ahead with the rehash */
763  
764 <  if ((ConfigFileEntry.client_flood < CLIENT_FLOOD_MIN) ||
2003 <      (ConfigFileEntry.client_flood > CLIENT_FLOOD_MAX))
2004 <    ConfigFileEntry.client_flood = CLIENT_FLOOD_MAX;
764 >  read_conf_files(0);
765  
766 <  ConfigFileEntry.max_watch = IRCD_MAX(ConfigFileEntry.max_watch, WATCHSIZE_MIN);
766 >  load_conf_modules();
767 >  check_conf_klines();
768   }
769  
770   /* lookup_confhost()
# Line 2011 | Line 772 | validate_conf(void)
772   * start DNS lookups of all hostnames in the conf
773   * line and convert an IP addresses in a.b.c.d number for to IP#s.
774   */
775 < static void
776 < lookup_confhost(struct ConfItem *conf)
775 > void
776 > lookup_confhost(struct MaskItem *conf)
777   {
2017  struct AccessItem *aconf;
778    struct addrinfo hints, *res;
779  
780 <  aconf = map_to_conf(conf);
781 <
2022 <  if (EmptyString(aconf->host) ||
2023 <      EmptyString(aconf->user))
2024 <  {
2025 <    ilog(L_ERROR, "Host/server name error: (%s) (%s)",
2026 <         aconf->host, conf->name);
2027 <    return;
2028 <  }
2029 <
2030 <  if (strchr(aconf->host, '*') ||
2031 <      strchr(aconf->host, '?'))
2032 <    return;
2033 <
2034 <  /* Do name lookup now on hostnames given and store the
780 >  /*
781 >   * Do name lookup now on hostnames given and store the
782     * ip numbers in conf structure.
783     */
784    memset(&hints, 0, sizeof(hints));
# Line 2042 | Line 789 | lookup_confhost(struct ConfItem *conf)
789    /* Get us ready for a bind() and don't bother doing dns lookup */
790    hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
791  
792 <  if (getaddrinfo(aconf->host, NULL, &hints, &res))
792 >  if (getaddrinfo(conf->host, NULL, &hints, &res))
793    {
794 <    conf_dns_lookup(aconf);
794 >    conf_dns_lookup(conf);
795      return;
796    }
797  
798 <  assert(res != NULL);
798 >  assert(res);
799 >
800 >  memcpy(&conf->addr, res->ai_addr, res->ai_addrlen);
801 >  conf->addr.ss_len = res->ai_addrlen;
802 >  conf->addr.ss.ss_family = res->ai_family;
803  
2053  memcpy(&aconf->ipnum, res->ai_addr, res->ai_addrlen);
2054  aconf->ipnum.ss_len = res->ai_addrlen;
2055  aconf->ipnum.ss.ss_family = res->ai_family;
804    freeaddrinfo(res);
805   }
806  
# Line 2066 | Line 814 | lookup_confhost(struct ConfItem *conf)
814   int
815   conf_connect_allowed(struct irc_ssaddr *addr, int aftype)
816   {
817 <  struct ip_entry *ip_found;
818 <  struct AccessItem *aconf = find_dline_conf(addr, aftype);
2071 <
2072 <  /* DLINE exempt also gets you out of static limits/pacing... */
2073 <  if (aconf && (aconf->status & CONF_EXEMPTDLINE))
2074 <    return 0;
817 >  struct ip_entry *ip_found = NULL;
818 >  const struct MaskItem *conf = find_dline_conf(addr, aftype);
819  
820 <  if (aconf != NULL)
2077 <    return BANNED_CLIENT;
2078 <
2079 <  ip_found = find_or_add_ip(addr);
2080 <
2081 <  if ((CurrentTime - ip_found->last_attempt) <
2082 <      ConfigFileEntry.throttle_time)
820 >  if (conf)
821    {
822 <    ip_found->last_attempt = CurrentTime;
823 <    return TOO_FAST;
822 >    /* DLINE exempt also gets you out of static limits/pacing... */
823 >    if (conf->type == CONF_EXEMPT)
824 >      return 0;
825 >    return BANNED_CLIENT;
826    }
827  
828 <  ip_found->last_attempt = CurrentTime;
2089 <  return 0;
2090 < }
828 >  ip_found = ipcache_find_or_add_address(addr);
829  
830 < static struct AccessItem *
2093 < find_regexp_kline(const char *uhi[])
2094 < {
2095 < #ifdef HAVE_LIBPCRE
2096 <  const dlink_node *ptr = NULL;
2097 <
2098 <  DLINK_FOREACH(ptr, rkconf_items.head)
830 >  if ((CurrentTime - ip_found->last_attempt) < ConfigGeneral.throttle_time)
831    {
832 <    struct AccessItem *aptr = map_to_conf(ptr->data);
833 <
2102 <    assert(aptr->regexuser);
2103 <    assert(aptr->regexhost);
832 >    if (ip_found->connection_count >= ConfigGeneral.throttle_count)
833 >      return TOO_FAST;
834  
835 <    if (!ircd_pcre_exec(aptr->regexuser, uhi[0]) &&
2106 <        (!ircd_pcre_exec(aptr->regexhost, uhi[1]) ||
2107 <         !ircd_pcre_exec(aptr->regexhost, uhi[2])))
2108 <      return aptr;
835 >    ++ip_found->connection_count;
836    }
837 < #endif
838 <  return NULL;
2112 < }
2113 <
2114 < /* find_kill()
2115 < *
2116 < * inputs       - pointer to client structure
2117 < * output       - pointer to struct AccessItem if found
2118 < * side effects - See if this user is klined already,
2119 < *                and if so, return struct AccessItem pointer
2120 < */
2121 < struct AccessItem *
2122 < find_kill(struct Client *client_p)
2123 < {
2124 <  struct AccessItem *aconf = NULL;
2125 <  const char *uhi[3];
2126 <
2127 <  uhi[0] = client_p->username;
2128 <  uhi[1] = client_p->host;
2129 <  uhi[2] = client_p->sockhost;
2130 <
2131 <  assert(client_p != NULL);
2132 <
2133 <  aconf = find_kline_conf(client_p->host, client_p->username,
2134 <                          &client_p->localClient->ip,
2135 <                          client_p->localClient->aftype);
2136 <  if (aconf == NULL)
2137 <    aconf = find_regexp_kline(uhi);
2138 <
2139 <  if (aconf && (aconf->status & CONF_KLINE))
2140 <    return aconf;
2141 <
2142 <  return NULL;
2143 < }
2144 <
2145 < struct AccessItem *
2146 < find_gline(struct Client *client_p)
2147 < {
2148 <  struct AccessItem *aconf;
2149 <
2150 <  assert(client_p != NULL);
2151 <
2152 <  aconf = find_gline_conf(client_p->host, client_p->username,
2153 <                          &client_p->localClient->ip,
2154 <                          client_p->localClient->aftype);
2155 <
2156 <  if (aconf && (aconf->status & CONF_GLINE))
2157 <    return aconf;
2158 <
2159 <  return NULL;
2160 < }
2161 <
2162 < /* add_temp_line()
2163 < *
2164 < * inputs        - pointer to struct ConfItem
2165 < * output        - none
2166 < * Side effects  - links in given struct ConfItem into
2167 < *                 temporary *line link list
2168 < */
2169 < void
2170 < add_temp_line(struct ConfItem *conf)
2171 < {
2172 <  struct AccessItem *aconf;
837 >  else
838 >    ip_found->connection_count = 1;
839  
840 <  if (conf->type == DLINE_TYPE)
841 <  {
2176 <    aconf = map_to_conf(conf);
2177 <    SetConfTemporary(aconf);
2178 <    dlinkAdd(conf, &conf->node, &temporary_dlines);
2179 <    MyFree(aconf->user);
2180 <    aconf->user = NULL;
2181 <    add_conf_by_address(CONF_DLINE, aconf);
2182 <  }
2183 <  else if (conf->type == KLINE_TYPE)
2184 <  {
2185 <    aconf = map_to_conf(conf);
2186 <    SetConfTemporary(aconf);
2187 <    dlinkAdd(conf, &conf->node, &temporary_klines);
2188 <    add_conf_by_address(CONF_KILL, aconf);
2189 <  }
2190 <  else if (conf->type == GLINE_TYPE)
2191 <  {
2192 <    aconf = map_to_conf(conf);
2193 <    SetConfTemporary(aconf);
2194 <    dlinkAdd(conf, &conf->node, &temporary_glines);
2195 <    add_conf_by_address(CONF_GLINE, aconf);
2196 <  }
2197 <  else if (conf->type == XLINE_TYPE)
2198 <  {
2199 <    conf->flags |= CONF_FLAGS_TEMPORARY;
2200 <    dlinkAdd(conf, make_dlink_node(), &temporary_xlines);
2201 <  }
2202 <  else if (conf->type == RXLINE_TYPE)
2203 <  {
2204 <    conf->flags |= CONF_FLAGS_TEMPORARY;
2205 <    dlinkAdd(conf, make_dlink_node(), &temporary_rxlines);
2206 <  }
2207 <  else if (conf->type == RKLINE_TYPE)
2208 <  {
2209 <    conf->flags |= CONF_FLAGS_TEMPORARY;
2210 <    dlinkAdd(conf, make_dlink_node(), &temporary_rklines);
2211 <  }
2212 <  else if ((conf->type == NRESV_TYPE) || (conf->type == CRESV_TYPE))
2213 <  {
2214 <    conf->flags |= CONF_FLAGS_TEMPORARY;
2215 <    dlinkAdd(conf, make_dlink_node(), &temporary_resv);
2216 <  }
840 >  ip_found->last_attempt = CurrentTime;
841 >  return 0;
842   }
843  
844   /* cleanup_tklines()
# Line 2224 | Line 849 | add_temp_line(struct ConfItem *conf)
849   *                This is an event started off in ircd.c
850   */
851   void
852 < cleanup_tklines(void *notused)
852 > cleanup_tklines(void *unused)
853   {
854 <  expire_tklines(&temporary_glines);
855 <  expire_tklines(&temporary_klines);
856 <  expire_tklines(&temporary_dlines);
2232 <  expire_tklines(&temporary_xlines);
2233 <  expire_tklines(&temporary_rxlines);
2234 <  expire_tklines(&temporary_rklines);
2235 <  expire_tklines(&temporary_resv);
2236 < }
2237 <
2238 < /* expire_tklines()
2239 < *
2240 < * inputs       - tkline list pointer
2241 < * output       - NONE
2242 < * side effects - expire tklines
2243 < */
2244 < static void
2245 < expire_tklines(dlink_list *tklist)
2246 < {
2247 <  dlink_node *ptr;
2248 <  dlink_node *next_ptr;
2249 <  struct ConfItem *conf;
2250 <  struct MatchItem *xconf;
2251 <  struct MatchItem *nconf;
2252 <  struct AccessItem *aconf;
2253 <  struct ResvChannel *cconf;
2254 <
2255 <  DLINK_FOREACH_SAFE(ptr, next_ptr, tklist->head)
2256 <  {
2257 <    conf = ptr->data;
2258 <    if (conf->type == GLINE_TYPE ||
2259 <        conf->type == KLINE_TYPE ||
2260 <        conf->type == DLINE_TYPE)
2261 <    {
2262 <      aconf = (struct AccessItem *)map_to_conf(conf);
2263 <      if (aconf->hold <= CurrentTime)
2264 <      {
2265 <        /* XXX - Do we want GLINE expiry notices?? */
2266 <        /* Alert opers that a TKline expired - Hwy */
2267 <        if (ConfigFileEntry.tkline_expire_notices)
2268 <        {
2269 <          if (aconf->status & CONF_KILL)
2270 <          {
2271 <            sendto_realops_flags(UMODE_ALL, L_ALL,
2272 <                                 "Temporary K-line for [%s@%s] expired",
2273 <                                 (aconf->user) ? aconf->user : "*",
2274 <                                 (aconf->host) ? aconf->host : "*");
2275 <          }
2276 <          else if (conf->type == DLINE_TYPE)
2277 <          {
2278 <            sendto_realops_flags(UMODE_ALL, L_ALL,
2279 <                                 "Temporary D-line for [%s] expired",
2280 <                                 (aconf->host) ? aconf->host : "*");
2281 <          }
2282 <        }
2283 <
2284 <        dlinkDelete(ptr, tklist);
2285 <        delete_one_address_conf(aconf->host, aconf);
2286 <      }
2287 <    }
2288 <    else if (conf->type == XLINE_TYPE ||
2289 <             conf->type == RXLINE_TYPE)
2290 <    {
2291 <      xconf = (struct MatchItem *)map_to_conf(conf);
2292 <      if (xconf->hold <= CurrentTime)
2293 <      {
2294 <        if (ConfigFileEntry.tkline_expire_notices)
2295 <          sendto_realops_flags(UMODE_ALL, L_ALL,
2296 <                               "Temporary X-line for [%s] %sexpired", conf->name,
2297 <                               conf->type == RXLINE_TYPE ? "(REGEX) " : "");
2298 <        dlinkDelete(ptr, tklist);
2299 <        free_dlink_node(ptr);
2300 <        delete_conf_item(conf);
2301 <      }
2302 <    }
2303 <    else if (conf->type == RKLINE_TYPE)
2304 <    {
2305 <      aconf = map_to_conf(conf);
2306 <      if (aconf->hold <= CurrentTime)
2307 <      {
2308 <        if (ConfigFileEntry.tkline_expire_notices)
2309 <           sendto_realops_flags(UMODE_ALL, L_ALL,
2310 <                                "Temporary K-line for [%s@%s] (REGEX) expired",
2311 <                                (aconf->user) ? aconf->user : "*",
2312 <                                (aconf->host) ? aconf->host : "*");
2313 <        dlinkDelete(ptr, tklist);
2314 <        free_dlink_node(ptr);
2315 <        delete_conf_item(conf);
2316 <      }
2317 <    }
2318 <    else if (conf->type == NRESV_TYPE)
2319 <    {
2320 <      nconf = (struct MatchItem *)map_to_conf(conf);
2321 <      if (nconf->hold <= CurrentTime)
2322 <      {
2323 <        if (ConfigFileEntry.tkline_expire_notices)
2324 <          sendto_realops_flags(UMODE_ALL, L_ALL,
2325 <                               "Temporary RESV for [%s] expired", conf->name);
2326 <        dlinkDelete(ptr, tklist);
2327 <        free_dlink_node(ptr);
2328 <        delete_conf_item(conf);
2329 <      }
2330 <    }
2331 <    else if (conf->type == CRESV_TYPE)
2332 <    {
2333 <      cconf = (struct ResvChannel *)map_to_conf(conf);
2334 <      if (cconf->hold <= CurrentTime)
2335 <      {
2336 <        if (ConfigFileEntry.tkline_expire_notices)
2337 <          sendto_realops_flags(UMODE_ALL, L_ALL,
2338 <                               "Temporary RESV for [%s] expired", cconf->name);
2339 <        delete_channel_resv(cconf);
2340 <      }
2341 <    }
2342 <  }
854 >  hostmask_expire_temporary();
855 >  gecos_expire();
856 >  resv_expire();
857   }
858  
859   /* oper_privs_as_string()
# Line 2348 | Line 862 | expire_tklines(dlink_list *tklist)
862   * output        - pointer to static string showing oper privs
863   * side effects  - return as string, the oper privs as derived from port
864   */
865 < static const struct oper_privs
865 > static const struct oper_flags
866   {
867 <  const unsigned int oprivs;
2354 <  const unsigned int hidden;
867 >  const unsigned int flag;
868    const unsigned char c;
869 < } flag_list[] = {
870 <  { OPER_FLAG_ADMIN,       OPER_FLAG_HIDDEN_ADMIN,  'A' },
871 <  { OPER_FLAG_REMOTEBAN,   0,                       'B' },
872 <  { OPER_FLAG_DIE,         0,                       'D' },
873 <  { OPER_FLAG_GLINE,       0,                       'G' },
874 <  { OPER_FLAG_REHASH,      0,                       'H' },
875 <  { OPER_FLAG_K,           0,                       'K' },
876 <  { OPER_FLAG_OPERWALL,    0,                       'L' },
877 <  { OPER_FLAG_N,           0,                       'N' },
878 <  { OPER_FLAG_GLOBAL_KILL, 0,                       'O' },
879 <  { OPER_FLAG_REMOTE,      0,                       'R' },
880 <  { OPER_FLAG_OPER_SPY,    0,                       'S' },
881 <  { OPER_FLAG_UNKLINE,     0,                       'U' },
882 <  { OPER_FLAG_X,           0,                       'X' },
883 <  { 0, 0, '\0' }
869 > } flag_table[] = {
870 >  { OPER_FLAG_ADMIN,          'A' },
871 >  { OPER_FLAG_CLOSE,          'B' },
872 >  { OPER_FLAG_CONNECT,        'C' },
873 >  { OPER_FLAG_CONNECT_REMOTE, 'D' },
874 >  { OPER_FLAG_DIE,            'E' },
875 >  { OPER_FLAG_DLINE,          'F' },
876 >  { OPER_FLAG_GLOBOPS,        'G' },
877 >  { OPER_FLAG_JOIN_RESV,      'H' },
878 >  { OPER_FLAG_KILL,           'I' },
879 >  { OPER_FLAG_KILL_REMOTE,    'J' },
880 >  { OPER_FLAG_KLINE,          'K' },
881 >  { OPER_FLAG_LOCOPS,         'L' },
882 >  { OPER_FLAG_MODULE,         'M' },
883 >  { OPER_FLAG_NICK_RESV,      'N' },
884 >  { OPER_FLAG_OPME,           'O' },
885 >  { OPER_FLAG_REHASH,         'P' },
886 >  { OPER_FLAG_REMOTEBAN,      'Q' },
887 >  { OPER_FLAG_RESTART,        'R' },
888 >  { OPER_FLAG_RESV,           'S' },
889 >  { OPER_FLAG_SET,            'T' },
890 >  { OPER_FLAG_SQUIT,          'U' },
891 >  { OPER_FLAG_SQUIT_REMOTE,   'V' },
892 >  { OPER_FLAG_UNDLINE,        'W' },
893 >  { OPER_FLAG_UNKLINE,        'X' },
894 >  { OPER_FLAG_UNRESV,         'Y' },
895 >  { OPER_FLAG_UNXLINE,        'Z' },
896 >  { OPER_FLAG_WALLOPS,        'a' },
897 >  { OPER_FLAG_XLINE,          'b' },
898 >  { 0, '\0' }
899   };
900  
901 < char *
902 < oper_privs_as_string(const unsigned int port)
901 > const char *
902 > oper_privs_as_string(const unsigned int flags)
903   {
904 <  static char privs_out[16];
905 <  char *privs_ptr = privs_out;
906 <  unsigned int i = 0;
907 <
908 <  for (; flag_list[i].oprivs; ++i)
909 <  {
2382 <    if ((port & flag_list[i].oprivs) &&
2383 <        (port & flag_list[i].hidden) == 0)
2384 <      *privs_ptr++ = flag_list[i].c;
2385 <    else
2386 <      *privs_ptr++ = ToLowerTab[flag_list[i].c];
2387 <  }
904 >  static char buf[sizeof(flag_table) / sizeof(struct oper_flags)];
905 >  char *p = buf;
906 >
907 >  for (const struct oper_flags *tab = flag_table; tab->flag; ++tab)
908 >    if (flags & tab->flag)
909 >      *p++ = tab->c;
910  
911 <  *privs_ptr = '\0';
911 >  if (p == buf)
912 >    *p++ = '0';
913 >
914 >  *p = '\0';
915  
916 <  return privs_out;
916 >  return buf;
917   }
918  
919   /*
920 < * Input: A client to find the active oper{} name for.
920 > * Input: A client to find the active operator {} name for.
921   * Output: The nick!user@host{oper} of the oper.
922   *         "oper" is server name for remote opers
923   * Side effects: None.
924   */
925 < char *
925 > const char *
926   get_oper_name(const struct Client *client_p)
927   {
928 <  dlink_node *cnode;
2404 <  struct ConfItem *conf;
2405 <  struct AccessItem *aconf;
928 >  static char buffer[IRCD_BUFSIZE];
929  
930 <  /* +5 for !,@,{,} and null */
931 <  static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5];
930 >  if (IsServer(client_p))
931 >    return client_p->name;
932  
933    if (MyConnect(client_p))
934    {
935 <    DLINK_FOREACH(cnode, client_p->localClient->confs.head)
935 >    const dlink_node *const node = client_p->connection->confs.head;
936 >
937 >    if (node)
938      {
939 <      conf = cnode->data;
2415 <      aconf = map_to_conf(conf);
939 >      const struct MaskItem *const conf = node->data;
940  
941 <      if (IsConfOperator(aconf))
941 >      if (conf->type == CONF_OPER)
942        {
943 <        snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
943 >        snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
944                   client_p->username, client_p->host, conf->name);
945 <        return buffer;
945 >        return buffer;
946        }
947      }
948  
949 <    /* Probably should assert here for now. If there is an oper out there
950 <     * with no oper{} conf attached, it would be good for us to know...
949 >    /*
950 >     * Probably should assert here for now. If there is an oper out there
951 >     * with no operator {} conf attached, it would be good for us to know...
952       */
953 <    assert(0); /* Oper without oper conf! */
953 >    assert(0);  /* Oper without oper conf! */
954    }
955  
956    snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
957 <           client_p->username, client_p->host, client_p->servptr->name);
957 >           client_p->username, client_p->host, client_p->servptr->name);
958    return buffer;
959   }
960  
2436 /* read_conf_files()
2437 *
2438 * inputs       - cold start YES or NO
2439 * output       - none
2440 * side effects - read all conf files needed, ircd.conf kline.conf etc.
2441 */
2442 void
2443 read_conf_files(int cold)
2444 {
2445  const char *filename;
2446  char chanmodes[32];
2447  char chanlimit[32];
2448
2449  conf_parser_ctx.boot = cold;
2450  filename = get_conf_name(CONF_TYPE);
2451
2452  /* We need to know the initial filename for the yyerror() to report
2453     FIXME: The full path is in conffilenamebuf first time since we
2454             dont know anything else
2455
2456     - Gozem 2002-07-21
2457  */
2458  strlcpy(conffilebuf, filename, sizeof(conffilebuf));
2459
2460  if ((conf_parser_ctx.conf_file = fbopen(filename, "r")) == NULL)
2461  {
2462    if (cold)
2463    {
2464      ilog(L_CRIT, "Unable to read configuration file '%s': %s",
2465           filename, strerror(errno));
2466      exit(-1);
2467    }
2468    else
2469    {
2470      sendto_realops_flags(UMODE_ALL, L_ALL,
2471                           "Unable to read configuration file '%s': %s",
2472                           filename, strerror(errno));
2473      return;
2474    }
2475  }
2476
2477  if (!cold)
2478    clear_out_old_conf();
2479
2480  read_conf(conf_parser_ctx.conf_file);
2481  fbclose(conf_parser_ctx.conf_file);
2482
2483  add_isupport("NETWORK", ServerInfo.network_name, -1);
2484  snprintf(chanmodes, sizeof(chanmodes), "b%s%s:%d",
2485           ConfigChannel.use_except ? "e" : "",
2486           ConfigChannel.use_invex ? "I" : "", ConfigChannel.max_bans);
2487  add_isupport("MAXLIST", chanmodes, -1);
2488  add_isupport("MAXTARGETS", NULL, ConfigFileEntry.max_targets);
2489
2490  if (ConfigChannel.disable_local_channels)
2491    add_isupport("CHANTYPES", "#", -1);
2492  else
2493    add_isupport("CHANTYPES", "#&", -1);
2494
2495  snprintf(chanlimit, sizeof(chanlimit), "%s:%d",
2496           ConfigChannel.disable_local_channels ? "#" : "#&",
2497           ConfigChannel.max_chans_per_user);
2498  add_isupport("CHANLIMIT", chanlimit, -1);
2499  snprintf(chanmodes, sizeof(chanmodes), "%s%s%s",
2500           ConfigChannel.use_except ? "e" : "",
2501           ConfigChannel.use_invex ? "I" : "", "b,k,l,imnprstORS");
2502  add_isupport("CHANNELLEN", NULL, LOCAL_CHANNELLEN);
2503
2504  if (ConfigChannel.use_except)
2505    add_isupport("EXCEPTS", "e", -1);
2506  if (ConfigChannel.use_invex)
2507    add_isupport("INVEX", "I", -1);
2508  add_isupport("CHANMODES", chanmodes, -1);
2509
2510  /*
2511   * message_locale may have changed.  rebuild isupport since it relies
2512   * on strlen(form_str(RPL_ISUPPORT))
2513   */
2514  rebuild_isupport_message_line();
2515
2516 #ifdef HAVE_LIBPCRE
2517  parse_conf_file(RKLINE_TYPE, cold);
2518  parse_conf_file(RXLINE_TYPE, cold);
2519 #endif
2520  parse_conf_file(KLINE_TYPE, cold);
2521  parse_conf_file(DLINE_TYPE, cold);
2522  parse_conf_file(XLINE_TYPE, cold);
2523  parse_conf_file(NRESV_TYPE, cold);
2524  parse_conf_file(CRESV_TYPE, cold);
2525 }
2526
2527 /* parse_conf_file()
2528 *
2529 * inputs       - type of conf file to parse
2530 * output       - none
2531 * side effects - conf file for givenconf type is opened and read then parsed
2532 */
2533 static void
2534 parse_conf_file(int type, int cold)
2535 {
2536  FBFILE *file = NULL;
2537  const char *filename = get_conf_name(type);
2538
2539  if ((file = fbopen(filename, "r")) == NULL)
2540  {
2541    if (cold)
2542      ilog(L_ERROR, "Unable to read configuration file '%s': %s",
2543           filename, strerror(errno));
2544    else
2545      sendto_realops_flags(UMODE_ALL, L_ALL,
2546                    "Unable to read configuration file '%s': %s",
2547                           filename, strerror(errno));
2548  }
2549  else
2550  {
2551    parse_csv_file(file, type);
2552    fbclose(file);
2553  }
2554 }
2555
961   /* clear_out_old_conf()
962   *
963   * inputs       - none
# Line 2562 | Line 967 | parse_conf_file(int type, int cold)
967   static void
968   clear_out_old_conf(void)
969   {
970 <  dlink_node *ptr = NULL, *next_ptr = NULL;
2566 <  struct ConfItem *conf;
2567 <  struct AccessItem *aconf;
2568 <  struct ClassItem *cltmp;
2569 <  struct MatchItem *match_item;
970 >  dlink_node *node = NULL, *node_next = NULL;
971    dlink_list *free_items [] = {
972 <    &server_items,   &oconf_items,    &hub_items, &leaf_items,
2572 <     &uconf_items,   &xconf_items, &rxconf_items, &rkconf_items,
2573 <     &nresv_items, &cluster_items,  &gdeny_items, &service_items, NULL
972 >    &connect_items, &operator_items, NULL
973    };
974  
975    dlink_list ** iterator = free_items; /* C is dumb */
# Line 2578 | Line 977 | clear_out_old_conf(void)
977    /* We only need to free anything allocated by yyparse() here.
978     * Resetting structs, etc, is taken care of by set_default_conf().
979     */
980 <  
981 <  for (; *iterator != NULL; iterator++)
980 >
981 >  for (; *iterator; iterator++)
982    {
983 <    DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head)
983 >    DLINK_FOREACH_SAFE(node, node_next, (*iterator)->head)
984      {
985 <      conf = ptr->data;
2587 <      /* XXX This is less than pretty */
2588 <      if (conf->type == SERVER_TYPE)
2589 <      {
2590 <        aconf = map_to_conf(conf);
985 >      struct MaskItem *conf = node->data;
986  
987 <        if (aconf->clients != 0)
988 <        {
2594 <          SetConfIllegal(aconf);
2595 <          dlinkDelete(&conf->node, &server_items);
2596 <        }
2597 <        else
2598 <        {
2599 <          delete_conf_item(conf);
2600 <        }
2601 <      }
2602 <      else if (conf->type == OPER_TYPE)
2603 <      {
2604 <        aconf = map_to_conf(conf);
2605 <
2606 <        if (aconf->clients != 0)
2607 <        {
2608 <          SetConfIllegal(aconf);
2609 <          dlinkDelete(&conf->node, &oconf_items);
2610 <        }
2611 <        else
2612 <        {
2613 <          delete_conf_item(conf);
2614 <        }
2615 <      }
2616 <      else if (conf->type == CLIENT_TYPE)
2617 <      {
2618 <        aconf = map_to_conf(conf);
2619 <
2620 <        if (aconf->clients != 0)
2621 <        {
2622 <          SetConfIllegal(aconf);
2623 <        }
2624 <        else
2625 <        {
2626 <          delete_conf_item(conf);
2627 <        }
2628 <      }
2629 <      else if (conf->type == XLINE_TYPE  ||
2630 <               conf->type == RXLINE_TYPE ||
2631 <               conf->type == RKLINE_TYPE)
2632 <      {
2633 <        /* temporary (r)xlines are also on
2634 <         * the (r)xconf items list */
2635 <        if (conf->flags & CONF_FLAGS_TEMPORARY)
2636 <          continue;
987 >      conf->active = 0;
988 >      dlinkDelete(&conf->node, *iterator);
989  
990 <        delete_conf_item(conf);
991 <      }
2640 <      else
2641 <      {
2642 <        if ((conf->type == LEAF_TYPE) || (conf->type == HUB_TYPE))
2643 <        {
2644 <          match_item = map_to_conf(conf);
2645 <          if (match_item->ref_count <= 0)
2646 <            delete_conf_item(conf);
2647 <          else
2648 <          {
2649 <            match_item->illegal = 1;
2650 <            dlinkDelete(&conf->node, *iterator);
2651 <          }
2652 <        }
2653 <        else
2654 <          delete_conf_item(conf);
2655 <      }
990 >      if (!conf->ref_count)
991 >        conf_free(conf);
992      }
993    }
994  
995    /*
996 <   * don't delete the class table, rather mark all entries
997 <   * for deletion. The table is cleaned up by check_class. - avalon
996 >   * Don't delete the class table, rather mark all entries for deletion.
997 >   * The table is cleaned up by class_delete_marked. - avalon
998     */
999 <  DLINK_FOREACH(ptr, class_items.head)
2664 <  {
2665 <    cltmp = map_to_conf(ptr->data);
2666 <
2667 <    if (ptr != class_items.tail)  /* never mark the "default" class */
2668 <      cltmp->active = 0;
2669 <  }
999 >  class_mark_for_deletion();
1000  
1001    clear_out_address_conf();
1002  
1003 <  /* clean out module paths */
2674 <  mod_clear_paths();
1003 >  modules_conf_clear();  /* Clear modules {} items */
1004  
1005 <  /* clean out ServerInfo */
2677 <  MyFree(ServerInfo.description);
2678 <  ServerInfo.description = NULL;
2679 <  MyFree(ServerInfo.network_name);
2680 <  ServerInfo.network_name = NULL;
2681 <  MyFree(ServerInfo.network_desc);
2682 <  ServerInfo.network_desc = NULL;
2683 <  MyFree(ConfigFileEntry.egdpool_path);
2684 <  ConfigFileEntry.egdpool_path = NULL;
2685 < #ifdef HAVE_LIBCRYPTO
2686 <  if (ServerInfo.rsa_private_key != NULL)
2687 <  {
2688 <    RSA_free(ServerInfo.rsa_private_key);
2689 <    ServerInfo.rsa_private_key = NULL;
2690 <  }
1005 >  motd_clear();  /* Clear motd {} items and re-cache default motd */
1006  
1007 <  MyFree(ServerInfo.rsa_private_key_file);
2693 <  ServerInfo.rsa_private_key_file = NULL;
2694 < #endif
1007 >  cluster_clear();  /* Clear cluster {} items */
1008  
1009 <  /* clean out old resvs from the conf */
2697 <  clear_conf_resv();
1009 >  gecos_clear();  /* Clear gecos {} items */
1010  
1011 <  /* clean out AdminInfo */
2700 <  MyFree(AdminInfo.name);
2701 <  AdminInfo.name = NULL;
2702 <  MyFree(AdminInfo.email);
2703 <  AdminInfo.email = NULL;
2704 <  MyFree(AdminInfo.description);
2705 <  AdminInfo.description = NULL;
2706 <
2707 <  /* operator{} and class{} blocks are freed above */
2708 <  /* clean out listeners */
2709 <  close_listeners();
1011 >  resv_clear();  /* Clear resv {} items */
1012  
1013 <  /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{},
2712 <   * exempt{} and gecos{} blocks are freed above too
2713 <   */
1013 >  service_clear();  /* Clear service {} items */
1014  
1015 <  /* clean out general */
2716 <  MyFree(ConfigFileEntry.service_name);
2717 <  ConfigFileEntry.service_name = NULL;
2718 <
2719 <  MyFree(ConfigFileEntry.servlink_path);
2720 <  ConfigFileEntry.servlink_path = NULL;
2721 < #ifdef HAVE_LIBCRYPTO
2722 <  ConfigFileEntry.default_cipher_preference = NULL;
2723 < #endif /* HAVE_LIBCRYPTO */
2724 <  delete_isupport("INVEX");
2725 <  delete_isupport("EXCEPTS");
2726 < }
1015 >  shared_clear();  /* Clear shared {} items */
1016  
1017 < /* flush_deleted_I_P()
2729 < *
2730 < * inputs       - none
2731 < * output       - none
2732 < * side effects - This function removes I/P conf items
2733 < */
2734 < static void
2735 < flush_deleted_I_P(void)
2736 < {
2737 <  dlink_node *ptr;
2738 <  dlink_node *next_ptr;
2739 <  struct ConfItem *conf;
2740 <  struct AccessItem *aconf;
2741 <  dlink_list * free_items [] = {
2742 <    &server_items, &oconf_items, NULL
2743 <  };
2744 <  dlink_list ** iterator = free_items; /* C is dumb */
2745 <
2746 <  /* flush out deleted I and P lines
2747 <   * although still in use.
2748 <   */
2749 <  for (; *iterator != NULL; iterator++)
2750 <  {
2751 <    DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head)
2752 <    {
2753 <      conf = ptr->data;
2754 <      aconf = (struct AccessItem *)map_to_conf(conf);
1017 >  pseudo_clear();  /* Clear pseudo {} items */
1018  
1019 <      if (IsConfIllegal(aconf))
1020 <      {
1021 <        dlinkDelete(ptr, *iterator);
1019 > #ifdef HAVE_LIBGEOIP
1020 >  GeoIP_delete(GeoIPv4_ctx);
1021 >  GeoIPv4_ctx = NULL;
1022 >  GeoIP_delete(GeoIPv6_ctx);
1023 >  GeoIPv6_ctx = NULL;
1024 > #endif
1025  
1026 <        if (aconf->clients == 0)
1027 <          delete_conf_item(conf);
1028 <      }
1029 <    }
1030 <  }
1031 < }
1026 >  /* Clean out ConfigServerInfo */
1027 >  xfree(ConfigServerInfo.description);
1028 >  ConfigServerInfo.description = NULL;
1029 >  xfree(ConfigServerInfo.network_name);
1030 >  ConfigServerInfo.network_name = NULL;
1031 >  xfree(ConfigServerInfo.network_desc);
1032 >  ConfigServerInfo.network_desc = NULL;
1033 >  xfree(ConfigServerInfo.libgeoip_ipv6_database_file);
1034 >  ConfigServerInfo.libgeoip_ipv6_database_file = NULL;
1035 >  xfree(ConfigServerInfo.libgeoip_ipv4_database_file);
1036 >  ConfigServerInfo.libgeoip_ipv4_database_file = NULL;
1037 >  xfree(ConfigServerInfo.rsa_private_key_file);
1038 >  ConfigServerInfo.rsa_private_key_file = NULL;
1039 >  xfree(ConfigServerInfo.ssl_certificate_file);
1040 >  ConfigServerInfo.ssl_certificate_file = NULL;
1041 >  xfree(ConfigServerInfo.ssl_dh_param_file);
1042 >  ConfigServerInfo.ssl_dh_param_file = NULL;
1043 >  xfree(ConfigServerInfo.ssl_dh_elliptic_curve);
1044 >  ConfigServerInfo.ssl_dh_elliptic_curve = NULL;
1045 >  xfree(ConfigServerInfo.ssl_cipher_list);
1046 >  ConfigServerInfo.ssl_cipher_list = NULL;
1047 >  xfree(ConfigServerInfo.ssl_message_digest_algorithm);
1048 >  ConfigServerInfo.ssl_message_digest_algorithm = NULL;
1049 >
1050 >  /* Clean out ConfigAdminInfo */
1051 >  xfree(ConfigAdminInfo.name);
1052 >  ConfigAdminInfo.name = NULL;
1053 >  xfree(ConfigAdminInfo.email);
1054 >  ConfigAdminInfo.email = NULL;
1055 >  xfree(ConfigAdminInfo.description);
1056 >  ConfigAdminInfo.description = NULL;
1057  
1058 < /* get_conf_name()
1059 < *
2769 < * inputs       - type of conf file to return name of file for
2770 < * output       - pointer to filename for type of conf
2771 < * side effects - none
2772 < */
2773 < const char *
2774 < get_conf_name(ConfType type)
2775 < {
2776 <  switch (type)
2777 <  {
2778 <    case CONF_TYPE:
2779 <      return ConfigFileEntry.configfile;
2780 <      break;
2781 <    case KLINE_TYPE:
2782 <      return ConfigFileEntry.klinefile;
2783 <      break;
2784 <    case RKLINE_TYPE:
2785 <      return ConfigFileEntry.rklinefile;
2786 <      break;
2787 <    case DLINE_TYPE:
2788 <      return ConfigFileEntry.dlinefile;
2789 <      break;
2790 <    case XLINE_TYPE:
2791 <      return ConfigFileEntry.xlinefile;
2792 <      break;
2793 <    case RXLINE_TYPE:
2794 <      return ConfigFileEntry.rxlinefile;
2795 <      break;
2796 <    case CRESV_TYPE:
2797 <      return ConfigFileEntry.cresvfile;
2798 <      break;
2799 <    case NRESV_TYPE:
2800 <      return ConfigFileEntry.nresvfile;
2801 <      break;
2802 <    case GLINE_TYPE:
2803 <      return ConfigFileEntry.glinefile;
2804 <      break;
1058 >  xfree(ConfigServerHide.flatten_links_file);
1059 >  ConfigServerHide.flatten_links_file = NULL;
1060  
1061 <    default:
1062 <      return NULL;  /* This should NEVER HAPPEN since we call this function
2808 <                       only with the above values, this will cause us to core
2809 <                       at some point if this happens so we know where it was */
2810 <  }
1061 >  /* Clean out listeners */
1062 >  listener_close_marked();
1063   }
1064  
1065 < #define BAD_PING (-1)
1066 <
2815 < /* get_conf_ping()
2816 < *
2817 < * inputs       - pointer to struct AccessItem
2818 < *              - pointer to a variable that receives ping warning time
2819 < * output       - ping frequency
2820 < * side effects - NONE
2821 < */
2822 < static int
2823 < get_conf_ping(struct ConfItem *conf, int *pingwarn)
1065 > static void
1066 > conf_handle_tls(int cold)
1067   {
1068 <  struct ClassItem *aclass;
2826 <  struct AccessItem *aconf;
2827 <
2828 <  if (conf != NULL)
1068 >  if (!tls_new_cred())
1069    {
1070 <    aconf = (struct AccessItem *)map_to_conf(conf);
2831 <    if (aconf->class_ptr != NULL)
1070 >    if (cold)
1071      {
1072 <      aclass = (struct ClassItem *)map_to_conf(aconf->class_ptr);
1073 <      *pingwarn = PingWarning(aclass);
2835 <      return PingFreq(aclass);
1072 >      ilog(LOG_TYPE_IRCD, "Error while initializing TLS");
1073 >      exit(EXIT_FAILURE);
1074      }
1075 <  }
2838 <
2839 <  return BAD_PING;
2840 < }
2841 <
2842 < /* get_client_class()
2843 < *
2844 < * inputs       - pointer to client struct
2845 < * output       - pointer to name of class
2846 < * side effects - NONE
2847 < */
2848 < const char *
2849 < get_client_class(struct Client *target_p)
2850 < {
2851 <  dlink_node *ptr;
2852 <  struct ConfItem *conf;
2853 <  struct AccessItem *aconf;
2854 <
2855 <  if (target_p != NULL && !IsMe(target_p) &&
2856 <      target_p->localClient->confs.head != NULL)
2857 <  {
2858 <    DLINK_FOREACH(ptr, target_p->localClient->confs.head)
1075 >    else
1076      {
1077 <      conf = ptr->data;
1078 <
1079 <      if (conf->type == CLIENT_TYPE || conf->type == SERVER_TYPE ||
2863 <          conf->type == OPER_TYPE)
2864 <      {
2865 <        aconf = (struct AccessItem *) map_to_conf(conf);
2866 <        if (aconf->class_ptr != NULL)
2867 <          return aconf->class_ptr->name;
2868 <      }
1077 >      /* Failed to load new settings/certs, old ones remain active */
1078 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
1079 >                           "Error reloading TLS settings, check the ircd log"); // report_crypto_errors logs this
1080      }
1081    }
2871
2872  return "default";
1082   }
1083  
1084 < /* get_client_ping()
2876 < *
2877 < * inputs       - pointer to client struct
2878 < *              - pointer to a variable that receives ping warning time
2879 < * output       - ping frequency
2880 < * side effects - NONE
2881 < */
2882 < int
2883 < get_client_ping(struct Client *target_p, int *pingwarn)
2884 < {
2885 <  int ping;
2886 <  struct ConfItem *conf;
2887 <  dlink_node *nlink;
2888 <
2889 <  if (target_p->localClient->confs.head != NULL)
2890 <    DLINK_FOREACH(nlink, target_p->localClient->confs.head)
2891 <    {
2892 <      conf = nlink->data;
2893 <
2894 <      if ((conf->type == CLIENT_TYPE) || (conf->type == SERVER_TYPE) ||
2895 <          (conf->type == OPER_TYPE))
2896 <      {
2897 <        ping = get_conf_ping(conf, pingwarn);
2898 <        if (ping > 0)
2899 <          return ping;
2900 <      }
2901 <    }
2902 <
2903 <  *pingwarn = 0;
2904 <  return DEFAULT_PINGFREQUENCY;
2905 < }
2906 <
2907 < /* find_class()
1084 > /* read_conf_files()
1085   *
1086 < * inputs       - string name of class
1087 < * output       - corresponding Class pointer
1088 < * side effects - NONE
1086 > * inputs       - cold start YES or NO
1087 > * output       - none
1088 > * side effects - read all conf files needed, ircd.conf kline.conf etc.
1089   */
1090 < struct ConfItem *
1091 < find_class(const char *classname)
1090 > void
1091 > read_conf_files(int cold)
1092   {
1093 <  struct ConfItem *conf;
1093 >  const char *filename = NULL;
1094 >  char chanmodes[IRCD_BUFSIZE] = "";
1095 >  char chanlimit[IRCD_BUFSIZE] = "";
1096  
1097 <  if ((conf = find_exact_name_conf(CLASS_TYPE, classname, NULL, NULL)) != NULL)
1098 <    return conf;
1097 >  conf_parser_ctx.boot = cold;
1098 >  filename = ConfigGeneral.configfile;
1099  
1100 <  return class_default;
1101 < }
1100 >  /* We need to know the initial filename for the yyerror() to report
1101 >     FIXME: The full path is in conffilenamebuf first time since we
1102 >             don't know anything else
1103  
1104 < /* check_class()
1105 < *
1106 < * inputs       - NONE
2927 < * output       - NONE
2928 < * side effects -
2929 < */
2930 < void
2931 < check_class(void)
2932 < {
2933 <  dlink_node *ptr = NULL, *next_ptr = NULL;
1104 >     - Gozem 2002-07-21
1105 >  */
1106 >  strlcpy(conffilebuf, filename, sizeof(conffilebuf));
1107  
1108 <  DLINK_FOREACH_SAFE(ptr, next_ptr, class_items.head)
1108 >  if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL)
1109    {
1110 <    struct ClassItem *aclass = map_to_conf(ptr->data);
2938 <
2939 <    if (!aclass->active && !CurrUserCount(aclass))
1110 >    if (cold)
1111      {
1112 <      destroy_cidr_class(aclass);
1113 <      delete_conf_item(ptr->data);
1112 >      ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
1113 >           filename, strerror(errno));
1114 >      exit(EXIT_FAILURE);
1115 >    }
1116 >    else
1117 >    {
1118 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1119 >                           "Unable to read configuration file '%s': %s",
1120 >                           filename, strerror(errno));
1121 >      return;
1122      }
1123    }
2945 }
1124  
1125 < /* init_class()
1126 < *
2949 < * inputs       - NONE
2950 < * output       - NONE
2951 < * side effects -
2952 < */
2953 < void
2954 < init_class(void)
2955 < {
2956 <  struct ClassItem *aclass;
1125 >  if (!cold)
1126 >    clear_out_old_conf();
1127  
1128 <  class_default = make_conf_item(CLASS_TYPE);
1128 >  read_conf(conf_parser_ctx.conf_file);
1129 >  fclose(conf_parser_ctx.conf_file);
1130  
1131 <  aclass = map_to_conf(class_default);
1132 <  aclass->active = 1;
2962 <  DupString(class_default->name, "default");
2963 <  ConFreq(aclass)  = DEFAULT_CONNECTFREQUENCY;
2964 <  PingFreq(aclass) = DEFAULT_PINGFREQUENCY;
2965 <  MaxTotal(aclass) = MAXIMUM_LINKS_DEFAULT;
2966 <  MaxSendq(aclass) = DEFAULT_SENDQ;
1131 >  log_reopen_all();
1132 >  conf_handle_tls(cold);
1133  
1134 <  client_check_cb = register_callback("check_client", check_client);
1135 < }
1134 >  isupport_add("NICKLEN", NULL, ConfigServerInfo.max_nick_length);
1135 >  isupport_add("NETWORK", ConfigServerInfo.network_name, -1);
1136  
1137 < /* get_sendq()
1138 < *
1139 < * inputs       - pointer to client
1140 < * output       - sendq for this client as found from its class
1141 < * side effects - NONE
1142 < */
1143 < unsigned int
1144 < get_sendq(struct Client *client_p)
1145 < {
1146 <  unsigned int sendq = DEFAULT_SENDQ;
1147 <  dlink_node *ptr;
1148 <  struct ConfItem *conf;
2983 <  struct ConfItem *class_conf;
2984 <  struct ClassItem *aclass;
2985 <  struct AccessItem *aconf;
2986 <
2987 <  if (client_p && !IsMe(client_p) && (client_p->localClient->confs.head))
2988 <  {
2989 <    DLINK_FOREACH(ptr, client_p->localClient->confs.head)
2990 <    {
2991 <      conf = ptr->data;
2992 <      if ((conf->type == SERVER_TYPE) || (conf->type == OPER_TYPE)
2993 <          || (conf->type == CLIENT_TYPE))
2994 <      {
2995 <        aconf = (struct AccessItem *)map_to_conf(conf);
2996 <        if ((class_conf = aconf->class_ptr) == NULL)
2997 <          continue;
2998 <        aclass = (struct ClassItem *)map_to_conf(class_conf);
2999 <        sendq = MaxSendq(aclass);
3000 <        return sendq;
3001 <      }
3002 <    }
3003 <  }
3004 <  /* XXX return a default?
3005 <   * if here, then there wasn't an attached conf with a sendq
3006 <   * that is very bad -Dianora
3007 <   */
3008 <  return DEFAULT_SENDQ;
1137 >  snprintf(chanmodes, sizeof(chanmodes), "beI:%u", ConfigChannel.max_bans);
1138 >  isupport_add("MAXLIST", chanmodes, -1);
1139 >  isupport_add("MAXTARGETS", NULL, ConfigGeneral.max_targets);
1140 >  isupport_add("CHANTYPES", "#", -1);
1141 >
1142 >  snprintf(chanlimit, sizeof(chanlimit), "#:%u",
1143 >           ConfigChannel.max_channels);
1144 >  isupport_add("CHANLIMIT", chanlimit, -1);
1145 >  snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,cimnprstCMORST");
1146 >  isupport_add("CHANNELLEN", NULL, CHANNELLEN);
1147 >  isupport_add("TOPICLEN", NULL, ConfigServerInfo.max_topic_length);
1148 >  isupport_add("CHANMODES", chanmodes, -1);
1149   }
1150  
1151   /* conf_add_class_to_conf()
1152   *
1153   * inputs       - pointer to config item
1154   * output       - NONE
1155 < * side effects - Add a class pointer to a conf
1155 > * side effects - Add a class pointer to a conf
1156   */
1157   void
1158 < conf_add_class_to_conf(struct ConfItem *conf, const char *class_name)
1158 > conf_add_class_to_conf(struct MaskItem *conf, const char *name)
1159   {
1160 <  struct AccessItem *aconf = map_to_conf(conf);
3021 <  struct ClassItem *class = NULL;
3022 <
3023 <  if (class_name == NULL)
1160 >  if (EmptyString(name) || (conf->class = class_find(name, 1)) == NULL)
1161    {
1162 <    aconf->class_ptr = class_default;
1162 >    conf->class = class_default;
1163  
1164 <    if (conf->type == CLIENT_TYPE)
1165 <      sendto_realops_flags(UMODE_ALL, L_ALL,
1166 <                           "Warning *** Defaulting to default class for %s@%s",
1167 <                           aconf->user, aconf->host);
3031 <    else
3032 <      sendto_realops_flags(UMODE_ALL, L_ALL,
3033 <                           "Warning *** Defaulting to default class for %s",
3034 <                           conf->name);
3035 <  }
3036 <  else
3037 <    aconf->class_ptr = find_class(class_name);
3038 <
3039 <  if (aconf->class_ptr)
3040 <    class = map_to_conf(aconf->class_ptr);
3041 <
3042 <  if (aconf->class_ptr == NULL || !class->active)
3043 <  {
3044 <    if (conf->type == CLIENT_TYPE)
3045 <      sendto_realops_flags(UMODE_ALL, L_ALL,
3046 <                           "Warning *** Defaulting to default class for %s@%s",
3047 <                           aconf->user, aconf->host);
1164 >    if (conf->type == CONF_CLIENT || conf->type == CONF_OPER)
1165 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1166 >                           "Warning *** Defaulting to default class for %s@%s",
1167 >                           conf->user, conf->host);
1168      else
1169 <      sendto_realops_flags(UMODE_ALL, L_ALL,
1170 <                           "Warning *** Defaulting to default class for %s",
1171 <                           conf->name);
3052 <    aconf->class_ptr = class_default;
1169 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1170 >                           "Warning *** Defaulting to default class for %s",
1171 >                           conf->name);
1172    }
1173   }
1174  
3056 /* conf_add_server()
3057 *
3058 * inputs       - pointer to config item
3059 *              - pointer to link count already on this conf
3060 * output       - NONE
3061 * side effects - Add a connect block
3062 */
3063 int
3064 conf_add_server(struct ConfItem *conf, const char *class_name)
3065 {
3066  struct AccessItem *aconf;
3067  struct split_nuh_item nuh;
3068  char conf_user[USERLEN + 1];
3069  char conf_host[HOSTLEN + 1];
3070
3071  aconf = map_to_conf(conf);
3072
3073  conf_add_class_to_conf(conf, class_name);
3074
3075  if (!aconf->host || !conf->name)
3076  {
3077    sendto_realops_flags(UMODE_ALL, L_ALL, "Bad connect block");
3078    ilog(L_WARN, "Bad connect block");
3079    return -1;
3080  }
3081
3082  if (EmptyString(aconf->passwd) && !IsConfCryptLink(aconf))
3083  {
3084    sendto_realops_flags(UMODE_ALL, L_ALL, "Bad connect block, name %s",
3085                         conf->name);
3086    ilog(L_WARN, "Bad connect block, host %s", conf->name);
3087    return -1;
3088  }
3089
3090  nuh.nuhmask  = aconf->host;
3091  nuh.nickptr  = NULL;
3092  nuh.userptr  = conf_user;
3093  nuh.hostptr  = conf_host;
3094
3095  nuh.nicksize = 0;
3096  nuh.usersize = sizeof(conf_user);
3097  nuh.hostsize = sizeof(conf_host);
3098
3099  split_nuh(&nuh);
3100
3101  MyFree(aconf->host);
3102  aconf->host = NULL;
3103
3104  DupString(aconf->user, conf_user); /* somehow username checking for servers
3105                                 got lost in H6/7, will have to be re-added */
3106  DupString(aconf->host, conf_host);
3107
3108  lookup_confhost(conf);
3109
3110  return 0;
3111 }
3112
1175   /* yyerror()
1176   *
1177   * inputs       - message from parser
# Line 3119 | Line 1181 | conf_add_server(struct ConfItem *conf, c
1181   void
1182   yyerror(const char *msg)
1183   {
3122  char newlinebuf[IRCD_BUFSIZE];
3123
1184    if (conf_parser_ctx.pass != 1)
1185      return;
1186  
1187 <  strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1188 <  sendto_realops_flags(UMODE_ALL, L_ALL, "\"%s\", line %u: %s: %s",
1189 <                       conffilebuf, lineno + 1, msg, newlinebuf);
1190 <  ilog(L_WARN, "\"%s\", line %u: %s: %s",
1191 <       conffilebuf, lineno + 1, msg, newlinebuf);
1192 < }
3133 <
3134 < int
3135 < conf_fbgets(char *lbuf, unsigned int max_size, FBFILE *fb)
3136 < {
3137 <  if (fbgets(lbuf, max_size, fb) == NULL)
3138 <    return 0;
3139 <
3140 <  return strlen(lbuf);
1187 >  char *p = stripws(linebuf);
1188 >  sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1189 >                       "\"%s\", line %u: %s: %s",
1190 >                       conffilebuf, lineno + 1, msg, p);
1191 >  ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1192 >       conffilebuf, lineno + 1, msg, p);
1193   }
1194  
1195 < int
1196 < conf_yy_fatal_error(const char *msg)
1195 > void
1196 > conf_error_report(const char *msg)
1197   {
1198 <  return 0;
1198 >  char *p = stripws(linebuf);
1199 >  sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1200 >                       "\"%s\", line %u: %s: %s",
1201 >                       conffilebuf, lineno + 1, msg, linebuf);
1202 >  ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1203 >       conffilebuf, lineno + 1, msg, linebuf);
1204   }
1205  
1206   /*
1207   * valid_tkline()
1208 < *
1208 > *
1209   * inputs       - pointer to ascii string to check
1210   *              - whether the specified time is in seconds or minutes
1211   * output       - -1 not enough parameters
# Line 3156 | Line 1213 | conf_yy_fatal_error(const char *msg)
1213   * side effects - none
1214   * Originally written by Dianora (Diane, db@db.net)
1215   */
1216 < time_t
1217 < valid_tkline(const char *p, int minutes)
1216 > uintmax_t
1217 > valid_tkline(const char *data, const int minutes)
1218   {
1219 <  time_t result = 0;
1219 >  const unsigned char *p = (const unsigned char *)data;
1220 >  unsigned char tmpch = '\0';
1221 >  uintmax_t result = 0;
1222  
1223 <  for (; *p; ++p)
1223 >  while ((tmpch = *p++))
1224    {
1225 <    if (!IsDigit(*p))
1225 >    if (!IsDigit(tmpch))
1226        return 0;
1227  
1228      result *= 10;
1229 <    result += ((*p) & 0xF);
1229 >    result += (tmpch & 0xF);
1230    }
1231  
1232    /*
1233 <   * In the degenerate case where oper does a /quote kline 0 user@host :reason
1234 <   * i.e. they specifically use 0, I am going to return 1 instead
1235 <   * as a return value of non-zero is used to flag it as a temporary kline
1233 >   * In the degenerate case where oper does a /quote kline 0 user@host :reason
1234 >   * i.e. they specifically use 0, I am going to return 1 instead as a return
1235 >   * value of non-zero is used to flag it as a temporary kline
1236     */
1237    if (result == 0)
1238      result = 1;
1239  
1240 <  /*
1240 >  /*
1241     * If the incoming time is in seconds convert it to minutes for the purpose
1242     * of this calculation
1243     */
1244    if (!minutes)
1245 <    result = result / (time_t)60;
1245 >    result = result / 60;
1246  
1247    if (result > MAX_TDKLINE_TIME)
1248      result = MAX_TDKLINE_TIME;
1249  
1250 <  result = result * (time_t)60;  /* turn it into seconds */
1250 >  result = result * 60;  /* Turn it into seconds */
1251  
1252    return result;
1253   }
1254  
1255 + /* valid_wild_card_simple()
1256 + *
1257 + * inputs       - data to check for sufficient non-wildcard characters
1258 + * outputs      - 1 if valid, else 0
1259 + * side effects - none
1260 + */
1261 + int
1262 + valid_wild_card_simple(const char *data)
1263 + {
1264 +  const unsigned char *p = (const unsigned char *)data;
1265 +  unsigned char tmpch = '\0';
1266 +  unsigned int nonwild = 0, wild = 0;
1267 +
1268 +  while ((tmpch = *p++))
1269 +  {
1270 +    if (tmpch == '\\' && *p)
1271 +    {
1272 +      ++p;
1273 +      if (++nonwild >= ConfigGeneral.min_nonwildcard_simple)
1274 +        return 1;
1275 +    }
1276 +    else if (!IsMWildChar(tmpch))
1277 +    {
1278 +      if (++nonwild >= ConfigGeneral.min_nonwildcard_simple)
1279 +        return 1;
1280 +    }
1281 +    else
1282 +      ++wild;
1283 +  }
1284 +
1285 +  return !wild;
1286 + }
1287 +
1288   /* valid_wild_card()
1289   *
1290   * input        - pointer to client
# Line 3202 | Line 1294 | valid_tkline(const char *p, int minutes)
1294   * side effects - NOTICE is given to source_p if warn is 1
1295   */
1296   int
1297 < valid_wild_card(struct Client *source_p, int warn, int count, ...)
1297 > valid_wild_card(int count, ...)
1298   {
1299 <  char *p;
1300 <  char tmpch;
3209 <  int nonwild = 0;
1299 >  unsigned char tmpch = '\0';
1300 >  unsigned int nonwild = 0;
1301    va_list args;
1302  
1303    /*
# Line 3225 | Line 1316 | valid_wild_card(struct Client *source_p,
1316  
1317    while (count--)
1318    {
1319 <    p = va_arg(args, char *);
1319 >    const unsigned char *p = va_arg(args, const unsigned char *);
1320      if (p == NULL)
1321        continue;
1322  
# Line 3237 | Line 1328 | valid_wild_card(struct Client *source_p,
1328           * If we find enough non-wild characters, we can
1329           * break - no point in searching further.
1330           */
1331 <        if (++nonwild >= ConfigFileEntry.min_nonwildcard)
1331 >        if (++nonwild >= ConfigGeneral.min_nonwildcard)
1332 >        {
1333 >          va_end(args);
1334            return 1;
1335 +        }
1336        }
1337      }
1338    }
1339  
1340 <  if (warn)
1341 <    sendto_one(source_p, ":%s NOTICE %s :Please include at least %d non-wildcard characters with the mask",
1342 <               me.name, source_p->name, ConfigFileEntry.min_nonwildcard);
1340 >  va_end(args);
1341 >  return 0;
1342 > }
1343 >
1344 > /* find_user_host()
1345 > *
1346 > * inputs       - pointer to client placing kline
1347 > *              - pointer to user_host_or_nick
1348 > *              - pointer to user buffer
1349 > *              - pointer to host buffer
1350 > * output       - 0 if not ok to kline, 1 to kline i.e. if valid user host
1351 > * side effects -
1352 > */
1353 > static int
1354 > find_user_host(struct Client *source_p, char *user_host_or_nick,
1355 >               char *luser, char *lhost)
1356 > {
1357 >  struct Client *target_p = NULL;
1358 >  char *hostp = NULL;
1359 >
1360 >  if (lhost == NULL)
1361 >  {
1362 >    strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
1363 >    return 1;
1364 >  }
1365 >
1366 >  if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
1367 >  {
1368 >    /* Explicit user@host mask given */
1369 >    if (hostp)                            /* I'm a little user@host */
1370 >    {
1371 >      *(hostp++) = '\0';                       /* short and squat */
1372 >
1373 >      if (*user_host_or_nick)
1374 >        strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
1375 >      else
1376 >        strcpy(luser, "*");
1377 >
1378 >      if (*hostp)
1379 >        strlcpy(lhost, hostp, HOSTLEN + 1);    /* here is my host */
1380 >      else
1381 >        strcpy(lhost, "*");
1382 >    }
1383 >    else
1384 >    {
1385 >      luser[0] = '*';             /* no @ found, assume its *@somehost */
1386 >      luser[1] = '\0';
1387 >      strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
1388 >    }
1389 >
1390 >    return 1;
1391 >  }
1392 >  else
1393 >  {
1394 >    /* Try to find user@host mask from nick */
1395 >    /* Okay to use source_p as the first param, because source_p == client_p */
1396 >    if ((target_p =
1397 >        find_chasing(source_p, user_host_or_nick)) == NULL)
1398 >      return 0;  /* find_chasing sends ERR_NOSUCHNICK */
1399 >
1400 >    if (HasFlag(target_p, FLAGS_EXEMPTKLINE))
1401 >    {
1402 >      if (IsClient(source_p))
1403 >        sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
1404 >      return 0;
1405 >    }
1406 >
1407 >    /*
1408 >     * Turn the "user" bit into "*user", blow away '~'
1409 >     * if found in original user name (non-idented)
1410 >     */
1411 >    strlcpy(luser, target_p->username, USERLEN*4 + 1);
1412 >
1413 >    if (target_p->username[0] == '~')
1414 >      luser[0] = '*';
1415 >
1416 >    strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
1417 >    return 1;
1418 >  }
1419 >
1420    return 0;
1421   }
1422  
# Line 3259 | Line 1430 | valid_wild_card(struct Client *source_p,
1430   *              - parse_flags bit map of things to test
1431   *              - pointer to user or string to parse into
1432   *              - pointer to host or NULL to parse into if non NULL
1433 < *              - pointer to optional tkline time or NULL
1433 > *              - pointer to optional tkline time or NULL
1434   *              - pointer to target_server to parse into if non NULL
1435   *              - pointer to reason to parse into
1436   *
1437 < * output       - 1 if valid, -1 if not valid
1437 > * output       - 1 if valid, 0 if not valid
1438   * side effects - A generalised k/d/x etc. line parser,
1439   *               "ALINE [time] user@host|string [ON] target :reason"
1440   *                will parse returning a parsed user, host if
# Line 3281 | Line 1452 | valid_wild_card(struct Client *source_p,
1452   */
1453   int
1454   parse_aline(const char *cmd, struct Client *source_p,
1455 <            int parc, char **parv,
1456 <            int parse_flags, char **up_p, char **h_p, time_t *tkline_time,
1457 <            char **target_server, char **reason)
1455 >            int parc, char **parv,
1456 >            char **up_p, char **h_p, uintmax_t *tkline_time,
1457 >            char **target_server, char **reason)
1458   {
1459 <  int found_tkline_time=0;
1460 <  static char def_reason[] = "No Reason";
1459 >  uintmax_t found_tkline_time=0;
1460 >  static char default_reason[] = CONF_NOREASON;
1461    static char user[USERLEN*4+1];
1462    static char host[HOSTLEN*4+1];
1463  
# Line 3295 | Line 1466 | parse_aline(const char *cmd, struct Clie
1466  
1467    found_tkline_time = valid_tkline(*parv, TK_MINUTES);
1468  
1469 <  if (found_tkline_time != 0)
1469 >  if (found_tkline_time)
1470    {
1471      parv++;
1472      parc--;
1473  
1474 <    if (tkline_time != NULL)
1474 >    if (tkline_time)
1475        *tkline_time = found_tkline_time;
1476      else
1477      {
1478 <      sendto_one(source_p, ":%s NOTICE %s :temp_line not supported by %s",
1479 <                 me.name, source_p->name, cmd);
3309 <      return -1;
1478 >      sendto_one_notice(source_p, &me, ":temp_line not supported by %s", cmd);
1479 >      return 0;
1480      }
1481    }
1482  
1483    if (parc == 0)
1484    {
1485 <    sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1486 <               me.name, source_p->name, cmd);
3317 <    return -1;
1485 >    sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1486 >    return 0;
1487    }
1488  
1489    if (h_p == NULL)
1490      *up_p = *parv;
1491    else
1492    {
1493 <    if (find_user_host(source_p, *parv, user, host, parse_flags) == 0)
1494 <      return -1;
1493 >    if (find_user_host(source_p, *parv, user, host) == 0)
1494 >      return 0;
1495  
1496      *up_p = user;
1497      *h_p = host;
1498    }
1499 <
1499 >
1500    parc--;
1501    parv++;
1502  
1503 <  if (parc != 0)
1503 >  if (parc)
1504    {
1505      if (irccmp(*parv, "ON") == 0)
1506      {
1507        parc--;
1508        parv++;
1509  
1510 <      if (target_server == NULL)
3342 <      {
3343 <        sendto_one(source_p, ":%s NOTICE %s :ON server not supported by %s",
3344 <                   me.name, source_p->name, cmd);
3345 <        return -1;
3346 <      }
3347 <
3348 <      if (!IsOperRemoteBan(source_p))
1510 >      if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN))
1511        {
1512 <        sendto_one(source_p, form_str(ERR_NOPRIVS),
1513 <                   me.name, source_p->name, "remoteban");
3352 <        return -1;
1512 >        sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "remoteban");
1513 >        return 0;
1514        }
1515  
1516        if (parc == 0 || EmptyString(*parv))
1517        {
1518 <        sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1519 <                   me.name, source_p->name, cmd);
3359 <        return -1;
1518 >        sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1519 >        return 0;
1520        }
1521  
1522        *target_server = *parv;
# Line 3368 | Line 1528 | parse_aline(const char *cmd, struct Clie
1528        /* Make sure target_server *is* NULL if no ON server found
1529         * caller probably NULL'd it first, but no harm to do it again -db
1530         */
1531 <      if (target_server != NULL)
1532 <        *target_server = NULL;
1531 >      if (target_server)
1532 >        *target_server = NULL;
1533      }
1534    }
1535  
1536 <  if (h_p != NULL)
1536 >  if (reason)
1537    {
1538 <    if (strchr(user, '!') != NULL)
3379 <    {
3380 <      sendto_one(source_p, ":%s NOTICE %s :Invalid character '!' in kline",
3381 <                 me.name, source_p->name);
3382 <      return -1;
3383 <    }
3384 <
3385 <    if ((parse_flags & AWILD) && !valid_wild_card(source_p, YES, 2, *up_p, *h_p))
3386 <      return -1;
3387 <  }
3388 <  else
3389 <    if ((parse_flags & AWILD) && !valid_wild_card(source_p, YES, 1, *up_p))
3390 <      return -1;
3391 <
3392 <  if (reason != NULL)
3393 <  {
3394 <    if (parc != 0 && !EmptyString(*parv))
3395 <    {
1538 >    if (parc && !EmptyString(*parv))
1539        *reason = *parv;
3397      if (!valid_comment(source_p, *reason, YES))
3398        return -1;
3399    }
1540      else
1541 <      *reason = def_reason;
1541 >      *reason = default_reason;
1542    }
1543  
1544    return 1;
1545   }
1546  
3407 /* find_user_host()
3408 *
3409 * inputs       - pointer to client placing kline
3410 *              - pointer to user_host_or_nick
3411 *              - pointer to user buffer
3412 *              - pointer to host buffer
3413 * output       - 0 if not ok to kline, 1 to kline i.e. if valid user host
3414 * side effects -
3415 */
3416 static int
3417 find_user_host(struct Client *source_p, char *user_host_or_nick,
3418               char *luser, char *lhost, unsigned int flags)
3419 {
3420  struct Client *target_p = NULL;
3421  char *hostp = NULL;
3422
3423  if (lhost == NULL)
3424  {
3425    strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
3426    return 1;
3427  }
3428
3429  if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
3430  {
3431    /* Explicit user@host mask given */
3432
3433    if (hostp != NULL)                            /* I'm a little user@host */
3434    {
3435      *(hostp++) = '\0';                       /* short and squat */
3436      if (*user_host_or_nick)
3437        strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
3438      else
3439        strcpy(luser, "*");
3440      if (*hostp)
3441        strlcpy(lhost, hostp, HOSTLEN + 1);    /* here is my host */
3442      else
3443        strcpy(lhost, "*");
3444    }
3445    else
3446    {
3447      luser[0] = '*';             /* no @ found, assume its *@somehost */
3448      luser[1] = '\0';    
3449      strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
3450    }
3451    
3452    return 1;
3453  }
3454  else if (!(flags & NOUSERLOOKUP))
3455  {
3456    /* Try to find user@host mask from nick */
3457    /* Okay to use source_p as the first param, because source_p == client_p */
3458    if ((target_p =
3459        find_chasing(source_p, source_p, user_host_or_nick, NULL)) == NULL)
3460      return 0;
3461
3462    if (IsExemptKline(target_p))
3463    {
3464      if (!IsServer(source_p))
3465        sendto_one(source_p,
3466                   ":%s NOTICE %s :%s is E-lined",
3467                   me.name, source_p->name, target_p->name);
3468      return 0;
3469    }
3470
3471    /*
3472     * turn the "user" bit into "*user", blow away '~'
3473     * if found in original user name (non-idented)
3474     */
3475    strlcpy(luser, target_p->username, USERLEN*4 + 1);
3476
3477    if (target_p->username[0] == '~')
3478      luser[0] = '*';
3479
3480    if (target_p->sockhost[0] == '\0' ||
3481        (target_p->sockhost[0] == '0' && target_p->sockhost[1] == '\0'))
3482      strlcpy(lhost, target_p->host, HOSTLEN*4 + 1);
3483    else
3484      strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
3485    return 1;
3486  }
3487
3488  return 0;
3489 }
3490
3491 /* valid_comment()
3492 *
3493 * inputs       - pointer to client
3494 *              - pointer to comment
3495 * output       - 0 if no valid comment,
3496 *              - 1 if valid
3497 * side effects - truncates reason where necessary
3498 */
3499 int
3500 valid_comment(struct Client *source_p, char *comment, int warn)
3501 {
3502  if (strchr(comment, '"'))
3503  {
3504    if (warn)
3505      sendto_one(source_p, ":%s NOTICE %s :Invalid character '\"' in comment",
3506                 me.name, source_p->name);
3507    return 0;
3508  }
3509
3510  if (strlen(comment) > REASONLEN)
3511    comment[REASONLEN-1] = '\0';
3512
3513  return 1;
3514 }
3515
1547   /* match_conf_password()
1548   *
1549   * inputs       - pointer to given password
# Line 3521 | Line 1552 | valid_comment(struct Client *source_p, c
1552   * side effects - none
1553   */
1554   int
1555 < match_conf_password(const char *password, const struct AccessItem *aconf)
1555 > match_conf_password(const char *password, const struct MaskItem *conf)
1556   {
1557    const char *encr = NULL;
1558  
1559 <  if (password == NULL || aconf->passwd == NULL)
1559 >  if (EmptyString(password) || EmptyString(conf->passwd))
1560      return 0;
1561  
1562 <  if (aconf->flags & CONF_FLAGS_ENCRYPTED)
1563 <  {
3533 <    /* use first two chars of the password they send in as salt */
3534 <    /* If the password in the conf is MD5, and ircd is linked
3535 <     * to scrypt on FreeBSD, or the standard crypt library on
3536 <     * glibc Linux, then this code will work fine on generating
3537 <     * the proper encrypted hash for comparison.
3538 <     */
3539 <    if (*aconf->passwd)
3540 <      encr = crypt(password, aconf->passwd);
3541 <    else
3542 <      encr = "";
3543 <  }
1562 >  if (conf->flags & CONF_FLAGS_ENCRYPTED)
1563 >    encr = crypt(password, conf->passwd);
1564    else
1565      encr = password;
1566  
1567 <  return !strcmp(encr, aconf->passwd);
3548 < }
3549 <
3550 < /*
3551 < * cluster_a_line
3552 < *
3553 < * inputs       - client sending the cluster
3554 < *              - command name "KLINE" "XLINE" etc.
3555 < *              - capab -- CAP_KLN etc. from s_serv.h
3556 < *              - cluster type -- CLUSTER_KLINE etc. from s_conf.h
3557 < *              - pattern and args to send along
3558 < * output       - none
3559 < * side effects - Take source_p send the pattern with args given
3560 < *                along to all servers that match capab and cluster type
3561 < */
3562 < void
3563 < cluster_a_line(struct Client *source_p, const char *command,
3564 <               int capab, int cluster_type, const char *pattern, ...)
3565 < {
3566 <  va_list args;
3567 <  char buffer[IRCD_BUFSIZE];
3568 <  const dlink_node *ptr = NULL;
3569 <
3570 <  va_start(args, pattern);
3571 <  vsnprintf(buffer, sizeof(buffer), pattern, args);
3572 <  va_end(args);
3573 <
3574 <  DLINK_FOREACH(ptr, cluster_items.head)
3575 <  {
3576 <    const struct ConfItem *conf = ptr->data;
3577 <
3578 <    if (conf->flags & cluster_type)
3579 <      sendto_match_servs(source_p, conf->name, CAP_CLUSTER|capab,
3580 <                         "%s %s %s", command, conf->name, buffer);
3581 <  }
1567 >  return encr && !strcmp(encr, conf->passwd);
1568   }
1569  
1570   /*
# Line 3616 | Line 1602 | split_nuh(struct split_nuh_item *const i
1602  
1603    if (iptr->nickptr)
1604      strlcpy(iptr->nickptr, "*", iptr->nicksize);
1605 +
1606    if (iptr->userptr)
1607      strlcpy(iptr->userptr, "*", iptr->usersize);
1608 +
1609    if (iptr->hostptr)
1610      strlcpy(iptr->hostptr, "*", iptr->hostsize);
1611  
# Line 3625 | Line 1613 | split_nuh(struct split_nuh_item *const i
1613    {
1614      *p = '\0';
1615  
1616 <    if (iptr->nickptr && *iptr->nuhmask != '\0')
1616 >    if (iptr->nickptr && *iptr->nuhmask)
1617        strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
1618  
1619 <    if ((q = strchr(++p, '@'))) {
1619 >    if ((q = strchr(++p, '@')))
1620 >    {
1621        *q++ = '\0';
1622  
1623 <      if (*p != '\0')
1623 >      if (*p)
1624          strlcpy(iptr->userptr, p, iptr->usersize);
1625  
1626 <      if (*q != '\0')
1626 >      if (*q)
1627          strlcpy(iptr->hostptr, q, iptr->hostsize);
1628      }
1629      else
1630      {
1631 <      if (*p != '\0')
1631 >      if (*p)
1632          strlcpy(iptr->userptr, p, iptr->usersize);
1633      }
1634    }
# Line 3651 | Line 1640 | split_nuh(struct split_nuh_item *const i
1640        /* if found a @ */
1641        *p++ = '\0';
1642  
1643 <      if (*iptr->nuhmask != '\0')
1643 >      if (*iptr->nuhmask)
1644          strlcpy(iptr->userptr, iptr->nuhmask, iptr->usersize);
1645  
1646 <      if (*p != '\0')
1646 >      if (*p)
1647          strlcpy(iptr->hostptr, p, iptr->hostsize);
1648      }
1649      else
1650      {
1651 <      /* no @ found */
1651 >      /* No @ found */
1652        if (!iptr->nickptr || strpbrk(iptr->nuhmask, ".:"))
1653          strlcpy(iptr->hostptr, iptr->nuhmask, iptr->hostsize);
1654        else
# Line 3667 | Line 1656 | split_nuh(struct split_nuh_item *const i
1656      }
1657    }
1658   }
3670
3671 /*
3672 * flags_to_ascii
3673 *
3674 * inputs       - flags is a bitmask
3675 *              - pointer to table of ascii letters corresponding
3676 *                to each bit
3677 *              - flag 1 for convert ToLower if bit missing
3678 *                0 if ignore.
3679 * output       - none
3680 * side effects - string pointed to by p has bitmap chars written to it
3681 */
3682 static void
3683 flags_to_ascii(unsigned int flags, const unsigned int bit_table[], char *p,
3684               int lowerit)
3685 {
3686  unsigned int mask = 1;
3687  int i = 0;
3688
3689  for (mask = 1; (mask != 0) && (bit_table[i] != 0); mask <<= 1, i++)
3690  {
3691    if (flags & mask)
3692      *p++ = bit_table[i];
3693    else if (lowerit)
3694      *p++ = ToLower(bit_table[i]);
3695  }
3696  *p = '\0';
3697 }
3698
3699 /*
3700 * cidr_limit_reached
3701 *
3702 * inputs       - int flag allowing over_rule of limits
3703 *              - pointer to the ip to be added
3704 *              - pointer to the class
3705 * output       - non zero if limit reached
3706 *                0 if limit not reached
3707 * side effects -
3708 */
3709 static int
3710 cidr_limit_reached(int over_rule,
3711                   struct irc_ssaddr *ip, struct ClassItem *aclass)
3712 {
3713  dlink_node *ptr = NULL;
3714  struct CidrItem *cidr;
3715
3716  if (NumberPerCidr(aclass) <= 0)
3717    return 0;
3718
3719  if (ip->ss.ss_family == AF_INET)
3720  {
3721    if (CidrBitlenIPV4(aclass) <= 0)
3722      return 0;
3723
3724    DLINK_FOREACH(ptr, aclass->list_ipv4.head)
3725    {
3726      cidr = ptr->data;
3727      if (match_ipv4(ip, &cidr->mask, CidrBitlenIPV4(aclass)))
3728      {
3729        if (!over_rule && (cidr->number_on_this_cidr >= NumberPerCidr(aclass)))
3730          return -1;
3731        cidr->number_on_this_cidr++;
3732        return 0;
3733      }
3734    }
3735    cidr = MyMalloc(sizeof(struct CidrItem));
3736    cidr->number_on_this_cidr = 1;
3737    cidr->mask = *ip;
3738    mask_addr(&cidr->mask, CidrBitlenIPV4(aclass));
3739    dlinkAdd(cidr, &cidr->node, &aclass->list_ipv4);
3740  }
3741 #ifdef IPV6
3742  else if (CidrBitlenIPV6(aclass) > 0)
3743  {
3744    DLINK_FOREACH(ptr, aclass->list_ipv6.head)
3745    {
3746      cidr = ptr->data;
3747      if (match_ipv6(ip, &cidr->mask, CidrBitlenIPV6(aclass)))
3748      {
3749        if (!over_rule && (cidr->number_on_this_cidr >= NumberPerCidr(aclass)))
3750          return -1;
3751        cidr->number_on_this_cidr++;
3752        return 0;
3753      }
3754    }
3755    cidr = MyMalloc(sizeof(struct CidrItem));
3756    cidr->number_on_this_cidr = 1;
3757    cidr->mask = *ip;
3758    mask_addr(&cidr->mask, CidrBitlenIPV6(aclass));
3759    dlinkAdd(cidr, &cidr->node, &aclass->list_ipv6);
3760  }
3761 #endif
3762  return 0;
3763 }
3764
3765 /*
3766 * remove_from_cidr_check
3767 *
3768 * inputs       - pointer to the ip to be removed
3769 *              - pointer to the class
3770 * output       - NONE
3771 * side effects -
3772 */
3773 static void
3774 remove_from_cidr_check(struct irc_ssaddr *ip, struct ClassItem *aclass)
3775 {
3776  dlink_node *ptr = NULL;
3777  dlink_node *next_ptr = NULL;
3778  struct CidrItem *cidr;
3779
3780  if (NumberPerCidr(aclass) == 0)
3781    return;
3782
3783  if (ip->ss.ss_family == AF_INET)
3784  {
3785    if (CidrBitlenIPV4(aclass) <= 0)
3786      return;
3787
3788    DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv4.head)
3789    {
3790      cidr = ptr->data;
3791      if (match_ipv4(ip, &cidr->mask, CidrBitlenIPV4(aclass)))
3792      {
3793        cidr->number_on_this_cidr--;
3794        if (cidr->number_on_this_cidr == 0)
3795        {
3796          dlinkDelete(ptr, &aclass->list_ipv4);
3797          MyFree(cidr);
3798          return;
3799        }
3800      }
3801    }
3802  }
3803 #ifdef IPV6
3804  else if (CidrBitlenIPV6(aclass) > 0)
3805  {
3806    DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv6.head)
3807    {
3808      cidr = ptr->data;
3809      if (match_ipv6(ip, &cidr->mask, CidrBitlenIPV6(aclass)))
3810      {
3811        cidr->number_on_this_cidr--;
3812        if (cidr->number_on_this_cidr == 0)
3813        {
3814          dlinkDelete(ptr, &aclass->list_ipv6);
3815          MyFree(cidr);
3816          return;
3817        }
3818      }
3819    }
3820  }
3821 #endif
3822 }
3823
3824 static void
3825 rebuild_cidr_list(int aftype, struct ConfItem *oldcl, struct ClassItem *newcl,
3826                  dlink_list *old_list, dlink_list *new_list, int changed)
3827 {
3828  dlink_node *ptr;
3829  struct Client *client_p;
3830  struct ConfItem *conf;
3831  struct AccessItem *aconf;
3832
3833  if (!changed)
3834  {
3835    *new_list = *old_list;
3836    old_list->head = old_list->tail = NULL;
3837    old_list->length = 0;
3838    return;
3839  }
3840
3841  DLINK_FOREACH(ptr, local_client_list.head)
3842  {
3843    client_p = ptr->data;
3844    if (client_p->localClient->aftype != aftype)
3845      continue;
3846    if (dlink_list_length(&client_p->localClient->confs) == 0)
3847      continue;
3848
3849    conf = client_p->localClient->confs.tail->data;
3850    if (conf->type == CLIENT_TYPE)
3851    {
3852      aconf = map_to_conf(conf);
3853      if (aconf->class_ptr == oldcl)
3854        cidr_limit_reached(1, &client_p->localClient->ip, newcl);
3855    }
3856  }
3857 }
3858
3859 /*
3860 * rebuild_cidr_class
3861 *
3862 * inputs       - pointer to old conf
3863 *              - pointer to new_class
3864 * output       - none
3865 * side effects - rebuilds the class link list of cidr blocks
3866 */
3867 void
3868 rebuild_cidr_class(struct ConfItem *conf, struct ClassItem *new_class)
3869 {
3870  struct ClassItem *old_class = map_to_conf(conf);
3871
3872  if (NumberPerCidr(old_class) > 0 && NumberPerCidr(new_class) > 0)
3873  {
3874    if (CidrBitlenIPV4(old_class) > 0 && CidrBitlenIPV4(new_class) > 0)
3875      rebuild_cidr_list(AF_INET, conf, new_class,
3876                        &old_class->list_ipv4, &new_class->list_ipv4,
3877                        CidrBitlenIPV4(old_class) != CidrBitlenIPV4(new_class));
3878
3879 #ifdef IPV6
3880    if (CidrBitlenIPV6(old_class) > 0 && CidrBitlenIPV6(new_class) > 0)
3881      rebuild_cidr_list(AF_INET6, conf, new_class,
3882                        &old_class->list_ipv6, &new_class->list_ipv6,
3883                        CidrBitlenIPV6(old_class) != CidrBitlenIPV6(new_class));
3884 #endif
3885  }
3886
3887  destroy_cidr_class(old_class);
3888 }
3889
3890 /*
3891 * destroy_cidr_list
3892 *
3893 * inputs       - pointer to class dlink list of cidr blocks
3894 * output       - none
3895 * side effects - completely destroys the class link list of cidr blocks
3896 */
3897 static void
3898 destroy_cidr_list(dlink_list *list)
3899 {
3900  dlink_node *ptr = NULL, *next_ptr = NULL;
3901
3902  DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
3903  {
3904    dlinkDelete(ptr, list);
3905    MyFree(ptr->data);
3906  }
3907 }
3908
3909 /*
3910 * destroy_cidr_class
3911 *
3912 * inputs       - pointer to class
3913 * output       - none
3914 * side effects - completely destroys the class link list of cidr blocks
3915 */
3916 static void
3917 destroy_cidr_class(struct ClassItem *aclass)
3918 {
3919  destroy_cidr_list(&aclass->list_ipv4);
3920  destroy_cidr_list(&aclass->list_ipv6);
3921 }

Comparing:
ircd-hybrid-8/src/s_conf.c (property svn:keywords), Revision 1175 by michael, Sun Aug 14 10:47:48 2011 UTC vs.
ircd-hybrid/branches/8.2.x/src/conf.c (property svn:keywords), Revision 7725 by michael, Mon Sep 26 14:59:44 2016 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines