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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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 "SNFMulti.hpp"
  11. #include <string>
  12. /// Base class for the Sniffer configuration.
  13. //
  14. // This class provides capability common to the configuration applications.
  15. //
  16. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  17. class UtilityConfig {
  18. public:
  19. /// Default constructor.
  20. UtilityConfig();
  21. /// Check whether a file exists.
  22. //
  23. // \returns true if the file exists, false otherwise.
  24. //
  25. bool FileExists(std::string File);
  26. /// Load the specified or default config file.
  27. //
  28. // This function loads (or reloads) the config file specified in
  29. // the most recent call to LoadConfigFile. If LoadConfigFile has
  30. // not been called, then this method searches for a unique default
  31. // config file in the specified list, and loads that config file.
  32. //
  33. // \param[in] DefaultFile is the list of default locations of the file.
  34. //
  35. // \param[in] NumDefaultFiles is the number of defaultlocations.
  36. //
  37. // If the local data member ConfigFile has a value of "" on input,
  38. // then this function checks for the existence (but not
  39. // readability) of a configuration file in several locations. If
  40. // exactly one file exists, then that file is loaded and
  41. // ConfigFile is set to that name. Otherwise, an exception is
  42. // thrown.
  43. //
  44. void CheckAndLoadConfigFile(const std::string DefaultFile[], int NumDefaultFiles);
  45. /// Load the specified configuration file.
  46. //
  47. // \param[in] Name is the name of the configuration file.
  48. //
  49. void LoadConfigFile(std::string Name);
  50. /// Set the configuration file name.
  51. //
  52. // \param[in] Name is the name of the configuration file.
  53. //
  54. void SetConfigFileName(std::string Name);
  55. /// Get the configuration file name.
  56. //
  57. // \returns the name of the configuration file.
  58. //
  59. std::string GetConfigFileName(void);
  60. /// Get the contents of the <platform> element of the loaded
  61. /// config file.
  62. //
  63. // \returns the contents of the <platform> element.
  64. //
  65. string GetPlatformContents(void);
  66. /// Get the workspace path.
  67. //
  68. // \returns the workspace path.
  69. std::string GetWorkspacePath(void);
  70. /// Get the rulebase path.
  71. //
  72. // \returns the rulebase path.
  73. std::string GetRulebasePath(void);
  74. /// Get the log path.
  75. //
  76. // \returns the log path.
  77. std::string GetLogPath(void);
  78. /// Get the identity file name.
  79. //
  80. // \returns the identity file name.
  81. std::string GetIdentityFileName(void);
  82. /// Get the rulebase script file name.
  83. //
  84. // \returns the rulebase script file name.
  85. std::string GetRulebaseScriptName(void);
  86. /// Copy a file.
  87. //
  88. // \param[in] From is the name of the source file.
  89. //
  90. // \param[in] To is the name of the destination file.
  91. //
  92. void Copy(std::string From, std::string To);
  93. /// Set the owner and group of the specified file.
  94. //
  95. // This function sets the owner and group of the specified file to the
  96. // value specified in UtilityConfig.cpp.
  97. //
  98. // \param[in] File is the specified file.
  99. //
  100. // \see SNFUserName.
  101. //
  102. // \see SNFGroupName.
  103. //
  104. void SetOwnerGroup(std::string &File);
  105. /// Set the mode of a file.
  106. //
  107. // This function sets the mode of the specified file. If an error
  108. // occurs, an exception is thrown.
  109. //
  110. // \param[in] File is the specified file.
  111. //
  112. // \param[in] is the mode.
  113. //
  114. void SetMode(std::string &File, mode_t mode);
  115. /// Create a directory.
  116. //
  117. // This function creates the specified directory. If an error
  118. // occurs, an exception is thrown.
  119. //
  120. // \param[in] Dir is the directory to create.
  121. //
  122. void MkDir(std::string &Dir);
  123. /// Restart the MTA.
  124. //
  125. // This function starts or restarts the MTA.
  126. //
  127. // \param[in] Mta specifies the MTA. The acceptable values are
  128. // "postfix" and "sendmail".
  129. //
  130. void StartOrRestartMta(std::string Mta);
  131. /// Check for a specified string at the beginning of a line.
  132. //
  133. // This function checks for the specified string at the beginning of a
  134. // line. Leading whitespace in the line is ignored.
  135. //
  136. // \param[in] Line is the line.
  137. //
  138. // \param[in] SearchString is the string to check for.
  139. //
  140. static bool CheckForString(std::string Line, std::string SearchString);
  141. /// Operating system specification.
  142. enum OperatingSystemSpecEnum {
  143. OpenBSD, ///< OpenBSD OS.
  144. FreeBSD, ///< FreeBSD OS.
  145. Ubuntu, ///< Ubuntu and variants.
  146. RedHat, ///< RedHat and variants.
  147. Suse ///< Suse and variants.
  148. };
  149. /// Load the operating-system-dependent info (file locations, etc).
  150. //
  151. // This method updates the public members that contain the OS
  152. // specification and file paths.
  153. //
  154. void LoadInfo();
  155. /// OS specification.
  156. OperatingSystemSpecEnum OsSpec;
  157. /// Postfix main.cf file path.
  158. std::string PostfixMainCfPath;
  159. /// Postfix main.cf file path.
  160. std::string PostfixMasterCfPath;
  161. /// Create or update the ignore list file.
  162. //
  163. // The ignore list file is created if it dosn't exist. In any
  164. // case, the owner/group is changed by SetOwnerGroup(), and the
  165. // permissions are changed to readonly for everyone, and
  166. // read/write for the owner.
  167. void UpdateIgnoreListFile();
  168. /// Create or update the log directory.
  169. //
  170. // The log directory is created if it dosn't exist. In any case,
  171. // the owner/group is changed by SetOwnerGroup(), and the
  172. // permissions are changed to r-x for everyone, and rwx for the
  173. // owner.
  174. void UpdateLogDir();
  175. /// Process one command-line item.
  176. //
  177. // \param[in] OneInput is the command-line item to process.
  178. //
  179. bool ProcessCommandLineItem(std::string OneInput);
  180. /// Provide verbose output?
  181. //
  182. // \returns true if the application is to provide verbose output.
  183. //
  184. bool Verbose();
  185. /// Provide an explanation of the actions only?
  186. //
  187. // \returns true if the application is to provide an explanation
  188. // of the actions without executing any commands.
  189. //
  190. bool Explain();
  191. /// Provide help?
  192. //
  193. // \returns true if the application is to output a help message.
  194. //
  195. bool Help();
  196. /// Output the legal command-line input.
  197. std::string HelpCommandLine();
  198. /// Output the description of the legal command-line input.
  199. std::string HelpDescription();
  200. /// Output the end of a verbose output line.
  201. void OutputVerboseEnd();
  202. private:
  203. bool VerboseRequested; ///< User requested verbose processing.
  204. bool ExplainRequested; ///< User requested verbose processing but without actually executing the commands.
  205. bool HelpRequested; ///< User requested help.
  206. std::string ConfigFile; ///< Configuration file name.
  207. static const std::string SampleIgnoreListFile; ///< Sample ignore list file.
  208. static const std::string SampleRulebaseScriptFile; ///< Sample rulebase script file.
  209. snfCFGData CFGData; ///< Configuration data.
  210. /// Operating system type.
  211. //
  212. // This is either Windows or the value specified for
  213. // --enable-os-type when configuring for *nix.
  214. static const std::string OperatingSystemType;
  215. };
  216. #endif