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/trunk/src/s_serv.c (file contents):
Revision 1857 by michael, Wed Apr 24 20:47:21 2013 UTC vs.
Revision 2182 by michael, Tue Jun 4 12:19:04 2013 UTC

# Line 54 | Line 54
54  
55   #define MIN_CONN_FREQ 300
56  
57 + dlink_list flatten_links;
58   static dlink_list cap_list = { NULL, NULL, 0 };
59   static void server_burst(struct Client *);
60   static void burst_all(struct Client *);
# Line 72 | Line 73 | static void burst_members(struct Client
73   *                but in no particular order.
74   */
75   void
76 < write_links_file(void* notused)
76 > write_links_file(void *notused)
77   {
78 <  MessageFileLine *next_mptr = NULL;
79 <  MessageFileLine *mptr = NULL;
80 <  MessageFileLine *currentMessageLine = NULL;
80 <  MessageFileLine *newMessageLine = NULL;
81 <  MessageFile *MessageFileptr = &ConfigFileEntry.linksfile;
82 <  FILE *file;
83 <  char buff[512];
84 <  dlink_node *ptr;
78 >  FILE *file = NULL;
79 >  dlink_node *ptr = NULL, *ptr_next = NULL;;
80 >  char buff[IRCD_BUFSIZE] = { '\0' };
81  
82 <  if ((file = fopen(MessageFileptr->fileName, "w")) == NULL)
82 >  if ((file = fopen(LIPATH, "w")) == NULL)
83      return;
84  
85 <  for (mptr = MessageFileptr->contentsOfFile; mptr; mptr = next_mptr)
85 >  DLINK_FOREACH_SAFE(ptr, ptr_next, flatten_links.head)
86    {
87 <    next_mptr = mptr->next;
88 <    MyFree(mptr);
87 >    dlinkDelete(ptr, &flatten_links);
88 >    MyFree(ptr->data);
89 >    free_dlink_node(ptr);
90    }
91  
95  MessageFileptr->contentsOfFile = NULL;
96
92    DLINK_FOREACH(ptr, global_serv_list.head)
93    {
94      const struct Client *target_p = ptr->data;
95  
96 <    /* skip ourselves, we send ourselves in /links */
97 <    if (IsMe(target_p))
98 <      continue;
99 <
100 <    /* skip hidden servers */
106 <    if (IsHidden(target_p))
96 >    /*
97 >     * Skip hidden servers, aswell as ourselves, since we already send
98 >     * ourselves in /links
99 >     */
100 >    if (IsHidden(target_p) || IsMe(target_p))
101        continue;
102  
103      if (HasFlag(target_p, FLAGS_SERVICE) && ConfigServerHide.hide_services)
104        continue;
105  
112    newMessageLine = MyMalloc(sizeof(MessageFileLine));
113
106      /*
107       * Attempt to format the file in such a way it follows the usual links output
108       * ie  "servername uplink :hops info"
109       * Mostly for aesthetic reasons - makes it look pretty in mIRC ;)
110       * - madmax
111       */
112 <    snprintf(newMessageLine->line, sizeof(newMessageLine->line), "%s %s :1 %s",
113 <             target_p->name, me.name, target_p->info);
114 <
115 <    if (MessageFileptr->contentsOfFile)
116 <    {
125 <      if (currentMessageLine)
126 <        currentMessageLine->next = newMessageLine;
127 <      currentMessageLine = newMessageLine;
128 <    }
129 <    else
130 <    {
131 <      MessageFileptr->contentsOfFile = newMessageLine;
132 <      currentMessageLine = newMessageLine;
133 <    }
112 >    snprintf(buff, sizeof(buff), "%s %s :1 %s",   target_p->name,
113 >             me.name, target_p->info);
114 >    dlinkAdd(xstrdup(buff), make_dlink_node(), &flatten_links);
115 >    snprintf(buff, sizeof(buff), "%s %s :1 %s\n", target_p->name,
116 >             me.name, target_p->info);
117  
135    snprintf(buff, sizeof(buff), "%s %s :1 %s\n",
136             target_p->name, me.name, target_p->info);
118      fputs(buff, file);
119    }
120  
# Line 192 | Line 173 | hunt_server(struct Client *client_p, str
173      if (target_p->from == source_p->from && !MyConnect(target_p))
174        target_p = NULL;
175  
195  collapse(parv[server]);
176    wilds = has_wildcards(parv[server]);
177  
178    /* Again, if there are no wild cards involved in the server
# Line 206 | Line 186 | hunt_server(struct Client *client_p, str
186        {
187          sendto_one(source_p, form_str(ERR_NOSUCHSERVER),
188                     me.name, source_p->name, parv[server]);
189 <        return(HUNTED_NOSUCH);
189 >        return HUNTED_NOSUCH;
190        }
191      }
192      else
# Line 252 | Line 232 | hunt_server(struct Client *client_p, str
232      sendto_one(target_p, command, parv[0],
233                 parv[1], parv[2], parv[3], parv[4],
234                 parv[5], parv[6], parv[7], parv[8]);
235 <    return(HUNTED_PASS);
235 >    return HUNTED_PASS;
236    }
237  
238    sendto_one(source_p, form_str(ERR_NOSUCHSERVER),
239               me.name, source_p->name, parv[server]);
240 <  return(HUNTED_NOSUCH);
240 >  return HUNTED_NOSUCH;
241   }
242  
243   /* try_connections()
# Line 308 | Line 288 | try_connections(void *unused)
288      {
289        confrq = conf->class->con_freq;
290        if (confrq < MIN_CONN_FREQ)
291 <        confrq = MIN_CONN_FREQ;
291 >        confrq = MIN_CONN_FREQ;
292      }
293  
294      conf->until = CurrentTime + confrq;
# Line 411 | Line 391 | check_server(const char *name, struct Cl
391    }
392  
393    if (server_conf == NULL)
394 <    return(error);
394 >    return error;
395  
396    attach_conf(client_p, server_conf);
397  
# Line 441 | Line 421 | check_server(const char *name, struct Cl
421      }
422    }
423  
424 <  return(0);
424 >  return 0;
425   }
426  
427   /* add_capability()
# Line 487 | Line 467 | delete_capability(const char *capab_name
467      {
468        if (irccmp(cap->name, capab_name) == 0)
469        {
470 <        default_server_capabs &= ~(cap->cap);
471 <        dlinkDelete(ptr, &cap_list);
472 <        MyFree(cap->name);
473 <        cap->name = NULL;
494 <        MyFree(cap);
470 >        default_server_capabs &= ~(cap->cap);
471 >        dlinkDelete(ptr, &cap_list);
472 >        MyFree(cap->name);
473 >        MyFree(cap);
474        }
475      }
476    }
# Line 506 | Line 485 | delete_capability(const char *capab_name
485   * output       - 0 if not found CAPAB otherwise
486   * side effects - none
487   */
488 < int
488 > unsigned int
489   find_capability(const char *capab)
490   {
491    const dlink_node *ptr = NULL;
# Line 725 | Line 704 | server_estab(struct Client *client_p)
704  
705    if (IsUnknown(client_p))
706    {
707 <    /* jdc -- 1.  Use EmptyString(), not [0] index reference.
729 <     *        2.  Check conf->spasswd, not conf->passwd.
730 <     */
731 <    if (!EmptyString(conf->spasswd))
732 <      sendto_one(client_p, "PASS %s TS %d %s",
733 <                 conf->spasswd, TS_CURRENT, me.id);
707 >    sendto_one(client_p, "PASS %s TS %d %s", conf->spasswd, TS_CURRENT, me.id);
708  
709      send_capabilities(client_p, 0);
710  
# Line 898 | Line 872 | server_estab(struct Client *client_p)
872        sendto_one(client_p, ":%s SERVER %s %d :%s%s",
873                   target_p->servptr->name, target_p->name, target_p->hopcount+1,
874                   IsHidden(target_p) ? "(H) " : "", target_p->info);
875 +
876 +    if (HasFlag(target_p, FLAGS_EOB))
877 +      sendto_one(client_p, ":%s EOB", ID_or_name(client_p, target_p));
878    }
879  
880    server_burst(client_p);
# Line 952 | Line 929 | burst_all(struct Client *client_p)
929        send_channel_modes(client_p, chptr);
930  
931        if (IsCapable(client_p, CAP_TBURST))
932 <        send_tb(client_p, chptr);
932 >        send_tb(client_p, chptr);
933      }
934    }
935  
# Line 968 | Line 945 | burst_all(struct Client *client_p)
945      DelFlag(target_p, FLAGS_BURSTED);
946    }
947  
971  /* We send the time we started the burst, and let the remote host determine an EOB time,
972  ** as otherwise we end up sending a EOB of 0   Sending here means it gets sent last -- fl
973  */
974  /* Its simpler to just send EOB and use the time its been connected.. --fl_ */
948    if (IsCapable(client_p, CAP_EOB))
949      sendto_one(client_p, ":%s EOB", ID_or_name(&me, client_p));
950   }
# Line 1100 | Line 1073 | serv_connect(struct MaskItem *conf, stru
1073    if ((client_p = hash_find_server(conf->name)) != NULL)
1074    {
1075      sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1076 <                         "Server %s already present from %s",
1077 <                         conf->name, get_client_name(client_p, SHOW_IP));
1076 >                         "Server %s already present from %s",
1077 >                         conf->name, get_client_name(client_p, SHOW_IP));
1078      sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
1079 <                         "Server %s already present from %s",
1080 <                         conf->name, get_client_name(client_p, MASK_IP));
1079 >                         "Server %s already present from %s",
1080 >                         conf->name, get_client_name(client_p, MASK_IP));
1081      if (by && IsClient(by) && !MyClient(by))
1082        sendto_one(by, ":%s NOTICE %s :Server %s already present from %s",
1083 <                 me.name, by->name, conf->name,
1084 <                 get_client_name(client_p, MASK_IP));
1085 <    return (0);
1083 >                 me.name, by->name, conf->name,
1084 >                 get_client_name(client_p, MASK_IP));
1085 >    return 0;
1086    }
1087      
1088    /* Create a local client */
# Line 1127 | Line 1100 | serv_connect(struct MaskItem *conf, stru
1100                  SOCK_STREAM, 0, NULL) < 0)
1101    {
1102      /* Eek, failure to create the socket */
1103 <    report_error(L_ALL,
1104 <                 "opening stream socket to %s: %s", conf->name, errno);
1103 >    report_error(L_ALL, "opening stream socket to %s: %s",
1104 >                 conf->name, errno);
1105      SetDead(client_p);
1106      exit_client(client_p, &me, "Connection failed");
1107 <    return (0);
1107 >    return 0;
1108    }
1109  
1110    /* servernames are always guaranteed under HOSTLEN chars */
# Line 1143 | Line 1116 | serv_connect(struct MaskItem *conf, stru
1116    if (!attach_connect_block(client_p, conf->name, conf->host))
1117    {
1118      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1119 <                         "Host %s is not enabled for connecting: no connect{} block",
1120 <                         conf->name);
1119 >                         "Host %s is not enabled for connecting: no connect{} block",
1120 >                         conf->name);
1121      if (by && IsClient(by) && !MyClient(by))  
1122        sendto_one(by, ":%s NOTICE %s :Connect to host %s failed.",
1123 <                 me.name, by->name, client_p->name);
1123 >                 me.name, by->name, client_p->name);
1124      SetDead(client_p);
1125      exit_client(client_p, client_p, "Connection failed");
1126 <    return (0);
1126 >    return 0;
1127    }
1128  
1129    /* at this point we have a connection in progress and C/N lines
# Line 1186 | Line 1159 | serv_connect(struct MaskItem *conf, stru
1159          ipn.ss.ss_family = AF_INET;
1160          ipn.ss_port = 0;
1161          memcpy(&ipn, &conf->bind, sizeof(struct irc_ssaddr));
1162 <        comm_connect_tcp(&client_p->localClient->fd, conf->host, conf->port,
1163 <                         (struct sockaddr *)&ipn, ipn.ss_len,
1164 <                         serv_connect_callback, client_p, conf->aftype,
1165 <                         CONNECTTIMEOUT);
1162 >        comm_connect_tcp(&client_p->localClient->fd, conf->host, conf->port,
1163 >                         (struct sockaddr *)&ipn, ipn.ss_len,
1164 >                         serv_connect_callback, client_p, conf->aftype,
1165 >                         CONNECTTIMEOUT);
1166        }
1167        else if (ServerInfo.specific_ipv4_vhost)
1168        {
# Line 1201 | Line 1174 | serv_connect(struct MaskItem *conf, stru
1174          comm_connect_tcp(&client_p->localClient->fd, conf->host, conf->port,
1175                           (struct sockaddr *)&ipn, ipn.ss_len,
1176                           serv_connect_callback, client_p, conf->aftype,
1177 <                         CONNECTTIMEOUT);
1177 >                         CONNECTTIMEOUT);
1178        }
1179        else
1180          comm_connect_tcp(&client_p->localClient->fd, conf->host, conf->port,
# Line 1211 | Line 1184 | serv_connect(struct MaskItem *conf, stru
1184   #ifdef IPV6
1185      case AF_INET6:
1186        {
1187 <        struct irc_ssaddr ipn;
1188 <        struct sockaddr_in6 *v6;
1189 <        struct sockaddr_in6 *v6conf;
1190 <
1191 <        memset(&ipn, 0, sizeof(struct irc_ssaddr));
1192 <        v6conf = (struct sockaddr_in6 *)&conf->bind;
1193 <        v6 = (struct sockaddr_in6 *)&ipn;
1194 <
1195 <        if (memcmp(&v6conf->sin6_addr, &v6->sin6_addr,
1223 <                   sizeof(struct in6_addr)) != 0)
1224 <        {
1225 <          memcpy(&ipn, &conf->bind, sizeof(struct irc_ssaddr));
1226 <          ipn.ss.ss_family = AF_INET6;
1227 <          ipn.ss_port = 0;
1228 <          comm_connect_tcp(&client_p->localClient->fd,
1229 <                           conf->host, conf->port,
1230 <                           (struct sockaddr *)&ipn, ipn.ss_len,
1231 <                           serv_connect_callback, client_p,
1232 <                           conf->aftype, CONNECTTIMEOUT);
1233 <        }
1234 <        else if (ServerInfo.specific_ipv6_vhost)
1187 >        struct irc_ssaddr ipn;
1188 >        struct sockaddr_in6 *v6;
1189 >        struct sockaddr_in6 *v6conf;
1190 >
1191 >        memset(&ipn, 0, sizeof(struct irc_ssaddr));
1192 >        v6conf = (struct sockaddr_in6 *)&conf->bind;
1193 >        v6 = (struct sockaddr_in6 *)&ipn;
1194 >
1195 >        if (memcmp(&v6conf->sin6_addr, &v6->sin6_addr, sizeof(struct in6_addr)) != 0)
1196          {
1197 <          memcpy(&ipn, &ServerInfo.ip6, sizeof(struct irc_ssaddr));
1198 <          ipn.ss.ss_family = AF_INET6;
1199 <          ipn.ss_port = 0;
1200 <          comm_connect_tcp(&client_p->localClient->fd,
1201 <                           conf->host, conf->port,
1202 <                           (struct sockaddr *)&ipn, ipn.ss_len,
1203 <                           serv_connect_callback, client_p,
1204 <                           conf->aftype, CONNECTTIMEOUT);
1205 <        }
1206 <        else
1207 <          comm_connect_tcp(&client_p->localClient->fd,
1208 <                           conf->host, conf->port,
1209 <                           NULL, 0, serv_connect_callback, client_p,
1210 <                           conf->aftype, CONNECTTIMEOUT);
1197 >          memcpy(&ipn, &conf->bind, sizeof(struct irc_ssaddr));
1198 >          ipn.ss.ss_family = AF_INET6;
1199 >          ipn.ss_port = 0;
1200 >          comm_connect_tcp(&client_p->localClient->fd,
1201 >                           conf->host, conf->port,
1202 >                           (struct sockaddr *)&ipn, ipn.ss_len,
1203 >                           serv_connect_callback, client_p,
1204 >                           conf->aftype, CONNECTTIMEOUT);
1205 >        }
1206 >        else if (ServerInfo.specific_ipv6_vhost)
1207 >        {
1208 >          memcpy(&ipn, &ServerInfo.ip6, sizeof(struct irc_ssaddr));
1209 >          ipn.ss.ss_family = AF_INET6;
1210 >          ipn.ss_port = 0;
1211 >          comm_connect_tcp(&client_p->localClient->fd,
1212 >                           conf->host, conf->port,
1213 >                           (struct sockaddr *)&ipn, ipn.ss_len,
1214 >                           serv_connect_callback, client_p,
1215 >                           conf->aftype, CONNECTTIMEOUT);
1216 >        }
1217 >        else
1218 >          comm_connect_tcp(&client_p->localClient->fd,
1219 >                           conf->host, conf->port,
1220 >                           NULL, 0, serv_connect_callback, client_p,
1221 >                           conf->aftype, CONNECTTIMEOUT);
1222        }
1223   #endif
1224    }
1225 <  return (1);
1225 >  return 1;
1226   }
1227  
1228   #ifdef HAVE_LIBCRYPTO
# Line 1272 | Line 1244 | finish_ssl_server_handshake(struct Clien
1244      return;
1245    }
1246  
1247 <  /* jdc -- Check and send spasswd, not passwd. */
1276 <  if (!EmptyString(conf->spasswd))
1277 <    sendto_one(client_p, "PASS %s TS %d %s",
1278 <               conf->spasswd, TS_CURRENT, me.id);
1247 >  sendto_one(client_p, "PASS %s TS %d %s", conf->spasswd, TS_CURRENT, me.id);
1248  
1249    send_capabilities(client_p, 0);
1250  
# Line 1391 | Line 1360 | serv_connect_callback(fde_t *fd, int sta
1360                              client_p->name, comm_errstr(status));
1361       else
1362         sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1363 <                            "Error connecting to %s[%s]: %s", client_p->name,
1364 <                            client_p->host, comm_errstr(status));
1363 >                            "Error connecting to %s[%s]: %s", client_p->name,
1364 >                            client_p->host, comm_errstr(status));
1365  
1366       sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
1367 <                          "Error connecting to %s: %s",
1368 <                          client_p->name, comm_errstr(status));
1367 >                          "Error connecting to %s: %s",
1368 >                          client_p->name, comm_errstr(status));
1369  
1370       /* If a fd goes bad, call dead_link() the socket is no
1371        * longer valid for reading or writing.
# Line 1408 | Line 1377 | serv_connect_callback(fde_t *fd, int sta
1377    /* COMM_OK, so continue the connection procedure */
1378    /* Get the C/N lines */
1379    conf = find_conf_name(&client_p->localClient->confs,
1380 <                        client_p->name, CONF_SERVER);
1380 >                        client_p->name, CONF_SERVER);
1381    if (conf == NULL)
1382    {
1383      sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1384 <                         "Lost connect{} block for %s", get_client_name(client_p, HIDE_IP));
1384 >                         "Lost connect{} block for %s", get_client_name(client_p, HIDE_IP));
1385      sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
1386 <                         "Lost connect{} block for %s", get_client_name(client_p, MASK_IP));
1386 >                         "Lost connect{} block for %s", get_client_name(client_p, MASK_IP));
1387  
1388      exit_client(client_p, &me, "Lost connect{} block");
1389      return;
# Line 1431 | Line 1400 | serv_connect_callback(fde_t *fd, int sta
1400    }
1401   #endif
1402  
1403 <  /* jdc -- Check and send spasswd, not passwd. */
1435 <  if (!EmptyString(conf->spasswd))
1436 <    sendto_one(client_p, "PASS %s TS %d %s",
1437 <               conf->spasswd, TS_CURRENT, me.id);
1403 >  sendto_one(client_p, "PASS %s TS %d %s", conf->spasswd, TS_CURRENT, me.id);
1404  
1405    send_capabilities(client_p, 0);
1406  
1407 <  sendto_one(client_p, "SERVER %s 1 :%s%s",
1408 <             me.name, ConfigServerHide.hidden ? "(H) " : "",
1443 <             me.info);
1407 >  sendto_one(client_p, "SERVER %s 1 :%s%s", me.name,
1408 >             ConfigServerHide.hidden ? "(H) " : "", me.info);
1409  
1410    /* If we've been marked dead because a send failed, just exit
1411     * here now and save everyone the trouble of us ever existing.
# Line 1448 | Line 1413 | serv_connect_callback(fde_t *fd, int sta
1413    if (IsDead(client_p))
1414    {
1415        sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1416 <                           "%s[%s] went dead during handshake",
1416 >                           "%s[%s] went dead during handshake",
1417                             client_p->name,
1418 <                           client_p->host);
1418 >                           client_p->host);
1419        sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
1420 <                           "%s went dead during handshake", client_p->name);
1420 >                           "%s went dead during handshake", client_p->name);
1421        return;
1422    }
1423  

Diff Legend

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