// 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: /// Running status of the Sniffer application. enum SnifferRunningStateEnum { SnifferIsRunning, ///< OpenBSD OS. SnifferIsStopped, ///< FreeBSD OS. SnifferRunningStatusIsUknown ///< Ubuntu and variants. }; /// Default constructor. UtilityConfig(void); /// 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. In any case, set the owner and mode. // // 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); /// Setup/repair the configuration. // // This method creates any configuration files that don't exist // from the sample files. void SetupCreate(void); /// 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(void); /// 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(void); /// Postfix main.cf file path. std::string PostfixMainCfPath; /// Postfix master.cf file path. std::string PostfixMasterCfPath; /// Directory containing the Sniffer start script. std::string SnifferStartScriptDir; /// Setup/repair the configuration. // // Copy the following files from the sample files if they don't // exist: // //
    //
  1. Identity file.
  2. //
  3. Ignore list file.
  4. //
  5. Rulebase script.
  6. //
// // Set the owner/group of each of the above files. // // Make sure that the log directory exists and has the correct // owner and permissions. // void SetupRepair(const std::string SampleIdentityFile); /// Update the rulebase script credentials. // // This method updates the rulebase with the credentials specified // on the command line. // void UpdateRulebaseScriptCredentials(void); /// Download the rulebase. // void DownloadRulebase(void); /// 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); /// Start the sniffer. // // This method runs the specified sniffer start script in the // appropriate (i.e. OS-dependent) directory. The script is // prepended with the directory, and run with an argument of // "start". // // \param[in] Script is the name of the start script. // // \pre LoadInfo() must have been called. That method initializes // the directory the script resides in. // void StartSniffer(std::string Script); /// 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(void); /// Output the legal command-line input. // // \param[in] ExclusiveCommands contains the command-line help of // the additional commands implemented by the descendent classes. // Only one command may be specified when invoking the // configuration utility. // std::string HelpCommandLine(std::string ExclusiveCommands); /// Output the description of the legal command-line input. // // \param[in] ExclusiveCommandsHelp contains the description of // the additional commands implemented by the descendent classes. // std::string HelpDescription(std::string ExclusiveCommandsHelp); /// Store whether the setup/help command was specified. // // \param[in] Specified specifies whether the command was specified. // void SetSetupRepair(bool Specified); /// Setup/repair specified? // // \returns true if the setup/help command was specified on the command line. // bool SetupRepairSpecified(void); /// 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(void); /// Store whether the start sniffer command was specified. // // \param[in] Specified specifies whether the command was specified. // void SetStartSniffer(bool Specified); /// Start sniffer specified? // // \returns true if the start sniffer command was specified on the command line. // bool StartSnifferSpecified(void); /// Store whether the stop sniffer command was specified. // // \param[in] Specified specifies whether the command was specified. // void SetStopSniffer(bool Specified); /// Stop sniffer specified? // // \returns true if the stop sniffer command was specified on the command line. // bool StopSnifferSpecified(void); private: /// Setup/repair the identity file. // // If the identity file doesn't exist, create it from the sample // file. // // In any case, set the owner and permissions of the identity // file. // // \param[in] SampleIdentityFile is the name of the sample // identity file. // // \note The configuration information must be loaded before calling this method. // // \see CheckAndSetConfigFileName. // // \see CreateDefaultConfigFile. // // \see LoadConfig. // // \see LoadInfo. // void SetupRepairIdentityFile(std::string SampleIdentityFile); /// Setup/repair the rulebase script. // // If the rulebase script doesn't exist, this method creates the // rulebase script from the sample rulebase script. // // In any case, set the owner and permissions of the rulebase // script. // void SetupRepairRulebaseScript(void); /// Setup/repair 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 SetupRepairIgnoreListFile(void); /// Setup/repair 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 SetupRepairLogDir(void); std::string ConfigFileName; ///< Configuration file name. 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; bool SetupRepairRequested; ///< User requested setup/repair. bool StartSnifferRequested; ///< User requested that Sniffer be started. bool StopSnifferRequested; ///< User requested that Sniffer be stopped. }; #endif