123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- // main.cpp
- //
- // Copyright (C) 2011, ARM Research Labs, LLC.
- // See www.armresearch.com for the copyright terms.
- //
- // Configure the identity.xml and getRulebase files with the license
- // and authentication credentials.
- //
- // The license and authentication credentials are specified on the
- // command line, and are used to create the identity.xml and update
- // the getRulebase files with that information.
- //
- // $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 "SNFIdentityConfig.hpp"
-
- using namespace std;
-
- //////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Configuration. ////////////////////////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////////////////////////////////////////
-
- /// Version string.
- const char* SNF_IDENTITY_VERSION = "SNFIdentity 0.0.1 Build: " __DATE__ " " __TIME__;
-
- /// Locations to search for default configuration files.
- const string DefaultConfigFile[] = {
- "/etc/snf-milter/SNFMilter.xml",
- "/usr/local/etc/snf-milter/SNFMilter.xml",
- "/etc/snf-server/SNFServer.xml",
- "/usr/local/etc/snf-server/SNFServer.xml"
- };
-
- const size_t DefaultConfigFileSize = sizeof DefaultConfigFile / sizeof DefaultConfigFile[0];
-
- //////////////////////////////////////////////////////////////////////////////////////////////////////////
- // End of configuration. /////////////////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////////////////////////////////////////
-
- int main(int argc, char* argv[]) {
-
- SNFIdentityConfig SnfIdentityConfig;
-
- if (!SnfIdentityConfig.GetCommandLineInput(argc, argv) || // If our command line arguments
- SnfIdentityConfig.Help()) { // don't look right, or if help is
- // requested then display our help
- SnfIdentityConfig.DisplayHelp(SNF_IDENTITY_VERSION, // screen.
- DefaultConfigFile,
- DefaultConfigFileSize);
- 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_IDENTITY_VERSION << endl; // watchers.
- cout << "Debug Mode" << endl;
- }
-
- try { // Catch anything that breaks loose.
-
- SnfIdentityConfig.CheckAndLoadConfigFile(DefaultConfigFile, // Load configuration from the
- DefaultConfigFileSize); // config file specified on the
- // command line, or the default file.
-
- SnfIdentityConfig.CreateIdentityFile();
-
- SnfIdentityConfig.UpdateRulebaseScriptCredentials();
-
- } // That's all folks.
-
- catch(exception& e) { // Report any normal exceptions.
- cerr << "SNFIdentity Exception: " << e.what() << endl;
- }
- catch (snfCFGmgr::LoadFailure) { // Error loading configuration file.
- cerr << "snfCFGmgr Exception: Unable to load the configuration file "
- << SnfIdentityConfig.GetConfigFileName() << endl;
- }
- catch(...) { // Report any unexpected exceptions.
- cerr << "SNFIdentity Panic! Unknown Exception!" << endl;
- }
-
- return 0; // Normally we return zero.
- }
|