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/trunk/src/conf.c (file contents):
Revision 3347 by michael, Sun Apr 20 14:03:06 2014 UTC vs.
Revision 5583 by michael, Sun Feb 15 14:43:15 2015 UTC

# Line 1 | Line 1
1   /*
2   *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (c) 1997-2014 ircd-hybrid development team
4 > *  Copyright (c) 1997-2015 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 15 | 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  
# Line 28 | Line 28
28   #include "list.h"
29   #include "ircd_defs.h"
30   #include "conf.h"
31 + #include "conf_pseudo.h"
32   #include "server.h"
33   #include "resv.h"
34   #include "channel.h"
# Line 44 | Line 45
45   #include "log.h"
46   #include "send.h"
47   #include "memory.h"
47 – #include "mempool.h"
48   #include "res.h"
49   #include "userhost.h"
50   #include "user.h"
# Line 54 | Line 54
54   #include "conf_db.h"
55   #include "conf_class.h"
56   #include "motd.h"
57 + #include "ipcache.h"
58  
59  
59 – struct config_channel_entry ConfigChannel;
60 – struct config_server_hide ConfigServerHide;
61 – struct config_file_entry ConfigFileEntry;
62 – struct logging_entry ConfigLoggingEntry = { .use_logging = 1 };
63 – struct server_info ServerInfo;
64 – struct admin_info AdminInfo;
65 –
60   /* general conf items link list root, other than k lines etc. */
61 < dlink_list service_items = { NULL, NULL, 0 };
62 < dlink_list server_items  = { NULL, NULL, 0 };
63 < dlink_list cluster_items = { NULL, NULL, 0 };
64 < dlink_list oconf_items   = { NULL, NULL, 0 };
65 < dlink_list uconf_items   = { NULL, NULL, 0 };
66 < dlink_list xconf_items   = { NULL, NULL, 0 };
67 < dlink_list nresv_items   = { NULL, NULL, 0 };
68 < dlink_list cresv_items = { NULL, NULL, 0 };
61 > dlink_list service_items;
62 > dlink_list server_items;
63 > dlink_list cluster_items;
64 > dlink_list oconf_items;
65 > dlink_list uconf_items;
66 > dlink_list xconf_items;
67 > dlink_list nresv_items;
68 > dlink_list cresv_items;
69  
70   extern unsigned int lineno;
71   extern char linebuf[];
72   extern char conffilebuf[IRCD_BUFSIZE];
73   extern int yyparse(); /* defined in y.tab.c */
74  
81 – struct conf_parser_context conf_parser_ctx = { 0, 0, NULL };
82 –
83 – /* internally defined functions */
84 – static void read_conf(FILE *);
85 – static void clear_out_old_conf(void);
86 – static void expire_tklines(dlink_list *);
87 – static void garbage_collect_ip_entries(void);
88 – static int hash_ip(struct irc_ssaddr *);
89 – static int verify_access(struct Client *);
90 – static int attach_iline(struct Client *, struct MaskItem *);
91 – static struct ip_entry *find_or_add_ip(struct irc_ssaddr *);
92 – static dlink_list *map_to_list(enum maskitem_type);
93 – static int find_user_host(struct Client *, char *, char *, char *, unsigned int);
94 –
95 –
96 – /* usually, with hash tables, you use a prime number...
97 – * but in this case I am dealing with ip addresses,
98 – * not ascii strings.
99 – */
100 – #define IP_HASH_SIZE 0x1000
101 –
102 – struct ip_entry
103 – {
104 –  struct irc_ssaddr ip;
105 –  unsigned int count;
106 –  time_t last_attempt;
107 –  struct ip_entry *next;
108 – };
109 –
110 – static struct ip_entry *ip_hash_table[IP_HASH_SIZE];
111 – static mp_pool_t *ip_entry_pool = NULL;
112 – static int ip_entries_count = 0;
113 –
75  
76   /* conf_dns_callback()
77   *
# Line 123 | Line 84 | static int ip_entries_count = 0;
84   * if successful save hp in the conf item it was called with
85   */
86   static void
87 < conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name)
87 > conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name, size_t namelength)
88   {
89 <  struct MaskItem *conf = vptr;
89 >  struct MaskItem *const conf = vptr;
90  
91    conf->dns_pending = 0;
92  
# Line 144 | Line 105 | conf_dns_callback(void *vptr, const stru
105   static void
106   conf_dns_lookup(struct MaskItem *conf)
107   {
108 <  if (!conf->dns_pending)
108 >  if (conf->dns_pending)
109 >    return;
110 >
111 >  conf->dns_pending = 1;
112 >
113 >  if (conf->aftype == AF_INET)
114 >    gethost_byname_type(conf_dns_callback, conf, conf->host, T_A);
115 >  else
116 >    gethost_byname_type(conf_dns_callback, conf, conf->host, T_AAAA);
117 > }
118 >
119 > /* map_to_list()
120 > *
121 > * inputs       - ConfType conf
122 > * output       - pointer to dlink_list to use
123 > * side effects - none
124 > */
125 > static dlink_list *
126 > map_to_list(enum maskitem_type type)
127 > {
128 >  switch (type)
129    {
130 <    conf->dns_pending = 1;
131 <    gethost_byname(conf_dns_callback, conf, conf->host);
130 >    case CONF_XLINE:
131 >      return &xconf_items;
132 >      break;
133 >    case CONF_ULINE:
134 >      return &uconf_items;
135 >      break;
136 >    case CONF_NRESV:
137 >      return &nresv_items;
138 >      break;
139 >    case CONF_CRESV:
140 >      return &cresv_items;
141 >      break;
142 >    case CONF_OPER:
143 >      return &oconf_items;
144 >      break;
145 >    case CONF_SERVER:
146 >      return &server_items;
147 >      break;
148 >    case CONF_SERVICE:
149 >      return &service_items;
150 >      break;
151 >    case CONF_CLUSTER:
152 >      return &cluster_items;
153 >      break;
154 >    default:
155 >      return NULL;
156    }
157   }
158  
159   struct MaskItem *
160   conf_make(enum maskitem_type type)
161   {
162 <  struct MaskItem *conf = MyMalloc(sizeof(*conf));
162 >  struct MaskItem *const conf = MyCalloc(sizeof(*conf));
163    dlink_list *list = NULL;
164  
165    conf->type   = type;
# Line 169 | Line 174 | conf_make(enum maskitem_type type)
174   void
175   conf_free(struct MaskItem *conf)
176   {
177 <  dlink_node *ptr = NULL, *ptr_next = NULL;
177 >  dlink_node *node = NULL, *node_next = NULL;
178    dlink_list *list = NULL;
179  
180 <  if (conf->node.next)
181 <    if ((list = map_to_list(conf->type)))
177 <      dlinkDelete(&conf->node, list);
180 >  if ((list = map_to_list(conf->type)))
181 >    dlinkFindDelete(list, conf);
182  
183    MyFree(conf->name);
184  
# Line 191 | Line 195 | conf_free(struct MaskItem *conf)
195    MyFree(conf->spasswd);
196    MyFree(conf->reason);
197    MyFree(conf->certfp);
198 +  MyFree(conf->whois);
199    MyFree(conf->user);
200    MyFree(conf->host);
201   #ifdef HAVE_LIBCRYPTO
# Line 199 | Line 204 | conf_free(struct MaskItem *conf)
204    if (conf->rsa_public_key)
205      RSA_free(conf->rsa_public_key);
206   #endif
207 <  DLINK_FOREACH_SAFE(ptr, ptr_next, conf->hub_list.head)
207 >  DLINK_FOREACH_SAFE(node, node_next, conf->hub_list.head)
208    {
209 <    MyFree(ptr->data);
210 <    dlinkDelete(ptr, &conf->hub_list);
211 <    free_dlink_node(ptr);
209 >    MyFree(node->data);
210 >    dlinkDelete(node, &conf->hub_list);
211 >    free_dlink_node(node);
212    }
213  
214 <  DLINK_FOREACH_SAFE(ptr, ptr_next, conf->leaf_list.head)
214 >  DLINK_FOREACH_SAFE(node, node_next, conf->leaf_list.head)
215    {
216 <    MyFree(ptr->data);
217 <    dlinkDelete(ptr, &conf->leaf_list);
218 <    free_dlink_node(ptr);
216 >    MyFree(node->data);
217 >    dlinkDelete(node, &conf->leaf_list);
218 >    free_dlink_node(node);
219    }
220  
221 <  DLINK_FOREACH_SAFE(ptr, ptr_next, conf->exempt_list.head)
221 >  DLINK_FOREACH_SAFE(node, node_next, conf->exempt_list.head)
222    {
223 <    struct exempt *exptr = ptr->data;
223 >    struct exempt *exptr = node->data;
224  
225 <    dlinkDelete(ptr, &conf->exempt_list);
225 >    dlinkDelete(node, &conf->exempt_list);
226      MyFree(exptr->name);
227      MyFree(exptr->user);
228      MyFree(exptr->host);
# Line 227 | Line 232 | conf_free(struct MaskItem *conf)
232    MyFree(conf);
233   }
234  
235 < /* check_client()
235 > /* attach_iline()
236   *
237 < * inputs       - pointer to client
238 < * output       - 0 = Success
239 < *                NOT_AUTHORIZED    (-1) = Access denied (no I line match)
240 < *                IRCD_SOCKET_ERROR (-2) = Bad socket.
236 < *                I_LINE_FULL       (-3) = I-line is full
237 < *                TOO_MANY          (-4) = Too many connections from hostname
238 < *                BANNED_CLIENT     (-5) = K-lined
239 < * side effects - Ordinary client access check.
240 < *                Look for conf lines which have the same
241 < *                status as the flags passed.
237 > * inputs       - client pointer
238 > *              - conf pointer
239 > * output       -
240 > * side effects - do actual attach
241   */
242 < int
243 < check_client(struct Client *source_p)
242 > static int
243 > attach_iline(struct Client *client_p, struct MaskItem *conf)
244   {
245 <  int i;
246 <
247 <  if ((i = verify_access(source_p)))
248 <    ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
250 <         source_p->name, source_p->sockhost);
251 <
252 <  switch (i)
253 <  {
254 <    case TOO_MANY:
255 <      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
256 <                           "Too many on IP for %s (%s).",
257 <                           get_client_name(source_p, SHOW_IP),
258 <                           source_p->sockhost);
259 <      ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
260 <           get_client_name(source_p, SHOW_IP));
261 <      ++ServerStats.is_ref;
262 <      exit_client(source_p, "No more connections allowed on that IP");
263 <      break;
245 >  const struct ClassItem *const class = conf->class;
246 >  struct ip_entry *ip_found;
247 >  int a_limit_reached = 0;
248 >  unsigned int local = 0, global = 0, ident = 0;
249  
250 <    case I_LINE_FULL:
251 <      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
252 <                           "auth{} block is full for %s (%s).",
268 <                           get_client_name(source_p, SHOW_IP),
269 <                           source_p->sockhost);
270 <      ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
271 <           get_client_name(source_p, SHOW_IP));
272 <      ++ServerStats.is_ref;
273 <      exit_client(source_p, "No more connections allowed in your connection class");
274 <      break;
250 >  ip_found = ipcache_find_or_add_address(&client_p->connection->ip);
251 >  ip_found->count++;
252 >  AddFlag(client_p, FLAGS_IPHASH);
253  
254 <    case NOT_AUTHORIZED:
255 <      ++ServerStats.is_ref;
278 <      /* jdc - lists server name & port connections are on */
279 <      /*       a purely cosmetical change */
280 <      sendto_realops_flags(UMODE_UNAUTH, L_ALL, SEND_NOTICE,
281 <                           "Unauthorized client connection from %s [%s] on [%s/%u].",
282 <                           get_client_name(source_p, SHOW_IP),
283 <                           source_p->sockhost,
284 <                           source_p->localClient->listener->name,
285 <                           source_p->localClient->listener->port);
286 <      ilog(LOG_TYPE_IRCD,
287 <           "Unauthorized client connection from %s on [%s/%u].",
288 <           get_client_name(source_p, SHOW_IP),
289 <           source_p->localClient->listener->name,
290 <           source_p->localClient->listener->port);
254 >  count_user_host(client_p->username, client_p->host,
255 >                  &global, &local, &ident);
256  
257 <      exit_client(source_p, "You are not authorized to use this server");
258 <      break;
257 >  /* XXX blah. go down checking the various silly limits
258 >   * setting a_limit_reached if any limit is reached.
259 >   * - Dianora
260 >   */
261 >  if (class->max_total && class->ref_count >= class->max_total)
262 >    a_limit_reached = 1;
263 >  else if (class->max_perip && ip_found->count > class->max_perip)
264 >    a_limit_reached = 1;
265 >  else if (class->max_local && local >= class->max_local)
266 >    a_limit_reached = 1;
267 >  else if (class->max_global && global >= class->max_global)
268 >    a_limit_reached = 1;
269 >  else if (class->max_ident && ident >= class->max_ident &&
270 >           client_p->username[0] != '~')
271 >    a_limit_reached = 1;
272  
273 <   case BANNED_CLIENT:
274 <     exit_client(source_p, "Banned");
275 <     ++ServerStats.is_ref;
276 <     break;
273 >  if (a_limit_reached)
274 >  {
275 >    if (!IsConfExemptLimits(conf))
276 >      return TOO_MANY;   /* Already at maximum allowed */
277  
278 <   case 0:
279 <   default:
302 <     break;
278 >    sendto_one_notice(client_p, &me, ":*** Your connection class is full, "
279 >                      "but you have exceed_limit = yes;");
280    }
281  
282 <  return (i < 0 ? 0 : 1);
282 >  return attach_conf(client_p, conf);
283   }
284  
285   /* verify_access()
286   *
287 < * inputs       - pointer to client to verify
288 < * output       - 0 if success -'ve if not
289 < * side effect  - find the first (best) I line to attach.
287 > * inputs       - pointer to client to verify
288 > * output       - 0 if success -'ve if not
289 > * side effect  - find the first (best) I line to attach.
290   */
291   static int
292   verify_access(struct Client *client_p)
293   {
294    struct MaskItem *conf = NULL;
318 –  char non_ident[USERLEN + 1] = "~";
295  
296    if (IsGotId(client_p))
297    {
298      conf = find_address_conf(client_p->host, client_p->username,
299 <                             &client_p->localClient->ip,
300 <                             client_p->localClient->aftype,
301 <                             client_p->localClient->passwd);
299 >                             &client_p->connection->ip,
300 >                             client_p->connection->aftype,
301 >                             client_p->connection->password);
302    }
303    else
304    {
305 +    char non_ident[USERLEN + 1] = "~";
306 +
307      strlcpy(non_ident + 1, client_p->username, sizeof(non_ident) - 1);
308 <    conf = find_address_conf(client_p->host,non_ident,
309 <                             &client_p->localClient->ip,
310 <                             client_p->localClient->aftype,
311 <                             client_p->localClient->passwd);
308 >    conf = find_address_conf(client_p->host, non_ident,
309 >                             &client_p->connection->ip,
310 >                             client_p->connection->aftype,
311 >                             client_p->connection->password);
312    }
313  
314    if (conf)
# Line 345 | Line 323 | verify_access(struct Client *client_p)
323          return NOT_AUTHORIZED;
324        }
325  
348 –      if (IsConfDoIdentd(conf))
349 –        SetNeedId(client_p);
350 –
326        /* Thanks for spoof idea amm */
327        if (IsConfDoSpoofIp(conf))
328        {
329 <        if (!ConfigFileEntry.hide_spoof_ips && IsConfSpoofNotice(conf))
330 <          sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
356 <                               "%s spoofing: %s as %s",
329 >        if (IsConfSpoofNotice(conf))
330 >          sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, "%s spoofing: %s as %s",
331                                 client_p->name, client_p->host, conf->name);
332 +
333          strlcpy(client_p->host, conf->name, sizeof(client_p->host));
359 –        AddFlag(client_p, FLAGS_IP_SPOOFING | FLAGS_AUTH_SPOOF);
334        }
335  
336        return attach_iline(client_p, conf);
337      }
338 <    else if (IsConfKill(conf) || (ConfigFileEntry.glines && IsConfGline(conf)))
338 >    else if (IsConfKill(conf) || (ConfigGeneral.glines && IsConfGline(conf)))
339      {
340        if (IsConfGline(conf))
341          sendto_one_notice(client_p, &me, ":*** G-lined");
342 +
343        sendto_one_notice(client_p, &me, ":*** Banned: %s", conf->reason);
344        return BANNED_CLIENT;
345      }
# Line 373 | Line 348 | verify_access(struct Client *client_p)
348    return NOT_AUTHORIZED;
349   }
350  
351 < /* attach_iline()
377 < *
378 < * inputs       - client pointer
379 < *              - conf pointer
380 < * output       -
381 < * side effects - do actual attach
382 < */
383 < static int
384 < attach_iline(struct Client *client_p, struct MaskItem *conf)
385 < {
386 <  struct ClassItem *class = NULL;
387 <  struct ip_entry *ip_found;
388 <  int a_limit_reached = 0;
389 <  unsigned int local = 0, global = 0, ident = 0;
390 <
391 <  assert(conf->class);
392 <
393 <  ip_found = find_or_add_ip(&client_p->localClient->ip);
394 <  ip_found->count++;
395 <  SetIpHash(client_p);
396 <
397 <  class = conf->class;
398 <
399 <  count_user_host(client_p->username, client_p->host,
400 <                  &global, &local, &ident);
401 <
402 <  /* XXX blah. go down checking the various silly limits
403 <   * setting a_limit_reached if any limit is reached.
404 <   * - Dianora
405 <   */
406 <  if (class->max_total != 0 && class->ref_count >= class->max_total)
407 <    a_limit_reached = 1;
408 <  else if (class->max_perip != 0 && ip_found->count > class->max_perip)
409 <    a_limit_reached = 1;
410 <  else if (class->max_local != 0 && local >= class->max_local)
411 <    a_limit_reached = 1;
412 <  else if (class->max_global != 0 && global >= class->max_global)
413 <    a_limit_reached = 1;
414 <  else if (class->max_ident != 0 && ident >= class->max_ident &&
415 <           client_p->username[0] != '~')
416 <    a_limit_reached = 1;
417 <
418 <  if (a_limit_reached)
419 <  {
420 <    if (!IsConfExemptLimits(conf))
421 <      return TOO_MANY;   /* Already at maximum allowed */
422 <
423 <    sendto_one_notice(client_p, &me, ":*** Your connection class is full, "
424 <                      "but you have exceed_limit = yes;");
425 <  }
426 <
427 <  return attach_conf(client_p, conf);
428 < }
429 <
430 < /* init_ip_hash_table()
431 < *
432 < * inputs               - NONE
433 < * output               - NONE
434 < * side effects         - allocate memory for ip_entry(s)
435 < *                      - clear the ip hash table
436 < */
437 < void
438 < init_ip_hash_table(void)
439 < {
440 <  ip_entry_pool = mp_pool_new(sizeof(struct ip_entry), MP_CHUNK_SIZE_IP_ENTRY);
441 <  memset(ip_hash_table, 0, sizeof(ip_hash_table));
442 < }
443 <
444 < /* find_or_add_ip()
445 < *
446 < * inputs       - pointer to struct irc_ssaddr
447 < * output       - pointer to a struct ip_entry
448 < * side effects -
351 > /* check_client()
352   *
353 < * If the ip # was not found, a new struct ip_entry is created, and the ip
354 < * count set to 0.
353 > * inputs       - pointer to client
354 > * output       - 0 = Success
355 > *                NOT_AUTHORIZED    (-1) = Access denied (no I line match)
356 > *                IRCD_SOCKET_ERROR (-2) = Bad socket.
357 > *                I_LINE_FULL       (-3) = I-line is full
358 > *                TOO_MANY          (-4) = Too many connections from hostname
359 > *                BANNED_CLIENT     (-5) = K-lined
360 > * side effects - Ordinary client access check.
361 > *                Look for conf lines which have the same
362 > *                status as the flags passed.
363   */
364 < static struct ip_entry *
365 < find_or_add_ip(struct irc_ssaddr *ip_in)
364 > int
365 > check_client(struct Client *source_p)
366   {
367 <  struct ip_entry *ptr, *newptr;
457 <  int hash_index = hash_ip(ip_in), res;
458 <  struct sockaddr_in *v4 = (struct sockaddr_in *)ip_in, *ptr_v4;
459 < #ifdef IPV6
460 <  struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)ip_in, *ptr_v6;
461 < #endif
462 <
463 <  for (ptr = ip_hash_table[hash_index]; ptr; ptr = ptr->next)
464 <  {
465 < #ifdef IPV6
466 <    if (ptr->ip.ss.ss_family != ip_in->ss.ss_family)
467 <      continue;
468 <    if (ip_in->ss.ss_family == AF_INET6)
469 <    {
470 <      ptr_v6 = (struct sockaddr_in6 *)&ptr->ip;
471 <      res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr));
472 <    }
473 <    else
474 < #endif
475 <    {
476 <      ptr_v4 = (struct sockaddr_in *)&ptr->ip;
477 <      res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr));
478 <    }
479 <    if (res == 0)
480 <    {
481 <      /* Found entry already in hash, return it. */
482 <      return ptr;
483 <    }
484 <  }
485 <
486 <  if (ip_entries_count >= 2 * hard_fdlimit)
487 <    garbage_collect_ip_entries();
488 <
489 <  newptr = mp_pool_get(ip_entry_pool);
490 <  memset(newptr, 0, sizeof(*newptr));
491 <  ip_entries_count++;
492 <  memcpy(&newptr->ip, ip_in, sizeof(struct irc_ssaddr));
493 <
494 <  newptr->next = ip_hash_table[hash_index];
495 <  ip_hash_table[hash_index] = newptr;
496 <
497 <  return newptr;
498 < }
367 >  int i;
368  
369 < /* remove_one_ip()
370 < *
371 < * inputs        - unsigned long IP address value
503 < * output        - NONE
504 < * side effects  - The ip address given, is looked up in ip hash table
505 < *                 and number of ip#'s for that ip decremented.
506 < *                 If ip # count reaches 0 and has expired,
507 < *                 the struct ip_entry is returned to the ip_entry_heap
508 < */
509 < void
510 < remove_one_ip(struct irc_ssaddr *ip_in)
511 < {
512 <  struct ip_entry *ptr;
513 <  struct ip_entry *last_ptr = NULL;
514 <  int hash_index = hash_ip(ip_in), res;
515 <  struct sockaddr_in *v4 = (struct sockaddr_in *)ip_in, *ptr_v4;
516 < #ifdef IPV6
517 <  struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)ip_in, *ptr_v6;
518 < #endif
369 >  if ((i = verify_access(source_p)))
370 >    ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
371 >         source_p->name, source_p->sockhost);
372  
373 <  for (ptr = ip_hash_table[hash_index]; ptr; ptr = ptr->next)
373 >  switch (i)
374    {
375 < #ifdef IPV6
376 <    if (ptr->ip.ss.ss_family != ip_in->ss.ss_family)
377 <      continue;
378 <    if (ip_in->ss.ss_family == AF_INET6)
379 <    {
380 <      ptr_v6 = (struct sockaddr_in6 *)&ptr->ip;
381 <      res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr));
382 <    }
383 <    else
384 < #endif
532 <    {
533 <      ptr_v4 = (struct sockaddr_in *)&ptr->ip;
534 <      res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr));
535 <    }
536 <    if (res)
537 <      continue;
538 <    if (ptr->count > 0)
539 <      ptr->count--;
540 <    if (ptr->count == 0 &&
541 <        (CurrentTime-ptr->last_attempt) >= ConfigFileEntry.throttle_time)
542 <    {
543 <      if (last_ptr != NULL)
544 <        last_ptr->next = ptr->next;
545 <      else
546 <        ip_hash_table[hash_index] = ptr->next;
547 <
548 <      mp_pool_release(ptr);
549 <      ip_entries_count--;
550 <      return;
551 <    }
552 <    last_ptr = ptr;
553 <  }
554 < }
375 >    case TOO_MANY:
376 >      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
377 >                           "Too many on IP for %s (%s).",
378 >                           get_client_name(source_p, SHOW_IP),
379 >                           source_p->sockhost);
380 >      ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
381 >           get_client_name(source_p, SHOW_IP));
382 >      ++ServerStats.is_ref;
383 >      exit_client(source_p, "No more connections allowed on that IP");
384 >      break;
385  
386 < /* hash_ip()
387 < *
388 < * input        - pointer to an irc_inaddr
389 < * output       - integer value used as index into hash table
390 < * side effects - hopefully, none
391 < */
392 < static int
393 < hash_ip(struct irc_ssaddr *addr)
394 < {
395 <  if (addr->ss.ss_family == AF_INET)
566 <  {
567 <    struct sockaddr_in *v4 = (struct sockaddr_in *)addr;
568 <    int hash;
569 <    uint32_t ip;
386 >    case I_LINE_FULL:
387 >      sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
388 >                           "auth {} block is full for %s (%s).",
389 >                           get_client_name(source_p, SHOW_IP),
390 >                           source_p->sockhost);
391 >      ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
392 >           get_client_name(source_p, SHOW_IP));
393 >      ++ServerStats.is_ref;
394 >      exit_client(source_p, "No more connections allowed in your connection class");
395 >      break;
396  
397 <    ip   = ntohl(v4->sin_addr.s_addr);
398 <    hash = ((ip >> 12) + ip) & (IP_HASH_SIZE-1);
399 <    return hash;
400 <  }
401 < #ifdef IPV6
402 <  else
403 <  {
404 <    int hash;
405 <    struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr;
406 <    uint32_t *ip = (uint32_t *)&v6->sin6_addr.s6_addr;
407 <
408 <    hash  = ip[0] ^ ip[3];
409 <    hash ^= hash >> 16;
584 <    hash ^= hash >> 8;
585 <    hash  = hash & (IP_HASH_SIZE - 1);
586 <    return hash;
587 <  }
588 < #else
589 <  return 0;
590 < #endif
591 < }
397 >    case NOT_AUTHORIZED:
398 >      /* jdc - lists server name & port connections are on */
399 >      /*       a purely cosmetical change */
400 >      sendto_realops_flags(UMODE_UNAUTH, L_ALL, SEND_NOTICE,
401 >                           "Unauthorized client connection from %s [%s] on [%s/%u].",
402 >                           get_client_name(source_p, SHOW_IP),
403 >                           source_p->sockhost,
404 >                           source_p->connection->listener->name,
405 >                           source_p->connection->listener->port);
406 >      ilog(LOG_TYPE_IRCD, "Unauthorized client connection from %s on [%s/%u].",
407 >           get_client_name(source_p, SHOW_IP),
408 >           source_p->connection->listener->name,
409 >           source_p->connection->listener->port);
410  
411 < /* count_ip_hash()
412 < *
413 < * inputs        - pointer to counter of number of ips hashed
596 < *               - pointer to memory used for ip hash
597 < * output        - returned via pointers input
598 < * side effects  - NONE
599 < *
600 < * number of hashed ip #'s is counted up, plus the amount of memory
601 < * used in the hash.
602 < */
603 < void
604 < count_ip_hash(unsigned int *number_ips_stored, uint64_t *mem_ips_stored)
605 < {
606 <  struct ip_entry *ptr;
607 <  int i;
411 >      ++ServerStats.is_ref;
412 >      exit_client(source_p, "You are not authorized to use this server");
413 >      break;
414  
415 <  *number_ips_stored = 0;
416 <  *mem_ips_stored    = 0;
415 >    case BANNED_CLIENT:
416 >      ++ServerStats.is_ref;
417 >      exit_client(source_p, "Banned");
418 >      break;
419  
420 <  for (i = 0; i < IP_HASH_SIZE; i++)
421 <  {
422 <    for (ptr = ip_hash_table[i]; ptr; ptr = ptr->next)
615 <    {
616 <      *number_ips_stored += 1;
617 <      *mem_ips_stored += sizeof(struct ip_entry);
618 <    }
420 >    case 0:
421 >    default:
422 >      break;
423    }
620 – }
621 –
622 – /* garbage_collect_ip_entries()
623 – *
624 – * input        - NONE
625 – * output       - NONE
626 – * side effects - free up all ip entries with no connections
627 – */
628 – static void
629 – garbage_collect_ip_entries(void)
630 – {
631 –  struct ip_entry *ptr;
632 –  struct ip_entry *last_ptr;
633 –  struct ip_entry *next_ptr;
634 –  int i;
424  
425 <  for (i = 0; i < IP_HASH_SIZE; i++)
637 <  {
638 <    last_ptr = NULL;
639 <
640 <    for (ptr = ip_hash_table[i]; ptr; ptr = next_ptr)
641 <    {
642 <      next_ptr = ptr->next;
643 <
644 <      if (ptr->count == 0 &&
645 <          (CurrentTime - ptr->last_attempt) >= ConfigFileEntry.throttle_time)
646 <      {
647 <        if (last_ptr != NULL)
648 <          last_ptr->next = ptr->next;
649 <        else
650 <          ip_hash_table[i] = ptr->next;
651 <        mp_pool_release(ptr);
652 <        ip_entries_count--;
653 <      }
654 <      else
655 <        last_ptr = ptr;
656 <    }
657 <  }
425 >  return !(i < 0);
426   }
427  
428   /* detach_conf()
# Line 668 | Line 436 | garbage_collect_ip_entries(void)
436   void
437   detach_conf(struct Client *client_p, enum maskitem_type type)
438   {
439 <  dlink_node *ptr = NULL, *ptr_next = NULL;
439 >  dlink_node *node = NULL, *node_next = NULL;
440  
441 <  DLINK_FOREACH_SAFE(ptr, ptr_next, client_p->localClient->confs.head)
441 >  DLINK_FOREACH_SAFE(node, node_next, client_p->connection->confs.head)
442    {
443 <    struct MaskItem *conf = ptr->data;
443 >    struct MaskItem *conf = node->data;
444  
445      assert(conf->type & (CONF_CLIENT | CONF_OPER | CONF_SERVER));
446      assert(conf->ref_count > 0);
# Line 681 | Line 449 | detach_conf(struct Client *client_p, enu
449      if (!(conf->type & type))
450        continue;
451  
452 <    dlinkDelete(ptr, &client_p->localClient->confs);
453 <    free_dlink_node(ptr);
452 >    dlinkDelete(node, &client_p->connection->confs);
453 >    free_dlink_node(node);
454  
455      if (conf->type == CONF_CLIENT)
456 <      remove_from_cidr_check(&client_p->localClient->ip, conf->class);
456 >      remove_from_cidr_check(&client_p->connection->ip, conf->class);
457  
458      if (--conf->class->ref_count == 0 && conf->class->active == 0)
459      {
# Line 711 | Line 479 | detach_conf(struct Client *client_p, enu
479   int
480   attach_conf(struct Client *client_p, struct MaskItem *conf)
481   {
482 <  if (dlinkFind(&client_p->localClient->confs, conf))
482 >  if (dlinkFind(&client_p->connection->confs, conf))
483      return 1;
484  
485    if (conf->type == CONF_CLIENT)
486      if (cidr_limit_reached(IsConfExemptLimits(conf),
487 <                           &client_p->localClient->ip, conf->class))
487 >                           &client_p->connection->ip, conf->class))
488        return TOO_MANY;    /* Already at maximum allowed */
489  
490    conf->class->ref_count++;
491    conf->ref_count++;
492  
493 <  dlinkAdd(conf, make_dlink_node(), &client_p->localClient->confs);
493 >  dlinkAdd(conf, make_dlink_node(), &client_p->connection->confs);
494  
495    return 0;
496   }
# Line 739 | Line 507 | int
507   attach_connect_block(struct Client *client_p, const char *name,
508                       const char *host)
509   {
510 <  dlink_node *ptr;
743 <  struct MaskItem *conf = NULL;
510 >  dlink_node *node = NULL;
511  
512 <  assert(client_p != NULL);
746 <  assert(host != NULL);
512 >  assert(host);
513  
514 <  if (client_p == NULL || host == NULL)
749 <    return 0;
750 <
751 <  DLINK_FOREACH(ptr, server_items.head)
514 >  DLINK_FOREACH(node, server_items.head)
515    {
516 <    conf = ptr->data;
516 >    struct MaskItem *conf = node->data;
517  
518      if (match(conf->name, name) || match(conf->host, host))
519        continue;
# Line 774 | Line 537 | attach_connect_block(struct Client *clie
537   struct MaskItem *
538   find_conf_name(dlink_list *list, const char *name, enum maskitem_type type)
539   {
540 <  dlink_node *ptr;
778 <  struct MaskItem* conf;
540 >  dlink_node *node = NULL;
541  
542 <  DLINK_FOREACH(ptr, list->head)
542 >  DLINK_FOREACH(node, list->head)
543    {
544 <    conf = ptr->data;
544 >    struct MaskItem *conf = node->data;
545  
546      if (conf->type == type)
547      {
548 <      if (conf->name && (irccmp(conf->name, name) == 0 ||
549 <                         !match(conf->name, name)))
788 <      return conf;
548 >      if (conf->name && !irccmp(conf->name, name))
549 >        return conf;
550      }
551    }
552  
553    return NULL;
554   }
555  
795 – /* map_to_list()
796 – *
797 – * inputs       - ConfType conf
798 – * output       - pointer to dlink_list to use
799 – * side effects - none
800 – */
801 – static dlink_list *
802 – map_to_list(enum maskitem_type type)
803 – {
804 –  switch(type)
805 –  {
806 –  case CONF_XLINE:
807 –    return(&xconf_items);
808 –    break;
809 –  case CONF_ULINE:
810 –    return(&uconf_items);
811 –    break;
812 –  case CONF_NRESV:
813 –    return(&nresv_items);
814 –    break;
815 –  case CONF_CRESV:
816 –    return(&cresv_items);
817 –  case CONF_OPER:
818 –    return(&oconf_items);
819 –    break;
820 –  case CONF_SERVER:
821 –    return(&server_items);
822 –    break;
823 –  case CONF_SERVICE:
824 –    return(&service_items);
825 –    break;
826 –  case CONF_CLUSTER:
827 –    return(&cluster_items);
828 –    break;
829 –  default:
830 –    return NULL;
831 –  }
832 – }
833 –
556   /* find_matching_name_conf()
557   *
558   * inputs       - type of link list to look in
# Line 845 | Line 567 | struct MaskItem *
567   find_matching_name_conf(enum maskitem_type type, const char *name, const char *user,
568                          const char *host, unsigned int flags)
569   {
570 <  dlink_node *ptr=NULL;
571 <  struct MaskItem *conf=NULL;
572 <  dlink_list *list_p = map_to_list(type);
570 >  dlink_node *node = NULL;
571 >  dlink_list *list = map_to_list(type);
572 >  struct MaskItem *conf = NULL;
573  
574    switch (type)
575    {
576    case CONF_SERVICE:
577 <    DLINK_FOREACH(ptr, list_p->head)
577 >    DLINK_FOREACH(node, list->head)
578      {
579 <      conf = ptr->data;
579 >      conf = node->data;
580  
581        if (EmptyString(conf->name))
582          continue;
583 <      if ((name != NULL) && !irccmp(name, conf->name))
583 >      if (name && !irccmp(name, conf->name))
584          return conf;
585      }
586      break;
# Line 867 | Line 589 | find_matching_name_conf(enum maskitem_ty
589    case CONF_ULINE:
590    case CONF_NRESV:
591    case CONF_CRESV:
592 <    DLINK_FOREACH(ptr, list_p->head)
592 >    DLINK_FOREACH(node, list->head)
593      {
594 <      conf = ptr->data;
594 >      conf = node->data;
595  
596        if (EmptyString(conf->name))
597          continue;
598 <      if ((name != NULL) && !match(conf->name, name))
598 >      if (name && !match(conf->name, name))
599        {
600          if ((user == NULL && (host == NULL)))
601            return conf;
# Line 888 | Line 610 | find_matching_name_conf(enum maskitem_ty
610        break;
611  
612    case CONF_SERVER:
613 <    DLINK_FOREACH(ptr, list_p->head)
613 >    DLINK_FOREACH(node, list->head)
614      {
615 <      conf = ptr->data;
615 >      conf = node->data;
616  
617 <      if ((name != NULL) && !match(name, conf->name))
617 >      if (name && !match(name, conf->name))
618          return conf;
619 <      else if ((host != NULL) && !match(host, conf->host))
619 >      if (host && !match(host, conf->host))
620          return conf;
621      }
622      break;
# Line 918 | Line 640 | struct MaskItem *
640   find_exact_name_conf(enum maskitem_type type, const struct Client *who, const char *name,
641                       const char *user, const char *host)
642   {
643 <  dlink_node *ptr = NULL;
644 <  struct MaskItem *conf;
645 <  dlink_list *list_p = map_to_list(type);
643 >  dlink_node *node = NULL;
644 >  dlink_list *list = map_to_list(type);
645 >  struct MaskItem *conf = NULL;
646  
647    switch(type)
648    {
# Line 929 | Line 651 | find_exact_name_conf(enum maskitem_type
651    case CONF_NRESV:
652    case CONF_CRESV:
653  
654 <    DLINK_FOREACH(ptr, list_p->head)
654 >    DLINK_FOREACH(node, list->head)
655      {
656 <      conf = ptr->data;
656 >      conf = node->data;
657  
658        if (EmptyString(conf->name))
659          continue;
# Line 949 | Line 671 | find_exact_name_conf(enum maskitem_type
671      break;
672  
673    case CONF_OPER:
674 <    DLINK_FOREACH(ptr, list_p->head)
674 >    DLINK_FOREACH(node, list->head)
675      {
676 <      conf = ptr->data;
676 >      conf = node->data;
677  
678        if (EmptyString(conf->name))
679          continue;
# Line 972 | Line 694 | find_exact_name_conf(enum maskitem_type
694                    return conf;
695                break;
696              case HM_IPV4:
697 <              if (who->localClient->aftype == AF_INET)
698 <                if (match_ipv4(&who->localClient->ip, &conf->addr, conf->bits))
697 >              if (who->connection->aftype == AF_INET)
698 >                if (match_ipv4(&who->connection->ip, &conf->addr, conf->bits))
699                    if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
700                      return conf;
701                break;
980 – #ifdef IPV6
702              case HM_IPV6:
703 <              if (who->localClient->aftype == AF_INET6)
704 <                if (match_ipv6(&who->localClient->ip, &conf->addr, conf->bits))
703 >              if (who->connection->aftype == AF_INET6)
704 >                if (match_ipv6(&who->connection->ip, &conf->addr, conf->bits))
705                    if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
706                      return conf;
707                break;
987 – #endif
708              default:
709                assert(0);
710            }
# Line 995 | Line 715 | find_exact_name_conf(enum maskitem_type
715      break;
716  
717    case CONF_SERVER:
718 <    DLINK_FOREACH(ptr, list_p->head)
718 >    DLINK_FOREACH(node, list->head)
719      {
720 <      conf = ptr->data;
720 >      conf = node->data;
721  
722        if (EmptyString(conf->name))
723          continue;
# Line 1022 | Line 742 | find_exact_name_conf(enum maskitem_type
742    return NULL;
743   }
744  
1025 – /* rehash()
1026 – *
1027 – * Actual REHASH service routine. Called with sig == 0 if it has been called
1028 – * as a result of an operator issuing this command, else assume it has been
1029 – * called as a result of the server receiving a HUP signal.
1030 – */
1031 – int
1032 – rehash(int sig)
1033 – {
1034 –  if (sig)
1035 –    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1036 –                         "Got signal SIGHUP, reloading configuration file(s)");
1037 –
1038 –  restart_resolver();
1039 –
1040 –  /* don't close listeners until we know we can go ahead with the rehash */
1041 –
1042 –  /* Check to see if we magically got(or lost) IPv6 support */
1043 –  check_can_use_v6();
1044 –
1045 –  read_conf_files(0);
1046 –
1047 –  if (ServerInfo.description)
1048 –    strlcpy(me.info, ServerInfo.description, sizeof(me.info));
1049 –
1050 –  load_conf_modules();
1051 –
1052 –  rehashed_klines = 1;
1053 –
1054 –  return 0;
1055 – }
1056 –
745   /* set_default_conf()
746   *
747   * inputs       - NONE
# Line 1072 | Line 760 | set_default_conf(void)
760    assert(class_default == class_get_list()->tail->data);
761  
762   #ifdef HAVE_LIBCRYPTO
763 <  ServerInfo.rsa_private_key = NULL;
764 <  ServerInfo.rsa_private_key_file = NULL;
763 > #if OPENSSL_VERSION_NUMBER >= 0x009080FFL && !defined(OPENSSL_NO_ECDH)
764 >  {
765 >    EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
766 >
767 >    if (key)
768 >    {
769 >      SSL_CTX_set_tmp_ecdh(ConfigServerInfo.server_ctx, key);
770 >      EC_KEY_free(key);
771 >    }
772 >  }
773 >
774 >  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE);
775   #endif
776  
777 <  /* ServerInfo.name is not rehashable */
778 <  /* ServerInfo.name = ServerInfo.name; */
779 <  ServerInfo.description = NULL;
780 <  ServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
781 <  ServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
782 <
783 <  memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip));
784 <  ServerInfo.specific_ipv4_vhost = 0;
785 <  memset(&ServerInfo.ip6, 0, sizeof(ServerInfo.ip6));
786 <  ServerInfo.specific_ipv6_vhost = 0;
787 <
788 <  ServerInfo.max_clients = MAXCLIENTS_MAX;
789 <  ServerInfo.max_nick_length = 9;
790 <  ServerInfo.max_topic_length = 80;
791 <
792 <  ServerInfo.hub = 0;
793 <  ServerInfo.dns_host.sin_addr.s_addr = 0;
794 <  ServerInfo.dns_host.sin_port = 0;
795 <  AdminInfo.name = NULL;
796 <  AdminInfo.email = NULL;
797 <  AdminInfo.description = NULL;
777 >  SSL_CTX_set_cipher_list(ConfigServerInfo.server_ctx, "EECDH+HIGH:EDH+HIGH:HIGH:!aNULL");
778 >  ConfigServerInfo.message_digest_algorithm = EVP_sha256();
779 >  ConfigServerInfo.rsa_private_key = NULL;
780 >  ConfigServerInfo.rsa_private_key_file = NULL;
781 > #endif
782 >
783 >  /* ConfigServerInfo.name is not rehashable */
784 >  /* ConfigServerInfo.name = ConfigServerInfo.name; */
785 >  ConfigServerInfo.description = NULL;
786 >  ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
787 >  ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
788 >
789 >  memset(&ConfigServerInfo.ip, 0, sizeof(ConfigServerInfo.ip));
790 >  ConfigServerInfo.specific_ipv4_vhost = 0;
791 >  memset(&ConfigServerInfo.ip6, 0, sizeof(ConfigServerInfo.ip6));
792 >  ConfigServerInfo.specific_ipv6_vhost = 0;
793 >
794 >  ConfigServerInfo.default_max_clients = MAXCLIENTS_MAX;
795 >  ConfigServerInfo.max_nick_length = 9;
796 >  ConfigServerInfo.max_topic_length = 80;
797 >  ConfigServerInfo.hub = 0;
798 >
799 >  ConfigAdminInfo.name = NULL;
800 >  ConfigAdminInfo.email = NULL;
801 >  ConfigAdminInfo.description = NULL;
802  
803    log_del_all();
804  
805 <  ConfigLoggingEntry.use_logging = 1;
805 >  ConfigLog.use_logging = 1;
806  
807    ConfigChannel.disable_fake_channels = 0;
808 <  ConfigChannel.knock_delay = 300;
808 >  ConfigChannel.invite_client_count = 10;
809 >  ConfigChannel.invite_client_time = 300;
810 >  ConfigChannel.knock_client_count = 1;
811 >  ConfigChannel.knock_client_time = 300;
812    ConfigChannel.knock_delay_channel = 60;
813 <  ConfigChannel.max_chans_per_user = 25;
1109 <  ConfigChannel.max_chans_per_oper = 50;
813 >  ConfigChannel.max_channels = 25;
814    ConfigChannel.max_bans = 25;
815 +  ConfigChannel.default_join_flood_count = 18;
816 +  ConfigChannel.default_join_flood_time = 6;
817    ConfigChannel.default_split_user_count = 0;
818    ConfigChannel.default_split_server_count = 0;
819    ConfigChannel.no_join_on_split = 0;
# Line 1122 | Line 828 | set_default_conf(void)
828    ConfigServerHide.hide_server_ips = 0;
829    ConfigServerHide.disable_remote_commands = 0;
830  
831 <  ConfigFileEntry.service_name = xstrdup(SERVICE_NAME_DEFAULT);
832 <  ConfigFileEntry.max_watch = WATCHSIZE_DEFAULT;
833 <  ConfigFileEntry.cycle_on_host_change = 1;
834 <  ConfigFileEntry.glines = 0;
835 <  ConfigFileEntry.gline_time = 12 * 3600;
836 <  ConfigFileEntry.gline_request_time = GLINE_REQUEST_EXPIRE_DEFAULT;
837 <  ConfigFileEntry.gline_min_cidr = 16;
838 <  ConfigFileEntry.gline_min_cidr6 = 48;
839 <  ConfigFileEntry.invisible_on_connect = 1;
840 <  ConfigFileEntry.tkline_expire_notices = 1;
841 <  ConfigFileEntry.hide_spoof_ips = 1;
842 <  ConfigFileEntry.ignore_bogus_ts = 0;
843 <  ConfigFileEntry.disable_auth = 0;
844 <  ConfigFileEntry.kill_chase_time_limit = 90;
845 <  ConfigFileEntry.default_floodcount = 8;
846 <  ConfigFileEntry.failed_oper_notice = 1;
847 <  ConfigFileEntry.dots_in_ident = 0;
848 <  ConfigFileEntry.min_nonwildcard = 4;
849 <  ConfigFileEntry.min_nonwildcard_simple = 3;
850 <  ConfigFileEntry.max_accept = 20;
851 <  ConfigFileEntry.anti_nick_flood = 0;
852 <  ConfigFileEntry.max_nick_time = 20;
853 <  ConfigFileEntry.max_nick_changes = 5;
854 <  ConfigFileEntry.anti_spam_exit_message_time = 0;
855 <  ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
856 <  ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
857 <  ConfigFileEntry.warn_no_nline = 1;
858 <  ConfigFileEntry.stats_o_oper_only = 0;
859 <  ConfigFileEntry.stats_k_oper_only = 1;  /* masked */
860 <  ConfigFileEntry.stats_i_oper_only = 1;  /* masked */
861 <  ConfigFileEntry.stats_P_oper_only = 0;
862 <  ConfigFileEntry.stats_u_oper_only = 0;
863 <  ConfigFileEntry.caller_id_wait = 60;
864 <  ConfigFileEntry.opers_bypass_callerid = 0;
865 <  ConfigFileEntry.pace_wait = 10;
866 <  ConfigFileEntry.pace_wait_simple = 1;
867 <  ConfigFileEntry.short_motd = 0;
868 <  ConfigFileEntry.ping_cookie = 0;
869 <  ConfigFileEntry.no_oper_flood = 0;
870 <  ConfigFileEntry.true_no_oper_flood = 0;
871 <  ConfigFileEntry.oper_pass_resv = 1;
872 <  ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT;
873 <  ConfigFileEntry.oper_only_umodes = UMODE_DEBUG;
874 <  ConfigFileEntry.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE |
875 <    UMODE_OPERWALL | UMODE_WALLOP;
876 <  ConfigFileEntry.use_egd = 0;
877 <  ConfigFileEntry.egdpool_path = NULL;
878 <  ConfigFileEntry.throttle_time = 10;
831 >  ConfigGeneral.away_count = 2;
832 >  ConfigGeneral.away_time = 10;
833 >  ConfigGeneral.max_watch = WATCHSIZE_DEFAULT;
834 >  ConfigGeneral.cycle_on_host_change = 1;
835 >  ConfigGeneral.glines = 0;
836 >  ConfigGeneral.gline_time = 12 * 3600;
837 >  ConfigGeneral.gline_request_time = GLINE_REQUEST_EXPIRE_DEFAULT;
838 >  ConfigGeneral.gline_min_cidr = 16;
839 >  ConfigGeneral.gline_min_cidr6 = 48;
840 >  ConfigGeneral.invisible_on_connect = 1;
841 >  ConfigGeneral.tkline_expire_notices = 1;
842 >  ConfigGeneral.ignore_bogus_ts = 0;
843 >  ConfigGeneral.disable_auth = 0;
844 >  ConfigGeneral.kill_chase_time_limit = 90;
845 >  ConfigGeneral.default_floodcount = 8;
846 >  ConfigGeneral.failed_oper_notice = 1;
847 >  ConfigGeneral.dots_in_ident = 0;
848 >  ConfigGeneral.min_nonwildcard = 4;
849 >  ConfigGeneral.min_nonwildcard_simple = 3;
850 >  ConfigGeneral.max_accept = 20;
851 >  ConfigGeneral.anti_nick_flood = 0;
852 >  ConfigGeneral.max_nick_time = 20;
853 >  ConfigGeneral.max_nick_changes = 5;
854 >  ConfigGeneral.anti_spam_exit_message_time = 0;
855 >  ConfigGeneral.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
856 >  ConfigGeneral.ts_max_delta = TS_MAX_DELTA_DEFAULT;
857 >  ConfigGeneral.warn_no_connect_block = 1;
858 >  ConfigGeneral.stats_e_disabled = 0;
859 >  ConfigGeneral.stats_i_oper_only = 1;  /* 1 = masked */
860 >  ConfigGeneral.stats_k_oper_only = 1;  /* 1 = masked */
861 >  ConfigGeneral.stats_o_oper_only = 1;
862 >  ConfigGeneral.stats_m_oper_only = 1;
863 >  ConfigGeneral.stats_P_oper_only = 0;
864 >  ConfigGeneral.stats_u_oper_only = 0;
865 >  ConfigGeneral.caller_id_wait = 60;
866 >  ConfigGeneral.opers_bypass_callerid = 0;
867 >  ConfigGeneral.pace_wait = 10;
868 >  ConfigGeneral.pace_wait_simple = 1;
869 >  ConfigGeneral.short_motd = 0;
870 >  ConfigGeneral.ping_cookie = 0;
871 >  ConfigGeneral.no_oper_flood = 0;
872 >  ConfigGeneral.oper_pass_resv = 1;
873 >  ConfigGeneral.max_targets = MAX_TARGETS_DEFAULT;
874 >  ConfigGeneral.oper_only_umodes = UMODE_DEBUG | UMODE_LOCOPS | UMODE_HIDDEN | UMODE_FARCONNECT |
875 >                                   UMODE_UNAUTH | UMODE_EXTERNAL | UMODE_BOTS | UMODE_NCHANGE |
876 >                                   UMODE_SPY | UMODE_FULL | UMODE_SKILL | UMODE_REJ | UMODE_CCONN;
877 >  ConfigGeneral.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE | UMODE_WALLOP;
878 >  ConfigGeneral.throttle_count = 1;
879 >  ConfigGeneral.throttle_time = 1;
880   }
881  
882   static void
883   validate_conf(void)
884   {
885 <  if (ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN)
886 <    ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
1180 <
1181 <  if (ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN)
1182 <    ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
885 >  if (ConfigGeneral.ts_warn_delta < TS_WARN_DELTA_MIN)
886 >    ConfigGeneral.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
887  
888 <  if (ServerInfo.network_name == NULL)
889 <    ServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
888 >  if (ConfigGeneral.ts_max_delta < TS_MAX_DELTA_MIN)
889 >    ConfigGeneral.ts_max_delta = TS_MAX_DELTA_DEFAULT;
890  
891 <  if (ServerInfo.network_desc == NULL)
892 <    ServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
891 >  if (EmptyString(ConfigServerInfo.network_name))
892 >    ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
893  
894 <  if (ConfigFileEntry.service_name == NULL)
895 <    ConfigFileEntry.service_name = xstrdup(SERVICE_NAME_DEFAULT);
894 >  if (EmptyString(ConfigServerInfo.network_desc))
895 >    ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
896  
897 <  ConfigFileEntry.max_watch = IRCD_MAX(ConfigFileEntry.max_watch, WATCHSIZE_MIN);
897 >  ConfigGeneral.max_watch = IRCD_MAX(ConfigGeneral.max_watch, WATCHSIZE_MIN);
898   }
899  
900   /* read_conf()
# Line 1204 | Line 908 | read_conf(FILE *file)
908   {
909    lineno = 0;
910  
911 <  set_default_conf(); /* Set default values prior to conf parsing */
911 >  set_default_conf();  /* Set default values prior to conf parsing */
912    conf_parser_ctx.pass = 1;
913 <  yyparse();          /* pick up the classes first */
913 >  yyparse();  /* Pick up the classes first */
914  
915    rewind(file);
916  
917    conf_parser_ctx.pass = 2;
918 <  yyparse();          /* Load the values from the conf */
919 <  validate_conf();    /* Check to make sure some values are still okay. */
920 <                      /* Some global values are also loaded here. */
921 <  class_delete_marked();      /* Make sure classes are valid */
918 >  yyparse();  /* Load the values from the conf */
919 >  validate_conf();  /* Check to make sure some values are still okay. */
920 >                    /* Some global values are also loaded here. */
921 >  class_delete_marked();  /* Delete unused classes that are marked for deletion */
922 > }
923 >
924 > /* conf_rehash()
925 > *
926 > * Actual REHASH service routine. Called with sig == 0 if it has been called
927 > * as a result of an operator issuing this command, else assume it has been
928 > * called as a result of the server receiving a HUP signal.
929 > */
930 > int
931 > conf_rehash(int sig)
932 > {
933 >  if (sig)
934 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
935 >                         "Got signal SIGHUP, reloading configuration file(s)");
936 >
937 >  restart_resolver();
938 >
939 >  /* don't close listeners until we know we can go ahead with the rehash */
940 >
941 >  read_conf_files(0);
942 >
943 >  load_conf_modules();
944 >  check_conf_klines();
945 >
946 >  return 0;
947   }
948  
949   /* lookup_confhost()
# Line 1227 | Line 956 | lookup_confhost(struct MaskItem *conf)
956   {
957    struct addrinfo hints, *res;
958  
959 <  /* Do name lookup now on hostnames given and store the
959 >  /*
960 >   * Do name lookup now on hostnames given and store the
961     * ip numbers in conf structure.
962     */
963    memset(&hints, 0, sizeof(hints));
# Line 1263 | Line 993 | lookup_confhost(struct MaskItem *conf)
993   int
994   conf_connect_allowed(struct irc_ssaddr *addr, int aftype)
995   {
996 <  struct ip_entry *ip_found;
997 <  struct MaskItem *conf = find_dline_conf(addr, aftype);
996 >  struct ip_entry *ip_found = NULL;
997 >  struct MaskItem *const conf = find_dline_conf(addr, aftype);
998  
999    /* DLINE exempt also gets you out of static limits/pacing... */
1000    if (conf && (conf->type == CONF_EXEMPT))
# Line 1273 | Line 1003 | conf_connect_allowed(struct irc_ssaddr *
1003    if (conf)
1004      return BANNED_CLIENT;
1005  
1006 <  ip_found = find_or_add_ip(addr);
1006 >  ip_found = ipcache_find_or_add_address(addr);
1007  
1008 <  if ((CurrentTime - ip_found->last_attempt) <
1279 <      ConfigFileEntry.throttle_time)
1008 >  if ((CurrentTime - ip_found->last_attempt) < ConfigGeneral.throttle_time)
1009    {
1010 <    ip_found->last_attempt = CurrentTime;
1011 <    return TOO_FAST;
1010 >    if (ip_found->connection_count >= ConfigGeneral.throttle_count)
1011 >      return TOO_FAST;
1012 >
1013 >    ++ip_found->connection_count;
1014    }
1015 +  else
1016 +    ip_found->connection_count = 1;
1017  
1018    ip_found->last_attempt = CurrentTime;
1019    return 0;
1020   }
1021  
1289 – /* cleanup_tklines()
1290 – *
1291 – * inputs       - NONE
1292 – * output       - NONE
1293 – * side effects - call function to expire temporary k/d lines
1294 – *                This is an event started off in ircd.c
1295 – */
1296 – void
1297 – cleanup_tklines(void *notused)
1298 – {
1299 –  hostmask_expire_temporary();
1300 –  expire_tklines(&xconf_items);
1301 –  expire_tklines(&nresv_items);
1302 –  expire_tklines(&cresv_items);
1303 – }
1304 –
1022   /* expire_tklines()
1023   *
1024   * inputs       - tkline list pointer
# Line 1309 | Line 1026 | cleanup_tklines(void *notused)
1026   * side effects - expire tklines
1027   */
1028   static void
1029 < expire_tklines(dlink_list *tklist)
1029 > expire_tklines(dlink_list *list)
1030   {
1031 <  dlink_node *ptr = NULL, *ptr_next = NULL;
1315 <  struct MaskItem *conf = NULL;
1031 >  dlink_node *node = NULL, *node_next = NULL;
1032  
1033 <  DLINK_FOREACH_SAFE(ptr, ptr_next, tklist->head)
1033 >  DLINK_FOREACH_SAFE(node, node_next, list->head)
1034    {
1035 <    conf = ptr->data;
1035 >    struct MaskItem *conf = node->data;
1036  
1037      if (!conf->until || conf->until > CurrentTime)
1038        continue;
1039  
1040      if (conf->type == CONF_XLINE)
1041      {
1042 <      if (ConfigFileEntry.tkline_expire_notices)
1042 >      if (ConfigGeneral.tkline_expire_notices)
1043          sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1044 <                               "Temporary X-line for [%s] expired", conf->name);
1044 >                             "Temporary X-line for [%s] expired", conf->name);
1045        conf_free(conf);
1046      }
1047      else if (conf->type == CONF_NRESV || conf->type == CONF_CRESV)
1048      {
1049 <      if (ConfigFileEntry.tkline_expire_notices)
1049 >      if (ConfigGeneral.tkline_expire_notices)
1050          sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1051 <                               "Temporary RESV for [%s] expired", conf->name);
1051 >                             "Temporary RESV for [%s] expired", conf->name);
1052        conf_free(conf);
1053      }
1054    }
1055   }
1056  
1057 + /* cleanup_tklines()
1058 + *
1059 + * inputs       - NONE
1060 + * output       - NONE
1061 + * side effects - call function to expire temporary k/d lines
1062 + *                This is an event started off in ircd.c
1063 + */
1064 + void
1065 + cleanup_tklines(void *unused)
1066 + {
1067 +  hostmask_expire_temporary();
1068 +  expire_tklines(&xconf_items);
1069 +  expire_tklines(&nresv_items);
1070 +  expire_tklines(&cresv_items);
1071 + }
1072 +
1073   /* oper_privs_as_string()
1074   *
1075   * inputs        - pointer to client_p
# Line 1354 | Line 1086 | static const struct oper_privs
1086    { OPER_FLAG_DIE,            'D' },
1087    { OPER_FLAG_GLINE,          'G' },
1088    { OPER_FLAG_REHASH,         'H' },
1089 <  { OPER_FLAG_K,              'K' },
1358 <  { OPER_FLAG_OPERWALL,       'L' },
1089 >  { OPER_FLAG_KLINE,          'K' },
1090    { OPER_FLAG_KILL,           'N' },
1091    { OPER_FLAG_KILL_REMOTE,    'O' },
1092    { OPER_FLAG_CONNECT,        'P' },
# Line 1387 | Line 1118 | oper_privs_as_string(const unsigned int
1118   }
1119  
1120   /*
1121 < * Input: A client to find the active oper{} name for.
1121 > * Input: A client to find the active operator {} name for.
1122   * Output: The nick!user@host{oper} of the oper.
1123   *         "oper" is server name for remote opers
1124   * Side effects: None.
# Line 1395 | Line 1126 | oper_privs_as_string(const unsigned int
1126   const char *
1127   get_oper_name(const struct Client *client_p)
1128   {
1129 <  const dlink_node *cnode = NULL;
1130 <  /* +5 for !,@,{,} and null */
1131 <  static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5];
1129 >  static char buffer[IRCD_BUFSIZE];
1130 >
1131 >  if (IsServer(client_p))
1132 >    return client_p->name;
1133  
1134    if (MyConnect(client_p))
1135    {
1136 <    if ((cnode = client_p->localClient->confs.head))
1136 >    const dlink_node *const node = client_p->connection->confs.head;
1137 >
1138 >    if (node)
1139      {
1140 <      const struct MaskItem *conf = cnode->data;
1140 >      const struct MaskItem *const conf = node->data;
1141  
1142 <      if (IsConfOperator(conf))
1142 >      if (conf->type == CONF_OPER)
1143        {
1144          snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1145                   client_p->username, client_p->host, conf->name);
# Line 1413 | Line 1147 | get_oper_name(const struct Client *clien
1147        }
1148      }
1149  
1150 <    /* Probably should assert here for now. If there is an oper out there
1151 <     * with no oper{} conf attached, it would be good for us to know...
1150 >    /*
1151 >     * Probably should assert here for now. If there is an oper out there
1152 >     * with no operator {} conf attached, it would be good for us to know...
1153       */
1154 <    assert(0); /* Oper without oper conf! */
1154 >    assert(0);  /* Oper without oper conf! */
1155    }
1156  
1157    snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
# Line 1424 | Line 1159 | get_oper_name(const struct Client *clien
1159    return buffer;
1160   }
1161  
1427 – /* read_conf_files()
1428 – *
1429 – * inputs       - cold start YES or NO
1430 – * output       - none
1431 – * side effects - read all conf files needed, ircd.conf kline.conf etc.
1432 – */
1433 – void
1434 – read_conf_files(int cold)
1435 – {
1436 –  const char *filename;
1437 –  char chanmodes[IRCD_BUFSIZE];
1438 –  char chanlimit[IRCD_BUFSIZE];
1439 –
1440 –  conf_parser_ctx.boot = cold;
1441 –  filename = ConfigFileEntry.configfile;
1442 –
1443 –  /* We need to know the initial filename for the yyerror() to report
1444 –     FIXME: The full path is in conffilenamebuf first time since we
1445 –             dont know anything else
1446 –
1447 –     - Gozem 2002-07-21
1448 –  */
1449 –  strlcpy(conffilebuf, filename, sizeof(conffilebuf));
1450 –
1451 –  if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL)
1452 –  {
1453 –    if (cold)
1454 –    {
1455 –      ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
1456 –           filename, strerror(errno));
1457 –      exit(-1);
1458 –    }
1459 –    else
1460 –    {
1461 –      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1462 –                           "Unable to read configuration file '%s': %s",
1463 –                           filename, strerror(errno));
1464 –      return;
1465 –    }
1466 –  }
1467 –
1468 –  if (!cold)
1469 –    clear_out_old_conf();
1470 –
1471 –  read_conf(conf_parser_ctx.conf_file);
1472 –  fclose(conf_parser_ctx.conf_file);
1473 –
1474 –  log_reopen_all();
1475 –
1476 –  add_isupport("NICKLEN", NULL, ServerInfo.max_nick_length);
1477 –  add_isupport("NETWORK", ServerInfo.network_name, -1);
1478 –
1479 –  snprintf(chanmodes, sizeof(chanmodes), "beI:%d", ConfigChannel.max_bans);
1480 –  add_isupport("MAXLIST", chanmodes, -1);
1481 –  add_isupport("MAXTARGETS", NULL, ConfigFileEntry.max_targets);
1482 –  add_isupport("CHANTYPES", "#", -1);
1483 –
1484 –  snprintf(chanlimit, sizeof(chanlimit), "#:%d",
1485 –           ConfigChannel.max_chans_per_user);
1486 –  add_isupport("CHANLIMIT", chanlimit, -1);
1487 –  snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,imnprstORS");
1488 –  add_isupport("CHANNELLEN", NULL, LOCAL_CHANNELLEN);
1489 –  add_isupport("TOPICLEN", NULL, ServerInfo.max_topic_length);
1490 –  add_isupport("CHANMODES", chanmodes, -1);
1491 –
1492 –  /*
1493 –   * message_locale may have changed.  rebuild isupport since it relies
1494 –   * on strlen(form_str(RPL_ISUPPORT))
1495 –   */
1496 –  rebuild_isupport_message_line();
1497 – }
1498 –
1162   /* clear_out_old_conf()
1163   *
1164   * inputs       - none
# Line 1505 | Line 1168 | read_conf_files(int cold)
1168   static void
1169   clear_out_old_conf(void)
1170   {
1171 <  dlink_node *ptr = NULL, *next_ptr = NULL;
1509 <  struct MaskItem *conf;
1171 >  dlink_node *node = NULL, *node_next = NULL;
1172    dlink_list *free_items [] = {
1173      &server_items,   &oconf_items,
1174       &uconf_items,   &xconf_items,
# Line 1519 | Line 1181 | clear_out_old_conf(void)
1181     * Resetting structs, etc, is taken care of by set_default_conf().
1182     */
1183  
1184 <  for (; *iterator != NULL; iterator++)
1184 >  for (; *iterator; iterator++)
1185    {
1186 <    DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head)
1186 >    DLINK_FOREACH_SAFE(node, node_next, (*iterator)->head)
1187      {
1188 <      conf = ptr->data;
1188 >      struct MaskItem *conf = node->data;
1189  
1190 <      dlinkDelete(&conf->node, map_to_list(conf->type));
1190 >      conf->active = 0;
1191 >      dlinkDelete(&conf->node, *iterator);
1192  
1193        /* XXX This is less than pretty */
1194        if (conf->type == CONF_SERVER || conf->type == CONF_OPER)
# Line 1546 | Line 1209 | clear_out_old_conf(void)
1209    motd_clear();
1210  
1211    /*
1212 <   * don't delete the class table, rather mark all entries
1213 <   * for deletion. The table is cleaned up by class_delete_marked. - avalon
1212 >   * Don't delete the class table, rather mark all entries for deletion.
1213 >   * The table is cleaned up by class_delete_marked. - avalon
1214     */
1215    class_mark_for_deletion();
1216  
1217    clear_out_address_conf();
1218  
1219 <  /* clean out module paths */
1219 >  /* Clean out module paths */
1220    mod_clear_paths();
1221  
1222 <  /* clean out ServerInfo */
1223 <  MyFree(ServerInfo.description);
1224 <  ServerInfo.description = NULL;
1225 <  MyFree(ServerInfo.network_name);
1226 <  ServerInfo.network_name = NULL;
1227 <  MyFree(ServerInfo.network_desc);
1228 <  ServerInfo.network_desc = NULL;
1229 <  MyFree(ConfigFileEntry.egdpool_path);
1230 <  ConfigFileEntry.egdpool_path = NULL;
1222 >  pseudo_clear();
1223 >
1224 >  /* Clean out ConfigServerInfo */
1225 >  MyFree(ConfigServerInfo.description);
1226 >  ConfigServerInfo.description = NULL;
1227 >  MyFree(ConfigServerInfo.network_name);
1228 >  ConfigServerInfo.network_name = NULL;
1229 >  MyFree(ConfigServerInfo.network_desc);
1230 >  ConfigServerInfo.network_desc = NULL;
1231   #ifdef HAVE_LIBCRYPTO
1232 <  if (ServerInfo.rsa_private_key)
1232 >  if (ConfigServerInfo.rsa_private_key)
1233    {
1234 <    RSA_free(ServerInfo.rsa_private_key);
1235 <    ServerInfo.rsa_private_key = NULL;
1234 >    RSA_free(ConfigServerInfo.rsa_private_key);
1235 >    ConfigServerInfo.rsa_private_key = NULL;
1236    }
1237  
1238 <  MyFree(ServerInfo.rsa_private_key_file);
1239 <  ServerInfo.rsa_private_key_file = NULL;
1577 <
1578 <  if (ServerInfo.server_ctx)
1579 <    SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|
1580 <                                               SSL_OP_NO_SSLv3|
1581 <                                               SSL_OP_NO_TLSv1);
1582 <  if (ServerInfo.client_ctx)
1583 <    SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|
1584 <                                               SSL_OP_NO_SSLv3|
1585 <                                               SSL_OP_NO_TLSv1);
1238 >  MyFree(ConfigServerInfo.rsa_private_key_file);
1239 >  ConfigServerInfo.rsa_private_key_file = NULL;
1240   #endif
1241  
1242 <  /* clean out AdminInfo */
1243 <  MyFree(AdminInfo.name);
1244 <  AdminInfo.name = NULL;
1245 <  MyFree(AdminInfo.email);
1246 <  AdminInfo.email = NULL;
1247 <  MyFree(AdminInfo.description);
1248 <  AdminInfo.description = NULL;
1242 >  /* Clean out ConfigAdminInfo */
1243 >  MyFree(ConfigAdminInfo.name);
1244 >  ConfigAdminInfo.name = NULL;
1245 >  MyFree(ConfigAdminInfo.email);
1246 >  ConfigAdminInfo.email = NULL;
1247 >  MyFree(ConfigAdminInfo.description);
1248 >  ConfigAdminInfo.description = NULL;
1249  
1250 <  /* clean out listeners */
1250 >  /* Clean out listeners */
1251    close_listeners();
1252 + }
1253 +
1254 + /* read_conf_files()
1255 + *
1256 + * inputs       - cold start YES or NO
1257 + * output       - none
1258 + * side effects - read all conf files needed, ircd.conf kline.conf etc.
1259 + */
1260 + void
1261 + read_conf_files(int cold)
1262 + {
1263 +  const char *filename = NULL;
1264 +  char chanmodes[IRCD_BUFSIZE] = "";
1265 +  char chanlimit[IRCD_BUFSIZE] = "";
1266 +
1267 +  conf_parser_ctx.boot = cold;
1268 +  filename = ConfigGeneral.configfile;
1269 +
1270 +  /* We need to know the initial filename for the yyerror() to report
1271 +     FIXME: The full path is in conffilenamebuf first time since we
1272 +             don't know anything else
1273 +
1274 +     - Gozem 2002-07-21
1275 +  */
1276 +  strlcpy(conffilebuf, filename, sizeof(conffilebuf));
1277 +
1278 +  if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL)
1279 +  {
1280 +    if (cold)
1281 +    {
1282 +      ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
1283 +           filename, strerror(errno));
1284 +      exit(-1);
1285 +    }
1286 +    else
1287 +    {
1288 +      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1289 +                           "Unable to read configuration file '%s': %s",
1290 +                           filename, strerror(errno));
1291 +      return;
1292 +    }
1293 +  }
1294 +
1295 +  if (!cold)
1296 +    clear_out_old_conf();
1297 +
1298 +  read_conf(conf_parser_ctx.conf_file);
1299 +  fclose(conf_parser_ctx.conf_file);
1300  
1301 <  /* clean out general */
1302 <  MyFree(ConfigFileEntry.service_name);
1303 <  ConfigFileEntry.service_name = NULL;
1301 >  log_reopen_all();
1302 >
1303 >  add_isupport("NICKLEN", NULL, ConfigServerInfo.max_nick_length);
1304 >  add_isupport("NETWORK", ConfigServerInfo.network_name, -1);
1305 >
1306 >  snprintf(chanmodes, sizeof(chanmodes), "beI:%d", ConfigChannel.max_bans);
1307 >  add_isupport("MAXLIST", chanmodes, -1);
1308 >  add_isupport("MAXTARGETS", NULL, ConfigGeneral.max_targets);
1309 >  add_isupport("CHANTYPES", "#", -1);
1310 >
1311 >  snprintf(chanlimit, sizeof(chanlimit), "#:%d",
1312 >           ConfigChannel.max_channels);
1313 >  add_isupport("CHANLIMIT", chanlimit, -1);
1314 >  snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,cimnprstCMORS");
1315 >  add_isupport("CHANNELLEN", NULL, CHANNELLEN);
1316 >  add_isupport("TOPICLEN", NULL, ConfigServerInfo.max_topic_length);
1317 >  add_isupport("CHANMODES", chanmodes, -1);
1318 >
1319 >  /*
1320 >   * message_locale may have changed.  rebuild isupport since it relies
1321 >   * on strlen(form_str(RPL_ISUPPORT))
1322 >   */
1323 >  rebuild_isupport_message_line();
1324   }
1325  
1326   /* conf_add_class_to_conf()
# Line 1614 | Line 1336 | conf_add_class_to_conf(struct MaskItem *
1336    {
1337      conf->class = class_default;
1338  
1339 <    if (conf->type == CONF_CLIENT)
1339 >    if (conf->type == CONF_CLIENT || conf->type == CONF_OPER)
1340        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1341                             "Warning *** Defaulting to default class for %s@%s",
1342                             conf->user, conf->host);
# Line 1628 | Line 1350 | conf_add_class_to_conf(struct MaskItem *
1350  
1351    if (conf->class == NULL)
1352    {
1353 <    if (conf->type == CONF_CLIENT)
1353 >    if (conf->type == CONF_CLIENT || conf->type == CONF_OPER)
1354        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1355                             "Warning *** Defaulting to default class for %s@%s",
1356                             conf->user, conf->host);
# Line 1703 | Line 1425 | valid_tkline(const char *data, const int
1425  
1426    /*
1427     * In the degenerate case where oper does a /quote kline 0 user@host :reason
1428 <   * i.e. they specifically use 0, I am going to return 1 instead
1429 <   * as a return value of non-zero is used to flag it as a temporary kline
1428 >   * i.e. they specifically use 0, I am going to return 1 instead as a return
1429 >   * value of non-zero is used to flag it as a temporary kline
1430     */
1431    if (result == 0)
1432      result = 1;
# Line 1719 | Line 1441 | valid_tkline(const char *data, const int
1441    if (result > MAX_TDKLINE_TIME)
1442      result = MAX_TDKLINE_TIME;
1443  
1444 <  result = result * 60;  /* turn it into seconds */
1444 >  result = result * 60;  /* Turn it into seconds */
1445  
1446    return result;
1447   }
# Line 1735 | Line 1457 | valid_wild_card_simple(const char *data)
1457   {
1458    const unsigned char *p = (const unsigned char *)data;
1459    unsigned char tmpch = '\0';
1460 <  int nonwild = 0;
1460 >  unsigned int nonwild = 0;
1461  
1462    while ((tmpch = *p++))
1463    {
1464 <    if (tmpch == '\\')
1464 >    if (tmpch == '\\' && *p)
1465      {
1466        ++p;
1467 <      if (++nonwild >= ConfigFileEntry.min_nonwildcard_simple)
1467 >      if (++nonwild >= ConfigGeneral.min_nonwildcard_simple)
1468          return 1;
1469      }
1470      else if (!IsMWildChar(tmpch))
1471      {
1472 <      if (++nonwild >= ConfigFileEntry.min_nonwildcard_simple)
1472 >      if (++nonwild >= ConfigGeneral.min_nonwildcard_simple)
1473          return 1;
1474      }
1475    }
# Line 1766 | Line 1488 | valid_wild_card_simple(const char *data)
1488   int
1489   valid_wild_card(struct Client *source_p, int warn, int count, ...)
1490   {
1491 <  char tmpch;
1492 <  int nonwild = 0;
1491 >  unsigned char tmpch = '\0';
1492 >  unsigned int nonwild = 0;
1493    va_list args;
1494  
1495    /*
# Line 1786 | Line 1508 | valid_wild_card(struct Client *source_p,
1508  
1509    while (count--)
1510    {
1511 <    const char *p = va_arg(args, const char *);
1511 >    const unsigned char *p = va_arg(args, const unsigned char *);
1512      if (p == NULL)
1513        continue;
1514  
# Line 1798 | Line 1520 | valid_wild_card(struct Client *source_p,
1520           * If we find enough non-wild characters, we can
1521           * break - no point in searching further.
1522           */
1523 <        if (++nonwild >= ConfigFileEntry.min_nonwildcard)
1523 >        if (++nonwild >= ConfigGeneral.min_nonwildcard)
1524          {
1525            va_end(args);
1526            return 1;
# Line 1809 | Line 1531 | valid_wild_card(struct Client *source_p,
1531  
1532    if (warn)
1533      sendto_one_notice(source_p, &me,
1534 <                      ":Please include at least %d non-wildcard characters with the mask",
1535 <                      ConfigFileEntry.min_nonwildcard);
1534 >                      ":Please include at least %u non-wildcard characters with the mask",
1535 >                      ConfigGeneral.min_nonwildcard);
1536    va_end(args);
1537    return 0;
1538   }
1539  
1540 + /* find_user_host()
1541 + *
1542 + * inputs       - pointer to client placing kline
1543 + *              - pointer to user_host_or_nick
1544 + *              - pointer to user buffer
1545 + *              - pointer to host buffer
1546 + * output       - 0 if not ok to kline, 1 to kline i.e. if valid user host
1547 + * side effects -
1548 + */
1549 + static int
1550 + find_user_host(struct Client *source_p, char *user_host_or_nick,
1551 +               char *luser, char *lhost, unsigned int flags)
1552 + {
1553 +  struct Client *target_p = NULL;
1554 +  char *hostp = NULL;
1555 +
1556 +  if (lhost == NULL)
1557 +  {
1558 +    strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
1559 +    return 1;
1560 +  }
1561 +
1562 +  if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
1563 +  {
1564 +    /* Explicit user@host mask given */
1565 +    if (hostp)                            /* I'm a little user@host */
1566 +    {
1567 +      *(hostp++) = '\0';                       /* short and squat */
1568 +
1569 +      if (*user_host_or_nick)
1570 +        strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
1571 +      else
1572 +        strcpy(luser, "*");
1573 +
1574 +      if (*hostp)
1575 +        strlcpy(lhost, hostp, HOSTLEN + 1);    /* here is my host */
1576 +      else
1577 +        strcpy(lhost, "*");
1578 +    }
1579 +    else
1580 +    {
1581 +      luser[0] = '*';             /* no @ found, assume its *@somehost */
1582 +      luser[1] = '\0';
1583 +      strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
1584 +    }
1585 +
1586 +    return 1;
1587 +  }
1588 +  else
1589 +  {
1590 +    /* Try to find user@host mask from nick */
1591 +    /* Okay to use source_p as the first param, because source_p == client_p */
1592 +    if ((target_p =
1593 +        find_chasing(source_p, user_host_or_nick)) == NULL)
1594 +      return 0;  /* find_chasing sends ERR_NOSUCHNICK */
1595 +
1596 +    if (IsExemptKline(target_p))
1597 +    {
1598 +      if (IsClient(source_p))
1599 +        sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
1600 +      return 0;
1601 +    }
1602 +
1603 +    /*
1604 +     * Turn the "user" bit into "*user", blow away '~'
1605 +     * if found in original user name (non-idented)
1606 +     */
1607 +    strlcpy(luser, target_p->username, USERLEN*4 + 1);
1608 +
1609 +    if (target_p->username[0] == '~')
1610 +      luser[0] = '*';
1611 +
1612 +    if (!strcmp(target_p->sockhost, "0"))
1613 +      strlcpy(lhost, target_p->host, HOSTLEN*4 + 1);
1614 +    else
1615 +      strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
1616 +    return 1;
1617 +  }
1618 +
1619 +  return 0;
1620 + }
1621 +
1622   /* XXX should this go into a separate file ? -Dianora */
1623   /* parse_aline
1624   *
# Line 1852 | Line 1656 | parse_aline(const char *cmd, struct Clie
1656              char **target_server, char **reason)
1657   {
1658    int found_tkline_time=0;
1659 <  static char def_reason[] = "No Reason";
1659 >  static char def_reason[] = CONF_NOREASON;
1660    static char user[USERLEN*4+1];
1661    static char host[HOSTLEN*4+1];
1662  
# Line 1861 | Line 1665 | parse_aline(const char *cmd, struct Clie
1665  
1666    found_tkline_time = valid_tkline(*parv, TK_MINUTES);
1667  
1668 <  if (found_tkline_time != 0)
1668 >  if (found_tkline_time)
1669    {
1670      parv++;
1671      parc--;
1672  
1673 <    if (tkline_time != NULL)
1673 >    if (tkline_time)
1674        *tkline_time = found_tkline_time;
1675      else
1676      {
# Line 1895 | Line 1699 | parse_aline(const char *cmd, struct Clie
1699    parc--;
1700    parv++;
1701  
1702 <  if (parc != 0)
1702 >  if (parc)
1703    {
1704      if (irccmp(*parv, "ON") == 0)
1705      {
# Line 1929 | Line 1733 | parse_aline(const char *cmd, struct Clie
1733        /* Make sure target_server *is* NULL if no ON server found
1734         * caller probably NULL'd it first, but no harm to do it again -db
1735         */
1736 <      if (target_server != NULL)
1736 >      if (target_server)
1737          *target_server = NULL;
1738      }
1739    }
1740  
1741 <  if (h_p != NULL)
1741 >  if (h_p)
1742    {
1743 <    if (strchr(user, '!') != NULL)
1743 >    if (strchr(user, '!'))
1744      {
1745        sendto_one_notice(source_p, &me, ":Invalid character '!' in kline");
1746        return -1;
# Line 1949 | Line 1753 | parse_aline(const char *cmd, struct Clie
1753      if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 1, *up_p))
1754        return -1;
1755  
1756 <  if (reason != NULL)
1756 >  if (reason)
1757    {
1758 <    if (parc != 0 && !EmptyString(*parv))
1758 >    if (parc && !EmptyString(*parv))
1759      {
1760        *reason = *parv;
1761 +
1762        if (!valid_comment(source_p, *reason, 1))
1763          return -1;
1764      }
# Line 1964 | Line 1769 | parse_aline(const char *cmd, struct Clie
1769    return 1;
1770   }
1771  
1967 – /* find_user_host()
1968 – *
1969 – * inputs       - pointer to client placing kline
1970 – *              - pointer to user_host_or_nick
1971 – *              - pointer to user buffer
1972 – *              - pointer to host buffer
1973 – * output       - 0 if not ok to kline, 1 to kline i.e. if valid user host
1974 – * side effects -
1975 – */
1976 – static int
1977 – find_user_host(struct Client *source_p, char *user_host_or_nick,
1978 –               char *luser, char *lhost, unsigned int flags)
1979 – {
1980 –  struct Client *target_p = NULL;
1981 –  char *hostp = NULL;
1982 –
1983 –  if (lhost == NULL)
1984 –  {
1985 –    strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
1986 –    return 1;
1987 –  }
1988 –
1989 –  if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
1990 –  {
1991 –    /* Explicit user@host mask given */
1992 –
1993 –    if (hostp != NULL)                            /* I'm a little user@host */
1994 –    {
1995 –      *(hostp++) = '\0';                       /* short and squat */
1996 –      if (*user_host_or_nick)
1997 –        strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
1998 –      else
1999 –        strcpy(luser, "*");
2000 –
2001 –      if (*hostp)
2002 –        strlcpy(lhost, hostp, HOSTLEN + 1);    /* here is my host */
2003 –      else
2004 –        strcpy(lhost, "*");
2005 –    }
2006 –    else
2007 –    {
2008 –      luser[0] = '*';             /* no @ found, assume its *@somehost */
2009 –      luser[1] = '\0';
2010 –      strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
2011 –    }
2012 –
2013 –    return 1;
2014 –  }
2015 –  else
2016 –  {
2017 –    /* Try to find user@host mask from nick */
2018 –    /* Okay to use source_p as the first param, because source_p == client_p */
2019 –    if ((target_p =
2020 –        find_chasing(source_p, user_host_or_nick)) == NULL)
2021 –      return 0;
2022 –
2023 –    if (IsExemptKline(target_p))
2024 –    {
2025 –      if (!IsServer(source_p))
2026 –        sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
2027 –      return 0;
2028 –    }
2029 –
2030 –    /*
2031 –     * turn the "user" bit into "*user", blow away '~'
2032 –     * if found in original user name (non-idented)
2033 –     */
2034 –    strlcpy(luser, target_p->username, USERLEN*4 + 1);
2035 –
2036 –    if (target_p->username[0] == '~')
2037 –      luser[0] = '*';
2038 –
2039 –    if (target_p->sockhost[0] == '\0' ||
2040 –        (target_p->sockhost[0] == '0' && target_p->sockhost[1] == '\0'))
2041 –      strlcpy(lhost, target_p->host, HOSTLEN*4 + 1);
2042 –    else
2043 –      strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
2044 –    return 1;
2045 –  }
2046 –
2047 –  return 0;
2048 – }
2049 –
1772   /* valid_comment()
1773   *
1774   * inputs       - pointer to client
# Line 2100 | Line 1822 | match_conf_password(const char *password
1822   *                along to all servers that match capab and cluster type
1823   */
1824   void
1825 < cluster_a_line(struct Client *source_p, const char *command,
1826 <               int capab, int cluster_type, const char *pattern, ...)
1825 > cluster_a_line(struct Client *source_p, const char *command, int capab,
1826 >               int cluster_type, const char *pattern, ...)
1827   {
1828    va_list args;
1829 <  char buffer[IRCD_BUFSIZE];
1830 <  const dlink_node *ptr = NULL;
1829 >  char buffer[IRCD_BUFSIZE] = "";
1830 >  const dlink_node *node = NULL;
1831  
1832    va_start(args, pattern);
1833    vsnprintf(buffer, sizeof(buffer), pattern, args);
1834    va_end(args);
1835  
1836 <  DLINK_FOREACH(ptr, cluster_items.head)
1836 >  DLINK_FOREACH(node, cluster_items.head)
1837    {
1838 <    const struct MaskItem *conf = ptr->data;
1838 >    const struct MaskItem *conf = node->data;
1839  
1840      if (conf->flags & cluster_type)
1841 <      sendto_match_servs(source_p, conf->name, CAP_CLUSTER|capab,
1841 >      sendto_match_servs(source_p, conf->name, CAP_CLUSTER | capab,
1842                           "%s %s %s", command, conf->name, buffer);
1843    }
1844   }
# Line 2156 | Line 1878 | split_nuh(struct split_nuh_item *const i
1878  
1879    if (iptr->nickptr)
1880      strlcpy(iptr->nickptr, "*", iptr->nicksize);
1881 +
1882    if (iptr->userptr)
1883      strlcpy(iptr->userptr, "*", iptr->usersize);
1884 +
1885    if (iptr->hostptr)
1886      strlcpy(iptr->hostptr, "*", iptr->hostsize);
1887  
# Line 2165 | Line 1889 | split_nuh(struct split_nuh_item *const i
1889    {
1890      *p = '\0';
1891  
1892 <    if (iptr->nickptr && *iptr->nuhmask != '\0')
1892 >    if (iptr->nickptr && *iptr->nuhmask)
1893        strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
1894  
1895      if ((q = strchr(++p, '@')))
1896      {
1897        *q++ = '\0';
1898  
1899 <      if (*p != '\0')
1899 >      if (*p)
1900          strlcpy(iptr->userptr, p, iptr->usersize);
1901  
1902 <      if (*q != '\0')
1902 >      if (*q)
1903          strlcpy(iptr->hostptr, q, iptr->hostsize);
1904      }
1905      else
1906      {
1907 <      if (*p != '\0')
1907 >      if (*p)
1908          strlcpy(iptr->userptr, p, iptr->usersize);
1909      }
1910    }
# Line 2192 | Line 1916 | split_nuh(struct split_nuh_item *const i
1916        /* if found a @ */
1917        *p++ = '\0';
1918  
1919 <      if (*iptr->nuhmask != '\0')
1919 >      if (*iptr->nuhmask)
1920          strlcpy(iptr->userptr, iptr->nuhmask, iptr->usersize);
1921  
1922 <      if (*p != '\0')
1922 >      if (*p)
1923          strlcpy(iptr->hostptr, p, iptr->hostsize);
1924      }
1925      else
1926      {
1927 <      /* no @ found */
1927 >      /* No @ found */
1928        if (!iptr->nickptr || strpbrk(iptr->nuhmask, ".:"))
1929          strlcpy(iptr->hostptr, iptr->nuhmask, iptr->hostsize);
1930        else

Diff Legend

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