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