2 * ircd-ratbox: A slightly useful ircd.
3 * s_serv.c: Server related functions.
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
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.
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.
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
24 * $Id: s_serv.c 3550 2007-08-09 06:47:26Z nenolod $
30 #include <openssl/rsa.h>
38 #include "irc_string.h"
39 #include "sprintf_irc.h"
41 #include "ircd_defs.h"
46 #include "s_newconf.h"
53 #include "channel.h" /* chcap_usage_counts stuff... */
61 #define INADDR_NONE ((unsigned int) 0xffffffff)
64 #ifndef HAVE_SOCKETPAIR
65 static int inet_socketpair(int d
, int type
, int protocol
, int sv
[2]);
68 int MaxConnectionCount
= 1;
69 int MaxClientCount
= 1;
70 int refresh_user_links
= 0;
72 static char buf
[BUFSIZE
];
74 static void start_io(struct Client
*server
);
76 static SlinkRplHnd slink_error
;
77 static SlinkRplHnd slink_zipstats
;
79 * list of recognized server capabilities. "TS" is not on the list
80 * because all servers that we talk to already do TS, and the kludged
81 * extra argument to "PASS" takes care of checking that. -orabidoo
83 struct Capability captab
[] = {
91 { "KNOCK", CAP_KNOCK
},
94 { "UNKLN", CAP_UNKLN
},
95 { "CLUSTER", CAP_CLUSTER
},
96 { "ENCAP", CAP_ENCAP
},
97 { "SERVICES", CAP_SERVICE
},
98 { "RSFNC", CAP_RSFNC
},
100 { "EUID", CAP_EUID
},
104 struct SlinkRplDef slinkrpltab
[] = {
105 {SLINKRPL_ERROR
, slink_error
, SLINKRPL_FLAG_DATA
},
106 {SLINKRPL_ZIPSTATS
, slink_zipstats
, SLINKRPL_FLAG_DATA
},
110 static int fork_server(struct Client
*client_p
);
112 static CNCB serv_connect_callback
;
115 slink_error(unsigned int rpl
, unsigned int len
, unsigned char *data
, struct Client
*server_p
)
117 char squitreason
[256];
119 s_assert(rpl
== SLINKRPL_ERROR
);
122 data
[len
- 1] = '\0';
124 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "SlinkError for %s: %s", server_p
->name
, data
);
125 snprintf(squitreason
, sizeof squitreason
, "servlink error: %s", data
);
126 exit_client(server_p
, server_p
, &me
, squitreason
);
130 slink_zipstats(unsigned int rpl
, unsigned int len
, unsigned char *data
, struct Client
*server_p
)
132 struct ZipStats zipstats
;
133 u_int32_t in
= 0, in_wire
= 0, out
= 0, out_wire
= 0;
136 s_assert(rpl
== SLINKRPL_ZIPSTATS
);
138 s_assert(IsCapable(server_p
, CAP_ZIP
));
140 /* Yes, it needs to be done this way, no we cannot let the compiler
141 * work with the pointer to the structure. This works around a GCC
142 * bug on SPARC that affects all versions at the time of this writing.
143 * I will feed you to the creatures living in RMS's beard if you do
144 * not leave this as is, without being sure that you are not causing
145 * regression for most of our installed SPARC base.
146 * -jmallett, 04/27/2002
148 memcpy(&zipstats
, &server_p
->localClient
->zipstats
, sizeof(struct ZipStats
));
150 in
|= (data
[i
++] << 24);
151 in
|= (data
[i
++] << 16);
152 in
|= (data
[i
++] << 8);
155 in_wire
|= (data
[i
++] << 24);
156 in_wire
|= (data
[i
++] << 16);
157 in_wire
|= (data
[i
++] << 8);
158 in_wire
|= (data
[i
++]);
160 out
|= (data
[i
++] << 24);
161 out
|= (data
[i
++] << 16);
162 out
|= (data
[i
++] << 8);
165 out_wire
|= (data
[i
++] << 24);
166 out_wire
|= (data
[i
++] << 16);
167 out_wire
|= (data
[i
++] << 8);
168 out_wire
|= (data
[i
++]);
171 zipstats
.inK
+= zipstats
.in
>> 10;
172 zipstats
.in
&= 0x03ff;
174 zipstats
.in_wire
+= in_wire
;
175 zipstats
.inK_wire
+= zipstats
.in_wire
>> 10;
176 zipstats
.in_wire
&= 0x03ff;
179 zipstats
.outK
+= zipstats
.out
>> 10;
180 zipstats
.out
&= 0x03ff;
182 zipstats
.out_wire
+= out_wire
;
183 zipstats
.outK_wire
+= zipstats
.out_wire
>> 10;
184 zipstats
.out_wire
&= 0x03ff;
188 (((double) (zipstats
.inK
- zipstats
.inK_wire
) /
189 (double) zipstats
.inK
) * 100.00);
191 zipstats
.in_ratio
= 0;
193 if(zipstats
.outK
> 0)
195 (((double) (zipstats
.outK
- zipstats
.outK_wire
) /
196 (double) zipstats
.outK
) * 100.00);
198 zipstats
.out_ratio
= 0;
200 memcpy(&server_p
->localClient
->zipstats
, &zipstats
, sizeof(struct ZipStats
));
204 collect_zipstats(void *unused
)
207 struct Client
*target_p
;
209 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
211 target_p
= ptr
->data
;
212 if(IsCapable(target_p
, CAP_ZIP
))
214 /* only bother if we haven't already got something queued... */
215 if(!target_p
->localClient
->slinkq
)
217 target_p
->localClient
->slinkq
= rb_malloc(1); /* sigh.. */
218 target_p
->localClient
->slinkq
[0] = SLINKCMD_ZIPSTATS
;
219 target_p
->localClient
->slinkq_ofs
= 0;
220 target_p
->localClient
->slinkq_len
= 1;
221 // send_queued_slink_write(target_p->localClient->ctrlfd, target_p);
228 * hunt_server - Do the basic thing in delivering the message (command)
229 * across the relays to the specific server (server) for
232 * Note: The command is a format string and *MUST* be
233 * of prefixed style (e.g. ":%s COMMAND %s ...").
234 * Command can have only max 8 parameters.
236 * server parv[server] is the parameter identifying the
240 * parv[server] is replaced with the pointer to the
241 * real servername from the matched client (I'm lazy
244 * returns: (see #defines)
247 hunt_server(struct Client
*client_p
, struct Client
*source_p
,
248 const char *command
, int server
, int parc
, const char *parv
[])
250 struct Client
*target_p
;
257 * Assume it's me, if no server
259 if(parc
<= server
|| EmptyString(parv
[server
]) ||
260 match(parv
[server
], me
.name
) || (strcmp(parv
[server
], me
.id
) == 0))
261 return (HUNTED_ISME
);
263 new = LOCAL_COPY(parv
[server
]);
266 * These are to pickup matches that would cause the following
267 * message to go in the wrong direction while doing quick fast
268 * non-matching lookups.
270 if(MyClient(source_p
))
271 target_p
= find_named_client(new);
273 target_p
= find_client(new);
276 if(target_p
->from
== source_p
->from
&& !MyConnect(target_p
))
280 wilds
= (strchr(new, '?') || strchr(new, '*'));
283 * Again, if there are no wild cards involved in the server
284 * name, use the hash lookup
290 if(MyClient(source_p
) || !IsDigit(parv
[server
][0]))
291 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
292 form_str(ERR_NOSUCHSERVER
),
294 return (HUNTED_NOSUCH
);
300 RB_DLINK_FOREACH(ptr
, global_client_list
.head
)
302 if(match(new, ((struct Client
*) (ptr
->data
))->name
))
304 target_p
= ptr
->data
;
313 if(!IsRegistered(target_p
))
315 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
316 form_str(ERR_NOSUCHSERVER
),
318 return HUNTED_NOSUCH
;
321 if(IsMe(target_p
) || MyClient(target_p
))
325 parv
[server
] = get_id(target_p
, target_p
);
327 sendto_one(target_p
, command
, get_id(source_p
, target_p
),
328 parv
[1], parv
[2], parv
[3], parv
[4], parv
[5], parv
[6], parv
[7], parv
[8]);
330 return (HUNTED_PASS
);
333 if(MyClient(source_p
) || !IsDigit(parv
[server
][0]))
334 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
335 form_str(ERR_NOSUCHSERVER
), parv
[server
]);
336 return (HUNTED_NOSUCH
);
340 * try_connections - scan through configuration and try new connections.
341 * Returns the calendar time when the next call to this
342 * function should be made latest. (No harm done if this
343 * is called earlier or later...)
346 try_connections(void *unused
)
348 struct Client
*client_p
;
349 struct server_conf
*server_p
= NULL
;
350 struct server_conf
*tmp_p
;
353 int connecting
= FALSE
;
357 RB_DLINK_FOREACH(ptr
, server_conf_list
.head
)
361 if(ServerConfIllegal(tmp_p
) || !ServerConfAutoconn(tmp_p
))
364 cltmp
= tmp_p
->class;
367 * Skip this entry if the use of it is still on hold until
368 * future. Otherwise handle this entry (and set it on hold
369 * until next time). Will reset only hold times, if already
370 * made one successfull connection... [this algorithm is
371 * a bit fuzzy... -- msa >;) ]
373 if(tmp_p
->hold
> rb_current_time())
375 if(next
> tmp_p
->hold
|| next
== 0)
380 confrq
= get_con_freq(cltmp
);
381 tmp_p
->hold
= rb_current_time() + confrq
;
384 * Found a CONNECT config with port specified, scan clients
385 * and see if this server is already connected?
387 client_p
= find_server(NULL
, tmp_p
->name
);
389 if(!client_p
&& (CurrUsers(cltmp
) < MaxUsers(cltmp
)) && !connecting
)
393 /* We connect only one at time... */
397 if((next
> tmp_p
->hold
) || (next
== 0))
401 /* TODO: change this to set active flag to 0 when added to event! --Habeeb */
402 if(GlobalSetOptions
.autoconn
== 0)
408 /* move this connect entry to end.. */
409 rb_dlinkDelete(&server_p
->node
, &server_conf_list
);
410 rb_dlinkAddTail(server_p
, &server_p
->node
, &server_conf_list
);
413 * We used to only print this if serv_connect() actually
414 * suceeded, but since rb_tcp_connect() can call the callback
415 * immediately if there is an error, we were getting error messages
416 * in the wrong order. SO, we just print out the activated line,
417 * and let serv_connect() / serv_connect_callback() print an
418 * error afterwards if it fails.
421 #ifndef HIDE_SERVERS_IPS
422 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
423 "Connection to %s[%s] activated.",
424 server_p
->name
, server_p
->host
);
426 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
427 "Connection to %s activated",
431 serv_connect(server_p
, 0);
435 check_server(const char *name
, struct Client
*client_p
)
437 struct server_conf
*server_p
= NULL
;
438 struct server_conf
*tmp_p
;
442 s_assert(NULL
!= client_p
);
446 if(!(client_p
->localClient
->passwd
))
449 if(strlen(name
) > HOSTLEN
)
452 RB_DLINK_FOREACH(ptr
, server_conf_list
.head
)
456 if(ServerConfIllegal(tmp_p
))
459 if(!match(tmp_p
->name
, name
))
464 /* XXX: Fix me for IPv6 */
465 /* XXX sockhost is the IPv4 ip as a string */
466 if(match(tmp_p
->host
, client_p
->host
) ||
467 match(tmp_p
->host
, client_p
->sockhost
))
471 if(ServerConfEncrypted(tmp_p
))
473 if(!strcmp(tmp_p
->passwd
, crypt(client_p
->localClient
->passwd
,
480 else if(!strcmp(tmp_p
->passwd
, client_p
->localClient
->passwd
))
491 attach_server_conf(client_p
, server_p
);
493 /* clear ZIP/TB if they support but we dont want them */
495 if(!ServerConfCompressed(server_p
))
497 ClearCap(client_p
, CAP_ZIP
);
499 if(!ServerConfTb(server_p
))
500 ClearCap(client_p
, CAP_TB
);
508 * inputs - Client pointer to send to
509 * - int flag of capabilities that this server has
511 * side effects - send the CAPAB line to a server -orabidoo
515 send_capabilities(struct Client
*client_p
, int cap_can_send
)
517 struct Capability
*cap
;
518 char msgbuf
[BUFSIZE
];
524 for (cap
= captab
; cap
->name
; ++cap
)
526 if(cap
->cap
& cap_can_send
)
528 tl
= rb_sprintf(t
, "%s ", cap
->name
);
536 sendto_one(client_p
, "CAPAB :%s", msgbuf
);
541 * input - client to burst to, channel name, list to burst, mode flag
543 * side effects - client is sent a list of +b, or +e, or +I modes
546 burst_modes_TS5(struct Client
*client_p
, char *chname
, rb_dlink_list
*list
, char flag
)
550 char mbuf
[MODEBUFLEN
];
559 mlen
= rb_sprintf(buf
, ":%s MODE %s +", me
.name
, chname
);
565 RB_DLINK_FOREACH(ptr
, list
->head
)
568 tlen
= strlen(banptr
->banstr
) + 3;
571 if(tlen
> MODEBUFLEN
)
574 if((count
>= MAXMODEPARAMS
) || ((cur_len
+ tlen
+ 2) > (BUFSIZE
- 3)))
576 sendto_one(client_p
, "%s%s %s", buf
, mbuf
, pbuf
);
586 pp
+= rb_sprintf(pp
, "%s ", banptr
->banstr
);
592 sendto_one(client_p
, "%s%s %s", buf
, mbuf
, pbuf
);
597 * input - client to burst to, channel name, list to burst, mode flag
599 * side effects - client is sent a list of +b, +e, or +I modes
602 burst_modes_TS6(struct Client
*client_p
, struct Channel
*chptr
,
603 rb_dlink_list
*list
, char flag
)
612 cur_len
= mlen
= rb_sprintf(buf
, ":%s BMASK %ld %s %c :",
613 me
.id
, (long) chptr
->channelts
, chptr
->chname
, flag
);
616 RB_DLINK_FOREACH(ptr
, list
->head
)
620 tlen
= strlen(banptr
->banstr
) + 1;
623 if(cur_len
+ tlen
> BUFSIZE
- 3)
625 /* the one we're trying to send doesnt fit at all! */
632 /* chop off trailing space and send.. */
634 sendto_one(client_p
, "%s", buf
);
639 rb_sprintf(t
, "%s ", banptr
->banstr
);
644 /* cant ever exit the loop above without having modified buf,
645 * chop off trailing space and send.
648 sendto_one(client_p
, "%s", buf
);
654 * inputs - client (server) to send nick towards
655 * - client to send nick for
657 * side effects - NICK message is sent towards given client_p
660 burst_TS5(struct Client
*client_p
)
662 static char ubuf
[12];
663 struct Client
*target_p
;
664 struct Channel
*chptr
;
665 struct membership
*msptr
;
666 hook_data_client hclientinfo
;
667 hook_data_channel hchaninfo
;
674 hclientinfo
.client
= hchaninfo
.client
= client_p
;
676 RB_DLINK_FOREACH(ptr
, global_client_list
.head
)
678 target_p
= ptr
->data
;
680 if(!IsPerson(target_p
))
683 send_umode(NULL
, target_p
, 0, 0, ubuf
);
690 sendto_one(client_p
, "NICK %s %d %ld %s %s %s %s :%s",
691 target_p
->name
, target_p
->hopcount
+ 1,
692 (long) target_p
->tsinfo
, ubuf
,
693 target_p
->username
, target_p
->host
,
694 target_p
->servptr
->name
, target_p
->info
);
696 if(IsDynSpoof(target_p
))
697 sendto_one(client_p
, ":%s ENCAP * REALHOST %s",
698 target_p
->name
, target_p
->orighost
);
699 if(!EmptyString(target_p
->user
->suser
))
700 sendto_one(client_p
, ":%s ENCAP * LOGIN %s",
701 target_p
->name
, target_p
->user
->suser
);
703 if(ConfigFileEntry
.burst_away
&& !EmptyString(target_p
->user
->away
))
704 sendto_one(client_p
, ":%s AWAY :%s",
705 target_p
->name
, target_p
->user
->away
);
707 hclientinfo
.target
= target_p
;
708 call_hook(h_burst_client
, &hclientinfo
);
711 RB_DLINK_FOREACH(ptr
, global_channel_list
.head
)
715 if(*chptr
->chname
!= '#')
718 cur_len
= mlen
= rb_sprintf(buf
, ":%s SJOIN %ld %s %s :", me
.name
,
719 (long) chptr
->channelts
, chptr
->chname
,
720 channel_modes(chptr
, client_p
));
724 RB_DLINK_FOREACH(uptr
, chptr
->members
.head
)
728 tlen
= strlen(msptr
->client_p
->name
) + 1;
734 if(cur_len
+ tlen
>= BUFSIZE
- 3)
738 sendto_one(client_p
, "%s", buf
);
743 rb_sprintf(t
, "%s%s ", find_channel_status(msptr
, 1),
744 msptr
->client_p
->name
);
750 if (rb_dlink_list_length(&chptr
->members
) > 0)
752 /* remove trailing space */
756 sendto_one(client_p
, "%s", buf
);
758 burst_modes_TS5(client_p
, chptr
->chname
, &chptr
->banlist
, 'b');
760 if(IsCapable(client_p
, CAP_EX
))
761 burst_modes_TS5(client_p
, chptr
->chname
, &chptr
->exceptlist
, 'e');
763 if(IsCapable(client_p
, CAP_IE
))
764 burst_modes_TS5(client_p
, chptr
->chname
, &chptr
->invexlist
, 'I');
766 burst_modes_TS5(client_p
, chptr
->chname
, &chptr
->quietlist
, 'q');
768 if(IsCapable(client_p
, CAP_TB
) && chptr
->topic
!= NULL
)
769 sendto_one(client_p
, ":%s TB %s %ld %s%s:%s",
770 me
.name
, chptr
->chname
, (long) chptr
->topic_time
,
771 ConfigChannel
.burst_topicwho
? chptr
->topic_info
: "",
772 ConfigChannel
.burst_topicwho
? " " : "",
775 hchaninfo
.chptr
= chptr
;
776 call_hook(h_burst_channel
, &hchaninfo
);
779 hclientinfo
.target
= NULL
;
780 call_hook(h_burst_finished
, &hclientinfo
);
786 * inputs - client (server) to send nick towards
787 * - client to send nick for
789 * side effects - NICK message is sent towards given client_p
792 burst_TS6(struct Client
*client_p
)
794 static char ubuf
[12];
795 struct Client
*target_p
;
796 struct Channel
*chptr
;
797 struct membership
*msptr
;
798 hook_data_client hclientinfo
;
799 hook_data_channel hchaninfo
;
806 hclientinfo
.client
= hchaninfo
.client
= client_p
;
808 RB_DLINK_FOREACH(ptr
, global_client_list
.head
)
810 target_p
= ptr
->data
;
812 if(!IsPerson(target_p
))
815 send_umode(NULL
, target_p
, 0, 0, ubuf
);
822 if(has_id(target_p
) && IsCapable(client_p
, CAP_EUID
))
823 sendto_one(client_p
, ":%s EUID %s %d %ld %s %s %s %s %s %s %s :%s",
824 target_p
->servptr
->id
, target_p
->name
,
825 target_p
->hopcount
+ 1,
826 (long) target_p
->tsinfo
, ubuf
,
827 target_p
->username
, target_p
->host
,
828 IsIPSpoof(target_p
) ? "0" : target_p
->sockhost
,
830 IsDynSpoof(target_p
) ? target_p
->orighost
: "*",
831 EmptyString(target_p
->user
->suser
) ? "*" : target_p
->user
->suser
,
833 else if(has_id(target_p
))
834 sendto_one(client_p
, ":%s UID %s %d %ld %s %s %s %s %s :%s",
835 target_p
->servptr
->id
, target_p
->name
,
836 target_p
->hopcount
+ 1,
837 (long) target_p
->tsinfo
, ubuf
,
838 target_p
->username
, target_p
->host
,
839 IsIPSpoof(target_p
) ? "0" : target_p
->sockhost
,
840 target_p
->id
, target_p
->info
);
842 sendto_one(client_p
, "NICK %s %d %ld %s %s %s %s :%s",
844 target_p
->hopcount
+ 1,
845 (long) target_p
->tsinfo
,
847 target_p
->username
, target_p
->host
,
848 target_p
->servptr
->name
, target_p
->info
);
850 if(!has_id(target_p
) || !IsCapable(client_p
, CAP_EUID
))
852 if(IsDynSpoof(target_p
))
853 sendto_one(client_p
, ":%s ENCAP * REALHOST %s",
854 use_id(target_p
), target_p
->orighost
);
855 if(!EmptyString(target_p
->user
->suser
))
856 sendto_one(client_p
, ":%s ENCAP * LOGIN %s",
857 use_id(target_p
), target_p
->user
->suser
);
860 if(ConfigFileEntry
.burst_away
&& !EmptyString(target_p
->user
->away
))
861 sendto_one(client_p
, ":%s AWAY :%s",
863 target_p
->user
->away
);
865 hclientinfo
.target
= target_p
;
866 call_hook(h_burst_client
, &hclientinfo
);
869 RB_DLINK_FOREACH(ptr
, global_channel_list
.head
)
873 if(*chptr
->chname
!= '#')
876 cur_len
= mlen
= rb_sprintf(buf
, ":%s SJOIN %ld %s %s :", me
.id
,
877 (long) chptr
->channelts
, chptr
->chname
,
878 channel_modes(chptr
, client_p
));
882 RB_DLINK_FOREACH(uptr
, chptr
->members
.head
)
886 tlen
= strlen(use_id(msptr
->client_p
)) + 1;
892 if(cur_len
+ tlen
>= BUFSIZE
- 3)
895 sendto_one(client_p
, "%s", buf
);
900 rb_sprintf(t
, "%s%s ", find_channel_status(msptr
, 1),
901 use_id(msptr
->client_p
));
907 if (rb_dlink_list_length(&chptr
->members
) > 0)
909 /* remove trailing space */
912 sendto_one(client_p
, "%s", buf
);
914 if(rb_dlink_list_length(&chptr
->banlist
) > 0)
915 burst_modes_TS6(client_p
, chptr
, &chptr
->banlist
, 'b');
917 if(IsCapable(client_p
, CAP_EX
) &&
918 rb_dlink_list_length(&chptr
->exceptlist
) > 0)
919 burst_modes_TS6(client_p
, chptr
, &chptr
->exceptlist
, 'e');
921 if(IsCapable(client_p
, CAP_IE
) &&
922 rb_dlink_list_length(&chptr
->invexlist
) > 0)
923 burst_modes_TS6(client_p
, chptr
, &chptr
->invexlist
, 'I');
925 if(rb_dlink_list_length(&chptr
->quietlist
) > 0)
926 burst_modes_TS6(client_p
, chptr
, &chptr
->quietlist
, 'q');
928 if(IsCapable(client_p
, CAP_TB
) && chptr
->topic
!= NULL
)
929 sendto_one(client_p
, ":%s TB %s %ld %s%s:%s",
930 me
.id
, chptr
->chname
, (long) chptr
->topic_time
,
931 ConfigChannel
.burst_topicwho
? chptr
->topic_info
: "",
932 ConfigChannel
.burst_topicwho
? " " : "",
935 hchaninfo
.chptr
= chptr
;
936 call_hook(h_burst_channel
, &hchaninfo
);
939 hclientinfo
.target
= NULL
;
940 call_hook(h_burst_finished
, &hclientinfo
);
944 * show_capabilities - show current server capabilities
946 * inputs - pointer to an struct Client
947 * output - pointer to static string
948 * side effects - build up string representing capabilities of server listed
951 show_capabilities(struct Client
*target_p
)
953 static char msgbuf
[BUFSIZE
];
954 struct Capability
*cap
;
959 tl
= rb_sprintf(msgbuf
, "TS ");
962 if(!IsServer(target_p
) || !target_p
->serv
->caps
) /* short circuit if no caps */
968 for (cap
= captab
; cap
->cap
; ++cap
)
970 if(cap
->cap
& target_p
->serv
->caps
)
972 tl
= rb_sprintf(t
, "%s ", cap
->name
);
986 * inputs - pointer to a struct Client
991 server_estab(struct Client
*client_p
)
993 struct Client
*target_p
;
994 struct server_conf
*server_p
;
995 hook_data_client hdata
;
998 char note
[HOSTLEN
+ 15];
1000 s_assert(NULL
!= client_p
);
1001 if(client_p
== NULL
)
1004 host
= client_p
->name
;
1006 if((server_p
= client_p
->localClient
->att_sconf
) == NULL
)
1008 /* This shouldn't happen, better tell the ops... -A1kmm */
1009 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) ? L_NETWIDE
: L_ALL
,
1010 "Warning: Lost connect{} block for server %s!", host
);
1011 return exit_client(client_p
, client_p
, client_p
, "Lost connect{} block!");
1014 /* We shouldn't have to check this, it should already done before
1015 * server_estab is called. -A1kmm
1017 if(client_p
->localClient
->passwd
)
1019 memset(client_p
->localClient
->passwd
, 0, strlen(client_p
->localClient
->passwd
));
1020 rb_free(client_p
->localClient
->passwd
);
1021 client_p
->localClient
->passwd
= NULL
;
1024 /* Its got identd , since its a server */
1027 /* If there is something in the serv_list, it might be this
1028 * connecting server..
1030 if(!ServerInfo
.hub
&& serv_list
.head
)
1032 if(client_p
!= serv_list
.head
->data
|| serv_list
.head
->next
)
1034 ServerStats
->is_ref
++;
1035 sendto_one(client_p
, "ERROR :I'm a leaf not a hub");
1036 return exit_client(client_p
, client_p
, client_p
, "I'm a leaf");
1040 if(IsUnknown(client_p
))
1043 * jdc -- 1. Use EmptyString(), not [0] index reference.
1044 * 2. Check ->spasswd, not ->passwd.
1046 if(!EmptyString(server_p
->spasswd
))
1048 sendto_one(client_p
, "PASS %s TS %d :%s",
1049 server_p
->spasswd
, TS_CURRENT
, me
.id
);
1052 /* pass info to new server */
1053 send_capabilities(client_p
, default_server_capabs
1054 | (ServerConfCompressed(server_p
) ? CAP_ZIP_SUPPORTED
: 0)
1055 | (ServerConfTb(server_p
) ? CAP_TB
: 0));
1057 sendto_one(client_p
, "SERVER %s 1 :%s%s",
1059 ConfigServerHide
.hidden
? "(H) " : "",
1060 (me
.info
[0]) ? (me
.info
) : "IRCers United");
1063 if(!rb_set_buffers(client_p
->localClient
->F
, READBUF_SIZE
))
1064 ilog_error("rb_set_buffers failed for server");
1066 /* Hand the server off to servlink now */
1067 if(IsCapable(client_p
, CAP_ZIP
))
1069 if(fork_server(client_p
) < 0)
1071 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) ? L_NETWIDE
: L_ALL
,
1072 "Warning: fork failed for server %s -- check servlink_path (%s)",
1073 get_server_name(client_p
, HIDE_IP
),
1074 ConfigFileEntry
.servlink_path
);
1075 return exit_client(client_p
, client_p
, client_p
, "Fork failed");
1078 SetServlink(client_p
);
1081 sendto_one(client_p
, "SVINFO %d %d 0 :%ld", TS_CURRENT
, TS_MIN
, rb_current_time());
1083 client_p
->servptr
= &me
;
1085 if(IsAnyDead(client_p
))
1086 return CLIENT_EXITED
;
1088 SetServer(client_p
);
1090 /* Update the capability combination usage counts */
1091 set_chcap_usage_counts(client_p
);
1093 rb_dlinkAdd(client_p
, &client_p
->lnode
, &me
.serv
->servers
);
1094 del_unknown_ip(client_p
);
1095 rb_dlinkMoveNode(&client_p
->localClient
->tnode
, &unknown_list
, &serv_list
);
1096 rb_dlinkAddTailAlloc(client_p
, &global_serv_list
);
1098 if(has_id(client_p
))
1099 add_to_id_hash(client_p
->id
, client_p
);
1101 add_to_client_hash(client_p
->name
, client_p
);
1102 /* doesnt duplicate client_p->serv if allocated this struct already */
1103 make_server(client_p
);
1105 client_p
->serv
->caps
= client_p
->localClient
->caps
;
1107 if(client_p
->localClient
->fullcaps
)
1109 client_p
->serv
->fullcaps
= rb_strdup(client_p
->localClient
->fullcaps
);
1110 rb_free(client_p
->localClient
->fullcaps
);
1111 client_p
->localClient
->fullcaps
= NULL
;
1114 client_p
->serv
->nameinfo
= scache_connect(client_p
->name
, client_p
->info
, IsHidden(client_p
));
1115 client_p
->localClient
->firsttime
= rb_current_time();
1116 /* fixing eob timings.. -gnp */
1118 if((rb_dlink_list_length(&lclient_list
) + rb_dlink_list_length(&serv_list
)) >
1119 (unsigned long)MaxConnectionCount
)
1120 MaxConnectionCount
= rb_dlink_list_length(&lclient_list
) +
1121 rb_dlink_list_length(&serv_list
);
1123 /* Show the real host/IP to admins */
1124 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1125 "Link with %s established: (%s) link",
1126 get_server_name(client_p
, SHOW_IP
),
1127 show_capabilities(client_p
));
1129 ilog(L_SERVER
, "Link with %s established: (%s) link",
1130 log_client_name(client_p
, SHOW_IP
), show_capabilities(client_p
));
1133 hdata
.target
= client_p
;
1134 call_hook(h_server_introduced
, &hdata
);
1136 if(HasServlink(client_p
))
1138 /* we won't overflow FD_DESC_SZ here, as it can hold
1139 * client_p->name + 64
1141 rb_snprintf(note
, sizeof note
, "slink data: %s", client_p
->name
);
1142 rb_note(client_p
->localClient
->F
, note
);
1143 // rb_note(client_p->localClient->ctrlfd, "slink ctrl: %s", client_p->name);
1147 rb_snprintf(note
, sizeof note
, "Server: %s", client_p
->name
);
1148 rb_note(client_p
->localClient
->F
, note
);
1152 ** Old sendto_serv_but_one() call removed because we now
1153 ** need to send different names to different servers
1154 ** (domain name matching) Send new server to other servers.
1156 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
1158 target_p
= ptr
->data
;
1160 if(target_p
== client_p
)
1163 if(has_id(target_p
) && has_id(client_p
))
1165 sendto_one(target_p
, ":%s SID %s 2 %s :%s%s",
1166 me
.id
, client_p
->name
, client_p
->id
,
1167 IsHidden(client_p
) ? "(H) " : "", client_p
->info
);
1169 if(IsCapable(target_p
, CAP_ENCAP
) &&
1170 !EmptyString(client_p
->serv
->fullcaps
))
1171 sendto_one(target_p
, ":%s ENCAP * GCAP :%s",
1172 client_p
->id
, client_p
->serv
->fullcaps
);
1176 sendto_one(target_p
, ":%s SERVER %s 2 :%s%s",
1177 me
.name
, client_p
->name
,
1178 IsHidden(client_p
) ? "(H) " : "", client_p
->info
);
1180 if(IsCapable(target_p
, CAP_ENCAP
) &&
1181 !EmptyString(client_p
->serv
->fullcaps
))
1182 sendto_one(target_p
, ":%s ENCAP * GCAP :%s",
1183 client_p
->name
, client_p
->serv
->fullcaps
);
1188 ** Pass on my client information to the new server
1190 ** First, pass only servers (idea is that if the link gets
1191 ** cancelled beacause the server was already there,
1192 ** there are no NICK's to be cancelled...). Of course,
1193 ** if cancellation occurs, all this info is sent anyway,
1194 ** and I guess the link dies when a read is attempted...? --msa
1196 ** Note: Link cancellation to occur at this point means
1197 ** that at least two servers from my fragment are building
1198 ** up connection this other fragment at the same time, it's
1199 ** a race condition, not the normal way of operation...
1201 ** ALSO NOTE: using the get_client_name for server names--
1202 ** see previous *WARNING*!!! (Also, original inpath
1205 RB_DLINK_FOREACH(ptr
, global_serv_list
.head
)
1207 target_p
= ptr
->data
;
1209 /* target_p->from == target_p for target_p == client_p */
1210 if(IsMe(target_p
) || target_p
->from
== client_p
)
1213 /* presumption, if target has an id, so does its uplink */
1214 if(has_id(client_p
) && has_id(target_p
))
1215 sendto_one(client_p
, ":%s SID %s %d %s :%s%s",
1216 target_p
->servptr
->id
, target_p
->name
,
1217 target_p
->hopcount
+ 1, target_p
->id
,
1218 IsHidden(target_p
) ? "(H) " : "", target_p
->info
);
1220 sendto_one(client_p
, ":%s SERVER %s %d :%s%s",
1221 target_p
->servptr
->name
,
1222 target_p
->name
, target_p
->hopcount
+ 1,
1223 IsHidden(target_p
) ? "(H) " : "", target_p
->info
);
1225 if(IsCapable(client_p
, CAP_ENCAP
) &&
1226 !EmptyString(target_p
->serv
->fullcaps
))
1227 sendto_one(client_p
, ":%s ENCAP * GCAP :%s",
1228 get_id(target_p
, client_p
),
1229 target_p
->serv
->fullcaps
);
1232 if(has_id(client_p
))
1233 burst_TS6(client_p
);
1235 burst_TS5(client_p
);
1237 /* Always send a PING after connect burst is done */
1238 sendto_one(client_p
, "PING :%s", get_id(&me
, client_p
));
1240 free_pre_client(client_p
);
1246 start_io(struct Client
*server
)
1248 unsigned char *iobuf
;
1253 iobuf
= rb_malloc(256); /* XXX: This seems arbitrary. Perhaps make it IRCD_BUFSIZE? --nenolod */
1255 if(IsCapable(server
, CAP_ZIP
))
1258 iobuf
[c
++] = SLINKCMD_SET_ZIP_OUT_LEVEL
;
1259 iobuf
[c
++] = 0; /* | */
1260 iobuf
[c
++] = 1; /* \ len is 1 */
1261 iobuf
[c
++] = ConfigFileEntry
.compression_level
;
1262 iobuf
[c
++] = SLINKCMD_START_ZIP_IN
;
1263 iobuf
[c
++] = SLINKCMD_START_ZIP_OUT
;
1266 while (MyConnect(server
))
1270 iobuf
= rb_realloc(iobuf
, (c
+ READBUF_SIZE
+ 64));
1272 /* store data in c+3 to allow for SLINKCMD_INJECT_RECVQ and len u16 */
1273 linelen
= rb_linebuf_get(&server
->localClient
->buf_recvq
, (char *) (iobuf
+ c
+ 3), READBUF_SIZE
, LINEBUF_PARTIAL
, LINEBUF_RAW
); /* include partial lines */
1277 iobuf
[c
++] = SLINKCMD_INJECT_RECVQ
;
1278 iobuf
[c
++] = (linelen
>> 8);
1279 iobuf
[c
++] = (linelen
& 0xff);
1286 while (MyConnect(server
))
1290 iobuf
= rb_realloc(iobuf
, (c
+ BUF_DATA_SIZE
+ 64));
1292 /* store data in c+3 to allow for SLINKCMD_INJECT_RECVQ and len u16 */
1293 linelen
= rb_linebuf_get(&server
->localClient
->buf_sendq
,
1294 (char *) (iobuf
+ c
+ 3), READBUF_SIZE
,
1295 LINEBUF_PARTIAL
, LINEBUF_PARSED
); /* include partial lines */
1299 iobuf
[c
++] = SLINKCMD_INJECT_SENDQ
;
1300 iobuf
[c
++] = (linelen
>> 8);
1301 iobuf
[c
++] = (linelen
& 0xff);
1309 iobuf
[c
++] = SLINKCMD_INIT
;
1311 server
->localClient
->slinkq
= iobuf
;
1312 server
->localClient
->slinkq_ofs
= 0;
1313 server
->localClient
->slinkq_len
= c
;
1315 /* schedule a write */
1316 //XXX send_queued_slink_write(server->localClient->ctrlF, server);
1322 * inputs - struct Client *server
1323 * output - success: 0 / failure: -1
1324 * side effect - fork, and exec SERVLINK to handle this connection
1327 fork_server(struct Client
*server
)
1336 char slink
[] = "-slink";
1340 #ifdef HAVE_SOCKETPAIR
1341 if(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctrl_fds
) < 0)
1343 if(inet_socketpair(AF_INET
,SOCK_STREAM
, 0, ctrl_fds
) < 0)
1350 #ifdef HAVE_SOCKETPAIR
1351 if(socketpair(AF_UNIX
, SOCK_STREAM
, 0, data_fds
) < 0)
1353 if(inet_socketpair(AF_INET
,SOCK_STREAM
, 0, data_fds
) < 0)
1359 if((ret
= vfork()) < 0)
1361 if((ret
= fork()) < 0)
1366 int maxconn
= maxconnections
;
1368 /* set our fds as non blocking and close everything else */
1369 for (i
= 0; i
< maxconn
; i
++)
1373 if((i
== ctrl_fds
[1]) || (i
== data_fds
[1]) || (i
== rb_get_fd(server
->localClient
->F
)))
1375 // XXX rb_set_nb(i);
1380 if(i
> 2) /* don't close std* */
1386 rb_snprintf(fd_str
[0], sizeof(fd_str
[0]), "%d", ctrl_fds
[1]);
1387 rb_snprintf(fd_str
[1], sizeof(fd_str
[1]), "%d", data_fds
[1]);
1388 rb_snprintf(fd_str
[2], sizeof(fd_str
[2]), "%d", rb_get_fd(server
->localClient
->F
));
1389 kid_argv
[0] = slink
;
1390 kid_argv
[1] = fd_str
[0];
1391 kid_argv
[2] = fd_str
[1];
1392 kid_argv
[3] = fd_str
[2];
1395 /* exec servlink program */
1396 execv(ConfigFileEntry
.servlink_path
, kid_argv
);
1398 /* We're still here, abort. */
1403 rb_close(server
->localClient
->F
);
1405 /* close the childs end of the pipes */
1409 s_assert(server
->localClient
);
1410 // server->localClient->ctrlfd = ctrl_fds[0];
1411 server
->localClient
->F
= rb_open(data_fds
[0], RB_FD_PIPE
, "servlink data");
1413 if(!rb_set_nb(server
->localClient
->F
))
1415 ilog_error("setting a slink fd nonblocking");
1418 /* if(!rb_set_nb(server->localClient->ctrlfd))
1420 ilog_error("setting a slink fd nonblocking");
1423 rb_open(server->localClient->ctrlfd, FD_SOCKET, NULL);
1426 read_packet(server
->localClient
->F
, server
);
1432 /* this is ugly, but nicer than repeating
1433 * about 50 close() statements everywhre... */
1442 * New server connection code
1443 * Based upon the stuff floating about in s_bsd.c
1448 * serv_connect() - initiate a server connection
1450 * inputs - pointer to conf
1451 * - pointer to client doing the connet
1455 * This code initiates a connection to a server. It first checks to make
1456 * sure the given server exists. If this is the case, it creates a socket,
1457 * creates a client, saves the socket information in the client, and
1458 * initiates a connection to the server through rb_connect_tcp(). The
1459 * completion of this goes through serv_completed_connection().
1461 * We return 1 if the connection is attempted, since we don't know whether
1462 * it suceeded or not, and 0 if it fails in here somewhere.
1465 serv_connect(struct server_conf
*server_p
, struct Client
*by
)
1467 struct Client
*client_p
;
1468 struct rb_sockaddr_storage myipnum
, theiripnum
;
1470 char vhoststr
[HOSTIPLEN
];
1471 char note
[HOSTLEN
+ 10];
1473 s_assert(server_p
!= NULL
);
1474 if(server_p
== NULL
)
1478 * Make sure this server isn't already connected
1480 if((client_p
= find_server(NULL
, server_p
->name
)))
1482 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1483 "Server %s already present from %s",
1484 server_p
->name
, get_server_name(client_p
, SHOW_IP
));
1485 if(by
&& IsPerson(by
) && !MyClient(by
))
1486 sendto_one_notice(by
, ":Server %s already present from %s",
1487 server_p
->name
, get_server_name(client_p
, SHOW_IP
));
1491 if (rb_inet_pton_sock(server_p
->host
, (struct sockaddr
*)&theiripnum
) <= 0)
1493 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1494 "Server %s host is a DNS name which is currently not implemented",
1496 if(by
&& IsPerson(by
) && !MyClient(by
))
1497 sendto_one_notice(by
, ":Server %s host is a DNS name which is currently not implemented",
1503 if(theiripnum
.ss_family
== AF_INET6
)
1504 ((struct sockaddr_in6
*)&theiripnum
)->sin6_port
= htons(server_p
->port
);
1507 ((struct sockaddr_in
*)&theiripnum
)->sin_port
= htons(server_p
->port
);
1509 /* create a socket for the server connection */
1510 if((F
= rb_socket(server_p
->aftype
, SOCK_STREAM
, 0, NULL
)) != NULL
)
1512 ilog_error("opening a stream socket");
1516 rb_snprintf(note
, sizeof note
, "Server: %s", server_p
->name
);
1519 /* Create a local client */
1520 client_p
= make_client(NULL
);
1522 /* Copy in the server, hostname, fd
1523 * The sockhost may be a hostname, this will be corrected later
1526 strlcpy(client_p
->name
, server_p
->name
, sizeof(client_p
->name
));
1527 strlcpy(client_p
->host
, server_p
->host
, sizeof(client_p
->host
));
1528 strlcpy(client_p
->sockhost
, server_p
->host
, sizeof(client_p
->sockhost
));
1529 memcpy(&client_p
->localClient
->ip
, &theiripnum
, sizeof(client_p
->localClient
->ip
));
1530 client_p
->localClient
->F
= F
;
1533 * Set up the initial server evilness, ripped straight from
1534 * connect_server(), so don't blame me for it being evil.
1538 if(!rb_set_buffers(client_p
->localClient
->F
, READBUF_SIZE
))
1540 ilog_error("setting the buffer size for a server connection");
1544 * Attach config entries to client here rather than in
1545 * serv_connect_callback(). This to avoid null pointer references.
1547 attach_server_conf(client_p
, server_p
);
1550 * at this point we have a connection in progress and C/N lines
1551 * attached to the client, the socket info should be saved in the
1552 * client and it should either be resolved or have a valid address.
1554 * The socket has been connected or connect is in progress.
1556 make_server(client_p
);
1557 if(by
&& IsPerson(by
))
1559 strcpy(client_p
->serv
->by
, by
->name
);
1560 if(client_p
->serv
->user
)
1561 free_user(client_p
->serv
->user
, NULL
);
1562 client_p
->serv
->user
= by
->user
;
1567 strcpy(client_p
->serv
->by
, "AutoConn.");
1568 if(client_p
->serv
->user
)
1569 free_user(client_p
->serv
->user
, NULL
);
1570 client_p
->serv
->user
= NULL
;
1572 SetConnecting(client_p
);
1573 rb_dlinkAddTail(client_p
, &client_p
->node
, &global_client_list
);
1575 if(ServerConfVhosted(server_p
))
1577 memcpy(&myipnum
, &server_p
->my_ipnum
, sizeof(myipnum
));
1578 ((struct sockaddr_in
*)&myipnum
)->sin_port
= 0;
1579 myipnum
.ss_family
= server_p
->aftype
;
1582 else if(server_p
->aftype
== AF_INET
&& ServerInfo
.specific_ipv4_vhost
)
1584 memcpy(&myipnum
, &ServerInfo
.ip
, sizeof(myipnum
));
1585 ((struct sockaddr_in
*)&myipnum
)->sin_port
= 0;
1586 myipnum
.ss_family
= AF_INET
;
1587 SET_SS_LEN(&myipnum
, sizeof(struct sockaddr_in
));
1591 else if((server_p
->aftype
== AF_INET6
) && ServerInfo
.specific_ipv6_vhost
)
1593 memcpy(&myipnum
, &ServerInfo
.ip6
, sizeof(myipnum
));
1594 ((struct sockaddr_in6
*)&myipnum
)->sin6_port
= 0;
1595 myipnum
.ss_family
= AF_INET6
;
1596 SET_SS_LEN(&myipnum
, sizeof(struct sockaddr_in6
));
1602 ilog(L_SERVER
, "Connecting to %s[%s] port %d (%s)", server_p
->name
, server_p
->host
, server_p
->port
,
1604 server_p
->aftype
== AF_INET6
? "IPv6" :
1606 (server_p
->aftype
== AF_INET
? "IPv4" : "?"));
1608 rb_connect_tcp(client_p
->localClient
->F
,
1609 (struct sockaddr
*) &theiripnum
,
1611 serv_connect_callback
, client_p
,
1612 ConfigFileEntry
.connect_timeout
);
1617 inetntop_sock((struct sockaddr
*)&myipnum
, vhoststr
, sizeof vhoststr
);
1618 ilog(L_SERVER
, "Connecting to %s[%s] port %d (%s) (vhost %s)", server_p
->name
, server_p
->host
, server_p
->port
,
1620 server_p
->aftype
== AF_INET6
? "IPv6" :
1622 (server_p
->aftype
== AF_INET
? "IPv4" : "?"), vhoststr
);
1625 rb_connect_tcp(client_p
->localClient
->F
,
1626 (struct sockaddr
*) &theiripnum
,
1627 (struct sockaddr
*) &myipnum
, GET_SS_LEN(&myipnum
),
1628 serv_connect_callback
, client_p
,
1629 ConfigFileEntry
.connect_timeout
);
1635 * serv_connect_callback() - complete a server connection.
1637 * This routine is called after the server connection attempt has
1638 * completed. If unsucessful, an error is sent to ops and the client
1639 * is closed. If sucessful, it goes through the initialisation/check
1640 * procedures, the capabilities are sent, and the socket is then
1641 * marked for reading.
1644 serv_connect_callback(rb_fde_t
*F
, int status
, void *data
)
1646 struct Client
*client_p
= data
;
1647 struct server_conf
*server_p
;
1650 /* First, make sure its a real client! */
1651 s_assert(client_p
!= NULL
);
1652 s_assert(client_p
->localClient
->F
== F
);
1654 if(client_p
== NULL
)
1657 /* while we were waiting for the callback, its possible this already
1660 if(find_server(NULL
, client_p
->name
) != NULL
)
1662 exit_client(client_p
, client_p
, &me
, "Server Exists");
1667 /* Next, for backward purposes, record the ip of the server */
1668 memcpy(&client_p
->localClient
->ip
, &F
->connect
.hostaddr
, sizeof client_p
->localClient
->ip
);
1669 /* Set sockhost properly now -- jilles */
1670 inetntop_sock((struct sockaddr
*)&F
->connect
.hostaddr
,
1671 client_p
->sockhost
, sizeof client_p
->sockhost
);
1674 /* Check the status */
1677 /* COMM_ERR_TIMEOUT wont have an errno associated with it,
1678 * the others will.. --fl
1680 if(status
== RB_ERR_TIMEOUT
)
1682 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) ? L_NETWIDE
: L_ALL
,
1683 "Error connecting to %s[%s]: %s",
1685 #ifdef HIDE_SERVERS_IPS
1691 ilog(L_SERVER
, "Error connecting to %s[%s]: %s",
1692 client_p
->name
, client_p
->sockhost
,
1697 errstr
= strerror(rb_get_sockerr(F
));
1698 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) ? L_NETWIDE
: L_ALL
,
1699 "Error connecting to %s[%s]: %s (%s)",
1701 #ifdef HIDE_SERVERS_IPS
1706 rb_errstr(status
), errstr
);
1707 ilog(L_SERVER
, "Error connecting to %s[%s]: %s (%s)",
1708 client_p
->name
, client_p
->sockhost
,
1709 rb_errstr(status
), errstr
);
1712 exit_client(client_p
, client_p
, &me
, rb_errstr(status
));
1716 /* COMM_OK, so continue the connection procedure */
1717 /* Get the C/N lines */
1718 if((server_p
= client_p
->localClient
->att_sconf
) == NULL
)
1720 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) ? L_NETWIDE
: L_ALL
, "Lost connect{} block for %s",
1721 get_server_name(client_p
, HIDE_IP
));
1722 exit_client(client_p
, client_p
, &me
, "Lost connect{} block");
1726 /* Next, send the initial handshake */
1727 SetHandshake(client_p
);
1729 /* kludge, if we're not using TS6, dont ever send
1730 * ourselves as being TS6 capable.
1732 if(!EmptyString(server_p
->spasswd
))
1734 sendto_one(client_p
, "PASS %s TS %d :%s",
1735 server_p
->spasswd
, TS_CURRENT
, me
.id
);
1738 /* pass my info to the new server */
1739 send_capabilities(client_p
, default_server_capabs
1740 | (ServerConfCompressed(server_p
) ? CAP_ZIP_SUPPORTED
: 0)
1741 | (ServerConfTb(server_p
) ? CAP_TB
: 0));
1743 sendto_one(client_p
, "SERVER %s 1 :%s%s",
1745 ConfigServerHide
.hidden
? "(H) " : "", me
.info
);
1748 * If we've been marked dead because a send failed, just exit
1749 * here now and save everyone the trouble of us ever existing.
1751 if(IsAnyDead(client_p
))
1753 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) ? L_NETWIDE
: L_ALL
,
1754 "%s went dead during handshake", client_p
->name
);
1755 exit_client(client_p
, client_p
, &me
, "Went dead during handshake");
1759 /* don't move to serv_list yet -- we haven't sent a burst! */
1761 /* If we get here, we're ok, so lets start reading some data */
1762 read_packet(F
, client_p
);
1765 #ifndef HAVE_SOCKETPAIR
1767 inet_socketpair(int d
, int type
, int protocol
, int sv
[2])
1769 struct sockaddr_in addr1
, addr2
, addr3
;
1770 int addr3_len
= sizeof(addr3
);
1772 int port_no
= 20000;
1774 if(d
!= AF_INET
|| type
!= SOCK_STREAM
|| protocol
)
1776 errno
= EAFNOSUPPORT
;
1779 if(((sv
[0] = socket(AF_INET
, SOCK_STREAM
, 0)) < 0) || ((sv
[1] = socket(AF_INET
, SOCK_STREAM
, 0)) < 0))
1782 addr1
.sin_port
= htons(port_no
);
1783 addr1
.sin_family
= AF_INET
;
1784 addr1
.sin_addr
.s_addr
= htonl(INADDR_LOOPBACK
);
1785 while ((rc
= bind (sv
[0], (struct sockaddr
*) &addr1
, sizeof (addr1
))) < 0 && errno
== EADDRINUSE
)
1786 addr1
.sin_port
= htons(++port_no
);
1791 if(listen(sv
[0], 1) < 0)
1798 addr2
.sin_port
= htons(port_no
);
1799 addr2
.sin_family
= AF_INET
;
1800 addr2
.sin_addr
.s_addr
= htonl(INADDR_LOOPBACK
);
1801 if(connect (sv
[1], (struct sockaddr
*) &addr2
, sizeof (addr2
)) < 0)
1808 if((fd
= accept(sv
[1], (struct sockaddr
*) &addr3
, &addr3_len
)) < 0)