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 = CycleHosts = InvBypassModes = true;
38 NetBufferSize = 10240;
39 SoftLimit = ServerInstance->SE->GetMaxFds();
47 template<typename T, typename V>
48 static void range(T& value, V min, V max, V def, const char* msg)
50 if (value >= (T)min && value <= (T)max)
52 ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "WARNING: %s value of %ld is not between %ld and %ld; set to %ld.",
53 msg, (long)value, (long)min, (long)max, (long)def);
57 static void ValidHost(const std::string& p, const std::string& msg)
60 if (p.empty() || p[0] == '.')
61 throw CoreException("The value of "+msg+" is not a valid hostname");
62 for (unsigned int i=0;i < p.length();i++)
67 throw CoreException("The value of "+msg+" is not a valid hostname");
74 throw CoreException("The value of "+msg+" is not a valid hostname");
77 bool ServerConfig::ApplyDisabledCommands(const std::string& data)
79 std::stringstream dcmds(data);
82 /* Enable everything first */
83 for (Commandtable::iterator x = ServerInstance->Parser->cmdlist.begin(); x != ServerInstance->Parser->cmdlist.end(); x++)
84 x->second->Disable(false);
86 /* Now disable all the ones which the user wants disabled */
87 while (dcmds >> thiscmd)
89 Commandtable::iterator cm = ServerInstance->Parser->cmdlist.find(thiscmd);
90 if (cm != ServerInstance->Parser->cmdlist.end())
92 cm->second->Disable(true);
98 static void ReadXLine(ServerConfig* conf, const std::string& tag, const std::string& key, XLineFactory* make)
100 ConfigTagList tags = conf->ConfTags(tag);
101 for(ConfigIter i = tags.first; i != tags.second; ++i)
103 ConfigTag* ctag = i->second;
105 if (!ctag->readString(key, mask))
106 throw CoreException("<"+tag+":"+key+"> missing at " + ctag->getTagLocation());
107 std::string reason = ctag->getString("reason", "<Config>");
108 XLine* xl = make->Generate(ServerInstance->Time(), 0, "<Config>", reason, mask);
109 if (!ServerInstance->XLines->AddLine(xl, NULL))
114 typedef std::map<std::string, ConfigTag*> LocalIndex;
115 void ServerConfig::CrossCheckOperClassType()
117 LocalIndex operclass;
118 ConfigTagList tags = ConfTags("class");
119 for(ConfigIter i = tags.first; i != tags.second; ++i)
121 ConfigTag* tag = i->second;
122 std::string name = tag->getString("name");
124 throw CoreException("<class:name> missing from tag at " + tag->getTagLocation());
125 if (operclass.find(name) != operclass.end())
126 throw CoreException("Duplicate class block with name " + name + " at " + tag->getTagLocation());
127 operclass[name] = tag;
129 tags = ConfTags("type");
130 for(ConfigIter i = tags.first; i != tags.second; ++i)
132 ConfigTag* tag = i->second;
133 std::string name = tag->getString("name");
135 throw CoreException("<type:name> is missing from tag at " + tag->getTagLocation());
136 if (oper_blocks.find(" " + name) != oper_blocks.end())
137 throw CoreException("Duplicate type block with name " + name + " at " + tag->getTagLocation());
139 OperInfo* ifo = new OperInfo;
140 oper_blocks[" " + name] = ifo;
142 ifo->type_block = tag;
144 std::string classname;
145 irc::spacesepstream str(tag->getString("classes"));
146 while (str.GetToken(classname))
148 LocalIndex::iterator cls = operclass.find(classname);
149 if (cls == operclass.end())
150 throw CoreException("Oper type " + name + " has missing class " + classname);
151 ifo->class_blocks.push_back(cls->second);
155 tags = ConfTags("oper");
156 for(ConfigIter i = tags.first; i != tags.second; ++i)
158 ConfigTag* tag = i->second;
160 std::string name = tag->getString("name");
162 throw CoreException("<oper:name> missing from tag at " + tag->getTagLocation());
164 std::string type = tag->getString("type");
165 OperIndex::iterator tblk = oper_blocks.find(" " + type);
166 if (tblk == oper_blocks.end())
167 throw CoreException("Oper block " + name + " has missing type " + type);
168 if (oper_blocks.find(name) != oper_blocks.end())
169 throw CoreException("Duplicate oper block with name " + name + " at " + tag->getTagLocation());
171 OperInfo* ifo = new OperInfo;
173 ifo->oper_block = tag;
174 ifo->type_block = tblk->second->type_block;
175 ifo->class_blocks.assign(tblk->second->class_blocks.begin(), tblk->second->class_blocks.end());
176 oper_blocks[name] = ifo;
180 void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current)
182 typedef std::map<std::string, ConnectClass*> ClassMap;
183 ClassMap oldBlocksByMask;
186 for(ClassVector::iterator i = current->Classes.begin(); i != current->Classes.end(); ++i)
188 ConnectClass* c = *i;
189 if (c->name.substr(0, 8) != "unnamed-")
191 oldBlocksByMask["n" + c->name] = c;
193 else if (c->type == CC_ALLOW || c->type == CC_DENY)
195 std::string typeMask = (c->type == CC_ALLOW) ? "a" : "d";
197 oldBlocksByMask[typeMask] = c;
202 int blk_count = config_data.count("connect");
205 // No connect blocks found; make a trivial default block
206 std::vector<KeyVal>* items;
207 ConfigTag* tag = ConfigTag::create("connect", "<auto>", 0, items);
208 items->push_back(std::make_pair("allow", "*"));
209 config_data.insert(std::make_pair("connect", tag));
213 Classes.resize(blk_count);
214 std::map<std::string, int> names;
216 bool try_again = true;
217 for(int tries=0; try_again; tries++)
220 ConfigTagList tags = ConfTags("connect");
222 for(ConfigIter it = tags.first; it != tags.second; ++it, ++i)
224 ConfigTag* tag = it->second;
228 ConnectClass* parent = NULL;
229 std::string parentName = tag->getString("parent");
230 if (!parentName.empty())
232 std::map<std::string,int>::iterator parentIter = names.find(parentName);
233 if (parentIter == names.end())
236 // couldn't find parent this time. If it's the last time, we'll never find it.
237 if (tries >= blk_count)
238 throw CoreException("Could not find parent connect class \"" + parentName + "\" for connect block at " + tag->getTagLocation());
241 parent = Classes[parentIter->second];
244 std::string name = tag->getString("name");
245 std::string mask, typeMask;
248 if (tag->readString("allow", mask, false))
251 typeMask = 'a' + mask;
253 else if (tag->readString("deny", mask, false))
256 typeMask = 'd' + mask;
258 else if (!name.empty())
262 typeMask = 'n' + mask;
266 throw CoreException("Connect class must have allow, deny, or name specified at " + tag->getTagLocation());
271 name = "unnamed-" + ConvToStr(i);
275 typeMask = 'n' + name;
278 if (names.find(name) != names.end())
279 throw CoreException("Two connect classes with name \"" + name + "\" defined!");
282 ConnectClass* me = parent ?
283 new ConnectClass(tag, type, mask, *parent) :
284 new ConnectClass(tag, type, mask);
288 me->registration_timeout = tag->getInt("timeout", me->registration_timeout);
289 me->pingtime = tag->getInt("pingfreq", me->pingtime);
291 if (tag->readString("sendq", sendq))
293 // attempt to guess a good hard/soft sendq from a single value
294 long value = atol(sendq.c_str());
296 me->softsendqmax = value / 16;
298 me->softsendqmax = value;
299 me->hardsendqmax = value * 8;
301 me->softsendqmax = tag->getInt("softsendq", me->softsendqmax);
302 me->hardsendqmax = tag->getInt("hardsendq", me->hardsendqmax);
303 me->recvqmax = tag->getInt("recvq", me->recvqmax);
304 me->penaltythreshold = tag->getInt("threshold", me->penaltythreshold);
305 me->commandrate = tag->getInt("commandrate", me->commandrate);
306 me->fakelag = tag->getBool("fakelag", me->fakelag);
307 me->maxlocal = tag->getInt("localmax", me->maxlocal);
308 me->maxglobal = tag->getInt("globalmax", me->maxglobal);
309 me->maxchans = tag->getInt("maxchans", me->maxchans);
310 me->maxconnwarn = tag->getBool("maxconnwarn", me->maxconnwarn);
311 me->limit = tag->getInt("limit", me->limit);
312 me->nouserdns = tag->getBool("nouserdns", me->nouserdns);
314 ClassMap::iterator oldMask = oldBlocksByMask.find(typeMask);
315 if (oldMask != oldBlocksByMask.end())
317 ConnectClass* old = oldMask->second;
318 oldBlocksByMask.erase(oldMask);
328 /** Represents a deprecated configuration tag.
330 struct DeprecatedConfig
335 /** Attribute key. */
338 /** Attribute value. */
341 /** Reason for deprecation. */
345 static const DeprecatedConfig ChangedConfig[] = {
346 { "bind", "transport", "", "has been moved to <bind:ssl> as of 2.0" },
347 { "die", "value", "", "you need to reread your config" },
348 { "link", "autoconnect", "", "2.0+ does not use this attribute - define <autoconnect> tags instead" },
349 { "link", "transport", "", "has been moved to <link:ssl> as of 2.0" },
350 { "module", "name", "m_chanprotect.so", "has been replaced with m_customprefix as of 2.2" },
351 { "module", "name", "m_halfop.so", "has been replaced with m_customprefix as of 2.2" },
352 { "performance", "nouserdns", "", "has been moved to <connect:nouserdns> as of 2.2" }
355 void ServerConfig::Fill()
357 ConfigTag* options = ConfValue("options");
358 ConfigTag* security = ConfValue("security");
361 ServerName = ConfValue("server")->getString("name");
362 sid = ConfValue("server")->getString("id");
363 ValidHost(ServerName, "<server:name>");
364 if (!sid.empty() && !InspIRCd::IsSID(sid))
365 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.");
369 if (ServerName != ConfValue("server")->getString("name"))
370 throw CoreException("You must restart to change the server name");
372 std::string nsid = ConfValue("server")->getString("id");
373 if (!nsid.empty() && nsid != sid)
374 throw CoreException("You must restart to change the server id");
376 if (Limits.MaxLine != static_cast<size_t>(ConfValue("limits")->getInt("maxline", 512)))
377 throw CoreException("You must restart to change the maximum line length");
380 diepass = ConfValue("power")->getString("diepass");
381 restartpass = ConfValue("power")->getString("restartpass");
382 powerhash = ConfValue("power")->getString("hash");
383 PrefixQuit = options->getString("prefixquit");
384 SuffixQuit = options->getString("suffixquit");
385 FixedQuit = options->getString("fixedquit");
386 PrefixPart = options->getString("prefixpart");
387 SuffixPart = options->getString("suffixpart");
388 FixedPart = options->getString("fixedpart");
389 SoftLimit = ConfValue("performance")->getInt("softlimit", ServerInstance->SE->GetMaxFds());
390 MaxConn = ConfValue("performance")->getInt("somaxconn", SOMAXCONN);
391 MoronBanner = options->getString("moronbanner", "You're banned!");
392 ServerDesc = ConfValue("server")->getString("description", "Configure Me");
393 Network = ConfValue("server")->getString("network", "Network");
394 AdminName = ConfValue("admin")->getString("name", "");
395 AdminEmail = ConfValue("admin")->getString("email", "null@example.com");
396 AdminNick = ConfValue("admin")->getString("nick", "admin");
397 ModPath = ConfValue("path")->getString("moduledir", MOD_PATH);
398 NetBufferSize = ConfValue("performance")->getInt("netbuffersize", 10240);
399 dns_timeout = ConfValue("dns")->getInt("timeout", 5);
400 DisabledCommands = ConfValue("disabled")->getString("commands", "");
401 DisabledDontExist = ConfValue("disabled")->getBool("fakenonexistant");
402 UserStats = security->getString("userstats");
403 CustomVersion = security->getString("customversion", Network + " IRCd");
404 HideSplits = security->getBool("hidesplits");
405 HideBans = security->getBool("hidebans");
406 HideWhoisServer = security->getString("hidewhois");
407 HideKillsServer = security->getString("hidekills");
408 RestrictBannedUsers = security->getBool("restrictbannedusers", true);
409 GenericOper = security->getBool("genericoper");
410 SyntaxHints = options->getBool("syntaxhints");
411 CycleHosts = options->getBool("cyclehosts");
412 CycleHostsFromUser = options->getBool("cyclehostsfromuser");
413 UndernetMsgPrefix = options->getBool("ircumsgprefix");
414 FullHostInTopic = options->getBool("hostintopic");
415 MaxTargets = security->getInt("maxtargets", 20);
416 DefaultModes = options->getString("defaultmodes", "nt");
417 PID = ConfValue("pid")->getString("file");
418 MaxChans = ConfValue("channels")->getInt("users", 20);
419 OperMaxChans = ConfValue("channels")->getInt("opers", 60);
420 c_ipv4_range = ConfValue("cidr")->getInt("ipv4clone", 32);
421 c_ipv6_range = ConfValue("cidr")->getInt("ipv6clone", 128);
422 Limits.NickMax = ConfValue("limits")->getInt("maxnick", 32);
423 Limits.ChanMax = ConfValue("limits")->getInt("maxchan", 64);
424 Limits.MaxModes = ConfValue("limits")->getInt("maxmodes", 20);
425 Limits.IdentMax = ConfValue("limits")->getInt("maxident", 11);
426 Limits.MaxQuit = ConfValue("limits")->getInt("maxquit", 255);
427 Limits.MaxTopic = ConfValue("limits")->getInt("maxtopic", 307);
428 Limits.MaxKick = ConfValue("limits")->getInt("maxkick", 255);
429 Limits.MaxGecos = ConfValue("limits")->getInt("maxgecos", 128);
430 Limits.MaxAway = ConfValue("limits")->getInt("maxaway", 200);
431 Limits.MaxLine = ConfValue("limits")->getInt("maxline", 512);
432 InvBypassModes = options->getBool("invitebypassmodes", true);
433 NoSnoticeStack = options->getBool("nosnoticestack", false);
435 range(SoftLimit, 10, ServerInstance->SE->GetMaxFds(), ServerInstance->SE->GetMaxFds(), "<performance:softlimit>");
436 if (ConfValue("performance")->getBool("limitsomaxconn", true))
437 range(MaxConn, 0, SOMAXCONN, SOMAXCONN, "<performance:somaxconn>");
438 range(MaxTargets, 1, 31, 20, "<security:maxtargets>");
439 range(NetBufferSize, 1024, 65534, 10240, "<performance:netbuffersize>");
441 std::string defbind = options->getString("defaultbind");
442 if (assign(defbind) == "ipv4")
444 WildcardIPv6 = false;
446 else if (assign(defbind) == "ipv6")
453 int socktest = socket(AF_INET6, SOCK_STREAM, 0);
455 WildcardIPv6 = false;
457 ServerInstance->SE->Close(socktest);
459 ConfigTagList tags = ConfTags("uline");
460 for(ConfigIter i = tags.first; i != tags.second; ++i)
462 ConfigTag* tag = i->second;
464 if (!tag->readString("server", server))
465 throw CoreException("<uline> tag missing server at " + tag->getTagLocation());
466 ulines[assign(server)] = tag->getBool("silent");
469 ReadXLine(this, "badip", "ipmask", ServerInstance->XLines->GetFactory("Z"));
470 ReadXLine(this, "badnick", "nick", ServerInstance->XLines->GetFactory("Q"));
471 ReadXLine(this, "badhost", "host", ServerInstance->XLines->GetFactory("K"));
472 ReadXLine(this, "exception", "host", ServerInstance->XLines->GetFactory("E"));
474 memset(DisabledUModes, 0, sizeof(DisabledUModes));
475 std::string modes = ConfValue("disabled")->getString("usermodes");
476 for (std::string::const_iterator p = modes.begin(); p != modes.end(); ++p)
478 // Complain when the character is not a-z or A-Z
479 if ((*p < 'A') || (*p > 'z') || ((*p < 'a') && (*p > 'Z')))
480 throw CoreException("Invalid usermode " + std::string(1, *p) + " was found.");
481 DisabledUModes[*p - 'A'] = 1;
484 memset(DisabledCModes, 0, sizeof(DisabledCModes));
485 modes = ConfValue("disabled")->getString("chanmodes");
486 for (std::string::const_iterator p = modes.begin(); p != modes.end(); ++p)
488 if ((*p < 'A') || (*p > 'z') || ((*p < 'a') && (*p > 'Z')))
489 throw CoreException("Invalid chanmode " + std::string(1, *p) + " was found.");
490 DisabledCModes[*p - 'A'] = 1;
493 memset(HideModeLists, 0, sizeof(HideModeLists));
494 modes = ConfValue("security")->getString("hidemodes");
495 for (std::string::const_iterator p = modes.begin(); p != modes.end(); ++p)
496 HideModeLists[(unsigned char) *p] = true;
498 std::string v = security->getString("announceinvites");
501 AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_OPS;
503 AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_ALL;
504 else if (v == "dynamic")
505 AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_DYNAMIC;
507 AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_NONE;
509 v = security->getString("operspywhois");
511 OperSpyWhois = SPYWHOIS_SPLITMSG;
512 else if (v == "on" || v == "yes")
513 OperSpyWhois = SPYWHOIS_SINGLEMSG;
515 OperSpyWhois = SPYWHOIS_NONE;
518 // WARNING: it is not safe to use most of the codebase in this function, as it
519 // will run in the config reader thread
520 void ServerConfig::Read()
522 /* Load and parse the config file, if there are any errors then explode */
524 ParseStack stack(this);
527 valid = stack.ParseFile(ServerInstance->ConfigFileName, 0);
529 catch (CoreException& err)
532 errstr << err.GetReason();
536 void ServerConfig::Apply(ServerConfig* old, const std::string &useruid)
542 * These values can only be set on boot. Keep their old values. Do it before we send messages so we actually have a servername.
544 this->ServerName = old->ServerName;
545 this->sid = old->sid;
546 this->cmdline = old->cmdline;
549 /* The stuff in here may throw CoreException, be sure we're in a position to catch it. */
552 for (int index = 0; index * sizeof(DeprecatedConfig) < sizeof(ChangedConfig); index++)
555 ConfigTagList tags = ConfTags(ChangedConfig[index].tag);
556 for(ConfigIter i = tags.first; i != tags.second; ++i)
558 if (i->second->readString(ChangedConfig[index].key, value, true)
559 && (ChangedConfig[index].value.empty() || value == ChangedConfig[index].value))
561 errstr << "Your configuration contains a deprecated value: <" << ChangedConfig[index].tag;
562 if (ChangedConfig[index].value.empty())
564 errstr << ':' << ChangedConfig[index].key;
568 errstr << ' ' << ChangedConfig[index].key << "=\"" << ChangedConfig[index].value << "\"";
570 errstr << "> - " << ChangedConfig[index].reason << " (at " << i->second->getTagLocation() << ")\n";
577 // Handle special items
578 CrossCheckOperClassType();
579 CrossCheckConnectBlocks(old);
581 catch (CoreException &ce)
583 errstr << ce.GetReason();
586 // Check errors before dealing with failed binds, since continuing on failed bind is wanted in some circumstances.
587 valid = errstr.str().empty();
589 // write once here, to try it out and make sure its ok
591 ServerInstance->WritePID(this->PID);
595 // On first run, ports are bound later on
597 ServerInstance->BindPorts(pl);
600 errstr << "Not all your client ports could be bound." << std::endl
601 << "The following port(s) failed to bind:" << std::endl;
604 for (FailedPortList::iterator i = pl.begin(); i != pl.end(); i++, j++)
606 errstr << j << ".\tAddress: " << (i->first.empty() ? "<all>" : i->first.c_str()) << "\tReason: "
607 << i->second << std::endl;
612 User* user = useruid.empty() ? NULL : ServerInstance->FindNick(useruid);
615 ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "There were errors in your configuration file:");
617 while (errstr.good())
620 getline(errstr, line, '\n');
623 // On startup, print out to console (still attached at this point)
625 std::cout << line << std::endl;
626 // If a user is rehashing, tell them directly
628 user->SendText(":%s NOTICE %s :*** %s", ServerInstance->Config->ServerName.c_str(), user->nick.c_str(), line.c_str());
630 ServerInstance->SNO->WriteGlobalSno('a', line);
634 errstr.str(std::string());
636 // Re-parse our MOTD and RULES files for colors -- Justasic
637 for (ClassVector::const_iterator it = this->Classes.begin(), it_end = this->Classes.end(); it != it_end; ++it)
639 ConfigTag *tag = (*it)->config;
640 // Make sure our connection class allows motd colors
641 if(!tag->getBool("allowmotdcolors"))
644 ConfigFileCache::iterator file = this->Files.find(tag->getString("motd", "motd"));
645 if (file != this->Files.end())
646 InspIRCd::ProcessColors(file->second);
648 file = this->Files.find(tag->getString("rules", "rules"));
649 if (file != this->Files.end())
650 InspIRCd::ProcessColors(file->second);
653 /* No old configuration -> initial boot, nothing more to do here */
658 ServerInstance->Exit(EXIT_STATUS_CONFIG);
665 // If there were errors processing configuration, don't touch modules.
672 user->SendText(":%s NOTICE %s :*** Successfully rehashed server.",
673 ServerInstance->Config->ServerName.c_str(), user->nick.c_str());
674 ServerInstance->SNO->WriteGlobalSno('a', "*** Successfully rehashed server.");
677 void ServerConfig::ApplyModules(User* user)
679 const std::vector<std::string> v = ServerInstance->Modules->GetAllModuleNames(0);
680 std::vector<std::string> added_modules;
681 std::set<std::string> removed_modules(v.begin(), v.end());
683 ConfigTagList tags = ConfTags("module");
684 for(ConfigIter i = tags.first; i != tags.second; ++i)
686 ConfigTag* tag = i->second;
688 if (tag->readString("name", name))
690 // if this module is already loaded, the erase will succeed, so we need do nothing
691 // otherwise, we need to add the module (which will be done later)
692 if (removed_modules.erase(name) == 0)
693 added_modules.push_back(name);
697 if (ConfValue("options")->getBool("allowhalfop") && removed_modules.erase("m_halfop.so") == 0)
698 added_modules.push_back("m_halfop.so");
700 for (std::set<std::string>::iterator removing = removed_modules.begin(); removing != removed_modules.end(); removing++)
702 // Don't remove cmd_*.so, just remove m_*.so
703 if (removing->c_str()[0] == 'c')
705 Module* m = ServerInstance->Modules->Find(*removing);
706 if (m && ServerInstance->Modules->Unload(m))
708 ServerInstance->SNO->WriteGlobalSno('a', "*** REHASH UNLOADED MODULE: %s",removing->c_str());
711 user->WriteNumeric(RPL_UNLOADEDMODULE, "%s %s :Module %s successfully unloaded.",user->nick.c_str(), removing->c_str(), removing->c_str());
713 ServerInstance->SNO->WriteGlobalSno('a', "Module %s successfully unloaded.", removing->c_str());
718 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());
720 ServerInstance->SNO->WriteGlobalSno('a', "Failed to unload module %s: %s", removing->c_str(), ServerInstance->Modules->LastError().c_str());
724 for (std::vector<std::string>::iterator adding = added_modules.begin(); adding != added_modules.end(); adding++)
726 if (ServerInstance->Modules->Load(adding->c_str()))
728 ServerInstance->SNO->WriteGlobalSno('a', "*** REHASH LOADED MODULE: %s",adding->c_str());
730 user->WriteNumeric(RPL_LOADEDMODULE, "%s %s :Module %s successfully loaded.",user->nick.c_str(), adding->c_str(), adding->c_str());
732 ServerInstance->SNO->WriteGlobalSno('a', "Module %s successfully loaded.", adding->c_str());
737 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());
739 ServerInstance->SNO->WriteGlobalSno('a', "Failed to load module %s: %s", adding->c_str(), ServerInstance->Modules->LastError().c_str());
744 bool ServerConfig::StartsWithWindowsDriveLetter(const std::string &path)
746 return (path.length() > 2 && isalpha(path[0]) && path[1] == ':');
749 ConfigTag* ServerConfig::ConfValue(const std::string &tag)
751 ConfigTagList found = config_data.equal_range(tag);
752 if (found.first == found.second)
754 ConfigTag* rv = found.first->second;
756 if (found.first != found.second)
757 ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "Multiple <" + tag + "> tags found; only first will be used "
758 "(first at " + rv->getTagLocation() + "; second at " + found.first->second->getTagLocation() + ")");
762 ConfigTagList ServerConfig::ConfTags(const std::string& tag)
764 return config_data.equal_range(tag);
767 bool ServerConfig::FileExists(const char* file)
770 if (stat(file, &sb) == -1)
773 if ((sb.st_mode & S_IFDIR) > 0)
776 return !access(file, F_OK);
779 std::string ServerConfig::Escape(const std::string& str, bool xml)
782 for (std::string::const_iterator it = str.begin(); it != str.end(); ++it)
787 escaped += xml ? """ : "\"";
790 escaped += xml ? "&" : "&";
793 escaped += xml ? "\\" : "\\\\";
803 const char* ServerConfig::CleanFilename(const char* name)
805 const char* p = name + strlen(name);
806 while ((p != name) && (*p != '/') && (*p != '\\')) p--;
807 return (p != name ? ++p : p);
810 void ConfigReaderThread::Run()
816 void ConfigReaderThread::Finish()
818 ServerConfig* old = ServerInstance->Config;
819 ServerInstance->Logs->Log("CONFIG", LOG_DEBUG, "Switching to new configuration...");
820 ServerInstance->Config = this->Config;
821 Config->Apply(old, TheUserUID);
826 * Apply the changed configuration from the rehash.
828 * XXX: The order of these is IMPORTANT, do not reorder them without testing
831 ServerInstance->XLines->CheckELines();
832 ServerInstance->XLines->ApplyLines();
833 ModeReference ban(NULL, "ban");
834 static_cast<ListModeBase*>(*ban)->DoRehash();
835 Config->ApplyDisabledCommands(Config->DisabledCommands);
836 User* user = ServerInstance->FindNick(TheUserUID);
837 FOREACH_MOD(I_OnRehash, OnRehash(user));
838 ServerInstance->ISupport.Build();
840 ServerInstance->Logs->CloseLogs();
841 ServerInstance->Logs->OpenFileLogs();
843 if (Config->RawLog && !old->RawLog)
844 ServerInstance->Users->ServerNoticeAll("*** Raw I/O logging is enabled on this server. All messages, passwords, and commands are being recorded.");
851 ServerInstance->Config = old;