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

Comparing:
ircd-hybrid-8/src/conf.c (file contents), Revision 1353 by michael, Sun Apr 15 18:35:55 2012 UTC vs.
ircd-hybrid/trunk/src/conf.c (file contents), Revision 7217 by michael, Wed Feb 3 15:22:21 2016 UTC

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

Diff Legend

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