class CloakUser : public ModeHandler
{
public:
+ bool active;
LocalStringExt ext;
std::string debounce_uid;
time_t debounce_ts;
int debounce_count;
CloakUser(Module* source)
- : ModeHandler(source, "cloak", 'x', PARAM_NONE, MODETYPE_USER),
- ext("cloaked_host", ExtensionItem::EXT_USER, source), debounce_ts(0), debounce_count(0)
+ : ModeHandler(source, "cloak", 'x', PARAM_NONE, MODETYPE_USER)
+ , active(false)
+ , ext("cloaked_host", ExtensionItem::EXT_USER, source)
+ , debounce_ts(0)
+ , debounce_count(0)
{
}
- ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
+ ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding) CXX11_OVERRIDE
{
LocalUser* user = IS_LOCAL(dest);
*/
if (!user)
{
+ // Remote setters broadcast mode before host while local setters do the opposite, so this takes that into account
+ active = IS_LOCAL(source) ? adding : !adding;
dest->SetMode(this, adding);
return MODEACTION_ALLOW;
}
syntax = "<host>";
}
- CmdResult Handle(const std::vector<std::string> ¶meters, User *user);
+ CmdResult Handle(const std::vector<std::string>& parameters, User* user) CXX11_OVERRIDE;
};
class ModuleCloaking : public Module
unsigned int domainparts;
dynamic_reference<HashProvider> Hash;
- ModuleCloaking() : cu(this), mode(MODE_OPAQUE), ck(this), Hash(this, "hash/md5")
+ ModuleCloaking()
+ : cu(this)
+ , mode(MODE_OPAQUE)
+ , ck(this)
+ , Hash(this, "hash/md5")
{
}
* @param id A unique ID for this type of item (to make it unique if the item matches)
* @param len The length of the output. Maximum for MD5 is 16 characters.
*/
- std::string SegmentCloak(const std::string& item, char id, int len)
+ std::string SegmentCloak(const std::string& item, char id, size_t len)
{
std::string input;
input.reserve(key.length() + 3 + item.length());
input.append(item);
std::string rv = Hash->GenerateRaw(input).substr(0,len);
- for(int i=0; i < len; i++)
+ for(size_t i = 0; i < len; i++)
{
// this discards 3 bits per byte. We have an
// overabundance of bits in the hash output, doesn't
std::string SegmentIP(const irc::sockets::sockaddrs& ip, bool full)
{
std::string bindata;
- int hop1, hop2, hop3;
- int len1, len2;
+ size_t hop1, hop2, hop3;
+ size_t len1, len2;
std::string rv;
- if (ip.sa.sa_family == AF_INET6)
+ if (ip.family() == AF_INET6)
{
bindata = std::string((const char*)ip.in6.sin6_addr.s6_addr, 16);
hop1 = 8;
}
else
{
- if (ip.sa.sa_family == AF_INET6)
+ if (ip.family() == AF_INET6)
{
rv.append(InspIRCd::Format(".%02x%02x.%02x%02x%s",
ip.in6.sin6_addr.s6_addr[2], ip.in6.sin6_addr.s6_addr[3],
// mode change, we will call SetMode back to true AFTER the host change is done.
void OnChangeHost(User* u, const std::string& host) CXX11_OVERRIDE
{
- if (u->IsModeSet(cu))
+ if (u->IsModeSet(cu) && !cu.active)
{
u->SetMode(cu, false);
u->WriteCommand("MODE", "-" + ConvToStr(cu.GetModeChar()));
}
+ cu.active = false;
}
Version GetVersion() CXX11_OVERRIDE
suffix = tag->getString("suffix", ".IP");
std::string modestr = tag->getString("mode");
- if (modestr == "half")
+ if (stdalgo::string::equalsci(modestr, "half"))
{
mode = MODE_HALF_CLOAK;
- domainparts = tag->getInt("domainparts", 3, 1, 10);
+ domainparts = tag->getUInt("domainparts", 3, 1, 10);
}
- else if (modestr == "full")
+ else if (stdalgo::string::equalsci(modestr, "full"))
mode = MODE_OPAQUE;
else
throw ModuleException("Bad value for <cloak:mode>; must be half or full");
if (cloak)
return;
+ // TODO: decide how we are going to cloak AF_UNIX hostnames.
+ if (dest->client_sa.family() != AF_INET && dest->client_sa.family() != AF_INET6)
+ return;
+
cu.ext.set(dest, GenCloak(dest->client_sa, dest->GetIPString(), dest->GetRealHost()));
}
};