diff options
-rw-r--r-- | include/account.h | 3 | ||||
-rw-r--r-- | include/opertype.h (renamed from include/svsoper.h) | 6 | ||||
-rw-r--r-- | include/services.h | 2 | ||||
-rw-r--r-- | src/Makefile | 4 | ||||
-rw-r--r-- | src/config.c | 114 | ||||
-rw-r--r-- | src/opertype.cpp (renamed from src/svsopers.cpp) | 12 |
6 files changed, 129 insertions, 12 deletions
diff --git a/include/account.h b/include/account.h index 0217753ad..ed0bcc877 100644 --- a/include/account.h +++ b/include/account.h @@ -58,6 +58,7 @@ class NickCore : public Extensible { next = prev = NULL; display = email = greet = url = NULL; + ot = NULL; pass[0] = '\0'; icq = flags = 0; language = accesscount = channelcount = 0; @@ -79,6 +80,8 @@ class NickCore : public Extensible MemoInfo memos; uint16 channelcount; /* Number of channels currently registered */ + OperType *ot; + /* Unsaved data */ time_t lastmail; /* Last time this nick record got a mail */ SList aliases; /* List of aliases */ diff --git a/include/svsoper.h b/include/opertype.h index bf5c5c486..9d5e77224 100644 --- a/include/svsoper.h +++ b/include/opertype.h @@ -9,7 +9,7 @@ * */ -class SVSOper +class OperType { private: /** The name of this opertype, e.g. "sra". @@ -31,6 +31,10 @@ class SVSOper */ std::list<std::string> commands; public: + /** Create a new opertype of the given name. + * @param nname The opertype name, e.g. "sra". + */ + OperType(const std::string &nname); /** Check whether this opertype has access to run the given command string. * @param cmdstr The string to check, e.g. botserv/set/private. diff --git a/include/services.h b/include/services.h index 552688411..6f7353111 100644 --- a/include/services.h +++ b/include/services.h @@ -433,7 +433,7 @@ typedef struct csmodeutil_ CSModeUtil; typedef struct session_ Session; #include "bots.h" -#include "svsoper.h" +#include "opertype.h" /*************************************************************************/ diff --git a/src/Makefile b/src/Makefile index 51e469933..92d24cb10 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,7 +1,7 @@ OBJS = actions.o base64.o bots.o botserv.o channels.o chanserv.o commands.o compat.o \ config.o datafiles.o encrypt.o events.o hashcomp.o helpserv.o hostserv.o init.o ircd.o language.o log.o mail.o main.o \ memory.o memoserv.o messages.o misc.o modules.o news.o nickserv.o operserv.o \ - process.o protocol.o send.o servers.o sessions.o slist.o sockutil.o svsopers.o timeout.o users.o module.o modulemanager.o configreader.o \ + process.o protocol.o send.o servers.o sessions.o slist.o sockutil.o opertype.o timeout.o users.o module.o modulemanager.o configreader.o \ wildcard.o INCLUDES = ../include/commands.h ../include/defs.h ../include/language.h \ @@ -70,7 +70,7 @@ servers.o: servers.c $(INCLUDES) sessions.o: sessions.c $(INCLUDES) slist.o: slist.c $(INCLUDES) sockutil.o: sockutil.c $(INCLUDES) -svsopers.o: svsopers.cpp $(INCLUDES) +opertype.o: opertype.cpp $(INCLUDES) timeout.o: timeout.c $(INCLUDES) users.o: users.c $(INCLUDES) vsnprintf.o: vsnprintf.c $(INCLUDES) diff --git a/src/config.c b/src/config.c index 2ad7e753d..5bd4d4c42 100644 --- a/src/config.c +++ b/src/config.c @@ -271,6 +271,12 @@ static char *UlineServers; char **Ulines; int NumUlines; +static std::list<OperType *> MyOperTypes; +/* Pair of nick/opertype lookup. It's stored like this currently, because config is parsed before db load. + * XXX: It would be nice to not need this. + */ +static std::list<std::pair<std::string, std::string> > svsopers_in_config; + /*************************************************************************/ ServerConfig::ServerConfig() : include_stack(), errstr(""), newconfig(), config_data() @@ -563,13 +569,13 @@ bool DoUplink(ServerConfig *conf, const char *, const char **, ValueList &values ValueItem vi_host(host), vi_port(port), vi_password(password); // Validate the host to make sure it is not empty if (!ValidateNotEmpty(conf, "uplink", "host", vi_host)) - throw ConfigException("One or more values in your configuration file failed to validate. Please see your ircd.log for more information."); + throw ConfigException("One or more values in your configuration file failed to validate. Please see your log for more information."); // Validate the port to make sure it is a valid port if (!ValidatePort(conf, "uplink", "port", vi_port)) - throw ConfigException("One or more values in your configuration file failed to validate. Please see your ircd.log for more information."); + throw ConfigException("One or more values in your configuration file failed to validate. Please see your log for more information."); // Validate the password to make sure it is not empty if (!ValidateNotEmpty(conf, "uplink", "password", vi_password)) - throw ConfigException("One or more values in your configuration file failed to validate. Please see your ircd.log for more information."); + throw ConfigException("One or more values in your configuration file failed to validate. Please see your log for more information."); // If we get here, all the values are valid, we'll add it to the Uplinks list Uplinks.push_back(new Uplink(host, port, password)); return true; @@ -583,6 +589,94 @@ bool DoneUplinks(ServerConfig *, const char *, bool bail) return true; } +static bool InitOperTypes(ServerConfig *, const char *, bool) +{ + for (std::list<OperType *>::iterator it = MyOperTypes.begin(); it != MyOperTypes.end(); it++) + { + delete *(it); + } + + MyOperTypes.clear(); + return true; +} + +static bool DoOperType(ServerConfig *conf, const char *, const char **, ValueList &values, int *, bool) +{ + const char *name = values[0].GetString(); + const char *commands = values[1].GetString(); + const char *privs = values[2].GetString(); + + ValueItem vi(name); + if (!ValidateNotEmpty(conf, "opertype", "name", vi)) + throw ConfigException("One or more values in your configuration file failed to validate. Please see your log for more information."); + + OperType *ot = new OperType(name); + + std::string tok; + spacesepstream cmdstr(commands); + while (cmdstr.GetToken(tok)) + { + ot->AddCommand(tok); + } + + spacesepstream privstr(privs); + while (privstr.GetToken(tok)) + { + ot->AddPriv(tok); + } + + MyOperTypes.push_back(ot); + return true; +} + +static bool DoneOperTypes(ServerConfig *, const char *, bool) +{ + return true; +} + + +/*************************************************************************/ + +static bool InitOpers(ServerConfig *, const char *, bool) +{ + int i; + NickCore *nc; + + for (i = 0; i < 1024; i++) + { + for (nc = nclists[i]; nc; nc = nc->next) + { + nc->ot = NULL; + } + } + + return true; +} + +static bool DoOper(ServerConfig *conf, const char *, const char **, ValueList &values, int *, bool) +{ + const char *name = values[0].GetString(); + const char *type = values[1].GetString(); + + ValueItem vi(name); + if (!ValidateNotEmpty(conf, "oper", "name", vi)) + throw ConfigException("One or more values in your configuration file failed to validate. Please see your log for more information."); + + ValueItem vi2(type); + if (!ValidateNotEmpty(conf, "oper", "type", vi2)) + throw ConfigException("One or more values in your configuration file failed to validate. Please see your log for more information."); + + svsopers_in_config.push_back(std::make_pair(name, type)); + return true; +} + +static bool DoneOpers(ServerConfig *, const char *, bool) +{ + return true; +} + +/*************************************************************************/ + bool InitModules(ServerConfig *, const char *, bool) { Modules.clear(); @@ -595,7 +689,7 @@ bool DoModule(ServerConfig *conf, const char *, const char **, ValueList &values const char *module = values[0].GetString(); ValueItem vi(module); if (!ValidateNotEmpty(conf, "module", "name", vi)) - throw ConfigException("One or more values in your configuration file failed to validate. Please see your ircd.log for more information."); + throw ConfigException("One or more values in your configuration file failed to validate. Please see your log for more information."); // If the string isn't empty, add a space before we add the module name if (!Modules.empty()) Modules += " "; // Add the module name to the string @@ -831,6 +925,7 @@ int ServerConfig::Read(bool bail) {"defcon", "akillreason", "", new ValueContainerChar(&DefConAkillReason), DT_CHARPTR, ValidateDefCon}, {NULL, NULL, NULL, NULL, DT_NOTHING, NoValidation} }; + /* 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[] = { @@ -844,12 +939,23 @@ int ServerConfig::Read(bool bail) {"", NULL}, {DT_CHARPTR}, InitModules, DoModule, DoneModules}, + {"opertype", + {"name", "commands", "privs", NULL}, + {"", "", "", NULL}, + {DT_CHARPTR, DT_CHARPTR, DT_CHARPTR}, + InitOperTypes, DoOperType, DoneOperTypes}, + {"oper", + {"name", "type", NULL}, + {"", "", NULL}, + {DT_CHARPTR, DT_CHARPTR}, + InitOpers, DoOper, DoneOpers}, {NULL, {NULL}, {NULL}, {0}, NULL, NULL, NULL} }; + // Load and parse the config file, if there are any errors then explode // Make a copy here so if it fails then we can carry on running with an unaffected config newconfig.clear(); diff --git a/src/svsopers.cpp b/src/opertype.cpp index 8b2adee5b..440078f96 100644 --- a/src/svsopers.cpp +++ b/src/opertype.cpp @@ -11,22 +11,26 @@ #include "services.h" -bool SVSOper::HasCommand(const std::string &cmdstr) +OperType::OperType(const std::string &nname) : name(nname) +{ +} + +bool OperType::HasCommand(const std::string &cmdstr) { } -bool SVSOper::HasPriv(const std::string &privstr) +bool OperType::HasPriv(const std::string &privstr) { } -void SVSOper::AddCommand(const std::string &cmdstr) +void OperType::AddCommand(const std::string &cmdstr) { this->commands.push_back(cmdstr); } -void SVSOper::AddPriv(const std::string &privstr) +void OperType::AddPriv(const std::string &privstr) { this->privs.push_back(privstr); } |