ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/server.c
Revision: 3096
Committed: Sat Mar 1 23:31:45 2014 UTC (12 years, 7 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/src/s_serv.c
File size: 44988 byte(s)
Log Message:
- Applied Adam's "Put the command name in parv[0], not prefix name" patch

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2014 ircd-hybrid development team
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 * USA
20 */
21
22 /*! \file s_serv.c
23 * \brief Server related functions.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #ifdef HAVE_LIBCRYPTO
29 #include <openssl/rsa.h>
30 #include "rsa.h"
31 #endif
32 #include "list.h"
33 #include "channel.h"
34 #include "channel_mode.h"
35 #include "client.h"
36 #include "dbuf.h"
37 #include "event.h"
38 #include "fdlist.h"
39 #include "hash.h"
40 #include "irc_string.h"
41 #include "ircd.h"
42 #include "ircd_defs.h"
43 #include "s_bsd.h"
44 #include "numeric.h"
45 #include "packet.h"
46 #include "irc_res.h"
47 #include "conf.h"
48 #include "s_serv.h"
49 #include "log.h"
50 #include "s_misc.h"
51 #include "s_user.h"
52 #include "send.h"
53 #include "memory.h"
54 #include "channel.h"
55 #include "parse.h"
56
57 #define MIN_CONN_FREQ 300
58
59 dlink_list flatten_links;
60 static dlink_list cap_list = { NULL, NULL, 0 };
61 static void server_burst(struct Client *);
62 static void burst_all(struct Client *);
63 static void send_tb(struct Client *client_p, struct Channel *chptr);
64
65 static CNCB serv_connect_callback;
66
67 static void burst_members(struct Client *, struct Channel *);
68
69 /*
70 * write_links_file
71 *
72 * inputs - void pointer which is not used
73 * output - NONE
74 * side effects - called from an event, write out list of linked servers
75 * but in no particular order.
76 */
77 void
78 write_links_file(void *notused)
79 {
80 FILE *file = NULL;
81 dlink_node *ptr = NULL, *ptr_next = NULL;
82 char buff[IRCD_BUFSIZE] = { '\0' };
83
84 if ((file = fopen(LIPATH, "w")) == NULL)
85 return;
86
87 DLINK_FOREACH_SAFE(ptr, ptr_next, flatten_links.head)
88 {
89 dlinkDelete(ptr, &flatten_links);
90 MyFree(ptr->data);
91 free_dlink_node(ptr);
92 }
93
94 DLINK_FOREACH(ptr, global_serv_list.head)
95 {
96 const struct Client *target_p = ptr->data;
97
98 /*
99 * Skip hidden servers, aswell as ourselves, since we already send
100 * ourselves in /links
101 */
102 if (IsHidden(target_p) || IsMe(target_p))
103 continue;
104
105 if (HasFlag(target_p, FLAGS_SERVICE) && ConfigServerHide.hide_services)
106 continue;
107
108 /*
109 * Attempt to format the file in such a way it follows the usual links output
110 * ie "servername uplink :hops info"
111 * Mostly for aesthetic reasons - makes it look pretty in mIRC ;)
112 * - madmax
113 */
114 snprintf(buff, sizeof(buff), "%s %s :1 %s", target_p->name,
115 me.name, target_p->info);
116 dlinkAddTail(xstrdup(buff), make_dlink_node(), &flatten_links);
117 snprintf(buff, sizeof(buff), "%s %s :1 %s\n", target_p->name,
118 me.name, target_p->info);
119
120 fputs(buff, file);
121 }
122
123 fclose(file);
124 }
125
126 void
127 read_links_file(void)
128 {
129 FILE *file = NULL;
130 char *p = NULL;
131 char buff[IRCD_BUFSIZE] = { '\0' };
132
133 if ((file = fopen(LIPATH, "r")) == NULL)
134 return;
135
136 while (fgets(buff, sizeof(buff), file))
137 {
138 if ((p = strchr(buff, '\n')) != NULL)
139 *p = '\0';
140
141 dlinkAddTail(xstrdup(buff), make_dlink_node(), &flatten_links);
142 }
143
144 fclose(file);
145 }
146
147 /* hunt_server()
148 * Do the basic thing in delivering the message (command)
149 * across the relays to the specific server (server) for
150 * actions.
151 *
152 * Note: The command is a format string and *MUST* be
153 * of prefixed style (e.g. ":%s COMMAND %s ...").
154 * Command can have only max 8 parameters.
155 *
156 * server parv[server] is the parameter identifying the
157 * target server.
158 *
159 * *WARNING*
160 * parv[server] is replaced with the pointer to the
161 * real servername from the matched client (I'm lazy
162 * now --msa).
163 *
164 * returns: (see #defines)
165 */
166 int
167 hunt_server(struct Client *client_p, struct Client *source_p, const char *command,
168 const int server, const int parc, char *parv[])
169 {
170 struct Client *target_p = NULL;
171 struct Client *target_tmp = NULL;
172 dlink_node *ptr;
173 int wilds;
174
175 /* Assume it's me, if no server */
176 if (parc <= server || EmptyString(parv[server]))
177 return HUNTED_ISME;
178
179 if (!strcmp(parv[server], me.id) || !match(parv[server], me.name))
180 return HUNTED_ISME;
181
182 /* These are to pickup matches that would cause the following
183 * message to go in the wrong direction while doing quick fast
184 * non-matching lookups.
185 */
186 if (MyClient(source_p))
187 target_p = hash_find_client(parv[server]);
188 else
189 target_p = find_person(client_p, parv[server]);
190
191 if (target_p)
192 if (target_p->from == source_p->from && !MyConnect(target_p))
193 target_p = NULL;
194
195 if (target_p == NULL && (target_p = hash_find_server(parv[server])))
196 if (target_p->from == source_p->from && !MyConnect(target_p))
197 target_p = NULL;
198
199 wilds = has_wildcards(parv[server]);
200
201 /* Again, if there are no wild cards involved in the server
202 * name, use the hash lookup
203 */
204 if (target_p == NULL)
205 {
206 if (!wilds)
207 {
208 if (!(target_p = hash_find_server(parv[server])))
209 {
210 sendto_one(source_p, form_str(ERR_NOSUCHSERVER),
211 me.name, source_p->name, parv[server]);
212 return HUNTED_NOSUCH;
213 }
214 }
215 else
216 {
217 DLINK_FOREACH(ptr, global_client_list.head)
218 {
219 target_tmp = ptr->data;
220
221 if (!match(parv[server], target_tmp->name))
222 {
223 if (target_tmp->from == source_p->from && !MyConnect(target_tmp))
224 continue;
225 target_p = ptr->data;
226
227 if (IsRegistered(target_p) && (target_p != client_p))
228 break;
229 }
230 }
231 }
232 }
233
234 if (target_p != NULL)
235 {
236 if(!IsRegistered(target_p))
237 {
238 sendto_one(source_p, form_str(ERR_NOSUCHSERVER),
239 me.name, source_p->name, parv[server]);
240 return HUNTED_NOSUCH;
241 }
242
243 if (IsMe(target_p) || MyClient(target_p))
244 return HUNTED_ISME;
245
246 if (match(target_p->name, parv[server]))
247 parv[server] = target_p->name;
248
249 sendto_one(target_p, command, ID_or_name(source_p, target_p),
250 parv[1], parv[2], parv[3], parv[4],
251 parv[5], parv[6], parv[7], parv[8]);
252 return HUNTED_PASS;
253 }
254
255 sendto_one(source_p, form_str(ERR_NOSUCHSERVER),
256 me.name, source_p->name, parv[server]);
257 return HUNTED_NOSUCH;
258 }
259
260 /* try_connections()
261 *
262 * inputs - void pointer which is not used
263 * output - NONE
264 * side effects -
265 * scan through configuration and try new connections.
266 * Returns the calendar time when the next call to this
267 * function should be made latest. (No harm done if this
268 * is called earlier or later...)
269 */
270 void
271 try_connections(void *unused)
272 {
273 dlink_node *ptr = NULL;
274 struct MaskItem *conf;
275 int confrq;
276
277 /* TODO: change this to set active flag to 0 when added to event! --Habeeb */
278 if (GlobalSetOptions.autoconn == 0)
279 return;
280
281 DLINK_FOREACH(ptr, server_items.head)
282 {
283 conf = ptr->data;
284
285 assert(conf->type == CONF_SERVER);
286
287 /* Also when already connecting! (update holdtimes) --SRB
288 */
289 if (!conf->port ||!IsConfAllowAutoConn(conf))
290 continue;
291
292
293 /* Skip this entry if the use of it is still on hold until
294 * future. Otherwise handle this entry (and set it on hold
295 * until next time). Will reset only hold times, if already
296 * made one successfull connection... [this algorithm is
297 * a bit fuzzy... -- msa >;) ]
298 */
299 if (conf->until > CurrentTime)
300 continue;
301
302 if (conf->class == NULL)
303 confrq = DEFAULT_CONNECTFREQUENCY;
304 else
305 {
306 confrq = conf->class->con_freq;
307 if (confrq < MIN_CONN_FREQ)
308 confrq = MIN_CONN_FREQ;
309 }
310
311 conf->until = CurrentTime + confrq;
312
313 /* Found a CONNECT config with port specified, scan clients
314 * and see if this server is already connected?
315 */
316 if (hash_find_server(conf->name) != NULL)
317 continue;
318
319 if (conf->class->ref_count < conf->class->max_total)
320 {
321 /* Go to the end of the list, if not already last */
322 if (ptr->next != NULL)
323 {
324 dlinkDelete(ptr, &server_items);
325 dlinkAddTail(conf, &conf->node, &server_items);
326 }
327
328 if (find_servconn_in_progress(conf->name))
329 return;
330
331 /* We used to only print this if serv_connect() actually
332 * succeeded, but since comm_tcp_connect() can call the callback
333 * immediately if there is an error, we were getting error messages
334 * in the wrong order. SO, we just print out the activated line,
335 * and let serv_connect() / serv_connect_callback() print an
336 * error afterwards if it fails.
337 * -- adrian
338 */
339 if (ConfigServerHide.hide_server_ips)
340 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
341 "Connection to %s activated.",
342 conf->name);
343 else
344 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
345 "Connection to %s[%s] activated.",
346 conf->name, conf->host);
347
348 serv_connect(conf, NULL);
349 /* We connect only one at time... */
350 return;
351 }
352 }
353 }
354
355 int
356 valid_servname(const char *name)
357 {
358 unsigned int length = 0;
359 unsigned int dots = 0;
360 const char *p = name;
361
362 for (; *p; ++p)
363 {
364 if (!IsServChar(*p))
365 return 0;
366
367 ++length;
368
369 if (*p == '.')
370 ++dots;
371 }
372
373 return dots != 0 && length <= HOSTLEN;
374 }
375
376 int
377 check_server(const char *name, struct Client *client_p)
378 {
379 dlink_node *ptr;
380 struct MaskItem *conf = NULL;
381 struct MaskItem *server_conf = NULL;
382 int error = -1;
383
384 assert(client_p != NULL);
385
386 /* loop through looking for all possible connect items that might work */
387 DLINK_FOREACH(ptr, server_items.head)
388 {
389 conf = ptr->data;
390
391 if (match(name, conf->name))
392 continue;
393
394 error = -3;
395
396 /* XXX: Fix me for IPv6 */
397 /* XXX sockhost is the IPv4 ip as a string */
398 if (!match(conf->host, client_p->host) ||
399 !match(conf->host, client_p->sockhost))
400 {
401 error = -2;
402
403 if (!match_conf_password(client_p->localClient->passwd, conf))
404 return -2;
405
406 if (!EmptyString(conf->certfp))
407 if (EmptyString(client_p->certfp) || strcasecmp(client_p->certfp, conf->certfp))
408 return -4;
409
410 server_conf = conf;
411 }
412 }
413
414 if (server_conf == NULL)
415 return error;
416
417 attach_conf(client_p, server_conf);
418
419
420 if (server_conf != NULL)
421 {
422 struct sockaddr_in *v4;
423 #ifdef IPV6
424 struct sockaddr_in6 *v6;
425 #endif
426 switch (server_conf->aftype)
427 {
428 #ifdef IPV6
429 case AF_INET6:
430 v6 = (struct sockaddr_in6 *)&server_conf->addr;
431
432 if (IN6_IS_ADDR_UNSPECIFIED(&v6->sin6_addr))
433 memcpy(&server_conf->addr, &client_p->localClient->ip, sizeof(struct irc_ssaddr));
434 break;
435 #endif
436 case AF_INET:
437 v4 = (struct sockaddr_in *)&server_conf->addr;
438
439 if (v4->sin_addr.s_addr == INADDR_NONE)
440 memcpy(&server_conf->addr, &client_p->localClient->ip, sizeof(struct irc_ssaddr));
441 break;
442 }
443 }
444
445 return 0;
446 }
447
448 /* add_capability()
449 *
450 * inputs - string name of CAPAB
451 * - int flag of capability
452 * output - NONE
453 * side effects - Adds given capability name and bit mask to
454 * current supported capabilities. This allows
455 * modules to dynamically add or subtract their capability.
456 */
457 void
458 add_capability(const char *capab_name, int cap_flag, int add_to_default)
459 {
460 struct Capability *cap = MyMalloc(sizeof(*cap));
461
462 cap->name = xstrdup(capab_name);
463 cap->cap = cap_flag;
464 dlinkAdd(cap, &cap->node, &cap_list);
465
466 if (add_to_default)
467 default_server_capabs |= cap_flag;
468 }
469
470 /* delete_capability()
471 *
472 * inputs - string name of CAPAB
473 * output - NONE
474 * side effects - delete given capability from ones known.
475 */
476 int
477 delete_capability(const char *capab_name)
478 {
479 dlink_node *ptr;
480 dlink_node *next_ptr;
481 struct Capability *cap;
482
483 DLINK_FOREACH_SAFE(ptr, next_ptr, cap_list.head)
484 {
485 cap = ptr->data;
486
487 if (cap->cap != 0)
488 {
489 if (irccmp(cap->name, capab_name) == 0)
490 {
491 default_server_capabs &= ~(cap->cap);
492 dlinkDelete(ptr, &cap_list);
493 MyFree(cap->name);
494 MyFree(cap);
495 }
496 }
497 }
498
499 return 0;
500 }
501
502 /*
503 * find_capability()
504 *
505 * inputs - string name of capab to find
506 * output - 0 if not found CAPAB otherwise
507 * side effects - none
508 */
509 unsigned int
510 find_capability(const char *capab)
511 {
512 const dlink_node *ptr = NULL;
513
514 DLINK_FOREACH(ptr, cap_list.head)
515 {
516 const struct Capability *cap = ptr->data;
517
518 if (cap->cap && !irccmp(cap->name, capab))
519 return cap->cap;
520 }
521
522 return 0;
523 }
524
525 /* send_capabilities()
526 *
527 * inputs - Client pointer to send to
528 * - int flag of capabilities that this server can send
529 * output - NONE
530 * side effects - send the CAPAB line to a server -orabidoo
531 *
532 */
533 void
534 send_capabilities(struct Client *client_p, int cap_can_send)
535 {
536 struct Capability *cap=NULL;
537 char msgbuf[IRCD_BUFSIZE];
538 char *t;
539 int tl;
540 dlink_node *ptr;
541
542 t = msgbuf;
543
544 DLINK_FOREACH(ptr, cap_list.head)
545 {
546 cap = ptr->data;
547
548 if (cap->cap & (cap_can_send|default_server_capabs))
549 {
550 tl = sprintf(t, "%s ", cap->name);
551 t += tl;
552 }
553 }
554
555 *(t - 1) = '\0';
556 sendto_one(client_p, "CAPAB :%s", msgbuf);
557 }
558
559 /* sendnick_TS()
560 *
561 * inputs - client (server) to send nick towards
562 * - client to send nick for
563 * output - NONE
564 * side effects - NICK message is sent towards given client_p
565 */
566 void
567 sendnick_TS(struct Client *client_p, struct Client *target_p)
568 {
569 char ubuf[IRCD_BUFSIZE];
570
571 if (!IsClient(target_p))
572 return;
573
574 send_umode(NULL, target_p, 0, SEND_UMODES, ubuf);
575
576 if (ubuf[0] == '\0')
577 {
578 ubuf[0] = '+';
579 ubuf[1] = '\0';
580 }
581
582 if (IsCapable(client_p, CAP_SVS))
583 {
584 if (HasID(target_p) && IsCapable(client_p, CAP_TS6))
585 sendto_one(client_p, ":%s UID %s %d %lu %s %s %s %s %s %s :%s",
586 target_p->servptr->id,
587 target_p->name, target_p->hopcount + 1,
588 (unsigned long) target_p->tsinfo,
589 ubuf, target_p->username, target_p->host,
590 (MyClient(target_p) && IsIPSpoof(target_p)) ?
591 "0" : target_p->sockhost, target_p->id,
592 target_p->svid, target_p->info);
593 else
594 sendto_one(client_p, "NICK %s %d %lu %s %s %s %s %s :%s",
595 target_p->name, target_p->hopcount + 1,
596 (unsigned long) target_p->tsinfo,
597 ubuf, target_p->username, target_p->host,
598 target_p->servptr->name, target_p->svid,
599 target_p->info);
600 }
601 else
602 {
603 if (HasID(target_p) && IsCapable(client_p, CAP_TS6))
604 sendto_one(client_p, ":%s UID %s %d %lu %s %s %s %s %s :%s",
605 target_p->servptr->id,
606 target_p->name, target_p->hopcount + 1,
607 (unsigned long) target_p->tsinfo,
608 ubuf, target_p->username, target_p->host,
609 (MyClient(target_p) && IsIPSpoof(target_p)) ?
610 "0" : target_p->sockhost, target_p->id, target_p->info);
611 else
612 sendto_one(client_p, "NICK %s %d %lu %s %s %s %s :%s",
613 target_p->name, target_p->hopcount + 1,
614 (unsigned long) target_p->tsinfo,
615 ubuf, target_p->username, target_p->host,
616 target_p->servptr->name, target_p->info);
617 }
618
619 if (!EmptyString(target_p->certfp))
620 sendto_one(client_p, ":%s CERTFP %s",
621 ID_or_name(target_p, client_p), target_p->certfp);
622
623 if (target_p->away[0])
624 sendto_one(client_p, ":%s AWAY :%s", ID_or_name(target_p, client_p),
625 target_p->away);
626
627 }
628
629 /*
630 * show_capabilities - show current server capabilities
631 *
632 * inputs - pointer to a struct Client
633 * output - pointer to static string
634 * side effects - build up string representing capabilities of server listed
635 */
636 const char *
637 show_capabilities(const struct Client *target_p)
638 {
639 static char msgbuf[IRCD_BUFSIZE] = "";
640 const dlink_node *ptr = NULL;
641
642 strlcpy(msgbuf, "TS", sizeof(msgbuf));
643
644 DLINK_FOREACH(ptr, cap_list.head)
645 {
646 const struct Capability *cap = ptr->data;
647
648 if (!IsCapable(target_p, cap->cap))
649 continue;
650
651 strlcat(msgbuf, " ", sizeof(msgbuf));
652 strlcat(msgbuf, cap->name, sizeof(msgbuf));
653 }
654
655 return msgbuf;
656 }
657
658 /* make_server()
659 *
660 * inputs - pointer to client struct
661 * output - pointer to struct Server
662 * side effects - add's an Server information block to a client
663 * if it was not previously allocated.
664 */
665 struct Server *
666 make_server(struct Client *client_p)
667 {
668 if (client_p->serv == NULL)
669 client_p->serv = MyMalloc(sizeof(struct Server));
670
671 return client_p->serv;
672 }
673
674 /* server_estab()
675 *
676 * inputs - pointer to a struct Client
677 * output -
678 * side effects -
679 */
680 void
681 server_estab(struct Client *client_p)
682 {
683 struct Client *target_p;
684 struct MaskItem *conf = NULL;
685 char *host;
686 const char *inpath;
687 static char inpath_ip[HOSTLEN * 2 + USERLEN + 6];
688 dlink_node *ptr;
689 #ifdef HAVE_LIBCRYPTO
690 const COMP_METHOD *compression = NULL, *expansion = NULL;
691 #endif
692
693 assert(client_p != NULL);
694
695 strlcpy(inpath_ip, get_client_name(client_p, SHOW_IP), sizeof(inpath_ip));
696
697 inpath = get_client_name(client_p, MASK_IP); /* "refresh" inpath with host */
698 host = client_p->name;
699
700 if ((conf = find_conf_name(&client_p->localClient->confs, host, CONF_SERVER))
701 == NULL)
702 {
703 /* This shouldn't happen, better tell the ops... -A1kmm */
704 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
705 "Warning: Lost connect{} block "
706 "for server %s(this shouldn't happen)!", host);
707 exit_client(client_p, &me, "Lost connect{} block!");
708 return;
709 }
710
711 MyFree(client_p->localClient->passwd);
712 client_p->localClient->passwd = NULL;
713
714 /* Its got identd, since its a server */
715 SetGotId(client_p);
716
717 /* If there is something in the serv_list, it might be this
718 * connecting server..
719 */
720 if (!ServerInfo.hub && serv_list.head)
721 {
722 if (client_p != serv_list.head->data || serv_list.head->next)
723 {
724 ++ServerStats.is_ref;
725 sendto_one(client_p, "ERROR :I'm a leaf not a hub");
726 exit_client(client_p, &me, "I'm a leaf");
727 return;
728 }
729 }
730
731 if (IsUnknown(client_p))
732 {
733 sendto_one(client_p, "PASS %s TS %d %s", conf->spasswd, TS_CURRENT, me.id);
734
735 send_capabilities(client_p, 0);
736
737 sendto_one(client_p, "SERVER %s 1 :%s%s",
738 me.name, ConfigServerHide.hidden ? "(H) " : "", me.info);
739 }
740
741 sendto_one(client_p, "SVINFO %d %d 0 :%lu", TS_CURRENT, TS_MIN,
742 (unsigned long)CurrentTime);
743
744 /* assumption here is if they passed the correct TS version, they also passed an SID */
745 if (IsCapable(client_p, CAP_TS6))
746 hash_add_id(client_p);
747
748 /* XXX Does this ever happen? I don't think so -db */
749 detach_conf(client_p, CONF_OPER);
750
751 /* *WARNING*
752 ** In the following code in place of plain server's
753 ** name we send what is returned by get_client_name
754 ** which may add the "sockhost" after the name. It's
755 ** *very* *important* that there is a SPACE between
756 ** the name and sockhost (if present). The receiving
757 ** server will start the information field from this
758 ** first blank and thus puts the sockhost into info.
759 ** ...a bit tricky, but you have been warned, besides
760 ** code is more neat this way... --msa
761 */
762 client_p->servptr = &me;
763
764 if (IsClosing(client_p))
765 return;
766
767 SetServer(client_p);
768
769 /* Update the capability combination usage counts. -A1kmm */
770 set_chcap_usage_counts(client_p);
771
772 /* Some day, all these lists will be consolidated *sigh* */
773 dlinkAdd(client_p, &client_p->lnode, &me.serv->server_list);
774
775 assert(dlinkFind(&unknown_list, client_p));
776
777 dlink_move_node(&client_p->localClient->lclient_node,
778 &unknown_list, &serv_list);
779
780 Count.myserver++;
781
782 dlinkAdd(client_p, make_dlink_node(), &global_serv_list);
783 hash_add_client(client_p);
784
785 /* doesnt duplicate client_p->serv if allocated this struct already */
786 make_server(client_p);
787
788 /* fixing eob timings.. -gnp */
789 client_p->localClient->firsttime = CurrentTime;
790
791 if (find_matching_name_conf(CONF_SERVICE, client_p->name, NULL, NULL, 0))
792 AddFlag(client_p, FLAGS_SERVICE);
793
794 /* Show the real host/IP to admins */
795 #ifdef HAVE_LIBCRYPTO
796 if (client_p->localClient->fd.ssl)
797 {
798 compression = SSL_get_current_compression(client_p->localClient->fd.ssl);
799 expansion = SSL_get_current_expansion(client_p->localClient->fd.ssl);
800
801 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
802 "Link with %s established: [SSL: %s, Compression/Expansion method: %s/%s] (Capabilities: %s)",
803 inpath_ip, ssl_get_cipher(client_p->localClient->fd.ssl),
804 compression ? SSL_COMP_get_name(compression) : "NONE",
805 expansion ? SSL_COMP_get_name(expansion) : "NONE",
806 show_capabilities(client_p));
807 /* Now show the masked hostname/IP to opers */
808 sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
809 "Link with %s established: [SSL: %s, Compression/Expansion method: %s/%s] (Capabilities: %s)",
810 inpath, ssl_get_cipher(client_p->localClient->fd.ssl),
811 compression ? SSL_COMP_get_name(compression) : "NONE",
812 expansion ? SSL_COMP_get_name(expansion) : "NONE",
813 show_capabilities(client_p));
814 ilog(LOG_TYPE_IRCD, "Link with %s established: [SSL: %s, Compression/Expansion method: %s/%s] (Capabilities: %s)",
815 inpath_ip, ssl_get_cipher(client_p->localClient->fd.ssl),
816 compression ? SSL_COMP_get_name(compression) : "NONE",
817 expansion ? SSL_COMP_get_name(expansion) : "NONE",
818 show_capabilities(client_p));
819 }
820 else
821 #endif
822 {
823 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
824 "Link with %s established: (Capabilities: %s)",
825 inpath_ip, show_capabilities(client_p));
826 /* Now show the masked hostname/IP to opers */
827 sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
828 "Link with %s established: (Capabilities: %s)",
829 inpath, show_capabilities(client_p));
830 ilog(LOG_TYPE_IRCD, "Link with %s established: (Capabilities: %s)",
831 inpath_ip, show_capabilities(client_p));
832 }
833
834 fd_note(&client_p->localClient->fd, "Server: %s", client_p->name);
835
836 /* Old sendto_serv_but_one() call removed because we now
837 ** need to send different names to different servers
838 ** (domain name matching) Send new server to other servers.
839 */
840 DLINK_FOREACH(ptr, serv_list.head)
841 {
842 target_p = ptr->data;
843
844 if (target_p == client_p)
845 continue;
846
847 if (IsCapable(target_p, CAP_TS6) && HasID(client_p))
848 sendto_one(target_p, ":%s SID %s 2 %s :%s%s",
849 me.id, client_p->name, client_p->id,
850 IsHidden(client_p) ? "(H) " : "",
851 client_p->info);
852 else
853 sendto_one(target_p,":%s SERVER %s 2 :%s%s",
854 me.name, client_p->name,
855 IsHidden(client_p) ? "(H) " : "",
856 client_p->info);
857 }
858
859 /*
860 * Pass on my client information to the new server
861 *
862 * First, pass only servers (idea is that if the link gets
863 * cancelled beacause the server was already there,
864 * there are no NICK's to be cancelled...). Of course,
865 * if cancellation occurs, all this info is sent anyway,
866 * and I guess the link dies when a read is attempted...? --msa
867 *
868 * Note: Link cancellation to occur at this point means
869 * that at least two servers from my fragment are building
870 * up connection this other fragment at the same time, it's
871 * a race condition, not the normal way of operation...
872 *
873 * ALSO NOTE: using the get_client_name for server names--
874 * see previous *WARNING*!!! (Also, original inpath
875 * is destroyed...)
876 */
877
878 DLINK_FOREACH_PREV(ptr, global_serv_list.tail)
879 {
880 target_p = ptr->data;
881
882 /* target_p->from == target_p for target_p == client_p */
883 if (IsMe(target_p) || target_p->from == client_p)
884 continue;
885
886 if (IsCapable(client_p, CAP_TS6))
887 {
888 if (HasID(target_p))
889 sendto_one(client_p, ":%s SID %s %d %s :%s%s",
890 ID(target_p->servptr), target_p->name, target_p->hopcount+1,
891 target_p->id, IsHidden(target_p) ? "(H) " : "",
892 target_p->info);
893 else /* introducing non-ts6 server */
894 sendto_one(client_p, ":%s SERVER %s %d :%s%s",
895 ID(target_p->servptr), target_p->name, target_p->hopcount+1,
896 IsHidden(target_p) ? "(H) " : "", target_p->info);
897 }
898 else
899 sendto_one(client_p, ":%s SERVER %s %d :%s%s",
900 target_p->servptr->name, target_p->name, target_p->hopcount+1,
901 IsHidden(target_p) ? "(H) " : "", target_p->info);
902
903 if (HasFlag(target_p, FLAGS_EOB))
904 sendto_one(client_p, ":%s EOB", ID_or_name(target_p, client_p));
905 }
906
907 server_burst(client_p);
908 }
909
910 /* server_burst()
911 *
912 * inputs - struct Client pointer server
913 * -
914 * output - none
915 * side effects - send a server burst
916 * bugs - still too long
917 */
918 static void
919 server_burst(struct Client *client_p)
920 {
921 /* Send it in the shortened format with the TS, if
922 ** it's a TS server; walk the list of channels, sending
923 ** all the nicks that haven't been sent yet for each
924 ** channel, then send the channel itself -- it's less
925 ** obvious than sending all nicks first, but on the
926 ** receiving side memory will be allocated more nicely
927 ** saving a few seconds in the handling of a split
928 ** -orabidoo
929 */
930
931 burst_all(client_p);
932
933 /* EOB stuff is now in burst_all */
934 /* Always send a PING after connect burst is done */
935 sendto_one(client_p, "PING :%s", ID_or_name(&me, client_p));
936 }
937
938 /* burst_all()
939 *
940 * inputs - pointer to server to send burst to
941 * output - NONE
942 * side effects - complete burst of channels/nicks is sent to client_p
943 */
944 static void
945 burst_all(struct Client *client_p)
946 {
947 dlink_node *ptr = NULL;
948
949 DLINK_FOREACH(ptr, global_channel_list.head)
950 {
951 struct Channel *chptr = ptr->data;
952
953 if (dlink_list_length(&chptr->members) != 0)
954 {
955 burst_members(client_p, chptr);
956 send_channel_modes(client_p, chptr);
957
958 if (IsCapable(client_p, CAP_TBURST))
959 send_tb(client_p, chptr);
960 }
961 }
962
963 /* also send out those that are not on any channel
964 */
965 DLINK_FOREACH(ptr, global_client_list.head)
966 {
967 struct Client *target_p = ptr->data;
968
969 if (!HasFlag(target_p, FLAGS_BURSTED) && target_p->from != client_p)
970 sendnick_TS(client_p, target_p);
971
972 DelFlag(target_p, FLAGS_BURSTED);
973 }
974
975 if (IsCapable(client_p, CAP_EOB))
976 sendto_one(client_p, ":%s EOB", ID_or_name(&me, client_p));
977 }
978
979 /*
980 * send_tb
981 *
982 * inputs - pointer to Client
983 * - pointer to channel
984 * output - NONE
985 * side effects - Called on a server burst when
986 * server is CAP_TBURST capable
987 */
988 static void
989 send_tb(struct Client *client_p, struct Channel *chptr)
990 {
991 /*
992 * We may also send an empty topic here, but only if topic_time isn't 0,
993 * i.e. if we had a topic that got unset. This is required for syncing
994 * topics properly.
995 *
996 * Imagine the following scenario: Our downlink introduces a channel
997 * to us with a TS that is equal to ours, but the channel topic on
998 * their side got unset while the servers were in splitmode, which means
999 * their 'topic' is newer. They simply wanted to unset it, so we have to
1000 * deal with it in a more sophisticated fashion instead of just resetting
1001 * it to their old topic they had before. Read m_tburst.c:ms_tburst
1002 * for further information -Michael
1003 */
1004 if (chptr->topic_time != 0)
1005 sendto_one(client_p, ":%s TBURST %lu %s %lu %s :%s",
1006 ID_or_name(&me, client_p),
1007 (unsigned long)chptr->channelts, chptr->chname,
1008 (unsigned long)chptr->topic_time,
1009 chptr->topic_info,
1010 chptr->topic);
1011 }
1012
1013 /* burst_members()
1014 *
1015 * inputs - pointer to server to send members to
1016 * - dlink_list pointer to membership list to send
1017 * output - NONE
1018 * side effects -
1019 */
1020 static void
1021 burst_members(struct Client *client_p, struct Channel *chptr)
1022 {
1023 struct Client *target_p;
1024 struct Membership *ms;
1025 dlink_node *ptr;
1026
1027 DLINK_FOREACH(ptr, chptr->members.head)
1028 {
1029 ms = ptr->data;
1030 target_p = ms->client_p;
1031
1032 if (!HasFlag(target_p, FLAGS_BURSTED))
1033 {
1034 AddFlag(target_p, FLAGS_BURSTED);
1035
1036 if (target_p->from != client_p)
1037 sendnick_TS(client_p, target_p);
1038 }
1039 }
1040 }
1041
1042 /* New server connection code
1043 * Based upon the stuff floating about in s_bsd.c
1044 * -- adrian
1045 */
1046
1047 /* serv_connect() - initiate a server connection
1048 *
1049 * inputs - pointer to conf
1050 * - pointer to client doing the connect
1051 * output -
1052 * side effects -
1053 *
1054 * This code initiates a connection to a server. It first checks to make
1055 * sure the given server exists. If this is the case, it creates a socket,
1056 * creates a client, saves the socket information in the client, and
1057 * initiates a connection to the server through comm_connect_tcp(). The
1058 * completion of this goes through serv_completed_connection().
1059 *
1060 * We return 1 if the connection is attempted, since we don't know whether
1061 * it suceeded or not, and 0 if it fails in here somewhere.
1062 */
1063 int
1064 serv_connect(struct MaskItem *conf, struct Client *by)
1065 {
1066 struct Client *client_p;
1067 char buf[HOSTIPLEN + 1];
1068
1069 /* conversion structs */
1070 struct sockaddr_in *v4;
1071 /* Make sure conf is useful */
1072 assert(conf != NULL);
1073
1074
1075 getnameinfo((struct sockaddr *)&conf->addr, conf->addr.ss_len,
1076 buf, sizeof(buf), NULL, 0, NI_NUMERICHOST);
1077 ilog(LOG_TYPE_IRCD, "Connect to %s[%s] @%s", conf->name, conf->host,
1078 buf);
1079
1080 /* Still processing a DNS lookup? -> exit */
1081 if (conf->dns_pending)
1082 {
1083 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1084 "Error connecting to %s: DNS lookup for connect{} in progress.",
1085 conf->name);
1086 return (0);
1087 }
1088
1089 if (conf->dns_failed)
1090 {
1091 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1092 "Error connecting to %s: DNS lookup for connect{} failed.",
1093 conf->name);
1094 return (0);
1095 }
1096
1097 /* Make sure this server isn't already connected
1098 * Note: conf should ALWAYS be a valid C: line
1099 */
1100 if ((client_p = hash_find_server(conf->name)) != NULL)
1101 {
1102 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1103 "Server %s already present from %s",
1104 conf->name, get_client_name(client_p, SHOW_IP));
1105 sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
1106 "Server %s already present from %s",
1107 conf->name, get_client_name(client_p, MASK_IP));
1108 if (by && IsClient(by) && !MyClient(by))
1109 sendto_one(by, ":%s NOTICE %s :Server %s already present from %s",
1110 me.name, by->name, conf->name,
1111 get_client_name(client_p, MASK_IP));
1112 return 0;
1113 }
1114
1115 /* Create a local client */
1116 client_p = make_client(NULL);
1117
1118 /* Copy in the server, hostname, fd */
1119 strlcpy(client_p->name, conf->name, sizeof(client_p->name));
1120 strlcpy(client_p->host, conf->host, sizeof(client_p->host));
1121
1122 /* We already converted the ip once, so lets use it - stu */
1123 strlcpy(client_p->sockhost, buf, sizeof(client_p->sockhost));
1124
1125 /* create a socket for the server connection */
1126 if (comm_open(&client_p->localClient->fd, conf->addr.ss.ss_family,
1127 SOCK_STREAM, 0, NULL) < 0)
1128 {
1129 /* Eek, failure to create the socket */
1130 report_error(L_ALL, "opening stream socket to %s: %s",
1131 conf->name, errno);
1132 SetDead(client_p);
1133 exit_client(client_p, &me, "Connection failed");
1134 return 0;
1135 }
1136
1137 /* servernames are always guaranteed under HOSTLEN chars */
1138 fd_note(&client_p->localClient->fd, "Server: %s", conf->name);
1139
1140 /* Attach config entries to client here rather than in
1141 * serv_connect_callback(). This to avoid null pointer references.
1142 */
1143 if (!attach_connect_block(client_p, conf->name, conf->host))
1144 {
1145 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1146 "Host %s is not enabled for connecting: no connect{} block",
1147 conf->name);
1148 if (by && IsClient(by) && !MyClient(by))
1149 sendto_one(by, ":%s NOTICE %s :Connect to host %s failed.",
1150 me.name, by->name, client_p->name);
1151 SetDead(client_p);
1152 exit_client(client_p, client_p, "Connection failed");
1153 return 0;
1154 }
1155
1156 /* at this point we have a connection in progress and C/N lines
1157 * attached to the client, the socket info should be saved in the
1158 * client and it should either be resolved or have a valid address.
1159 *
1160 * The socket has been connected or connect is in progress.
1161 */
1162 make_server(client_p);
1163
1164 if (by && IsClient(by))
1165 strlcpy(client_p->serv->by, by->name, sizeof(client_p->serv->by));
1166 else
1167 strlcpy(client_p->serv->by, "AutoConn.", sizeof(client_p->serv->by));
1168
1169 SetConnecting(client_p);
1170 dlinkAdd(client_p, &client_p->node, &global_client_list);
1171 /* from def_fam */
1172 client_p->localClient->aftype = conf->aftype;
1173
1174 /* Now, initiate the connection */
1175 /* XXX assume that a non 0 type means a specific bind address
1176 * for this connect.
1177 */
1178 switch (conf->aftype)
1179 {
1180 case AF_INET:
1181 v4 = (struct sockaddr_in*)&conf->bind;
1182 if (v4->sin_addr.s_addr != 0)
1183 {
1184 struct irc_ssaddr ipn;
1185 memset(&ipn, 0, sizeof(struct irc_ssaddr));
1186 ipn.ss.ss_family = AF_INET;
1187 ipn.ss_port = 0;
1188 memcpy(&ipn, &conf->bind, sizeof(struct irc_ssaddr));
1189 comm_connect_tcp(&client_p->localClient->fd, conf->host, conf->port,
1190 (struct sockaddr *)&ipn, ipn.ss_len,
1191 serv_connect_callback, client_p, conf->aftype,
1192 CONNECTTIMEOUT);
1193 }
1194 else if (ServerInfo.specific_ipv4_vhost)
1195 {
1196 struct irc_ssaddr ipn;
1197 memset(&ipn, 0, sizeof(struct irc_ssaddr));
1198 ipn.ss.ss_family = AF_INET;
1199 ipn.ss_port = 0;
1200 memcpy(&ipn, &ServerInfo.ip, sizeof(struct irc_ssaddr));
1201 comm_connect_tcp(&client_p->localClient->fd, conf->host, conf->port,
1202 (struct sockaddr *)&ipn, ipn.ss_len,
1203 serv_connect_callback, client_p, conf->aftype,
1204 CONNECTTIMEOUT);
1205 }
1206 else
1207 comm_connect_tcp(&client_p->localClient->fd, conf->host, conf->port,
1208 NULL, 0, serv_connect_callback, client_p, conf->aftype,
1209 CONNECTTIMEOUT);
1210 break;
1211 #ifdef IPV6
1212 case AF_INET6:
1213 {
1214 struct irc_ssaddr ipn;
1215 struct sockaddr_in6 *v6;
1216 struct sockaddr_in6 *v6conf;
1217
1218 memset(&ipn, 0, sizeof(struct irc_ssaddr));
1219 v6conf = (struct sockaddr_in6 *)&conf->bind;
1220 v6 = (struct sockaddr_in6 *)&ipn;
1221
1222 if (memcmp(&v6conf->sin6_addr, &v6->sin6_addr, sizeof(struct in6_addr)) != 0)
1223 {
1224 memcpy(&ipn, &conf->bind, sizeof(struct irc_ssaddr));
1225 ipn.ss.ss_family = AF_INET6;
1226 ipn.ss_port = 0;
1227 comm_connect_tcp(&client_p->localClient->fd,
1228 conf->host, conf->port,
1229 (struct sockaddr *)&ipn, ipn.ss_len,
1230 serv_connect_callback, client_p,
1231 conf->aftype, CONNECTTIMEOUT);
1232 }
1233 else if (ServerInfo.specific_ipv6_vhost)
1234 {
1235 memcpy(&ipn, &ServerInfo.ip6, sizeof(struct irc_ssaddr));
1236 ipn.ss.ss_family = AF_INET6;
1237 ipn.ss_port = 0;
1238 comm_connect_tcp(&client_p->localClient->fd,
1239 conf->host, conf->port,
1240 (struct sockaddr *)&ipn, ipn.ss_len,
1241 serv_connect_callback, client_p,
1242 conf->aftype, CONNECTTIMEOUT);
1243 }
1244 else
1245 comm_connect_tcp(&client_p->localClient->fd,
1246 conf->host, conf->port,
1247 NULL, 0, serv_connect_callback, client_p,
1248 conf->aftype, CONNECTTIMEOUT);
1249 }
1250 #endif
1251 }
1252 return 1;
1253 }
1254
1255 #ifdef HAVE_LIBCRYPTO
1256 static void
1257 finish_ssl_server_handshake(struct Client *client_p)
1258 {
1259 struct MaskItem *conf = NULL;
1260
1261 conf = find_conf_name(&client_p->localClient->confs,
1262 client_p->name, CONF_SERVER);
1263 if (conf == NULL)
1264 {
1265 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1266 "Lost connect{} block for %s", get_client_name(client_p, HIDE_IP));
1267 sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
1268 "Lost connect{} block for %s", get_client_name(client_p, MASK_IP));
1269
1270 exit_client(client_p, &me, "Lost connect{} block");
1271 return;
1272 }
1273
1274 sendto_one(client_p, "PASS %s TS %d %s", conf->spasswd, TS_CURRENT, me.id);
1275
1276 send_capabilities(client_p, 0);
1277
1278 sendto_one(client_p, "SERVER %s 1 :%s%s",
1279 me.name, ConfigServerHide.hidden ? "(H) " : "",
1280 me.info);
1281
1282 /* If we've been marked dead because a send failed, just exit
1283 * here now and save everyone the trouble of us ever existing.
1284 */
1285 if (IsDead(client_p))
1286 {
1287 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1288 "%s[%s] went dead during handshake",
1289 client_p->name,
1290 client_p->host);
1291 sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
1292 "%s went dead during handshake", client_p->name);
1293 return;
1294 }
1295
1296 /* don't move to serv_list yet -- we haven't sent a burst! */
1297 /* If we get here, we're ok, so lets start reading some data */
1298 comm_setselect(&client_p->localClient->fd, COMM_SELECT_READ, read_packet, client_p, 0);
1299 }
1300
1301 static void
1302 ssl_server_handshake(fde_t *fd, struct Client *client_p)
1303 {
1304 X509 *cert = NULL;
1305 int ret = 0;
1306
1307 if ((ret = SSL_connect(client_p->localClient->fd.ssl)) <= 0)
1308 {
1309 switch (SSL_get_error(client_p->localClient->fd.ssl, ret))
1310 {
1311 case SSL_ERROR_WANT_WRITE:
1312 comm_setselect(&client_p->localClient->fd, COMM_SELECT_WRITE,
1313 (PF *)ssl_server_handshake, client_p, 0);
1314 return;
1315 case SSL_ERROR_WANT_READ:
1316 comm_setselect(&client_p->localClient->fd, COMM_SELECT_READ,
1317 (PF *)ssl_server_handshake, client_p, 0);
1318 return;
1319 default:
1320 {
1321 const char *sslerr = ERR_error_string(ERR_get_error(), NULL);
1322 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1323 "Error connecting to %s: %s", client_p->name,
1324 sslerr ? sslerr : "unknown SSL error");
1325 exit_client(client_p, client_p, "Error during SSL handshake");
1326 return;
1327 }
1328 }
1329 }
1330
1331 if ((cert = SSL_get_peer_certificate(client_p->localClient->fd.ssl)))
1332 {
1333 int res = SSL_get_verify_result(client_p->localClient->fd.ssl);
1334 char buf[EVP_MAX_MD_SIZE * 2 + 1] = { '\0' };
1335 unsigned char md[EVP_MAX_MD_SIZE] = { '\0' };
1336
1337 if (res == X509_V_OK || res == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN ||
1338 res == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE ||
1339 res == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT)
1340 {
1341 unsigned int i = 0, n = 0;
1342
1343 if (X509_digest(cert, EVP_sha256(), md, &n))
1344 {
1345 for (; i < n; ++i)
1346 snprintf(buf + 2 * i, 3, "%02X", md[i]);
1347 client_p->certfp = xstrdup(buf);
1348 }
1349 }
1350 else
1351 ilog(LOG_TYPE_IRCD, "Server %s!%s@%s gave bad SSL client certificate: %d",
1352 client_p->name, client_p->username, client_p->host, res);
1353 X509_free(cert);
1354 }
1355
1356 finish_ssl_server_handshake(client_p);
1357 }
1358
1359 static void
1360 ssl_connect_init(struct Client *client_p, struct MaskItem *conf, fde_t *fd)
1361 {
1362 if ((client_p->localClient->fd.ssl = SSL_new(ServerInfo.client_ctx)) == NULL)
1363 {
1364 ilog(LOG_TYPE_IRCD, "SSL_new() ERROR! -- %s",
1365 ERR_error_string(ERR_get_error(), NULL));
1366 SetDead(client_p);
1367 exit_client(client_p, client_p, "SSL_new failed");
1368 return;
1369 }
1370
1371 SSL_set_fd(fd->ssl, fd->fd);
1372
1373 if (!EmptyString(conf->cipher_list))
1374 SSL_set_cipher_list(client_p->localClient->fd.ssl, conf->cipher_list);
1375
1376 ssl_server_handshake(NULL, client_p);
1377 }
1378 #endif
1379
1380 /* serv_connect_callback() - complete a server connection.
1381 *
1382 * This routine is called after the server connection attempt has
1383 * completed. If unsucessful, an error is sent to ops and the client
1384 * is closed. If sucessful, it goes through the initialisation/check
1385 * procedures, the capabilities are sent, and the socket is then
1386 * marked for reading.
1387 */
1388 static void
1389 serv_connect_callback(fde_t *fd, int status, void *data)
1390 {
1391 struct Client *client_p = data;
1392 struct MaskItem *conf = NULL;
1393
1394 /* First, make sure its a real client! */
1395 assert(client_p != NULL);
1396 assert(&client_p->localClient->fd == fd);
1397
1398 /* Next, for backward purposes, record the ip of the server */
1399 memcpy(&client_p->localClient->ip, &fd->connect.hostaddr,
1400 sizeof(struct irc_ssaddr));
1401 /* Check the status */
1402 if (status != COMM_OK)
1403 {
1404 /* We have an error, so report it and quit
1405 * Admins get to see any IP, mere opers don't *sigh*
1406 */
1407 if (ConfigServerHide.hide_server_ips)
1408 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1409 "Error connecting to %s: %s",
1410 client_p->name, comm_errstr(status));
1411 else
1412 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1413 "Error connecting to %s[%s]: %s", client_p->name,
1414 client_p->host, comm_errstr(status));
1415
1416 sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
1417 "Error connecting to %s: %s",
1418 client_p->name, comm_errstr(status));
1419
1420 /* If a fd goes bad, call dead_link() the socket is no
1421 * longer valid for reading or writing.
1422 */
1423 dead_link_on_write(client_p, 0);
1424 return;
1425 }
1426
1427 /* COMM_OK, so continue the connection procedure */
1428 /* Get the C/N lines */
1429 conf = find_conf_name(&client_p->localClient->confs,
1430 client_p->name, CONF_SERVER);
1431 if (conf == NULL)
1432 {
1433 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1434 "Lost connect{} block for %s", get_client_name(client_p, HIDE_IP));
1435 sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
1436 "Lost connect{} block for %s", get_client_name(client_p, MASK_IP));
1437
1438 exit_client(client_p, &me, "Lost connect{} block");
1439 return;
1440 }
1441
1442 /* Next, send the initial handshake */
1443 SetHandshake(client_p);
1444
1445 #ifdef HAVE_LIBCRYPTO
1446 if (IsConfSSL(conf))
1447 {
1448 ssl_connect_init(client_p, conf, fd);
1449 return;
1450 }
1451 #endif
1452
1453 sendto_one(client_p, "PASS %s TS %d %s", conf->spasswd, TS_CURRENT, me.id);
1454
1455 send_capabilities(client_p, 0);
1456
1457 sendto_one(client_p, "SERVER %s 1 :%s%s", me.name,
1458 ConfigServerHide.hidden ? "(H) " : "", me.info);
1459
1460 /* If we've been marked dead because a send failed, just exit
1461 * here now and save everyone the trouble of us ever existing.
1462 */
1463 if (IsDead(client_p))
1464 {
1465 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
1466 "%s[%s] went dead during handshake",
1467 client_p->name,
1468 client_p->host);
1469 sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
1470 "%s went dead during handshake", client_p->name);
1471 return;
1472 }
1473
1474 /* don't move to serv_list yet -- we haven't sent a burst! */
1475 /* If we get here, we're ok, so lets start reading some data */
1476 comm_setselect(fd, COMM_SELECT_READ, read_packet, client_p, 0);
1477 }
1478
1479 struct Client *
1480 find_servconn_in_progress(const char *name)
1481 {
1482 dlink_node *ptr;
1483 struct Client *cptr;
1484
1485 DLINK_FOREACH(ptr, unknown_list.head)
1486 {
1487 cptr = ptr->data;
1488
1489 if (cptr && cptr->name[0])
1490 if (!match(name, cptr->name))
1491 return cptr;
1492 }
1493
1494 return NULL;
1495 }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision