X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_spanningtree%2Fmain.cpp;h=8b24b1e226b7a3e61d996b831679287272c8e473;hb=9f3502de449f3bd4a88163ddc39626305071531f;hp=2fd578698e2151f722117c43080d7a65b5a59858;hpb=35b70631f0532a5828b04a8e0c02092a285f331a;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index 2fd578698..8b24b1e22 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -37,14 +37,17 @@ #include "translate.h" ModuleSpanningTree::ModuleSpanningTree() - : Stats::EventListener(this) + : Away::EventListener(this) + , Stats::EventListener(this) , rconnect(this) , rsquit(this) , map(this) , commands(this) , currmembid(0) , eventprov(this, "event/server") + , sslapi(this) , DNS(this, "DNS") + , tagevprov(this, "event/messagetag") , loopCall(false) { } @@ -136,7 +139,7 @@ void ModuleSpanningTree::ShowLinks(TreeServer* Current, User* user, int hops) InspIRCd::Format("%d %s", (((Utils->FlatLinks) && (!user->IsOper())) ? 0 : hops), Current->GetDesc().c_str())); } -void ModuleSpanningTree::HandleLinks(const std::vector& parameters, User* user) +void ModuleSpanningTree::HandleLinks(const CommandBase::Params& parameters, User* user) { ShowLinks(Utils->TreeRoot,user,0); user->WriteNumeric(RPL_ENDOFLINKS, '*', "End of /LINKS list."); @@ -195,32 +198,38 @@ void ModuleSpanningTree::ConnectServer(Autoconnect* a, bool on_timer) void ModuleSpanningTree::ConnectServer(Link* x, Autoconnect* y) { - bool ipvalid = true; - if (InspIRCd::Match(ServerInstance->Config->ServerName, x->Name, ascii_case_insensitive_map)) { ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Not connecting to myself."); return; } - if (strchr(x->IPAddr.c_str(),':')) + irc::sockets::sockaddrs sa; +#ifndef _WIN32 + if (x->IPAddr.find('/') != std::string::npos) { - in6_addr n; - if (inet_pton(AF_INET6, x->IPAddr.c_str(), &n) < 1) - ipvalid = false; + struct stat sb; + if (stat(x->IPAddr.c_str(), &sb) == -1 || !S_ISSOCK(sb.st_mode) || !irc::sockets::untosa(x->IPAddr, sa)) + { + // We don't use the family() != AF_UNSPEC check below for UNIX sockets as + // that results in a DNS lookup. + ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: %s is not a UNIX socket!", + x->Name.c_str(), x->IPAddr.c_str()); + return; + } } else +#endif { - in_addr n; - if (inet_pton(AF_INET, x->IPAddr.c_str(),&n) < 1) - ipvalid = false; + // If this fails then the IP sa will be AF_UNSPEC. + irc::sockets::aptosa(x->IPAddr, x->Port, sa); } - + /* Do we already have an IP? If so, no need to resolve it. */ - if (ipvalid) + if (sa.family() != AF_UNSPEC) { // Create a TreeServer object that will start connecting immediately in the background - TreeSocket* newsocket = new TreeSocket(x, y, x->IPAddr); + TreeSocket* newsocket = new TreeSocket(x, y, sa); if (newsocket->GetFd() > -1) { /* Handled automatically on success */ @@ -243,7 +252,7 @@ void ModuleSpanningTree::ConnectServer(Link* x, Autoconnect* y) irc::sockets::sockaddrs bind; if ((!x->Bind.empty()) && (irc::sockets::aptosa(x->Bind, 0, bind))) { - if (bind.sa.sa_family == AF_INET) + if (bind.family() == AF_INET) start_type = DNS::QUERY_A; } @@ -297,7 +306,7 @@ void ModuleSpanningTree::DoConnectTimeout(time_t curtime) } } -ModResult ModuleSpanningTree::HandleVersion(const std::vector& parameters, User* user) +ModResult ModuleSpanningTree::HandleVersion(const CommandBase::Params& parameters, User* user) { // We've already confirmed that !parameters.empty(), so this is safe TreeServer* found = Utils->FindServerMask(parameters[0]); @@ -314,8 +323,12 @@ ModResult ModuleSpanningTree::HandleVersion(const std::vector& para // If it's empty it might be that the server is still syncing (full version hasn't arrived yet) // or the server is a 2.0 server and does not send a full version. bool showfull = ((user->IsOper()) && (!found->GetFullVersion().empty())); - const std::string& Version = (showfull ? found->GetFullVersion() : found->GetVersion()); - user->WriteNumeric(RPL_VERSION, Version); + + Numeric::Numeric numeric(RPL_VERSION); + irc::tokenstream tokens(showfull ? found->GetFullVersion() : found->GetVersion()); + for (std::string token; tokens.GetTrailing(token); ) + numeric.push(token); + user->WriteNumeric(numeric); } else { @@ -324,7 +337,7 @@ ModResult ModuleSpanningTree::HandleVersion(const std::vector& para return MOD_RES_DENY; } -ModResult ModuleSpanningTree::HandleConnect(const std::vector& parameters, User* user) +ModResult ModuleSpanningTree::HandleConnect(const CommandBase::Params& parameters, User* user) { for (std::vector >::iterator i = Utils->LinkBlocks.begin(); i < Utils->LinkBlocks.end(); i++) { @@ -401,6 +414,7 @@ void ModuleSpanningTree::OnUserPostMessage(User* user, const MessageTarget& targ if (!IS_LOCAL(d)) { CmdBuilder params(user, message_type); + params.push_tags(details.tags_out); params.push_back(d->uuid); params.push_last(details.text); params.Unicast(d); @@ -408,12 +422,13 @@ void ModuleSpanningTree::OnUserPostMessage(User* user, const MessageTarget& targ } else if (target.type == MessageTarget::TYPE_CHANNEL) { - Utils->SendChannelMessage(user->uuid, target.Get(), details.text, target.status, details.exemptions, message_type); + Utils->SendChannelMessage(user->uuid, target.Get(), details.text, target.status, details.tags_out, details.exemptions, message_type); } else if (target.type == MessageTarget::TYPE_SERVER) { const std::string* serverglob = target.Get(); CmdBuilder par(user, message_type); + par.push_tags(details.tags_out); par.push_back(*serverglob); par.push_last(details.text); par.Broadcast(); @@ -431,6 +446,10 @@ void ModuleSpanningTree::OnUserConnect(LocalUser* user) if (user->quitting) return; + // Create the lazy ssl_cert metadata for this user if not already created. + if (sslapi) + sslapi->GetCertificate(user); + CommandUID::Builder(user).Broadcast(); if (user->IsOper()) @@ -485,12 +504,12 @@ void ModuleSpanningTree::OnChangeHost(User* user, const std::string &newhost) CmdBuilder(user, "FHOST").push(newhost).Broadcast(); } -void ModuleSpanningTree::OnChangeName(User* user, const std::string &gecos) +void ModuleSpanningTree::OnChangeRealName(User* user, const std::string& real) { if (user->registered != REG_ALL || !IS_LOCAL(user)) return; - CmdBuilder(user, "FNAME").push_last(gecos).Broadcast(); + CmdBuilder(user, "FNAME").push_last(real).Broadcast(); } void ModuleSpanningTree::OnChangeIdent(User* user, const std::string &ident) @@ -573,9 +592,6 @@ void ModuleSpanningTree::OnUserKick(User* source, Membership* memb, const std::s void ModuleSpanningTree::OnPreRehash(User* user, const std::string ¶meter) { - if (loopCall) - return; // Don't generate a REHASH here if we're in the middle of processing a message that generated this one - ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "OnPreRehash called with param %s", parameter.c_str()); // Send out to other servers @@ -710,15 +726,19 @@ void ModuleSpanningTree::OnDelLine(User* user, XLine *x) params.Broadcast(); } -ModResult ModuleSpanningTree::OnSetAway(User* user, const std::string &awaymsg) +void ModuleSpanningTree::OnUserAway(User* user) { if (IS_LOCAL(user)) - CommandAway::Builder(user, awaymsg).Broadcast(); + CommandAway::Builder(user).Broadcast(); +} - return MOD_RES_PASSTHRU; +void ModuleSpanningTree::OnUserBack(User* user) +{ + if (IS_LOCAL(user)) + CommandAway::Builder(user).Broadcast(); } -void ModuleSpanningTree::OnMode(User* source, User* u, Channel* c, const Modes::ChangeList& modes, ModeParser::ModeProcessFlag processflags, const std::string& output_mode) +void ModuleSpanningTree::OnMode(User* source, User* u, Channel* c, const Modes::ChangeList& modes, ModeParser::ModeProcessFlag processflags) { if (processflags & ModeParser::MODE_LOCALONLY) return; @@ -730,7 +750,7 @@ void ModuleSpanningTree::OnMode(User* source, User* u, Channel* c, const Modes:: CmdBuilder params(source, "MODE"); params.push(u->uuid); - params.push(output_mode); + params.push(ClientProtocol::Messages::Mode::ToModeLetters(modes)); params.push_raw(Translate::ModeChangeListToParams(modes.getlist())); params.Broadcast(); } @@ -739,7 +759,7 @@ void ModuleSpanningTree::OnMode(User* source, User* u, Channel* c, const Modes:: CmdBuilder params(source, "FMODE"); params.push(c->name); params.push_int(c->age); - params.push(output_mode); + params.push(ClientProtocol::Messages::Mode::ToModeLetters(modes)); params.push_raw(Translate::ModeChangeListToParams(modes.getlist())); params.Broadcast(); }