+ void Prioritize()
+ {
+ /* Needs to be after m_banexception etc. */
+ ServerInstance->Modules->SetPriority(this, I_OnCheckBan, PRIORITY_LAST);
+
+ /* but before m_conn_umodes, so host is generated ready to apply */
+ Module *um = ServerInstance->Modules->Find("m_conn_umodes.so");
+ ServerInstance->Modules->SetPriority(this, I_OnUserConnect, PRIORITY_AFTER, &um);
+ }
+
+ virtual void OnUserDisconnect(User* user)
+ {
+ std::string* tofree;
+ if (user->GetExt("cloaked_host", tofree))
+ {
+ delete tofree;
+ user->Shrink("cloaked_host");
+ }
+ }
+
+ virtual void OnCleanup(int target_type, void* item)
+ {
+ if (target_type == TYPE_USER)
+ OnUserDisconnect((User*)item);
+ }
+
+ virtual ~ModuleCloaking()
+ {
+ ServerInstance->Modes->DelMode(cu);
+ delete cu;
+ ServerInstance->Modules->DoneWithInterface("HashRequest");
+ }
+
+ virtual Version GetVersion()
+ {
+ // returns the version number of the module to be
+ // listed in /MODULES
+ return Version("$Id$", VF_COMMON|VF_VENDOR,API_VERSION);
+ }
+
+ virtual void OnRehash(User* user)
+ {
+ cu->DoRehash();
+ }
+
+ virtual void OnUserConnect(User* dest)
+ {
+ std::string* tofree;
+ if (dest->GetExt("cloaked_host", tofree))
+ return;
+
+ if (dest->host.find('.') != std::string::npos || dest->host.find(':') != std::string::npos)
+ {
+ unsigned int iv[] = { cu->key1, cu->key2, cu->key3, cu->key4 };
+ std::string a = cu->LastTwoDomainParts(dest->host);
+ std::string b;
+
+ /* InspIRCd users have two hostnames; A displayed
+ * hostname which can be modified by modules (e.g.
+ * to create vhosts, implement chghost, etc) and a
+ * 'real' hostname which you shouldnt write to.
+ */
+
+ /* 2008/08/18: add <cloak:ipalways> which always cloaks
+ * the IP, for anonymity. --nenolod
+ */
+ if (!cu->ipalways)
+ {
+ /** Reset the Hash module, and send it our IV and hex table */
+ HashResetRequest(this, cu->HashProvider).Send();
+ HashKeyRequest(this, cu->HashProvider, iv).Send();
+ HashHexRequest(this, cu->HashProvider, cu->xtab[(dest->host[0]) % 4]);
+
+ /* Generate a cloak using specialized Hash */
+ std::string hostcloak = cu->prefix + "-" + std::string(HashSumRequest(this, cu->HashProvider, dest->host.c_str()).Send()).substr(0,8) + a;
+
+ /* Fix by brain - if the cloaked host is > the max length of a host (64 bytes
+ * according to the DNS RFC) then tough titty, they get cloaked as an IP.
+ * Their ISP shouldnt go to town on subdomains, or they shouldnt have a kiddie
+ * vhost.
+ */
+ std::string testaddr;
+ int testport;
+ if (!irc::sockets::satoap(&dest->client_sa, testaddr, testport) && (hostcloak.length() <= 64))
+ /* not a valid address, must have been a host, so cloak as a host */
+ b = hostcloak;
+ else if (dest->client_sa.sa.sa_family == AF_INET6)
+ b = cu->Cloak6(dest->GetIPString());
+ else
+ b = cu->Cloak4(dest->GetIPString());
+ }
+ else
+ {
+ if (dest->client_sa.sa.sa_family == AF_INET6)
+ b = cu->Cloak6(dest->GetIPString());
+ else
+ b = cu->Cloak4(dest->GetIPString());
+ }
+
+ dest->Extend("cloaked_host", new std::string(b));
+ }
+ }
+
+};