Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

main.cpp 4.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. int main(int argc, char* argv[]) {
  37. SNFMilterConfig SnfMilterConfig;
  38. if (!SnfMilterConfig.GetCommandLineInput(argc, argv) || // If our command line arguments
  39. SnfMilterConfig.Help()) { // don't look right, or if help is
  40. // requested then display our help
  41. SnfMilterConfig.DisplayHelp(SNF_MILTERCONFIG_VERSION); // screen.
  42. return 0;
  43. }
  44. bool DebugMode = false; // This will be our debug mode.
  45. string argv0(argv[0]); // Capture how we were called.
  46. if(
  47. string::npos != argv0.find("Debug") || // If we find "Debug" or
  48. string::npos != argv0.find("debug") // "debug" in our command path
  49. ) { // then we are in DebugMode.
  50. DebugMode = true; // Set the flag and tell the
  51. cout << SNF_MILTERCONFIG_VERSION << endl; // watchers.
  52. cout << "Debug Mode" << endl;
  53. }
  54. try { // Catch anything that breaks loose.
  55. SnfMilterConfig.UpdateConfigFiles(); // Create config files if they don't
  56. // exist, or update config files.
  57. SnfMilterConfig.DoIntegrationCommand(); // Integrate/unintegrate.
  58. } // That's all folks.
  59. catch(exception& e) { // Report any normal exceptions.
  60. cerr << "SNFMilterConfig Exception: " << e.what() << endl;
  61. }
  62. catch (snfCFGmgr::LoadFailure) { // Error loading configuration file.
  63. cerr << "snfCFGmgr Exception: Unable to load the configuration file "
  64. << SnfMilterConfig.GetConfigFileName() << endl;
  65. }
  66. catch(...) { // Report any unexpected exceptions.
  67. cerr << "SNFMilterConfig Panic! Unknown Exception!" << endl;
  68. }
  69. return 0; // Normally we return zero.
  70. }