Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

UtilityConfig.hpp 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. /// Set the config file name to the default if it wasn't specified.
  26. //
  27. // If the configuration file wasn't specified by
  28. // SetConfigFileName() on the command line, then this method sets
  29. // the config file to the default. The default is the unique file
  30. // that exists in the specified list. If more than one file in
  31. // the specified list exists, an exception is thrown.
  32. //
  33. // If the configuration file was specified by SetConfigFileName()
  34. // or on the command line, then this method does nothing.
  35. //
  36. // \param[in] DefaultFile is the list of default locations of the file.
  37. //
  38. // \param[in] NumDefaultFiles is the number of defaultlocations.
  39. //
  40. void CheckAndSetConfigFileName(const std::string DefaultFile[], int NumDefaultFiles);
  41. /// If the configuration file doesn't exist, create it from the
  42. /// sample file.
  43. //
  44. // This method creates the default configuration file if the
  45. // specified configuration file doesn't exist.
  46. //
  47. // The method CheckAndSetConfigFileName must be called before this
  48. // method.
  49. //
  50. // \param[in] SampleConfigFile is the name of the sample
  51. // configuration file.
  52. //
  53. void CreateDefaultConfigFile(std::string SampleConfigFile);
  54. /// If the identity file doesn't exist, create it from the sample
  55. /// file.
  56. //
  57. // This method creates the default identity file if the identity
  58. // file specified in the configuration file doesn't exist.
  59. //
  60. // The method CheckAndSetConfigFileName must be called before this
  61. // method.
  62. //
  63. // \param[in] SampleIdentityFile is the name of the sample
  64. // identity file.
  65. //
  66. void CreateDefaultIdentityFile(std::string SampleIdentityFile);
  67. /// Load the configuration from the file specified by SetConfigFileName.
  68. //
  69. void LoadConfig(void);
  70. /// Set the configuration file name.
  71. //
  72. // \param[in] Name is the name of the configuration file.
  73. //
  74. void SetConfigFileName(std::string Name);
  75. /// Get the configuration file name.
  76. //
  77. // \returns the name of the configuration file.
  78. //
  79. std::string GetConfigFileName(void);
  80. /// Get the contents of the <platform> element of the loaded
  81. /// config file.
  82. //
  83. // \returns the contents of the <platform> element.
  84. //
  85. string GetPlatformContents(void);
  86. /// Get the workspace path.
  87. //
  88. // \returns the workspace path.
  89. std::string GetWorkspacePath(void);
  90. /// Get the rulebase path.
  91. //
  92. // \returns the rulebase path.
  93. std::string GetRulebasePath(void);
  94. /// Get the log path.
  95. //
  96. // \returns the log path.
  97. std::string GetLogPath(void);
  98. /// Get the identity file name.
  99. //
  100. // \returns the identity file name.
  101. std::string GetIdentityFileName(void);
  102. /// Get the rulebase script file name.
  103. //
  104. // \returns the rulebase script file name.
  105. std::string GetRulebaseScriptName(void);
  106. /// Get the ignore list file name.
  107. //
  108. // \returns the ignore list file name.
  109. //
  110. std::string GetIgnoreListFileName(void);
  111. /// Return the rulebase file name.
  112. //
  113. // \returns the name of the rulebase file, including the path.
  114. //
  115. std::string GetRulebaseFileName();
  116. /// Get the operating system type.
  117. //
  118. // \returns the operating system type. This is the value of
  119. // SNF_OSTYPE specified on the compile commandline. For *nix, it
  120. // is identical to the value of the --enable-os-type command-line
  121. // input to ./configure:
  122. //
  123. // <ol>
  124. // <li>OpenBSD</li>
  125. // <li>FreeBSD</li>
  126. // <li>Suse</li>
  127. // <li>RedHat</li>
  128. // <li>Ubuntu</li>
  129. // </ol>
  130. //
  131. std::string GetOperatingSystemType(void);
  132. /// Load the operating-system-dependent info (file locations, etc).
  133. //
  134. // This method updates the public members that contain the OS
  135. // specification and file paths.
  136. //
  137. void LoadInfo();
  138. /// Postfix main.cf file path.
  139. std::string PostfixMainCfPath;
  140. /// Postfix master.cf file path.
  141. std::string PostfixMasterCfPath;
  142. /// Create or update the ignore list file.
  143. //
  144. // The ignore list file is created if it dosn't exist. In any
  145. // case, the owner/group is changed by SetOwnerGroup(), and the
  146. // permissions are changed to readonly for everyone, and
  147. // read/write for the owner.
  148. void UpdateIgnoreListFile();
  149. /// Create or update the log directory.
  150. //
  151. // The log directory is created if it dosn't exist. In any case,
  152. // the owner/group is changed by SetOwnerGroup(), and the
  153. // permissions are changed to r-x for everyone, and rwx for the
  154. // owner.
  155. void UpdateLogDir();
  156. /// Determine whether the credentials should be updated.
  157. //
  158. // This method determines whether the credentials should be
  159. // updated. If the user specified both the License ID and
  160. // Authentication, then the credentials should be updated.
  161. //
  162. // \returns true if the credentials should be updated.
  163. //
  164. bool UpdateCredentialsSpecified();
  165. /// Create or update the rulebase script.
  166. //
  167. // If the rulebase script doesn't exist, this method creates the
  168. // rulebase script from the sample rulebase script.
  169. //
  170. // If the credentials were supplied, this method updates the
  171. // rulebase with the supplied credentials.
  172. //
  173. // In either case, the permissions of the rulebase script are
  174. // updated.
  175. //
  176. void CreateUpdateRulebaseScript();
  177. /// Download the rulebase.
  178. //
  179. void DownloadRulebase();
  180. /// Update the identity file.
  181. //
  182. // If the credentials were supplied, this method updates the
  183. // identity file with the supplied credentials.
  184. //
  185. // In any case, the owner/group is changed by SetOwnerGroup(), and
  186. // the permissions are changed to readonly for the owner.
  187. //
  188. // \pre Either the identity file must exist, or the credentials
  189. // must be supplied so that the identity file is created.
  190. //
  191. // \see SetOwnerGroup().
  192. //
  193. void UpdateIdentityFile(void);
  194. /// Process one command-line item.
  195. //
  196. // \param[in] OneInput is the command-line item to process.
  197. //
  198. bool ProcessCommandLineItem(std::string OneInput);
  199. /// Check whether the command-line parameters were specified
  200. /// correctly.
  201. //
  202. // This function check that either both the LicenseID and
  203. // Authentication were specified, or neither were.
  204. //
  205. // \returns if the command-line parameters were specified
  206. // correctly, false otherwise.
  207. bool CommandLineIsOkay();
  208. /// Output the legal command-line input.
  209. std::string HelpCommandLine();
  210. /// Output the description of the legal command-line input.
  211. std::string HelpDescription();
  212. private:
  213. /// Update the credentials of an existing rulebase script.
  214. //
  215. // This method does the actual work of updating the credentials of
  216. // the rulebase script.
  217. //
  218. // \pre The rulebase script file must exist.
  219. //
  220. // Side effect: The rulebase script is updated.
  221. //
  222. void UpdateRulebaseScriptCredentials();
  223. std::string ConfigFileName; ///< Configuration file name.
  224. bool ConfigFileExists; ///< True if the configuration file exists.
  225. std::string LicenseId; ///< License ID string.
  226. bool LicenseIdIsSpecified; ///< true if the License ID was specified on the command line.
  227. std::string Authentication; ///< Authentication string.
  228. bool AuthenticationIsSpecified; ///< true if the Authentication was specified on the command line.
  229. static const std::string RulebaseDownloadCommand; ///< Command to download the rulebase.
  230. static const std::string RulebaseDownloadStatusFile; ///< Status file for rulebase download status.
  231. static const std::string SampleIgnoreListFile; ///< Sample ignore list file.
  232. static const std::string SampleRulebaseScriptFile; ///< Sample rulebase script file.
  233. snfCFGData CFGData; ///< Configuration data.
  234. /// Operating system type.
  235. //
  236. // This is either Windows or the value specified for
  237. // --enable-os-type when configuring for *nix.
  238. static const std::string OperatingSystemType;
  239. };
  240. #endif