]> jfr.im git - solanum.git/blame - ircd/s_serv.c
Add .travis.yml
[solanum.git] / ircd / s_serv.c
CommitLineData
212380e3
AC
1/*
2 * ircd-ratbox: A slightly useful ircd.
3 * s_serv.c: Server related functions.
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 *
cda8e9b8 24 * $Id: s_serv.c 3550 2007-08-09 06:47:26Z nenolod $
212380e3
AC
25 */
26
27#include "stdinc.h"
28
29#ifdef HAVE_LIBCRYPTO
30#include <openssl/rsa.h>
31#endif
32
212380e3
AC
33#include "s_serv.h"
34#include "class.h"
35#include "client.h"
36#include "common.h"
212380e3 37#include "hash.h"
4562c604 38#include "match.h"
212380e3
AC
39#include "ircd.h"
40#include "ircd_defs.h"
41#include "numeric.h"
42#include "packet.h"
212380e3
AC
43#include "s_conf.h"
44#include "s_newconf.h"
4016731b 45#include "logger.h"
212380e3
AC
46#include "s_stats.h"
47#include "s_user.h"
48#include "scache.h"
49#include "send.h"
50#include "client.h"
212380e3
AC
51#include "channel.h" /* chcap_usage_counts stuff... */
52#include "hook.h"
53#include "msg.h"
54015b5f 54#include "reject.h"
c6d72037 55#include "sslproc.h"
346fba92 56#include "capability.h"
77d3d2db 57#include "s_assert.h"
212380e3 58
212380e3
AC
59#ifndef INADDR_NONE
60#define INADDR_NONE ((unsigned int) 0xffffffff)
61#endif
62
212380e3
AC
63int MaxConnectionCount = 1;
64int MaxClientCount = 1;
65int refresh_user_links = 0;
66
67static char buf[BUFSIZE];
68
212380e3
AC
69/*
70 * list of recognized server capabilities. "TS" is not on the list
71 * because all servers that we talk to already do TS, and the kludged
72 * extra argument to "PASS" takes care of checking that. -orabidoo
73 */
346fba92
AC
74struct CapabilityIndex *serv_capindex = NULL;
75
76unsigned int CAP_CAP;
77unsigned int CAP_QS;
78unsigned int CAP_EX;
79unsigned int CAP_CHW;
80unsigned int CAP_IE;
81unsigned int CAP_KLN;
82unsigned int CAP_ZIP;
83unsigned int CAP_KNOCK;
84unsigned int CAP_TB;
85unsigned int CAP_UNKLN;
86unsigned int CAP_CLUSTER;
87unsigned int CAP_ENCAP;
88unsigned int CAP_TS6;
89unsigned int CAP_SERVICE;
90unsigned int CAP_RSFNC;
91unsigned int CAP_SAVE;
92unsigned int CAP_EUID;
93unsigned int CAP_EOPMOD;
94unsigned int CAP_BAN;
95unsigned int CAP_MLOCK;
96
97/*
98 * initialize our builtin capability table. --nenolod
99 */
100void
101init_builtin_capabs(void)
102{
885cd603 103 serv_capindex = capability_index_create("server capabilities");
346fba92 104
22cae20f
JT
105 /* These two are not set via CAPAB/GCAP keywords. */
106 CAP_CAP = capability_put_anonymous(serv_capindex);
107 CAP_TS6 = capability_put_anonymous(serv_capindex);
108
346fba92
AC
109 CAP_QS = capability_put(serv_capindex, "QS");
110 CAP_EX = capability_put(serv_capindex, "EX");
111 CAP_CHW = capability_put(serv_capindex, "CHW");
112 CAP_IE = capability_put(serv_capindex, "IE");
113 CAP_KLN = capability_put(serv_capindex, "KLN");
114 CAP_KNOCK = capability_put(serv_capindex, "KNOCK");
115 CAP_ZIP = capability_put(serv_capindex, "ZIP");
116 CAP_TB = capability_put(serv_capindex, "TB");
117 CAP_UNKLN = capability_put(serv_capindex, "UNKLN");
118 CAP_CLUSTER = capability_put(serv_capindex, "CLUSTER");
119 CAP_ENCAP = capability_put(serv_capindex, "ENCAP");
120 CAP_SERVICE = capability_put(serv_capindex, "SERVICES");
121 CAP_RSFNC = capability_put(serv_capindex, "RSFNC");
122 CAP_SAVE = capability_put(serv_capindex, "SAVE");
123 CAP_EUID = capability_put(serv_capindex, "EUID");
124 CAP_EOPMOD = capability_put(serv_capindex, "EOPMOD");
125 CAP_BAN = capability_put(serv_capindex, "BAN");
126 CAP_MLOCK = capability_put(serv_capindex, "MLOCK");
58b60c20
JT
127
128 capability_require(serv_capindex, "QS");
d0c2fc82
JT
129 capability_require(serv_capindex, "EX");
130 capability_require(serv_capindex, "IE");
58b60c20 131 capability_require(serv_capindex, "ENCAP");
346fba92 132}
212380e3 133
212380e3 134static CNCB serv_connect_callback;
c6d72037 135static CNCB serv_connect_ssl_callback;
212380e3
AC
136
137/*
138 * hunt_server - Do the basic thing in delivering the message (command)
139 * across the relays to the specific server (server) for
140 * actions.
141 *
142 * Note: The command is a format string and *MUST* be
143 * of prefixed style (e.g. ":%s COMMAND %s ...").
144 * Command can have only max 8 parameters.
145 *
146 * server parv[server] is the parameter identifying the
147 * target server.
148 *
149 * *WARNING*
150 * parv[server] is replaced with the pointer to the
151 * real servername from the matched client (I'm lazy
152 * now --msa).
153 *
154 * returns: (see #defines)
155 */
156int
157hunt_server(struct Client *client_p, struct Client *source_p,
158 const char *command, int server, int parc, const char *parv[])
159{
160 struct Client *target_p;
161 int wilds;
330fc5c1 162 rb_dlink_node *ptr;
212380e3
AC
163 const char *old;
164 char *new;
165
166 /*
167 * Assume it's me, if no server
168 */
169 if(parc <= server || EmptyString(parv[server]) ||
4d7a1ee5 170 match(parv[server], me.name) || (strcmp(parv[server], me.id) == 0))
212380e3 171 return (HUNTED_ISME);
346fba92 172
212380e3
AC
173 new = LOCAL_COPY(parv[server]);
174
175 /*
176 * These are to pickup matches that would cause the following
177 * message to go in the wrong direction while doing quick fast
178 * non-matching lookups.
179 */
180 if(MyClient(source_p))
181 target_p = find_named_client(new);
182 else
183 target_p = find_client(new);
184
185 if(target_p)
186 if(target_p->from == source_p->from && !MyConnect(target_p))
187 target_p = NULL;
188
212380e3
AC
189 collapse(new);
190 wilds = (strchr(new, '?') || strchr(new, '*'));
191
192 /*
193 * Again, if there are no wild cards involved in the server
194 * name, use the hash lookup
195 */
cd300c1b 196 if(!target_p && wilds)
212380e3 197 {
2fb07961 198 RB_DLINK_FOREACH(ptr, global_serv_list.head)
212380e3 199 {
cd300c1b 200 if(match(new, ((struct Client *) (ptr->data))->name))
212380e3 201 {
cd300c1b
JT
202 target_p = ptr->data;
203 break;
212380e3
AC
204 }
205 }
206 }
207
cd300c1b
JT
208 if(target_p && !IsRegistered(target_p))
209 target_p = NULL;
210
212380e3
AC
211 if(target_p)
212 {
212380e3
AC
213 if(IsMe(target_p) || MyClient(target_p))
214 return HUNTED_ISME;
215
216 old = parv[server];
217 parv[server] = get_id(target_p, target_p);
218
219 sendto_one(target_p, command, get_id(source_p, target_p),
220 parv[1], parv[2], parv[3], parv[4], parv[5], parv[6], parv[7], parv[8]);
221 parv[server] = old;
222 return (HUNTED_PASS);
223 }
224
95d36ef5 225 if(MyClient(source_p) || !IsDigit(parv[server][0]))
212380e3
AC
226 sendto_one_numeric(source_p, ERR_NOSUCHSERVER,
227 form_str(ERR_NOSUCHSERVER), parv[server]);
228 return (HUNTED_NOSUCH);
229}
230
231/*
232 * try_connections - scan through configuration and try new connections.
233 * Returns the calendar time when the next call to this
234 * function should be made latest. (No harm done if this
235 * is called earlier or later...)
236 */
237void
238try_connections(void *unused)
239{
240 struct Client *client_p;
241 struct server_conf *server_p = NULL;
242 struct server_conf *tmp_p;
243 struct Class *cltmp;
330fc5c1 244 rb_dlink_node *ptr;
212380e3
AC
245 int connecting = FALSE;
246 int confrq = 0;
247 time_t next = 0;
248
5cefa1d6 249 RB_DLINK_FOREACH(ptr, server_conf_list.head)
212380e3
AC
250 {
251 tmp_p = ptr->data;
252
253 if(ServerConfIllegal(tmp_p) || !ServerConfAutoconn(tmp_p))
254 continue;
255
f4a759c5
VY
256 /* don't allow ssl connections if ssl isn't setup */
257 if(ServerConfSSL(tmp_p) && (!ssl_ok || !get_ssld_count()))
c6d72037
VY
258 continue;
259
212380e3
AC
260 cltmp = tmp_p->class;
261
262 /*
263 * Skip this entry if the use of it is still on hold until
264 * future. Otherwise handle this entry (and set it on hold
265 * until next time). Will reset only hold times, if already
266 * made one successfull connection... [this algorithm is
267 * a bit fuzzy... -- msa >;) ]
268 */
e3354945 269 if(tmp_p->hold > rb_current_time())
212380e3
AC
270 {
271 if(next > tmp_p->hold || next == 0)
272 next = tmp_p->hold;
273 continue;
274 }
275
276 confrq = get_con_freq(cltmp);
e3354945 277 tmp_p->hold = rb_current_time() + confrq;
212380e3
AC
278
279 /*
280 * Found a CONNECT config with port specified, scan clients
281 * and see if this server is already connected?
282 */
283 client_p = find_server(NULL, tmp_p->name);
284
285 if(!client_p && (CurrUsers(cltmp) < MaxUsers(cltmp)) && !connecting)
286 {
287 server_p = tmp_p;
288
289 /* We connect only one at time... */
290 connecting = TRUE;
291 }
292
293 if((next > tmp_p->hold) || (next == 0))
294 next = tmp_p->hold;
295 }
296
297 /* TODO: change this to set active flag to 0 when added to event! --Habeeb */
298 if(GlobalSetOptions.autoconn == 0)
299 return;
300
301 if(!connecting)
302 return;
303
304 /* move this connect entry to end.. */
330fc5c1
AC
305 rb_dlinkDelete(&server_p->node, &server_conf_list);
306 rb_dlinkAddTail(server_p, &server_p->node, &server_conf_list);
212380e3
AC
307
308 /*
309 * We used to only print this if serv_connect() actually
b2f0da88 310 * suceeded, but since rb_tcp_connect() can call the callback
212380e3
AC
311 * immediately if there is an error, we were getting error messages
312 * in the wrong order. SO, we just print out the activated line,
313 * and let serv_connect() / serv_connect_callback() print an
314 * error afterwards if it fails.
315 * -- adrian
316 */
212380e3
AC
317 sendto_realops_snomask(SNO_GENERAL, L_ALL,
318 "Connection to %s activated",
319 server_p->name);
212380e3
AC
320
321 serv_connect(server_p, 0);
322}
323
324int
325check_server(const char *name, struct Client *client_p)
326{
327 struct server_conf *server_p = NULL;
328 struct server_conf *tmp_p;
330fc5c1 329 rb_dlink_node *ptr;
212380e3 330 int error = -1;
e69375f3 331 const char *encr;
212380e3
AC
332
333 s_assert(NULL != client_p);
334 if(client_p == NULL)
335 return error;
336
337 if(!(client_p->localClient->passwd))
338 return -2;
339
340 if(strlen(name) > HOSTLEN)
341 return -4;
342
5cefa1d6 343 RB_DLINK_FOREACH(ptr, server_conf_list.head)
212380e3
AC
344 {
345 tmp_p = ptr->data;
346
347 if(ServerConfIllegal(tmp_p))
348 continue;
349
350 if(!match(tmp_p->name, name))
351 continue;
352
353 error = -3;
354
355 /* XXX: Fix me for IPv6 */
356 /* XXX sockhost is the IPv4 ip as a string */
357 if(match(tmp_p->host, client_p->host) ||
358 match(tmp_p->host, client_p->sockhost))
359 {
360 error = -2;
361
ff0cc1e6 362 if(tmp_p->passwd)
212380e3 363 {
ff0cc1e6 364 if(ServerConfEncrypted(tmp_p))
212380e3 365 {
e69375f3
JT
366 encr = rb_crypt(client_p->localClient->passwd,
367 tmp_p->passwd);
368 if(encr != NULL && !strcmp(tmp_p->passwd, encr))
ff0cc1e6
AC
369 {
370 server_p = tmp_p;
371 break;
372 }
373 else
374 continue;
212380e3 375 }
ff0cc1e6
AC
376 else if(strcmp(tmp_p->passwd, client_p->localClient->passwd))
377 continue;
212380e3 378 }
ff0cc1e6
AC
379
380 if(tmp_p->certfp)
212380e3 381 {
ff0cc1e6
AC
382 if(!client_p->certfp || strcasecmp(tmp_p->certfp, client_p->certfp) != 0)
383 continue;
212380e3 384 }
ff0cc1e6
AC
385
386 server_p = tmp_p;
387 break;
212380e3
AC
388 }
389 }
390
391 if(server_p == NULL)
392 return error;
393
f4a759c5
VY
394 if(ServerConfSSL(server_p) && client_p->localClient->ssl_ctl == NULL)
395 {
396 return -5;
c6d72037
VY
397 }
398
212380e3
AC
399 attach_server_conf(client_p, server_p);
400
401 /* clear ZIP/TB if they support but we dont want them */
402#ifdef HAVE_LIBZ
403 if(!ServerConfCompressed(server_p))
404#endif
405 ClearCap(client_p, CAP_ZIP);
406
407 if(!ServerConfTb(server_p))
408 ClearCap(client_p, CAP_TB);
409
410 return 0;
411}
412
413/*
414 * send_capabilities
415 *
416 * inputs - Client pointer to send to
417 * - int flag of capabilities that this server has
418 * output - NONE
419 * side effects - send the CAPAB line to a server -orabidoo
420 *
421 */
422void
346fba92 423send_capabilities(struct Client *client_p, unsigned int cap_can_send)
212380e3 424{
346fba92 425 sendto_one(client_p, "CAPAB :%s", capability_index_list(serv_capindex, cap_can_send));
212380e3
AC
426}
427
431a1a27
JT
428static void
429burst_ban(struct Client *client_p)
430{
431 rb_dlink_node *ptr;
432 struct ConfItem *aconf;
433 const char *type, *oper;
434 /* +5 for !,@,{,} and null */
435 char operbuf[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5];
436 char *p;
437 size_t melen;
438
439 melen = strlen(me.name);
440 RB_DLINK_FOREACH(ptr, prop_bans.head)
441 {
442 aconf = ptr->data;
443
444 /* Skip expired stuff. */
445 if(aconf->lifetime < rb_current_time())
446 continue;
447 switch(aconf->status & ~CONF_ILLEGAL)
448 {
449 case CONF_KILL: type = "K"; break;
450 case CONF_DLINE: type = "D"; break;
451 case CONF_XLINE: type = "X"; break;
452 case CONF_RESV_NICK: type = "R"; break;
453 case CONF_RESV_CHANNEL: type = "R"; break;
454 default:
455 continue;
456 }
457 oper = aconf->info.oper;
458 if(aconf->flags & CONF_FLAGS_MYOPER)
459 {
460 /* Our operator{} names may not be meaningful
461 * to other servers, so rewrite to our server
462 * name.
463 */
464 rb_strlcpy(operbuf, aconf->info.oper, sizeof buf);
465 p = strrchr(operbuf, '{');
ee6da53d
JT
466 if (p != NULL &&
467 operbuf + sizeof operbuf - p > (ptrdiff_t)(melen + 2))
431a1a27
JT
468 {
469 memcpy(p + 1, me.name, melen);
470 p[melen + 1] = '}';
471 p[melen + 2] = '\0';
472 oper = operbuf;
473 }
474 }
cedb7d05 475 sendto_one(client_p, ":%s BAN %s %s %s %lu %d %d %s :%s%s%s",
431a1a27 476 me.id,
431a1a27
JT
477 type,
478 aconf->user ? aconf->user : "*", aconf->host,
479 (unsigned long)aconf->created,
480 (int)(aconf->hold - aconf->created),
481 (int)(aconf->lifetime - aconf->created),
482 oper,
483 aconf->passwd,
484 aconf->spasswd ? "|" : "",
485 aconf->spasswd ? aconf->spasswd : "");
486 }
487}
488
212380e3
AC
489/* burst_modes_TS6()
490 *
491 * input - client to burst to, channel name, list to burst, mode flag
492 * output -
493 * side effects - client is sent a list of +b, +e, or +I modes
494 */
495static void
55abcbb2 496burst_modes_TS6(struct Client *client_p, struct Channel *chptr,
330fc5c1 497 rb_dlink_list *list, char flag)
212380e3 498{
330fc5c1 499 rb_dlink_node *ptr;
212380e3
AC
500 struct Ban *banptr;
501 char *t;
502 int tlen;
503 int mlen;
504 int cur_len;
505
b2f0da88 506 cur_len = mlen = rb_sprintf(buf, ":%s BMASK %ld %s %c :",
212380e3
AC
507 me.id, (long) chptr->channelts, chptr->chname, flag);
508 t = buf + mlen;
509
5cefa1d6 510 RB_DLINK_FOREACH(ptr, list->head)
212380e3
AC
511 {
512 banptr = ptr->data;
513
7f0fc87d 514 tlen = strlen(banptr->banstr) + (banptr->forward ? strlen(banptr->forward) + 1 : 0) + 1;
212380e3
AC
515
516 /* uh oh */
517 if(cur_len + tlen > BUFSIZE - 3)
518 {
519 /* the one we're trying to send doesnt fit at all! */
520 if(cur_len == mlen)
521 {
522 s_assert(0);
523 continue;
524 }
525
526 /* chop off trailing space and send.. */
527 *(t-1) = '\0';
528 sendto_one(client_p, "%s", buf);
529 cur_len = mlen;
530 t = buf + mlen;
531 }
532
7f0fc87d
JT
533 if (banptr->forward)
534 rb_sprintf(t, "%s$%s ", banptr->banstr, banptr->forward);
535 else
536 rb_sprintf(t, "%s ", banptr->banstr);
212380e3
AC
537 t += tlen;
538 cur_len += tlen;
539 }
540
541 /* cant ever exit the loop above without having modified buf,
542 * chop off trailing space and send.
543 */
544 *(t-1) = '\0';
545 sendto_one(client_p, "%s", buf);
546}
547
212380e3
AC
548/*
549 * burst_TS6
55abcbb2 550 *
212380e3
AC
551 * inputs - client (server) to send nick towards
552 * - client to send nick for
553 * output - NONE
554 * side effects - NICK message is sent towards given client_p
555 */
556static void
557burst_TS6(struct Client *client_p)
558{
9744d53e 559 char ubuf[BUFSIZE];
212380e3
AC
560 struct Client *target_p;
561 struct Channel *chptr;
562 struct membership *msptr;
563 hook_data_client hclientinfo;
564 hook_data_channel hchaninfo;
330fc5c1
AC
565 rb_dlink_node *ptr;
566 rb_dlink_node *uptr;
212380e3
AC
567 char *t;
568 int tlen, mlen;
569 int cur_len = 0;
570
571 hclientinfo.client = hchaninfo.client = client_p;
572
5cefa1d6 573 RB_DLINK_FOREACH(ptr, global_client_list.head)
212380e3
AC
574 {
575 target_p = ptr->data;
576
577 if(!IsPerson(target_p))
578 continue;
579
29c92cf9 580 send_umode(NULL, target_p, 0, ubuf);
212380e3
AC
581 if(!*ubuf)
582 {
583 ubuf[0] = '+';
584 ubuf[1] = '\0';
585 }
586
bea2295f 587 if(IsCapable(client_p, CAP_EUID))
212380e3
AC
588 sendto_one(client_p, ":%s EUID %s %d %ld %s %s %s %s %s %s %s :%s",
589 target_p->servptr->id, target_p->name,
55abcbb2 590 target_p->hopcount + 1,
212380e3
AC
591 (long) target_p->tsinfo, ubuf,
592 target_p->username, target_p->host,
593 IsIPSpoof(target_p) ? "0" : target_p->sockhost,
594 target_p->id,
595 IsDynSpoof(target_p) ? target_p->orighost : "*",
596 EmptyString(target_p->user->suser) ? "*" : target_p->user->suser,
597 target_p->info);
bea2295f 598 else
212380e3
AC
599 sendto_one(client_p, ":%s UID %s %d %ld %s %s %s %s %s :%s",
600 target_p->servptr->id, target_p->name,
55abcbb2 601 target_p->hopcount + 1,
212380e3
AC
602 (long) target_p->tsinfo, ubuf,
603 target_p->username, target_p->host,
604 IsIPSpoof(target_p) ? "0" : target_p->sockhost,
605 target_p->id, target_p->info);
bea2295f 606
8eda114a
JT
607 if(!EmptyString(target_p->certfp))
608 sendto_one(client_p, ":%s ENCAP * CERTFP :%s",
609 use_id(target_p), target_p->certfp);
610
bea2295f 611 if(!IsCapable(client_p, CAP_EUID))
212380e3
AC
612 {
613 if(IsDynSpoof(target_p))
614 sendto_one(client_p, ":%s ENCAP * REALHOST %s",
615 use_id(target_p), target_p->orighost);
616 if(!EmptyString(target_p->user->suser))
617 sendto_one(client_p, ":%s ENCAP * LOGIN %s",
618 use_id(target_p), target_p->user->suser);
619 }
620
c127b45b 621 if(ConfigFileEntry.burst_away && !EmptyString(target_p->user->away))
212380e3
AC
622 sendto_one(client_p, ":%s AWAY :%s",
623 use_id(target_p),
c127b45b 624 target_p->user->away);
212380e3
AC
625
626 hclientinfo.target = target_p;
627 call_hook(h_burst_client, &hclientinfo);
628 }
629
5cefa1d6 630 RB_DLINK_FOREACH(ptr, global_channel_list.head)
212380e3
AC
631 {
632 chptr = ptr->data;
633
634 if(*chptr->chname != '#')
635 continue;
636
b2f0da88 637 cur_len = mlen = rb_sprintf(buf, ":%s SJOIN %ld %s %s :", me.id,
212380e3
AC
638 (long) chptr->channelts, chptr->chname,
639 channel_modes(chptr, client_p));
640
641 t = buf + mlen;
642
5cefa1d6 643 RB_DLINK_FOREACH(uptr, chptr->members.head)
212380e3
AC
644 {
645 msptr = uptr->data;
646
647 tlen = strlen(use_id(msptr->client_p)) + 1;
648 if(is_chanop(msptr))
649 tlen++;
650 if(is_voiced(msptr))
651 tlen++;
652
653 if(cur_len + tlen >= BUFSIZE - 3)
654 {
655 *(t-1) = '\0';
656 sendto_one(client_p, "%s", buf);
657 cur_len = mlen;
658 t = buf + mlen;
659 }
660
55abcbb2 661 rb_sprintf(t, "%s%s ", find_channel_status(msptr, 1),
212380e3
AC
662 use_id(msptr->client_p));
663
664 cur_len += tlen;
665 t += tlen;
666 }
667
330fc5c1 668 if (rb_dlink_list_length(&chptr->members) > 0)
212380e3
AC
669 {
670 /* remove trailing space */
671 *(t-1) = '\0';
672 }
673 sendto_one(client_p, "%s", buf);
674
330fc5c1 675 if(rb_dlink_list_length(&chptr->banlist) > 0)
212380e3
AC
676 burst_modes_TS6(client_p, chptr, &chptr->banlist, 'b');
677
678 if(IsCapable(client_p, CAP_EX) &&
330fc5c1 679 rb_dlink_list_length(&chptr->exceptlist) > 0)
212380e3
AC
680 burst_modes_TS6(client_p, chptr, &chptr->exceptlist, 'e');
681
682 if(IsCapable(client_p, CAP_IE) &&
330fc5c1 683 rb_dlink_list_length(&chptr->invexlist) > 0)
212380e3
AC
684 burst_modes_TS6(client_p, chptr, &chptr->invexlist, 'I');
685
330fc5c1 686 if(rb_dlink_list_length(&chptr->quietlist) > 0)
212380e3
AC
687 burst_modes_TS6(client_p, chptr, &chptr->quietlist, 'q');
688
689 if(IsCapable(client_p, CAP_TB) && chptr->topic != NULL)
690 sendto_one(client_p, ":%s TB %s %ld %s%s:%s",
691 me.id, chptr->chname, (long) chptr->topic_time,
692 ConfigChannel.burst_topicwho ? chptr->topic_info : "",
693 ConfigChannel.burst_topicwho ? " " : "",
694 chptr->topic);
695
084ecbe0 696 if(IsCapable(client_p, CAP_MLOCK))
6b8db2da 697 sendto_one(client_p, ":%s MLOCK %ld %s :%s",
084ecbe0 698 me.id, (long) chptr->channelts, chptr->chname,
6b8db2da 699 EmptyString(chptr->mode_lock) ? "" : chptr->mode_lock);
084ecbe0 700
212380e3
AC
701 hchaninfo.chptr = chptr;
702 call_hook(h_burst_channel, &hchaninfo);
703 }
704
705 hclientinfo.target = NULL;
706 call_hook(h_burst_finished, &hclientinfo);
707}
708
709/*
710 * show_capabilities - show current server capabilities
711 *
712 * inputs - pointer to an struct Client
713 * output - pointer to static string
714 * side effects - build up string representing capabilities of server listed
715 */
716const char *
717show_capabilities(struct Client *target_p)
718{
719 static char msgbuf[BUFSIZE];
346fba92
AC
720
721 *msgbuf = '\0';
212380e3 722
f4a759c5
VY
723 if(has_id(target_p))
724 rb_strlcpy(msgbuf, " TS6", sizeof(msgbuf));
f4a759c5
VY
725
726 if(IsSSL(target_p))
727 rb_strlcat(msgbuf, " SSL", sizeof(msgbuf));
212380e3
AC
728
729 if(!IsServer(target_p) || !target_p->serv->caps) /* short circuit if no caps */
f4a759c5 730 return msgbuf + 1;
212380e3 731
89fd463e 732 rb_strlcat(msgbuf, " ", sizeof(msgbuf));
346fba92 733 rb_strlcat(msgbuf, capability_index_list(serv_capindex, target_p->serv->caps), sizeof(msgbuf));
212380e3 734
f4a759c5 735 return msgbuf + 1;
212380e3
AC
736}
737
738/*
739 * server_estab
740 *
741 * inputs - pointer to a struct Client
742 * output -
743 * side effects -
744 */
745int
746server_estab(struct Client *client_p)
747{
748 struct Client *target_p;
749 struct server_conf *server_p;
750 hook_data_client hdata;
751 char *host;
330fc5c1 752 rb_dlink_node *ptr;
6c528b8e 753 char note[HOSTLEN + 15];
212380e3
AC
754
755 s_assert(NULL != client_p);
756 if(client_p == NULL)
757 return -1;
212380e3
AC
758
759 host = client_p->name;
760
761 if((server_p = client_p->localClient->att_sconf) == NULL)
762 {
763 /* This shouldn't happen, better tell the ops... -A1kmm */
764 sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL,
765 "Warning: Lost connect{} block for server %s!", host);
766 return exit_client(client_p, client_p, client_p, "Lost connect{} block!");
767 }
768
769 /* We shouldn't have to check this, it should already done before
770 * server_estab is called. -A1kmm
771 */
772 if(client_p->localClient->passwd)
773 {
774 memset(client_p->localClient->passwd, 0, strlen(client_p->localClient->passwd));
637c4932 775 rb_free(client_p->localClient->passwd);
212380e3
AC
776 client_p->localClient->passwd = NULL;
777 }
778
779 /* Its got identd , since its a server */
780 SetGotId(client_p);
781
782 /* If there is something in the serv_list, it might be this
783 * connecting server..
784 */
785 if(!ServerInfo.hub && serv_list.head)
786 {
787 if(client_p != serv_list.head->data || serv_list.head->next)
788 {
47adde3d 789 ServerStats.is_ref++;
212380e3
AC
790 sendto_one(client_p, "ERROR :I'm a leaf not a hub");
791 return exit_client(client_p, client_p, client_p, "I'm a leaf");
792 }
793 }
794
795 if(IsUnknown(client_p))
796 {
ff0cc1e6 797 /* the server may be linking based on certificate fingerprint now. --nenolod */
55abcbb2 798 sendto_one(client_p, "PASS %s TS %d :%s",
ff0cc1e6 799 EmptyString(server_p->spasswd) ? "*" : server_p->spasswd, TS_CURRENT, me.id);
212380e3
AC
800
801 /* pass info to new server */
802 send_capabilities(client_p, default_server_capabs
803 | (ServerConfCompressed(server_p) ? CAP_ZIP_SUPPORTED : 0)
804 | (ServerConfTb(server_p) ? CAP_TB : 0));
805
806 sendto_one(client_p, "SERVER %s 1 :%s%s",
807 me.name,
808 ConfigServerHide.hidden ? "(H) " : "",
809 (me.info[0]) ? (me.info) : "IRCers United");
810 }
811
6c528b8e 812 if(!rb_set_buffers(client_p->localClient->F, READBUF_SIZE))
825ddf13 813 ilog_error("rb_set_buffers failed for server");
212380e3 814
c6d72037 815 /* Enable compression now */
f4a759c5
VY
816 if(IsCapable(client_p, CAP_ZIP))
817 {
818 start_zlib_session(client_p);
819 }
8982edb0 820 sendto_one(client_p, "SVINFO %d %d 0 :%ld", TS_CURRENT, TS_MIN, (long int)rb_current_time());
212380e3
AC
821
822 client_p->servptr = &me;
823
824 if(IsAnyDead(client_p))
825 return CLIENT_EXITED;
826
827 SetServer(client_p);
828
330fc5c1 829 rb_dlinkAdd(client_p, &client_p->lnode, &me.serv->servers);
330fc5c1
AC
830 rb_dlinkMoveNode(&client_p->localClient->tnode, &unknown_list, &serv_list);
831 rb_dlinkAddTailAlloc(client_p, &global_serv_list);
212380e3
AC
832
833 if(has_id(client_p))
834 add_to_id_hash(client_p->id, client_p);
835
836 add_to_client_hash(client_p->name, client_p);
837 /* doesnt duplicate client_p->serv if allocated this struct already */
838 make_server(client_p);
212380e3
AC
839
840 client_p->serv->caps = client_p->localClient->caps;
841
842 if(client_p->localClient->fullcaps)
843 {
47a03750 844 client_p->serv->fullcaps = rb_strdup(client_p->localClient->fullcaps);
637c4932 845 rb_free(client_p->localClient->fullcaps);
212380e3
AC
846 client_p->localClient->fullcaps = NULL;
847 }
848
994544c2 849 client_p->serv->nameinfo = scache_connect(client_p->name, client_p->info, IsHidden(client_p));
e3354945 850 client_p->localClient->firsttime = rb_current_time();
212380e3
AC
851 /* fixing eob timings.. -gnp */
852
330fc5c1 853 if((rb_dlink_list_length(&lclient_list) + rb_dlink_list_length(&serv_list)) >
2f15f871 854 (unsigned long)MaxConnectionCount)
55abcbb2 855 MaxConnectionCount = rb_dlink_list_length(&lclient_list) +
330fc5c1 856 rb_dlink_list_length(&serv_list);
2f15f871 857
212380e3
AC
858 /* Show the real host/IP to admins */
859 sendto_realops_snomask(SNO_GENERAL, L_ALL,
860 "Link with %s established: (%s) link",
b3ebc7ab 861 client_p->name,
212380e3
AC
862 show_capabilities(client_p));
863
864 ilog(L_SERVER, "Link with %s established: (%s) link",
865 log_client_name(client_p, SHOW_IP), show_capabilities(client_p));
866
867 hdata.client = &me;
868 hdata.target = client_p;
869 call_hook(h_server_introduced, &hdata);
870
f4a759c5 871 rb_snprintf(note, sizeof(note), "Server: %s", client_p->name);
c6d72037 872 rb_note(client_p->localClient->F, note);
212380e3
AC
873
874 /*
875 ** Old sendto_serv_but_one() call removed because we now
876 ** need to send different names to different servers
877 ** (domain name matching) Send new server to other servers.
878 */
5cefa1d6 879 RB_DLINK_FOREACH(ptr, serv_list.head)
212380e3
AC
880 {
881 target_p = ptr->data;
882
883 if(target_p == client_p)
884 continue;
885
886 if(has_id(target_p) && has_id(client_p))
887 {
888 sendto_one(target_p, ":%s SID %s 2 %s :%s%s",
889 me.id, client_p->name, client_p->id,
890 IsHidden(client_p) ? "(H) " : "", client_p->info);
891
ce4fa447 892 if(!EmptyString(client_p->serv->fullcaps))
212380e3
AC
893 sendto_one(target_p, ":%s ENCAP * GCAP :%s",
894 client_p->id, client_p->serv->fullcaps);
895 }
896 else
897 {
898 sendto_one(target_p, ":%s SERVER %s 2 :%s%s",
899 me.name, client_p->name,
900 IsHidden(client_p) ? "(H) " : "", client_p->info);
901
ce4fa447 902 if(!EmptyString(client_p->serv->fullcaps))
212380e3
AC
903 sendto_one(target_p, ":%s ENCAP * GCAP :%s",
904 client_p->name, client_p->serv->fullcaps);
905 }
906 }
907
908 /*
909 ** Pass on my client information to the new server
910 **
911 ** First, pass only servers (idea is that if the link gets
912 ** cancelled beacause the server was already there,
913 ** there are no NICK's to be cancelled...). Of course,
914 ** if cancellation occurs, all this info is sent anyway,
915 ** and I guess the link dies when a read is attempted...? --msa
55abcbb2 916 **
212380e3
AC
917 ** Note: Link cancellation to occur at this point means
918 ** that at least two servers from my fragment are building
919 ** up connection this other fragment at the same time, it's
920 ** a race condition, not the normal way of operation...
921 **
922 ** ALSO NOTE: using the get_client_name for server names--
923 ** see previous *WARNING*!!! (Also, original inpath
924 ** is destroyed...)
925 */
5cefa1d6 926 RB_DLINK_FOREACH(ptr, global_serv_list.head)
212380e3
AC
927 {
928 target_p = ptr->data;
929
930 /* target_p->from == target_p for target_p == client_p */
931 if(IsMe(target_p) || target_p->from == client_p)
932 continue;
933
934 /* presumption, if target has an id, so does its uplink */
935 if(has_id(client_p) && has_id(target_p))
936 sendto_one(client_p, ":%s SID %s %d %s :%s%s",
66c8fdd2 937 target_p->servptr->id, target_p->name,
212380e3
AC
938 target_p->hopcount + 1, target_p->id,
939 IsHidden(target_p) ? "(H) " : "", target_p->info);
940 else
941 sendto_one(client_p, ":%s SERVER %s %d :%s%s",
66c8fdd2 942 target_p->servptr->name,
212380e3
AC
943 target_p->name, target_p->hopcount + 1,
944 IsHidden(target_p) ? "(H) " : "", target_p->info);
945
ce4fa447 946 if(!EmptyString(target_p->serv->fullcaps))
212380e3
AC
947 sendto_one(client_p, ":%s ENCAP * GCAP :%s",
948 get_id(target_p, client_p),
949 target_p->serv->fullcaps);
950 }
951
431a1a27
JT
952 if(IsCapable(client_p, CAP_BAN))
953 burst_ban(client_p);
954
7bb8c655 955 burst_TS6(client_p);
212380e3
AC
956
957 /* Always send a PING after connect burst is done */
958 sendto_one(client_p, "PING :%s", get_id(&me, client_p));
959
960 free_pre_client(client_p);
961
0bd120ed 962 send_pop_queue(client_p);
212380e3
AC
963
964 return 0;
212380e3
AC
965}
966
967/*
968 * New server connection code
969 * Based upon the stuff floating about in s_bsd.c
970 * -- adrian
971 */
972
973/*
974 * serv_connect() - initiate a server connection
975 *
1d02144f 976 * inputs - pointer to conf
212380e3
AC
977 * - pointer to client doing the connet
978 * output -
979 * side effects -
980 *
981 * This code initiates a connection to a server. It first checks to make
982 * sure the given server exists. If this is the case, it creates a socket,
983 * creates a client, saves the socket information in the client, and
b2f0da88 984 * initiates a connection to the server through rb_connect_tcp(). The
212380e3
AC
985 * completion of this goes through serv_completed_connection().
986 *
987 * We return 1 if the connection is attempted, since we don't know whether
988 * it suceeded or not, and 0 if it fails in here somewhere.
989 */
990int
991serv_connect(struct server_conf *server_p, struct Client *by)
992{
993 struct Client *client_p;
1d02144f 994 struct rb_sockaddr_storage myipnum;
6c528b8e 995 char note[HOSTLEN + 10];
1d02144f 996 rb_fde_t *F;
212380e3
AC
997
998 s_assert(server_p != NULL);
999 if(server_p == NULL)
1000 return 0;
1001
1d02144f
AC
1002 /* log */
1003 rb_inet_ntop_sock((struct sockaddr *)&server_p->my_ipnum, buf, sizeof(buf));
1004 ilog(L_SERVER, "Connect to *[%s] @%s", server_p->name, buf);
1005
212380e3
AC
1006 /*
1007 * Make sure this server isn't already connected
1008 */
1009 if((client_p = find_server(NULL, server_p->name)))
1010 {
1011 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1012 "Server %s already present from %s",
b3ebc7ab 1013 server_p->name, client_p->name);
212380e3
AC
1014 if(by && IsPerson(by) && !MyClient(by))
1015 sendto_one_notice(by, ":Server %s already present from %s",
b3ebc7ab 1016 server_p->name, client_p->name);
212380e3
AC
1017 return 0;
1018 }
1019
1020 /* create a socket for the server connection */
1d02144f 1021 if((F = rb_socket(GET_SS_FAMILY(&server_p->my_ipnum), SOCK_STREAM, 0, NULL)) == NULL)
212380e3 1022 {
825ddf13 1023 ilog_error("opening a stream socket");
212380e3
AC
1024 return 0;
1025 }
1026
1d02144f
AC
1027 /* servernames are always guaranteed under HOSTLEN chars */
1028 rb_snprintf(note, sizeof(note), "Server: %s", server_p->name);
6c528b8e 1029 rb_note(F, note);
212380e3
AC
1030
1031 /* Create a local client */
1032 client_p = make_client(NULL);
1033
1d02144f 1034 /* Copy in the server, hostname, fd */
f427c8b0
VY
1035 rb_strlcpy(client_p->name, server_p->name, sizeof(client_p->name));
1036 rb_strlcpy(client_p->host, server_p->host, sizeof(client_p->host));
1d02144f 1037 rb_strlcpy(client_p->sockhost, buf, sizeof(client_p->sockhost));
6c528b8e 1038 client_p->localClient->F = F;
b5b4a0e7 1039 add_to_cli_connid_hash(client_p);
1d02144f
AC
1040 /* shove the port number into the sockaddr */
1041#ifdef RB_IPV6
1042 if(GET_SS_FAMILY(&server_p->my_ipnum) == AF_INET6)
1043 ((struct sockaddr_in6 *)&server_p->my_ipnum)->sin6_port = htons(server_p->port);
1044 else
1045#endif
1046 ((struct sockaddr_in *)&server_p->my_ipnum)->sin_port = htons(server_p->port);
212380e3
AC
1047
1048 /*
1049 * Set up the initial server evilness, ripped straight from
1050 * connect_server(), so don't blame me for it being evil.
1051 * -- adrian
1052 */
1053
6c528b8e 1054 if(!rb_set_buffers(client_p->localClient->F, READBUF_SIZE))
212380e3 1055 {
825ddf13 1056 ilog_error("setting the buffer size for a server connection");
212380e3
AC
1057 }
1058
1059 /*
1060 * Attach config entries to client here rather than in
1061 * serv_connect_callback(). This to avoid null pointer references.
1062 */
1063 attach_server_conf(client_p, server_p);
1064
1065 /*
1066 * at this point we have a connection in progress and C/N lines
1067 * attached to the client, the socket info should be saved in the
1068 * client and it should either be resolved or have a valid address.
1069 *
1070 * The socket has been connected or connect is in progress.
1071 */
1072 make_server(client_p);
1d02144f
AC
1073 if(by && IsClient(by))
1074 strcpy(client_p->serv->by, by->name);
212380e3 1075 else
1d02144f
AC
1076 strcpy(client_p->serv->by, "AutoConn.");
1077
212380e3 1078 SetConnecting(client_p);
330fc5c1 1079 rb_dlinkAddTail(client_p, &client_p->node, &global_client_list);
212380e3 1080
1d02144f 1081 if(ServerConfVhosted(server_p))
212380e3 1082 {
1d02144f
AC
1083 memcpy(&myipnum, &server_p->my_ipnum, sizeof(myipnum));
1084 ((struct sockaddr_in *)&myipnum)->sin_port = 0;
1085 SET_SS_FAMILY(&myipnum, GET_SS_FAMILY(&server_p->my_ipnum));
abe5dd20 1086
abe5dd20 1087 }
1d02144f 1088 else if(GET_SS_FAMILY(&server_p->my_ipnum) == AF_INET && ServerInfo.specific_ipv4_vhost)
212380e3 1089 {
1d02144f
AC
1090 memcpy(&myipnum, &ServerInfo.ip, sizeof(myipnum));
1091 ((struct sockaddr_in *)&myipnum)->sin_port = 0;
1092 SET_SS_FAMILY(&myipnum, AF_INET);
1093 SET_SS_LEN(&myipnum, sizeof(struct sockaddr_in));
1094 }
17648928 1095
ccda6e3f 1096#ifdef RB_IPV6
1d02144f
AC
1097 else if((GET_SS_FAMILY(&server_p->my_ipnum) == AF_INET6) && ServerInfo.specific_ipv6_vhost)
1098 {
1099 memcpy(&myipnum, &ServerInfo.ip6, sizeof(myipnum));
1100 ((struct sockaddr_in6 *)&myipnum)->sin6_port = 0;
1101 SET_SS_FAMILY(&myipnum, AF_INET6);
1102 SET_SS_LEN(&myipnum, sizeof(struct sockaddr_in6));
1103 }
17648928 1104#endif
1d02144f
AC
1105 else
1106 {
1107 if(ServerConfSSL(server_p))
1108 {
1109 rb_connect_tcp(client_p->localClient->F,
1110 (struct sockaddr *)&server_p->my_ipnum, NULL, 0,
1111 serv_connect_ssl_callback, client_p,
1112 ConfigFileEntry.connect_timeout);
1113 }
1114 else
1115 rb_connect_tcp(client_p->localClient->F,
1116 (struct sockaddr *)&server_p->my_ipnum, NULL, 0,
1117 serv_connect_callback, client_p,
1118 ConfigFileEntry.connect_timeout);
1119
abe5dd20
JT
1120 return 1;
1121 }
1d02144f
AC
1122 if(ServerConfSSL(server_p))
1123 rb_connect_tcp(client_p->localClient->F, (struct sockaddr *)&server_p->my_ipnum,
1124 (struct sockaddr *)&myipnum,
1125 GET_SS_LEN(&myipnum), serv_connect_ssl_callback, client_p,
1126 ConfigFileEntry.connect_timeout);
1127 else
1128 rb_connect_tcp(client_p->localClient->F, (struct sockaddr *)&server_p->my_ipnum,
1129 (struct sockaddr *)&myipnum,
1130 GET_SS_LEN(&myipnum), serv_connect_callback, client_p,
1131 ConfigFileEntry.connect_timeout);
1132
1133 return 1;
212380e3
AC
1134}
1135
f4a759c5
VY
1136static void
1137serv_connect_ssl_callback(rb_fde_t *F, int status, void *data)
1138{
1139 struct Client *client_p = data;
1140 rb_fde_t *xF[2];
9ec51326 1141 rb_connect_sockaddr(F, (struct sockaddr *)&client_p->localClient->ip, sizeof(client_p->localClient->ip));
f4a759c5
VY
1142 if(status != RB_OK)
1143 {
9ec51326
JT
1144 /* Print error message, just like non-SSL. */
1145 serv_connect_callback(F, status, data);
f4a759c5
VY
1146 return;
1147 }
eda22d87
JT
1148 if(rb_socketpair(AF_UNIX, SOCK_STREAM, 0, &xF[0], &xF[1], "Outgoing ssld connection") == -1)
1149 {
1150 ilog_error("rb_socketpair failed for server");
1151 serv_connect_callback(F, RB_ERROR, data);
1152 return;
55abcbb2 1153
eda22d87 1154 }
b5b4a0e7 1155 del_from_cli_connid_hash(client_p);
f4a759c5 1156 client_p->localClient->F = xF[0];
b5b4a0e7 1157 add_to_cli_connid_hash(client_p);
f4a759c5
VY
1158
1159 client_p->localClient->ssl_ctl = start_ssld_connect(F, xF[1], rb_get_fd(xF[0]));
1160 SetSSL(client_p);
39452169 1161 serv_connect_callback(client_p->localClient->F, RB_OK, client_p);
c6d72037
VY
1162}
1163
212380e3
AC
1164/*
1165 * serv_connect_callback() - complete a server connection.
55abcbb2 1166 *
212380e3
AC
1167 * This routine is called after the server connection attempt has
1168 * completed. If unsucessful, an error is sent to ops and the client
1169 * is closed. If sucessful, it goes through the initialisation/check
1170 * procedures, the capabilities are sent, and the socket is then
1171 * marked for reading.
1172 */
1173static void
6c528b8e 1174serv_connect_callback(rb_fde_t *F, int status, void *data)
212380e3
AC
1175{
1176 struct Client *client_p = data;
1177 struct server_conf *server_p;
1178 char *errstr;
1179
1180 /* First, make sure its a real client! */
1181 s_assert(client_p != NULL);
6c528b8e 1182 s_assert(client_p->localClient->F == F);
212380e3
AC
1183
1184 if(client_p == NULL)
1185 return;
1186
1187 /* while we were waiting for the callback, its possible this already
1188 * linked in.. --fl
1189 */
1190 if(find_server(NULL, client_p->name) != NULL)
1191 {
1192 exit_client(client_p, client_p, &me, "Server Exists");
1193 return;
1194 }
1195
f4a759c5 1196 if(client_p->localClient->ssl_ctl == NULL)
c6d72037
VY
1197 rb_connect_sockaddr(F, (struct sockaddr *)&client_p->localClient->ip, sizeof(client_p->localClient->ip));
1198
212380e3 1199 /* Check the status */
6c528b8e 1200 if(status != RB_OK)
212380e3
AC
1201 {
1202 /* COMM_ERR_TIMEOUT wont have an errno associated with it,
1203 * the others will.. --fl
1204 */
6c528b8e 1205 if(status == RB_ERR_TIMEOUT)
212380e3
AC
1206 {
1207 sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL,
1208 "Error connecting to %s[%s]: %s",
55abcbb2 1209 client_p->name,
212380e3 1210 "255.255.255.255",
b2f0da88 1211 rb_errstr(status));
212380e3
AC
1212 ilog(L_SERVER, "Error connecting to %s[%s]: %s",
1213 client_p->name, client_p->sockhost,
b2f0da88 1214 rb_errstr(status));
212380e3
AC
1215 }
1216 else
1217 {
6c528b8e 1218 errstr = strerror(rb_get_sockerr(F));
212380e3
AC
1219 sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL,
1220 "Error connecting to %s[%s]: %s (%s)",
1221 client_p->name,
212380e3 1222 "255.255.255.255",
b2f0da88 1223 rb_errstr(status), errstr);
212380e3
AC
1224 ilog(L_SERVER, "Error connecting to %s[%s]: %s (%s)",
1225 client_p->name, client_p->sockhost,
b2f0da88 1226 rb_errstr(status), errstr);
212380e3
AC
1227 }
1228
b2f0da88 1229 exit_client(client_p, client_p, &me, rb_errstr(status));
212380e3
AC
1230 return;
1231 }
1232
1233 /* COMM_OK, so continue the connection procedure */
1234 /* Get the C/N lines */
1235 if((server_p = client_p->localClient->att_sconf) == NULL)
1236 {
1237 sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, "Lost connect{} block for %s",
b3ebc7ab 1238 client_p->name);
212380e3
AC
1239 exit_client(client_p, client_p, &me, "Lost connect{} block");
1240 return;
1241 }
1242
1243 /* Next, send the initial handshake */
1244 SetHandshake(client_p);
1245
ff0cc1e6 1246 /* the server may be linking based on certificate fingerprint now. --nenolod */
55abcbb2 1247 sendto_one(client_p, "PASS %s TS %d :%s",
ff0cc1e6 1248 EmptyString(server_p->spasswd) ? "*" : server_p->spasswd, TS_CURRENT, me.id);
212380e3
AC
1249
1250 /* pass my info to the new server */
1251 send_capabilities(client_p, default_server_capabs
1252 | (ServerConfCompressed(server_p) ? CAP_ZIP_SUPPORTED : 0)
1253 | (ServerConfTb(server_p) ? CAP_TB : 0));
1254
1255 sendto_one(client_p, "SERVER %s 1 :%s%s",
1256 me.name,
1257 ConfigServerHide.hidden ? "(H) " : "", me.info);
1258
55abcbb2 1259 /*
212380e3
AC
1260 * If we've been marked dead because a send failed, just exit
1261 * here now and save everyone the trouble of us ever existing.
1262 */
1263 if(IsAnyDead(client_p))
1264 {
1265 sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL,
1266 "%s went dead during handshake", client_p->name);
1267 exit_client(client_p, client_p, &me, "Went dead during handshake");
1268 return;
1269 }
1270
1271 /* don't move to serv_list yet -- we haven't sent a burst! */
1272
1273 /* If we get here, we're ok, so lets start reading some data */
6c528b8e 1274 read_packet(F, client_p);
212380e3 1275}