Sfoglia il codice sorgente

Implemented checking via XCI, status.second, and status.minute the

Sniffer running state.

Updated StartSniffer to check the running state.

Implemented StopSniffer.


git-svn-id: https://svn.microneil.com/svn/SNFUtility/trunk@19 aa37657e-1934-4a5f-aa6d-2d8eab27ff7c
master
adeniz 12 anni fa
parent
commit
15ec1d8c69

+ 68
- 0
Common/Utility.cpp Vedi File

@@ -76,6 +76,60 @@ Utility::FileExists(const std::string File) {
}
std::string
Utility::ReadLastPartOfFile(std::string File, long Size) {
if (!FileExists(File)) {
return "";
}
std::ifstream Input;
Input.open(File.c_str());
if (!Input) {
std::string Temp;
Temp = "Error opening the file " + File;
Temp += " to read from: ";
Temp += strerror(errno);
throw std::runtime_error(Temp);
}
Input.seekg(Size, ios_base::end);
std::ostringstream Output;
if (!Input.eof()) { // Copy if there are characters.
// Copying an empty file causes
Output << Input.rdbuf(); // failbit to be set.
}
if (Output.bad() || Output.fail()) {
std::string Temp;
Temp = "Error " + File;
Temp += ": ";
Temp += strerror(errno);
throw std::runtime_error(Temp);
}
Input.close();
if (!Input) {
std::string Temp;
Temp = "Error closing the file " + File;
Temp += " after reading: ";
Temp += strerror(errno);
throw std::runtime_error(Temp);
}
return Output.str();
}
void
Utility::Copy(std::string From, std::string To) {
@@ -441,6 +495,20 @@ Utility::Trim(std::string String) {
}
void
Utility::SetDebug(bool Mode) {
DebugRequested = Mode;
}
bool
Utility::Debug() {
return DebugRequested;
}
void
Utility::SetVerbose(bool Mode) {

+ 26
- 2
Common/Utility.hpp Vedi File

@@ -27,10 +27,22 @@ public:
/// Check whether a file exists.
//
// \param[in] File is the name of the file.
//
// \returns true if the file exists, false otherwise.
//
bool FileExists(std::string File);
/// Read last part of a file.
//
// \param[in] File is the name of the file.
//
// \param[in] Size is the number of bytes from the end to start reading.
//
// \returns contents of the end of the file if the file exists, "" otherwise.
//
std::string ReadLastPartOfFile(std::string File, long Size);
/// Copy a file.
//
// \param[in] From is the name of the source file.
@@ -106,6 +118,18 @@ public:
// \returns String with the leading and trailing whitespace removed.
static std::string Trim(std::string String);
/// Store the Debug mode.
//
// \param[in] Mode stores the Debug mode.
//
void SetDebug(bool Mode);
/// Provide debug output?
//
// \returns true if the application is to provide debug output.
//
bool Debug();
/// Store the Verbose mode.
//
// \param[in] Mode stores the Verbose mode.
@@ -149,10 +173,10 @@ public:
/// Directory separator.
static const std::string DirectorySeparator;
/// Trim whitespace from a string.
private:
bool DebugRequested; ///< User requested debug output.
bool VerboseRequested; ///< User requested verbose processing.
bool ExplainRequested; ///< User requested verbose processing but without actually executing the commands.

+ 411
- 33
Common/UtilityConfig.cpp Vedi File

@@ -187,7 +187,7 @@ UtilityConfig::CheckAndSetConfigFileName(const std::string DefaultFile[], int Nu
Temp << "Internal error: NumDefaultFiles <= 0 at " << __FILE__ << ":" << __LINE__;
throw runtime_error(Temp.str());
throw std::runtime_error(Temp.str());
}
@@ -204,7 +204,7 @@ UtilityConfig::CheckAndSetConfigFileName(const std::string DefaultFile[], int Nu
}
throw runtime_error(Temp);
throw std::runtime_error(Temp);
}
@@ -257,7 +257,7 @@ UtilityConfig::LoadConfig() {
Temp = "Error reading configuration file " + GetConfigFileName();
Temp += ".";
throw runtime_error(Temp);
throw std::runtime_error(Temp);
}
@@ -276,7 +276,7 @@ UtilityConfig::LoadConfig() {
Temp += "\n Log path: " + CFGData.paths_log_path;
Temp += "\n Update script: " + CFGData.update_script_call;
Temp += "\n Identity file: " + CFGData.node_identity;
throw runtime_error(Temp);
throw std::runtime_error(Temp);
}
@@ -324,6 +324,36 @@ UtilityConfig::GetLogPath(void) {
}
std::string
UtilityConfig::GetStatusSecondLogFileName(void) {
std::string FileName = CFGData.paths_log_path + CFGData.node_licenseid + ".status.second.log";
if (CFGData.Scan_XML_Mode) {
FileName += ".xml";
}
return FileName;
}
std::string
UtilityConfig::GetStatusMinuteLogFileName(void) {
std::string FileName = CFGData.paths_log_path + CFGData.node_licenseid + ".status.minute.log";
if (CFGData.Scan_XML_Mode) {
FileName += ".xml";
}
return FileName;
}
string
UtilityConfig::GetIdentityFileName(void) {
@@ -404,7 +434,7 @@ UtilityConfig::LoadInfo(){
Temp << "Internal error in UtilityConfig::LoadInfo: Invalid value of OperatingSystemType: "
<< OperatingSystemType;
throw runtime_error(Temp.str());
throw std::runtime_error(Temp.str());
}
@@ -489,6 +519,293 @@ UtilityConfig::SetupRepairLogDir() {
}
UtilityConfig::StatusCheckMethod
UtilityConfig::GetPreferredStatusCheckMethod(void) {
if (CFGData.XCI_OnOff) {
return StatusCheckXci;
}
if (CFGData.Status_SecondReport_Log_OnOff) {
return StatusCheckSecond;
}
if (CFGData.Status_MinuteReport_Log_OnOff) {
return StatusCheckMinute;
}
return StatusCheckNotAvailable;
}
std::string
UtilityConfig::GetSnifferStatusReport() {
std::string StatusReport;
switch (GetPreferredStatusCheckMethod()) {
case StatusCheckXci:
StatusReport = GetReportViaXci();
break;
case StatusCheckSecond:
StatusReport = GetReportViaLogFile(GetStatusSecondLogFileName(), 5000);
break;
case StatusCheckMinute:
std::cout << "Getting Sniffer status from status.minute log file (this takes about 70 s)...";
std::cout.flush();
StatusReport = GetReportViaLogFile(GetStatusMinuteLogFileName(), 70 * 1000);
std::cout << "done." << std::endl;
break;
default:
{
std::string Temp;
Temp = "No method for determining Sniffer status is available. ";
Temp += "Tried XCI, status.second logging, and status.minute logging.";
throw std::runtime_error(Temp);
}
}
return StatusReport;
}
std::string
UtilityConfig::GetReportViaXci() {
if (Verbose()) {
cout << "Getting Sniffer status report via XCI...";
}
bool ConnectSuccess = false;
std::string ResultString;
const std::string RequestString("<snf><xci><report><request><status class='second'/></request></report></xci></snf>");
// Code copied from SNFClient.
// Max time in this loop should be (100*50ms) = 5 seconds per try times
// 10 tries = 50 seconds, plus (9*500ms) = 4.5 secs for re-tries. ~ 55 secs.
const int ResultBufferSize = 4096;
char ResultBuffer[ResultBufferSize+1]; // Make an oversize buffer for the answer.
memset(ResultBuffer, 0, sizeof(ResultBuffer)); // Set the entire thing to nulls.
const int Tries = 20; // How many times to try this.
Sleeper SleepAfterAttempt(100); // How long to sleep between attempts.
const int OpenTries = 90; // How many tries at opening.
Sleeper WaitForOpen(10); // How long to wait for an open cycle.
const int ReadTries = 900; // How many tries at reading.
Sleeper SleepBeforeReading(10); // How long to pause before reading.
/*
** 20 * 100ms = 2 seconds for all tries.
** 90 * 10ms = 900ms for a failed connection.
** 900 * 10ms = 9 seconds for a failed read.
**
** Approximate wait for can't connect = 2.0 + (20 * 0.9) = ~ 20.0 seconds.
** Maximum impossible wait = 2.0 + (0.9 * 20) + (9.0 * 20) = 200.0 seconds.
*/
for(int tryagain = Tries; (0<tryagain) && (!ConnectSuccess); tryagain--) { // Try a few times to get this done.
try {
ResultString = ""; // Clear our result string.
TCPHost SNFServer(9001); // Create connection to server.
SNFServer.makeNonBlocking(); // Make it non-blocking.
for(int tries = OpenTries; 0 < tries; tries--) { // Wait & Watch for a good connection.
try { SNFServer.open(); } catch(...) {} // Try opening the connection.
if(SNFServer.isOpen()) break; // When successful, let's Go!
else WaitForOpen(); // When not successful, pause.
}
if(SNFServer.isOpen()) { // If we have a good connection:
SNFServer.transmit(
RequestString.c_str(), RequestString.length()); // Send the request.
for(int tries = ReadTries; 0 < tries; tries--) { // Try to read the result a few times.
SleepBeforeReading(); // Provide some time for each try.
memset(ResultBuffer, 0, sizeof(ResultBuffer)); // Clear the buffer.
SNFServer.receive(ResultBuffer, ResultBufferSize); // Receive the answer.
ResultString.append(ResultBuffer);
if(string::npos ==
ResultString.rfind("</snf>",ResultString.length())) { // If we don't have the end yet.
continue; // Try again.
} else { // If we got to end of line
ConnectSuccess = true; // Success!
break; // We're done.
}
}
SNFServer.close(); // No need for our connection after that.
}
} catch(...) { } // Ignore errors for now.
if(!ConnectSuccess) SleepAfterAttempt(); // Pause for a moment before trying again..
}
if(!ConnectSuccess) { // If no connection then Sniffer isn't running.
if (Verbose()) {
cout << "no response...";
}
return "";
}
// At this point we should have a usable result.
if(Debug()) { cout << ResultString << endl; } // In debug, show the result string.
snf_xci Reader(ResultString); // Interpret the data and check for
if(Reader.bad()) { // a proper read. If it was bad...
std::string Temp;
Temp = "Bad result from Sniffer:\n" + ResultString;
throw std::runtime_error(Temp);
}
if(0 < Reader.xci_error_message.length()) { // If the result was a general error...
std::string Temp;
Temp = "XCI error when determing status of Sniffer: " + Reader.xci_error_message;
throw std::runtime_error(Temp);
}
OutputVerboseEnd();
return Reader.report_response;
}
std::string
UtilityConfig::GetReportViaLogFile(std::string LogFileName, int SleepTime_msec) {
if (Verbose()) {
cout << "Getting Sniffer status report via log file " << LogFileName << "...";
}
std::string InitialContents;
InitialContents = ReadLastPartOfFile(LogFileName, LogFileReportSize); // Read last part of log file.
Sleeper Sleep(SleepTime_msec); // Wait 5 s.
Sleep();
std::string FinalContents;
FinalContents = ReadLastPartOfFile(LogFileName, LogFileReportSize); // Read again.
if (InitialContents == FinalContents) { // If unchanged...
if (Verbose()) {
cout << "report unchanged...";
}
return ""; // ...there is no report.
}
OutputVerboseEnd();
return FinalContents;
}
void
UtilityConfig::CheckSnifferStatusReport(std::string StatusReport, std::string ApplicationName) {
if (Verbose()) {
cout << "Checking Sniffer status report...";
}
ConfigurationElement MyCFGReader("stats"); // Object to parse the XML.
ConfigurationData MyCFGData(StatusReport); // Object that contains the XML.
std::string PlatformContent;
MyCFGReader
.Element("version")
.Element("platform", PlatformContent, "")
.End("platform")
.End("version")
.End("stats");
MyCFGReader.initialize();
if (!MyCFGReader.interpret(MyCFGData)) {
std::ostringstream Temp;
Temp << "Error interpreting the Sniffer status report:\n" << StatusReport;
throw std::runtime_error(Temp.str());
}
if (std::string::npos == PlatformContent.find(ApplicationName)) { // Verify correct application.
std::ostringstream Temp;
Temp << "Error--The expected Sniffer application (" << ApplicationName
<< ") isn't running. The running application determined from the status report is "
<< PlatformContent;
throw std::runtime_error(Temp.str());
}
OutputVerboseEnd();
}
UtilityConfig::SnifferRunningStateEnum
UtilityConfig::GetRunningState(std::string ApplicationName) {
if (Verbose()) {
cout << "Checking whether " << ApplicationName << " is running...";
}
std::string StatusReport = GetSnifferStatusReport();
if (StatusReport.length() == 0) {
return SnifferIsStopped;
}
CheckSnifferStatusReport(StatusReport, ApplicationName);
OutputVerboseEnd();
return SnifferIsRunning;
}
void
UtilityConfig::SetupRepair(const std::string SampleIdentityFile) {
@@ -519,7 +836,7 @@ UtilityConfig::UpdateRulebaseScriptCredentials() {
Temp = "Error opening rulebase download script file " + File;
Temp += " for reading: ";
Temp += strerror(errno);
throw runtime_error(Temp);
throw std::runtime_error(Temp);
}
string Content;
@@ -536,7 +853,7 @@ UtilityConfig::UpdateRulebaseScriptCredentials() {
Temp = "Rulebase sownload script file " + File;
Temp += " has the wrong format: Found two lines beginning with " + LicenseSearchString;
throw runtime_error(Temp);
throw std::runtime_error(Temp);
}
@@ -558,7 +875,7 @@ UtilityConfig::UpdateRulebaseScriptCredentials() {
Temp = "Rulebase download script file " + File;
Temp += " has the wrong format: Found two lines beginning with " + AuthSearchString;
throw runtime_error(Temp);
throw std::runtime_error(Temp);
}
if (Verbose()) {
@@ -583,7 +900,7 @@ UtilityConfig::UpdateRulebaseScriptCredentials() {
Temp += " has the wrong format: Missing required line beginning with '" + LicenseSearchString;
Temp += "' or '" + AuthSearchString;
Temp += "'";
throw runtime_error(Temp);
throw std::runtime_error(Temp);
}
if (!Input.eof()) { // Should be at end-of-file.
@@ -592,7 +909,7 @@ UtilityConfig::UpdateRulebaseScriptCredentials() {
Temp = "Error reading the rulebase download script file " + File;
Temp += ": ";
Temp += strerror(errno);
throw runtime_error(Temp);
throw std::runtime_error(Temp);
}
Input.close();
@@ -602,7 +919,7 @@ UtilityConfig::UpdateRulebaseScriptCredentials() {
Temp = "Error closing the rulebase download script file " + File;
Temp += " after reading: ";
Temp += strerror(errno);
throw runtime_error(Temp);
throw std::runtime_error(Temp);
}
@@ -619,7 +936,7 @@ UtilityConfig::UpdateRulebaseScriptCredentials() {
Temp = "Error opening rulebase download script file " + File;
Temp += " for writing: ";
Temp += strerror(errno);
throw runtime_error(Temp);
throw std::runtime_error(Temp);
}
Output << Content;
@@ -629,7 +946,7 @@ UtilityConfig::UpdateRulebaseScriptCredentials() {
Temp = "Error writing the rulebase download script file " + File;
Temp += ": ";
Temp += strerror(errno);
throw runtime_error(Temp);
throw std::runtime_error(Temp);
}
Output.close();
@@ -639,7 +956,7 @@ UtilityConfig::UpdateRulebaseScriptCredentials() {
Temp = "Error closing the rulebase download script file " + File;
Temp += " after writing: ";
Temp += strerror(errno);
throw runtime_error(Temp);
throw std::runtime_error(Temp);
}
}
@@ -700,9 +1017,8 @@ UtilityConfig::DownloadRulebase() {
std::ostringstream Temp;
Temp << "Unable to remove rulebase download status file " << StatusFile
<< ": " << strerror(errno) << "\n";
throw runtime_error(Temp.str());
<< ": " << strerror(errno);
throw std::runtime_error(Temp.str());
}
@@ -713,7 +1029,7 @@ UtilityConfig::DownloadRulebase() {
Temp = "Error running the command '" + Command;
Temp += "'.";
throw runtime_error(Temp);
throw std::runtime_error(Temp);
}
@@ -726,7 +1042,7 @@ UtilityConfig::DownloadRulebase() {
Temp = "Error opening rulebase download scriptstatus file " + StatusFile;
Temp += ": ";
Temp += strerror(errno);
throw runtime_error(Temp);
throw std::runtime_error(Temp);
}
string Line;
@@ -744,7 +1060,7 @@ UtilityConfig::DownloadRulebase() {
string Temp;
Temp = "Error downloading the rulebase. Rulebase download status:\n\n" + Content;
throw runtime_error(Temp);
throw std::runtime_error(Temp);
}
@@ -774,7 +1090,7 @@ UtilityConfig::UpdateIdentityFile() {
Temp = "Error opening identity file " + File;
Temp += " for reading: ";
Temp += strerror(errno);
throw runtime_error(Temp);
throw std::runtime_error(Temp);
}
ostringstream InputContents;
@@ -799,7 +1115,7 @@ UtilityConfig::UpdateIdentityFile() {
Temp = "Error closing the identity file " + File;
Temp += " after reading: ";
Temp += strerror(errno);
throw runtime_error(Temp);
throw std::runtime_error(Temp);
}
string Content = InputContents.str();
@@ -815,7 +1131,7 @@ UtilityConfig::UpdateIdentityFile() {
Temp = "Error updating credentials for identity file " + File;
Temp += ": ";
Temp += e.what();
throw runtime_error(Temp);
throw std::runtime_error(Temp);
}
@@ -832,7 +1148,7 @@ UtilityConfig::UpdateIdentityFile() {
Temp = "Error opening identity file " + File;
Temp += " for writing: ";
Temp += strerror(errno);
throw runtime_error(Temp);
throw std::runtime_error(Temp);
}
Output << Content;
@@ -842,7 +1158,7 @@ UtilityConfig::UpdateIdentityFile() {
Temp = "Error writing the identity file " + File;
Temp += ": ";
Temp += strerror(errno);
throw runtime_error(Temp);
throw std::runtime_error(Temp);
}
Output.close();
@@ -852,7 +1168,7 @@ UtilityConfig::UpdateIdentityFile() {
Temp = "Error closing the identity file " + File;
Temp += " after writing: ";
Temp += strerror(errno);
throw runtime_error(Temp);
throw std::runtime_error(Temp);
}
}
@@ -886,7 +1202,7 @@ UtilityConfig::UpdateIdentityFileOld() {
Temp = "Error opening identity file " + File;
Temp += ": ";
Temp += strerror(errno);
throw runtime_error(Temp);
throw std::runtime_error(Temp);
}
Output << "<!-- License file created by SNFIdentity-->\n"
@@ -900,7 +1216,7 @@ UtilityConfig::UpdateIdentityFileOld() {
Temp = "Error writing identity file " + File;
Temp += ": ";
Temp += strerror(errno);
throw runtime_error(Temp);
throw std::runtime_error(Temp);
}
Output.close();
@@ -910,7 +1226,7 @@ UtilityConfig::UpdateIdentityFileOld() {
Temp = "Error closing identity file " + File;
Temp += ": ";
Temp += strerror(errno);
throw runtime_error(Temp);
throw std::runtime_error(Temp);
}
}
@@ -925,12 +1241,11 @@ UtilityConfig::UpdateIdentityFileOld() {
#endif
void
UtilityConfig::StartSniffer(std::string Script) {
UtilityConfig::StartSniffer(std::string ScriptAndArgs, std::string ApplicationName) {
std::string Command;
Command = SnifferStartScriptDir + Script;
Command += " start";
Command = SnifferStartScriptDir + ScriptAndArgs;
if (Verbose()) {
@@ -938,6 +1253,14 @@ UtilityConfig::StartSniffer(std::string Script) {
}
if (SnifferIsRunning == GetRunningState(ApplicationName)) {
std::cout << ApplicationName << " is already running.\n";
OutputVerboseEnd();
return;
}
if (!Explain()) {
if (std::system(Command.c_str()) == -1) { // Start the sniffer.
@@ -946,12 +1269,67 @@ UtilityConfig::StartSniffer(std::string Script) {
Temp = "Error running the command '" + Command;
Temp += "' to start the Sniffer: ";
Temp += strerror(errno);
throw runtime_error(Temp);
throw std::runtime_error(Temp);
}
}
if (SnifferIsRunning != GetRunningState(ApplicationName)) {
std::string Temp;
Temp = "Unable to start " + ApplicationName;
throw std::runtime_error(Temp);
}
OutputVerboseEnd();
}
void
UtilityConfig::StopSniffer(std::string ScriptAndArgs, std::string ApplicationName) {
std::string Command;
Command = SnifferStartScriptDir + ScriptAndArgs;
if (Verbose()) {
cout << "Stopping Sniffer with the command '" << Command << "'...";
}
if (SnifferIsStopped == GetRunningState(ApplicationName)) {
std::cout << ApplicationName << " is already not running.\n";
OutputVerboseEnd();
return;
}
if (!Explain()) {
if (std::system(Command.c_str()) == -1) { // Start the sniffer.
string Temp;
Temp = "Error running the command '" + Command;
Temp += "' to stop the Sniffer: ";
Temp += strerror(errno);
throw std::runtime_error(Temp);
}
}
if (SnifferIsStopped != GetRunningState(ApplicationName)) {
std::string Temp;
Temp = "Unable to sto " + ApplicationName;
throw std::runtime_error(Temp);
}
OutputVerboseEnd();
}

+ 133
- 10
Common/UtilityConfig.hpp Vedi File

@@ -26,9 +26,8 @@ public:
/// Running status of the Sniffer application.
enum SnifferRunningStateEnum {
SnifferIsRunning, ///< OpenBSD OS.
SnifferIsStopped, ///< FreeBSD OS.
SnifferRunningStatusIsUknown ///< Ubuntu and variants.
SnifferIsRunning, ///< Sniffer is running.
SnifferIsStopped ///< Sniffer is not running.
};
/// Default constructor.
@@ -112,6 +111,16 @@ public:
// \returns the log path.
std::string GetLogPath(void);
/// Get the status.second log file name.
//
// \returns the status.second log file name.
std::string GetStatusSecondLogFileName(void);
/// Get the status.minute log file name.
//
// \returns the status.minute log file name.
std::string GetStatusMinuteLogFileName(void);
/// Get the identity file name.
//
// \returns the identity file name.
@@ -211,19 +220,50 @@ public:
//
void UpdateIdentityFile(void);
/// Start the sniffer.
/// Get the Sniffer running status.
//
// This method determines whether or not the specified application
// is running.
//
// \param[in] ApplicationName is the specified application name.
//
// \returns enumeration specifying the running state.
//
SnifferRunningStateEnum GetRunningState(std::string ApplicationName);
/// Start the Sniffer application if it isn't running.
//
// This method runs the specified sniffer start script and
// arguments in the appropriate (i.e. OS-dependent) directory.
// The script is prepended with the directory.
//
// This method runs the specified sniffer start script in the
// appropriate (i.e. OS-dependent) directory. The script is
// prepended with the directory, and run with an argument of
// "start".
// \param[in] ScriptAndArgs contains the name of the start script
// and any arguments.
//
// \param[in] Script is the name of the start script.
// \param[in] ApplicationName is the name of the application to
// run. This is passed to GetRunningState().
//
// \pre LoadInfo() must have been called. That method initializes
// the directory the script resides in.
//
void StartSniffer(std::string Script);
void StartSniffer(std::string ScriptAndArgs, std::string ApplicationName);
/// Stop the Sniffer application if it's running.
//
// This method runs the specified sniffer stop script and
// arguments in the appropriate (i.e. OS-dependent) directory.
// The script is prepended with the directory.
//
// \param[in] ScriptAndArgs contains the name of the stop script
// and any arguments.
//
// \param[in] ApplicationName is the name of the application to
// top. This is passed to GetRunningState().
//
// \pre LoadInfo() must have been called. That method initializes
// the directory the script resides in.
//
void StopSniffer(std::string ScriptAndArgs, std::string ApplicationName);
/// Process one command-line item.
//
@@ -305,6 +345,14 @@ public:
private:
/// Method for checking the status of Sniffer.
enum StatusCheckMethod {
StatusCheckXci, ///< Check using XCI.
StatusCheckSecond, ///< Check using status.second log file.
StatusCheckMinute, ///< Check using status.minute log file.
StatusCheckNotAvailable ///< No method for checking is available.
};
/// Setup/repair the identity file.
//
// If the identity file doesn't exist, create it from the sample
@@ -344,6 +392,7 @@ private:
// case, the owner/group is changed by SetOwnerGroup(), and the
// permissions are changed to readonly for everyone, and
// read/write for the owner.
//
void SetupRepairIgnoreListFile(void);
/// Setup/repair the log directory.
@@ -352,8 +401,80 @@ private:
// the owner/group is changed by SetOwnerGroup(), and the
// permissions are changed to r-x for everyone, and rwx for the
// owner.
//
void SetupRepairLogDir(void);
/// Determine the mode for checking the status of Sniffer.
//
// This method determines how the status of the sniffer should be
// checked. The configuration loaded from the configuration file
// is used to determine the method.
//
// If XCI is enabled, then the preferred method is XCI.
// Otherwise, if status.second logging is enabled, the preferred
// method is to check the status.second file. Otherwise, if
// status.minute logging is enabled, the preferred method is to
// check the status.minute file.
//
// \returns Enumeration value indicating how to check the sniffer
// status.
//
StatusCheckMethod GetPreferredStatusCheckMethod(void);
/// Get the Sniffer status report using the preferred method.
//
// \returns Status report obtained from Sniffer using the method
// specified by GetPrefferedStatusCheckMethod() if the Sniffer is
// running. If the Sniffer is not running, "" is returned.
//
// \see GetPreferredStatusCheckMethod().
//
std::string GetSnifferStatusReport();
/// Check the Sniffer status report.
//
// This method checks that the status report is well-formed by
// extracting the <platform> element contents, and also checks
// that the <platform> element contents contains the specified
// application name.
//
// If the status report is not well-formed, or the expected
// application name isn't in the <platform> element content, an
// exception is thrown.
//
// \param[in] StatusReport is the status report obtained by
// GetSnifferStatusReport().
//
// \param[in] ApplicationName is the specified application name.
//
void CheckSnifferStatusReport(std::string StatusReport, std::string ApplicationName);
/// Get the Sniffer status report using XCI.
//
// \returns Status report obtained from Sniffer using XCI if the
// Sniffer is running. Otherwise, "" is returned.
//
std::string GetReportViaXci();
/// Get the Sniffer status report from the specified log file.
//
// This method gets the status report of a running Sniffer.
// Whether or not the Sniffer is running is determined by reading
// the specified log file twice, separated by the specified time
// interval. If the log file contents are different, then the
// Sniffer is running. Otherwise, the Sniffer is not running.
//
// \param[in] LogFileName is the name of the log file.
//
// \param[in] SleepTime_msec is the length of time to wait between
// log file reads.
//
// \returns Status report obtained from Sniffer using the
// specified log file if the Sniffer is running. Otherwise, "" is
// returned.
//
std::string GetReportViaLogFile(std::string LogFileName, int SleepTime_msec);
std::string ConfigFileName; ///< Configuration file name.
std::string LicenseId; ///< License ID string.
bool LicenseIdIsSpecified; ///< true if the License ID was specified on the command line.
@@ -366,6 +487,8 @@ private:
static const std::string SampleIgnoreListFile; ///< Sample ignore list file.
static const std::string SampleRulebaseScriptFile; ///< Sample rulebase script file.
static const long LogFileReportSize = 4096; ///< Size of log file report.
snfCFGData CFGData; ///< Configuration data.
/// Operating system type.

+ 4
- 35
SNFMilterConfig/SNFMilterConfig.cpp Vedi File

@@ -59,6 +59,8 @@ const std::string SNFMilterConfig::SampleIdentityFile("");
#endif
const string SNFMilterConfig::ApplicationName("SNFMilter");
const string IntegrateWithNoneKey("-mta=none");
const string IntegrateWithPostfixKey("-mta=postfix");
const string IntegrateWithSendmailKey("-mta=sendmail");
@@ -216,10 +218,12 @@ SNFMilterConfig::ExecuteCommand() {
case StartSnifferCommand:
StartSniffer("snf-milter start", ApplicationName);
break;
case StopSnifferCommand:
StopSniffer("snf-milter stop", ApplicationName);
break;
default:
@@ -228,41 +232,6 @@ SNFMilterConfig::ExecuteCommand() {
}
#if 0
SnifferRunningStatue RunningStatus;
SnfMilterConfig.CreateLoadConfig(); // Save config file state and load config.
// Load the default if necessary.
SnfMilterConfig.SaveFileState(); // Save state of all other files.
RunningStatus = SnfMilterConfig.GetSnifferRunningStatus(); // Get state before changing anything.
SnfMilterConfig.UpdateConfigFiles(); // Create/update config files
SnfMilterConfig.CreateUpdateRulebaseScript(); // Create/update GetRulebase.
SnfMilterConfig.DownloadRulebase(); // Download rulebase.
SnfMilterConfig.UpdateIdentityFile(); // Update Identity file with credentials,
// if credentials were specified.
SnfMilterConfig.DoIntegrationCommand(); // Integrate/unintegrate.
if (SnifferIsStopped == RunningStatus) {
SnfMilterConfig.StartSniffer();
} else if (SnifferRunningStatusIsUknown == RunningStatus) {
std::cout << "SNFMilterConfig: Unable to determine whether SNFMilter is running.\n"
<< "Please start SNFMilter if it isn't running.\n";
}
#endif
}
void

+ 2
- 0
SNFMilterConfig/SNFMilterConfig.hpp Vedi File

@@ -123,6 +123,8 @@ private:
static const std::string SampleIdentityFile; ///< Sample identity file.
static const std::string ApplicationName; ///< Application name.
std::string SocketFileName;
};

+ 1
- 0
SNFMilterConfig/main.cpp Vedi File

@@ -78,6 +78,7 @@ int main(int argc, char* argv[]) {
DebugMode = true; // Set the flag and tell the
cout << SNF_MILTERCONFIG_VERSION << endl; // watchers.
cout << "Debug Mode" << endl;
SnfMilterConfig.SetDebug(true);
}
try { // Catch anything that breaks loose.

Loading…
Annulla
Salva