Browse Source

cleaned up namespace and dropped inline snfCFGmgr

master
Pete McNeil 4 years ago
parent
commit
bb37eb00c3
3 changed files with 217 additions and 226 deletions
  1. 172
    130
      snfCFGmgr.cpp
  2. 45
    50
      snfCFGmgr.hpp
  3. 0
    46
      snfCFGmgr.inline.hpp

+ 172
- 130
snfCFGmgr.cpp View File

// snfCFGmgr.cpp // snfCFGmgr.cpp
// Copyright (C) 2006 - 2009 Arm Research Labs, LLC
// Copyright (C) 2006 - 2020 Arm Research Labs, LLC
// See www.armresearch.com for the copyright terms. // See www.armresearch.com for the copyright terms.
// //


#include "snfCFGmgr.hpp" #include "snfCFGmgr.hpp"
#include <iostream> #include <iostream>


namespace cd = codedweller;

//// IntegerSetHandler /////////////////////////////////////////////////////////

bool IntegerSetHandler::isListed(int x) { // How to check if an int is listed.
return (IntegerSet.end() != IntegerSet.find(x));
}


//// snfCFGmgr /////////////////////////////////////////////////////////////////

snfCFGmgr::snfCFGmgr() : // We construct a CFGmgr this way...
AisActive(false), // So that A is active after 1st load()
InitFileName(""), // and all of the Init strings are
InitLicenseId(""), // empty.
InitAuthentication(""),
ConfigurationPath("") {
}

void snfCFGmgr::swapCFGData() { // This swaps the active dataset.
AisActive = (AisActive)?false:true;
}

snfCFGData& snfCFGmgr::ActiveData() { // This returns the active dataset.
return (AisActive) ? A : B;
}

snfCFGData& snfCFGmgr::InactiveData() { // This returns the inactive dataset.
return (AisActive) ? B : A;
}

std::string snfCFGmgr::RuleFilePath() { // Rulebase file path
return ActiveData().RuleFilePath;
}

std::string snfCFGmgr::SecurityKey() { // Security key for rulebase
return ActiveData().SecurityKey;
}

snfCFGData* snfCFGmgr::ActiveConfiguration() { // Pointer to active configuration
return &(ActiveData());
}


//// RangeHandler ////////////////////////////////////////////////////////////// //// RangeHandler //////////////////////////////////////////////////////////////


return false; // there is no map so there is return false; // there is no map so there is
} // no side to be on. } // no side to be on.
// If there are points we will need // If there are points we will need
set<RangePoint>::iterator iRangePoint; // to examine them.
std::set<RangePoint>::iterator iRangePoint; // to examine them.
iRangePoint = EdgeMap.begin(); // What is the first point. iRangePoint = EdgeMap.begin(); // What is the first point.


if(x < (*iRangePoint)) { // If x is below that then if(x < (*iRangePoint)) { // If x is below that then
return false; // there is no map so there is return false; // there is no map so there is
} // no side to be on. } // no side to be on.
// If ther are points then we // If ther are points then we
set<RangePoint>::iterator iRangePoint; // need to examine them.
std::set<RangePoint>::iterator iRangePoint; // need to examine them.
iRangePoint = EdgeMap.begin(); // What is the first point. iRangePoint = EdgeMap.begin(); // What is the first point.


if(x < (*iRangePoint)) { // If x is below that then if(x < (*iRangePoint)) { // If x is below that then
.End("snf"); .End("snf");
} }


void fixPathTermination(string& s) { // Ensure s ends in a / or a \ as needed.
void fixPathTermination(std::string& s) { // Ensure s ends in a / or a \ as needed.


if(0 == s.length()) return; // If the string is empty we do nothing. if(0 == s.length()) return; // If the string is empty we do nothing.


// see what separator has already been used. // see what separator has already been used.


char Terminator; // This will be our terminator. char Terminator; // This will be our terminator.
if(string::npos == s.find('\\')) { // If we're not using a backslash then
if(std::string::npos == s.find('\\')) { // If we're not using a backslash then
Terminator = '/'; // we will use the forward slash. Terminator = '/'; // we will use the forward slash.
} else { // If we are using the backslash then } else { // If we are using the backslash then
Terminator = '\\'; // we will remain consistent and terminate Terminator = '\\'; // we will remain consistent and terminate
//// that way an attacker can't trick the application into disclosing the true //// that way an attacker can't trick the application into disclosing the true
//// authentication string -- they will only get out what they put in. //// authentication string -- they will only get out what they put in.


string SecurityKeyDisplayString(snfCFGData& D) { // Returns appropriate SecurityKey: data
string ConfigLogSecurityKey = "************************"; // Start with a masked display.
std::string SecurityKeyDisplayString(snfCFGData& D) { // Returns appropriate SecurityKey: data
std::string ConfigLogSecurityKey = "************************"; // Start with a masked display.
if(0 < D.node_authentication.length()) { // If auth info is in the config files then if(0 < D.node_authentication.length()) { // If auth info is in the config files then
ConfigLogSecurityKey = D.node_licenseid + D.node_authentication; // build up the key from that data so it ConfigLogSecurityKey = D.node_licenseid + D.node_authentication; // build up the key from that data so it
} // can be displayed in the config log. } // can be displayed in the config log.
void logCFGData(snfCFGData& D) { // Log interpreted cfg data (debug aid). void logCFGData(snfCFGData& D) { // Log interpreted cfg data (debug aid).


try { try {
string CFGLogPath; // Build the snf_cfg log path.
std::string CFGLogPath; // Build the snf_cfg log path.
CFGLogPath = D.paths_log_path + CFGLogPath = D.paths_log_path +
D.node_licenseid + "_snf_engine_cfg.log"; D.node_licenseid + "_snf_engine_cfg.log";


ofstream cfgl(CFGLogPath.c_str(), ios::trunc); // Open and truncate the cfg log file.
std::ofstream cfgl(CFGLogPath.c_str(), std::ios::trunc); // Open and truncate the cfg log file.
cfgl // Report important cfg information. cfgl // Report important cfg information.
<< "SNF Engine Configuration" << endl
<< "____________" << endl
<< "Fundamentals" << endl
<< " License: " << D.node_licenseid << endl
<< " ConfigFilePath: " << D.ConfigFilePath << endl
<< " IdentityFilePath: " << D.node_identity << endl
<< " SecurityKey: " << SecurityKeyDisplayString(D) << endl
<< "_____" << endl
<< "Paths" << endl
<< " Log Path: " << D.paths_log_path << endl
<< " Rulebase Path: " << D.paths_rulebase_path << endl
<< " Workspace Path: " << D.paths_workspace_path << endl
<< " RuleFilePath: " << D.RuleFilePath << endl
<< "____" << endl
<< "Logs" << endl
<< endl
<< " Rotation-Midnight: " << ((D.Logs_Rotation_LocalTime_OnOff)? "Local" : "UTC") << endl
<< " ______" << endl
<< " Status" << endl
<< "SNF Engine Configuration" << std::endl
<< "____________" << std::endl
<< "Fundamentals" << std::endl
<< " License: " << D.node_licenseid << std::endl
<< " ConfigFilePath: " << D.ConfigFilePath << std::endl
<< " IdentityFilePath: " << D.node_identity << std::endl
<< " SecurityKey: " << SecurityKeyDisplayString(D) << std::endl
<< "_____" << std::endl
<< "Paths" << std::endl
<< " Log Path: " << D.paths_log_path << std::endl
<< " Rulebase Path: " << D.paths_rulebase_path << std::endl
<< " Workspace Path: " << D.paths_workspace_path << std::endl
<< " RuleFilePath: " << D.RuleFilePath << std::endl
<< "____" << std::endl
<< "Logs" << std::endl
<< std::endl
<< " Rotation-Midnight: " << ((D.Logs_Rotation_LocalTime_OnOff)? "Local" : "UTC") << std::endl
<< " ______" << std::endl
<< " Status" << std::endl
<< " PerSecond: " << " PerSecond: "
<< ((D.Status_SecondReport_Log_OnOff)? "yes, " : "no, ") << ((D.Status_SecondReport_Log_OnOff)? "yes, " : "no, ")
<< "Append: " << "Append: "
<< ((D.Status_SecondReport_Append_OnOff)? "yes" : "no") << ((D.Status_SecondReport_Append_OnOff)? "yes" : "no")
<< endl
<< std::endl
<< " PerMinute: " << " PerMinute: "
<< ((D.Status_MinuteReport_Log_OnOff)? "yes, " : "no, ") << ((D.Status_MinuteReport_Log_OnOff)? "yes, " : "no, ")
<< "Append: " << "Append: "
<< ((D.Status_MinuteReport_Append_OnOff)? "yes" : "no") << ((D.Status_MinuteReport_Append_OnOff)? "yes" : "no")
<< endl
<< std::endl
<< " PerHour: " << " PerHour: "
<< ((D.Status_HourReport_Log_OnOff)? "yes, " : "no, ") << ((D.Status_HourReport_Log_OnOff)? "yes, " : "no, ")
<< "Append: " << "Append: "
<< ((D.Status_HourReport_Append_OnOff)? "yes" : "no") << ((D.Status_HourReport_Append_OnOff)? "yes" : "no")
<< endl
<< " ____" << endl
<< " Scan" << endl
<< std::endl
<< " ____" << std::endl
<< " Scan" << std::endl
<< " Identifier: " << " Identifier: "
<< ((D.Scan_Identifier_Force_Message_Id)? "Force RFC822 Message-ID" : "Use Provided Identifier") << ((D.Scan_Identifier_Force_Message_Id)? "Force RFC822 Message-ID" : "Use Provided Identifier")
<< endl
<< std::endl
<< " Classic: Output-" << " Classic: Output-"
<< ((LogOutputMode_None == D.Scan_Classic_Mode)? "None, " : << ((LogOutputMode_None == D.Scan_Classic_Mode)? "None, " :
((LogOutputMode_API == D.Scan_Classic_Mode)? "API, " : ((LogOutputMode_API == D.Scan_Classic_Mode)? "API, " :
<< ((D.Scan_Classic_Matches == ScanLogMatches_None) ? "No Mathes": << ((D.Scan_Classic_Matches == ScanLogMatches_None) ? "No Mathes":
((D.Scan_Classic_Matches == ScanLogMatches_Unique) ? "Unique Matches": ((D.Scan_Classic_Matches == ScanLogMatches_Unique) ? "Unique Matches":
((D.Scan_Classic_Matches == ScanLogMatches_All) ? "All Matches" : "Error!"))) ((D.Scan_Classic_Matches == ScanLogMatches_All) ? "All Matches" : "Error!")))
<< endl
<< std::endl
<< " XML: Output-" << " XML: Output-"
<< ((LogOutputMode_None == D.Scan_XML_Mode)? "None, " : << ((LogOutputMode_None == D.Scan_XML_Mode)? "None, " :
((LogOutputMode_API == D.Scan_XML_Mode)? "API, " : ((LogOutputMode_API == D.Scan_XML_Mode)? "API, " :
((D.Scan_XML_Matches == ScanLogMatches_All) ? "All Matches, " : "Match Error! "))) ((D.Scan_XML_Matches == ScanLogMatches_All) ? "All Matches, " : "Match Error! ")))
<< ((D.Scan_XML_Performance)? "Performance Metrics, " : "No Performance Metrics, ") << ((D.Scan_XML_Performance)? "Performance Metrics, " : "No Performance Metrics, ")
<< ((D.Scan_XML_GBUdb)? "GBUdb Data" : "No GBUdb Data") << ((D.Scan_XML_GBUdb)? "GBUdb Data" : "No GBUdb Data")
<< endl
<< " XHeaders:" << endl
<< std::endl
<< " XHeaders:" << std::endl
<< " Output: " << " Output: "
<< ((LogOutputMode_None == D.XHDROutput_Mode) ? "None" : << ((LogOutputMode_None == D.XHDROutput_Mode) ? "None" :
((LogOutputMode_API == D.XHDROutput_Mode) ? "API" : ((LogOutputMode_API == D.XHDROutput_Mode) ? "API" :
((LogOutputMode_File == D.XHDROutput_Mode) ? "File" : ((LogOutputMode_File == D.XHDROutput_Mode) ? "File" :
((LogOutputMode_Inject == D.XHDROutput_Mode)? "Inject" : "Error!")))) ((LogOutputMode_Inject == D.XHDROutput_Mode)? "Inject" : "Error!"))))
<< endl
<< std::endl
<< " Version: " << " Version: "
<< ((D.XHDRVersion_OnOff)? "On, " : "Off, ") << ((D.XHDRVersion_OnOff)? "On, " : "Off, ")
<< D.XHDRVersion_Header << D.XHDRVersion_Header
<< endl
<< std::endl
<< " License: " << " License: "
<< ((D.XHDRLicense_OnOff)? "On, " : "Off, ") << ((D.XHDRLicense_OnOff)? "On, " : "Off, ")
<< D.XHDRLicense_Header << D.XHDRLicense_Header
<< endl
<< std::endl
<< " Rulebase: " << " Rulebase: "
<< ((D.XHDRRulebase_OnOff)? "On, " : "Off, ") << ((D.XHDRRulebase_OnOff)? "On, " : "Off, ")
<< D.XHDRRulebase_Header << D.XHDRRulebase_Header
<< endl
<< std::endl
<< " Identifier: " << " Identifier: "
<< ((D.XHDRIdentifier_OnOff)? "On, " : "Off, ") << ((D.XHDRIdentifier_OnOff)? "On, " : "Off, ")
<< D.XHDRIdentifier_Header << D.XHDRIdentifier_Header
<< endl
<< std::endl
<< " GBUdb: " << " GBUdb: "
<< ((D.XHDRGBUdb_OnOff)? "On, " : "Off, ") << ((D.XHDRGBUdb_OnOff)? "On, " : "Off, ")
<< D.XHDRGBUdb_Header << D.XHDRGBUdb_Header
<< endl
<< std::endl
<< " Result: " << " Result: "
<< ((D.XHDRResult_OnOff)? "On, " : "Off, ") << ((D.XHDRResult_OnOff)? "On, " : "Off, ")
<< D.XHDRResult_Header << D.XHDRResult_Header
<< endl
<< std::endl
<< " Matches: " << " Matches: "
<< ((D.XHDRMatches_OnOff)? "On, " : "Off, ") << ((D.XHDRMatches_OnOff)? "On, " : "Off, ")
<< D.XHDRMatches_Header << D.XHDRMatches_Header
<< endl
<< std::endl
<< " Black: " << " Black: "
<< ((D.XHDRBlack_OnOff)? "On, " : "Off, ") << ((D.XHDRBlack_OnOff)? "On, " : "Off, ")
<< D.XHDRBlack_Header << D.XHDRBlack_Header
<< endl
<< std::endl
<< " White: " << " White: "
<< ((D.XHDRWhite_OnOff)? "On, " : "Off, ") << ((D.XHDRWhite_OnOff)? "On, " : "Off, ")
<< D.XHDRWhite_Header << D.XHDRWhite_Header
<< endl
<< std::endl
<< " Clean: " << " Clean: "
<< ((D.XHDRClean_OnOff)? "On, " : "Off, ") << ((D.XHDRClean_OnOff)? "On, " : "Off, ")
<< D.XHDRClean_Header << D.XHDRClean_Header
<< endl;
<< std::endl;


for( for(
set<XHDRSymbol>::iterator iH = D.XHDRSymbolHeaders.SymbolHeaders.begin();
std::set<XHDRSymbol>::iterator iH = D.XHDRSymbolHeaders.SymbolHeaders.begin();
iH != D.XHDRSymbolHeaders.SymbolHeaders.end(); iH++ iH != D.XHDRSymbolHeaders.SymbolHeaders.end(); iH++
) { ) {
cfgl cfgl
<< " Symbol: " << " Symbol: "
<< (*iH).Symbol << ", " << (*iH).Symbol << ", "
<< (*iH).Header << (*iH).Header
<< endl;
<< std::endl;
} }


cfgl cfgl
<< "_______" << endl
<< "Network" << endl
<< " Sync Host: " << D.network_sync_host << endl
<< " Sync Port: " << D.network_sync_port << endl
<< " Sync Secs: " << D.network_sync_secs << endl
<< " _____________" << endl
<< " Update-Script" << endl
<< " On-Off: " << ((D.update_script_on_off) ? "On" : "Off") << endl
<< " Script: " << D.update_script_call << endl
<< " Guard-Time: " << D.update_script_guard_time << " seconds" << endl
<< "___" << endl
<< "XCI" << endl
<< " " << ((D.XCI_OnOff)? "Enabled" : "Disabled") << endl
<< " Port: " << D.XCI_Port << endl
<< "_____" << endl
<< "GBUdb" << endl
<< " ____________" << endl
<< " Condensation" << endl
<< " Minimum-Seconds-Between = " << D.gbudb_database_condense_minimum_seconds_between << endl
<< "_______" << std::endl
<< "Network" << std::endl
<< " Sync Host: " << D.network_sync_host << std::endl
<< " Sync Port: " << D.network_sync_port << std::endl
<< " Sync Secs: " << D.network_sync_secs << std::endl
<< " _____________" << std::endl
<< " Update-Script" << std::endl
<< " On-Off: " << ((D.update_script_on_off) ? "On" : "Off") << std::endl
<< " Script: " << D.update_script_call << std::endl
<< " Guard-Time: " << D.update_script_guard_time << " seconds" << std::endl
<< "___" << std::endl
<< "XCI" << std::endl
<< " " << ((D.XCI_OnOff)? "Enabled" : "Disabled") << std::endl
<< " Port: " << D.XCI_Port << std::endl
<< "_____" << std::endl
<< "GBUdb" << std::endl
<< " ____________" << std::endl
<< " Condensation" << std::endl
<< " Minimum-Seconds-Between = " << D.gbudb_database_condense_minimum_seconds_between << std::endl
<< " Time-Trigger: " << " Time-Trigger: "
<< ((D.gbudb_database_condense_time_trigger_on_off)? "on, " : "off, ") << ((D.gbudb_database_condense_time_trigger_on_off)? "on, " : "off, ")
<< D.gbudb_database_condense_time_trigger_seconds << " seconds" << endl
<< D.gbudb_database_condense_time_trigger_seconds << " seconds" << std::endl
<< " Posts-Trigger: " << " Posts-Trigger: "
<< ((D.gbudb_database_condense_posts_trigger_on_off)? "on, " : "off, ") << ((D.gbudb_database_condense_posts_trigger_on_off)? "on, " : "off, ")
<< D.gbudb_database_condense_posts_trigger_posts << " posts" << endl
<< D.gbudb_database_condense_posts_trigger_posts << " posts" << std::endl
<< " Records-Trigger: " << " Records-Trigger: "
<< ((D.gbudb_database_condense_records_trigger_on_off) ? "on, " : "off, ") << ((D.gbudb_database_condense_records_trigger_on_off) ? "on, " : "off, ")
<< D.gbudb_database_condense_records_trigger_records << " records" << endl
<< D.gbudb_database_condense_records_trigger_records << " records" << std::endl
<< " Size-Trigger: " << " Size-Trigger: "
<< ((D.gbudb_database_condense_size_trigger_on_off) ? "on, " : "off, ") << ((D.gbudb_database_condense_size_trigger_on_off) ? "on, " : "off, ")
<< D.gbudb_database_condense_size_trigger_megabytes << " megabytes" << endl
<< " __________" << endl
<< " Checkpoint" << endl
<< D.gbudb_database_condense_size_trigger_megabytes << " megabytes" << std::endl
<< " __________" << std::endl
<< " Checkpoint" << std::endl
<< " Checkpoint: " << " Checkpoint: "
<< ((D.gbudb_database_checkpoint_on_off) ? "on, " : "off, ") << ((D.gbudb_database_checkpoint_on_off) ? "on, " : "off, ")
<< D.gbudb_database_checkpoint_secs << " seconds" << endl
<< " ______" << endl
<< " Ranges" << endl
<< D.gbudb_database_checkpoint_secs << " seconds" << std::endl
<< " ______" << std::endl
<< " Ranges" << std::endl
<< " White: " << " White: "
<< ((D.WhiteRangeHandler.On_Off) ? "on, " : "off, ") << ((D.WhiteRangeHandler.On_Off) ? "on, " : "off, ")
<< "Symbol " << D.WhiteRangeHandler.Symbol << endl
<< "Symbol " << D.WhiteRangeHandler.Symbol << std::endl
<< " Auto-Panic: " << " Auto-Panic: "
<< ((D.gbudb_regions_white_panic_on_off) ? "on, " : "off, ") << ((D.gbudb_regions_white_panic_on_off) ? "on, " : "off, ")
<< "Range " << D.gbudb_regions_white_panic_rule_range << endl
<< endl
<< "Range " << D.gbudb_regions_white_panic_rule_range << std::endl
<< std::endl
<< " Caution: " << " Caution: "
<< ((D.CautionRangeHandler.On_Off) ? "on, " : "off, ") << ((D.CautionRangeHandler.On_Off) ? "on, " : "off, ")
<< "Symbol " << D.CautionRangeHandler.Symbol << endl
<< endl
<< "Symbol " << D.CautionRangeHandler.Symbol << std::endl
<< std::endl
<< " Black: " << " Black: "
<< ((D.BlackRangeHandler.On_Off) ? "on, " : "off, ") << ((D.BlackRangeHandler.On_Off) ? "on, " : "off, ")
<< "Symbol " << D.BlackRangeHandler.Symbol << endl
<< "Symbol " << D.BlackRangeHandler.Symbol << std::endl
<< " Truncate: " << " Truncate: "
<< ((D.gbudb_regions_black_truncate_on_off) ? "on, " : "off, ") << ((D.gbudb_regions_black_truncate_on_off) ? "on, " : "off, ")
<< "Probability " << D.gbudb_regions_black_truncate_probability << ", " << "Probability " << D.gbudb_regions_black_truncate_probability << ", "
<< "Peek-One-In " << D.gbudb_regions_black_truncate_peek_one_in << ", " << "Peek-One-In " << D.gbudb_regions_black_truncate_peek_one_in << ", "
<< "Symbol " << D.gbudb_regions_black_truncate_symbol << endl
<< "Symbol " << D.gbudb_regions_black_truncate_symbol << std::endl
<< " Sample: " << " Sample: "
<< ((D.gbudb_regions_black_sample_on_off) ? "on, " : "off, ") << ((D.gbudb_regions_black_sample_on_off) ? "on, " : "off, ")
<< "Probability: " << D.gbudb_regions_black_sample_probability << ", " << "Probability: " << D.gbudb_regions_black_sample_probability << ", "
<< "Grab-One-In: " << D.gbudb_regions_black_sample_grab_one_in << ", " << endl
<< "Grab-One-In: " << D.gbudb_regions_black_sample_grab_one_in << ", " << std::endl
<< " Passthrough: " << " Passthrough: "
<< ((D.gbudb_regions_black_sample_passthrough) ? "yes, " : "no, ") << ((D.gbudb_regions_black_sample_passthrough) ? "yes, " : "no, ")
<< "Passthrough Symbol " << D.gbudb_regions_black_sample_passthrough_symbol << endl
<< endl
<< " Range Map - [W]hite [B]lack [C]aution [ ]undefined" << endl << endl
<< " |-9876543210123456789+|" << endl;
<< "Passthrough Symbol " << D.gbudb_regions_black_sample_passthrough_symbol << std::endl
<< std::endl
<< " Range Map - [W]hite [B]lack [C]aution [ ]undefined" << std::endl << std::endl
<< " |-9876543210123456789+|" << std::endl;


// Output GBUdb Range Map // Output GBUdb Range Map


cfgl << " "; // Otherwise put in a space. cfgl << " "; // Otherwise put in a space.
} }
} }
cfgl << "|" << c << endl;
cfgl << "|" << c << std::endl;
} }
cfgl << " |---------------------|" << endl;
cfgl << " |---------------------|" << std::endl;


cfgl cfgl
<< endl
<< " ________" << endl
<< " Training" << endl
<< std::endl
<< " ________" << std::endl
<< " Training" << std::endl
<< " GBUdb Updates: " << " GBUdb Updates: "
<< ((D.GBUdbTrainingOn_Off)? "Enabled" : "Disabled") << endl
<< endl;
<< ((D.GBUdbTrainingOn_Off)? "Enabled" : "Disabled") << std::endl
<< std::endl;


cfgl cfgl
<< " Source Header Directives: " << endl;
<< " Source Header Directives: " << std::endl;
for( for(
HeaderDirectiveSet::iterator iD = D.HeaderDirectivesHandler.HeaderDirectives.begin(); HeaderDirectiveSet::iterator iD = D.HeaderDirectivesHandler.HeaderDirectives.begin();
iD != D.HeaderDirectivesHandler.HeaderDirectives.end(); iD++ iD != D.HeaderDirectivesHandler.HeaderDirectives.end(); iD++
<< "Context " << Dx.Context << " is a " << "Context " << Dx.Context << " is a "
<< Dx.Header << " header at" << Dx.Header << " header at"
<< " Ordinal " << Dx.Ordinal << " Ordinal " << Dx.Ordinal
<< " that Contains " << Dx.Contains << endl;
<< " that Contains " << Dx.Contains << std::endl;
} else } else
if(HeaderDirectiveSource == Dx.Directive) { if(HeaderDirectiveSource == Dx.Directive) {
cfgl cfgl
<< " " << " "
<< "Context " << Dx.Context << " Source ip is in " << "Context " << Dx.Context << " Source ip is in "
<< Dx.Header << " header at" << Dx.Header << " header at"
<< " Ordinal " << Dx.Ordinal << endl;
<< " Ordinal " << Dx.Ordinal << std::endl;
} }
} }
cfgl << endl;
cfgl << std::endl;


cfgl cfgl
<< " Drilldown Header Directives: " << endl;
<< " Drilldown Header Directives: " << std::endl;
for( for(
HeaderDirectiveSet::iterator iD = D.HeaderDirectivesHandler.HeaderDirectives.begin(); HeaderDirectiveSet::iterator iD = D.HeaderDirectivesHandler.HeaderDirectives.begin();
iD != D.HeaderDirectivesHandler.HeaderDirectives.end(); iD++ iD != D.HeaderDirectivesHandler.HeaderDirectives.end(); iD++
<< " " << " "
<< Dx.Header << " header at" << Dx.Header << " header at"
<< " Ordinal " << Dx.Ordinal << " Ordinal " << Dx.Ordinal
<< " Contains " << Dx.Contains << endl;
<< " Contains " << Dx.Contains << std::endl;
} }
} }
cfgl << endl;
cfgl << std::endl;


cfgl cfgl
<< " Bypass Header Directives: " << endl;
<< " Bypass Header Directives: " << std::endl;
for( for(
HeaderDirectiveSet::iterator iD = D.HeaderDirectivesHandler.HeaderDirectives.begin(); HeaderDirectiveSet::iterator iD = D.HeaderDirectivesHandler.HeaderDirectives.begin();
iD != D.HeaderDirectivesHandler.HeaderDirectives.end(); iD++ iD != D.HeaderDirectivesHandler.HeaderDirectives.end(); iD++
<< " " << " "
<< Dx.Header << " header at" << Dx.Header << " header at"
<< " Ordinal " << Dx.Ordinal << " Ordinal " << Dx.Ordinal
<< " Contains " << Dx.Contains << endl;
<< " Contains " << Dx.Contains << std::endl;
} }
} }
cfgl << endl;
cfgl << std::endl;


cfgl cfgl
<< " White Rule Header Directives: " << endl;
<< " White Rule Header Directives: " << std::endl;
for( for(
HeaderDirectiveSet::iterator iD = D.HeaderDirectivesHandler.HeaderDirectives.begin(); HeaderDirectiveSet::iterator iD = D.HeaderDirectivesHandler.HeaderDirectives.begin();
iD != D.HeaderDirectivesHandler.HeaderDirectives.end(); iD++ iD != D.HeaderDirectivesHandler.HeaderDirectives.end(); iD++
<< " " << " "
<< Dx.Header << " header at" << Dx.Header << " header at"
<< " Ordinal " << Dx.Ordinal << " Ordinal " << Dx.Ordinal
<< " Contains " << Dx.Contains << endl;
<< " Contains " << Dx.Contains << std::endl;
} }
} }
cfgl << endl;
cfgl << std::endl;


cfgl cfgl
<< " White Rule Symbols: "; << " White Rule Symbols: ";
// Output white rule symbols // Output white rule symbols


for( for(
set<int>::iterator ix = D.TrainingWhiteRuleHandler.IntegerSet.begin();
std::set<int>::iterator ix = D.TrainingWhiteRuleHandler.IntegerSet.begin();
ix != D.TrainingWhiteRuleHandler.IntegerSet.end(); ix != D.TrainingWhiteRuleHandler.IntegerSet.end();
ix ++) { ix ++) {
if(D.TrainingWhiteRuleHandler.IntegerSet.begin() != ix) { if(D.TrainingWhiteRuleHandler.IntegerSet.begin() != ix) {
} }
cfgl << (*ix); cfgl << (*ix);
} }
cfgl << endl;
cfgl << std::endl;


// Rule Panics // Rule Panics


cfgl cfgl
<< "___________" << endl
<< "Rule-Panics" << endl;
<< "___________" << std::endl
<< "Rule-Panics" << std::endl;


for( for(
set<int>::iterator ix = D.RulePanicHandler.IntegerSet.begin();
std::set<int>::iterator ix = D.RulePanicHandler.IntegerSet.begin();
ix != D.RulePanicHandler.IntegerSet.end(); ix != D.RulePanicHandler.IntegerSet.end();
ix ++) { ix ++) {
cfgl << " Rule ID: " << (*ix) << endl;
cfgl << " Rule ID: " << (*ix) << std::endl;
} }
cfgl << endl;
cfgl << std::endl;


cfgl cfgl
<< "___________" << endl
<< "Integration" << endl
<< endl
<< "___________" << std::endl
<< "Integration" << std::endl
<< std::endl
<< " Message Format: " << " Message Format: "
<< ((D.MessageFileTypeCGP_on_off)? "CGP" : "RFC822") << ((D.MessageFileTypeCGP_on_off)? "CGP" : "RFC822")
<< endl;
<< std::endl;


#ifdef __BIG_ENDIAN__ #ifdef __BIG_ENDIAN__


cfgl << " Rulebase Conversion: BIG ENDIAN" << endl;
cfgl << " Rulebase Conversion: BIG ENDIAN" << std::endl;


#else #else


cfgl << " Rulebase Conversion: LITTLE ENDIAN" << endl;
cfgl << " Rulebase Conversion: LITTLE ENDIAN" << std::endl;


#endif #endif


cfgl cfgl
<< "________" << endl
<< "Platform" << endl
<< "________" << std::endl
<< "Platform" << std::endl
<< D.PlatformElementContents << D.PlatformElementContents
<< endl;
<< std::endl;


cfgl << endl; // End with a new line.
cfgl << std::endl; // End with a new line.
cfgl.close(); // Close the cfg log file. cfgl.close(); // Close the cfg log file.
} catch (...) {} // Ignore any errors. } catch (...) {} // Ignore any errors.
} }
int PathLength = InitFileName.length(); // How long is the path? int PathLength = InitFileName.length(); // How long is the path?
const int MinimumPathLength = 12; // Must be at least licensid.snf long. const int MinimumPathLength = 12; // Must be at least licensid.snf long.
if(MinimumPathLength > PathLength) throw LoadFailure(); // Path length is impossible? throw! if(MinimumPathLength > PathLength) throw LoadFailure(); // Path length is impossible? throw!
const string SNFExt = ".snf"; // The extension we are looking for.
const string CFGExt = ".xml"; // The default cfg extension.
const std::string SNFExt = ".snf"; // The extension we are looking for.
const std::string CFGExt = ".xml"; // The default cfg extension.
const int SNFExtLength = SNFExt.length(); // The length of the extension. const int SNFExtLength = SNFExt.length(); // The length of the extension.
int SNFExtPosition = InitFileName.rfind(SNFExt,PathLength); // Find the extension at the end. int SNFExtPosition = InitFileName.rfind(SNFExt,PathLength); // Find the extension at the end.


CFGData.SecurityKey = CFGData.node_licenseid; // the LicenseID from our config file. CFGData.SecurityKey = CFGData.node_licenseid; // the LicenseID from our config file.
} }


string LicenseIDToUse = CFGData.SecurityKey; // Grab the License ID we want to use.
std::string LicenseIDToUse = CFGData.SecurityKey; // Grab the License ID we want to use.


if(InitAuthenticationIsProvided) { // If the Authentication has been provided then if(InitAuthenticationIsProvided) { // If the Authentication has been provided then
CFGData.SecurityKey += InitAuthentication; // we use it for the second part of our CFGData.SecurityKey += InitAuthentication; // we use it for the second part of our

+ 45
- 50
snfCFGmgr.hpp View File

// snfCFGmgr.hpp // snfCFGmgr.hpp
// Copyright (C) 2006 - 2009 Arm Research Labs, LLC
// Copyright (C) 2006 - 2020 Arm Research Labs, LLC
// See www.armresearch.com for the copyright terms. // See www.armresearch.com for the copyright terms.
// //
// SNF Configuration manager. // SNF Configuration manager.


//// Begin include only once //// Begin include only once


#ifndef included_snfCFGmgr_hpp
#define included_snfCFGmgr_hpp
#pragma once


#include "GBUdb.hpp" #include "GBUdb.hpp"
#include "snf_HeaderFinder.hpp" #include "snf_HeaderFinder.hpp"
int Priority; // They have an evaluation priority. int Priority; // They have an evaluation priority.


RangePoint EdgeInput; // This EdgePoint is set, and added using (). RangePoint EdgeInput; // This EdgePoint is set, and added using ().
set<RangePoint> EdgeMap; // This contains the set of EdgePoints.
std::set<RangePoint> EdgeMap; // This contains the set of EdgePoints.


bool isInWhite(RangePoint& x); // True if x is inside the -P of the EdgeMap. bool isInWhite(RangePoint& x); // True if x is inside the -P of the EdgeMap.
bool isInBlack(RangePoint& x); // True if x is inside the +P of the EdgeMap. bool isInBlack(RangePoint& x); // True if x is inside the +P of the EdgeMap.
} }


int IntegerInput; // The input port. int IntegerInput; // The input port.
set<int> IntegerSet; // The set itself.
std::set<int> IntegerSet; // The set itself.


bool isListed(int x); // How to check if an int is listed. bool isListed(int x); // How to check if an int is listed.


class XHDRSymbol { // XHeader associated with a Symbol class XHDRSymbol { // XHeader associated with a Symbol
public: public:
int Symbol; // The integer symbol. int Symbol; // The integer symbol.
string Header; // The header to associate.
XHDRSymbol(int FreshSymbol, string FreshHeader) : // Creating the object requires both.
std::string Header; // The header to associate.
XHDRSymbol(int FreshSymbol, std::string FreshHeader) : // Creating the object requires both.
Symbol(FreshSymbol), Symbol(FreshSymbol),
Header(FreshHeader) {} Header(FreshHeader) {}




class XHDRSymbolsHandler : public cd::Configurator { // XHDRSymbol hander. class XHDRSymbolsHandler : public cd::Configurator { // XHDRSymbol hander.
public: public:
set<XHDRSymbol> SymbolHeaders; // Carries a set of Symbol Headers.
std::set<XHDRSymbol> SymbolHeaders; // Carries a set of Symbol Headers.


void reset() { SymbolHeaders.clear(); } // Is reset by clearing the set. void reset() { SymbolHeaders.clear(); } // Is reset by clearing the set.


string HeaderForSymbol(int S) { // Can return a Header for symbol.
string MatchingHeader = ""; // Starting with an empty string,
set<XHDRSymbol>::iterator iS = SymbolHeaders.find(XHDRSymbol(S,"")); // we look up the symbol and
if(SymbolHeaders.end() != iS) { // if we find it then we will
MatchingHeader = (*iS).Header; // return the matching header
} // string. If not then we return
return MatchingHeader; // the empty string.
} // Coded in-line on purpose.
std::string HeaderForSymbol(int S) { // Can return a Header for symbol.
std::string MatchingHeader = ""; // Starting with an empty string,
std::set<XHDRSymbol>::iterator iS = SymbolHeaders.find(XHDRSymbol(S,"")); // we look up the symbol and
if(SymbolHeaders.end() != iS) { // if we find it then we will
MatchingHeader = (*iS).Header; // return the matching header
} // string. If not then we return
return MatchingHeader; // the empty string.
} // Coded in-line on purpose.


bool OnOff; // Input OnOff value. bool OnOff; // Input OnOff value.
int Symbol; // Input Symbol value. int Symbol; // Input Symbol value.
string Header; // Input Header value.
std::string Header; // Input Header value.


void operator()(cd::ConfigurationElement& E, cd::ConfigurationData& D) { // The operator() inserts an XHDRSymbol void operator()(cd::ConfigurationElement& E, cd::ConfigurationData& D) { // The operator() inserts an XHDRSymbol
if(OnOff) { // if the header entry is turned on and if(OnOff) { // if the header entry is turned on and


// Here are the derived data elements... // Here are the derived data elements...


string ConfigFilePath; // Configuration file path
string RuleFilePath; // Rulebase file path
string SecurityKey; // Security key for rulebase
std::string ConfigFilePath; // Configuration file path
std::string RuleFilePath; // Rulebase file path
std::string SecurityKey; // Security key for rulebase


// Here are the basic data elements... // Here are the basic data elements...


string node_identity;
string node_licenseid;
string node_authentication;
std::string node_identity;
std::string node_licenseid;
std::string node_authentication;


//// paths //// paths


string paths_workspace_path;
string paths_rulebase_path;
string paths_log_path;
std::string paths_workspace_path;
std::string paths_rulebase_path;
std::string paths_log_path;


//// logging //// logging


int XHDROutput_Mode; int XHDROutput_Mode;


bool XHDRVersion_OnOff; bool XHDRVersion_OnOff;
string XHDRVersion_Header;
std::string XHDRVersion_Header;


bool XHDRLicense_OnOff; bool XHDRLicense_OnOff;
string XHDRLicense_Header;
std::string XHDRLicense_Header;


bool XHDRRulebase_OnOff; bool XHDRRulebase_OnOff;
string XHDRRulebase_Header;
std::string XHDRRulebase_Header;


bool XHDRIdentifier_OnOff; bool XHDRIdentifier_OnOff;
string XHDRIdentifier_Header;
std::string XHDRIdentifier_Header;


bool XHDRGBUdb_OnOff; bool XHDRGBUdb_OnOff;
string XHDRGBUdb_Header;
std::string XHDRGBUdb_Header;


bool XHDRResult_OnOff; bool XHDRResult_OnOff;
string XHDRResult_Header;
std::string XHDRResult_Header;


bool XHDRMatches_OnOff; bool XHDRMatches_OnOff;
string XHDRMatches_Header;
std::string XHDRMatches_Header;


bool XHDRBlack_OnOff; bool XHDRBlack_OnOff;
string XHDRBlack_Header;
std::string XHDRBlack_Header;


bool XHDRWhite_OnOff; bool XHDRWhite_OnOff;
string XHDRWhite_Header;
std::string XHDRWhite_Header;


bool XHDRClean_OnOff; bool XHDRClean_OnOff;
string XHDRClean_Header;
std::string XHDRClean_Header;


XHDRSymbolsHandler XHDRSymbolHeaders; XHDRSymbolsHandler XHDRSymbolHeaders;
XHDRSymbolsInitializer XHDRSymbolHeadersInitializer; XHDRSymbolsInitializer XHDRSymbolHeadersInitializer;


//// platform //// platform


string PlatformElementContents;
std::string PlatformElementContents;


//// network //// network


int network_sync_secs; int network_sync_secs;
string network_sync_host;
std::string network_sync_host;
int network_sync_port; int network_sync_port;


bool update_script_on_off; bool update_script_on_off;
string update_script_call;
std::string update_script_call;
int update_script_guard_time; int update_script_guard_time;


//// gbudb //// gbudb


private: private:


Mutex myMutex; // Serialize control during updates.
cd::Mutex myMutex; // Serialize control during updates.


snfCFGData A; // This is where we store one copy. snfCFGData A; // This is where we store one copy.
snfCFGData B; // This is where we store the other. snfCFGData B; // This is where we store the other.
snfCFGData& ActiveData(); // This returns the active dataset. snfCFGData& ActiveData(); // This returns the active dataset.
snfCFGData& InactiveData(); // This returns the inactive dataset. snfCFGData& InactiveData(); // This returns the inactive dataset.


string InitFileName; // Initilization parameters are reused
string InitLicenseId; // any time load() is called.
string InitAuthentication;
std::string InitFileName; // Initilization parameters are reused
std::string InitLicenseId; // any time load() is called.
std::string InitAuthentication;


string ConfigurationPath; // Path to active configuration file.
std::string ConfigurationPath; // Path to active configuration file.


public: public:




//// Access methods for config data... //// Access methods for config data...


string RuleFilePath(); // Rulebase file path
string SecurityKey(); // Security key for rulebase
std::string RuleFilePath(); // Rulebase file path
std::string SecurityKey(); // Security key for rulebase


snfCFGData* ActiveConfiguration(); // Pointer to active configuration snfCFGData* ActiveConfiguration(); // Pointer to active configuration


}; };


#include "snfCFGmgr.inline.hpp"

#endif
// End include only once

+ 0
- 46
snfCFGmgr.inline.hpp View File

// snfCFGmgr.inline.hpp
//
// (C) Copyright 2006 - 2009 ARM Research Labs, LLC.
//
// Inline functions/methods for snfCFGmgr module.

//// IntegerSetHandler /////////////////////////////////////////////////////////

inline bool IntegerSetHandler::isListed(int x) { // How to check if an int is listed.
return (IntegerSet.end() != IntegerSet.find(x));
}


//// snfCFGmgr /////////////////////////////////////////////////////////////////

inline snfCFGmgr::snfCFGmgr() : // We construct a CFGmgr this way...
AisActive(false), // So that A is active after 1st load()
InitFileName(""), // and all of the Init strings are
InitLicenseId(""), // empty.
InitAuthentication(""),
ConfigurationPath("") {
}

inline void snfCFGmgr::swapCFGData() { // This swaps the active dataset.
AisActive = (AisActive)?false:true;
}

inline snfCFGData& snfCFGmgr::ActiveData() { // This returns the active dataset.
return (AisActive) ? A : B;
}

inline snfCFGData& snfCFGmgr::InactiveData() { // This returns the inactive dataset.
return (AisActive) ? B : A;
}

inline string snfCFGmgr::RuleFilePath() { // Rulebase file path
return ActiveData().RuleFilePath;
}

inline string snfCFGmgr::SecurityKey() { // Security key for rulebase
return ActiveData().SecurityKey;
}

inline snfCFGData* snfCFGmgr::ActiveConfiguration() { // Pointer to active configuration
return &(ActiveData());
}

Loading…
Cancel
Save