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 7230 by michael, Wed Feb 3 16:00:29 2016 UTC vs.
Revision 8682 by michael, Sun Nov 25 08:21:03 2018 UTC

# Line 1 | Line 1
1   /*
2   *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (c) 1997-2016 ircd-hybrid development team
4 > *  Copyright (c) 1997-2018 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 27 | Line 27
27   #include "stdinc.h"
28   #include "list.h"
29   #include "ircd_defs.h"
30 + #include "parse.h"
31   #include "conf.h"
32   #include "conf_cluster.h"
33 + #include "conf_gecos.h"
34   #include "conf_pseudo.h"
35 + #include "conf_resv.h"
36 + #include "conf_service.h"
37   #include "conf_shared.h"
38   #include "server.h"
35 #include "resv.h"
39   #include "channel.h"
40   #include "client.h"
41   #include "event.h"
# Line 48 | Line 51
51   #include "send.h"
52   #include "memory.h"
53   #include "res.h"
51 #include "userhost.h"
54   #include "user.h"
55   #include "channel_mode.h"
54 #include "parse.h"
56   #include "misc.h"
57   #include "conf_db.h"
58   #include "conf_class.h"
59   #include "motd.h"
60   #include "ipcache.h"
61   #include "isupport.h"
62 + #include "whowas.h"
63  
64  
65   struct config_channel_entry ConfigChannel;
# Line 69 | Line 71 | struct config_admin_entry ConfigAdminInf
71   struct conf_parser_context conf_parser_ctx;
72  
73   /* general conf items link list root, other than k lines etc. */
74 < dlink_list service_items;
73 < dlink_list server_items;
74 > dlink_list connect_items;
75   dlink_list operator_items;
75 dlink_list gecos_items;
76 dlink_list nresv_items;
77 dlink_list cresv_items;
76  
77   extern unsigned int lineno;
78   extern char linebuf[];
# Line 97 | Line 95 | conf_dns_callback(void *vptr, const stru
95   {
96    struct MaskItem *const conf = vptr;
97  
98 <  conf->dns_pending = 0;
98 >  conf->dns_pending = false;
99  
100    if (addr)
101      memcpy(&conf->addr, addr, sizeof(conf->addr));
102    else
103 <    conf->dns_failed = 1;
103 >    conf->dns_failed = true;
104   }
105  
106   /* conf_dns_lookup()
# Line 114 | Line 112 | conf_dns_callback(void *vptr, const stru
112   static void
113   conf_dns_lookup(struct MaskItem *conf)
114   {
115 <  if (conf->dns_pending)
115 >  if (conf->dns_pending == true)
116      return;
117  
118 <  conf->dns_pending = 1;
118 >  conf->dns_pending = true;
119  
120    if (conf->aftype == AF_INET)
121      gethost_byname_type(conf_dns_callback, conf, conf->host, T_A);
# Line 136 | Line 134 | map_to_list(enum maskitem_type type)
134   {
135    switch (type)
136    {
139    case CONF_XLINE:
140      return &gecos_items;
141      break;
142    case CONF_NRESV:
143      return &nresv_items;
144      break;
145    case CONF_CRESV:
146      return &cresv_items;
147      break;
137      case CONF_OPER:
138        return &operator_items;
139        break;
140      case CONF_SERVER:
141 <      return &server_items;
153 <      break;
154 <    case CONF_SERVICE:
155 <      return &service_items;
141 >      return &connect_items;
142        break;
143      default:
144        return NULL;
# Line 166 | Line 152 | conf_make(enum maskitem_type type)
152    dlink_list *list = NULL;
153  
154    conf->type   = type;
155 <  conf->active = 1;
155 >  conf->active = true;
156    conf->aftype = AF_INET;
157  
158    if ((list = map_to_list(type)))
# Line 185 | Line 171 | conf_free(struct MaskItem *conf)
171  
172    xfree(conf->name);
173  
174 <  if (conf->dns_pending)
174 >  if (conf->dns_pending == true)
175      delete_resolver_queries(conf);
176    if (conf->passwd)
177      memset(conf->passwd, 0, strlen(conf->passwd));
# Line 217 | Line 203 | conf_free(struct MaskItem *conf)
203      free_dlink_node(node);
204    }
205  
220  DLINK_FOREACH_SAFE(node, node_next, conf->exempt_list.head)
221  {
222    struct exempt *exptr = node->data;
223
224    dlinkDelete(node, &conf->exempt_list);
225    xfree(exptr->name);
226    xfree(exptr->user);
227    xfree(exptr->host);
228    xfree(exptr);
229  }
230
206    xfree(conf);
207   }
208  
# Line 242 | Line 217 | static int
217   attach_iline(struct Client *client_p, struct MaskItem *conf)
218   {
219    const struct ClassItem *const class = conf->class;
220 <  struct ip_entry *ip_found;
246 <  int a_limit_reached = 0;
247 <  unsigned int local = 0, global = 0, ident = 0;
220 >  bool a_limit_reached = false;
221  
222 <  ip_found = ipcache_find_or_add_address(&client_p->connection->ip);
223 <  ip_found->count++;
222 >  struct ip_entry *ipcache = ipcache_record_find_or_add(&client_p->ip);
223 >  ++ipcache->count_local;
224    AddFlag(client_p, FLAGS_IPHASH);
225  
253  userhost_count(client_p->username, client_p->host,
254                 &global, &local, &ident);
255
256  /* XXX blah. go down checking the various silly limits
257   * setting a_limit_reached if any limit is reached.
258   * - Dianora
259   */
226    if (class->max_total && class->ref_count >= class->max_total)
227 <    a_limit_reached = 1;
228 <  else if (class->max_perip && ip_found->count > class->max_perip)
229 <    a_limit_reached = 1;
230 <  else if (class->max_local && local >= class->max_local)
231 <    a_limit_reached = 1;
232 <  else if (class->max_global && global >= class->max_global)
267 <    a_limit_reached = 1;
268 <  else if (class->max_ident && ident >= class->max_ident &&
269 <           client_p->username[0] != '~')
270 <    a_limit_reached = 1;
227 >    a_limit_reached = true;
228 >  else if (class->max_perip_local && ipcache->count_local > class->max_perip_local)
229 >    a_limit_reached = true;
230 >  else if (class->max_perip_global &&
231 >           (ipcache->count_local + ipcache->count_remote) > class->max_perip_global)
232 >    a_limit_reached = true;
233  
234 <  if (a_limit_reached)
234 >  if (a_limit_reached == true)
235    {
236      if (!IsConfExemptLimits(conf))
237        return TOO_MANY;   /* Already at maximum allowed */
# Line 278 | Line 240 | attach_iline(struct Client *client_p, st
240                        "but you have exceed_limit = yes;");
241    }
242  
243 <  return attach_conf(client_p, conf);
243 >  return conf_attach(client_p, conf);
244   }
245  
246   /* verify_access()
# Line 295 | Line 257 | verify_access(struct Client *client_p)
257    if (HasFlag(client_p, FLAGS_GOTID))
258    {
259      conf = find_address_conf(client_p->host, client_p->username,
260 <                             &client_p->connection->ip,
261 <                             client_p->connection->aftype,
260 >                             &client_p->ip,
261 >                             client_p->ip.ss.ss_family,
262                               client_p->connection->password);
263    }
264    else
# Line 305 | Line 267 | verify_access(struct Client *client_p)
267  
268      strlcpy(non_ident + 1, client_p->username, sizeof(non_ident) - 1);
269      conf = find_address_conf(client_p->host, non_ident,
270 <                             &client_p->connection->ip,
271 <                             client_p->connection->aftype,
270 >                             &client_p->ip,
271 >                             client_p->ip.ss.ss_family,
272                               client_p->connection->password);
273    }
274  
# Line 368 | Line 330 | check_client(struct Client *source_p)
330      case TOO_MANY:
331        sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
332                             "Too many on IP for %s (%s).",
333 <                           get_client_name(source_p, SHOW_IP),
333 >                           client_get_name(source_p, SHOW_IP),
334                             source_p->sockhost);
335        ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
336 <           get_client_name(source_p, SHOW_IP));
336 >           client_get_name(source_p, SHOW_IP));
337        ++ServerStats.is_ref;
338        exit_client(source_p, "No more connections allowed on that IP");
339        break;
# Line 379 | Line 341 | check_client(struct Client *source_p)
341      case I_LINE_FULL:
342        sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
343                             "auth {} block is full for %s (%s).",
344 <                           get_client_name(source_p, SHOW_IP),
344 >                           client_get_name(source_p, SHOW_IP),
345                             source_p->sockhost);
346        ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
347 <           get_client_name(source_p, SHOW_IP));
347 >           client_get_name(source_p, SHOW_IP));
348        ++ServerStats.is_ref;
349        exit_client(source_p, "No more connections allowed in your connection class");
350        break;
# Line 391 | Line 353 | check_client(struct Client *source_p)
353        /* jdc - lists server name & port connections are on */
354        /*       a purely cosmetical change */
355        sendto_realops_flags(UMODE_UNAUTH, L_ALL, SEND_NOTICE,
356 <                           "Unauthorized client connection from %s [%s] on [%s/%u].",
357 <                           get_client_name(source_p, SHOW_IP),
396 <                           source_p->sockhost,
356 >                           "Unauthorized client connection from %s on [%s/%u].",
357 >                           client_get_name(source_p, SHOW_IP),
358                             source_p->connection->listener->name,
359                             source_p->connection->listener->port);
360        ilog(LOG_TYPE_IRCD, "Unauthorized client connection from %s on [%s/%u].",
361 <           get_client_name(source_p, SHOW_IP),
361 >           client_get_name(source_p, SHOW_IP),
362             source_p->connection->listener->name,
363             source_p->connection->listener->port);
364  
# Line 418 | Line 379 | check_client(struct Client *source_p)
379    return !(i < 0);
380   }
381  
382 < /* detach_conf()
383 < *
384 < * inputs       - pointer to client to detach
385 < *              - type of conf to detach
425 < * output       - 0 for success, -1 for failure
426 < * side effects - Disassociate configuration from the client.
427 < *                Also removes a class from the list if marked for deleting.
382 > /*! \brief Disassociate configuration from the client. Also removes a class
383 > *         from the list if marked for deleting.
384 > * \param client_p Client to operate on
385 > * \param type     Type of conf to detach
386   */
387   void
388 < detach_conf(struct Client *client_p, enum maskitem_type type)
388 > conf_detach(struct Client *client_p, enum maskitem_type type)
389   {
390 <  dlink_node *node = NULL, *node_next = NULL;
390 >  dlink_node *node, *node_next;
391  
392    DLINK_FOREACH_SAFE(node, node_next, client_p->connection->confs.head)
393    {
# Line 446 | Line 404 | detach_conf(struct Client *client_p, enu
404      free_dlink_node(node);
405  
406      if (conf->type == CONF_CLIENT)
407 <      remove_from_cidr_check(&client_p->connection->ip, conf->class);
407 >      class_ip_limit_remove(conf->class, &client_p->ip);
408  
409 <    if (--conf->class->ref_count == 0 && conf->class->active == 0)
409 >    if (--conf->class->ref_count == 0 && conf->class->active == false)
410      {
411        class_free(conf->class);
412        conf->class = NULL;
413      }
414  
415 <    if (--conf->ref_count == 0 && conf->active == 0)
415 >    if (--conf->ref_count == 0 && conf->active == false)
416        conf_free(conf);
417    }
418   }
419  
420 < /* attach_conf()
421 < *
422 < * inputs       - client pointer
423 < *              - conf pointer
424 < * output       -
467 < * side effects - Associate a specific configuration entry to a *local*
468 < *                client (this is the one which used in accepting the
469 < *                connection). Note, that this automatically changes the
470 < *                attachment if there was an old one...
420 > /*! \brief Associate a specific configuration entry to a *local* client (this
421 > *         is the one which used in accepting the connection). Note, that this
422 > *         automatically changes the attachment if there was an old one.
423 > * \param client_p Client to attach the conf to
424 > * \param conf Configuration record to attach
425   */
426   int
427 < attach_conf(struct Client *client_p, struct MaskItem *conf)
427 > conf_attach(struct Client *client_p, struct MaskItem *conf)
428   {
429    if (dlinkFind(&client_p->connection->confs, conf))
430      return 1;
431  
432    if (conf->type == CONF_CLIENT)
433 <    if (cidr_limit_reached(IsConfExemptLimits(conf),
480 <                           &client_p->connection->ip, conf->class))
433 >    if (class_ip_limit_add(conf->class, &client_p->ip, IsConfExemptLimits(conf)) == true)
434        return TOO_MANY;    /* Already at maximum allowed */
435  
436    conf->class->ref_count++;
# Line 488 | Line 441 | attach_conf(struct Client *client_p, str
441    return 0;
442   }
443  
491 /* attach_connect_block()
492 *
493 * inputs       - pointer to server to attach
494 *              - name of server
495 *              - hostname of server
496 * output       - true (1) if both are found, otherwise return false (0)
497 * side effects - find connect block and attach them to connecting client
498 */
499 int
500 attach_connect_block(struct Client *client_p, const char *name,
501                     const char *host)
502 {
503  dlink_node *node = NULL;
504
505  assert(host);
506
507  DLINK_FOREACH(node, server_items.head)
508  {
509    struct MaskItem *conf = node->data;
510
511    if (match(conf->name, name) || match(conf->host, host))
512      continue;
513
514    attach_conf(client_p, conf);
515    return 1;
516  }
517
518  return 0;
519 }
520
444   /* find_conf_name()
445   *
446   * inputs       - pointer to conf link list to search
# Line 546 | Line 469 | find_conf_name(dlink_list *list, const c
469    return NULL;
470   }
471  
472 < /* find_matching_name_conf()
473 < *
474 < * inputs       - type of link list to look in
552 < *              - pointer to name string to find
553 < *              - pointer to user
554 < *              - pointer to host
555 < *              - optional flags to match on as well
556 < * output       - NULL or pointer to found struct MaskItem
557 < * side effects - looks for a match on name field
472 > /*! \brief Find a connect {} conf that has a name that matches \a name.
473 > * \param name Name to match
474 > * \param compare Pointer to function to be used for string matching
475   */
476   struct MaskItem *
477 < find_matching_name_conf(enum maskitem_type type, const char *name, const char *user,
561 <                        const char *host, unsigned int flags)
477 > connect_find(const char *name, int (*compare)(const char *, const char *))
478   {
479 <  dlink_node *node = NULL;
564 <  dlink_list *list = map_to_list(type);
565 <  struct MaskItem *conf = NULL;
479 >  dlink_node *node;
480  
481 <  switch (type)
481 >  DLINK_FOREACH(node, connect_items.head)
482    {
483 <  case CONF_SERVICE:
570 <    DLINK_FOREACH(node, list->head)
571 <    {
572 <      conf = node->data;
573 <
574 <      if (EmptyString(conf->name))
575 <        continue;
576 <      if (name && !irccmp(name, conf->name))
577 <        return conf;
578 <    }
579 <    break;
580 <
581 <  case CONF_XLINE:
582 <  case CONF_NRESV:
583 <  case CONF_CRESV:
584 <    DLINK_FOREACH(node, list->head)
585 <    {
586 <      conf = node->data;
587 <
588 <      if (EmptyString(conf->name))
589 <        continue;
590 <      if (name && !match(conf->name, name))
591 <      {
592 <        if ((user == NULL && (host == NULL)))
593 <          return conf;
594 <        if ((conf->modes & flags) != flags)
595 <          continue;
596 <        if (EmptyString(conf->user) || EmptyString(conf->host))
597 <          return conf;
598 <        if (!match(conf->user, user) && !match(conf->host, host))
599 <          return conf;
600 <      }
601 <    }
602 <      break;
603 <
604 <  case CONF_SERVER:
605 <    DLINK_FOREACH(node, list->head)
606 <    {
607 <      conf = node->data;
608 <
609 <      if (name && !match(name, conf->name))
610 <        return conf;
611 <      if (host && !match(host, conf->host))
612 <        return conf;
613 <    }
614 <    break;
483 >    struct MaskItem *conf = node->data;
484  
485 <  default:
486 <    break;
485 >    if (!compare(name, conf->name))
486 >      return conf;
487    }
488 +
489    return NULL;
490   }
491  
# Line 629 | Line 499 | find_matching_name_conf(enum maskitem_ty
499   * side effects - looks for an exact match on name field
500   */
501   struct MaskItem *
502 < find_exact_name_conf(enum maskitem_type type, const struct Client *who, const char *name,
633 <                     const char *user, const char *host)
502 > operator_find(const struct Client *who, const char *name)
503   {
504    dlink_node *node = NULL;
636  dlink_list *list = map_to_list(type);
637  struct MaskItem *conf = NULL;
505  
506 <  switch(type)
506 >  DLINK_FOREACH(node, operator_items.head)
507    {
508 <  case CONF_XLINE:
642 <  case CONF_NRESV:
643 <  case CONF_CRESV:
644 <
645 <    DLINK_FOREACH(node, list->head)
646 <    {
647 <      conf = node->data;
648 <
649 <      if (EmptyString(conf->name))
650 <        continue;
651 <
652 <      if (irccmp(conf->name, name) == 0)
653 <      {
654 <        if ((user == NULL && (host == NULL)))
655 <          return conf;
656 <        if (EmptyString(conf->user) || EmptyString(conf->host))
657 <          return conf;
658 <        if (!match(conf->user, user) && !match(conf->host, host))
659 <          return conf;
660 <      }
661 <    }
662 <    break;
508 >    struct MaskItem *conf = node->data;
509  
510 <  case CONF_OPER:
665 <    DLINK_FOREACH(node, list->head)
510 >    if (!irccmp(conf->name, name))
511      {
512 <      conf = node->data;
513 <
669 <      if (EmptyString(conf->name))
670 <        continue;
512 >      if (!who)
513 >        return conf;
514  
515 <      if (!irccmp(conf->name, name))
515 >      if (!match(conf->user, who->username))
516        {
517 <        if (!who)
675 <          return conf;
676 <        if (EmptyString(conf->user) || EmptyString(conf->host))
677 <          return NULL;
678 <        if (!match(conf->user, who->username))
517 >        switch (conf->htype)
518          {
519 <          switch (conf->htype)
520 <          {
521 <            case HM_HOST:
522 <              if (!match(conf->host, who->host) || !match(conf->host, who->sockhost))
519 >          case HM_HOST:
520 >            if (!match(conf->host, who->host) || !match(conf->host, who->sockhost))
521 >              if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
522 >                return conf;
523 >            break;
524 >          case HM_IPV4:
525 >            if (who->ip.ss.ss_family == AF_INET)
526 >              if (match_ipv4(&who->ip, &conf->addr, conf->bits))
527                  if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
528                    return conf;
529 <              break;
530 <            case HM_IPV4:
531 <              if (who->connection->aftype == AF_INET)
532 <                if (match_ipv4(&who->connection->ip, &conf->addr, conf->bits))
533 <                  if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
534 <                    return conf;
535 <              break;
536 <            case HM_IPV6:
537 <              if (who->connection->aftype == AF_INET6)
695 <                if (match_ipv6(&who->connection->ip, &conf->addr, conf->bits))
696 <                  if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
697 <                    return conf;
698 <              break;
699 <            default:
700 <              assert(0);
701 <          }
529 >            break;
530 >          case HM_IPV6:
531 >            if (who->ip.ss.ss_family == AF_INET6)
532 >              if (match_ipv6(&who->ip, &conf->addr, conf->bits))
533 >                if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
534 >                  return conf;
535 >            break;
536 >          default:
537 >            assert(0);
538          }
539        }
540      }
705
706    break;
707
708  case CONF_SERVER:
709    DLINK_FOREACH(node, list->head)
710    {
711      conf = node->data;
712
713      if (EmptyString(conf->name))
714        continue;
715
716      if (name == NULL)
717      {
718        if (EmptyString(conf->host))
719          continue;
720        if (irccmp(conf->host, host) == 0)
721          return conf;
722      }
723      else if (irccmp(conf->name, name) == 0)
724        return conf;
725    }
726
727    break;
728
729  default:
730    break;
541    }
542  
543    return NULL;
# Line 763 | Line 573 | set_default_conf(void)
573    ConfigServerInfo.max_topic_length = 80;
574    ConfigServerInfo.hub = 0;
575  
576 <  log_del_all();
576 >  log_iterate(log_free);
577  
578    ConfigLog.use_logging = 1;
579  
# Line 771 | Line 581 | set_default_conf(void)
581    ConfigChannel.invite_client_count = 10;
582    ConfigChannel.invite_client_time = 300;
583    ConfigChannel.invite_delay_channel = 5;
584 +  ConfigChannel.invite_expire_time = 1800;
585    ConfigChannel.knock_client_count = 1;
586    ConfigChannel.knock_client_time = 300;
587    ConfigChannel.knock_delay_channel = 60;
588    ConfigChannel.max_channels = 25;
589 <  ConfigChannel.max_bans = 25;
589 >  ConfigChannel.max_invites = 20;
590 >  ConfigChannel.max_bans = 100;
591 >  ConfigChannel.max_bans_large = 500;
592    ConfigChannel.default_join_flood_count = 18;
593    ConfigChannel.default_join_flood_time = 6;
594  
# Line 791 | Line 604 | set_default_conf(void)
604    ConfigGeneral.away_count = 2;
605    ConfigGeneral.away_time = 10;
606    ConfigGeneral.max_watch = 50;
607 +  ConfigGeneral.whowas_history_length = 15000;
608    ConfigGeneral.cycle_on_host_change = 1;
609    ConfigGeneral.dline_min_cidr = 16;
610    ConfigGeneral.dline_min_cidr6 = 48;
# Line 802 | Line 616 | set_default_conf(void)
616    ConfigGeneral.disable_auth = 0;
617    ConfigGeneral.kill_chase_time_limit = 90;
618    ConfigGeneral.default_floodcount = 8;
619 +  ConfigGeneral.default_floodtime = 1;
620    ConfigGeneral.failed_oper_notice = 1;
621    ConfigGeneral.dots_in_ident = 0;
622    ConfigGeneral.min_nonwildcard = 4;
# Line 822 | Line 637 | set_default_conf(void)
637    ConfigGeneral.stats_P_oper_only = 0;
638    ConfigGeneral.stats_u_oper_only = 0;
639    ConfigGeneral.caller_id_wait = 60;
640 <  ConfigGeneral.opers_bypass_callerid = 0;
640 >  ConfigGeneral.opers_bypass_callerid = 1;
641    ConfigGeneral.pace_wait = 10;
642    ConfigGeneral.pace_wait_simple = 1;
643    ConfigGeneral.short_motd = 0;
# Line 856 | Line 671 | validate_conf(void)
671   static void
672   read_conf(FILE *file)
673   {
674 <  lineno = 0;
674 >  lineno = 1;
675  
676    set_default_conf();  /* Set default values prior to conf parsing */
677    conf_parser_ctx.pass = 1;
# Line 868 | Line 683 | read_conf(FILE *file)
683    yyparse();  /* Load the values from the conf */
684    validate_conf();  /* Check to make sure some values are still okay. */
685                      /* Some global values are also loaded here. */
686 +  whowas_trim();  /* Attempt to trim whowas list if necessary */
687    class_delete_marked();  /* Delete unused classes that are marked for deletion */
688   }
689  
# Line 878 | Line 694 | read_conf(FILE *file)
694   * called as a result of the server receiving a HUP signal.
695   */
696   void
697 < conf_rehash(int sig)
697 > conf_rehash(bool sig)
698   {
699 <  if (sig)
699 >  if (sig == true)
700 >  {
701      sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
702                           "Got signal SIGHUP, reloading configuration file(s)");
703 +    ilog(LOG_TYPE_IRCD, "Got signal SIGHUP, reloading configuration file(s)");
704 +  }
705  
706    restart_resolver();
707  
708    /* don't close listeners until we know we can go ahead with the rehash */
709  
710 <  read_conf_files(0);
710 >  read_conf_files(false);
711  
712    load_conf_modules();
713    check_conf_klines();
# Line 952 | Line 771 | conf_connect_allowed(struct irc_ssaddr *
771      return BANNED_CLIENT;
772    }
773  
774 <  ip_found = ipcache_find_or_add_address(addr);
774 >  ip_found = ipcache_record_find_or_add(addr);
775  
776    if ((CurrentTime - ip_found->last_attempt) < ConfigGeneral.throttle_time)
777    {
# Line 968 | Line 787 | conf_connect_allowed(struct irc_ssaddr *
787    return 0;
788   }
789  
971 /* expire_tklines()
972 *
973 * inputs       - tkline list pointer
974 * output       - NONE
975 * side effects - expire tklines
976 */
977 static void
978 expire_tklines(dlink_list *list)
979 {
980  dlink_node *node = NULL, *node_next = NULL;
981
982  DLINK_FOREACH_SAFE(node, node_next, list->head)
983  {
984    struct MaskItem *conf = node->data;
985
986    if (!conf->until || conf->until > CurrentTime)
987      continue;
988
989    if (ConfigGeneral.tkline_expire_notices)
990      sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "Temporary %s for [%s] expired",
991                           (conf->type == CONF_XLINE) ? "X-line" : "RESV", conf->name);
992    conf_free(conf);
993  }
994 }
995
790   /* cleanup_tklines()
791   *
792   * inputs       - NONE
# Line 1004 | Line 798 | void
798   cleanup_tklines(void *unused)
799   {
800    hostmask_expire_temporary();
801 <  expire_tklines(&gecos_items);
802 <  expire_tklines(&nresv_items);
1009 <  expire_tklines(&cresv_items);
801 >  gecos_expire();
802 >  resv_expire();
803   }
804  
805   /* oper_privs_as_string()
# Line 1054 | Line 847 | static const struct oper_flags
847   const char *
848   oper_privs_as_string(const unsigned int flags)
849   {
850 <  static char buf[sizeof(flag_table) / sizeof(struct oper_flags)];
850 >  static char buf[sizeof(flag_table) / sizeof(flag_table[0])];
851    char *p = buf;
852  
853    for (const struct oper_flags *tab = flag_table; tab->flag; ++tab)
# Line 1122 | Line 915 | clear_out_old_conf(void)
915   {
916    dlink_node *node = NULL, *node_next = NULL;
917    dlink_list *free_items [] = {
918 <    &server_items,   &operator_items,
1126 <     &gecos_items,
1127 <     &nresv_items, &service_items, &cresv_items, NULL
918 >    &connect_items, &operator_items, NULL
919    };
920  
921    dlink_list ** iterator = free_items; /* C is dumb */
# Line 1139 | Line 930 | clear_out_old_conf(void)
930      {
931        struct MaskItem *conf = node->data;
932  
933 <      conf->active = 0;
933 >      conf->active = false;
934 >      dlinkDelete(&conf->node, *iterator);
935  
936 <      if (!IsConfDatabase(conf))
937 <      {
1146 <        dlinkDelete(&conf->node, *iterator);
1147 <
1148 <        if (!conf->ref_count)
1149 <          conf_free(conf);
1150 <      }
936 >      if (!conf->ref_count)
937 >        conf_free(conf);
938      }
939    }
940  
1154  motd_clear();  /* Clear motd {} items and re-cache default motd */
1155
941    /*
942     * Don't delete the class table, rather mark all entries for deletion.
943     * The table is cleaned up by class_delete_marked. - avalon
# Line 1161 | Line 946 | clear_out_old_conf(void)
946  
947    clear_out_address_conf();
948  
949 <  mod_clear_paths();  /* Clear modules {} items */
949 >  modules_conf_clear();  /* Clear modules {} items */
950  
951    motd_clear();  /* Clear motd {} items and re-cache default motd */
952  
953    cluster_clear();  /* Clear cluster {} items */
954  
955 +  gecos_clear();  /* Clear gecos {} items */
956 +
957 +  resv_clear();  /* Clear resv {} items */
958 +
959 +  service_clear();  /* Clear service {} items */
960 +
961    shared_clear();  /* Clear shared {} items */
962  
963    pseudo_clear();  /* Clear pseudo {} items */
# Line 1178 | Line 969 | clear_out_old_conf(void)
969    ConfigServerInfo.network_name = NULL;
970    xfree(ConfigServerInfo.network_desc);
971    ConfigServerInfo.network_desc = NULL;
1181
972    xfree(ConfigServerInfo.rsa_private_key_file);
973    ConfigServerInfo.rsa_private_key_file = NULL;
974    xfree(ConfigServerInfo.ssl_certificate_file);
# Line 1200 | Line 990 | clear_out_old_conf(void)
990    xfree(ConfigAdminInfo.description);
991    ConfigAdminInfo.description = NULL;
992  
993 +  /* Clean out ConfigServerHide */
994    xfree(ConfigServerHide.flatten_links_file);
995    ConfigServerHide.flatten_links_file = NULL;
996 +  xfree(ConfigServerHide.hidden_name);
997 +  ConfigServerHide.hidden_name = NULL;
998  
999    /* Clean out listeners */
1000    listener_close_marked();
1001   }
1002  
1003   static void
1004 < conf_handle_tls(int cold)
1004 > conf_handle_tls(bool cold)
1005   {
1006 <  if (!tls_new_cred())
1006 >  if (tls_new_cred() == false)
1007    {
1008 <    if (cold)
1008 >    if (cold == true)
1009      {
1010        ilog(LOG_TYPE_IRCD, "Error while initializing TLS");
1011        exit(EXIT_FAILURE);
# Line 1233 | Line 1026 | conf_handle_tls(int cold)
1026   * side effects - read all conf files needed, ircd.conf kline.conf etc.
1027   */
1028   void
1029 < read_conf_files(int cold)
1029 > read_conf_files(bool cold)
1030   {
1031    const char *filename = NULL;
1032    char chanmodes[IRCD_BUFSIZE] = "";
# Line 1252 | Line 1045 | read_conf_files(int cold)
1045  
1046    if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL)
1047    {
1048 <    if (cold)
1048 >    if (cold == true)
1049      {
1050        ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
1051             filename, strerror(errno));
# Line 1267 | Line 1060 | read_conf_files(int cold)
1060      }
1061    }
1062  
1063 <  if (!cold)
1063 >  if (cold == false)
1064      clear_out_old_conf();
1065  
1066    read_conf(conf_parser_ctx.conf_file);
1067    fclose(conf_parser_ctx.conf_file);
1068  
1069 <  log_reopen_all();
1069 >  log_iterate(log_reopen);
1070    conf_handle_tls(cold);
1071  
1072    isupport_add("NICKLEN", NULL, ConfigServerInfo.max_nick_length);
# Line 1287 | Line 1080 | read_conf_files(int cold)
1080    snprintf(chanlimit, sizeof(chanlimit), "#:%u",
1081             ConfigChannel.max_channels);
1082    isupport_add("CHANLIMIT", chanlimit, -1);
1083 <  snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,cimnprstCMORST");
1083 >  snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,cimnprstuCLMNORST");
1084    isupport_add("CHANNELLEN", NULL, CHANNELLEN);
1085    isupport_add("TOPICLEN", NULL, ConfigServerInfo.max_topic_length);
1086    isupport_add("CHANMODES", chanmodes, -1);
1294
1295  /*
1296   * message_locale may have changed.  rebuild isupport since it relies
1297   * on strlen(form_str(RPL_ISUPPORT))
1298   */
1299  isupport_rebuild();
1087   }
1088  
1089   /* conf_add_class_to_conf()
# Line 1308 | Line 1095 | read_conf_files(int cold)
1095   void
1096   conf_add_class_to_conf(struct MaskItem *conf, const char *name)
1097   {
1098 <  if (EmptyString(name) || (conf->class = class_find(name, 1)) == NULL)
1098 >  if (EmptyString(name) || (conf->class = class_find(name, true)) == NULL)
1099    {
1100      conf->class = class_default;
1101  
# Line 1332 | Line 1119 | conf_add_class_to_conf(struct MaskItem *
1119   void
1120   yyerror(const char *msg)
1121   {
1335  char newlinebuf[IRCD_BUFSIZE];
1336
1122    if (conf_parser_ctx.pass != 1)
1123      return;
1124  
1125 <  strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1125 >  const char *p = stripws(linebuf);
1126    sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1127                         "\"%s\", line %u: %s: %s",
1128 <                       conffilebuf, lineno + 1, msg, newlinebuf);
1128 >                       conffilebuf, lineno, msg, p);
1129    ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1130 <       conffilebuf, lineno + 1, msg, newlinebuf);
1130 >       conffilebuf, lineno, msg, p);
1131   }
1132  
1133   void
1134   conf_error_report(const char *msg)
1135   {
1136 <  char newlinebuf[IRCD_BUFSIZE];
1352 <
1353 <  strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1136 >  const char *p = stripws(linebuf);
1137    sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1138                         "\"%s\", line %u: %s: %s",
1139 <                       conffilebuf, lineno + 1, msg, newlinebuf);
1139 >                       conffilebuf, lineno, msg, p);
1140    ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1141 <       conffilebuf, lineno + 1, msg, newlinebuf);
1141 >       conffilebuf, lineno, msg, p);
1142   }
1143  
1144   /*
# Line 1368 | Line 1151 | conf_error_report(const char *msg)
1151   * side effects - none
1152   * Originally written by Dianora (Diane, db@db.net)
1153   */
1154 < time_t
1154 > uintmax_t
1155   valid_tkline(const char *data, const int minutes)
1156   {
1157    const unsigned char *p = (const unsigned char *)data;
1158    unsigned char tmpch = '\0';
1159 <  time_t result = 0;
1159 >  uintmax_t result = 0;
1160  
1161    while ((tmpch = *p++))
1162    {
# Line 1396 | Line 1179 | valid_tkline(const char *data, const int
1179     * If the incoming time is in seconds convert it to minutes for the purpose
1180     * of this calculation
1181     */
1182 <  if (!minutes)
1182 >  if (minutes == 0)
1183      result = result / 60;
1184  
1185    if (result > MAX_TDKLINE_TIME)
# Line 1413 | Line 1196 | valid_tkline(const char *data, const int
1196   * outputs      - 1 if valid, else 0
1197   * side effects - none
1198   */
1199 < int
1199 > bool
1200   valid_wild_card_simple(const char *data)
1201   {
1202    const unsigned char *p = (const unsigned char *)data;
# Line 1426 | Line 1209 | valid_wild_card_simple(const char *data)
1209      {
1210        ++p;
1211        if (++nonwild >= ConfigGeneral.min_nonwildcard_simple)
1212 <        return 1;
1212 >        return true;
1213      }
1214      else if (!IsMWildChar(tmpch))
1215      {
1216        if (++nonwild >= ConfigGeneral.min_nonwildcard_simple)
1217 <        return 1;
1217 >        return true;
1218      }
1219      else
1220        ++wild;
1221    }
1222  
1223 <  return !wild;
1223 >  return wild == 0;
1224   }
1225  
1226   /* valid_wild_card()
# Line 1448 | Line 1231 | valid_wild_card_simple(const char *data)
1231   * output       - 0 if not valid, 1 if valid
1232   * side effects - NOTICE is given to source_p if warn is 1
1233   */
1234 < int
1235 < valid_wild_card(struct Client *source_p, int count, ...)
1234 > bool
1235 > valid_wild_card(int count, ...)
1236   {
1237    unsigned char tmpch = '\0';
1238    unsigned int nonwild = 0;
# Line 1486 | Line 1269 | valid_wild_card(struct Client *source_p,
1269          if (++nonwild >= ConfigGeneral.min_nonwildcard)
1270          {
1271            va_end(args);
1272 <          return 1;
1272 >          return true;
1273          }
1274        }
1275      }
1276    }
1277  
1495  if (IsClient(source_p))
1496    sendto_one_notice(source_p, &me,
1497                      ":Please include at least %u non-wildcard characters with the mask",
1498                      ConfigGeneral.min_nonwildcard);
1278    va_end(args);
1279 <  return 0;
1501 < }
1502 <
1503 < /* find_user_host()
1504 < *
1505 < * inputs       - pointer to client placing kline
1506 < *              - pointer to user_host_or_nick
1507 < *              - pointer to user buffer
1508 < *              - pointer to host buffer
1509 < * output       - 0 if not ok to kline, 1 to kline i.e. if valid user host
1510 < * side effects -
1511 < */
1512 < static int
1513 < find_user_host(struct Client *source_p, char *user_host_or_nick,
1514 <               char *luser, char *lhost)
1515 < {
1516 <  struct Client *target_p = NULL;
1517 <  char *hostp = NULL;
1518 <
1519 <  if (lhost == NULL)
1520 <  {
1521 <    strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
1522 <    return 1;
1523 <  }
1524 <
1525 <  if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
1526 <  {
1527 <    /* Explicit user@host mask given */
1528 <    if (hostp)                            /* I'm a little user@host */
1529 <    {
1530 <      *(hostp++) = '\0';                       /* short and squat */
1531 <
1532 <      if (*user_host_or_nick)
1533 <        strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
1534 <      else
1535 <        strcpy(luser, "*");
1536 <
1537 <      if (*hostp)
1538 <        strlcpy(lhost, hostp, HOSTLEN + 1);    /* here is my host */
1539 <      else
1540 <        strcpy(lhost, "*");
1541 <    }
1542 <    else
1543 <    {
1544 <      luser[0] = '*';             /* no @ found, assume its *@somehost */
1545 <      luser[1] = '\0';
1546 <      strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
1547 <    }
1548 <
1549 <    return 1;
1550 <  }
1551 <  else
1552 <  {
1553 <    /* Try to find user@host mask from nick */
1554 <    /* Okay to use source_p as the first param, because source_p == client_p */
1555 <    if ((target_p =
1556 <        find_chasing(source_p, user_host_or_nick)) == NULL)
1557 <      return 0;  /* find_chasing sends ERR_NOSUCHNICK */
1558 <
1559 <    if (HasFlag(target_p, FLAGS_EXEMPTKLINE))
1560 <    {
1561 <      if (IsClient(source_p))
1562 <        sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
1563 <      return 0;
1564 <    }
1565 <
1566 <    /*
1567 <     * Turn the "user" bit into "*user", blow away '~'
1568 <     * if found in original user name (non-idented)
1569 <     */
1570 <    strlcpy(luser, target_p->username, USERLEN*4 + 1);
1571 <
1572 <    if (target_p->username[0] == '~')
1573 <      luser[0] = '*';
1574 <
1575 <    strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
1576 <    return 1;
1577 <  }
1578 <
1579 <  return 0;
1279 >  return false;
1280   }
1281  
1282   /* XXX should this go into a separate file ? -Dianora */
# Line 1609 | Line 1309 | find_user_host(struct Client *source_p,
1309   *
1310   * - Dianora
1311   */
1312 < int
1313 < parse_aline(const char *cmd, struct Client *source_p,
1614 <            int parc, char **parv,
1615 <            int parse_flags, char **up_p, char **h_p, time_t *tkline_time,
1616 <            char **target_server, char **reason)
1312 > bool
1313 > parse_aline(const char *cmd, struct Client *source_p, int parc, char **parv, struct aline_ctx *aline)
1314   {
1618  int found_tkline_time=0;
1315    static char default_reason[] = CONF_NOREASON;
1316 <  static char user[USERLEN*4+1];
1317 <  static char host[HOSTLEN*4+1];
1622 <
1623 <  parv++;
1624 <  parc--;
1316 >  static char user[USERLEN * 2 + 1];
1317 >  static char host[HOSTLEN * 2 + 1];
1318  
1319 <  found_tkline_time = valid_tkline(*parv, TK_MINUTES);
1319 >  ++parv;
1320 >  --parc;
1321  
1322 <  if (found_tkline_time)
1322 >  if (aline->add == true && (aline->duration = valid_tkline(*parv, TK_MINUTES)))
1323    {
1324 <    parv++;
1325 <    parc--;
1632 <
1633 <    if (tkline_time)
1634 <      *tkline_time = found_tkline_time;
1635 <    else
1636 <    {
1637 <      sendto_one_notice(source_p, &me, ":temp_line not supported by %s", cmd);
1638 <      return 0;
1639 <    }
1324 >    ++parv;
1325 >    --parc;
1326    }
1327  
1328    if (parc == 0)
1329    {
1330      sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1331 <    return 0;
1331 >    return false;
1332    }
1333  
1334 <  if (h_p == NULL)
1335 <    *up_p = *parv;
1334 >  if (aline->simple_mask == true)
1335 >  {
1336 >    aline->mask = *parv;
1337 >    aline->user = NULL;
1338 >    aline->host = NULL;
1339 >  }
1340    else
1341    {
1342 <    if (find_user_host(source_p, *parv, user, host) == 0)
1653 <      return 0;
1342 >    struct split_nuh_item nuh;
1343  
1344 <    *up_p = user;
1345 <    *h_p = host;
1344 >    nuh.nuhmask  = *parv;
1345 >    nuh.nickptr  = NULL;
1346 >    nuh.userptr  = user;
1347 >    nuh.hostptr  = host;
1348 >
1349 >    nuh.nicksize = 0;
1350 >    nuh.usersize = sizeof(user);
1351 >    nuh.hostsize = sizeof(host);
1352 >
1353 >    split_nuh(&nuh);
1354 >
1355 >    aline->mask = NULL;
1356 >    aline->user = user;
1357 >    aline->host = host;
1358    }
1359  
1360 <  parc--;
1361 <  parv++;
1360 >  ++parv;
1361 >  --parc;
1362  
1363    if (parc)
1364    {
1365      if (irccmp(*parv, "ON") == 0)
1366      {
1367 <      parc--;
1368 <      parv++;
1367 >      ++parv;
1368 >      --parc;
1369  
1370        if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN))
1371        {
1372          sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "remoteban");
1373 <        return 0;
1373 >        return false;
1374        }
1375  
1376        if (parc == 0 || EmptyString(*parv))
1377        {
1378          sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1379 <        return 0;
1379 >        return false;
1380        }
1381  
1382 <      *target_server = *parv;
1383 <      parc--;
1384 <      parv++;
1382 >      aline->server = *parv;
1383 >      ++parv;
1384 >      --parc;
1385      }
1386      else
1387 <    {
1687 <      /* Make sure target_server *is* NULL if no ON server found
1688 <       * caller probably NULL'd it first, but no harm to do it again -db
1689 <       */
1690 <      if (target_server)
1691 <        *target_server = NULL;
1692 <    }
1387 >      aline->server = NULL;
1388    }
1389  
1390 <  if (h_p)
1390 >  if (aline->add == true)
1391    {
1392 <    if (strchr(user, '!'))
1393 <    {
1699 <      sendto_one_notice(source_p, &me, ":Invalid character '!' in kline");
1700 <      return 0;
1701 <    }
1702 <
1703 <    if ((parse_flags & AWILD) && !valid_wild_card(source_p, 2, *up_p, *h_p))
1704 <      return 0;
1705 <  }
1706 <  else
1707 <    if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, *up_p))
1708 <      return 0;
1709 <
1710 <  if (reason)
1711 <  {
1712 <    if (parc && !EmptyString(*parv))
1713 <      *reason = *parv;
1392 >    if (parc == 0 || EmptyString(*parv))
1393 >      aline->reason = default_reason;
1394      else
1395 <      *reason = default_reason;
1395 >      aline->reason = *parv;
1396    }
1397  
1398 <  return 1;
1398 >  return true;
1399   }
1400  
1401   /* match_conf_password()
# Line 1725 | Line 1405 | parse_aline(const char *cmd, struct Clie
1405   * output       - 1 or 0 if match
1406   * side effects - none
1407   */
1408 < int
1408 > bool
1409   match_conf_password(const char *password, const struct MaskItem *conf)
1410   {
1411    const char *encr = NULL;
1412  
1413    if (EmptyString(password) || EmptyString(conf->passwd))
1414 <    return 0;
1414 >    return false;
1415  
1416    if (conf->flags & CONF_FLAGS_ENCRYPTED)
1417      encr = crypt(password, conf->passwd);
1418    else
1419      encr = password;
1420  
1421 <  return encr && !strcmp(encr, conf->passwd);
1421 >  return encr && strcmp(encr, conf->passwd) == 0;
1422   }
1423  
1424   /*

Comparing ircd-hybrid/trunk/src/conf.c (property svn:keywords):
Revision 7230 by michael, Wed Feb 3 16:00:29 2016 UTC vs.
Revision 8682 by michael, Sun Nov 25 08:21:03 2018 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines