Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // main.cpp
  2. //
  3. // Copyright (C) 2011, ARM Research Labs, LLC.
  4. // See www.armresearch.com for the copyright terms.
  5. //
  6. // Configure the identity.xml and getRulebase files with the license
  7. // and authentication credentials.
  8. //
  9. // The license and authentication credentials are specified on the
  10. // command line, and are used to create the identity.xml and update
  11. // the getRulebase files with that information.
  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 "SNFIdentityConfig.hpp"
  27. using namespace std;
  28. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  29. // Configuration. ////////////////////////////////////////////////////////////////////////////////////////
  30. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  31. /// Version string.
  32. const char* SNF_IDENTITY_VERSION = "SNFIdentity 0.0.1 Build: " __DATE__ " " __TIME__;
  33. /// Locations to search for default configuration files.
  34. const string DefaultConfigFile[] = {
  35. "/etc/snf-milter/SNFMilter.xml",
  36. "/usr/local/etc/snf-milter/SNFMilter.xml",
  37. "/etc/snf-server/SNFServer.xml",
  38. "/usr/local/etc/snf-server/SNFServer.xml"
  39. };
  40. const size_t DefaultConfigFileSize = sizeof DefaultConfigFile / sizeof DefaultConfigFile[0];
  41. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  42. // End of configuration. /////////////////////////////////////////////////////////////////////////////////
  43. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  44. int main(int argc, char* argv[]) {
  45. SNFIdentityConfig SnfIdentityConfig;
  46. if (!SnfIdentityConfig.GetCommandLineInput(argc, argv) || // If our command line arguments
  47. SnfIdentityConfig.Help()) { // don't look right, or if help is
  48. // requested then display our help
  49. SnfIdentityConfig.DisplayHelp(SNF_IDENTITY_VERSION, // screen.
  50. DefaultConfigFile,
  51. DefaultConfigFileSize);
  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_IDENTITY_VERSION << endl; // watchers.
  62. cout << "Debug Mode" << endl;
  63. }
  64. try { // Catch anything that breaks loose.
  65. SnfIdentityConfig.CheckAndLoadConfigFile(DefaultConfigFile, // Load configuration from the
  66. DefaultConfigFileSize); // config file specified on the
  67. // command line, or the default file.
  68. SnfIdentityConfig.CreateIdentityFile();
  69. SnfIdentityConfig.UpdateRulebaseScriptCredentials();
  70. } // That's all folks.
  71. catch(exception& e) { // Report any normal exceptions.
  72. cerr << "SNFIdentity Exception: " << e.what() << endl;
  73. }
  74. catch (snfCFGmgr::LoadFailure) { // Error loading configuration file.
  75. cerr << "snfCFGmgr Exception: Unable to load the configuration file "
  76. << SnfIdentityConfig.GetConfigFileName() << endl;
  77. }
  78. catch(...) { // Report any unexpected exceptions.
  79. cerr << "SNFIdentity Panic! Unknown Exception!" << endl;
  80. }
  81. return 0; // Normally we return zero.
  82. }