From f07229a9ee06bd989efd14f4223e787b90f9148e Mon Sep 17 00:00:00 2001 From: rburchell Date: Sun, 15 Feb 2009 15:21:35 +0000 Subject: Blah, blah.. git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2061 5417fbe8-f217-4b02-8779-1006273d7864 --- include/account.h | 3 ++ include/opertype.h | 60 ++++++++++++++++++++++++++++ include/services.h | 2 +- include/svsoper.h | 56 -------------------------- src/Makefile | 4 +- src/config.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++-- src/opertype.cpp | 37 +++++++++++++++++ src/svsopers.cpp | 33 ---------------- 8 files changed, 213 insertions(+), 96 deletions(-) create mode 100644 include/opertype.h delete mode 100644 include/svsoper.h create mode 100644 src/opertype.cpp delete mode 100644 src/svsopers.cpp 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/opertype.h b/include/opertype.h new file mode 100644 index 000000000..9d5e77224 --- /dev/null +++ b/include/opertype.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2008-2009 Robin Burchell + * Copyright (C) 2008-2009 Anope Team + * + * Please read COPYING and README for further details. + * + * + * $Id$ + * + */ + +class OperType +{ + private: + /** The name of this opertype, e.g. "sra". + */ + std::string name; + + /** Privs that this opertype may use, e.g. 'users/auspex'. + * This *must* be std::list, see commands comment for details. + */ + std::list privs; + + /** Commands this user may execute, e.g: + * botserv/set/ *, botserv/set/private, botserv/ * + * et cetera. + * + * This *must* be std::list, not std::map, because + * we support full globbing here. This shouldn't be a problem + * as we don't invoke it often. + */ + std::list 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. + * @return True if this opertype may run the specified command, false otherwise. + */ + bool HasCommand(const std::string &cmdstr); + + /** Check whether this opertype has access to the given special permission. + * @param privstr The priv to check for, e.g. users/auspex. + * @return True if this opertype has the specified priv, false otherwise. + */ + bool HasPriv(const std::string &privstr); + + /** Add the specified command to this opertype. + * @param cmdstr The command mask to grant this opertype access to, e.g: nickserv/ *, chanserv/set/ *, botserv/set/private. + */ + void AddCommand(const std::string &cmdstr); + + /** Add the specified priv mask to this opertype. + * @param privstr The specified mask of privs to grant this opertype access to, e.g. users/auspex, users/ *, etc. + */ + void AddPriv(const std::string &privstr); +}; 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/include/svsoper.h b/include/svsoper.h deleted file mode 100644 index bf5c5c486..000000000 --- a/include/svsoper.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2008-2009 Robin Burchell - * Copyright (C) 2008-2009 Anope Team - * - * Please read COPYING and README for further details. - * - * - * $Id$ - * - */ - -class SVSOper -{ - private: - /** The name of this opertype, e.g. "sra". - */ - std::string name; - - /** Privs that this opertype may use, e.g. 'users/auspex'. - * This *must* be std::list, see commands comment for details. - */ - std::list privs; - - /** Commands this user may execute, e.g: - * botserv/set/ *, botserv/set/private, botserv/ * - * et cetera. - * - * This *must* be std::list, not std::map, because - * we support full globbing here. This shouldn't be a problem - * as we don't invoke it often. - */ - std::list commands; - public: - - /** Check whether this opertype has access to run the given command string. - * @param cmdstr The string to check, e.g. botserv/set/private. - * @return True if this opertype may run the specified command, false otherwise. - */ - bool HasCommand(const std::string &cmdstr); - - /** Check whether this opertype has access to the given special permission. - * @param privstr The priv to check for, e.g. users/auspex. - * @return True if this opertype has the specified priv, false otherwise. - */ - bool HasPriv(const std::string &privstr); - - /** Add the specified command to this opertype. - * @param cmdstr The command mask to grant this opertype access to, e.g: nickserv/ *, chanserv/set/ *, botserv/set/private. - */ - void AddCommand(const std::string &cmdstr); - - /** Add the specified priv mask to this opertype. - * @param privstr The specified mask of privs to grant this opertype access to, e.g. users/auspex, users/ *, etc. - */ - void AddPriv(const std::string &privstr); -}; 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 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 > 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::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/opertype.cpp b/src/opertype.cpp new file mode 100644 index 000000000..440078f96 --- /dev/null +++ b/src/opertype.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2008-2009 Robin Burchell + * Copyright (C) 2008-2009 Anope Team + * + * Please read COPYING and README for further details. + * + * + * $Id$ + * + */ + + #include "services.h" + +OperType::OperType(const std::string &nname) : name(nname) +{ +} + +bool OperType::HasCommand(const std::string &cmdstr) +{ + +} + +bool OperType::HasPriv(const std::string &privstr) +{ + +} + +void OperType::AddCommand(const std::string &cmdstr) +{ + this->commands.push_back(cmdstr); +} + +void OperType::AddPriv(const std::string &privstr) +{ + this->privs.push_back(privstr); +} + diff --git a/src/svsopers.cpp b/src/svsopers.cpp deleted file mode 100644 index 8b2adee5b..000000000 --- a/src/svsopers.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2008-2009 Robin Burchell - * Copyright (C) 2008-2009 Anope Team - * - * Please read COPYING and README for further details. - * - * - * $Id$ - * - */ - - #include "services.h" - -bool SVSOper::HasCommand(const std::string &cmdstr) -{ - -} - -bool SVSOper::HasPriv(const std::string &privstr) -{ - -} - -void SVSOper::AddCommand(const std::string &cmdstr) -{ - this->commands.push_back(cmdstr); -} - -void SVSOper::AddPriv(const std::string &privstr) -{ - this->privs.push_back(privstr); -} - -- cgit