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-8/src/s_serv.c (file contents):
Revision 1303 by michael, Fri Mar 23 10:52:19 2012 UTC vs.
Revision 1483 by michael, Wed Jul 25 19:15:48 2012 UTC

# Line 43 | Line 43
43   #include "numeric.h"
44   #include "packet.h"
45   #include "irc_res.h"
46 < #include "s_conf.h"
46 > #include "conf.h"
47   #include "s_serv.h"
48 < #include "s_log.h"
48 > #include "log.h"
49   #include "s_misc.h"
50   #include "s_user.h"
51   #include "send.h"
# Line 62 | Line 62 | static void send_tb(struct Client *clien
62  
63   static CNCB serv_connect_callback;
64  
65 static void start_io(struct Client *);
65   static void burst_members(struct Client *, struct Channel *);
66  
67   /*
# Line 82 | Line 81 | write_links_file(void* notused)
81    MessageFileLine *newMessageLine = 0;
82    MessageFile *MessageFileptr;
83    const char *p;
84 <  FBFILE *file;
84 >  FILE *file;
85    char buff[512];
86    dlink_node *ptr;
87  
88    MessageFileptr = &ConfigFileEntry.linksfile;
89  
90 <  if ((file = fbopen(MessageFileptr->fileName, "w")) == NULL)
90 >  if ((file = fopen(MessageFileptr->fileName, "w")) == NULL)
91      return;
92  
93    for (mptr = MessageFileptr->contentsOfFile; mptr; mptr = next_mptr)
# Line 102 | Line 101 | write_links_file(void* notused)
101  
102    DLINK_FOREACH(ptr, global_serv_list.head)
103    {
104 <    size_t nbytes = 0;
106 <    struct Client *target_p = ptr->data;
104 >    const struct Client *target_p = ptr->data;
105  
106      /* skip ourselves, we send ourselves in /links */
107      if (IsMe(target_p))
# Line 134 | Line 132 | write_links_file(void* notused)
132       */
133      assert(strlen(target_p->name) + strlen(me.name) + 6 + strlen(p) <=
134              MESSAGELINELEN);
135 <    ircsprintf(newMessageLine->line, "%s %s :1 %s",
136 <               target_p->name, me.name, p);
135 >    snprintf(newMessageLine->line, sizeof(newMessageLine->line), "%s %s :1 %s",
136 >             target_p->name, me.name, p);
137      newMessageLine->next = NULL;
138  
139      if (MessageFileptr->contentsOfFile)
# Line 150 | Line 148 | write_links_file(void* notused)
148        currentMessageLine = newMessageLine;
149      }
150  
151 <    nbytes = ircsprintf(buff, "%s %s :1 %s\n", target_p->name, me.name, p);
152 <    fbputs(buff, file, nbytes);
151 >    snprintf(buff, sizeof(buff), "%s %s :1 %s\n", target_p->name, me.name, p);
152 >    fputs(buff, file);
153    }
154  
155 <  fbclose(file);
155 >  fclose(file);
156   }
157  
158   /* hunt_server()
# Line 185 | Line 183 | hunt_server(struct Client *client_p, str
183    dlink_node *ptr;
184    int wilds;
185  
186 <  /* Assume it's me, if no server
187 <   */
188 <  if (parc <= server || EmptyString(parv[server]) ||
189 <      match(me.name, parv[server]) ||
190 <      match(parv[server], me.name) ||
191 <      !strcmp(parv[server], me.id))
194 <    return(HUNTED_ISME);
186 >  /* Assume it's me, if no server */
187 >  if (parc <= server || EmptyString(parv[server]))
188 >    return HUNTED_ISME;
189 >
190 >  if (!strcmp(parv[server], me.id) || match(parv[server], me.name))
191 >    return HUNTED_ISME;
192  
193    /* These are to pickup matches that would cause the following
194     * message to go in the wrong direction while doing quick fast
# Line 211 | Line 208 | hunt_server(struct Client *client_p, str
208        target_p = NULL;
209  
210    collapse(parv[server]);
211 <  wilds = (strchr(parv[server], '?') || strchr(parv[server], '*'));
211 >  wilds = has_wildcards(parv[server]);
212  
213    /* Again, if there are no wild cards involved in the server
214     * name, use the hash lookup
# Line 327 | Line 324 | try_connections(void *unused)
324        confrq = DEFAULT_CONNECTFREQUENCY;
325      else
326      {
327 <      confrq = ConFreq(cltmp);
328 <      if (confrq < MIN_CONN_FREQ )
327 >      confrq = cltmp->con_freq;
328 >      if (confrq < MIN_CONN_FREQ)
329          confrq = MIN_CONN_FREQ;
330      }
331  
# Line 340 | Line 337 | try_connections(void *unused)
337      if (hash_find_server(conf->name) != NULL)
338        continue;
339  
340 <    if (CurrUserCount(cltmp) < MaxTotal(cltmp))
340 >    if (cltmp->curr_user_count < cltmp->max_total)
341      {
342        /* Go to the end of the list, if not already last */
343        if (ptr->next != NULL)
# Line 407 | Line 404 | check_server(const char *name, struct Cl
404  
405    assert(client_p != NULL);
406  
410  if (client_p == NULL)
411    return(error);
412
413  if (strlen(name) > HOSTLEN)
414    return(-4);
415
407    /* loop through looking for all possible connect items that might work */
408    DLINK_FOREACH(ptr, server_items.head)
409    {
# Line 430 | Line 421 | check_server(const char *name, struct Cl
421          match(aconf->host, client_p->sockhost))
422      {
423        error = -2;
433      {
434        /* A NULL password is as good as a bad one */
435        if (EmptyString(client_p->localClient->passwd))
436          return(-2);
437
438        /* code in s_conf.c should not have allowed this to be NULL */
439        if (aconf->passwd == NULL)
440          return(-2);
424  
425 <        if (IsConfEncrypted(aconf))
426 <        {
427 <          if (strcmp(aconf->passwd,
428 <              (const char *)crypt(client_p->localClient->passwd,
446 <                                  aconf->passwd)) == 0)
447 <            server_conf = conf;
448 <        }
449 <        else
450 <        {
451 <          if (strcmp(aconf->passwd, client_p->localClient->passwd) == 0)
452 <            server_conf = conf;
453 <        }
454 <      }
425 >      if (!match_conf_password(client_p->localClient->passwd, aconf))
426 >        return -2;
427 >
428 >      server_conf = conf;
429      }
430    }
431  
# Line 460 | Line 434 | check_server(const char *name, struct Cl
434  
435    attach_conf(client_p, server_conf);
436  
463  /* Now find all leaf or hub config items for this server */
464  DLINK_FOREACH(ptr, hub_items.head)
465  {
466    conf = ptr->data;
467
468    if (!match(name, conf->name))
469      continue;
470    attach_conf(client_p, conf);
471  }
472
473  DLINK_FOREACH(ptr, leaf_items.head)
474  {
475    conf = ptr->data;
476
477    if (!match(name, conf->name))
478      continue;
479    attach_conf(client_p, conf);
480  }
481
437    server_aconf = map_to_conf(server_conf);
438  
439    if (!IsConfTopicBurst(server_aconf))
485  {
486    ClearCap(client_p, CAP_TB);
440      ClearCap(client_p, CAP_TBURST);
488  }
441  
442    if (aconf != NULL)
443    {
# Line 497 | Line 449 | check_server(const char *name, struct Cl
449      {
450   #ifdef IPV6
451        case AF_INET6:
452 <        v6 = (struct sockaddr_in6 *)&aconf->ipnum;
452 >        v6 = (struct sockaddr_in6 *)&aconf->addr;
453  
454          if (IN6_IS_ADDR_UNSPECIFIED(&v6->sin6_addr))
455 <          memcpy(&aconf->ipnum, &client_p->localClient->ip, sizeof(struct irc_ssaddr));
455 >          memcpy(&aconf->addr, &client_p->localClient->ip, sizeof(struct irc_ssaddr));
456          break;
457   #endif
458        case AF_INET:
459 <        v4 = (struct sockaddr_in *)&aconf->ipnum;
459 >        v4 = (struct sockaddr_in *)&aconf->addr;
460  
461          if (v4->sin_addr.s_addr == INADDR_NONE)
462 <          memcpy(&aconf->ipnum, &client_p->localClient->ip, sizeof(struct irc_ssaddr));
462 >          memcpy(&aconf->addr, &client_p->localClient->ip, sizeof(struct irc_ssaddr));
463          break;
464      }
465    }
# Line 690 | Line 642 | sendnick_TS(struct Client *client_p, str
642                   target_p->servptr->name, target_p->info);
643    }
644  
645 <  if (IsConfAwayBurst((struct AccessItem *)map_to_conf(client_p->serv->sconf)))
646 <    if (!EmptyString(target_p->away))
647 <      sendto_one(client_p, ":%s AWAY :%s", target_p->name,
645 >  if (IsConfAwayBurst((struct AccessItem *)map_to_conf(client_p->localClient->confs.head->data)))
646 >    if (target_p->away[0])
647 >      sendto_one(client_p, ":%s AWAY :%s", ID_or_name(target_p, client_p),
648                   target_p->away);
649  
650   }
# Line 757 | Line 709 | server_estab(struct Client *client_p)
709    const char *inpath;
710    static char inpath_ip[HOSTLEN * 2 + USERLEN + 6];
711    dlink_node *ptr;
712 + #ifdef HAVE_LIBCRYPTO
713 +  const COMP_METHOD *compression = NULL, *expansion = NULL;
714 + #endif
715  
716    assert(client_p != NULL);
717  
# Line 814 | Line 769 | server_estab(struct Client *client_p)
769       */
770  
771      send_capabilities(client_p, aconf,
772 <      (IsConfTopicBurst(aconf) ? CAP_TBURST|CAP_TB : 0));
772 >      (IsConfTopicBurst(aconf) ? CAP_TBURST : 0));
773  
774      sendto_one(client_p, "SERVER %s 1 :%s%s",
775                 me.name, ConfigServerHide.hidden ? "(H) " : "", me.info);
# Line 874 | Line 829 | server_estab(struct Client *client_p)
829      AddFlag(client_p, FLAGS_SERVICE);
830  
831    /* Show the real host/IP to admins */
832 + #ifdef HAVE_LIBCRYPTO
833    if (client_p->localClient->fd.ssl)
834    {
835 +    compression = SSL_get_current_compression(client_p->localClient->fd.ssl);
836 +    expansion   = SSL_get_current_expansion(client_p->localClient->fd.ssl);
837 +
838      sendto_realops_flags(UMODE_ALL, L_ADMIN,
839 <                         "Link with %s established: [SSL: %s] (Capabilities: %s)",
839 >                         "Link with %s established: [SSL: %s, Compression/Expansion method: %s/%s] (Capabilities: %s)",
840                           inpath_ip, ssl_get_cipher(client_p->localClient->fd.ssl),
841 +                         compression ? SSL_COMP_get_name(compression) : "NONE",
842 +                         expansion ? SSL_COMP_get_name(expansion) : "NONE",
843                           show_capabilities(client_p));
844      /* Now show the masked hostname/IP to opers */
845      sendto_realops_flags(UMODE_ALL, L_OPER,
846 <                         "Link with %s established: [SSL: %s] (Capabilities: %s)",
846 >                         "Link with %s established: [SSL: %s, Compression/Expansion method: %s/%s] (Capabilities: %s)",
847                           inpath, ssl_get_cipher(client_p->localClient->fd.ssl),
848 +                         compression ? SSL_COMP_get_name(compression) : "NONE",
849 +                         expansion ? SSL_COMP_get_name(expansion) : "NONE",
850                           show_capabilities(client_p));
851 <    ilog(LOG_TYPE_IRCD, "Link with %s established: [SSL: %s] (Capabilities: %s)",
851 >    ilog(LOG_TYPE_IRCD, "Link with %s established: [SSL: %s, Compression/Expansion method: %s/%s] (Capabilities: %s)",
852           inpath_ip, ssl_get_cipher(client_p->localClient->fd.ssl),
853 +         compression ? SSL_COMP_get_name(compression) : "NONE",
854 +         expansion ? SSL_COMP_get_name(expansion) : "NONE",
855           show_capabilities(client_p));
856    }
857    else
858 + #endif
859    {
860      sendto_realops_flags(UMODE_ALL, L_ADMIN,
861                           "Link with %s established: (Capabilities: %s)",
# Line 902 | Line 868 | server_estab(struct Client *client_p)
868           inpath_ip, show_capabilities(client_p));
869    }
870  
905  client_p->serv->sconf = conf;
906
871    fd_note(&client_p->localClient->fd, "Server: %s", client_p->name);
872  
873    /* Old sendto_serv_but_one() call removed because we now
# Line 1024 | Line 988 | burst_all(struct Client *client_p)
988        burst_members(client_p, chptr);
989        send_channel_modes(client_p, chptr);
990  
991 <      if (IsCapable(client_p, CAP_TBURST) ||
1028 <          IsCapable(client_p, CAP_TB))
991 >      if (IsCapable(client_p, CAP_TBURST))
992          send_tb(client_p, chptr);
993      }
994    }
# Line 1057 | Line 1020 | burst_all(struct Client *client_p)
1020   *              - pointer to channel
1021   * output       - NONE
1022   * side effects - Called on a server burst when
1023 < *                server is CAP_TB|CAP_TBURST capable
1023 > *                server is CAP_TBURST capable
1024   */
1025   static void
1026   send_tb(struct Client *client_p, struct Channel *chptr)
# Line 1076 | Line 1039 | send_tb(struct Client *client_p, struct
1039     * for further information   -Michael
1040     */
1041    if (chptr->topic_time != 0)
1042 <  {
1043 <    if (IsCapable(client_p, CAP_TBURST))
1044 <      sendto_one(client_p, ":%s TBURST %lu %s %lu %s :%s",
1045 <                 me.name, (unsigned long)chptr->channelts, chptr->chname,
1046 <                 (unsigned long)chptr->topic_time,
1047 <                 chptr->topic_info,
1085 <                 chptr->topic);
1086 <    else if (IsCapable(client_p, CAP_TB))
1087 <    {
1088 <      if (ConfigChannel.burst_topicwho)
1089 <      {
1090 <        sendto_one(client_p, ":%s TB %s %lu %s :%s",
1091 <                   me.name, chptr->chname,
1092 <                   (unsigned long)chptr->topic_time,
1093 <                   chptr->topic_info, chptr->topic);
1094 <      }
1095 <      else
1096 <      {
1097 <        sendto_one(client_p, ":%s TB %s %lu :%s",
1098 <                   me.name, chptr->chname,
1099 <                   (unsigned long)chptr->topic_time,
1100 <                   chptr->topic);
1101 <      }
1102 <    }
1103 <  }
1042 >    sendto_one(client_p, ":%s TBURST %lu %s %lu %s :%s",
1043 >               ID_or_name(&me, client_p),
1044 >               (unsigned long)chptr->channelts, chptr->chname,
1045 >               (unsigned long)chptr->topic_time,
1046 >               chptr->topic_info,
1047 >               chptr->topic);
1048   }
1049  
1050   /* burst_members()
# Line 1158 | Line 1102 | serv_connect(struct AccessItem *aconf, s
1102   {
1103    struct ConfItem *conf;
1104    struct Client *client_p;
1105 <  char buf[HOSTIPLEN];
1105 >  char buf[HOSTIPLEN + 1];
1106  
1107    /* conversion structs */
1108    struct sockaddr_in *v4;
1109    /* Make sure aconf is useful */
1110    assert(aconf != NULL);
1111  
1168  if(aconf == NULL)
1169    return (0);
1170
1112    /* XXX should be passing struct ConfItem in the first place */
1113    conf = unmap_conf_item(aconf);
1114  
1115    /* log */
1116 <  getnameinfo((struct sockaddr *)&aconf->ipnum, aconf->ipnum.ss_len,
1116 >  getnameinfo((struct sockaddr *)&aconf->addr, aconf->addr.ss_len,
1117                buf, sizeof(buf), NULL, 0, NI_NUMERICHOST);
1118 <  ilog(LOG_TYPE_IRCD, "Connect to %s[%s] @%s", aconf->user, aconf->host,
1118 >  ilog(LOG_TYPE_IRCD, "Connect to %s[%s] @%s", conf->name, aconf->host,
1119         buf);
1120  
1121    /* Still processing a DNS lookup? -> exit */
# Line 1223 | Line 1164 | serv_connect(struct AccessItem *aconf, s
1164    strlcpy(client_p->sockhost, buf, sizeof(client_p->sockhost));
1165  
1166    /* create a socket for the server connection */
1167 <  if (comm_open(&client_p->localClient->fd, aconf->ipnum.ss.ss_family,
1167 >  if (comm_open(&client_p->localClient->fd, aconf->addr.ss.ss_family,
1168                  SOCK_STREAM, 0, NULL) < 0)
1169    {
1170      /* Eek, failure to create the socket */
# Line 1278 | Line 1219 | serv_connect(struct AccessItem *aconf, s
1219    switch (aconf->aftype)
1220    {
1221      case AF_INET:
1222 <      v4 = (struct sockaddr_in*)&aconf->my_ipnum;
1222 >      v4 = (struct sockaddr_in*)&aconf->bind;
1223        if (v4->sin_addr.s_addr != 0)
1224        {
1225          struct irc_ssaddr ipn;
1226          memset(&ipn, 0, sizeof(struct irc_ssaddr));
1227          ipn.ss.ss_family = AF_INET;
1228          ipn.ss_port = 0;
1229 <        memcpy(&ipn, &aconf->my_ipnum, sizeof(struct irc_ssaddr));
1229 >        memcpy(&ipn, &aconf->bind, sizeof(struct irc_ssaddr));
1230          comm_connect_tcp(&client_p->localClient->fd, aconf->host, aconf->port,
1231                           (struct sockaddr *)&ipn, ipn.ss_len,
1232                           serv_connect_callback, client_p, aconf->aftype,
# Line 1316 | Line 1257 | serv_connect(struct AccessItem *aconf, s
1257          struct sockaddr_in6 *v6conf;
1258  
1259          memset(&ipn, 0, sizeof(struct irc_ssaddr));
1260 <        v6conf = (struct sockaddr_in6 *)&aconf->my_ipnum;
1260 >        v6conf = (struct sockaddr_in6 *)&aconf->bind;
1261          v6 = (struct sockaddr_in6 *)&ipn;
1262  
1263          if (memcmp(&v6conf->sin6_addr, &v6->sin6_addr,
1264                     sizeof(struct in6_addr)) != 0)
1265          {
1266 <          memcpy(&ipn, &aconf->my_ipnum, sizeof(struct irc_ssaddr));
1266 >          memcpy(&ipn, &aconf->bind, sizeof(struct irc_ssaddr));
1267            ipn.ss.ss_family = AF_INET6;
1268            ipn.ss_port = 0;
1269            comm_connect_tcp(&client_p->localClient->fd,
# Line 1381 | Line 1322 | finish_ssl_server_handshake(struct Clien
1322                 aconf->spasswd, TS_CURRENT, me.id);
1323  
1324    send_capabilities(client_p, aconf,
1325 <                   (IsConfTopicBurst(aconf) ? CAP_TBURST|CAP_TB : 0));
1325 >                   (IsConfTopicBurst(aconf) ? CAP_TBURST : 0));
1326  
1327    sendto_one(client_p, "SERVER %s 1 :%s%s",
1328               me.name, ConfigServerHide.hidden ? "(H) " : "",
# Line 1407 | Line 1348 | finish_ssl_server_handshake(struct Clien
1348   }
1349  
1350   static void
1351 < ssl_server_handshake(struct Client *client_p)
1351 > ssl_server_handshake(fde_t *fd, struct Client *client_p)
1352   {
1353    int ret;
1354    int err;
# Line 1420 | Line 1361 | ssl_server_handshake(struct Client *clie
1361      {
1362        case SSL_ERROR_WANT_WRITE:
1363          comm_setselect(&client_p->localClient->fd, COMM_SELECT_WRITE,
1364 <            (PF *) ssl_server_handshake, client_p, 0);
1364 >                       (PF *)ssl_server_handshake, client_p, 0);
1365          return;
1366        case SSL_ERROR_WANT_READ:
1367          comm_setselect(&client_p->localClient->fd, COMM_SELECT_READ,
1368 <            (PF *) ssl_server_handshake, client_p, 0);
1368 >                       (PF *)ssl_server_handshake, client_p, 0);
1369          return;
1370        default:
1371 +      {
1372 +        const char *sslerr = ERR_error_string(ERR_get_error(), NULL);
1373 +        sendto_realops_flags(UMODE_ALL, L_ALL,
1374 +                             "Error connecting to %s: %s", client_p->name,
1375 +                             sslerr ? sslerr : "unknown SSL error");
1376          exit_client(client_p, client_p, "Error during SSL handshake");
1377          return;
1378 +      }
1379      }
1380    }
1381  
# Line 1436 | Line 1383 | ssl_server_handshake(struct Client *clie
1383   }
1384  
1385   static void
1386 < ssl_connect_init(struct Client *client_p, fde_t *fd)
1386 > ssl_connect_init(struct Client *client_p, struct AccessItem *aconf, fde_t *fd)
1387   {
1388    if ((client_p->localClient->fd.ssl = SSL_new(ServerInfo.client_ctx)) == NULL)
1389    {
# Line 1448 | Line 1395 | ssl_connect_init(struct Client *client_p
1395    }
1396  
1397    SSL_set_fd(fd->ssl, fd->fd);
1398 <  ssl_server_handshake(client_p);
1398 >
1399 >  if (!EmptyString(aconf->cipher_list))
1400 >    SSL_set_cipher_list(client_p->localClient->fd.ssl, aconf->cipher_list);
1401 >
1402 >  ssl_server_handshake(NULL, client_p);
1403   }
1404   #endif
1405  
# Line 1522 | Line 1473 | serv_connect_callback(fde_t *fd, int sta
1473   #ifdef HAVE_LIBCRYPTO
1474    if (IsConfSSL(aconf))
1475    {
1476 <    ssl_connect_init(client_p, fd);
1476 >    ssl_connect_init(client_p, aconf, fd);
1477      return;
1478    }
1479   #endif
# Line 1533 | Line 1484 | serv_connect_callback(fde_t *fd, int sta
1484                 aconf->spasswd, TS_CURRENT, me.id);
1485  
1486    send_capabilities(client_p, aconf,
1487 <                   (IsConfTopicBurst(aconf) ? CAP_TBURST|CAP_TB : 0));
1487 >                   (IsConfTopicBurst(aconf) ? CAP_TBURST : 0));
1488  
1489    sendto_one(client_p, "SERVER %s 1 :%s%s",
1490               me.name, ConfigServerHide.hidden ? "(H) " : "",

Diff Legend

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