Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

UtilityConfig.hpp 9.9KB

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