-/* These tags can occur ONCE or not at all */
-static const InitialConfig Values[] = {
- {"performance", "softlimit", "0", new ValueContainerUInt (&ServerConfig::SoftLimit), DT_INTEGER, ValidateSoftLimit},
- {"performance", "somaxconn", SOMAXCONN_S, new ValueContainerInt (&ServerConfig::MaxConn), DT_INTEGER, ValidateMaxConn},
- {"options", "moronbanner", "You're banned!", new ValueContainerChar (&ServerConfig::MoronBanner), DT_CHARPTR, NULL},
- {"server", "name", "", new ValueContainerChar (&ServerConfig::ServerName), DT_HOSTNAME, ValidateServerName},
- {"server", "description", "Configure Me", new ValueContainerChar (&ServerConfig::ServerDesc), DT_CHARPTR, NULL},
- {"server", "network", "Network", new ValueContainerChar (&ServerConfig::Network), DT_NOSPACES, NULL},
- {"server", "id", "", new ValueContainerChar (&ServerConfig::sid), DT_CHARPTR, ValidateSID},
- {"admin", "name", "", new ValueContainerChar (&ServerConfig::AdminName), DT_CHARPTR, NULL},
- {"admin", "email", "Mis@configu.red", new ValueContainerChar (&ServerConfig::AdminEmail), DT_CHARPTR, NULL},
- {"admin", "nick", "Misconfigured", new ValueContainerChar (&ServerConfig::AdminNick), DT_CHARPTR, NULL},
- {"files", "motd", "", new ValueContainerChar (&ServerConfig::motd), DT_CHARPTR, ValidateMotd},
- {"files", "rules", "", new ValueContainerChar (&ServerConfig::rules), DT_CHARPTR, ValidateRules},
- {"power", "diepass", "", new ValueContainerChar (&ServerConfig::diepass), DT_CHARPTR, ValidateNotEmpty},
- {"power", "pause", "", new ValueContainerInt (&ServerConfig::DieDelay), DT_INTEGER, NULL},
- {"power", "hash", "", new ValueContainerChar (&ServerConfig::powerhash), DT_CHARPTR, NULL},
- {"power", "restartpass", "", new ValueContainerChar (&ServerConfig::restartpass), DT_CHARPTR, ValidateNotEmpty},
- {"options", "prefixquit", "", new ValueContainerChar (&ServerConfig::PrefixQuit), DT_CHARPTR, NULL},
- {"options", "suffixquit", "", new ValueContainerChar (&ServerConfig::SuffixQuit), DT_CHARPTR, NULL},
- {"options", "fixedquit", "", new ValueContainerChar (&ServerConfig::FixedQuit), DT_CHARPTR, NULL},
- {"options", "prefixpart", "", new ValueContainerChar (&ServerConfig::PrefixPart), DT_CHARPTR, NULL},
- {"options", "suffixpart", "", new ValueContainerChar (&ServerConfig::SuffixPart), DT_CHARPTR, NULL},
- {"options", "fixedpart", "", new ValueContainerChar (&ServerConfig::FixedPart), DT_CHARPTR, NULL},
- {"performance", "netbuffersize","10240", new ValueContainerInt (&ServerConfig::NetBufferSize), DT_INTEGER, ValidateNetBufferSize},
- {"performance", "maxwho", "128", new ValueContainerInt (&ServerConfig::MaxWhoResults), DT_INTEGER, ValidateMaxWho},
- {"options", "allowhalfop", "0", new ValueContainerBool (&ServerConfig::AllowHalfop), DT_BOOLEAN, ValidateHalfOp},
- {"dns", "server", "", new ValueContainerChar (&ServerConfig::DNSServer), DT_IPADDRESS,ValidateDnsServer},
- {"dns", "timeout", "5", new ValueContainerInt (&ServerConfig::dns_timeout), DT_INTEGER, NULL},
- {"options", "moduledir", MOD_PATH, new ValueContainerString (&ServerConfig::ModPath), DT_CHARPTR, NULL},
- {"disabled", "commands", "", new ValueContainerChar (&ServerConfig::DisabledCommands), DT_CHARPTR, NULL},
- {"disabled", "usermodes", "", NULL, DT_NOTHING, ValidateDisabledUModes},
- {"disabled", "chanmodes", "", NULL, DT_NOTHING, ValidateDisabledCModes},
- {"disabled", "fakenonexistant", "0", new ValueContainerBool (&ServerConfig::DisabledDontExist), DT_BOOLEAN, NULL},
-
- {"security", "runasuser", "", new ValueContainerChar(&ServerConfig::SetUser), DT_CHARPTR, NULL},
- {"security", "runasgroup", "", new ValueContainerChar(&ServerConfig::SetGroup), DT_CHARPTR, NULL},
- {"security", "userstats", "", new ValueContainerChar (&ServerConfig::UserStats), DT_CHARPTR, NULL},
- {"security", "customversion","", new ValueContainerChar (&ServerConfig::CustomVersion), DT_CHARPTR, NULL},
- {"security", "hidesplits", "0", new ValueContainerBool (&ServerConfig::HideSplits), DT_BOOLEAN, NULL},
- {"security", "hidebans", "0", new ValueContainerBool (&ServerConfig::HideBans), DT_BOOLEAN, NULL},
- {"security", "hidewhois", "", new ValueContainerChar (&ServerConfig::HideWhoisServer), DT_NOSPACES, NULL},
- {"security", "hidekills", "", new ValueContainerChar (&ServerConfig::HideKillsServer), DT_NOSPACES, NULL},
- {"security", "operspywhois", "0", new ValueContainerBool (&ServerConfig::OperSpyWhois), DT_BOOLEAN, NULL},
- {"security", "restrictbannedusers", "1", new ValueContainerBool (&ServerConfig::RestrictBannedUsers), DT_BOOLEAN, NULL},
- {"security", "genericoper", "0", new ValueContainerBool (&ServerConfig::GenericOper), DT_BOOLEAN, NULL},
- {"performance", "nouserdns", "0", new ValueContainerBool (&ServerConfig::NoUserDns), DT_BOOLEAN, NULL},
- {"options", "syntaxhints", "0", new ValueContainerBool (&ServerConfig::SyntaxHints), DT_BOOLEAN, NULL},
- {"options", "cyclehosts", "0", new ValueContainerBool (&ServerConfig::CycleHosts), DT_BOOLEAN, NULL},
- {"options", "ircumsgprefix","0", new ValueContainerBool (&ServerConfig::UndernetMsgPrefix), DT_BOOLEAN, NULL},
- {"security", "announceinvites", "1", NULL, DT_NOTHING, ValidateInvite},
- {"options", "hostintopic", "1", new ValueContainerBool (&ServerConfig::FullHostInTopic), DT_BOOLEAN, NULL},
- {"security", "hidemodes", "", NULL, DT_NOTHING, ValidateModeLists},
- {"options", "exemptchanops","", NULL, DT_NOTHING, ValidateExemptChanOps},
- {"security", "maxtargets", "20", new ValueContainerUInt (&ServerConfig::MaxTargets), DT_INTEGER, ValidateMaxTargets},
- {"options", "defaultmodes", "nt", new ValueContainerChar (&ServerConfig::DefaultModes), DT_CHARPTR, NULL},
- {"pid", "file", "", new ValueContainerString (&ServerConfig::PID), DT_CHARPTR, NULL},
- {"whowas", "groupsize", "10", new ValueContainerInt (&ServerConfig::WhoWasGroupSize), DT_INTEGER, NULL},
- {"whowas", "maxgroups", "10240", new ValueContainerInt (&ServerConfig::WhoWasMaxGroups), DT_INTEGER, NULL},
- {"whowas", "maxkeep", "3600", NULL, DT_NOTHING, ValidateWhoWas},
- {"die", "value", "", new ValueContainerChar (&ServerConfig::DieValue), DT_CHARPTR, NULL},
- {"channels", "users", "20", new ValueContainerUInt (&ServerConfig::MaxChans), DT_INTEGER, NULL},
- {"channels", "opers", "60", new ValueContainerUInt (&ServerConfig::OperMaxChans), DT_INTEGER, NULL},
- {"cidr", "ipv4clone", "32", new ValueContainerInt (&ServerConfig::c_ipv4_range), DT_INTEGER, NULL},
- {"cidr", "ipv6clone", "128", new ValueContainerInt (&ServerConfig::c_ipv6_range), DT_INTEGER, NULL},
- {"limits", "maxnick", "32", new ValueContainerLimit (&ServerLimits::NickMax), DT_LIMIT, NULL},
- {"limits", "maxchan", "64", new ValueContainerLimit (&ServerLimits::ChanMax), DT_LIMIT, NULL},
- {"limits", "maxmodes", "20", new ValueContainerLimit (&ServerLimits::MaxModes), DT_LIMIT, NULL},
- {"limits", "maxident", "11", new ValueContainerLimit (&ServerLimits::IdentMax), DT_LIMIT, NULL},
- {"limits", "maxquit", "255", new ValueContainerLimit (&ServerLimits::MaxQuit), DT_LIMIT, NULL},
- {"limits", "maxtopic", "307", new ValueContainerLimit (&ServerLimits::MaxTopic), DT_LIMIT, NULL},
- {"limits", "maxkick", "255", new ValueContainerLimit (&ServerLimits::MaxKick), DT_LIMIT, NULL},
- {"limits", "maxgecos", "128", new ValueContainerLimit (&ServerLimits::MaxGecos), DT_LIMIT, NULL},
- {"limits", "maxaway", "200", new ValueContainerLimit (&ServerLimits::MaxAway), DT_LIMIT, NULL},
- {"options", "invitebypassmodes", "1", new ValueContainerBool (&ServerConfig::InvBypassModes), DT_BOOLEAN, NULL},
-};
-
-/* These tags can occur multiple times, and therefore they have special code to read them
- * which is different to the code for reading the singular tags listed above.
- */
-MultiConfig MultiValues[] = {
-
- {"connect",
- {"allow", "deny", "password", "timeout", "pingfreq",
- "sendq", "recvq", "localmax", "globalmax", "port",
- "name", "parent", "maxchans", "limit", "hash",
- NULL},
- {"", "", "", "", "120",
- "", "", "3", "3", "0",
- "", "", "0", "0", "",
- NULL},
- {DT_IPADDRESS|DT_ALLOW_WILD, DT_IPADDRESS|DT_ALLOW_WILD, DT_CHARPTR, DT_INTEGER, DT_INTEGER,
- DT_INTEGER, DT_INTEGER, DT_INTEGER, DT_INTEGER, DT_INTEGER,
- DT_NOSPACES, DT_NOSPACES, DT_INTEGER, DT_INTEGER, DT_CHARPTR},
- NULL,},
-
- {"uline",
- {"server", "silent", NULL},
- {"", "0", NULL},
- {DT_HOSTNAME, DT_BOOLEAN},
- DoULine},
-
- {"banlist",
- {"chan", "limit", NULL},
- {"", "", NULL},
- {DT_CHARPTR, DT_INTEGER},
- DoMaxBans},
-
- {"module",
- {"name", NULL},
- {"", NULL},
- {DT_CHARPTR},
- NULL},
-
- {"badip",
- {"reason", "ipmask", NULL},
- {"No reason", "", NULL},
- {DT_CHARPTR, DT_IPADDRESS|DT_ALLOW_WILD},
- DoZLine},
-
- {"badnick",
- {"reason", "nick", NULL},
- {"No reason", "", NULL},
- {DT_CHARPTR, DT_CHARPTR},
- DoQLine},
-
- {"badhost",
- {"reason", "host", NULL},
- {"No reason", "", NULL},
- {DT_CHARPTR, DT_CHARPTR},
- DoKLine},
-
- {"exception",
- {"reason", "host", NULL},
- {"No reason", "", NULL},
- {DT_CHARPTR, DT_CHARPTR},
- DoELine},
-
- {"type",
- {"name", "classes", NULL},
- {"", "", NULL},
- {DT_NOSPACES, DT_CHARPTR},
- DoType},
-
- {"class",
- {"name", "commands", "usermodes", "chanmodes", "privs", NULL},
- {"", "", "", "", "", NULL},
- {DT_NOSPACES, DT_CHARPTR, DT_CHARPTR, DT_CHARPTR, DT_CHARPTR},
- DoClass},
-};
-
-/* These tags MUST occur and must ONLY occur once in the config file */
-static const char* Once[] = { "server", "admin", "files", "power", "options" };
-
-// WARNING: it is not safe to use most of the codebase in this function, as it
-// will run in the config reader thread
-void ServerConfig::Read()
-{
- /* Load and parse the config file, if there are any errors then explode */
-
- if (!this->DoInclude(ServerInstance->ConfigFileName))
- {
- valid = false;
- return;
- }
-}
-
-void ServerConfig::Apply(ServerConfig* old, const std::string &useruid)
-{
- valid = true;
- /* std::ostringstream::clear() does not clear the string itself, only the error flags. */
- errstr.clear();
- errstr.str().clear();
- include_stack.clear();
-
- /* The stuff in here may throw CoreException, be sure we're in a position to catch it. */
- try
- {
- /* Check we dont have more than one of singular tags, or any of them missing
- */
- for (int Index = 0; Index * sizeof(*Once) < sizeof(Once); Index++)
- CheckOnce(Once[Index]);
-
- for (int Index = 0; Index * sizeof(Deprecated) < sizeof(ChangedConfig); Index++)
- {
- char item[MAXBUF];
- *item = 0;
- if (ConfValue(ChangedConfig[Index].tag, ChangedConfig[Index].value, "", 0, item, MAXBUF, true) || *item)
- throw CoreException(std::string("Your configuration contains a deprecated value: <") + ChangedConfig[Index].tag + ":" + ChangedConfig[Index].value + "> - " + ChangedConfig[Index].reason);
- }
-
- /* Read the values of all the tags which occur once or not at all, and call their callbacks.
- */
- for (int Index = 0; Index * sizeof(*Values) < sizeof(Values); ++Index)
- {
- char item[MAXBUF];
- int dt = Values[Index].datatype;
- bool allow_newlines = ((dt & DT_ALLOW_NEWLINE) > 0);
- bool allow_wild = ((dt & DT_ALLOW_WILD) > 0);
- dt &= ~DT_ALLOW_NEWLINE;
- dt &= ~DT_ALLOW_WILD;
-
- ConfValue(Values[Index].tag, Values[Index].value, Values[Index].default_value, 0, item, MAXBUF, allow_newlines);
- ValueItem vi(item);
-
- if (Values[Index].validation_function && !Values[Index].validation_function(this, Values[Index].tag, Values[Index].value, vi))
- throw CoreException("One or more values in your configuration file failed to validate. Please see your ircd.log for more information.");
-
- switch (dt)
- {
- case DT_NOSPACES:
- {
- ValueContainerChar* vcc = (ValueContainerChar*)Values[Index].val;
- ValidateNoSpaces(vi.GetString(), Values[Index].tag, Values[Index].value);
- vcc->Set(this, vi);
- }
- break;
- case DT_HOSTNAME:
- {
- ValueContainerChar* vcc = (ValueContainerChar*)Values[Index].val;
- ValidateHostname(vi.GetString(), Values[Index].tag, Values[Index].value);
- vcc->Set(this, vi);
- }
- break;
- case DT_IPADDRESS:
- {
- ValueContainerChar* vcc = (ValueContainerChar*)Values[Index].val;
- ValidateIP(vi.GetString(), Values[Index].tag, Values[Index].value, allow_wild);
- vcc->Set(this, vi);
- }
- break;
- case DT_CHANNEL:
- {
- ValueContainerChar* vcc = (ValueContainerChar*)Values[Index].val;
- if (*(vi.GetString()) && !ServerInstance->IsChannel(vi.GetString(), MAXBUF))
- {
- throw CoreException("The value of <"+std::string(Values[Index].tag)+":"+Values[Index].value+"> is not a valid channel name");
- }
- vcc->Set(this, vi);
- }
- break;
- case DT_CHARPTR:
- {
- ValueContainerChar* vcc = dynamic_cast<ValueContainerChar*>(Values[Index].val);
- if (vcc)
- vcc->Set(this, vi);
- ValueContainerString* vcs = dynamic_cast<ValueContainerString*>(Values[Index].val);
- if (vcs)
- vcs->Set(this, vi.GetValue());
- }
- break;
- case DT_INTEGER:
- {
- int val = vi.GetInteger();
- ValueContainerInt* vci = (ValueContainerInt*)Values[Index].val;
- vci->Set(this, val);
- }
- break;
- case DT_LIMIT:
- {
- int val = vi.GetInteger();
- ValueContainerLimit* vci = (ValueContainerLimit*)Values[Index].val;
- vci->Set(this, val);
- }
- break;
- case DT_BOOLEAN:
- {
- bool val = vi.GetBool();
- ValueContainerBool* vcb = (ValueContainerBool*)Values[Index].val;
- vcb->Set(this, val);
- }
- break;
- }
- /* We're done with this now */
- delete Values[Index].val;
- }
-
- /* Read the multiple-tag items (class tags, connect tags, etc)
- * and call the callbacks associated with them. We have three
- * callbacks for these, a 'start', 'item' and 'end' callback.
- */
- for (int Index = 0; Index * sizeof(MultiConfig) < sizeof(MultiValues); ++Index)
- {
- int number_of_tags = ConfValueEnum(MultiValues[Index].tag);
-
- for (int tagnum = 0; tagnum < number_of_tags; ++tagnum)
- {
- ValueList vl;
- for (int valuenum = 0; (MultiValues[Index].items[valuenum]) && (valuenum < MAX_VALUES_PER_TAG); ++valuenum)
- {
- int dt = MultiValues[Index].datatype[valuenum];
- bool allow_newlines = ((dt & DT_ALLOW_NEWLINE) > 0);
- bool allow_wild = ((dt & DT_ALLOW_WILD) > 0);
- dt &= ~DT_ALLOW_NEWLINE;
- dt &= ~DT_ALLOW_WILD;
-
- switch (dt)
- {
- case DT_NOSPACES:
- {
- char item[MAXBUF];
- if (ConfValue(MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, MAXBUF, allow_newlines))
- vl.push_back(ValueItem(item));
- else
- vl.push_back(ValueItem(""));
- ValidateNoSpaces(vl[vl.size()-1].GetString(), MultiValues[Index].tag, MultiValues[Index].items[valuenum]);
- }
- break;
- case DT_HOSTNAME:
- {
- char item[MAXBUF];
- if (ConfValue(MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, MAXBUF, allow_newlines))
- vl.push_back(ValueItem(item));
- else
- vl.push_back(ValueItem(""));
- ValidateHostname(vl[vl.size()-1].GetString(), MultiValues[Index].tag, MultiValues[Index].items[valuenum]);
- }
- break;
- case DT_IPADDRESS:
- {
- char item[MAXBUF];
- if (ConfValue(MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, MAXBUF, allow_newlines))
- vl.push_back(ValueItem(item));
- else
- vl.push_back(ValueItem(""));
- ValidateIP(vl[vl.size()-1].GetString(), MultiValues[Index].tag, MultiValues[Index].items[valuenum], allow_wild);
- }
- break;
- case DT_CHANNEL:
- {
- char item[MAXBUF];
- if (ConfValue(MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, MAXBUF, allow_newlines))
- vl.push_back(ValueItem(item));
- else
- vl.push_back(ValueItem(""));
- if (!ServerInstance->IsChannel(vl[vl.size()-1].GetString(), MAXBUF))
- throw CoreException("The value of <"+std::string(MultiValues[Index].tag)+":"+MultiValues[Index].items[valuenum]+"> number "+ConvToStr(tagnum + 1)+" is not a valid channel name");
- }
- break;
- case DT_CHARPTR:
- {
- char item[MAXBUF];
- if (ConfValue(MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, MAXBUF, allow_newlines))
- vl.push_back(ValueItem(item));
- else
- vl.push_back(ValueItem(""));
- }
- break;
- case DT_INTEGER:
- {
- int item = 0;
- if (ConfValueInteger(MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item))
- vl.push_back(ValueItem(item));
- else
- vl.push_back(ValueItem(0));
- }
- break;
- case DT_BOOLEAN:
- {
- bool item = ConfValueBool(MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum);
- vl.push_back(ValueItem(item));
- }
- break;
- }
- }
- if (MultiValues[Index].validation_function)
- MultiValues[Index].validation_function(this, MultiValues[Index].tag, MultiValues[Index].items, vl, MultiValues[Index].datatype);
- }
- }
-
- /* Finalise the limits, increment them all by one so that we can just put assign(str, 0, val)
- * rather than assign(str, 0, val + 1)
- */
- Limits.Finalise();
-
- // Handle special items
- CrossCheckOperClassType();
- CrossCheckConnectBlocks(old);
- }
- catch (CoreException &ce)
- {
- errstr << ce.GetReason();
- valid = false;
- }
-
- // write once here, to try it out and make sure its ok
- ServerInstance->WritePID(this->PID);
-
- FailedPortList pl;
- ServerInstance->BindPorts(pl);
-
- /*
- * These values can only be set on boot. Keep their old values. Do it before we send messages so we actually have a servername.
- */
- if (old)
- {
- memcpy(this->ServerName, old->ServerName, sizeof(this->ServerName));
- memcpy(this->sid, old->sid, sizeof(this->sid));
- }
-
- if (pl.size())
- {
- errstr << "Not all your client ports could be bound.\nThe following port(s) failed to bind:\n";
-
- int j = 1;
- for (FailedPortList::iterator i = pl.begin(); i != pl.end(); i++, j++)
- {
- char buf[MAXBUF];
- snprintf(buf, MAXBUF, "%d. Address: %s Reason: %s\n", j, i->first.empty() ? "<all>" : i->first.c_str(), i->second.c_str());
- errstr << buf;
- }
- }
-
- User* user = useruid.empty() ? NULL : ServerInstance->FindNick(useruid);
-
- valid = errstr.str().empty();
- if (!valid)
- ServerInstance->Logs->Log("CONFIG",DEFAULT, "There were errors in your configuration file:");
-
- while (errstr.good())
- {
- std::string line;
- getline(errstr, line, '\n');
- if (!line.empty())
- {
- if (user)
- user->WriteServ("NOTICE %s :*** %s", user->nick.c_str(), line.c_str());
- else
- ServerInstance->SNO->WriteGlobalSno('a', line);
- }
-
- if (!old)
- {
- // Starting up, so print it out so it's seen. XXX this is a bit of a hack.
- printf("%s\n", line.c_str());
- }
- }
-
- errstr.clear();
- errstr.str(std::string());
-
- /* No old configuration -> initial boot, nothing more to do here */
- if (!old)
- {
- if (!valid)
- {
- ServerInstance->Exit(EXIT_STATUS_CONFIG);
- }
-
- return;
- }
-
- // If there were errors processing configuration, don't touch modules.
- if (!valid)
- return;
-
- ApplyModules(user);
- for (std::vector<ConnectClass*>::iterator i = removed_classes.begin(); i != removed_classes.end(); i++)
- {
- ConnectClass* c = *i;
- if (0 == --c->RefCount)
- delete c;
- }
-}
-
-void ServerConfig::ApplyModules(User* user)
-{
- const std::vector<std::string> v = ServerInstance->Modules->GetAllModuleNames(0);
- std::vector<std::string> added_modules;
- std::set<std::string> removed_modules(v.begin(), v.end());
-
- int new_module_count = ConfValueEnum("module");
- for(int i=0; i < new_module_count; i++)
- {
- std::string name;
- if (ConfValue("module", "name", i, name, false))
- {
- // if this module is already loaded, the erase will succeed, so we need do nothing
- // otherwise, we need to add the module (which will be done later)
- if (removed_modules.erase(name) == 0)
- added_modules.push_back(name);
- }
- }
-
- for (std::set<std::string>::iterator removing = removed_modules.begin(); removing != removed_modules.end(); removing++)
- {
- if (ServerInstance->Modules->Unload(removing->c_str()))
- {
- ServerInstance->SNO->WriteToSnoMask('a', "*** REHASH UNLOADED MODULE: %s",removing->c_str());
-
- if (user)
- user->WriteNumeric(RPL_UNLOADEDMODULE, "%s %s :Module %s successfully unloaded.",user->nick.c_str(), removing->c_str(), removing->c_str());
- else
- ServerInstance->SNO->WriteToSnoMask('a', "Module %s successfully unloaded.", removing->c_str());
- }
- else
- {
- if (user)
- user->WriteNumeric(ERR_CANTUNLOADMODULE, "%s %s :Failed to unload module %s: %s",user->nick.c_str(), removing->c_str(), removing->c_str(), ServerInstance->Modules->LastError().c_str());
- else
- ServerInstance->SNO->WriteToSnoMask('a', "Failed to unload module %s: %s", removing->c_str(), ServerInstance->Modules->LastError().c_str());
- }
- }
-
- for (std::vector<std::string>::iterator adding = added_modules.begin(); adding != added_modules.end(); adding++)
- {
- if (ServerInstance->Modules->Load(adding->c_str()))
- {
- ServerInstance->SNO->WriteToSnoMask('a', "*** REHASH LOADED MODULE: %s",adding->c_str());
- if (user)
- user->WriteNumeric(RPL_LOADEDMODULE, "%s %s :Module %s successfully loaded.",user->nick.c_str(), adding->c_str(), adding->c_str());
- else
- ServerInstance->SNO->WriteToSnoMask('a', "Module %s successfully loaded.", adding->c_str());
- }
- else
- {
- if (user)
- user->WriteNumeric(ERR_CANTLOADMODULE, "%s %s :Failed to load module %s: %s",user->nick.c_str(), adding->c_str(), adding->c_str(), ServerInstance->Modules->LastError().c_str());
- else
- ServerInstance->SNO->WriteToSnoMask('a', "Failed to load module %s: %s", adding->c_str(), ServerInstance->Modules->LastError().c_str());
- }
- }
-
- if (user)
- user->WriteServ("NOTICE %s :*** Successfully rehashed server.", user->nick.c_str());
- else
- ServerInstance->SNO->WriteToSnoMask('a', "*** Successfully rehashed server.");
-}
-
-bool ServerConfig::LoadConf(FILE* &conf, const char* filename)
-{
- std::string line;
- char ch;
- long linenumber = 1;
- long last_successful_parse = 1;
- bool in_tag;
- bool in_quote;
- bool in_comment;
- int character_count = 0;
-
- in_tag = false;
- in_quote = false;
- in_comment = false;
-
- ServerInstance->Logs->Log("CONFIG", DEBUG, "Reading %s", filename);
-
- /* Check if the file open failed first */
- if (!conf)
+void ServerConfig::Fill()
+{
+ ReqRead(this, "server", "name", ServerName);
+ ReqRead(this, "power", "diepass", diepass);
+ ReqRead(this, "power", "restartpass", restartpass);
+
+ ConfigTag* options = ConfValue("options");
+ ConfigTag* security = ConfValue("security");
+ powerhash = ConfValue("power")->getString("hash");
+ DieDelay = ConfValue("power")->getInt("pause");
+ PrefixQuit = options->getString("prefixquit");
+ SuffixQuit = options->getString("suffixquit");
+ FixedQuit = options->getString("fixedquit");
+ PrefixPart = options->getString("prefixpart");
+ SuffixPart = options->getString("suffixpart");
+ FixedPart = options->getString("fixedpart");
+ SoftLimit = ConfValue("performance")->getInt("softlimit", ServerInstance->SE->GetMaxFds());
+ MaxConn = ConfValue("performance")->getInt("somaxconn", SOMAXCONN);
+ MoronBanner = options->getString("moronbanner", "You're banned!");
+ ServerDesc = ConfValue("server")->getString("description", "Configure Me");
+ Network = ConfValue("server")->getString("network", "Network");
+ sid = ConfValue("server")->getString("id", "");
+ AdminName = ConfValue("admin")->getString("name", "");
+ AdminEmail = ConfValue("admin")->getString("email", "null@example.com");
+ AdminNick = ConfValue("admin")->getString("nick", "admin");
+ ModPath = ConfValue("path")->getString("moduledir", MOD_PATH);
+ NetBufferSize = ConfValue("performance")->getInt("netbuffersize", 10240);
+ MaxWhoResults = ConfValue("performance")->getInt("maxwho", 1024);
+ dns_timeout = ConfValue("dns")->getInt("timeout", 5);
+ DisabledCommands = ConfValue("disabled")->getString("commands", "");
+ DisabledDontExist = ConfValue("disabled")->getBool("fakenonexistant");
+ UserStats = security->getString("userstats");
+ CustomVersion = security->getString("customversion");
+ HideSplits = security->getBool("hidesplits");
+ HideBans = security->getBool("hidebans");
+ HideWhoisServer = security->getString("hidewhois");
+ HideKillsServer = security->getString("hidekills");
+ OperSpyWhois = security->getBool("operspywhois");
+ RestrictBannedUsers = security->getBool("restrictbannedusers", true);
+ GenericOper = security->getBool("genericoper");
+ NoUserDns = ConfValue("performance")->getBool("nouserdns");
+ SyntaxHints = options->getBool("syntaxhints");
+ CycleHosts = options->getBool("cyclehosts");
+ UndernetMsgPrefix = options->getBool("ircumsgprefix");
+ FullHostInTopic = options->getBool("hostintopic");
+ MaxTargets = security->getInt("maxtargets", 20);
+ DefaultModes = options->getString("defaultmodes", "nt");
+ PID = ConfValue("pid")->getString("file");
+ WhoWasGroupSize = ConfValue("whowas")->getInt("groupsize");
+ WhoWasMaxGroups = ConfValue("whowas")->getInt("maxgroups");
+ WhoWasMaxKeep = ServerInstance->Duration(ConfValue("whowas")->getString("maxkeep"));
+ DieValue = ConfValue("die")->getString("value");
+ MaxChans = ConfValue("channels")->getInt("users");
+ OperMaxChans = ConfValue("channels")->getInt("opers");
+ c_ipv4_range = ConfValue("cidr")->getInt("ipv4clone");
+ c_ipv6_range = ConfValue("cidr")->getInt("ipv6clone");
+ Limits.NickMax = ConfValue("limits")->getInt("maxnick", 32);
+ Limits.ChanMax = ConfValue("limits")->getInt("maxchan", 64);
+ Limits.MaxModes = ConfValue("limits")->getInt("maxmodes", 20);
+ Limits.IdentMax = ConfValue("limits")->getInt("maxident", 11);
+ Limits.MaxQuit = ConfValue("limits")->getInt("maxquit", 255);
+ Limits.MaxTopic = ConfValue("limits")->getInt("maxtopic", 307);
+ Limits.MaxKick = ConfValue("limits")->getInt("maxkick", 255);
+ Limits.MaxGecos = ConfValue("limits")->getInt("maxgecos", 128);
+ Limits.MaxAway = ConfValue("limits")->getInt("maxaway", 200);
+ InvBypassModes = options->getBool("invitebypassmodes", true);
+
+ range(SoftLimit, 10, ServerInstance->SE->GetMaxFds(), ServerInstance->SE->GetMaxFds(), "<performance:softlimit>");
+ range(MaxConn, 0, SOMAXCONN, SOMAXCONN, "<performance:somaxconn>");
+ range(MaxTargets, 1, 31, 20, "<security:maxtargets>");
+ range(NetBufferSize, 1024, 65534, 10240, "<performance:netbuffersize>");
+ range(MaxWhoResults, 1, 65535, 1024, "<performace:maxwho>");
+ range(WhoWasGroupSize, 0, 10000, 10, "<whowas:groupsize>");
+ range(WhoWasMaxGroups, 0, 1000000, 10240, "<whowas:maxgroups>");
+ range(WhoWasMaxKeep, 3600, INT_MAX, 3600, "<whowas:maxkeep>");
+
+ ValidIP(DNSServer, "<dns:server>");
+ ValidHost(ServerName, "<server:name>");
+ if (!sid.empty() && !ServerInstance->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.");
+
+ ConfigTagList tags = ConfTags("uline");
+ for(ConfigIter i = tags.first; i != tags.second; ++i)