]> 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 062b45eb64f7978da08331ec088aa198f353edd3..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>
@@ -27,23 +27,27 @@ using namespace std;
 #include <fstream>
 #include "inspircd.h"
 #include "inspircd_io.h"
-#include "inspircd_util.h"
 #include "inspstring.h"
 #include "helperfuncs.h"
+#include "userprocess.h"
 #include "xline.h"
 
 extern ServerConfig *Config;
+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;
@@ -63,6 +67,82 @@ void ServerConfig::ClearStack()
        include_stack.clear();
 }
 
+Module* ServerConfig::GetIOHook(int port)
+{
+       std::map<int,Module*>::iterator x = IOHookModule.find(port);
+       return (x != IOHookModule.end() ? x->second : NULL);
+}
+
+bool ServerConfig::AddIOHook(int port, Module* iomod)
+{
+       if (!GetIOHook(port))
+       {
+               IOHookModule[port] = iomod;
+               return true;
+       }
+       return false;
+}
+
+bool ServerConfig::DelIOHook(int port)
+{
+       std::map<int,Module*>::iterator x = IOHookModule.find(port);
+       if (x != IOHookModule.end())
+       {
+               IOHookModule.erase(x);
+               return true;
+       }
+       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)
 {
@@ -106,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);
@@ -131,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))
@@ -185,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);
@@ -195,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);
@@ -231,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());
                 }
 
         }
@@ -297,7 +388,7 @@ void ServerConfig::Read(bool bail, userrec* user)
                 if (!removed_modules.empty())
                 for (std::vector<std::string>::iterator removing = removed_modules.begin(); removing != removed_modules.end(); removing++)
                 {
-                        if (UnloadModule(removing->c_str()))
+                        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());
@@ -305,13 +396,13 @@ void ServerConfig::Read(bool bail, userrec* user)
                         }
                         else
                         {
-                                WriteServ(user->fd,"972 %s %s :Failed to unload module %s: %s",user->nick, removing->c_str(), removing->c_str(), ModuleError());
+                                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())
                 for (std::vector<std::string>::iterator adding = added_modules.begin(); adding != added_modules.end(); adding++)
                 {
-                        if (LoadModule(adding->c_str()))
+                        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());
@@ -319,7 +410,7 @@ void ServerConfig::Read(bool bail, userrec* user)
                         }
                         else
                         {
-                                WriteServ(user->fd,"974 %s %s :Failed to load module %s: %s",user->nick, adding->c_str(), adding->c_str(), ModuleError());
+                                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(),
@@ -328,8 +419,6 @@ void ServerConfig::Read(bool bail, userrec* user)
 }
 
 
-void WriteOpers(char* text, ...);
-
 void Exit (int status)
 {
        if (Config->log_file)
@@ -346,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(""));
 }
 
 
@@ -380,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)
@@ -649,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))
@@ -912,18 +1016,18 @@ 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
                                                {
                                                        key+=strlen(var);
-                                                       while (key[0] !='"')
+                                                       while (*key !='"')
                                                        {
-                                                               if (!strlen(key))
+                                                               if (!*key)
                                                                {
                                                                        /* missing quote */
-                                                                       strcpy(result,"");
+                                                                       *result = 0;
                                                                        return 0;
                                                                }
                                                                key++;
@@ -961,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;
 }
 
@@ -1028,7 +1132,7 @@ int BindPorts()
         char configToken[MAXBUF], Addr[MAXBUF], Type[MAXBUF];
        sockaddr_in client,server;
         int clientportcount = 0;
-       int BoundPortCount;
+       int BoundPortCount = 0;
         for (int count = 0; count < Config->ConfValueEnum("bind",&Config->config_f); count++)
         {
                 Config->ConfValue("bind","port",count,configToken,&Config->config_f);