您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // main.cpp
  2. //
  3. // Copyright (C) 2012, ARM Research Labs, LLC.
  4. // See www.armresearch.com for the copyright terms.
  5. //
  6. // Create and maintain the sniffer configuration file for SNFMilter.
  7. //
  8. // The configuration file and instructions are specified on the
  9. // command line, and are used to create/modify the configuration file,
  10. // and integrate or unintegrate with the specified MTA.
  11. //
  12. //
  13. // $Id$
  14. //
  15. ///////////////////////////////////////////////////////////////////////////////////////////////////
  16. #include <errno.h>
  17. #include <string.h>
  18. #include <unistd.h>
  19. #include <sys/types.h>
  20. #include <pwd.h>
  21. #include <sys/stat.h>
  22. #include <exception>
  23. #include <iostream>
  24. #include <fstream>
  25. #include "SNFMulti.hpp"
  26. #include "SNFMilterConfig.hpp"
  27. using namespace std;
  28. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  29. // Configuration. ////////////////////////////////////////////////////////////////////////////////////////
  30. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  31. /// Version string.
  32. const char* SNF_MILTERCONFIG_VERSION = "SNFMilterConfig 0.0.1 Build: " __DATE__ " " __TIME__;
  33. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  34. // End of configuration. /////////////////////////////////////////////////////////////////////////////////
  35. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  36. void RestoreFiles(SNFMilterConfig *Config) {
  37. try {
  38. cerr << "Restoring all configuration files...";
  39. Config->SaveFile.RestoreAllFilesFromBackup();
  40. cerr << "done.\n";
  41. }
  42. catch(exception& e) {
  43. cerr << "SNFMilterConfig::SaveFile Exception: " << e.what() << endl;
  44. }
  45. }
  46. int main(int argc, char* argv[]) {
  47. SNFMilterConfig SnfMilterConfig;
  48. if (!SnfMilterConfig.GetCommandLineInput(argc, argv) || // If our command line arguments
  49. SnfMilterConfig.Help()) { // don't look right, or if help is
  50. // requested then display our help
  51. SnfMilterConfig.DisplayHelp(SNF_MILTERCONFIG_VERSION); // screen.
  52. return 0;
  53. }
  54. bool DebugMode = false; // This will be our debug mode.
  55. string argv0(argv[0]); // Capture how we were called.
  56. if(
  57. string::npos != argv0.find("Debug") || // If we find "Debug" or
  58. string::npos != argv0.find("debug") // "debug" in our command path
  59. ) { // then we are in DebugMode.
  60. DebugMode = true; // Set the flag and tell the
  61. cout << SNF_MILTERCONFIG_VERSION << endl; // watchers.
  62. cout << "Debug Mode" << endl;
  63. }
  64. try { // Catch anything that breaks loose.
  65. SnfMilterConfig.CreateLoadConfig(); // Save config file state and load config.
  66. // Load the default if necessary.
  67. SnfMilterConfig.SaveFileState(); // Save state of all other files.
  68. SnfMilterConfig.UpdateConfigFiles(); // Create/update config files
  69. SnfMilterConfig.CreateUpdateRulebaseScript(); // Create/update GetRulebase.
  70. SnfMilterConfig.DownloadRulebase(); // Download rulebase.
  71. SnfMilterConfig.UpdateIdentityFile(); // Update Identity file with credentials,
  72. // if credentials were specified.
  73. SnfMilterConfig.DoIntegrationCommand(); // Integrate/unintegrate.
  74. } // That's all folks.
  75. catch(exception& e) { // Report any normal exceptions.
  76. cerr << "SNFMilterConfig Exception: " << e.what() << endl;
  77. RestoreFiles(&SnfMilterConfig);
  78. }
  79. catch (snfCFGmgr::LoadFailure) { // Error loading configuration file.
  80. cerr << "snfCFGmgr Exception: Unable to load the configuration file "
  81. << SnfMilterConfig.GetConfigFileName() << endl;
  82. RestoreFiles(&SnfMilterConfig);
  83. }
  84. catch(...) { // Report any unexpected exceptions.
  85. cerr << "SNFMilterConfig Panic! Unknown Exception!" << endl;
  86. RestoreFiles(&SnfMilterConfig);
  87. }
  88. return 0; // Normally we return zero.
  89. }