Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

main.cpp 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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.ExecuteCommand();
  66. } // That's all folks.
  67. catch(exception& e) { // Report any normal exceptions.
  68. cerr << "\n\nSNFMilterConfig Exception: " << e.what() << endl << endl;
  69. RestoreFiles(&SnfMilterConfig);
  70. }
  71. catch (snfCFGmgr::LoadFailure) { // Error loading configuration file.
  72. cerr << "\n\nsnfCFGmgr Exception: Unable to load the configuration file "
  73. << SnfMilterConfig.GetConfigFileName() << endl << endl;
  74. RestoreFiles(&SnfMilterConfig);
  75. }
  76. catch(...) { // Report any unexpected exceptions.
  77. cerr << "\n\nSNFMilterConfig Panic! Unknown Exception!" << endl << endl;
  78. RestoreFiles(&SnfMilterConfig);
  79. }
  80. return 0; // Normally we return zero.
  81. }