config.h

Go to the documentation of this file.
00001 /*
00002  *
00003  * (C) 2003-2013 Anope Team
00004  * Contact us at team@anope.org
00005  *
00006  * Please read COPYING and README for further details.
00007  *
00008  * Based on the original code of Epona by Lara.
00009  * Based on the original code of Services by Andy Church.
00010  *
00011  */
00012 
00013 #ifndef CONFIG_H
00014 #define CONFIG_H
00015 
00016 #include "account.h"
00017 #include "regchannel.h"
00018 #include "users.h"
00019 
00022 typedef std::pair<Anope::string, Anope::string> KeyVal;
00023 
00026 typedef std::vector<KeyVal> KeyValList;
00027 
00030 typedef std::multimap<Anope::string, KeyValList> ConfigDataHash;
00031 
00032 // Required forward definitions
00033 
00036 enum ConfigDataType
00037 {
00038         DT_NOTHING, // No data
00039         DT_INTEGER, // Integer
00040         DT_UINTEGER, // Unsigned Integer
00041         DT_LUINTEGER, // Long Unsigned Integer
00042         DT_STRING, // Anope::string
00043         DT_BOOLEAN, // Boolean
00044         DT_HOSTNAME, // Hostname syntax
00045         DT_NOSPACES, // No spaces
00046         DT_IPADDRESS, // IP address (v4, v6)
00047         DT_TIME, // Time value
00048         DT_NORELOAD = 32, // Item can't be reloaded after startup
00049         DT_ALLOW_WILD = 64, // Allow wildcards/CIDR in DT_IPADDRESS
00050         DT_ALLOW_NEWLINE = 128, // New line characters allowed in DT_STRING
00051         DT_ALLOW_EMPTY = 256 // Allow empty value
00052 };
00053 
00060 class CoreExport ValueItem
00061 {
00062  private:
00064         Anope::string v;
00065  public:
00067         ValueItem();
00069         ValueItem(int);
00071         ValueItem(bool);
00073         ValueItem(const Anope::string &);
00075         ValueItem(long);
00077         void Set(const Anope::string &);
00079         void Set(int);
00081         int GetInteger() const;
00083         const char *GetString() const;
00085         inline const Anope::string &GetValue() const { return v; }
00087         bool GetBool() const;
00088 };
00089 
00093 class ValueContainerBase
00094 {
00095  public:
00097         ValueContainerBase() { }
00099         virtual ~ValueContainerBase() { }
00100 };
00101 
00110 template<typename T> class ValueContainer : public ValueContainerBase
00111 {
00112  private:
00114         T val;
00115  public:
00117         ValueContainer() : ValueContainerBase(), val(NULL) { }
00119         ValueContainer(T Val) : ValueContainerBase(), val(Val) { }
00121         ValueContainer(const ValueContainer &Val) : ValueContainerBase(), val(Val.val) { }
00122         ValueContainer &operator=(const ValueContainer &Val)
00123         {
00124                 val = Val.val;
00125                 return *this;
00126         }
00128         void Set(const T newval, size_t s)
00129         {
00130                 memcpy(val, newval, s);
00131         }
00132 };
00133 
00136 template<> class ValueContainer<Anope::string *> : public ValueContainerBase
00137 {
00138  private:
00140         Anope::string *val;
00141  public:
00143         ValueContainer() : ValueContainerBase(), val(NULL) { }
00145         ValueContainer(Anope::string *Val) : ValueContainerBase(), val(Val) { }
00147         ValueContainer(const ValueContainer &Val) : ValueContainerBase(), val(Val.val) { }
00148         ValueContainer &operator=(const ValueContainer &Val)
00149         {
00150                 val = Val.val;
00151                 return *this;
00152         }
00153 
00155         void Set(const Anope::string &newval)
00156         {
00157                 *val = newval;
00158         }
00160         void Set(const char *newval)
00161         {
00162                 *val = newval;
00163         }
00164 };
00165 
00168 typedef ValueContainer<bool *> ValueContainerBool;
00169 
00173 typedef ValueContainer<unsigned *> ValueContainerUInt;
00174 
00178 typedef ValueContainer<long unsigned *> ValueContainerLUInt;
00179 
00183 typedef ValueContainer<int *> ValueContainerInt;
00184 
00188 typedef ValueContainer<time_t *> ValueContainerTime;
00189 
00193 typedef ValueContainer<Anope::string *> ValueContainerString;
00194 
00197 typedef std::deque<ValueItem> ValueList;
00198 
00201 typedef bool (*Validator)(ServerConfig *, const Anope::string &, const Anope::string &, ValueItem &);
00204 typedef bool (*MultiValidator)(ServerConfig *, const Anope::string &, const Anope::string *, ValueList &, int *);
00207 typedef bool (*MultiNotify)(ServerConfig *, const Anope::string &);
00208 
00211 class ConfigurationFile
00212 {
00213         Anope::string name;
00214         bool executable;
00215         FILE *fp;
00216  public:
00217         ConfigurationFile(const Anope::string &, bool);
00218         ~ConfigurationFile();
00219         const Anope::string &GetName() const;
00220 
00221         bool IsOpen() const;
00222         bool Open();
00223         void Close();
00224         bool End() const;
00225         Anope::string Read();
00226 };
00227 
00230 class CoreExport ConfigItems
00231 {
00232  public:
00235         struct Item
00236         {
00238                 Anope::string tag;
00240                 Anope::string value;
00242                 Anope::string default_value;
00244                 ValueContainerBase *val;
00246                 int datatype;
00248                 Validator validation_function;
00249         } *Values;
00250 
00254         struct MultiItem
00255         {
00257                 Anope::string tag;
00259                 Anope::string items[17];
00261                 Anope::string items_default[17];
00263                 int datatype[17];
00265                 MultiNotify init_function;
00267                 MultiValidator validation_function;
00269                 MultiNotify finish_function;
00270         } *MultiValues;
00271 
00272         ConfigItems(ServerConfig *conf);
00273         ~ConfigItems();
00274 };
00275 
00280 class CoreExport ServerConfig
00281 {
00282  private:
00285         bool CheckOnce(const Anope::string &);
00286  public:
00290         ConfigDataHash config_data;
00293         ServerConfig();
00294 
00299         void Read();
00303         void LoadConf(ConfigurationFile &file);
00304         // Both these return true if the value existed or false otherwise
00307         bool ConfValue(ConfigDataHash &, const Anope::string &, const Anope::string &, int, Anope::string &, bool = false);
00310         bool ConfValue(ConfigDataHash &, const Anope::string &, const Anope::string &, const Anope::string &, int, Anope::string &, bool = false);
00313         bool ConfValueInteger(ConfigDataHash &, const Anope::string &, const Anope::string &, int, int &);
00316         bool ConfValueInteger(ConfigDataHash &, const Anope::string &, const Anope::string &, const Anope::string &, int, int &);
00319         bool ConfValueBool(ConfigDataHash &, const Anope::string &, const Anope::string &, int);
00322         bool ConfValueBool(ConfigDataHash &, const Anope::string &, const Anope::string &, const Anope::string &, int);
00325         int ConfValueEnum(const ConfigDataHash &, const Anope::string &);
00328         int ConfVarEnum(ConfigDataHash &, const Anope::string &, int);
00329         void ValidateHostname(const Anope::string &, const Anope::string &, const Anope::string &) const;
00330         void ValidateIP(const Anope::string &p, const Anope::string &, const Anope::string &, bool) const;
00331         void ValidateNoSpaces(const Anope::string &, const Anope::string &, const Anope::string &) const;
00332 
00333         struct Uplink
00334         {
00335                 Anope::string host;
00336                 unsigned port;
00337                 Anope::string password;
00338                 bool ipv6;
00339 
00340                 Uplink(const Anope::string &_host, int _port, const Anope::string &_password, bool _ipv6) : host(_host), port(_port), password(_password), ipv6(_ipv6) { }
00341                 bool operator==(const Uplink &other) const
00342                 {
00343                         if (this->host != other.host)
00344                                 return false;
00345                         if (this->port != other.port)
00346                                 return false;
00347                         if (this->password != other.password)
00348                                 return false;
00349                         if (this->ipv6 != other.ipv6)
00350                                 return false;
00351                         return true;
00352                 }
00353                 inline bool operator!=(const Uplink &other) const { return !(*this == other); }
00354         };
00355 
00358         /* Host to bind to */
00359         Anope::string LocalHost;
00360         /* List of uplink servers to try and connect to */
00361         std::vector<Uplink *> Uplinks;
00362 
00363         /* Our server name */
00364         Anope::string ServerName;
00365         /* Our servers description */
00366         Anope::string ServerDesc;
00367 
00368         /* Name of the network were on */
00369         Anope::string NetworkName;
00370         /* The max legnth of nicks */
00371         unsigned NickLen;
00372         /* Max length of idents */
00373         unsigned UserLen;
00374         /* Max lenght of hostnames */
00375         unsigned HostLen;
00376         /* Max length of channel names */
00377         unsigned ChanLen;
00378 
00379         /* User and group to run as */
00380         Anope::string User;
00381         Anope::string Group;
00382 
00383         /* Casemapping to use */
00384         Anope::string CaseMap;
00385 
00386         /* Max length of passwords */
00387         unsigned PassLen;
00388 
00389         /* Filename for the PID file */
00390         Anope::string PIDFilename;
00391         /* MOTD filename */
00392         Anope::string MOTDFilename;
00393 
00394         Anope::string BotServ;
00395         Anope::string ChanServ;
00396         Anope::string Global;
00397         Anope::string HostServ;
00398         Anope::string NickServ;
00399         Anope::string OperServ;
00400         Anope::string MemoServ;
00401 
00402         /* True if its ok to not be able to save backs */
00403         bool NoBackupOkay;
00404         /* Do password checking when new people register */
00405         bool StrictPasswords;
00406         /* How many times you're allowed to give a bad password before being killed */
00407         unsigned BadPassLimit;
00408         /* How long before bad passwords are forgotten */
00409         time_t BadPassTimeout;
00410         /* Delay between automatic database updates */
00411         time_t UpdateTimeout;
00412         /* Delay between checks for expired nicks and channels */
00413         time_t ExpireTimeout;
00414         /* How long to wait for something from the uplink, this is passed to select() */
00415         time_t ReadTimeout;
00416         /* How often to send program errors */
00417         time_t WarningTimeout;
00418         /* How long to process things such as timers to see if there is anything to calll */
00419         time_t TimeoutCheck;
00420         /* Number of days backups are kept */
00421         int KeepBackups;
00422         /* Forbidding requires a reason */
00423         bool ForceForbidReason;
00424         /* Services should use privmsgs instead of notices */
00425         bool UsePrivmsg;
00426         /* Services only respond to full PRIVMSG client@services.server.name messages */
00427         bool UseStrictPrivMsg;
00428         /* This is not a configurable option.
00429          * Config::Config will set it depending on the value of UseStrictPrivMsg */
00430         Anope::string UseStrictPrivMsgString;
00431         /* Number of seconds between consecutive uses of the REGISTER command
00432          * Not to be confused with NSRegDelay */
00433         unsigned NickRegDelay;
00434         /* Max number if news items allowed in the list */
00435         unsigned NewsCount;
00436         /* Default mlock modes */
00437         Anope::string MLock;
00438         /* Unmlockable modes */
00439         Anope::string NoMLock;
00440         /* Modes that are required to be on registered channels */
00441         Anope::string CSRequire;
00442         /* Use server side mlock */
00443         bool UseServerSideMLock;
00444         /* Use server side topic lock */
00445         bool UseServerSideTopicLock;
00446         /* The max length for reasons (cs_kick, cs_ban, etc) */
00447         unsigned CSReasonMax;
00448         /* Default botmodes on channels, defaults to ao */
00449         Anope::string BotModes;
00450         /* How long to wait between connection attempts */
00451         int RetryWait;
00452         /* If services should hide unprivileged commands */
00453         bool HidePrivilegedCommands;
00454         /* If set, nicks cant be owned/everything is entirely account based */
00455         bool NoNicknameOwnership;
00456         /* Regex engine to use */
00457         Anope::string RegexEngine;
00458 
00459         /* A vector of our logfile options */
00460         std::vector<LogInfo *> LogInfos;
00461 
00462         /* Services can use email */
00463         bool UseMail;
00464         /* Path to the sendmail executable */
00465         Anope::string SendMailPath;
00466         /* Address to send from */
00467         Anope::string SendFrom;
00468         /* Only opers can have services send mail */
00469         bool RestrictMail;
00470         /* Delay between sending mail */
00471         time_t MailDelay;
00472         /* Don't quote the To: address */
00473         bool DontQuoteAddresses;
00474         /* Mail messages to send */
00475         Anope::string MailRegistrationSubject, MailRegistrationMessage;
00476         Anope::string MailResetSubject, MailResetMessage;
00477         Anope::string MailEmailchangeSubject, MailEmailchangeMessage;
00478         Anope::string MailMemoSubject, MailMemoMessage;
00479 
00480         /* Prefix of guest nicks when a user gets forced off of a nick */
00481         Anope::string NSGuestNickPrefix;
00482         /* Allow users to set kill immed on */
00483         bool NSAllowKillImmed;
00484         /* Don't allow nicks to use /ns group to regroup nicks */
00485         bool NSNoGroupChange;
00486         /* Default flags for newly registered nicks */
00487         std::set<Anope::string> NSDefFlags;
00488         /* All languages Anope is aware about */
00489         Anope::string Languages;
00490         /* Default language used by services */
00491         Anope::string NSDefLanguage;
00492         /* Users must be connected this long before they can register
00493          * Not to be confused with NickRegDelay */
00494         time_t NSRegDelay;
00495         /* Time before the registering mail will be resent */
00496         time_t NSResendDelay;
00497         /* How long before nicks expire */
00498         time_t NSExpire;
00499         /* How long before suspended nicks expire */
00500         time_t NSSuspendExpire;
00501         /* Time before unconfirmed nicks expire */
00502         time_t NSUnconfirmedExpire;
00503         /* Force email when registering */
00504         bool NSForceEmail;
00505         /* Force users to validate new email addresses */
00506         bool NSConfirmEmailChanges;
00507         /* Max number of nicks in a group */
00508         unsigned NSMaxAliases;
00509         /* Max number of allowed strings on the access list */
00510         unsigned NSAccessMax;
00511         /* Enforcer client user name */
00512         Anope::string NSEnforcerUser;
00513         /* Enforcer client hostname */
00514         Anope::string NSEnforcerHost;
00515         /* How long before recovered nicks are released */
00516         time_t NSReleaseTimeout;
00517         /* Max number of entries that can be returned from the list command */
00518         unsigned NSListMax;
00519         /* Only allow usermode +a etc on real services admins */
00520         bool NSSecureAdmins;
00521         /* Services opers must be /operd on the ircd aswell */
00522         bool NSStrictPrivileges;
00523         /* Type of confirmation to use, or to disable registration completely */
00524         Anope::string NSRegistration;
00525         /* A message sent to unregistered users on connect */
00526         Anope::string NSUnregisteredNotice;
00527         /* Core NickServ modules */
00528         Anope::string NickCoreModules;
00529         /* Set the proper channel modes on users when they identify */
00530         bool NSModeOnID;
00531         /* Add the users hostnask their access list when they register */
00532         bool NSAddAccessOnReg;
00533         /* Maximum number of channels on AJoin */
00534         unsigned AJoinMax;
00535         /* Kill & killquick delays before force changing off users */
00536         time_t NSKillQuick;
00537         time_t NSKill;
00538         /* Modes set on a user when they identify */
00539         Anope::string NSModesOnID;
00540         /* Restore nick/channels on recover */
00541         bool NSRestoreOnRecover;
00542         /* Whether or not to use SASL */
00543         bool NSSASL;
00544         /* If set, hides netsplits in the last_quit field of nicks */
00545         bool NSHideNetSplitQuit;
00546 
00547         /* Core ChanServ modules */
00548         Anope::string ChanCoreModules;
00549         /* Default flags for newly registered channels */
00550         std::set<Anope::string> CSDefFlags;
00551         /* Max number of channels a user can own */
00552         unsigned CSMaxReg;
00553         /* Time before a channel expires */
00554         time_t CSExpire;
00555         /* How long before suspended channels expire */
00556         time_t CSSuspendExpire;
00557         /* How long before forbidden channels expire */
00558         time_t CSForbidExpire;
00559         /* Default ban type to use for channels */
00560         int CSDefBantype;
00561         /* Max number of entries allowed on channel access lists */
00562         unsigned CSAccessMax;
00563         /* Max number of entries allowed on autokick lists */
00564         unsigned CSAutokickMax;
00565         /* Default autokick reason */
00566         Anope::string CSAutokickReason;
00567         /* Time ChanServ should stay in the channel to hold it to keep users from getting in */
00568         time_t CSInhabit;
00569         /* Max number of entries allowed to be returned from the LIST command */
00570         unsigned CSListMax;
00571         /* true to make ChanServ oper only */
00572         bool CSOpersOnly;
00573 
00574         /* Max number of memos allowed */
00575         unsigned MSMaxMemos;
00576         /* Time you must wait between sending memos */
00577         time_t MSSendDelay;
00578         /* Notify all of the aliases of the core the memo was sent to */
00579         bool MSNotifyAll;
00580         /* Who can use memos reciepts */
00581         unsigned MSMemoReceipt;
00582 
00583         /* Valid chars allowed in vhosts */
00584         Anope::string VhostChars;
00585         /* Allow undotted vhosts? */
00586         bool VhostUndotted;
00587         /* Chars disallowed at the beginning or end of vhosts */
00588         Anope::string VhostDisallowBE;
00589 
00590         /* Core BotServ modules */
00591         Anope::string BotCoreModules;
00592         /* Default BotServ flags */
00593         std::set<Anope::string> BSDefFlags;
00594         /* How long before botserv forgets a user. This is used for flood kickers etc */
00595         time_t BSKeepData;
00596         /* Min number of users to have in the channel before the service bot joins */
00597         unsigned BSMinUsers;
00598         /* Max number of words allowed on the badwordslist */
00599         unsigned BSBadWordsMax;
00600         /* BotServ bot only joins if it would normally allowed to, abides by bans etc */
00601         bool BSSmartJoin;
00602         /* Dont tell users what badword they used */
00603         bool BSGentleBWReason;
00604         /* Case sensitive badwords matching */
00605         bool BSCaseSensitive;
00606         /* Char to use for the fantasy char, eg ! */
00607         Anope::string BSFantasyCharacter;
00608 
00609         /* Only show /stats o to opers */
00610         bool HideStatsO;
00611         /* Send out a global when services shut down or restart */
00612         bool GlobalOnCycle;
00613         /* Don't include the opers name in globals */
00614         bool AnonymousGlobal;
00615         /* Dont allow users to register nicks with oper names in them */
00616         bool RestrictOperNicks;
00617         /* Message to send when shutting down */
00618         Anope::string GlobalOnCycleMessage;
00619         /* Message to send when starting up */
00620         Anope::string GlobalOnCycleUP;
00621         /* Super admin is allowed */
00622         bool SuperAdmin;
00623         /* Default expiry time for akills */
00624         time_t AutokillExpiry;
00625         /* Default expiry time for chan kills */
00626         time_t ChankillExpiry;
00627         /* Default expiry time for SNLine Expire */
00628         time_t SNLineExpiry;
00629         /* Default expiry time for SQLines */
00630         time_t SQLineExpiry;
00631         /* Actually akill the user when the akill is added */
00632         bool AkillOnAdd;
00633         /* Kill users on SNLine */
00634         bool KillonSNline;
00635         /* Kill users on SQline */
00636         bool KillonSQline;
00637         /* Add the akillers nick to the akill reason */
00638         bool AddAkiller;
00639         /* Add akill ids to akill reason */
00640         bool AkillIds;
00641 
00642         /* Limit sessions */
00643         bool LimitSessions;
00644         /* The default session limit */
00645         unsigned DefSessionLimit;
00646         /* How long before exceptions expire */
00647         time_t ExceptionExpiry;
00648         /* How many times to kill before adding an KILL */
00649         unsigned MaxSessionKill;
00650         /* Max limit that can be used for exceptions */
00651         unsigned MaxSessionLimit;
00652         /* How long session akills should last */
00653         time_t SessionAutoKillExpiry;
00654         /* Number of bits to use when comparing session IPs */
00655         unsigned SessionIPv4CIDR;
00656         unsigned SessionIPv6CIDR;
00657         /* Reason to use for session kills */
00658         Anope::string SessionLimitExceeded;
00659         /* Optional second reason */
00660         Anope::string SessionLimitDetailsLoc;
00661         /* OperServ requires you to be an operator */
00662         bool OSOpersOnly;
00663 
00664         /* List of modules to autoload */
00665         std::list<Anope::string> ModulesAutoLoad;
00666 
00667         /* Seed to use for RNG */
00668         unsigned long Seed;
00669 
00670         /* Numeric */
00671         Anope::string Numeric;
00672         /* Array of ulined servers */
00673         std::list<Anope::string> Ulines;
00674 
00675         /* List of available opertypes */
00676         std::list<OperType *> MyOperTypes;
00677         /* List of pairs of opers and their opertype from the config */
00678         std::vector<Oper *> Opers;
00679 
00680         /* Map of fantasy commands */
00681         CommandInfo::map Fantasy;
00682 
00683         std::vector<CommandGroup> CommandGroups;
00684 };
00685 
00692 class ConfigException : public CoreException
00693 {
00694  public:
00697         ConfigException() : CoreException("Config threw an exception", "Config Parser") { }
00700         ConfigException(const Anope::string &message) : CoreException(message, "Config Parser") { }
00705         virtual ~ConfigException() throw() { }
00706 };
00707 
00708 #define CONF_NO_ERROR 0x000000
00709 #define CONF_NOT_A_NUMBER 0x000010
00710 #define CONF_INT_NEGATIVE 0x000080
00711 #define CONF_VALUE_NOT_FOUND 0x000100
00712 #define CONF_FILE_NOT_FOUND 0x000200
00713 
00720 class CoreExport ConfigReader
00721 {
00722  protected:
00725         bool readerror;
00728         long error;
00729  public:
00733         ConfigReader();
00737         ConfigReader(const Anope::string &);
00741         ~ConfigReader();
00746         Anope::string ReadValue(const Anope::string &, const Anope::string &, int, bool = false);
00752         Anope::string ReadValue(const Anope::string &, const Anope::string &, const Anope::string &, int, bool = false);
00758         bool ReadFlag(const Anope::string &, const Anope::string &, int);
00765         bool ReadFlag(const Anope::string &, const Anope::string &, const Anope::string &, int);
00775         int ReadInteger(const Anope::string &, const Anope::string &, int, bool);
00784         int ReadInteger(const Anope::string &, const Anope::string &, const Anope::string &, int, bool);
00789         long GetError();
00796         int Enumerate(const Anope::string &) const;
00801         bool Verify();
00807         int EnumerateValues(const Anope::string &, int);
00808 };
00809 
00810 extern ConfigurationFile ServicesConf;
00811 extern CoreExport ServerConfig *Config;
00812 
00813 #endif // CONFIG_H