// UtilityConfig.hpp // // Copyright (C) 2011 ARM Research Labs, LLC. // See www.armresearch.com for the copyright terms. // // This file defines the interface used by the configuration utilities. // #ifndef UtilityConfighpp_included #define UtilityConfighpp_included #include #include "SNFMulti.hpp" #include "Utility.hpp" #include "FileBackup.hpp" /// Base class for the Sniffer configuration. // // This class provides capability common to the configuration applications. // ////////////////////////////////////////////////////////////////////////////////////////////////////////// class UtilityConfig : public Utility { public: /// Default constructor. UtilityConfig(); /// Object to back up and restore files. FileBackup SaveFile; /// Load the specified or default config file. // // This function loads (or reloads) the config file specified in // the most recent call to LoadConfigFile. If LoadConfigFile has // not been called, then this method searches for a unique default // config file in the specified list, and loads that config file. // // \param[in] DefaultFile is the list of default locations of the file. // // \param[in] NumDefaultFiles is the number of defaultlocations. // // If the local data member ConfigFile has a value of "" on input, // then this function checks for the existence (but not // readability) of a configuration file in several locations. If // exactly one file exists, then that file is loaded and // ConfigFile is set to that name. Otherwise, an exception is // thrown. // void CheckAndLoadConfigFile(const std::string DefaultFile[], int NumDefaultFiles); /// Load the specified configuration file. // // \param[in] Name is the name of the configuration file. // void LoadConfigFile(std::string Name); /// Set the configuration file name. // // \param[in] Name is the name of the configuration file. // void SetConfigFileName(std::string Name); /// Get the configuration file name. // // \returns the name of the configuration file. // std::string GetConfigFileName(void); /// Get the contents of the element of the loaded /// config file. // // \returns the contents of the element. // string GetPlatformContents(void); /// Get the workspace path. // // \returns the workspace path. std::string GetWorkspacePath(void); /// Get the rulebase path. // // \returns the rulebase path. std::string GetRulebasePath(void); /// Get the log path. // // \returns the log path. std::string GetLogPath(void); /// Get the identity file name. // // \returns the identity file name. std::string GetIdentityFileName(void); /// Get the rulebase script file name. // // \returns the rulebase script file name. std::string GetRulebaseScriptName(void); /// Restart the MTA. // // This function starts or restarts the MTA. // // \param[in] Mta specifies the MTA. The acceptable values are // "postfix" and "sendmail". // void StartOrRestartMta(std::string Mta); /// Operating system specification. enum OperatingSystemSpecEnum { OpenBSD, ///< OpenBSD OS. FreeBSD, ///< FreeBSD OS. Ubuntu, ///< Ubuntu and variants. RedHat, ///< RedHat and variants. Suse ///< Suse and variants. }; /// Load the operating-system-dependent info (file locations, etc). // // This method updates the public members that contain the OS // specification and file paths. // void LoadInfo(); /// OS specification. OperatingSystemSpecEnum OsSpec; /// Postfix main.cf file path. std::string PostfixMainCfPath; /// Postfix master.cf file path. std::string PostfixMasterCfPath; /// Create or update the ignore list file. // // The ignore list file is created if it dosn't exist. In any // case, the owner/group is changed by SetOwnerGroup(), and the // permissions are changed to readonly for everyone, and // read/write for the owner. void UpdateIgnoreListFile(); /// Create or update the log directory. // // The log directory is created if it dosn't exist. In any case, // the owner/group is changed by SetOwnerGroup(), and the // permissions are changed to r-x for everyone, and rwx for the // owner. void UpdateLogDir(); /// Process one command-line item. // // \param[in] OneInput is the command-line item to process. // bool ProcessCommandLineItem(std::string OneInput); /// Output the legal command-line input. std::string HelpCommandLine(); /// Output the description of the legal command-line input. std::string HelpDescription(); private: std::string ConfigFile; ///< Configuration file name. static const std::string SampleIgnoreListFile; ///< Sample ignore list file. static const std::string SampleRulebaseScriptFile; ///< Sample rulebase script file. snfCFGData CFGData; ///< Configuration data. /// Operating system type. // // This is either Windows or the value specified for // --enable-os-type when configuring for *nix. static const std::string OperatingSystemType; }; #endif