|
|
@@ -64,6 +64,9 @@ const std::string InstallFile("INSTALL"); |
|
|
|
|
|
|
|
const string SNFMilterConfig::ApplicationName("SNFMilter");
|
|
|
|
|
|
|
|
const std::string SNFMilterConfig::DefaultSocketFileName("/var/snf-milter/socket");
|
|
|
|
const std::string SNFMilterConfig::DefaultPostfixIsChrootedSocketFileName("/var/spool/postfix/snf-milter/socket");
|
|
|
|
|
|
|
|
const string IntegrateWithNoneKey("-with=none");
|
|
|
|
const string IntegrateWithPostfixKey("-with=postfix");
|
|
|
|
const string IntegrateWithSendmailKey("-with=sendmail");
|
|
|
@@ -236,18 +239,21 @@ SNFMilterConfig::ExecuteCommand() { |
|
|
|
|
|
|
|
case IntegrateWithPostfixCommand:
|
|
|
|
|
|
|
|
Postfix.Integrate(&SaveFile);
|
|
|
|
|
|
|
|
UnintegrateWithAllExcept("postfix");
|
|
|
|
|
|
|
|
Postfix.Integrate(&SaveFile);
|
|
|
|
if (Postfix.DefaultIsChrooted()) { // Update Sniffer file.
|
|
|
|
|
|
|
|
// Update Sniffer file.
|
|
|
|
if (Postfix.DefaultIsChrooted()) {
|
|
|
|
SetSocketFileName(DefaultPostfixIsChrootedSocketFileName); // Update Sniffer configuration with chrooted socket spec.
|
|
|
|
|
|
|
|
// Update Sniffer configuration with chrooted socket spec.
|
|
|
|
LoadConfig(); // Create the socket in the chrooted location.
|
|
|
|
LoadSocketInfo();
|
|
|
|
SetupRepairSocketDir();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Update Sniffer configuration with non-chrooted socket spec.
|
|
|
|
SetSocketFileName(DefaultSocketFileName); // Update Sniffer configuration with non-chrooted socket spec.
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
@@ -255,11 +261,12 @@ SNFMilterConfig::ExecuteCommand() { |
|
|
|
|
|
|
|
case IntegrateWithSendmailCommand:
|
|
|
|
|
|
|
|
UnintegrateWithAllExcept("sendmail");
|
|
|
|
|
|
|
|
Sendmail.Integrate(&SaveFile);
|
|
|
|
|
|
|
|
UnintegrateWithAllExcept("sendmail");
|
|
|
|
|
|
|
|
// Update Sniffer configuration with non-chrooted socket spec.
|
|
|
|
SetSocketFileName(DefaultSocketFileName);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
@@ -267,7 +274,7 @@ SNFMilterConfig::ExecuteCommand() { |
|
|
|
|
|
|
|
UnintegrateWithAllExcept();
|
|
|
|
|
|
|
|
// Update Sniffer configuration with non-chrooted socket spec.
|
|
|
|
SetSocketFileName(DefaultSocketFileName); // Update Sniffer configuration with non-chrooted socket spec.
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
@@ -293,6 +300,104 @@ SNFMilterConfig::ExecuteCommand() { |
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SNFMilterConfig::SetSocketFileName(std::string NewSocketFileName) {
|
|
|
|
|
|
|
|
std::string File = GetConfigFileName();
|
|
|
|
|
|
|
|
if (Verbose()) {
|
|
|
|
|
|
|
|
cout << "Setting socket to '" << NewSocketFileName << "' in '"
|
|
|
|
<< File << "'...";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Explain()) {
|
|
|
|
|
|
|
|
std::ifstream Input;
|
|
|
|
|
|
|
|
Input.open(File.c_str());
|
|
|
|
if (!Input) {
|
|
|
|
std::string Temp;
|
|
|
|
|
|
|
|
Temp = "Error opening the configuration file " + File;
|
|
|
|
Temp += " to read from: ";
|
|
|
|
Temp += strerror(errno);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostringstream ContentStream;
|
|
|
|
|
|
|
|
ContentStream << Input.rdbuf();
|
|
|
|
|
|
|
|
Input.close();
|
|
|
|
if (!Input) {
|
|
|
|
std::string Temp;
|
|
|
|
|
|
|
|
Temp = "Error closing the configuration file " + File;
|
|
|
|
Temp += ": ";
|
|
|
|
Temp += strerror(errno);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ContentStream.bad() || ContentStream.fail()) {
|
|
|
|
std::string Temp;
|
|
|
|
|
|
|
|
Temp = "Error reading the configuration file " + File;
|
|
|
|
Temp += ": ";
|
|
|
|
Temp += strerror(errno);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Content;
|
|
|
|
|
|
|
|
Content = ContentStream.str();
|
|
|
|
|
|
|
|
std::string ElementName = "socket";
|
|
|
|
std::string AttributeName = "path";
|
|
|
|
|
|
|
|
ReplaceXmlAttribute(&Content, ElementName, AttributeName, NewSocketFileName);
|
|
|
|
|
|
|
|
|
|
|
|
std::ofstream Output;
|
|
|
|
|
|
|
|
Output.open(File.c_str(), std::ios::trunc);
|
|
|
|
if (!Output) {
|
|
|
|
std::string Temp;
|
|
|
|
|
|
|
|
Temp = "Error opening the configuration file " + File;
|
|
|
|
Temp += " to write to: ";
|
|
|
|
Temp += strerror(errno);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
Output << Content;
|
|
|
|
|
|
|
|
if (Output.bad() || Output.fail()) {
|
|
|
|
std::string Temp;
|
|
|
|
|
|
|
|
Temp = "Error writing the configuration file " + File;
|
|
|
|
Temp += ": ";
|
|
|
|
Temp += strerror(errno);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
Output.close();
|
|
|
|
if (!Output) {
|
|
|
|
std::string Temp;
|
|
|
|
|
|
|
|
Temp = "Error closing the configuration file " + File;
|
|
|
|
Temp += ": ";
|
|
|
|
Temp += strerror(errno);
|
|
|
|
throw std::runtime_error(Temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
OutputVerboseEnd();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SNFMilterConfig::LoadSocketInfo() {
|
|
|
|
|