X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_flashpolicyd.cpp;h=a53f7f1a831e1d9f4e24b5ba540dcfe11904a6f9;hb=HEAD;hp=46fd33e612e818b91915e01ac907de3407ddc596;hpb=e164675ed98468350a78fa69ca4d18670959c200;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_flashpolicyd.cpp b/src/modules/m_flashpolicyd.cpp index 46fd33e61..a53f7f1a8 100644 --- a/src/modules/m_flashpolicyd.cpp +++ b/src/modules/m_flashpolicyd.cpp @@ -1,6 +1,11 @@ /* * InspIRCd -- Internet Relay Chat Daemon * + * Copyright (C) 2019 Robby + * Copyright (C) 2018 linuxdaemon + * Copyright (C) 2017-2018, 2020-2021 Sadie Powell + * Copyright (C) 2014 JustArchi + * Copyright (C) 2014 Attila Molnar * Copyright (C) 2013 Daniel Vassdal * * This file is part of InspIRCd. InspIRCd is free software: you can @@ -23,20 +28,30 @@ class FlashPDSocket; namespace { - std::set sockets; + insp::intrusive_list sockets; std::string policy_reply; const std::string expected_request("\0", 23); } -class FlashPDSocket : public BufferedSocket +class FlashPDSocket : public BufferedSocket, public Timer, public insp::intrusive_list_node { - public: - time_t created; + /** True if this object is in the cull list + */ + bool waitingcull; - FlashPDSocket(int newfd) + bool Tick(time_t currtime) CXX11_OVERRIDE + { + AddToCull(); + return false; + } + + public: + FlashPDSocket(int newfd, unsigned int timeoutsec) : BufferedSocket(newfd) - , created(ServerInstance->Time()) + , Timer(timeoutsec) + , waitingcull(false) { + ServerInstance->Timers.AddTimer(this); } ~FlashPDSocket() @@ -58,10 +73,10 @@ class FlashPDSocket : public BufferedSocket void AddToCull() { - if (created == 0) + if (waitingcull) return; - created = 0; + waitingcull = true; Close(); ServerInstance->GlobalCulls.AddItem(this); } @@ -69,35 +84,24 @@ class FlashPDSocket : public BufferedSocket class ModuleFlashPD : public Module { - time_t timeout; + unsigned int timeout; public: - void OnBackgroundTimer(time_t curtime) CXX11_OVERRIDE - { - for (std::set::const_iterator i = sockets.begin(); i != sockets.end(); ++i) - { - FlashPDSocket* sock = *i; - if ((sock->created + timeout <= curtime) && (sock->created != 0)) - sock->AddToCull(); - } - } - ModResult OnAcceptConnection(int nfd, ListenSocket* from, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) CXX11_OVERRIDE { - if (from->bind_tag->getString("type") != "flashpolicyd") + if (!stdalgo::string::equalsci(from->bind_tag->getString("type"), "flashpolicyd")) return MOD_RES_PASSTHRU; if (policy_reply.empty()) return MOD_RES_DENY; - sockets.insert(new FlashPDSocket(nfd)); + sockets.push_front(new FlashPDSocket(nfd, timeout)); return MOD_RES_ALLOW; } void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE { ConfigTag* tag = ServerInstance->Config->ConfValue("flashpolicyd"); - timeout = tag->getInt("timeout", 5, 1); std::string file = tag->getString("file"); if (!file.empty()) @@ -109,10 +113,7 @@ class ModuleFlashPD : public Module } catch (CoreException&) { - const std::string error_message = "A file was specified for FlashPD, but it could not be loaded."; - ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, error_message); - ServerInstance->SNO->WriteGlobalSno('a', error_message); - policy_reply.clear(); + throw ModuleException("A file was specified for FlashPD, but it could not be loaded at " + tag->getTagLocation()); } return; } @@ -123,10 +124,13 @@ class ModuleFlashPD : public Module for (std::vector::const_iterator i = ServerInstance->ports.begin(); i != ServerInstance->ports.end(); ++i) { ListenSocket* ls = *i; - if (ls->bind_tag->getString("type", "clients") != "clients" || ls->bind_tag->getString("ssl", "plaintext") != "plaintext") + if (!stdalgo::string::equalsci(ls->bind_tag->getString("type", "clients", 1), "clients")) + continue; + + if (!ls->bind_tag->getString("sslprofile", ls->bind_tag->getString("ssl")).empty()) continue; - to_ports.append(ConvToStr(ls->bind_port)).push_back(','); + to_ports.append(ConvToStr(ls->bind_sa.port())).push_back(','); } if (to_ports.empty()) @@ -144,11 +148,12 @@ class ModuleFlashPD : public Module \ \ "; + timeout = tag->getDuration("timeout", 5, 1); } - CullResult cull() + CullResult cull() CXX11_OVERRIDE { - for (std::set::const_iterator i = sockets.begin(); i != sockets.end(); ++i) + for (insp::intrusive_list::const_iterator i = sockets.begin(); i != sockets.end(); ++i) { FlashPDSocket* sock = *i; sock->AddToCull(); @@ -158,7 +163,7 @@ class ModuleFlashPD : public Module Version GetVersion() CXX11_OVERRIDE { - return Version("Flash Policy Daemon. Allows Flash IRC clients to connect", VF_VENDOR); + return Version("Allows connection policies to be served to IRC clients that use Adobe Flash.", VF_VENDOR); } };