]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd_io.cpp
Made <disabled> non-manditory, added check for when singular tags arent defined at all
[user/henk/code/inspircd.git] / src / inspircd_io.cpp
index aa6c8e33a3203512dccd03bf978427a41ba536cc..3716057aff3bb559a1088c65891f421e7f33fef9 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
+ *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
  *                       E-mail:
  *                <brain@chatspike.net>
  *               <Craig@chatspike.net>
@@ -29,6 +29,7 @@ using namespace std;
 #include "inspircd_io.h"
 #include "inspstring.h"
 #include "helperfuncs.h"
+#include "userprocess.h"
 #include "xline.h"
 
 extern ServerConfig *Config;
@@ -36,14 +37,17 @@ extern InspIRCd* ServerInstance;
 extern int openSockfd[MAXSOCKS];
 extern time_t TIME;
 
+extern int MODCOUNT;
+extern std::vector<Module*> modules;
+extern std::vector<ircd_module*> factory;
 
 ServerConfig::ServerConfig()
 {
        this->ClearStack();
        *ServerName = *Network = *ServerDesc = *AdminName = '\0';
        *AdminEmail = *AdminNick = *diepass = *restartpass = '\0';
-       *motd = *rules = *PrefixQuit = *DieValue = *DNSServer = '\0';
-       *ModPath = *MyExecutable = *DisabledCommands = *PID = '\0';
+       *CustomVersion = *motd = *rules = *PrefixQuit = *DieValue = *DNSServer = '\0';
+       *OperOnlyStats = *ModPath = *MyExecutable = *DisabledCommands = *PID = '\0';
        log_file = NULL;
        nofork = false;
        unlimitcore = false;
@@ -90,6 +94,56 @@ bool ServerConfig::DelIOHook(int port)
        return false;
 }
 
+bool ServerConfig::CheckOnce(char* tag, bool bail, userrec* user)
+{
+       int count = ConfValueEnum(tag,&Config->config_f);
+       if (count > 1)
+       {
+               if (bail)
+               {
+                       printf("There were errors in your configuration:\nYou have more than one <%s> tag, this is not permitted.\n",tag);
+                       Exit(0);
+               }
+               else
+               {
+                       if (user)
+                       {
+                               WriteServ(user->fd,"There were errors in your configuration:");
+                               WriteServ(user->fd,"You have more than one <%s> tag, this is not permitted.\n",tag);
+                       }
+                       else
+                       {
+                               WriteOpers("There were errors in the configuration file:");
+                               WriteOpers("You have more than one <%s> tag, this is not permitted.\n",tag);
+                       }
+               }
+               return false;
+       }
+       if (count < 1)
+       {
+               if (bail)
+               {
+                       printf("There were errors in your configuration:\nYou have not defined a <%s> tag, this is required.",tag);
+                       Exit(0);
+               }
+               else
+               {
+                       if (user)
+                       {
+                               WriteServ(user->fd,"There were errors in your configuration:");
+                               WriteServ(user->fd,"You have not defined a <%s> tag, this is required.",tag);
+                       }
+                       else
+                       {
+                               WriteOpers("There were errors in the configuration file:");
+                               WriteOpers("You have not defined a <%s> tag, this is required.",tag);
+                       }
+               }
+               return false;
+       }
+       return true;
+}
+
 void ServerConfig::Read(bool bail, userrec* user)
 {
         char dbg[MAXBUF],pauseval[MAXBUF],Value[MAXBUF],timeout[MAXBUF],NB[MAXBUF],flood[MAXBUF],MW[MAXBUF],MCON[MAXBUF];
@@ -132,6 +186,15 @@ 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))
+       {
+               return;
+       }
+
         ConfValue("server","name",0,Config->ServerName,&Config->config_f);
         ConfValue("server","description",0,Config->ServerDesc,&Config->config_f);
         ConfValue("server","network",0,Config->Network,&Config->config_f);
@@ -157,6 +220,8 @@ void ServerConfig::Read(bool bail, userrec* user)
         ConfValue("disabled","commands",0,Config->DisabledCommands,&Config->config_f);
         ConfValue("options","somaxconn",0,MCON,&Config->config_f);
         ConfValue("options","softlimit",0,SLIMT,&Config->config_f);
+       ConfValue("options","operonlystats",0,Config->OperOnlyStats,&Config->config_f);
+       ConfValue("options","customversion",0,Config->CustomVersion,&Config->config_f);
 
         Config->SoftLimit = atoi(SLIMT);
         if ((Config->SoftLimit < 1) || (Config->SoftLimit > MAXCLIENTS))
@@ -211,7 +276,7 @@ void ServerConfig::Read(bool bail, userrec* user)
         Classes.clear();
         for (int i = 0; i < ConfValueEnum("connect",&Config->config_f); i++)
         {
-                strcpy(Value,"");
+                *Value = 0;
                 ConfValue("connect","allow",i,Value,&Config->config_f);
                 ConfValue("connect","timeout",i,timeout,&Config->config_f);
                 ConfValue("connect","flood",i,flood,&Config->config_f);
@@ -221,11 +286,11 @@ void ServerConfig::Read(bool bail, userrec* user)
                 ConfValue("connect","recvq",i,rqmax,&Config->config_f);
                 if (*Value)
                 {
-                        strlcpy(c.host,Value,MAXBUF);
+                        c.host = Value;
                         c.type = CC_ALLOW;
                         strlcpy(Value,"",MAXBUF);
                         ConfValue("connect","password",i,Value,&Config->config_f);
-                        strlcpy(c.pass,Value,MAXBUF);
+                        c.pass = Value;
                         c.registration_timeout = 90; // default is 2 minutes
                         c.pingtime = 120;
                         c.flood = atoi(flood);
@@ -257,10 +322,10 @@ void ServerConfig::Read(bool bail, userrec* user)
                 else
                 {
                         ConfValue("connect","deny",i,Value,&Config->config_f);
-                        strlcpy(c.host,Value,MAXBUF);
+                        c.host = Value;
                         c.type = CC_DENY;
                         Classes.push_back(c);
-                        log(DEBUG,"Read connect class type DENY, host=%s",c.host);
+                        log(DEBUG,"Read connect class type DENY, host=%s",c.host.c_str());
                 }
 
         }
@@ -370,10 +435,21 @@ void Killed(int status)
        exit(status);
 }
 
+char* CleanFilename(char* name)
+{
+       char* p = name + strlen(name);
+       while ((p != name) && (*p != '/')) p--;
+       return (p != name ? ++p : p);
+}
+
+
 void Rehash(int status)
 {
-       WriteOpers("Rehashing config file %s due to SIGHUP",CONFIG_FILE);
+       WriteOpers("Rehashing config file %s due to SIGHUP",CleanFilename(CONFIG_FILE));
+       fclose(Config->log_file);
+       OpenLog(NULL,0);
        Config->Read(false,NULL);
+       FOREACH_MOD(I_OnRehash,OnRehash(""));
 }
 
 
@@ -404,15 +480,19 @@ void WritePID(std::string filename)
        }
 }
 
-
-int DaemonSeed (void)
+void SetSignals()
 {
-       int childpid;
        signal (SIGALRM, SIG_IGN);
        signal (SIGHUP, Rehash);
        signal (SIGPIPE, SIG_IGN);
        signal (SIGTERM, Exit);
        signal (SIGSEGV, Error);
+}
+
+
+int DaemonSeed (void)
+{
+       int childpid;
        if ((childpid = fork ()) < 0)
                return (ERROR);
        else if (childpid > 0)
@@ -673,7 +753,7 @@ bool ServerConfig::LoadConf(const char* filename, std::stringstream *target, std
                                                                }
                                                                snprintf(newconf,10240,"%s/%s",confpath,buf);
                                                        }
-                                                       else snprintf(newconf,10240,"%s",buf);
+                                                       else strlcpy(newconf,buf,10240);
                                                        std::stringstream merge(stringstream::in | stringstream::out);
                                                        // recursively call LoadConf and get the new data, use the same errorstream
                                                        if (LoadConf(newconf, &merge, errorstream))
@@ -936,7 +1016,7 @@ int ServerConfig::ReadConf(std::stringstream *config, const char* tag, const cha
                                                if (!key)
                                                {
                                                        /* value not found in tag */
-                                                       strcpy(result,"");
+                                                       *result = 0;
                                                        return 0;
                                                }
                                                else
@@ -947,7 +1027,7 @@ int ServerConfig::ReadConf(std::stringstream *config, const char* tag, const cha
                                                                if (!*key)
                                                                {
                                                                        /* missing quote */
-                                                                       strcpy(result,"");
+                                                                       *result = 0;
                                                                        return 0;
                                                                }
                                                                key++;
@@ -985,7 +1065,7 @@ int ServerConfig::ReadConf(std::stringstream *config, const char* tag, const cha
                        }
                }
        }
-       strcpy(result,""); // value or its tag not found at all
+       *result = 0; // value or its tag not found at all
        return 0;
 }