/[svn]/ircd-hybrid-8/src/s_serv.c
ViewVC logotype

Contents of /ircd-hybrid-8/src/s_serv.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1545 - (show annotations)
Sun Sep 30 15:21:59 2012 UTC (7 years, 9 months ago) by michael
File MIME type: text/x-chdr
File size: 44366 byte(s)
- write_links_file(): minor cleanups. Also remove useless assert()

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

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28