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 8436 by michael, Thu Mar 29 09:04:53 2018 UTC vs.
Revision 8878 by michael, Sun Feb 24 09:12:52 2019 UTC

# Line 1 | Line 1
1   /*
2   *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (c) 1997-2018 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 186 | Line 186 | server_hunt(struct Client *source_p, con
186      if (h->target_p->from == source_p->from && !MyConnect(h->target_p))
187        h->target_p = NULL;
188  
189 <  if (!h->target_p && has_wildcards(parv[server]))
189 >  if (h->target_p == NULL && has_wildcards(parv[server]))
190    {
191      DLINK_FOREACH(node, global_server_list.head)
192      {
193        struct Client *tmp = node->data;
194  
195        assert(IsMe(tmp) || IsServer(tmp));
196 <      if (!match(parv[server], tmp->name))
196 >      if (match(parv[server], tmp->name) == 0)
197        {
198          if (tmp->from == source_p->from && !MyConnect(tmp))
199            continue;
# Line 203 | Line 203 | server_hunt(struct Client *source_p, con
203        }
204      }
205  
206 <    if (!h->target_p)
206 >    if (h->target_p == NULL)
207      {
208        DLINK_FOREACH(node, global_client_list.head)
209        {
210          struct Client *tmp = node->data;
211  
212          assert(IsClient(tmp));
213 <        if (!match(parv[server], tmp->name))
213 >        if (match(parv[server], tmp->name) == 0)
214          {
215            if (tmp->from == source_p->from && !MyConnect(tmp))
216              continue;
# Line 259 | Line 259 | try_connections(void *unused)
259   {
260    dlink_node *node;
261  
262 <  if (GlobalSetOptions.autoconn == 0)
262 >  if (GlobalSetOptions.autoconn == false)
263      return;
264  
265    DLINK_FOREACH(node, connect_items.head)
# Line 329 | Line 329 | try_connections(void *unused)
329    }
330   }
331  
332 < int
332 > bool
333   server_valid_name(const char *name)
334   {
335    unsigned int dots = 0;
# Line 338 | Line 338 | server_valid_name(const char *name)
338    for (; *p; ++p)
339    {
340      if (!IsServChar(*p))
341 <      return 0;
341 >      return false;
342  
343      if (*p == '.')
344        ++dots;
# Line 379 | Line 379 | server_make(struct Client *client_p)
379   * We return 1 if the connection is attempted, since we don't know whether
380   * it suceeded or not, and 0 if it fails in here somewhere.
381   */
382 < int
382 > bool
383   server_connect(struct MaskItem *conf, struct Client *by)
384   {
385    char buf[HOSTIPLEN + 1] = "";
386  
387  /* conversion structs */
388  struct sockaddr_in *v4;
389
387    /* Make sure conf is useful */
388    assert(conf);
389    assert(conf->type == CONF_SERVER);
390    assert(hash_find_server(conf->name) == NULL);  /* This should have been checked by the caller */
391  
395  getnameinfo((const struct sockaddr *)&conf->addr, conf->addr.ss_len,
396              buf, sizeof(buf), NULL, 0, NI_NUMERICHOST);
397  ilog(LOG_TYPE_IRCD, "Connect to %s[%s] @%s", conf->name, conf->host, buf);
398
392    /* Still processing a DNS lookup? -> exit */
393 <  if (conf->dns_pending)
393 >  if (conf->dns_pending == true)
394    {
395      sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
396                           "Error connecting to %s: DNS lookup for connect{} in progress.",
397                           conf->name);
398 <    return 0;
398 >    return false;
399    }
400  
401 <  if (conf->dns_failed)
401 >  if (conf->dns_failed == true)
402    {
403      sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
404                           "Error connecting to %s: DNS lookup for connect{} failed.",
405                           conf->name);
406 <    return 0;
406 >    return false;
407    }
408  
409 +  getnameinfo((const struct sockaddr *)conf->addr, conf->addr->ss_len,
410 +              buf, sizeof(buf), NULL, 0, NI_NUMERICHOST);
411 +  ilog(LOG_TYPE_IRCD, "Connect to %s[%s] @%s", conf->name, conf->host, buf);
412 +
413    /* Create a socket for the server connection */
414 <  int fd = comm_socket(conf->addr.ss.ss_family, SOCK_STREAM, 0);
414 >  int fd = comm_socket(conf->addr->ss.ss_family, SOCK_STREAM, 0);
415    if (fd == -1)
416    {
417      /* Eek, failure to create the socket */
418      report_error(L_ALL, "opening stream socket to %s: %s", conf->name, errno);
419 <    return 0;
419 >    return false;
420    }
421  
422    /* Create a local client */
# Line 432 | Line 429 | server_connect(struct MaskItem *conf, st
429    /* We already converted the ip once, so lets use it - stu */
430    strlcpy(client_p->sockhost, buf, sizeof(client_p->sockhost));
431  
432 <  client_p->connection->fd = fd_open(fd, 1, NULL);
432 >  memcpy(&client_p->ip, conf->addr, sizeof(client_p->ip));
433 >
434 >  client_p->connection->fd = fd_open(fd, true, NULL);
435  
436    /* Server names are always guaranteed under HOSTLEN chars */
437    fd_note(client_p->connection->fd, "Server: %s", client_p->name);
# Line 451 | Line 450 | server_connect(struct MaskItem *conf, st
450      strlcpy(client_p->serv->by, "AutoConn.", sizeof(client_p->serv->by));
451  
452    SetConnecting(client_p);
454  client_p->connection->aftype = conf->aftype;
453  
454    /* Now, initiate the connection */
455 <  /* XXX assume that a non 0 type means a specific bind address
456 <   * for this connect.
459 <   */
460 <  switch (conf->aftype)
461 <  {
462 <    case AF_INET:
463 <      v4 = (struct sockaddr_in*)&conf->bind;
464 <
465 <      if (v4->sin_addr.s_addr)
466 <      {
467 <        struct irc_ssaddr ipn;
468 <
469 <        memset(&ipn, 0, sizeof(ipn));
470 <        ipn.ss.ss_family = AF_INET;
471 <        ipn.ss_port = 0;
472 <        memcpy(&ipn, &conf->bind, sizeof(ipn));
473 <
474 <        comm_connect_tcp(client_p->connection->fd, conf->host, conf->port,
475 <                         (struct sockaddr *)&ipn, ipn.ss_len,
476 <                         server_connect_callback, client_p, conf->aftype,
477 <                         CONNECTTIMEOUT);
478 <      }
479 <      else if (ConfigServerInfo.specific_ipv4_vhost)
480 <      {
481 <        struct irc_ssaddr ipn;
482 <
483 <        memset(&ipn, 0, sizeof(ipn));
484 <        ipn.ss.ss_family = AF_INET;
485 <        ipn.ss_port = 0;
486 <        memcpy(&ipn, &ConfigServerInfo.ip, sizeof(ipn));
487 <
488 <        comm_connect_tcp(client_p->connection->fd, conf->host, conf->port,
489 <                         (struct sockaddr *)&ipn, ipn.ss_len,
490 <                         server_connect_callback, client_p, conf->aftype,
491 <                         CONNECTTIMEOUT);
492 <      }
493 <      else
494 <        comm_connect_tcp(client_p->connection->fd, conf->host, conf->port,
495 <                         NULL, 0, server_connect_callback, client_p, conf->aftype,
496 <                         CONNECTTIMEOUT);
497 <      break;
498 <    case AF_INET6:
499 <      {
500 <        struct irc_ssaddr ipn;
501 <        struct sockaddr_in6 *v6;
502 <        struct sockaddr_in6 *v6conf;
503 <
504 <        memset(&ipn, 0, sizeof(ipn));
505 <        v6conf = (struct sockaddr_in6 *)&conf->bind;
506 <        v6 = (struct sockaddr_in6 *)&ipn;
507 <
508 <        if (memcmp(&v6conf->sin6_addr, &v6->sin6_addr, sizeof(struct in6_addr)))
509 <        {
510 <          memcpy(&ipn, &conf->bind, sizeof(ipn));
511 <          ipn.ss.ss_family = AF_INET6;
512 <          ipn.ss_port = 0;
513 <
514 <          comm_connect_tcp(client_p->connection->fd,
515 <                           conf->host, conf->port,
516 <                           (struct sockaddr *)&ipn, ipn.ss_len,
517 <                           server_connect_callback, client_p,
518 <                           conf->aftype, CONNECTTIMEOUT);
519 <        }
520 <        else if (ConfigServerInfo.specific_ipv6_vhost)
521 <        {
522 <          memcpy(&ipn, &ConfigServerInfo.ip6, sizeof(ipn));
523 <          ipn.ss.ss_family = AF_INET6;
524 <          ipn.ss_port = 0;
525 <
526 <          comm_connect_tcp(client_p->connection->fd,
527 <                           conf->host, conf->port,
528 <                           (struct sockaddr *)&ipn, ipn.ss_len,
529 <                           server_connect_callback, client_p,
530 <                           conf->aftype, CONNECTTIMEOUT);
531 <        }
532 <        else
533 <          comm_connect_tcp(client_p->connection->fd,
534 <                           conf->host, conf->port,
535 <                           NULL, 0, server_connect_callback, client_p,
536 <                           conf->aftype, CONNECTTIMEOUT);
537 <      }
538 <  }
455 >  comm_connect_tcp(client_p->connection->fd, conf->addr, conf->port, conf->bind,
456 >                   server_connect_callback, client_p, CONNECTTIMEOUT);
457  
458    /*
459     * At this point we have a connection in progress and a connect {} block
# Line 544 | Line 462 | server_connect(struct MaskItem *conf, st
462     *
463     * The socket has been connected or connect is in progress.
464     */
465 <  return 1;
465 >  return true;
466   }
467  
468   static void
# Line 563 | Line 481 | server_finish_tls_handshake(struct Clien
481      return;
482    }
483  
484 +  /* Next, send the initial handshake */
485 +  SetHandshake(client_p);
486 +
487    sendto_one(client_p, "PASS %s TS %u %s", conf->spasswd, TS_CURRENT, me.id);
488  
489    sendto_one(client_p, "CAPAB :%s", capab_get(NULL));
# Line 618 | Line 539 | server_tls_handshake(fde_t *F, void *dat
539  
540    comm_settimeout(F, 0, NULL, NULL);
541  
542 <  if (!tls_verify_cert(&F->ssl, ConfigServerInfo.message_digest_algorithm, &client_p->certfp))
542 >  if (tls_verify_cert(&F->ssl, ConfigServerInfo.message_digest_algorithm, &client_p->certfp) == false)
543      ilog(LOG_TYPE_IRCD, "Server %s!%s@%s gave bad TLS client certificate",
544           client_p->name, client_p->username, client_p->host);
545  
# Line 633 | Line 554 | server_tls_connect_init(struct Client *c
554    assert(client_p->connection->fd);
555    assert(client_p->connection->fd == F);
556  
557 <  if (!tls_new(&F->ssl, F->fd, TLS_ROLE_CLIENT))
557 >  if (tls_new(&F->ssl, F->fd, TLS_ROLE_CLIENT) == false)
558    {
559      SetDead(client_p);
560      exit_client(client_p, "TLS context initialization failed");
# Line 665 | Line 586 | server_connect_callback(fde_t *F, int st
586    assert(client_p->connection->fd);
587    assert(client_p->connection->fd == F);
588  
668  /* Next, for backward purposes, record the ip of the server */
669  memcpy(&client_p->connection->ip, &F->connect.hostaddr, sizeof(client_p->connection->ip));
670
589    /* Check the status */
590    if (status != COMM_OK)
591    {
# Line 702 | Line 620 | server_connect_callback(fde_t *F, int st
620      return;
621    }
622  
705  /* Next, send the initial handshake */
706  SetHandshake(client_p);
707
623    if (IsConfSSL(conf))
624    {
625      server_tls_connect_init(client_p, conf, F);
626      return;
627    }
628  
629 +  /* Next, send the initial handshake */
630 +  SetHandshake(client_p);
631 +
632    sendto_one(client_p, "PASS %s TS %u %s", conf->spasswd, TS_CURRENT, me.id);
633  
634    sendto_one(client_p, "CAPAB :%s", capab_get(NULL));

Diff Legend

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