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 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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. /// Running status of the Sniffer application.
  22. enum SnifferRunningStateEnum {
  23. SnifferIsRunning, ///< OpenBSD OS.
  24. SnifferIsStopped, ///< FreeBSD OS.
  25. SnifferRunningStatusIsUknown ///< Ubuntu and variants.
  26. };
  27. /// Default constructor.
  28. UtilityConfig(void);
  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. In any case, set the owner and mode.
  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. /// Setup/repair the configuration.
  61. //
  62. // This method creates any configuration files that don't exist
  63. // from the sample files.
  64. void SetupCreate(void);
  65. /// Load the configuration from the file specified by SetConfigFileName.
  66. //
  67. void LoadConfig(void);
  68. /// Set the configuration file name.
  69. //
  70. // \param[in] Name is the name of the configuration file.
  71. //
  72. void SetConfigFileName(std::string Name);
  73. /// Get the configuration file name.
  74. //
  75. // \returns the name of the configuration file.
  76. //
  77. std::string GetConfigFileName(void);
  78. /// Get the contents of the <platform> element of the loaded
  79. /// config file.
  80. //
  81. // \returns the contents of the <platform> element.
  82. //
  83. string GetPlatformContents(void);
  84. /// Get the workspace path.
  85. //
  86. // \returns the workspace path.
  87. std::string GetWorkspacePath(void);
  88. /// Get the rulebase path.
  89. //
  90. // \returns the rulebase path.
  91. std::string GetRulebasePath(void);
  92. /// Get the log path.
  93. //
  94. // \returns the log path.
  95. std::string GetLogPath(void);
  96. /// Get the identity file name.
  97. //
  98. // \returns the identity file name.
  99. std::string GetIdentityFileName(void);
  100. /// Get the rulebase script file name.
  101. //
  102. // \returns the rulebase script file name.
  103. std::string GetRulebaseScriptName(void);
  104. /// Get the ignore list file name.
  105. //
  106. // \returns the ignore list file name.
  107. //
  108. std::string GetIgnoreListFileName(void);
  109. /// Return the rulebase file name.
  110. //
  111. // \returns the name of the rulebase file, including the path.
  112. //
  113. std::string GetRulebaseFileName(void);
  114. /// Get the operating system type.
  115. //
  116. // \returns the operating system type. This is the value of
  117. // SNF_OSTYPE specified on the compile commandline. For *nix, it
  118. // is identical to the value of the --enable-os-type command-line
  119. // input to ./configure:
  120. //
  121. // <ol>
  122. // <li>OpenBSD</li>
  123. // <li>FreeBSD</li>
  124. // <li>Suse</li>
  125. // <li>RedHat</li>
  126. // <li>Ubuntu</li>
  127. // </ol>
  128. //
  129. std::string GetOperatingSystemType(void);
  130. /// Load the operating-system-dependent info (file locations, etc).
  131. //
  132. // This method updates the public members that contain the OS
  133. // specification and file paths.
  134. //
  135. void LoadInfo(void);
  136. /// Postfix main.cf file path.
  137. std::string PostfixMainCfPath;
  138. /// Postfix master.cf file path.
  139. std::string PostfixMasterCfPath;
  140. /// Directory containing the Sniffer start script.
  141. std::string SnifferStartScriptDir;
  142. /// Update the rulebase script credentials.
  143. //
  144. // This method updates the rulebase with the credentials specified
  145. // on the command line.
  146. //
  147. void UpdateRulebaseScriptCredentials(void);
  148. /// Download the rulebase.
  149. //
  150. void DownloadRulebase(void);
  151. /// Update the identity file.
  152. //
  153. // If the credentials were supplied, this method updates the
  154. // identity file with the supplied credentials.
  155. //
  156. // In any case, the owner/group is changed by SetOwnerGroup(), and
  157. // the permissions are changed to readonly for the owner.
  158. //
  159. // \pre Either the identity file must exist, or the credentials
  160. // must be supplied so that the identity file is created.
  161. //
  162. // \see SetOwnerGroup().
  163. //
  164. void UpdateIdentityFile(void);
  165. /// Start the sniffer.
  166. //
  167. // This method runs the specified sniffer start script in the
  168. // appropriate (i.e. OS-dependent) directory. The script is
  169. // prepended with the directory, and run with an argument of
  170. // "start".
  171. //
  172. // \param[in] Script is the name of the start script.
  173. //
  174. // \pre LoadInfo() must have been called. That method initializes
  175. // the directory the script resides in.
  176. //
  177. void StartSniffer(std::string Script);
  178. /// Process one command-line item.
  179. //
  180. // \param[in] OneInput is the command-line item to process.
  181. //
  182. bool ProcessCommandLineItem(std::string OneInput);
  183. /// Check whether the command-line parameters were specified
  184. /// correctly.
  185. //
  186. // This function check that either both the LicenseID and
  187. // Authentication were specified, or neither were.
  188. //
  189. // \returns if the command-line parameters were specified
  190. // correctly, false otherwise.
  191. bool CommandLineIsOkay(void);
  192. /// Output the legal command-line input.
  193. //
  194. // \param[in] ExclusiveCommands contains the command-line help of
  195. // the additional commands implemented by the descendent classes.
  196. // Only one command may be specified when invoking the
  197. // configuration utility.
  198. //
  199. std::string HelpCommandLine(std::string ExclusiveCommands);
  200. /// Output the description of the legal command-line input.
  201. //
  202. // \param[in] ExclusiveCommandsHelp contains the description of
  203. // the additional commands implemented by the descendent classes.
  204. //
  205. std::string HelpDescription(std::string ExclusiveCommandsHelp);
  206. /// Store whether the setup/help command was specified.
  207. //
  208. // \param[in] Specified specifies whether the command was specified.
  209. //
  210. void SetSetupRepair(bool Specified);
  211. /// Setup/repair specified?
  212. //
  213. // \returns true if the setup/help command was specified on the command line.
  214. //
  215. bool SetupRepairSpecified(void);
  216. /// Determine whether the credentials should be updated.
  217. //
  218. // This method determines whether the credentials should be
  219. // updated. If the user specified both the License ID and
  220. // Authentication, then the credentials should be updated.
  221. //
  222. // \returns true if the credentials should be updated.
  223. //
  224. bool UpdateCredentialsSpecified(void);
  225. /// Store whether the start sniffer command was specified.
  226. //
  227. // \param[in] Specified specifies whether the command was specified.
  228. //
  229. void SetStartSniffer(bool Specified);
  230. /// Start sniffer specified?
  231. //
  232. // \returns true if the start sniffer command was specified on the command line.
  233. //
  234. bool StartSnifferSpecified(void);
  235. /// Store whether the stop sniffer command was specified.
  236. //
  237. // \param[in] Specified specifies whether the command was specified.
  238. //
  239. void SetStopSniffer(bool Specified);
  240. /// Stop sniffer specified?
  241. //
  242. // \returns true if the stop sniffer command was specified on the command line.
  243. //
  244. bool StopSnifferSpecified(void);
  245. private:
  246. /// Setup/repair the identity file.
  247. //
  248. // If the identity file doesn't exist, create it from the sample
  249. // file.
  250. //
  251. // In any case, set the owner and permissions of the identity
  252. // file.
  253. //
  254. // \param[in] SampleIdentityFile is the name of the sample
  255. // identity file.
  256. //
  257. // \note The configuration information must be loaded before calling this method.
  258. //
  259. // \see CheckAndSetConfigFileName.
  260. //
  261. // \see CreateDefaultConfigFile.
  262. //
  263. // \see LoadConfig.
  264. //
  265. // \see LoadInfo.
  266. //
  267. void SetupRepairIdentityFile(std::string SampleIdentityFile);
  268. /// Setup/repair the rulebase script.
  269. //
  270. // If the rulebase script doesn't exist, this method creates the
  271. // rulebase script from the sample rulebase script.
  272. //
  273. // In any case, set the owner and permissions of the rulebase
  274. // script.
  275. //
  276. void SetupRepairRulebaseScript(void);
  277. /// Setup/repair the ignore list file.
  278. //
  279. // The ignore list file is created if it dosn't exist. In any
  280. // case, the owner/group is changed by SetOwnerGroup(), and the
  281. // permissions are changed to readonly for everyone, and
  282. // read/write for the owner.
  283. void SetupRepairIgnoreListFile(void);
  284. /// Setup/repair the log directory.
  285. //
  286. // The log directory is created if it dosn't exist. In any case,
  287. // the owner/group is changed by SetOwnerGroup(), and the
  288. // permissions are changed to r-x for everyone, and rwx for the
  289. // owner.
  290. void SetupRepairLogDir(void);
  291. std::string ConfigFileName; ///< Configuration file name.
  292. std::string LicenseId; ///< License ID string.
  293. bool LicenseIdIsSpecified; ///< true if the License ID was specified on the command line.
  294. std::string Authentication; ///< Authentication string.
  295. bool AuthenticationIsSpecified; ///< true if the Authentication was specified on the command line.
  296. static const std::string RulebaseDownloadCommand; ///< Command to download the rulebase.
  297. static const std::string RulebaseDownloadStatusFile; ///< Status file for rulebase download status.
  298. static const std::string SampleIgnoreListFile; ///< Sample ignore list file.
  299. static const std::string SampleRulebaseScriptFile; ///< Sample rulebase script file.
  300. snfCFGData CFGData; ///< Configuration data.
  301. /// Operating system type.
  302. //
  303. // This is either Windows or the value specified for
  304. // --enable-os-type when configuring for *nix.
  305. static const std::string OperatingSystemType;
  306. bool SetupRepairRequested; ///< User requested setup/repair.
  307. bool StartSnifferRequested; ///< User requested that Sniffer be started.
  308. bool StopSnifferRequested; ///< User requested that Sniffer be stopped.
  309. };
  310. #endif