Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. Config->SetOwnerPermissionsOfConfigFiles();
  41. cerr << "done.\n\n"
  42. << "Configuration files that resulted in this error are saved with a suffix \""
  43. << Config->SaveFile.GetFailedFileName("") << "\".\n";
  44. }
  45. catch(exception& e) {
  46. cerr << "SNFMilterConfig::SaveFile Exception: " << e.what() << endl;
  47. }
  48. }
  49. int main(int argc, char* argv[]) {
  50. SNFMilterConfig SnfMilterConfig;
  51. if (!SnfMilterConfig.GetCommandLineInput(argc, argv) || // If our command line arguments
  52. SnfMilterConfig.Help()) { // don't look right, or if help is
  53. // requested then display our help
  54. SnfMilterConfig.DisplayHelp(SNF_MILTERCONFIG_VERSION); // screen.
  55. return 0;
  56. }
  57. bool DebugMode = false; // This will be our debug mode.
  58. string argv0(argv[0]); // Capture how we were called.
  59. if(
  60. string::npos != argv0.find("Debug") || // If we find "Debug" or
  61. string::npos != argv0.find("debug") // "debug" in our command path
  62. ) { // then we are in DebugMode.
  63. DebugMode = true; // Set the flag and tell the
  64. cout << SNF_MILTERCONFIG_VERSION << endl; // watchers.
  65. cout << "Debug Mode" << endl;
  66. SnfMilterConfig.SetDebug(true);
  67. }
  68. try { // Catch anything that breaks loose.
  69. SnfMilterConfig.ExecuteCommand();
  70. } // That's all folks.
  71. catch(exception& e) { // Report any normal exceptions.
  72. cerr << "\n\nSNFMilterConfig Exception: " << e.what() << endl << endl;
  73. RestoreFiles(&SnfMilterConfig);
  74. return(-1);
  75. }
  76. catch (snfCFGmgr::LoadFailure) { // Error loading configuration file.
  77. cerr << "\n\nsnfCFGmgr Exception: Unable to load the configuration file "
  78. << SnfMilterConfig.GetConfigFileName() << endl << endl;
  79. RestoreFiles(&SnfMilterConfig);
  80. return(-1);
  81. }
  82. catch(...) { // Report any unexpected exceptions.
  83. cerr << "\n\nSNFMilterConfig Panic! Unknown Exception!" << endl << endl;
  84. RestoreFiles(&SnfMilterConfig);
  85. return(-1);
  86. }
  87. return 0; // Normally we return zero.
  88. }