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 3135 by michael, Mon Mar 10 21:11:25 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 31 | Line 33
33   #include "channel.h"
34   #include "channel_mode.h"
35   #include "client.h"
34 #include "dbuf.h"
36   #include "event.h"
37   #include "fdlist.h"
38   #include "hash.h"
39   #include "irc_string.h"
39 #include "sprintf_irc.h"
40   #include "ircd.h"
41   #include "ircd_defs.h"
42   #include "s_bsd.h"
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"
52   #include "memory.h"
53 < #include "channel.h" /* chcap_usage_counts stuff...*/
53 > #include "channel.h"
54   #include "parse.h"
55  
56   #define MIN_CONN_FREQ 300
57  
58 + dlink_list flatten_links;
59   static dlink_list cap_list = { NULL, NULL, 0 };
60   static void server_burst(struct Client *);
61   static void burst_all(struct Client *);
# Line 62 | Line 63 | static void send_tb(struct Client *clien
63  
64   static CNCB serv_connect_callback;
65  
65 static void start_io(struct Client *);
66   static void burst_members(struct Client *, struct Channel *);
67  
68   /*
# Line 74 | Line 74 | static void burst_members(struct Client
74   *                but in no particular order.
75   */
76   void
77 < write_links_file(void* notused)
77 > write_links_file(void *notused)
78   {
79 <  MessageFileLine *next_mptr = 0;
80 <  MessageFileLine *mptr = 0;
81 <  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;
79 >  FILE *file = NULL;
80 >  dlink_node *ptr = NULL, *ptr_next = NULL;
81 >  char buff[IRCD_BUFSIZE] = { '\0' };
82  
83 <  MessageFileptr = &ConfigFileEntry.linksfile;
90 <
91 <  if ((file = fbopen(MessageFileptr->fileName, "w")) == NULL)
83 >  if ((file = fopen(LIPATH, "w")) == NULL)
84      return;
85  
86 <  for (mptr = MessageFileptr->contentsOfFile; mptr; mptr = next_mptr)
86 >  DLINK_FOREACH_SAFE(ptr, ptr_next, flatten_links.head)
87    {
88 <    next_mptr = mptr->next;
89 <    MyFree(mptr);
88 >    dlinkDelete(ptr, &flatten_links);
89 >    MyFree(ptr->data);
90 >    free_dlink_node(ptr);
91    }
92  
100  MessageFileptr->contentsOfFile = NULL;
101  currentMessageLine             = NULL;
102
93    DLINK_FOREACH(ptr, global_serv_list.head)
94    {
95 <    size_t nbytes = 0;
106 <    struct Client *target_p = ptr->data;
95 >    const struct Client *target_p = ptr->data;
96  
97 <    /* skip ourselves, we send ourselves in /links */
98 <    if (IsMe(target_p))
97 >    /*
98 >     * Skip hidden servers, aswell as ourselves, since we already send
99 >     * ourselves in /links
100 >     */
101 >    if (IsHidden(target_p) || IsMe(target_p))
102        continue;
103  
104 <    /* skip hidden servers */
113 <    if (IsHidden(target_p) && !ConfigServerHide.disable_hidden)
104 >    if (HasFlag(target_p, FLAGS_SERVICE) && ConfigServerHide.hide_services)
105        continue;
106  
107 <    if (target_p->info[0])
108 <      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
107 >    /*
108 >     * Attempt to format the file in such a way it follows the usual links output
109       * ie  "servername uplink :hops info"
110       * Mostly for aesthetic reasons - makes it look pretty in mIRC ;)
111       * - madmax
112       */
113 +    snprintf(buff, sizeof(buff), "%s %s :1 %s",   target_p->name,
114 +             me.name, target_p->info);
115 +    dlinkAddTail(xstrdup(buff), make_dlink_node(), &flatten_links);
116 +    snprintf(buff, sizeof(buff), "%s %s :1 %s\n", target_p->name,
117 +             me.name, target_p->info);
118  
119 <    /*
120 <     * 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;
119 >    fputs(buff, file);
120 >  }
121  
122 <    if (MessageFileptr->contentsOfFile)
123 <    {
143 <      if (currentMessageLine)
144 <        currentMessageLine->next = newMessageLine;
145 <      currentMessageLine = newMessageLine;
146 <    }
147 <    else
148 <    {
149 <      MessageFileptr->contentsOfFile = newMessageLine;
150 <      currentMessageLine = newMessageLine;
151 <    }
122 >  fclose(file);
123 > }
124  
125 <    nbytes = ircsprintf(buff, "%s %s :1 %s\n", target_p->name, me.name, p);
126 <    fbputs(buff, file, nbytes);
125 > void
126 > read_links_file(void)
127 > {
128 >  FILE *file = NULL;
129 >  char *p = NULL;
130 >  char buff[IRCD_BUFSIZE] = { '\0' };
131 >
132 >  if ((file = fopen(LIPATH, "r")) == NULL)
133 >    return;
134 >
135 >  while (fgets(buff, sizeof(buff), file))
136 >  {
137 >    if ((p = strchr(buff, '\n')) != NULL)
138 >      *p = '\0';
139 >
140 >    dlinkAddTail(xstrdup(buff), make_dlink_node(), &flatten_links);
141    }
142  
143 <  fbclose(file);
143 >  fclose(file);
144   }
145  
146   /* hunt_server()
# Line 178 | Line 164 | write_links_file(void* notused)
164   */
165   int
166   hunt_server(struct Client *client_p, struct Client *source_p, const char *command,
167 <            int server, int parc, char *parv[])
167 >            const int server, const int parc, char *parv[])
168   {
169    struct Client *target_p = NULL;
170    struct Client *target_tmp = NULL;
171    dlink_node *ptr;
172    int wilds;
173  
174 <  /* Assume it's me, if no server
175 <   */
176 <  if (parc <= server || EmptyString(parv[server]) ||
177 <      match(me.name, parv[server]) ||
178 <      match(parv[server], me.name) ||
179 <      !strcmp(parv[server], me.id))
194 <    return(HUNTED_ISME);
174 >  /* Assume it's me, if no server */
175 >  if (parc <= server || EmptyString(parv[server]))
176 >    return HUNTED_ISME;
177 >
178 >  if (!strcmp(parv[server], me.id) || !match(parv[server], me.name))
179 >    return HUNTED_ISME;
180  
181    /* These are to pickup matches that would cause the following
182     * message to go in the wrong direction while doing quick fast
# Line 210 | Line 195 | hunt_server(struct Client *client_p, str
195      if (target_p->from == source_p->from && !MyConnect(target_p))
196        target_p = NULL;
197  
198 <  collapse(parv[server]);
214 <  wilds = (strchr(parv[server], '?') || strchr(parv[server], '*'));
198 >  wilds = has_wildcards(parv[server]);
199  
200    /* Again, if there are no wild cards involved in the server
201     * name, use the hash lookup
# Line 222 | Line 206 | hunt_server(struct Client *client_p, str
206      {
207        if (!(target_p = hash_find_server(parv[server])))
208        {
209 <        sendto_one(source_p, form_str(ERR_NOSUCHSERVER),
210 <                   me.name, source_p->name, parv[server]);
227 <        return(HUNTED_NOSUCH);
209 >        sendto_one_numeric(source_p, &me, ERR_NOSUCHSERVER, parv[server]);
210 >        return HUNTED_NOSUCH;
211        }
212      }
213      else
# Line 233 | Line 216 | hunt_server(struct Client *client_p, str
216        {
217          target_tmp = ptr->data;
218  
219 <        if (match(parv[server], target_tmp->name))
219 >        if (!match(parv[server], target_tmp->name))
220          {
221            if (target_tmp->from == source_p->from && !MyConnect(target_tmp))
222              continue;
# Line 250 | Line 233 | hunt_server(struct Client *client_p, str
233    {
234      if(!IsRegistered(target_p))
235      {
236 <      sendto_one(source_p, form_str(ERR_NOSUCHSERVER),
254 <                 me.name, source_p->name, parv[server]);
236 >      sendto_one_numeric(source_p, &me, ERR_NOSUCHSERVER, parv[server]);
237        return HUNTED_NOSUCH;
238      }
239  
240      if (IsMe(target_p) || MyClient(target_p))
241        return HUNTED_ISME;
242  
243 <    if (!match(target_p->name, parv[server]))
243 >    if (match(target_p->name, parv[server]))
244        parv[server] = target_p->name;
245  
246 <    /* 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],
246 >    sendto_one(target_p, command, ID_or_name(source_p, target_p),
247                 parv[1], parv[2], parv[3], parv[4],
248                 parv[5], parv[6], parv[7], parv[8]);
249 <    return(HUNTED_PASS);
250 <  }
249 >    return HUNTED_PASS;
250 >  }
251  
252 <  sendto_one(source_p, form_str(ERR_NOSUCHSERVER),
253 <             me.name, source_p->name, parv[server]);
278 <  return(HUNTED_NOSUCH);
252 >  sendto_one_numeric(source_p, &me, ERR_NOSUCHSERVER, parv[server]);
253 >  return HUNTED_NOSUCH;
254   }
255  
256   /* try_connections()
# Line 291 | Line 266 | hunt_server(struct Client *client_p, str
266   void
267   try_connections(void *unused)
268   {
269 <  dlink_node *ptr;
270 <  struct ConfItem *conf;
296 <  struct AccessItem *aconf;
297 <  struct ClassItem *cltmp;
269 >  dlink_node *ptr = NULL;
270 >  struct MaskItem *conf;
271    int confrq;
272  
273    /* TODO: change this to set active flag to 0 when added to event! --Habeeb */
# Line 304 | Line 277 | try_connections(void *unused)
277    DLINK_FOREACH(ptr, server_items.head)
278    {
279      conf = ptr->data;
307    aconf = map_to_conf(conf);
280  
281 <    /* Also when already connecting! (update holdtimes) --SRB
281 >    assert(conf->type == CONF_SERVER);
282 >
283 >    /* Also when already connecting! (update holdtimes) --SRB
284       */
285 <    if (!(aconf->status & CONF_SERVER) || !aconf->port ||
312 <        !(IsConfAllowAutoConn(aconf)))
285 >    if (!conf->port ||!IsConfAllowAutoConn(conf))
286        continue;
287  
315    cltmp = map_to_conf(aconf->class_ptr);
288  
289      /* Skip this entry if the use of it is still on hold until
290       * future. Otherwise handle this entry (and set it on hold
# Line 320 | Line 292 | try_connections(void *unused)
292       * made one successfull connection... [this algorithm is
293       * a bit fuzzy... -- msa >;) ]
294       */
295 <    if (aconf->hold > CurrentTime)
295 >    if (conf->until > CurrentTime)
296        continue;
297  
298 <    if (cltmp == NULL)
298 >    if (conf->class == NULL)
299        confrq = DEFAULT_CONNECTFREQUENCY;
300      else
301      {
302 <      confrq = ConFreq(cltmp);
303 <      if (confrq < MIN_CONN_FREQ )
304 <        confrq = MIN_CONN_FREQ;
302 >      confrq = conf->class->con_freq;
303 >      if (confrq < MIN_CONN_FREQ)
304 >        confrq = MIN_CONN_FREQ;
305      }
306  
307 <    aconf->hold = CurrentTime + confrq;
307 >    conf->until = CurrentTime + confrq;
308  
309      /* Found a CONNECT config with port specified, scan clients
310       * and see if this server is already connected?
# Line 340 | Line 312 | try_connections(void *unused)
312      if (hash_find_server(conf->name) != NULL)
313        continue;
314  
315 <    if (CurrUserCount(cltmp) < MaxTotal(cltmp))
315 >    if (conf->class->ref_count < conf->class->max_total)
316      {
317        /* Go to the end of the list, if not already last */
318        if (ptr->next != NULL)
# Line 361 | Line 333 | try_connections(void *unused)
333         *   -- adrian
334         */
335        if (ConfigServerHide.hide_server_ips)
336 <        sendto_realops_flags(UMODE_ALL, L_ALL, "Connection to %s activated.",
336 >        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
337 >                             "Connection to %s activated.",
338                               conf->name);
339        else
340 <        sendto_realops_flags(UMODE_ALL, L_ALL, "Connection to %s[%s] activated.",
341 <                             conf->name, aconf->host);
340 >        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
341 >                             "Connection to %s[%s] activated.",
342 >                             conf->name, conf->host);
343  
344 <      serv_connect(aconf, NULL);
344 >      serv_connect(conf, NULL);
345        /* We connect only one at time... */
346        return;
347      }
# Line 399 | Line 373 | int
373   check_server(const char *name, struct Client *client_p)
374   {
375    dlink_node *ptr;
376 <  struct ConfItem *conf           = NULL;
377 <  struct ConfItem *server_conf    = NULL;
404 <  struct AccessItem *server_aconf = NULL;
405 <  struct AccessItem *aconf        = NULL;
376 >  struct MaskItem *conf        = NULL;
377 >  struct MaskItem *server_conf = NULL;
378    int error = -1;
379  
380    assert(client_p != NULL);
381  
410  if (client_p == NULL)
411    return(error);
412
413  if (strlen(name) > HOSTLEN)
414    return(-4);
415
382    /* loop through looking for all possible connect items that might work */
383    DLINK_FOREACH(ptr, server_items.head)
384    {
385      conf = ptr->data;
420    aconf = map_to_conf(conf);
386  
387 <    if (!match(name, conf->name))
387 >    if (match(name, conf->name))
388        continue;
389  
390      error = -3;
391  
392      /* XXX: Fix me for IPv6                    */
393      /* XXX sockhost is the IPv4 ip as a string */
394 <    if (match(aconf->host, client_p->host) ||
395 <        match(aconf->host, client_p->sockhost))
394 >    if (!match(conf->host, client_p->host) ||
395 >        !match(conf->host, client_p->sockhost))
396      {
397        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);
398  
399 <        if (IsConfEncrypted(aconf))
400 <        {
401 <          if (strcmp(aconf->passwd,
402 <              (const char *)crypt(client_p->localClient->passwd,
403 <                                  aconf->passwd)) == 0)
404 <            server_conf = conf;
405 <        }
406 <        else
450 <        {
451 <          if (strcmp(aconf->passwd, client_p->localClient->passwd) == 0)
452 <            server_conf = conf;
453 <        }
454 <      }
399 >      if (!match_conf_password(client_p->localClient->passwd, conf))
400 >        return -2;
401 >
402 >      if (!EmptyString(conf->certfp))
403 >        if (EmptyString(client_p->certfp) || strcasecmp(client_p->certfp, conf->certfp))
404 >          return -4;
405 >
406 >      server_conf = conf;
407      }
408    }
409  
410    if (server_conf == NULL)
411 <    return(error);
411 >    return error;
412  
413    attach_conf(client_p, server_conf);
414  
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
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  }
415  
416 <  if (aconf != NULL)
416 >  if (server_conf != NULL)
417    {
418      struct sockaddr_in *v4;
419   #ifdef IPV6
420      struct sockaddr_in6 *v6;
421   #endif
422 <    switch (aconf->aftype)
422 >    switch (server_conf->aftype)
423      {
424   #ifdef IPV6
425 <      case AF_INET6:
426 <        v6 = (struct sockaddr_in6 *)&aconf->ipnum;
425 >      case AF_INET6:
426 >        v6 = (struct sockaddr_in6 *)&server_conf->addr;
427  
428          if (IN6_IS_ADDR_UNSPECIFIED(&v6->sin6_addr))
429 <          memcpy(&aconf->ipnum, &client_p->localClient->ip, sizeof(struct irc_ssaddr));
429 >          memcpy(&server_conf->addr, &client_p->localClient->ip, sizeof(struct irc_ssaddr));
430          break;
431   #endif
432        case AF_INET:
433 <        v4 = (struct sockaddr_in *)&aconf->ipnum;
433 >        v4 = (struct sockaddr_in *)&server_conf->addr;
434  
435          if (v4->sin_addr.s_addr == INADDR_NONE)
436 <          memcpy(&aconf->ipnum, &client_p->localClient->ip, sizeof(struct irc_ssaddr));
436 >          memcpy(&server_conf->addr, &client_p->localClient->ip, sizeof(struct irc_ssaddr));
437          break;
438      }
439    }
440  
441 <  return(0);
441 >  return 0;
442   }
443  
444   /* add_capability()
# Line 529 | Line 455 | add_capability(const char *capab_name, i
455   {
456    struct Capability *cap = MyMalloc(sizeof(*cap));
457  
458 <  DupString(cap->name, capab_name);
458 >  cap->name = xstrdup(capab_name);
459    cap->cap = cap_flag;
460    dlinkAdd(cap, &cap->node, &cap_list);
461  
# Line 558 | Line 484 | delete_capability(const char *capab_name
484      {
485        if (irccmp(cap->name, capab_name) == 0)
486        {
487 <        default_server_capabs &= ~(cap->cap);
488 <        dlinkDelete(ptr, &cap_list);
489 <        MyFree(cap->name);
490 <        cap->name = NULL;
565 <        MyFree(cap);
487 >        default_server_capabs &= ~(cap->cap);
488 >        dlinkDelete(ptr, &cap_list);
489 >        MyFree(cap->name);
490 >        MyFree(cap);
491        }
492      }
493    }
# Line 577 | Line 502 | delete_capability(const char *capab_name
502   * output       - 0 if not found CAPAB otherwise
503   * side effects - none
504   */
505 < int
505 > unsigned int
506   find_capability(const char *capab)
507   {
508    const dlink_node *ptr = NULL;
# Line 596 | Line 521 | find_capability(const char *capab)
521   /* send_capabilities()
522   *
523   * inputs       - Client pointer to send to
599 *              - Pointer to AccessItem (for crypt)
524   *              - int flag of capabilities that this server can send
525   * output       - NONE
526   * side effects - send the CAPAB line to a server  -orabidoo
527   *
528   */
529   void
530 < send_capabilities(struct Client *client_p, struct AccessItem *aconf,
607 <                  int cap_can_send)
530 > send_capabilities(struct Client *client_p, int cap_can_send)
531   {
532    struct Capability *cap=NULL;
533    char msgbuf[IRCD_BUFSIZE];
# Line 620 | Line 543 | send_capabilities(struct Client *client_
543  
544      if (cap->cap & (cap_can_send|default_server_capabs))
545      {
546 <      tl = ircsprintf(t, "%s ", cap->name);
546 >      tl = sprintf(t, "%s ", cap->name);
547        t += tl;
548      }
549    }
# Line 630 | Line 553 | send_capabilities(struct Client *client_
553   }
554  
555   /* sendnick_TS()
556 < *
556 > *
557   * inputs       - client (server) to send nick towards
558   *          - client to send nick for
559   * output       - NONE
# Line 639 | Line 562 | send_capabilities(struct Client *client_
562   void
563   sendnick_TS(struct Client *client_p, struct Client *target_p)
564   {
565 <  static char ubuf[12];
565 >  char ubuf[IRCD_BUFSIZE];
566  
567    if (!IsClient(target_p))
568      return;
# Line 652 | Line 575 | sendnick_TS(struct Client *client_p, str
575      ubuf[1] = '\0';
576    }
577  
655  /* XXX Both of these need to have a :me.name or :mySID!?!?! */
578    if (IsCapable(client_p, CAP_SVS))
579 <  {
580 <    if (HasID(target_p) && IsCapable(client_p, CAP_TS6))
581 <      sendto_one(client_p, ":%s UID %s %d %lu %s %s %s %s %s %lu :%s",
582 <                 target_p->servptr->id,
583 <                 target_p->name, target_p->hopcount + 1,
584 <                 (unsigned long) target_p->tsinfo,
585 <                 ubuf, target_p->username, target_p->host,
586 <                 (MyClient(target_p) && IsIPSpoof(target_p)) ?
665 <                 "0" : target_p->sockhost, target_p->id,
666 <                 (unsigned long)target_p->servicestamp, target_p->info);
667 <    else
668 <      sendto_one(client_p, "NICK %s %d %lu %s %s %s %s %lu :%s",
669 <                 target_p->name, target_p->hopcount + 1,
670 <                 (unsigned long) target_p->tsinfo,
671 <                 ubuf, target_p->username, target_p->host,
672 <                 target_p->servptr->name, (unsigned long)target_p->servicestamp,
673 <                 target_p->info);
674 <  }
579 >    sendto_one(client_p, ":%s UID %s %d %lu %s %s %s %s %s %s :%s",
580 >               target_p->servptr->id,
581 >               target_p->name, target_p->hopcount + 1,
582 >               (unsigned long) target_p->tsinfo,
583 >               ubuf, target_p->username, target_p->host,
584 >               (MyClient(target_p) && IsIPSpoof(target_p)) ?
585 >               "0" : target_p->sockhost, target_p->id,
586 >               target_p->svid, target_p->info);
587    else
588 <  {
589 <    if (HasID(target_p) && IsCapable(client_p, CAP_TS6))
590 <      sendto_one(client_p, ":%s UID %s %d %lu %s %s %s %s %s :%s",
591 <                 target_p->servptr->id,
592 <                 target_p->name, target_p->hopcount + 1,
593 <                 (unsigned long) target_p->tsinfo,
594 <                 ubuf, target_p->username, target_p->host,
595 <                 (MyClient(target_p) && IsIPSpoof(target_p)) ?
596 <                 "0" : target_p->sockhost, target_p->id, target_p->info);
597 <    else
598 <      sendto_one(client_p, "NICK %s %d %lu %s %s %s %s :%s",
599 <                 target_p->name, target_p->hopcount + 1,
600 <                 (unsigned long) target_p->tsinfo,
601 <                 ubuf, target_p->username, target_p->host,
602 <                 target_p->servptr->name, target_p->info);
691 <  }
692 <
693 <  if (IsConfAwayBurst((struct AccessItem *)map_to_conf(client_p->serv->sconf)))
694 <    if (!EmptyString(target_p->away))
695 <      sendto_one(client_p, ":%s AWAY :%s", target_p->name,
696 <                 target_p->away);
588 >    sendto_one(client_p, ":%s UID %s %d %lu %s %s %s %s %s :%s",
589 >               target_p->servptr->id,
590 >               target_p->name, target_p->hopcount + 1,
591 >               (unsigned long) target_p->tsinfo,
592 >               ubuf, target_p->username, target_p->host,
593 >               (MyClient(target_p) && IsIPSpoof(target_p)) ?
594 >               "0" : target_p->sockhost, target_p->id, target_p->info);
595 >
596 >  if (!EmptyString(target_p->certfp))
597 >    sendto_one(client_p, ":%s CERTFP %s",
598 >               ID_or_name(target_p, client_p), target_p->certfp);
599 >
600 >  if (target_p->away[0])
601 >    sendto_one(client_p, ":%s AWAY :%s", ID_or_name(target_p, client_p),
602 >               target_p->away);
603  
604   }
605  
# Line 705 | Line 611 | sendnick_TS(struct Client *client_p, str
611   * side effects - build up string representing capabilities of server listed
612   */
613   const char *
614 < show_capabilities(struct Client *target_p)
614 > show_capabilities(const struct Client *target_p)
615   {
616 <  static char msgbuf[IRCD_BUFSIZE];
617 <  char *t = msgbuf;
712 <  dlink_node *ptr;
616 >  static char msgbuf[IRCD_BUFSIZE] = "";
617 >  const dlink_node *ptr = NULL;
618  
619 <  t += ircsprintf(msgbuf, "TS ");
619 >  strlcpy(msgbuf, "TS", sizeof(msgbuf));
620  
621    DLINK_FOREACH(ptr, cap_list.head)
622    {
623      const struct Capability *cap = ptr->data;
624  
625 <    if (IsCapable(target_p, cap->cap))
626 <      t += ircsprintf(t, "%s ", cap->name);
625 >    if (!IsCapable(target_p, cap->cap))
626 >      continue;
627 >
628 >    strlcat(msgbuf,       " ", sizeof(msgbuf));
629 >    strlcat(msgbuf, cap->name, sizeof(msgbuf));
630    }
631  
724  *(t - 1) = '\0';
632    return msgbuf;
633   }
634  
# Line 751 | Line 658 | void
658   server_estab(struct Client *client_p)
659   {
660    struct Client *target_p;
661 <  struct ConfItem *conf;
755 <  struct AccessItem *aconf=NULL;
661 >  struct MaskItem *conf = NULL;
662    char *host;
663    const char *inpath;
664    static char inpath_ip[HOSTLEN * 2 + USERLEN + 6];
# Line 768 | Line 674 | server_estab(struct Client *client_p)
674    inpath = get_client_name(client_p, MASK_IP); /* "refresh" inpath with host */
675    host   = client_p->name;
676  
677 <  if ((conf = find_conf_name(&client_p->localClient->confs, host, SERVER_TYPE))
677 >  if ((conf = find_conf_name(&client_p->localClient->confs, host, CONF_SERVER))
678        == NULL)
679    {
680      /* This shouldn't happen, better tell the ops... -A1kmm */
681 <    sendto_realops_flags(UMODE_ALL, L_ALL, "Warning: Lost connect{} block "
681 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
682 >                         "Warning: Lost connect{} block "
683                           "for server %s(this shouldn't happen)!", host);
684      exit_client(client_p, &me, "Lost connect{} block!");
685      return;
# Line 787 | Line 694 | server_estab(struct Client *client_p)
694    /* If there is something in the serv_list, it might be this
695     * connecting server..
696     */
697 <  if (!ServerInfo.hub && serv_list.head)  
697 >  if (!ServerInfo.hub && serv_list.head)
698    {
699      if (client_p != serv_list.head->data || serv_list.head->next)
700      {
# Line 798 | Line 705 | server_estab(struct Client *client_p)
705      }
706    }
707  
801  aconf = map_to_conf(conf);
802
708    if (IsUnknown(client_p))
709    {
710 <    /* 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 <     */
710 >    sendto_one(client_p, "PASS %s TS %d %s", conf->spasswd, TS_CURRENT, me.id);
711  
712 <    send_capabilities(client_p, aconf,
820 <      (IsConfTopicBurst(aconf) ? CAP_TBURST|CAP_TB : 0));
712 >    send_capabilities(client_p, 0);
713  
714      sendto_one(client_p, "SERVER %s 1 :%s%s",
715                 me.name, ConfigServerHide.hidden ? "(H) " : "", me.info);
# Line 826 | Line 718 | server_estab(struct Client *client_p)
718    sendto_one(client_p, "SVINFO %d %d 0 :%lu", TS_CURRENT, TS_MIN,
719               (unsigned long)CurrentTime);
720  
721 <  /* assumption here is if they passed the correct TS version, they also passed an SID */
830 <  if (IsCapable(client_p, CAP_TS6))
721 >  if (HasID(client_p))
722      hash_add_id(client_p);
723  
724    /* XXX Does this ever happen? I don't think so -db */
725 <  detach_conf(client_p, OPER_TYPE);
725 >  detach_conf(client_p, CONF_OPER);
726  
727    /* *WARNING*
728    **    In the following code in place of plain server's
# Line 873 | Line 764 | server_estab(struct Client *client_p)
764    /* fixing eob timings.. -gnp */
765    client_p->localClient->firsttime = CurrentTime;
766  
767 <  if (find_matching_name_conf(SERVICE_TYPE, client_p->name, NULL, NULL, 0))
767 >  if (find_matching_name_conf(CONF_SERVICE, client_p->name, NULL, NULL, 0))
768      AddFlag(client_p, FLAGS_SERVICE);
769  
770    /* Show the real host/IP to admins */
# Line 883 | Line 774 | server_estab(struct Client *client_p)
774      compression = SSL_get_current_compression(client_p->localClient->fd.ssl);
775      expansion   = SSL_get_current_expansion(client_p->localClient->fd.ssl);
776  
777 <    sendto_realops_flags(UMODE_ALL, L_ADMIN,
777 >    sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
778                           "Link with %s established: [SSL: %s, Compression/Expansion method: %s/%s] (Capabilities: %s)",
779                           inpath_ip, ssl_get_cipher(client_p->localClient->fd.ssl),
780                           compression ? SSL_COMP_get_name(compression) : "NONE",
781                           expansion ? SSL_COMP_get_name(expansion) : "NONE",
782                           show_capabilities(client_p));
783      /* Now show the masked hostname/IP to opers */
784 <    sendto_realops_flags(UMODE_ALL, L_OPER,
784 >    sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
785                           "Link with %s established: [SSL: %s, Compression/Expansion method: %s/%s] (Capabilities: %s)",
786                           inpath, ssl_get_cipher(client_p->localClient->fd.ssl),
787                           compression ? SSL_COMP_get_name(compression) : "NONE",
# Line 905 | Line 796 | server_estab(struct Client *client_p)
796    else
797   #endif
798    {
799 <    sendto_realops_flags(UMODE_ALL, L_ADMIN,
799 >    sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
800                           "Link with %s established: (Capabilities: %s)",
801 <                         inpath_ip,show_capabilities(client_p));
801 >                         inpath_ip, show_capabilities(client_p));
802      /* Now show the masked hostname/IP to opers */
803 <    sendto_realops_flags(UMODE_ALL, L_OPER,
803 >    sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
804                           "Link with %s established: (Capabilities: %s)",
805 <                         inpath,show_capabilities(client_p));
805 >                         inpath, show_capabilities(client_p));
806      ilog(LOG_TYPE_IRCD, "Link with %s established: (Capabilities: %s)",
807           inpath_ip, show_capabilities(client_p));
808    }
809  
919  client_p->serv->sconf = conf;
920
810    fd_note(&client_p->localClient->fd, "Server: %s", client_p->name);
811  
812    /* Old sendto_serv_but_one() call removed because we now
# Line 931 | Line 820 | server_estab(struct Client *client_p)
820      if (target_p == client_p)
821        continue;
822  
823 <    if (IsCapable(target_p, CAP_TS6) && HasID(client_p))
824 <      sendto_one(target_p, ":%s SID %s 2 %s :%s%s",
825 <                 me.id, client_p->name, client_p->id,
826 <                 IsHidden(client_p) ? "(H) " : "",
827 <                 client_p->info);
828 <    else
829 <      sendto_one(target_p,":%s SERVER %s 2 :%s%s",
830 <                 me.name, client_p->name,
831 <                 IsHidden(client_p) ? "(H) " : "",
832 <                 client_p->info);
833 <  }
834 <
835 <  /* Pass on my client information to the new server
836 <  **
837 <  ** First, pass only servers (idea is that if the link gets
838 <  ** cancelled beacause the server was already there,
839 <  ** there are no NICK's to be cancelled...). Of course,
840 <  ** if cancellation occurs, all this info is sent anyway,
841 <  ** and I guess the link dies when a read is attempted...? --msa
842 <  **
843 <  ** Note: Link cancellation to occur at this point means
844 <  ** that at least two servers from my fragment are building
845 <  ** up connection this other fragment at the same time, it's
846 <  ** a race condition, not the normal way of operation...
958 <  **
959 <  ** ALSO NOTE: using the get_client_name for server names--
960 <  **    see previous *WARNING*!!! (Also, original inpath
961 <  **    is destroyed...)
962 <  */
823 >    sendto_one(target_p, ":%s SID %s 2 %s :%s%s",
824 >               me.id, client_p->name, client_p->id,
825 >               IsHidden(client_p) ? "(H) " : "",
826 >               client_p->info);
827 >  }
828 >
829 >  /*
830 >   * Pass on my client information to the new server
831 >   *
832 >   * First, pass only servers (idea is that if the link gets
833 >   * cancelled beacause the server was already there,
834 >   * there are no NICK's to be cancelled...). Of course,
835 >   * if cancellation occurs, all this info is sent anyway,
836 >   * and I guess the link dies when a read is attempted...? --msa
837 >   *
838 >   * Note: Link cancellation to occur at this point means
839 >   * that at least two servers from my fragment are building
840 >   * up connection this other fragment at the same time, it's
841 >   * a race condition, not the normal way of operation...
842 >   *
843 >   * ALSO NOTE: using the get_client_name for server names--
844 >   *    see previous *WARNING*!!! (Also, original inpath
845 >   *    is destroyed...)
846 >   */
847  
848    DLINK_FOREACH_PREV(ptr, global_serv_list.tail)
849    {
# Line 969 | Line 853 | server_estab(struct Client *client_p)
853      if (IsMe(target_p) || target_p->from == client_p)
854        continue;
855  
856 <    if (IsCapable(client_p, CAP_TS6))
857 <    {
858 <      if (HasID(target_p))
859 <        sendto_one(client_p, ":%s SID %s %d %s :%s%s",
860 <                   ID(target_p->servptr), target_p->name, target_p->hopcount+1,
861 <                   target_p->id, IsHidden(target_p) ? "(H) " : "",
862 <                   target_p->info);
979 <      else  /* introducing non-ts6 server */
980 <        sendto_one(client_p, ":%s SERVER %s %d :%s%s",
981 <                   ID(target_p->servptr), target_p->name, target_p->hopcount+1,
982 <                   IsHidden(target_p) ? "(H) " : "", target_p->info);
983 <    }
984 <    else
985 <      sendto_one(client_p, ":%s SERVER %s %d :%s%s",
986 <                 target_p->servptr->name, target_p->name, target_p->hopcount+1,
987 <                 IsHidden(target_p) ? "(H) " : "", target_p->info);
856 >    sendto_one(client_p, ":%s SID %s %d %s :%s%s",
857 >               ID(target_p->servptr), target_p->name, target_p->hopcount+1,
858 >               target_p->id, IsHidden(target_p) ? "(H) " : "",
859 >               target_p->info);
860 >
861 >    if (HasFlag(target_p, FLAGS_EOB))
862 >      sendto_one(client_p, ":%s EOB", ID_or_name(target_p, client_p));
863    }
864  
865    server_burst(client_p);
# Line 1020 | Line 895 | server_burst(struct Client *client_p)
895  
896   /* burst_all()
897   *
898 < * inputs       - pointer to server to send burst to
898 > * inputs       - pointer to server to send burst to
899   * output       - NONE
900   * side effects - complete burst of channels/nicks is sent to client_p
901   */
# Line 1038 | Line 913 | burst_all(struct Client *client_p)
913        burst_members(client_p, chptr);
914        send_channel_modes(client_p, chptr);
915  
916 <      if (IsCapable(client_p, CAP_TBURST) ||
917 <          IsCapable(client_p, CAP_TB))
1043 <        send_tb(client_p, chptr);
916 >      if (IsCapable(client_p, CAP_TBURST))
917 >        send_tb(client_p, chptr);
918      }
919    }
920  
# Line 1052 | Line 926 | burst_all(struct Client *client_p)
926  
927      if (!HasFlag(target_p, FLAGS_BURSTED) && target_p->from != client_p)
928        sendnick_TS(client_p, target_p);
929 <    
929 >
930      DelFlag(target_p, FLAGS_BURSTED);
931    }
932  
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_ */
933    if (IsCapable(client_p, CAP_EOB))
934      sendto_one(client_p, ":%s EOB", ID_or_name(&me, client_p));
935   }
# Line 1071 | Line 941 | burst_all(struct Client *client_p)
941   *              - pointer to channel
942   * output       - NONE
943   * side effects - Called on a server burst when
944 < *                server is CAP_TB|CAP_TBURST capable
944 > *                server is CAP_TBURST capable
945   */
946   static void
947   send_tb(struct Client *client_p, struct Channel *chptr)
# Line 1090 | Line 960 | send_tb(struct Client *client_p, struct
960     * for further information   -Michael
961     */
962    if (chptr->topic_time != 0)
963 <  {
964 <    if (IsCapable(client_p, CAP_TBURST))
965 <      sendto_one(client_p, ":%s TBURST %lu %s %lu %s :%s",
966 <                 me.name, (unsigned long)chptr->channelts, chptr->chname,
967 <                 (unsigned long)chptr->topic_time,
968 <                 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 <  }
963 >    sendto_one(client_p, ":%s TBURST %lu %s %lu %s :%s",
964 >               ID_or_name(&me, client_p),
965 >               (unsigned long)chptr->channelts, chptr->chname,
966 >               (unsigned long)chptr->topic_time,
967 >               chptr->topic_info,
968 >               chptr->topic);
969   }
970  
971   /* burst_members()
# Line 1153 | Line 1004 | burst_members(struct Client *client_p, s
1004  
1005   /* serv_connect() - initiate a server connection
1006   *
1007 < * inputs       - pointer to conf
1007 > * inputs       - pointer to conf
1008   *              - pointer to client doing the connect
1009   * output       -
1010   * side effects -
# Line 1168 | Line 1019 | burst_members(struct Client *client_p, s
1019   * it suceeded or not, and 0 if it fails in here somewhere.
1020   */
1021   int
1022 < serv_connect(struct AccessItem *aconf, struct Client *by)
1022 > serv_connect(struct MaskItem *conf, struct Client *by)
1023   {
1173  struct ConfItem *conf;
1024    struct Client *client_p;
1025 <  char buf[HOSTIPLEN];
1025 >  char buf[HOSTIPLEN + 1];
1026  
1027    /* conversion structs */
1028    struct sockaddr_in *v4;
1029 <  /* Make sure aconf is useful */
1030 <  assert(aconf != NULL);
1029 >  /* Make sure conf is useful */
1030 >  assert(conf != NULL);
1031  
1182  if(aconf == NULL)
1183    return (0);
1032  
1033 <  /* XXX should be passing struct ConfItem in the first place */
1186 <  conf = unmap_conf_item(aconf);
1187 <
1188 <  /* log */
1189 <  getnameinfo((struct sockaddr *)&aconf->ipnum, aconf->ipnum.ss_len,
1033 >  getnameinfo((struct sockaddr *)&conf->addr, conf->addr.ss_len,
1034                buf, sizeof(buf), NULL, 0, NI_NUMERICHOST);
1035 <  ilog(LOG_TYPE_IRCD, "Connect to %s[%s] @%s", aconf->user, aconf->host,
1035 >  ilog(LOG_TYPE_IRCD, "Connect to %s[%s] @%s", conf->name, conf->host,
1036         buf);
1037  
1038    /* Still processing a DNS lookup? -> exit */
1039 <  if (aconf->dns_pending)
1039 >  if (conf->dns_pending)
1040    {
1041 <    sendto_realops_flags(UMODE_ALL, L_ALL,
1041 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1042                           "Error connecting to %s: DNS lookup for connect{} in progress.",
1043                           conf->name);
1044      return (0);
1045    }
1046  
1047 <  if (aconf->dns_failed)
1047 >  if (conf->dns_failed)
1048    {
1049 <    sendto_realops_flags(UMODE_ALL, L_ALL,
1049 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1050                           "Error connecting to %s: DNS lookup for connect{} failed.",
1051                           conf->name);
1052      return (0);
1053    }
1054  
1055    /* Make sure this server isn't already connected
1056 <   * Note: aconf should ALWAYS be a valid C: line
1056 >   * Note: conf should ALWAYS be a valid C: line
1057     */
1058    if ((client_p = hash_find_server(conf->name)) != NULL)
1059 <  {
1060 <    sendto_realops_flags(UMODE_ALL, L_ADMIN,
1061 <                         "Server %s already present from %s",
1062 <                         conf->name, get_client_name(client_p, SHOW_IP));
1063 <    sendto_realops_flags(UMODE_ALL, L_OPER,
1064 <                         "Server %s already present from %s",
1065 <                         conf->name, get_client_name(client_p, MASK_IP));
1059 >  {
1060 >    sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1061 >                         "Server %s already present from %s",
1062 >                         conf->name, get_client_name(client_p, SHOW_IP));
1063 >    sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
1064 >                         "Server %s already present from %s",
1065 >                         conf->name, get_client_name(client_p, MASK_IP));
1066      if (by && IsClient(by) && !MyClient(by))
1067 <      sendto_one(by, ":%s NOTICE %s :Server %s already present from %s",
1068 <                 me.name, by->name, conf->name,
1069 <                 get_client_name(client_p, MASK_IP));
1226 <    return (0);
1067 >      sendto_one_notice(by, &me, ":Server %s already present from %s",
1068 >                        conf->name, get_client_name(client_p, MASK_IP));
1069 >    return 0;
1070    }
1071 <    
1071 >
1072    /* Create a local client */
1073    client_p = make_client(NULL);
1074  
1075    /* Copy in the server, hostname, fd */
1076    strlcpy(client_p->name, conf->name, sizeof(client_p->name));
1077 <  strlcpy(client_p->host, aconf->host, sizeof(client_p->host));
1077 >  strlcpy(client_p->host, conf->host, sizeof(client_p->host));
1078  
1079    /* We already converted the ip once, so lets use it - stu */
1080    strlcpy(client_p->sockhost, buf, sizeof(client_p->sockhost));
1081  
1082 <  /* create a socket for the server connection */
1083 <  if (comm_open(&client_p->localClient->fd, aconf->ipnum.ss.ss_family,
1082 >  /* create a socket for the server connection */
1083 >  if (comm_open(&client_p->localClient->fd, conf->addr.ss.ss_family,
1084                  SOCK_STREAM, 0, NULL) < 0)
1085    {
1086      /* Eek, failure to create the socket */
1087 <    report_error(L_ALL,
1088 <                 "opening stream socket to %s: %s", conf->name, errno);
1087 >    report_error(L_ALL, "opening stream socket to %s: %s",
1088 >                 conf->name, errno);
1089      SetDead(client_p);
1090      exit_client(client_p, &me, "Connection failed");
1091 <    return (0);
1091 >    return 0;
1092    }
1093  
1094    /* servernames are always guaranteed under HOSTLEN chars */
# Line 1254 | Line 1097 | serv_connect(struct AccessItem *aconf, s
1097    /* Attach config entries to client here rather than in
1098     * serv_connect_callback(). This to avoid null pointer references.
1099     */
1100 <  if (!attach_connect_block(client_p, conf->name, aconf->host))
1100 >  if (!attach_connect_block(client_p, conf->name, conf->host))
1101    {
1102 <    sendto_realops_flags(UMODE_ALL, L_ALL,
1103 <                         "Host %s is not enabled for connecting:no C/N-line",
1104 <                         conf->name);
1105 <    if (by && IsClient(by) && !MyClient(by))  
1106 <      sendto_one(by, ":%s NOTICE %s :Connect to host %s failed.",
1107 <                 me.name, by->name, client_p->name);
1102 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1103 >                         "Host %s is not enabled for connecting: no connect{} block",
1104 >                         conf->name);
1105 >    if (by && IsClient(by) && !MyClient(by))
1106 >      sendto_one_notice(by, &me, ":Connect to host %s failed.", client_p->name);
1107 >
1108      SetDead(client_p);
1109      exit_client(client_p, client_p, "Connection failed");
1110 <    return (0);
1110 >    return 0;
1111    }
1112  
1113    /* at this point we have a connection in progress and C/N lines
# Line 1283 | Line 1126 | serv_connect(struct AccessItem *aconf, s
1126    SetConnecting(client_p);
1127    dlinkAdd(client_p, &client_p->node, &global_client_list);
1128    /* from def_fam */
1129 <  client_p->localClient->aftype = aconf->aftype;
1129 >  client_p->localClient->aftype = conf->aftype;
1130  
1131    /* Now, initiate the connection */
1132 <  /* XXX assume that a non 0 type means a specific bind address
1132 >  /* XXX assume that a non 0 type means a specific bind address
1133     * for this connect.
1134     */
1135 <  switch (aconf->aftype)
1135 >  switch (conf->aftype)
1136    {
1137      case AF_INET:
1138 <      v4 = (struct sockaddr_in*)&aconf->my_ipnum;
1138 >      v4 = (struct sockaddr_in*)&conf->bind;
1139        if (v4->sin_addr.s_addr != 0)
1140        {
1141          struct irc_ssaddr ipn;
1142          memset(&ipn, 0, sizeof(struct irc_ssaddr));
1143          ipn.ss.ss_family = AF_INET;
1144          ipn.ss_port = 0;
1145 <        memcpy(&ipn, &aconf->my_ipnum, sizeof(struct irc_ssaddr));
1146 <        comm_connect_tcp(&client_p->localClient->fd, aconf->host, aconf->port,
1147 <                         (struct sockaddr *)&ipn, ipn.ss_len,
1148 <                         serv_connect_callback, client_p, aconf->aftype,
1149 <                         CONNECTTIMEOUT);
1145 >        memcpy(&ipn, &conf->bind, sizeof(struct irc_ssaddr));
1146 >        comm_connect_tcp(&client_p->localClient->fd, conf->host, conf->port,
1147 >                         (struct sockaddr *)&ipn, ipn.ss_len,
1148 >                         serv_connect_callback, client_p, conf->aftype,
1149 >                         CONNECTTIMEOUT);
1150        }
1151        else if (ServerInfo.specific_ipv4_vhost)
1152        {
# Line 1312 | Line 1155 | serv_connect(struct AccessItem *aconf, s
1155          ipn.ss.ss_family = AF_INET;
1156          ipn.ss_port = 0;
1157          memcpy(&ipn, &ServerInfo.ip, sizeof(struct irc_ssaddr));
1158 <        comm_connect_tcp(&client_p->localClient->fd, aconf->host, aconf->port,
1158 >        comm_connect_tcp(&client_p->localClient->fd, conf->host, conf->port,
1159                           (struct sockaddr *)&ipn, ipn.ss_len,
1160 <                         serv_connect_callback, client_p, aconf->aftype,
1161 <                         CONNECTTIMEOUT);
1160 >                         serv_connect_callback, client_p, conf->aftype,
1161 >                         CONNECTTIMEOUT);
1162        }
1163        else
1164 <        comm_connect_tcp(&client_p->localClient->fd, aconf->host, aconf->port,
1165 <                         NULL, 0, serv_connect_callback, client_p, aconf->aftype,
1164 >        comm_connect_tcp(&client_p->localClient->fd, conf->host, conf->port,
1165 >                         NULL, 0, serv_connect_callback, client_p, conf->aftype,
1166                           CONNECTTIMEOUT);
1167        break;
1168   #ifdef IPV6
1169      case AF_INET6:
1170        {
1171 <        struct irc_ssaddr ipn;
1172 <        struct sockaddr_in6 *v6;
1173 <        struct sockaddr_in6 *v6conf;
1174 <
1175 <        memset(&ipn, 0, sizeof(struct irc_ssaddr));
1176 <        v6conf = (struct sockaddr_in6 *)&aconf->my_ipnum;
1177 <        v6 = (struct sockaddr_in6 *)&ipn;
1178 <
1179 <        if (memcmp(&v6conf->sin6_addr, &v6->sin6_addr,
1180 <                   sizeof(struct in6_addr)) != 0)
1181 <        {
1182 <          memcpy(&ipn, &aconf->my_ipnum, sizeof(struct irc_ssaddr));
1183 <          ipn.ss.ss_family = AF_INET6;
1184 <          ipn.ss_port = 0;
1185 <          comm_connect_tcp(&client_p->localClient->fd,
1186 <                           aconf->host, aconf->port,
1187 <                           (struct sockaddr *)&ipn, ipn.ss_len,
1188 <                           serv_connect_callback, client_p,
1189 <                           aconf->aftype, CONNECTTIMEOUT);
1190 <        }
1348 <        else if (ServerInfo.specific_ipv6_vhost)
1171 >        struct irc_ssaddr ipn;
1172 >        struct sockaddr_in6 *v6;
1173 >        struct sockaddr_in6 *v6conf;
1174 >
1175 >        memset(&ipn, 0, sizeof(struct irc_ssaddr));
1176 >        v6conf = (struct sockaddr_in6 *)&conf->bind;
1177 >        v6 = (struct sockaddr_in6 *)&ipn;
1178 >
1179 >        if (memcmp(&v6conf->sin6_addr, &v6->sin6_addr, sizeof(struct in6_addr)) != 0)
1180 >        {
1181 >          memcpy(&ipn, &conf->bind, sizeof(struct irc_ssaddr));
1182 >          ipn.ss.ss_family = AF_INET6;
1183 >          ipn.ss_port = 0;
1184 >          comm_connect_tcp(&client_p->localClient->fd,
1185 >                           conf->host, conf->port,
1186 >                           (struct sockaddr *)&ipn, ipn.ss_len,
1187 >                           serv_connect_callback, client_p,
1188 >                           conf->aftype, CONNECTTIMEOUT);
1189 >        }
1190 >        else if (ServerInfo.specific_ipv6_vhost)
1191          {
1192 <          memcpy(&ipn, &ServerInfo.ip6, sizeof(struct irc_ssaddr));
1193 <          ipn.ss.ss_family = AF_INET6;
1194 <          ipn.ss_port = 0;
1195 <          comm_connect_tcp(&client_p->localClient->fd,
1196 <                           aconf->host, aconf->port,
1197 <                           (struct sockaddr *)&ipn, ipn.ss_len,
1198 <                           serv_connect_callback, client_p,
1199 <                           aconf->aftype, CONNECTTIMEOUT);
1200 <        }
1201 <        else
1202 <          comm_connect_tcp(&client_p->localClient->fd,
1203 <                           aconf->host, aconf->port,
1204 <                           NULL, 0, serv_connect_callback, client_p,
1205 <                           aconf->aftype, CONNECTTIMEOUT);
1192 >          memcpy(&ipn, &ServerInfo.ip6, sizeof(struct irc_ssaddr));
1193 >          ipn.ss.ss_family = AF_INET6;
1194 >          ipn.ss_port = 0;
1195 >          comm_connect_tcp(&client_p->localClient->fd,
1196 >                           conf->host, conf->port,
1197 >                           (struct sockaddr *)&ipn, ipn.ss_len,
1198 >                           serv_connect_callback, client_p,
1199 >                           conf->aftype, CONNECTTIMEOUT);
1200 >        }
1201 >        else
1202 >          comm_connect_tcp(&client_p->localClient->fd,
1203 >                           conf->host, conf->port,
1204 >                           NULL, 0, serv_connect_callback, client_p,
1205 >                           conf->aftype, CONNECTTIMEOUT);
1206        }
1207   #endif
1208    }
1209 <  return (1);
1209 >  return 1;
1210   }
1211  
1212   #ifdef HAVE_LIBCRYPTO
1213   static void
1214   finish_ssl_server_handshake(struct Client *client_p)
1215   {
1216 <  struct ConfItem *conf=NULL;
1375 <  struct AccessItem *aconf=NULL;
1216 >  struct MaskItem *conf = NULL;
1217  
1218    conf = find_conf_name(&client_p->localClient->confs,
1219 <                        client_p->name, SERVER_TYPE);
1219 >                        client_p->name, CONF_SERVER);
1220    if (conf == NULL)
1221    {
1222 <    sendto_realops_flags(UMODE_ALL, L_ADMIN,
1222 >    sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1223                           "Lost connect{} block for %s", get_client_name(client_p, HIDE_IP));
1224 <    sendto_realops_flags(UMODE_ALL, L_OPER,
1224 >    sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
1225                           "Lost connect{} block for %s", get_client_name(client_p, MASK_IP));
1226  
1227      exit_client(client_p, &me, "Lost connect{} block");
1228      return;
1229    }
1230  
1231 <  aconf = map_to_conf(conf);
1231 >  sendto_one(client_p, "PASS %s TS %d %s", conf->spasswd, TS_CURRENT, me.id);
1232  
1233 <  /* 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));
1233 >  send_capabilities(client_p, 0);
1234  
1235    sendto_one(client_p, "SERVER %s 1 :%s%s",
1236               me.name, ConfigServerHide.hidden ? "(H) " : "",
# Line 1406 | Line 1241 | finish_ssl_server_handshake(struct Clien
1241     */
1242    if (IsDead(client_p))
1243    {
1244 <      sendto_realops_flags(UMODE_ALL, L_ADMIN,
1244 >      sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1245                             "%s[%s] went dead during handshake",
1246                             client_p->name,
1247                             client_p->host);
1248 <      sendto_realops_flags(UMODE_ALL, L_OPER,
1248 >      sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
1249                             "%s went dead during handshake", client_p->name);
1250        return;
1251    }
# Line 1423 | Line 1258 | finish_ssl_server_handshake(struct Clien
1258   static void
1259   ssl_server_handshake(fde_t *fd, struct Client *client_p)
1260   {
1261 <  int ret;
1262 <  int err;
1428 <
1429 <  ret = SSL_connect(client_p->localClient->fd.ssl);
1261 >  X509 *cert = NULL;
1262 >  int ret = 0;
1263  
1264 <  if (ret <= 0)
1264 >  if ((ret = SSL_connect(client_p->localClient->fd.ssl)) <= 0)
1265    {
1266 <    switch ((err = SSL_get_error(client_p->localClient->fd.ssl, ret)))
1266 >    switch (SSL_get_error(client_p->localClient->fd.ssl, ret))
1267      {
1268        case SSL_ERROR_WANT_WRITE:
1269          comm_setselect(&client_p->localClient->fd, COMM_SELECT_WRITE,
1270 <            (PF *) ssl_server_handshake, client_p, 0);
1270 >                       (PF *)ssl_server_handshake, client_p, 0);
1271          return;
1272        case SSL_ERROR_WANT_READ:
1273          comm_setselect(&client_p->localClient->fd, COMM_SELECT_READ,
1274 <            (PF *) ssl_server_handshake, client_p, 0);
1274 >                       (PF *)ssl_server_handshake, client_p, 0);
1275          return;
1276        default:
1277 +      {
1278 +        const char *sslerr = ERR_error_string(ERR_get_error(), NULL);
1279 +        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1280 +                             "Error connecting to %s: %s", client_p->name,
1281 +                             sslerr ? sslerr : "unknown SSL error");
1282          exit_client(client_p, client_p, "Error during SSL handshake");
1283          return;
1284 +      }
1285      }
1286    }
1287  
1288 +  if ((cert = SSL_get_peer_certificate(client_p->localClient->fd.ssl)))
1289 +  {
1290 +    int res = SSL_get_verify_result(client_p->localClient->fd.ssl);
1291 +    char buf[EVP_MAX_MD_SIZE * 2 + 1] = { '\0' };
1292 +    unsigned char md[EVP_MAX_MD_SIZE] = { '\0' };
1293 +
1294 +    if (res == X509_V_OK || res == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN ||
1295 +        res == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE ||
1296 +        res == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT)
1297 +    {
1298 +      unsigned int i = 0, n = 0;
1299 +
1300 +      if (X509_digest(cert, EVP_sha256(), md, &n))
1301 +      {
1302 +        for (; i < n; ++i)
1303 +          snprintf(buf + 2 * i, 3, "%02X", md[i]);
1304 +        client_p->certfp = xstrdup(buf);
1305 +      }
1306 +    }
1307 +    else
1308 +      ilog(LOG_TYPE_IRCD, "Server %s!%s@%s gave bad SSL client certificate: %d",
1309 +           client_p->name, client_p->username, client_p->host, res);
1310 +    X509_free(cert);
1311 +  }
1312 +
1313    finish_ssl_server_handshake(client_p);
1314   }
1315  
1316   static void
1317 < ssl_connect_init(struct Client *client_p, struct AccessItem *aconf, fde_t *fd)
1317 > ssl_connect_init(struct Client *client_p, struct MaskItem *conf, fde_t *fd)
1318   {
1319    if ((client_p->localClient->fd.ssl = SSL_new(ServerInfo.client_ctx)) == NULL)
1320    {
# Line 1463 | Line 1327 | ssl_connect_init(struct Client *client_p
1327  
1328    SSL_set_fd(fd->ssl, fd->fd);
1329  
1330 <  if (!EmptyString(aconf->cipher_list))
1331 <    SSL_set_cipher_list(client_p->localClient->fd.ssl, aconf->cipher_list);
1330 >  if (!EmptyString(conf->cipher_list))
1331 >    SSL_set_cipher_list(client_p->localClient->fd.ssl, conf->cipher_list);
1332  
1333    ssl_server_handshake(NULL, client_p);
1334   }
1335   #endif
1336  
1337   /* serv_connect_callback() - complete a server connection.
1338 < *
1338 > *
1339   * This routine is called after the server connection attempt has
1340   * completed. If unsucessful, an error is sent to ops and the client
1341   * is closed. If sucessful, it goes through the initialisation/check
# Line 1482 | Line 1346 | static void
1346   serv_connect_callback(fde_t *fd, int status, void *data)
1347   {
1348    struct Client *client_p = data;
1349 <  struct ConfItem *conf=NULL;
1486 <  struct AccessItem *aconf=NULL;
1349 >  struct MaskItem *conf = NULL;
1350  
1351    /* First, make sure its a real client! */
1352    assert(client_p != NULL);
# Line 1499 | Line 1362 | serv_connect_callback(fde_t *fd, int sta
1362       * Admins get to see any IP, mere opers don't *sigh*
1363       */
1364       if (ConfigServerHide.hide_server_ips)
1365 <       sendto_realops_flags(UMODE_ALL, L_ADMIN,
1365 >       sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1366                              "Error connecting to %s: %s",
1367                              client_p->name, comm_errstr(status));
1368       else
1369 <       sendto_realops_flags(UMODE_ALL, L_ADMIN,
1370 <                            "Error connecting to %s[%s]: %s", client_p->name,
1371 <                            client_p->host, comm_errstr(status));
1372 <
1373 <     sendto_realops_flags(UMODE_ALL, L_OPER,
1374 <                          "Error connecting to %s: %s",
1375 <                          client_p->name, comm_errstr(status));
1369 >       sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1370 >                            "Error connecting to %s[%s]: %s", client_p->name,
1371 >                            client_p->host, comm_errstr(status));
1372 >
1373 >     sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
1374 >                          "Error connecting to %s: %s",
1375 >                          client_p->name, comm_errstr(status));
1376  
1377       /* If a fd goes bad, call dead_link() the socket is no
1378        * longer valid for reading or writing.
# Line 1521 | Line 1384 | serv_connect_callback(fde_t *fd, int sta
1384    /* COMM_OK, so continue the connection procedure */
1385    /* Get the C/N lines */
1386    conf = find_conf_name(&client_p->localClient->confs,
1387 <                        client_p->name, SERVER_TYPE);
1387 >                        client_p->name, CONF_SERVER);
1388    if (conf == NULL)
1389    {
1390 <    sendto_realops_flags(UMODE_ALL, L_ADMIN,
1391 <                         "Lost connect{} block for %s", get_client_name(client_p, HIDE_IP));
1392 <    sendto_realops_flags(UMODE_ALL, L_OPER,
1393 <                         "Lost connect{} block for %s", get_client_name(client_p, MASK_IP));
1390 >    sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1391 >                         "Lost connect{} block for %s", get_client_name(client_p, HIDE_IP));
1392 >    sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
1393 >                         "Lost connect{} block for %s", get_client_name(client_p, MASK_IP));
1394  
1395      exit_client(client_p, &me, "Lost connect{} block");
1396      return;
1397    }
1398  
1536  aconf = map_to_conf(conf);
1399    /* Next, send the initial handshake */
1400    SetHandshake(client_p);
1401  
1402   #ifdef HAVE_LIBCRYPTO
1403 <  if (IsConfSSL(aconf))
1403 >  if (IsConfSSL(conf))
1404    {
1405 <    ssl_connect_init(client_p, aconf, fd);
1405 >    ssl_connect_init(client_p, conf, fd);
1406      return;
1407    }
1408   #endif
1409  
1410 <  /* 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);
1410 >  sendto_one(client_p, "PASS %s TS %d %s", conf->spasswd, TS_CURRENT, me.id);
1411  
1412 <  send_capabilities(client_p, aconf,
1554 <                   (IsConfTopicBurst(aconf) ? CAP_TBURST|CAP_TB : 0));
1412 >  send_capabilities(client_p, 0);
1413  
1414 <  sendto_one(client_p, "SERVER %s 1 :%s%s",
1415 <             me.name, ConfigServerHide.hidden ? "(H) " : "",
1558 <             me.info);
1414 >  sendto_one(client_p, "SERVER %s 1 :%s%s", me.name,
1415 >             ConfigServerHide.hidden ? "(H) " : "", me.info);
1416  
1417    /* If we've been marked dead because a send failed, just exit
1418     * here now and save everyone the trouble of us ever existing.
1419     */
1420 <  if (IsDead(client_p))
1420 >  if (IsDead(client_p))
1421    {
1422 <      sendto_realops_flags(UMODE_ALL, L_ADMIN,
1423 <                           "%s[%s] went dead during handshake",
1422 >      sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1423 >                           "%s[%s] went dead during handshake",
1424                             client_p->name,
1425 <                           client_p->host);
1426 <      sendto_realops_flags(UMODE_ALL, L_OPER,
1427 <                           "%s went dead during handshake", client_p->name);
1425 >                           client_p->host);
1426 >      sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
1427 >                           "%s went dead during handshake", client_p->name);
1428        return;
1429    }
1430  
# Line 1587 | Line 1444 | find_servconn_in_progress(const char *na
1444      cptr = ptr->data;
1445  
1446      if (cptr && cptr->name[0])
1447 <      if (match(name, cptr->name))
1447 >      if (!match(name, cptr->name))
1448          return cptr;
1449    }
1450 <  
1450 >
1451    return NULL;
1452   }

Diff Legend

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