1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
15 #include "commands/cmd_whois.h"
16 #include "commands/cmd_stats.h"
20 #include "transport.h"
21 #include "socketengine.h"
23 #include "m_spanningtree/main.h"
24 #include "m_spanningtree/utils.h"
25 #include "m_spanningtree/treeserver.h"
26 #include "m_spanningtree/link.h"
27 #include "m_spanningtree/treesocket.h"
28 #include "m_spanningtree/resolvers.h"
29 #include "m_spanningtree/handshaketimer.h"
31 /* $ModDep: m_spanningtree/timesynctimer.h m_spanningtree/resolvers.h m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/link.h m_spanningtree/treesocket.h */
33 static std::map<std::string, std::string> warned; /* Server names that have had protocol violation warnings displayed for them */
35 int TreeSocket::WriteLine(std::string line)
37 Instance->Log(DEBUG, "S[%d] O %s", this->GetFd(), line.c_str());
39 return this->Write(line);
43 /* Handle ERROR command */
44 bool TreeSocket::Error(std::deque<std::string> ¶ms)
46 if (params.size() < 1)
48 this->Instance->SNO->WriteToSnoMask('l',"ERROR from %s: %s",(!InboundServerName.empty() ? InboundServerName.c_str() : myhost.c_str()),params[0].c_str());
49 /* we will return false to cause the socket to close. */
53 bool TreeSocket::Modules(const std::string &prefix, std::deque<std::string> ¶ms)
58 if (!this->Instance->MatchText(this->Instance->Config->ServerName, params[0]))
60 /* Pass it on, not for us */
61 Utils->DoOneToOne(prefix, "MODULES", params, params[0]);
66 std::deque<std::string> par;
67 par.push_back(prefix);
70 User* source = this->Instance->FindNick(prefix);
74 for (unsigned int i = 0; i < Instance->Config->module_names.size(); i++)
76 Version V = Instance->Modules->modules[i]->GetVersion();
77 char modulename[MAXBUF];
78 char flagstate[MAXBUF];
80 if (V.Flags & VF_STATIC)
81 strlcat(flagstate,", static",MAXBUF);
82 if (V.Flags & VF_VENDOR)
83 strlcat(flagstate,", vendor",MAXBUF);
84 if (V.Flags & VF_COMMON)
85 strlcat(flagstate,", common",MAXBUF);
86 if (V.Flags & VF_SERVICEPROVIDER)
87 strlcat(flagstate,", service provider",MAXBUF);
89 strcpy(flagstate," <no flags>");
90 strlcpy(modulename,Instance->Config->module_names[i].c_str(),256);
93 snprintf(strbuf, MAXBUF, "::%s 900 %s :0x%08lx %d.%d.%d.%d %s (%s)",Instance->Config->ServerName,source->nick,(long unsigned int)Instance->Modules->modules[i],V.Major,V.Minor,V.Revision,V.Build,ServerConfig::CleanFilename(modulename),flagstate+2);
97 snprintf(strbuf, MAXBUF, "::%s 900 %s :%s",Instance->Config->ServerName,source->nick,ServerConfig::CleanFilename(modulename));
100 Utils->DoOneToOne(Instance->Config->GetSID(), "PUSH", par, source->server);
102 snprintf(strbuf, MAXBUF, "::%s 901 %s :End of MODULES list", Instance->Config->ServerName, source->nick);
104 Utils->DoOneToOne(Instance->Config->GetSID(), "PUSH", par, source->server);
108 /** remote MOTD. leet, huh? */
109 bool TreeSocket::Motd(const std::string &prefix, std::deque<std::string> ¶ms)
111 if (params.size() > 0)
113 if (this->Instance->MatchText(this->Instance->Config->ServerName, params[0]))
115 /* It's for our server */
117 User* source = this->Instance->FindNick(prefix);
121 std::deque<std::string> par;
122 par.push_back(prefix);
125 if (!Instance->Config->MOTD.size())
127 par[1] = std::string("::")+Instance->Config->ServerName+" 422 "+source->nick+" :Message of the day file is missing.";
128 Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
132 par[1] = std::string("::")+Instance->Config->ServerName+" 375 "+source->nick+" :"+Instance->Config->ServerName+" message of the day";
133 Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
135 for (unsigned int i = 0; i < Instance->Config->MOTD.size(); i++)
137 par[1] = std::string("::")+Instance->Config->ServerName+" 372 "+source->nick+" :- "+Instance->Config->MOTD[i];
138 Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
141 par[1] = std::string("::")+Instance->Config->ServerName+" 376 "+source->nick+" :End of message of the day.";
142 Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
148 User* source = this->Instance->FindNick(prefix);
150 Utils->DoOneToOne(prefix, "MOTD", params, params[0]);
156 /** remote ADMIN. leet, huh? */
157 bool TreeSocket::Admin(const std::string &prefix, std::deque<std::string> ¶ms)
159 if (params.size() > 0)
161 if (this->Instance->MatchText(this->Instance->Config->ServerName, params[0]))
163 /* It's for our server */
165 User* source = this->Instance->FindNick(prefix);
168 std::deque<std::string> par;
169 par.push_back(prefix);
171 par[1] = std::string("::")+Instance->Config->ServerName+" 256 "+source->nick+" :Administrative info for "+Instance->Config->ServerName;
172 Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
173 par[1] = std::string("::")+Instance->Config->ServerName+" 257 "+source->nick+" :Name - "+Instance->Config->AdminName;
174 Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
175 par[1] = std::string("::")+Instance->Config->ServerName+" 258 "+source->nick+" :Nickname - "+Instance->Config->AdminNick;
176 Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
177 par[1] = std::string("::")+Instance->Config->ServerName+" 258 "+source->nick+" :E-Mail - "+Instance->Config->AdminEmail;
178 Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
184 User* source = this->Instance->FindNick(prefix);
186 Utils->DoOneToOne(prefix, "ADMIN", params, params[0]);
192 bool TreeSocket::Stats(const std::string &prefix, std::deque<std::string> ¶ms)
194 /* Get the reply to a STATS query if it matches this servername,
195 * and send it back as a load of PUSH queries
197 if (params.size() > 1)
199 if (this->Instance->MatchText(this->Instance->Config->ServerName, params[1]))
201 /* It's for our server */
203 User* source = this->Instance->FindNick(prefix);
206 std::deque<std::string> par;
207 par.push_back(prefix);
209 DoStats(this->Instance, *(params[0].c_str()), source, results);
210 for (size_t i = 0; i < results.size(); i++)
212 par[1] = "::" + results[i];
213 Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
220 User* source = this->Instance->FindNick(prefix);
222 Utils->DoOneToOne(source->uuid, "STATS", params, params[1]);
229 /** Because the core won't let users or even SERVERS set +o,
230 * we use the OPERTYPE command to do this.
232 bool TreeSocket::OperType(const std::string &prefix, std::deque<std::string> ¶ms)
234 if (params.size() != 1)
236 std::string opertype = params[0];
237 User* u = this->Instance->FindNick(prefix);
240 if (!u->IsModeSet('o'))
241 this->Instance->all_opers.push_back(u);
242 u->modes[UM_OPERATOR] = 1;
243 strlcpy(u->oper,opertype.c_str(),NICKMAX-1);
244 Utils->DoOneToAllButSender(u->nick,"OPERTYPE",params,u->server);
246 TreeServer* remoteserver = Utils->FindServer(u->server);
249 if (this->Utils->quiet_bursts)
252 * If quiet bursts are enabled, and server is bursting or silent uline (i.e. services),
253 * then do nothing. -- w00t
257 Utils->FindRemoteBurstServer(remoteserver) ||
258 this->Instance->SilentULine(this->Instance->FindServerNamePtr(u->server))
266 this->Instance->SNO->WriteToSnoMask('o',"From %s: User %s (%s@%s) is now an IRC operator of type %s",u->server, u->nick,u->ident,u->host,irc::Spacify(opertype.c_str()));
271 /** Because Andy insists that services-compatible servers must
272 * implement SVSNICK and SVSJOIN, that's exactly what we do :p
274 bool TreeSocket::ForceNick(const std::string &prefix, std::deque<std::string> ¶ms)
276 if (params.size() < 3)
279 User* u = this->Instance->FindNick(params[0]);
283 Utils->DoOneToAllButSender(prefix,"SVSNICK",params,prefix);
287 std::deque<std::string> par;
288 par.push_back(params[1]);
290 if (!u->ForceNickChange(params[1].c_str()))
293 if (!u->ForceNickChange(u->uuid))
295 User::QuitUser(this->Instance, u, "Nickname collision");
300 u->age = atoi(params[2].c_str());
307 bool TreeSocket::OperQuit(const std::string &prefix, std::deque<std::string> ¶ms)
309 if (params.size() < 1)
312 User* u = this->Instance->FindNick(prefix);
316 u->SetOperQuit(params[0]);
317 params[0] = ":" + params[0];
318 Utils->DoOneToAllButSender(prefix,"OPERQUIT",params,prefix);
323 bool TreeSocket::ServiceJoin(const std::string &prefix, std::deque<std::string> ¶ms)
325 if (params.size() < 2)
328 if (!this->Instance->IsChannel(params[1].c_str()))
331 User* u = this->Instance->FindNick(params[0]);
335 /* only join if it's local, otherwise just pass it on! */
337 Channel::JoinUser(this->Instance, u, params[1].c_str(), false, "", Instance->Time());
338 Utils->DoOneToAllButSender(prefix,"SVSJOIN",params,prefix);
343 bool TreeSocket::ServicePart(const std::string &prefix, std::deque<std::string> ¶ms)
345 if (params.size() < 2)
348 if (!this->Instance->IsChannel(params[1].c_str()))
351 User* u = this->Instance->FindNick(params[0]);
352 Channel* c = this->Instance->FindChan(params[1]);
356 /* only part if it's local, otherwise just pass it on! */
358 if (!c->PartUser(u, "Services forced part"))
360 Utils->DoOneToAllButSender(prefix,"SVSPART",params,prefix);
366 bool TreeSocket::RemoteRehash(const std::string &prefix, std::deque<std::string> ¶ms)
368 if (params.size() < 1)
371 std::string servermask = params[0];
373 if (this->Instance->MatchText(this->Instance->Config->ServerName,servermask))
375 this->Instance->SNO->WriteToSnoMask('l',"Remote rehash initiated by \002"+prefix+"\002.");
376 this->Instance->RehashServer();
377 Utils->ReadConfiguration(false);
378 InitializeDisabledCommands(Instance->Config->DisabledCommands, Instance);
380 Utils->DoOneToAllButSender(prefix,"REHASH",params,prefix);
384 bool TreeSocket::RemoteKill(const std::string &prefix, std::deque<std::string> ¶ms)
386 if (params.size() != 2)
389 User* who = this->Instance->FindNick(params[0]);
393 /* Prepend kill source, if we don't have one */
394 if (*(params[1].c_str()) != '[')
396 params[1] = "[" + prefix + "] Killed (" + params[1] +")";
398 std::string reason = params[1];
399 params[1] = ":" + params[1];
400 Utils->DoOneToAllButSender(prefix,"KILL",params,prefix);
401 // NOTE: This is safe with kill hiding on, as RemoteKill is only reached if we have a server prefix.
402 // in short this is not executed for USERS.
403 who->Write(":%s KILL %s :%s (%s)", prefix.c_str(), who->nick, prefix.c_str(), reason.c_str());
404 User::QuitUser(this->Instance,who,reason);
409 bool TreeSocket::LocalPong(const std::string &prefix, std::deque<std::string> ¶ms)
411 if (params.size() < 1)
414 if (params.size() == 1)
416 TreeServer* ServerSource = Utils->FindServer(prefix);
419 ServerSource->SetPingFlag();
421 gettimeofday(&t, NULL);
422 long ts = (t.tv_sec * 1000) + (t.tv_usec / 1000);
423 ServerSource->rtt = ts - ServerSource->LastPingMsec;
428 std::string forwardto = params[1];
429 if (forwardto == Instance->Config->GetSID() || forwardto == Instance->Config->ServerName)
432 * this is a PONG for us
433 * if the prefix is a user, check theyre local, and if they are,
434 * dump the PONG reply back to their fd. If its a server, do nowt.
435 * Services might want to send these s->s, but we dont need to yet.
437 User* u = this->Instance->FindNick(prefix);
440 u->WriteServ("PONG %s %s",params[0].c_str(),params[1].c_str());
445 // not for us, pass it on :)
446 Utils->DoOneToOne(prefix,"PONG",params,forwardto);
453 bool TreeSocket::MetaData(const std::string &prefix, std::deque<std::string> ¶ms)
455 if (params.size() < 2)
457 else if (params.size() < 3)
458 params.push_back("");
459 TreeServer* ServerSource = Utils->FindServer(prefix);
462 Utils->SetRemoteBursting(ServerSource, false);
464 if (params[0] == "*")
466 FOREACH_MOD_I(this->Instance,I_OnDecodeMetaData,OnDecodeMetaData(TYPE_OTHER,NULL,params[1],params[2]));
468 else if (*(params[0].c_str()) == '#')
470 Channel* c = this->Instance->FindChan(params[0]);
473 FOREACH_MOD_I(this->Instance,I_OnDecodeMetaData,OnDecodeMetaData(TYPE_CHANNEL,c,params[1],params[2]));
476 else if (*(params[0].c_str()) != '#')
478 User* u = this->Instance->FindNick(params[0]);
481 FOREACH_MOD_I(this->Instance,I_OnDecodeMetaData,OnDecodeMetaData(TYPE_USER,u,params[1],params[2]));
486 params[2] = ":" + params[2];
487 Utils->DoOneToAllButSender(prefix,"METADATA",params,prefix);
491 bool TreeSocket::ServerVersion(const std::string &prefix, std::deque<std::string> ¶ms)
493 if (params.size() < 1)
496 TreeServer* ServerSource = Utils->FindServer(prefix);
500 ServerSource->SetVersion(params[0]);
502 params[0] = ":" + params[0];
503 Utils->DoOneToAllButSender(prefix,"VERSION",params,prefix);
507 bool TreeSocket::ChangeHost(const std::string &prefix, std::deque<std::string> ¶ms)
509 if (params.size() < 1)
511 User* u = this->Instance->FindNick(prefix);
515 u->ChangeDisplayedHost(params[0].c_str());
516 Utils->DoOneToAllButSender(prefix,"FHOST",params,u->server);
521 bool TreeSocket::AddLine(const std::string &prefix, std::deque<std::string> ¶ms)
523 if (params.size() < 6)
526 bool propogate = false;
531 switch (*(params[0].c_str()))
534 xl = (XLine*)(new ZLine(Instance, Instance->Time(), atoi(params[4].c_str()), params[2].c_str(), params[5].c_str(), params[1].c_str()));
535 propogate = Instance->XLines->AddLine(xl);
536 Instance->XLines->zline_set_creation_time(params[1].c_str(), atoi(params[3].c_str()));
539 xl = (XLine*)(new QLine(Instance, Instance->Time(), atoi(params[4].c_str()), params[2].c_str(), params[5].c_str(), params[1].c_str()));
540 propogate = Instance->XLines->AddLine(xl);
541 Instance->XLines->qline_set_creation_time(params[1].c_str(), atoi(params[3].c_str()));
544 ih = Instance->XLines->IdentSplit(params[1]);
545 xl = (XLine*)(new GLine(Instance, Instance->Time(), atoi(params[4].c_str()), params[2].c_str(), params[5].c_str(), ih.first.c_str(), ih.second.c_str()));
546 propogate = Instance->XLines->AddLine(xl);
547 Instance->XLines->eline_set_creation_time(params[1].c_str(), atoi(params[3].c_str()));
550 ih = Instance->XLines->IdentSplit(params[1]);
551 xl = (XLine*)(new GLine(Instance, Instance->Time(), atoi(params[4].c_str()), params[2].c_str(), params[5].c_str(), ih.first.c_str(), ih.second.c_str()));
552 propogate = Instance->XLines->AddLine(xl);
553 Instance->XLines->gline_set_creation_time(params[1].c_str(), atoi(params[3].c_str()));
556 ih = Instance->XLines->IdentSplit(params[1]);
557 xl = (XLine*)(new KLine(Instance, Instance->Time(), atoi(params[4].c_str()), params[2].c_str(), params[5].c_str(), ih.first.c_str(), ih.second.c_str()));
558 propogate = Instance->XLines->AddLine(xl);
561 /* Just in case... */
562 this->Instance->SNO->WriteToSnoMask('x',"\2WARNING\2: Invalid xline type '"+params[0]+"' sent by server "+prefix+", ignored!");
566 /* Send it on its way */
571 this->Instance->SNO->WriteToSnoMask('x',"%s Added %cLINE on %s to expire on %s (%s).",prefix.c_str(),*(params[0].c_str()),params[1].c_str(),Instance->TimeString(xl->expiry).c_str(),params[5].c_str());
575 this->Instance->SNO->WriteToSnoMask('x',"%s Added permenant %cLINE on %s (%s).",prefix.c_str(),*(params[0].c_str()),params[1].c_str(),params[5].c_str());
577 params[5] = ":" + params[5];
578 Utils->DoOneToAllButSender(prefix,"ADDLINE",params,prefix);
583 Instance->XLines->ApplyLines();
589 bool TreeSocket::ChangeName(const std::string &prefix, std::deque<std::string> ¶ms)
591 if (params.size() < 1)
593 User* u = this->Instance->FindNick(prefix);
596 u->ChangeName(params[0].c_str());
597 params[0] = ":" + params[0];
598 Utils->DoOneToAllButSender(prefix,"FNAME",params,u->server);
603 bool TreeSocket::Whois(const std::string &prefix, std::deque<std::string> ¶ms)
605 if (params.size() < 1)
607 User* u = this->Instance->FindNick(prefix);
610 // an incoming request
611 if (params.size() == 1)
613 User* x = this->Instance->FindNick(params[0]);
614 if ((x) && (IS_LOCAL(x)))
616 User* x = this->Instance->FindNick(params[0]);
619 snprintf(signon, MAXBUF, "%lu", (unsigned long)x->signon);
620 snprintf(idle, MAXBUF, "%lu", (unsigned long)abs((x->idle_lastmsg) - Instance->Time(true)));
621 std::deque<std::string> par;
622 par.push_back(prefix);
623 par.push_back(signon);
625 // ours, we're done, pass it BACK
626 Utils->DoOneToOne(params[0], "IDLE", par, u->server);
630 // not ours pass it on
632 Utils->DoOneToOne(prefix, "IDLE", params, x->server);
635 else if (params.size() == 3)
637 std::string who_did_the_whois = params[0];
638 User* who_to_send_to = this->Instance->FindNick(who_did_the_whois);
639 if ((who_to_send_to) && (IS_LOCAL(who_to_send_to)))
641 // an incoming reply to a whois we sent out
642 std::string nick_whoised = prefix;
643 unsigned long signon = atoi(params[1].c_str());
644 unsigned long idle = atoi(params[2].c_str());
645 if ((who_to_send_to) && (IS_LOCAL(who_to_send_to)))
647 do_whois(this->Instance, who_to_send_to, u, signon, idle, nick_whoised.c_str());
652 // not ours, pass it on
654 Utils->DoOneToOne(prefix, "IDLE", params, who_to_send_to->server);
661 bool TreeSocket::Push(const std::string &prefix, std::deque<std::string> ¶ms)
663 if (params.size() < 2)
665 User* u = this->Instance->FindNick(params[0]);
674 // continue the raw onwards
675 params[1] = ":" + params[1];
676 Utils->DoOneToOne(prefix,"PUSH",params,u->server);
681 bool TreeSocket::HandleSetTime(const std::string &prefix, std::deque<std::string> ¶ms)
683 if (!params.size() || !Utils->EnableTimeSync)
688 if ((params.size() == 2) && (params[1] == "FORCE"))
691 time_t them = atoi(params[0].c_str());
692 time_t us = Instance->Time(false);
694 time_t diff = them - us;
696 Utils->DoOneToAllButSender(prefix, "TIMESET", params, prefix);
698 if (force || (them != us))
700 time_t old = Instance->SetTimeDelta(diff);
701 Instance->Log(DEBUG, "TS (diff %d) from %s applied (old delta was %d)", diff, prefix.c_str(), old);
707 bool TreeSocket::Time(const std::string &prefix, std::deque<std::string> ¶ms)
709 // :source.server TIME remote.server sendernick
710 // :remote.server TIME source.server sendernick TS
711 if (params.size() == 2)
713 // someone querying our time?
714 if (this->Instance->Config->ServerName == params[0] || this->Instance->Config->GetSID() == params[0])
716 User* u = this->Instance->FindNick(params[1]);
719 params.push_back(ConvToStr(Instance->Time(false)));
721 Utils->DoOneToOne(this->Instance->Config->GetSID(),"TIME",params,params[0]);
726 // not us, pass it on
727 User* u = this->Instance->FindNick(params[1]);
729 Utils->DoOneToOne(prefix,"TIME",params,params[0]);
732 else if (params.size() == 3)
734 // a response to a previous TIME
735 User* u = this->Instance->FindNick(params[1]);
736 if ((u) && (IS_LOCAL(u)))
738 time_t rawtime = atol(params[2].c_str());
739 struct tm * timeinfo;
740 timeinfo = localtime(&rawtime);
742 snprintf(tms,26,"%s",asctime(timeinfo));
744 u->WriteServ("391 %s %s :%s",u->nick,prefix.c_str(),tms);
749 Utils->DoOneToOne(prefix,"TIME",params,u->server);
755 bool TreeSocket::LocalPing(const std::string &prefix, std::deque<std::string> ¶ms)
757 if (params.size() < 1)
759 if (params.size() == 1)
761 std::string stufftobounce = params[0];
762 this->WriteLine(std::string(":")+this->Instance->Config->GetSID()+" PONG "+stufftobounce);
767 std::string forwardto = params[1];
768 if (forwardto == this->Instance->Config->ServerName || forwardto == this->Instance->Config->GetSID())
770 // this is a ping for us, send back PONG to the requesting server
771 params[1] = params[0];
772 params[0] = forwardto;
773 Utils->DoOneToOne(forwardto,"PONG",params,params[1]);
777 // not for us, pass it on :)
778 Utils->DoOneToOne(prefix,"PING",params,forwardto);
784 /** TODO: This creates a total mess of output and needs to really use irc::modestacker.
786 bool TreeSocket::RemoveStatus(const std::string &prefix, std::deque<std::string> ¶ms)
788 if (params.size() < 1)
790 Channel* c = Instance->FindChan(params[0]);
793 for (char modeletter = 'A'; modeletter <= 'z'; modeletter++)
795 ModeHandler* mh = Instance->Modes->FindMode(modeletter, MODETYPE_CHANNEL);
803 bool TreeSocket::RemoteServer(const std::string &prefix, std::deque<std::string> ¶ms)
805 if (params.size() < 5)
807 SendError("Protocol error - Missing SID");
811 std::string servername = params[0];
812 std::string password = params[1];
813 // hopcount is not used for a remote server, we calculate this ourselves
814 std::string sid = params[3];
815 std::string description = params[4];
816 TreeServer* ParentOfThis = Utils->FindServer(prefix);
819 this->SendError("Protocol error - Introduced remote server from unknown server "+prefix);
822 if (!Utils->IsSID(sid))
824 this->SendError("Invalid format server ID: "+sid+"!");
827 TreeServer* CheckDupe = Utils->FindServer(servername);
830 this->SendError("Server "+servername+" already exists!");
831 this->Instance->SNO->WriteToSnoMask('l',"Server \2"+servername+"\2 being introduced from \2" + prefix + "\2 denied, already exists. Closing link with " + prefix);
835 Link* lnk = Utils->FindLink(servername);
837 TreeServer *Node = new TreeServer(this->Utils, this->Instance, servername, description, sid, ParentOfThis,NULL, lnk ? lnk->Hidden : false);
839 if (Node->DuplicateID())
841 this->SendError("Server ID "+sid+" already exists on the network!");
842 this->Instance->SNO->WriteToSnoMask('l',"Server \2"+servername+"\2 being introduced from \2" + prefix + "\2 denied, server ID already exists on the network. Closing link with " + prefix);
846 ParentOfThis->AddChild(Node);
847 params[4] = ":" + params[4];
848 Utils->SetRemoteBursting(Node, true);
849 Utils->DoOneToAllButSender(prefix,"SERVER",params,prefix);
850 this->Instance->SNO->WriteToSnoMask('l',"Server \002"+prefix+"\002 introduced server \002"+servername+"\002 ("+description+")");
854 bool TreeSocket::ComparePass(const std::string &ours, const std::string &theirs)
856 if ((!strncmp(ours.c_str(), "HMAC-SHA256:", 12)) || (!strncmp(theirs.c_str(), "HMAC-SHA256:", 12)))
858 /* One or both of us specified hmac sha256, but we don't have sha256 module loaded!
859 * We can't allow this password as valid.
861 if (!Instance->Modules->Find("m_sha256.so") || !Utils->ChallengeResponse)
864 /* Straight string compare of hashes */
865 return ours == theirs;
868 /* Straight string compare of plaintext */
869 return ours == theirs;
872 bool TreeSocket::Outbound_Reply_Server(std::deque<std::string> ¶ms)
874 if (params.size() < 5)
876 SendError("Protocol error - Missing SID");
880 irc::string servername = params[0].c_str();
881 std::string sname = params[0];
882 std::string password = params[1];
883 std::string sid = params[3];
884 std::string description = params[4];
885 int hops = atoi(params[2].c_str());
887 this->InboundServerName = sname;
888 this->InboundDescription = description;
889 this->InboundSID = sid;
892 this->SendCapabilities();
896 this->SendError("Server too far away for authentication");
897 this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, server is too far away for authentication");
901 if (!Utils->IsSID(sid))
903 this->SendError("Invalid format server ID: "+sid+"!");
907 for (std::vector<Link>::iterator x = Utils->LinkBlocks.begin(); x < Utils->LinkBlocks.end(); x++)
909 if ((x->Name == servername) && ((ComparePass(this->MakePass(x->RecvPass,this->GetOurChallenge()),password)) || (x->RecvPass == password && (this->GetTheirChallenge().empty()))))
911 TreeServer* CheckDupe = Utils->FindServer(sname);
914 this->SendError("Server "+sname+" already exists on server "+CheckDupe->GetParent()->GetName()+"!");
915 this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, already exists on server "+CheckDupe->GetParent()->GetName());
918 // Begin the sync here. this kickstarts the
919 // other side, waiting in WAIT_AUTH_2 state,
920 // into starting their burst, as it shows
922 this->LinkState = CONNECTED;
923 // we should add the details of this server now
924 // to the servers tree, as a child of the root
927 TreeServer *Node = new TreeServer(this->Utils, this->Instance, sname, description, sid, Utils->TreeRoot, this, x->Hidden);
929 if (Node->DuplicateID())
931 this->SendError("Server ID "+sid+" already exists on the network!");
932 this->Instance->SNO->WriteToSnoMask('l',"Server \2"+assign(servername)+"\2 being introduced denied, server ID already exists on the network. Closing link.");
936 Utils->TreeRoot->AddChild(Node);
937 params[4] = ":" + params[4];
938 Utils->DoOneToAllButSender(Instance->Config->GetSID(),"SERVER",params,sname);
939 this->bursting = true;
944 this->SendError("Invalid credentials");
945 this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, invalid link credentials");
949 bool TreeSocket::Inbound_Server(std::deque<std::string> ¶ms)
951 if (params.size() < 5)
953 SendError("Protocol error - Missing SID");
957 irc::string servername = params[0].c_str();
958 std::string sname = params[0];
959 std::string password = params[1];
960 std::string sid = params[3];
961 std::string description = params[4];
962 int hops = atoi(params[2].c_str());
964 this->InboundServerName = sname;
965 this->InboundDescription = description;
966 this->InboundSID = sid;
969 this->SendCapabilities();
973 this->SendError("Server too far away for authentication");
974 this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, server is too far away for authentication");
978 if (!Utils->IsSID(sid))
980 this->SendError("Invalid format server ID: "+sid+"!");
984 for (std::vector<Link>::iterator x = Utils->LinkBlocks.begin(); x < Utils->LinkBlocks.end(); x++)
986 if ((x->Name == servername) && ((ComparePass(this->MakePass(x->RecvPass,this->GetOurChallenge()),password) || x->RecvPass == password && (this->GetTheirChallenge().empty()))))
988 /* First check for instances of the server that are waiting between the inbound and outbound SERVER command */
989 TreeSocket* CheckDupeSocket = Utils->FindBurstingServer(sname);
992 /* If we find one, we abort the link to prevent a race condition */
993 this->SendError("Negotiation collision");
994 this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, already exists in a negotiating state.");
995 CheckDupeSocket->SendError("Negotiation collision");
996 Instance->SE->DelFd(CheckDupeSocket);
997 CheckDupeSocket->Close();
1000 /* Check for fully initialized instances of the server by id */
1001 Instance->Log(DEBUG,"Looking for dupe SID %s", sid.c_str());
1002 TreeServer* CheckDupeSID = Utils->FindServerID(sid);
1005 this->SendError("Server ID "+CheckDupeSID->GetID()+" already exists on server "+CheckDupeSID->GetName()+"!");
1006 this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, server ID '"+CheckDupeSID->GetID()+
1007 "' already exists on server "+CheckDupeSID->GetName());
1010 /* Now check for fully initialized instances of the server by name */
1011 TreeServer* CheckDupe = Utils->FindServer(sname);
1014 this->SendError("Server "+sname+" already exists on server "+CheckDupe->GetParent()->GetName()+"!");
1015 this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, already exists on server "+CheckDupe->GetParent()->GetName());
1018 this->Instance->SNO->WriteToSnoMask('l',"Verified incoming server connection from \002"+sname+"\002["+(x->HiddenFromStats ? "<hidden>" : this->GetIP())+"] ("+description+")");
1021 std::string name = BufferedSocketNameRequest((Module*)Utils->Creator, this->Hook).Send();
1022 this->Instance->SNO->WriteToSnoMask('l',"Connection from \2"+sname+"\2["+(x->HiddenFromStats ? "<hidden>" : this->GetIP())+"] using transport \2"+name+"\2");
1025 Utils->AddBurstingServer(sname,this);
1027 // this is good. Send our details: Our server name and description and hopcount of 0,
1028 // along with the sendpass from this block.
1029 this->WriteLine(std::string("SERVER ")+this->Instance->Config->ServerName+" "+this->MakePass(x->SendPass, this->GetTheirChallenge())+" 0 "+Instance->Config->GetSID()+" :"+this->Instance->Config->ServerDesc);
1030 // move to the next state, we are now waiting for THEM.
1031 this->LinkState = WAIT_AUTH_2;
1035 this->SendError("Invalid credentials");
1036 this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, invalid link credentials");
1040 void TreeSocket::Split(const std::string &line, std::deque<std::string> &n)
1043 irc::tokenstream tokens(line);
1045 while (tokens.GetToken(param))
1052 bool TreeSocket::ProcessLine(std::string &line)
1054 std::deque<std::string> params;
1055 irc::string command;
1058 line = line.substr(0, line.find_first_of("\r\n"));
1063 Instance->Log(DEBUG, "S[%d] I %s", this->GetFd(), line.c_str());
1065 this->Split(line.c_str(),params);
1070 if ((params[0][0] == ':') && (params.size() > 1))
1072 prefix = params[0].substr(1);
1075 command = params[0].c_str();
1077 switch (this->LinkState)
1082 // Waiting for SERVER command from remote server. Server initiating
1083 // the connection sends the first SERVER command, listening server
1084 // replies with theirs if its happy, then if the initiator is happy,
1085 // it starts to send its net sync, which starts the merge, otherwise
1086 // it sends an ERROR.
1087 if (command == "PASS")
1089 /* Silently ignored */
1091 else if (command == "SERVER")
1093 return this->Inbound_Server(params);
1095 else if (command == "ERROR")
1097 return this->Error(params);
1099 else if (command == "USER")
1101 this->SendError("Client connections to this port are prohibited.");
1104 else if (command == "CAPAB")
1106 return this->Capab(params);
1110 irc::string error = "Invalid command in negotiation phase: " + command;
1111 this->SendError(assign(error));
1116 // Waiting for start of other side's netmerge to say they liked our
1118 if (command == "SERVER")
1120 // cant do this, they sent it to us in the WAIT_AUTH_1 state!
1124 else if (command == "BURST")
1126 if (params.size() && Utils->EnableTimeSync)
1128 bool we_have_delta = (Instance->Time(false) != Instance->Time(true));
1129 time_t them = atoi(params[0].c_str());
1130 time_t delta = them - Instance->Time(false);
1131 if ((delta < -600) || (delta > 600))
1133 Instance->SNO->WriteToSnoMask('l',"\2ERROR\2: Your clocks are out by %d seconds (this is more than five minutes). Link aborted, \2PLEASE SYNC YOUR CLOCKS!\2",abs(delta));
1134 SendError("Your clocks are out by "+ConvToStr(abs(delta))+" seconds (this is more than five minutes). Link aborted, PLEASE SYNC YOUR CLOCKS!");
1137 else if ((delta < -30) || (delta > 30))
1139 Instance->SNO->WriteToSnoMask('l',"\2WARNING\2: Your clocks are out by %d seconds. Please consider synching your clocks.", abs(delta));
1142 if (!Utils->MasterTime && !we_have_delta)
1144 this->Instance->SetTimeDelta(delta);
1145 // Send this new timestamp to any other servers
1146 Utils->DoOneToMany(Instance->Config->GetSID(), "TIMESET", params);
1149 this->LinkState = CONNECTED;
1150 Link* lnk = Utils->FindLink(InboundServerName);
1152 Node = new TreeServer(this->Utils, this->Instance, InboundServerName, InboundDescription, InboundSID, Utils->TreeRoot, this, lnk ? lnk->Hidden : false);
1154 if (Node->DuplicateID())
1156 this->SendError("Server ID "+InboundSID+" already exists on the network!");
1157 this->Instance->SNO->WriteToSnoMask('l',"Server \2"+InboundServerName+"\2 being introduced from \2" + prefix + "\2 denied, server ID already exists on the network. Closing link.");
1160 Utils->DelBurstingServer(this);
1161 Utils->TreeRoot->AddChild(Node);
1163 params.push_back(InboundServerName);
1164 params.push_back("*");
1165 params.push_back("1");
1166 params.push_back(InboundSID);
1167 params.push_back(":"+InboundDescription);
1168 Utils->DoOneToAllButSender(Instance->Config->GetSID(),"SERVER",params,InboundServerName);
1169 this->bursting = true;
1170 this->DoBurst(Node);
1172 else if (command == "ERROR")
1174 return this->Error(params);
1176 else if (command == "CAPAB")
1178 return this->Capab(params);
1183 this->SendError("Internal error -- listening socket accepted its own descriptor!!!");
1187 if (command == "SERVER")
1189 // another server we connected to, which was in WAIT_AUTH_1 state,
1190 // has just sent us their credentials. If we get this far, theyre
1191 // happy with OUR credentials, and they are now in WAIT_AUTH_2 state.
1192 // if we're happy with this, we should send our netburst which
1193 // kickstarts the merge.
1194 return this->Outbound_Reply_Server(params);
1196 else if (command == "ERROR")
1198 return this->Error(params);
1200 else if (command == "CAPAB")
1202 return this->Capab(params);
1206 // This is the 'authenticated' state, when all passwords
1207 // have been exchanged and anything past this point is taken
1210 if (!prefix.empty())
1212 std::string direction = prefix;
1214 User *t = this->Instance->FindUUID(prefix);
1217 direction = t->server;
1220 TreeServer* route_back_again = Utils->BestRouteTo(direction);
1221 if ((!route_back_again) || (route_back_again->GetSocket() != this))
1223 if (route_back_again)
1224 Instance->Log(DEBUG,"Protocol violation: Fake direction in command '%s' from connection '%s'",line.c_str(),this->GetName().c_str());
1228 * When there is activity on the socket, reset the ping counter so
1229 * that we're not wasting bandwidth pinging an active server.
1231 route_back_again->SetNextPingTime(time(NULL) + Utils->PingFreq);
1232 route_back_again->SetPingFlag();
1236 TreeServer* n = Utils->FindServer(GetName());
1238 prefix = n->GetID();
1243 if ((command == "MODE") && (params.size() >= 2))
1245 Channel* channel = Instance->FindChan(params[0]);
1248 User* x = Instance->FindNick(prefix);
1251 if (warned.find(x->server) == warned.end())
1253 Instance->Log(DEFAULT,"WARNING: I revceived modes '%s' from another server '%s'. This is not compliant with InspIRCd. Please check that server for bugs.", params[1].c_str(), x->server);
1254 Instance->SNO->WriteToSnoMask('d', "WARNING: The server %s is sending nonstandard modes: '%s MODE %s' where FMODE should be used, and may cause desyncs.", x->server, x->nick, params[1].c_str());
1255 warned[x->server] = x->nick;
1261 if (command == "SVSMODE")
1263 /* Services expects us to implement
1264 * SVSMODE. In inspircd its the same as
1270 /* Yes, know, this is a mess. Its reasonably fast though as we're
1271 * working with std::string here.
1273 if (command == "UID")
1275 return this->ParseUID(prefix, params);
1277 else if (command == "FJOIN")
1279 TreeServer* ServerSource = Utils->FindServer(prefix);
1281 Utils->SetRemoteBursting(ServerSource, false);
1282 return this->ForceJoin(prefix,params);
1284 else if (command == "STATS")
1286 return this->Stats(prefix, params);
1288 else if (command == "MOTD")
1290 return this->Motd(prefix, params);
1292 else if (command == "KILL" && Utils->IsServer(prefix))
1294 return this->RemoteKill(prefix,params);
1296 else if (command == "MODULES")
1298 return this->Modules(prefix, params);
1300 else if (command == "ADMIN")
1302 return this->Admin(prefix, params);
1304 else if (command == "SERVER")
1306 return this->RemoteServer(prefix,params);
1308 else if (command == "ERROR")
1310 return this->Error(params);
1312 else if (command == "OPERTYPE")
1314 return this->OperType(prefix,params);
1316 else if (command == "FMODE")
1318 TreeServer* ServerSource = Utils->FindServer(prefix);
1320 Utils->SetRemoteBursting(ServerSource, false);
1321 return this->ForceMode(prefix,params);
1323 else if (command == "FTOPIC")
1325 return this->ForceTopic(prefix,params);
1327 else if (command == "REHASH")
1329 return this->RemoteRehash(prefix,params);
1331 else if (command == "METADATA")
1333 return this->MetaData(prefix,params);
1335 else if (command == "REMSTATUS")
1337 return this->RemoveStatus(prefix,params);
1339 else if (command == "PING")
1342 * We just got a ping from a server that's bursting.
1343 * This can't be right, so set them to not bursting, and
1344 * apply their lines.
1346 TreeServer* ServerSource = Utils->FindServer(prefix);
1348 Utils->SetRemoteBursting(ServerSource, false);
1352 this->bursting = false;
1353 Instance->XLines->ApplyLines();
1356 return this->LocalPing(prefix,params);
1358 else if (command == "PONG")
1361 * We just got a pong from a server that's bursting.
1362 * This can't be right, so set them to not bursting, and
1363 * apply their lines.
1365 TreeServer* ServerSource = Utils->FindServer(prefix);
1367 Utils->SetRemoteBursting(ServerSource, false);
1371 this->bursting = false;
1372 Instance->XLines->ApplyLines();
1375 return this->LocalPong(prefix,params);
1377 else if (command == "VERSION")
1379 return this->ServerVersion(prefix,params);
1381 else if (command == "FHOST")
1383 return this->ChangeHost(prefix,params);
1385 else if (command == "FNAME")
1387 return this->ChangeName(prefix,params);
1389 else if (command == "ADDLINE")
1391 TreeServer* ServerSource = Utils->FindServer(prefix);
1393 Utils->SetRemoteBursting(ServerSource, false);
1394 return this->AddLine(prefix,params);
1396 else if (command == "SVSNICK")
1398 return this->ForceNick(prefix,params);
1400 else if (command == "OPERQUIT")
1402 return this->OperQuit(prefix,params);
1404 else if (command == "IDLE")
1406 return this->Whois(prefix,params);
1408 else if (command == "PUSH")
1410 return this->Push(prefix,params);
1412 else if (command == "TIMESET")
1414 return this->HandleSetTime(prefix, params);
1416 else if (command == "TIME")
1418 return this->Time(prefix,params);
1420 else if ((command == "KICK") && (Utils->IsServer(prefix)))
1422 std::string sourceserv = this->myhost;
1423 if (params.size() == 3)
1425 User* user = this->Instance->FindNick(params[1]);
1426 Channel* chan = this->Instance->FindChan(params[0]);
1429 if (!chan->ServerKickUser(user, params[2].c_str(), false))
1430 /* Yikes, the channels gone! */
1434 if (!this->InboundServerName.empty())
1436 sourceserv = this->InboundServerName;
1438 return Utils->DoOneToAllButSenderRaw(line,sourceserv,prefix,command,params);
1440 else if (command == "SVSJOIN")
1442 return this->ServiceJoin(prefix,params);
1444 else if (command == "SVSPART")
1446 return this->ServicePart(prefix,params);
1448 else if (command == "SQUIT")
1450 if (params.size() == 2)
1452 this->Squit(Utils->FindServer(params[0]),params[1]);
1456 else if (command == "OPERNOTICE")
1458 std::string sourceserv = this->myhost;
1459 if (!this->InboundServerName.empty())
1460 sourceserv = this->InboundServerName;
1461 if (params.size() >= 1)
1462 Instance->WriteOpers("*** From " + prefix + ": " + params[0]);
1463 return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
1465 else if (command == "MODENOTICE")
1467 std::string sourceserv = this->myhost;
1468 if (!this->InboundServerName.empty())
1469 sourceserv = this->InboundServerName;
1470 if (params.size() >= 2)
1472 Instance->WriteMode(params[0].c_str(), WM_AND, "*** From %s: %s", prefix.c_str(), params[1].c_str());
1474 return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
1476 else if (command == "SNONOTICE")
1478 std::string sourceserv = this->myhost;
1479 if (!this->InboundServerName.empty())
1480 sourceserv = this->InboundServerName;
1481 if (params.size() >= 2)
1483 Instance->SNO->WriteToSnoMask(*(params[0].c_str()), "From " + prefix + ": "+ params[1]);
1485 return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
1487 else if (command == "ENDBURST")
1489 this->bursting = false;
1490 Instance->XLines->ApplyLines();
1491 std::string sourceserv = this->myhost;
1492 if (!this->InboundServerName.empty())
1493 sourceserv = this->InboundServerName;
1494 this->Instance->SNO->WriteToSnoMask('l',"Received end of netburst from \2%s\2",sourceserv.c_str());
1496 Event rmode((char*)sourceserv.c_str(), (Module*)Utils->Creator, "new_server");
1497 rmode.Send(Instance);
1504 * Not a special s2s command. Emulate the user doing it.
1505 * This saves us having a huge ugly command parser again.
1507 User *who = this->Instance->FindUUID(prefix);
1509 std::string sourceserv = this->myhost;
1510 if (!this->InboundServerName.empty())
1512 sourceserv = this->InboundServerName;
1514 if ((!who) && (command == "MODE"))
1516 if (Utils->IsServer(prefix))
1518 const char* modelist[MAXPARAMETERS];
1519 for (size_t i = 0; i < params.size(); i++)
1520 modelist[i] = params[i].c_str();
1521 this->Instance->SendMode(modelist, params.size(), this->Instance->FakeClient);
1522 /* Hot potato! pass it on! */
1523 return Utils->DoOneToAllButSenderRaw(line,sourceserv,prefix,command,params);
1528 if (command == "NICK")
1530 if (params.size() != 2)
1532 SendError("Protocol violation: NICK message without TS - :"+std::string(who->uuid)+" NICK "+params[0]);
1535 /* Update timestamp on user when they change nicks */
1536 who->age = atoi(params[1].c_str());
1538 /* On nick messages, check that the nick doesnt
1539 * already exist here. If it does, kill their copy,
1542 User* x = this->Instance->FindNickOnly(params[0]);
1543 if ((x) && (x != who))
1546 /* x is local, who is remote */
1547 collideret = this->DoCollision(x, who->age, who->ident, who->GetIPString(), who->uuid);
1548 if (collideret != 1)
1551 * Remote client lost, or both lost,
1552 * parsing this nickchange would be
1553 * pointless, as the incoming client's
1554 * server will soon recieve SVSNICK to
1555 * change its nick to its UID. :)
1561 Old nickname collision logic..
1562 std::deque<std::string> p;
1563 p.push_back(params[0]);
1564 p.push_back(":Nickname collision ("+prefix+" -> "+params[0]+")");
1565 Utils->DoOneToMany(this->Instance->Config->ServerName,"KILL",p);
1567 p.push_back(prefix);
1568 p.push_back(":Nickname collision");
1569 Utils->DoOneToMany(this->Instance->Config->ServerName,"KILL",p);
1570 User::QuitUser(this->Instance,x,"Nickname collision ("+prefix+" -> "+params[0]+")");
1571 User* y = this->Instance->FindNick(prefix);
1574 User::QuitUser(this->Instance,y,"Nickname collision");
1576 return Utils->DoOneToAllButSenderRaw(line,sourceserv,prefix,command,params);
1581 target = who->server;
1582 const char* strparams[127];
1583 for (unsigned int q = 0; q < params.size(); q++)
1585 strparams[q] = params[q].c_str();
1587 switch (this->Instance->CallCommandHandler(command.c_str(), strparams, params.size(), who))
1590 this->SendError("Unrecognised or malformed command '"+std::string(command.c_str())+"' -- possibly loaded mismatched modules");
1597 /* CMD_SUCCESS and CMD_USER_DELETED fall through here */
1603 // its not a user. Its either a server, or somethings screwed up.
1604 if (Utils->IsServer(prefix))
1605 target = this->Instance->Config->GetSID();
1609 return Utils->DoOneToAllButSenderRaw(line,sourceserv,prefix,command,params);
1618 std::string TreeSocket::GetName()
1620 std::string sourceserv = this->myhost;
1621 if (!this->InboundServerName.empty())
1623 sourceserv = this->InboundServerName;
1628 void TreeSocket::OnTimeout()
1630 if (this->LinkState == CONNECTING)
1632 Utils->Creator->RemoteMessage(NULL, "CONNECT: Connection to \002%s\002 timed out.", myhost.c_str());
1633 Link* MyLink = Utils->FindLink(myhost);
1635 Utils->DoFailOver(MyLink);
1639 void TreeSocket::OnClose()
1641 if (this->LinkState == LISTENER)
1644 // Connection closed.
1645 // If the connection is fully up (state CONNECTED)
1646 // then propogate a netsplit to all peers.
1647 std::string quitserver = this->myhost;
1648 if (!this->InboundServerName.empty())
1650 quitserver = this->InboundServerName;
1652 TreeServer* s = Utils->FindServer(quitserver);
1655 Squit(s,"Remote host closed the connection");
1658 if (!quitserver.empty())
1660 Utils->Creator->RemoteMessage(NULL,"Connection to '\2%s\2' failed.",quitserver.c_str());
1661 time_t server_uptime = Instance->Time() - this->age;
1663 Utils->Creator->RemoteMessage(NULL,"Connection to '\2%s\2' was established for %s", quitserver.c_str(), Utils->Creator->TimeToStr(server_uptime).c_str());
1667 int TreeSocket::OnIncomingConnection(int newsock, char* ip)
1669 /* To prevent anyone from attempting to flood opers/DDoS by connecting to the server port,
1670 * or discovering if this port is the server port, we don't allow connections from any
1671 * IPs for which we don't have a link block.
1675 found = (std::find(Utils->ValidIPs.begin(), Utils->ValidIPs.end(), ip) != Utils->ValidIPs.end());
1678 for (vector<std::string>::iterator i = Utils->ValidIPs.begin(); i != Utils->ValidIPs.end(); i++)
1679 if (irc::sockets::MatchCIDR(ip, (*i).c_str()))
1684 Utils->Creator->RemoteMessage(NULL,"Server connection from %s denied (no link blocks with that IP address)", ip);
1685 Instance->SE->Close(newsock);
1690 TreeSocket* s = new TreeSocket(this->Utils, this->Instance, newsock, ip, this->Hook);
1691 s = s; /* Whinge whinge whinge, thats all GCC ever does. */