Quellcode durchsuchen

Implemented PostfixIntegrate::MtaConfigurationIsChrooted().


git-svn-id: https://svn.microneil.com/svn/SNFUtility/trunk@55 aa37657e-1934-4a5f-aa6d-2d8eab27ff7c
master
adeniz vor 12 Jahren
Ursprung
Commit
fffa19cbb6

+ 102
- 5
SNFMilterConfig/PostfixIntegrate.cpp Datei anzeigen

@@ -38,7 +38,7 @@ PostfixIntegrate::SetOperatingSystem(std::string OperatingSystemType) {
if ("OpenBSD" == OperatingSystemType) {
PostfixDefaultIsChrooted = true;
PostfixDefaultIsChrooted = true;
PostfixSocketSpec = "unix:/snf-milter/socket";
PostfixMainCfPath = "/etc/postfix/main.cf";
PostfixMasterCfPath = "/etc/postfix/master.cf";
@@ -46,7 +46,7 @@ PostfixIntegrate::SetOperatingSystem(std::string OperatingSystemType) {
} else if ("FreeBSD" == OperatingSystemType) {
PostfixDefaultIsChrooted = false;
PostfixDefaultIsChrooted = false;
PostfixSocketSpec = "unix:/var/snf-milter/socket";
PostfixMainCfPath = "/usr/local/etc/postfix/main.cf";
PostfixMasterCfPath = "/usr/local/etc/postfix/master.cf";
@@ -54,7 +54,7 @@ PostfixIntegrate::SetOperatingSystem(std::string OperatingSystemType) {
} else if ("Ubuntu" == OperatingSystemType) {
PostfixDefaultIsChrooted = true;
PostfixDefaultIsChrooted = true;
PostfixSocketSpec = "unix:/snf-milter/socket";
PostfixMainCfPath = "/etc/postfix/main.cf";
PostfixMasterCfPath = "/etc/postfix/master.cf";
@@ -62,7 +62,7 @@ PostfixIntegrate::SetOperatingSystem(std::string OperatingSystemType) {
} else if ("RedHat" == OperatingSystemType) {
PostfixDefaultIsChrooted = false;
PostfixDefaultIsChrooted = false;
PostfixSocketSpec = "unix:/var/snf-milter/socket";
PostfixMainCfPath = "/etc/postfix/main.cf";
PostfixMasterCfPath = "/etc/postfix/master.cf";
@@ -70,7 +70,7 @@ PostfixIntegrate::SetOperatingSystem(std::string OperatingSystemType) {
} else if ("Suse" == OperatingSystemType) {
PostfixDefaultIsChrooted = false;
PostfixDefaultIsChrooted = false;
PostfixSocketSpec = "unix:/var/snf-milter/socket";
PostfixMainCfPath = "/etc/postfix/main.cf";
PostfixMasterCfPath = "/etc/postfix/master.cf";
@@ -98,6 +98,28 @@ PostfixIntegrate::Integrate(FileBackup *SaveFile) {
}
// Check whether the chroot configuration is as expected.
bool IsChrooted;
IsChrooted = MtaConfigurationIsChrooted();
std::cout << "IsChrooted: " << IsChrooted << "\n";
if (IsChrooted != PostfixDefaultIsChrooted) {
std::string Temp;
Temp = "Error--postfix must be configured to run ";
Temp += (PostfixDefaultIsChrooted ? "" : "not ");
Temp += "chrooted, which is the default for this operating system. ";
Temp += "postfix was detected to be configured to run ";
Temp += (IsChrooted ? "" : "not ");
Temp += "chrooted.";
Temp += strerror(errno);
throw std::runtime_error(Temp);
}
std::ifstream Input;
if (Verbose()) {
@@ -510,3 +532,78 @@ PostfixIntegrate::IsIntegrated() {
return Integrated;
}
bool
PostfixIntegrate::DefaultIsChrooted() {
return PostfixDefaultIsChrooted;
}
bool
PostfixIntegrate::MtaConfigurationIsChrooted() {
std::string File;
std::ifstream Input;
File = PostfixMasterCfPath;
Input.open(File.c_str());
if (!Input) {
std::string Temp;
Temp = "Error opening postfix configuration file " + File;
Temp += " for reading: ";
Temp += strerror(errno);
throw std::runtime_error(Temp);
}
std::string Line;
bool ConfigurationIsChrooted = false;
while (getline(Input, Line)) {
if (CheckForString(Line, "smtp")) { // Check for smtp line.
std::istringstream Buffer(Line); // Parse buffer line.
std::string Token[8];
for (unsigned int iToken = 0; iToken < 8; iToken++) {
Buffer >> Token[iToken];
}
if ( ("y" == Token[4]) || ("-" == Token[4]) ) {
Input.close();
if (Input.bad()) {
std::string Temp;
Temp = "Error closing the postfix configuration file " + File;
Temp += " after reading: ";
Temp += strerror(errno);
throw std::runtime_error(Temp);
}
return true;
}
}
}
Input.close();
if (Input.bad()) {
std::string Temp;
Temp = "Error closing the rulebase download script file " + File;
Temp += " after reading: ";
Temp += strerror(errno);
throw std::runtime_error(Temp);
}
return false;
}

+ 12
- 3
SNFMilterConfig/PostfixIntegrate.hpp Datei anzeigen

@@ -29,6 +29,13 @@ public:
virtual void Unintegrate(FileBackup *SaveFile);
// Return the default chroot configuration of Postfix.
//
// \returns true if the default configuration is for postfix to
// run chrooted, false otherwise.
//
bool DefaultIsChrooted();
private:
virtual bool MtaIsRunningDetected();
@@ -37,6 +44,8 @@ private:
virtual bool IsIntegrated();
bool MtaConfigurationIsChrooted();
/// Postfix main.cf file path.
std::string PostfixMainCfPath;
@@ -46,15 +55,15 @@ private:
/// Value of smtpd_milters keyword.
std::string PostfixSocketSpec;
/// True if postfix runs chrooted by default.
bool PostfixDefaultIsChrooted;
/// Command to determine whether postfix is running.
std::string MtaIsRunningCommand;
/// Command to reload postfix.
std::string ReloadMtaCommand;
/// True if postfix runs chrooted by default.
bool PostfixDefaultIsChrooted;
};
#endif

+ 15
- 43
SNFMilterConfig/SNFMilterConfig.cpp Datei anzeigen

@@ -68,10 +68,6 @@ const string IntegrateWithNoneKey("-with=none");
const string IntegrateWithPostfixKey("-with=postfix");
const string IntegrateWithSendmailKey("-with=sendmail");
const string SnfMilterMainCfSearchString("Added by SNFMilterConfig");
const string SnfMilterMainCfIntegrationString("smtpd_milters = unix:/var/snf-milter/socket $smtpd_milters # Added by SNFMilterConfig");
//////////////////////////////////////////////////////////////////////////////////////////////////////////
// End of configuration. /////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -244,6 +240,17 @@ SNFMilterConfig::ExecuteCommand() {
Postfix.Integrate(&SaveFile);
// Update Sniffer file.
if (Postfix.DefaultIsChrooted()) {
// Update Sniffer configuration with chrooted socket spec.
} else {
// Update Sniffer configuration with non-chrooted socket spec.
}
break;
case IntegrateWithSendmailCommand:
@@ -252,12 +259,16 @@ SNFMilterConfig::ExecuteCommand() {
Sendmail.Integrate(&SaveFile);
// Update Sniffer configuration with non-chrooted socket spec.
break;
case IntegrateWithNoneCommand:
UnintegrateWithAllExcept();
// Update Sniffer configuration with non-chrooted socket spec.
break;
case StartSnifferCommand:
@@ -352,45 +363,6 @@ SNFMilterConfig::SaveFileState() {
}
#if 0
void
SNFMilterConfig::DoIntegrationCommand() {
switch (Command) {
case NoCommand:
break;
case IntegrateWithNoneCommand:
UnintegrateWithAllExcept();
break;
case IntegrateWithPostfixCommand:
UnintegrateWithAllExcept("postfix");
Postfix.Integrate(&SaveFile);
break;
case IntegrateWithSendmailCommand:
UnintegrateWithAllExcept("sendmail");
Sendmail.Integrate(&SaveFile);
break;
default:
{
ostringstream Temp;
Temp << "Internal error in SNFMilterConfig::DoIntegrationCommand: Invalid value of command: "
<< Command;
throw runtime_error(Temp.str());
}
}
}
#endif
void
SNFMilterConfig::UnintegrateWithAllExcept(std::string Except) {

Laden…
Abbrechen
Speichern