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