]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd_io.cpp
Decide that it wasn't quite appropriate :(
[user/henk/code/inspircd.git] / src / inspircd_io.cpp
index 7630eddceebaceee5db24f8417c4b159694181a9..aee8abe88d2ecc57c1814a71091a4f1aa50dadbd 100644 (file)
@@ -44,7 +44,7 @@ extern std::vector<ircd_module*> 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: <server:name> '%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: <dns:server> 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,"<dns:server> 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);
@@ -600,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] == '#')
@@ -772,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);