Credential, Start/stop with XCI. git-svn-id: https://svn.microneil.com/svn/SNFUtility/trunk@20 aa37657e-1934-4a5f-aa6d-2d8eab27ff7cmaster
// End of configuration. ///////////////////////////////////////////////////////////////////////////////// | // End of configuration. ///////////////////////////////////////////////////////////////////////////////// | ||||
////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
Utility::Utility() { | |||||
Utility::Utility() : | |||||
DebugRequested(false), VerboseRequested(false), ExplainRequested(false), HelpRequested(false) | |||||
{ | |||||
} | } | ||||
bool | bool | ||||
Utility::FileExists(const std::string File) { | Utility::FileExists(const std::string File) { | ||||
if (Verbose()) { | |||||
cout << "Check whether " << File << " exists..."; | |||||
} | |||||
bool Exists; | bool Exists; | ||||
std::ifstream Input; | std::ifstream Input; | ||||
Input.close(); | Input.close(); | ||||
OutputVerboseEnd(); | |||||
return Exists; | return Exists; | ||||
} | } |
} | } | ||||
void | void | ||||
UtilityConfig::CheckAndSetConfigFileName(const std::string DefaultFile[], int NumDefaultFiles) { | |||||
UtilityConfig::CheckAndSetConfigFileName(const std::string DefaultFile) { | |||||
string ProvisionalConfigFile = ConfigFileName; | |||||
string SpecifiedConfigFile = GetConfigFileName(); | |||||
if (ProvisionalConfigFile.length() == 0) { | |||||
if (SpecifiedConfigFile.length() > 0) { | |||||
int i; | |||||
vector<string> FoundFile; | |||||
for (i = 0; i < NumDefaultFiles; i++) { | |||||
if (!FileExists(DefaultFile[i])) { | |||||
continue; // File doesn't exist. | |||||
} | |||||
FoundFile.push_back(DefaultFile[i]); // Update list of found files. | |||||
ProvisionalConfigFile = DefaultFile[i]; // Found configuration file. | |||||
} | |||||
if (0 == FoundFile.size()) { // No default file found. | |||||
if (NumDefaultFiles > 0) { | |||||
ProvisionalConfigFile = DefaultFile[0]; // Use the first default file. | |||||
} else { // No default config file was specified. | |||||
ostringstream Temp; | |||||
Temp << "Internal error: NumDefaultFiles <= 0 at " << __FILE__ << ":" << __LINE__; | |||||
throw std::runtime_error(Temp.str()); | |||||
} | |||||
} else if (FoundFile.size() > 1) { // Multiple default files found. | |||||
string Temp; | |||||
Temp = "Configuration file was not specified, and more than one default configuration file was found::\n\n"; | |||||
for (i = 0; i < FoundFile.size(); i++) { | |||||
Temp += " "; | |||||
Temp += FoundFile[i] + "\n"; | |||||
} | |||||
throw std::runtime_error(Temp); | |||||
} | |||||
return; | |||||
} | } | ||||
SetConfigFileName(ProvisionalConfigFile); | |||||
SetConfigFileName(DefaultFile); | |||||
} | } | ||||
} | } | ||||
void | |||||
UtilityConfig::SetupRepairIdentityFile(std::string SampleIdentityFile) { | |||||
std::string File = GetIdentityFileName(); | |||||
if (!FileExists(File)) { | |||||
if (!Explain()) { | |||||
SaveFile.CreateBackupFile(File); | |||||
} | |||||
// Create the config file. | |||||
Copy(SampleIdentityFile, File); | |||||
} | |||||
} | |||||
void | |||||
UtilityConfig::SetupRepairRulebaseScript() { | |||||
std::string File = GetRulebaseScriptName(); | |||||
if (!FileExists(File)) { | |||||
if (!Explain()) { | |||||
SaveFile.CreateBackupFile(File); | |||||
} | |||||
Copy(SampleRulebaseScriptFile, File); // Copy if !Explain(). | |||||
} | |||||
SetMode(File, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); // Set permissions. | |||||
} | |||||
void | |||||
UtilityConfig::SetupRepairIgnoreListFile() { | |||||
string File = GetIgnoreListFileName(); | |||||
if (!FileExists(File)) { | |||||
if (!Explain()) { | |||||
SaveFile.CreateBackupFile(File); | |||||
} | |||||
Copy(SampleIgnoreListFile, File); | |||||
} | |||||
SetMode(File, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); // Set permissions. | |||||
SetOwnerGroup(File); // Set to sniffer user. | |||||
} | |||||
void | |||||
UtilityConfig::SetupRepairLogDir() { | |||||
string LogDir = GetLogPath(); | |||||
if (!FileExists(LogDir)) { | |||||
MkDir(LogDir); | |||||
} | |||||
SetMode(LogDir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); | |||||
SetOwnerGroup(LogDir); | |||||
} | |||||
UtilityConfig::StatusCheckMethod | UtilityConfig::StatusCheckMethod | ||||
UtilityConfig::GetPreferredStatusCheckMethod(void) { | UtilityConfig::GetPreferredStatusCheckMethod(void) { | ||||
if (Verbose()) { | if (Verbose()) { | ||||
cout << "Getting Sniffer status report via XCI..."; | |||||
std::cout << "Getting Sniffer status report via XCI..."; | |||||
std::cout.flush(); | |||||
} | } | ||||
if (Verbose()) { | if (Verbose()) { | ||||
cout << "no response..."; | |||||
std::cout << "no response..."; | |||||
} | } | ||||
} | } | ||||
OutputVerboseEnd(); | |||||
if (Verbose()) { | |||||
std::cout << "response received..."; | |||||
} | |||||
return Reader.report_response; | return Reader.report_response; | ||||
if (Verbose()) { | if (Verbose()) { | ||||
cout << "Getting Sniffer status report via log file " << LogFileName << "..."; | cout << "Getting Sniffer status report via log file " << LogFileName << "..."; | ||||
std::cout.flush(); | |||||
} | } | ||||
} | } | ||||
ConfigurationElement MyCFGReader("stats"); // Object to parse the XML. | ConfigurationElement MyCFGReader("stats"); // Object to parse the XML. | ||||
ConfigurationData MyCFGData(StatusReport); // Object that contains the XML. | |||||
ConfigurationData MyCFGData(StatusReport.c_str(), StatusReport.length()); // Object that contains the XML. | |||||
std::string PlatformContent; | std::string PlatformContent; | ||||
if (Verbose()) { | if (Verbose()) { | ||||
cout << "Checking whether " << ApplicationName << " is running..."; | cout << "Checking whether " << ApplicationName << " is running..."; | ||||
cout.flush(); | |||||
} | } | ||||
std::string StatusReport = GetSnifferStatusReport(); | std::string StatusReport = GetSnifferStatusReport(); | ||||
OutputVerboseEnd(); | |||||
if (StatusReport.length() == 0) { | if (StatusReport.length() == 0) { | ||||
return SnifferIsStopped; | return SnifferIsStopped; | ||||
CheckSnifferStatusReport(StatusReport, ApplicationName); | CheckSnifferStatusReport(StatusReport, ApplicationName); | ||||
OutputVerboseEnd(); | |||||
return SnifferIsRunning; | return SnifferIsRunning; | ||||
} | } | ||||
void | void | ||||
UtilityConfig::SetupRepair(const std::string SampleIdentityFile) { | UtilityConfig::SetupRepair(const std::string SampleIdentityFile) { | ||||
SetupRepairIdentityFile(SampleIdentityFile); | |||||
SetupRepairRulebaseScript(); | |||||
SetupRepairIgnoreListFile(); | |||||
SetupRepairLogDir(); | |||||
RestoreMissingConfigFiles(SampleIdentityFile); | |||||
SetOwnerPermissionsOfConfigFiles(); | |||||
} | |||||
void | |||||
UtilityConfig::RestoreMissingConfigFiles(std::string SampleIdentityFile) { | |||||
std::string File; | |||||
File = GetIdentityFileName(); | |||||
if (!FileExists(File)) { | |||||
if (!Explain()) { | |||||
SaveFile.CreateBackupFile(File); | |||||
} | |||||
// Create the config file. | |||||
Copy(SampleIdentityFile, File); | |||||
} | |||||
File = GetRulebaseScriptName(); | |||||
if (!FileExists(File)) { | |||||
if (!Explain()) { | |||||
SaveFile.CreateBackupFile(File); | |||||
} | |||||
Copy(SampleRulebaseScriptFile, File); // Copy if !Explain(). | |||||
} | |||||
File = GetIgnoreListFileName(); | |||||
if (!FileExists(File)) { | |||||
if (!Explain()) { | |||||
SaveFile.CreateBackupFile(File); | |||||
} | |||||
Copy(SampleIgnoreListFile, File); | |||||
} | |||||
std::string LogDir = GetLogPath(); | |||||
if (!FileExists(LogDir)) { | |||||
MkDir(LogDir); | |||||
} | |||||
} | |||||
void | |||||
UtilityConfig::SetOwnerPermissionsOfConfigFiles() { | |||||
std::string File; | |||||
File = GetIdentityFileName(); | |||||
if (FileExists(File)) { | |||||
SetMode(File, S_IRUSR | S_IWUSR | S_IRGRP); | |||||
SetOwnerGroup(File); | |||||
} | |||||
File = GetRulebaseScriptName(); | |||||
if (FileExists(File)) { | |||||
SetMode(File, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); | |||||
} | |||||
File = GetIgnoreListFileName(); | |||||
if (FileExists(File)) { | |||||
SetMode(File, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); | |||||
SetOwnerGroup(File); | |||||
} | |||||
std::string LogDir = GetLogPath(); | |||||
if (FileExists(LogDir)) { | |||||
SetMode(LogDir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); | |||||
SetOwnerGroup(LogDir); | |||||
} | |||||
} | } | ||||
void | void | ||||
UtilityConfig::StartSniffer(std::string ScriptAndArgs, std::string ApplicationName) { | UtilityConfig::StartSniffer(std::string ScriptAndArgs, std::string ApplicationName) { | ||||
if (SnifferIsRunning == GetRunningState(ApplicationName)) { | |||||
std::cout << ApplicationName << " is already running.\n"; | |||||
return; | |||||
} | |||||
std::string Command; | std::string Command; | ||||
Command = SnifferStartScriptDir + ScriptAndArgs; | Command = SnifferStartScriptDir + ScriptAndArgs; | ||||
if (Verbose()) { | if (Verbose()) { | ||||
cout << "Starting Sniffer with the command '" << Command << "'..."; | cout << "Starting Sniffer with the command '" << Command << "'..."; | ||||
} | |||||
if (SnifferIsRunning == GetRunningState(ApplicationName)) { | |||||
std::cout << ApplicationName << " is already running.\n"; | |||||
OutputVerboseEnd(); | |||||
return; | |||||
cout.flush(); | |||||
} | } | ||||
} | } | ||||
} | |||||
OutputVerboseEnd(); | |||||
if (SnifferIsRunning != GetRunningState(ApplicationName)) { | |||||
std::string Temp; | |||||
if (SnifferIsRunning != GetRunningState(ApplicationName)) { | |||||
std::string Temp; | |||||
Temp = "Unable to start " + ApplicationName; | |||||
throw std::runtime_error(Temp); | |||||
Temp = "Unable to start " + ApplicationName; | |||||
throw std::runtime_error(Temp); | |||||
} | |||||
} | |||||
OutputVerboseEnd(); | |||||
} else { | |||||
OutputVerboseEnd(); | |||||
} | |||||
} | } | ||||
void | void | ||||
UtilityConfig::StopSniffer(std::string ScriptAndArgs, std::string ApplicationName) { | UtilityConfig::StopSniffer(std::string ScriptAndArgs, std::string ApplicationName) { | ||||
if (SnifferIsStopped == GetRunningState(ApplicationName)) { | |||||
std::cout << ApplicationName << " is already not running.\n"; | |||||
return; | |||||
} | |||||
std::string Command; | std::string Command; | ||||
Command = SnifferStartScriptDir + ScriptAndArgs; | Command = SnifferStartScriptDir + ScriptAndArgs; | ||||
if (Verbose()) { | if (Verbose()) { | ||||
cout << "Stopping Sniffer with the command '" << Command << "'..."; | cout << "Stopping Sniffer with the command '" << Command << "'..."; | ||||
} | |||||
if (SnifferIsStopped == GetRunningState(ApplicationName)) { | |||||
std::cout << ApplicationName << " is already not running.\n"; | |||||
OutputVerboseEnd(); | |||||
return; | |||||
cout.flush(); | |||||
} | } | ||||
} | } | ||||
} | |||||
OutputVerboseEnd(); | |||||
if (SnifferIsStopped != GetRunningState(ApplicationName)) { | |||||
std::string Temp; | |||||
if (SnifferIsStopped != GetRunningState(ApplicationName)) { | |||||
std::string Temp; | |||||
Temp = "Unable to sto " + ApplicationName; | |||||
throw std::runtime_error(Temp); | |||||
Temp = "Unable to stop " + ApplicationName; | |||||
throw std::runtime_error(Temp); | |||||
} | |||||
} | |||||
OutputVerboseEnd(); | |||||
} else { | |||||
OutputVerboseEnd(); | |||||
} | |||||
} | } | ||||
SetStopSniffer(true); | SetStopSniffer(true); | ||||
} else if (OneInput == ConfigFileKey) { | |||||
SetConfigFileName(OneInput.substr(ConfigFileKey.length())); | |||||
} else if (0 == OneInput.find(ConfigFileKey)) { | |||||
TempString = Trim(OneInput.substr(ConfigFileKey.length())); // Copy only if not null after trimming. | |||||
SetConfigFileName(TempString); | |||||
} else if (0 == OneInput.find(LicenseIdKey)) { | } else if (0 == OneInput.find(LicenseIdKey)) { | ||||
// | // | ||||
// If the configuration file wasn't specified by | // If the configuration file wasn't specified by | ||||
// SetConfigFileName() on the command line, then this method sets | // SetConfigFileName() on the command line, then this method sets | ||||
// the config file to the default. The default is the unique file | |||||
// that exists in the specified list. If more than one file in | |||||
// the specified list exists, an exception is thrown. | |||||
// the config file to the specified default. | |||||
// | // | ||||
// If the configuration file was specified by SetConfigFileName() | // If the configuration file was specified by SetConfigFileName() | ||||
// or on the command line, then this method does nothing. | // or on the command line, then this method does nothing. | ||||
// | // | ||||
// \param[in] DefaultFile is the list of default locations of the file. | |||||
// \param[in] DefaultFile is the default file name. | |||||
// | // | ||||
// \param[in] NumDefaultFiles is the number of defaultlocations. | |||||
// | |||||
void CheckAndSetConfigFileName(const std::string DefaultFile[], int NumDefaultFiles); | |||||
void CheckAndSetConfigFileName(const std::string DefaultFile); | |||||
/// If the configuration file doesn't exist, create it from the | /// If the configuration file doesn't exist, create it from the | ||||
/// sample file. In any case, set the owner and mode. | /// sample file. In any case, set the owner and mode. | ||||
// Make sure that the log directory exists and has the correct | // Make sure that the log directory exists and has the correct | ||||
// owner and permissions. | // owner and permissions. | ||||
// | // | ||||
// \param[in] SampleIdentityFile is the name of the sample identity file. | |||||
// | |||||
// \note The configuration information must be loaded before calling this method. | |||||
// | |||||
// \see CheckAndSetConfigFileName. | |||||
// | |||||
// \see CreateDefaultConfigFile. | |||||
// | |||||
// \see LoadConfig. | |||||
// | |||||
// \see LoadInfo. | |||||
// | |||||
void SetupRepair(const std::string SampleIdentityFile); | void SetupRepair(const std::string SampleIdentityFile); | ||||
/// Restore any missing configuration files. | |||||
// | |||||
// Restore missing configuration files from the sample files. The | |||||
// files restored are the ones restored by SetupRepair. | |||||
// | |||||
// \param[in] SampleIdentityFile is the name of the sample identity file. | |||||
// | |||||
void RestoreMissingConfigFiles(const std::string SampleIdentityFile); | |||||
/// Set the owner, group, and permissions of the configuration | |||||
/// files and directories. | |||||
// | |||||
// This method sets the ownership, group, and permissions of all | |||||
// the configuration files. | |||||
// | |||||
void SetOwnerPermissionsOfConfigFiles(void); | |||||
/// Update the rulebase script credentials. | /// Update the rulebase script credentials. | ||||
// | // | ||||
// This method updates the rulebase with the credentials specified | // This method updates the rulebase with the credentials specified | ||||
StatusCheckNotAvailable ///< No method for checking is available. | StatusCheckNotAvailable ///< No method for checking is available. | ||||
}; | }; | ||||
/// Setup/repair the identity file. | |||||
// | |||||
// If the identity file doesn't exist, create it from the sample | |||||
// file. | |||||
// | |||||
// In any case, set the owner and permissions of the identity | |||||
// file. | |||||
// | |||||
// \param[in] SampleIdentityFile is the name of the sample | |||||
// identity file. | |||||
// | |||||
// \note The configuration information must be loaded before calling this method. | |||||
// | |||||
// \see CheckAndSetConfigFileName. | |||||
// | |||||
// \see CreateDefaultConfigFile. | |||||
// | |||||
// \see LoadConfig. | |||||
// | |||||
// \see LoadInfo. | |||||
// | |||||
void SetupRepairIdentityFile(std::string SampleIdentityFile); | |||||
/// Setup/repair the rulebase script. | |||||
// | |||||
// If the rulebase script doesn't exist, this method creates the | |||||
// rulebase script from the sample rulebase script. | |||||
// | |||||
// In any case, set the owner and permissions of the rulebase | |||||
// script. | |||||
// | |||||
void SetupRepairRulebaseScript(void); | |||||
/// Setup/repair the ignore list file. | |||||
// | |||||
// The ignore list file is created if it dosn't exist. In any | |||||
// case, the owner/group is changed by SetOwnerGroup(), and the | |||||
// permissions are changed to readonly for everyone, and | |||||
// read/write for the owner. | |||||
// | |||||
void SetupRepairIgnoreListFile(void); | |||||
/// Setup/repair the log directory. | |||||
// | |||||
// The log directory is created if it dosn't exist. In any case, | |||||
// the owner/group is changed by SetOwnerGroup(), and the | |||||
// permissions are changed to r-x for everyone, and rwx for the | |||||
// owner. | |||||
// | |||||
void SetupRepairLogDir(void); | |||||
/// Determine the mode for checking the status of Sniffer. | /// Determine the mode for checking the status of Sniffer. | ||||
// | // | ||||
// This method determines how the status of the sniffer should be | // This method determines how the status of the sniffer should be |
case SetupRepairCommand: | case SetupRepairCommand: | ||||
CreateLoadConfig(); // Save config file state create default | |||||
// config if necessary, and load config. | |||||
CheckAndSetConfigFileName(DefaultConfigFile); // Load the config file name if not specified. | |||||
CreateDefaultConfigFile(SampleConfigFile); // Create the file if it doesn't exist, | |||||
// Set owner and mode in any case. | |||||
LoadConfig(); | |||||
LoadInfo(); // Load the file paths. | |||||
LoadSocketInfo(); // Load the socket path. | |||||
SetupRepair(SampleIdentityFile); | SetupRepair(SampleIdentityFile); | ||||
SetupRepairSocketDir(); | SetupRepairSocketDir(); | ||||
case UpdateCredentialsCommand: | case UpdateCredentialsCommand: | ||||
UpdateRulebaseScriptCredentials(); | |||||
CheckAndSetConfigFileName(DefaultConfigFile); // Load the config file name if not specified. | |||||
LoadConfig(); | |||||
LoadInfo(); // Load the file paths. | |||||
LoadSocketInfo(); // Load the socket path. | |||||
UpdateRulebaseScriptCredentials(); | |||||
DownloadRulebase(); | DownloadRulebase(); | ||||
case StartSnifferCommand: | case StartSnifferCommand: | ||||
CheckAndSetConfigFileName(DefaultConfigFile); | |||||
LoadConfig(); | |||||
LoadInfo(); | |||||
LoadSocketInfo(); | |||||
StartSniffer("snf-milter start", ApplicationName); | StartSniffer("snf-milter start", ApplicationName); | ||||
break; | break; | ||||
case StopSnifferCommand: | case StopSnifferCommand: | ||||
CheckAndSetConfigFileName(DefaultConfigFile); | |||||
LoadConfig(); | |||||
LoadInfo(); | |||||
LoadSocketInfo(); | |||||
StopSniffer("snf-milter stop", ApplicationName); | StopSniffer("snf-milter stop", ApplicationName); | ||||
break; | break; | ||||
} | } | ||||
void | |||||
SNFMilterConfig::CreateLoadConfig() { | |||||
CheckAndSetConfigFileName(&DefaultConfigFile, 1); // Load the config file name. | |||||
CreateDefaultConfigFile(SampleConfigFile); // Create the file if it doesn't exist, | |||||
// Set owner and mode in any case. | |||||
LoadConfig(); | |||||
LoadInfo(); // Load the file paths. | |||||
LoadSocketInfo(); // Load the socket path. | |||||
} | |||||
void | void | ||||
SNFMilterConfig::SaveFileState() { | SNFMilterConfig::SaveFileState() { | ||||
// | // | ||||
bool GetCommandLineInput(int argc, char* argv[]); | bool GetCommandLineInput(int argc, char* argv[]); | ||||
/// Load the configuration, creating default configuration if necessary. | |||||
// | |||||
// This method load the configuration specified in the command | |||||
// line, or the default config file. If the config file to load | |||||
// doesn't exit, the config file is created by copying from the | |||||
// sample config file. | |||||
// | |||||
// Side effect: The state of the config file is saved. | |||||
// | |||||
// Side effect: If the config file doesn't exist, a new config | |||||
// file is created. | |||||
// | |||||
void CreateLoadConfig(void); | |||||
/// Execute the command specified by the command-line parameters. | /// Execute the command specified by the command-line parameters. | ||||
// | // | ||||
void ExecuteCommand(void); | void ExecuteCommand(void); |
SNFUtility revision 9 | SNFUtility revision 9 | ||||
Help functionality-- | |||||
Help functionality | |||||
------------------ | |||||
HELP-01: SNFMilterConfig without any command options outputs a help | HELP-01: SNFMilterConfig without any command options outputs a help | ||||
message. | message. | ||||
Credentials functionality-- | |||||
Result: Pass. | |||||
CRED-01: Start with no identity.xml and no getRulebase. Verify that | |||||
when the valid credentials are specified on the command line: | |||||
1) getRulebase is created, | |||||
Conflict detection | |||||
------------------ | |||||
2) The rulebase is downloaded, | |||||
CONFLICT-01: Run with -setup, -id, and -auth. Verify that help | |||||
message is output, and that SNFMilterConfig takes no action. | |||||
3) The identity.xml file is created. | |||||
Result: Pass. | |||||
Repeat with -mta=none, -mta=postfix, and -mta=sendmail. | |||||
CONFLICT-02: Run with -setup and -start. Verify that help message is | |||||
output, and that SNFMilterConfig takes no action. | |||||
CRED-02: After the previous test, specify incorrect credentials. | |||||
Verify: | |||||
Result: Pass. | |||||
1) getRulebase is not updated, | |||||
CONFLICT-03: Run with -setup and -stop. Verify that help message is | |||||
output, and that SNFMilterConfig takes no action. | |||||
Result: Pass. | |||||
CONFLICT-04: Run with -setup and -mta=XXX, where XXX is postfix, | |||||
sendmail, and none. Verify that help message is output, and that | |||||
SNFMilterConfig takes no action. | |||||
Result: Pass. | |||||
Setup/Repair functionality | |||||
-------------------------- | |||||
SETUP-01: Start with no configuration files installed (SNFMilter.xml, | |||||
identity.xml GBUdbIgnoreList.txt, and getRulebase). Verify that | |||||
either "-setup" or "-repair" creates these files with the default | |||||
credentials. | |||||
Result: Pass. | |||||
SETUP-02: Repeat SETUP-01 with -v and verify that files are created. | |||||
Result: Pass. | |||||
SETUP-03: Repeat SETUP-01 with -explain and verify that files are not created. | |||||
Result: Pass? Exception thrown (as expected) when attempting to read | |||||
configuration file that doesn't exist. | |||||
Config file specification | |||||
------------------------- | |||||
CONF-01: Start with no configuration files, and copy the sample | |||||
configuration file to test.xml. Run with "-setup -config=test.xml", | |||||
and verify that all configuration files except | |||||
/etc/snf-milter/SNFMilter.xml are created. | |||||
Result: Pass. | |||||
CONF-02: Repeat with -v and verify the same behavior. | |||||
Result: Pass. | |||||
CONF-03: Repeat with -explain. | |||||
Result: Pass. | |||||
Credential Functionality | |||||
------------------------ | |||||
CRED-01: Configure, and run "-id=xxx -auth=yyy" with specification of | |||||
incorrect credentials. Verify: | |||||
1) getRulebase is not updated, and getRulebase.failed file is | |||||
created., | |||||
2) The rulebase downloaded fails, and an error message is output, | 2) The rulebase downloaded fails, and an error message is output, | ||||
3) The identity.xml file is not created. | |||||
3) The identity.xml file is not changed. | |||||
Result: Pass. | |||||
CRED-02: Repeat CRED-01 with -v and verify correct operation. | |||||
Result: Pass. | |||||
CRED-03: Repeat CRED-01 with -explain and verify correct operation. | |||||
Result: Pass. | |||||
CRED-04: Install default configuration files. Modify identity.xml as | |||||
follows: | |||||
1) Change the license ID to "XXX" and authentication to "YYY". | |||||
2) Add a comment. | |||||
Then run with "-id=testmode -auth=setuptestingonly". Verify: | |||||
1) getRulebase is updated, and the new rulebase is downloaded. | |||||
2) identity.xml has only the license ID and authentication updated. | |||||
Result: Pass. | |||||
CRED-05: Repeat CRED-04 with -v and verify correct operation. | |||||
Result: Pass. | |||||
CRED-05: Repeat CRED-04 with -explain and verify correct operation. | |||||
Result: Pass | |||||
Start/stop functionality with XCI enabled | |||||
----------------------------------------- | |||||
START_STOP_XCI-01: Install default configuration files, and ensure | |||||
that SNFMilter is stoped. Create a configuration file | |||||
SNFMilter_xci.xml as follows: | |||||
1) Enable XCI. | |||||
2) Enable status.second logging, with no append. | |||||
3) Enable status.minute logging, with append. | |||||
Do the following, specifying the configuration file SNFMilter_xci.xml: | |||||
1) Run SNFMilterConfig with "-start", and verify that SNFMilter starts. | |||||
2) Run SNFMilterConfig with "-start" again and verify that SNFMilter | |||||
is not started again. | |||||
3) Run SNFMitlerConfig with "-stop" and verify that SNFMilter stops. | |||||
4) Run SNFMitlerConfig with "-stop" again and verify that SNFMilter | |||||
is not stopped again. | |||||
Result: Pass | |||||
START_STOP_XCI-02: Repeat START_STOP_XCI-01 but with "-v" in the command-line. | |||||
Result: Pass | |||||
START_STOP_XCI-03: Configure as for START_STOP_XCI-01, and do the following: | |||||
1) Run SNFMilterConfig with "-start -explain". Verify correct | |||||
output, and that SNFMilterConfig doesn't start SNFMilter. | |||||
2) Run SNFMilterConfig with "-stop -explain". Verify correct | |||||
output, and that SNFMilterConfig doesn't stop SNFMilter. | |||||
3) Start SNFMilter. | |||||
4) Run SNFMilterConfig with "-start -explain". Verify correct | |||||
output, and that SNFMilterConfig doesn't start SNFMilter. | |||||
5) Run SNFMilterConfig with "-stop -explain". Verify correct | |||||
output, and that SNFMilterConfig doesn't stop SNFMilter. | |||||
Result: Pass | |||||
Start/stop functionality with XCI disabled, status.second enabled | |||||
----------------------------------------------------------------- | |||||
START_STOP_SEC-01: Install default configuration files, and ensure | |||||
that SNFMilter is stoped. Create a configuration file | |||||
SNFMilter_second.xml as follows: | |||||
1) Disable XCI. | |||||
2) Enable status.second logging, with no append. | |||||
3) Enable status.minute logging, with append. | |||||
Do the following, specifying the configuration file SNFMilter_second.xml: | |||||
Repeat with -mta=none, -mta=postfix, and -mta=sendmail. | |||||
1) Run SNFMilterConfig with "-start", and verify that SNFMilter starts. | |||||
CRED-03: Start with no identity.xml and no getRulebase. Verify that | |||||
when no credentials are specified on the command line: | |||||
2) Run SNFMilterConfig with "-start" again and verify that SNFMilter | |||||
is not started again. | |||||
1) getRulebase is created with the default credentials, | |||||
3) Run SNFMitlerConfig with "-stop" and verify that SNFMilter stops. | |||||
2) The rulebase is not downloaded, | |||||
4) Run SNFMitlerConfig with "-stop" again and verify that SNFMilter | |||||
is not stopped again. | |||||
3) The identity.xml file is created with the default credentials.. | |||||
Result: | |||||
Repeat with -mta=none, -mta=postfix, and -mta=sendmail. | |||||
START_STOP_SEC-02: Repeat START_STOP_SEC-01 but with "-v" in the | |||||
command-line. | |||||
Default config file functionality-- | |||||
Result: | |||||
CONF-01: Starting with no configuration (no SNFMilter.xml, | |||||
identity.xml, getRulebase, rulebase file (but the default rulebase | |||||
file is present), or GBUdbIgnore.txt), run with the following | |||||
command-line parameters: | |||||
START_STOP_SEC-03: Configure as for START_STOP_SEC-01, and do the | |||||
following: | |||||
1) "-mta=none" installs all files with testmode credentials, | |||||
downloads rulebase, starts SNFMilter. | |||||
1) Run SNFMilterConfig with "-start -explain". Verify correct | |||||
output, and that SNFMilterConfig doesn't start SNFMilter. | |||||
2) "-mta=none -auth=xxx, id=yyy" where xxx/yyy is a valid auth/id | |||||
pair, installs all files with xxx/yyy credentials, downloads | |||||
rulebase, starts SNFMilter. | |||||
2) Run SNFMilterConfig with "-stop -explain". Verify correct | |||||
output, and that SNFMilterConfig doesn't stop SNFMilter. | |||||
3) "-mta=postfix" installs all files with testmode credentials, | |||||
downloads rulebase, starts SNFMilter, restarts postfix. | |||||
3) Start SNFMilter. | |||||
4) "-mta=postfix -auth=xxx, id=yyy" where xxx/yyy is a valid auth/id | |||||
pair, installs all files with xxx/yyy credentials, downloads | |||||
rulebase, starts SNFMilter, restarts postfix. | |||||
4) Run SNFMilterConfig with "-start -explain". Verify correct | |||||
output, and that SNFMilterConfig doesn't start SNFMilter. | |||||
5) "-mta=none -config=/etc/snf-milter/test.xml" installs all files | |||||
in the default locations except the configuration file is | |||||
test.xml, downloads rulebase, starts SNFMilter. Starting | |||||
SNFMilter should fail because there is no configuration file | |||||
test.xml. Verify that the configuration files are not present. | |||||
5) Run SNFMilterConfig with "-stop -explain". Verify correct | |||||
output, and that SNFMilterConfig doesn't stop SNFMilter. | |||||
Result: |
try { | try { | ||||
cerr << "Restoring all configuration files..."; | cerr << "Restoring all configuration files..."; | ||||
Config->SaveFile.RestoreAllFilesFromBackup(); | Config->SaveFile.RestoreAllFilesFromBackup(); | ||||
cerr << "done.\n"; | |||||
Config->SetOwnerPermissionsOfConfigFiles(); | |||||
cerr << "done.\n\n" | |||||
<< "Configuration files that resulted in this error are saved with a suffix \"" | |||||
<< Config->SaveFile.GetFailedFileName("") << "\".\n"; | |||||
} | } | ||||
catch(exception& e) { | catch(exception& e) { | ||||