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

Diff Legend

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