1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/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) */
28 #include "exitcodes.h"
29 #include "commands/cmd_whowas.h"
31 std::vector<std::string> old_module_names, new_module_names, added_modules, removed_modules;
33 /* Needs forward declaration */
34 bool ValidateDnsServer(ServerConfig* conf, const char* tag, const char* value, ValueItem &data);
35 bool DoneELine(ServerConfig* conf, const char* tag);
37 ServerConfig::ServerConfig(InspIRCd* Instance) : ServerInstance(Instance)
40 *sid = *ServerName = *Network = *ServerDesc = *AdminName = '\0';
41 *HideWhoisServer = *AdminEmail = *AdminNick = *diepass = *restartpass = *FixedQuit = *HideKillsServer = '\0';
42 *DefaultModes = *CustomVersion = *motd = *rules = *PrefixQuit = *DieValue = *DNSServer = '\0';
43 *UserStats = *ModPath = *MyExecutable = *DisabledCommands = *PID = *SuffixQuit = '\0';
44 WhoWasGroupSize = WhoWasMaxGroups = WhoWasMaxKeep = 0;
46 NoUserDns = forcedebug = OperSpyWhois = nofork = HideBans = HideSplits = UndernetMsgPrefix = false;
47 CycleHosts = writelog = AllowHalfop = InvBypassModes = true;
48 dns_timeout = DieDelay = 5;
50 NetBufferSize = 10240;
51 SoftLimit = Instance->SE->GetMaxFds();
60 DNSServerValidator = &ValidateDnsServer;
63 void ServerConfig::ClearStack()
65 include_stack.clear();
68 Module* ServerConfig::GetIOHook(BufferedSocket* is)
70 std::map<BufferedSocket*,Module*>::iterator x = SocketIOHookModule.find(is);
71 return (x != SocketIOHookModule.end() ? x->second : NULL);
74 bool ServerConfig::AddIOHook(Module* iomod, BufferedSocket* is)
78 SocketIOHookModule[is] = iomod;
79 is->IsIOHooked = true;
84 throw ModuleException("BufferedSocket derived class already hooked by another module");
88 bool ServerConfig::DelIOHook(BufferedSocket* is)
90 std::map<BufferedSocket*,Module*>::iterator x = SocketIOHookModule.find(is);
91 if (x != SocketIOHookModule.end())
93 SocketIOHookModule.erase(x);
99 void ServerConfig::Update005()
101 std::stringstream out(data005);
104 int token_counter = 0;
108 line5 = line5 + token + " ";
110 if (token_counter >= 13)
113 snprintf(buf, MAXBUF, "%s:are supported by this server", line5.c_str());
114 isupport.push_back(buf);
122 snprintf(buf, MAXBUF, "%s:are supported by this server", line5.c_str());
123 isupport.push_back(buf);
127 void ServerConfig::Send005(User* user)
129 for (std::vector<std::string>::iterator line = ServerInstance->Config->isupport.begin(); line != ServerInstance->Config->isupport.end(); line++)
130 user->WriteNumeric(RPL_ISUPPORT, "%s %s", user->nick.c_str(), line->c_str());
133 bool ServerConfig::CheckOnce(const char* tag, ConfigDataHash &newconf)
135 int count = ConfValueEnum(newconf, tag);
138 throw CoreException("You have more than one <"+std::string(tag)+"> tag, this is not permitted.");
140 throw CoreException("You have not defined a <"+std::string(tag)+"> tag, this is required.");
144 bool NoValidation(ServerConfig*, const char*, const char*, ValueItem&)
149 bool DoneConfItem(ServerConfig* conf, const char* tag)
154 void ServerConfig::ValidateNoSpaces(const char* p, const std::string &tag, const std::string &val)
156 for (const char* ptr = p; *ptr; ++ptr)
159 throw CoreException("The value of <"+tag+":"+val+"> cannot contain spaces");
163 /* NOTE: Before anyone asks why we're not using inet_pton for this, it is because inet_pton and friends do not return so much detail,
164 * even in strerror(errno). They just return 'yes' or 'no' to an address without such detail as to whats WRONG with the address.
165 * Because ircd users arent as technical as they used to be (;)) we are going to give more of a useful error message.
167 void ServerConfig::ValidateIP(const char* p, const std::string &tag, const std::string &val, bool wild)
171 int not_numbers = false;
177 throw CoreException("The value of <"+tag+":"+val+"> is not an IP address");
179 for (const char* ptr = p; *ptr; ++ptr)
181 if (wild && (*ptr == '*' || *ptr == '?' || *ptr == '/'))
184 if (*ptr != ':' && *ptr != '.')
186 if (*ptr < '0' || *ptr > '9')
188 if ((*ptr < '0' || *ptr > '9') && (toupper(*ptr) < 'A' || toupper(*ptr) > 'F'))
194 throw CoreException("The value of <"+tag+":"+val+"> is not an IP address");
205 throw CoreException("The value of <"+tag+":"+val+"> is an IPv4 address with too many fields!");
208 throw CoreException("The value of <"+tag+":"+val+"> is an IPv6 address with too many fields!");
210 if (num_seps == 0 && num_dots < 3 && !wild)
211 throw CoreException("The value of <"+tag+":"+val+"> looks to be a malformed IPv4 address");
213 if (num_seps == 0 && num_dots == 3 && not_numbers)
214 throw CoreException("The value of <"+tag+":"+val+"> contains non-numeric characters in an IPv4 address");
216 if (num_seps != 0 && not_hex)
217 throw CoreException("The value of <"+tag+":"+val+"> contains non-hexdecimal characters in an IPv6 address");
219 if (num_seps != 0 && num_dots != 3 && num_dots != 0 && !wild)
220 throw CoreException("The value of <"+tag+":"+val+"> is a malformed IPv6 4in6 address");
224 void ServerConfig::ValidateHostname(const char* p, const std::string &tag, const std::string &val)
230 throw CoreException("The value of <"+tag+":"+val+"> is not a valid hostname");
231 for (const char* ptr = p; *ptr; ++ptr)
236 throw CoreException("The value of <"+tag+":"+val+"> is not a valid hostname");
243 throw CoreException("The value of <"+tag+":"+val+"> is not a valid hostname");
247 bool ValidateMaxTargets(ServerConfig* conf, const char*, const char*, ValueItem &data)
249 if ((data.GetInteger() < 0) || (data.GetInteger() > 31))
251 conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"WARNING: <security:maxtargets> value is greater than 31 or less than 0, set to 20.");
257 bool ValidateSoftLimit(ServerConfig* conf, const char*, const char*, ValueItem &data)
259 if ((data.GetInteger() < 1) || (data.GetInteger() > conf->GetInstance()->SE->GetMaxFds()))
261 conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"WARNING: <performance:softlimit> value is greater than %d or less than 0, set to %d.",conf->GetInstance()->SE->GetMaxFds(),conf->GetInstance()->SE->GetMaxFds());
262 data.Set(conf->GetInstance()->SE->GetMaxFds());
267 bool ValidateMaxConn(ServerConfig* conf, const char*, const char*, ValueItem &data)
269 if (data.GetInteger() > SOMAXCONN)
270 conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"WARNING: <performance:somaxconn> value may be higher than the system-defined SOMAXCONN value!");
274 bool InitializeDisabledCommands(const char* data, InspIRCd* ServerInstance)
276 std::stringstream dcmds(data);
279 /* Enable everything first */
280 for (Commandtable::iterator x = ServerInstance->Parser->cmdlist.begin(); x != ServerInstance->Parser->cmdlist.end(); x++)
281 x->second->Disable(false);
283 /* Now disable all the ones which the user wants disabled */
284 while (dcmds >> thiscmd)
286 Commandtable::iterator cm = ServerInstance->Parser->cmdlist.find(thiscmd);
287 if (cm != ServerInstance->Parser->cmdlist.end())
289 cm->second->Disable(true);
295 bool ValidateDisabledUModes(ServerConfig* conf, const char*, const char*, ValueItem &data)
297 memset(conf->DisabledUModes, 0, sizeof(conf->DisabledUModes));
298 for (const unsigned char* p = (const unsigned char*)data.GetString(); *p; ++p)
300 if (*p < 'A' || *p > ('A' + 64)) throw CoreException(std::string("Invalid usermode ")+(char)*p+" was found.");
301 conf->DisabledUModes[*p - 'A'] = 1;
306 bool ValidateDisabledCModes(ServerConfig* conf, const char*, const char*, ValueItem &data)
308 memset(conf->DisabledCModes, 0, sizeof(conf->DisabledCModes));
309 for (const unsigned char* p = (const unsigned char*)data.GetString(); *p; ++p)
311 if (*p < 'A' || *p > ('A' + 64)) throw CoreException(std::string("Invalid chanmode ")+(char)*p+" was found.");
312 conf->DisabledCModes[*p - 'A'] = 1;
317 bool ValidateDnsServer(ServerConfig* conf, const char*, const char*, ValueItem &data)
319 if (!*(data.GetString()))
321 std::string nameserver;
322 // attempt to look up their nameserver from /etc/resolv.conf
323 conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"WARNING: <dns:server> not defined, attempting to find working server in /etc/resolv.conf...");
324 std::ifstream resolv("/etc/resolv.conf");
325 bool found_server = false;
327 if (resolv.is_open())
329 while (resolv >> nameserver)
331 if ((nameserver == "nameserver") && (!found_server))
333 resolv >> nameserver;
334 data.Set(nameserver.c_str());
336 conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"<dns:server> set to '%s' as first resolver in /etc/resolv.conf.",nameserver.c_str());
342 conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"/etc/resolv.conf contains no viable nameserver entries! Defaulting to nameserver '127.0.0.1'!");
343 data.Set("127.0.0.1");
348 conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"/etc/resolv.conf can't be opened! Defaulting to nameserver '127.0.0.1'!");
349 data.Set("127.0.0.1");
355 bool ValidateServerName(ServerConfig* conf, const char*, const char*, ValueItem &data)
357 conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"Validating server name");
358 /* If we already have a servername, and they changed it, we should throw an exception. */
359 if (!strchr(data.GetString(), '.'))
361 conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"WARNING: <server:name> '%s' is not a fully-qualified domain name. Changed to '%s%c'",data.GetString(),data.GetString(),'.');
362 std::string moo = std::string(data.GetString()).append(".");
363 data.Set(moo.c_str());
365 conf->ValidateHostname(data.GetString(), "server", "name");
369 bool ValidateNetBufferSize(ServerConfig* conf, const char*, const char*, ValueItem &data)
371 // 65534 not 65535 because of null terminator
372 if ((!data.GetInteger()) || (data.GetInteger() > 65534) || (data.GetInteger() < 1024))
374 conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"No NetBufferSize specified or size out of range, setting to default of 10240.");
380 bool ValidateMaxWho(ServerConfig* conf, const char*, const char*, ValueItem &data)
382 if ((data.GetInteger() > 65535) || (data.GetInteger() < 1))
384 conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"<performance:maxwho> size out of range, setting to default of 128.");
390 bool ValidateMotd(ServerConfig* conf, const char*, const char*, ValueItem &data)
392 conf->ReadFile(conf->MOTD, data.GetString());
396 bool ValidateNotEmpty(ServerConfig*, const char* tag, const char*, ValueItem &data)
398 if (!*data.GetString())
399 throw CoreException(std::string("The value for ")+tag+" cannot be empty!");
403 bool ValidateRules(ServerConfig* conf, const char*, const char*, ValueItem &data)
405 conf->ReadFile(conf->RULES, data.GetString());
409 bool ValidateModeLists(ServerConfig* conf, const char*, const char*, ValueItem &data)
411 memset(conf->HideModeLists, 0, sizeof(conf->HideModeLists));
412 for (const unsigned char* x = (const unsigned char*)data.GetString(); *x; ++x)
413 conf->HideModeLists[*x] = true;
417 bool ValidateExemptChanOps(ServerConfig* conf, const char*, const char*, ValueItem &data)
419 memset(conf->ExemptChanOps, 0, sizeof(conf->ExemptChanOps));
420 for (const unsigned char* x = (const unsigned char*)data.GetString(); *x; ++x)
421 conf->ExemptChanOps[*x] = true;
425 bool ValidateInvite(ServerConfig* conf, const char*, const char*, ValueItem &data)
427 std::string v = data.GetString();
430 conf->AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_OPS;
432 conf->AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_ALL;
433 else if (v == "dynamic")
434 conf->AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_DYNAMIC;
436 conf->AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_NONE;
441 bool ValidateSID(ServerConfig* conf, const char*, const char*, ValueItem &data)
443 conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"Validating server id");
445 const char *sid = data.GetString();
447 if (*sid && !conf->GetInstance()->IsSID(sid))
449 throw CoreException(std::string(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.");
452 strlcpy(conf->sid, sid, 5);
457 bool ValidateWhoWas(ServerConfig* conf, const char*, const char*, ValueItem &data)
459 conf->WhoWasMaxKeep = conf->GetInstance()->Duration(data.GetString());
461 if (conf->WhoWasGroupSize < 0)
462 conf->WhoWasGroupSize = 0;
464 if (conf->WhoWasMaxGroups < 0)
465 conf->WhoWasMaxGroups = 0;
467 if (conf->WhoWasMaxKeep < 3600)
469 conf->WhoWasMaxKeep = 3600;
470 conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"WARNING: <whowas:maxkeep> value less than 3600, setting to default 3600");
473 Command* whowas_command = conf->GetInstance()->Parser->GetHandler("WHOWAS");
476 std::deque<classbase*> params;
477 whowas_command->HandleInternal(WHOWAS_PRUNE, params);
483 /* Callback called before processing the first <connect> tag
485 bool InitConnect(ServerConfig* conf, const char*)
487 conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"Reading connect classes...");
489 for (ClassVector::iterator i = conf->Classes.begin(); i != conf->Classes.end() ; )
491 ConnectClass* c = *i;
493 /* only delete a class with refcount 0 */
494 if (c->RefCount == 0)
496 conf->GetInstance()->Logs->Log("CONFIG",DEFAULT, "Removing connect class, refcount is 0!");
498 /* This was causing a crash, because we'd set i to .begin() just here, but then the for loop's increment would
499 * set it to .begin() + 1. Which if it was already the last thing in the list, wasn't good.
500 * Now the increment is in the else { } below.
502 conf->Classes.erase(i);
503 i = conf->Classes.begin(); // start over so we don't trample on a bad iterator
507 /* also mark all existing classes disabled, if they still exist in the conf, they will be reenabled. */
508 c->SetDisabled(true);
516 /* Callback called to process a single <connect> tag
518 bool DoConnect(ServerConfig* conf, const char*, char**, ValueList &values, int*)
521 const char* allow = values[0].GetString(); /* Yeah, there are a lot of values. Live with it. */
522 const char* deny = values[1].GetString();
523 const char* password = values[2].GetString();
524 int timeout = values[3].GetInteger();
525 int pingfreq = values[4].GetInteger();
526 int flood = values[5].GetInteger();
527 int threshold = values[6].GetInteger();
528 int sendq = values[7].GetInteger();
529 int recvq = values[8].GetInteger();
530 int localmax = values[9].GetInteger();
531 int globalmax = values[10].GetInteger();
532 int port = values[11].GetInteger();
533 const char* name = values[12].GetString();
534 const char* parent = values[13].GetString();
535 int maxchans = values[14].GetInteger();
536 unsigned long limit = values[15].GetInteger();
537 const char* hashtype = values[16].GetString();
540 * duplicates check: Now we don't delete all connect classes on rehash, we need to ensure we don't add dupes.
541 * easier said than done, but for now we'll just disallow anything with a duplicate host or name. -- w00t
543 for (ClassVector::iterator item = conf->Classes.begin(); item != conf->Classes.end(); ++item)
545 ConnectClass* cc = *item;
547 ((*name && (cc->GetName() == name)) || // if the name is the same
548 (*allow && (cc->GetHost() == allow)) || // or the allow is the same
549 (*deny && (cc->GetHost() == deny))) && // or the deny is the same
550 (!port || (port && (cc->GetPort() == port))) // and there is no port, or there is a port and the port is the same
553 /* reenable class so users can be shoved into it :P */
554 cc->SetDisabled(false);
555 conf->GetInstance()->Logs->Log("CONFIG",DEFAULT, "Not adding class, it already exists!");
560 conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"Adding a connect class!");
564 /* Find 'parent' and inherit a new class from it,
565 * then overwrite any values that are set here
567 ClassVector::iterator item = conf->Classes.begin();
568 for (; item != conf->Classes.end(); ++item)
570 ConnectClass* cc = *item;
571 conf->GetInstance()->Logs->Log("CONFIG",DEBUG,"Class: %s", cc->GetName().c_str());
572 if (cc->GetName() == parent)
574 ConnectClass* newclass = new ConnectClass(name, cc);
575 newclass->Update(timeout, flood, *allow ? allow : deny, pingfreq, password, threshold, sendq, recvq, localmax, globalmax, maxchans, port, limit);
576 conf->Classes.push_back(newclass);
580 if (item == conf->Classes.end())
581 throw CoreException("Class name '" + std::string(name) + "' is configured to inherit from class '" + std::string(parent) + "' which cannot be found.");
587 /* Find existing class by mask, the mask should be unique */
588 for (ClassVector::iterator item = conf->Classes.begin(); item != conf->Classes.end(); ++item)
590 if ((*item)->GetHost() == allow)
592 (*item)->Update(timeout, flood, allow, pingfreq, password, threshold, sendq, recvq, localmax, globalmax, maxchans, port, limit);
596 ConnectClass* cc = new ConnectClass(name, timeout, flood, allow, pingfreq, password, hashtype, threshold, sendq, recvq, localmax, globalmax, maxchans);
599 conf->Classes.push_back(cc);
603 /* Find existing class by mask, the mask should be unique */
604 for (ClassVector::iterator item = conf->Classes.begin(); item != conf->Classes.end(); ++item)
606 if ((*item)->GetHost() == deny)
608 (*item)->Update(name, deny);
609 (*item)->SetPort(port);
613 ConnectClass* cc = new ConnectClass(name, deny);
615 conf->Classes.push_back(cc);
622 /* Callback called when there are no more <connect> tags
624 bool DoneConnect(ServerConfig *conf, const char*)
626 conf->GetInstance()->Logs->Log("CONFIG",DEFAULT, "Done adding connect classes!");
630 /* Callback called before processing the first <uline> tag
632 bool InitULine(ServerConfig* conf, const char*)
634 conf->ulines.clear();
638 /* Callback called to process a single <uline> tag
640 bool DoULine(ServerConfig* conf, const char*, char**, ValueList &values, int*)
642 const char* server = values[0].GetString();
643 const bool silent = values[1].GetBool();
644 conf->ulines[server] = silent;
648 /* Callback called when there are no more <uline> tags
650 bool DoneULine(ServerConfig*, const char*)
655 /* Callback called before processing the first <module> tag
657 bool InitModule(ServerConfig* conf, const char*)
659 old_module_names = conf->GetInstance()->Modules->GetAllModuleNames(0);
660 new_module_names.clear();
661 added_modules.clear();
662 removed_modules.clear();
666 /* Callback called to process a single <module> tag
668 bool DoModule(ServerConfig*, const char*, char**, ValueList &values, int*)
670 const char* modname = values[0].GetString();
671 new_module_names.push_back(modname);
675 /* Callback called when there are no more <module> tags
677 bool DoneModule(ServerConfig*, const char*)
679 // now create a list of new modules that are due to be loaded
680 // and a seperate list of modules which are due to be unloaded
681 for (std::vector<std::string>::iterator _new = new_module_names.begin(); _new != new_module_names.end(); _new++)
685 for (std::vector<std::string>::iterator old = old_module_names.begin(); old != old_module_names.end(); old++)
692 added_modules.push_back(*_new);
695 for (std::vector<std::string>::iterator oldm = old_module_names.begin(); oldm != old_module_names.end(); oldm++)
698 for (std::vector<std::string>::iterator newm = new_module_names.begin(); newm != new_module_names.end(); newm++)
705 removed_modules.push_back(*oldm);
710 /* Callback called before processing the first <banlist> tag
712 bool InitMaxBans(ServerConfig* conf, const char*)
714 conf->maxbans.clear();
718 /* Callback called to process a single <banlist> tag
720 bool DoMaxBans(ServerConfig* conf, const char*, char**, ValueList &values, int*)
722 const char* channel = values[0].GetString();
723 int limit = values[1].GetInteger();
724 conf->maxbans[channel] = limit;
728 /* Callback called when there are no more <banlist> tags.
730 bool DoneMaxBans(ServerConfig*, const char*)
735 void ServerConfig::ReportConfigError(const std::string &errormessage, bool bail, User* user)
737 ServerInstance->Logs->Log("CONFIG",DEFAULT, "There were errors in your configuration file: %s", errormessage.c_str());
740 /* Unneeded because of the ServerInstance->Log() aboive? */
741 printf("There were errors in your configuration:\n%s\n\n",errormessage.c_str());
742 ServerInstance->Exit(EXIT_STATUS_CONFIG);
746 std::string errors = errormessage;
747 std::string::size_type start;
748 unsigned int prefixlen;
750 /* ":ServerInstance->Config->ServerName NOTICE user->nick :" */
753 prefixlen = strlen(this->ServerName) + user->nick.length() + 11;
754 user->WriteServ("NOTICE %s :There were errors in the configuration file:",user->nick.c_str());
755 while (start < errors.length())
757 user->WriteServ("NOTICE %s :%s",user->nick.c_str(), errors.substr(start, 510 - prefixlen).c_str());
758 start += 510 - prefixlen;
763 ServerInstance->SNO->WriteToSnoMask('A', "There were errors in the configuration file:");
764 while (start < errors.length())
766 ServerInstance->SNO->WriteToSnoMask('A', errors.substr(start, 360));
774 void ServerConfig::Read(bool bail, User* user)
776 int rem = 0, add = 0; /* Number of modules added, number of modules removed */
778 static char maxkeep[MAXBUF]; /* Temporary buffer for WhoWasMaxKeep value */
779 static char hidemodes[MAXBUF]; /* Modes to not allow listing from users below halfop */
780 static char exemptchanops[MAXBUF]; /* Exempt channel ops from these modes */
781 static char announceinvites[MAXBUF]; /* options:announceinvites setting */
782 static char disabledumodes[MAXBUF]; /* Disabled usermodes */
783 static char disabledcmodes[MAXBUF]; /* Disabled chanmodes */
786 include_stack.clear();
788 /* These tags MUST occur and must ONLY occur once in the config file */
789 static const char* Once[] = { "server", "admin", "files", "power", "options", NULL };
791 Deprecated ChangedConfig[] = {
792 {"options", "hidelinks", "has been moved to <security:hidelinks> as of 1.2a3"},
793 {"options", "hidewhois", "has been moved to <security:hidewhois> as of 1.2a3"},
794 {"options", "userstats", "has been moved to <security:userstats> as of 1.2a3"},
795 {"options", "customversion", "has been moved to <security:customversion> as of 1.2a3"},
796 {"options", "hidesplits", "has been moved to <security:hidesplits> as of 1.2a3"},
797 {"options", "hidebans", "has been moved to <security:hidebans> as of 1.2a3"},
798 {"options", "hidekills", "has been moved to <security:hidekills> as of 1.2a3"},
799 {"options", "operspywhois", "has been moved to <security:operspywhois> as of 1.2a3"},
800 {"options", "announceinvites", "has been moved to <security:announceinvites> as of 1.2a3"},
801 {"options", "hidemodes", "has been moved to <security:hidemodes> as of 1.2a3"},
802 {"options", "maxtargets", "has been moved to <security:maxtargets> as of 1.2a3"},
803 {"options", "nouserdns", "has been moved to <performance:nouserdns> as of 1.2a3"},
804 {"options", "maxwho", "has been moved to <performance:maxwho> as of 1.2a3"},
805 {"options", "softlimit", "has been moved to <performance:softlimit> as of 1.2a3"},
806 {"options", "somaxconn", "has been moved to <performance:somaxconn> as of 1.2a3"},
807 {"options", "netbuffersize", "has been moved to <performance:netbuffersize> as of 1.2a3"},
808 {"options", "maxwho", "has been moved to <performance:maxwho> as of 1.2a3"},
809 {"options", "loglevel", "1.2 does not use the loglevel value. Please define <log> tags instead."},
813 /* These tags can occur ONCE or not at all */
814 InitialConfig Values[] = {
815 {"performance", "softlimit", "0", new ValueContainerUInt (&this->SoftLimit), DT_INTEGER, ValidateSoftLimit},
816 {"performance", "somaxconn", SOMAXCONN_S, new ValueContainerInt (&this->MaxConn), DT_INTEGER, ValidateMaxConn},
817 {"options", "moronbanner", "Youre banned!", new ValueContainerChar (this->MoronBanner), DT_CHARPTR, NoValidation},
818 {"server", "name", "", new ValueContainerChar (this->ServerName), DT_HOSTNAME|DT_BOOTONLY, ValidateServerName},
819 {"server", "description", "Configure Me", new ValueContainerChar (this->ServerDesc), DT_CHARPTR, NoValidation},
820 {"server", "network", "Network", new ValueContainerChar (this->Network), DT_NOSPACES, NoValidation},
821 {"server", "id", "", new ValueContainerChar (this->sid), DT_CHARPTR|DT_BOOTONLY, ValidateSID},
822 {"admin", "name", "", new ValueContainerChar (this->AdminName), DT_CHARPTR, NoValidation},
823 {"admin", "email", "Mis@configu.red", new ValueContainerChar (this->AdminEmail), DT_CHARPTR, NoValidation},
824 {"admin", "nick", "Misconfigured", new ValueContainerChar (this->AdminNick), DT_CHARPTR, NoValidation},
825 {"files", "motd", "", new ValueContainerChar (this->motd), DT_CHARPTR, ValidateMotd},
826 {"files", "rules", "", new ValueContainerChar (this->rules), DT_CHARPTR, ValidateRules},
827 {"power", "diepass", "", new ValueContainerChar (this->diepass), DT_CHARPTR, ValidateNotEmpty},
828 {"power", "pause", "", new ValueContainerInt (&this->DieDelay), DT_INTEGER, NoValidation},
829 {"power", "hash", "", new ValueContainerChar (this->powerhash), DT_CHARPTR, NoValidation},
830 {"power", "restartpass", "", new ValueContainerChar (this->restartpass), DT_CHARPTR, ValidateNotEmpty},
831 {"options", "prefixquit", "", new ValueContainerChar (this->PrefixQuit), DT_CHARPTR, NoValidation},
832 {"options", "suffixquit", "", new ValueContainerChar (this->SuffixQuit), DT_CHARPTR, NoValidation},
833 {"options", "fixedquit", "", new ValueContainerChar (this->FixedQuit), DT_CHARPTR, NoValidation},
834 {"options", "prefixpart", "", new ValueContainerChar (this->PrefixPart), DT_CHARPTR, NoValidation},
835 {"options", "suffixpart", "", new ValueContainerChar (this->SuffixPart), DT_CHARPTR, NoValidation},
836 {"options", "fixedpart", "", new ValueContainerChar (this->FixedPart), DT_CHARPTR, NoValidation},
837 {"performance", "netbuffersize","10240", new ValueContainerInt (&this->NetBufferSize), DT_INTEGER, ValidateNetBufferSize},
838 {"performance", "maxwho", "128", new ValueContainerInt (&this->MaxWhoResults), DT_INTEGER, ValidateMaxWho},
839 {"options", "allowhalfop", "0", new ValueContainerBool (&this->AllowHalfop), DT_BOOLEAN, NoValidation},
840 {"dns", "server", "", new ValueContainerChar (this->DNSServer), DT_IPADDRESS,DNSServerValidator},
841 {"dns", "timeout", "5", new ValueContainerInt (&this->dns_timeout), DT_INTEGER, NoValidation},
842 {"options", "moduledir", MOD_PATH, new ValueContainerChar (this->ModPath), DT_CHARPTR, NoValidation},
843 {"disabled", "commands", "", new ValueContainerChar (this->DisabledCommands), DT_CHARPTR, NoValidation},
844 {"disabled", "usermodes", "", new ValueContainerChar (disabledumodes), DT_CHARPTR, ValidateDisabledUModes},
845 {"disabled", "chanmodes", "", new ValueContainerChar (disabledcmodes), DT_CHARPTR, ValidateDisabledCModes},
846 {"disabled", "fakenonexistant", "0", new ValueContainerBool (&this->DisabledDontExist), DT_BOOLEAN, NoValidation},
847 {"security", "userstats", "", new ValueContainerChar (this->UserStats), DT_CHARPTR, NoValidation},
848 {"security", "customversion","", new ValueContainerChar (this->CustomVersion), DT_CHARPTR, NoValidation},
849 {"security", "hidesplits", "0", new ValueContainerBool (&this->HideSplits), DT_BOOLEAN, NoValidation},
850 {"security", "hidebans", "0", new ValueContainerBool (&this->HideBans), DT_BOOLEAN, NoValidation},
851 {"security", "hidewhois", "", new ValueContainerChar (this->HideWhoisServer), DT_NOSPACES, NoValidation},
852 {"security", "hidekills", "", new ValueContainerChar (this->HideKillsServer), DT_NOSPACES, NoValidation},
853 {"security", "operspywhois", "0", new ValueContainerBool (&this->OperSpyWhois), DT_BOOLEAN, NoValidation},
854 {"performance", "nouserdns", "0", new ValueContainerBool (&this->NoUserDns), DT_BOOLEAN, NoValidation},
855 {"options", "syntaxhints", "0", new ValueContainerBool (&this->SyntaxHints), DT_BOOLEAN, NoValidation},
856 {"options", "cyclehosts", "0", new ValueContainerBool (&this->CycleHosts), DT_BOOLEAN, NoValidation},
857 {"options", "ircumsgprefix","0", new ValueContainerBool (&this->UndernetMsgPrefix), DT_BOOLEAN, NoValidation},
858 {"security", "announceinvites", "1", new ValueContainerChar (announceinvites), DT_CHARPTR, ValidateInvite},
859 {"options", "hostintopic", "1", new ValueContainerBool (&this->FullHostInTopic), DT_BOOLEAN, NoValidation},
860 {"security", "hidemodes", "", new ValueContainerChar (hidemodes), DT_CHARPTR, ValidateModeLists},
861 {"options", "exemptchanops","", new ValueContainerChar (exemptchanops), DT_CHARPTR, ValidateExemptChanOps},
862 {"security", "maxtargets", "20", new ValueContainerUInt (&this->MaxTargets), DT_INTEGER, ValidateMaxTargets},
863 {"options", "defaultmodes", "nt", new ValueContainerChar (this->DefaultModes), DT_CHARPTR, NoValidation},
864 {"pid", "file", "", new ValueContainerChar (this->PID), DT_CHARPTR, NoValidation},
865 {"whowas", "groupsize", "10", new ValueContainerInt (&this->WhoWasGroupSize), DT_INTEGER, NoValidation},
866 {"whowas", "maxgroups", "10240", new ValueContainerInt (&this->WhoWasMaxGroups), DT_INTEGER, NoValidation},
867 {"whowas", "maxkeep", "3600", new ValueContainerChar (maxkeep), DT_CHARPTR, ValidateWhoWas},
868 {"die", "value", "", new ValueContainerChar (this->DieValue), DT_CHARPTR, NoValidation},
869 {"channels", "users", "20", new ValueContainerUInt (&this->MaxChans), DT_INTEGER, NoValidation},
870 {"channels", "opers", "60", new ValueContainerUInt (&this->OperMaxChans), DT_INTEGER, NoValidation},
871 {"cidr", "ipv4clone", "32", new ValueContainerInt (&this->c_ipv4_range), DT_INTEGER, NoValidation},
872 {"cidr", "ipv6clone", "128", new ValueContainerInt (&this->c_ipv6_range), DT_INTEGER, NoValidation},
873 {"limits", "maxnick", "32", new ValueContainerST (&this->Limits.NickMax), DT_INTEGER, NoValidation},
874 {"limits", "maxchan", "64", new ValueContainerST (&this->Limits.ChanMax), DT_INTEGER, NoValidation},
875 {"limits", "maxmodes", "20", new ValueContainerST (&this->Limits.MaxModes), DT_INTEGER, NoValidation},
876 {"limits", "maxident", "11", new ValueContainerST (&this->Limits.IdentMax), DT_INTEGER, NoValidation},
877 {"limits", "maxquit", "255", new ValueContainerST (&this->Limits.MaxQuit), DT_INTEGER, NoValidation},
878 {"limits", "maxtopic", "307", new ValueContainerST (&this->Limits.MaxTopic), DT_INTEGER, NoValidation},
879 {"limits", "maxkick", "255", new ValueContainerST (&this->Limits.MaxKick), DT_INTEGER, NoValidation},
880 {"limits", "maxgecos", "128", new ValueContainerST (&this->Limits.MaxGecos), DT_INTEGER, NoValidation},
881 {"limits", "maxaway", "200", new ValueContainerST (&this->Limits.MaxAway), DT_INTEGER, NoValidation},
882 {"options", "invitebypassmodes", "1", new ValueContainerBool (&this->InvBypassModes), DT_BOOLEAN, NoValidation},
883 {NULL, NULL, NULL, NULL, DT_NOTHING, NoValidation}
887 /* These tags can occur multiple times, and therefore they have special code to read them
888 * which is different to the code for reading the singular tags listed above.
890 MultiConfig MultiValues[] = {
893 {"allow", "deny", "password", "timeout", "pingfreq", "flood",
894 "threshold", "sendq", "recvq", "localmax", "globalmax", "port",
895 "name", "parent", "maxchans", "limit", "hash",
897 {"", "", "", "", "120", "",
898 "", "", "", "3", "3", "0",
899 "", "", "0", "0", "",
901 {DT_IPADDRESS|DT_ALLOW_WILD,
902 DT_IPADDRESS|DT_ALLOW_WILD,
903 DT_CHARPTR, DT_INTEGER, DT_INTEGER, DT_INTEGER,
904 DT_INTEGER, DT_INTEGER, DT_INTEGER, DT_INTEGER, DT_INTEGER, DT_INTEGER,
905 DT_NOSPACES, DT_NOSPACES, DT_INTEGER, DT_INTEGER, DT_CHARPTR},
906 InitConnect, DoConnect, DoneConnect},
909 {"server", "silent", NULL},
911 {DT_HOSTNAME, DT_BOOLEAN},
912 InitULine,DoULine,DoneULine},
915 {"chan", "limit", NULL},
917 {DT_CHARPTR, DT_INTEGER},
918 InitMaxBans, DoMaxBans, DoneMaxBans},
924 InitModule, DoModule, DoneModule},
927 {"reason", "ipmask", NULL},
928 {"No reason", "", NULL},
929 {DT_CHARPTR, DT_IPADDRESS|DT_ALLOW_WILD},
930 InitXLine, DoZLine, DoneConfItem},
933 {"reason", "nick", NULL},
934 {"No reason", "", NULL},
935 {DT_CHARPTR, DT_CHARPTR},
936 InitXLine, DoQLine, DoneConfItem},
939 {"reason", "host", NULL},
940 {"No reason", "", NULL},
941 {DT_CHARPTR, DT_CHARPTR},
942 InitXLine, DoKLine, DoneConfItem},
945 {"reason", "host", NULL},
946 {"No reason", "", NULL},
947 {DT_CHARPTR, DT_CHARPTR},
948 InitXLine, DoELine, DoneELine},
951 {"name", "classes", NULL},
953 {DT_NOSPACES, DT_CHARPTR},
954 InitTypes, DoType, DoneClassesAndTypes},
957 {"name", "commands", "usermodes", "chanmodes", NULL},
958 {"", "", "", "", NULL},
959 {DT_NOSPACES, DT_CHARPTR, DT_CHARPTR, DT_CHARPTR},
960 InitClasses, DoClass, DoneClassesAndTypes},
969 /* Load and parse the config file, if there are any errors then explode */
971 /* Make a copy here so if it fails then we can carry on running with an unaffected config */
974 if (!this->DoInclude(newconfig, ServerInstance->ConfigFileName, errstr))
976 ReportConfigError(errstr.str(), bail, user);
980 /* The stuff in here may throw CoreException, be sure we're in a position to catch it. */
983 /* Check we dont have more than one of singular tags, or any of them missing
985 for (int Index = 0; Once[Index]; Index++)
986 if (!CheckOnce(Once[Index], newconfig))
989 for (int Index = 0; ChangedConfig[Index].tag; Index++)
993 if (ConfValue(newconfig, ChangedConfig[Index].tag, ChangedConfig[Index].value, "", 0, item, MAXBUF, true) || *item)
994 throw CoreException(std::string("Your configuration contains a deprecated value: <") + ChangedConfig[Index].tag + ":" + ChangedConfig[Index].value + "> - " + ChangedConfig[Index].reason);
996 ServerInstance->Logs->Log("CONFIG",DEBUG,"Deprecated item <%s:%s> does not exist, good.", ChangedConfig[Index].tag, ChangedConfig[Index].value);
999 /* Read the values of all the tags which occur once or not at all, and call their callbacks.
1001 for (int Index = 0; Values[Index].tag; ++Index)
1004 int dt = Values[Index].datatype;
1005 bool allow_newlines = ((dt & DT_ALLOW_NEWLINE) > 0);
1006 bool allow_wild = ((dt & DT_ALLOW_WILD) > 0);
1007 bool bootonly = ((dt & DT_BOOTONLY) > 0);
1008 dt &= ~DT_ALLOW_NEWLINE;
1009 dt &= ~DT_ALLOW_WILD;
1012 /* Silently ignore boot only values */
1013 if (bootonly && !bail)
1016 ConfValue(newconfig, Values[Index].tag, Values[Index].value, Values[Index].default_value, 0, item, MAXBUF, allow_newlines);
1019 if (!Values[Index].validation_function(this, Values[Index].tag, Values[Index].value, vi))
1020 throw CoreException("One or more values in your configuration file failed to validate. Please see your ircd.log for more information.");
1022 ServerInstance->Threads->Mutex(true);
1027 ValueContainerChar* vcc = (ValueContainerChar*)Values[Index].val;
1028 this->ValidateNoSpaces(vi.GetString(), Values[Index].tag, Values[Index].value);
1029 vcc->Set(vi.GetString(), strlen(vi.GetString()) + 1);
1034 ValueContainerChar* vcc = (ValueContainerChar*)Values[Index].val;
1035 this->ValidateHostname(vi.GetString(), Values[Index].tag, Values[Index].value);
1036 vcc->Set(vi.GetString(), strlen(vi.GetString()) + 1);
1041 ValueContainerChar* vcc = (ValueContainerChar*)Values[Index].val;
1042 this->ValidateIP(vi.GetString(), Values[Index].tag, Values[Index].value, allow_wild);
1043 vcc->Set(vi.GetString(), strlen(vi.GetString()) + 1);
1048 ValueContainerChar* vcc = (ValueContainerChar*)Values[Index].val;
1049 if (*(vi.GetString()) && !ServerInstance->IsChannel(vi.GetString(), MAXBUF))
1051 ServerInstance->Threads->Mutex(false);
1052 throw CoreException("The value of <"+std::string(Values[Index].tag)+":"+Values[Index].value+"> is not a valid channel name");
1054 vcc->Set(vi.GetString(), strlen(vi.GetString()) + 1);
1059 ValueContainerChar* vcc = (ValueContainerChar*)Values[Index].val;
1060 /* Make sure we also copy the null terminator */
1061 vcc->Set(vi.GetString(), strlen(vi.GetString()) + 1);
1066 int val = vi.GetInteger();
1067 ValueContainerInt* vci = (ValueContainerInt*)Values[Index].val;
1068 vci->Set(&val, sizeof(int));
1073 bool val = vi.GetBool();
1074 ValueContainerBool* vcb = (ValueContainerBool*)Values[Index].val;
1075 vcb->Set(&val, sizeof(bool));
1079 /* You don't want to know what happens if someones bad code sends us here. */
1082 /* We're done with this now */
1083 delete Values[Index].val;
1084 ServerInstance->Threads->Mutex(false);
1087 /* Read the multiple-tag items (class tags, connect tags, etc)
1088 * and call the callbacks associated with them. We have three
1089 * callbacks for these, a 'start', 'item' and 'end' callback.
1091 for (int Index = 0; MultiValues[Index].tag; ++Index)
1093 ServerInstance->Threads->Mutex(true);
1094 MultiValues[Index].init_function(this, MultiValues[Index].tag);
1095 ServerInstance->Threads->Mutex(false);
1097 int number_of_tags = ConfValueEnum(newconfig, MultiValues[Index].tag);
1099 for (int tagnum = 0; tagnum < number_of_tags; ++tagnum)
1102 for (int valuenum = 0; (MultiValues[Index].items[valuenum]) && (valuenum < MAX_VALUES_PER_TAG); ++valuenum)
1104 int dt = MultiValues[Index].datatype[valuenum];
1105 bool allow_newlines = ((dt & DT_ALLOW_NEWLINE) > 0);
1106 bool allow_wild = ((dt & DT_ALLOW_WILD) > 0);
1107 dt &= ~DT_ALLOW_NEWLINE;
1108 dt &= ~DT_ALLOW_WILD;
1110 ServerInstance->Threads->Mutex(true);
1111 /* We catch and rethrow any exception here just so we can free our mutex
1120 if (ConfValue(newconfig, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, MAXBUF, allow_newlines))
1121 vl.push_back(ValueItem(item));
1123 vl.push_back(ValueItem(""));
1124 this->ValidateNoSpaces(vl[vl.size()-1].GetString(), MultiValues[Index].tag, MultiValues[Index].items[valuenum]);
1130 if (ConfValue(newconfig, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, MAXBUF, allow_newlines))
1131 vl.push_back(ValueItem(item));
1133 vl.push_back(ValueItem(""));
1134 this->ValidateHostname(vl[vl.size()-1].GetString(), MultiValues[Index].tag, MultiValues[Index].items[valuenum]);
1140 if (ConfValue(newconfig, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, MAXBUF, allow_newlines))
1141 vl.push_back(ValueItem(item));
1143 vl.push_back(ValueItem(""));
1144 this->ValidateIP(vl[vl.size()-1].GetString(), MultiValues[Index].tag, MultiValues[Index].items[valuenum], allow_wild);
1150 if (ConfValue(newconfig, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, MAXBUF, allow_newlines))
1151 vl.push_back(ValueItem(item));
1153 vl.push_back(ValueItem(""));
1154 if (!ServerInstance->IsChannel(vl[vl.size()-1].GetString(), MAXBUF))
1155 throw CoreException("The value of <"+std::string(MultiValues[Index].tag)+":"+MultiValues[Index].items[valuenum]+"> number "+ConvToStr(tagnum + 1)+" is not a valid channel name");
1161 if (ConfValue(newconfig, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, MAXBUF, allow_newlines))
1162 vl.push_back(ValueItem(item));
1164 vl.push_back(ValueItem(""));
1170 if (ConfValueInteger(newconfig, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item))
1171 vl.push_back(ValueItem(item));
1173 vl.push_back(ValueItem(0));
1178 bool item = ConfValueBool(newconfig, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum);
1179 vl.push_back(ValueItem(item));
1183 /* Someone was smoking craq if we got here, and we're all gonna die. */
1187 catch (CoreException &e)
1189 ServerInstance->Threads->Mutex(false);
1192 ServerInstance->Threads->Mutex(false);
1194 MultiValues[Index].validation_function(this, MultiValues[Index].tag, (char**)MultiValues[Index].items, vl, MultiValues[Index].datatype);
1196 MultiValues[Index].finish_function(this, MultiValues[Index].tag);
1199 /* Finalise the limits, increment them all by one so that we can just put assign(str, 0, val)
1200 * rather than assign(str, 0, val + 1)
1206 catch (CoreException &ce)
1208 ReportConfigError(ce.GetReason(), bail, user);
1212 ServerInstance->Threads->Mutex(true);
1213 for (int i = 0; i < ConfValueEnum(newconfig, "type"); ++i)
1215 char item[MAXBUF], classn[MAXBUF], classes[MAXBUF];
1216 std::string classname;
1217 ConfValue(newconfig, "type", "classes", "", i, classes, MAXBUF, false);
1218 irc::spacesepstream str(classes);
1219 ConfValue(newconfig, "type", "name", "", i, item, MAXBUF, false);
1220 while (str.GetToken(classname))
1223 bool foundclass = false;
1224 for (int j = 0; j < ConfValueEnum(newconfig, "class"); ++j)
1226 ConfValue(newconfig, "class", "name", "", j, classn, MAXBUF, false);
1227 if (!strcmp(classn, classname.c_str()))
1236 user->WriteServ("NOTICE %s :*** Warning: Oper type '%s' has a missing class named '%s', this does nothing!", user->nick.c_str(), item, classname.c_str());
1240 printf("Warning: Oper type '%s' has a missing class named '%s', this does nothing!\n", item, classname.c_str());
1242 ServerInstance->SNO->WriteToSnoMask('A', "Warning: Oper type '%s' has a missing class named '%s', this does nothing!", item, classname.c_str());
1248 /* If we succeeded, set the ircd config to the new one */
1249 this->config_data = newconfig;
1251 ServerInstance->Threads->Mutex(false);
1253 // write once here, to try it out and make sure its ok
1254 ServerInstance->WritePID(this->PID);
1256 /* Switch over logfiles */
1257 ServerInstance->Logs->CloseLogs();
1258 ServerInstance->Logs->OpenFileLogs();
1260 ServerInstance->Logs->Log("CONFIG", DEFAULT, "Done reading configuration file.");
1262 /* If we're rehashing, let's load any new modules, and unload old ones
1266 int found_ports = 0;
1268 ServerInstance->BindPorts(false, found_ports, pl);
1270 if (pl.size() && user)
1272 ServerInstance->Threads->Mutex(true);
1273 user->WriteServ("NOTICE %s :*** Not all your client ports could be bound.", user->nick.c_str());
1274 user->WriteServ("NOTICE %s :*** The following port(s) failed to bind:", user->nick.c_str());
1276 for (FailedPortList::iterator i = pl.begin(); i != pl.end(); i++, j++)
1278 user->WriteServ("NOTICE %s :*** %d. Address: %s Reason: %s", user->nick.c_str(), j, i->first.empty() ? "<all>" : i->first.c_str(), i->second.c_str());
1280 ServerInstance->Threads->Mutex(false);
1283 ServerInstance->Threads->Mutex(true);
1284 if (!removed_modules.empty())
1286 for (std::vector<std::string>::iterator removing = removed_modules.begin(); removing != removed_modules.end(); removing++)
1288 if (ServerInstance->Modules->Unload(removing->c_str()))
1290 ServerInstance->SNO->WriteToSnoMask('A', "*** REHASH UNLOADED MODULE: %s",removing->c_str());
1293 user->WriteNumeric(RPL_UNLOADEDMODULE, "%s %s :Module %s successfully unloaded.",user->nick.c_str(), removing->c_str(), removing->c_str());
1300 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());
1305 if (!added_modules.empty())
1307 for (std::vector<std::string>::iterator adding = added_modules.begin(); adding != added_modules.end(); adding++)
1309 if (ServerInstance->Modules->Load(adding->c_str()))
1311 ServerInstance->SNO->WriteToSnoMask('A', "*** REHASH LOADED MODULE: %s",adding->c_str());
1314 user->WriteNumeric(RPL_LOADEDMODULE, "%s %s :Module %s successfully loaded.",user->nick.c_str(), adding->c_str(), adding->c_str());
1321 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());
1326 ServerInstance->Logs->Log("CONFIG", DEFAULT, "Successfully unloaded %lu of %lu modules and loaded %lu of %lu modules.",(unsigned long)rem,(unsigned long)removed_modules.size(),(unsigned long)add,(unsigned long)added_modules.size());
1328 ServerInstance->Threads->Mutex(false);
1334 /** Note: This is safe, the method checks for user == NULL */
1335 ServerInstance->Threads->Mutex(true);
1336 ServerInstance->Parser->SetupCommandTable(user);
1337 ServerInstance->Threads->Mutex(false);
1342 user->WriteServ("NOTICE %s :*** Successfully rehashed server.", user->nick.c_str());
1344 ServerInstance->SNO->WriteToSnoMask('A', "*** Successfully rehashed server.");
1350 bool ServerConfig::LoadConf(ConfigDataHash &target, FILE* &conf, const char* filename, std::ostringstream &errorstream)
1354 long linenumber = 1;
1355 long last_successful_parse = 1;
1359 int character_count = 0;
1365 ServerInstance->Logs->Log("CONFIG", DEBUG, "Reading %s", filename);
1367 /* Check if the file open failed first */
1370 errorstream << "LoadConf: Couldn't open config file: " << filename << std::endl;
1374 for (unsigned int t = 0; t < include_stack.size(); t++)
1376 if (std::string(filename) == include_stack[t])
1378 errorstream << "File " << filename << " is included recursively (looped inclusion)." << std::endl;
1383 /* It's not already included, add it to the list of files we've loaded */
1384 include_stack.push_back(filename);
1386 /* Start reading characters... */
1387 while ((ch = fgetc(conf)) != EOF)
1390 * Fix for moronic windows issue spotted by Adremelech.
1391 * Some windows editors save text files as utf-16, which is
1392 * a total pain in the ass to parse. Users should save in the
1393 * right config format! If we ever see a file where the first
1394 * byte is 0xFF or 0xFE, or the second is 0xFF or 0xFE, then
1395 * this is most likely a utf-16 file. Bail out and insult user.
1397 if ((character_count++ < 2) && (ch == '\xFF' || ch == '\xFE'))
1399 errorstream << "File " << filename << " cannot be read, as it is encoded in braindead UTF-16. Save your file as plain ASCII!" << std::endl;
1404 * Here we try and get individual tags on separate lines,
1405 * this would be so easy if we just made people format
1406 * their config files like that, but they don't so...
1407 * We check for a '<' and then know the line is over when
1408 * we get a '>' not inside quotes. If we find two '<' and
1409 * no '>' then die with an error.
1412 if ((ch == '#') && !in_quote)
1433 /* XXX: Added by Brain, May 1st 2006 - Escaping of characters.
1434 * Note that this WILL NOT usually allow insertion of newlines,
1435 * because a newline is two characters long. Use it primarily to
1436 * insert the " symbol.
1438 * Note that this also involves a further check when parsing the line,
1439 * which can be found below.
1441 if ((ch == '\\') && (in_quote) && (in_tag))
1444 char real_character;
1447 real_character = fgetc(conf);
1448 if (real_character == 'n')
1449 real_character = '\n';
1450 line += real_character;
1455 errorstream << "End of file after a \\, what did you want to escape?: " << filename << ":" << linenumber << std::endl;
1463 if ((ch != '<') && (!in_tag) && (!in_comment) && (ch > ' ') && (ch != 9))
1465 errorstream << "You have stray characters beyond the tag which starts at " << filename << ":" << last_successful_parse << std::endl;
1475 errorstream << "The tag at location " << filename << ":" << last_successful_parse << " was valid, but there is an error in the tag which comes after it. You are possibly missing a \" or >. Please check this." << std::endl;
1483 errorstream << "Parser error: Inside a quote but not within the last valid tag, which was opened at: " << filename << ":" << last_successful_parse << std::endl;
1488 // errorstream << "Opening new config tag on line " << linenumber << std::endl;
1499 // errorstream << "Closing quote in config tag on line " << linenumber << std::endl;
1504 // errorstream << "Opening quote in config tag on line " << linenumber << std::endl;
1512 errorstream << "The tag immediately after the one at " << filename << ":" << last_successful_parse << " has a missing closing \" symbol. Please check this." << std::endl;
1516 errorstream << "You have opened a quote (\") beyond the tag at " << filename << ":" << last_successful_parse << " without opening a new tag. Please check this." << std::endl;
1526 // errorstream << "Closing config tag on line " << linenumber << std::endl;
1530 * If this finds an <include> then ParseLine can simply call
1531 * LoadConf() and load the included config into the same ConfigDataHash
1533 long bl = linenumber;
1534 if (!this->ParseLine(target, filename, line, linenumber, errorstream))
1536 last_successful_parse = linenumber;
1544 errorstream << "You forgot to close the tag which comes immediately after the one at " << filename << ":" << last_successful_parse << std::endl;
1551 /* Fix for bug #392 - if we reach the end of a file and we are still in a quote or comment, most likely the user fucked up */
1552 if (in_comment || in_quote)
1554 errorstream << "Reached end of file whilst still inside a quoted section or tag. This is most likely an error or there \
1555 is a newline missing from the end of the file: " << filename << ":" << linenumber << std::endl;
1562 bool ServerConfig::LoadConf(ConfigDataHash &target, FILE* &conf, const std::string &filename, std::ostringstream &errorstream)
1564 return this->LoadConf(target, conf, filename.c_str(), errorstream);
1567 bool ServerConfig::ParseLine(ConfigDataHash &target, const std::string &filename, std::string &line, long &linenumber, std::ostringstream &errorstream)
1569 std::string tagname;
1570 std::string current_key;
1571 std::string current_value;
1578 got_name = got_key = in_quote = false;
1580 for(std::string::iterator c = line.begin(); c != line.end(); c++)
1584 /* We don't know the tag name yet. */
1590 if ((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <='Z') || (*c >= '0' && *c <= '9') || *c == '_')
1594 errorstream << "Invalid character in value name of tag: '" << *c << "' in value '" << tagname << "' in filename: " << filename << ":" << linenumber << std::endl;
1601 /* We got to a space, we should have the tagname now. */
1602 if(tagname.length())
1610 /* We have the tag name */
1613 /* We're still reading the key name */
1614 if ((*c != '=') && (*c != '>'))
1618 if ((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <='Z') || (*c >= '0' && *c <= '9') || *c == '_')
1622 errorstream << "Invalid character in key: '" << *c << "' in key '" << current_key << "' in filename: " << filename << ":" << linenumber << std::endl;
1629 /* We got an '=', end of the key name. */
1635 /* We have the key name, now we're looking for quotes and the value */
1637 /* Correctly handle escaped characters here.
1638 * See the XXX'ed section above.
1640 if ((*c == '\\') && (in_quote))
1644 current_value += '\n';
1646 current_value += *c;
1649 else if ((*c == '\\') && (!in_quote))
1651 errorstream << "You can't have an escape sequence outside of a quoted section: " << filename << ":" << linenumber << std::endl;
1654 else if ((*c == '\n') && (in_quote))
1656 /* Got a 'real' \n, treat it as part of the value */
1657 current_value += '\n';
1660 else if ((*c == '\r') && (in_quote))
1662 /* Got a \r, drop it */
1670 /* We're not already in a quote. */
1675 /* Leaving the quotes, we have the current value */
1676 results.push_back(KeyVal(current_key, current_value));
1678 // std::cout << "<" << tagname << ":" << current_key << "> " << current_value << std::endl;
1683 if ((tagname == "include") && (current_key == "file"))
1685 if (!this->DoInclude(target, current_value, errorstream))
1688 else if ((tagname == "include") && (current_key == "executable"))
1690 /* Pipe an executable and use its stdout as config data */
1691 if (!this->DoPipe(target, current_value, errorstream))
1695 current_key.clear();
1696 current_value.clear();
1704 current_value += *c;
1711 /* Finished parsing the tag, add it to the config hash */
1712 target.insert(std::pair<std::string, KeyValList > (tagname, results));
1717 bool ServerConfig::DoPipe(ConfigDataHash &target, const std::string &file, std::ostringstream &errorstream)
1719 FILE* conf = popen(file.c_str(), "r");
1724 ret = LoadConf(target, conf, file.c_str(), errorstream);
1728 errorstream << "Couldn't execute: " << file << std::endl;
1733 bool ServerConfig::StartsWithWindowsDriveLetter(const std::string &path)
1735 return (path.length() > 2 && isalpha(path[0]) && path[1] == ':');
1738 bool ServerConfig::DoInclude(ConfigDataHash &target, const std::string &file, std::ostringstream &errorstream)
1740 std::string confpath;
1741 std::string newfile;
1742 std::string::size_type pos;
1744 confpath = ServerInstance->ConfigFileName;
1747 std::replace(newfile.begin(),newfile.end(),'\\','/');
1748 std::replace(confpath.begin(),confpath.end(),'\\','/');
1750 if ((newfile[0] != '/') && (!StartsWithWindowsDriveLetter(newfile)))
1752 if((pos = confpath.rfind("/")) != std::string::npos)
1754 /* Leaves us with just the path */
1755 newfile = confpath.substr(0, pos) + std::string("/") + newfile;
1759 errorstream << "Couldn't get config path from: " << ServerInstance->ConfigFileName << std::endl;
1764 FILE* conf = fopen(newfile.c_str(), "r");
1769 ret = LoadConf(target, conf, newfile, errorstream);
1773 errorstream << "Couldn't open config file: " << file << std::endl;
1778 bool ServerConfig::ConfValue(ConfigDataHash &target, const char* tag, const char* var, int index, char* result, int length, bool allow_linefeeds)
1780 return ConfValue(target, tag, var, "", index, result, length, allow_linefeeds);
1783 bool ServerConfig::ConfValue(ConfigDataHash &target, const char* tag, const char* var, const char* default_value, int index, char* result, int length, bool allow_linefeeds)
1786 bool r = ConfValue(target, std::string(tag), std::string(var), std::string(default_value), index, value, allow_linefeeds);
1787 strlcpy(result, value.c_str(), length);
1791 bool ServerConfig::ConfValue(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, std::string &result, bool allow_linefeeds)
1793 return ConfValue(target, tag, var, "", index, result, allow_linefeeds);
1796 bool ServerConfig::ConfValue(ConfigDataHash &target, const std::string &tag, const std::string &var, const std::string &default_value, int index, std::string &result, bool allow_linefeeds)
1798 ConfigDataHash::size_type pos = index;
1799 if (pos < target.count(tag))
1801 ConfigDataHash::iterator iter = target.find(tag);
1803 for(int i = 0; i < index; i++)
1806 for(KeyValList::iterator j = iter->second.begin(); j != iter->second.end(); j++)
1810 if ((!allow_linefeeds) && (j->second.find('\n') != std::string::npos))
1812 ServerInstance->Logs->Log("CONFIG",DEFAULT, "Value of <" + tag + ":" + var+ "> contains a linefeed, and linefeeds in this value are not permitted -- stripped to spaces.");
1813 for (std::string::iterator n = j->second.begin(); n != j->second.end(); n++)
1824 if (!default_value.empty())
1826 result = default_value;
1832 if (!default_value.empty())
1834 result = default_value;
1841 bool ServerConfig::ConfValueInteger(ConfigDataHash &target, const char* tag, const char* var, int index, int &result)
1843 return ConfValueInteger(target, std::string(tag), std::string(var), "", index, result);
1846 bool ServerConfig::ConfValueInteger(ConfigDataHash &target, const char* tag, const char* var, const char* default_value, int index, int &result)
1848 return ConfValueInteger(target, std::string(tag), std::string(var), std::string(default_value), index, result);
1851 bool ServerConfig::ConfValueInteger(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, int &result)
1853 return ConfValueInteger(target, tag, var, "", index, result);
1856 bool ServerConfig::ConfValueInteger(ConfigDataHash &target, const std::string &tag, const std::string &var, const std::string &default_value, int index, int &result)
1859 std::istringstream stream;
1860 bool r = ConfValue(target, tag, var, default_value, index, value);
1862 if(!(stream >> result))
1868 if (value.substr(0,2) == "0x")
1873 result = strtol(value.c_str(), &endptr, 16);
1875 /* No digits found */
1876 if (endptr == value.c_str())
1881 char denominator = *(value.end() - 1);
1882 switch (toupper(denominator))
1885 /* Kilobytes -> bytes */
1886 result = result * 1024;
1889 /* Megabytes -> bytes */
1890 result = result * 1024 * 1024;
1893 /* Gigabytes -> bytes */
1894 result = result * 1024 * 1024 * 1024;
1904 bool ServerConfig::ConfValueBool(ConfigDataHash &target, const char* tag, const char* var, int index)
1906 return ConfValueBool(target, std::string(tag), std::string(var), "", index);
1909 bool ServerConfig::ConfValueBool(ConfigDataHash &target, const char* tag, const char* var, const char* default_value, int index)
1911 return ConfValueBool(target, std::string(tag), std::string(var), std::string(default_value), index);
1914 bool ServerConfig::ConfValueBool(ConfigDataHash &target, const std::string &tag, const std::string &var, int index)
1916 return ConfValueBool(target, tag, var, "", index);
1919 bool ServerConfig::ConfValueBool(ConfigDataHash &target, const std::string &tag, const std::string &var, const std::string &default_value, int index)
1922 if(!ConfValue(target, tag, var, default_value, index, result))
1925 return ((result == "yes") || (result == "true") || (result == "1"));
1928 int ServerConfig::ConfValueEnum(ConfigDataHash &target, const char* tag)
1930 return target.count(tag);
1933 int ServerConfig::ConfValueEnum(ConfigDataHash &target, const std::string &tag)
1935 return target.count(tag);
1938 int ServerConfig::ConfVarEnum(ConfigDataHash &target, const char* tag, int index)
1940 return ConfVarEnum(target, std::string(tag), index);
1943 int ServerConfig::ConfVarEnum(ConfigDataHash &target, const std::string &tag, int index)
1945 ConfigDataHash::size_type pos = index;
1947 if (pos < target.count(tag))
1949 ConfigDataHash::const_iterator iter = target.find(tag);
1951 for(int i = 0; i < index; i++)
1954 return iter->second.size();
1960 /** Read the contents of a file located by `fname' into a file_cache pointed at by `F'.
1962 bool ServerConfig::ReadFile(file_cache &F, const char* fname)
1964 if (!fname || !*fname)
1968 char linebuf[MAXBUF];
1972 if ((*fname != '/') && (*fname != '\\') && (!StartsWithWindowsDriveLetter(fname)))
1974 std::string::size_type pos;
1975 std::string confpath = ServerInstance->ConfigFileName;
1976 std::string newfile = fname;
1978 if (((pos = confpath.rfind("/"))) != std::string::npos)
1979 newfile = confpath.substr(0, pos) + std::string("/") + fname;
1980 else if (((pos = confpath.rfind("\\"))) != std::string::npos)
1981 newfile = confpath.substr(0, pos) + std::string("\\") + fname;
1983 ServerInstance->Logs->Log("config", DEBUG, "Filename: %s", newfile.c_str());
1985 if (!FileExists(newfile.c_str()))
1987 file = fopen(newfile.c_str(), "r");
1991 if (!FileExists(fname))
1993 file = fopen(fname, "r");
2000 if (fgets(linebuf, sizeof(linebuf), file))
2001 linebuf[strlen(linebuf)-1] = 0;
2005 F.push_back(*linebuf ? linebuf : " ");
2016 bool ServerConfig::FileExists(const char* file)
2019 if (stat(file, &sb) == -1)
2022 if ((sb.st_mode & S_IFDIR) > 0)
2026 if ((input = fopen (file, "r")) == NULL)
2035 char* ServerConfig::CleanFilename(char* name)
2037 char* p = name + strlen(name);
2038 while ((p != name) && (*p != '/') && (*p != '\\')) p--;
2039 return (p != name ? ++p : p);
2043 bool ServerConfig::DirValid(const char* dirandfile)
2051 char otherdir[1024];
2054 strlcpy(work, dirandfile, 1024);
2057 // we just want the dir
2069 // Get the current working directory
2070 if (getcwd(buffer, 1024 ) == NULL )
2073 if (chdir(work) == -1)
2076 if (getcwd(otherdir, 1024 ) == NULL )
2079 if (chdir(buffer) == -1)
2082 size_t t = strlen(work);
2084 if (strlen(otherdir) >= t)
2087 if (!strcmp(otherdir,work))
2101 std::string ServerConfig::GetFullProgDir()
2103 char buffer[PATH_MAX];
2105 /* Windows has specific api calls to get the exe path that never fail.
2106 * For once, windows has something of use, compared to the POSIX code
2107 * for this, this is positively neato.
2109 if (GetModuleFileName(NULL, buffer, MAX_PATH))
2111 std::string fullpath = buffer;
2112 std::string::size_type n = fullpath.rfind("\\inspircd.exe");
2113 return std::string(fullpath, 0, n);
2116 // Get the current working directory
2117 if (getcwd(buffer, PATH_MAX))
2119 std::string remainder = this->argv[0];
2121 /* Does argv[0] start with /? its a full path, use it */
2122 if (remainder[0] == '/')
2124 std::string::size_type n = remainder.rfind("/inspircd");
2125 return std::string(remainder, 0, n);
2128 std::string fullpath = std::string(buffer) + "/" + remainder;
2129 std::string::size_type n = fullpath.rfind("/inspircd");
2130 return std::string(fullpath, 0, n);
2136 InspIRCd* ServerConfig::GetInstance()
2138 return ServerInstance;
2141 std::string ServerConfig::GetSID()
2146 ValueItem::ValueItem(int value)
2148 std::stringstream n;
2153 ValueItem::ValueItem(bool value)
2155 std::stringstream n;
2160 ValueItem::ValueItem(const char* value)
2165 void ValueItem::Set(const char* value)
2170 void ValueItem::Set(int value)
2172 std::stringstream n;
2177 int ValueItem::GetInteger()
2181 return atoi(v.c_str());
2184 char* ValueItem::GetString()
2186 return (char*)v.c_str();
2189 bool ValueItem::GetBool()
2191 return (GetInteger() || v == "yes" || v == "true");
2198 * XXX should this be in a class? -- w00t
2200 bool InitTypes(ServerConfig* conf, const char*)
2202 if (conf->opertypes.size())
2204 for (opertype_t::iterator n = conf->opertypes.begin(); n != conf->opertypes.end(); n++)
2211 conf->opertypes.clear();
2216 * XXX should this be in a class? -- w00t
2218 bool InitClasses(ServerConfig* conf, const char*)
2220 if (conf->operclass.size())
2222 for (operclass_t::iterator n = conf->operclass.begin(); n != conf->operclass.end(); n++)
2224 if (n->second.commandlist)
2225 delete[] n->second.commandlist;
2226 if (n->second.cmodelist)
2227 delete[] n->second.cmodelist;
2228 if (n->second.umodelist)
2229 delete[] n->second.umodelist;
2233 conf->operclass.clear();
2238 * XXX should this be in a class? -- w00t
2240 bool DoType(ServerConfig* conf, const char*, char**, ValueList &values, int*)
2242 const char* TypeName = values[0].GetString();
2243 const char* Classes = values[1].GetString();
2245 conf->opertypes[TypeName] = strnewdup(Classes);
2250 * XXX should this be in a class? -- w00t
2252 bool DoClass(ServerConfig* conf, const char* tag, char**, ValueList &values, int*)
2254 const char* ClassName = values[0].GetString();
2255 const char* CommandList = values[1].GetString();
2256 const char* UModeList = values[2].GetString();
2257 const char* CModeList = values[3].GetString();
2259 for (const char* c = UModeList; *c; ++c)
2261 if ((*c < 'A' || *c > 'z') && *c != '*')
2263 throw CoreException("Character " + std::string(1, *c) + " is not a valid mode in <class:usermodes>");
2266 for (const char* c = CModeList; *c; ++c)
2268 if ((*c < 'A' || *c > 'z') && *c != '*')
2270 throw CoreException("Character " + std::string(1, *c) + " is not a valid mode in <class:chanmodes>");
2274 conf->operclass[ClassName].commandlist = strnewdup(CommandList);
2275 conf->operclass[ClassName].umodelist = strnewdup(UModeList);
2276 conf->operclass[ClassName].cmodelist = strnewdup(CModeList);
2281 * XXX should this be in a class? -- w00t
2283 bool DoneClassesAndTypes(ServerConfig*, const char*)
2290 bool InitXLine(ServerConfig* conf, const char* tag)
2295 bool DoZLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
2297 const char* reason = values[0].GetString();
2298 const char* ipmask = values[1].GetString();
2300 ZLine* zl = new ZLine(conf->GetInstance(), conf->GetInstance()->Time(), 0, "<Config>", reason, ipmask);
2301 if (!conf->GetInstance()->XLines->AddLine(zl, NULL))
2307 bool DoQLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
2309 const char* reason = values[0].GetString();
2310 const char* nick = values[1].GetString();
2312 QLine* ql = new QLine(conf->GetInstance(), conf->GetInstance()->Time(), 0, "<Config>", reason, nick);
2313 if (!conf->GetInstance()->XLines->AddLine(ql, NULL))
2319 bool DoKLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
2321 const char* reason = values[0].GetString();
2322 const char* host = values[1].GetString();
2324 XLineManager* xlm = conf->GetInstance()->XLines;
2326 IdentHostPair ih = xlm->IdentSplit(host);
2328 KLine* kl = new KLine(conf->GetInstance(), conf->GetInstance()->Time(), 0, "<Config>", reason, ih.first.c_str(), ih.second.c_str());
2329 if (!xlm->AddLine(kl, NULL))
2334 bool DoELine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
2336 const char* reason = values[0].GetString();
2337 const char* host = values[1].GetString();
2339 XLineManager* xlm = conf->GetInstance()->XLines;
2341 IdentHostPair ih = xlm->IdentSplit(host);
2343 ELine* el = new ELine(conf->GetInstance(), conf->GetInstance()->Time(), 0, "<Config>", reason, ih.first.c_str(), ih.second.c_str());
2344 if (!xlm->AddLine(el, NULL))
2349 // this should probably be moved to configreader, but atm it relies on CheckELines above.
2350 bool DoneELine(ServerConfig* conf, const char* tag)
2352 for (std::vector<User*>::const_iterator u2 = conf->GetInstance()->Users->local_users.begin(); u2 != conf->GetInstance()->Users->local_users.end(); u2++)
2354 User* u = (User*)(*u2);
2358 conf->GetInstance()->XLines->CheckELines();
2362 void ConfigReaderThread::Run()
2364 /* TODO: TheUser may be invalid by the time we get here! Check its validity, or pass a UID would be better */
2365 ServerInstance->Config->Read(do_bail, TheUser);
2366 ServerInstance->Threads->Mutex(true);
2367 this->SetExitFlag();
2368 ServerInstance->Threads->Mutex(false);