]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/configreader.cpp
Refactor port binding, warning not yet tested fully
[user/henk/code/inspircd.git] / src / configreader.cpp
index 315c1eb082ccacefa16c77a2d28938c797dcb152..1bc530b9b3c21f857bbe32fc8f104b7677c146de 100644 (file)
@@ -25,7 +25,7 @@ ServerConfig::ServerConfig(InspIRCd* Instance) : ServerInstance(Instance)
 {
        this->ClearStack();
        *ServerName = *Network = *ServerDesc = *AdminName = '\0';
-       *HideWhoisServer = *AdminEmail = *AdminNick = *diepass = *restartpass = *FixedQuit = '\0';
+       *HideWhoisServer = *AdminEmail = *AdminNick = *diepass = *restartpass = *FixedQuit = *HideKillsServer = '\0';
        *CustomVersion = *motd = *rules = *PrefixQuit = *DieValue = *DNSServer = '\0';
        *UserStats = *ModPath = *MyExecutable = *DisabledCommands = *PID = *SuffixQuit = '\0';
        WhoWasGroupSize = WhoWasMaxGroups = WhoWasMaxKeep = 0;
@@ -202,13 +202,13 @@ bool InitializeDisabledCommands(const char* data, InspIRCd* ServerInstance)
        std::string thiscmd;
 
        /* Enable everything first */
-       for (nspace::hash_map<std::string,command_t*>::iterator x = ServerInstance->Parser->cmdlist.begin(); x != ServerInstance->Parser->cmdlist.end(); x++)
+       for (command_table::iterator x = ServerInstance->Parser->cmdlist.begin(); x != ServerInstance->Parser->cmdlist.end(); x++)
                x->second->Disable(false);
 
        /* Now disable all the ones which the user wants disabled */
        while (dcmds >> thiscmd)
        {
-               nspace::hash_map<std::string,command_t*>::iterator cm = ServerInstance->Parser->cmdlist.find(thiscmd);
+               command_table::iterator cm = ServerInstance->Parser->cmdlist.find(thiscmd);
                if (cm != ServerInstance->Parser->cmdlist.end())
                {
                        cm->second->Disable(true);
@@ -320,12 +320,27 @@ bool ValidateMotd(ServerConfig* conf, const char* tag, const char* value, ValueI
        return true;
 }
 
+bool ValidateNotEmpty(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
+{
+       if (!*data.GetString())
+               throw CoreException(std::string("The value for ")+tag+" cannot be empty!");
+       return true;
+}
+
 bool ValidateRules(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
 {
        conf->ReadFile(conf->RULES, data.GetString());
        return true;
 }
 
+bool ValidateModeLists(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
+{
+       memset(conf->HideModeLists, 0, 256);
+       for (const unsigned char* x = (const unsigned char*)data.GetString(); *x; ++x)
+               conf->HideModeLists[*x] = true;
+       return true;
+}
+
 bool ValidateWhoWas(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
 {
        conf->WhoWasMaxKeep = conf->GetInstance()->Duration(data.GetString());
@@ -412,7 +427,8 @@ bool InitULine(ServerConfig* conf, const char* tag)
 bool DoULine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
 {
        const char* server = values[0].GetString();
-       conf->ulines.push_back(server);
+       const bool silent = values[1].GetBool();
+       conf->ulines[server] = silent;
        return true;
 }
 
@@ -550,6 +566,7 @@ void ServerConfig::Read(bool bail, userrec* user)
 {
        static char debug[MAXBUF];      /* Temporary buffer for debugging value */
        static char maxkeep[MAXBUF];    /* Temporary buffer for WhoWasMaxKeep value */
+       static char hidemodes[MAXBUF];  /* Modes to not allow listing from users below halfop */
        int rem = 0, add = 0;           /* Number of modules added, number of modules removed */
        std::ostringstream errstr;      /* String stream containing the error output */
 
@@ -568,9 +585,9 @@ void ServerConfig::Read(bool bail, userrec* user)
                {"admin",       "nick",         "Misconfigured",        new ValueContainerChar (this->AdminNick),               DT_CHARPTR, NoValidation},
                {"files",       "motd",         "",                     new ValueContainerChar (this->motd),                    DT_CHARPTR, ValidateMotd},
                {"files",       "rules",        "",                     new ValueContainerChar (this->rules),                   DT_CHARPTR, ValidateRules},
-               {"power",       "diepass",      "",                     new ValueContainerChar (this->diepass),                 DT_CHARPTR, NoValidation},
+               {"power",       "diepass",      "",                     new ValueContainerChar (this->diepass),                 DT_CHARPTR, ValidateNotEmpty},
                {"power",       "pause",        "",                     new ValueContainerInt  (&this->DieDelay),               DT_INTEGER, NoValidation},
-               {"power",       "restartpass",  "",                     new ValueContainerChar (this->restartpass),             DT_CHARPTR, NoValidation},
+               {"power",       "restartpass",  "",                     new ValueContainerChar (this->restartpass),             DT_CHARPTR, ValidateNotEmpty},
                {"options",     "prefixquit",   "",                     new ValueContainerChar (this->PrefixQuit),              DT_CHARPTR, NoValidation},
                {"options",     "suffixquit",   "",                     new ValueContainerChar (this->SuffixQuit),              DT_CHARPTR, NoValidation},
                {"options",     "fixedquit",    "",                     new ValueContainerChar (this->FixedQuit),               DT_CHARPTR, NoValidation},
@@ -587,6 +604,7 @@ void ServerConfig::Read(bool bail, userrec* user)
                {"options",     "hidesplits",   "0",                    new ValueContainerBool (&this->HideSplits),             DT_BOOLEAN, NoValidation},
                {"options",     "hidebans",     "0",                    new ValueContainerBool (&this->HideBans),               DT_BOOLEAN, NoValidation},
                {"options",     "hidewhois",    "",                     new ValueContainerChar (this->HideWhoisServer),         DT_CHARPTR, NoValidation},
+               {"options", "hidekills",    "",         new ValueContainerChar (this->HideKillsServer),     DT_CHARPTR, NoValidation},
                {"options",     "operspywhois", "0",                    new ValueContainerBool (&this->OperSpyWhois),           DT_BOOLEAN, NoValidation},
                {"options",     "nouserdns",    "0",                    new ValueContainerBool (&this->NoUserDns),              DT_BOOLEAN, NoValidation},
                {"options",     "syntaxhints",  "0",                    new ValueContainerBool (&this->SyntaxHints),            DT_BOOLEAN, NoValidation},
@@ -594,6 +612,7 @@ void ServerConfig::Read(bool bail, userrec* user)
                {"options",     "ircumsgprefix","0",                    new ValueContainerBool (&this->UndernetMsgPrefix),      DT_BOOLEAN, NoValidation},
                {"options",     "announceinvites", "1",                 new ValueContainerBool (&this->AnnounceInvites),        DT_BOOLEAN, NoValidation},
                {"options",     "hostintopic",  "1",                    new ValueContainerBool (&this->FullHostInTopic),        DT_BOOLEAN, NoValidation},
+               {"options",     "hidemodes",    "",                     new ValueContainerChar (hidemodes),                     DT_CHARPTR, ValidateModeLists},
                {"pid",         "file",         "",                     new ValueContainerChar (this->PID),                     DT_CHARPTR, NoValidation},
                {"whowas",      "groupsize",    "10",                   new ValueContainerInt  (&this->WhoWasGroupSize),        DT_INTEGER, NoValidation},
                {"whowas",      "maxgroups",    "10240",                new ValueContainerInt  (&this->WhoWasMaxGroups),        DT_INTEGER, NoValidation},
@@ -611,17 +630,19 @@ void ServerConfig::Read(bool bail, userrec* user)
 
                {"connect",
                                {"allow",       "deny",         "password",     "timeout",      "pingfreq",     "flood",
-                               "threshold",    "sendq",        "recvq",        "localmax",     "globalmax",    NULL},
+                               "threshold",    "sendq",        "recvq",        "localmax",     "globalmax",    "port",
+                               NULL},
                                {"",            "",             "",             "",             "120",          "",
-                                "",            "",             "",             "3",            "3",            NULL},
+                                "",            "",             "",             "3",            "3",            "0",
+                                NULL},
                                {DT_CHARPTR,    DT_CHARPTR,     DT_CHARPTR,     DT_INTEGER,     DT_INTEGER,     DT_INTEGER,
-                                DT_INTEGER,    DT_INTEGER,     DT_INTEGER,     DT_INTEGER,     DT_INTEGER},
+                                DT_INTEGER,    DT_INTEGER,     DT_INTEGER,     DT_INTEGER,     DT_INTEGER,     DT_INTEGER},
                                InitConnect, DoConnect, DoneConnect},
 
                {"uline",
-                               {"server",      NULL},
-                               {"",            NULL},
-                               {DT_CHARPTR},
+                               {"server",      "silent",       NULL},
+                               {"",            "0",            NULL},
+                               {DT_CHARPTR,    DT_BOOLEAN},
                                InitULine,DoULine,DoneULine},
 
                {"banlist",
@@ -682,7 +703,7 @@ void ServerConfig::Read(bool bail, userrec* user)
        /* Make a copy here so if it fails then we can carry on running with an unaffected config */
        ConfigDataHash newconfig;
 
-       if (this->LoadConf(newconfig, CONFIG_FILE, errstr))
+       if (this->LoadConf(newconfig, ServerInstance->ConfigFileName, errstr))
        {
                /* If we succeeded, set the ircd config to the new one */
                this->config_data = newconfig;
@@ -722,7 +743,8 @@ void ServerConfig::Read(bool bail, userrec* user)
                                case DT_CHARPTR:
                                {
                                        ValueContainerChar* vcc = (ValueContainerChar*)Values[Index].val;
-                                       vcc->Set(vi.GetString(), strlen(vi.GetString()));
+                                       /* Make sure we also copy the null terminator */
+                                       vcc->Set(vi.GetString(), strlen(vi.GetString()) + 1);
                                }
                                break;
                                case DT_INTEGER:
@@ -824,12 +846,12 @@ void ServerConfig::Read(bool bail, userrec* user)
        {
                int found_ports = 0;
                FailedPortList pl;
-               ServerInstance->stats->BoundPortCount = ServerInstance->BindPorts(false, found_ports, pl);
+               ServerInstance->BindPorts(false, found_ports, pl);
 
                if (pl.size())
                {
                        user->WriteServ("NOTICE %s :*** Not all your client ports could be bound.", user->nick);
-                       user->WriteServ("NOTICE %s :*** The following port%s failed to bind:", user->nick, found_ports - ServerInstance->stats->BoundPortCount != 1 ? "s" : "");
+                       user->WriteServ("NOTICE %s :*** The following port(s) failed to bind:", user->nick);
                        int j = 1;
                        for (FailedPortList::iterator i = pl.begin(); i != pl.end(); i++, j++)
                        {
@@ -1211,7 +1233,7 @@ bool ServerConfig::DoInclude(ConfigDataHash &target, const std::string &file, st
        std::string newfile;
        std::string::size_type pos;
 
-       confpath = CONFIG_FILE;
+       confpath = ServerInstance->ConfigFileName;
        newfile = file;
 
        for (std::string::iterator c = newfile.begin(); c != newfile.end(); c++)
@@ -1224,7 +1246,7 @@ bool ServerConfig::DoInclude(ConfigDataHash &target, const std::string &file, st
 
        if (file[0] != '/')
        {
-               if((pos = confpath.find("/inspircd.conf")) != std::string::npos)
+               if((pos = confpath.rfind("/")) != std::string::npos)
                {
                        /* Leaves us with just the path */
                        newfile = confpath.substr(0, pos) + std::string("/") + newfile;
@@ -1436,8 +1458,8 @@ bool ServerConfig::ReadFile(file_cache &F, const char* fname)
        if (*fname != '/')
        {
                std::string::size_type pos;
-               std::string confpath = CONFIG_FILE;
-               if((pos = confpath.find("/inspircd.conf")) != std::string::npos)
+               std::string confpath = ServerInstance->ConfigFileName;
+               if((pos = confpath.rfind("/")) != std::string::npos)
                {
                        /* Leaves us with just the path */
                        std::string newfile = confpath.substr(0, pos) + std::string("/") + fname;