X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Finspircd_io.cpp;h=aee8abe88d2ecc57c1814a71091a4f1aa50dadbd;hb=59b1a8955142935b02af6446005ab47fc7c3fc8c;hp=66fa0908ec49ec39f11378979e2d4877c37df1a4;hpb=7cbc465e2a153f65c242aebc1b2a88d3c667d551;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/inspircd_io.cpp b/src/inspircd_io.cpp index 66fa0908e..aee8abe88 100644 --- a/src/inspircd_io.cpp +++ b/src/inspircd_io.cpp @@ -44,7 +44,7 @@ extern std::vector factory; ServerConfig::ServerConfig() { this->ClearStack(); - *ServerName = *Network = *ServerDesc = *AdminName = '\0'; + *TempDir = *ServerName = *Network = *ServerDesc = *AdminName = '\0'; *HideWhoisServer = *AdminEmail = *AdminNick = *diepass = *restartpass = '\0'; *CustomVersion = *motd = *rules = *PrefixQuit = *DieValue = *DNSServer = '\0'; *OperOnlyStats = *ModPath = *MyExecutable = *DisabledCommands = *PID = '\0'; @@ -82,7 +82,12 @@ bool ServerConfig::AddIOHook(int port, Module* iomod) IOHookModule[port] = iomod; return true; } - return false; + else + { + ModuleException err("Port already hooked by another module"); + throw(err); + return false; + } } bool ServerConfig::DelIOHook(int port) @@ -148,6 +153,11 @@ bool ServerConfig::CheckOnce(char* tag, bool bail, userrec* user) void ServerConfig::Read(bool bail, userrec* user) { + /** Yes yes, i know, this function is craq worthy of + * sirv. Its a mess, and some day i will tidy it. + * ...But that day will not be today. or probaby not + * tomorrow even, because it works fine. + */ char dbg[MAXBUF],pauseval[MAXBUF],Value[MAXBUF],timeout[MAXBUF],NB[MAXBUF],flood[MAXBUF],MW[MAXBUF],MCON[MAXBUF],MT[MAXBUF]; char AH[MAXBUF],AP[MAXBUF],AF[MAXBUF],DNT[MAXBUF],pfreq[MAXBUF],thold[MAXBUF],sqmax[MAXBUF],rqmax[MAXBUF],SLIMT[MAXBUF]; char localmax[MAXBUF],globalmax[MAXBUF],HS[MAXBUF]; @@ -192,8 +202,7 @@ void ServerConfig::Read(bool bail, userrec* user) /* Check we dont have more than one of singular tags */ if (!CheckOnce("server",bail,user) || !CheckOnce("admin",bail,user) || !CheckOnce("files",bail,user) - || !CheckOnce("power",bail,user) || !CheckOnce("options",bail,user) - || !CheckOnce("dns",bail,user) || !CheckOnce("pid",bail,user)) + || !CheckOnce("power",bail,user) || !CheckOnce("options",bail,user) || !CheckOnce("pid",bail,user)) { return; } @@ -228,7 +237,10 @@ void ServerConfig::Read(bool bail, userrec* user) ConfValue("options","maxtargets",0,MT,&Config->config_f); ConfValue("options","hidesplits",0,HS,&Config->config_f); ConfValue("options","hidewhois",0,Config->HideWhoisServer,&Config->config_f); + ConfValue("options","tempdir",0,Config->TempDir,&Config->config_f); + if (!*Config->TempDir) + strlcpy(Config->TempDir,"/tmp",1024); Config->HideSplits = ((*HS == 'y') || (*HS == 'Y') || (*HS == '1') || (*HS == 't') || (*HS == 'T')); Config->SoftLimit = atoi(SLIMT); if (*MT) @@ -249,12 +261,46 @@ void ServerConfig::Read(bool bail, userrec* user) Config->NetBufferSize = atoi(NB); Config->MaxWhoResults = atoi(MW); Config->dns_timeout = atoi(DNT); + if (!strchr(Config->ServerName,'.')) + { + log(DEFAULT,"WARNING: '%s' is not a fully-qualified domain name. Changed to '%s%c'",Config->ServerName,Config->ServerName,'.'); + strlcat(Config->ServerName,".",MAXBUF); + } if (!Config->dns_timeout) Config->dns_timeout = 5; if (!Config->MaxConn) Config->MaxConn = SOMAXCONN; if (!*Config->DNSServer) - strlcpy(Config->DNSServer,"127.0.0.1",MAXBUF); + { + // attempt to look up their nameserver from /etc/resolv.conf + log(DEFAULT,"WARNING: not defined, attempting to find working server in /etc/resolv.conf..."); + ifstream resolv("/etc/resolv.conf"); + std::string nameserver; + bool found_server = false; + if (resolv.is_open()) + { + while (resolv >> nameserver) + { + if ((nameserver == "nameserver") && (!found_server)) + { + resolv >> nameserver; + strlcpy(Config->DNSServer,nameserver.c_str(),MAXBUF); + found_server = true; + log(DEFAULT," set to '%s' as first resolver in /etc/resolv.conf.",nameserver.c_str()); + } + } + if (!found_server) + { + log(DEFAULT,"/etc/resolv.conf contains no viable nameserver entries! Defaulting to nameserver '127.0.0.1'!"); + strlcpy(Config->DNSServer,"127.0.0.1",MAXBUF); + } + } + else + { + log(DEFAULT,"/etc/resolv.conf can't be opened! Defaulting to nameserver '127.0.0.1'!"); + strlcpy(Config->DNSServer,"127.0.0.1",MAXBUF); + } + } if (!*Config->ModPath) strlcpy(Config->ModPath,MOD_PATH,MAXBUF); Config->AllowHalfop = ((!strcasecmp(AH,"true")) || (!strcasecmp(AH,"1")) || (!strcasecmp(AH,"yes"))); @@ -327,6 +373,12 @@ void ServerConfig::Read(bool bail, userrec* user) { c.threshold = atoi(thold); } + else + { + c.threshold = 1; + c.flood = 999; + log(DEFAULT,"Warning: Connect allow line '%s' has no flood/threshold settings. Setting this tag to 999 lines in 1 second.",c.host.c_str()); + } if (atoi(sqmax)>0) { c.sendqmax = atoi(sqmax); @@ -417,12 +469,14 @@ void ServerConfig::Read(bool bail, userrec* user) if (ServerInstance->UnloadModule(removing->c_str())) { WriteOpers("*** REHASH UNLOADED MODULE: %s",removing->c_str()); - WriteServ(user->fd,"973 %s %s :Module %s successfully unloaded.",user->nick, removing->c_str(), removing->c_str()); + if (user) + WriteServ(user->fd,"973 %s %s :Module %s successfully unloaded.",user->nick, removing->c_str(), removing->c_str()); rem++; } else { - WriteServ(user->fd,"972 %s %s :Failed to unload module %s: %s",user->nick, removing->c_str(), removing->c_str(), ServerInstance->ModuleError()); + if (user) + WriteServ(user->fd,"972 %s %s :Failed to unload module %s: %s",user->nick, removing->c_str(), removing->c_str(), ServerInstance->ModuleError()); } } if (!added_modules.empty()) @@ -431,12 +485,14 @@ void ServerConfig::Read(bool bail, userrec* user) if (ServerInstance->LoadModule(adding->c_str())) { WriteOpers("*** REHASH LOADED MODULE: %s",adding->c_str()); - WriteServ(user->fd,"975 %s %s :Module %s successfully loaded.",user->nick, adding->c_str(), adding->c_str()); + if (user) + WriteServ(user->fd,"975 %s %s :Module %s successfully loaded.",user->nick, adding->c_str(), adding->c_str()); add++; } else { - WriteServ(user->fd,"974 %s %s :Failed to load module %s: %s",user->nick, adding->c_str(), adding->c_str(), ServerInstance->ModuleError()); + if (user) + WriteServ(user->fd,"974 %s %s :Failed to load module %s: %s",user->nick, adding->c_str(), adding->c_str(), ServerInstance->ModuleError()); } } log(DEFAULT,"Successfully unloaded %lu of %lu modules and loaded %lu of %lu modules.",(unsigned long)rem,(unsigned long)removed_modules.size(), @@ -596,11 +652,11 @@ std::string ServerConfig::ConfProcess(char* buffer, long linenumber, std::string return ""; } // firstly clean up the line by stripping spaces from the start and end and converting tabs to spaces - for (unsigned int d = 0; d < strlen(buffer); d++) - if ((buffer[d]) == 9) - buffer[d] = ' '; - while ((buffer[0] == ' ') && (strlen(buffer)>0)) buffer++; - while ((buffer[strlen(buffer)-1] == ' ') && (strlen(buffer)>0)) buffer[strlen(buffer)-1] = '\0'; + for (char* d = buffer; *d; d++) + if (*d == 9) + *d = ' '; + while (*buffer == ' ') buffer++; + while ((buffer[strlen(buffer)-1] == ' ') && (*buffer)) buffer[strlen(buffer)-1] = '\0'; // empty lines are syntactically valid, as are comments if (!(*buffer) || buffer[0] == '#') @@ -768,7 +824,7 @@ bool ServerConfig::LoadConf(const char* filename, std::stringstream *target, std break; } } - log(DEFAULT,"Opening included file '%s'",buf); + log(DEBUG,"Opening included file '%s'",buf); if (*buf != '/') { strlcpy(confpath,CONFIG_FILE,10240);