Selaa lähdekoodia

Implemented updating of SNFMilter.xml, tested -with functionality on Ubuntu.


git-svn-id: https://svn.microneil.com/svn/SNFUtility/trunk@57 aa37657e-1934-4a5f-aa6d-2d8eab27ff7c
master
adeniz 11 vuotta sitten
vanhempi
commit
0f5b91a89a

+ 2
- 1
Common/Utility.cpp Näytä tiedosto

@@ -347,7 +347,8 @@ Utility::ReplaceXmlAttribute(std::string *Content, std::string ElementName, std:
PrevCommentEnd = Content->rfind("-->", ElementContentBegin);
if ( (PrevCommentBegin == std::string::npos) ||
(PrevCommentEnd < ElementContentBegin) ) {
( (PrevCommentEnd < ElementContentBegin) &&
(PrevCommentEnd > PrevCommentBegin) ) ) {
FoundElement = true;
break; // Not in comment; continue processing.

+ 4
- 2
CommonTests/TestUtility.cpp Näytä tiedosto

@@ -209,7 +209,8 @@ TestReplaceXmlAttribute() {
}
// Element in comment.
Content = "<!-- License file created by SNFIdentity\n"
Content = "<!-- License file created by SNFIdentity -->\n"
"<!-- This is a comment\n"
"<TestElement TestAttribute = \"testmode\" authentication='setuptestingonly'/>\n"
"-->\n"
"<snf>\n"
@@ -217,7 +218,8 @@ TestReplaceXmlAttribute() {
"</snf>\n";
OriginalContent = Content;
ExpectedContent = "<!-- License file created by SNFIdentity\n"
ExpectedContent = "<!-- License file created by SNFIdentity -->\n"
"<!-- This is a comment\n"
"<TestElement TestAttribute = \"testmode\" authentication='setuptestingonly'/>\n"
"-->\n"
"<snf>\n"

+ 113
- 8
SNFMilterConfig/SNFMilterConfig.cpp Näytä tiedosto

@@ -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() {

+ 9
- 0
SNFMilterConfig/SNFMilterConfig.hpp Näytä tiedosto

@@ -70,6 +70,9 @@ public:
private:
/// Set the socket name in the configuration file.
void SetSocketFileName(std::string NewSocketFileName);
/// Load the socket info (file name) from the <platform> section
/// of the loaded config file.
void LoadSocketInfo();
@@ -111,6 +114,12 @@ private:
static const std::string ApplicationName; ///< Application name.
/// Default name of socket file.
static const std::string DefaultSocketFileName;
/// Name of socket file when postfix is chrooted.
static const std::string DefaultPostfixIsChrootedSocketFileName;
std::string SocketFileName;
};

Loading…
Peruuta
Tallenna