123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365 |
- // 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 <string>
-
- #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 <platform> element of the loaded
- /// config file.
- //
- // \returns the contents of the <platform> 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:
- //
- // <ol>
- // <li>OpenBSD</li>
- // <li>FreeBSD</li>
- // <li>Suse</li>
- // <li>RedHat</li>
- // <li>Ubuntu</li>
- // </ol>
- //
- 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;
-
- /// 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
|