X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fconfigreader.cpp;h=46ae6ac4ed22db9f86c67db6a4759fe9ef12dc0c;hb=6cdc212ce7559bfc6cb26bf1e09fb3601a48c5ce;hp=9ec8aa367bf7b0c1652542f882a2fcffdf219fd2;hpb=dfba08638c3b940fb6e96389c12376a411769be1;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/configreader.cpp b/src/configreader.cpp index 9ec8aa367..46ae6ac4e 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -21,6 +21,8 @@ /* $CopyInstall: conf/inspircd.filter.example $(CONPATH) */ /* $CopyInstall: conf/inspircd.conf.example $(CONPATH) */ /* $CopyInstall: conf/modules.conf.example $(CONPATH) */ +/* $CopyInstall: conf/opers.conf.example $(CONPATH) */ +/* $CopyInstall: conf/links.conf.example $(CONPATH) */ #include "inspircd.h" #include @@ -65,37 +67,6 @@ void ServerConfig::ClearStack() include_stack.clear(); } -Module* ServerConfig::GetIOHook(BufferedSocket* is) -{ - std::map::iterator x = SocketIOHookModule.find(is); - return (x != SocketIOHookModule.end() ? x->second : NULL); -} - -bool ServerConfig::AddIOHook(Module* iomod, BufferedSocket* is) -{ - if (!GetIOHook(is)) - { - SocketIOHookModule[is] = iomod; - is->IsIOHooked = true; - return true; - } - else - { - throw ModuleException("BufferedSocket derived class already hooked by another module"); - } -} - -bool ServerConfig::DelIOHook(BufferedSocket* is) -{ - std::map::iterator x = SocketIOHookModule.find(is); - if (x != SocketIOHookModule.end()) - { - SocketIOHookModule.erase(x); - return true; - } - return false; -} - void ServerConfig::Update005() { std::stringstream out(data005); @@ -393,10 +364,10 @@ bool ValidateMotd(ServerConfig* conf, const char*, const char*, ValueItem &data) return true; } -bool ValidateNotEmpty(ServerConfig*, const char* tag, const char*, ValueItem &data) +bool ValidateNotEmpty(ServerConfig*, const char* tag, const char* val, ValueItem &data) { if (!*data.GetString()) - throw CoreException(std::string("The value for ")+tag+" cannot be empty!"); + throw CoreException(std::string("The value for <")+tag+":"+val+"> cannot be empty!"); return true; } @@ -732,7 +703,7 @@ bool DoneMaxBans(ServerConfig*, const char*) return true; } -void ServerConfig::ReportConfigError(const std::string &errormessage, bool bail, User* user) +void ServerConfig::ReportConfigError(const std::string &errormessage, bool bail, const std::string &useruid) { ServerInstance->Logs->Log("CONFIG",DEFAULT, "There were errors in your configuration file: %s", errormessage.c_str()); if (bail) @@ -748,14 +719,18 @@ void ServerConfig::ReportConfigError(const std::string &errormessage, bool bail, unsigned int prefixlen; start = 0; /* ":ServerInstance->Config->ServerName NOTICE user->nick :" */ - if (user) + if (!useruid.empty()) { - prefixlen = strlen(this->ServerName) + user->nick.length() + 11; - user->WriteServ("NOTICE %s :There were errors in the configuration file:",user->nick.c_str()); - while (start < errors.length()) + User* user = ServerInstance->FindNick(useruid); + if (user) { - user->WriteServ("NOTICE %s :%s",user->nick.c_str(), errors.substr(start, 510 - prefixlen).c_str()); - start += 510 - prefixlen; + prefixlen = strlen(this->ServerName) + user->nick.length() + 11; + user->WriteServ("NOTICE %s :There were errors in the configuration file:",user->nick.c_str()); + while (start < errors.length()) + { + user->WriteServ("NOTICE %s :%s",user->nick.c_str(), errors.substr(start, 510 - prefixlen).c_str()); + start += 510 - prefixlen; + } } } else @@ -771,7 +746,7 @@ void ServerConfig::ReportConfigError(const std::string &errormessage, bool bail, } } -void ServerConfig::Read(bool bail, User* user) +void ServerConfig::Read(bool bail, const std::string &useruid) { int rem = 0, add = 0; /* Number of modules added, number of modules removed */ @@ -973,7 +948,7 @@ void ServerConfig::Read(bool bail, User* user) if (!this->DoInclude(newconfig, ServerInstance->ConfigFileName, errstr)) { - ReportConfigError(errstr.str(), bail, user); + ReportConfigError(errstr.str(), bail, useruid); return; } @@ -1019,7 +994,7 @@ void ServerConfig::Read(bool bail, User* user) if (!Values[Index].validation_function(this, Values[Index].tag, Values[Index].value, vi)) 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); + ServerInstance->Threads->Lock(); switch (dt) { case DT_NOSPACES: @@ -1048,7 +1023,7 @@ void ServerConfig::Read(bool bail, User* user) ValueContainerChar* vcc = (ValueContainerChar*)Values[Index].val; if (*(vi.GetString()) && !ServerInstance->IsChannel(vi.GetString(), MAXBUF)) { - ServerInstance->Threads->Mutex(false); + ServerInstance->Threads->Unlock(); throw CoreException("The value of <"+std::string(Values[Index].tag)+":"+Values[Index].value+"> is not a valid channel name"); } vcc->Set(vi.GetString(), strlen(vi.GetString()) + 1); @@ -1081,7 +1056,7 @@ void ServerConfig::Read(bool bail, User* user) } /* We're done with this now */ delete Values[Index].val; - ServerInstance->Threads->Mutex(false); + ServerInstance->Threads->Unlock(); } /* Read the multiple-tag items (class tags, connect tags, etc) @@ -1090,9 +1065,9 @@ void ServerConfig::Read(bool bail, User* user) */ for (int Index = 0; MultiValues[Index].tag; ++Index) { - ServerInstance->Threads->Mutex(true); + ServerInstance->Threads->Lock(); MultiValues[Index].init_function(this, MultiValues[Index].tag); - ServerInstance->Threads->Mutex(false); + ServerInstance->Threads->Unlock(); int number_of_tags = ConfValueEnum(newconfig, MultiValues[Index].tag); @@ -1107,7 +1082,7 @@ void ServerConfig::Read(bool bail, User* user) dt &= ~DT_ALLOW_NEWLINE; dt &= ~DT_ALLOW_WILD; - ServerInstance->Threads->Mutex(true); + ServerInstance->Threads->Lock(); /* We catch and rethrow any exception here just so we can free our mutex */ try @@ -1186,10 +1161,10 @@ void ServerConfig::Read(bool bail, User* user) } catch (CoreException &e) { - ServerInstance->Threads->Mutex(false); + ServerInstance->Threads->Unlock(); throw e; } - ServerInstance->Threads->Mutex(false); + ServerInstance->Threads->Unlock(); } MultiValues[Index].validation_function(this, MultiValues[Index].tag, (char**)MultiValues[Index].items, vl, MultiValues[Index].datatype); } @@ -1205,11 +1180,11 @@ void ServerConfig::Read(bool bail, User* user) catch (CoreException &ce) { - ReportConfigError(ce.GetReason(), bail, user); + ReportConfigError(ce.GetReason(), bail, useruid); return; } - ServerInstance->Threads->Mutex(true); + ServerInstance->Threads->Lock(); for (int i = 0; i < ConfValueEnum(newconfig, "type"); ++i) { char item[MAXBUF], classn[MAXBUF], classes[MAXBUF]; @@ -1232,8 +1207,12 @@ void ServerConfig::Read(bool bail, User* user) } if (!foundclass) { - if (user) - 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()); + if (!useruid.empty()) + { + User* user = ServerInstance->FindNick(useruid); + if (user) + 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()); + } else { if (bail) @@ -1248,7 +1227,7 @@ void ServerConfig::Read(bool bail, User* user) /* If we succeeded, set the ircd config to the new one */ this->config_data = newconfig; - ServerInstance->Threads->Mutex(false); + ServerInstance->Threads->Unlock(); // write once here, to try it out and make sure its ok ServerInstance->WritePID(this->PID); @@ -1267,20 +1246,24 @@ void ServerConfig::Read(bool bail, User* user) FailedPortList pl; ServerInstance->BindPorts(false, found_ports, pl); - if (pl.size() && user) + if (pl.size() && !useruid.empty()) { - ServerInstance->Threads->Mutex(true); - user->WriteServ("NOTICE %s :*** Not all your client ports could be bound.", user->nick.c_str()); - user->WriteServ("NOTICE %s :*** The following port(s) failed to bind:", user->nick.c_str()); - int j = 1; - for (FailedPortList::iterator i = pl.begin(); i != pl.end(); i++, j++) + ServerInstance->Threads->Lock(); + User* user = ServerInstance->FindNick(useruid); + if (user) { - user->WriteServ("NOTICE %s :*** %d. Address: %s Reason: %s", user->nick.c_str(), j, i->first.empty() ? "" : i->first.c_str(), i->second.c_str()); + user->WriteServ("NOTICE %s :*** Not all your client ports could be bound.", user->nick.c_str()); + user->WriteServ("NOTICE %s :*** The following port(s) failed to bind:", user->nick.c_str()); + int j = 1; + for (FailedPortList::iterator i = pl.begin(); i != pl.end(); i++, j++) + { + user->WriteServ("NOTICE %s :*** %d. Address: %s Reason: %s", user->nick.c_str(), j, i->first.empty() ? "" : i->first.c_str(), i->second.c_str()); + } } - ServerInstance->Threads->Mutex(false); + ServerInstance->Threads->Unlock(); } - ServerInstance->Threads->Mutex(true); + ServerInstance->Threads->Lock(); if (!removed_modules.empty()) { for (std::vector::iterator removing = removed_modules.begin(); removing != removed_modules.end(); removing++) @@ -1289,15 +1272,27 @@ void ServerConfig::Read(bool bail, User* user) { ServerInstance->SNO->WriteToSnoMask('A', "*** REHASH UNLOADED MODULE: %s",removing->c_str()); - if (user) - user->WriteNumeric(RPL_UNLOADEDMODULE, "%s %s :Module %s successfully unloaded.",user->nick.c_str(), removing->c_str(), removing->c_str()); + if (!useruid.empty()) + { + User* user = ServerInstance->FindNick(useruid); + if (user) + user->WriteNumeric(RPL_UNLOADEDMODULE, "%s %s :Module %s successfully unloaded.",user->nick.c_str(), removing->c_str(), removing->c_str()); + } + else + ServerInstance->SNO->WriteToSnoMask('A', "Module %s successfully unloaded.", removing->c_str()); rem++; } else { - if (user) - 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()); + if (!useruid.empty()) + { + User* user = ServerInstance->FindNick(useruid); + if (user) + 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()); + } + else + ServerInstance->SNO->WriteToSnoMask('A', "Failed to unload module %s: %s", removing->c_str(), ServerInstance->Modules->LastError().c_str()); } } } @@ -1309,37 +1304,55 @@ void ServerConfig::Read(bool bail, User* user) if (ServerInstance->Modules->Load(adding->c_str())) { ServerInstance->SNO->WriteToSnoMask('A', "*** REHASH LOADED MODULE: %s",adding->c_str()); - - if (user) - user->WriteNumeric(RPL_LOADEDMODULE, "%s %s :Module %s successfully loaded.",user->nick.c_str(), adding->c_str(), adding->c_str()); + if (!useruid.empty()) + { + User* user = ServerInstance->FindNick(useruid); + if (user) + user->WriteNumeric(RPL_LOADEDMODULE, "%s %s :Module %s successfully loaded.",user->nick.c_str(), adding->c_str(), adding->c_str()); + } + else + ServerInstance->SNO->WriteToSnoMask('A', "Module %s successfully loaded.", adding->c_str()); add++; } else { - if (user) - 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()); + if (!useruid.empty()) + { + User* user = ServerInstance->FindNick(useruid); + if (user) + 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()); + } + else + ServerInstance->SNO->WriteToSnoMask('A', "Failed to load module %s: %s", adding->c_str(), ServerInstance->Modules->LastError().c_str()); } } } 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); + ServerInstance->Threads->Unlock(); } if (bail) { /** Note: This is safe, the method checks for user == NULL */ - ServerInstance->Threads->Mutex(true); + ServerInstance->Threads->Lock(); + User* user = NULL; + if (!useruid.empty()) + user = ServerInstance->FindNick(useruid); ServerInstance->Parser->SetupCommandTable(user); - ServerInstance->Threads->Mutex(false); + ServerInstance->Threads->Unlock(); } else { - if (user) - user->WriteServ("NOTICE %s :*** Successfully rehashed server.", user->nick.c_str()); + if (!useruid.empty()) + { + User* user = ServerInstance->FindNick(useruid); + if (user) + user->WriteServ("NOTICE %s :*** Successfully rehashed server.", user->nick.c_str()); + } else ServerInstance->SNO->WriteToSnoMask('A', "*** Successfully rehashed server."); } @@ -2361,10 +2374,9 @@ bool DoneELine(ServerConfig* conf, const char* tag) void ConfigReaderThread::Run() { - /* TODO: TheUser may be invalid by the time we get here! Check its validity, or pass a UID would be better */ - ServerInstance->Config->Read(do_bail, TheUser); - ServerInstance->Threads->Mutex(true); + ServerInstance->Config->Read(do_bail, TheUserUID); + ServerInstance->Threads->Lock(); this->SetExitFlag(); - ServerInstance->Threads->Mutex(false); + ServerInstance->Threads->Unlock(); }