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.
ircd-hybrid/trunk/src/s_serv.c (file contents), Revision 3096 by michael, Sat Mar 1 23:31:45 2014 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  s_serv.c: Server related functions.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2005 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-2014 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 18 | Line 17
17   *  along with this program; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file s_serv.c
23 > * \brief Server related functions.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
# Line 36 | Line 38
38   #include "fdlist.h"
39   #include "hash.h"
40   #include "irc_string.h"
39 #include "sprintf_irc.h"
41   #include "ircd.h"
42   #include "ircd_defs.h"
43   #include "s_bsd.h"
44   #include "numeric.h"
45   #include "packet.h"
46   #include "irc_res.h"
47 < #include "s_conf.h"
47 > #include "conf.h"
48   #include "s_serv.h"
49 < #include "s_log.h"
49 > #include "log.h"
50   #include "s_misc.h"
51   #include "s_user.h"
52   #include "send.h"
53   #include "memory.h"
54 < #include "channel.h" /* chcap_usage_counts stuff...*/
54 > #include "channel.h"
55   #include "parse.h"
56  
57   #define MIN_CONN_FREQ 300
58  
59 + dlink_list flatten_links;
60   static dlink_list cap_list = { NULL, NULL, 0 };
61   static void server_burst(struct Client *);
62   static void burst_all(struct Client *);
# Line 62 | Line 64 | static void send_tb(struct Client *clien
64  
65   static CNCB serv_connect_callback;
66  
65 static void start_io(struct Client *);
67   static void burst_members(struct Client *, struct Channel *);
68  
69   /*
# Line 74 | Line 75 | static void burst_members(struct Client
75   *                but in no particular order.
76   */
77   void
78 < write_links_file(void* notused)
78 > write_links_file(void *notused)
79   {
80 <  MessageFileLine *next_mptr = 0;
81 <  MessageFileLine *mptr = 0;
82 <  MessageFileLine *currentMessageLine = 0;
82 <  MessageFileLine *newMessageLine = 0;
83 <  MessageFile *MessageFileptr;
84 <  const char *p;
85 <  FBFILE *file;
86 <  char buff[512];
87 <  dlink_node *ptr;
80 >  FILE *file = NULL;
81 >  dlink_node *ptr = NULL, *ptr_next = NULL;
82 >  char buff[IRCD_BUFSIZE] = { '\0' };
83  
84 <  MessageFileptr = &ConfigFileEntry.linksfile;
90 <
91 <  if ((file = fbopen(MessageFileptr->fileName, "w")) == NULL)
84 >  if ((file = fopen(LIPATH, "w")) == NULL)
85      return;
86  
87 <  for (mptr = MessageFileptr->contentsOfFile; mptr; mptr = next_mptr)
87 >  DLINK_FOREACH_SAFE(ptr, ptr_next, flatten_links.head)
88    {
89 <    next_mptr = mptr->next;
90 <    MyFree(mptr);
89 >    dlinkDelete(ptr, &flatten_links);
90 >    MyFree(ptr->data);
91 >    free_dlink_node(ptr);
92    }
93  
100  MessageFileptr->contentsOfFile = NULL;
101  currentMessageLine             = NULL;
102
94    DLINK_FOREACH(ptr, global_serv_list.head)
95    {
96 <    size_t nbytes = 0;
106 <    struct Client *target_p = ptr->data;
96 >    const struct Client *target_p = ptr->data;
97  
98 <    /* skip ourselves, we send ourselves in /links */
99 <    if (IsMe(target_p))
98 >    /*
99 >     * Skip hidden servers, aswell as ourselves, since we already send
100 >     * ourselves in /links
101 >     */
102 >    if (IsHidden(target_p) || IsMe(target_p))
103        continue;
104  
105 <    /* skip hidden servers */
113 <    if (IsHidden(target_p) && !ConfigServerHide.disable_hidden)
105 >    if (HasFlag(target_p, FLAGS_SERVICE) && ConfigServerHide.hide_services)
106        continue;
107  
108 <    if (target_p->info[0])
109 <      p = target_p->info;
118 <    else
119 <      p = "(Unknown Location)";
120 <
121 <    newMessageLine = MyMalloc(sizeof(MessageFileLine));
122 <
123 <    /* Attempt to format the file in such a way it follows the usual links output
108 >    /*
109 >     * Attempt to format the file in such a way it follows the usual links output
110       * ie  "servername uplink :hops info"
111       * Mostly for aesthetic reasons - makes it look pretty in mIRC ;)
112       * - madmax
113       */
114 +    snprintf(buff, sizeof(buff), "%s %s :1 %s",   target_p->name,
115 +             me.name, target_p->info);
116 +    dlinkAddTail(xstrdup(buff), make_dlink_node(), &flatten_links);
117 +    snprintf(buff, sizeof(buff), "%s %s :1 %s\n", target_p->name,
118 +             me.name, target_p->info);
119  
120 <    /*
121 <     * 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;
120 >    fputs(buff, file);
121 >  }
122  
123 <    if (MessageFileptr->contentsOfFile)
124 <    {
125 <      if (currentMessageLine)
126 <        currentMessageLine->next = newMessageLine;
127 <      currentMessageLine = newMessageLine;
128 <    }
129 <    else
130 <    {
131 <      MessageFileptr->contentsOfFile = newMessageLine;
132 <      currentMessageLine = newMessageLine;
133 <    }
123 >  fclose(file);
124 > }
125 >
126 > void
127 > read_links_file(void)
128 > {
129 >  FILE *file = NULL;
130 >  char *p = NULL;
131 >  char buff[IRCD_BUFSIZE] = { '\0' };
132 >
133 >  if ((file = fopen(LIPATH, "r")) == NULL)
134 >    return;
135  
136 <    nbytes = ircsprintf(buff, "%s %s :1 %s\n", target_p->name, me.name, p);
137 <    fbputs(buff, file, nbytes);
136 >  while (fgets(buff, sizeof(buff), file))
137 >  {
138 >    if ((p = strchr(buff, '\n')) != NULL)
139 >      *p = '\0';
140 >
141 >    dlinkAddTail(xstrdup(buff), make_dlink_node(), &flatten_links);
142    }
143  
144 <  fbclose(file);
144 >  fclose(file);
145   }
146  
147   /* hunt_server()
# Line 178 | Line 165 | write_links_file(void* notused)
165   */
166   int
167   hunt_server(struct Client *client_p, struct Client *source_p, const char *command,
168 <            int server, int parc, char *parv[])
168 >            const int server, const int parc, char *parv[])
169   {
170    struct Client *target_p = NULL;
171    struct Client *target_tmp = NULL;
172    dlink_node *ptr;
173    int wilds;
174  
175 <  /* Assume it's me, if no server
176 <   */
177 <  if (parc <= server || EmptyString(parv[server]) ||
178 <      match(me.name, parv[server]) ||
179 <      match(parv[server], me.name) ||
180 <      !strcmp(parv[server], me.id))
194 <    return(HUNTED_ISME);
175 >  /* Assume it's me, if no server */
176 >  if (parc <= server || EmptyString(parv[server]))
177 >    return HUNTED_ISME;
178 >
179 >  if (!strcmp(parv[server], me.id) || !match(parv[server], me.name))
180 >    return HUNTED_ISME;
181  
182    /* These are to pickup matches that would cause the following
183     * message to go in the wrong direction while doing quick fast
# Line 210 | Line 196 | hunt_server(struct Client *client_p, str
196      if (target_p->from == source_p->from && !MyConnect(target_p))
197        target_p = NULL;
198  
199 <  collapse(parv[server]);
214 <  wilds = (strchr(parv[server], '?') || strchr(parv[server], '*'));
199 >  wilds = has_wildcards(parv[server]);
200  
201    /* Again, if there are no wild cards involved in the server
202     * name, use the hash lookup
# Line 224 | Line 209 | hunt_server(struct Client *client_p, str
209        {
210          sendto_one(source_p, form_str(ERR_NOSUCHSERVER),
211                     me.name, source_p->name, parv[server]);
212 <        return(HUNTED_NOSUCH);
212 >        return HUNTED_NOSUCH;
213        }
214      }
215      else
# Line 233 | Line 218 | hunt_server(struct Client *client_p, str
218        {
219          target_tmp = ptr->data;
220  
221 <        if (match(parv[server], target_tmp->name))
221 >        if (!match(parv[server], target_tmp->name))
222          {
223            if (target_tmp->from == source_p->from && !MyConnect(target_tmp))
224              continue;
# Line 258 | Line 243 | hunt_server(struct Client *client_p, str
243      if (IsMe(target_p) || MyClient(target_p))
244        return HUNTED_ISME;
245  
246 <    if (!match(target_p->name, parv[server]))
246 >    if (match(target_p->name, parv[server]))
247        parv[server] = target_p->name;
248  
249 <    /* This is a little kludgy but should work... */
265 <    if (IsClient(source_p) &&
266 <        ((MyConnect(target_p) && IsCapable(target_p, CAP_TS6)) ||
267 <         (!MyConnect(target_p) && IsCapable(target_p->from, CAP_TS6))))
268 <      parv[0] = ID(source_p);
269 <
270 <    sendto_one(target_p, command, parv[0],
249 >    sendto_one(target_p, command, ID_or_name(source_p, target_p),
250                 parv[1], parv[2], parv[3], parv[4],
251                 parv[5], parv[6], parv[7], parv[8]);
252 <    return(HUNTED_PASS);
253 <  }
252 >    return HUNTED_PASS;
253 >  }
254  
255    sendto_one(source_p, form_str(ERR_NOSUCHSERVER),
256               me.name, source_p->name, parv[server]);
257 <  return(HUNTED_NOSUCH);
257 >  return HUNTED_NOSUCH;
258   }
259  
260   /* try_connections()
# Line 291 | Line 270 | hunt_server(struct Client *client_p, str
270   void
271   try_connections(void *unused)
272   {
273 <  dlink_node *ptr;
274 <  struct ConfItem *conf;
296 <  struct AccessItem *aconf;
297 <  struct ClassItem *cltmp;
273 >  dlink_node *ptr = NULL;
274 >  struct MaskItem *conf;
275    int confrq;
276  
277    /* TODO: change this to set active flag to 0 when added to event! --Habeeb */
# Line 304 | Line 281 | try_connections(void *unused)
281    DLINK_FOREACH(ptr, server_items.head)
282    {
283      conf = ptr->data;
307    aconf = map_to_conf(conf);
284  
285 <    /* Also when already connecting! (update holdtimes) --SRB
285 >    assert(conf->type == CONF_SERVER);
286 >
287 >    /* Also when already connecting! (update holdtimes) --SRB
288       */
289 <    if (!(aconf->status & CONF_SERVER) || !aconf->port ||
312 <        !(IsConfAllowAutoConn(aconf)))
289 >    if (!conf->port ||!IsConfAllowAutoConn(conf))
290        continue;
291  
315    cltmp = map_to_conf(aconf->class_ptr);
292  
293      /* Skip this entry if the use of it is still on hold until
294       * future. Otherwise handle this entry (and set it on hold
# Line 320 | Line 296 | try_connections(void *unused)
296       * made one successfull connection... [this algorithm is
297       * a bit fuzzy... -- msa >;) ]
298       */
299 <    if (aconf->hold > CurrentTime)
299 >    if (conf->until > CurrentTime)
300        continue;
301  
302 <    if (cltmp == NULL)
302 >    if (conf->class == NULL)
303        confrq = DEFAULT_CONNECTFREQUENCY;
304      else
305      {
306 <      confrq = ConFreq(cltmp);
307 <      if (confrq < MIN_CONN_FREQ )
308 <        confrq = MIN_CONN_FREQ;
306 >      confrq = conf->class->con_freq;
307 >      if (confrq < MIN_CONN_FREQ)
308 >        confrq = MIN_CONN_FREQ;
309      }
310  
311 <    aconf->hold = CurrentTime + confrq;
311 >    conf->until = CurrentTime + confrq;
312  
313      /* Found a CONNECT config with port specified, scan clients
314       * and see if this server is already connected?
# Line 340 | Line 316 | try_connections(void *unused)
316      if (hash_find_server(conf->name) != NULL)
317        continue;
318  
319 <    if (CurrUserCount(cltmp) < MaxTotal(cltmp))
319 >    if (conf->class->ref_count < conf->class->max_total)
320      {
321        /* Go to the end of the list, if not already last */
322        if (ptr->next != NULL)
# Line 361 | Line 337 | try_connections(void *unused)
337         *   -- adrian
338         */
339        if (ConfigServerHide.hide_server_ips)
340 <        sendto_realops_flags(UMODE_ALL, L_ALL, "Connection to %s activated.",
340 >        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
341 >                             "Connection to %s activated.",
342                               conf->name);
343        else
344 <        sendto_realops_flags(UMODE_ALL, L_ALL, "Connection to %s[%s] activated.",
345 <                             conf->name, aconf->host);
344 >        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
345 >                             "Connection to %s[%s] activated.",
346 >                             conf->name, conf->host);
347  
348 <      serv_connect(aconf, NULL);
348 >      serv_connect(conf, NULL);
349        /* We connect only one at time... */
350        return;
351      }
# Line 399 | Line 377 | int
377   check_server(const char *name, struct Client *client_p)
378   {
379    dlink_node *ptr;
380 <  struct ConfItem *conf           = NULL;
381 <  struct ConfItem *server_conf    = NULL;
404 <  struct AccessItem *server_aconf = NULL;
405 <  struct AccessItem *aconf        = NULL;
380 >  struct MaskItem *conf        = NULL;
381 >  struct MaskItem *server_conf = NULL;
382    int error = -1;
383  
384    assert(client_p != NULL);
385  
410  if (client_p == NULL)
411    return(error);
412
413  if (strlen(name) > HOSTLEN)
414    return(-4);
415
386    /* loop through looking for all possible connect items that might work */
387    DLINK_FOREACH(ptr, server_items.head)
388    {
389      conf = ptr->data;
420    aconf = map_to_conf(conf);
390  
391 <    if (!match(name, conf->name))
391 >    if (match(name, conf->name))
392        continue;
393  
394      error = -3;
395  
396      /* XXX: Fix me for IPv6                    */
397      /* XXX sockhost is the IPv4 ip as a string */
398 <    if (match(aconf->host, client_p->host) ||
399 <        match(aconf->host, client_p->sockhost))
398 >    if (!match(conf->host, client_p->host) ||
399 >        !match(conf->host, client_p->sockhost))
400      {
401        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);
402  
403 <        if (IsConfEncrypted(aconf))
404 <        {
405 <          if (strcmp(aconf->passwd,
406 <              (const char *)crypt(client_p->localClient->passwd,
407 <                                  aconf->passwd)) == 0)
408 <            server_conf = conf;
409 <        }
410 <        else
450 <        {
451 <          if (strcmp(aconf->passwd, client_p->localClient->passwd) == 0)
452 <            server_conf = conf;
453 <        }
454 <      }
403 >      if (!match_conf_password(client_p->localClient->passwd, conf))
404 >        return -2;
405 >
406 >      if (!EmptyString(conf->certfp))
407 >        if (EmptyString(client_p->certfp) || strcasecmp(client_p->certfp, conf->certfp))
408 >          return -4;
409 >
410 >      server_conf = conf;
411      }
412    }
413  
414    if (server_conf == NULL)
415 <    return(error);
415 >    return error;
416  
417    attach_conf(client_p, server_conf);
418  
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  }
419  
420 <  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 <
482 <  server_aconf = map_to_conf(server_conf);
483 <
484 <  if (!IsConfTopicBurst(server_aconf))
485 <  {
486 <    ClearCap(client_p, CAP_TB);
487 <    ClearCap(client_p, CAP_TBURST);
488 <  }
489 <
490 <  if (aconf != NULL)
420 >  if (server_conf != NULL)
421    {
422      struct sockaddr_in *v4;
423   #ifdef IPV6
424      struct sockaddr_in6 *v6;
425   #endif
426 <    switch (aconf->aftype)
426 >    switch (server_conf->aftype)
427      {
428   #ifdef IPV6
429 <      case AF_INET6:
430 <        v6 = (struct sockaddr_in6 *)&aconf->ipnum;
429 >      case AF_INET6:
430 >        v6 = (struct sockaddr_in6 *)&server_conf->addr;
431  
432          if (IN6_IS_ADDR_UNSPECIFIED(&v6->sin6_addr))
433 <          memcpy(&aconf->ipnum, &client_p->localClient->ip, sizeof(struct irc_ssaddr));
433 >          memcpy(&server_conf->addr, &client_p->localClient->ip, sizeof(struct irc_ssaddr));
434          break;
435   #endif
436        case AF_INET:
437 <        v4 = (struct sockaddr_in *)&aconf->ipnum;
437 >        v4 = (struct sockaddr_in *)&server_conf->addr;
438  
439          if (v4->sin_addr.s_addr == INADDR_NONE)
440 <          memcpy(&aconf->ipnum, &client_p->localClient->ip, sizeof(struct irc_ssaddr));
440 >          memcpy(&server_conf->addr, &client_p->localClient->ip, sizeof(struct irc_ssaddr));
441          break;
442      }
443    }
444  
445 <  return(0);
445 >  return 0;
446   }
447  
448   /* add_capability()
# Line 529 | Line 459 | add_capability(const char *capab_name, i
459   {
460    struct Capability *cap = MyMalloc(sizeof(*cap));
461  
462 <  DupString(cap->name, capab_name);
462 >  cap->name = xstrdup(capab_name);
463    cap->cap = cap_flag;
464    dlinkAdd(cap, &cap->node, &cap_list);
465  
# Line 558 | Line 488 | delete_capability(const char *capab_name
488      {
489        if (irccmp(cap->name, capab_name) == 0)
490        {
491 <        default_server_capabs &= ~(cap->cap);
492 <        dlinkDelete(ptr, &cap_list);
493 <        MyFree(cap->name);
494 <        cap->name = NULL;
565 <        MyFree(cap);
491 >        default_server_capabs &= ~(cap->cap);
492 >        dlinkDelete(ptr, &cap_list);
493 >        MyFree(cap->name);
494 >        MyFree(cap);
495        }
496      }
497    }
# Line 577 | Line 506 | delete_capability(const char *capab_name
506   * output       - 0 if not found CAPAB otherwise
507   * side effects - none
508   */
509 < int
509 > unsigned int
510   find_capability(const char *capab)
511   {
512    const dlink_node *ptr = NULL;
# Line 596 | Line 525 | find_capability(const char *capab)
525   /* send_capabilities()
526   *
527   * inputs       - Client pointer to send to
599 *              - Pointer to AccessItem (for crypt)
528   *              - int flag of capabilities that this server can send
529   * output       - NONE
530   * side effects - send the CAPAB line to a server  -orabidoo
531   *
532   */
533   void
534 < send_capabilities(struct Client *client_p, struct AccessItem *aconf,
607 <                  int cap_can_send)
534 > send_capabilities(struct Client *client_p, int cap_can_send)
535   {
536    struct Capability *cap=NULL;
537    char msgbuf[IRCD_BUFSIZE];
# Line 620 | Line 547 | send_capabilities(struct Client *client_
547  
548      if (cap->cap & (cap_can_send|default_server_capabs))
549      {
550 <      tl = ircsprintf(t, "%s ", cap->name);
550 >      tl = sprintf(t, "%s ", cap->name);
551        t += tl;
552      }
553    }
# Line 630 | Line 557 | send_capabilities(struct Client *client_
557   }
558  
559   /* sendnick_TS()
560 < *
560 > *
561   * inputs       - client (server) to send nick towards
562   *          - client to send nick for
563   * output       - NONE
# Line 639 | Line 566 | send_capabilities(struct Client *client_
566   void
567   sendnick_TS(struct Client *client_p, struct Client *target_p)
568   {
569 <  static char ubuf[12];
569 >  char ubuf[IRCD_BUFSIZE];
570  
571    if (!IsClient(target_p))
572      return;
# Line 652 | Line 579 | sendnick_TS(struct Client *client_p, str
579      ubuf[1] = '\0';
580    }
581  
655  /* XXX Both of these need to have a :me.name or :mySID!?!?! */
582    if (IsCapable(client_p, CAP_SVS))
583    {
584      if (HasID(target_p) && IsCapable(client_p, CAP_TS6))
585 <      sendto_one(client_p, ":%s UID %s %d %lu %s %s %s %s %s %lu :%s",
585 >      sendto_one(client_p, ":%s UID %s %d %lu %s %s %s %s %s %s :%s",
586                   target_p->servptr->id,
587                   target_p->name, target_p->hopcount + 1,
588                   (unsigned long) target_p->tsinfo,
589                   ubuf, target_p->username, target_p->host,
590                   (MyClient(target_p) && IsIPSpoof(target_p)) ?
591                   "0" : target_p->sockhost, target_p->id,
592 <                 (unsigned long)target_p->servicestamp, target_p->info);
592 >                 target_p->svid, target_p->info);
593      else
594 <      sendto_one(client_p, "NICK %s %d %lu %s %s %s %s %lu :%s",
594 >      sendto_one(client_p, "NICK %s %d %lu %s %s %s %s %s :%s",
595                   target_p->name, target_p->hopcount + 1,
596                   (unsigned long) target_p->tsinfo,
597                   ubuf, target_p->username, target_p->host,
598 <                 target_p->servptr->name, (unsigned long)target_p->servicestamp,
598 >                 target_p->servptr->name, target_p->svid,
599                   target_p->info);
600    }
601    else
# Line 690 | Line 616 | sendnick_TS(struct Client *client_p, str
616                   target_p->servptr->name, target_p->info);
617    }
618  
619 <  if (IsConfAwayBurst((struct AccessItem *)map_to_conf(client_p->serv->sconf)))
620 <    if (!EmptyString(target_p->away))
621 <      sendto_one(client_p, ":%s AWAY :%s", target_p->name,
622 <                 target_p->away);
619 >  if (!EmptyString(target_p->certfp))
620 >    sendto_one(client_p, ":%s CERTFP %s",
621 >               ID_or_name(target_p, client_p), target_p->certfp);
622 >
623 >  if (target_p->away[0])
624 >    sendto_one(client_p, ":%s AWAY :%s", ID_or_name(target_p, client_p),
625 >               target_p->away);
626  
627   }
628  
# Line 705 | Line 634 | sendnick_TS(struct Client *client_p, str
634   * side effects - build up string representing capabilities of server listed
635   */
636   const char *
637 < show_capabilities(struct Client *target_p)
637 > show_capabilities(const struct Client *target_p)
638   {
639 <  static char msgbuf[IRCD_BUFSIZE];
640 <  char *t = msgbuf;
712 <  dlink_node *ptr;
639 >  static char msgbuf[IRCD_BUFSIZE] = "";
640 >  const dlink_node *ptr = NULL;
641  
642 <  t += ircsprintf(msgbuf, "TS ");
642 >  strlcpy(msgbuf, "TS", sizeof(msgbuf));
643  
644    DLINK_FOREACH(ptr, cap_list.head)
645    {
646      const struct Capability *cap = ptr->data;
647  
648 <    if (IsCapable(target_p, cap->cap))
649 <      t += ircsprintf(t, "%s ", cap->name);
648 >    if (!IsCapable(target_p, cap->cap))
649 >      continue;
650 >
651 >    strlcat(msgbuf,       " ", sizeof(msgbuf));
652 >    strlcat(msgbuf, cap->name, sizeof(msgbuf));
653    }
654  
724  *(t - 1) = '\0';
655    return msgbuf;
656   }
657  
# Line 751 | Line 681 | void
681   server_estab(struct Client *client_p)
682   {
683    struct Client *target_p;
684 <  struct ConfItem *conf;
755 <  struct AccessItem *aconf=NULL;
684 >  struct MaskItem *conf = NULL;
685    char *host;
686    const char *inpath;
687    static char inpath_ip[HOSTLEN * 2 + USERLEN + 6];
# Line 768 | Line 697 | server_estab(struct Client *client_p)
697    inpath = get_client_name(client_p, MASK_IP); /* "refresh" inpath with host */
698    host   = client_p->name;
699  
700 <  if ((conf = find_conf_name(&client_p->localClient->confs, host, SERVER_TYPE))
700 >  if ((conf = find_conf_name(&client_p->localClient->confs, host, CONF_SERVER))
701        == NULL)
702    {
703      /* This shouldn't happen, better tell the ops... -A1kmm */
704 <    sendto_realops_flags(UMODE_ALL, L_ALL, "Warning: Lost connect{} block "
704 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
705 >                         "Warning: Lost connect{} block "
706                           "for server %s(this shouldn't happen)!", host);
707      exit_client(client_p, &me, "Lost connect{} block!");
708      return;
# Line 787 | Line 717 | server_estab(struct Client *client_p)
717    /* If there is something in the serv_list, it might be this
718     * connecting server..
719     */
720 <  if (!ServerInfo.hub && serv_list.head)  
720 >  if (!ServerInfo.hub && serv_list.head)
721    {
722      if (client_p != serv_list.head->data || serv_list.head->next)
723      {
# Line 798 | Line 728 | server_estab(struct Client *client_p)
728      }
729    }
730  
801  aconf = map_to_conf(conf);
802
731    if (IsUnknown(client_p))
732    {
733 <    /* jdc -- 1.  Use EmptyString(), not [0] index reference.
806 <     *        2.  Check aconf->spasswd, not aconf->passwd.
807 <     */
808 <    if (!EmptyString(aconf->spasswd))
809 <      sendto_one(client_p, "PASS %s TS %d %s",
810 <                 aconf->spasswd, TS_CURRENT, me.id);
811 <
812 <    /* Pass my info to the new server
813 <     *
814 <     * Pass on ZIP if supported
815 <     * Pass on TB if supported.
816 <     * - Dianora
817 <     */
733 >    sendto_one(client_p, "PASS %s TS %d %s", conf->spasswd, TS_CURRENT, me.id);
734  
735 <    send_capabilities(client_p, aconf,
820 <      (IsConfTopicBurst(aconf) ? CAP_TBURST|CAP_TB : 0));
735 >    send_capabilities(client_p, 0);
736  
737      sendto_one(client_p, "SERVER %s 1 :%s%s",
738                 me.name, ConfigServerHide.hidden ? "(H) " : "", me.info);
# Line 831 | Line 746 | server_estab(struct Client *client_p)
746      hash_add_id(client_p);
747  
748    /* XXX Does this ever happen? I don't think so -db */
749 <  detach_conf(client_p, OPER_TYPE);
749 >  detach_conf(client_p, CONF_OPER);
750  
751    /* *WARNING*
752    **    In the following code in place of plain server's
# Line 873 | Line 788 | server_estab(struct Client *client_p)
788    /* fixing eob timings.. -gnp */
789    client_p->localClient->firsttime = CurrentTime;
790  
791 <  if (find_matching_name_conf(SERVICE_TYPE, client_p->name, NULL, NULL, 0))
791 >  if (find_matching_name_conf(CONF_SERVICE, client_p->name, NULL, NULL, 0))
792      AddFlag(client_p, FLAGS_SERVICE);
793  
794    /* Show the real host/IP to admins */
# Line 883 | Line 798 | server_estab(struct Client *client_p)
798      compression = SSL_get_current_compression(client_p->localClient->fd.ssl);
799      expansion   = SSL_get_current_expansion(client_p->localClient->fd.ssl);
800  
801 <    sendto_realops_flags(UMODE_ALL, L_ADMIN,
801 >    sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
802                           "Link with %s established: [SSL: %s, Compression/Expansion method: %s/%s] (Capabilities: %s)",
803                           inpath_ip, ssl_get_cipher(client_p->localClient->fd.ssl),
804                           compression ? SSL_COMP_get_name(compression) : "NONE",
805                           expansion ? SSL_COMP_get_name(expansion) : "NONE",
806                           show_capabilities(client_p));
807      /* Now show the masked hostname/IP to opers */
808 <    sendto_realops_flags(UMODE_ALL, L_OPER,
808 >    sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
809                           "Link with %s established: [SSL: %s, Compression/Expansion method: %s/%s] (Capabilities: %s)",
810                           inpath, ssl_get_cipher(client_p->localClient->fd.ssl),
811                           compression ? SSL_COMP_get_name(compression) : "NONE",
# Line 905 | Line 820 | server_estab(struct Client *client_p)
820    else
821   #endif
822    {
823 <    sendto_realops_flags(UMODE_ALL, L_ADMIN,
823 >    sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
824                           "Link with %s established: (Capabilities: %s)",
825 <                         inpath_ip,show_capabilities(client_p));
825 >                         inpath_ip, show_capabilities(client_p));
826      /* Now show the masked hostname/IP to opers */
827 <    sendto_realops_flags(UMODE_ALL, L_OPER,
827 >    sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
828                           "Link with %s established: (Capabilities: %s)",
829 <                         inpath,show_capabilities(client_p));
829 >                         inpath, show_capabilities(client_p));
830      ilog(LOG_TYPE_IRCD, "Link with %s established: (Capabilities: %s)",
831           inpath_ip, show_capabilities(client_p));
832    }
833  
919  client_p->serv->sconf = conf;
920
834    fd_note(&client_p->localClient->fd, "Server: %s", client_p->name);
835  
836    /* Old sendto_serv_but_one() call removed because we now
# Line 937 | Line 850 | server_estab(struct Client *client_p)
850                   IsHidden(client_p) ? "(H) " : "",
851                   client_p->info);
852      else
853 <      sendto_one(target_p,":%s SERVER %s 2 :%s%s",
853 >      sendto_one(target_p,":%s SERVER %s 2 :%s%s",
854                   me.name, client_p->name,
855                   IsHidden(client_p) ? "(H) " : "",
856                   client_p->info);
857    }
858  
859 <  /* Pass on my client information to the new server
860 <  **
861 <  ** First, pass only servers (idea is that if the link gets
862 <  ** cancelled beacause the server was already there,
863 <  ** there are no NICK's to be cancelled...). Of course,
864 <  ** if cancellation occurs, all this info is sent anyway,
865 <  ** and I guess the link dies when a read is attempted...? --msa
866 <  **
867 <  ** Note: Link cancellation to occur at this point means
868 <  ** that at least two servers from my fragment are building
869 <  ** up connection this other fragment at the same time, it's
870 <  ** a race condition, not the normal way of operation...
871 <  **
872 <  ** ALSO NOTE: using the get_client_name for server names--
873 <  **    see previous *WARNING*!!! (Also, original inpath
874 <  **    is destroyed...)
875 <  */
859 >  /*
860 >   * Pass on my client information to the new server
861 >   *
862 >   * First, pass only servers (idea is that if the link gets
863 >   * cancelled beacause the server was already there,
864 >   * there are no NICK's to be cancelled...). Of course,
865 >   * if cancellation occurs, all this info is sent anyway,
866 >   * and I guess the link dies when a read is attempted...? --msa
867 >   *
868 >   * Note: Link cancellation to occur at this point means
869 >   * that at least two servers from my fragment are building
870 >   * up connection this other fragment at the same time, it's
871 >   * a race condition, not the normal way of operation...
872 >   *
873 >   * ALSO NOTE: using the get_client_name for server names--
874 >   *    see previous *WARNING*!!! (Also, original inpath
875 >   *    is destroyed...)
876 >   */
877  
878    DLINK_FOREACH_PREV(ptr, global_serv_list.tail)
879    {
# Line 982 | Line 896 | server_estab(struct Client *client_p)
896                     IsHidden(target_p) ? "(H) " : "", target_p->info);
897      }
898      else
899 <      sendto_one(client_p, ":%s SERVER %s %d :%s%s",
899 >      sendto_one(client_p, ":%s SERVER %s %d :%s%s",
900                   target_p->servptr->name, target_p->name, target_p->hopcount+1,
901                   IsHidden(target_p) ? "(H) " : "", target_p->info);
902 +
903 +    if (HasFlag(target_p, FLAGS_EOB))
904 +      sendto_one(client_p, ":%s EOB", ID_or_name(target_p, client_p));
905    }
906  
907    server_burst(client_p);
# Line 1020 | Line 937 | server_burst(struct Client *client_p)
937  
938   /* burst_all()
939   *
940 < * inputs       - pointer to server to send burst to
940 > * inputs       - pointer to server to send burst to
941   * output       - NONE
942   * side effects - complete burst of channels/nicks is sent to client_p
943   */
# Line 1038 | Line 955 | burst_all(struct Client *client_p)
955        burst_members(client_p, chptr);
956        send_channel_modes(client_p, chptr);
957  
958 <      if (IsCapable(client_p, CAP_TBURST) ||
959 <          IsCapable(client_p, CAP_TB))
1043 <        send_tb(client_p, chptr);
958 >      if (IsCapable(client_p, CAP_TBURST))
959 >        send_tb(client_p, chptr);
960      }
961    }
962  
# Line 1052 | Line 968 | burst_all(struct Client *client_p)
968  
969      if (!HasFlag(target_p, FLAGS_BURSTED) && target_p->from != client_p)
970        sendnick_TS(client_p, target_p);
971 <    
971 >
972      DelFlag(target_p, FLAGS_BURSTED);
973    }
974  
1059  /* We send the time we started the burst, and let the remote host determine an EOB time,
1060  ** as otherwise we end up sending a EOB of 0   Sending here means it gets sent last -- fl
1061  */
1062  /* Its simpler to just send EOB and use the time its been connected.. --fl_ */
975    if (IsCapable(client_p, CAP_EOB))
976      sendto_one(client_p, ":%s EOB", ID_or_name(&me, client_p));
977   }
# Line 1071 | Line 983 | burst_all(struct Client *client_p)
983   *              - pointer to channel
984   * output       - NONE
985   * side effects - Called on a server burst when
986 < *                server is CAP_TB|CAP_TBURST capable
986 > *                server is CAP_TBURST capable
987   */
988   static void
989   send_tb(struct Client *client_p, struct Channel *chptr)
# Line 1090 | Line 1002 | send_tb(struct Client *client_p, struct
1002     * for further information   -Michael
1003     */
1004    if (chptr->topic_time != 0)
1005 <  {
1006 <    if (IsCapable(client_p, CAP_TBURST))
1007 <      sendto_one(client_p, ":%s TBURST %lu %s %lu %s :%s",
1008 <                 me.name, (unsigned long)chptr->channelts, chptr->chname,
1009 <                 (unsigned long)chptr->topic_time,
1010 <                 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 <  }
1005 >    sendto_one(client_p, ":%s TBURST %lu %s %lu %s :%s",
1006 >               ID_or_name(&me, client_p),
1007 >               (unsigned long)chptr->channelts, chptr->chname,
1008 >               (unsigned long)chptr->topic_time,
1009 >               chptr->topic_info,
1010 >               chptr->topic);
1011   }
1012  
1013   /* burst_members()
# Line 1153 | Line 1046 | burst_members(struct Client *client_p, s
1046  
1047   /* serv_connect() - initiate a server connection
1048   *
1049 < * inputs       - pointer to conf
1049 > * inputs       - pointer to conf
1050   *              - pointer to client doing the connect
1051   * output       -
1052   * side effects -
# Line 1168 | Line 1061 | burst_members(struct Client *client_p, s
1061   * it suceeded or not, and 0 if it fails in here somewhere.
1062   */
1063   int
1064 < serv_connect(struct AccessItem *aconf, struct Client *by)
1064 > serv_connect(struct MaskItem *conf, struct Client *by)
1065   {
1173  struct ConfItem *conf;
1066    struct Client *client_p;
1067 <  char buf[HOSTIPLEN];
1067 >  char buf[HOSTIPLEN + 1];
1068  
1069    /* conversion structs */
1070    struct sockaddr_in *v4;
1071 <  /* Make sure aconf is useful */
1072 <  assert(aconf != NULL);
1181 <
1182 <  if(aconf == NULL)
1183 <    return (0);
1071 >  /* Make sure conf is useful */
1072 >  assert(conf != NULL);
1073  
1185  /* XXX should be passing struct ConfItem in the first place */
1186  conf = unmap_conf_item(aconf);
1074  
1075 <  /* log */
1189 <  getnameinfo((struct sockaddr *)&aconf->ipnum, aconf->ipnum.ss_len,
1075 >  getnameinfo((struct sockaddr *)&conf->addr, conf->addr.ss_len,
1076                buf, sizeof(buf), NULL, 0, NI_NUMERICHOST);
1077 <  ilog(LOG_TYPE_IRCD, "Connect to %s[%s] @%s", aconf->user, aconf->host,
1077 >  ilog(LOG_TYPE_IRCD, "Connect to %s[%s] @%s", conf->name, conf->host,
1078         buf);
1079  
1080    /* Still processing a DNS lookup? -> exit */
1081 <  if (aconf->dns_pending)
1081 >  if (conf->dns_pending)
1082    {
1083 <    sendto_realops_flags(UMODE_ALL, L_ALL,
1083 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1084                           "Error connecting to %s: DNS lookup for connect{} in progress.",
1085                           conf->name);
1086      return (0);
1087    }
1088  
1089 <  if (aconf->dns_failed)
1089 >  if (conf->dns_failed)
1090    {
1091 <    sendto_realops_flags(UMODE_ALL, L_ALL,
1091 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1092                           "Error connecting to %s: DNS lookup for connect{} failed.",
1093                           conf->name);
1094      return (0);
1095    }
1096  
1097    /* Make sure this server isn't already connected
1098 <   * Note: aconf should ALWAYS be a valid C: line
1098 >   * Note: conf should ALWAYS be a valid C: line
1099     */
1100    if ((client_p = hash_find_server(conf->name)) != NULL)
1101 <  {
1102 <    sendto_realops_flags(UMODE_ALL, L_ADMIN,
1103 <                         "Server %s already present from %s",
1104 <                         conf->name, get_client_name(client_p, SHOW_IP));
1105 <    sendto_realops_flags(UMODE_ALL, L_OPER,
1106 <                         "Server %s already present from %s",
1107 <                         conf->name, get_client_name(client_p, MASK_IP));
1101 >  {
1102 >    sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1103 >                         "Server %s already present from %s",
1104 >                         conf->name, get_client_name(client_p, SHOW_IP));
1105 >    sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
1106 >                         "Server %s already present from %s",
1107 >                         conf->name, get_client_name(client_p, MASK_IP));
1108      if (by && IsClient(by) && !MyClient(by))
1109        sendto_one(by, ":%s NOTICE %s :Server %s already present from %s",
1110 <                 me.name, by->name, conf->name,
1111 <                 get_client_name(client_p, MASK_IP));
1112 <    return (0);
1110 >                 me.name, by->name, conf->name,
1111 >                 get_client_name(client_p, MASK_IP));
1112 >    return 0;
1113    }
1114 <    
1114 >
1115    /* Create a local client */
1116    client_p = make_client(NULL);
1117  
1118    /* Copy in the server, hostname, fd */
1119    strlcpy(client_p->name, conf->name, sizeof(client_p->name));
1120 <  strlcpy(client_p->host, aconf->host, sizeof(client_p->host));
1120 >  strlcpy(client_p->host, conf->host, sizeof(client_p->host));
1121  
1122    /* We already converted the ip once, so lets use it - stu */
1123    strlcpy(client_p->sockhost, buf, sizeof(client_p->sockhost));
1124  
1125 <  /* create a socket for the server connection */
1126 <  if (comm_open(&client_p->localClient->fd, aconf->ipnum.ss.ss_family,
1125 >  /* create a socket for the server connection */
1126 >  if (comm_open(&client_p->localClient->fd, conf->addr.ss.ss_family,
1127                  SOCK_STREAM, 0, NULL) < 0)
1128    {
1129      /* Eek, failure to create the socket */
1130 <    report_error(L_ALL,
1131 <                 "opening stream socket to %s: %s", conf->name, errno);
1130 >    report_error(L_ALL, "opening stream socket to %s: %s",
1131 >                 conf->name, errno);
1132      SetDead(client_p);
1133      exit_client(client_p, &me, "Connection failed");
1134 <    return (0);
1134 >    return 0;
1135    }
1136  
1137    /* servernames are always guaranteed under HOSTLEN chars */
# Line 1254 | Line 1140 | serv_connect(struct AccessItem *aconf, s
1140    /* Attach config entries to client here rather than in
1141     * serv_connect_callback(). This to avoid null pointer references.
1142     */
1143 <  if (!attach_connect_block(client_p, conf->name, aconf->host))
1143 >  if (!attach_connect_block(client_p, conf->name, conf->host))
1144    {
1145 <    sendto_realops_flags(UMODE_ALL, L_ALL,
1146 <                         "Host %s is not enabled for connecting:no C/N-line",
1147 <                         conf->name);
1148 <    if (by && IsClient(by) && !MyClient(by))  
1145 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1146 >                         "Host %s is not enabled for connecting: no connect{} block",
1147 >                         conf->name);
1148 >    if (by && IsClient(by) && !MyClient(by))
1149        sendto_one(by, ":%s NOTICE %s :Connect to host %s failed.",
1150 <                 me.name, by->name, client_p->name);
1150 >                 me.name, by->name, client_p->name);
1151      SetDead(client_p);
1152      exit_client(client_p, client_p, "Connection failed");
1153 <    return (0);
1153 >    return 0;
1154    }
1155  
1156    /* at this point we have a connection in progress and C/N lines
# Line 1283 | Line 1169 | serv_connect(struct AccessItem *aconf, s
1169    SetConnecting(client_p);
1170    dlinkAdd(client_p, &client_p->node, &global_client_list);
1171    /* from def_fam */
1172 <  client_p->localClient->aftype = aconf->aftype;
1172 >  client_p->localClient->aftype = conf->aftype;
1173  
1174    /* Now, initiate the connection */
1175 <  /* XXX assume that a non 0 type means a specific bind address
1175 >  /* XXX assume that a non 0 type means a specific bind address
1176     * for this connect.
1177     */
1178 <  switch (aconf->aftype)
1178 >  switch (conf->aftype)
1179    {
1180      case AF_INET:
1181 <      v4 = (struct sockaddr_in*)&aconf->my_ipnum;
1181 >      v4 = (struct sockaddr_in*)&conf->bind;
1182        if (v4->sin_addr.s_addr != 0)
1183        {
1184          struct irc_ssaddr ipn;
1185          memset(&ipn, 0, sizeof(struct irc_ssaddr));
1186          ipn.ss.ss_family = AF_INET;
1187          ipn.ss_port = 0;
1188 <        memcpy(&ipn, &aconf->my_ipnum, sizeof(struct irc_ssaddr));
1189 <        comm_connect_tcp(&client_p->localClient->fd, aconf->host, aconf->port,
1190 <                         (struct sockaddr *)&ipn, ipn.ss_len,
1191 <                         serv_connect_callback, client_p, aconf->aftype,
1192 <                         CONNECTTIMEOUT);
1188 >        memcpy(&ipn, &conf->bind, sizeof(struct irc_ssaddr));
1189 >        comm_connect_tcp(&client_p->localClient->fd, conf->host, conf->port,
1190 >                         (struct sockaddr *)&ipn, ipn.ss_len,
1191 >                         serv_connect_callback, client_p, conf->aftype,
1192 >                         CONNECTTIMEOUT);
1193        }
1194        else if (ServerInfo.specific_ipv4_vhost)
1195        {
# Line 1312 | Line 1198 | serv_connect(struct AccessItem *aconf, s
1198          ipn.ss.ss_family = AF_INET;
1199          ipn.ss_port = 0;
1200          memcpy(&ipn, &ServerInfo.ip, sizeof(struct irc_ssaddr));
1201 <        comm_connect_tcp(&client_p->localClient->fd, aconf->host, aconf->port,
1201 >        comm_connect_tcp(&client_p->localClient->fd, conf->host, conf->port,
1202                           (struct sockaddr *)&ipn, ipn.ss_len,
1203 <                         serv_connect_callback, client_p, aconf->aftype,
1204 <                         CONNECTTIMEOUT);
1203 >                         serv_connect_callback, client_p, conf->aftype,
1204 >                         CONNECTTIMEOUT);
1205        }
1206        else
1207 <        comm_connect_tcp(&client_p->localClient->fd, aconf->host, aconf->port,
1208 <                         NULL, 0, serv_connect_callback, client_p, aconf->aftype,
1207 >        comm_connect_tcp(&client_p->localClient->fd, conf->host, conf->port,
1208 >                         NULL, 0, serv_connect_callback, client_p, conf->aftype,
1209                           CONNECTTIMEOUT);
1210        break;
1211   #ifdef IPV6
1212      case AF_INET6:
1213        {
1214 <        struct irc_ssaddr ipn;
1215 <        struct sockaddr_in6 *v6;
1216 <        struct sockaddr_in6 *v6conf;
1217 <
1218 <        memset(&ipn, 0, sizeof(struct irc_ssaddr));
1219 <        v6conf = (struct sockaddr_in6 *)&aconf->my_ipnum;
1220 <        v6 = (struct sockaddr_in6 *)&ipn;
1221 <
1222 <        if (memcmp(&v6conf->sin6_addr, &v6->sin6_addr,
1223 <                   sizeof(struct in6_addr)) != 0)
1224 <        {
1225 <          memcpy(&ipn, &aconf->my_ipnum, 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 <                           aconf->host, aconf->port,
1230 <                           (struct sockaddr *)&ipn, ipn.ss_len,
1231 <                           serv_connect_callback, client_p,
1232 <                           aconf->aftype, CONNECTTIMEOUT);
1233 <        }
1348 <        else if (ServerInfo.specific_ipv6_vhost)
1214 >        struct irc_ssaddr ipn;
1215 >        struct sockaddr_in6 *v6;
1216 >        struct sockaddr_in6 *v6conf;
1217 >
1218 >        memset(&ipn, 0, sizeof(struct irc_ssaddr));
1219 >        v6conf = (struct sockaddr_in6 *)&conf->bind;
1220 >        v6 = (struct sockaddr_in6 *)&ipn;
1221 >
1222 >        if (memcmp(&v6conf->sin6_addr, &v6->sin6_addr, sizeof(struct in6_addr)) != 0)
1223 >        {
1224 >          memcpy(&ipn, &conf->bind, sizeof(struct irc_ssaddr));
1225 >          ipn.ss.ss_family = AF_INET6;
1226 >          ipn.ss_port = 0;
1227 >          comm_connect_tcp(&client_p->localClient->fd,
1228 >                           conf->host, conf->port,
1229 >                           (struct sockaddr *)&ipn, ipn.ss_len,
1230 >                           serv_connect_callback, client_p,
1231 >                           conf->aftype, CONNECTTIMEOUT);
1232 >        }
1233 >        else if (ServerInfo.specific_ipv6_vhost)
1234          {
1235 <          memcpy(&ipn, &ServerInfo.ip6, sizeof(struct irc_ssaddr));
1236 <          ipn.ss.ss_family = AF_INET6;
1237 <          ipn.ss_port = 0;
1238 <          comm_connect_tcp(&client_p->localClient->fd,
1239 <                           aconf->host, aconf->port,
1240 <                           (struct sockaddr *)&ipn, ipn.ss_len,
1241 <                           serv_connect_callback, client_p,
1242 <                           aconf->aftype, CONNECTTIMEOUT);
1243 <        }
1244 <        else
1245 <          comm_connect_tcp(&client_p->localClient->fd,
1246 <                           aconf->host, aconf->port,
1247 <                           NULL, 0, serv_connect_callback, client_p,
1248 <                           aconf->aftype, CONNECTTIMEOUT);
1235 >          memcpy(&ipn, &ServerInfo.ip6, sizeof(struct irc_ssaddr));
1236 >          ipn.ss.ss_family = AF_INET6;
1237 >          ipn.ss_port = 0;
1238 >          comm_connect_tcp(&client_p->localClient->fd,
1239 >                           conf->host, conf->port,
1240 >                           (struct sockaddr *)&ipn, ipn.ss_len,
1241 >                           serv_connect_callback, client_p,
1242 >                           conf->aftype, CONNECTTIMEOUT);
1243 >        }
1244 >        else
1245 >          comm_connect_tcp(&client_p->localClient->fd,
1246 >                           conf->host, conf->port,
1247 >                           NULL, 0, serv_connect_callback, client_p,
1248 >                           conf->aftype, CONNECTTIMEOUT);
1249        }
1250   #endif
1251    }
1252 <  return (1);
1252 >  return 1;
1253   }
1254  
1255   #ifdef HAVE_LIBCRYPTO
1256   static void
1257   finish_ssl_server_handshake(struct Client *client_p)
1258   {
1259 <  struct ConfItem *conf=NULL;
1375 <  struct AccessItem *aconf=NULL;
1259 >  struct MaskItem *conf = NULL;
1260  
1261    conf = find_conf_name(&client_p->localClient->confs,
1262 <                        client_p->name, SERVER_TYPE);
1262 >                        client_p->name, CONF_SERVER);
1263    if (conf == NULL)
1264    {
1265 <    sendto_realops_flags(UMODE_ALL, L_ADMIN,
1265 >    sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1266                           "Lost connect{} block for %s", get_client_name(client_p, HIDE_IP));
1267 <    sendto_realops_flags(UMODE_ALL, L_OPER,
1267 >    sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
1268                           "Lost connect{} block for %s", get_client_name(client_p, MASK_IP));
1269  
1270      exit_client(client_p, &me, "Lost connect{} block");
1271      return;
1272    }
1273  
1274 <  aconf = map_to_conf(conf);
1274 >  sendto_one(client_p, "PASS %s TS %d %s", conf->spasswd, TS_CURRENT, me.id);
1275  
1276 <  /* jdc -- Check and send spasswd, not passwd. */
1393 <  if (!EmptyString(aconf->spasswd))
1394 <    sendto_one(client_p, "PASS %s TS %d %s",
1395 <               aconf->spasswd, TS_CURRENT, me.id);
1396 <
1397 <  send_capabilities(client_p, aconf,
1398 <                   (IsConfTopicBurst(aconf) ? CAP_TBURST|CAP_TB : 0));
1276 >  send_capabilities(client_p, 0);
1277  
1278    sendto_one(client_p, "SERVER %s 1 :%s%s",
1279               me.name, ConfigServerHide.hidden ? "(H) " : "",
# Line 1406 | Line 1284 | finish_ssl_server_handshake(struct Clien
1284     */
1285    if (IsDead(client_p))
1286    {
1287 <      sendto_realops_flags(UMODE_ALL, L_ADMIN,
1287 >      sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1288                             "%s[%s] went dead during handshake",
1289                             client_p->name,
1290                             client_p->host);
1291 <      sendto_realops_flags(UMODE_ALL, L_OPER,
1291 >      sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
1292                             "%s went dead during handshake", client_p->name);
1293        return;
1294    }
# Line 1423 | Line 1301 | finish_ssl_server_handshake(struct Clien
1301   static void
1302   ssl_server_handshake(fde_t *fd, struct Client *client_p)
1303   {
1304 <  int ret;
1305 <  int err;
1428 <
1429 <  ret = SSL_connect(client_p->localClient->fd.ssl);
1304 >  X509 *cert = NULL;
1305 >  int ret = 0;
1306  
1307 <  if (ret <= 0)
1307 >  if ((ret = SSL_connect(client_p->localClient->fd.ssl)) <= 0)
1308    {
1309 <    switch ((err = SSL_get_error(client_p->localClient->fd.ssl, ret)))
1309 >    switch (SSL_get_error(client_p->localClient->fd.ssl, ret))
1310      {
1311        case SSL_ERROR_WANT_WRITE:
1312          comm_setselect(&client_p->localClient->fd, COMM_SELECT_WRITE,
1313 <            (PF *) ssl_server_handshake, client_p, 0);
1313 >                       (PF *)ssl_server_handshake, client_p, 0);
1314          return;
1315        case SSL_ERROR_WANT_READ:
1316          comm_setselect(&client_p->localClient->fd, COMM_SELECT_READ,
1317 <            (PF *) ssl_server_handshake, client_p, 0);
1317 >                       (PF *)ssl_server_handshake, client_p, 0);
1318          return;
1319        default:
1320 +      {
1321 +        const char *sslerr = ERR_error_string(ERR_get_error(), NULL);
1322 +        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1323 +                             "Error connecting to %s: %s", client_p->name,
1324 +                             sslerr ? sslerr : "unknown SSL error");
1325          exit_client(client_p, client_p, "Error during SSL handshake");
1326          return;
1327 +      }
1328      }
1329    }
1330  
1331 +  if ((cert = SSL_get_peer_certificate(client_p->localClient->fd.ssl)))
1332 +  {
1333 +    int res = SSL_get_verify_result(client_p->localClient->fd.ssl);
1334 +    char buf[EVP_MAX_MD_SIZE * 2 + 1] = { '\0' };
1335 +    unsigned char md[EVP_MAX_MD_SIZE] = { '\0' };
1336 +
1337 +    if (res == X509_V_OK || res == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN ||
1338 +        res == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE ||
1339 +        res == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT)
1340 +    {
1341 +      unsigned int i = 0, n = 0;
1342 +
1343 +      if (X509_digest(cert, EVP_sha256(), md, &n))
1344 +      {
1345 +        for (; i < n; ++i)
1346 +          snprintf(buf + 2 * i, 3, "%02X", md[i]);
1347 +        client_p->certfp = xstrdup(buf);
1348 +      }
1349 +    }
1350 +    else
1351 +      ilog(LOG_TYPE_IRCD, "Server %s!%s@%s gave bad SSL client certificate: %d",
1352 +           client_p->name, client_p->username, client_p->host, res);
1353 +    X509_free(cert);
1354 +  }
1355 +
1356    finish_ssl_server_handshake(client_p);
1357   }
1358  
1359   static void
1360 < ssl_connect_init(struct Client *client_p, struct AccessItem *aconf, fde_t *fd)
1360 > ssl_connect_init(struct Client *client_p, struct MaskItem *conf, fde_t *fd)
1361   {
1362    if ((client_p->localClient->fd.ssl = SSL_new(ServerInfo.client_ctx)) == NULL)
1363    {
# Line 1463 | Line 1370 | ssl_connect_init(struct Client *client_p
1370  
1371    SSL_set_fd(fd->ssl, fd->fd);
1372  
1373 <  if (!EmptyString(aconf->cipher_list))
1374 <    SSL_set_cipher_list(client_p->localClient->fd.ssl, aconf->cipher_list);
1373 >  if (!EmptyString(conf->cipher_list))
1374 >    SSL_set_cipher_list(client_p->localClient->fd.ssl, conf->cipher_list);
1375  
1376    ssl_server_handshake(NULL, client_p);
1377   }
1378   #endif
1379  
1380   /* serv_connect_callback() - complete a server connection.
1381 < *
1381 > *
1382   * This routine is called after the server connection attempt has
1383   * completed. If unsucessful, an error is sent to ops and the client
1384   * is closed. If sucessful, it goes through the initialisation/check
# Line 1482 | Line 1389 | static void
1389   serv_connect_callback(fde_t *fd, int status, void *data)
1390   {
1391    struct Client *client_p = data;
1392 <  struct ConfItem *conf=NULL;
1486 <  struct AccessItem *aconf=NULL;
1392 >  struct MaskItem *conf = NULL;
1393  
1394    /* First, make sure its a real client! */
1395    assert(client_p != NULL);
# Line 1499 | Line 1405 | serv_connect_callback(fde_t *fd, int sta
1405       * Admins get to see any IP, mere opers don't *sigh*
1406       */
1407       if (ConfigServerHide.hide_server_ips)
1408 <       sendto_realops_flags(UMODE_ALL, L_ADMIN,
1408 >       sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1409                              "Error connecting to %s: %s",
1410                              client_p->name, comm_errstr(status));
1411       else
1412 <       sendto_realops_flags(UMODE_ALL, L_ADMIN,
1413 <                            "Error connecting to %s[%s]: %s", client_p->name,
1414 <                            client_p->host, comm_errstr(status));
1415 <
1416 <     sendto_realops_flags(UMODE_ALL, L_OPER,
1417 <                          "Error connecting to %s: %s",
1418 <                          client_p->name, comm_errstr(status));
1412 >       sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1413 >                            "Error connecting to %s[%s]: %s", client_p->name,
1414 >                            client_p->host, comm_errstr(status));
1415 >
1416 >     sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
1417 >                          "Error connecting to %s: %s",
1418 >                          client_p->name, comm_errstr(status));
1419  
1420       /* If a fd goes bad, call dead_link() the socket is no
1421        * longer valid for reading or writing.
# Line 1521 | Line 1427 | serv_connect_callback(fde_t *fd, int sta
1427    /* COMM_OK, so continue the connection procedure */
1428    /* Get the C/N lines */
1429    conf = find_conf_name(&client_p->localClient->confs,
1430 <                        client_p->name, SERVER_TYPE);
1430 >                        client_p->name, CONF_SERVER);
1431    if (conf == NULL)
1432    {
1433 <    sendto_realops_flags(UMODE_ALL, L_ADMIN,
1434 <                         "Lost connect{} block for %s", get_client_name(client_p, HIDE_IP));
1435 <    sendto_realops_flags(UMODE_ALL, L_OPER,
1436 <                         "Lost connect{} block for %s", get_client_name(client_p, MASK_IP));
1433 >    sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1434 >                         "Lost connect{} block for %s", get_client_name(client_p, HIDE_IP));
1435 >    sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
1436 >                         "Lost connect{} block for %s", get_client_name(client_p, MASK_IP));
1437  
1438      exit_client(client_p, &me, "Lost connect{} block");
1439      return;
1440    }
1441  
1536  aconf = map_to_conf(conf);
1442    /* Next, send the initial handshake */
1443    SetHandshake(client_p);
1444  
1445   #ifdef HAVE_LIBCRYPTO
1446 <  if (IsConfSSL(aconf))
1446 >  if (IsConfSSL(conf))
1447    {
1448 <    ssl_connect_init(client_p, aconf, fd);
1448 >    ssl_connect_init(client_p, conf, fd);
1449      return;
1450    }
1451   #endif
1452  
1453 <  /* jdc -- Check and send spasswd, not passwd. */
1549 <  if (!EmptyString(aconf->spasswd))
1550 <    sendto_one(client_p, "PASS %s TS %d %s",
1551 <               aconf->spasswd, TS_CURRENT, me.id);
1453 >  sendto_one(client_p, "PASS %s TS %d %s", conf->spasswd, TS_CURRENT, me.id);
1454  
1455 <  send_capabilities(client_p, aconf,
1554 <                   (IsConfTopicBurst(aconf) ? CAP_TBURST|CAP_TB : 0));
1455 >  send_capabilities(client_p, 0);
1456  
1457 <  sendto_one(client_p, "SERVER %s 1 :%s%s",
1458 <             me.name, ConfigServerHide.hidden ? "(H) " : "",
1558 <             me.info);
1457 >  sendto_one(client_p, "SERVER %s 1 :%s%s", me.name,
1458 >             ConfigServerHide.hidden ? "(H) " : "", me.info);
1459  
1460    /* If we've been marked dead because a send failed, just exit
1461     * here now and save everyone the trouble of us ever existing.
1462     */
1463 <  if (IsDead(client_p))
1463 >  if (IsDead(client_p))
1464    {
1465 <      sendto_realops_flags(UMODE_ALL, L_ADMIN,
1466 <                           "%s[%s] went dead during handshake",
1465 >      sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1466 >                           "%s[%s] went dead during handshake",
1467                             client_p->name,
1468 <                           client_p->host);
1469 <      sendto_realops_flags(UMODE_ALL, L_OPER,
1470 <                           "%s went dead during handshake", client_p->name);
1468 >                           client_p->host);
1469 >      sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
1470 >                           "%s went dead during handshake", client_p->name);
1471        return;
1472    }
1473  
# Line 1587 | Line 1487 | find_servconn_in_progress(const char *na
1487      cptr = ptr->data;
1488  
1489      if (cptr && cptr->name[0])
1490 <      if (match(name, cptr->name))
1490 >      if (!match(name, cptr->name))
1491          return cptr;
1492    }
1493 <  
1493 >
1494    return NULL;
1495   }

Diff Legend

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