2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2007-2009 Robin Burchell <robin+git@viroteck.net>
6 * Copyright (C) 2006-2009 Dennis Friis <peavey@inspircd.org>
7 * Copyright (C) 2006-2008 Craig Edwards <craigedwards@brainbox.cc>
8 * Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
9 * Copyright (C) 2006 Oliver Lupton <oliverlupton@gmail.com>
11 * This file is part of InspIRCd. InspIRCd is free software: you can
12 * redistribute it and/or modify it under the terms of the GNU General Public
13 * License as published by the Free Software Foundation, version 2.
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #include "exitcodes.h"
29 #include "configparser.h"
32 ServerConfig::ServerConfig()
34 RawLog = HideBans = HideSplits = UndernetMsgPrefix = false;
35 WildcardIPv6 = InvBypassModes = true;
38 NetBufferSize = 10240;
39 SoftLimit = ServerInstance->SE->GetMaxFds();
47 static void ValidHost(const std::string& p, const std::string& msg)
50 if (p.empty() || p[0] == '.')
51 throw CoreException("The value of "+msg+" is not a valid hostname");
52 for (unsigned int i=0;i < p.length();i++)
57 throw CoreException("The value of "+msg+" is not a valid hostname");
64 throw CoreException("The value of "+msg+" is not a valid hostname");
67 bool ServerConfig::ApplyDisabledCommands(const std::string& data)
69 std::stringstream dcmds(data);
72 /* Enable everything first */
73 for (Commandtable::iterator x = ServerInstance->Parser->cmdlist.begin(); x != ServerInstance->Parser->cmdlist.end(); x++)
74 x->second->Disable(false);
76 /* Now disable all the ones which the user wants disabled */
77 while (dcmds >> thiscmd)
79 Commandtable::iterator cm = ServerInstance->Parser->cmdlist.find(thiscmd);
80 if (cm != ServerInstance->Parser->cmdlist.end())
82 cm->second->Disable(true);
88 static void ReadXLine(ServerConfig* conf, const std::string& tag, const std::string& key, XLineFactory* make)
90 ConfigTagList tags = conf->ConfTags(tag);
91 for(ConfigIter i = tags.first; i != tags.second; ++i)
93 ConfigTag* ctag = i->second;
95 if (!ctag->readString(key, mask))
96 throw CoreException("<"+tag+":"+key+"> missing at " + ctag->getTagLocation());
97 std::string reason = ctag->getString("reason", "<Config>");
98 XLine* xl = make->Generate(ServerInstance->Time(), 0, "<Config>", reason, mask);
99 if (!ServerInstance->XLines->AddLine(xl, NULL))
104 typedef std::map<std::string, ConfigTag*> LocalIndex;
105 void ServerConfig::CrossCheckOperClassType()
107 LocalIndex operclass;
108 ConfigTagList tags = ConfTags("class");
109 for(ConfigIter i = tags.first; i != tags.second; ++i)
111 ConfigTag* tag = i->second;
112 std::string name = tag->getString("name");
114 throw CoreException("<class:name> missing from tag at " + tag->getTagLocation());
115 if (operclass.find(name) != operclass.end())
116 throw CoreException("Duplicate class block with name " + name + " at " + tag->getTagLocation());
117 operclass[name] = tag;
119 tags = ConfTags("type");
120 for(ConfigIter i = tags.first; i != tags.second; ++i)
122 ConfigTag* tag = i->second;
123 std::string name = tag->getString("name");
125 throw CoreException("<type:name> is missing from tag at " + tag->getTagLocation());
126 if (oper_blocks.find(" " + name) != oper_blocks.end())
127 throw CoreException("Duplicate type block with name " + name + " at " + tag->getTagLocation());
129 OperInfo* ifo = new OperInfo;
130 oper_blocks[" " + name] = ifo;
132 ifo->type_block = tag;
134 std::string classname;
135 irc::spacesepstream str(tag->getString("classes"));
136 while (str.GetToken(classname))
138 LocalIndex::iterator cls = operclass.find(classname);
139 if (cls == operclass.end())
140 throw CoreException("Oper type " + name + " has missing class " + classname);
141 ifo->class_blocks.push_back(cls->second);
145 tags = ConfTags("oper");
146 for(ConfigIter i = tags.first; i != tags.second; ++i)
148 ConfigTag* tag = i->second;
150 std::string name = tag->getString("name");
152 throw CoreException("<oper:name> missing from tag at " + tag->getTagLocation());
154 std::string type = tag->getString("type");
155 OperIndex::iterator tblk = oper_blocks.find(" " + type);
156 if (tblk == oper_blocks.end())
157 throw CoreException("Oper block " + name + " has missing type " + type);
158 if (oper_blocks.find(name) != oper_blocks.end())
159 throw CoreException("Duplicate oper block with name " + name + " at " + tag->getTagLocation());
161 OperInfo* ifo = new OperInfo;
163 ifo->oper_block = tag;
164 ifo->type_block = tblk->second->type_block;
165 ifo->class_blocks.assign(tblk->second->class_blocks.begin(), tblk->second->class_blocks.end());
166 oper_blocks[name] = ifo;
170 void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current)
172 typedef std::map<std::string, ConnectClass*> ClassMap;
173 ClassMap oldBlocksByMask;
176 for(ClassVector::iterator i = current->Classes.begin(); i != current->Classes.end(); ++i)
178 ConnectClass* c = *i;
179 if (c->name.substr(0, 8) != "unnamed-")
181 oldBlocksByMask["n" + c->name] = c;
183 else if (c->type == CC_ALLOW || c->type == CC_DENY)
185 std::string typeMask = (c->type == CC_ALLOW) ? "a" : "d";
187 oldBlocksByMask[typeMask] = c;
192 int blk_count = config_data.count("connect");
195 // No connect blocks found; make a trivial default block
196 std::vector<KeyVal>* items;
197 ConfigTag* tag = ConfigTag::create("connect", "<auto>", 0, items);
198 items->push_back(std::make_pair("allow", "*"));
199 config_data.insert(std::make_pair("connect", tag));
203 Classes.resize(blk_count);
204 std::map<std::string, int> names;
206 bool try_again = true;
207 for(int tries=0; try_again; tries++)
210 ConfigTagList tags = ConfTags("connect");
212 for(ConfigIter it = tags.first; it != tags.second; ++it, ++i)
214 ConfigTag* tag = it->second;
218 ConnectClass* parent = NULL;
219 std::string parentName = tag->getString("parent");
220 if (!parentName.empty())
222 std::map<std::string,int>::iterator parentIter = names.find(parentName);
223 if (parentIter == names.end())
226 // couldn't find parent this time. If it's the last time, we'll never find it.
227 if (tries >= blk_count)
228 throw CoreException("Could not find parent connect class \"" + parentName + "\" for connect block at " + tag->getTagLocation());
231 parent = Classes[parentIter->second];
234 std::string name = tag->getString("name");
235 std::string mask, typeMask;
238 if (tag->readString("allow", mask, false))
241 typeMask = 'a' + mask;
243 else if (tag->readString("deny", mask, false))
246 typeMask = 'd' + mask;
248 else if (!name.empty())
252 typeMask = 'n' + mask;
256 throw CoreException("Connect class must have allow, deny, or name specified at " + tag->getTagLocation());
261 name = "unnamed-" + ConvToStr(i);
265 typeMask = 'n' + name;
268 if (names.find(name) != names.end())
269 throw CoreException("Two connect classes with name \"" + name + "\" defined!");
272 ConnectClass* me = parent ?
273 new ConnectClass(tag, type, mask, *parent) :
274 new ConnectClass(tag, type, mask);
278 me->registration_timeout = tag->getInt("timeout", me->registration_timeout);
279 me->pingtime = tag->getInt("pingfreq", me->pingtime);
281 if (tag->readString("sendq", sendq))
283 // attempt to guess a good hard/soft sendq from a single value
284 long value = atol(sendq.c_str());
286 me->softsendqmax = value / 16;
288 me->softsendqmax = value;
289 me->hardsendqmax = value * 8;
291 me->softsendqmax = tag->getInt("softsendq", me->softsendqmax);
292 me->hardsendqmax = tag->getInt("hardsendq", me->hardsendqmax);
293 me->recvqmax = tag->getInt("recvq", me->recvqmax);
294 me->penaltythreshold = tag->getInt("threshold", me->penaltythreshold);
295 me->commandrate = tag->getInt("commandrate", me->commandrate);
296 me->fakelag = tag->getBool("fakelag", me->fakelag);
297 me->maxlocal = tag->getInt("localmax", me->maxlocal);
298 me->maxglobal = tag->getInt("globalmax", me->maxglobal);
299 me->maxchans = tag->getInt("maxchans", me->maxchans);
300 me->maxconnwarn = tag->getBool("maxconnwarn", me->maxconnwarn);
301 me->limit = tag->getInt("limit", me->limit);
302 me->resolvehostnames = tag->getBool("resolvehostnames", me->resolvehostnames);
304 ClassMap::iterator oldMask = oldBlocksByMask.find(typeMask);
305 if (oldMask != oldBlocksByMask.end())
307 ConnectClass* old = oldMask->second;
308 oldBlocksByMask.erase(oldMask);
318 /** Represents a deprecated configuration tag.
320 struct DeprecatedConfig
325 /** Attribute key. */
328 /** Attribute value. */
331 /** Reason for deprecation. */
335 static const DeprecatedConfig ChangedConfig[] = {
336 { "bind", "transport", "", "has been moved to <bind:ssl> as of 2.0" },
337 { "die", "value", "", "you need to reread your config" },
338 { "link", "autoconnect", "", "2.0+ does not use this attribute - define <autoconnect> tags instead" },
339 { "link", "transport", "", "has been moved to <link:ssl> as of 2.0" },
340 { "module", "name", "m_chanprotect.so", "has been replaced with m_customprefix as of 2.2" },
341 { "module", "name", "m_halfop.so", "has been replaced with m_customprefix as of 2.2" },
342 { "options", "cyclehosts", "", "has been replaced with m_hostcycle as of 2.2" },
343 { "performance", "nouserdns", "", "has been moved to <connect:resolvehostnames> as of 2.2" }
346 void ServerConfig::Fill()
348 ConfigTag* options = ConfValue("options");
349 ConfigTag* security = ConfValue("security");
352 ServerName = ConfValue("server")->getString("name", "irc.example.com");
353 ValidHost(ServerName, "<server:name>");
355 sid = ConfValue("server")->getString("id");
356 if (!sid.empty() && !InspIRCd::IsSID(sid))
357 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.");
361 if (ServerName != ConfValue("server")->getString("name"))
362 throw CoreException("You must restart to change the server name");
364 std::string nsid = ConfValue("server")->getString("id");
365 if (!nsid.empty() && nsid != sid)
366 throw CoreException("You must restart to change the server id");
368 diepass = ConfValue("power")->getString("diepass");
369 restartpass = ConfValue("power")->getString("restartpass");
370 powerhash = ConfValue("power")->getString("hash");
371 PrefixQuit = options->getString("prefixquit");
372 SuffixQuit = options->getString("suffixquit");
373 FixedQuit = options->getString("fixedquit");
374 PrefixPart = options->getString("prefixpart");
375 SuffixPart = options->getString("suffixpart");
376 FixedPart = options->getString("fixedpart");
377 SoftLimit = ConfValue("performance")->getInt("softlimit", ServerInstance->SE->GetMaxFds(), 10, ServerInstance->SE->GetMaxFds());
378 CCOnConnect = ConfValue("performance")->getBool("clonesonconnect", true);
379 MaxConn = ConfValue("performance")->getInt("somaxconn", SOMAXCONN);
380 XLineMessage = options->getString("xlinemessage", options->getString("moronbanner", "You're banned!"));
381 ServerDesc = ConfValue("server")->getString("description", "Configure Me");
382 Network = ConfValue("server")->getString("network", "Network");
383 AdminName = ConfValue("admin")->getString("name", "");
384 AdminEmail = ConfValue("admin")->getString("email", "null@example.com");
385 AdminNick = ConfValue("admin")->getString("nick", "admin");
386 ModPath = ConfValue("path")->getString("moduledir", MOD_PATH);
387 NetBufferSize = ConfValue("performance")->getInt("netbuffersize", 10240, 1024, 65534);
388 dns_timeout = ConfValue("dns")->getInt("timeout", 5);
389 DisabledCommands = ConfValue("disabled")->getString("commands", "");
390 DisabledDontExist = ConfValue("disabled")->getBool("fakenonexistant");
391 UserStats = security->getString("userstats");
392 CustomVersion = security->getString("customversion");
393 HideSplits = security->getBool("hidesplits");
394 HideBans = security->getBool("hidebans");
395 HideWhoisServer = security->getString("hidewhois");
396 HideKillsServer = security->getString("hidekills");
397 RestrictBannedUsers = security->getBool("restrictbannedusers", true);
398 GenericOper = security->getBool("genericoper");
399 SyntaxHints = options->getBool("syntaxhints");
400 CycleHostsFromUser = options->getBool("cyclehostsfromuser");
401 UndernetMsgPrefix = options->getBool("ircumsgprefix");
402 FullHostInTopic = options->getBool("hostintopic");
403 MaxTargets = security->getInt("maxtargets", 20, 1, 31);
404 DefaultModes = options->getString("defaultmodes", "not");
405 PID = ConfValue("pid")->getString("file");
406 MaxChans = ConfValue("channels")->getInt("users", 20);
407 OperMaxChans = ConfValue("channels")->getInt("opers", 60);
408 c_ipv4_range = ConfValue("cidr")->getInt("ipv4clone", 32);
409 c_ipv6_range = ConfValue("cidr")->getInt("ipv6clone", 128);
410 Limits.NickMax = ConfValue("limits")->getInt("maxnick", 32);
411 Limits.ChanMax = ConfValue("limits")->getInt("maxchan", 64);
412 Limits.MaxModes = ConfValue("limits")->getInt("maxmodes", 20);
413 Limits.IdentMax = ConfValue("limits")->getInt("maxident", 11);
414 Limits.MaxQuit = ConfValue("limits")->getInt("maxquit", 255);
415 Limits.MaxTopic = ConfValue("limits")->getInt("maxtopic", 307);
416 Limits.MaxKick = ConfValue("limits")->getInt("maxkick", 255);
417 Limits.MaxGecos = ConfValue("limits")->getInt("maxgecos", 128);
418 Limits.MaxAway = ConfValue("limits")->getInt("maxaway", 200);
419 Limits.MaxLine = ConfValue("limits")->getInt("maxline", 512);
420 InvBypassModes = options->getBool("invitebypassmodes", true);
421 NoSnoticeStack = options->getBool("nosnoticestack", false);
423 if (Network.find(' ') != std::string::npos)
424 throw CoreException(Network + " is not a valid network name. A network name must not contain spaces.");
426 std::string defbind = options->getString("defaultbind");
427 if (assign(defbind) == "ipv4")
429 WildcardIPv6 = false;
431 else if (assign(defbind) == "ipv6")
438 int socktest = socket(AF_INET6, SOCK_STREAM, 0);
440 WildcardIPv6 = false;
442 ServerInstance->SE->Close(socktest);
444 ConfigTagList tags = ConfTags("uline");
445 for(ConfigIter i = tags.first; i != tags.second; ++i)
447 ConfigTag* tag = i->second;
449 if (!tag->readString("server", server))
450 throw CoreException("<uline> tag missing server at " + tag->getTagLocation());
452 if (ServerName == server)
453 throw CoreException("Servers should not uline themselves (at " + tag->getTagLocation() + ")");
455 ulines[assign(server)] = tag->getBool("silent");
458 ReadXLine(this, "badip", "ipmask", ServerInstance->XLines->GetFactory("Z"));
459 ReadXLine(this, "badnick", "nick", ServerInstance->XLines->GetFactory("Q"));
460 ReadXLine(this, "badhost", "host", ServerInstance->XLines->GetFactory("K"));
461 ReadXLine(this, "exception", "host", ServerInstance->XLines->GetFactory("E"));
463 memset(DisabledUModes, 0, sizeof(DisabledUModes));
464 std::string modes = ConfValue("disabled")->getString("usermodes");
465 for (std::string::const_iterator p = modes.begin(); p != modes.end(); ++p)
467 // Complain when the character is not a-z or A-Z
468 if ((*p < 'A') || (*p > 'z') || ((*p < 'a') && (*p > 'Z')))
469 throw CoreException("Invalid usermode " + std::string(1, *p) + " was found.");
470 DisabledUModes[*p - 'A'] = 1;
473 memset(DisabledCModes, 0, sizeof(DisabledCModes));
474 modes = ConfValue("disabled")->getString("chanmodes");
475 for (std::string::const_iterator p = modes.begin(); p != modes.end(); ++p)
477 if ((*p < 'A') || (*p > 'z') || ((*p < 'a') && (*p > 'Z')))
478 throw CoreException("Invalid chanmode " + std::string(1, *p) + " was found.");
479 DisabledCModes[*p - 'A'] = 1;
482 memset(HideModeLists, 0, sizeof(HideModeLists));
483 modes = ConfValue("security")->getString("hidemodes");
484 for (std::string::const_iterator p = modes.begin(); p != modes.end(); ++p)
485 HideModeLists[(unsigned char) *p] = true;
487 std::string v = security->getString("announceinvites");
490 AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_OPS;
492 AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_ALL;
493 else if (v == "dynamic")
494 AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_DYNAMIC;
496 AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_NONE;
498 v = security->getString("operspywhois");
500 OperSpyWhois = SPYWHOIS_SPLITMSG;
501 else if (v == "on" || v == "yes")
502 OperSpyWhois = SPYWHOIS_SINGLEMSG;
504 OperSpyWhois = SPYWHOIS_NONE;
507 // WARNING: it is not safe to use most of the codebase in this function, as it
508 // will run in the config reader thread
509 void ServerConfig::Read()
511 /* Load and parse the config file, if there are any errors then explode */
513 ParseStack stack(this);
516 valid = stack.ParseFile(ServerInstance->ConfigFileName, 0);
518 catch (CoreException& err)
521 errstr << err.GetReason();
525 void ServerConfig::Apply(ServerConfig* old, const std::string &useruid)
531 * These values can only be set on boot. Keep their old values. Do it before we send messages so we actually have a servername.
533 this->ServerName = old->ServerName;
534 this->sid = old->sid;
535 this->cmdline = old->cmdline;
538 /* The stuff in here may throw CoreException, be sure we're in a position to catch it. */
541 for (int index = 0; index * sizeof(DeprecatedConfig) < sizeof(ChangedConfig); index++)
544 ConfigTagList tags = ConfTags(ChangedConfig[index].tag);
545 for(ConfigIter i = tags.first; i != tags.second; ++i)
547 if (i->second->readString(ChangedConfig[index].key, value, true)
548 && (ChangedConfig[index].value.empty() || value == ChangedConfig[index].value))
550 errstr << "Your configuration contains a deprecated value: <" << ChangedConfig[index].tag;
551 if (ChangedConfig[index].value.empty())
553 errstr << ':' << ChangedConfig[index].key;
557 errstr << ' ' << ChangedConfig[index].key << "=\"" << ChangedConfig[index].value << "\"";
559 errstr << "> - " << ChangedConfig[index].reason << " (at " << i->second->getTagLocation() << ")" << std::endl;
566 // Handle special items
567 CrossCheckOperClassType();
568 CrossCheckConnectBlocks(old);
570 catch (CoreException &ce)
572 errstr << ce.GetReason();
575 // Check errors before dealing with failed binds, since continuing on failed bind is wanted in some circumstances.
576 valid = errstr.str().empty();
578 // write once here, to try it out and make sure its ok
580 ServerInstance->WritePID(this->PID);
582 ConfigTagList binds = ConfTags("bind");
583 if (binds.first == binds.second)
584 errstr << "Possible configuration error: you have not defined any <bind> blocks." << std::endl
585 << "You will need to do this if you want clients to be able to connect!" << std::endl;
589 // On first run, ports are bound later on
591 ServerInstance->BindPorts(pl);
594 errstr << "Not all your client ports could be bound." << std::endl
595 << "The following port(s) failed to bind:" << std::endl;
598 for (FailedPortList::iterator i = pl.begin(); i != pl.end(); i++, j++)
600 errstr << j << ".\tAddress: " << (i->first.empty() ? "<all>" : i->first.c_str()) << "\tReason: "
601 << i->second << std::endl;
606 User* user = useruid.empty() ? NULL : ServerInstance->FindNick(useruid);
609 ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "There were errors in your configuration file:");
611 while (errstr.good())
614 getline(errstr, line, '\n');
617 // On startup, print out to console (still attached at this point)
619 std::cout << line << std::endl;
620 // If a user is rehashing, tell them directly
622 user->SendText(":%s NOTICE %s :*** %s", ServerInstance->Config->ServerName.c_str(), user->nick.c_str(), line.c_str());
624 ServerInstance->SNO->WriteGlobalSno('a', line);
628 errstr.str(std::string());
630 // Re-parse our MOTD and RULES files for colors -- Justasic
631 for (ClassVector::const_iterator it = this->Classes.begin(), it_end = this->Classes.end(); it != it_end; ++it)
633 ConfigTag *tag = (*it)->config;
634 // Make sure our connection class allows motd colors
635 if(!tag->getBool("allowmotdcolors"))
638 ConfigFileCache::iterator file = this->Files.find(tag->getString("motd", "motd"));
639 if (file != this->Files.end())
640 InspIRCd::ProcessColors(file->second);
642 file = this->Files.find(tag->getString("rules", "rules"));
643 if (file != this->Files.end())
644 InspIRCd::ProcessColors(file->second);
647 /* No old configuration -> initial boot, nothing more to do here */
652 ServerInstance->Exit(EXIT_STATUS_CONFIG);
659 // If there were errors processing configuration, don't touch modules.
666 user->SendText(":%s NOTICE %s :*** Successfully rehashed server.",
667 ServerInstance->Config->ServerName.c_str(), user->nick.c_str());
668 ServerInstance->SNO->WriteGlobalSno('a', "*** Successfully rehashed server.");
671 void ServerConfig::ApplyModules(User* user)
673 const std::vector<std::string> v = ServerInstance->Modules->GetAllModuleNames(0);
674 std::vector<std::string> added_modules;
675 std::set<std::string> removed_modules(v.begin(), v.end());
677 ConfigTagList tags = ConfTags("module");
678 for(ConfigIter i = tags.first; i != tags.second; ++i)
680 ConfigTag* tag = i->second;
682 if (tag->readString("name", name))
684 // if this module is already loaded, the erase will succeed, so we need do nothing
685 // otherwise, we need to add the module (which will be done later)
686 if (removed_modules.erase(name) == 0)
687 added_modules.push_back(name);
691 for (std::set<std::string>::iterator removing = removed_modules.begin(); removing != removed_modules.end(); removing++)
693 // Don't remove cmd_*.so, just remove m_*.so
694 if (removing->c_str()[0] == 'c')
696 Module* m = ServerInstance->Modules->Find(*removing);
697 if (m && ServerInstance->Modules->Unload(m))
699 ServerInstance->SNO->WriteGlobalSno('a', "*** REHASH UNLOADED MODULE: %s",removing->c_str());
702 user->WriteNumeric(RPL_UNLOADEDMODULE, "%s %s :Module %s successfully unloaded.",user->nick.c_str(), removing->c_str(), removing->c_str());
704 ServerInstance->SNO->WriteGlobalSno('a', "Module %s successfully unloaded.", removing->c_str());
709 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());
711 ServerInstance->SNO->WriteGlobalSno('a', "Failed to unload module %s: %s", removing->c_str(), ServerInstance->Modules->LastError().c_str());
715 for (std::vector<std::string>::iterator adding = added_modules.begin(); adding != added_modules.end(); adding++)
717 if (ServerInstance->Modules->Load(adding->c_str()))
719 ServerInstance->SNO->WriteGlobalSno('a', "*** REHASH LOADED MODULE: %s",adding->c_str());
721 user->WriteNumeric(RPL_LOADEDMODULE, "%s %s :Module %s successfully loaded.",user->nick.c_str(), adding->c_str(), adding->c_str());
723 ServerInstance->SNO->WriteGlobalSno('a', "Module %s successfully loaded.", adding->c_str());
728 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());
730 ServerInstance->SNO->WriteGlobalSno('a', "Failed to load module %s: %s", adding->c_str(), ServerInstance->Modules->LastError().c_str());
735 bool ServerConfig::StartsWithWindowsDriveLetter(const std::string &path)
737 return (path.length() > 2 && isalpha(path[0]) && path[1] == ':');
740 ConfigTag* ServerConfig::ConfValue(const std::string &tag)
742 ConfigTagList found = config_data.equal_range(tag);
743 if (found.first == found.second)
745 ConfigTag* rv = found.first->second;
747 if (found.first != found.second)
748 ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "Multiple <" + tag + "> tags found; only first will be used "
749 "(first at " + rv->getTagLocation() + "; second at " + found.first->second->getTagLocation() + ")");
753 ConfigTagList ServerConfig::ConfTags(const std::string& tag)
755 return config_data.equal_range(tag);
758 bool ServerConfig::FileExists(const char* file)
761 if (stat(file, &sb) == -1)
764 if ((sb.st_mode & S_IFDIR) > 0)
767 return !access(file, F_OK);
770 std::string ServerConfig::Escape(const std::string& str, bool xml)
773 for (std::string::const_iterator it = str.begin(); it != str.end(); ++it)
778 escaped += xml ? """ : "\"";
781 escaped += xml ? "&" : "&";
784 escaped += xml ? "\\" : "\\\\";
794 const char* ServerConfig::CleanFilename(const char* name)
796 const char* p = name + strlen(name);
797 while ((p != name) && (*p != '/') && (*p != '\\')) p--;
798 return (p != name ? ++p : p);
801 void ConfigReaderThread::Run()
807 void ConfigReaderThread::Finish()
809 ServerConfig* old = ServerInstance->Config;
810 ServerInstance->Logs->Log("CONFIG", LOG_DEBUG, "Switching to new configuration...");
811 ServerInstance->Config = this->Config;
812 Config->Apply(old, TheUserUID);
817 * Apply the changed configuration from the rehash.
819 * XXX: The order of these is IMPORTANT, do not reorder them without testing
822 ServerInstance->XLines->CheckELines();
823 ServerInstance->XLines->ApplyLines();
824 ChanModeReference ban(NULL, "ban");
825 static_cast<ListModeBase*>(*ban)->DoRehash();
826 Config->ApplyDisabledCommands(Config->DisabledCommands);
827 User* user = ServerInstance->FindNick(TheUserUID);
828 FOREACH_MOD(OnRehash, (user));
829 ServerInstance->ISupport.Build();
831 ServerInstance->Logs->CloseLogs();
832 ServerInstance->Logs->OpenFileLogs();
834 if (Config->RawLog && !old->RawLog)
835 ServerInstance->Users->ServerNoticeAll("*** Raw I/O logging is enabled on this server. All messages, passwords, and commands are being recorded.");
842 ServerInstance->Config = old;