Added test procedures to test the integration/unintegration with postfix. git-svn-id: https://svn.microneil.com/svn/SNFUtility/trunk@28 aa37657e-1934-4a5f-aa6d-2d8eab27ff7cmaster
/// Integrate with the MTA. | /// Integrate with the MTA. | ||||
// | // | ||||
// If the MTA is already integrated, this method does nothing. | |||||
// If the MTA is already integrated, this method takes no action. | |||||
// Otherwise, the MTA is integrated with Sniffer, and the MTA | |||||
// configuration is reloaded if the MTA is running. | |||||
// | // | ||||
// \param[in] SaveFile is the object to back up any configuration | // \param[in] SaveFile is the object to back up any configuration | ||||
// files. | // files. | ||||
/// Unintegrate with the MTA. | /// Unintegrate with the MTA. | ||||
// | // | ||||
// If the MTA is not integrated, this method does nothing. | |||||
// If the MTA is not integrated, this method takes no action. | |||||
// Otherwise, the MTA is unintegrated with Sniffer, and the MTA | |||||
// configuration is reloaded if the MTA is running. | |||||
// | // | ||||
// \param[in] SaveFile is the object to back up any configuration | // \param[in] SaveFile is the object to back up any configuration | ||||
// files. | // files. | ||||
// | // | ||||
virtual void Unintegrate(FileBackup *SaveFile) = 0; | virtual void Unintegrate(FileBackup *SaveFile) = 0; | ||||
private: | |||||
/// Check whether the MTA is determined to be running. | /// Check whether the MTA is determined to be running. | ||||
// | // | ||||
// \return true if the MTA is determined to be running. If the | // \return true if the MTA is determined to be running. If the | ||||
// | // | ||||
virtual bool ReloadMta() = 0; | virtual bool ReloadMta() = 0; | ||||
private: | |||||
/// Determine whether the MTA is integrated. | /// Determine whether the MTA is integrated. | ||||
virtual bool IsIntegrated() = 0; | virtual bool IsIntegrated() = 0; | ||||
throw std::runtime_error(Temp); | throw std::runtime_error(Temp); | ||||
} | } | ||||
if (MtaIsRunningDetected()) { | |||||
ReloadMta(); | |||||
} | |||||
} | } | ||||
OutputVerboseEnd(); | OutputVerboseEnd(); | ||||
} | } | ||||
if (MtaIsRunningDetected()) { | |||||
ReloadMta(); | |||||
} | |||||
} | } | ||||
OutputVerboseEnd(); | OutputVerboseEnd(); | ||||
} | } | ||||
bool Succeeded; | |||||
bool Failed; | |||||
if (!Explain()) { | if (!Explain()) { | ||||
Succeeded = (std::system(ReloadMtaCommand.c_str()) == 0); | |||||
Failed = (std::system(ReloadMtaCommand.c_str()) == 0); | |||||
if (Verbose()) { | if (Verbose()) { | ||||
std::cout << (Succeeded ? "succeeded" : "failed"); | |||||
std::cout << (Failed ? "failed..." : "succeeded..."); | |||||
} | } | ||||
OutputVerboseEnd(); | OutputVerboseEnd(); | ||||
return Succeeded; | |||||
return !Failed; | |||||
} | } | ||||
bool | bool | ||||
PostfixIntegrate::IsIntegrated() { | PostfixIntegrate::IsIntegrated() { | ||||
if (!FileExists(PostfixMainCfPath)) { | |||||
if (Verbose()) { | |||||
return false; | |||||
std::cout << "Checking for any SNFMilter integration in the postfix file " << PostfixMainCfPath << "..."; | |||||
} | } | ||||
bool Integrated = false; | |||||
if (!FileExists(PostfixMainCfPath)) { | |||||
if (Verbose()) { | |||||
if (Verbose()) { | |||||
std::cout << "file doesn't exist; postfix is not integrated..."; | |||||
} | |||||
std::cout << "Checking for any SNFMilter integration in the postfix file " << PostfixMainCfPath << "--\n"; | |||||
OutputVerboseEnd(); | |||||
return false; | |||||
} | } | ||||
bool Integrated = false; | |||||
std::ifstream Input; | std::ifstream Input; | ||||
Input.open(PostfixMainCfPath.c_str()); // Read the contents. | Input.open(PostfixMainCfPath.c_str()); // Read the contents. | ||||
if (std::string::npos != Line.find(SnfMilterMainCfSearchString)) { // Check for integration line. | if (std::string::npos != Line.find(SnfMilterMainCfSearchString)) { // Check for integration line. | ||||
Integrated = true; // Found it. | Integrated = true; // Found it. | ||||
if (Verbose()) { | |||||
std::cout << "found '" << Line << "'..."; | |||||
} | |||||
break; | break; | ||||
} | } |
virtual void Unintegrate(FileBackup *SaveFile); | virtual void Unintegrate(FileBackup *SaveFile); | ||||
private: | |||||
virtual bool MtaIsRunningDetected(); | virtual bool MtaIsRunningDetected(); | ||||
virtual bool ReloadMta(); | virtual bool ReloadMta(); | ||||
private: | |||||
virtual bool IsIntegrated(); | virtual bool IsIntegrated(); | ||||
/// Postfix main.cf file path. | /// Postfix main.cf file path. |
case IntegrateWithPostfixCommand: | case IntegrateWithPostfixCommand: | ||||
UnintegrateWithAllExcept("postfix"); | |||||
Postfix.Integrate(&SaveFile); | |||||
break; | break; | ||||
case IntegrateWithSendmailCommand: | case IntegrateWithSendmailCommand: | ||||
case IntegrateWithNoneCommand: | case IntegrateWithNoneCommand: | ||||
UnintegrateWithAllExcept(); | |||||
break; | break; | ||||
case StartSnifferCommand: | case StartSnifferCommand: | ||||
} | } | ||||
#if 0 | |||||
void | void | ||||
SNFMilterConfig::DoIntegrationCommand() { | SNFMilterConfig::DoIntegrationCommand() { | ||||
} | } | ||||
} | } | ||||
#endif | |||||
void | void | ||||
SNFMilterConfig::UnintegrateWithAllExcept(std::string Except) { | SNFMilterConfig::UnintegrateWithAllExcept(std::string Except) { | ||||
// | // | ||||
void SaveFileState(void); // OBSOLETE. | void SaveFileState(void); // OBSOLETE. | ||||
#if 0 | |||||
/// Execute the command to integrate/unintegrate with the MTAs. | /// Execute the command to integrate/unintegrate with the MTAs. | ||||
void DoIntegrationCommand(); | void DoIntegrationCommand(); | ||||
#endif | |||||
private: | private: | ||||
/// Setup/repair the directory containing the milter socket. | /// Setup/repair the directory containing the milter socket. | ||||
// | // | ||||
// This method ensures that the directore to contain the milter | |||||
// This method ensures that the directory to contain the milter | |||||
// socket exists and has the correct owner and permissions. | // socket exists and has the correct owner and permissions. | ||||
void SetupRepairSocketDir(); | void SetupRepairSocketDir(); | ||||
output, and that SNFMilterConfig doesn't stop SNFMilter. | output, and that SNFMilterConfig doesn't stop SNFMilter. | ||||
Result: | Result: | ||||
Integration with postfix | |||||
------------------------ | |||||
POSTFIX-01: Set up the environment as follows: | |||||
1) Default configuration files for SNFMilter. | |||||
2) SNFMilter stopped. | |||||
3) Default configuration files for postfix. | |||||
4) postfix stopped. | |||||
Do the following: | |||||
1) Run SNFMilterConfig with "-with=postfix -v" and verify that the | |||||
postfix configuration files are updated to be integrated with | |||||
SNFMilter. Verify also that both postfix and SNFMilter are | |||||
stopped. | |||||
2) Run SNFMilterConfig with "-with=postfix -v" and verify that the | |||||
postfix configuration files are not updated, and that both | |||||
postfix and SNFMilter are stopped. | |||||
3) Run SNFMilterConfig with "-with=none -v" and verify that the | |||||
postfix configuration files are updated such that the integration | |||||
with SNFMilter is removed. Verify also that both postfix and | |||||
SNFMilter are stopped. | |||||
4) Run SNFMilterConfig with "-with=none -v" and verify that the | |||||
postfix configuration files are not updated, and that both | |||||
postfix and SNFMilter are stopped. | |||||
Result: | |||||
POSTFIX-02: Repeat POSTFIX-01 but without "-v". | |||||
Result: | |||||
POSTFIX-03: Configure as for POSTFIX-01, and do the following: | |||||
1) Run SNFMilterConfig with "-with=postfix -explain". Verify | |||||
correct output, and that SNFMilterConfig doesn't update the | |||||
postfix configuration files or reload any MTA. | |||||
2) Run SNFMilterConfig with "-with=none -explain". Verify correct | |||||
output, and that SNFMilterConfig doesn't update the postfix | |||||
configuration files or reload any MTA. | |||||
Result: | |||||
POSTFIX-04: Set up the environment as follows: | |||||
1) Default configuration files for SNFMilter. | |||||
2) SNFMilter stopped. | |||||
3) Default configuration files for postfix. | |||||
4) postfix running. | |||||
Do the following: | |||||
1) Run SNFMilterConfig with "-with=postfix -v" and verify that the | |||||
postfix configuration files are updated to be integrated with | |||||
SNFMilter. Verify also that SNFMilter is not running and that | |||||
postfix is running and was reloaded. | |||||
2) Run SNFMilterConfig with "-with=postfix -v" and verify that the | |||||
postfix configuration files are not updated, that SNFMilter is | |||||
not running, and that postfix is running and was not reloaded. | |||||
3) Run SNFMilterConfig with "-with=none -v" and verify that the | |||||
postfix configuration files are updated such that the integration | |||||
with SNFMilter is removed. Verify also that SNFMilter is not | |||||
running, and that postfix is running and was not reloaded. | |||||
4) Run SNFMilterConfig with "-with=none -v" and verify that the | |||||
postfix configuration files are not updated, and that SNFMilter | |||||
is not running and that postfix is running and was not reloaded. | |||||
Result: | |||||
POSTFIX-05: Repeat POSTFIX-04 but without "-v". | |||||
Result: | |||||
POSTFIX-06: Configure as for POSTFIX-04, and do the following: | |||||
1) Run SNFMilterConfig with "-with=postfix -explain". Verify | |||||
correct output, and that SNFMilterConfig doesn't update the | |||||
postfix configuration files or reload any MTA. | |||||
2) Run SNFMilterConfig with "-with=none -explain". Verify correct | |||||
output, and that SNFMilterConfig doesn't update the postfix | |||||
configuration files or reload any MTA. | |||||
Result: | |||||