Example #1
0
	void init() override
	{
		ConfigTagList tags = ServerInstance->Config->ConfTags("customprefix");
		for (ConfigIter iter = tags.first; iter != tags.second; ++iter)
		{
			ConfigTag* tag = iter->second;

			const std::string name = tag->getString("name");
			if (name.empty())
				throw ModuleException("<customprefix:name> must be specified at " + tag->getTagLocation());

			if (tag->getBool("change"))
			{
				ModeHandler* mh = ServerInstance->Modes.FindMode(name, MODETYPE_CHANNEL);
				if (!mh)
					throw ModuleException("<customprefix:change> specified for a non-existent mode at " + tag->getTagLocation());

				PrefixMode* pm = mh->IsPrefixMode();
				if (!pm)
					throw ModuleException("<customprefix:change> specified for a non-prefix mode at " + tag->getTagLocation());

				unsigned long rank = tag->getUInt("rank", pm->GetPrefixRank(), 0, UINT_MAX);
				unsigned long setrank = tag->getUInt("ranktoset", pm->GetLevelRequired(true), rank, UINT_MAX);
				unsigned long unsetrank = tag->getUInt("ranktounset", pm->GetLevelRequired(false), setrank, UINT_MAX);
				bool depriv = tag->getBool("depriv", pm->CanSelfRemove());
				pm->Update(rank, setrank, unsetrank, depriv);

				ServerInstance->Logs.Log(MODNAME, LOG_DEBUG, "Changed the %s prefix: depriv=%u rank=%u ranktoset=%u ranktounset=%u",
					pm->name.c_str(), pm->CanSelfRemove(), pm->GetPrefixRank(), pm->GetLevelRequired(true), pm->GetLevelRequired(false));
				continue;
			}

			const std::string letter = tag->getString("letter");
			if (letter.length() != 1)
				throw ModuleException("<customprefix:letter> must be set to a mode character at " + tag->getTagLocation());

			const std::string prefix = tag->getString("prefix");
			if (prefix.length() != 1)
				throw ModuleException("<customprefix:prefix> must be set to a mode prefix at " + tag->getTagLocation());

			try
			{
				CustomPrefixMode* mh = new CustomPrefixMode(this, name, letter[0], prefix[0], tag);
				modes.push_back(mh);
				ServerInstance->Modules.AddService(*mh);
			}
			catch (ModuleException& e)
			{
				throw ModuleException(e.GetReason() + " (while creating mode from " + tag->getTagLocation() + ")");
			}
		}
	}
Example #2
0
	void ReadConfig()
	{
		ConfigTag* conf = ServerInstance->Config->ConfValue("repeat");
		ms.MaxLines = conf->getUInt("maxlines", 20);
		ms.MaxBacklog = conf->getUInt("maxbacklog", 20);
		ms.MaxSecs = conf->getDuration("maxtime", 0);

		ms.MaxDiff = conf->getUInt("maxdistance", 50);
		if (ms.MaxDiff > 100)
			ms.MaxDiff = 100;

		unsigned int newsize = conf->getUInt("size", 512);
		if (newsize > ServerInstance->Config->Limits.MaxLine)
			newsize = ServerInstance->Config->Limits.MaxLine;
		Resize(newsize);
	}
Example #3
0
	void ReadConfig(ConfigStatus& status) override
	{
		// TODO: Multiple SNI profiles
		ConfigTag* tag = ServerInstance->Config->ConfValue("sts");
		if (tag == ServerInstance->Config->EmptyTag)
			throw ModuleException("You must define a STS policy!");

		const std::string host = tag->getString("host");
		if (host.empty())
			throw ModuleException("<sts:host> must contain a hostname, at " + tag->getTagLocation());

		unsigned int port = tag->getUInt("port", 0, 0, UINT16_MAX);
		if (!HasValidSSLPort(port))
			throw ModuleException("<sts:port> must be a TLS port, at " + tag->getTagLocation());

		unsigned long duration = tag->getDuration("duration", 60*60*24*30*2);
		bool preload = tag->getBool("preload");
		cap.SetPolicy(host, duration, port, preload);
	}
Example #4
0
void ServerConfig::Fill()
{
	ConfigTag* options = ConfValue("options");
	ConfigTag* security = ConfValue("security");
	ConfigTag* server = ConfValue("server");
	if (sid.empty())
	{
		ServerName = server->getString("name", "irc.example.com", InspIRCd::IsHost);

		sid = server->getString("id");
		if (!sid.empty() && !InspIRCd::IsSID(sid))
			throw CoreException(sid + " is not a valid server ID. A server ID must be 3 characters long, with the first character a digit and the next two characters a digit or letter.");
	}
	else
	{
		std::string name = server->getString("name");
		if (!name.empty() && name != ServerName)
			throw CoreException("You must restart to change the server name");

		std::string nsid = server->getString("id");
		if (!nsid.empty() && nsid != sid)
			throw CoreException("You must restart to change the server id");
	}
	SoftLimit = ConfValue("performance")->getUInt("softlimit", (SocketEngine::GetMaxFds() > 0 ? SocketEngine::GetMaxFds() : LONG_MAX), 10);
	CCOnConnect = ConfValue("performance")->getBool("clonesonconnect", true);
	MaxConn = ConfValue("performance")->getUInt("somaxconn", SOMAXCONN);
	TimeSkipWarn = ConfValue("performance")->getDuration("timeskipwarn", 2, 0, 30);
	XLineMessage = options->getString("xlinemessage", "You're banned!");
	ServerDesc = server->getString("description", "Configure Me");
	Network = server->getString("network", "Network");
	NetBufferSize = ConfValue("performance")->getInt("netbuffersize", 10240, 1024, 65534);
	CustomVersion = security->getString("customversion");
	HideBans = security->getBool("hidebans");
	HideServer = security->getString("hideserver");
	SyntaxHints = options->getBool("syntaxhints");
	FullHostInTopic = options->getBool("hostintopic");
	MaxTargets = security->getUInt("maxtargets", 20, 1, 31);
	DefaultModes = options->getString("defaultmodes", "not");
	PID = ConfValue("pid")->getString("file");
	c_ipv4_range = ConfValue("cidr")->getUInt("ipv4clone", 32, 1, 32);
	c_ipv6_range = ConfValue("cidr")->getUInt("ipv6clone", 128, 1, 128);
	Limits = ServerLimits(ConfValue("limits"));
	Paths = ServerPaths(ConfValue("path"));
	NoSnoticeStack = options->getBool("nosnoticestack", false);

	std::string defbind = options->getString("defaultbind");
	if (stdalgo::string::equalsci(defbind, "ipv4"))
	{
		WildcardIPv6 = false;
	}
	else if (stdalgo::string::equalsci(defbind, "ipv6"))
	{
		WildcardIPv6 = true;
	}
	else
	{
		WildcardIPv6 = true;
		int socktest = socket(AF_INET6, SOCK_STREAM, 0);
		if (socktest < 0)
			WildcardIPv6 = false;
		else
			SocketEngine::Close(socktest);
	}

	ServerInstance->XLines->ClearConfigLines();
	ReadXLine(this, "badip", "ipmask", ServerInstance->XLines->GetFactory("Z"));
	ReadXLine(this, "badnick", "nick", ServerInstance->XLines->GetFactory("Q"));
	ReadXLine(this, "badhost", "host", ServerInstance->XLines->GetFactory("K"));
	ReadXLine(this, "exception", "host", ServerInstance->XLines->GetFactory("E"));

	const std::string restrictbannedusers = options->getString("restrictbannedusers", "yes");
	if (stdalgo::string::equalsci(restrictbannedusers, "no"))
		RestrictBannedUsers = ServerConfig::BUT_NORMAL;
	else if (stdalgo::string::equalsci(restrictbannedusers, "silent"))
		RestrictBannedUsers = ServerConfig::BUT_RESTRICT_SILENT;
	else if (stdalgo::string::equalsci(restrictbannedusers, "yes"))
		RestrictBannedUsers =  ServerConfig::BUT_RESTRICT_NOTIFY;
	else
		throw CoreException(restrictbannedusers + " is an invalid <options:restrictbannedusers> value, at " + options->getTagLocation());
}
Example #5
0
void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current)
{
	typedef std::map<std::string, ConnectClass*> ClassMap;
	ClassMap oldBlocksByMask;
	if (current)
	{
		for(ClassVector::iterator i = current->Classes.begin(); i != current->Classes.end(); ++i)
		{
			ConnectClass* c = *i;
			if (c->name.compare(0, 8, "unnamed-", 8))
			{
				oldBlocksByMask["n" + c->name] = c;
			}
			else if (c->type == CC_ALLOW || c->type == CC_DENY)
			{
				std::string typeMask = (c->type == CC_ALLOW) ? "a" : "d";
				typeMask += c->host;
				oldBlocksByMask[typeMask] = c;
			}
		}
	}

	size_t blk_count = config_data.count("connect");
	if (blk_count == 0)
	{
		// No connect blocks found; make a trivial default block
		ConfigItems* items;
		ConfigTag* tag = ConfigTag::create("connect", "<auto>", 0, items);
		(*items)["allow"] = "*";
		config_data.insert(std::make_pair("connect", tag));
		blk_count = 1;
	}

	Classes.resize(blk_count);
	std::map<std::string, size_t> names;

	bool try_again = true;
	for(size_t tries = 0; try_again; tries++)
	{
		try_again = false;
		ConfigTagList tags = ConfTags("connect");
		size_t i = 0;
		for(ConfigIter it = tags.first; it != tags.second; ++it, ++i)
		{
			ConfigTag* tag = it->second;
			if (Classes[i])
				continue;

			ConnectClass* parent = NULL;
			std::string parentName = tag->getString("parent");
			if (!parentName.empty())
			{
				std::map<std::string, size_t>::const_iterator parentIter = names.find(parentName);
				if (parentIter == names.end())
				{
					try_again = true;
					// couldn't find parent this time. If it's the last time, we'll never find it.
					if (tries >= blk_count)
						throw CoreException("Could not find parent connect class \"" + parentName + "\" for connect block at " + tag->getTagLocation());
					continue;
				}
				parent = Classes[parentIter->second];
			}

			std::string name = tag->getString("name");
			std::string mask, typeMask;
			char type;

			if (tag->readString("allow", mask, false))
			{
				type = CC_ALLOW;
				typeMask = 'a' + mask;
			}
			else if (tag->readString("deny", mask, false))
			{
				type = CC_DENY;
				typeMask = 'd' + mask;
			}
			else if (!name.empty())
			{
				type = CC_NAMED;
				mask = name;
				typeMask = 'n' + mask;
			}
			else
			{
				throw CoreException("Connect class must have allow, deny, or name specified at " + tag->getTagLocation());
			}

			if (name.empty())
			{
				name = "unnamed-" + ConvToStr(i);
			}
			else
			{
				typeMask = 'n' + name;
			}

			if (names.find(name) != names.end())
				throw CoreException("Two connect classes with name \"" + name + "\" defined!");
			names[name] = i;

			ConnectClass* me = parent ?
				new ConnectClass(tag, type, mask, *parent) :
				new ConnectClass(tag, type, mask);

			me->name = name;

			me->registration_timeout = tag->getDuration("timeout", me->registration_timeout);
			me->pingtime = tag->getDuration("pingfreq", me->pingtime);
			std::string sendq;
			if (tag->readString("sendq", sendq))
			{
				// attempt to guess a good hard/soft sendq from a single value
				unsigned long value = strtoul(sendq.c_str(), NULL, 10);
				if (value > 16384)
					me->softsendqmax = value / 16;
				else
					me->softsendqmax = value;
				me->hardsendqmax = value * 8;
			}
			me->softsendqmax = tag->getUInt("softsendq", me->softsendqmax);
			me->hardsendqmax = tag->getUInt("hardsendq", me->hardsendqmax);
			me->recvqmax = tag->getUInt("recvq", me->recvqmax);
			me->penaltythreshold = tag->getUInt("threshold", me->penaltythreshold);
			me->commandrate = tag->getUInt("commandrate", me->commandrate);
			me->fakelag = tag->getBool("fakelag", me->fakelag);
			me->maxlocal = tag->getUInt("localmax", me->maxlocal);
			me->maxglobal = tag->getUInt("globalmax", me->maxglobal);
			me->maxchans = tag->getUInt("maxchans", me->maxchans);
			me->maxconnwarn = tag->getBool("maxconnwarn", me->maxconnwarn);
			me->limit = tag->getUInt("limit", me->limit);
			me->resolvehostnames = tag->getBool("resolvehostnames", me->resolvehostnames);

			std::string ports = tag->getString("port");
			if (!ports.empty())
			{
				irc::portparser portrange(ports, false);
				while (int port = portrange.GetToken())
					me->ports.insert(port);
			}

			ClassMap::iterator oldMask = oldBlocksByMask.find(typeMask);
			if (oldMask != oldBlocksByMask.end())
			{
				ConnectClass* old = oldMask->second;
				oldBlocksByMask.erase(oldMask);
				old->Update(me);
				delete me;
				me = old;
			}
			Classes[i] = me;
		}
	}
}
Example #6
0
	void ReadConfig(ConfigStatus& status) override
	{
		ConfigTag* tag = ServerInstance->Config->ConfValue("watch");
		cmd.maxwatch = tag->getUInt("maxwatch", 30, 1);
	}
Example #7
0
	void ReadConfig(ConfigStatus& status) override
	{
		ConfigTag* tag = ServerInstance->Config->ConfValue("monitor");
		cmd.maxmonitor = tag->getUInt("maxentries", 30, 1);
	}
Example #8
0
	void ReadConfig(ConfigStatus& status) override
	{
		ConfigTag* tag = ServerInstance->Config->ConfValue("remove");
		supportnokicks = tag->getBool("supportnokicks");
		cmd1.protectedrank = cmd2.protectedrank = tag->getUInt("protectedrank", 50000);
	}