|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- // main.cpp
- //
- // Copyright (C) 2012, ARM Research Labs, LLC.
- // See www.armresearch.com for the copyright terms.
- //
- // Create and maintain the sniffer configuration file for SNFMilter.
- //
- // The configuration file and instructions are specified on the
- // command line, and are used to create/modify the configuration file,
- // and integrate or unintegrate with the specified MTA.
- //
- //
- // $Id$
- //
- ///////////////////////////////////////////////////////////////////////////////////////////////////
-
- #include <errno.h>
- #include <string.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <pwd.h>
- #include <sys/stat.h>
-
- #include <exception>
- #include <iostream>
- #include <fstream>
-
- #include "SNFMulti.hpp"
- #include "SNFMilterConfig.hpp"
-
- using namespace std;
-
- //////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Configuration. ////////////////////////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////////////////////////////////////////
-
- /// Version string.
- const char* SNF_MILTERCONFIG_VERSION = "SNFMilterConfig 0.0.1 Build: " __DATE__ " " __TIME__;
-
- //////////////////////////////////////////////////////////////////////////////////////////////////////////
- // End of configuration. /////////////////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////////////////////////////////////////
-
- void RestoreFiles(SNFMilterConfig *Config) {
-
- try {
-
- cerr << "Restoring all configuration files...";
- Config->SaveFile.RestoreAllFilesFromBackup();
- cerr << "done.\n";
- }
- catch(exception& e) {
-
- cerr << "SNFMilterConfig::SaveFile Exception: " << e.what() << endl;
-
- }
-
- }
-
- int main(int argc, char* argv[]) {
-
- SNFMilterConfig SnfMilterConfig;
-
- if (!SnfMilterConfig.GetCommandLineInput(argc, argv) || // If our command line arguments
- SnfMilterConfig.Help()) { // don't look right, or if help is
- // requested then display our help
- SnfMilterConfig.DisplayHelp(SNF_MILTERCONFIG_VERSION); // screen.
- return 0;
-
- }
-
- bool DebugMode = false; // This will be our debug mode.
- string argv0(argv[0]); // Capture how we were called.
- if(
- string::npos != argv0.find("Debug") || // If we find "Debug" or
- string::npos != argv0.find("debug") // "debug" in our command path
- ) { // then we are in DebugMode.
- DebugMode = true; // Set the flag and tell the
- cout << SNF_MILTERCONFIG_VERSION << endl; // watchers.
- cout << "Debug Mode" << endl;
- }
-
- try { // Catch anything that breaks loose.
-
- #if 0
- SnifferRunningStatue RunningStatus;
- #endif
-
- SnfMilterConfig.CreateLoadConfig(); // Save config file state and load config.
- // Load the default if necessary.
-
- SnfMilterConfig.SaveFileState(); // Save state of all other files.
-
- #if 0
- RunningStatus = SnfMilterConfig.GetSnifferRunningStatus(); // Get state before changing anything.
- #endif
-
- SnfMilterConfig.UpdateConfigFiles(); // Create/update config files
-
- SnfMilterConfig.CreateUpdateRulebaseScript(); // Create/update GetRulebase.
-
- SnfMilterConfig.DownloadRulebase(); // Download rulebase.
-
- SnfMilterConfig.UpdateIdentityFile(); // Update Identity file with credentials,
- // if credentials were specified.
-
- SnfMilterConfig.DoIntegrationCommand(); // Integrate/unintegrate.
-
- #if 0
- if (SnifferIsStopped == RunningStatus) {
-
- SnfMilterConfig.StartSniffer();
-
- } else if (SnifferRunningStatusIsUknown == RunningStatus) {
-
- std::cout << "SNFMilterConfig: Unable to determine whether SNFMilter is running.\n"
- << "Please start SNFMilter if it isn't running.\n";
-
- }
- #else
- SnfMilterConfig.StartSniffer("snf-milter");
- #endif
-
- } // That's all folks.
-
- catch(exception& e) { // Report any normal exceptions.
- cerr << "\n\nSNFMilterConfig Exception: " << e.what() << endl << endl;
- RestoreFiles(&SnfMilterConfig);
- }
- catch (snfCFGmgr::LoadFailure) { // Error loading configuration file.
- cerr << "\n\nsnfCFGmgr Exception: Unable to load the configuration file "
- << SnfMilterConfig.GetConfigFileName() << endl << endl;
- RestoreFiles(&SnfMilterConfig);
- }
- catch(...) { // Report any unexpected exceptions.
- cerr << "\n\nSNFMilterConfig Panic! Unknown Exception!" << endl << endl;
- RestoreFiles(&SnfMilterConfig);
- }
-
- return 0; // Normally we return zero.
-
- }
|