X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fconfigreader.cpp;h=df7721e826adfe0d4bc5ac327fc3c318d8b49c0e;hb=0ba0beb0c465cd7bfbd98b6f51429d3147c362eb;hp=d0fff119f60674cbee298bcb0b3e64f3331dcf9c;hpb=75327637e73bed15dd1cb869f034183a03781752;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/configreader.cpp b/src/configreader.cpp index d0fff119f..df7721e82 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -47,7 +47,7 @@ ServerConfig::ServerConfig(InspIRCd* Instance) : ServerInstance(Instance) dns_timeout = DieDelay = 5; MaxTargets = 20; NetBufferSize = 10240; - SoftLimit = MAXCLIENTS; + SoftLimit = Instance->SE->GetMaxFds(); MaxConn = SOMAXCONN; MaxWhoResults = 0; debugging = 0; @@ -63,32 +63,12 @@ void ServerConfig::ClearStack() include_stack.clear(); } -Module* ServerConfig::GetIOHook(int port) -{ - std::map::iterator x = IOHookModule.find(port); - return (x != IOHookModule.end() ? x->second : NULL); -} - Module* ServerConfig::GetIOHook(BufferedSocket* is) { std::map::iterator x = SocketIOHookModule.find(is); return (x != SocketIOHookModule.end() ? x->second : NULL); } -bool ServerConfig::AddIOHook(int port, Module* iomod) -{ - if (!GetIOHook(port)) - { - IOHookModule[port] = iomod; - return true; - } - else - { - throw ModuleException("Port already hooked by another module"); - return false; - } -} - bool ServerConfig::AddIOHook(Module* iomod, BufferedSocket* is) { if (!GetIOHook(is)) @@ -104,17 +84,6 @@ bool ServerConfig::AddIOHook(Module* iomod, BufferedSocket* is) } } -bool ServerConfig::DelIOHook(int port) -{ - std::map::iterator x = IOHookModule.find(port); - if (x != IOHookModule.end()) - { - IOHookModule.erase(x); - return true; - } - return false; -} - bool ServerConfig::DelIOHook(BufferedSocket* is) { std::map::iterator x = SocketIOHookModule.find(is); @@ -157,7 +126,7 @@ void ServerConfig::Update005() void ServerConfig::Send005(User* user) { for (std::vector::iterator line = ServerInstance->Config->isupport.begin(); line != ServerInstance->Config->isupport.end(); line++) - user->WriteServ("005 %s %s", user->nick, line->c_str()); + user->WriteNumeric(005, "%s %s", user->nick, line->c_str()); } bool ServerConfig::CheckOnce(const char* tag) @@ -292,10 +261,10 @@ bool ValidateMaxTargets(ServerConfig* conf, const char*, const char*, ValueItem bool ValidateSoftLimit(ServerConfig* conf, const char*, const char*, ValueItem &data) { - if ((data.GetInteger() < 1) || (data.GetInteger() > MAXCLIENTS)) + if ((data.GetInteger() < 1) || (data.GetInteger() > conf->GetInstance()->SE->GetMaxFds())) { - conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"WARNING: value is greater than %d or less than 0, set to %d.",MAXCLIENTS,MAXCLIENTS); - data.Set(MAXCLIENTS); + conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"WARNING: value is greater than %d or less than 0, set to %d.",conf->GetInstance()->SE->GetMaxFds(),conf->GetInstance()->SE->GetMaxFds()); + data.Set(conf->GetInstance()->SE->GetMaxFds()); } return true; } @@ -368,14 +337,9 @@ bool ValidateDnsServer(ServerConfig* conf, const char*, const char*, ValueItem & bool ValidateServerName(ServerConfig* conf, const char*, const char*, ValueItem &data) { + conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"Validating server name"); /* If we already have a servername, and they changed it, we should throw an exception. */ - if ((strcasecmp(conf->ServerName, data.GetString())) && (*conf->ServerName)) - { - throw CoreException("Configuration error: You cannot change your servername at runtime! Please restart your server for this change to be applied."); - /* We don't actually reach this return of course... */ - return false; - } - if (!strchr(data.GetString(),'.')) + if (!strchr(data.GetString(), '.')) { conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"WARNING: '%s' is not a fully-qualified domain name. Changed to '%s%c'",data.GetString(),data.GetString(),'.'); std::string moo = std::string(data.GetString()).append("."); @@ -478,6 +442,8 @@ bool ValidateInvite(ServerConfig* conf, const char*, const char*, ValueItem &dat bool ValidateSID(ServerConfig* conf, const char*, const char*, ValueItem &data) { + conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"Validating server id"); + const char *sid = data.GetString(); if (*sid && !conf->GetInstance()->IsSID(sid)) @@ -485,6 +451,8 @@ bool ValidateSID(ServerConfig* conf, const char*, const char*, ValueItem &data) 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."); } + strlcpy(conf->sid, sid, 5); + return true; } @@ -520,13 +488,6 @@ bool InitConnect(ServerConfig* conf, const char*) { conf->GetInstance()->Logs->Log("CONFIG",DEFAULT,"Reading connect classes..."); - for (ClassVector::iterator i = conf->Classes.begin(); i != conf->Classes.end(); i++) - { - ConnectClass *c = *i; - - conf->GetInstance()->Logs->Log("CONFIG",DEBUG, "Address of class is %p", c); - } - for (ClassVector::iterator i = conf->Classes.begin(); i != conf->Classes.end() ; ) { ConnectClass* c = *i; @@ -780,7 +741,7 @@ void ServerConfig::ReportConfigError(const std::string &errormessage, bool bail, ServerInstance->SNO->WriteToSnoMask('A', "There were errors in the configuration file:"); while (start < errors.length()) { - ServerInstance->SNO->WriteToSnoMask('A', errors.substr(start, 360).c_str()); + ServerInstance->SNO->WriteToSnoMask('A', errors.substr(start, 360)); start += 360; } } @@ -806,13 +767,13 @@ void ServerConfig::Read(bool bail, User* user) /* These tags can occur ONCE or not at all */ InitialConfig Values[] = { - {"options", "softlimit", MAXCLIENTS_S, new ValueContainerUInt (&this->SoftLimit), DT_INTEGER, ValidateSoftLimit}, + {"options", "softlimit", "0", new ValueContainerUInt (&this->SoftLimit), DT_INTEGER, ValidateSoftLimit}, {"options", "somaxconn", SOMAXCONN_S, new ValueContainerInt (&this->MaxConn), DT_INTEGER, ValidateMaxConn}, {"options", "moronbanner", "Youre banned!", new ValueContainerChar (this->MoronBanner), DT_CHARPTR, NoValidation}, - {"server", "name", "", new ValueContainerChar (this->ServerName), DT_HOSTNAME, ValidateServerName}, + {"server", "name", "", new ValueContainerChar (this->ServerName), DT_HOSTNAME|DT_BOOTONLY, ValidateServerName}, {"server", "description", "Configure Me", new ValueContainerChar (this->ServerDesc), DT_CHARPTR, NoValidation}, {"server", "network", "Network", new ValueContainerChar (this->Network), DT_NOSPACES, NoValidation}, - {"server", "id", "", new ValueContainerChar (this->sid), DT_CHARPTR, ValidateSID}, + {"server", "id", "", new ValueContainerChar (this->sid), DT_CHARPTR|DT_BOOTONLY, ValidateSID}, {"admin", "name", "", new ValueContainerChar (this->AdminName), DT_CHARPTR, NoValidation}, {"admin", "email", "Mis@configu.red", new ValueContainerChar (this->AdminEmail), DT_CHARPTR, NoValidation}, {"admin", "nick", "Misconfigured", new ValueContainerChar (this->AdminNick), DT_CHARPTR, NoValidation}, @@ -933,9 +894,9 @@ void ServerConfig::Read(bool bail, User* user) InitTypes, DoType, DoneClassesAndTypes}, {"class", - {"name", "commands", NULL}, - {"", "", NULL}, - {DT_NOSPACES, DT_CHARPTR}, + {"name", "commands", "usermodes", "chanmodes", NULL}, + {"", "", "", "", NULL}, + {DT_NOSPACES, DT_CHARPTR, DT_CHARPTR, DT_CHARPTR}, InitClasses, DoClass, DoneClassesAndTypes}, {NULL, @@ -980,8 +941,14 @@ void ServerConfig::Read(bool bail, User* user) int dt = Values[Index].datatype; bool allow_newlines = ((dt & DT_ALLOW_NEWLINE) > 0); bool allow_wild = ((dt & DT_ALLOW_WILD) > 0); + bool bootonly = ((dt & DT_BOOTONLY) > 0); dt &= ~DT_ALLOW_NEWLINE; dt &= ~DT_ALLOW_WILD; + dt &= ~DT_BOOTONLY; + + /* Silently ignore boot only values */ + if (bootonly && !bail) + continue; ConfValue(this->config_data, Values[Index].tag, Values[Index].value, Values[Index].default_value, 0, item, MAXBUF, allow_newlines); ValueItem vi(item); @@ -990,7 +957,7 @@ void ServerConfig::Read(bool bail, User* user) throw CoreException("One or more values in your configuration file failed to validate. Please see your ircd.log for more information."); ServerInstance->Threads->Mutex(true); - switch (Values[Index].datatype) + switch (dt) { case DT_NOSPACES: { @@ -1004,6 +971,7 @@ void ServerConfig::Read(bool bail, User* user) ValueContainerChar* vcc = (ValueContainerChar*)Values[Index].val; this->ValidateHostname(vi.GetString(), Values[Index].tag, Values[Index].value); vcc->Set(vi.GetString(), strlen(vi.GetString()) + 1); + ServerInstance->Logs->Log("CONFIG",DEFAULT,"Got %s", vi.GetString()); } break; case DT_IPADDRESS: @@ -1177,12 +1145,12 @@ void ServerConfig::Read(bool bail, User* user) // write once here, to try it out and make sure its ok ServerInstance->WritePID(this->PID); - ServerInstance->Log(DEFAULT,"Done reading configuration file."); - /* Switch over logfiles */ ServerInstance->Logs->CloseLogs(); ServerInstance->Logs->OpenFileLogs(); + ServerInstance->Logs->Log("CONFIG", DEFAULT, "Done reading configuration file."); + /* If we're rehashing, let's load any new modules, and unload old ones */ if (!bail) @@ -1214,14 +1182,14 @@ void ServerConfig::Read(bool bail, User* user) ServerInstance->SNO->WriteToSnoMask('A', "*** REHASH UNLOADED MODULE: %s",removing->c_str()); if (user) - user->WriteServ("973 %s %s :Module %s successfully unloaded.",user->nick, removing->c_str(), removing->c_str()); + user->WriteNumeric(973, "%s %s :Module %s successfully unloaded.",user->nick, removing->c_str(), removing->c_str()); rem++; } else { if (user) - user->WriteServ("972 %s %s :Failed to unload module %s: %s",user->nick, removing->c_str(), removing->c_str(), ServerInstance->Modules->LastError().c_str()); + user->WriteNumeric(972, "%s %s :Failed to unload module %s: %s",user->nick, removing->c_str(), removing->c_str(), ServerInstance->Modules->LastError().c_str()); } } } @@ -1235,19 +1203,19 @@ void ServerConfig::Read(bool bail, User* user) ServerInstance->SNO->WriteToSnoMask('A', "*** REHASH LOADED MODULE: %s",adding->c_str()); if (user) - user->WriteServ("975 %s %s :Module %s successfully loaded.",user->nick, adding->c_str(), adding->c_str()); + user->WriteNumeric(975, "%s %s :Module %s successfully loaded.",user->nick, adding->c_str(), adding->c_str()); add++; } else { if (user) - user->WriteServ("974 %s %s :Failed to load module %s: %s",user->nick, adding->c_str(), adding->c_str(), ServerInstance->Modules->LastError().c_str()); + user->WriteNumeric(974, "%s %s :Failed to load module %s: %s",user->nick, adding->c_str(), adding->c_str(), ServerInstance->Modules->LastError().c_str()); } } } - ServerInstance->Log(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()); + 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()); ServerInstance->Threads->Mutex(false); @@ -1281,6 +1249,8 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, FILE* &conf, const char* fil in_quote = false; in_comment = false; + ServerInstance->Logs->Log("CONFIG", DEBUG, "Reading %s", filename); + /* Check if the file open failed first */ if (!conf) { @@ -1304,7 +1274,6 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, FILE* &conf, const char* fil while (!feof(conf)) { ch = fgetc(conf); - /* * Fix for moronic windows issue spotted by Adremelech. * Some windows editors save text files as utf-16, which is @@ -2105,8 +2074,12 @@ bool InitClasses(ServerConfig* conf, const char*) { for (operclass_t::iterator n = conf->operclass.begin(); n != conf->operclass.end(); n++) { - if (n->second) - delete[] n->second; + if (n->second.commandlist) + delete[] n->second.commandlist; + if (n->second.cmodelist) + delete[] n->second.cmodelist; + if (n->second.umodelist) + delete[] n->second.umodelist; } } @@ -2129,12 +2102,31 @@ bool DoType(ServerConfig* conf, const char*, char**, ValueList &values, int*) /* * XXX should this be in a class? -- w00t */ -bool DoClass(ServerConfig* conf, const char*, char**, ValueList &values, int*) +bool DoClass(ServerConfig* conf, const char* tag, char**, ValueList &values, int*) { const char* ClassName = values[0].GetString(); const char* CommandList = values[1].GetString(); + const char* UModeList = values[2].GetString(); + const char* CModeList = values[3].GetString(); + + for (const char* c = UModeList; *c; ++c) + { + if ((*c < 'A' || *c > 'z') && *c != '*') + { + throw CoreException("Character " + std::string(1, *c) + " is not a valid mode in "); + } + } + for (const char* c = CModeList; *c; ++c) + { + if ((*c < 'A' || *c > 'z') && *c != '*') + { + throw CoreException("Character " + std::string(1, *c) + " is not a valid mode in "); + } + } - conf->operclass[ClassName] = strnewdup(CommandList); + conf->operclass[ClassName].commandlist = strnewdup(CommandList); + conf->operclass[ClassName].umodelist = strnewdup(UModeList); + conf->operclass[ClassName].cmodelist = strnewdup(CModeList); return true; }