X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_cgiirc.cpp;h=7042bc7a7123b38edbfc792b51af029795e41ac9;hb=8fa7e20b6b47d4de617e1bba2773606df569f11d;hp=45447148bcde234da90f29ed3708f7631eaf9c26;hpb=d46783efbda0a89b92175120ed5249a3456e25ee;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_cgiirc.cpp b/src/modules/m_cgiirc.cpp index 45447148b..7042bc7a7 100644 --- a/src/modules/m_cgiirc.cpp +++ b/src/modules/m_cgiirc.cpp @@ -102,23 +102,30 @@ class CommandWebirc : public Command class CGIResolver : public Resolver { std::string typ; - int theirfd; - LocalUser* them; + std::string theiruid; + LocalIntExt& waiting; bool notify; public: - CGIResolver(Module* me, bool NotifyOpers, const std::string &source, bool forward, LocalUser* u, int userfd, const std::string &type, bool &cached) - : Resolver(source, forward ? DNS_QUERY_A : DNS_QUERY_PTR4, cached, me), typ(type), theirfd(userfd), them(u), notify(NotifyOpers) { } + CGIResolver(Module* me, bool NotifyOpers, const std::string &source, bool forward, LocalUser* u, + const std::string &type, bool &cached, LocalIntExt& ext) + : Resolver(source, forward ? DNS_QUERY_A : DNS_QUERY_PTR4, cached, me), typ(type), theiruid(u->uuid), + waiting(ext), notify(NotifyOpers) + { + } virtual void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached) { /* Check the user still exists */ - if ((them) && (&them->eh == ServerInstance->SE->GetRef(theirfd))) + User* them = ServerInstance->FindUUID(theiruid); + if (them) { if (notify) ServerInstance->SNO->WriteGlobalSno('a', "Connecting user %s detected as using CGI:IRC (%s), changing real host to %s from %s", them->nick.c_str(), them->host.c_str(), result.c_str(), typ.c_str()); - them->host.assign(result,0, 64); - them->dhost.assign(result, 0, 64); + if (result.length() > 64) + return; + them->host = result; + them->dhost = result; them->InvalidateCache(); them->CheckLines(true); } @@ -126,7 +133,8 @@ class CGIResolver : public Resolver virtual void OnError(ResolverError e, const std::string &errormessage) { - if ((them) && (&them->eh == ServerInstance->SE->GetRef(theirfd))) + User* them = ServerInstance->FindUUID(theiruid); + if (them) { if (notify) ServerInstance->SNO->WriteToSnoMask('a', "Connecting user %s detected as using CGI:IRC (%s), but their host can't be resolved from their %s!", them->nick.c_str(), them->host.c_str(), typ.c_str()); @@ -135,15 +143,26 @@ class CGIResolver : public Resolver virtual ~CGIResolver() { + User* them = ServerInstance->FindUUID(theiruid); + if (!them) + return; + int count = waiting.get(them); + if (count) + waiting.set(them, count - 1); } }; class ModuleCgiIRC : public Module { CommandWebirc cmd; + LocalIntExt waiting; bool NotifyOpers; public: - ModuleCgiIRC() : cmd(this, NotifyOpers) + ModuleCgiIRC() : cmd(this, NotifyOpers), waiting("cgiirc-delay", this) + { + } + + void init() { OnRehash(NULL); ServerInstance->AddCommand(&cmd); @@ -152,31 +171,31 @@ public: ServerInstance->Extensions.Register(&cmd.webirc_hostname); ServerInstance->Extensions.Register(&cmd.webirc_ip); - Implementation eventlist[] = { I_OnRehash, I_OnUserRegister, I_OnDecodeMetaData, I_OnUserDisconnect, I_OnUserConnect }; - ServerInstance->Modules->Attach(eventlist, this, 5); + Implementation eventlist[] = { I_OnRehash, I_OnUserRegister, I_OnCheckReady, I_OnUserConnect }; + ServerInstance->Modules->Attach(eventlist, this, 4); } - - virtual void Prioritize() + void Prioritize() { ServerInstance->Modules->SetPriority(this, I_OnUserConnect, PRIORITY_FIRST); + Module* umodes = ServerInstance->Modules->Find("m_conn_umodes.so"); + ServerInstance->Modules->SetPriority(this, I_OnUserConnect, PRIORITY_BEFORE, &umodes); } - virtual void OnRehash(User* user) + void OnRehash(User* user) { - ConfigReader Conf; cmd.Hosts.clear(); - NotifyOpers = Conf.ReadFlag("cgiirc", "opernotice", 0); // If we send an oper notice when a CGI:IRC has their host changed. + // Do we send an oper notice when a CGI:IRC has their host changed? + NotifyOpers = ServerInstance->Config->ConfValue("cgiirc")->getBool("opernotice", true); - if(Conf.GetError() == CONF_VALUE_NOT_FOUND) - NotifyOpers = true; - - for(int i = 0; i < Conf.Enumerate("cgihost"); i++) + ConfigTagList tags = ServerInstance->Config->ConfTags("cgihost"); + for (ConfigIter i = tags.first; i != tags.second; ++i) { - std::string hostmask = Conf.ReadValue("cgihost", "mask", i); // An allowed CGI:IRC host - std::string type = Conf.ReadValue("cgihost", "type", i); // What type of user-munging we do on this host. - std::string password = Conf.ReadValue("cgihost", "password", i); + ConfigTag* tag = i->second; + std::string hostmask = tag->getString("mask"); // An allowed CGI:IRC host + std::string type = tag->getString("type"); // What type of user-munging we do on this host. + std::string password = tag->getString("password"); if(hostmask.length()) { @@ -211,7 +230,14 @@ public: } } - virtual ModResult OnUserRegister(LocalUser* user) + ModResult OnCheckReady(LocalUser *user) + { + if (waiting.get(user)) + return MOD_RES_DENY; + return MOD_RES_PASSTHRU; + } + + ModResult OnUserRegister(LocalUser* user) { for(CGIHostlist::iterator iter = cmd.Hosts.begin(); iter != cmd.Hosts.end(); iter++) { @@ -254,12 +280,11 @@ public: { std::string *webirc_hostname = cmd.webirc_hostname.get(user); std::string *webirc_ip = cmd.webirc_ip.get(user); - if (webirc_hostname) + if (webirc_hostname && webirc_hostname->length() < 64) { - user->host.assign(*webirc_hostname, 0, 64); - user->dhost.assign(*webirc_hostname, 0, 64); + user->host = *webirc_hostname; + user->dhost = *webirc_hostname; user->InvalidateCache(); - cmd.webirc_hostname.unset(user); } if (webirc_ip) { @@ -273,6 +298,7 @@ public: user->CheckClass(); user->CheckLines(true); } + cmd.webirc_hostname.unset(user); } bool CheckPass(LocalUser* user) @@ -281,8 +307,8 @@ public: { cmd.realhost.set(user, user->host); cmd.realip.set(user, user->GetIPString()); - user->host.assign(user->password, 0, 64); - user->dhost.assign(user->password, 0, 64); + user->host = user->password; + user->dhost = user->password; user->InvalidateCache(); ServerInstance->Users->RemoveCloneCounts(user); @@ -294,10 +320,10 @@ public: try { - bool cached; - CGIResolver* r = new CGIResolver(this, NotifyOpers, user->password, false, user, user->GetFd(), "PASS", cached); + CGIResolver* r = new CGIResolver(this, NotifyOpers, user->password, false, user, "PASS", cached, waiting); ServerInstance->AddResolver(r, cached); + waiting.set(user, waiting.get(user) + 1); } catch (...) { @@ -347,8 +373,9 @@ public: { bool cached; - CGIResolver* r = new CGIResolver(this, NotifyOpers, newipstr, false, user, user->GetFd(), "IDENT", cached); + CGIResolver* r = new CGIResolver(this, NotifyOpers, newipstr, false, user, "IDENT", cached, waiting); ServerInstance->AddResolver(r, cached); + waiting.set(user, waiting.get(user) + 1); } catch (...) { @@ -363,7 +390,7 @@ public: bool IsValidHost(const std::string &host) { - if(!host.size()) + if(!host.size() || host.size() > 64) return false; for(unsigned int i = 0; i < host.size(); i++)