// 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 "SNFMulti.hpp" #include /// Base class for the Sniffer configuration. // // This class provides capability common to the configuration applications. // ////////////////////////////////////////////////////////////////////////////////////////////////////////// class UtilityConfig { public: /// Default constructor. UtilityConfig(); /// Check whether a file exists. // // \returns true if the file exists, false otherwise. // bool FileExists(std::string File); /// 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); /// Copy a file. // // \param[in] From is the name of the source file. // // \param[in] To is the name of the destination file. // void Copy(std::string From, std::string To); /// Set the owner and group of the specified file. // // This function sets the owner and group of the specified file to the // value specified in UtilityConfig.cpp. // // \param[in] File is the specified file. // // \see SNFUserName. // // \see SNFGroupName. // void SetOwnerGroup(std::string &File); /// Set the mode of a file. // // This function sets the mode of the specified file. If an error // occurs, an exception is thrown. // // \param[in] File is the specified file. // // \param[in] is the mode. // void SetMode(std::string &File, mode_t mode); /// Create a directory. // // This function creates the specified directory. If an error // occurs, an exception is thrown. // // \param[in] Dir is the directory to create. // void MkDir(std::string &Dir); /// 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); /// Check for a specified string at the beginning of a line. // // This function checks for the specified string at the beginning of a // line. Leading whitespace in the line is ignored. // // \param[in] Line is the line. // // \param[in] SearchString is the string to check for. // static bool CheckForString(std::string Line, std::string SearchString); /// 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 main.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); /// Provide verbose output? // // \returns true if the application is to provide verbose output. // bool Verbose(); /// Provide an explanation of the actions only? // // \returns true if the application is to provide an explanation // of the actions without executing any commands. // bool Explain(); /// Provide help? // // \returns true if the application is to output a help message. // bool Help(); /// Output the legal command-line input. std::string HelpCommandLine(); /// Output the description of the legal command-line input. std::string HelpDescription(); /// Output the end of a verbose output line. void OutputVerboseEnd(); private: bool VerboseRequested; ///< User requested verbose processing. bool ExplainRequested; ///< User requested verbose processing but without actually executing the commands. bool HelpRequested; ///< User requested help. 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