Преглед на файлове

Updated integration/unintegration to restart postfix if it is running.

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-2d8eab27ff7c
master
adeniz преди 12 години
родител
ревизия
391b879527

+ 8
- 4
Common/MtaIntegrate.hpp Целия файл

@@ -38,7 +38,9 @@ public:
/// 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
// files.
@@ -47,13 +49,17 @@ public:
/// 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
// files.
//
virtual void Unintegrate(FileBackup *SaveFile) = 0;
private:
/// Check whether the MTA is determined to be running.
//
// \return true if the MTA is determined to be running. If the
@@ -71,8 +77,6 @@ public:
//
virtual bool ReloadMta() = 0;
private:
/// Determine whether the MTA is integrated.
virtual bool IsIntegrated() = 0;

+ 36
- 9
SNFMilterConfig/PostfixIntegrate.cpp Целия файл

@@ -133,6 +133,12 @@ PostfixIntegrate::Integrate(FileBackup *SaveFile) {
throw std::runtime_error(Temp);
}
if (MtaIsRunningDetected()) {
ReloadMta();
}
}
OutputVerboseEnd();
@@ -246,6 +252,12 @@ PostfixIntegrate::Unintegrate(FileBackup *SaveFile) {
}
if (MtaIsRunningDetected()) {
ReloadMta();
}
}
OutputVerboseEnd();
@@ -286,15 +298,15 @@ PostfixIntegrate::ReloadMta() {
}
bool Succeeded;
bool Failed;
if (!Explain()) {
Succeeded = (std::system(ReloadMtaCommand.c_str()) == 0);
Failed = (std::system(ReloadMtaCommand.c_str()) == 0);
if (Verbose()) {
std::cout << (Succeeded ? "succeeded" : "failed");
std::cout << (Failed ? "failed..." : "succeeded...");
}
@@ -302,27 +314,35 @@ PostfixIntegrate::ReloadMta() {
OutputVerboseEnd();
return Succeeded;
return !Failed;
}
bool
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;
Input.open(PostfixMainCfPath.c_str()); // Read the contents.
@@ -342,6 +362,13 @@ PostfixIntegrate::IsIntegrated() {
if (std::string::npos != Line.find(SnfMilterMainCfSearchString)) { // Check for integration line.
Integrated = true; // Found it.
if (Verbose()) {
std::cout << "found '" << Line << "'...";
}
break;
}

+ 2
- 2
SNFMilterConfig/PostfixIntegrate.hpp Целия файл

@@ -29,12 +29,12 @@ public:
virtual void Unintegrate(FileBackup *SaveFile);
private:
virtual bool MtaIsRunningDetected();
virtual bool ReloadMta();
private:
virtual bool IsIntegrated();
/// Postfix main.cf file path.

+ 7
- 1
SNFMilterConfig/SNFMilterConfig.cpp Целия файл

@@ -214,6 +214,9 @@ SNFMilterConfig::ExecuteCommand() {
case IntegrateWithPostfixCommand:
UnintegrateWithAllExcept("postfix");
Postfix.Integrate(&SaveFile);
break;
case IntegrateWithSendmailCommand:
@@ -222,6 +225,8 @@ SNFMilterConfig::ExecuteCommand() {
case IntegrateWithNoneCommand:
UnintegrateWithAllExcept();
break;
case StartSnifferCommand:
@@ -324,6 +329,7 @@ SNFMilterConfig::SaveFileState() {
}
#if 0
void
SNFMilterConfig::DoIntegrationCommand() {
@@ -361,7 +367,7 @@ SNFMilterConfig::DoIntegrationCommand() {
}
}
#endif
void
SNFMilterConfig::UnintegrateWithAllExcept(std::string Except) {

+ 3
- 1
SNFMilterConfig/SNFMilterConfig.hpp Целия файл

@@ -67,8 +67,10 @@ public:
//
void SaveFileState(void); // OBSOLETE.
#if 0
/// Execute the command to integrate/unintegrate with the MTAs.
void DoIntegrationCommand();
#endif
private:
@@ -78,7 +80,7 @@ private:
/// 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.
void SetupRepairSocketDir();

+ 100
- 0
SNFMilterConfig/SNFMilterConfigTests.txt Целия файл

@@ -369,3 +369,103 @@ gmtime(). In each step, verify that the datestamp is the local date.
output, and that SNFMilterConfig doesn't stop SNFMilter.

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:


Loading…
Отказ
Запис