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 1306 by michael, Sat Mar 24 07:43:04 2012 UTC vs.
Revision 1545 by michael, Sun Sep 30 15:21:59 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 76 | Line 75 | static void burst_members(struct Client
75   void
76   write_links_file(void* notused)
77   {
78 <  MessageFileLine *next_mptr = 0;
79 <  MessageFileLine *mptr = 0;
80 <  MessageFileLine *currentMessageLine = 0;
81 <  MessageFileLine *newMessageLine = 0;
82 <  MessageFile *MessageFileptr;
83 <  const char *p;
85 <  FBFILE *file;
78 >  MessageFileLine *next_mptr = NULL;
79 >  MessageFileLine *mptr = NULL;
80 >  MessageFileLine *currentMessageLine = NULL;
81 >  MessageFileLine *newMessageLine = NULL;
82 >  MessageFile *MessageFileptr = &ConfigFileEntry.linksfile;
83 >  FILE *file;
84    char buff[512];
85    dlink_node *ptr;
86  
87 <  MessageFileptr = &ConfigFileEntry.linksfile;
90 <
91 <  if ((file = fbopen(MessageFileptr->fileName, "w")) == NULL)
87 >  if ((file = fopen(MessageFileptr->fileName, "w")) == NULL)
88      return;
89  
90    for (mptr = MessageFileptr->contentsOfFile; mptr; mptr = next_mptr)
# Line 98 | Line 94 | write_links_file(void* notused)
94    }
95  
96    MessageFileptr->contentsOfFile = NULL;
101  currentMessageLine             = NULL;
97  
98    DLINK_FOREACH(ptr, global_serv_list.head)
99    {
100 <    size_t nbytes = 0;
106 <    struct Client *target_p = ptr->data;
100 >    const struct Client *target_p = ptr->data;
101  
102      /* skip ourselves, we send ourselves in /links */
103      if (IsMe(target_p))
104        continue;
105  
106      /* skip hidden servers */
107 <    if (IsHidden(target_p) && !ConfigServerHide.disable_hidden)
107 >    if (IsHidden(target_p))
108        continue;
109  
116    if (target_p->info[0])
117      p = target_p->info;
118    else
119      p = "(Unknown Location)";
120
110      newMessageLine = MyMalloc(sizeof(MessageFileLine));
111  
112 <    /* Attempt to format the file in such a way it follows the usual links output
112 >    /*
113 >     * Attempt to format the file in such a way it follows the usual links output
114       * ie  "servername uplink :hops info"
115       * Mostly for aesthetic reasons - makes it look pretty in mIRC ;)
116       * - madmax
117       */
118 <
119 <    /*
130 <     * For now, check this ircsprintf wont overflow - it shouldnt on a
131 <     * default config but it is configurable..
132 <     * This should be changed to an snprintf at some point, but I'm wanting to
133 <     * know if this is a cause of a bug - cryogen
134 <     */
135 <    assert(strlen(target_p->name) + strlen(me.name) + 6 + strlen(p) <=
136 <            MESSAGELINELEN);
137 <    ircsprintf(newMessageLine->line, "%s %s :1 %s",
138 <               target_p->name, me.name, p);
139 <    newMessageLine->next = NULL;
118 >    snprintf(newMessageLine->line, sizeof(newMessageLine->line), "%s %s :1 %s",
119 >             target_p->name, me.name, target_p->info);
120  
121      if (MessageFileptr->contentsOfFile)
122      {
# Line 150 | Line 130 | write_links_file(void* notused)
130        currentMessageLine = newMessageLine;
131      }
132  
133 <    nbytes = ircsprintf(buff, "%s %s :1 %s\n", target_p->name, me.name, p);
134 <    fbputs(buff, file, nbytes);
133 >    snprintf(buff, sizeof(buff), "%s %s :1 %s\n",
134 >             target_p->name, me.name, target_p->info);
135 >    fputs(buff, file);
136    }
137  
138 <  fbclose(file);
138 >  fclose(file);
139   }
140  
141   /* hunt_server()
# Line 185 | Line 166 | hunt_server(struct Client *client_p, str
166    dlink_node *ptr;
167    int wilds;
168  
169 <  /* Assume it's me, if no server
170 <   */
171 <  if (parc <= server || EmptyString(parv[server]) ||
172 <      match(me.name, parv[server]) ||
173 <      match(parv[server], me.name) ||
174 <      !strcmp(parv[server], me.id))
194 <    return(HUNTED_ISME);
169 >  /* Assume it's me, if no server */
170 >  if (parc <= server || EmptyString(parv[server]))
171 >    return HUNTED_ISME;
172 >
173 >  if (!strcmp(parv[server], me.id) || match(parv[server], me.name))
174 >    return HUNTED_ISME;
175  
176    /* These are to pickup matches that would cause the following
177     * message to go in the wrong direction while doing quick fast
# Line 211 | Line 191 | hunt_server(struct Client *client_p, str
191        target_p = NULL;
192  
193    collapse(parv[server]);
194 <  wilds = (strchr(parv[server], '?') || strchr(parv[server], '*'));
194 >  wilds = has_wildcards(parv[server]);
195  
196    /* Again, if there are no wild cards involved in the server
197     * name, use the hash lookup
# Line 327 | Line 307 | try_connections(void *unused)
307        confrq = DEFAULT_CONNECTFREQUENCY;
308      else
309      {
310 <      confrq = ConFreq(cltmp);
311 <      if (confrq < MIN_CONN_FREQ )
310 >      confrq = cltmp->con_freq;
311 >      if (confrq < MIN_CONN_FREQ)
312          confrq = MIN_CONN_FREQ;
313      }
314  
# Line 340 | Line 320 | try_connections(void *unused)
320      if (hash_find_server(conf->name) != NULL)
321        continue;
322  
323 <    if (CurrUserCount(cltmp) < MaxTotal(cltmp))
323 >    if (cltmp->curr_user_count < cltmp->max_total)
324      {
325        /* Go to the end of the list, if not already last */
326        if (ptr->next != NULL)
# Line 407 | Line 387 | check_server(const char *name, struct Cl
387  
388    assert(client_p != NULL);
389  
410  if (client_p == NULL)
411    return(error);
412
413  if (strlen(name) > HOSTLEN)
414    return(-4);
415
390    /* loop through looking for all possible connect items that might work */
391    DLINK_FOREACH(ptr, server_items.head)
392    {
# Line 430 | Line 404 | check_server(const char *name, struct Cl
404          match(aconf->host, client_p->sockhost))
405      {
406        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);
407  
408 <        if (IsConfEncrypted(aconf))
409 <        {
410 <          if (strcmp(aconf->passwd,
411 <              (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 <      }
408 >      if (!match_conf_password(client_p->localClient->passwd, aconf))
409 >        return -2;
410 >
411 >      server_conf = conf;
412      }
413    }
414  
# Line 460 | Line 417 | check_server(const char *name, struct Cl
417  
418    attach_conf(client_p, server_conf);
419  
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
420    server_aconf = map_to_conf(server_conf);
421  
484  if (!IsConfTopicBurst(server_aconf))
485  {
486    ClearCap(client_p, CAP_TB);
487    ClearCap(client_p, CAP_TBURST);
488  }
489
422    if (aconf != NULL)
423    {
424      struct sockaddr_in *v4;
# Line 497 | Line 429 | check_server(const char *name, struct Cl
429      {
430   #ifdef IPV6
431        case AF_INET6:
432 <        v6 = (struct sockaddr_in6 *)&aconf->ipnum;
432 >        v6 = (struct sockaddr_in6 *)&aconf->addr;
433  
434          if (IN6_IS_ADDR_UNSPECIFIED(&v6->sin6_addr))
435 <          memcpy(&aconf->ipnum, &client_p->localClient->ip, sizeof(struct irc_ssaddr));
435 >          memcpy(&aconf->addr, &client_p->localClient->ip, sizeof(struct irc_ssaddr));
436          break;
437   #endif
438        case AF_INET:
439 <        v4 = (struct sockaddr_in *)&aconf->ipnum;
439 >        v4 = (struct sockaddr_in *)&aconf->addr;
440  
441          if (v4->sin_addr.s_addr == INADDR_NONE)
442 <          memcpy(&aconf->ipnum, &client_p->localClient->ip, sizeof(struct irc_ssaddr));
442 >          memcpy(&aconf->addr, &client_p->localClient->ip, sizeof(struct irc_ssaddr));
443          break;
444      }
445    }
# Line 652 | Line 584 | sendnick_TS(struct Client *client_p, str
584      ubuf[1] = '\0';
585    }
586  
655  /* XXX Both of these need to have a :me.name or :mySID!?!?! */
587    if (IsCapable(client_p, CAP_SVS))
588    {
589      if (HasID(target_p) && IsCapable(client_p, CAP_TS6))
# Line 690 | Line 621 | sendnick_TS(struct Client *client_p, str
621                   target_p->servptr->name, target_p->info);
622    }
623  
624 <  if (IsConfAwayBurst((struct AccessItem *)map_to_conf(client_p->serv->sconf)))
625 <    if (!EmptyString(target_p->away))
626 <      sendto_one(client_p, ":%s AWAY :%s", target_p->name,
696 <                 target_p->away);
624 >  if (target_p->away[0])
625 >    sendto_one(client_p, ":%s AWAY :%s", ID_or_name(target_p, client_p),
626 >               target_p->away);
627  
628   }
629  
# Line 816 | Line 746 | server_estab(struct Client *client_p)
746       * - Dianora
747       */
748  
749 <    send_capabilities(client_p, aconf,
820 <      (IsConfTopicBurst(aconf) ? CAP_TBURST|CAP_TB : 0));
749 >    send_capabilities(client_p, aconf, 0);
750  
751      sendto_one(client_p, "SERVER %s 1 :%s%s",
752                 me.name, ConfigServerHide.hidden ? "(H) " : "", me.info);
# Line 916 | Line 845 | server_estab(struct Client *client_p)
845           inpath_ip, show_capabilities(client_p));
846    }
847  
919  client_p->serv->sconf = conf;
920
848    fd_note(&client_p->localClient->fd, "Server: %s", client_p->name);
849  
850    /* Old sendto_serv_but_one() call removed because we now
# Line 1038 | Line 965 | burst_all(struct Client *client_p)
965        burst_members(client_p, chptr);
966        send_channel_modes(client_p, chptr);
967  
968 <      if (IsCapable(client_p, CAP_TBURST) ||
1042 <          IsCapable(client_p, CAP_TB))
968 >      if (IsCapable(client_p, CAP_TBURST))
969          send_tb(client_p, chptr);
970      }
971    }
# Line 1071 | Line 997 | burst_all(struct Client *client_p)
997   *              - pointer to channel
998   * output       - NONE
999   * side effects - Called on a server burst when
1000 < *                server is CAP_TB|CAP_TBURST capable
1000 > *                server is CAP_TBURST capable
1001   */
1002   static void
1003   send_tb(struct Client *client_p, struct Channel *chptr)
# Line 1090 | Line 1016 | send_tb(struct Client *client_p, struct
1016     * for further information   -Michael
1017     */
1018    if (chptr->topic_time != 0)
1019 <  {
1020 <    if (IsCapable(client_p, CAP_TBURST))
1021 <      sendto_one(client_p, ":%s TBURST %lu %s %lu %s :%s",
1022 <                 me.name, (unsigned long)chptr->channelts, chptr->chname,
1023 <                 (unsigned long)chptr->topic_time,
1024 <                 chptr->topic_info,
1099 <                 chptr->topic);
1100 <    else if (IsCapable(client_p, CAP_TB))
1101 <    {
1102 <      if (ConfigChannel.burst_topicwho)
1103 <      {
1104 <        sendto_one(client_p, ":%s TB %s %lu %s :%s",
1105 <                   me.name, chptr->chname,
1106 <                   (unsigned long)chptr->topic_time,
1107 <                   chptr->topic_info, chptr->topic);
1108 <      }
1109 <      else
1110 <      {
1111 <        sendto_one(client_p, ":%s TB %s %lu :%s",
1112 <                   me.name, chptr->chname,
1113 <                   (unsigned long)chptr->topic_time,
1114 <                   chptr->topic);
1115 <      }
1116 <    }
1117 <  }
1019 >    sendto_one(client_p, ":%s TBURST %lu %s %lu %s :%s",
1020 >               ID_or_name(&me, client_p),
1021 >               (unsigned long)chptr->channelts, chptr->chname,
1022 >               (unsigned long)chptr->topic_time,
1023 >               chptr->topic_info,
1024 >               chptr->topic);
1025   }
1026  
1027   /* burst_members()
# Line 1172 | Line 1079 | serv_connect(struct AccessItem *aconf, s
1079   {
1080    struct ConfItem *conf;
1081    struct Client *client_p;
1082 <  char buf[HOSTIPLEN];
1082 >  char buf[HOSTIPLEN + 1];
1083  
1084    /* conversion structs */
1085    struct sockaddr_in *v4;
1086    /* Make sure aconf is useful */
1087    assert(aconf != NULL);
1088  
1182  if(aconf == NULL)
1183    return (0);
1184
1089    /* XXX should be passing struct ConfItem in the first place */
1090    conf = unmap_conf_item(aconf);
1091  
1092    /* log */
1093 <  getnameinfo((struct sockaddr *)&aconf->ipnum, aconf->ipnum.ss_len,
1093 >  getnameinfo((struct sockaddr *)&aconf->addr, aconf->addr.ss_len,
1094                buf, sizeof(buf), NULL, 0, NI_NUMERICHOST);
1095 <  ilog(LOG_TYPE_IRCD, "Connect to %s[%s] @%s", aconf->user, aconf->host,
1095 >  ilog(LOG_TYPE_IRCD, "Connect to %s[%s] @%s", conf->name, aconf->host,
1096         buf);
1097  
1098    /* Still processing a DNS lookup? -> exit */
# Line 1237 | Line 1141 | serv_connect(struct AccessItem *aconf, s
1141    strlcpy(client_p->sockhost, buf, sizeof(client_p->sockhost));
1142  
1143    /* create a socket for the server connection */
1144 <  if (comm_open(&client_p->localClient->fd, aconf->ipnum.ss.ss_family,
1144 >  if (comm_open(&client_p->localClient->fd, aconf->addr.ss.ss_family,
1145                  SOCK_STREAM, 0, NULL) < 0)
1146    {
1147      /* Eek, failure to create the socket */
# Line 1292 | Line 1196 | serv_connect(struct AccessItem *aconf, s
1196    switch (aconf->aftype)
1197    {
1198      case AF_INET:
1199 <      v4 = (struct sockaddr_in*)&aconf->my_ipnum;
1199 >      v4 = (struct sockaddr_in*)&aconf->bind;
1200        if (v4->sin_addr.s_addr != 0)
1201        {
1202          struct irc_ssaddr ipn;
1203          memset(&ipn, 0, sizeof(struct irc_ssaddr));
1204          ipn.ss.ss_family = AF_INET;
1205          ipn.ss_port = 0;
1206 <        memcpy(&ipn, &aconf->my_ipnum, sizeof(struct irc_ssaddr));
1206 >        memcpy(&ipn, &aconf->bind, sizeof(struct irc_ssaddr));
1207          comm_connect_tcp(&client_p->localClient->fd, aconf->host, aconf->port,
1208                           (struct sockaddr *)&ipn, ipn.ss_len,
1209                           serv_connect_callback, client_p, aconf->aftype,
# Line 1330 | Line 1234 | serv_connect(struct AccessItem *aconf, s
1234          struct sockaddr_in6 *v6conf;
1235  
1236          memset(&ipn, 0, sizeof(struct irc_ssaddr));
1237 <        v6conf = (struct sockaddr_in6 *)&aconf->my_ipnum;
1237 >        v6conf = (struct sockaddr_in6 *)&aconf->bind;
1238          v6 = (struct sockaddr_in6 *)&ipn;
1239  
1240          if (memcmp(&v6conf->sin6_addr, &v6->sin6_addr,
1241                     sizeof(struct in6_addr)) != 0)
1242          {
1243 <          memcpy(&ipn, &aconf->my_ipnum, sizeof(struct irc_ssaddr));
1243 >          memcpy(&ipn, &aconf->bind, sizeof(struct irc_ssaddr));
1244            ipn.ss.ss_family = AF_INET6;
1245            ipn.ss_port = 0;
1246            comm_connect_tcp(&client_p->localClient->fd,
# Line 1394 | Line 1298 | finish_ssl_server_handshake(struct Clien
1298      sendto_one(client_p, "PASS %s TS %d %s",
1299                 aconf->spasswd, TS_CURRENT, me.id);
1300  
1301 <  send_capabilities(client_p, aconf,
1398 <                   (IsConfTopicBurst(aconf) ? CAP_TBURST|CAP_TB : 0));
1301 >  send_capabilities(client_p, aconf, 0);
1302  
1303    sendto_one(client_p, "SERVER %s 1 :%s%s",
1304               me.name, ConfigServerHide.hidden ? "(H) " : "",
# Line 1434 | Line 1337 | ssl_server_handshake(fde_t *fd, struct C
1337      {
1338        case SSL_ERROR_WANT_WRITE:
1339          comm_setselect(&client_p->localClient->fd, COMM_SELECT_WRITE,
1340 <            (PF *) ssl_server_handshake, client_p, 0);
1340 >                       (PF *)ssl_server_handshake, client_p, 0);
1341          return;
1342        case SSL_ERROR_WANT_READ:
1343          comm_setselect(&client_p->localClient->fd, COMM_SELECT_READ,
1344 <            (PF *) ssl_server_handshake, client_p, 0);
1344 >                       (PF *)ssl_server_handshake, client_p, 0);
1345          return;
1346        default:
1347 +      {
1348 +        const char *sslerr = ERR_error_string(ERR_get_error(), NULL);
1349 +        sendto_realops_flags(UMODE_ALL, L_ALL,
1350 +                             "Error connecting to %s: %s", client_p->name,
1351 +                             sslerr ? sslerr : "unknown SSL error");
1352          exit_client(client_p, client_p, "Error during SSL handshake");
1353          return;
1354 +      }
1355      }
1356    }
1357  
# Line 1550 | Line 1459 | serv_connect_callback(fde_t *fd, int sta
1459      sendto_one(client_p, "PASS %s TS %d %s",
1460                 aconf->spasswd, TS_CURRENT, me.id);
1461  
1462 <  send_capabilities(client_p, aconf,
1554 <                   (IsConfTopicBurst(aconf) ? CAP_TBURST|CAP_TB : 0));
1462 >  send_capabilities(client_p, aconf, 0);
1463  
1464    sendto_one(client_p, "SERVER %s 1 :%s%s",
1465               me.name, ConfigServerHide.hidden ? "(H) " : "",

Diff Legend

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