]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/utils.cpp
Attempt to revert r11734
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / utils.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "socket.h"
16 #include "xline.h"
17 #include "../transport.h"
18 #include "socketengine.h"
19
20 #include "main.h"
21 #include "utils.h"
22 #include "treeserver.h"
23 #include "link.h"
24 #include "treesocket.h"
25 #include "resolvers.h"
26
27 /* $ModDep: m_spanningtree/resolvers.h m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/link.h m_spanningtree/treesocket.h */
28
29 /* Create server sockets off a listener. */
30 void ServerSocketListener::OnAcceptReady(int newsock)
31 {
32         bool found = false;
33         int port;
34         std::string incomingip;
35         irc::sockets::satoap(&client, incomingip, port);
36         char *ip = const_cast<char*>(incomingip.c_str());
37
38         found = (std::find(Utils->ValidIPs.begin(), Utils->ValidIPs.end(), ip) != Utils->ValidIPs.end());
39         if (!found)
40         {
41                 for (std::vector<std::string>::iterator i = Utils->ValidIPs.begin(); i != Utils->ValidIPs.end(); i++)
42                 {
43                         if (*i == "*" || irc::sockets::MatchCIDR(ip, *i))
44                         {
45                                 found = true;
46                                 break;
47                         }
48                 }
49
50                 if (!found)
51                 {
52                         this->ServerInstance->SNO->WriteToSnoMask('l', "Server connection from %s denied (no link blocks with that IP address)", ip);
53                         ServerInstance->SE->Close(newsock);
54                         return;
55                 }
56         }
57
58         if (this->GetIOHook())
59         {
60                 this->GetIOHook()->OnRawSocketAccept(newsock, &client, &server);
61         }
62
63         /* we don't need a pointer to this, creating it stores it in the necessary places */
64         new TreeSocket(this->Utils, this->ServerInstance, newsock, ip, this->GetIOHook());
65         return;
66 }
67
68 /** Yay for fast searches!
69  * This is hundreds of times faster than recursion
70  * or even scanning a linked list, especially when
71  * there are more than a few servers to deal with.
72  * (read as: lots).
73  */
74 TreeServer* SpanningTreeUtilities::FindServer(const std::string &ServerName)
75 {
76         if (this->ServerInstance->IsSID(ServerName))
77                 return this->FindServerID(ServerName);
78
79         server_hash::iterator iter = serverlist.find(ServerName.c_str());
80         if (iter != serverlist.end())
81         {
82                 return iter->second;
83         }
84         else
85         {
86                 return NULL;
87         }
88 }
89
90 /** Returns the locally connected server we must route a
91  * message through to reach server 'ServerName'. This
92  * only applies to one-to-one and not one-to-many routing.
93  * See the comments for the constructor of TreeServer
94  * for more details.
95  */
96 TreeServer* SpanningTreeUtilities::BestRouteTo(const std::string &ServerName)
97 {
98         if (ServerName.c_str() == TreeRoot->GetName() || ServerName == ServerInstance->Config->GetSID())
99                 return NULL;
100         TreeServer* Found = FindServer(ServerName);
101         if (Found)
102         {
103                 return Found->GetRoute();
104         }
105         else
106         {
107                 // Cheat a bit. This allows for (better) working versions of routing commands with nick based prefixes, without hassle
108                 User *u = ServerInstance->FindNick(ServerName);
109                 if (u)
110                 {
111                         Found = FindServer(u->server);
112                         if (Found)
113                                 return Found->GetRoute();
114                 }
115
116                 return NULL;
117         }
118 }
119
120 /** Find the first server matching a given glob mask.
121  * Theres no find-using-glob method of hash_map [awwww :-(]
122  * so instead, we iterate over the list using an iterator
123  * and match each one until we get a hit. Yes its slow,
124  * deal with it.
125  */
126 TreeServer* SpanningTreeUtilities::FindServerMask(const std::string &ServerName)
127 {
128         for (server_hash::iterator i = serverlist.begin(); i != serverlist.end(); i++)
129         {
130                 if (InspIRCd::Match(i->first,ServerName))
131                         return i->second;
132         }
133         return NULL;
134 }
135
136 TreeServer* SpanningTreeUtilities::FindServerID(const std::string &id)
137 {
138         server_hash::iterator iter = sidlist.find(id);
139         if (iter != sidlist.end())
140                 return iter->second;
141         else
142                 return NULL;
143 }
144
145 /* A convenient wrapper that returns true if a server exists */
146 bool SpanningTreeUtilities::IsServer(const std::string &ServerName)
147 {
148         return (FindServer(ServerName) != NULL);
149 }
150
151 SpanningTreeUtilities::SpanningTreeUtilities(InspIRCd* Instance, ModuleSpanningTree* C) : ServerInstance(Instance), Creator(C)
152 {
153         Bindings.clear();
154
155         ServerInstance->Logs->Log("m_spanningtree",DEBUG,"***** Using SID for hash: %s *****", ServerInstance->Config->GetSID().c_str());
156
157         this->TreeRoot = new TreeServer(this, ServerInstance, ServerInstance->Config->ServerName, ServerInstance->Config->ServerDesc, ServerInstance->Config->GetSID());
158         this->ServerUser = new FakeUser(ServerInstance, TreeRoot->GetID());
159
160         this->ReadConfiguration(true);
161 }
162
163 SpanningTreeUtilities::~SpanningTreeUtilities()
164 {
165         for (unsigned int i = 0; i < Bindings.size(); i++)
166         {
167                 delete Bindings[i];
168         }
169
170         while (TreeRoot->ChildCount())
171         {
172                 TreeServer* child_server = TreeRoot->GetChild(0);
173                 if (child_server)
174                 {
175                         TreeSocket* sock = child_server->GetSocket();
176                         ServerInstance->SE->DelFd(sock);
177                         sock->Close();
178                 }
179         }
180         
181         // This avoids a collision on reload
182         ServerUser->uuid = TreeRoot->GetID();
183         delete TreeRoot;
184         delete ServerUser;
185         ServerInstance->BufferedSocketCull();
186 }
187
188 void SpanningTreeUtilities::AddThisServer(TreeServer* server, TreeServerList &list)
189 {
190         if (list.find(server) == list.end())
191                 list[server] = server;
192 }
193
194 /* returns a list of DIRECT servernames for a specific channel */
195 void SpanningTreeUtilities::GetListOfServersForChannel(Channel* c, TreeServerList &list, char status, const CUList &exempt_list)
196 {
197         const UserMembList *ulist = c->GetUsers();
198
199         for (UserMembCIter i = ulist->begin(); i != ulist->end(); i++)
200         {
201                 if (IS_LOCAL(i->first))
202                         continue;
203
204                 if (status && !strchr(c->GetAllPrefixChars(i->first), status))
205                         continue;
206
207                 if (exempt_list.find(i->first) == exempt_list.end())
208                 {
209                         TreeServer* best = this->BestRouteTo(i->first->server);
210                         if (best)
211                                 AddThisServer(best,list);
212                 }
213         }
214         return;
215 }
216
217 bool SpanningTreeUtilities::DoOneToAllButSenderRaw(const std::string &data, const std::string &omit, const std::string &prefix, const irc::string &command, parameterlist &params)
218 {
219         char pfx = 0;
220         TreeServer* omitroute = this->BestRouteTo(omit);
221         if ((command == "NOTICE") || (command == "PRIVMSG"))
222         {
223                 if (params.size() >= 2)
224                 {
225                         /* Prefixes */
226                         if (ServerInstance->Modes->FindPrefix(params[0][0]))
227                         {
228                                 pfx = params[0][0];
229                                 params[0] = params[0].substr(1, params[0].length()-1);
230                         }
231                         if ((*(params[0].c_str()) != '#') && (*(params[0].c_str()) != '$'))
232                         {
233                                 // special routing for private messages/notices
234                                 User* d = ServerInstance->FindNick(params[0]);
235                                 if (d)
236                                 {
237                                         parameterlist par;
238                                         par.push_back(params[0]);
239                                         par.push_back(":"+params[1]);
240                                         this->DoOneToOne(prefix,command.c_str(),par,d->server);
241                                         return true;
242                                 }
243                         }
244                         else if (*(params[0].c_str()) == '$')
245                         {
246                                 parameterlist par;
247                                 par.push_back(params[0]);
248                                 par.push_back(":"+params[1]);
249                                 this->DoOneToAllButSender(prefix,command.c_str(),par,omitroute->GetName());
250                                 return true;
251                         }
252                         else
253                         {
254                                 Channel* c = ServerInstance->FindChan(params[0]);
255                                 User* u = ServerInstance->FindNick(prefix);
256                                 if (c)
257                                 {
258                                         CUList elist;
259                                         TreeServerList list;
260                                         FOREACH_MOD(I_OnBuildExemptList, OnBuildExemptList((command == "PRIVMSG" ? MSG_PRIVMSG : MSG_NOTICE), c, u, pfx, elist, params[1]));
261                                         GetListOfServersForChannel(c,list,pfx,elist);
262
263                                         for (TreeServerList::iterator i = list.begin(); i != list.end(); i++)
264                                         {
265                                                 TreeSocket* Sock = i->second->GetSocket();
266                                                 if ((Sock) && (i->second->GetName() != omit) && (omitroute != i->second))
267                                                 {
268                                                         Sock->WriteLine(data);
269                                                 }
270                                         }
271                                         return true;
272                                 }
273                         }
274                 }
275         }
276         unsigned int items =this->TreeRoot->ChildCount();
277         for (unsigned int x = 0; x < items; x++)
278         {
279                 TreeServer* Route = this->TreeRoot->GetChild(x);
280                 if ((Route) && (Route->GetSocket()) && (Route->GetName() != omit) && (omitroute != Route))
281                 {
282                         TreeSocket* Sock = Route->GetSocket();
283                         if (Sock)
284                                 Sock->WriteLine(data);
285                 }
286         }
287         return true;
288 }
289
290 bool SpanningTreeUtilities::DoOneToAllButSender(const std::string &prefix, const std::string &command, parameterlist &params, std::string omit)
291 {
292         TreeServer* omitroute = this->BestRouteTo(omit);
293         std::string FullLine = ":" + prefix + " " + command;
294         unsigned int words = params.size();
295         for (unsigned int x = 0; x < words; x++)
296         {
297                 FullLine = FullLine + " " + params[x];
298         }
299         unsigned int items = this->TreeRoot->ChildCount();
300         for (unsigned int x = 0; x < items; x++)
301         {
302                 TreeServer* Route = this->TreeRoot->GetChild(x);
303                 // Send the line IF:
304                 // The route has a socket (its a direct connection)
305                 // The route isnt the one to be omitted
306                 // The route isnt the path to the one to be omitted
307                 if ((Route) && (Route->GetSocket()) && (Route->GetName() != omit) && (omitroute != Route))
308                 {
309                         TreeSocket* Sock = Route->GetSocket();
310                         if (Sock)
311                                 Sock->WriteLine(FullLine);
312                 }
313         }
314         return true;
315 }
316
317 bool SpanningTreeUtilities::DoOneToMany(const std::string &prefix, const std::string &command, parameterlist &params)
318 {
319         std::string FullLine = ":" + prefix + " " + command;
320         unsigned int words = params.size();
321         for (unsigned int x = 0; x < words; x++)
322         {
323                 FullLine = FullLine + " " + params[x];
324         }
325         unsigned int items = this->TreeRoot->ChildCount();
326         for (unsigned int x = 0; x < items; x++)
327         {
328                 TreeServer* Route = this->TreeRoot->GetChild(x);
329                 if (Route && Route->GetSocket())
330                 {
331                         TreeSocket* Sock = Route->GetSocket();
332                         if (Sock)
333                                 Sock->WriteLine(FullLine);
334                 }
335         }
336         return true;
337 }
338
339 bool SpanningTreeUtilities::DoOneToMany(const char* prefix, const char* command, parameterlist &params)
340 {
341         std::string spfx = prefix;
342         std::string scmd = command;
343         return this->DoOneToMany(spfx, scmd, params);
344 }
345
346 bool SpanningTreeUtilities::DoOneToAllButSender(const char* prefix, const char* command, parameterlist &params, std::string omit)
347 {
348         std::string spfx = prefix;
349         std::string scmd = command;
350         return this->DoOneToAllButSender(spfx, scmd, params, omit);
351 }
352
353 bool SpanningTreeUtilities::DoOneToOne(const std::string &prefix, const std::string &command, parameterlist &params, std::string target)
354 {
355         TreeServer* Route = this->BestRouteTo(target);
356         if (Route)
357         {
358                 std::string FullLine = ":" + prefix + " " + command;
359                 unsigned int words = params.size();
360                 for (unsigned int x = 0; x < words; x++)
361                 {
362                         FullLine = FullLine + " " + params[x];
363                 }
364                 if (Route && Route->GetSocket())
365                 {
366                         TreeSocket* Sock = Route->GetSocket();
367                         if (Sock)
368                                 Sock->WriteLine(FullLine);
369                 }
370                 return true;
371         }
372         else
373         {
374                 return false;
375         }
376 }
377
378 void SpanningTreeUtilities::RefreshIPCache()
379 {
380         ValidIPs.clear();
381         for (std::vector<Link>::iterator L = LinkBlocks.begin(); L != LinkBlocks.end(); L++)
382         {
383                 if (L->IPAddr.empty() || L->RecvPass.empty() || L->SendPass.empty() || L->Name.empty() || !L->Port)
384                 {
385                         if (L->Name.empty())
386                         {
387                                 ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"m_spanningtree: Ignoring a malformed link block (all link blocks require a name!)");
388                         }
389                         else
390                         {
391                                 ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"m_spanningtree: Ignoring a link block missing recvpass, sendpass, port or ipaddr.");
392                         }
393
394                         /* Invalid link block */
395                         continue;
396                 }
397
398                 ValidIPs.push_back(L->IPAddr);
399
400                 if (L->AllowMask.length())
401                         ValidIPs.push_back(L->AllowMask);
402
403                 /* Needs resolving */
404                 bool ipvalid = true;
405                 QueryType start_type = DNS_QUERY_A;
406                 start_type = DNS_QUERY_AAAA;
407                 if (strchr(L->IPAddr.c_str(),':'))
408                 {
409                         in6_addr n;
410                         if (inet_pton(AF_INET6, L->IPAddr.c_str(), &n) < 1)
411                                 ipvalid = false;
412                 }
413                 else
414                 {
415                         in_addr n;
416                         if (inet_aton(L->IPAddr.c_str(),&n) < 1)
417                                 ipvalid = false;
418                 }
419
420                 if (!ipvalid)
421                 {
422                         try
423                         {
424                                 bool cached;
425                                 SecurityIPResolver* sr = new SecurityIPResolver((Module*)this->Creator, this, ServerInstance, L->IPAddr, *L, cached, start_type);
426                                 ServerInstance->AddResolver(sr, cached);
427                         }
428                         catch (...)
429                         {
430                         }
431                 }
432         }
433 }
434
435 void SpanningTreeUtilities::ReadConfiguration(bool rebind)
436 {
437         ConfigReader* Conf = new ConfigReader(ServerInstance);
438
439         /* We don't need to worry about these being *unloaded* on the fly, only loaded,
440          * because we 'use' the interface locking the module in memory.
441          */
442         hooks.clear();
443         hooknames.clear();
444         modulelist* ml = ServerInstance->Modules->FindInterface("BufferedSocketHook");
445
446         /* Did we find any modules? */
447         if (ml)
448         {
449                 /* Yes, enumerate them all to find out the hook name */
450                 for (modulelist::iterator m = ml->begin(); m != ml->end(); m++)
451                 {
452                         /* Make a request to it for its name, its implementing
453                          * BufferedSocketHook so we know its safe to do this
454                          */
455                         std::string name = BufferedSocketNameRequest((Module*)Creator, *m).Send();
456                         /* Build a map of them */
457                         hooks[name.c_str()] = *m;
458                         hooknames.push_back(name);
459                 }
460         }
461
462         if (rebind)
463         {
464                 for (unsigned int i = 0; i < Bindings.size(); i++)
465                 {
466                         delete Bindings[i];
467                 }
468                 ServerInstance->BufferedSocketCull();
469                 Bindings.clear();
470
471                 for (int j = 0; j < Conf->Enumerate("bind"); j++)
472                 {
473                         std::string Type = Conf->ReadValue("bind","type",j);
474                         std::string IP = Conf->ReadValue("bind","address",j);
475                         std::string Port = Conf->ReadValue("bind","port",j);
476                         std::string transport = Conf->ReadValue("bind","transport",j);
477                         if (Type == "servers")
478                         {
479                                 irc::portparser portrange(Port, false);
480                                 int portno = -1;
481
482                                 if (IP == "*")
483                                         IP.clear();
484
485                                 while ((portno = portrange.GetToken()))
486                                 {
487                                         if ((!transport.empty()) && (hooks.find(transport.c_str()) ==  hooks.end()))
488                                         {
489                                                 throw CoreException("Can't find transport type '"+transport+"' for port "+IP+":"+Port+" - maybe you forgot to load it BEFORE m_spanningtree in your config file?");
490                                                 break;
491                                         }
492
493                                         ServerSocketListener *listener = new ServerSocketListener(ServerInstance, this, portno, (char *)IP.c_str());
494                                         if (listener->GetFd() == -1)
495                                         {
496                                                 delete listener;
497                                                 continue;
498                                         }
499
500                                         if (!transport.empty())
501                                                 listener->AddIOHook(hooks[transport.c_str()]);
502
503                                         Bindings.push_back(listener);
504                                 }
505                         }
506                 }
507         }
508         FlatLinks = Conf->ReadFlag("security","flatlinks",0);
509         HideULines = Conf->ReadFlag("security","hideulines",0);
510         AnnounceTSChange = Conf->ReadFlag("options","announcets",0);
511         AllowOptCommon = Conf->ReadFlag("options", "allowmismatch", 0);
512         ChallengeResponse = !Conf->ReadFlag("security", "disablehmac", 0);
513         quiet_bursts = Conf->ReadFlag("performance", "quietbursts", 0);
514         PingWarnTime = Conf->ReadInteger("options", "pingwarning", 0, true);
515         PingFreq = Conf->ReadInteger("options", "serverpingfreq", 0, true);
516
517         if (PingFreq == 0)
518                 PingFreq = 60;
519
520         if (PingWarnTime < 0 || PingWarnTime > PingFreq - 1)
521                 PingWarnTime = 0;
522
523         LinkBlocks.clear();
524         ValidIPs.clear();
525         for (int j = 0; j < Conf->Enumerate("link"); j++)
526         {
527                 Link L;
528                 std::string Allow = Conf->ReadValue("link", "allowmask", j);
529                 L.Name = (Conf->ReadValue("link", "name", j)).c_str();
530                 L.AllowMask = Allow;
531                 L.IPAddr = Conf->ReadValue("link", "ipaddr", j);
532                 L.FailOver = Conf->ReadValue("link", "failover", j).c_str();
533                 L.Port = Conf->ReadInteger("link", "port", j, true);
534                 L.SendPass = Conf->ReadValue("link", "sendpass", j);
535                 L.RecvPass = Conf->ReadValue("link", "recvpass", j);
536                 L.Fingerprint = Conf->ReadValue("link", "fingerprint", j);
537                 L.AutoConnect = Conf->ReadInteger("link", "autoconnect", j, true);
538                 L.HiddenFromStats = Conf->ReadFlag("link", "statshidden", j);
539                 L.Timeout = Conf->ReadInteger("link", "timeout", j, true);
540                 L.Hook = Conf->ReadValue("link", "transport", j);
541                 L.Bind = Conf->ReadValue("link", "bind", j);
542                 L.Hidden = Conf->ReadFlag("link", "hidden", j);
543
544                 if ((!L.Hook.empty()) && (hooks.find(L.Hook.c_str()) ==  hooks.end()))
545                 {
546                         throw CoreException("Can't find transport type '"+L.Hook+"' for link '"+assign(L.Name)+"' - maybe you forgot to load it BEFORE m_spanningtree in your config file? Skipping <link> tag completely.");
547                         continue;
548
549                 }
550
551                 // Fix: Only trip autoconnects if this wouldn't delay autoconnect..
552                 if (L.NextConnectTime > ((time_t)(ServerInstance->Time() + L.AutoConnect)))
553                         L.NextConnectTime = ServerInstance->Time() + L.AutoConnect;
554
555                 if (L.Name.find('.') == std::string::npos)
556                         throw CoreException("The link name '"+assign(L.Name)+"' is invalid and must contain at least one '.' character");
557
558                 if (L.Name.length() > 64)
559                         throw CoreException("The link name '"+assign(L.Name)+"' is longer than 64 characters!");
560
561                 if ((!L.IPAddr.empty()) && (!L.RecvPass.empty()) && (!L.SendPass.empty()) && (!L.Name.empty()) && (L.Port))
562                 {
563                         if (Allow.length())
564                                 ValidIPs.push_back(Allow);
565
566                         ValidIPs.push_back(L.IPAddr);
567
568                         /* Needs resolving */
569                         bool ipvalid = true;
570                         QueryType start_type = DNS_QUERY_A;
571                         start_type = DNS_QUERY_AAAA;
572                         if (strchr(L.IPAddr.c_str(),':'))
573                         {
574                                 in6_addr n;
575                                 if (inet_pton(AF_INET6, L.IPAddr.c_str(), &n) < 1)
576                                         ipvalid = false;
577                         }
578                         else
579                         {
580                                 in_addr n;
581                                 if (inet_aton(L.IPAddr.c_str(),&n) < 1)
582                                         ipvalid = false;
583                         }
584
585                         if (!ipvalid)
586                         {
587                                 try
588                                 {
589                                         bool cached;
590                                         SecurityIPResolver* sr = new SecurityIPResolver((Module*)this->Creator, this, ServerInstance, L.IPAddr, L, cached, start_type);
591                                         ServerInstance->AddResolver(sr, cached);
592                                 }
593                                 catch (...)
594                                 {
595                                 }
596                         }
597                 }
598                 else
599                 {
600                         if (L.IPAddr.empty())
601                         {
602                                 L.IPAddr = "*";
603                                 ValidIPs.push_back("*");
604                                 ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"Configuration warning: Link block " + assign(L.Name) + " has no IP defined! This will allow any IP to connect as this server, and MAY not be what you want.");
605                         }
606
607                         if (L.RecvPass.empty())
608                         {
609                                 throw CoreException("Invalid configuration for server '"+assign(L.Name)+"', recvpass not defined!");
610                         }
611
612                         if (L.SendPass.empty())
613                         {
614                                 throw CoreException("Invalid configuration for server '"+assign(L.Name)+"', sendpass not defined!");
615                         }
616
617                         if (L.Name.empty())
618                         {
619                                 throw CoreException("Invalid configuration, link tag without a name! IP address: "+L.IPAddr);
620                         }
621
622                         if (!L.Port)
623                         {
624                                 ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"Configuration warning: Link block " + assign(L.Name) + " has no port defined, you will not be able to /connect it.");
625                         }
626                 }
627
628                 LinkBlocks.push_back(L);
629         }
630         delete Conf;
631 }
632
633 void SpanningTreeUtilities::DoFailOver(Link* x)
634 {
635         if (x->FailOver.length())
636         {
637                 if (x->FailOver == x->Name)
638                 {
639                         this->ServerInstance->SNO->WriteToSnoMask('l', "FAILOVER: Some muppet configured the failover for server \002%s\002 to point at itself. Not following it!", x->Name.c_str());
640                         return;
641                 }
642                 Link* TryThisOne = this->FindLink(x->FailOver.c_str());
643                 if (TryThisOne)
644                 {
645                         TreeServer* CheckDupe = this->FindServer(x->FailOver.c_str());
646                         if (CheckDupe)
647                         {
648                                 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Skipping existing failover: %s", x->FailOver.c_str());
649                         }
650                         else
651                         {
652                                 this->ServerInstance->SNO->WriteToSnoMask('l', "FAILOVER: Trying failover link for \002%s\002: \002%s\002...", x->Name.c_str(), TryThisOne->Name.c_str());
653                                 Creator->ConnectServer(TryThisOne);
654                         }
655                 }
656                 else
657                 {
658                         this->ServerInstance->SNO->WriteToSnoMask('l', "FAILOVER: Invalid failover server specified for server \002%s\002, will not follow!", x->Name.c_str());
659                 }
660         }
661 }
662
663 Link* SpanningTreeUtilities::FindLink(const std::string& name)
664 {
665         for (std::vector<Link>::iterator x = LinkBlocks.begin(); x != LinkBlocks.end(); x++)
666         {
667                 if (InspIRCd::Match(x->Name.c_str(), name.c_str()))
668                 {
669                         return &(*x);
670                 }
671         }
672         return NULL;
673 }