1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
15 /* $CopyInstall: conf/inspircd.quotes.example $(CONPATH) */
16 /* $CopyInstall: conf/inspircd.rules.example $(CONPATH) */
17 /* $CopyInstall: conf/inspircd.motd.example $(CONPATH) */
18 /* $CopyInstall: conf/inspircd.helpop-full.example $(CONPATH) */
19 /* $CopyInstall: conf/inspircd.helpop.example $(CONPATH) */
20 /* $CopyInstall: conf/inspircd.censor.example $(CONPATH) */
21 /* $CopyInstall: conf/inspircd.filter.example $(CONPATH) */
22 /* $CopyInstall: conf/inspircd.conf.example $(CONPATH) */
23 /* $CopyInstall: conf/modules.conf.example $(CONPATH) */
24 /* $CopyInstall: conf/opers.conf.example $(CONPATH) */
25 /* $CopyInstall: conf/links.conf.example $(CONPATH) */
26 /* $CopyInstall: tools/gdbargs $(BASE)/.gdbargs */
31 #include "exitcodes.h"
32 #include "commands/cmd_whowas.h"
33 #include "configparser.h"
35 ServerConfig::ServerConfig()
37 WhoWasGroupSize = WhoWasMaxGroups = WhoWasMaxKeep = 0;
38 NoUserDns = OperSpyWhois = HideBans = HideSplits = UndernetMsgPrefix = false;
39 CycleHosts = InvBypassModes = true;
42 NetBufferSize = 10240;
43 SoftLimit = ServerInstance->SE->GetMaxFds();
52 void ServerConfig::Update005()
54 std::stringstream out(data005);
57 int token_counter = 0;
61 line5 = line5 + token + " ";
63 if (token_counter >= 13)
66 snprintf(buf, MAXBUF, "%s:are supported by this server", line5.c_str());
67 isupport.push_back(buf);
75 snprintf(buf, MAXBUF, "%s:are supported by this server", line5.c_str());
76 isupport.push_back(buf);
80 void ServerConfig::Send005(User* user)
82 for (std::vector<std::string>::iterator line = ServerInstance->Config->isupport.begin(); line != ServerInstance->Config->isupport.end(); line++)
83 user->WriteNumeric(RPL_ISUPPORT, "%s %s", user->nick.c_str(), line->c_str());
86 template<typename T, typename V>
87 static void range(T& value, V min, V max, V def, const char* msg)
89 if (value >= (T)min && value <= (T)max)
91 ServerInstance->Logs->Log("CONFIG", DEFAULT,
92 "WARNING: %s value of %ld is not between %ld and %ld; set to %ld.",
93 msg, (long)value, (long)min, (long)max, (long)def);
98 static void ValidIP(const std::string& ip, const std::string& key)
100 irc::sockets::sockaddrs dummy;
101 if (!irc::sockets::aptosa(ip, 0, dummy))
102 throw CoreException("The value of "+key+" is not an IP address");
105 static void ValidHost(const std::string& p, const std::string& msg)
108 if (p.empty() || p[0] == '.')
109 throw CoreException("The value of "+msg+" is not a valid hostname");
110 for (unsigned int i=0;i < p.length();i++)
115 throw CoreException("The value of "+msg+" is not a valid hostname");
122 throw CoreException("The value of "+msg+" is not a valid hostname");
125 bool ServerConfig::ApplyDisabledCommands(const std::string& data)
127 std::stringstream dcmds(data);
130 /* Enable everything first */
131 for (Commandtable::iterator x = ServerInstance->Parser->cmdlist.begin(); x != ServerInstance->Parser->cmdlist.end(); x++)
132 x->second->Disable(false);
134 /* Now disable all the ones which the user wants disabled */
135 while (dcmds >> thiscmd)
137 Commandtable::iterator cm = ServerInstance->Parser->cmdlist.find(thiscmd);
138 if (cm != ServerInstance->Parser->cmdlist.end())
140 cm->second->Disable(true);
147 // Note: the windows validator is in win32wrapper.cpp
148 void FindDNS(std::string& server);
150 static void FindDNS(std::string& server)
155 // attempt to look up their nameserver from /etc/resolv.conf
156 ServerInstance->Logs->Log("CONFIG",DEFAULT,"WARNING: <dns:server> not defined, attempting to find working server in /etc/resolv.conf...");
158 std::ifstream resolv("/etc/resolv.conf");
160 while (resolv >> server)
162 if (server == "nameserver")
165 ServerInstance->Logs->Log("CONFIG",DEFAULT,"<dns:server> set to '%s' as first resolver in /etc/resolv.conf.",server.c_str());
170 ServerInstance->Logs->Log("CONFIG",DEFAULT,"/etc/resolv.conf contains no viable nameserver entries! Defaulting to nameserver '127.0.0.1'!");
171 server = "127.0.0.1";
175 static void ReadXLine(ServerConfig* conf, const std::string& tag, const std::string& key, XLineFactory* make)
177 ConfigTagList tags = conf->ConfTags(tag);
178 for(ConfigIter i = tags.first; i != tags.second; ++i)
180 ConfigTag* ctag = i->second;
182 if (!ctag->readString(key, mask))
183 throw CoreException("<"+tag+":"+key+"> missing at " + ctag->getTagLocation());
184 std::string reason = ctag->getString("reason", "<Config>");
185 XLine* xl = make->Generate(ServerInstance->Time(), 0, "<Config>", reason, mask);
186 if (!ServerInstance->XLines->AddLine(xl, NULL))
191 typedef std::map<std::string, ConfigTag*> LocalIndex;
192 void ServerConfig::CrossCheckOperClassType()
194 LocalIndex operclass;
195 ConfigTagList tags = ConfTags("class");
196 for(ConfigIter i = tags.first; i != tags.second; ++i)
198 ConfigTag* tag = i->second;
199 std::string name = tag->getString("name");
201 throw CoreException("<class:name> missing from tag at " + tag->getTagLocation());
202 operclass[name] = tag;
204 tags = ConfTags("type");
205 for(ConfigIter i = tags.first; i != tags.second; ++i)
207 ConfigTag* tag = i->second;
208 std::string name = tag->getString("name");
210 throw CoreException("<type:name> is missing from tag at " + tag->getTagLocation());
212 if (!ServerInstance->IsNick(name.c_str(), Limits.NickMax))
213 throw CoreException("<type:name> is invalid (value '" + name + "')");
215 OperInfo* ifo = new OperInfo;
216 oper_blocks[" " + name] = ifo;
218 ifo->type_block = tag;
220 std::string classname;
221 irc::spacesepstream str(tag->getString("classes"));
222 while (str.GetToken(classname))
224 LocalIndex::iterator cls = operclass.find(classname);
225 if (cls == operclass.end())
226 throw CoreException("Oper type " + name + " has missing class " + classname);
227 ifo->class_blocks.push_back(cls->second);
231 tags = ConfTags("oper");
232 for(ConfigIter i = tags.first; i != tags.second; ++i)
234 ConfigTag* tag = i->second;
236 std::string name = tag->getString("name");
238 throw CoreException("<oper:name> missing from tag at " + tag->getTagLocation());
240 std::string type = tag->getString("type");
241 OperIndex::iterator tblk = oper_blocks.find(" " + type);
242 if (tblk == oper_blocks.end())
243 throw CoreException("Oper block " + name + " has missing type " + type);
244 if (oper_blocks.find(name) != oper_blocks.end())
245 throw CoreException("Duplicate oper block with name " + name);
247 OperInfo* ifo = new OperInfo;
249 ifo->oper_block = tag;
250 ifo->type_block = tblk->second->type_block;
251 ifo->class_blocks.assign(tblk->second->class_blocks.begin(), tblk->second->class_blocks.end());
252 oper_blocks[name] = ifo;
256 void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current)
258 typedef std::map<std::string, ConnectClass*> ClassMap;
259 ClassMap oldBlocksByMask;
262 for(ClassVector::iterator i = current->Classes.begin(); i != current->Classes.end(); ++i)
264 ConnectClass* c = *i;
265 std::string typeMask = (c->type == CC_ALLOW) ? "a" : "d";
267 oldBlocksByMask[typeMask] = c;
271 int blk_count = config_data.count("connect");
274 // No connect blocks found; make a trivial default block
275 std::vector<KeyVal>* items;
276 ConfigTag* tag = ConfigTag::create("connect", "<auto>", 0, items);
277 items->push_back(std::make_pair("allow", "*"));
278 config_data.insert(std::make_pair("connect", tag));
282 ClassMap newBlocksByMask;
283 Classes.resize(blk_count);
284 std::map<std::string, int> names;
286 bool try_again = true;
287 for(int tries=0; try_again; tries++)
290 ConfigTagList tags = ConfTags("connect");
292 for(ConfigIter it = tags.first; it != tags.second; ++it, ++i)
294 ConfigTag* tag = it->second;
298 ConnectClass* parent = NULL;
299 std::string parentName = tag->getString("parent");
300 if (!parentName.empty())
302 std::map<std::string,int>::iterator parentIter = names.find(parentName);
303 if (parentIter == names.end())
306 // couldn't find parent this time. If it's the last time, we'll never find it.
307 if (tries >= blk_count)
308 throw CoreException("Could not find parent connect class \"" + parentName + "\" for connect block " + ConvToStr(i));
311 parent = Classes[parentIter->second];
314 std::string name = tag->getString("name");
317 name = "unnamed-" + ConvToStr(i);
320 if (names.find(name) != names.end())
321 throw CoreException("Two connect classes with name \"" + name + "\" defined!");
324 std::string mask, typeMask;
327 if (tag->readString("allow", mask, false))
330 typeMask = 'a' + mask;
332 else if (tag->readString("deny", mask, false))
335 typeMask = 'd' + mask;
339 throw CoreException("Connect class must have an allow or deny mask at " + tag->getTagLocation());
341 ClassMap::iterator dupMask = newBlocksByMask.find(typeMask);
342 if (dupMask != newBlocksByMask.end())
343 throw CoreException("Two connect classes cannot have the same mask (" + mask + ")");
345 ConnectClass* me = parent ?
346 new ConnectClass(tag, type, mask, *parent) :
347 new ConnectClass(tag, type, mask);
351 tag->readString("password", me->pass);
352 tag->readString("hash", me->hash);
353 me->registration_timeout = tag->getInt("timeout", me->registration_timeout);
354 me->pingtime = tag->getInt("pingfreq", me->pingtime);
356 if (tag->readString("sendq", sendq))
358 // attempt to guess a good hard/soft sendq from a single value
359 long value = atol(sendq.c_str());
361 me->softsendqmax = value / 16;
363 me->softsendqmax = value;
364 me->hardsendqmax = value * 8;
366 me->softsendqmax = tag->getInt("softsendq", me->softsendqmax);
367 me->hardsendqmax = tag->getInt("hardsendq", me->hardsendqmax);
368 me->recvqmax = tag->getInt("recvq", me->recvqmax);
369 me->penaltythreshold = tag->getInt("threshold", me->penaltythreshold);
370 me->commandrate = tag->getInt("commandrate", me->commandrate);
371 me->fakelag = tag->getBool("fakelag", me->fakelag);
372 me->maxlocal = tag->getInt("localmax", me->maxlocal);
373 me->maxglobal = tag->getInt("globalmax", me->maxglobal);
374 me->port = tag->getInt("port", me->port);
375 me->maxchans = tag->getInt("maxchans", me->maxchans);
376 me->limit = tag->getInt("limit", me->limit);
378 ClassMap::iterator oldMask = oldBlocksByMask.find(typeMask);
379 if (oldMask != oldBlocksByMask.end())
381 ConnectClass* old = oldMask->second;
382 oldBlocksByMask.erase(oldMask);
387 newBlocksByMask[typeMask] = me;
393 /** Represents a deprecated configuration tag.
403 /** Reason for deprecation
408 static const Deprecated ChangedConfig[] = {
409 {"options", "hidelinks", "has been moved to <security:hidelinks> as of 1.2a3"},
410 {"options", "hidewhois", "has been moved to <security:hidewhois> as of 1.2a3"},
411 {"options", "userstats", "has been moved to <security:userstats> as of 1.2a3"},
412 {"options", "customversion", "has been moved to <security:customversion> as of 1.2a3"},
413 {"options", "hidesplits", "has been moved to <security:hidesplits> as of 1.2a3"},
414 {"options", "hidebans", "has been moved to <security:hidebans> as of 1.2a3"},
415 {"options", "hidekills", "has been moved to <security:hidekills> as of 1.2a3"},
416 {"options", "operspywhois", "has been moved to <security:operspywhois> as of 1.2a3"},
417 {"options", "announceinvites", "has been moved to <security:announceinvites> as of 1.2a3"},
418 {"options", "hidemodes", "has been moved to <security:hidemodes> as of 1.2a3"},
419 {"options", "maxtargets", "has been moved to <security:maxtargets> as of 1.2a3"},
420 {"options", "nouserdns", "has been moved to <performance:nouserdns> as of 1.2a3"},
421 {"options", "maxwho", "has been moved to <performance:maxwho> as of 1.2a3"},
422 {"options", "softlimit", "has been moved to <performance:softlimit> as of 1.2a3"},
423 {"options", "somaxconn", "has been moved to <performance:somaxconn> as of 1.2a3"},
424 {"options", "netbuffersize", "has been moved to <performance:netbuffersize> as of 1.2a3"},
425 {"options", "maxwho", "has been moved to <performance:maxwho> as of 1.2a3"},
426 {"options", "loglevel", "1.2 does not use the loglevel value. Please define <log> tags instead."},
427 {"die", "value", "you need to reread your config"},
430 void ServerConfig::Fill()
432 ConfigTag* options = ConfValue("options");
433 ConfigTag* security = ConfValue("security");
434 diepass = ConfValue("power")->getString("diepass");
435 restartpass = ConfValue("power")->getString("restartpass");
436 powerhash = ConfValue("power")->getString("hash");
437 PrefixQuit = options->getString("prefixquit");
438 SuffixQuit = options->getString("suffixquit");
439 FixedQuit = options->getString("fixedquit");
440 PrefixPart = options->getString("prefixpart");
441 SuffixPart = options->getString("suffixpart");
442 FixedPart = options->getString("fixedpart");
443 SoftLimit = ConfValue("performance")->getInt("softlimit", ServerInstance->SE->GetMaxFds());
444 MaxConn = ConfValue("performance")->getInt("somaxconn", SOMAXCONN);
445 MoronBanner = options->getString("moronbanner", "You're banned!");
446 ServerName = ConfValue("server")->getString("name");
447 ServerDesc = ConfValue("server")->getString("description", "Configure Me");
448 Network = ConfValue("server")->getString("network", "Network");
449 sid = ConfValue("server")->getString("id", "");
450 AdminName = ConfValue("admin")->getString("name", "");
451 AdminEmail = ConfValue("admin")->getString("email", "null@example.com");
452 AdminNick = ConfValue("admin")->getString("nick", "admin");
453 ModPath = ConfValue("path")->getString("moduledir", MOD_PATH);
454 NetBufferSize = ConfValue("performance")->getInt("netbuffersize", 10240);
455 MaxWhoResults = ConfValue("performance")->getInt("maxwho", 1024);
456 dns_timeout = ConfValue("dns")->getInt("timeout", 5);
457 DisabledCommands = ConfValue("disabled")->getString("commands", "");
458 DisabledDontExist = ConfValue("disabled")->getBool("fakenonexistant");
459 UserStats = security->getString("userstats");
460 CustomVersion = security->getString("customversion");
461 HideSplits = security->getBool("hidesplits");
462 HideBans = security->getBool("hidebans");
463 HideWhoisServer = security->getString("hidewhois");
464 HideKillsServer = security->getString("hidekills");
465 OperSpyWhois = security->getBool("operspywhois");
466 RestrictBannedUsers = security->getBool("restrictbannedusers", true);
467 GenericOper = security->getBool("genericoper");
468 NoUserDns = ConfValue("performance")->getBool("nouserdns");
469 SyntaxHints = options->getBool("syntaxhints");
470 CycleHosts = options->getBool("cyclehosts");
471 UndernetMsgPrefix = options->getBool("ircumsgprefix");
472 FullHostInTopic = options->getBool("hostintopic");
473 MaxTargets = security->getInt("maxtargets", 20);
474 DefaultModes = options->getString("defaultmodes", "nt");
475 PID = ConfValue("pid")->getString("file");
476 WhoWasGroupSize = ConfValue("whowas")->getInt("groupsize");
477 WhoWasMaxGroups = ConfValue("whowas")->getInt("maxgroups");
478 WhoWasMaxKeep = ServerInstance->Duration(ConfValue("whowas")->getString("maxkeep"));
479 DieValue = ConfValue("die")->getString("value");
480 MaxChans = ConfValue("channels")->getInt("users", 20);
481 OperMaxChans = ConfValue("channels")->getInt("opers", 60);
482 c_ipv4_range = ConfValue("cidr")->getInt("ipv4clone", 32);
483 c_ipv6_range = ConfValue("cidr")->getInt("ipv6clone", 128);
484 Limits.NickMax = ConfValue("limits")->getInt("maxnick", 32);
485 Limits.ChanMax = ConfValue("limits")->getInt("maxchan", 64);
486 Limits.MaxModes = ConfValue("limits")->getInt("maxmodes", 20);
487 Limits.IdentMax = ConfValue("limits")->getInt("maxident", 11);
488 Limits.MaxQuit = ConfValue("limits")->getInt("maxquit", 255);
489 Limits.MaxTopic = ConfValue("limits")->getInt("maxtopic", 307);
490 Limits.MaxKick = ConfValue("limits")->getInt("maxkick", 255);
491 Limits.MaxGecos = ConfValue("limits")->getInt("maxgecos", 128);
492 Limits.MaxAway = ConfValue("limits")->getInt("maxaway", 200);
493 InvBypassModes = options->getBool("invitebypassmodes", true);
495 range(SoftLimit, 10, ServerInstance->SE->GetMaxFds(), ServerInstance->SE->GetMaxFds(), "<performance:softlimit>");
496 range(MaxConn, 0, SOMAXCONN, SOMAXCONN, "<performance:somaxconn>");
497 range(MaxTargets, 1, 31, 20, "<security:maxtargets>");
498 range(NetBufferSize, 1024, 65534, 10240, "<performance:netbuffersize>");
499 range(MaxWhoResults, 1, 65535, 1024, "<performace:maxwho>");
500 range(WhoWasGroupSize, 0, 10000, 10, "<whowas:groupsize>");
501 range(WhoWasMaxGroups, 0, 1000000, 10240, "<whowas:maxgroups>");
502 range(WhoWasMaxKeep, 3600, INT_MAX, 3600, "<whowas:maxkeep>");
504 ValidIP(DNSServer, "<dns:server>");
505 ValidHost(ServerName, "<server:name>");
506 if (!sid.empty() && !ServerInstance->IsSID(sid))
507 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.");
509 ConfigTagList tags = ConfTags("uline");
510 for(ConfigIter i = tags.first; i != tags.second; ++i)
512 ConfigTag* tag = i->second;
514 if (!tag->readString("server", server))
515 throw CoreException("<uline> tag missing server at " + tag->getTagLocation());
516 ulines[assign(server)] = tag->getBool("silent");
519 tags = ConfTags("banlist");
520 for(ConfigIter i = tags.first; i != tags.second; ++i)
522 ConfigTag* tag = i->second;
524 if (!tag->readString("chan", chan))
525 throw CoreException("<banlist> tag missing chan at " + tag->getTagLocation());
526 maxbans[chan] = tag->getInt("limit");
529 ReadXLine(this, "badip", "ipmask", ServerInstance->XLines->GetFactory("Z"));
530 ReadXLine(this, "badnick", "nick", ServerInstance->XLines->GetFactory("Q"));
531 ReadXLine(this, "badhost", "host", ServerInstance->XLines->GetFactory("K"));
532 ReadXLine(this, "exception", "host", ServerInstance->XLines->GetFactory("E"));
534 memset(DisabledUModes, 0, sizeof(DisabledUModes));
535 for (const unsigned char* p = (const unsigned char*)ConfValue("disabled")->getString("usermodes").c_str(); *p; ++p)
537 if (*p < 'A' || *p > ('A' + 64)) throw CoreException(std::string("Invalid usermode ")+(char)*p+" was found.");
538 DisabledUModes[*p - 'A'] = 1;
541 memset(DisabledCModes, 0, sizeof(DisabledCModes));
542 for (const unsigned char* p = (const unsigned char*)ConfValue("disabled")->getString("chanmodes").c_str(); *p; ++p)
544 if (*p < 'A' || *p > ('A' + 64)) throw CoreException(std::string("Invalid chanmode ")+(char)*p+" was found.");
545 DisabledCModes[*p - 'A'] = 1;
548 memset(HideModeLists, 0, sizeof(HideModeLists));
549 for (const unsigned char* p = (const unsigned char*)ConfValue("security")->getString("hidemodes").c_str(); *p; ++p)
550 HideModeLists[*p] = true;
552 std::string v = security->getString("announceinvites");
555 AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_OPS;
557 AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_ALL;
558 else if (v == "dynamic")
559 AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_DYNAMIC;
561 AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_NONE;
566 // WARNING: it is not safe to use most of the codebase in this function, as it
567 // will run in the config reader thread
568 void ServerConfig::Read()
570 /* Load and parse the config file, if there are any errors then explode */
572 ParseStack stack(this);
575 valid = stack.ParseFile(ServerInstance->ConfigFileName, 0);
577 catch (CoreException& err)
580 errstr << err.GetReason();
584 ReadFile(MOTD, ConfValue("files")->getString("motd"));
585 ReadFile(RULES, ConfValue("files")->getString("rules"));
586 DNSServer = ConfValue("dns")->getString("server");
591 void ServerConfig::Apply(ServerConfig* old, const std::string &useruid)
595 /* The stuff in here may throw CoreException, be sure we're in a position to catch it. */
598 for (int Index = 0; Index * sizeof(Deprecated) < sizeof(ChangedConfig); Index++)
601 if (ConfValue(ChangedConfig[Index].tag)->readString(ChangedConfig[Index].value, dummy, true))
602 errstr << "Your configuration contains a deprecated value: <"
603 << ChangedConfig[Index].tag << ":" << ChangedConfig[Index].value << "> - " << ChangedConfig[Index].reason
604 << " (at " << ConfValue(ChangedConfig[Index].tag)->getTagLocation() << ")\n";
609 // Handle special items
610 CrossCheckOperClassType();
611 CrossCheckConnectBlocks(old);
613 catch (CoreException &ce)
615 errstr << ce.GetReason();
618 // write once here, to try it out and make sure its ok
619 ServerInstance->WritePID(this->PID);
621 // Check errors before dealing with failed binds, since continuing on failed bind is wanted in some circumstances.
622 valid = errstr.str().empty();
625 * These values can only be set on boot. Keep their old values. Do it before we send messages so we actually have a servername.
629 this->ServerName = old->ServerName;
630 this->sid = old->sid;
631 this->cmdline = old->cmdline;
633 // Same for ports... they're bound later on first run.
635 ServerInstance->BindPorts(pl);
638 errstr << "Not all your client ports could be bound.\nThe following port(s) failed to bind:\n";
641 for (FailedPortList::iterator i = pl.begin(); i != pl.end(); i++, j++)
644 snprintf(buf, MAXBUF, "%d. Address: %s Reason: %s\n", j, i->first.empty() ? "<all>" : i->first.c_str(), i->second.c_str());
650 User* user = useruid.empty() ? NULL : ServerInstance->FindNick(useruid);
653 ServerInstance->Logs->Log("CONFIG",DEFAULT, "There were errors in your configuration file:");
655 while (errstr.good())
658 getline(errstr, line, '\n');
662 user->WriteServ("NOTICE %s :*** %s", user->nick.c_str(), line.c_str());
664 ServerInstance->SNO->WriteGlobalSno('a', line);
669 // Starting up, so print it out so it's seen. XXX this is a bit of a hack.
670 printf("%s\n", line.c_str());
675 errstr.str(std::string());
677 /* No old configuration -> initial boot, nothing more to do here */
682 ServerInstance->Exit(EXIT_STATUS_CONFIG);
688 // If there were errors processing configuration, don't touch modules.
695 user->WriteServ("NOTICE %s :*** Successfully rehashed server.", user->nick.c_str());
696 ServerInstance->SNO->WriteGlobalSno('a', "*** Successfully rehashed server.");
699 void ServerConfig::ApplyModules(User* user)
701 Module* whowas = ServerInstance->Modules->Find("cmd_whowas.so");
703 WhowasRequest(NULL, whowas, WhowasRequest::WHOWAS_PRUNE).Send();
705 const std::vector<std::string> v = ServerInstance->Modules->GetAllModuleNames(0);
706 std::vector<std::string> added_modules;
707 std::set<std::string> removed_modules(v.begin(), v.end());
709 ConfigTagList tags = ConfTags("module");
710 for(ConfigIter i = tags.first; i != tags.second; ++i)
712 ConfigTag* tag = i->second;
714 if (tag->readString("name", name))
716 // if this module is already loaded, the erase will succeed, so we need do nothing
717 // otherwise, we need to add the module (which will be done later)
718 if (removed_modules.erase(name) == 0)
719 added_modules.push_back(name);
723 if (ConfValue("options")->getBool("allowhalfop") && removed_modules.erase("m_halfop.so") == 0)
724 added_modules.push_back("m_halfop.so");
726 for (std::set<std::string>::iterator removing = removed_modules.begin(); removing != removed_modules.end(); removing++)
728 // Don't remove cmd_*.so, just remove m_*.so
729 if (removing->c_str()[0] == 'c')
731 Module* m = ServerInstance->Modules->Find(*removing);
732 if (m && ServerInstance->Modules->Unload(m))
734 ServerInstance->SNO->WriteGlobalSno('a', "*** REHASH UNLOADED MODULE: %s",removing->c_str());
737 user->WriteNumeric(RPL_UNLOADEDMODULE, "%s %s :Module %s successfully unloaded.",user->nick.c_str(), removing->c_str(), removing->c_str());
739 ServerInstance->SNO->WriteGlobalSno('a', "Module %s successfully unloaded.", removing->c_str());
744 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());
746 ServerInstance->SNO->WriteGlobalSno('a', "Failed to unload module %s: %s", removing->c_str(), ServerInstance->Modules->LastError().c_str());
750 for (std::vector<std::string>::iterator adding = added_modules.begin(); adding != added_modules.end(); adding++)
752 if (ServerInstance->Modules->Load(adding->c_str()))
754 ServerInstance->SNO->WriteGlobalSno('a', "*** REHASH LOADED MODULE: %s",adding->c_str());
756 user->WriteNumeric(RPL_LOADEDMODULE, "%s %s :Module %s successfully loaded.",user->nick.c_str(), adding->c_str(), adding->c_str());
758 ServerInstance->SNO->WriteGlobalSno('a', "Module %s successfully loaded.", adding->c_str());
763 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());
765 ServerInstance->SNO->WriteGlobalSno('a', "Failed to load module %s: %s", adding->c_str(), ServerInstance->Modules->LastError().c_str());
770 bool ServerConfig::StartsWithWindowsDriveLetter(const std::string &path)
772 return (path.length() > 2 && isalpha(path[0]) && path[1] == ':');
775 ConfigTag* ServerConfig::ConfValue(const std::string &tag)
777 ConfigDataHash::iterator iter = config_data.find(tag);
778 if (iter == config_data.end())
783 ConfigTagList ServerConfig::ConfTags(const std::string& tag)
785 return config_data.equal_range(tag);
788 /** Read the contents of a file located by `fname' into a file_cache pointed at by `F'.
790 bool ServerConfig::ReadFile(file_cache &F, const std::string& fname)
795 char linebuf[MAXBUF];
799 FileWrapper file(fopen(fname.c_str(), "r"));
805 if (fgets(linebuf, sizeof(linebuf), file))
806 linebuf[strlen(linebuf)-1] = 0;
810 F.push_back(*linebuf ? linebuf : " ");
816 bool ServerConfig::FileExists(const char* file)
819 if (stat(file, &sb) == -1)
822 if ((sb.st_mode & S_IFDIR) > 0)
825 FILE *input = fopen(file, "r");
835 const char* ServerConfig::CleanFilename(const char* name)
837 const char* p = name + strlen(name);
838 while ((p != name) && (*p != '/') && (*p != '\\')) p--;
839 return (p != name ? ++p : p);
842 std::string ServerConfig::GetSID()
847 void ConfigReaderThread::Run()
853 void ConfigReaderThread::Finish()
855 ServerConfig* old = ServerInstance->Config;
856 ServerInstance->Logs->Log("CONFIG",DEBUG,"Switching to new configuration...");
857 ServerInstance->Logs->CloseLogs();
858 ServerInstance->Config = this->Config;
859 ServerInstance->Logs->OpenFileLogs();
860 Config->Apply(old, TheUserUID);
865 * Apply the changed configuration from the rehash.
867 * XXX: The order of these is IMPORTANT, do not reorder them without testing
870 ServerInstance->XLines->CheckELines();
871 ServerInstance->XLines->CheckELines();
872 ServerInstance->XLines->ApplyLines();
873 ServerInstance->Res->Rehash();
874 ServerInstance->ResetMaxBans();
875 Config->ApplyDisabledCommands(Config->DisabledCommands);
876 User* user = ServerInstance->FindNick(TheUserUID);
877 FOREACH_MOD(I_OnRehash, OnRehash(user));
878 ServerInstance->BuildISupport();
885 ServerInstance->Logs->CloseLogs();
886 ServerInstance->Config = old;
887 ServerInstance->Logs->OpenFileLogs();