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

Comparing ircd-hybrid/trunk/src/server.c (file contents):
Revision 4439 by michael, Sat Aug 9 18:36:19 2014 UTC vs.
Revision 6428 by michael, Thu Aug 27 09:59:42 2015 UTC

# Line 1 | Line 1
1   /*
2   *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (c) 1997-2014 ircd-hybrid development team
4 > *  Copyright (c) 1997-2015 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 15 | Line 15
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18 < *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19   *  USA
20   */
21  
# Line 48 | Line 48
48   #include "channel.h"
49   #include "parse.h"
50  
51 #define MIN_CONN_FREQ 300
52
51   dlink_list flatten_links;
52 < static dlink_list cap_list = { NULL, NULL, 0 };
53 < static CNCB serv_connect_callback;
52 > static dlink_list server_capabilities_list;
53 > static void serv_connect_callback(fde_t *, int, void *);
54  
55  
56   /*
# Line 67 | Line 65 | void
65   write_links_file(void *unused)
66   {
67    FILE *file = NULL;
68 <  dlink_node *ptr = NULL, *ptr_next = NULL;
68 >  dlink_node *node = NULL, *node_next = NULL;
69    char buff[IRCD_BUFSIZE] = "";
70  
71    if ((file = fopen(LIPATH, "w")) == NULL)
72      return;
73  
74 <  DLINK_FOREACH_SAFE(ptr, ptr_next, flatten_links.head)
74 >  DLINK_FOREACH_SAFE(node, node_next, flatten_links.head)
75    {
76 <    dlinkDelete(ptr, &flatten_links);
77 <    MyFree(ptr->data);
78 <    free_dlink_node(ptr);
76 >    dlinkDelete(node, &flatten_links);
77 >    MyFree(node->data);
78 >    free_dlink_node(node);
79    }
80  
81 <  DLINK_FOREACH(ptr, global_server_list.head)
81 >  DLINK_FOREACH(node, global_server_list.head)
82    {
83 <    const struct Client *target_p = ptr->data;
83 >    const struct Client *target_p = node->data;
84  
85      /*
86       * Skip hidden servers, aswell as ourselves, since we already send
# Line 157 | Line 155 | hunt_server(struct Client *source_p, con
155              const int server, const int parc, char *parv[])
156   {
157    struct Client *target_p = NULL;
158 <  dlink_node *ptr = NULL;
158 >  dlink_node *node = NULL;
159  
160    /* Assume it's me, if no server */
161    if (parc <= server || EmptyString(parv[server]))
# Line 177 | Line 175 | hunt_server(struct Client *source_p, con
175  
176    if (!target_p && has_wildcards(parv[server]))
177    {
178 <    DLINK_FOREACH(ptr, global_client_list.head)
178 >    DLINK_FOREACH(node, global_server_list.head)
179      {
180 <      struct Client *tmp = ptr->data;
180 >      struct Client *tmp = node->data;
181  
182 <      assert(IsMe(tmp) || IsServer(tmp) || IsClient(tmp));
182 >      assert(IsMe(tmp) || IsServer(tmp));
183        if (!match(parv[server], tmp->name))
184        {
185          if (tmp->from == source_p->from && !MyConnect(tmp))
186            continue;
187  
188 <        target_p = ptr->data;
188 >        target_p = node->data;
189          break;
190        }
191      }
192 +
193 +    if (!target_p)
194 +    {
195 +      DLINK_FOREACH(node, global_client_list.head)
196 +      {
197 +        struct Client *tmp = node->data;
198 +
199 +        assert(IsMe(tmp) || IsServer(tmp) || IsClient(tmp));
200 +        if (!match(parv[server], tmp->name))
201 +        {
202 +          if (tmp->from == source_p->from && !MyConnect(tmp))
203 +            continue;
204 +
205 +          target_p = node->data;
206 +          break;
207 +        }
208 +      }
209 +    }
210    }
211  
212    if (target_p)
# Line 223 | Line 239 | hunt_server(struct Client *source_p, con
239   void
240   try_connections(void *unused)
241   {
242 <  dlink_node *ptr = NULL;
227 <  int confrq = 0;
242 >  dlink_node *node = NULL;
243  
244    /* TODO: change this to set active flag to 0 when added to event! --Habeeb */
245    if (GlobalSetOptions.autoconn == 0)
246      return;
247  
248 <  DLINK_FOREACH(ptr, server_items.head)
248 >  DLINK_FOREACH(node, server_items.head)
249    {
250 <    struct MaskItem *conf = ptr->data;
250 >    struct MaskItem *conf = node->data;
251  
252      assert(conf->type == CONF_SERVER);
253  
# Line 253 | Line 268 | try_connections(void *unused)
268  
269      assert(conf->class);
270  
271 <    confrq = conf->class->con_freq;
257 <    if (confrq < MIN_CONN_FREQ)
258 <      confrq = MIN_CONN_FREQ;
259 <
260 <    conf->until = CurrentTime + confrq;
271 >    conf->until = CurrentTime + conf->class->con_freq;
272  
273      /*
274       * Found a CONNECT config with port specified, scan clients
# Line 268 | Line 279 | try_connections(void *unused)
279  
280      if (conf->class->ref_count < conf->class->max_total)
281      {
282 <      /* Go to the end of the list, if not already last */
283 <      if (ptr->next)
282 >      /* Move this entry to the end of the list, if not already last */
283 >      if (node->next)
284        {
285 <        dlinkDelete(ptr, &server_items);
285 >        dlinkDelete(node, &server_items);
286          dlinkAddTail(conf, &conf->node, &server_items);
287        }
288  
# Line 288 | Line 299 | try_connections(void *unused)
299         *   -- adrian
300         */
301        if (ConfigServerHide.hide_server_ips)
302 <        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
302 >        sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
303                               "Connection to %s activated.",
304                               conf->name);
305        else
306 <        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
306 >        sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
307                               "Connection to %s[%s] activated.",
308                               conf->name, conf->host);
309  
# Line 324 | Line 335 | valid_servname(const char *name)
335   int
336   check_server(const char *name, struct Client *client_p)
337   {
338 <  dlink_node *ptr;
338 >  dlink_node *node = NULL;
339    struct MaskItem *conf        = NULL;
340    struct MaskItem *server_conf = NULL;
341    int error = -1;
# Line 332 | Line 343 | check_server(const char *name, struct Cl
343    assert(client_p);
344  
345    /* loop through looking for all possible connect items that might work */
346 <  DLINK_FOREACH(ptr, server_items.head)
346 >  DLINK_FOREACH(node, server_items.head)
347    {
348 <    conf = ptr->data;
348 >    conf = node->data;
349  
350      if (match(name, conf->name))
351        continue;
# Line 348 | Line 359 | check_server(const char *name, struct Cl
359      {
360        error = -2;
361  
362 <      if (!match_conf_password(client_p->localClient->password, conf))
362 >      if (!match_conf_password(client_p->connection->password, conf))
363          return -2;
364  
365        if (!EmptyString(conf->certfp))
# Line 376 | Line 387 | check_server(const char *name, struct Cl
387          v6 = (struct sockaddr_in6 *)&server_conf->addr;
388  
389          if (IN6_IS_ADDR_UNSPECIFIED(&v6->sin6_addr))
390 <          memcpy(&server_conf->addr, &client_p->localClient->ip, sizeof(struct irc_ssaddr));
390 >          memcpy(&server_conf->addr, &client_p->connection->ip, sizeof(struct irc_ssaddr));
391          break;
392        case AF_INET:
393          v4 = (struct sockaddr_in *)&server_conf->addr;
394  
395          if (v4->sin_addr.s_addr == INADDR_NONE)
396 <          memcpy(&server_conf->addr, &client_p->localClient->ip, sizeof(struct irc_ssaddr));
396 >          memcpy(&server_conf->addr, &client_p->connection->ip, sizeof(struct irc_ssaddr));
397          break;
398      }
399    }
# Line 400 | Line 411 | check_server(const char *name, struct Cl
411   *                modules to dynamically add or subtract their capability.
412   */
413   void
414 < add_capability(const char *capab_name, int cap_flag, int add_to_default)
414 > add_capability(const char *name, unsigned int flag)
415   {
416    struct Capability *cap = MyCalloc(sizeof(*cap));
417  
418 <  cap->name = xstrdup(capab_name);
419 <  cap->cap = cap_flag;
420 <  dlinkAdd(cap, &cap->node, &cap_list);
410 <
411 <  if (add_to_default)
412 <    default_server_capabs |= cap_flag;
418 >  cap->name = xstrdup(name);
419 >  cap->cap = flag;
420 >  dlinkAdd(cap, &cap->node, &server_capabilities_list);
421   }
422  
423   /* delete_capability()
# Line 418 | Line 426 | add_capability(const char *capab_name, i
426   * output       - NONE
427   * side effects - delete given capability from ones known.
428   */
429 < int
430 < delete_capability(const char *capab_name)
429 > void
430 > delete_capability(const char *name)
431   {
432 <  dlink_node *ptr = NULL, *ptr_next = NULL;
432 >  dlink_node *node = NULL, *node_next = NULL;
433  
434 <  DLINK_FOREACH_SAFE(ptr, ptr_next, cap_list.head)
434 >  DLINK_FOREACH_SAFE(node, node_next, server_capabilities_list.head)
435    {
436 <    struct Capability *cap = ptr->data;
436 >    struct Capability *cap = node->data;
437  
438 <    if (cap->cap)
438 >    if (!irccmp(cap->name, name))
439      {
440 <      if (!irccmp(cap->name, capab_name))
441 <      {
442 <        default_server_capabs &= ~(cap->cap);
435 <        dlinkDelete(ptr, &cap_list);
436 <        MyFree(cap->name);
437 <        MyFree(cap);
438 <      }
440 >      dlinkDelete(node, &server_capabilities_list);
441 >      MyFree(cap->name);
442 >      MyFree(cap);
443      }
444    }
441
442  return 0;
445   }
446  
447   /*
# Line 450 | Line 452 | delete_capability(const char *capab_name
452   * side effects - none
453   */
454   unsigned int
455 < find_capability(const char *capab)
455 > find_capability(const char *name)
456   {
457 <  const dlink_node *ptr = NULL;
457 >  const dlink_node *node = NULL;
458  
459 <  DLINK_FOREACH(ptr, cap_list.head)
459 >  DLINK_FOREACH(node, server_capabilities_list.head)
460    {
461 <    const struct Capability *cap = ptr->data;
461 >    const struct Capability *cap = node->data;
462  
463 <    if (cap->cap && !irccmp(cap->name, capab))
463 >    if (!irccmp(cap->name, name))
464        return cap->cap;
465    }
466  
# Line 474 | Line 476 | find_capability(const char *capab)
476   *
477   */
478   void
479 < send_capabilities(struct Client *client_p, int cap_can_send)
479 > send_capabilities(struct Client *client_p)
480   {
481    char buf[IRCD_BUFSIZE] = "";
482 <  const dlink_node *ptr = NULL;
482 >  const dlink_node *node = NULL;
483  
484 <  DLINK_FOREACH(ptr, cap_list.head)
484 >  DLINK_FOREACH(node, server_capabilities_list.head)
485    {
486 <    const struct Capability *cap = ptr->data;
486 >    const struct Capability *cap = node->data;
487  
488 <    if (cap->cap & (cap_can_send|default_server_capabs))
489 <    {
490 <      strlcat(buf, cap->name, sizeof(buf));
491 <      if (ptr->next)
490 <        strlcat(buf, " ", sizeof(buf));
491 <    }
488 >    strlcat(buf, cap->name, sizeof(buf));
489 >
490 >    if (node->next)
491 >      strlcat(buf, " ", sizeof(buf));
492    }
493  
494    sendto_one(client_p, "CAPAB :%s", buf);
# Line 505 | Line 505 | const char *
505   show_capabilities(const struct Client *target_p)
506   {
507    static char msgbuf[IRCD_BUFSIZE] = "";
508 <  const dlink_node *ptr = NULL;
508 >  const dlink_node *node = NULL;
509  
510    strlcpy(msgbuf, "TS", sizeof(msgbuf));
511  
512 <  DLINK_FOREACH(ptr, cap_list.head)
512 >  DLINK_FOREACH(node, server_capabilities_list.head)
513    {
514 <    const struct Capability *cap = ptr->data;
514 >    const struct Capability *cap = node->data;
515  
516      if (!IsCapable(target_p, cap->cap))
517        continue;
# Line 572 | Line 572 | serv_connect(struct MaskItem *conf, stru
572    /* Make sure conf is useful */
573    assert(conf);
574  
575 <  getnameinfo((struct sockaddr *)&conf->addr, conf->addr.ss_len,
575 >  getnameinfo((const struct sockaddr *)&conf->addr, conf->addr.ss_len,
576                buf, sizeof(buf), NULL, 0, NI_NUMERICHOST);
577    ilog(LOG_TYPE_IRCD, "Connect to %s[%s] @%s", conf->name, conf->host,
578         buf);
# Line 580 | Line 580 | serv_connect(struct MaskItem *conf, stru
580    /* Still processing a DNS lookup? -> exit */
581    if (conf->dns_pending)
582    {
583 <    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
583 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
584                           "Error connecting to %s: DNS lookup for connect{} in progress.",
585                           conf->name);
586      return 0;
# Line 588 | Line 588 | serv_connect(struct MaskItem *conf, stru
588  
589    if (conf->dns_failed)
590    {
591 <    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
591 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
592                           "Error connecting to %s: DNS lookup for connect{} failed.",
593                           conf->name);
594      return 0;
# Line 599 | Line 599 | serv_connect(struct MaskItem *conf, stru
599     */
600    if ((client_p = hash_find_server(conf->name)))
601    {
602 <    sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
602 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
603                           "Server %s already present from %s",
604                           conf->name, get_client_name(client_p, SHOW_IP));
605 <    sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
605 >    sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
606                           "Server %s already present from %s",
607                           conf->name, get_client_name(client_p, MASK_IP));
608      if (by && IsClient(by) && !MyClient(by))
# Line 622 | Line 622 | serv_connect(struct MaskItem *conf, stru
622    strlcpy(client_p->sockhost, buf, sizeof(client_p->sockhost));
623  
624    /* create a socket for the server connection */
625 <  if (comm_open(&client_p->localClient->fd, conf->addr.ss.ss_family, SOCK_STREAM, 0, NULL) < 0)
625 >  if (comm_open(&client_p->connection->fd, conf->addr.ss.ss_family, SOCK_STREAM, 0, NULL) < 0)
626    {
627      /* Eek, failure to create the socket */
628      report_error(L_ALL, "opening stream socket to %s: %s", conf->name, errno);
# Line 633 | Line 633 | serv_connect(struct MaskItem *conf, stru
633    }
634  
635    /* servernames are always guaranteed under HOSTLEN chars */
636 <  fd_note(&client_p->localClient->fd, "Server: %s", conf->name);
636 >  fd_note(&client_p->connection->fd, "Server: %s", conf->name);
637  
638    /* Attach config entries to client here rather than in
639     * serv_connect_callback(). This to avoid null pointer references.
640     */
641    if (!attach_connect_block(client_p, conf->name, conf->host))
642    {
643 <    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
644 <                         "Host %s is not enabled for connecting: no connect{} block",
643 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
644 >                         "Host %s is not enabled for connecting: no connect {} block",
645                           conf->name);
646      if (by && IsClient(by) && !MyClient(by))
647 <      sendto_one_notice(by, &me, ":Connect to host %s failed.", client_p->name);
647 >      sendto_one_notice(by, &me, ":Connect to host %s failed: no connect {} block", client_p->name);
648  
649      SetDead(client_p);
650      exit_client(client_p, "Connection failed");
# Line 665 | Line 665 | serv_connect(struct MaskItem *conf, stru
665      strlcpy(client_p->serv->by, "AutoConn.", sizeof(client_p->serv->by));
666  
667    SetConnecting(client_p);
668 <  client_p->localClient->aftype = conf->aftype;
668 >  client_p->connection->aftype = conf->aftype;
669  
670    /* Now, initiate the connection */
671    /* XXX assume that a non 0 type means a specific bind address
# Line 682 | Line 682 | serv_connect(struct MaskItem *conf, stru
682          ipn.ss.ss_family = AF_INET;
683          ipn.ss_port = 0;
684          memcpy(&ipn, &conf->bind, sizeof(struct irc_ssaddr));
685 <        comm_connect_tcp(&client_p->localClient->fd, conf->host, conf->port,
685 >        comm_connect_tcp(&client_p->connection->fd, conf->host, conf->port,
686                           (struct sockaddr *)&ipn, ipn.ss_len,
687                           serv_connect_callback, client_p, conf->aftype,
688                           CONNECTTIMEOUT);
# Line 694 | Line 694 | serv_connect(struct MaskItem *conf, stru
694          ipn.ss.ss_family = AF_INET;
695          ipn.ss_port = 0;
696          memcpy(&ipn, &ConfigServerInfo.ip, sizeof(struct irc_ssaddr));
697 <        comm_connect_tcp(&client_p->localClient->fd, conf->host, conf->port,
697 >        comm_connect_tcp(&client_p->connection->fd, conf->host, conf->port,
698                           (struct sockaddr *)&ipn, ipn.ss_len,
699                           serv_connect_callback, client_p, conf->aftype,
700                           CONNECTTIMEOUT);
701        }
702        else
703 <        comm_connect_tcp(&client_p->localClient->fd, conf->host, conf->port,
703 >        comm_connect_tcp(&client_p->connection->fd, conf->host, conf->port,
704                           NULL, 0, serv_connect_callback, client_p, conf->aftype,
705                           CONNECTTIMEOUT);
706        break;
# Line 719 | Line 719 | serv_connect(struct MaskItem *conf, stru
719            memcpy(&ipn, &conf->bind, sizeof(struct irc_ssaddr));
720            ipn.ss.ss_family = AF_INET6;
721            ipn.ss_port = 0;
722 <          comm_connect_tcp(&client_p->localClient->fd,
722 >          comm_connect_tcp(&client_p->connection->fd,
723                             conf->host, conf->port,
724                             (struct sockaddr *)&ipn, ipn.ss_len,
725                             serv_connect_callback, client_p,
# Line 730 | Line 730 | serv_connect(struct MaskItem *conf, stru
730            memcpy(&ipn, &ConfigServerInfo.ip6, sizeof(struct irc_ssaddr));
731            ipn.ss.ss_family = AF_INET6;
732            ipn.ss_port = 0;
733 <          comm_connect_tcp(&client_p->localClient->fd,
733 >          comm_connect_tcp(&client_p->connection->fd,
734                             conf->host, conf->port,
735                             (struct sockaddr *)&ipn, ipn.ss_len,
736                             serv_connect_callback, client_p,
737                             conf->aftype, CONNECTTIMEOUT);
738          }
739          else
740 <          comm_connect_tcp(&client_p->localClient->fd,
740 >          comm_connect_tcp(&client_p->connection->fd,
741                             conf->host, conf->port,
742                             NULL, 0, serv_connect_callback, client_p,
743                             conf->aftype, CONNECTTIMEOUT);
# Line 753 | Line 753 | finish_ssl_server_handshake(struct Clien
753   {
754    struct MaskItem *conf = NULL;
755  
756 <  conf = find_conf_name(&client_p->localClient->confs,
756 >  conf = find_conf_name(&client_p->connection->confs,
757                          client_p->name, CONF_SERVER);
758    if (conf == NULL)
759    {
760 <    sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
761 <                         "Lost connect{} block for %s", get_client_name(client_p, HIDE_IP));
762 <    sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
760 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
761 >                         "Lost connect{} block for %s", get_client_name(client_p, SHOW_IP));
762 >    sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
763                           "Lost connect{} block for %s", get_client_name(client_p, MASK_IP));
764  
765      exit_client(client_p, "Lost connect{} block");
# Line 768 | Line 768 | finish_ssl_server_handshake(struct Clien
768  
769    sendto_one(client_p, "PASS %s TS %d %s", conf->spasswd, TS_CURRENT, me.id);
770  
771 <  send_capabilities(client_p, 0);
771 >  send_capabilities(client_p);
772  
773    sendto_one(client_p, "SERVER %s 1 :%s%s",
774               me.name, ConfigServerHide.hidden ? "(H) " : "",
775               me.info);
776  
777 <  /* If we've been marked dead because a send failed, just exit
777 >  /*
778 >   * If we've been marked dead because a send failed, just exit
779     * here now and save everyone the trouble of us ever existing.
780     */
781    if (IsDead(client_p))
782    {
783 <      sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
784 <                           "%s[%s] went dead during handshake",
785 <                           client_p->name,
786 <                           client_p->host);
787 <      sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
787 <                           "%s went dead during handshake", client_p->name);
788 <      return;
783 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
784 >                         "%s went dead during handshake", get_client_name(client_p, SHOW_IP));
785 >    sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
786 >                         "%s went dead during handshake", get_client_name(client_p, MASK_IP));
787 >    return;
788    }
789  
790    /* don't move to serv_list yet -- we haven't sent a burst! */
791    /* If we get here, we're ok, so lets start reading some data */
792 <  comm_setselect(&client_p->localClient->fd, COMM_SELECT_READ, read_packet, client_p, 0);
792 >  comm_setselect(&client_p->connection->fd, COMM_SELECT_READ, read_packet, client_p, 0);
793   }
794  
795   static void
796 < ssl_server_handshake(fde_t *fd, struct Client *client_p)
796 > ssl_server_handshake(fde_t *fd, void *data)
797   {
798 +  struct Client *client_p = data;
799    X509 *cert = NULL;
800    int ret = 0;
801  
802 <  if ((ret = SSL_connect(client_p->localClient->fd.ssl)) <= 0)
802 >  if ((ret = SSL_connect(client_p->connection->fd.ssl)) <= 0)
803    {
804 <    switch (SSL_get_error(client_p->localClient->fd.ssl, ret))
804 >    if ((CurrentTime - client_p->connection->firsttime) > CONNECTTIMEOUT)
805 >    {
806 >      exit_client(client_p, "Timeout during SSL handshake");
807 >      return;
808 >    }
809 >
810 >    switch (SSL_get_error(client_p->connection->fd.ssl, ret))
811      {
812        case SSL_ERROR_WANT_WRITE:
813 <        comm_setselect(&client_p->localClient->fd, COMM_SELECT_WRITE,
814 <                       (PF *)ssl_server_handshake, client_p, 0);
813 >        comm_setselect(&client_p->connection->fd, COMM_SELECT_WRITE,
814 >                       ssl_server_handshake, client_p, CONNECTTIMEOUT);
815          return;
816        case SSL_ERROR_WANT_READ:
817 <        comm_setselect(&client_p->localClient->fd, COMM_SELECT_READ,
818 <                       (PF *)ssl_server_handshake, client_p, 0);
817 >        comm_setselect(&client_p->connection->fd, COMM_SELECT_READ,
818 >                       ssl_server_handshake, client_p, CONNECTTIMEOUT);
819          return;
820        default:
821        {
822          const char *sslerr = ERR_error_string(ERR_get_error(), NULL);
823 <        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
823 >        sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
824                               "Error connecting to %s: %s", client_p->name,
825                               sslerr ? sslerr : "unknown SSL error");
826          exit_client(client_p, "Error during SSL handshake");
# Line 823 | Line 829 | ssl_server_handshake(fde_t *fd, struct C
829      }
830    }
831  
832 <  if ((cert = SSL_get_peer_certificate(client_p->localClient->fd.ssl)))
832 >  comm_settimeout(&client_p->connection->fd, 0, NULL, NULL);
833 >
834 >  if ((cert = SSL_get_peer_certificate(client_p->connection->fd.ssl)))
835    {
836 <    int res = SSL_get_verify_result(client_p->localClient->fd.ssl);
836 >    int res = SSL_get_verify_result(client_p->connection->fd.ssl);
837      char buf[EVP_MAX_MD_SIZE * 2 + 1] = "";
838      unsigned char md[EVP_MAX_MD_SIZE] = "";
839  
# Line 851 | Line 859 | ssl_server_handshake(fde_t *fd, struct C
859   }
860  
861   static void
862 < ssl_connect_init(struct Client *client_p, struct MaskItem *conf, fde_t *fd)
862 > ssl_connect_init(struct Client *client_p, const struct MaskItem *conf, fde_t *fd)
863   {
864 <  if ((client_p->localClient->fd.ssl = SSL_new(ConfigServerInfo.client_ctx)) == NULL)
864 >  if ((client_p->connection->fd.ssl = SSL_new(ConfigServerInfo.client_ctx)) == NULL)
865    {
866      ilog(LOG_TYPE_IRCD, "SSL_new() ERROR! -- %s",
867           ERR_error_string(ERR_get_error(), NULL));
# Line 865 | Line 873 | ssl_connect_init(struct Client *client_p
873    SSL_set_fd(fd->ssl, fd->fd);
874  
875    if (!EmptyString(conf->cipher_list))
876 <    SSL_set_cipher_list(client_p->localClient->fd.ssl, conf->cipher_list);
876 >    SSL_set_cipher_list(client_p->connection->fd.ssl, conf->cipher_list);
877  
878    ssl_server_handshake(NULL, client_p);
879   }
# Line 882 | Line 890 | ssl_connect_init(struct Client *client_p
890   static void
891   serv_connect_callback(fde_t *fd, int status, void *data)
892   {
893 <  struct Client *client_p = data;
894 <  struct MaskItem *conf = NULL;
893 >  struct Client *const client_p = data;
894 >  const struct MaskItem *conf = NULL;
895  
896    /* First, make sure it's a real client! */
897    assert(client_p);
898 <  assert(&client_p->localClient->fd == fd);
898 >  assert(&client_p->connection->fd == fd);
899  
900    /* Next, for backward purposes, record the ip of the server */
901 <  memcpy(&client_p->localClient->ip, &fd->connect.hostaddr,
901 >  memcpy(&client_p->connection->ip, &fd->connect.hostaddr,
902           sizeof(struct irc_ssaddr));
903  
904    /* Check the status */
905    if (status != COMM_OK)
906    {
907 <    /* We have an error, so report it and quit
908 <     * Admins get to see any IP, mere opers don't *sigh*
907 >    /* We have an error, so report it and quit */
908 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
909 >                         "Error connecting to %s: %s",
910 >                         get_client_name(client_p, SHOW_IP), comm_errstr(status));
911 >    sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
912 >                         "Error connecting to %s: %s",
913 >                         get_client_name(client_p, MASK_IP), comm_errstr(status));
914 >
915 >    /*
916 >     * If a fd goes bad, call dead_link() the socket is no
917 >     * longer valid for reading or writing.
918       */
919 <     if (ConfigServerHide.hide_server_ips)
920 <       sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
904 <                            "Error connecting to %s: %s",
905 <                            client_p->name, comm_errstr(status));
906 <     else
907 <       sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
908 <                            "Error connecting to %s[%s]: %s", client_p->name,
909 <                            client_p->host, comm_errstr(status));
910 <
911 <     sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
912 <                          "Error connecting to %s: %s",
913 <                          client_p->name, comm_errstr(status));
914 <
915 <     /* If a fd goes bad, call dead_link() the socket is no
916 <      * longer valid for reading or writing.
917 <      */
918 <     dead_link_on_write(client_p, 0);
919 <     return;
919 >    dead_link_on_write(client_p, 0);
920 >    return;
921    }
922  
923    /* COMM_OK, so continue the connection procedure */
924    /* Get the C/N lines */
925 <  conf = find_conf_name(&client_p->localClient->confs,
925 >  conf = find_conf_name(&client_p->connection->confs,
926                          client_p->name, CONF_SERVER);
927    if (conf == NULL)
928    {
929 <    sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
930 <                         "Lost connect{} block for %s", get_client_name(client_p, HIDE_IP));
931 <    sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
929 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
930 >                         "Lost connect{} block for %s", get_client_name(client_p, SHOW_IP));
931 >    sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
932                           "Lost connect{} block for %s", get_client_name(client_p, MASK_IP));
933  
934      exit_client(client_p, "Lost connect{} block");
# Line 947 | Line 948 | serv_connect_callback(fde_t *fd, int sta
948  
949    sendto_one(client_p, "PASS %s TS %d %s", conf->spasswd, TS_CURRENT, me.id);
950  
951 <  send_capabilities(client_p, 0);
951 >  send_capabilities(client_p);
952  
953    sendto_one(client_p, "SERVER %s 1 :%s%s", me.name,
954               ConfigServerHide.hidden ? "(H) " : "", me.info);
955  
956 <  /* If we've been marked dead because a send failed, just exit
956 >  /*
957 >   * If we've been marked dead because a send failed, just exit
958     * here now and save everyone the trouble of us ever existing.
959     */
960    if (IsDead(client_p))
961    {
962 <      sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
963 <                           "%s[%s] went dead during handshake",
964 <                           client_p->name,
965 <                           client_p->host);
966 <      sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
965 <                           "%s went dead during handshake", client_p->name);
966 <      return;
962 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
963 >                         "%s went dead during handshake", get_client_name(client_p, SHOW_IP));
964 >    sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
965 >                         "%s went dead during handshake", get_client_name(client_p, MASK_IP));
966 >    return;
967    }
968  
969    /* 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)