]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/configreader.cpp
Change for reverse output of lists, most recent first, for bug #307. Also fix(Oms...
[user/henk/code/inspircd.git] / src / configreader.cpp
index dbed24ae567e2f8e910c25bcc436410848530471..5ec60d1c31beb187cfe0474b0a9bba5226259e8a 100644 (file)
  * ---------------------------------------------------
  */
 
+#include "inspircd.h"
 #include "configreader.h"
 #include <sstream>
 #include <fstream>
-#include "inspircd.h"
 #include "xline.h"
 #include "exitcodes.h"
 #include "commands/cmd_whowas.h"
@@ -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);
@@ -221,10 +221,16 @@ bool ValidateDnsServer(ServerConfig* conf, const char* tag, const char* value, V
 {
        if (!*(data.GetString()))
        {
+               std::string nameserver;
+#ifdef WINDOWS
+               conf->GetInstance()->Log(DEFAULT,"WARNING: <dns:server> not defined, attempting to find working server in the registry...");
+               nameserver = FindNameServerWin();
+               data.Set(nameserver.c_str());
+               conf->GetInstance()->Log(DEFAULT,"<dns:server> set to '%s' as first active resolver in registry.", nameserver.c_str());
+#else
                // attempt to look up their nameserver from /etc/resolv.conf
                conf->GetInstance()->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())
@@ -251,6 +257,7 @@ bool ValidateDnsServer(ServerConfig* conf, const char* tag, const char* value, V
                        conf->GetInstance()->Log(DEFAULT,"/etc/resolv.conf can't be opened! Defaulting to nameserver '127.0.0.1'!");
                        data.Set("127.0.0.1");
                }
+#endif
        }
        return true;
 }
@@ -333,6 +340,22 @@ bool ValidateRules(ServerConfig* conf, const char* tag, const char* value, Value
        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 ValidateExemptChanOps(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
+{
+       memset(conf->ExemptChanOps, 0, 256);
+       for (const unsigned char* x = (const unsigned char*)data.GetString(); *x; ++x)
+               conf->ExemptChanOps[*x] = true;
+       return true;
+}
+
 bool ValidateWhoWas(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
 {
        conf->WhoWasMaxKeep = conf->GetInstance()->Duration(data.GetString());
@@ -558,6 +581,8 @@ 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 */
+       static char exemptchanops[MAXBUF];      /* Exempt channel ops from these modes */
        int rem = 0, add = 0;           /* Number of modules added, number of modules removed */
        std::ostringstream errstr;      /* String stream containing the error output */
 
@@ -595,6 +620,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},
@@ -602,6 +628,8 @@ 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},
+               {"options",     "exemptchanops","",                     new ValueContainerChar (exemptchanops),                 DT_CHARPTR, ValidateExemptChanOps},
                {"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},
@@ -835,12 +863,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++)
                        {
@@ -1517,6 +1545,10 @@ char* ServerConfig::CleanFilename(char* name)
 
 bool ServerConfig::DirValid(const char* dirandfile)
 {
+#ifdef WINDOWS
+       return true;
+#endif
+
        char work[1024];
        char buffer[1024];
        char otherdir[1024];
@@ -1555,7 +1587,6 @@ bool ServerConfig::DirValid(const char* dirandfile)
        if (strlen(otherdir) >= t)
        {
                otherdir[t] = '\0';
-
                if (!strcmp(otherdir,work))
                {
                        return true;
@@ -1569,42 +1600,28 @@ bool ServerConfig::DirValid(const char* dirandfile)
        }
 }
 
-std::string ServerConfig::GetFullProgDir(char** argv, int argc)
+std::string ServerConfig::GetFullProgDir()
 {
-       char work[1024];
-       char buffer[1024];
-       char otherdir[1024];
-       int p;
-
-       strlcpy(work,argv[0],1024);
-       p = strlen(work);
+       char buffer[PATH_MAX+1];
 
-       // we just want the dir
-       while (*work)
+       // Get the current working directory
+       if (getcwd(buffer, PATH_MAX))
        {
-               if (work[p] == '/')
+               std::string remainder = this->argv[0];
+
+               /* Does argv[0] start with /? its a full path, use it */
+               if (remainder[0] == '/')
                {
-                       work[p] = '\0';
-                       break;
+                       std::string::size_type n = remainder.rfind("/inspircd");
+                       return std::string(remainder, 0, n);
                }
 
-               work[p--] = '\0';
+               std::string fullpath = std::string(buffer) + "/" + remainder;
+               std::string::size_type n = fullpath.rfind("/inspircd");
+               return std::string(fullpath, 0, n);
        }
 
-       // Get the current working directory
-       if (getcwd(buffer, 1024) == NULL)
-               return "";
-
-       if (chdir(work) == -1)
-               return "";
-
-       if (getcwd(otherdir, 1024) == NULL)
-               return "";
-
-       if (chdir(buffer) == -1)
-               return "";
-
-       return otherdir;
+       return "/";
 }
 
 InspIRCd* ServerConfig::GetInstance()