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

Comparing ircd-hybrid/branches/8.2.x/src/server.c (file contents):
Revision 5459 by michael, Tue Feb 3 22:24:23 2015 UTC vs.
Revision 7143 by michael, Thu Jan 28 09:57:03 2016 UTC

# Line 1 | Line 1
1   /*
2   *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (c) 1997-2015 ircd-hybrid development team
4 > *  Copyright (c) 1997-2016 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 25 | Line 25
25   */
26  
27   #include "stdinc.h"
28 #ifdef HAVE_LIBCRYPTO
29 #include <openssl/rsa.h>
30 #include "rsa.h"
31 #endif
28   #include "list.h"
29   #include "client.h"
30   #include "event.h"
# Line 48 | Line 44
44   #include "channel.h"
45   #include "parse.h"
46  
51 #define MIN_CONN_FREQ 300
47  
48   dlink_list flatten_links;
49 < static dlink_list cap_list;
49 > static dlink_list server_capabilities_list;
50   static void serv_connect_callback(fde_t *, int, void *);
51  
52  
# Line 70 | Line 65 | write_links_file(void *unused)
65    dlink_node *node = NULL, *node_next = NULL;
66    char buff[IRCD_BUFSIZE] = "";
67  
68 <  if ((file = fopen(LIPATH, "w")) == NULL)
68 >  if (EmptyString(ConfigServerHide.flatten_links_file))
69      return;
70  
71 +  if ((file = fopen(ConfigServerHide.flatten_links_file, "w")) == NULL)
72 +  {
73 +    ilog(LOG_TYPE_IRCD, "Couldn't open \"%s\": %s", ConfigServerHide.flatten_links_file,
74 +         strerror(errno));
75 +    return;
76 +  }
77 +
78    DLINK_FOREACH_SAFE(node, node_next, flatten_links.head)
79    {
80      dlinkDelete(node, &flatten_links);
81 <    MyFree(node->data);
81 >    xfree(node->data);
82      free_dlink_node(node);
83    }
84  
# Line 119 | Line 121 | read_links_file(void)
121    char *p = NULL;
122    char buff[IRCD_BUFSIZE] = "";
123  
124 <  if ((file = fopen(LIPATH, "r")) == NULL)
124 >  if (EmptyString(ConfigServerHide.flatten_links_file))
125      return;
126  
127 +  if ((file = fopen(ConfigServerHide.flatten_links_file, "r")) == NULL)
128 +  {
129 +    ilog(LOG_TYPE_IRCD, "Couldn't open \"%s\": %s", ConfigServerHide.flatten_links_file,
130 +         strerror(errno));
131 +    return;
132 +  }
133 +
134    while (fgets(buff, sizeof(buff), file))
135    {
136      if ((p = strchr(buff, '\n')))
# Line 177 | Line 186 | hunt_server(struct Client *source_p, con
186  
187    if (!target_p && has_wildcards(parv[server]))
188    {
189 <    DLINK_FOREACH(node, global_client_list.head)
189 >    DLINK_FOREACH(node, global_server_list.head)
190      {
191        struct Client *tmp = node->data;
192  
193 <      assert(IsMe(tmp) || IsServer(tmp) || IsClient(tmp));
193 >      assert(IsMe(tmp) || IsServer(tmp));
194        if (!match(parv[server], tmp->name))
195        {
196          if (tmp->from == source_p->from && !MyConnect(tmp))
# Line 191 | Line 200 | hunt_server(struct Client *source_p, con
200          break;
201        }
202      }
203 +
204 +    if (!target_p)
205 +    {
206 +      DLINK_FOREACH(node, global_client_list.head)
207 +      {
208 +        struct Client *tmp = node->data;
209 +
210 +        assert(IsMe(tmp) || IsServer(tmp) || IsClient(tmp));
211 +        if (!match(parv[server], tmp->name))
212 +        {
213 +          if (tmp->from == source_p->from && !MyConnect(tmp))
214 +            continue;
215 +
216 +          target_p = node->data;
217 +          break;
218 +        }
219 +      }
220 +    }
221    }
222  
223    if (target_p)
# Line 224 | Line 251 | void
251   try_connections(void *unused)
252   {
253    dlink_node *node = NULL;
227  int confrq = 0;
254  
229  /* TODO: change this to set active flag to 0 when added to event! --Habeeb */
255    if (GlobalSetOptions.autoconn == 0)
256      return;
257  
# Line 236 | Line 261 | try_connections(void *unused)
261  
262      assert(conf->type == CONF_SERVER);
263  
264 <    /* Also when already connecting! (update holdtimes) --SRB
240 <     */
264 >    /* Also when already connecting! (update holdtimes) --SRB */
265      if (!conf->port || !IsConfAllowAutoConn(conf))
266        continue;
267  
268 <
269 <    /* Skip this entry if the use of it is still on hold until
268 >    /*
269 >     * Skip this entry if the use of it is still on hold until
270       * future. Otherwise handle this entry (and set it on hold
271       * until next time). Will reset only hold times, if already
272       * made one successfull connection... [this algorithm is
# Line 253 | Line 277 | try_connections(void *unused)
277  
278      assert(conf->class);
279  
280 <    confrq = conf->class->con_freq;
257 <    if (confrq < MIN_CONN_FREQ)
258 <      confrq = MIN_CONN_FREQ;
259 <
260 <    conf->until = CurrentTime + confrq;
280 >    conf->until = CurrentTime + conf->class->con_freq;
281  
282      /*
283       * Found a CONNECT config with port specified, scan clients
# Line 268 | Line 288 | try_connections(void *unused)
288  
289      if (conf->class->ref_count < conf->class->max_total)
290      {
291 <      /* Go to the end of the list, if not already last */
291 >      /* Move this entry to the end of the list, if not already last */
292        if (node->next)
293        {
294          dlinkDelete(node, &server_items);
# Line 288 | Line 308 | try_connections(void *unused)
308         *   -- adrian
309         */
310        if (ConfigServerHide.hide_server_ips)
311 <        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
311 >        sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
312                               "Connection to %s activated.",
313                               conf->name);
314        else
315 <        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
315 >        sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
316                               "Connection to %s[%s] activated.",
317                               conf->name, conf->host);
318  
# Line 331 | Line 351 | check_server(const char *name, struct Cl
351  
352    assert(client_p);
353  
354 <  /* loop through looking for all possible connect items that might work */
354 >  /* Loop through looking for all possible connect items that might work */
355    DLINK_FOREACH(node, server_items.head)
356    {
357      conf = node->data;
# Line 341 | Line 361 | check_server(const char *name, struct Cl
361  
362      error = -3;
363  
344    /* XXX: Fix me for IPv6                    */
345    /* XXX sockhost is the IPv4 ip as a string */
364      if (!match(conf->host, client_p->host) ||
365          !match(conf->host, client_p->sockhost))
366      {
# Line 364 | Line 382 | check_server(const char *name, struct Cl
382  
383    attach_conf(client_p, server_conf);
384  
385 <
368 <  if (server_conf)
385 >  switch (server_conf->aftype)
386    {
387 <    struct sockaddr_in *v4;
371 <    struct sockaddr_in6 *v6;
372 <
373 <    switch (server_conf->aftype)
387 >    case AF_INET6:
388      {
389 <      case AF_INET6:
376 <        v6 = (struct sockaddr_in6 *)&server_conf->addr;
389 >      const struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)&server_conf->addr;
390  
391 <        if (IN6_IS_ADDR_UNSPECIFIED(&v6->sin6_addr))
392 <          memcpy(&server_conf->addr, &client_p->connection->ip, sizeof(struct irc_ssaddr));
393 <        break;
394 <      case AF_INET:
395 <        v4 = (struct sockaddr_in *)&server_conf->addr;
391 >      if (IN6_IS_ADDR_UNSPECIFIED(&v6->sin6_addr))
392 >        memcpy(&server_conf->addr, &client_p->connection->ip, sizeof(struct irc_ssaddr));
393 >      break;
394 >    }
395 >    case AF_INET:
396 >    {
397 >      const struct sockaddr_in *v4 = (struct sockaddr_in *)&server_conf->addr;
398  
399 <        if (v4->sin_addr.s_addr == INADDR_NONE)
400 <          memcpy(&server_conf->addr, &client_p->connection->ip, sizeof(struct irc_ssaddr));
401 <        break;
399 >      if (v4->sin_addr.s_addr == INADDR_NONE)
400 >        memcpy(&server_conf->addr, &client_p->connection->ip, sizeof(struct irc_ssaddr));
401 >      break;
402      }
403    }
404  
# Line 400 | Line 415 | check_server(const char *name, struct Cl
415   *                modules to dynamically add or subtract their capability.
416   */
417   void
418 < add_capability(const char *capab_name, int cap_flag, int add_to_default)
418 > add_capability(const char *name, unsigned int flag)
419   {
420 <  struct Capability *cap = MyCalloc(sizeof(*cap));
406 <
407 <  cap->name = xstrdup(capab_name);
408 <  cap->cap = cap_flag;
409 <  dlinkAdd(cap, &cap->node, &cap_list);
420 >  struct Capability *cap = xcalloc(sizeof(*cap));
421  
422 <  if (add_to_default)
423 <    default_server_capabs |= cap_flag;
422 >  cap->name = xstrdup(name);
423 >  cap->cap = flag;
424 >  dlinkAdd(cap, &cap->node, &server_capabilities_list);
425   }
426  
427   /* delete_capability()
# Line 418 | Line 430 | add_capability(const char *capab_name, i
430   * output       - NONE
431   * side effects - delete given capability from ones known.
432   */
433 < int
434 < delete_capability(const char *capab_name)
433 > void
434 > delete_capability(const char *name)
435   {
436    dlink_node *node = NULL, *node_next = NULL;
437  
438 <  DLINK_FOREACH_SAFE(node, node_next, cap_list.head)
438 >  DLINK_FOREACH_SAFE(node, node_next, server_capabilities_list.head)
439    {
440      struct Capability *cap = node->data;
441  
442 <    if (cap->cap)
442 >    if (!irccmp(cap->name, name))
443      {
444 <      if (!irccmp(cap->name, capab_name))
445 <      {
446 <        default_server_capabs &= ~(cap->cap);
435 <        dlinkDelete(node, &cap_list);
436 <        MyFree(cap->name);
437 <        MyFree(cap);
438 <      }
444 >      dlinkDelete(node, &server_capabilities_list);
445 >      xfree(cap->name);
446 >      xfree(cap);
447      }
448    }
441
442  return 0;
449   }
450  
451   /*
# Line 450 | Line 456 | delete_capability(const char *capab_name
456   * side effects - none
457   */
458   unsigned int
459 < find_capability(const char *capab)
459 > find_capability(const char *name)
460   {
461    const dlink_node *node = NULL;
462  
463 <  DLINK_FOREACH(node, cap_list.head)
463 >  DLINK_FOREACH(node, server_capabilities_list.head)
464    {
465      const struct Capability *cap = node->data;
466  
467 <    if (cap->cap && !irccmp(cap->name, capab))
467 >    if (!irccmp(cap->name, name))
468        return cap->cap;
469    }
470  
# Line 474 | Line 480 | find_capability(const char *capab)
480   *
481   */
482   void
483 < send_capabilities(struct Client *client_p, int cap_can_send)
483 > send_capabilities(struct Client *client_p)
484   {
485    char buf[IRCD_BUFSIZE] = "";
486    const dlink_node *node = NULL;
487  
488 <  DLINK_FOREACH(node, cap_list.head)
488 >  DLINK_FOREACH(node, server_capabilities_list.head)
489    {
490      const struct Capability *cap = node->data;
491  
492 <    if (cap->cap & (cap_can_send|default_server_capabs))
493 <    {
494 <      strlcat(buf, cap->name, sizeof(buf));
495 <      if (node->next)
490 <        strlcat(buf, " ", sizeof(buf));
491 <    }
492 >    strlcat(buf, cap->name, sizeof(buf));
493 >
494 >    if (node->next)
495 >      strlcat(buf, " ", sizeof(buf));
496    }
497  
498    sendto_one(client_p, "CAPAB :%s", buf);
# Line 509 | Line 513 | show_capabilities(const struct Client *t
513  
514    strlcpy(msgbuf, "TS", sizeof(msgbuf));
515  
516 <  DLINK_FOREACH(node, cap_list.head)
516 >  DLINK_FOREACH(node, server_capabilities_list.head)
517    {
518      const struct Capability *cap = node->data;
519  
# Line 534 | Line 538 | struct Server *
538   make_server(struct Client *client_p)
539   {
540    if (client_p->serv == NULL)
541 <    client_p->serv = MyCalloc(sizeof(struct Server));
541 >    client_p->serv = xcalloc(sizeof(struct Server));
542  
543    return client_p->serv;
544   }
# Line 580 | Line 584 | serv_connect(struct MaskItem *conf, stru
584    /* Still processing a DNS lookup? -> exit */
585    if (conf->dns_pending)
586    {
587 <    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
587 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
588                           "Error connecting to %s: DNS lookup for connect{} in progress.",
589                           conf->name);
590      return 0;
# Line 588 | Line 592 | serv_connect(struct MaskItem *conf, stru
592  
593    if (conf->dns_failed)
594    {
595 <    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
595 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
596                           "Error connecting to %s: DNS lookup for connect{} failed.",
597                           conf->name);
598      return 0;
599    }
600  
601 <  /* Make sure this server isn't already connected
602 <   * Note: conf should ALWAYS be a valid C: line
601 >  /*
602 >   * Make sure this server isn't already connected.
603 >   * Note: conf should ALWAYS be a valid connect {} block
604     */
605    if ((client_p = hash_find_server(conf->name)))
606    {
607 <    sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
607 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
608                           "Server %s already present from %s",
609                           conf->name, get_client_name(client_p, SHOW_IP));
610 <    sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
610 >    sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
611                           "Server %s already present from %s",
612                           conf->name, get_client_name(client_p, MASK_IP));
613      if (by && IsClient(by) && !MyClient(by))
# Line 621 | Line 626 | serv_connect(struct MaskItem *conf, stru
626    /* We already converted the ip once, so lets use it - stu */
627    strlcpy(client_p->sockhost, buf, sizeof(client_p->sockhost));
628  
629 <  /* create a socket for the server connection */
629 >  /* Create a socket for the server connection */
630    if (comm_open(&client_p->connection->fd, conf->addr.ss.ss_family, SOCK_STREAM, 0, NULL) < 0)
631    {
632      /* Eek, failure to create the socket */
# Line 632 | Line 637 | serv_connect(struct MaskItem *conf, stru
637      return 0;
638    }
639  
640 <  /* servernames are always guaranteed under HOSTLEN chars */
641 <  fd_note(&client_p->connection->fd, "Server: %s", conf->name);
640 >  /* Server names are always guaranteed under HOSTLEN chars */
641 >  fd_note(&client_p->connection->fd, "Server: %s", client_p->name);
642  
643 <  /* Attach config entries to client here rather than in
644 <   * serv_connect_callback(). This to avoid null pointer references.
643 >  /*
644 >   * Attach config entries to client here rather than in serv_connect_callback().
645 >   * This to avoid null pointer references.
646     */
647    if (!attach_connect_block(client_p, conf->name, conf->host))
648    {
649 <    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
649 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
650                           "Host %s is not enabled for connecting: no connect {} block",
651                           conf->name);
652      if (by && IsClient(by) && !MyClient(by))
# Line 651 | Line 657 | serv_connect(struct MaskItem *conf, stru
657      return 0;
658    }
659  
660 <  /* at this point we have a connection in progress and C/N lines
661 <   * attached to the client, the socket info should be saved in the
662 <   * client and it should either be resolved or have a valid address.
660 >  /*
661 >   * At this point we have a connection in progress and a connect {} block
662 >   * attached to the client, the socket info should be saved in the client
663 >   * and it should either be resolved or have a valid address.
664     *
665     * The socket has been connected or connect is in progress.
666     */
# Line 747 | Line 754 | serv_connect(struct MaskItem *conf, stru
754    return 1;
755   }
756  
757 < #ifdef HAVE_LIBCRYPTO
757 > #ifdef HAVE_TLS
758   static void
759   finish_ssl_server_handshake(struct Client *client_p)
760   {
# Line 757 | Line 764 | finish_ssl_server_handshake(struct Clien
764                          client_p->name, CONF_SERVER);
765    if (conf == NULL)
766    {
767 <    sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
768 <                         "Lost connect{} block for %s", get_client_name(client_p, HIDE_IP));
769 <    sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
767 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
768 >                         "Lost connect{} block for %s", get_client_name(client_p, SHOW_IP));
769 >    sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
770                           "Lost connect{} block for %s", get_client_name(client_p, MASK_IP));
771  
772      exit_client(client_p, "Lost connect{} block");
# Line 768 | Line 775 | finish_ssl_server_handshake(struct Clien
775  
776    sendto_one(client_p, "PASS %s TS %d %s", conf->spasswd, TS_CURRENT, me.id);
777  
778 <  send_capabilities(client_p, 0);
778 >  send_capabilities(client_p);
779  
780    sendto_one(client_p, "SERVER %s 1 :%s%s",
781               me.name, ConfigServerHide.hidden ? "(H) " : "",
782               me.info);
783  
784 <  /* If we've been marked dead because a send failed, just exit
784 >  /*
785 >   * If we've been marked dead because a send failed, just exit
786     * here now and save everyone the trouble of us ever existing.
787     */
788    if (IsDead(client_p))
789    {
790 <      sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
791 <                           "%s[%s] went dead during handshake",
792 <                           client_p->name,
793 <                           client_p->host);
794 <      sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
787 <                           "%s went dead during handshake", client_p->name);
788 <      return;
790 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
791 >                         "%s went dead during handshake", get_client_name(client_p, SHOW_IP));
792 >    sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
793 >                         "%s went dead during handshake", get_client_name(client_p, MASK_IP));
794 >    return;
795    }
796  
797    /* don't move to serv_list yet -- we haven't sent a burst! */
# Line 797 | Line 803 | static void
803   ssl_server_handshake(fde_t *fd, void *data)
804   {
805    struct Client *client_p = data;
806 <  X509 *cert = NULL;
801 <  int ret = 0;
806 >  const char *sslerr = NULL;
807  
808 <  if ((ret = SSL_connect(client_p->connection->fd.ssl)) <= 0)
808 >  tls_handshake_status_t ret = tls_handshake(&client_p->connection->fd.ssl, TLS_ROLE_CLIENT, &sslerr);
809 >  if (ret != TLS_HANDSHAKE_DONE)
810    {
811      if ((CurrentTime - client_p->connection->firsttime) > CONNECTTIMEOUT)
812      {
813 <      exit_client(client_p, "Timeout during SSL handshake");
813 >      exit_client(client_p, "Timeout during TLS handshake");
814        return;
815      }
816  
817 <    switch (SSL_get_error(client_p->connection->fd.ssl, ret))
817 >    switch (ret)
818      {
819 <      case SSL_ERROR_WANT_WRITE:
819 >      case TLS_HANDSHAKE_WANT_WRITE:
820          comm_setselect(&client_p->connection->fd, COMM_SELECT_WRITE,
821                         ssl_server_handshake, client_p, CONNECTTIMEOUT);
822          return;
823 <      case SSL_ERROR_WANT_READ:
823 >      case TLS_HANDSHAKE_WANT_READ:
824          comm_setselect(&client_p->connection->fd, COMM_SELECT_READ,
825                         ssl_server_handshake, client_p, CONNECTTIMEOUT);
826          return;
827        default:
828        {
829 <        const char *sslerr = ERR_error_string(ERR_get_error(), NULL);
824 <        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
829 >        sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
830                               "Error connecting to %s: %s", client_p->name,
831 <                             sslerr ? sslerr : "unknown SSL error");
832 <        exit_client(client_p, "Error during SSL handshake");
831 >                             sslerr ? sslerr : "unknown TLS error");
832 >        exit_client(client_p, "Error during TLS handshake");
833          return;
834        }
835      }
# Line 832 | Line 837 | ssl_server_handshake(fde_t *fd, void *da
837  
838    comm_settimeout(&client_p->connection->fd, 0, NULL, NULL);
839  
840 <  if ((cert = SSL_get_peer_certificate(client_p->connection->fd.ssl)))
841 <  {
842 <    int res = SSL_get_verify_result(client_p->connection->fd.ssl);
838 <    char buf[EVP_MAX_MD_SIZE * 2 + 1] = "";
839 <    unsigned char md[EVP_MAX_MD_SIZE] = "";
840 <
841 <    if (res == X509_V_OK || res == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN ||
842 <        res == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE ||
843 <        res == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT)
844 <    {
845 <      unsigned int n = 0;
846 <
847 <      if (X509_digest(cert, ConfigServerInfo.message_digest_algorithm, md, &n))
848 <      {
849 <        binary_to_hex(md, buf, n);
850 <        client_p->certfp = xstrdup(buf);
851 <      }
852 <    }
853 <    else
854 <      ilog(LOG_TYPE_IRCD, "Server %s!%s@%s gave bad SSL client certificate: %d",
855 <           client_p->name, client_p->username, client_p->host, res);
856 <    X509_free(cert);
857 <  }
840 >  if (!tls_verify_cert(&client_p->connection->fd.ssl, ConfigServerInfo.message_digest_algorithm, &client_p->certfp))
841 >    ilog(LOG_TYPE_IRCD, "Server %s!%s@%s gave bad TLS client certificate",
842 >         client_p->name, client_p->username, client_p->host);
843  
844    finish_ssl_server_handshake(client_p);
845   }
846  
847   static void
848 < ssl_connect_init(struct Client *client_p, struct MaskItem *conf, fde_t *fd)
848 > ssl_connect_init(struct Client *client_p, const struct MaskItem *conf, fde_t *fd)
849   {
850 <  if ((client_p->connection->fd.ssl = SSL_new(ConfigServerInfo.client_ctx)) == NULL)
850 >  if (!tls_new(&client_p->connection->fd.ssl, fd->fd, TLS_ROLE_CLIENT))
851    {
867    ilog(LOG_TYPE_IRCD, "SSL_new() ERROR! -- %s",
868         ERR_error_string(ERR_get_error(), NULL));
852      SetDead(client_p);
853 <    exit_client(client_p, "SSL_new failed");
853 >    exit_client(client_p, "TLS context initialization failed");
854      return;
855    }
856  
874  SSL_set_fd(fd->ssl, fd->fd);
875
857    if (!EmptyString(conf->cipher_list))
858 <    SSL_set_cipher_list(client_p->connection->fd.ssl, conf->cipher_list);
858 >    tls_set_ciphers(&client_p->connection->fd.ssl, conf->cipher_list);
859  
860    ssl_server_handshake(NULL, client_p);
861   }
# Line 891 | Line 872 | ssl_connect_init(struct Client *client_p
872   static void
873   serv_connect_callback(fde_t *fd, int status, void *data)
874   {
875 <  struct Client *client_p = data;
876 <  struct MaskItem *conf = NULL;
875 >  struct Client *const client_p = data;
876 >  const struct MaskItem *conf = NULL;
877  
878    /* First, make sure it's a real client! */
879    assert(client_p);
# Line 905 | Line 886 | serv_connect_callback(fde_t *fd, int sta
886    /* Check the status */
887    if (status != COMM_OK)
888    {
889 <    /* We have an error, so report it and quit
890 <     * Admins get to see any IP, mere opers don't *sigh*
889 >    /* We have an error, so report it and quit */
890 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
891 >                         "Error connecting to %s: %s",
892 >                         get_client_name(client_p, SHOW_IP), comm_errstr(status));
893 >    sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
894 >                         "Error connecting to %s: %s",
895 >                         get_client_name(client_p, MASK_IP), comm_errstr(status));
896 >
897 >    /*
898 >     * If a fd goes bad, call dead_link() the socket is no
899 >     * longer valid for reading or writing.
900       */
901 <     if (ConfigServerHide.hide_server_ips)
902 <       sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
913 <                            "Error connecting to %s: %s",
914 <                            client_p->name, comm_errstr(status));
915 <     else
916 <       sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
917 <                            "Error connecting to %s[%s]: %s", client_p->name,
918 <                            client_p->host, comm_errstr(status));
919 <
920 <     sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
921 <                          "Error connecting to %s: %s",
922 <                          client_p->name, comm_errstr(status));
923 <
924 <     /* If a fd goes bad, call dead_link() the socket is no
925 <      * longer valid for reading or writing.
926 <      */
927 <     dead_link_on_write(client_p, 0);
928 <     return;
901 >    dead_link_on_write(client_p, 0);
902 >    return;
903    }
904  
905    /* COMM_OK, so continue the connection procedure */
# Line 934 | Line 908 | serv_connect_callback(fde_t *fd, int sta
908                          client_p->name, CONF_SERVER);
909    if (conf == NULL)
910    {
911 <    sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
912 <                         "Lost connect{} block for %s", get_client_name(client_p, HIDE_IP));
913 <    sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
911 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
912 >                         "Lost connect{} block for %s", get_client_name(client_p, SHOW_IP));
913 >    sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
914                           "Lost connect{} block for %s", get_client_name(client_p, MASK_IP));
915  
916      exit_client(client_p, "Lost connect{} block");
# Line 946 | Line 920 | serv_connect_callback(fde_t *fd, int sta
920    /* Next, send the initial handshake */
921    SetHandshake(client_p);
922  
923 < #ifdef HAVE_LIBCRYPTO
923 > #ifdef HAVE_TLS
924    if (IsConfSSL(conf))
925    {
926      ssl_connect_init(client_p, conf, fd);
# Line 956 | Line 930 | serv_connect_callback(fde_t *fd, int sta
930  
931    sendto_one(client_p, "PASS %s TS %d %s", conf->spasswd, TS_CURRENT, me.id);
932  
933 <  send_capabilities(client_p, 0);
933 >  send_capabilities(client_p);
934  
935    sendto_one(client_p, "SERVER %s 1 :%s%s", me.name,
936               ConfigServerHide.hidden ? "(H) " : "", me.info);
937  
938 <  /* If we've been marked dead because a send failed, just exit
938 >  /*
939 >   * If we've been marked dead because a send failed, just exit
940     * here now and save everyone the trouble of us ever existing.
941     */
942    if (IsDead(client_p))
943    {
944 <      sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
945 <                           "%s[%s] went dead during handshake",
946 <                           client_p->name,
947 <                           client_p->host);
948 <      sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
974 <                           "%s went dead during handshake", client_p->name);
975 <      return;
944 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
945 >                         "%s went dead during handshake", get_client_name(client_p, SHOW_IP));
946 >    sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
947 >                         "%s went dead during handshake", get_client_name(client_p, MASK_IP));
948 >    return;
949    }
950  
951    /* don't move to serv_list yet -- we haven't sent a burst! */

Diff Legend

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