diff options
author | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-10-17 02:14:44 +0000 |
---|---|---|
committer | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-10-17 02:14:44 +0000 |
commit | bf6724c049ba0f156544c49aab2008d6280e5ffa (patch) | |
tree | 0c56caccf906b87575dfefe52acc526f38c1fc81 | |
parent | 62a1eab66838294f2b88d5ea94c1678c167d6189 (diff) |
Rewrite ConfigReader again
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11879 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/configreader.h | 301 | ||||
-rw-r--r-- | include/inspircd.h | 16 | ||||
-rw-r--r-- | include/modules.h | 17 | ||||
-rw-r--r-- | include/typedefs.h | 4 | ||||
-rw-r--r-- | src/commands.cpp | 30 | ||||
-rw-r--r-- | src/commands/cmd_oper.cpp | 99 | ||||
-rw-r--r-- | src/configreader.cpp | 1344 | ||||
-rw-r--r-- | src/logger.cpp | 13 | ||||
-rw-r--r-- | src/modules.cpp | 41 | ||||
-rw-r--r-- | src/modules/m_httpd_config.cpp | 5 | ||||
-rw-r--r-- | src/socket.cpp | 25 | ||||
-rw-r--r-- | src/stats.cpp | 20 | ||||
-rw-r--r-- | src/users.cpp | 14 |
13 files changed, 513 insertions, 1416 deletions
diff --git a/include/configreader.h b/include/configreader.h index 61010d321..754d17379 100644 --- a/include/configreader.h +++ b/include/configreader.h @@ -29,34 +29,34 @@ class ServerLimits; class InspIRCd; class BufferedSocket; -/** A set of oper types +/** A cached text file stored with its contents as lines */ -typedef std::map<irc::string,std::string> opertype_t; +typedef std::vector<std::string> file_cache; -/** Holds an oper class. +/** A configuration key and value pair */ -struct operclass_data : public classbase +typedef std::pair<std::string, std::string> KeyVal; + +struct ConfigTag : public refcountbase { - /** Command list for the class - */ - std::string commandlist; + const std::string tag; + std::vector<KeyVal> items; - /** Channel mode list for the class - */ - std::string cmodelist; + ConfigTag(const std::string& Tag) : tag(Tag) {} - /** User mode list for the class - */ - std::string umodelist; + std::string getString(const std::string& key, const std::string& def = ""); + long getInt(const std::string& key, long def = 0); + double getFloat(const std::string& key, double def = 0); + bool getBool(const std::string& key, bool def = false); - /** Priviledges given by this class - */ - std::string privs; + bool readString(const std::string& key, std::string& value, bool allow_newline = false); }; -/** A Set of oper classes +/** An entire config file, built up of KeyValLists */ -typedef std::map<irc::string, operclass_data> operclass_t; +typedef std::multimap<std::string, reference<ConfigTag> > ConfigDataHash; + +typedef std::map<std::string, reference<ConfigTag> > TagIndex; /** Defines the server's length limits on various length-limited * items such as topics, nicknames, channel names etc. @@ -122,9 +122,6 @@ class CoreExport ServerConfig : public classbase */ std::vector<std::string> include_stack; - /* classes removed by this rehash */ - std::vector<ConnectClass*> removed_classes; - /** This private method processes one line of * configutation, appending errors to errorstream * and setting error if an error has occured. @@ -521,11 +518,11 @@ class CoreExport ServerConfig : public classbase /** All oper type definitions from the config file */ - opertype_t opertypes; + TagIndex opertypes; /** All oper class definitions from the config file */ - operclass_t operclass; + TagIndex operclass; /** Saved argv from startup */ @@ -582,9 +579,11 @@ class CoreExport ServerConfig : public classbase void Apply(ServerConfig* old, const std::string &useruid); void ApplyModules(User* user); + void Fill(); + /** Read a file into a file_cache object */ - bool ReadFile(file_cache &F, const char* fname); + bool ReadFile(file_cache &F, const std::string& fname); /* Returns true if the given string starts with a windows drive letter */ @@ -600,67 +599,7 @@ class CoreExport ServerConfig : public classbase */ bool LoadConf(FILE* &conf, const std::string &filename, bool allowexeinc); - /** Writes 'length' chars into 'result' as a string - */ - bool ConfValue(const char* tag, const char* var, int index, char* result, int length, bool allow_linefeeds = false); - - /** Writes 'length' chars into 'result' as a string - */ - bool ConfValue(const char* tag, const char* var, const char* default_value, int index, char* result, int length, bool allow_linefeeds = false); - - /** Writes 'length' chars into 'result' as a string - */ - bool ConfValue(const std::string &tag, const std::string &var, int index, std::string &result, bool allow_linefeeds = false); - - /** Writes 'length' chars into 'result' as a string - */ - bool ConfValue(const std::string &tag, const std::string &var, const std::string &default_value, int index, std::string &result, bool allow_linefeeds = false); - - /** Tries to convert the value to an integer and write it to 'result' - */ - bool ConfValueInteger(const char* tag, const char* var, int index, int &result); - - /** Tries to convert the value to an integer and write it to 'result' - */ - bool ConfValueInteger(const char* tag, const char* var, const char* default_value, int index, int &result); - - /** Tries to convert the value to an integer and write it to 'result' - */ - bool ConfValueInteger(const std::string &tag, const std::string &var, int index, int &result); - - /** Tries to convert the value to an integer and write it to 'result' - */ - bool ConfValueInteger(const std::string &tag, const std::string &var, const std::string &default_value, int index, int &result); - - /** Returns true if the value exists and has a true value, false otherwise - */ - bool ConfValueBool(const char* tag, const char* var, int index); - - /** Returns true if the value exists and has a true value, false otherwise - */ - bool ConfValueBool(const char* tag, const char* var, const char* default_value, int index); - - /** Returns true if the value exists and has a true value, false otherwise - */ - bool ConfValueBool(const std::string &tag, const std::string &var, int index); - - /** Returns true if the value exists and has a true value, false otherwise - */ - bool ConfValueBool(const std::string &tag, const std::string &var, const std::string &default_value, int index); - - /** Returns the number of occurences of tag in the config file - */ - int ConfValueEnum(const char* tag); - /** Returns the number of occurences of tag in the config file - */ - int ConfValueEnum(const std::string &tag); - - /** Returns the numbers of vars inside the index'th 'tag in the config file - */ - int ConfVarEnum(const char* tag, int index); - /** Returns the numbers of vars inside the index'th 'tag in the config file - */ - int ConfVarEnum(const std::string &tag, int index); + ConfigTag* ConfValue(const std::string& tag, int offset = 0); bool ApplyDisabledCommands(const std::string& data); @@ -681,196 +620,4 @@ class CoreExport ServerConfig : public classbase bool InvBypassModes; }; - - -/** Types of data in the core config - */ -enum ConfigDataType -{ - DT_NOTHING = 0, /* No data */ - DT_INTEGER = 1, /* Integer */ - DT_CHARPTR = 2, /* Char pointer */ - DT_BOOLEAN = 3, /* Boolean */ - DT_HOSTNAME = 4, /* Hostname syntax */ - DT_NOSPACES = 5, /* No spaces */ - DT_IPADDRESS = 6, /* IP address (v4, v6) */ - DT_CHANNEL = 7, /* Channel name */ - DT_LIMIT = 8, /* size_t */ - DT_ALLOW_WILD = 64, /* Allow wildcards/CIDR in DT_IPADDRESS */ - DT_ALLOW_NEWLINE = 128 /* New line characters allowed in DT_CHARPTR */ -}; - -/** The maximum number of values in a core configuration tag. Can be increased if needed. - */ -#define MAX_VALUES_PER_TAG 18 - -/** Holds a config value, either string, integer or boolean. - * Callback functions receive one or more of these, either on - * their own as a reference, or in a reference to a deque of them. - * The callback function can then alter the values of the ValueItem - * classes to validate the settings. - */ -class ValueItem -{ - /** Actual data */ - std::string v; - public: - /** Initialize with an int */ - ValueItem(int value); - /** Initialize with a bool */ - ValueItem(bool value); - /** Initialize with a string */ - ValueItem(const char* value) : v(value) { } - /** Change value to a string */ - void Set(const std::string &val); - /** Change value to an int */ - void Set(int value); - /** Get value as an int */ - int GetInteger(); - /** Get value as a string */ - const char* GetString() const; - /** Get value as a string */ - inline const std::string& GetValue() const { return v; } - /** Get value as a bool */ - bool GetBool(); -}; - -/** The base class of the container 'ValueContainer' - * used internally by the core to hold core values. - */ -class ValueContainerBase -{ - public: - /** Constructor */ - ValueContainerBase() { } - /** Destructor */ - virtual ~ValueContainerBase() { } -}; - -/** ValueContainer is used to contain pointers to different - * core values such as the server name, maximum number of - * clients etc. - * It is specialized to hold a data type, then pointed at - * a value in the ServerConfig class. When the value has been - * read and validated, the Set method is called to write the - * value safely in a type-safe manner. - */ -template<typename T> class ValueContainer : public ValueContainerBase -{ - T ServerConfig::* const vptr; - public: - /** Initialize with a value of type T */ - ValueContainer(T ServerConfig::* const offset) : vptr(offset) - { - } - - /** Change value to type T of size s */ - void Set(ServerConfig* conf, const T& value) - { - conf->*vptr = value; - } - - void Set(ServerConfig* conf, const ValueItem& item); -}; - -class ValueContainerLimit : public ValueContainerBase -{ - size_t ServerLimits::* const vptr; - public: - /** Initialize with a value of type T */ - ValueContainerLimit(size_t ServerLimits::* const offset) : vptr(offset) - { - } - - /** Change value to type T of size s */ - void Set(ServerConfig* conf, const size_t& value) - { - conf->Limits.*vptr = value; - } -}; - -/** A specialization of ValueContainer to hold a pointer to a bool - */ -typedef ValueContainer<bool> ValueContainerBool; - -/** A specialization of ValueContainer to hold a pointer to - * an unsigned int - */ -typedef ValueContainer<unsigned int> ValueContainerUInt; - -/** A specialization of ValueContainer to hold a pointer to - * a char array. - */ -typedef ValueContainer<std::string> ValueContainerString; - -/** A specialization of ValueContainer to hold a pointer to - * an int - */ -typedef ValueContainer<int> ValueContainerInt; - -/** A set of ValueItems used by multi-value validator functions - */ -typedef std::deque<ValueItem> ValueList; - -/** A callback for validating a single value - */ -typedef bool (*Validator)(ServerConfig* conf, const char*, const char*, ValueItem&); -/** A callback for validating multiple value entries - */ -typedef bool (*MultiValidator)(ServerConfig* conf, const char*, const char**, ValueList&, int*); -/** A callback indicating the end of a group of entries - */ -typedef bool (*MultiNotify)(ServerConfig* conf, const char*); - -/** Holds a core configuration item and its callbacks - */ -struct InitialConfig -{ - /** Tag name */ - const char* tag; - /** Value name */ - const char* value; - /** Default, if not defined */ - const char* default_value; - /** Value containers */ - ValueContainerBase* val; - /** Data types */ - int datatype; - /** Validation function */ - Validator validation_function; - ~InitialConfig(); -}; - -/** Represents a deprecated configuration tag. - */ -struct Deprecated -{ - /** Tag name - */ - const char* tag; - /** Tag value - */ - const char* value; - /** Reason for deprecation - */ - const char* reason; -}; - -/** Holds a core configuration item and its callbacks - * where there may be more than one item - */ -struct MultiConfig -{ - /** Tag name */ - const char* tag; - /** One or more items within tag */ - const char* items[MAX_VALUES_PER_TAG]; - /** One or more defaults for items within tags */ - const char* items_default[MAX_VALUES_PER_TAG]; - /** One or more data types */ - int datatype[MAX_VALUES_PER_TAG]; - /** Validation function */ - MultiValidator validation_function; -}; - #endif diff --git a/include/inspircd.h b/include/inspircd.h index 4fb28e2d7..93ba8bfa6 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -57,22 +57,6 @@ /** A list of failed port bindings, used for informational purposes on startup */ typedef std::vector<std::pair<std::string, std::string> > FailedPortList; -/** A cached text file stored with its contents as lines - */ -typedef std::deque< std::string > file_cache; - -/** A configuration key and value pair - */ -typedef std::pair< std::string, std::string > KeyVal; - -/** A list of related configuration keys and values - */ -typedef std::vector< KeyVal > KeyValList; - -/** An entire config file, built up of KeyValLists - */ -typedef std::multimap< std::string, KeyValList > ConfigDataHash; - class InspIRCd; CoreExport extern InspIRCd* ServerInstance; diff --git a/include/modules.h b/include/modules.h index 151c3fef8..4166af051 100644 --- a/include/modules.h +++ b/include/modules.h @@ -116,14 +116,9 @@ class ServerConfig; class Module; class InspIRCd; -/** Low level definition of a FileReader classes file cache area - - * a text file seperated into lines. - */ -typedef std::deque<std::string> file_cache; - /** A set of strings. */ -typedef file_cache string_list; +typedef std::vector<std::string> string_list; /** Holds a list of 'published features' for modules. */ @@ -1371,6 +1366,7 @@ class CoreExport ConfigReader : public classbase * A call to GetError() resets the error flag back to 0. */ long GetError(); + /** Counts the number of times a given tag appears in the config file. * This method counts the number of times a tag appears in a config file, for use where * there are several tags of the same kind, e.g. with opers and connect types. It can be @@ -1378,13 +1374,6 @@ class CoreExport ConfigReader : public classbase * multiple instance tag. */ int Enumerate(const std::string &tag); - - /** Returns the number of items within a tag. - * For example if the tag was <test tag="blah" data="foo"> then this - * function would return 2. Spaces and newlines both qualify as valid seperators - * between values. - */ - int EnumerateValues(const std::string &tag, int index); }; @@ -1398,7 +1387,7 @@ class CoreExport FileReader : public classbase { /** The file contents */ - file_cache fc; + std::vector<std::string> fc; /** Content size in bytes */ diff --git a/include/typedefs.h b/include/typedefs.h index fa4477f84..296c2efa5 100644 --- a/include/typedefs.h +++ b/include/typedefs.h @@ -27,9 +27,5 @@ #endif #endif -/** A cached text file stored line by line. - */ -typedef std::deque<std::string> file_cache; - #endif diff --git a/src/commands.cpp b/src/commands.cpp index db2074d87..1aeba2d80 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -21,15 +21,15 @@ bool InspIRCd::HostMatchesEveryone(const std::string &mask, User* user) { - char itrigger[MAXBUF]; long matches = 0; - if (!Config->ConfValue("insane","trigger", 0, itrigger, MAXBUF)) - strlcpy(itrigger,"95.5",MAXBUF); + ConfigTag* insane = Config->ConfValue("insane"); - if (Config->ConfValueBool("insane","hostmasks", 0)) + if (!insane || !insane->getBool("hostmasks")) return false; + float itrigger = insane->getFloat("trigger", 95.5); + for (user_hash::iterator u = this->Users->clientlist->begin(); u != this->Users->clientlist->end(); u++) { if ((InspIRCd::Match(u->second->MakeHost(), mask, ascii_case_insensitive_map)) || @@ -43,7 +43,7 @@ bool InspIRCd::HostMatchesEveryone(const std::string &mask, User* user) return false; float percent = ((float)matches / (float)this->Users->clientlist->size()) * 100; - if (percent > (float)atof(itrigger)) + if (percent > itrigger) { SNO->WriteToSnoMask('a', "\2WARNING\2: %s tried to set a G/K/E line mask of %s, which covers %.2f%% of the network!",user->nick.c_str(),mask.c_str(),percent); return true; @@ -53,15 +53,15 @@ bool InspIRCd::HostMatchesEveryone(const std::string &mask, User* user) bool InspIRCd::IPMatchesEveryone(const std::string &ip, User* user) { - char itrigger[MAXBUF]; long matches = 0; - if (!Config->ConfValue("insane","trigger",0,itrigger,MAXBUF)) - strlcpy(itrigger,"95.5",MAXBUF); + ConfigTag* insane = Config->ConfValue("insane"); - if (Config->ConfValueBool("insane","ipmasks",0)) + if (!insane || !insane->getBool("ipmasks")) return false; + float itrigger = insane->getFloat("trigger", 95.5); + for (user_hash::iterator u = this->Users->clientlist->begin(); u != this->Users->clientlist->end(); u++) { if (InspIRCd::Match(u->second->GetIPString(), ip, ascii_case_insensitive_map)) @@ -72,7 +72,7 @@ bool InspIRCd::IPMatchesEveryone(const std::string &ip, User* user) return false; float percent = ((float)matches / (float)this->Users->clientlist->size()) * 100; - if (percent > (float)atof(itrigger)) + if (percent > itrigger) { SNO->WriteToSnoMask('a', "\2WARNING\2: %s tried to set a Z line mask of %s, which covers %.2f%% of the network!",user->nick.c_str(),ip.c_str(),percent); return true; @@ -82,15 +82,15 @@ bool InspIRCd::IPMatchesEveryone(const std::string &ip, User* user) bool InspIRCd::NickMatchesEveryone(const std::string &nick, User* user) { - char itrigger[MAXBUF]; long matches = 0; - if (!Config->ConfValue("insane","trigger",0,itrigger,MAXBUF)) - strlcpy(itrigger,"95.5",MAXBUF); + ConfigTag* insane = Config->ConfValue("insane"); - if (Config->ConfValueBool("insane","nickmasks",0)) + if (!insane || !insane->getBool("nickmasks")) return false; + float itrigger = insane->getFloat("trigger", 95.5); + for (user_hash::iterator u = this->Users->clientlist->begin(); u != this->Users->clientlist->end(); u++) { if (InspIRCd::Match(u->second->nick, nick)) @@ -101,7 +101,7 @@ bool InspIRCd::NickMatchesEveryone(const std::string &nick, User* user) return false; float percent = ((float)matches / (float)this->Users->clientlist->size()) * 100; - if (percent > (float)atof(itrigger)) + if (percent > itrigger) { SNO->WriteToSnoMask('a', "\2WARNING\2: %s tried to set a Q line mask of %s, which covers %.2f%% of the network!",user->nick.c_str(),nick.c_str(),percent); return true; diff --git a/src/commands/cmd_oper.cpp b/src/commands/cmd_oper.cpp index da53d2b1a..683df9091 100644 --- a/src/commands/cmd_oper.cpp +++ b/src/commands/cmd_oper.cpp @@ -36,7 +36,7 @@ class CommandOper : public Command CmdResult Handle(const std::vector<std::string>& parameters, User *user); }; -bool OneOfMatches(const char* host, const char* ip, const char* hostlist) +bool OneOfMatches(const char* host, const char* ip, const std::string& hostlist) { std::stringstream hl(hostlist); std::string xhost; @@ -52,19 +52,10 @@ bool OneOfMatches(const char* host, const char* ip, const char* hostlist) CmdResult CommandOper::Handle (const std::vector<std::string>& parameters, User *user) { - char LoginName[MAXBUF]; - char Password[MAXBUF]; - char OperType[MAXBUF]; - char TypeName[MAXBUF]; - char HostName[MAXBUF]; - char ClassName[MAXBUF]; char TheHost[MAXBUF]; char TheIP[MAXBUF]; - char HashType[MAXBUF]; - int j; + std::string type; bool found = false; - bool type_invalid = false; - bool match_login = false; bool match_pass = false; bool match_hosts = false; @@ -72,74 +63,64 @@ CmdResult CommandOper::Handle (const std::vector<std::string>& parameters, User snprintf(TheHost,MAXBUF,"%s@%s",user->ident.c_str(),user->host.c_str()); snprintf(TheIP, MAXBUF,"%s@%s",user->ident.c_str(),user->GetIPString()); - for (int i = 0; i < ServerInstance->Config->ConfValueEnum("oper"); i++) + for (int i = 0;; i++) { - ServerInstance->Config->ConfValue("oper", "name", i, LoginName, MAXBUF); - ServerInstance->Config->ConfValue("oper", "password", i, Password, MAXBUF); - ServerInstance->Config->ConfValue("oper", "type", i, OperType, MAXBUF); - ServerInstance->Config->ConfValue("oper", "host", i, HostName, MAXBUF); - ServerInstance->Config->ConfValue("oper", "hash", i, HashType, MAXBUF); - - match_login = (LoginName == parameters[0]); - match_pass = !ServerInstance->PassCompare(user, Password, parameters[1], HashType); - match_hosts = OneOfMatches(TheHost,TheIP,HostName); + ConfigTag* tag = ServerInstance->Config->ConfValue("oper", i); + if (!tag) + break; + if (tag->getString("name") != parameters[0]) + continue; + match_login = true; + match_pass = !ServerInstance->PassCompare(user, tag->getString("password"), parameters[1], tag->getString("hash")); + match_hosts = OneOfMatches(TheHost,TheIP,tag->getString("host")); - if (match_login && match_pass && match_hosts) + if (match_pass && match_hosts) { - type_invalid = true; - for (j =0; j < ServerInstance->Config->ConfValueEnum("type"); j++) - { - ServerInstance->Config->ConfValue("type", "name", j, TypeName, MAXBUF); - ServerInstance->Config->ConfValue("type", "class", j, ClassName, MAXBUF); + type = tag->getString("type"); + ConfigTag* typeTag = ServerInstance->Config->opertypes[type]; - if (!strcmp(TypeName,OperType)) + if (typeTag) + { + /* found this oper's opertype */ + if (!ServerInstance->IsNick(type.c_str(), ServerInstance->Config->Limits.NickMax)) { - /* found this oper's opertype */ - if (!ServerInstance->IsNick(TypeName, ServerInstance->Config->Limits.NickMax)) - { - user->WriteNumeric(491, "%s :Invalid oper type (oper types must follow the same syntax as nicknames)",user->nick.c_str()); - ServerInstance->SNO->WriteToSnoMask('o',"CONFIGURATION ERROR! Oper type '%s' contains invalid characters",OperType); - ServerInstance->Logs->Log("OPER",DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: credentials valid, but oper type erroneous.", user->nick.c_str(), user->ident.c_str(), user->host.c_str()); - return CMD_FAILURE; - } - ServerInstance->Config->ConfValue("type","host", j, HostName, MAXBUF); - if (*HostName) - user->ChangeDisplayedHost(HostName); - if (*ClassName) - { - user->SetClass(ClassName); - user->CheckClass(); - } - found = true; - type_invalid = false; - break; + user->WriteNumeric(491, "%s :Invalid oper type (oper types must follow the same syntax as nicknames)",user->nick.c_str()); + ServerInstance->SNO->WriteToSnoMask('o',"CONFIGURATION ERROR! Oper type '%s' contains invalid characters",type.c_str()); + ServerInstance->Logs->Log("OPER",DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: credentials valid, but oper type erroneous.", user->nick.c_str(), user->ident.c_str(), user->host.c_str()); + return CMD_FAILURE; } + std::string host = typeTag->getString("host"); + if (!host.empty()) + user->ChangeDisplayedHost(host.c_str()); + std::string opClass = typeTag->getString("class"); + if (!opClass.empty()) + { + user->SetClass(opClass); + user->CheckClass(); + } + found = true; } } - if (match_login || found) - break; + break; } if (found) { /* correct oper credentials */ - user->Oper(OperType, LoginName); + user->Oper(type, parameters[0]); } else { char broadcast[MAXBUF]; - if (!type_invalid) + if (type.empty()) { std::string fields; if (!match_login) fields.append("login "); - else - { - if (!match_pass) - fields.append("password "); - if (!match_hosts) - fields.append("hosts"); - } + if (!match_pass) + fields.append("password "); + if (!match_hosts) + fields.append("hosts"); // tell them they suck, and lag them up to help prevent brute-force attacks user->WriteNumeric(491, "%s :Invalid oper credentials",user->nick.c_str()); @@ -156,7 +137,7 @@ CmdResult CommandOper::Handle (const std::vector<std::string>& parameters, User { user->WriteNumeric(491, "%s :Your oper block does not have a valid opertype associated with it",user->nick.c_str()); - snprintf(broadcast, MAXBUF, "CONFIGURATION ERROR! Oper block '%s': missing OperType %s",parameters[0].c_str(),OperType); + snprintf(broadcast, MAXBUF, "CONFIGURATION ERROR! Oper block '%s': missing OperType %s",parameters[0].c_str(),type.c_str()); ServerInstance->SNO->WriteToSnoMask('o', std::string(broadcast)); diff --git a/src/configreader.cpp b/src/configreader.cpp index d1fb5e197..6157b4d4b 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -32,6 +32,28 @@ #include "commands/cmd_whowas.h" #include "modes/cmode_h.h" +static void ReqRead(ServerConfig* src, const std::string& tag, const std::string& key, std::string& dest) +{ + ConfigTag* t = src->ConfValue(tag); + if (!t || !t->readString(key, dest)) + throw CoreException("You must specify a value for <" + tag + ":" + key + ">"); +} + +/** Represents a deprecated configuration tag. + */ +struct Deprecated +{ + /** Tag name + */ + const char* tag; + /** Tag value + */ + const char* value; + /** Reason for deprecation + */ + const char* reason; +}; + ServerConfig::ServerConfig() { WhoWasGroupSize = WhoWasMaxGroups = WhoWasMaxKeep = 0; @@ -85,32 +107,33 @@ void ServerConfig::Send005(User* user) user->WriteNumeric(RPL_ISUPPORT, "%s %s", user->nick.c_str(), line->c_str()); } -bool ServerConfig::CheckOnce(const char* tag) +template<typename T, typename V> +static void range(T& value, V min, V max, V def, const char* msg) { - int count = ConfValueEnum(tag); - - if (count > 1) - throw CoreException("You have more than one <"+std::string(tag)+"> tag, this is not permitted."); - if (count < 1) - throw CoreException("You have not defined a <"+std::string(tag)+"> tag, this is required."); - return true; + if (value >= (T)min && value <= (T)max) + return; + ServerInstance->Logs->Log("CONFIG", DEFAULT, + "WARNING: %s value of %ld is not between %ld and %ld; set to %ld.", + msg, (long)value, (long)min, (long)max, (long)def); + value = def; } -static void ValidateNoSpaces(const char* p, const std::string &tag, const std::string &val) +bool ServerConfig::CheckOnce(const char* tag) { - for (const char* ptr = p; *ptr; ++ptr) - { - if (*ptr == ' ') - throw CoreException("The value of <"+tag+":"+val+"> cannot contain spaces"); - } + if (!ConfValue(tag)) + throw CoreException("You have not defined a <"+std::string(tag)+"> tag, this is required."); + if (ConfValue(tag, 1)) + throw CoreException("You have more than one <"+std::string(tag)+"> tag, this is not permitted."); + return true; } /* NOTE: Before anyone asks why we're not using inet_pton for this, it is because inet_pton and friends do not return so much detail, * even in strerror(errno). They just return 'yes' or 'no' to an address without such detail as to whats WRONG with the address. * Because ircd users arent as technical as they used to be (;)) we are going to give more of a useful error message. */ -static void ValidateIP(const char* p, const std::string &tag, const std::string &val, bool wild) +static void ValidIP(const std::string& ip, const std::string& key) { + const char* p = ip.c_str(); int num_dots = 0; int num_seps = 0; int not_numbers = false; @@ -119,13 +142,10 @@ static void ValidateIP(const char* p, const std::string &tag, const std::string if (*p) { if (*p == '.') - throw CoreException("The value of <"+tag+":"+val+"> is not an IP address"); + throw CoreException("The value of "+key+" is not an IP address"); for (const char* ptr = p; *ptr; ++ptr) { - if (wild && (*ptr == '*' || *ptr == '?' || *ptr == '/')) - continue; - if (*ptr != ':' && *ptr != '.') { if (*ptr < '0' || *ptr > '9') @@ -136,7 +156,7 @@ static void ValidateIP(const char* p, const std::string &tag, const std::string switch (*ptr) { case ' ': - throw CoreException("The value of <"+tag+":"+val+"> is not an IP address"); + throw CoreException("The value of "+key+" is not an IP address"); case '.': num_dots++; break; @@ -147,77 +167,47 @@ static void ValidateIP(const char* p, const std::string &tag, const std::string } if (num_dots > 3) - throw CoreException("The value of <"+tag+":"+val+"> is an IPv4 address with too many fields!"); + throw CoreException("The value of "+key+" is an IPv4 address with too many fields!"); if (num_seps > 8) - throw CoreException("The value of <"+tag+":"+val+"> is an IPv6 address with too many fields!"); + throw CoreException("The value of "+key+" is an IPv6 address with too many fields!"); - if (num_seps == 0 && num_dots < 3 && !wild) - throw CoreException("The value of <"+tag+":"+val+"> looks to be a malformed IPv4 address"); + if (num_seps == 0 && num_dots < 3) + throw CoreException("The value of "+key+" looks to be a malformed IPv4 address"); if (num_seps == 0 && num_dots == 3 && not_numbers) - throw CoreException("The value of <"+tag+":"+val+"> contains non-numeric characters in an IPv4 address"); + throw CoreException("The value of "+key+" contains non-numeric characters in an IPv4 address"); if (num_seps != 0 && not_hex) - throw CoreException("The value of <"+tag+":"+val+"> contains non-hexdecimal characters in an IPv6 address"); + throw CoreException("The value of "+key+" contains non-hexdecimal characters in an IPv6 address"); - if (num_seps != 0 && num_dots != 3 && num_dots != 0 && !wild) - throw CoreException("The value of <"+tag+":"+val+"> is a malformed IPv6 4in6 address"); + if (num_seps != 0 && num_dots != 3 && num_dots != 0) + throw CoreException("The value of "+key+" is a malformed IPv6 4in6 address"); } } -static void ValidateHostname(const char* p, const std::string &tag, const std::string &val) +static void ValidHost(const std::string& p, const std::string& msg) { int num_dots = 0; - if (*p) + if (p.empty() || p[0] == '.') + throw CoreException("The value of "+msg+" is not a valid hostname"); + for (unsigned int i=0;i < p.length();i++) { - if (*p == '.') - throw CoreException("The value of <"+tag+":"+val+"> is not a valid hostname"); - for (const char* ptr = p; *ptr; ++ptr) + switch (p[i]) { - switch (*ptr) - { - case ' ': - throw CoreException("The value of <"+tag+":"+val+"> is not a valid hostname"); - case '.': - num_dots++; - break; - } + case ' ': + throw CoreException("The value of "+msg+" is not a valid hostname"); + case '.': + num_dots++; + break; } - if (num_dots == 0) - throw CoreException("The value of <"+tag+":"+val+"> is not a valid hostname"); } + if (num_dots == 0) + throw CoreException("The value of "+msg+" is not a valid hostname"); } // Specialized validators -static bool ValidateMaxTargets(ServerConfig* conf, const char*, const char*, ValueItem &data) -{ - if ((data.GetInteger() < 1) || (data.GetInteger() > 31)) - { - ServerInstance->Logs->Log("CONFIG",DEFAULT,"WARNING: <security:maxtargets> value is greater than 31 or less than 1, set to 20."); - data.Set(20); - } - return true; -} - -static bool ValidateSoftLimit(ServerConfig* conf, const char*, const char*, ValueItem &data) -{ - if ((data.GetInteger() < 1) || (data.GetInteger() > ServerInstance->SE->GetMaxFds())) - { - ServerInstance->Logs->Log("CONFIG",DEFAULT,"WARNING: <performance:softlimit> value is greater than %d or less than 0, set to %d.",ServerInstance->SE->GetMaxFds(),ServerInstance->SE->GetMaxFds()); - data.Set(ServerInstance->SE->GetMaxFds()); - } - return true; -} - -static bool ValidateMaxConn(ServerConfig* conf, const char*, const char*, ValueItem &data) -{ - if (data.GetInteger() > SOMAXCONN) - ServerInstance->Logs->Log("CONFIG",DEFAULT,"WARNING: <performance:somaxconn> value may be higher than the system-defined SOMAXCONN value!"); - return true; -} - bool ServerConfig::ApplyDisabledCommands(const std::string& data) { std::stringstream dcmds(data); @@ -239,348 +229,84 @@ bool ServerConfig::ApplyDisabledCommands(const std::string& data) return true; } -static bool ValidateDisabledUModes(ServerConfig* conf, const char*, const char*, ValueItem &data) -{ - memset(conf->DisabledUModes, 0, sizeof(conf->DisabledUModes)); - for (const unsigned char* p = (const unsigned char*)data.GetString(); *p; ++p) - { - if (*p < 'A' || *p > ('A' + 64)) throw CoreException(std::string("Invalid usermode ")+(char)*p+" was found."); - conf->DisabledUModes[*p - 'A'] = 1; - } - return true; -} - -static bool ValidateDisabledCModes(ServerConfig* conf, const char*, const char*, ValueItem &data) -{ - memset(conf->DisabledCModes, 0, sizeof(conf->DisabledCModes)); - for (const unsigned char* p = (const unsigned char*)data.GetString(); *p; ++p) - { - if (*p < 'A' || *p > ('A' + 64)) throw CoreException(std::string("Invalid chanmode ")+(char)*p+" was found."); - conf->DisabledCModes[*p - 'A'] = 1; - } - return true; -} - #ifdef WINDOWS // Note: the windows validator is in win32wrapper.cpp -bool ValidateDnsServer(ServerConfig* conf, const char*, const char*, ValueItem &data); +void ValidateDnsServer(std::string& server); #else -static bool ValidateDnsServer(ServerConfig* conf, const char*, const char*, ValueItem &data) -{ - if (!*(data.GetString())) - { - std::string nameserver; - // attempt to look up their nameserver from /etc/resolv.conf - ServerInstance->Logs->Log("CONFIG",DEFAULT,"WARNING: <dns:server> not defined, attempting to find working server in /etc/resolv.conf..."); - std::ifstream resolv("/etc/resolv.conf"); - bool found_server = false; - - if (resolv.is_open()) - { - while (resolv >> nameserver) - { - if ((nameserver == "nameserver") && (!found_server)) - { - resolv >> nameserver; - data.Set(nameserver.c_str()); - found_server = true; - ServerInstance->Logs->Log("CONFIG",DEFAULT,"<dns:server> set to '%s' as first resolver in /etc/resolv.conf.",nameserver.c_str()); - } - } - - if (!found_server) - { - ServerInstance->Logs->Log("CONFIG",DEFAULT,"/etc/resolv.conf contains no viable nameserver entries! Defaulting to nameserver '127.0.0.1'!"); - data.Set("127.0.0.1"); - } - } - else - { - ServerInstance->Logs->Log("CONFIG",DEFAULT,"/etc/resolv.conf can't be opened! Defaulting to nameserver '127.0.0.1'!"); - data.Set("127.0.0.1"); - } - } - return true; -} -#endif - -static bool ValidateServerName(ServerConfig* conf, const char*, const char*, ValueItem &data) -{ - ServerInstance->Logs->Log("CONFIG",DEFAULT,"Validating server name"); - /* If we already have a servername, and they changed it, we should throw an exception. */ - if (!strchr(data.GetString(), '.')) - { - ServerInstance->Logs->Log("CONFIG",DEFAULT,"WARNING: <server:name> '%s' is not a fully-qualified domain name. Changed to '%s.'", - data.GetString(),data.GetString()); - std::string moo = data.GetValue(); - data.Set(moo.append(".")); - } - ValidateHostname(data.GetString(), "server", "name"); - return true; -} - -static bool ValidateNetBufferSize(ServerConfig* conf, const char*, const char*, ValueItem &data) -{ - // 65534 not 65535 because of null terminator - if ((!data.GetInteger()) || (data.GetInteger() > 65534) || (data.GetInteger() < 1024)) - { - ServerInstance->Logs->Log("CONFIG",DEFAULT,"No NetBufferSize specified or size out of range, setting to default of 10240."); - data.Set(10240); - } - return true; -} - -static bool ValidateMaxWho(ServerConfig* conf, const char*, const char*, ValueItem &data) +static void ValidateDnsServer(std::string& server) { - if ((data.GetInteger() > 65535) || (data.GetInteger() < 1)) + if (!server.empty()) { - ServerInstance->Logs->Log("CONFIG",DEFAULT,"<performance:maxwho> size out of range, setting to default of 1024."); - data.Set(1024); - } - return true; -} - -static bool ValidateHalfOp(ServerConfig* conf, const char*, const char*, ValueItem &data) -{ - ModeHandler* mh = ServerInstance->Modes->FindMode('h', MODETYPE_CHANNEL); - if (data.GetBool() && !mh) { - ServerInstance->Logs->Log("CONFIG", DEFAULT, "Enabling halfop mode."); - mh = new ModeChannelHalfOp; - ServerInstance->Modes->AddMode(mh); - } else if (!data.GetBool() && mh) { - ServerInstance->Logs->Log("CONFIG", DEFAULT, "Disabling halfop mode."); - ServerInstance->Modes->DelMode(mh); - delete mh; + ValidIP(server, "<dns:server>"); + return; } - return true; -} - -static bool ValidateMotd(ServerConfig* conf, const char*, const char*, ValueItem &data) -{ - conf->ReadFile(conf->MOTD, data.GetString()); - return true; -} - -static bool ValidateNotEmpty(ServerConfig*, const char* tag, const char* val, ValueItem &data) -{ - if (data.GetValue().empty()) - throw CoreException(std::string("The value for <")+tag+":"+val+"> cannot be empty!"); - return true; -} - -static bool ValidateRules(ServerConfig* conf, const char*, const char*, ValueItem &data) -{ - conf->ReadFile(conf->RULES, data.GetString()); - return true; -} - -static bool ValidateModeLists(ServerConfig* conf, const char*, const char*, ValueItem &data) -{ - memset(conf->HideModeLists, 0, sizeof(conf->HideModeLists)); - for (const unsigned char* x = (const unsigned char*)data.GetString(); *x; ++x) - conf->HideModeLists[*x] = true; - return true; -} - -static bool ValidateInvite(ServerConfig* conf, const char*, const char*, ValueItem &data) -{ - const std::string& v = data.GetValue(); - - if (v == "ops") - conf->AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_OPS; - else if (v == "all") - conf->AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_ALL; - else if (v == "dynamic") - conf->AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_DYNAMIC; - else - conf->AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_NONE; - return true; -} + // attempt to look up their nameserver from /etc/resolv.conf + ServerInstance->Logs->Log("CONFIG",DEFAULT,"WARNING: <dns:server> not defined, attempting to find working server in /etc/resolv.conf..."); -static bool ValidateSID(ServerConfig* conf, const char*, const char*, ValueItem &data) -{ - ServerInstance->Logs->Log("CONFIG",DEFAULT,"Validating server id"); + std::ifstream resolv("/etc/resolv.conf"); - const std::string& sid = data.GetValue(); - - if (!sid.empty() && !ServerInstance->IsSID(sid)) + while (resolv >> server) { - throw CoreException(sid + " is not a valid server ID. A server ID must be 3 characters long, with the first character a digit and the next two characters a digit or letter."); + if (server == "nameserver") + { + resolv >> server; + ServerInstance->Logs->Log("CONFIG",DEFAULT,"<dns:server> set to '%s' as first resolver in /etc/resolv.conf.",server.c_str()); + return; + } } - conf->sid = sid; - - return true; + ServerInstance->Logs->Log("CONFIG",DEFAULT,"/etc/resolv.conf contains no viable nameserver entries! Defaulting to nameserver '127.0.0.1'!"); + server = "127.0.0.1"; } +#endif -static bool ValidateWhoWas(ServerConfig* conf, const char*, const char*, ValueItem &data) +static void ReadXLine(ServerConfig* conf, const std::string& tag, const std::string& key, XLineFactory* make) { - conf->WhoWasMaxKeep = ServerInstance->Duration(data.GetString()); - - if (conf->WhoWasGroupSize < 0) - conf->WhoWasGroupSize = 0; - - if (conf->WhoWasMaxGroups < 0) - conf->WhoWasMaxGroups = 0; - - if (conf->WhoWasMaxKeep < 3600) + for(int i=0;; ++i) { - conf->WhoWasMaxKeep = 3600; - ServerInstance->Logs->Log("CONFIG",DEFAULT,"WARNING: <whowas:maxkeep> value less than 3600, setting to default 3600"); + ConfigTag* ctag = conf->ConfValue(tag, i); + if (!ctag) + break; + std::string mask; + if (!ctag->readString(key, mask)) + throw CoreException("<"+tag+":"+key+"> missing"); + std::string reason = ctag->getString("reason", "<Config>"); + XLine* xl = make->Generate(ServerInstance->Time(), 0, "<Config>", reason, mask); + if (!ServerInstance->XLines->AddLine(xl, NULL)) + delete xl; } - - Module* whowas = ServerInstance->Modules->Find("cmd_whowas.so"); - if (whowas) - { - WhowasRequest(NULL, whowas, WhowasRequest::WHOWAS_PRUNE).Send(); - } - - return true; } -/* Callback called to process a single <uline> tag - */ -static bool DoULine(ServerConfig* conf, const char*, const char**, ValueList &values, int*) -{ - const char* server = values[0].GetString(); - const bool silent = values[1].GetBool(); - conf->ulines[server] = silent; - return true; -} - -/* Callback called to process a single <banlist> tag - */ -static bool DoMaxBans(ServerConfig* conf, const char*, const char**, ValueList &values, int*) -{ - const char* channel = values[0].GetString(); - int limit = values[1].GetInteger(); - conf->maxbans[channel] = limit; - return true; -} - -static bool DoZLine(ServerConfig* conf, const char* tag, const char** entries, ValueList &values, int* types) -{ - const char* reason = values[0].GetString(); - const char* ipmask = values[1].GetString(); - - ZLine* zl = new ZLine(ServerInstance->Time(), 0, "<Config>", reason, ipmask); - if (!ServerInstance->XLines->AddLine(zl, NULL)) - delete zl; - - return true; -} - -static bool DoQLine(ServerConfig* conf, const char* tag, const char** entries, ValueList &values, int* types) -{ - const char* reason = values[0].GetString(); - const char* nick = values[1].GetString(); - - QLine* ql = new QLine(ServerInstance->Time(), 0, "<Config>", reason, nick); - if (!ServerInstance->XLines->AddLine(ql, NULL)) - delete ql; - - return true; -} - -static bool DoKLine(ServerConfig* conf, const char* tag, const char** entries, ValueList &values, int* types) -{ - const char* reason = values[0].GetString(); - const char* host = values[1].GetString(); - - XLineManager* xlm = ServerInstance->XLines; - - IdentHostPair ih = xlm->IdentSplit(host); - - KLine* kl = new KLine(ServerInstance->Time(), 0, "<Config>", reason, ih.first.c_str(), ih.second.c_str()); - if (!xlm->AddLine(kl, NULL)) - delete kl; - return true; -} - -static bool DoELine(ServerConfig* conf, const char* tag, const char** entries, ValueList &values, int* types) -{ - const char* reason = values[0].GetString(); - const char* host = values[1].GetString(); - - XLineManager* xlm = ServerInstance->XLines; - - IdentHostPair ih = xlm->IdentSplit(host); - - ELine* el = new ELine(ServerInstance->Time(), 0, "<Config>", reason, ih.first.c_str(), ih.second.c_str()); - if (!xlm->AddLine(el, NULL)) - delete el; - return true; -} - -static bool DoType(ServerConfig* conf, const char*, const char**, ValueList &values, int*) -{ - const char* TypeName = values[0].GetString(); - const char* Classes = values[1].GetString(); - - conf->opertypes[TypeName] = std::string(Classes); - return true; -} - -static bool DoClass(ServerConfig* conf, const char* tag, const char**, ValueList &values, int*) +void ServerConfig::CrossCheckOperClassType() { - const char* ClassName = values[0].GetString(); - const char* CommandList = values[1].GetString(); - const char* UModeList = values[2].GetString(); - const char* CModeList = values[3].GetString(); - const char *PrivsList = values[4].GetString(); - - for (const char* c = UModeList; *c; ++c) + for (int i = 0;; ++i) { - if ((*c < 'A' || *c > 'z') && *c != '*') - { - throw CoreException("Character " + std::string(1, *c) + " is not a valid mode in <class:usermodes>"); - } + ConfigTag* tag = ConfValue("class", i); + if (!tag) + break; + std::string name = tag->getString("name"); + if (name.empty()) + throw CoreException("<class:name> is required for all <class> tags"); + operclass[name] = tag; } - for (const char* c = CModeList; *c; ++c) + for (int i = 0;; ++i) { - if ((*c < 'A' || *c > 'z') && *c != '*') - { - throw CoreException("Character " + std::string(1, *c) + " is not a valid mode in <class:chanmodes>"); - } - } + ConfigTag* tag = ConfValue("type", i); + if (!tag) + break; - conf->operclass[ClassName].commandlist = CommandList; - conf->operclass[ClassName].umodelist = UModeList; - conf->operclass[ClassName].cmodelist = CModeList; - conf->operclass[ClassName].privs = PrivsList; - return true; -} + std::string name = tag->getString("name"); + if (name.empty()) + throw CoreException("<type:name> is required for all <type> tags"); + opertypes[name] = tag; -void ServerConfig::CrossCheckOperClassType() -{ - for (int i = 0; i < ConfValueEnum("type"); ++i) - { - char item[MAXBUF], classn[MAXBUF], classes[MAXBUF]; std::string classname; - ConfValue("type", "classes", "", i, classes, MAXBUF, false); - irc::spacesepstream str(classes); - ConfValue("type", "name", "", i, item, MAXBUF, false); + irc::spacesepstream str(tag->getString("classes")); while (str.GetToken(classname)) { - std::string lost; - bool foundclass = false; - for (int j = 0; j < ConfValueEnum("class"); ++j) - { - ConfValue("class", "name", "", j, classn, MAXBUF, false); - if (!strcmp(classn, classname.c_str())) - { - foundclass = true; - break; - } - } - if (!foundclass) - { - char msg[MAXBUF]; - snprintf(msg, MAXBUF, " Warning: Oper type '%s' has a missing class named '%s', this does nothing!\n", - item, classname.c_str()); - throw CoreException(msg); - } + if (operclass.find(classname) == operclass.end()) + throw CoreException("Oper type " + name + " has missing class " + classname); } } } @@ -600,38 +326,41 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current) } } - int block_count = ConfValueEnum("connect"); ClassMap newBlocksByMask; - Classes.resize(block_count, NULL); std::map<std::string, int> names; bool try_again = true; - for(int tries=0; try_again && tries < block_count + 1; tries++) + for(int tries=0; try_again; tries++) { try_again = false; - for(int i=0; i < block_count; i++) + for(unsigned int i=0;; i++) { + ConfigTag* tag = ConfValue("connect", i); + if (!tag) + break; + if (Classes.size() <= i) + Classes.resize(i+1); if (Classes[i]) continue; ConnectClass* parent = NULL; - std::string parentName; - if (ConfValue("connect", "parent", i, parentName, false)) + std::string parentName = tag->getString("parent"); + if (!parentName.empty()) { std::map<std::string,int>::iterator parentIter = names.find(parentName); if (parentIter == names.end()) { try_again = true; // couldn't find parent this time. If it's the last time, we'll never find it. - if (tries == block_count) + if (tries == 50) throw CoreException("Could not find parent connect class \"" + parentName + "\" for connect block " + ConvToStr(i)); continue; } parent = Classes[parentIter->second]; } - std::string name; - if (ConfValue("connect", "name", i, name, false)) + std::string name = tag->getString("name"); + if (!name.empty()) { if (names.find(name) != names.end()) throw CoreException("Two connect classes with name \"" + name + "\" defined!"); @@ -641,12 +370,12 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current) std::string mask, typeMask; char type; - if (ConfValue("connect", "allow", i, mask, false)) + if (tag->readString("allow", mask, false)) { type = CC_ALLOW; typeMask = 'a' + mask; } - else if (ConfValue("connect", "deny", i, mask, false)) + else if (tag->readString("deny", mask, false)) { type = CC_DENY; typeMask = 'd' + mask; @@ -666,41 +395,29 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current) if (!name.empty()) me->name = name; - std::string tmpv; - if (ConfValue("connect", "password", i, tmpv, false)) - me->pass= tmpv; - if (ConfValue("connect", "hash", i, tmpv, false)) - me->hash = tmpv; - if (ConfValue("connect", "timeout", i, tmpv, false)) - me->registration_timeout = atol(tmpv.c_str()); - if (ConfValue("connect", "pingfreq", i, tmpv, false)) - me->pingtime = atol(tmpv.c_str()); - if (ConfValue("connect", "sendq", i, tmpv, false)) + tag->readString("password", me->pass); + tag->readString("hash", me->hash); + me->registration_timeout = tag->getInt("timeout", me->registration_timeout); + me->pingtime = tag->getInt("pingfreq", me->pingtime); + std::string sendq; + if (tag->readString("sendq", sendq)) { // attempt to guess a good hard/soft sendq from a single value - long value = atol(tmpv.c_str()); + long value = atol(sendq.c_str()); if (value > 16384) me->softsendqmax = value / 16; else me->softsendqmax = value; me->hardsendqmax = value * 8; } - if (ConfValue("connect", "softsendq", i, tmpv, false)) - me->softsendqmax = atol(tmpv.c_str()); - if (ConfValue("connect", "hardsendq", i, tmpv, false)) - me->hardsendqmax = atol(tmpv.c_str()); - if (ConfValue("connect", "recvq", i, tmpv, false)) - me->recvqmax = atol(tmpv.c_str()); - if (ConfValue("connect", "localmax", i, tmpv, false)) - me->maxlocal = atol(tmpv.c_str()); - if (ConfValue("connect", "globalmax", i, tmpv, false)) - me->maxglobal = atol(tmpv.c_str()); - if (ConfValue("connect", "port", i, tmpv, false)) - me->port = atol(tmpv.c_str()); - if (ConfValue("connect", "maxchans", i, tmpv, false)) - me->maxchans = atol(tmpv.c_str()); - if (ConfValue("connect", "limit", i, tmpv, false)) - me->limit = atol(tmpv.c_str()); + me->softsendqmax = tag->getInt("softsendq", me->softsendqmax); + me->hardsendqmax = tag->getInt("hardsendq", me->hardsendqmax); + me->recvqmax = tag->getInt("recvq", me->recvqmax); + me->maxlocal = tag->getInt("localmax", me->maxlocal); + me->maxglobal = tag->getInt("globalmax", me->maxglobal); + me->port = tag->getInt("port", me->port); + me->maxchans = tag->getInt("maxchans", me->maxchans); + me->limit = tag->getInt("limit", me->limit); ClassMap::iterator oldMask = oldBlocksByMask.find(typeMask); if (oldMask != oldBlocksByMask.end()) @@ -717,7 +434,6 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current) } } - static const Deprecated ChangedConfig[] = { {"options", "hidelinks", "has been moved to <security:hidelinks> as of 1.2a3"}, {"options", "hidewhois", "has been moved to <security:hidewhois> as of 1.2a3"}, @@ -740,163 +456,170 @@ static const Deprecated ChangedConfig[] = { {"die", "value", "has always been deprecated"}, }; -/* These tags can occur ONCE or not at all */ -static const InitialConfig Values[] = { - {"performance", "softlimit", "0", new ValueContainerUInt (&ServerConfig::SoftLimit), DT_INTEGER, ValidateSoftLimit}, - {"performance", "somaxconn", SOMAXCONN_S, new ValueContainerInt (&ServerConfig::MaxConn), DT_INTEGER, ValidateMaxConn}, - {"options", "moronbanner", "You're banned!", new ValueContainerString (&ServerConfig::MoronBanner), DT_CHARPTR, NULL}, - {"server", "name", "", new ValueContainerString (&ServerConfig::ServerName), DT_HOSTNAME, ValidateServerName}, - {"server", "description", "Configure Me", new ValueContainerString (&ServerConfig::ServerDesc), DT_CHARPTR, NULL}, - {"server", "network", "Network", new ValueContainerString (&ServerConfig::Network), DT_NOSPACES, NULL}, - {"server", "id", "", new ValueContainerString (&ServerConfig::sid), DT_CHARPTR, ValidateSID}, - {"admin", "name", "", new ValueContainerString (&ServerConfig::AdminName), DT_CHARPTR, NULL}, - {"admin", "email", "Mis@configu.red", new ValueContainerString (&ServerConfig::AdminEmail), DT_CHARPTR, NULL}, - {"admin", "nick", "Misconfigured", new ValueContainerString (&ServerConfig::AdminNick), DT_CHARPTR, NULL}, - {"files", "motd", "", new ValueContainerString (&ServerConfig::motd), DT_CHARPTR, ValidateMotd}, - {"files", "rules", "", new ValueContainerString (&ServerConfig::rules), DT_CHARPTR, ValidateRules}, - {"power", "diepass", "", new ValueContainerString (&ServerConfig::diepass), DT_CHARPTR, ValidateNotEmpty}, - {"power", "pause", "", new ValueContainerInt (&ServerConfig::DieDelay), DT_INTEGER, NULL}, - {"power", "hash", "", new ValueContainerString (&ServerConfig::powerhash), DT_CHARPTR, NULL}, - {"power", "restartpass", "", new ValueContainerString (&ServerConfig::restartpass), DT_CHARPTR, ValidateNotEmpty}, - {"options", "prefixquit", "", new ValueContainerString (&ServerConfig::PrefixQuit), DT_CHARPTR, NULL}, - {"options", "suffixquit", "", new ValueContainerString (&ServerConfig::SuffixQuit), DT_CHARPTR, NULL}, - {"options", "fixedquit", "", new ValueContainerString (&ServerConfig::FixedQuit), DT_CHARPTR, NULL}, - {"options", "prefixpart", "", new ValueContainerString (&ServerConfig::PrefixPart), DT_CHARPTR, NULL}, - {"options", "suffixpart", "", new ValueContainerString (&ServerConfig::SuffixPart), DT_CHARPTR, NULL}, - {"options", "fixedpart", "", new ValueContainerString (&ServerConfig::FixedPart), DT_CHARPTR, NULL}, - {"performance", "netbuffersize","10240", new ValueContainerInt (&ServerConfig::NetBufferSize), DT_INTEGER, ValidateNetBufferSize}, - {"performance", "maxwho", "1024", new ValueContainerInt (&ServerConfig::MaxWhoResults), DT_INTEGER, ValidateMaxWho}, - {"options", "allowhalfop", "0", new ValueContainerBool (&ServerConfig::AllowHalfop), DT_BOOLEAN, ValidateHalfOp}, - {"dns", "server", "", new ValueContainerString (&ServerConfig::DNSServer), DT_IPADDRESS,ValidateDnsServer}, - {"dns", "timeout", "5", new ValueContainerInt (&ServerConfig::dns_timeout), DT_INTEGER, NULL}, - {"options", "moduledir", MOD_PATH, new ValueContainerString (&ServerConfig::ModPath), DT_CHARPTR, NULL}, - {"disabled", "commands", "", new ValueContainerString (&ServerConfig::DisabledCommands), DT_CHARPTR, NULL}, - {"disabled", "usermodes", "", NULL, DT_NOTHING, ValidateDisabledUModes}, - {"disabled", "chanmodes", "", NULL, DT_NOTHING, ValidateDisabledCModes}, - {"disabled", "fakenonexistant", "0", new ValueContainerBool (&ServerConfig::DisabledDontExist), DT_BOOLEAN, NULL}, - - {"security", "runasuser", "", new ValueContainerString(&ServerConfig::SetUser), DT_CHARPTR, NULL}, - {"security", "runasgroup", "", new ValueContainerString(&ServerConfig::SetGroup), DT_CHARPTR, NULL}, - {"security", "userstats", "", new ValueContainerString (&ServerConfig::UserStats), DT_CHARPTR, NULL}, - {"security", "customversion","", new ValueContainerString (&ServerConfig::CustomVersion), DT_CHARPTR, NULL}, - {"security", "hidesplits", "0", new ValueContainerBool (&ServerConfig::HideSplits), DT_BOOLEAN, NULL}, - {"security", "hidebans", "0", new ValueContainerBool (&ServerConfig::HideBans), DT_BOOLEAN, NULL}, - {"security", "hidewhois", "", new ValueContainerString (&ServerConfig::HideWhoisServer), DT_NOSPACES, NULL}, - {"security", "hidekills", "", new ValueContainerString (&ServerConfig::HideKillsServer), DT_NOSPACES, NULL}, - {"security", "operspywhois", "0", new ValueContainerBool (&ServerConfig::OperSpyWhois), DT_BOOLEAN, NULL}, - {"security", "restrictbannedusers", "1", new ValueContainerBool (&ServerConfig::RestrictBannedUsers), DT_BOOLEAN, NULL}, - {"security", "genericoper", "0", new ValueContainerBool (&ServerConfig::GenericOper), DT_BOOLEAN, NULL}, - {"performance", "nouserdns", "0", new ValueContainerBool (&ServerConfig::NoUserDns), DT_BOOLEAN, NULL}, - {"options", "syntaxhints", "0", new ValueContainerBool (&ServerConfig::SyntaxHints), DT_BOOLEAN, NULL}, - {"options", "cyclehosts", "0", new ValueContainerBool (&ServerConfig::CycleHosts), DT_BOOLEAN, NULL}, - {"options", "ircumsgprefix","0", new ValueContainerBool (&ServerConfig::UndernetMsgPrefix), DT_BOOLEAN, NULL}, - {"security", "announceinvites", "1", NULL, DT_NOTHING, ValidateInvite}, - {"options", "hostintopic", "1", new ValueContainerBool (&ServerConfig::FullHostInTopic), DT_BOOLEAN, NULL}, - {"security", "hidemodes", "", NULL, DT_NOTHING, ValidateModeLists}, - {"security", "maxtargets", "20", new ValueContainerUInt (&ServerConfig::MaxTargets), DT_INTEGER, ValidateMaxTargets}, - {"options", "defaultmodes", "nt", new ValueContainerString (&ServerConfig::DefaultModes), DT_CHARPTR, NULL}, - {"pid", "file", "", new ValueContainerString (&ServerConfig::PID), DT_CHARPTR, NULL}, - {"whowas", "groupsize", "10", new ValueContainerInt (&ServerConfig::WhoWasGroupSize), DT_INTEGER, NULL}, - {"whowas", "maxgroups", "10240", new ValueContainerInt (&ServerConfig::WhoWasMaxGroups), DT_INTEGER, NULL}, - {"whowas", "maxkeep", "3600", NULL, DT_NOTHING, ValidateWhoWas}, - {"die", "value", "", new ValueContainerString (&ServerConfig::DieValue), DT_CHARPTR, NULL}, - {"channels", "users", "20", new ValueContainerUInt (&ServerConfig::MaxChans), DT_INTEGER, NULL}, - {"channels", "opers", "60", new ValueContainerUInt (&ServerConfig::OperMaxChans), DT_INTEGER, NULL}, - {"cidr", "ipv4clone", "32", new ValueContainerInt (&ServerConfig::c_ipv4_range), DT_INTEGER, NULL}, - {"cidr", "ipv6clone", "128", new ValueContainerInt (&ServerConfig::c_ipv6_range), DT_INTEGER, NULL}, - {"limits", "maxnick", "32", new ValueContainerLimit (&ServerLimits::NickMax), DT_LIMIT, NULL}, - {"limits", "maxchan", "64", new ValueContainerLimit (&ServerLimits::ChanMax), DT_LIMIT, NULL}, - {"limits", "maxmodes", "20", new ValueContainerLimit (&ServerLimits::MaxModes), DT_LIMIT, NULL}, - {"limits", "maxident", "11", new ValueContainerLimit (&ServerLimits::IdentMax), DT_LIMIT, NULL}, - {"limits", "maxquit", "255", new ValueContainerLimit (&ServerLimits::MaxQuit), DT_LIMIT, NULL}, - {"limits", "maxtopic", "307", new ValueContainerLimit (&ServerLimits::MaxTopic), DT_LIMIT, NULL}, - {"limits", "maxkick", "255", new ValueContainerLimit (&ServerLimits::MaxKick), DT_LIMIT, NULL}, - {"limits", "maxgecos", "128", new ValueContainerLimit (&ServerLimits::MaxGecos), DT_LIMIT, NULL}, - {"limits", "maxaway", "200", new ValueContainerLimit (&ServerLimits::MaxAway), DT_LIMIT, NULL}, - {"options", "invitebypassmodes", "1", new ValueContainerBool (&ServerConfig::InvBypassModes), DT_BOOLEAN, NULL}, -}; +void ServerConfig::Fill() +{ + ReqRead(this, "server", "name", ServerName); + ReqRead(this, "power", "diepass", diepass); + ReqRead(this, "power", "restartpass", restartpass); + + ConfigTag* options = ConfValue("options"); + ConfigTag* security = ConfValue("security"); + powerhash = ConfValue("power")->getString("hash"); + DieDelay = ConfValue("power")->getInt("pause"); + PrefixQuit = options->getString("prefixquit"); + SuffixQuit = options->getString("suffixquit"); + FixedQuit = options->getString("fixedquit"); + PrefixPart = options->getString("prefixpart"); + SuffixPart = options->getString("suffixpart"); + FixedPart = options->getString("fixedpart"); + SoftLimit = ConfValue("performance")->getInt("softlimit", ServerInstance->SE->GetMaxFds()); + MaxConn = ConfValue("performance")->getInt("somaxconn", SOMAXCONN); + MoronBanner = options->getString("moronbanner", "You're banned!"); + ServerDesc = ConfValue("server")->getString("description", "Configure Me"); + Network = ConfValue("server")->getString("network", "Network"); + sid = ConfValue("server")->getString("id", ""); + AdminName = ConfValue("admin")->getString("name", ""); + AdminEmail = ConfValue("admin")->getString("email", "null@example.com"); + AdminNick = ConfValue("admin")->getString("nick", "admin"); + ModPath = options->getString("moduledir", MOD_PATH); + NetBufferSize = ConfValue("performance")->getInt("netbuffersize", 10240); + MaxWhoResults = ConfValue("performance")->getInt("maxwho", 1024); + DNSServer = ConfValue("dns")->getString("server"); + dns_timeout = ConfValue("dns")->getInt("timeout", 5); + DisabledCommands = ConfValue("disabled")->getString("commands", ""); + DisabledDontExist = ConfValue("disabled")->getBool("fakenonexistant"); + SetUser = security->getString("runasuser"); + SetGroup = security->getString("runasgroup"); + UserStats = security->getString("userstats"); + CustomVersion = security->getString("customversion"); + HideSplits = security->getBool("hidesplits"); + HideBans = security->getBool("hidebans"); + HideWhoisServer = security->getString("hidewhois"); + HideKillsServer = security->getString("hidekills"); + OperSpyWhois = security->getBool("operspywhois"); + RestrictBannedUsers = security->getBool("restrictbannedusers"); + GenericOper = security->getBool("genericoper"); + NoUserDns = ConfValue("performance")->getBool("nouserdns"); + SyntaxHints = options->getBool("syntaxhints"); + CycleHosts = options->getBool("cyclehosts"); + UndernetMsgPrefix = options->getBool("ircumsgprefix"); + FullHostInTopic = options->getBool("hostintopic"); + MaxTargets = security->getInt("maxtargets"); + DefaultModes = options->getString("defaultmodes"); + PID = ConfValue("pid")->getString("file"); + WhoWasGroupSize = ConfValue("whowas")->getInt("groupsize"); + WhoWasMaxGroups = ConfValue("whowas")->getInt("maxgroups"); + WhoWasMaxKeep = ServerInstance->Duration(ConfValue("whowas")->getString("maxkeep")); + DieValue = ConfValue("die")->getString("value"); + MaxChans = ConfValue("channels")->getInt("users"); + OperMaxChans = ConfValue("channels")->getInt("opers"); + c_ipv4_range = ConfValue("cidr")->getInt("ipv4clone"); + c_ipv6_range = ConfValue("cidr")->getInt("ipv6clone"); + Limits.NickMax = ConfValue("limits")->getInt("maxnick"); + Limits.ChanMax = ConfValue("limits")->getInt("maxchan"); + Limits.MaxModes = ConfValue("limits")->getInt("maxmodes"); + Limits.IdentMax = ConfValue("limits")->getInt("maxident"); + Limits.MaxQuit = ConfValue("limits")->getInt("maxquit"); + Limits.MaxTopic = ConfValue("limits")->getInt("maxtopic"); + Limits.MaxKick = ConfValue("limits")->getInt("maxkick"); + Limits.MaxGecos = ConfValue("limits")->getInt("maxgecos"); + Limits.MaxAway = ConfValue("limits")->getInt("maxaway"); + InvBypassModes = options->getBool("invitebypassmodes"); + + ReadFile(MOTD, ConfValue("files")->getString("motd")); + ReadFile(RULES, ConfValue("files")->getString("rules")); + ValidateDnsServer(DNSServer); + + range(SoftLimit, 10, ServerInstance->SE->GetMaxFds(), ServerInstance->SE->GetMaxFds(), "<performance:softlimit>"); + range(MaxConn, 0, SOMAXCONN, SOMAXCONN, "<performance:somaxconn>"); + range(MaxTargets, 1, 31, 20, "<security:maxtargets>"); + range(NetBufferSize, 1024, 65534, 10240, "<performance:netbuffersize>"); + range(MaxWhoResults, 1, 65535, 1024, "<performace:maxwho>"); + range(WhoWasGroupSize, 0, 10000, 10, "<whowas:groupsize>"); + range(WhoWasMaxGroups, 0, 1000000, 10240, "<whowas:maxgroups>"); + range(WhoWasMaxKeep, 3600, INT_MAX, 3600, "<whowas:maxkeep>"); + + ValidHost(ServerName, "<server:name>"); + if (!sid.empty() && !ServerInstance->IsSID(sid)) + throw CoreException(sid + " is not a valid server ID. A server ID must be 3 characters long, with the first character a digit and the next two characters a digit or letter."); + + for (int i = 0;; ++i) + { + ConfigTag* tag = ConfValue("uline", i); + if (!tag) + break; + std::string server; + if (!tag->readString("server", server)) + throw CoreException("<uline> tag missing server"); + ulines[assign(server)] = tag->getBool("silent"); + } -InitialConfig::~InitialConfig() -{ - delete val; -} + for(int i=0;; ++i) + { + ConfigTag* tag = ConfValue("banlist", i); + if (!tag) + break; + std::string chan; + if (!tag->readString("chan", chan)) + throw CoreException("<banlist> tag missing chan"); + maxbans[chan] = tag->getInt("limit"); + } -/* These tags can occur multiple times, and therefore they have special code to read them - * which is different to the code for reading the singular tags listed above. - */ -MultiConfig MultiValues[] = { - - {"connect", - {"allow", "deny", "password", "timeout", "pingfreq", - "sendq", "recvq", "localmax", "globalmax", "port", - "name", "parent", "maxchans", "limit", "hash", - NULL}, - {"", "", "", "", "120", - "", "", "3", "3", "0", - "", "", "0", "0", "", - NULL}, - {DT_IPADDRESS|DT_ALLOW_WILD, DT_IPADDRESS|DT_ALLOW_WILD, DT_CHARPTR, DT_INTEGER, DT_INTEGER, - DT_INTEGER, DT_INTEGER, DT_INTEGER, DT_INTEGER, DT_INTEGER, - DT_NOSPACES, DT_NOSPACES, DT_INTEGER, DT_INTEGER, DT_CHARPTR}, - NULL,}, - - {"uline", - {"server", "silent", NULL}, - {"", "0", NULL}, - {DT_HOSTNAME, DT_BOOLEAN}, - DoULine}, - - {"banlist", - {"chan", "limit", NULL}, - {"", "", NULL}, - {DT_CHARPTR, DT_INTEGER}, - DoMaxBans}, - - {"module", - {"name", NULL}, - {"", NULL}, - {DT_CHARPTR}, - NULL}, - - {"badip", - {"reason", "ipmask", NULL}, - {"No reason", "", NULL}, - {DT_CHARPTR, DT_IPADDRESS|DT_ALLOW_WILD}, - DoZLine}, - - {"badnick", - {"reason", "nick", NULL}, - {"No reason", "", NULL}, - {DT_CHARPTR, DT_CHARPTR}, - DoQLine}, - - {"badhost", - {"reason", "host", NULL}, - {"No reason", "", NULL}, - {DT_CHARPTR, DT_CHARPTR}, - DoKLine}, - - {"exception", - {"reason", "host", NULL}, - {"No reason", "", NULL}, - {DT_CHARPTR, DT_CHARPTR}, - DoELine}, - - {"type", - {"name", "classes", NULL}, - {"", "", NULL}, - {DT_NOSPACES, DT_CHARPTR}, - DoType}, - - {"class", - {"name", "commands", "usermodes", "chanmodes", "privs", NULL}, - {"", "", "", "", "", NULL}, - {DT_NOSPACES, DT_CHARPTR, DT_CHARPTR, DT_CHARPTR, DT_CHARPTR}, - DoClass}, -}; + ReadXLine(this, "badip", "ipmask", ServerInstance->XLines->GetFactory("Z")); + ReadXLine(this, "badnick", "nick", ServerInstance->XLines->GetFactory("Q")); + ReadXLine(this, "badhost", "host", ServerInstance->XLines->GetFactory("K")); + ReadXLine(this, "exception", "host", ServerInstance->XLines->GetFactory("E")); + + memset(DisabledUModes, 0, sizeof(DisabledUModes)); + for (const unsigned char* p = (const unsigned char*)ConfValue("disabled")->getString("usermodes").c_str(); *p; ++p) + { + if (*p < 'A' || *p > ('A' + 64)) throw CoreException(std::string("Invalid usermode ")+(char)*p+" was found."); + DisabledUModes[*p - 'A'] = 1; + } + + memset(DisabledCModes, 0, sizeof(DisabledCModes)); + for (const unsigned char* p = (const unsigned char*)ConfValue("disabled")->getString("chanmodes").c_str(); *p; ++p) + { + if (*p < 'A' || *p > ('A' + 64)) throw CoreException(std::string("Invalid chanmode ")+(char)*p+" was found."); + DisabledCModes[*p - 'A'] = 1; + } + + memset(HideModeLists, 0, sizeof(HideModeLists)); + for (const unsigned char* p = (const unsigned char*)ConfValue("security")->getString("hidemodes").c_str(); *p; ++p) + HideModeLists[*p] = true; + + std::string v = security->getString("announceinvites"); + + if (v == "ops") + AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_OPS; + else if (v == "all") + AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_ALL; + else if (v == "dynamic") + AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_DYNAMIC; + else + AnnounceInvites = ServerConfig::INVITE_ANNOUNCE_NONE; + + bool AllowHalfOp = options->getBool("allowhalfop"); + ModeHandler* mh = ServerInstance->Modes->FindMode('h', MODETYPE_CHANNEL); + if (AllowHalfOp && !mh) { + ServerInstance->Logs->Log("CONFIG", DEFAULT, "Enabling halfop mode."); + mh = new ModeChannelHalfOp; + ServerInstance->Modes->AddMode(mh); + } else if (!AllowHalfOp && mh) { + ServerInstance->Logs->Log("CONFIG", DEFAULT, "Disabling halfop mode."); + ServerInstance->Modes->DelMode(mh); + delete mh; + } + + Module* whowas = ServerInstance->Modules->Find("cmd_whowas.so"); + if (whowas) + WhowasRequest(NULL, whowas, WhowasRequest::WHOWAS_PRUNE).Send(); + Limits.Finalise(); + +} /* These tags MUST occur and must ONLY occur once in the config file */ -static const char* Once[] = { "server", "admin", "files", "power", "options" }; +static const char* const Once[] = { "server", "admin", "files", "power", "options" }; // WARNING: it is not safe to use most of the codebase in this function, as it // will run in the config reader thread @@ -929,190 +652,12 @@ void ServerConfig::Apply(ServerConfig* old, const std::string &useruid) for (int Index = 0; Index * sizeof(Deprecated) < sizeof(ChangedConfig); Index++) { - char item[MAXBUF]; - *item = 0; - if (ConfValue(ChangedConfig[Index].tag, ChangedConfig[Index].value, "", 0, item, MAXBUF, true) || *item) + std::string dummy; + if (ConfValue(ChangedConfig[Index].tag)->readString(ChangedConfig[Index].value, dummy, true)) throw CoreException(std::string("Your configuration contains a deprecated value: <") + ChangedConfig[Index].tag + ":" + ChangedConfig[Index].value + "> - " + ChangedConfig[Index].reason); } - /* Read the values of all the tags which occur once or not at all, and call their callbacks. - */ - for (int Index = 0; Index * sizeof(*Values) < sizeof(Values); ++Index) - { - char item[MAXBUF]; - int dt = Values[Index].datatype; - bool allow_newlines = ((dt & DT_ALLOW_NEWLINE) > 0); - bool allow_wild = ((dt & DT_ALLOW_WILD) > 0); - dt &= ~DT_ALLOW_NEWLINE; - dt &= ~DT_ALLOW_WILD; - - ConfValue(Values[Index].tag, Values[Index].value, Values[Index].default_value, 0, item, MAXBUF, allow_newlines); - ValueItem vi(item); - - if (Values[Index].validation_function && !Values[Index].validation_function(this, Values[Index].tag, Values[Index].value, vi)) - throw CoreException("One or more values in your configuration file failed to validate. Please see your ircd.log for more information."); - - switch (dt) - { - case DT_NOSPACES: - { - ValueContainerString* vcc = (ValueContainerString*)Values[Index].val; - ValidateNoSpaces(vi.GetString(), Values[Index].tag, Values[Index].value); - vcc->Set(this, vi.GetValue()); - } - break; - case DT_HOSTNAME: - { - ValueContainerString* vcc = (ValueContainerString*)Values[Index].val; - ValidateHostname(vi.GetString(), Values[Index].tag, Values[Index].value); - vcc->Set(this, vi.GetValue()); - } - break; - case DT_IPADDRESS: - { - ValueContainerString* vcc = (ValueContainerString*)Values[Index].val; - ValidateIP(vi.GetString(), Values[Index].tag, Values[Index].value, allow_wild); - vcc->Set(this, vi.GetValue()); - } - break; - case DT_CHANNEL: - { - ValueContainerString* vcc = (ValueContainerString*)Values[Index].val; - if (*(vi.GetString()) && !ServerInstance->IsChannel(vi.GetString(), MAXBUF)) - { - throw CoreException("The value of <"+std::string(Values[Index].tag)+":"+Values[Index].value+"> is not a valid channel name"); - } - vcc->Set(this, vi.GetValue()); - } - break; - case DT_CHARPTR: - { - ValueContainerString* vcs = dynamic_cast<ValueContainerString*>(Values[Index].val); - if (vcs) - vcs->Set(this, vi.GetValue()); - } - break; - case DT_INTEGER: - { - int val = vi.GetInteger(); - ValueContainerInt* vci = (ValueContainerInt*)Values[Index].val; - vci->Set(this, val); - } - break; - case DT_LIMIT: - { - int val = vi.GetInteger(); - ValueContainerLimit* vci = (ValueContainerLimit*)Values[Index].val; - vci->Set(this, val); - } - break; - case DT_BOOLEAN: - { - bool val = vi.GetBool(); - ValueContainerBool* vcb = (ValueContainerBool*)Values[Index].val; - vcb->Set(this, val); - } - break; - } - } - - /* Read the multiple-tag items (class tags, connect tags, etc) - * and call the callbacks associated with them. We have three - * callbacks for these, a 'start', 'item' and 'end' callback. - */ - for (int Index = 0; Index * sizeof(MultiConfig) < sizeof(MultiValues); ++Index) - { - int number_of_tags = ConfValueEnum(MultiValues[Index].tag); - - for (int tagnum = 0; tagnum < number_of_tags; ++tagnum) - { - ValueList vl; - for (int valuenum = 0; (MultiValues[Index].items[valuenum]) && (valuenum < MAX_VALUES_PER_TAG); ++valuenum) - { - int dt = MultiValues[Index].datatype[valuenum]; - bool allow_newlines = ((dt & DT_ALLOW_NEWLINE) > 0); - bool allow_wild = ((dt & DT_ALLOW_WILD) > 0); - dt &= ~DT_ALLOW_NEWLINE; - dt &= ~DT_ALLOW_WILD; - - switch (dt) - { - case DT_NOSPACES: - { - char item[MAXBUF]; - if (ConfValue(MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, MAXBUF, allow_newlines)) - vl.push_back(ValueItem(item)); - else - vl.push_back(ValueItem("")); - ValidateNoSpaces(vl[vl.size()-1].GetString(), MultiValues[Index].tag, MultiValues[Index].items[valuenum]); - } - break; - case DT_HOSTNAME: - { - char item[MAXBUF]; - if (ConfValue(MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, MAXBUF, allow_newlines)) - vl.push_back(ValueItem(item)); - else - vl.push_back(ValueItem("")); - ValidateHostname(vl[vl.size()-1].GetString(), MultiValues[Index].tag, MultiValues[Index].items[valuenum]); - } - break; - case DT_IPADDRESS: - { - char item[MAXBUF]; - if (ConfValue(MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, MAXBUF, allow_newlines)) - vl.push_back(ValueItem(item)); - else - vl.push_back(ValueItem("")); - ValidateIP(vl[vl.size()-1].GetString(), MultiValues[Index].tag, MultiValues[Index].items[valuenum], allow_wild); - } - break; - case DT_CHANNEL: - { - char item[MAXBUF]; - if (ConfValue(MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, MAXBUF, allow_newlines)) - vl.push_back(ValueItem(item)); - else - vl.push_back(ValueItem("")); - if (!ServerInstance->IsChannel(vl[vl.size()-1].GetString(), MAXBUF)) - throw CoreException("The value of <"+std::string(MultiValues[Index].tag)+":"+MultiValues[Index].items[valuenum]+"> number "+ConvToStr(tagnum + 1)+" is not a valid channel name"); - } - break; - case DT_CHARPTR: - { - char item[MAXBUF]; - if (ConfValue(MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, MAXBUF, allow_newlines)) - vl.push_back(ValueItem(item)); - else - vl.push_back(ValueItem("")); - } - break; - case DT_INTEGER: - { - int item = 0; - if (ConfValueInteger(MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item)) - vl.push_back(ValueItem(item)); - else - vl.push_back(ValueItem(0)); - } - break; - case DT_BOOLEAN: - { - bool item = ConfValueBool(MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum); - vl.push_back(ValueItem(item)); - } - break; - } - } - if (MultiValues[Index].validation_function) - MultiValues[Index].validation_function(this, MultiValues[Index].tag, MultiValues[Index].items, vl, MultiValues[Index].datatype); - } - } - - /* Finalise the limits, increment them all by one so that we can just put assign(str, 0, val) - * rather than assign(str, 0, val + 1) - */ - Limits.Finalise(); + Fill(); // Handle special items CrossCheckOperClassType(); @@ -1206,11 +751,13 @@ void ServerConfig::ApplyModules(User* user) std::vector<std::string> added_modules; std::set<std::string> removed_modules(v.begin(), v.end()); - int new_module_count = ConfValueEnum("module"); - for(int i=0; i < new_module_count; i++) + for(int i=0; ; i++) { + ConfigTag* tag = ConfValue("module", i); + if (!tag) + break; std::string name; - if (ConfValue("module", "name", i, name, false)) + if (tag->readString("name", name)) { // if this module is already loaded, the erase will succeed, so we need do nothing // otherwise, we need to add the module (which will be done later) @@ -1490,17 +1037,16 @@ bool ServerConfig::ParseLine(const std::string &filename, std::string &line, lon std::string tagname; std::string current_key; std::string current_value; - KeyValList results; + reference<ConfigTag> result; char last_char = 0; - bool got_name; bool got_key; bool in_quote; - got_name = got_key = in_quote = false; + got_key = in_quote = false; for(std::string::iterator c = line.begin(); c != line.end(); c++) { - if (!got_name) + if (!result) { /* We don't know the tag name yet. */ @@ -1522,7 +1068,7 @@ bool ServerConfig::ParseLine(const std::string &filename, std::string &line, lon /* We got to a space, we should have the tagname now. */ if(tagname.length()) { - got_name = true; + result = new ConfigTag(tagname); } } } @@ -1594,7 +1140,7 @@ bool ServerConfig::ParseLine(const std::string &filename, std::string &line, lon else { /* Leaving the quotes, we have the current value */ - results.push_back(KeyVal(current_key, current_value)); + result->items.push_back(KeyVal(current_key, current_value)); // std::cout << "<" << tagname << ":" << current_key << "> " << current_value << std::endl; @@ -1639,7 +1185,7 @@ bool ServerConfig::ParseLine(const std::string &filename, std::string &line, lon } /* Finished parsing the tag, add it to the config hash */ - config_data.insert(std::pair<std::string, KeyValList > (tagname, results)); + config_data.insert(std::make_pair(tagname, result)); return true; } @@ -1681,193 +1227,97 @@ bool ServerConfig::DoInclude(const std::string &file, bool allowexeinc) return ret; } -bool ServerConfig::ConfValue(const char* tag, const char* var, int index, char* result, int length, bool allow_linefeeds) -{ - return ConfValue(tag, var, "", index, result, length, allow_linefeeds); -} - -bool ServerConfig::ConfValue(const char* tag, const char* var, const char* default_value, int index, char* result, int length, bool allow_linefeeds) +ConfigTag* ServerConfig::ConfValue(const std::string &tag, int offset) { - std::string value; - bool r = ConfValue(std::string(tag), std::string(var), std::string(default_value), index, value, allow_linefeeds); - strlcpy(result, value.c_str(), length); - return r; -} + ConfigDataHash::size_type pos = offset; + if (pos >= config_data.count(tag)) + return NULL; + + ConfigDataHash::iterator iter = config_data.find(tag); -bool ServerConfig::ConfValue(const std::string &tag, const std::string &var, int index, std::string &result, bool allow_linefeeds) -{ - return ConfValue(tag, var, "", index, result, allow_linefeeds); + for(int i = 0; i < offset; i++) + iter++; + + return iter->second; } -bool ServerConfig::ConfValue(const std::string &tag, const std::string &var, const std::string &default_value, int index, std::string &result, bool allow_linefeeds) +bool ConfigTag::readString(const std::string& key, std::string& value, bool allow_lf) { - ConfigDataHash::size_type pos = index; - if (pos < config_data.count(tag)) - { - ConfigDataHash::iterator iter = config_data.find(tag); - - for(int i = 0; i < index; i++) - iter++; - - for(KeyValList::iterator j = iter->second.begin(); j != iter->second.end(); j++) - { - if(j->first == var) - { - if ((!allow_linefeeds) && (j->second.find('\n') != std::string::npos)) - { - ServerInstance->Logs->Log("CONFIG",DEFAULT, "Value of <" + tag + ":" + var+ "> contains a linefeed, and linefeeds in this value are not permitted -- stripped to spaces."); - for (std::string::iterator n = j->second.begin(); n != j->second.end(); n++) - if (*n == '\n') - *n = ' '; - } - else - { - result = j->second; - return true; - } - } - } - if (!default_value.empty()) - { - result = default_value; - return true; - } - } - else if (pos == 0) + if (!this) + return false; + for(std::vector<KeyVal>::iterator j = items.begin(); j != items.end(); ++j) { - if (!default_value.empty()) + if(j->first != key) + continue; + value = j->second; + if (!allow_lf && (value.find('\n') != std::string::npos)) { - result = default_value; - return true; + ServerInstance->Logs->Log("CONFIG",DEFAULT, "Value of <" + tag + ":" + key + "> contains a linefeed, and linefeeds in this value are not permitted -- stripped to spaces."); + for (std::string::iterator n = value.begin(); n != value.end(); n++) + if (*n == '\n') + *n = ' '; } + return true; } return false; } -bool ServerConfig::ConfValueInteger(const char* tag, const char* var, int index, int &result) -{ - return ConfValueInteger(std::string(tag), std::string(var), "", index, result); -} - -bool ServerConfig::ConfValueInteger(const char* tag, const char* var, const char* default_value, int index, int &result) -{ - return ConfValueInteger(std::string(tag), std::string(var), std::string(default_value), index, result); -} - -bool ServerConfig::ConfValueInteger(const std::string &tag, const std::string &var, int index, int &result) +std::string ConfigTag::getString(const std::string& key, const std::string& def) { - return ConfValueInteger(tag, var, "", index, result); + std::string res = def; + if (this) + readString(key, res); + return res; } -bool ServerConfig::ConfValueInteger(const std::string &tag, const std::string &var, const std::string &default_value, int index, int &result) +long ConfigTag::getInt(const std::string &key, long def) { - std::string value; - std::istringstream stream; - bool r = ConfValue(tag, var, default_value, index, value); - stream.str(value); - if(!(stream >> result)) - return false; - else + std::string result; + if(!this || !readString(key, result)) + return def; + + const char* res_cstr = result.c_str(); + char* res_tail = NULL; + long res = strtol(res_cstr, &res_tail, 0); + if (res_tail == res_cstr) + return def; + switch (toupper(*res_tail)) { - if (!value.empty()) - { - if (value.substr(0,2) == "0x") - { - char* endptr; - - value.erase(0,2); - result = strtol(value.c_str(), &endptr, 16); - - /* No digits found */ - if (endptr == value.c_str()) - return false; - } - else - { - char denominator = *(value.end() - 1); - switch (toupper(denominator)) - { - case 'K': - /* Kilobytes -> bytes */ - result = result * 1024; - break; - case 'M': - /* Megabytes -> bytes */ - result = result * 1024 * 1024; - break; - case 'G': - /* Gigabytes -> bytes */ - result = result * 1024 * 1024 * 1024; - break; - } - } - } + case 'K': + res= res* 1024; + break; + case 'M': + res= res* 1024 * 1024; + break; + case 'G': + res= res* 1024 * 1024 * 1024; + break; } - return r; + return res; } - -bool ServerConfig::ConfValueBool(const char* tag, const char* var, int index) -{ - return ConfValueBool(std::string(tag), std::string(var), "", index); -} - -bool ServerConfig::ConfValueBool(const char* tag, const char* var, const char* default_value, int index) -{ - return ConfValueBool(std::string(tag), std::string(var), std::string(default_value), index); -} - -bool ServerConfig::ConfValueBool(const std::string &tag, const std::string &var, int index) -{ - return ConfValueBool(tag, var, "", index); -} - -bool ServerConfig::ConfValueBool(const std::string &tag, const std::string &var, const std::string &default_value, int index) +double ConfigTag::getFloat(const std::string &key, double def) { std::string result; - if(!ConfValue(tag, var, default_value, index, result)) - return false; - - return ((result == "yes") || (result == "true") || (result == "1")); -} - -int ServerConfig::ConfValueEnum(const char* tag) -{ - return config_data.count(tag); -} - -int ServerConfig::ConfValueEnum(const std::string &tag) -{ - return config_data.count(tag); + if (!readString(key, result)) + return def; + return strtod(result.c_str(), NULL); } -int ServerConfig::ConfVarEnum(const char* tag, int index) +bool ConfigTag::getBool(const std::string &key, bool def) { - return ConfVarEnum(std::string(tag), index); -} - -int ServerConfig::ConfVarEnum(const std::string &tag, int index) -{ - ConfigDataHash::size_type pos = index; - - if (pos < config_data.count(tag)) - { - ConfigDataHash::const_iterator iter = config_data.find(tag); - - for(int i = 0; i < index; i++) - iter++; - - return iter->second.size(); - } + std::string result; + if(!readString(key, result)) + return def; - return 0; + return (result == "yes" || result == "true" || result == "1" || result == "on"); } /** Read the contents of a file located by `fname' into a file_cache pointed at by `F'. */ -bool ServerConfig::ReadFile(file_cache &F, const char* fname) +bool ServerConfig::ReadFile(file_cache &F, const std::string& fname) { - if (!fname || !*fname) + if (fname.empty()) return false; FILE* file = NULL; @@ -1875,9 +1325,9 @@ bool ServerConfig::ReadFile(file_cache &F, const char* fname) F.clear(); - if (!FileExists(fname)) + if (!FileExists(fname.c_str())) return false; - file = fopen(fname, "r"); + file = fopen(fname.c_str(), "r"); if (file) { @@ -1931,50 +1381,6 @@ std::string ServerConfig::GetSID() return sid; } -ValueItem::ValueItem(int value) -{ - std::stringstream n; - n << value; - v = n.str(); -} - -ValueItem::ValueItem(bool value) -{ - std::stringstream n; - n << value; - v = n.str(); -} - -void ValueItem::Set(const std::string& value) -{ - v = value; -} - -void ValueItem::Set(int value) -{ - std::stringstream n; - n << value; - v = n.str(); -} - -int ValueItem::GetInteger() -{ - if (v.empty()) - return 0; - return atoi(v.c_str()); -} - -const char* ValueItem::GetString() const -{ - return v.c_str(); -} - -bool ValueItem::GetBool() -{ - return (GetInteger() || v == "yes" || v == "true"); -} - - void ConfigReaderThread::Run() { Config = new ServerConfig; diff --git a/src/logger.cpp b/src/logger.cpp index e2baa4b8d..c9b1cf9e4 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -11,8 +11,6 @@ * --------------------------------------------------- */ -/* $Core */ - #include "inspircd.h" #include "filelogger.h" @@ -73,15 +71,18 @@ void LogManager::OpenFileLogs() ConfigReader* Conf = new ConfigReader; std::map<std::string, FileWriter*> logmap; std::map<std::string, FileWriter*>::iterator i; - for (int index = 0; index < Conf->Enumerate("log"); ++index) + for (int index = 0;; ++index) { - std::string method = Conf->ReadValue("log", "method", index); + ConfigTag* tag = ServerInstance->Config->ConfValue("log", index); + if (!tag) + break; + std::string method = tag->getString("method"); if (method != "file") { continue; } - std::string type = Conf->ReadValue("log", "type", index); - std::string level = Conf->ReadValue("log", "level", index); + std::string type = tag->getString("type"); + std::string level = tag->getString("level"); int loglevel = DEFAULT; if (level == "debug" || ServerInstance->Config->forcedebug) { diff --git a/src/modules.cpp b/src/modules.cpp index f1e53deba..f8989b415 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -543,7 +543,6 @@ void ModuleManager::Reload(Module* mod, HandlerBase1<void, bool>* callback) /* We must load the modules AFTER initializing the socket engine, now */ void ModuleManager::LoadAll() { - char configToken[MAXBUF]; ModCount = 0; printf("\nLoading core commands"); @@ -572,12 +571,15 @@ void ModuleManager::LoadAll() printf("\n"); } - for(int count = 0; count < ServerInstance->Config->ConfValueEnum("module"); count++) + for(int count = 0;; count++) { - ServerInstance->Config->ConfValue("module", "name", count, configToken, MAXBUF); - printf_c("[\033[1;32m*\033[0m] Loading module:\t\033[1;32m%s\033[0m\n",configToken); + ConfigTag* tag = ServerInstance->Config->ConfValue("module", count); + if (!tag) + break; + std::string name = tag->getString("name"); + printf_c("[\033[1;32m*\033[0m] Loading module:\t\033[1;32m%s\033[0m\n",name.c_str()); - if (!this->Load(configToken)) + if (!this->Load(name.c_str())) { ServerInstance->Logs->Log("MODULE", DEFAULT, this->LastError()); printf_c("\n[\033[1;31m*\033[0m] %s\n\n", this->LastError().c_str()); @@ -603,6 +605,7 @@ void ModuleManager::UnloadAll() if (CanUnload(me->second)) { ServerInstance->GlobalCulls.AddItem(me->second); + Modules.erase(me); } } ServerInstance->GlobalCulls.Apply(); @@ -858,9 +861,8 @@ ConfigReader::~ConfigReader() std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool allow_linefeeds) { /* Don't need to strlcpy() tag and name anymore, ReadConf() takes const char* */ - std::string result; - - if (!ServerInstance->Config->ConfValue(tag, name, default_value, index, result, allow_linefeeds)) + std::string result = default_value; + if (!ServerInstance->Config->ConfValue(tag, index)->readString(name, result, allow_linefeeds)) { this->error = CONF_VALUE_NOT_FOUND; } @@ -874,7 +876,8 @@ std::string ConfigReader::ReadValue(const std::string &tag, const std::string &n bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, const std::string &default_value, int index) { - return ServerInstance->Config->ConfValueBool(tag, name, default_value, index); + bool def = (default_value == "yes"); + return ServerInstance->Config->ConfValue(tag, index)->getBool(name, def); } bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, int index) @@ -885,13 +888,8 @@ bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, int int ConfigReader::ReadInteger(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool need_positive) { - int result; - - if(!ServerInstance->Config->ConfValueInteger(tag, name, default_value, index, result)) - { - this->error = CONF_VALUE_NOT_FOUND; - return 0; - } + int v = atoi(default_value.c_str()); + int result = ServerInstance->Config->ConfValue(tag, index)->getInt(name, v); if ((need_positive) && (result < 0)) { @@ -916,12 +914,11 @@ long ConfigReader::GetError() int ConfigReader::Enumerate(const std::string &tag) { - return ServerInstance->Config->ConfValueEnum(tag); -} - -int ConfigReader::EnumerateValues(const std::string &tag, int index) -{ - return ServerInstance->Config->ConfVarEnum(tag, index); + ServerInstance->Logs->Log("MODULE", DEBUG, "Module is using ConfigReader::Enumerate on %s; this is slow!", + tag.c_str()); + int i=0; + while (ServerInstance->Config->ConfValue(tag, i)) i++; + return i; } FileReader::FileReader(const std::string &filename) diff --git a/src/modules/m_httpd_config.cpp b/src/modules/m_httpd_config.cpp index 988ba3977..fa8f5f95f 100644 --- a/src/modules/m_httpd_config.cpp +++ b/src/modules/m_httpd_config.cpp @@ -90,9 +90,10 @@ class ModuleHttpStats : public Module for (ConfigDataHash::iterator x = ServerInstance->Config->config_data.begin(); x != ServerInstance->Config->config_data.end(); ++x) { data << "<" << x->first << " "; - for (KeyValList::iterator j = x->second.begin(); j != x->second.end(); j++) + ConfigTag* tag = x->second; + for (std::vector<KeyVal>::iterator j = tag->items.begin(); j != tag->items.end(); j++) { - data << j->first << "="" << j->second << "" "; + data << Sanitize(j->first) << "="" << Sanitize(j->second) << "" "; } data << "><br>"; } diff --git a/src/socket.cpp b/src/socket.cpp index efe799bfc..c4be23a60 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -105,29 +105,28 @@ int irc::sockets::OpenTCPSocket(const std::string& addr, int socktype) // XXX: it would be VERY nice to genericize this so all listen stuff (server/client) could use the one function. -- w00t int InspIRCd::BindPorts(FailedPortList &failed_ports) { - char configToken[MAXBUF], Addr[MAXBUF], Type[MAXBUF], Desc[MAXBUF]; int bound = 0; std::vector<ListenSocketBase*> old_ports(ports.begin(), ports.end()); - for (int count = 0; count < Config->ConfValueEnum("bind"); count++) + for (int count = 0;; count++) { - Config->ConfValue("bind", "port", count, configToken, MAXBUF); - Config->ConfValue("bind", "address", count, Addr, MAXBUF); - Config->ConfValue("bind", "type", count, Type, MAXBUF); - Config->ConfValue("bind", "ssl", count, Desc, MAXBUF); + ConfigTag* tag = ServerInstance->Config->ConfValue("bind", count); + if (!tag) + break; + std::string porttag = tag->getString("port"); + std::string Addr = tag->getString("address"); + std::string Type = tag->getString("type"); + std::string Desc = tag->getString("ssl"); - if (strncmp(Addr, "::ffff:", 7) == 0) + if (strncmp(Addr.c_str(), "::ffff:", 7) == 0) this->Logs->Log("SOCKET",DEFAULT, "Using 4in6 (::ffff:) isn't recommended. You should bind IPv4 addresses directly instead."); - if ((!*Type) || (!strcmp(Type,"clients"))) + if (Type.empty() || Type == "clients") { - irc::portparser portrange(configToken, false); + irc::portparser portrange(porttag, false); int portno = -1; while (0 != (portno = portrange.GetToken())) { - if (*Addr == '*') - *Addr = 0; - irc::sockets::sockaddrs bindspec; irc::sockets::aptosa(Addr, portno, &bindspec); std::string bind_readable = irc::sockets::satouser(&bindspec); @@ -144,7 +143,7 @@ int InspIRCd::BindPorts(FailedPortList &failed_ports) } if (!skip) { - ClientListenSocket *ll = new ClientListenSocket(portno, Addr, "clients", *Desc ? Desc : "plaintext"); + ClientListenSocket *ll = new ClientListenSocket(portno, Addr, "clients", Desc.empty() ? "plaintext" : Desc); if (ll->GetFd() > -1) { bound++; diff --git a/src/stats.cpp b/src/stats.cpp index a512ccc38..eb8fe0e45 100644 --- a/src/stats.cpp +++ b/src/stats.cpp @@ -88,11 +88,9 @@ void InspIRCd::DoStats(char statschar, User* user, string_list &results) case 'U': { - char ulined[MAXBUF]; - for (int i = 0; i < this->Config->ConfValueEnum("uline"); i++) + for(std::map<irc::string, bool>::iterator i = Config->ulines.begin(); i != Config->ulines.end(); ++i) { - this->Config->ConfValue("uline","server", i, ulined, MAXBUF); - results.push_back(sn+" 248 "+user->nick+" U "+std::string(ulined)); + results.push_back(sn+" 248 "+user->nick+" U "+std::string(i->first.c_str())); } } break; @@ -236,15 +234,13 @@ void InspIRCd::DoStats(char statschar, User* user, string_list &results) /* stats o */ case 'o': - for (int i = 0; i < this->Config->ConfValueEnum("oper"); i++) + for (int i = 0;; i++) { - char LoginName[MAXBUF]; - char HostName[MAXBUF]; - char OperType[MAXBUF]; - this->Config->ConfValue("oper","name", i, LoginName, MAXBUF); - this->Config->ConfValue("oper","host", i, HostName, MAXBUF); - this->Config->ConfValue("oper","type", i, OperType, MAXBUF); - results.push_back(sn+" 243 "+user->nick+" O "+HostName+" * "+LoginName+" "+OperType+" 0"); + ConfigTag* tag = Config->ConfValue("oper", i); + if (!tag) + break; + results.push_back(sn+" 243 "+user->nick+" O "+tag->getString("host")+" * "+ + tag->getString("name") + " " + tag->getString("type")+" 0"); } break; diff --git a/src/users.cpp b/src/users.cpp index 729213e42..4b6686977 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -652,7 +652,7 @@ void User::Oper(const std::string &opertype, const std::string &opername) * For multi-network servers, we may not have the opertypes of the remote server, but we still want to mark the user as an oper of that type. * -- w00t */ - opertype_t::iterator iter_opertype = ServerInstance->Config->opertypes.find(this->oper.c_str()); + TagIndex::iterator iter_opertype = ServerInstance->Config->opertypes.find(this->oper.c_str()); if (iter_opertype != ServerInstance->Config->opertypes.end()) { if (AllowedOperCommands) @@ -670,26 +670,26 @@ void User::Oper(const std::string &opertype, const std::string &opername) this->AllowedUserModes['o' - 'A'] = true; // Call me paranoid if you want. std::string myclass, mycmd, mypriv; - irc::spacesepstream Classes(iter_opertype->second.c_str()); + irc::spacesepstream Classes(iter_opertype->second->getString("classes")); while (Classes.GetToken(myclass)) { - operclass_t::iterator iter_operclass = ServerInstance->Config->operclass.find(myclass.c_str()); + TagIndex::iterator iter_operclass = ServerInstance->Config->operclass.find(myclass.c_str()); if (iter_operclass != ServerInstance->Config->operclass.end()) { /* Process commands */ - irc::spacesepstream CommandList(iter_operclass->second.commandlist); + irc::spacesepstream CommandList(iter_operclass->second->getString("commands")); while (CommandList.GetToken(mycmd)) { this->AllowedOperCommands->insert(mycmd); } - irc::spacesepstream PrivList(iter_operclass->second.privs); + irc::spacesepstream PrivList(iter_operclass->second->getString("privs")); while (PrivList.GetToken(mypriv)) { this->AllowedPrivs->insert(mypriv); } - for (unsigned char* c = (unsigned char*)iter_operclass->second.umodelist.c_str(); *c; ++c) + for (unsigned char* c = (unsigned char*)iter_operclass->second->getString("usermodes").c_str(); *c; ++c) { if (*c == '*') { @@ -701,7 +701,7 @@ void User::Oper(const std::string &opertype, const std::string &opername) } } - for (unsigned char* c = (unsigned char*)iter_operclass->second.cmodelist.c_str(); *c; ++c) + for (unsigned char* c = (unsigned char*)iter_operclass->second->getString("chanmodes").c_str(); *c; ++c) { if (*c == '*') { |