X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_cloaking.cpp;h=f26e16e0e2edb7cb25a204ef0cba60f88d08c138;hb=40e990ed06126c1ba6164738527127d1f58fc032;hp=ab13708ea583d181cd03c5b2dfc9e6179b2d4590;hpb=0757a4a495daabf661ac3b7ab79f0a5ee423abe8;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_cloaking.cpp b/src/modules/m_cloaking.cpp index ab13708ea..f26e16e0e 100644 --- a/src/modules/m_cloaking.cpp +++ b/src/modules/m_cloaking.cpp @@ -35,6 +35,7 @@ #ifdef HAS_STDINT #include #endif +#include "configreader.h" #include "inspircd.h" #include "users.h" #include "channels.h" @@ -43,6 +44,7 @@ /* $ModDesc: Provides masking of user hostnames */ + /* The four core functions - F1 is optimized somewhat */ #define F1(x, y, z) (z ^ (x & (y ^ z))) @@ -68,7 +70,7 @@ class xMD5Context : public classbase class CloakUser : public ModeHandler { - Server* Srv; + std::string prefix; word32 key1; word32 key2; @@ -283,14 +285,20 @@ class CloakUser : public ModeHandler } public: - CloakUser(Server* Me) : ModeHandler('x', 0, 0, false, MODETYPE_USER, false), Srv(Me) { } + CloakUser(InspIRCd* Instance) : ModeHandler(Instance, 'x', 0, 0, false, MODETYPE_USER, false) { } ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding) { /* Only opers can change other users modes */ if ((source != dest) && (!*source->oper)) return MODEACTION_DENY; - + + /* For remote clients, we dont take any action, we just allow it. + * The local server where they are will set their cloak instead. + */ + if (!IS_LOCAL(dest)) + return MODEACTION_ALLOW; + if (adding) { if(!dest->IsModeSet('x')) @@ -304,20 +312,24 @@ class CloakUser : public ModeHandler * are connecting via localhost) -- this doesnt matter much. */ - if (strchr(dest->host,'.')) + if (strchr(dest->host,'.') || strchr(dest->host,':')) { /* 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. */ - - std::string a = strstr(dest->host,"."); + + char* n = strstr(dest->host,"."); + if (!n) + n = strstr(dest->host,":"); + + std::string a = n; char ra[64]; this->GenHash(dest->host,ra); std::string b = ""; - in_addr testaddr; + insp_inaddr testaddr; std::string hostcloak = prefix + "-" + std::string(ra) + a; /* Fix by brain - if the cloaked host is > the max length of a host (64 bytes @@ -325,8 +337,8 @@ class CloakUser : public ModeHandler * Their ISP shouldnt go to town on subdomains, or they shouldnt have a kiddie * vhost. */ - - if ((!inet_aton(dest->host,&testaddr)) && (hostcloak.length() < 64)) + + if ((insp_aton(dest->host,&testaddr) < 1) && (hostcloak.length() < 64)) { // if they have a hostname, make something appropriate b = hostcloak; @@ -336,8 +348,8 @@ class CloakUser : public ModeHandler // else, they have an ip b = std::string(ra) + "." + prefix + ".cloak"; } - Srv->Log(DEBUG,"cloak: allocated "+b); - Srv->ChangeHost(dest,b); + ServerInstance->Log(DEBUG,"cloak: allocated "+b); + dest->ChangeDisplayedHost(b.c_str()); } dest->SetMode('x',true); @@ -351,7 +363,7 @@ class CloakUser : public ModeHandler /* User is removing the mode, so just restore their real host * and make it match the displayed one. */ - Srv->ChangeHost(dest,dest->host); + dest->ChangeDisplayedHost(dest->host); dest->SetMode('x',false); return MODEACTION_ALLOW; } @@ -362,7 +374,7 @@ class CloakUser : public ModeHandler void DoRehash() { - ConfigReader Conf; + ConfigReader Conf(ServerInstance); key1 = key2 = key3 = key4 = 0; key1 = Conf.ReadInteger("cloak","key1",0,false); key2 = Conf.ReadInteger("cloak","key2",0,false); @@ -372,7 +384,7 @@ class CloakUser : public ModeHandler prefix = Conf.ReadValue("cloak","prefix",0); if (prefix == "") { - prefix = Srv->GetNetworkName(); + prefix = ServerInstance->Config->Network; } if (!key1 && !key2 && !key3 && !key4) { @@ -386,24 +398,25 @@ class CloakUser : public ModeHandler class ModuleCloaking : public Module { private: - Server *Srv; + CloakUser* cu; public: - ModuleCloaking(Server* Me) - : Module::Module(Me), Srv(Me) + ModuleCloaking(InspIRCd* Me) + : Module::Module(Me) { /* Create new mode handler object */ - cu = new CloakUser(Srv); + cu = new CloakUser(ServerInstance); /* Register it with the core */ - Srv->AddMode(cu, 'x'); + ServerInstance->AddMode(cu, 'x'); OnRehash(""); } virtual ~ModuleCloaking() { + ServerInstance->Modes->DelMode(cu); DELETE(cu); } @@ -411,7 +424,7 @@ class ModuleCloaking : public Module { // returns the version number of the module to be // listed in /MODULES - return Version(1,0,0,2,VF_STATIC|VF_VENDOR); + return Version(1,0,0,2,VF_COMMON|VF_VENDOR); } virtual void OnRehash(const std::string ¶meter) @@ -435,7 +448,7 @@ class ModuleCloaking : public Module const char* modes[2]; // only two parameters modes[0] = user->nick; // first parameter is the nick modes[1] = "+x"; // second parameter is the mode - Srv->SendMode(modes,2,user); // send these, forming the command "MODE +x" + ServerInstance->SendMode(modes,2,user); // send these, forming the command "MODE +x" } }; @@ -453,7 +466,7 @@ class ModuleCloakingFactory : public ModuleFactory { } - virtual Module * CreateModule(Server* Me) + virtual Module * CreateModule(InspIRCd* Me) { return new ModuleCloaking(Me); }