// 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; /// Set the config file name to the default if it wasn't specified. // // If the configuration file wasn't specified by // SetConfigFileName() on the command line, then this method sets // the config file to the default. The default is the unique file // that exists in the specified list. If more than one file in // the specified list exists, an exception is thrown. // // If the configuration file was specified by SetConfigFileName() // or on the command line, then this method does nothing. // // \param[in] DefaultFile is the list of default locations of the file. // // \param[in] NumDefaultFiles is the number of defaultlocations. // void CheckAndSetConfigFileName(const std::string DefaultFile[], int NumDefaultFiles); /// If the configuration file doesn't exist, create it from the /// sample file. // // This method creates the default configuration file if the // specified configuration file doesn't exist. // // The method CheckAndSetConfigFileName must be called before this // method. // // \param[in] SampleConfigFile is the name of the sample // configuration file. // void CreateDefaultConfigFile(std::string SampleConfigFile); /// If the identity file doesn't exist, create it from the sample /// file. // // This method creates the default identity file if the identity // file specified in the configuration file doesn't exist. // // The method CheckAndSetConfigFileName must be called before this // method. // // \param[in] SampleIdentityFile is the name of the sample // identity file. // void CreateDefaultIdentityFile(std::string SampleIdentityFile); /// Load the configuration from the file specified by SetConfigFileName. // void LoadConfig(void); /// 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); /// Get the ignore list file name. // // \returns the ignore list file name. // std::string GetIgnoreListFileName(void); /// Return the rulebase file name. // // \returns the name of the rulebase file, including the path. // std::string GetRulebaseFileName(); /// Get the operating system type. // // \returns the operating system type. This is the value of // SNF_OSTYPE specified on the compile commandline. For *nix, it // is identical to the value of the --enable-os-type command-line // input to ./configure: // //
    //
  1. OpenBSD
  2. //
  3. FreeBSD
  4. //
  5. Suse
  6. //
  7. RedHat
  8. //
  9. Ubuntu
  10. //
// std::string GetOperatingSystemType(void); /// 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(); /// 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(); /// Determine whether the credentials should be updated. // // This method determines whether the credentials should be // updated. If the user specified both the License ID and // Authentication, then the credentials should be updated. // // \returns true if the credentials should be updated. // bool UpdateCredentialsSpecified(); /// Create or update the rulebase script. // // If the rulebase script doesn't exist, this method creates the // rulebase script from the sample rulebase script. // // If the credentials were supplied, this method updates the // rulebase with the supplied credentials. // // In either case, the permissions of the rulebase script are // updated. // void CreateUpdateRulebaseScript(); /// Download the rulebase. // void DownloadRulebase(); /// Update the identity file. // // If the credentials were supplied, this method updates the // identity file with the supplied credentials. // // In any case, the owner/group is changed by SetOwnerGroup(), and // the permissions are changed to readonly for the owner. // // \pre Either the identity file must exist, or the credentials // must be supplied so that the identity file is created. // // \see SetOwnerGroup(). // void UpdateIdentityFile(void); /// Process one command-line item. // // \param[in] OneInput is the command-line item to process. // bool ProcessCommandLineItem(std::string OneInput); /// Check whether the command-line parameters were specified /// correctly. // // This function check that either both the LicenseID and // Authentication were specified, or neither were. // // \returns if the command-line parameters were specified // correctly, false otherwise. bool CommandLineIsOkay(); /// Output the legal command-line input. std::string HelpCommandLine(); /// Output the description of the legal command-line input. std::string HelpDescription(); private: /// Update the credentials of an existing rulebase script. // // This method does the actual work of updating the credentials of // the rulebase script. // // \pre The rulebase script file must exist. // // Side effect: The rulebase script is updated. // void UpdateRulebaseScriptCredentials(); std::string ConfigFileName; ///< Configuration file name. bool ConfigFileExists; ///< True if the configuration file exists. std::string LicenseId; ///< License ID string. bool LicenseIdIsSpecified; ///< true if the License ID was specified on the command line. std::string Authentication; ///< Authentication string. bool AuthenticationIsSpecified; ///< true if the Authentication was specified on the command line. static const std::string RulebaseDownloadCommand; ///< Command to download the rulebase. static const std::string RulebaseDownloadStatusFile; ///< Status file for rulebase download status. 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