Browse Source

Implemented PostfixIntegrate::MtaConfigurationIsChrooted().


git-svn-id: https://svn.microneil.com/svn/SNFUtility/trunk@55 aa37657e-1934-4a5f-aa6d-2d8eab27ff7c
master
adeniz 12 years ago
parent
commit
fffa19cbb6

+ 102
- 5
SNFMilterConfig/PostfixIntegrate.cpp View File

if ("OpenBSD" == OperatingSystemType) { if ("OpenBSD" == OperatingSystemType) {
PostfixDefaultIsChrooted = true;
PostfixDefaultIsChrooted = true;
PostfixSocketSpec = "unix:/snf-milter/socket"; PostfixSocketSpec = "unix:/snf-milter/socket";
PostfixMainCfPath = "/etc/postfix/main.cf"; PostfixMainCfPath = "/etc/postfix/main.cf";
PostfixMasterCfPath = "/etc/postfix/master.cf"; PostfixMasterCfPath = "/etc/postfix/master.cf";
} else if ("FreeBSD" == OperatingSystemType) { } else if ("FreeBSD" == OperatingSystemType) {
PostfixDefaultIsChrooted = false;
PostfixDefaultIsChrooted = false;
PostfixSocketSpec = "unix:/var/snf-milter/socket"; PostfixSocketSpec = "unix:/var/snf-milter/socket";
PostfixMainCfPath = "/usr/local/etc/postfix/main.cf"; PostfixMainCfPath = "/usr/local/etc/postfix/main.cf";
PostfixMasterCfPath = "/usr/local/etc/postfix/master.cf"; PostfixMasterCfPath = "/usr/local/etc/postfix/master.cf";
} else if ("Ubuntu" == OperatingSystemType) { } else if ("Ubuntu" == OperatingSystemType) {
PostfixDefaultIsChrooted = true;
PostfixDefaultIsChrooted = true;
PostfixSocketSpec = "unix:/snf-milter/socket"; PostfixSocketSpec = "unix:/snf-milter/socket";
PostfixMainCfPath = "/etc/postfix/main.cf"; PostfixMainCfPath = "/etc/postfix/main.cf";
PostfixMasterCfPath = "/etc/postfix/master.cf"; PostfixMasterCfPath = "/etc/postfix/master.cf";
} else if ("RedHat" == OperatingSystemType) { } else if ("RedHat" == OperatingSystemType) {
PostfixDefaultIsChrooted = false;
PostfixDefaultIsChrooted = false;
PostfixSocketSpec = "unix:/var/snf-milter/socket"; PostfixSocketSpec = "unix:/var/snf-milter/socket";
PostfixMainCfPath = "/etc/postfix/main.cf"; PostfixMainCfPath = "/etc/postfix/main.cf";
PostfixMasterCfPath = "/etc/postfix/master.cf"; PostfixMasterCfPath = "/etc/postfix/master.cf";
} else if ("Suse" == OperatingSystemType) { } else if ("Suse" == OperatingSystemType) {
PostfixDefaultIsChrooted = false;
PostfixDefaultIsChrooted = false;
PostfixSocketSpec = "unix:/var/snf-milter/socket"; PostfixSocketSpec = "unix:/var/snf-milter/socket";
PostfixMainCfPath = "/etc/postfix/main.cf"; PostfixMainCfPath = "/etc/postfix/main.cf";
PostfixMasterCfPath = "/etc/postfix/master.cf"; PostfixMasterCfPath = "/etc/postfix/master.cf";
} }
// 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; std::ifstream Input;
if (Verbose()) { if (Verbose()) {
return Integrated; 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 View File

virtual void Unintegrate(FileBackup *SaveFile); 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: private:
virtual bool MtaIsRunningDetected(); virtual bool MtaIsRunningDetected();
virtual bool IsIntegrated(); virtual bool IsIntegrated();
bool MtaConfigurationIsChrooted();
/// Postfix main.cf file path. /// Postfix main.cf file path.
std::string PostfixMainCfPath; std::string PostfixMainCfPath;
/// Value of smtpd_milters keyword. /// Value of smtpd_milters keyword.
std::string PostfixSocketSpec; std::string PostfixSocketSpec;
/// True if postfix runs chrooted by default.
bool PostfixDefaultIsChrooted;
/// Command to determine whether postfix is running. /// Command to determine whether postfix is running.
std::string MtaIsRunningCommand; std::string MtaIsRunningCommand;
/// Command to reload postfix. /// Command to reload postfix.
std::string ReloadMtaCommand; std::string ReloadMtaCommand;
/// True if postfix runs chrooted by default.
bool PostfixDefaultIsChrooted;
}; };
#endif #endif

+ 15
- 43
SNFMilterConfig/SNFMilterConfig.cpp View File

const string IntegrateWithPostfixKey("-with=postfix"); const string IntegrateWithPostfixKey("-with=postfix");
const string IntegrateWithSendmailKey("-with=sendmail"); 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. ///////////////////////////////////////////////////////////////////////////////// // End of configuration. /////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////
Postfix.Integrate(&SaveFile); 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; break;
case IntegrateWithSendmailCommand: case IntegrateWithSendmailCommand:
Sendmail.Integrate(&SaveFile); Sendmail.Integrate(&SaveFile);
// Update Sniffer configuration with non-chrooted socket spec.
break; break;
case IntegrateWithNoneCommand: case IntegrateWithNoneCommand:
UnintegrateWithAllExcept(); UnintegrateWithAllExcept();
// Update Sniffer configuration with non-chrooted socket spec.
break; break;
case StartSnifferCommand: case StartSnifferCommand:
} }
#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 void
SNFMilterConfig::UnintegrateWithAllExcept(std::string Except) { SNFMilterConfig::UnintegrateWithAllExcept(std::string Except) {

Loading…
Cancel
Save