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

Comparing ircd-hybrid/branches/8.2.x/src/conf.c (file contents):
Revision 7725 by michael, Mon Sep 26 14:59:44 2016 UTC vs.
Revision 8902 by michael, Sun Apr 21 20:41:04 2019 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-2019 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"
# Line 50 | Line 51
51   #include "send.h"
52   #include "memory.h"
53   #include "res.h"
53 #include "userhost.h"
54   #include "user.h"
55   #include "channel_mode.h"
56 #include "parse.h"
56   #include "misc.h"
57   #include "conf_db.h"
58   #include "conf_class.h"
# Line 96 | 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));
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 113 | 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 153 | 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 172 | 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 188 | Line 187 | conf_free(struct MaskItem *conf)
187    xfree(conf->whois);
188    xfree(conf->user);
189    xfree(conf->host);
190 +  xfree(conf->addr);
191 +  xfree(conf->bind);
192    xfree(conf->cipher_list);
193  
194    DLINK_FOREACH_SAFE(node, node_next, conf->hub_list.head)
# Line 218 | Line 219 | static int
219   attach_iline(struct Client *client_p, struct MaskItem *conf)
220   {
221    const struct ClassItem *const class = conf->class;
222 <  struct ip_entry *ip_found;
222 <  int a_limit_reached = 0;
223 <  unsigned int local = 0, global = 0;
222 >  bool a_limit_reached = false;
223  
224 <  ip_found = ipcache_find_or_add_address(&client_p->connection->ip);
225 <  ip_found->count++;
224 >  struct ip_entry *ipcache = ipcache_record_find_or_add(&client_p->ip);
225 >  ++ipcache->count_local;
226    AddFlag(client_p, FLAGS_IPHASH);
227  
229  userhost_count(client_p->sockhost, &global, &local);
230
231  /* XXX blah. go down checking the various silly limits
232   * setting a_limit_reached if any limit is reached.
233   * - Dianora
234   */
228    if (class->max_total && class->ref_count >= class->max_total)
229 <    a_limit_reached = 1;
230 <  else if (class->max_perip && ip_found->count > class->max_perip)
231 <    a_limit_reached = 1;
232 <  else if (class->max_local && local >= class->max_local) /* XXX: redundant */
233 <    a_limit_reached = 1;
234 <  else if (class->max_global && global >= class->max_global)
242 <    a_limit_reached = 1;
229 >    a_limit_reached = true;
230 >  else if (class->max_perip_local && ipcache->count_local > class->max_perip_local)
231 >    a_limit_reached = true;
232 >  else if (class->max_perip_global &&
233 >           (ipcache->count_local + ipcache->count_remote) > class->max_perip_global)
234 >    a_limit_reached = true;
235  
236 <  if (a_limit_reached)
236 >  if (a_limit_reached == true)
237    {
238      if (!IsConfExemptLimits(conf))
239        return TOO_MANY;   /* Already at maximum allowed */
# Line 250 | Line 242 | attach_iline(struct Client *client_p, st
242                        "but you have exceed_limit = yes;");
243    }
244  
245 <  return attach_conf(client_p, conf);
245 >  return conf_attach(client_p, conf);
246   }
247  
248   /* verify_access()
# Line 262 | Line 254 | attach_iline(struct Client *client_p, st
254   static int
255   verify_access(struct Client *client_p)
256   {
257 <  struct MaskItem *conf = NULL;
257 >  struct MaskItem *conf;
258  
259    if (HasFlag(client_p, FLAGS_GOTID))
260 <  {
269 <    conf = find_address_conf(client_p->host, client_p->username,
270 <                             &client_p->connection->ip,
271 <                             client_p->connection->aftype,
260 >    conf = find_address_conf(client_p->host, client_p->username, &client_p->ip,
261                               client_p->connection->password);
273  }
262    else
263    {
264      char non_ident[USERLEN + 1] = "~";
265  
266      strlcpy(non_ident + 1, client_p->username, sizeof(non_ident) - 1);
267 <    conf = find_address_conf(client_p->host, non_ident,
280 <                             &client_p->connection->ip,
281 <                             client_p->connection->aftype,
267 >    conf = find_address_conf(client_p->host, non_ident, &client_p->ip,
268                               client_p->connection->password);
269    }
270  
271 <  if (!conf)
271 >  if (conf == NULL)
272      return NOT_AUTHORIZED;
273  
274    assert(IsConfClient(conf) || IsConfKill(conf));
275  
276 <  if (IsConfClient(conf))
276 >  if (IsConfKill(conf))
277    {
278 <    if (IsConfRedir(conf))
279 <    {
280 <      sendto_one_numeric(client_p, &me, RPL_REDIR,
295 <                         conf->name ? conf->name : "",
296 <                         conf->port);
297 <      return NOT_AUTHORIZED;
298 <    }
278 >    sendto_one_notice(client_p, &me, ":*** Banned: %s", conf->reason);
279 >    return BANNED_CLIENT;
280 >  }
281  
282 <    if (IsConfDoSpoofIp(conf))
283 <    {
284 <      if (IsConfSpoofNotice(conf))
285 <        sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, "%s spoofing: %s as %s",
286 <                             client_p->name, client_p->host, conf->name);
282 >  if (IsConfRedir(conf))
283 >  {
284 >    sendto_one_numeric(client_p, &me, RPL_REDIR,
285 >                       conf->name ? conf->name : "",
286 >                       conf->port);
287 >    return NOT_AUTHORIZED;
288 >  }
289  
290 <      strlcpy(client_p->host, conf->name, sizeof(client_p->host));
291 <    }
290 >  if (IsConfDoSpoofIp(conf))
291 >  {
292 >    if (IsConfSpoofNotice(conf))
293 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, "%s spoofing: %s as %s",
294 >                           client_p->name, client_p->host, conf->name);
295  
296 <    return attach_iline(client_p, conf);
296 >    strlcpy(client_p->host, conf->name, sizeof(client_p->host));
297    }
298  
299 <  sendto_one_notice(client_p, &me, ":*** Banned: %s", conf->reason);
313 <  return BANNED_CLIENT;
299 >  return attach_iline(client_p, conf);
300   }
301  
302   /* check_client()
# Line 340 | Line 326 | check_client(struct Client *source_p)
326      case TOO_MANY:
327        sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
328                             "Too many on IP for %s (%s).",
329 <                           get_client_name(source_p, SHOW_IP),
329 >                           client_get_name(source_p, SHOW_IP),
330                             source_p->sockhost);
331        ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
332 <           get_client_name(source_p, SHOW_IP));
332 >           client_get_name(source_p, SHOW_IP));
333        ++ServerStats.is_ref;
334        exit_client(source_p, "No more connections allowed on that IP");
335        break;
# Line 351 | Line 337 | check_client(struct Client *source_p)
337      case I_LINE_FULL:
338        sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
339                             "auth {} block is full for %s (%s).",
340 <                           get_client_name(source_p, SHOW_IP),
340 >                           client_get_name(source_p, SHOW_IP),
341                             source_p->sockhost);
342        ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
343 <           get_client_name(source_p, SHOW_IP));
343 >           client_get_name(source_p, SHOW_IP));
344        ++ServerStats.is_ref;
345        exit_client(source_p, "No more connections allowed in your connection class");
346        break;
# Line 364 | Line 350 | check_client(struct Client *source_p)
350        /*       a purely cosmetical change */
351        sendto_realops_flags(UMODE_UNAUTH, L_ALL, SEND_NOTICE,
352                             "Unauthorized client connection from %s on [%s/%u].",
353 <                           get_client_name(source_p, SHOW_IP),
353 >                           client_get_name(source_p, SHOW_IP),
354                             source_p->connection->listener->name,
355                             source_p->connection->listener->port);
356        ilog(LOG_TYPE_IRCD, "Unauthorized client connection from %s on [%s/%u].",
357 <           get_client_name(source_p, SHOW_IP),
357 >           client_get_name(source_p, SHOW_IP),
358             source_p->connection->listener->name,
359             source_p->connection->listener->port);
360  
# Line 389 | Line 375 | check_client(struct Client *source_p)
375    return !(i < 0);
376   }
377  
378 < /* detach_conf()
379 < *
380 < * inputs       - pointer to client to detach
381 < *              - type of conf to detach
396 < * output       - 0 for success, -1 for failure
397 < * side effects - Disassociate configuration from the client.
398 < *                Also removes a class from the list if marked for deleting.
378 > /*! \brief Disassociate configuration from the client. Also removes a class
379 > *         from the list if marked for deleting.
380 > * \param client_p Client to operate on
381 > * \param type     Type of conf to detach
382   */
383   void
384 < detach_conf(struct Client *client_p, enum maskitem_type type)
384 > conf_detach(struct Client *client_p, enum maskitem_type type)
385   {
386 <  dlink_node *node = NULL, *node_next = NULL;
386 >  dlink_node *node, *node_next;
387  
388    DLINK_FOREACH_SAFE(node, node_next, client_p->connection->confs.head)
389    {
# Line 417 | Line 400 | detach_conf(struct Client *client_p, enu
400      free_dlink_node(node);
401  
402      if (conf->type == CONF_CLIENT)
403 <      remove_from_cidr_check(&client_p->connection->ip, conf->class);
403 >      class_ip_limit_remove(conf->class, &client_p->ip);
404  
405 <    if (--conf->class->ref_count == 0 && conf->class->active == 0)
405 >    if (--conf->class->ref_count == 0 && conf->class->active == false)
406      {
407        class_free(conf->class);
408        conf->class = NULL;
409      }
410  
411 <    if (--conf->ref_count == 0 && conf->active == 0)
411 >    if (--conf->ref_count == 0 && conf->active == false)
412        conf_free(conf);
413    }
414   }
415  
416 < /* attach_conf()
417 < *
418 < * inputs       - client pointer
419 < *              - conf pointer
420 < * output       -
438 < * side effects - Associate a specific configuration entry to a *local*
439 < *                client (this is the one which used in accepting the
440 < *                connection). Note, that this automatically changes the
441 < *                attachment if there was an old one...
416 > /*! \brief Associate a specific configuration entry to a *local* client (this
417 > *         is the one which used in accepting the connection). Note, that this
418 > *         automatically changes the attachment if there was an old one.
419 > * \param client_p Client to attach the conf to
420 > * \param conf Configuration record to attach
421   */
422   int
423 < attach_conf(struct Client *client_p, struct MaskItem *conf)
423 > conf_attach(struct Client *client_p, struct MaskItem *conf)
424   {
425    if (dlinkFind(&client_p->connection->confs, conf))
426      return 1;
427  
428    if (conf->type == CONF_CLIENT)
429 <    if (cidr_limit_reached(IsConfExemptLimits(conf),
451 <                           &client_p->connection->ip, conf->class))
429 >    if (class_ip_limit_add(conf->class, &client_p->ip, IsConfExemptLimits(conf)) == true)
430        return TOO_MANY;    /* Already at maximum allowed */
431  
432    conf->class->ref_count++;
# Line 459 | Line 437 | attach_conf(struct Client *client_p, str
437    return 0;
438   }
439  
462 /* attach_connect_block()
463 *
464 * inputs       - pointer to server to attach
465 *              - name of server
466 *              - hostname of server
467 * output       - true (1) if both are found, otherwise return false (0)
468 * side effects - find connect block and attach them to connecting client
469 */
470 int
471 attach_connect_block(struct Client *client_p, const char *name,
472                     const char *host)
473 {
474  dlink_node *node = NULL;
475
476  assert(host);
477
478  DLINK_FOREACH(node, connect_items.head)
479  {
480    struct MaskItem *conf = node->data;
481
482    if (irccmp(conf->name, name) ||
483        irccmp(conf->host, host))
484      continue;
485
486    attach_conf(client_p, conf);
487    return 1;
488  }
489
490  return 0;
491 }
492
440   /* find_conf_name()
441   *
442   * inputs       - pointer to conf link list to search
# Line 518 | Line 465 | find_conf_name(dlink_list *list, const c
465    return NULL;
466   }
467  
468 < /* find_matching_name_conf()
469 < *
470 < * inputs       - type of link list to look in
524 < *              - pointer to name string to find
525 < *              - pointer to user
526 < *              - pointer to host
527 < *              - optional flags to match on as well
528 < * output       - NULL or pointer to found struct MaskItem
529 < * side effects - looks for a match on name field
468 > /*! \brief Find a connect {} conf that has a name that matches \a name.
469 > * \param name Name to match
470 > * \param compare Pointer to function to be used for string matching
471   */
472   struct MaskItem *
473 < connect_find(const char *name, const char *host, int (*compare)(const char *, const char *))
473 > connect_find(const char *name, int (*compare)(const char *, const char *))
474   {
475 <  dlink_node *node = NULL;
475 >  dlink_node *node;
476  
477    DLINK_FOREACH(node, connect_items.head)
478    {
479      struct MaskItem *conf = node->data;
480  
481 <    if (name && !compare(name, conf->name))
541 <      return conf;
542 <    if (host && !compare(host, conf->host))
481 >    if (!compare(name, conf->name))
482        return conf;
483    }
484  
# Line 579 | Line 518 | operator_find(const struct Client *who,
518                  return conf;
519              break;
520            case HM_IPV4:
521 <            if (who->connection->aftype == AF_INET)
522 <              if (match_ipv4(&who->connection->ip, &conf->addr, conf->bits))
521 >            if (who->ip.ss.ss_family == AF_INET)
522 >              if (match_ipv4(&who->ip, conf->addr, conf->bits))
523                  if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
524                    return conf;
525              break;
526            case HM_IPV6:
527 <            if (who->connection->aftype == AF_INET6)
528 <              if (match_ipv6(&who->connection->ip, &conf->addr, conf->bits))
527 >            if (who->ip.ss.ss_family == AF_INET6)
528 >              if (match_ipv6(&who->ip, conf->addr, conf->bits))
529                  if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
530                    return conf;
531              break;
# Line 619 | Line 558 | set_default_conf(void)
558  
559    ConfigServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
560    ConfigServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
622
623  memset(&ConfigServerInfo.ip, 0, sizeof(ConfigServerInfo.ip));
624  ConfigServerInfo.specific_ipv4_vhost = 0;
625  memset(&ConfigServerInfo.ip6, 0, sizeof(ConfigServerInfo.ip6));
626  ConfigServerInfo.specific_ipv6_vhost = 0;
627
561    ConfigServerInfo.default_max_clients = MAXCLIENTS_MAX;
562    ConfigServerInfo.max_nick_length = 9;
563    ConfigServerInfo.max_topic_length = 80;
564    ConfigServerInfo.hub = 0;
632  ConfigServerInfo.libgeoip_database_options = 0;
565  
566 <  log_del_all();
566 >  log_iterate(log_free);
567  
568    ConfigLog.use_logging = 1;
569  
# Line 639 | Line 571 | set_default_conf(void)
571    ConfigChannel.invite_client_count = 10;
572    ConfigChannel.invite_client_time = 300;
573    ConfigChannel.invite_delay_channel = 5;
574 +  ConfigChannel.invite_expire_time = 1800;
575    ConfigChannel.knock_client_count = 1;
576    ConfigChannel.knock_client_time = 300;
577    ConfigChannel.knock_delay_channel = 60;
578    ConfigChannel.max_channels = 25;
579 <  ConfigChannel.max_bans = 25;
579 >  ConfigChannel.max_invites = 20;
580 >  ConfigChannel.max_bans = 100;
581 >  ConfigChannel.max_bans_large = 500;
582    ConfigChannel.default_join_flood_count = 18;
583    ConfigChannel.default_join_flood_time = 6;
584  
# Line 667 | Line 602 | set_default_conf(void)
602    ConfigGeneral.kline_min_cidr6 = 48;
603    ConfigGeneral.invisible_on_connect = 1;
604    ConfigGeneral.tkline_expire_notices = 1;
670  ConfigGeneral.ignore_bogus_ts = 0;
605    ConfigGeneral.disable_auth = 0;
606    ConfigGeneral.kill_chase_time_limit = 90;
607    ConfigGeneral.default_floodcount = 8;
608 +  ConfigGeneral.default_floodtime = 1;
609    ConfigGeneral.failed_oper_notice = 1;
610    ConfigGeneral.dots_in_ident = 0;
611    ConfigGeneral.min_nonwildcard = 4;
# Line 691 | Line 626 | set_default_conf(void)
626    ConfigGeneral.stats_P_oper_only = 0;
627    ConfigGeneral.stats_u_oper_only = 0;
628    ConfigGeneral.caller_id_wait = 60;
629 <  ConfigGeneral.opers_bypass_callerid = 0;
629 >  ConfigGeneral.opers_bypass_callerid = 1;
630    ConfigGeneral.pace_wait = 10;
631    ConfigGeneral.pace_wait_simple = 1;
632    ConfigGeneral.short_motd = 0;
# Line 725 | Line 660 | validate_conf(void)
660   static void
661   read_conf(FILE *file)
662   {
663 <  lineno = 0;
663 >  lineno = 1;
664  
665    set_default_conf();  /* Set default values prior to conf parsing */
666    conf_parser_ctx.pass = 1;
# Line 748 | Line 683 | read_conf(FILE *file)
683   * called as a result of the server receiving a HUP signal.
684   */
685   void
686 < conf_rehash(int sig)
686 > conf_rehash(bool sig)
687   {
688 <  if (sig)
688 >  if (sig == true)
689    {
690      sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
691                           "Got signal SIGHUP, reloading configuration file(s)");
# Line 761 | Line 696 | conf_rehash(int sig)
696  
697    /* don't close listeners until we know we can go ahead with the rehash */
698  
699 <  read_conf_files(0);
699 >  read_conf_files(false);
700  
701    load_conf_modules();
702    check_conf_klines();
# Line 797 | Line 732 | lookup_confhost(struct MaskItem *conf)
732  
733    assert(res);
734  
735 <  memcpy(&conf->addr, res->ai_addr, res->ai_addrlen);
736 <  conf->addr.ss_len = res->ai_addrlen;
802 <  conf->addr.ss.ss_family = res->ai_family;
735 >  memcpy(conf->addr, res->ai_addr, res->ai_addrlen);
736 >  conf->addr->ss_len = res->ai_addrlen;
737  
738    freeaddrinfo(res);
739   }
# Line 812 | Line 746 | lookup_confhost(struct MaskItem *conf)
746   * side effects - none
747   */
748   int
749 < conf_connect_allowed(struct irc_ssaddr *addr, int aftype)
749 > conf_connect_allowed(struct irc_ssaddr *addr)
750   {
751    struct ip_entry *ip_found = NULL;
752 <  const struct MaskItem *conf = find_dline_conf(addr, aftype);
752 >  const struct MaskItem *conf = find_dline_conf(addr);
753  
754    if (conf)
755    {
# Line 825 | Line 759 | conf_connect_allowed(struct irc_ssaddr *
759      return BANNED_CLIENT;
760    }
761  
762 <  ip_found = ipcache_find_or_add_address(addr);
762 >  ip_found = ipcache_record_find_or_add(addr);
763  
764 <  if ((CurrentTime - ip_found->last_attempt) < ConfigGeneral.throttle_time)
764 >  if ((event_base->time.sec_monotonic - ip_found->last_attempt) < ConfigGeneral.throttle_time)
765    {
766      if (ip_found->connection_count >= ConfigGeneral.throttle_count)
767        return TOO_FAST;
# Line 837 | Line 771 | conf_connect_allowed(struct irc_ssaddr *
771    else
772      ip_found->connection_count = 1;
773  
774 <  ip_found->last_attempt = CurrentTime;
774 >  ip_found->last_attempt = event_base->time.sec_monotonic;
775    return 0;
776   }
777  
# Line 901 | Line 835 | static const struct oper_flags
835   const char *
836   oper_privs_as_string(const unsigned int flags)
837   {
838 <  static char buf[sizeof(flag_table) / sizeof(struct oper_flags)];
838 >  static char buf[sizeof(flag_table) / sizeof(flag_table[0])];
839    char *p = buf;
840  
841    for (const struct oper_flags *tab = flag_table; tab->flag; ++tab)
# Line 984 | Line 918 | clear_out_old_conf(void)
918      {
919        struct MaskItem *conf = node->data;
920  
921 <      conf->active = 0;
921 >      conf->active = false;
922        dlinkDelete(&conf->node, *iterator);
923  
924        if (!conf->ref_count)
# Line 1016 | Line 950 | clear_out_old_conf(void)
950  
951    pseudo_clear();  /* Clear pseudo {} items */
952  
1019 #ifdef HAVE_LIBGEOIP
1020  GeoIP_delete(GeoIPv4_ctx);
1021  GeoIPv4_ctx = NULL;
1022  GeoIP_delete(GeoIPv6_ctx);
1023  GeoIPv6_ctx = NULL;
1024 #endif
1025
953    /* Clean out ConfigServerInfo */
954    xfree(ConfigServerInfo.description);
955    ConfigServerInfo.description = NULL;
# Line 1030 | Line 957 | clear_out_old_conf(void)
957    ConfigServerInfo.network_name = NULL;
958    xfree(ConfigServerInfo.network_desc);
959    ConfigServerInfo.network_desc = NULL;
1033  xfree(ConfigServerInfo.libgeoip_ipv6_database_file);
1034  ConfigServerInfo.libgeoip_ipv6_database_file = NULL;
1035  xfree(ConfigServerInfo.libgeoip_ipv4_database_file);
1036  ConfigServerInfo.libgeoip_ipv4_database_file = NULL;
960    xfree(ConfigServerInfo.rsa_private_key_file);
961    ConfigServerInfo.rsa_private_key_file = NULL;
962    xfree(ConfigServerInfo.ssl_certificate_file);
# Line 1055 | Line 978 | clear_out_old_conf(void)
978    xfree(ConfigAdminInfo.description);
979    ConfigAdminInfo.description = NULL;
980  
981 +  /* Clean out ConfigServerHide */
982    xfree(ConfigServerHide.flatten_links_file);
983    ConfigServerHide.flatten_links_file = NULL;
984 +  xfree(ConfigServerHide.hidden_name);
985 +  ConfigServerHide.hidden_name = NULL;
986  
987    /* Clean out listeners */
988    listener_close_marked();
989   }
990  
991   static void
992 < conf_handle_tls(int cold)
992 > conf_handle_tls(bool cold)
993   {
994 <  if (!tls_new_cred())
994 >  if (tls_new_cred() == false)
995    {
996 <    if (cold)
996 >    if (cold == true)
997      {
998        ilog(LOG_TYPE_IRCD, "Error while initializing TLS");
999        exit(EXIT_FAILURE);
# Line 1088 | Line 1014 | conf_handle_tls(int cold)
1014   * side effects - read all conf files needed, ircd.conf kline.conf etc.
1015   */
1016   void
1017 < read_conf_files(int cold)
1017 > read_conf_files(bool cold)
1018   {
1019    const char *filename = NULL;
1020    char chanmodes[IRCD_BUFSIZE] = "";
# Line 1107 | Line 1033 | read_conf_files(int cold)
1033  
1034    if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL)
1035    {
1036 <    if (cold)
1036 >    if (cold == true)
1037      {
1038        ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
1039             filename, strerror(errno));
# Line 1122 | Line 1048 | read_conf_files(int cold)
1048      }
1049    }
1050  
1051 <  if (!cold)
1051 >  if (cold == false)
1052      clear_out_old_conf();
1053  
1054    read_conf(conf_parser_ctx.conf_file);
1055    fclose(conf_parser_ctx.conf_file);
1056  
1057 <  log_reopen_all();
1057 >  log_iterate(log_reopen);
1058    conf_handle_tls(cold);
1059  
1060    isupport_add("NICKLEN", NULL, ConfigServerInfo.max_nick_length);
# Line 1142 | Line 1068 | read_conf_files(int cold)
1068    snprintf(chanlimit, sizeof(chanlimit), "#:%u",
1069             ConfigChannel.max_channels);
1070    isupport_add("CHANLIMIT", chanlimit, -1);
1071 <  snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,cimnprstCMORST");
1071 >  snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,cimnprstuCLMNORST");
1072    isupport_add("CHANNELLEN", NULL, CHANNELLEN);
1073    isupport_add("TOPICLEN", NULL, ConfigServerInfo.max_topic_length);
1074    isupport_add("CHANMODES", chanmodes, -1);
# Line 1157 | Line 1083 | read_conf_files(int cold)
1083   void
1084   conf_add_class_to_conf(struct MaskItem *conf, const char *name)
1085   {
1086 <  if (EmptyString(name) || (conf->class = class_find(name, 1)) == NULL)
1086 >  if (EmptyString(name) || (conf->class = class_find(name, true)) == NULL)
1087    {
1088      conf->class = class_default;
1089  
# Line 1184 | Line 1110 | yyerror(const char *msg)
1110    if (conf_parser_ctx.pass != 1)
1111      return;
1112  
1113 <  char *p = stripws(linebuf);
1113 >  const char *p = stripws(linebuf);
1114    sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1115                         "\"%s\", line %u: %s: %s",
1116 <                       conffilebuf, lineno + 1, msg, p);
1116 >                       conffilebuf, lineno, msg, p);
1117    ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1118 <       conffilebuf, lineno + 1, msg, p);
1118 >       conffilebuf, lineno, msg, p);
1119   }
1120  
1121   void
1122   conf_error_report(const char *msg)
1123   {
1124 <  char *p = stripws(linebuf);
1124 >  const char *p = stripws(linebuf);
1125    sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
1126                         "\"%s\", line %u: %s: %s",
1127 <                       conffilebuf, lineno + 1, msg, linebuf);
1127 >                       conffilebuf, lineno, msg, p);
1128    ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1129 <       conffilebuf, lineno + 1, msg, linebuf);
1129 >       conffilebuf, lineno, msg, p);
1130   }
1131  
1132   /*
# Line 1241 | Line 1167 | valid_tkline(const char *data, const int
1167     * If the incoming time is in seconds convert it to minutes for the purpose
1168     * of this calculation
1169     */
1170 <  if (!minutes)
1170 >  if (minutes == 0)
1171      result = result / 60;
1172  
1173    if (result > MAX_TDKLINE_TIME)
# Line 1258 | Line 1184 | valid_tkline(const char *data, const int
1184   * outputs      - 1 if valid, else 0
1185   * side effects - none
1186   */
1187 < int
1187 > bool
1188   valid_wild_card_simple(const char *data)
1189   {
1190    const unsigned char *p = (const unsigned char *)data;
# Line 1271 | Line 1197 | valid_wild_card_simple(const char *data)
1197      {
1198        ++p;
1199        if (++nonwild >= ConfigGeneral.min_nonwildcard_simple)
1200 <        return 1;
1200 >        return true;
1201      }
1202      else if (!IsMWildChar(tmpch))
1203      {
1204        if (++nonwild >= ConfigGeneral.min_nonwildcard_simple)
1205 <        return 1;
1205 >        return true;
1206      }
1207      else
1208        ++wild;
1209    }
1210  
1211 <  return !wild;
1211 >  return wild == 0;
1212   }
1213  
1214   /* valid_wild_card()
# Line 1293 | Line 1219 | valid_wild_card_simple(const char *data)
1219   * output       - 0 if not valid, 1 if valid
1220   * side effects - NOTICE is given to source_p if warn is 1
1221   */
1222 < int
1222 > bool
1223   valid_wild_card(int count, ...)
1224   {
1225    unsigned char tmpch = '\0';
# Line 1331 | Line 1257 | valid_wild_card(int count, ...)
1257          if (++nonwild >= ConfigGeneral.min_nonwildcard)
1258          {
1259            va_end(args);
1260 <          return 1;
1260 >          return true;
1261          }
1262        }
1263      }
1264    }
1265  
1266    va_end(args);
1267 <  return 0;
1342 < }
1343 <
1344 < /* find_user_host()
1345 < *
1346 < * inputs       - pointer to client placing kline
1347 < *              - pointer to user_host_or_nick
1348 < *              - pointer to user buffer
1349 < *              - pointer to host buffer
1350 < * output       - 0 if not ok to kline, 1 to kline i.e. if valid user host
1351 < * side effects -
1352 < */
1353 < static int
1354 < find_user_host(struct Client *source_p, char *user_host_or_nick,
1355 <               char *luser, char *lhost)
1356 < {
1357 <  struct Client *target_p = NULL;
1358 <  char *hostp = NULL;
1359 <
1360 <  if (lhost == NULL)
1361 <  {
1362 <    strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
1363 <    return 1;
1364 <  }
1365 <
1366 <  if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
1367 <  {
1368 <    /* Explicit user@host mask given */
1369 <    if (hostp)                            /* I'm a little user@host */
1370 <    {
1371 <      *(hostp++) = '\0';                       /* short and squat */
1372 <
1373 <      if (*user_host_or_nick)
1374 <        strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
1375 <      else
1376 <        strcpy(luser, "*");
1377 <
1378 <      if (*hostp)
1379 <        strlcpy(lhost, hostp, HOSTLEN + 1);    /* here is my host */
1380 <      else
1381 <        strcpy(lhost, "*");
1382 <    }
1383 <    else
1384 <    {
1385 <      luser[0] = '*';             /* no @ found, assume its *@somehost */
1386 <      luser[1] = '\0';
1387 <      strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
1388 <    }
1389 <
1390 <    return 1;
1391 <  }
1392 <  else
1393 <  {
1394 <    /* Try to find user@host mask from nick */
1395 <    /* Okay to use source_p as the first param, because source_p == client_p */
1396 <    if ((target_p =
1397 <        find_chasing(source_p, user_host_or_nick)) == NULL)
1398 <      return 0;  /* find_chasing sends ERR_NOSUCHNICK */
1399 <
1400 <    if (HasFlag(target_p, FLAGS_EXEMPTKLINE))
1401 <    {
1402 <      if (IsClient(source_p))
1403 <        sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
1404 <      return 0;
1405 <    }
1406 <
1407 <    /*
1408 <     * Turn the "user" bit into "*user", blow away '~'
1409 <     * if found in original user name (non-idented)
1410 <     */
1411 <    strlcpy(luser, target_p->username, USERLEN*4 + 1);
1412 <
1413 <    if (target_p->username[0] == '~')
1414 <      luser[0] = '*';
1415 <
1416 <    strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
1417 <    return 1;
1418 <  }
1419 <
1420 <  return 0;
1267 >  return false;
1268   }
1269  
1270   /* XXX should this go into a separate file ? -Dianora */
# Line 1450 | Line 1297 | find_user_host(struct Client *source_p,
1297   *
1298   * - Dianora
1299   */
1300 < int
1301 < parse_aline(const char *cmd, struct Client *source_p,
1455 <            int parc, char **parv,
1456 <            char **up_p, char **h_p, uintmax_t *tkline_time,
1457 <            char **target_server, char **reason)
1300 > bool
1301 > parse_aline(const char *cmd, struct Client *source_p, int parc, char **parv, struct aline_ctx *aline)
1302   {
1459  uintmax_t found_tkline_time=0;
1303    static char default_reason[] = CONF_NOREASON;
1304 <  static char user[USERLEN*4+1];
1305 <  static char host[HOSTLEN*4+1];
1463 <
1464 <  parv++;
1465 <  parc--;
1304 >  static char user[USERLEN * 2 + 1];
1305 >  static char host[HOSTLEN * 2 + 1];
1306  
1307 <  found_tkline_time = valid_tkline(*parv, TK_MINUTES);
1307 >  ++parv;
1308 >  --parc;
1309  
1310 <  if (found_tkline_time)
1310 >  if (aline->add == true && (aline->duration = valid_tkline(*parv, TK_MINUTES)))
1311    {
1312 <    parv++;
1313 <    parc--;
1473 <
1474 <    if (tkline_time)
1475 <      *tkline_time = found_tkline_time;
1476 <    else
1477 <    {
1478 <      sendto_one_notice(source_p, &me, ":temp_line not supported by %s", cmd);
1479 <      return 0;
1480 <    }
1312 >    ++parv;
1313 >    --parc;
1314    }
1315  
1316    if (parc == 0)
1317    {
1318      sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1319 <    return 0;
1319 >    return false;
1320    }
1321  
1322 <  if (h_p == NULL)
1323 <    *up_p = *parv;
1322 >  if (aline->simple_mask == true)
1323 >  {
1324 >    aline->mask = *parv;
1325 >    aline->user = NULL;
1326 >    aline->host = NULL;
1327 >  }
1328    else
1329    {
1330 <    if (find_user_host(source_p, *parv, user, host) == 0)
1494 <      return 0;
1330 >    struct split_nuh_item nuh;
1331  
1332 <    *up_p = user;
1333 <    *h_p = host;
1332 >    nuh.nuhmask  = *parv;
1333 >    nuh.nickptr  = NULL;
1334 >    nuh.userptr  = user;
1335 >    nuh.hostptr  = host;
1336 >
1337 >    nuh.nicksize = 0;
1338 >    nuh.usersize = sizeof(user);
1339 >    nuh.hostsize = sizeof(host);
1340 >
1341 >    split_nuh(&nuh);
1342 >
1343 >    aline->mask = NULL;
1344 >    aline->user = user;
1345 >    aline->host = host;
1346    }
1347  
1348 <  parc--;
1349 <  parv++;
1348 >  ++parv;
1349 >  --parc;
1350  
1351    if (parc)
1352    {
1353      if (irccmp(*parv, "ON") == 0)
1354      {
1355 <      parc--;
1356 <      parv++;
1355 >      ++parv;
1356 >      --parc;
1357  
1358        if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN))
1359        {
1360          sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "remoteban");
1361 <        return 0;
1361 >        return false;
1362        }
1363  
1364        if (parc == 0 || EmptyString(*parv))
1365        {
1366          sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1367 <        return 0;
1367 >        return false;
1368        }
1369  
1370 <      *target_server = *parv;
1371 <      parc--;
1372 <      parv++;
1370 >      aline->server = *parv;
1371 >      ++parv;
1372 >      --parc;
1373      }
1374      else
1375 <    {
1528 <      /* Make sure target_server *is* NULL if no ON server found
1529 <       * caller probably NULL'd it first, but no harm to do it again -db
1530 <       */
1531 <      if (target_server)
1532 <        *target_server = NULL;
1533 <    }
1375 >      aline->server = NULL;
1376    }
1377  
1378 <  if (reason)
1378 >  if (aline->add == true)
1379    {
1380 <    if (parc && !EmptyString(*parv))
1381 <      *reason = *parv;
1380 >    if (parc == 0 || EmptyString(*parv))
1381 >      aline->reason = default_reason;
1382      else
1383 <      *reason = default_reason;
1383 >      aline->reason = *parv;
1384    }
1385  
1386 <  return 1;
1386 >  return true;
1387   }
1388  
1389   /* match_conf_password()
# Line 1551 | Line 1393 | parse_aline(const char *cmd, struct Clie
1393   * output       - 1 or 0 if match
1394   * side effects - none
1395   */
1396 < int
1396 > bool
1397   match_conf_password(const char *password, const struct MaskItem *conf)
1398   {
1399    const char *encr = NULL;
1400  
1401    if (EmptyString(password) || EmptyString(conf->passwd))
1402 <    return 0;
1402 >    return false;
1403  
1404    if (conf->flags & CONF_FLAGS_ENCRYPTED)
1405      encr = crypt(password, conf->passwd);
1406    else
1407      encr = password;
1408  
1409 <  return encr && !strcmp(encr, conf->passwd);
1409 >  return encr && strcmp(encr, conf->passwd) == 0;
1410   }
1411  
1412   /*
# Line 1649 | Line 1491 | split_nuh(struct split_nuh_item *const i
1491      else
1492      {
1493        /* No @ found */
1494 <      if (!iptr->nickptr || strpbrk(iptr->nuhmask, ".:"))
1494 >      if (iptr->nickptr == NULL || strpbrk(iptr->nuhmask, ".:"))
1495          strlcpy(iptr->hostptr, iptr->nuhmask, iptr->hostsize);
1496        else
1497          strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines