Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

UtilityConfig.hpp 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // UtilityConfig.hpp
  2. //
  3. // Copyright (C) 2011 ARM Research Labs, LLC.
  4. // See www.armresearch.com for the copyright terms.
  5. //
  6. // This file defines the interface used by the configuration utilities.
  7. //
  8. #ifndef UtilityConfighpp_included
  9. #define UtilityConfighpp_included
  10. #include <string>
  11. #include "SNFMulti.hpp"
  12. #include "Utility.hpp"
  13. #include "FileBackup.hpp"
  14. /// Base class for the Sniffer configuration.
  15. //
  16. // This class provides capability common to the configuration applications.
  17. //
  18. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  19. class UtilityConfig : public Utility {
  20. public:
  21. /// Default constructor.
  22. UtilityConfig();
  23. /// Object to back up and restore files.
  24. FileBackup SaveFile;
  25. /// Load the specified or default config file.
  26. //
  27. // This function loads (or reloads) the config file specified in
  28. // the most recent call to LoadConfigFile. If LoadConfigFile has
  29. // not been called, then this method searches for a unique default
  30. // config file in the specified list, and loads that config file.
  31. //
  32. // \param[in] DefaultFile is the list of default locations of the file.
  33. //
  34. // \param[in] NumDefaultFiles is the number of defaultlocations.
  35. //
  36. // If the local data member ConfigFile has a value of "" on input,
  37. // then this function checks for the existence (but not
  38. // readability) of a configuration file in several locations. If
  39. // exactly one file exists, then that file is loaded and
  40. // ConfigFile is set to that name. Otherwise, an exception is
  41. // thrown.
  42. //
  43. void CheckAndLoadConfigFile(const std::string DefaultFile[], int NumDefaultFiles);
  44. /// Load the specified configuration file.
  45. //
  46. // \param[in] Name is the name of the configuration file.
  47. //
  48. void LoadConfigFile(std::string Name);
  49. /// Set the configuration file name.
  50. //
  51. // \param[in] Name is the name of the configuration file.
  52. //
  53. void SetConfigFileName(std::string Name);
  54. /// Get the configuration file name.
  55. //
  56. // \returns the name of the configuration file.
  57. //
  58. std::string GetConfigFileName(void);
  59. /// Get the contents of the <platform> element of the loaded
  60. /// config file.
  61. //
  62. // \returns the contents of the <platform> element.
  63. //
  64. string GetPlatformContents(void);
  65. /// Get the workspace path.
  66. //
  67. // \returns the workspace path.
  68. std::string GetWorkspacePath(void);
  69. /// Get the rulebase path.
  70. //
  71. // \returns the rulebase path.
  72. std::string GetRulebasePath(void);
  73. /// Get the log path.
  74. //
  75. // \returns the log path.
  76. std::string GetLogPath(void);
  77. /// Get the identity file name.
  78. //
  79. // \returns the identity file name.
  80. std::string GetIdentityFileName(void);
  81. /// Get the rulebase script file name.
  82. //
  83. // \returns the rulebase script file name.
  84. std::string GetRulebaseScriptName(void);
  85. /// Restart the MTA.
  86. //
  87. // This function starts or restarts the MTA.
  88. //
  89. // \param[in] Mta specifies the MTA. The acceptable values are
  90. // "postfix" and "sendmail".
  91. //
  92. void StartOrRestartMta(std::string Mta);
  93. /// Operating system specification.
  94. enum OperatingSystemSpecEnum {
  95. OpenBSD, ///< OpenBSD OS.
  96. FreeBSD, ///< FreeBSD OS.
  97. Ubuntu, ///< Ubuntu and variants.
  98. RedHat, ///< RedHat and variants.
  99. Suse ///< Suse and variants.
  100. };
  101. /// Load the operating-system-dependent info (file locations, etc).
  102. //
  103. // This method updates the public members that contain the OS
  104. // specification and file paths.
  105. //
  106. void LoadInfo();
  107. /// OS specification.
  108. OperatingSystemSpecEnum OsSpec;
  109. /// Postfix main.cf file path.
  110. std::string PostfixMainCfPath;
  111. /// Postfix master.cf file path.
  112. std::string PostfixMasterCfPath;
  113. /// Create or update the ignore list file.
  114. //
  115. // The ignore list file is created if it dosn't exist. In any
  116. // case, the owner/group is changed by SetOwnerGroup(), and the
  117. // permissions are changed to readonly for everyone, and
  118. // read/write for the owner.
  119. void UpdateIgnoreListFile();
  120. /// Create or update the log directory.
  121. //
  122. // The log directory is created if it dosn't exist. In any case,
  123. // the owner/group is changed by SetOwnerGroup(), and the
  124. // permissions are changed to r-x for everyone, and rwx for the
  125. // owner.
  126. void UpdateLogDir();
  127. /// Process one command-line item.
  128. //
  129. // \param[in] OneInput is the command-line item to process.
  130. //
  131. bool ProcessCommandLineItem(std::string OneInput);
  132. /// Output the legal command-line input.
  133. std::string HelpCommandLine();
  134. /// Output the description of the legal command-line input.
  135. std::string HelpDescription();
  136. private:
  137. std::string ConfigFile; ///< Configuration file name.
  138. static const std::string SampleIgnoreListFile; ///< Sample ignore list file.
  139. static const std::string SampleRulebaseScriptFile; ///< Sample rulebase script file.
  140. snfCFGData CFGData; ///< Configuration data.
  141. /// Operating system type.
  142. //
  143. // This is either Windows or the value specified for
  144. // --enable-os-type when configuring for *nix.
  145. static const std::string OperatingSystemType;
  146. };
  147. #endif