|
|
|
|
|
|
|
|
|
|
|
|
|
|
const string SNFMilterConfig::ApplicationName("SNFMilter");
|
|
|
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 IntegrateWithNoneKey("-with=none");
|
|
|
const string IntegrateWithPostfixKey("-with=postfix");
|
|
|
const string IntegrateWithPostfixKey("-with=postfix");
|
|
|
const string IntegrateWithSendmailKey("-with=sendmail");
|
|
|
const string IntegrateWithSendmailKey("-with=sendmail");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case IntegrateWithPostfixCommand:
|
|
|
case IntegrateWithPostfixCommand:
|
|
|
|
|
|
|
|
|
|
|
|
Postfix.Integrate(&SaveFile);
|
|
|
|
|
|
|
|
|
UnintegrateWithAllExcept("postfix");
|
|
|
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 {
|
|
|
} else {
|
|
|
|
|
|
|
|
|
// Update Sniffer configuration with non-chrooted socket spec.
|
|
|
|
|
|
|
|
|
SetSocketFileName(DefaultSocketFileName); // Update Sniffer configuration with non-chrooted socket spec.
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case IntegrateWithSendmailCommand:
|
|
|
case IntegrateWithSendmailCommand:
|
|
|
|
|
|
|
|
|
UnintegrateWithAllExcept("sendmail");
|
|
|
|
|
|
|
|
|
|
|
|
Sendmail.Integrate(&SaveFile);
|
|
|
Sendmail.Integrate(&SaveFile);
|
|
|
|
|
|
|
|
|
|
|
|
UnintegrateWithAllExcept("sendmail");
|
|
|
|
|
|
|
|
|
// Update Sniffer configuration with non-chrooted socket spec.
|
|
|
// Update Sniffer configuration with non-chrooted socket spec.
|
|
|
|
|
|
SetSocketFileName(DefaultSocketFileName);
|
|
|
|
|
|
|
|
|
break;
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UnintegrateWithAllExcept();
|
|
|
UnintegrateWithAllExcept();
|
|
|
|
|
|
|
|
|
// Update Sniffer configuration with non-chrooted socket spec.
|
|
|
|
|
|
|
|
|
SetSocketFileName(DefaultSocketFileName); // Update Sniffer configuration with non-chrooted socket spec.
|
|
|
|
|
|
|
|
|
break;
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
void
|
|
|
SNFMilterConfig::LoadSocketInfo() {
|
|
|
SNFMilterConfig::LoadSocketInfo() {
|
|
|
|
|
|
|