Browse Source

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 12 years ago
parent
commit
0f5b91a89a

+ 2
- 1
Common/Utility.cpp View File

PrevCommentEnd = Content->rfind("-->", ElementContentBegin); PrevCommentEnd = Content->rfind("-->", ElementContentBegin);
if ( (PrevCommentBegin == std::string::npos) || if ( (PrevCommentBegin == std::string::npos) ||
(PrevCommentEnd < ElementContentBegin) ) {
( (PrevCommentEnd < ElementContentBegin) &&
(PrevCommentEnd > PrevCommentBegin) ) ) {
FoundElement = true; FoundElement = true;
break; // Not in comment; continue processing. break; // Not in comment; continue processing.

+ 4
- 2
CommonTests/TestUtility.cpp View File

} }
// Element in comment. // 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" "<TestElement TestAttribute = \"testmode\" authentication='setuptestingonly'/>\n"
"-->\n" "-->\n"
"<snf>\n" "<snf>\n"
"</snf>\n"; "</snf>\n";
OriginalContent = Content; 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" "<TestElement TestAttribute = \"testmode\" authentication='setuptestingonly'/>\n"
"-->\n" "-->\n"
"<snf>\n" "<snf>\n"

+ 113
- 8
SNFMilterConfig/SNFMilterConfig.cpp View File

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

+ 9
- 0
SNFMilterConfig/SNFMilterConfig.hpp View File

private: private:
/// Set the socket name in the configuration file.
void SetSocketFileName(std::string NewSocketFileName);
/// Load the socket info (file name) from the <platform> section /// Load the socket info (file name) from the <platform> section
/// of the loaded config file. /// of the loaded config file.
void LoadSocketInfo(); void LoadSocketInfo();
static const std::string ApplicationName; ///< Application name. 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; std::string SocketFileName;
}; };

Loading…
Cancel
Save