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>
40 #include "irc_string.h"
41 #include "sprintf_irc.h"
43 #include "ircd_defs.h"
49 #include "s_newconf.h"
57 #include "channel.h" /* chcap_usage_counts stuff... */
65 #define INADDR_NONE ((unsigned int) 0xffffffff)
68 #ifndef HAVE_SOCKETPAIR
69 static int inet_socketpair(int d
, int type
, int protocol
, int sv
[2]);
72 int MaxConnectionCount
= 1;
73 int MaxClientCount
= 1;
74 int refresh_user_links
= 0;
76 static char buf
[BUFSIZE
];
78 static void start_io(struct Client
*server
);
80 static SlinkRplHnd slink_error
;
81 static SlinkRplHnd slink_zipstats
;
83 * list of recognized server capabilities. "TS" is not on the list
84 * because all servers that we talk to already do TS, and the kludged
85 * extra argument to "PASS" takes care of checking that. -orabidoo
87 struct Capability captab
[] = {
95 { "KNOCK", CAP_KNOCK
},
98 { "UNKLN", CAP_UNKLN
},
99 { "CLUSTER", CAP_CLUSTER
},
100 { "ENCAP", CAP_ENCAP
},
101 { "SERVICES", CAP_SERVICE
},
102 { "RSFNC", CAP_RSFNC
},
103 { "SAVE", CAP_SAVE
},
104 { "EUID", CAP_EUID
},
108 struct SlinkRplDef slinkrpltab
[] = {
109 {SLINKRPL_ERROR
, slink_error
, SLINKRPL_FLAG_DATA
},
110 {SLINKRPL_ZIPSTATS
, slink_zipstats
, SLINKRPL_FLAG_DATA
},
114 static int fork_server(struct Client
*client_p
);
116 static CNCB serv_connect_callback
;
119 slink_error(unsigned int rpl
, unsigned int len
, unsigned char *data
, struct Client
*server_p
)
121 char squitreason
[256];
123 s_assert(rpl
== SLINKRPL_ERROR
);
126 data
[len
- 1] = '\0';
128 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "SlinkError for %s: %s", server_p
->name
, data
);
129 snprintf(squitreason
, sizeof squitreason
, "servlink error: %s", data
);
130 exit_client(server_p
, server_p
, &me
, squitreason
);
134 slink_zipstats(unsigned int rpl
, unsigned int len
, unsigned char *data
, struct Client
*server_p
)
136 struct ZipStats zipstats
;
137 u_int32_t in
= 0, in_wire
= 0, out
= 0, out_wire
= 0;
140 s_assert(rpl
== SLINKRPL_ZIPSTATS
);
142 s_assert(IsCapable(server_p
, CAP_ZIP
));
144 /* Yes, it needs to be done this way, no we cannot let the compiler
145 * work with the pointer to the structure. This works around a GCC
146 * bug on SPARC that affects all versions at the time of this writing.
147 * I will feed you to the creatures living in RMS's beard if you do
148 * not leave this as is, without being sure that you are not causing
149 * regression for most of our installed SPARC base.
150 * -jmallett, 04/27/2002
152 memcpy(&zipstats
, &server_p
->localClient
->zipstats
, sizeof(struct ZipStats
));
154 in
|= (data
[i
++] << 24);
155 in
|= (data
[i
++] << 16);
156 in
|= (data
[i
++] << 8);
159 in_wire
|= (data
[i
++] << 24);
160 in_wire
|= (data
[i
++] << 16);
161 in_wire
|= (data
[i
++] << 8);
162 in_wire
|= (data
[i
++]);
164 out
|= (data
[i
++] << 24);
165 out
|= (data
[i
++] << 16);
166 out
|= (data
[i
++] << 8);
169 out_wire
|= (data
[i
++] << 24);
170 out_wire
|= (data
[i
++] << 16);
171 out_wire
|= (data
[i
++] << 8);
172 out_wire
|= (data
[i
++]);
175 zipstats
.inK
+= zipstats
.in
>> 10;
176 zipstats
.in
&= 0x03ff;
178 zipstats
.in_wire
+= in_wire
;
179 zipstats
.inK_wire
+= zipstats
.in_wire
>> 10;
180 zipstats
.in_wire
&= 0x03ff;
183 zipstats
.outK
+= zipstats
.out
>> 10;
184 zipstats
.out
&= 0x03ff;
186 zipstats
.out_wire
+= out_wire
;
187 zipstats
.outK_wire
+= zipstats
.out_wire
>> 10;
188 zipstats
.out_wire
&= 0x03ff;
192 (((double) (zipstats
.inK
- zipstats
.inK_wire
) /
193 (double) zipstats
.inK
) * 100.00);
195 zipstats
.in_ratio
= 0;
197 if(zipstats
.outK
> 0)
199 (((double) (zipstats
.outK
- zipstats
.outK_wire
) /
200 (double) zipstats
.outK
) * 100.00);
202 zipstats
.out_ratio
= 0;
204 memcpy(&server_p
->localClient
->zipstats
, &zipstats
, sizeof(struct ZipStats
));
208 collect_zipstats(void *unused
)
211 struct Client
*target_p
;
213 DLINK_FOREACH(ptr
, serv_list
.head
)
215 target_p
= ptr
->data
;
216 if(IsCapable(target_p
, CAP_ZIP
))
218 /* only bother if we haven't already got something queued... */
219 if(!target_p
->localClient
->slinkq
)
221 target_p
->localClient
->slinkq
= MyMalloc(1); /* sigh.. */
222 target_p
->localClient
->slinkq
[0] = SLINKCMD_ZIPSTATS
;
223 target_p
->localClient
->slinkq_ofs
= 0;
224 target_p
->localClient
->slinkq_len
= 1;
225 send_queued_slink_write(target_p
->localClient
->ctrlfd
, target_p
);
232 * hunt_server - Do the basic thing in delivering the message (command)
233 * across the relays to the specific server (server) for
236 * Note: The command is a format string and *MUST* be
237 * of prefixed style (e.g. ":%s COMMAND %s ...").
238 * Command can have only max 8 parameters.
240 * server parv[server] is the parameter identifying the
244 * parv[server] is replaced with the pointer to the
245 * real servername from the matched client (I'm lazy
248 * returns: (see #defines)
251 hunt_server(struct Client
*client_p
, struct Client
*source_p
,
252 const char *command
, int server
, int parc
, const char *parv
[])
254 struct Client
*target_p
;
261 * Assume it's me, if no server
263 if(parc
<= server
|| EmptyString(parv
[server
]) ||
264 match(parv
[server
], me
.name
) || (strcmp(parv
[server
], me
.id
) == 0))
265 return (HUNTED_ISME
);
267 new = LOCAL_COPY(parv
[server
]);
270 * These are to pickup matches that would cause the following
271 * message to go in the wrong direction while doing quick fast
272 * non-matching lookups.
274 if(MyClient(source_p
))
275 target_p
= find_named_client(new);
277 target_p
= find_client(new);
280 if(target_p
->from
== source_p
->from
&& !MyConnect(target_p
))
284 wilds
= (strchr(new, '?') || strchr(new, '*'));
287 * Again, if there are no wild cards involved in the server
288 * name, use the hash lookup
294 if(MyClient(source_p
) || !IsDigit(parv
[server
][0]))
295 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
296 form_str(ERR_NOSUCHSERVER
),
298 return (HUNTED_NOSUCH
);
304 DLINK_FOREACH(ptr
, global_client_list
.head
)
306 if(match(new, ((struct Client
*) (ptr
->data
))->name
))
308 target_p
= ptr
->data
;
317 if(!IsRegistered(target_p
))
319 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
320 form_str(ERR_NOSUCHSERVER
),
322 return HUNTED_NOSUCH
;
325 if(IsMe(target_p
) || MyClient(target_p
))
329 parv
[server
] = get_id(target_p
, target_p
);
331 sendto_one(target_p
, command
, get_id(source_p
, target_p
),
332 parv
[1], parv
[2], parv
[3], parv
[4], parv
[5], parv
[6], parv
[7], parv
[8]);
334 return (HUNTED_PASS
);
337 if(!IsDigit(parv
[server
][0]))
338 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
339 form_str(ERR_NOSUCHSERVER
), parv
[server
]);
340 return (HUNTED_NOSUCH
);
344 * try_connections - scan through configuration and try new connections.
345 * Returns the calendar time when the next call to this
346 * function should be made latest. (No harm done if this
347 * is called earlier or later...)
350 try_connections(void *unused
)
352 struct Client
*client_p
;
353 struct server_conf
*server_p
= NULL
;
354 struct server_conf
*tmp_p
;
357 int connecting
= FALSE
;
361 DLINK_FOREACH(ptr
, server_conf_list
.head
)
365 if(ServerConfIllegal(tmp_p
) || !ServerConfAutoconn(tmp_p
))
368 cltmp
= tmp_p
->class;
371 * Skip this entry if the use of it is still on hold until
372 * future. Otherwise handle this entry (and set it on hold
373 * until next time). Will reset only hold times, if already
374 * made one successfull connection... [this algorithm is
375 * a bit fuzzy... -- msa >;) ]
377 if(tmp_p
->hold
> CurrentTime
)
379 if(next
> tmp_p
->hold
|| next
== 0)
384 confrq
= get_con_freq(cltmp
);
385 tmp_p
->hold
= CurrentTime
+ confrq
;
388 * Found a CONNECT config with port specified, scan clients
389 * and see if this server is already connected?
391 client_p
= find_server(NULL
, tmp_p
->name
);
393 if(!client_p
&& (CurrUsers(cltmp
) < MaxUsers(cltmp
)) && !connecting
)
397 /* We connect only one at time... */
401 if((next
> tmp_p
->hold
) || (next
== 0))
405 /* TODO: change this to set active flag to 0 when added to event! --Habeeb */
406 if(GlobalSetOptions
.autoconn
== 0)
412 /* move this connect entry to end.. */
413 dlinkDelete(&server_p
->node
, &server_conf_list
);
414 dlinkAddTail(server_p
, &server_p
->node
, &server_conf_list
);
417 * We used to only print this if serv_connect() actually
418 * suceeded, but since comm_tcp_connect() can call the callback
419 * immediately if there is an error, we were getting error messages
420 * in the wrong order. SO, we just print out the activated line,
421 * and let serv_connect() / serv_connect_callback() print an
422 * error afterwards if it fails.
425 #ifndef HIDE_SERVERS_IPS
426 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
427 "Connection to %s[%s] activated.",
428 server_p
->name
, server_p
->host
);
430 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
431 "Connection to %s activated",
435 serv_connect(server_p
, 0);
439 check_server(const char *name
, struct Client
*client_p
)
441 struct server_conf
*server_p
= NULL
;
442 struct server_conf
*tmp_p
;
446 s_assert(NULL
!= client_p
);
450 if(!(client_p
->localClient
->passwd
))
453 if(strlen(name
) > HOSTLEN
)
456 DLINK_FOREACH(ptr
, server_conf_list
.head
)
460 if(ServerConfIllegal(tmp_p
))
463 if(!match(tmp_p
->name
, name
))
468 /* XXX: Fix me for IPv6 */
469 /* XXX sockhost is the IPv4 ip as a string */
470 if(match(tmp_p
->host
, client_p
->host
) ||
471 match(tmp_p
->host
, client_p
->sockhost
))
475 if(ServerConfEncrypted(tmp_p
))
477 if(!strcmp(tmp_p
->passwd
, crypt(client_p
->localClient
->passwd
,
484 else if(!strcmp(tmp_p
->passwd
, client_p
->localClient
->passwd
))
495 attach_server_conf(client_p
, server_p
);
497 /* clear ZIP/TB if they support but we dont want them */
499 if(!ServerConfCompressed(server_p
))
501 ClearCap(client_p
, CAP_ZIP
);
503 if(!ServerConfTb(server_p
))
504 ClearCap(client_p
, CAP_TB
);
512 * inputs - Client pointer to send to
513 * - int flag of capabilities that this server has
515 * side effects - send the CAPAB line to a server -orabidoo
519 send_capabilities(struct Client
*client_p
, int cap_can_send
)
521 struct Capability
*cap
;
522 char msgbuf
[BUFSIZE
];
528 for (cap
= captab
; cap
->name
; ++cap
)
530 if(cap
->cap
& cap_can_send
)
532 tl
= ircsprintf(t
, "%s ", cap
->name
);
540 sendto_one(client_p
, "CAPAB :%s", msgbuf
);
545 * input - client to burst to, channel name, list to burst, mode flag
547 * side effects - client is sent a list of +b, or +e, or +I modes
550 burst_modes_TS5(struct Client
*client_p
, char *chname
, dlink_list
*list
, char flag
)
554 char mbuf
[MODEBUFLEN
];
563 mlen
= ircsprintf(buf
, ":%s MODE %s +", me
.name
, chname
);
569 DLINK_FOREACH(ptr
, list
->head
)
572 tlen
= strlen(banptr
->banstr
) + 3;
575 if(tlen
> MODEBUFLEN
)
578 if((count
>= MAXMODEPARAMS
) || ((cur_len
+ tlen
+ 2) > (BUFSIZE
- 3)))
580 sendto_one(client_p
, "%s%s %s", buf
, mbuf
, pbuf
);
590 pp
+= ircsprintf(pp
, "%s ", banptr
->banstr
);
596 sendto_one(client_p
, "%s%s %s", buf
, mbuf
, pbuf
);
601 * input - client to burst to, channel name, list to burst, mode flag
603 * side effects - client is sent a list of +b, +e, or +I modes
606 burst_modes_TS6(struct Client
*client_p
, struct Channel
*chptr
,
607 dlink_list
*list
, char flag
)
616 cur_len
= mlen
= ircsprintf(buf
, ":%s BMASK %ld %s %c :",
617 me
.id
, (long) chptr
->channelts
, chptr
->chname
, flag
);
620 DLINK_FOREACH(ptr
, list
->head
)
624 tlen
= strlen(banptr
->banstr
) + 1;
627 if(cur_len
+ tlen
> BUFSIZE
- 3)
629 /* the one we're trying to send doesnt fit at all! */
636 /* chop off trailing space and send.. */
638 sendto_one(client_p
, "%s", buf
);
643 ircsprintf(t
, "%s ", banptr
->banstr
);
648 /* cant ever exit the loop above without having modified buf,
649 * chop off trailing space and send.
652 sendto_one(client_p
, "%s", buf
);
658 * inputs - client (server) to send nick towards
659 * - client to send nick for
661 * side effects - NICK message is sent towards given client_p
664 burst_TS5(struct Client
*client_p
)
666 static char ubuf
[12];
667 struct Client
*target_p
;
668 struct Channel
*chptr
;
669 struct membership
*msptr
;
670 hook_data_client hclientinfo
;
671 hook_data_channel hchaninfo
;
678 hclientinfo
.client
= hchaninfo
.client
= client_p
;
680 DLINK_FOREACH(ptr
, global_client_list
.head
)
682 target_p
= ptr
->data
;
684 if(!IsPerson(target_p
))
687 send_umode(NULL
, target_p
, 0, 0, ubuf
);
694 sendto_one(client_p
, "NICK %s %d %ld %s %s %s %s :%s",
695 target_p
->name
, target_p
->hopcount
+ 1,
696 (long) target_p
->tsinfo
, ubuf
,
697 target_p
->username
, target_p
->host
,
698 target_p
->servptr
->name
, target_p
->info
);
700 if(IsDynSpoof(target_p
))
701 sendto_one(client_p
, ":%s ENCAP * REALHOST %s",
702 target_p
->name
, target_p
->orighost
);
703 if(!EmptyString(target_p
->user
->suser
))
704 sendto_one(client_p
, ":%s ENCAP * LOGIN %s",
705 target_p
->name
, target_p
->user
->suser
);
707 if(ConfigFileEntry
.burst_away
&& !EmptyString(target_p
->user
->away
))
708 sendto_one(client_p
, ":%s AWAY :%s",
709 target_p
->name
, target_p
->user
->away
);
711 hclientinfo
.target
= target_p
;
712 call_hook(h_burst_client
, &hclientinfo
);
715 DLINK_FOREACH(ptr
, global_channel_list
.head
)
719 if(*chptr
->chname
!= '#')
722 cur_len
= mlen
= ircsprintf(buf
, ":%s SJOIN %ld %s %s :", me
.name
,
723 (long) chptr
->channelts
, chptr
->chname
,
724 channel_modes(chptr
, client_p
));
728 DLINK_FOREACH(uptr
, chptr
->members
.head
)
732 tlen
= strlen(msptr
->client_p
->name
) + 1;
738 if(cur_len
+ tlen
>= BUFSIZE
- 3)
742 sendto_one(client_p
, "%s", buf
);
747 ircsprintf(t
, "%s%s ", find_channel_status(msptr
, 1),
748 msptr
->client_p
->name
);
754 if (dlink_list_length(&chptr
->members
) > 0)
756 /* remove trailing space */
760 sendto_one(client_p
, "%s", buf
);
762 burst_modes_TS5(client_p
, chptr
->chname
, &chptr
->banlist
, 'b');
764 if(IsCapable(client_p
, CAP_EX
))
765 burst_modes_TS5(client_p
, chptr
->chname
, &chptr
->exceptlist
, 'e');
767 if(IsCapable(client_p
, CAP_IE
))
768 burst_modes_TS5(client_p
, chptr
->chname
, &chptr
->invexlist
, 'I');
770 burst_modes_TS5(client_p
, chptr
->chname
, &chptr
->quietlist
, 'q');
772 if(IsCapable(client_p
, CAP_TB
) && chptr
->topic
!= NULL
)
773 sendto_one(client_p
, ":%s TB %s %ld %s%s:%s",
774 me
.name
, chptr
->chname
, (long) chptr
->topic_time
,
775 ConfigChannel
.burst_topicwho
? chptr
->topic_info
: "",
776 ConfigChannel
.burst_topicwho
? " " : "",
779 hchaninfo
.chptr
= chptr
;
780 call_hook(h_burst_channel
, &hchaninfo
);
783 hclientinfo
.target
= NULL
;
784 call_hook(h_burst_finished
, &hclientinfo
);
790 * inputs - client (server) to send nick towards
791 * - client to send nick for
793 * side effects - NICK message is sent towards given client_p
796 burst_TS6(struct Client
*client_p
)
798 static char ubuf
[12];
799 struct Client
*target_p
;
800 struct Channel
*chptr
;
801 struct membership
*msptr
;
802 hook_data_client hclientinfo
;
803 hook_data_channel hchaninfo
;
810 hclientinfo
.client
= hchaninfo
.client
= client_p
;
812 DLINK_FOREACH(ptr
, global_client_list
.head
)
814 target_p
= ptr
->data
;
816 if(!IsPerson(target_p
))
819 send_umode(NULL
, target_p
, 0, 0, ubuf
);
826 if(has_id(target_p
) && IsCapable(client_p
, CAP_EUID
))
827 sendto_one(client_p
, ":%s EUID %s %d %ld %s %s %s %s %s %s %s :%s",
828 target_p
->servptr
->id
, target_p
->name
,
829 target_p
->hopcount
+ 1,
830 (long) target_p
->tsinfo
, ubuf
,
831 target_p
->username
, target_p
->host
,
832 IsIPSpoof(target_p
) ? "0" : target_p
->sockhost
,
834 IsDynSpoof(target_p
) ? target_p
->orighost
: "*",
835 EmptyString(target_p
->user
->suser
) ? "*" : target_p
->user
->suser
,
837 else if(has_id(target_p
))
838 sendto_one(client_p
, ":%s UID %s %d %ld %s %s %s %s %s :%s",
839 target_p
->servptr
->id
, target_p
->name
,
840 target_p
->hopcount
+ 1,
841 (long) target_p
->tsinfo
, ubuf
,
842 target_p
->username
, target_p
->host
,
843 IsIPSpoof(target_p
) ? "0" : target_p
->sockhost
,
844 target_p
->id
, target_p
->info
);
846 sendto_one(client_p
, "NICK %s %d %ld %s %s %s %s :%s",
848 target_p
->hopcount
+ 1,
849 (long) target_p
->tsinfo
,
851 target_p
->username
, target_p
->host
,
852 target_p
->servptr
->name
, target_p
->info
);
854 if(!has_id(target_p
) || !IsCapable(client_p
, CAP_EUID
))
856 if(IsDynSpoof(target_p
))
857 sendto_one(client_p
, ":%s ENCAP * REALHOST %s",
858 use_id(target_p
), target_p
->orighost
);
859 if(!EmptyString(target_p
->user
->suser
))
860 sendto_one(client_p
, ":%s ENCAP * LOGIN %s",
861 use_id(target_p
), target_p
->user
->suser
);
864 if(ConfigFileEntry
.burst_away
&& !EmptyString(target_p
->user
->away
))
865 sendto_one(client_p
, ":%s AWAY :%s",
867 target_p
->user
->away
);
869 hclientinfo
.target
= target_p
;
870 call_hook(h_burst_client
, &hclientinfo
);
873 DLINK_FOREACH(ptr
, global_channel_list
.head
)
877 if(*chptr
->chname
!= '#')
880 cur_len
= mlen
= ircsprintf(buf
, ":%s SJOIN %ld %s %s :", me
.id
,
881 (long) chptr
->channelts
, chptr
->chname
,
882 channel_modes(chptr
, client_p
));
886 DLINK_FOREACH(uptr
, chptr
->members
.head
)
890 tlen
= strlen(use_id(msptr
->client_p
)) + 1;
896 if(cur_len
+ tlen
>= BUFSIZE
- 3)
899 sendto_one(client_p
, "%s", buf
);
904 ircsprintf(t
, "%s%s ", find_channel_status(msptr
, 1),
905 use_id(msptr
->client_p
));
911 if (dlink_list_length(&chptr
->members
) > 0)
913 /* remove trailing space */
916 sendto_one(client_p
, "%s", buf
);
918 if(dlink_list_length(&chptr
->banlist
) > 0)
919 burst_modes_TS6(client_p
, chptr
, &chptr
->banlist
, 'b');
921 if(IsCapable(client_p
, CAP_EX
) &&
922 dlink_list_length(&chptr
->exceptlist
) > 0)
923 burst_modes_TS6(client_p
, chptr
, &chptr
->exceptlist
, 'e');
925 if(IsCapable(client_p
, CAP_IE
) &&
926 dlink_list_length(&chptr
->invexlist
) > 0)
927 burst_modes_TS6(client_p
, chptr
, &chptr
->invexlist
, 'I');
929 if(dlink_list_length(&chptr
->quietlist
) > 0)
930 burst_modes_TS6(client_p
, chptr
, &chptr
->quietlist
, 'q');
932 if(IsCapable(client_p
, CAP_TB
) && chptr
->topic
!= NULL
)
933 sendto_one(client_p
, ":%s TB %s %ld %s%s:%s",
934 me
.id
, chptr
->chname
, (long) chptr
->topic_time
,
935 ConfigChannel
.burst_topicwho
? chptr
->topic_info
: "",
936 ConfigChannel
.burst_topicwho
? " " : "",
939 hchaninfo
.chptr
= chptr
;
940 call_hook(h_burst_channel
, &hchaninfo
);
943 hclientinfo
.target
= NULL
;
944 call_hook(h_burst_finished
, &hclientinfo
);
948 * show_capabilities - show current server capabilities
950 * inputs - pointer to an struct Client
951 * output - pointer to static string
952 * side effects - build up string representing capabilities of server listed
955 show_capabilities(struct Client
*target_p
)
957 static char msgbuf
[BUFSIZE
];
958 struct Capability
*cap
;
963 tl
= ircsprintf(msgbuf
, "TS ");
966 if(!IsServer(target_p
) || !target_p
->serv
->caps
) /* short circuit if no caps */
972 for (cap
= captab
; cap
->cap
; ++cap
)
974 if(cap
->cap
& target_p
->serv
->caps
)
976 tl
= ircsprintf(t
, "%s ", cap
->name
);
990 * inputs - pointer to a struct Client
995 server_estab(struct Client
*client_p
)
997 struct Client
*target_p
;
998 struct server_conf
*server_p
;
999 hook_data_client hdata
;
1003 s_assert(NULL
!= client_p
);
1004 if(client_p
== NULL
)
1006 ClearAccess(client_p
);
1008 host
= client_p
->name
;
1010 if((server_p
= client_p
->localClient
->att_sconf
) == NULL
)
1012 /* This shouldn't happen, better tell the ops... -A1kmm */
1013 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) ? L_NETWIDE
: L_ALL
,
1014 "Warning: Lost connect{} block for server %s!", host
);
1015 return exit_client(client_p
, client_p
, client_p
, "Lost connect{} block!");
1018 /* We shouldn't have to check this, it should already done before
1019 * server_estab is called. -A1kmm
1021 if(client_p
->localClient
->passwd
)
1023 memset(client_p
->localClient
->passwd
, 0, strlen(client_p
->localClient
->passwd
));
1024 MyFree(client_p
->localClient
->passwd
);
1025 client_p
->localClient
->passwd
= NULL
;
1028 /* Its got identd , since its a server */
1031 /* If there is something in the serv_list, it might be this
1032 * connecting server..
1034 if(!ServerInfo
.hub
&& serv_list
.head
)
1036 if(client_p
!= serv_list
.head
->data
|| serv_list
.head
->next
)
1038 ServerStats
->is_ref
++;
1039 sendto_one(client_p
, "ERROR :I'm a leaf not a hub");
1040 return exit_client(client_p
, client_p
, client_p
, "I'm a leaf");
1044 if(IsUnknown(client_p
))
1047 * jdc -- 1. Use EmptyString(), not [0] index reference.
1048 * 2. Check ->spasswd, not ->passwd.
1050 if(!EmptyString(server_p
->spasswd
))
1052 sendto_one(client_p
, "PASS %s TS %d :%s",
1053 server_p
->spasswd
, TS_CURRENT
, me
.id
);
1056 /* pass info to new server */
1057 send_capabilities(client_p
, default_server_capabs
1058 | (ServerConfCompressed(server_p
) ? CAP_ZIP_SUPPORTED
: 0)
1059 | (ServerConfTb(server_p
) ? CAP_TB
: 0));
1061 sendto_one(client_p
, "SERVER %s 1 :%s%s",
1063 ConfigServerHide
.hidden
? "(H) " : "",
1064 (me
.info
[0]) ? (me
.info
) : "IRCers United");
1067 if(!comm_set_buffers(client_p
->localClient
->fd
, READBUF_SIZE
))
1068 report_error(SETBUF_ERROR_MSG
,
1069 get_server_name(client_p
, SHOW_IP
),
1070 log_client_name(client_p
, SHOW_IP
), errno
);
1072 /* Hand the server off to servlink now */
1073 if(IsCapable(client_p
, CAP_ZIP
))
1075 if(fork_server(client_p
) < 0)
1077 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) ? L_NETWIDE
: L_ALL
,
1078 "Warning: fork failed for server %s -- check servlink_path (%s)",
1079 get_server_name(client_p
, HIDE_IP
),
1080 ConfigFileEntry
.servlink_path
);
1081 return exit_client(client_p
, client_p
, client_p
, "Fork failed");
1084 SetServlink(client_p
);
1087 sendto_one(client_p
, "SVINFO %d %d 0 :%ld", TS_CURRENT
, TS_MIN
, CurrentTime
);
1089 client_p
->servptr
= &me
;
1091 if(IsAnyDead(client_p
))
1092 return CLIENT_EXITED
;
1094 SetServer(client_p
);
1096 /* Update the capability combination usage counts */
1097 set_chcap_usage_counts(client_p
);
1099 dlinkAdd(client_p
, &client_p
->lnode
, &me
.serv
->servers
);
1100 del_unknown_ip(client_p
);
1101 dlinkMoveNode(&client_p
->localClient
->tnode
, &unknown_list
, &serv_list
);
1102 dlinkAddTailAlloc(client_p
, &global_serv_list
);
1104 if(has_id(client_p
))
1105 add_to_id_hash(client_p
->id
, client_p
);
1107 add_to_client_hash(client_p
->name
, client_p
);
1108 /* doesnt duplicate client_p->serv if allocated this struct already */
1109 make_server(client_p
);
1111 client_p
->serv
->caps
= client_p
->localClient
->caps
;
1113 if(client_p
->localClient
->fullcaps
)
1115 DupString(client_p
->serv
->fullcaps
, client_p
->localClient
->fullcaps
);
1116 MyFree(client_p
->localClient
->fullcaps
);
1117 client_p
->localClient
->fullcaps
= NULL
;
1120 client_p
->serv
->nameinfo
= scache_connect(client_p
->name
, client_p
->info
, IsHidden(client_p
));
1121 client_p
->localClient
->firsttime
= CurrentTime
;
1122 /* fixing eob timings.. -gnp */
1124 if((dlink_list_length(&lclient_list
) + dlink_list_length(&serv_list
)) >
1125 (unsigned long)MaxConnectionCount
)
1126 MaxConnectionCount
= dlink_list_length(&lclient_list
) +
1127 dlink_list_length(&serv_list
);
1129 /* Show the real host/IP to admins */
1130 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1131 "Link with %s established: (%s) link",
1132 get_server_name(client_p
, SHOW_IP
),
1133 show_capabilities(client_p
));
1135 ilog(L_SERVER
, "Link with %s established: (%s) link",
1136 log_client_name(client_p
, SHOW_IP
), show_capabilities(client_p
));
1139 hdata
.target
= client_p
;
1140 call_hook(h_server_introduced
, &hdata
);
1142 if(HasServlink(client_p
))
1144 /* we won't overflow FD_DESC_SZ here, as it can hold
1145 * client_p->name + 64
1147 comm_note(client_p
->localClient
->fd
, "slink data: %s", client_p
->name
);
1148 comm_note(client_p
->localClient
->ctrlfd
, "slink ctrl: %s", client_p
->name
);
1151 comm_note(client_p
->localClient
->fd
, "Server: %s", client_p
->name
);
1154 ** Old sendto_serv_but_one() call removed because we now
1155 ** need to send different names to different servers
1156 ** (domain name matching) Send new server to other servers.
1158 DLINK_FOREACH(ptr
, serv_list
.head
)
1160 target_p
= ptr
->data
;
1162 if(target_p
== client_p
)
1165 if(has_id(target_p
) && has_id(client_p
))
1167 sendto_one(target_p
, ":%s SID %s 2 %s :%s%s",
1168 me
.id
, client_p
->name
, client_p
->id
,
1169 IsHidden(client_p
) ? "(H) " : "", client_p
->info
);
1171 if(IsCapable(target_p
, CAP_ENCAP
) &&
1172 !EmptyString(client_p
->serv
->fullcaps
))
1173 sendto_one(target_p
, ":%s ENCAP * GCAP :%s",
1174 client_p
->id
, client_p
->serv
->fullcaps
);
1178 sendto_one(target_p
, ":%s SERVER %s 2 :%s%s",
1179 me
.name
, client_p
->name
,
1180 IsHidden(client_p
) ? "(H) " : "", client_p
->info
);
1182 if(IsCapable(target_p
, CAP_ENCAP
) &&
1183 !EmptyString(client_p
->serv
->fullcaps
))
1184 sendto_one(target_p
, ":%s ENCAP * GCAP :%s",
1185 client_p
->name
, client_p
->serv
->fullcaps
);
1190 ** Pass on my client information to the new server
1192 ** First, pass only servers (idea is that if the link gets
1193 ** cancelled beacause the server was already there,
1194 ** there are no NICK's to be cancelled...). Of course,
1195 ** if cancellation occurs, all this info is sent anyway,
1196 ** and I guess the link dies when a read is attempted...? --msa
1198 ** Note: Link cancellation to occur at this point means
1199 ** that at least two servers from my fragment are building
1200 ** up connection this other fragment at the same time, it's
1201 ** a race condition, not the normal way of operation...
1203 ** ALSO NOTE: using the get_client_name for server names--
1204 ** see previous *WARNING*!!! (Also, original inpath
1207 DLINK_FOREACH(ptr
, global_serv_list
.head
)
1209 target_p
= ptr
->data
;
1211 /* target_p->from == target_p for target_p == client_p */
1212 if(IsMe(target_p
) || target_p
->from
== client_p
)
1215 /* presumption, if target has an id, so does its uplink */
1216 if(has_id(client_p
) && has_id(target_p
))
1217 sendto_one(client_p
, ":%s SID %s %d %s :%s%s",
1218 target_p
->servptr
->id
, target_p
->name
,
1219 target_p
->hopcount
+ 1, target_p
->id
,
1220 IsHidden(target_p
) ? "(H) " : "", target_p
->info
);
1222 sendto_one(client_p
, ":%s SERVER %s %d :%s%s",
1223 target_p
->servptr
->name
,
1224 target_p
->name
, target_p
->hopcount
+ 1,
1225 IsHidden(target_p
) ? "(H) " : "", target_p
->info
);
1227 if(IsCapable(client_p
, CAP_ENCAP
) &&
1228 !EmptyString(target_p
->serv
->fullcaps
))
1229 sendto_one(client_p
, ":%s ENCAP * GCAP :%s",
1230 get_id(target_p
, client_p
),
1231 target_p
->serv
->fullcaps
);
1234 if(has_id(client_p
))
1235 burst_TS6(client_p
);
1237 burst_TS5(client_p
);
1239 /* Always send a PING after connect burst is done */
1240 sendto_one(client_p
, "PING :%s", get_id(&me
, client_p
));
1242 free_pre_client(client_p
);
1248 start_io(struct Client
*server
)
1250 unsigned char *iobuf
;
1255 iobuf
= MyMalloc(256); /* XXX: This seems arbitrary. Perhaps make it IRCD_BUFSIZE? --nenolod */
1257 if(IsCapable(server
, CAP_ZIP
))
1260 iobuf
[c
++] = SLINKCMD_SET_ZIP_OUT_LEVEL
;
1261 iobuf
[c
++] = 0; /* | */
1262 iobuf
[c
++] = 1; /* \ len is 1 */
1263 iobuf
[c
++] = ConfigFileEntry
.compression_level
;
1264 iobuf
[c
++] = SLINKCMD_START_ZIP_IN
;
1265 iobuf
[c
++] = SLINKCMD_START_ZIP_OUT
;
1268 while (MyConnect(server
))
1272 iobuf
= MyRealloc(iobuf
, (c
+ READBUF_SIZE
+ 64));
1274 /* store data in c+3 to allow for SLINKCMD_INJECT_RECVQ and len u16 */
1275 linelen
= linebuf_get(&server
->localClient
->buf_recvq
, (char *) (iobuf
+ c
+ 3), READBUF_SIZE
, LINEBUF_PARTIAL
, LINEBUF_RAW
); /* include partial lines */
1279 iobuf
[c
++] = SLINKCMD_INJECT_RECVQ
;
1280 iobuf
[c
++] = (linelen
>> 8);
1281 iobuf
[c
++] = (linelen
& 0xff);
1288 while (MyConnect(server
))
1292 iobuf
= MyRealloc(iobuf
, (c
+ BUF_DATA_SIZE
+ 64));
1294 /* store data in c+3 to allow for SLINKCMD_INJECT_RECVQ and len u16 */
1295 linelen
= linebuf_get(&server
->localClient
->buf_sendq
,
1296 (char *) (iobuf
+ c
+ 3), READBUF_SIZE
,
1297 LINEBUF_PARTIAL
, LINEBUF_PARSED
); /* include partial lines */
1301 iobuf
[c
++] = SLINKCMD_INJECT_SENDQ
;
1302 iobuf
[c
++] = (linelen
>> 8);
1303 iobuf
[c
++] = (linelen
& 0xff);
1311 iobuf
[c
++] = SLINKCMD_INIT
;
1313 server
->localClient
->slinkq
= iobuf
;
1314 server
->localClient
->slinkq_ofs
= 0;
1315 server
->localClient
->slinkq_len
= c
;
1317 /* schedule a write */
1318 send_queued_slink_write(server
->localClient
->ctrlfd
, server
);
1324 * inputs - struct Client *server
1325 * output - success: 0 / failure: -1
1326 * side effect - fork, and exec SERVLINK to handle this connection
1329 fork_server(struct Client
*server
)
1338 char slink
[] = "-slink";
1342 #ifdef HAVE_SOCKETPAIR
1343 if(socketpair(AF_UNIX
, SOCK_STREAM
, 0, ctrl_fds
) < 0)
1345 if(inet_socketpair(AF_INET
,SOCK_STREAM
, 0, ctrl_fds
) < 0)
1352 #ifdef HAVE_SOCKETPAIR
1353 if(socketpair(AF_UNIX
, SOCK_STREAM
, 0, data_fds
) < 0)
1355 if(inet_socketpair(AF_INET
,SOCK_STREAM
, 0, data_fds
) < 0)
1361 if((ret
= vfork()) < 0)
1363 if((ret
= fork()) < 0)
1368 int maxconn
= comm_get_maxconnections();
1370 /* set our fds as non blocking and close everything else */
1371 for (i
= 0; i
< maxconn
; i
++)
1375 if((i
== ctrl_fds
[1]) || (i
== data_fds
[1]) || (i
== server
->localClient
->fd
))
1382 if(i
> 2) /* don't close std* */
1388 ircsnprintf(fd_str
[0], sizeof(fd_str
[0]), "%d", ctrl_fds
[1]);
1389 ircsnprintf(fd_str
[1], sizeof(fd_str
[1]), "%d", data_fds
[1]);
1390 ircsnprintf(fd_str
[2], sizeof(fd_str
[2]), "%d", server
->localClient
->fd
);
1391 kid_argv
[0] = slink
;
1392 kid_argv
[1] = fd_str
[0];
1393 kid_argv
[2] = fd_str
[1];
1394 kid_argv
[3] = fd_str
[2];
1397 /* exec servlink program */
1398 execv(ConfigFileEntry
.servlink_path
, kid_argv
);
1400 /* We're still here, abort. */
1405 comm_close(server
->localClient
->fd
);
1407 /* close the childs end of the pipes */
1411 s_assert(server
->localClient
);
1412 server
->localClient
->ctrlfd
= ctrl_fds
[0];
1413 server
->localClient
->fd
= data_fds
[0];
1415 if(!comm_set_nb(server
->localClient
->fd
))
1417 report_error(NONB_ERROR_MSG
,
1418 get_server_name(server
, SHOW_IP
),
1419 log_client_name(server
, SHOW_IP
),
1423 if(!comm_set_nb(server
->localClient
->ctrlfd
))
1425 report_error(NONB_ERROR_MSG
,
1426 get_server_name(server
, SHOW_IP
),
1427 log_client_name(server
, SHOW_IP
),
1431 comm_open(server
->localClient
->ctrlfd
, FD_SOCKET
, NULL
);
1432 comm_open(server
->localClient
->fd
, FD_SOCKET
, NULL
);
1434 read_ctrl_packet(server
->localClient
->ctrlfd
, server
);
1435 read_packet(server
->localClient
->fd
, server
);
1441 /* this is ugly, but nicer than repeating
1442 * about 50 close() statements everywhre... */
1451 * New server connection code
1452 * Based upon the stuff floating about in s_bsd.c
1457 * serv_connect() - initiate a server connection
1459 * inputs - pointer to conf
1460 * - pointer to client doing the connet
1464 * This code initiates a connection to a server. It first checks to make
1465 * sure the given server exists. If this is the case, it creates a socket,
1466 * creates a client, saves the socket information in the client, and
1467 * initiates a connection to the server through comm_connect_tcp(). The
1468 * completion of this goes through serv_completed_connection().
1470 * We return 1 if the connection is attempted, since we don't know whether
1471 * it suceeded or not, and 0 if it fails in here somewhere.
1474 serv_connect(struct server_conf
*server_p
, struct Client
*by
)
1476 struct Client
*client_p
;
1477 struct irc_sockaddr_storage myipnum
;
1480 s_assert(server_p
!= NULL
);
1481 if(server_p
== NULL
)
1485 * Make sure this server isn't already connected
1487 if((client_p
= find_server(NULL
, server_p
->name
)))
1489 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1490 "Server %s already present from %s",
1491 server_p
->name
, get_server_name(client_p
, SHOW_IP
));
1492 if(by
&& IsPerson(by
) && !MyClient(by
))
1493 sendto_one_notice(by
, ":Server %s already present from %s",
1494 server_p
->name
, get_server_name(client_p
, SHOW_IP
));
1498 /* create a socket for the server connection */
1499 if((fd
= comm_socket(server_p
->aftype
, SOCK_STREAM
, 0, NULL
)) < 0)
1501 /* Eek, failure to create the socket */
1502 report_error("opening stream socket to %s: %s",
1503 server_p
->name
, server_p
->name
, errno
);
1507 /* servernames are always guaranteed under HOSTLEN chars */
1508 comm_note(fd
, "Server: %s", server_p
->name
);
1510 /* Create a local client */
1511 client_p
= make_client(NULL
);
1513 /* Copy in the server, hostname, fd
1514 * The sockhost may be a hostname, this will be corrected later
1517 strlcpy(client_p
->name
, server_p
->name
, sizeof(client_p
->name
));
1518 strlcpy(client_p
->host
, server_p
->host
, sizeof(client_p
->host
));
1519 strlcpy(client_p
->sockhost
, server_p
->host
, sizeof(client_p
->sockhost
));
1520 client_p
->localClient
->fd
= fd
;
1523 * Set up the initial server evilness, ripped straight from
1524 * connect_server(), so don't blame me for it being evil.
1528 if(!comm_set_buffers(client_p
->localClient
->fd
, READBUF_SIZE
))
1530 report_error(SETBUF_ERROR_MSG
,
1531 get_server_name(client_p
, SHOW_IP
),
1532 log_client_name(client_p
, SHOW_IP
),
1537 * Attach config entries to client here rather than in
1538 * serv_connect_callback(). This to avoid null pointer references.
1540 attach_server_conf(client_p
, server_p
);
1543 * at this point we have a connection in progress and C/N lines
1544 * attached to the client, the socket info should be saved in the
1545 * client and it should either be resolved or have a valid address.
1547 * The socket has been connected or connect is in progress.
1549 make_server(client_p
);
1550 if(by
&& IsPerson(by
))
1552 strcpy(client_p
->serv
->by
, by
->name
);
1553 if(client_p
->serv
->user
)
1554 free_user(client_p
->serv
->user
, NULL
);
1555 client_p
->serv
->user
= by
->user
;
1560 strcpy(client_p
->serv
->by
, "AutoConn.");
1561 if(client_p
->serv
->user
)
1562 free_user(client_p
->serv
->user
, NULL
);
1563 client_p
->serv
->user
= NULL
;
1565 SetConnecting(client_p
);
1566 dlinkAddTail(client_p
, &client_p
->node
, &global_client_list
);
1569 ilog(L_SERVER
, "Connecting to %s[%s] port %d (%s)", server_p
->name
, server_p
->host
, server_p
->port
,
1571 server_p
->aftype
== AF_INET6
? "IPv6" :
1573 (server_p
->aftype
== AF_INET
? "IPv4" : "?"));
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
));
1601 comm_connect_tcp(client_p
->localClient
->fd
, server_p
->host
,
1602 server_p
->port
, NULL
, 0, serv_connect_callback
,
1603 client_p
, server_p
->aftype
,
1604 ConfigFileEntry
.connect_timeout
);
1608 comm_connect_tcp(client_p
->localClient
->fd
, server_p
->host
,
1609 server_p
->port
, (struct sockaddr
*) &myipnum
,
1610 GET_SS_LEN(myipnum
), serv_connect_callback
, client_p
,
1611 myipnum
.ss_family
, ConfigFileEntry
.connect_timeout
);
1617 * serv_connect_callback() - complete a server connection.
1619 * This routine is called after the server connection attempt has
1620 * completed. If unsucessful, an error is sent to ops and the client
1621 * is closed. If sucessful, it goes through the initialisation/check
1622 * procedures, the capabilities are sent, and the socket is then
1623 * marked for reading.
1626 serv_connect_callback(int fd
, int status
, void *data
)
1628 struct Client
*client_p
= data
;
1629 struct server_conf
*server_p
;
1631 fde_t
*F
= comm_locate_fd(fd
);
1633 /* First, make sure its a real client! */
1634 s_assert(client_p
!= NULL
);
1635 s_assert(client_p
->localClient
->fd
== fd
);
1637 if(client_p
== NULL
)
1640 /* while we were waiting for the callback, its possible this already
1643 if(find_server(NULL
, client_p
->name
) != NULL
)
1645 exit_client(client_p
, client_p
, &me
, "Server Exists");
1649 /* Next, for backward purposes, record the ip of the server */
1650 memcpy(&client_p
->localClient
->ip
, &F
->connect
.hostaddr
, sizeof client_p
->localClient
->ip
);
1651 /* Set sockhost properly now -- jilles */
1652 inetntop_sock((struct sockaddr
*)&F
->connect
.hostaddr
,
1653 client_p
->sockhost
, sizeof client_p
->sockhost
);
1655 /* Check the status */
1656 if(status
!= COMM_OK
)
1658 /* COMM_ERR_TIMEOUT wont have an errno associated with it,
1659 * the others will.. --fl
1661 if(status
== COMM_ERR_TIMEOUT
)
1663 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) ? L_NETWIDE
: L_ALL
,
1664 "Error connecting to %s[%s]: %s",
1666 #ifdef HIDE_SERVERS_IPS
1671 comm_errstr(status
));
1672 ilog(L_SERVER
, "Error connecting to %s[%s]: %s",
1673 client_p
->name
, client_p
->sockhost
,
1674 comm_errstr(status
));
1678 errstr
= strerror(comm_get_sockerr(fd
));
1679 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) ? L_NETWIDE
: L_ALL
,
1680 "Error connecting to %s[%s]: %s (%s)",
1682 #ifdef HIDE_SERVERS_IPS
1687 comm_errstr(status
), errstr
);
1688 ilog(L_SERVER
, "Error connecting to %s[%s]: %s (%s)",
1689 client_p
->name
, client_p
->sockhost
,
1690 comm_errstr(status
), errstr
);
1693 exit_client(client_p
, client_p
, &me
, comm_errstr(status
));
1697 /* COMM_OK, so continue the connection procedure */
1698 /* Get the C/N lines */
1699 if((server_p
= client_p
->localClient
->att_sconf
) == NULL
)
1701 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) ? L_NETWIDE
: L_ALL
, "Lost connect{} block for %s",
1702 get_server_name(client_p
, HIDE_IP
));
1703 exit_client(client_p
, client_p
, &me
, "Lost connect{} block");
1707 /* Next, send the initial handshake */
1708 SetHandshake(client_p
);
1710 /* kludge, if we're not using TS6, dont ever send
1711 * ourselves as being TS6 capable.
1713 if(!EmptyString(server_p
->spasswd
))
1715 sendto_one(client_p
, "PASS %s TS %d :%s",
1716 server_p
->spasswd
, TS_CURRENT
, me
.id
);
1719 /* pass my info to the new server */
1720 send_capabilities(client_p
, default_server_capabs
1721 | (ServerConfCompressed(server_p
) ? CAP_ZIP_SUPPORTED
: 0)
1722 | (ServerConfTb(server_p
) ? CAP_TB
: 0));
1724 sendto_one(client_p
, "SERVER %s 1 :%s%s",
1726 ConfigServerHide
.hidden
? "(H) " : "", me
.info
);
1729 * If we've been marked dead because a send failed, just exit
1730 * here now and save everyone the trouble of us ever existing.
1732 if(IsAnyDead(client_p
))
1734 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) ? L_NETWIDE
: L_ALL
,
1735 "%s went dead during handshake", client_p
->name
);
1736 exit_client(client_p
, client_p
, &me
, "Went dead during handshake");
1740 /* don't move to serv_list yet -- we haven't sent a burst! */
1742 /* If we get here, we're ok, so lets start reading some data */
1743 read_packet(fd
, client_p
);
1746 #ifndef HAVE_SOCKETPAIR
1748 inet_socketpair(int d
, int type
, int protocol
, int sv
[2])
1750 struct sockaddr_in addr1
, addr2
, addr3
;
1751 int addr3_len
= sizeof(addr3
);
1753 int port_no
= 20000;
1755 if(d
!= AF_INET
|| type
!= SOCK_STREAM
|| protocol
)
1757 errno
= EAFNOSUPPORT
;
1760 if(((sv
[0] = socket(AF_INET
, SOCK_STREAM
, 0)) < 0) || ((sv
[1] = socket(AF_INET
, SOCK_STREAM
, 0)) < 0))
1763 addr1
.sin_port
= htons(port_no
);
1764 addr1
.sin_family
= AF_INET
;
1765 addr1
.sin_addr
.s_addr
= htonl(INADDR_LOOPBACK
);
1766 while ((rc
= bind (sv
[0], (struct sockaddr
*) &addr1
, sizeof (addr1
))) < 0 && errno
== EADDRINUSE
)
1767 addr1
.sin_port
= htons(++port_no
);
1772 if(listen(sv
[0], 1) < 0)
1779 addr2
.sin_port
= htons(port_no
);
1780 addr2
.sin_family
= AF_INET
;
1781 addr2
.sin_addr
.s_addr
= htonl(INADDR_LOOPBACK
);
1782 if(connect (sv
[1], (struct sockaddr
*) &addr2
, sizeof (addr2
)) < 0)
1789 if((fd
= accept(sv
[1], (struct sockaddr
*) &addr3
, &addr3_len
)) < 0)