Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

snfCFGmgr.cpp 57KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031
  1. // snfCFGmgr.cpp
  2. // Copyright (C) 2006 - 2009 Arm Research Labs, LLC
  3. // See www.armresearch.com for the copyright terms.
  4. //
  5. // See snfCFGmgr.hpp for details.
  6. #include "snfCFGmgr.hpp"
  7. #include <iostream>
  8. //// RangeHandler //////////////////////////////////////////////////////////////
  9. bool RangeHandler::isInBlack(RangePoint& x) { // Find if x is on the black side.
  10. if(EdgeMap.empty()) { // If there are no points then
  11. return false; // there is no map so there is
  12. } // no side to be on.
  13. // If there are points we will need
  14. set<RangePoint>::iterator iRangePoint; // to examine them.
  15. iRangePoint = EdgeMap.begin(); // What is the first point.
  16. if(x < (*iRangePoint)) { // If x is below that then
  17. return false; // x is out of range -- false.
  18. }
  19. iRangePoint = EdgeMap.end();--iRangePoint; // What is the last range point.
  20. if(x > (*iRangePoint)) { // If x is beyond that then
  21. return false; // x is out of range -- false.
  22. }
  23. // At this point we know our point is in the range of the edge map.
  24. // So our next task is to find the two points between which we will
  25. // interpolate our comparative result.
  26. iRangePoint = EdgeMap.lower_bound(x); // Find the lower point.
  27. if(x < (*iRangePoint)) --iRangePoint; // If we've overshot, then move back.
  28. RangePoint LowerBound = (*iRangePoint); // Grab the value at that point.
  29. iRangePoint = EdgeMap.upper_bound(x); // Find the upper point.
  30. if(iRangePoint == EdgeMap.end()) --iRangePoint; // If we've overshot, then move back.
  31. RangePoint UpperBound = (*iRangePoint); // Grab the value at that point.
  32. // So then, where is x in [Lower, Upper]
  33. // First we check the obvious matching values. Then if those fail we will
  34. // interpolate between the two points.
  35. double ComparativeProbability; // This value will map the edge.
  36. if(x == LowerBound) { // If we match the lower bound then
  37. ComparativeProbability = LowerBound.Probability; // that is the Probability we compare.
  38. } else
  39. if(x == UpperBound) { // If we match the upper bound then
  40. ComparativeProbability = UpperBound.Probability; // that is the Probability we compare.
  41. } else { // For in-between we interpolate.
  42. double ULDifference = UpperBound.Confidence - LowerBound.Confidence; // First, find the difference.
  43. double Incursion = x.Confidence - LowerBound.Confidence; // How far does x go past L to U?
  44. double Ratio = Incursion / ULDifference; // Express that as a ratio.
  45. ComparativeProbability = // Interpolate the Probability using
  46. (((1-Ratio) * LowerBound.Probability) + // a weighted average of the lower and
  47. (Ratio * UpperBound.Probability)); // upper bound values using the Ratio
  48. }
  49. // Now compare x to the interpolated edge.
  50. return (x.Probability >= ComparativeProbability); // True if on or right of the edge.
  51. }
  52. bool RangeHandler::isInWhite(RangePoint& x) {
  53. if(EdgeMap.empty()) { // If there are no points then
  54. return false; // there is no map so there is
  55. } // no side to be on.
  56. // If ther are points then we
  57. set<RangePoint>::iterator iRangePoint; // need to examine them.
  58. iRangePoint = EdgeMap.begin(); // What is the first point.
  59. if(x < (*iRangePoint)) { // If x is below that then
  60. return false; // x is out of range -- false.
  61. }
  62. iRangePoint = EdgeMap.end();--iRangePoint; // What is the last range point.
  63. if(x > (*iRangePoint)) { // If x is beyond that then
  64. return false; // x is out of range -- false.
  65. }
  66. // At this point we know our point is in the range of the edge map.
  67. // So our next task is to find the two points between which we will
  68. // interpolate our comparative result.
  69. iRangePoint = EdgeMap.lower_bound(x); // Find the lower point.
  70. if(x < (*iRangePoint)) --iRangePoint; // If we've overshot, then move back.
  71. RangePoint LowerBound = (*iRangePoint); // Grab the value at that point.
  72. iRangePoint = EdgeMap.upper_bound(x); // Find the upper point.
  73. if(iRangePoint == EdgeMap.end()) --iRangePoint; // If we've overshot, then move back.
  74. RangePoint UpperBound = (*iRangePoint); // Grab the value at that point.
  75. // So then, where is x in [Lower, Upper]
  76. // First we check the obvious matching values. Then if those fail we will
  77. // interpolate between the two points.
  78. double ComparativeProbability; // This value will map the edge.
  79. if(x == LowerBound) { // If we match the lower bound then
  80. ComparativeProbability = LowerBound.Probability; // that is the Probability we compare.
  81. } else
  82. if(x == UpperBound) { // If we match the upper bound then
  83. ComparativeProbability = UpperBound.Probability; // that is the Probability we compare.
  84. } else { // For in-between we interpolate.
  85. double ULDifference = UpperBound.Confidence - LowerBound.Confidence; // First, find the difference.
  86. double Incursion = x.Confidence - LowerBound.Confidence; // How far does x go past L to U?
  87. double Ratio = Incursion / ULDifference; // Express that as a ratio.
  88. ComparativeProbability = // Interpolate the Probability using
  89. (((1-Ratio) * LowerBound.Probability) + // a weighted average of the lower and
  90. (Ratio * UpperBound.Probability)); // upper bound values using the Ratio
  91. }
  92. // Now compare x to the interpolated edge.
  93. return (x.Probability <= ComparativeProbability); // True if on or left of the edge.
  94. }
  95. //// snfCFGData ////////////////////////////////////////////////////////////////
  96. snfCFGData::snfCFGData() : // Constructor. No init list because the
  97. MyCFGReader("snf") { // interpreter will set the defaults.
  98. WhiteRangeInitializer.setTarget(WhiteRangeHandler); // However, we do need to link up our
  99. BlackRangeInitializer.setTarget(BlackRangeHandler); // Initialization configurators with our
  100. CautionRangeInitializer.setTarget(CautionRangeHandler); // Handlers.
  101. RulePanicInitializer.setTarget(RulePanicHandler);
  102. XHDRSymbolHeadersInitializer.setTarget(XHDRSymbolHeaders);
  103. HeaderDirectivesInitializer.setTarget(HeaderDirectivesHandler);
  104. HDSourceHeaderInitializer.setTarget(HeaderDirectivesHandler);
  105. HDDrilldownInitializer.setTarget(HeaderDirectivesHandler);
  106. HDBypassHeaderInitializer.setTarget(HeaderDirectivesHandler);
  107. HDWhiteHeaderInitializer.setTarget(HeaderDirectivesHandler);
  108. TrainingBypassRuleInitializer.setTarget(TrainingBypassRuleHandler);
  109. TrainingWhiteRuleInitializer.setTarget(TrainingWhiteRuleHandler);
  110. MyCFGReader // Building our interpreter.
  111. .Element("node")
  112. .Attribute("identity", node_identity)
  113. .Attribute("licenseid", node_licenseid)
  114. .Attribute("authentication", node_authentication)
  115. .Element("paths")
  116. .Element("workspace")
  117. .Attribute("path", paths_workspace_path)
  118. .End("workspace")
  119. .Element("rulebase")
  120. .Attribute("path", paths_rulebase_path)
  121. .End("rulebase")
  122. .Element("log")
  123. .Attribute("path", paths_log_path)
  124. .End("log")
  125. .End("paths")
  126. .Element("logs")
  127. .Element("rotation")
  128. .Attribute("localtime", Logs_Rotation_LocalTime_OnOff, false)
  129. .Mnemonic("yes", "true")
  130. .Mnemonic("no", "false")
  131. .End("rotation")
  132. .Element("status")
  133. .Element("second")
  134. .Attribute("log", Status_SecondReport_Log_OnOff, false)
  135. .Mnemonic("yes", "true")
  136. .Mnemonic("no", "false")
  137. .Attribute("append", Status_SecondReport_Append_OnOff, false)
  138. .Mnemonic("yes", "true")
  139. .Mnemonic("no", "false")
  140. .End("second")
  141. .Element("minute")
  142. .Attribute("log", Status_MinuteReport_Log_OnOff, false)
  143. .Mnemonic("yes", "true")
  144. .Mnemonic("no", "false")
  145. .Attribute("append", Status_MinuteReport_Append_OnOff, false)
  146. .Mnemonic("yes", "true")
  147. .Mnemonic("no", "false")
  148. .End("minute")
  149. .Element("hour")
  150. .Attribute("log", Status_HourReport_Log_OnOff, false)
  151. .Mnemonic("yes", "true")
  152. .Mnemonic("no", "false")
  153. .Attribute("append", Status_HourReport_Append_OnOff, false)
  154. .Mnemonic("yes", "true")
  155. .Mnemonic("no", "false")
  156. .End("hour")
  157. .End("status")
  158. .Element("scan")
  159. .Element("identifier")
  160. .Attribute("force-message-id", Scan_Identifier_Force_Message_Id, false)
  161. .End("identifier")
  162. .Element("classic")
  163. .Attribute("mode", Scan_Classic_Mode, LogOutputMode_None)
  164. .Mnemonic("none", "0")
  165. .Mnemonic("api", "1")
  166. .Mnemonic("file", "2")
  167. .Attribute("rotate", Scan_Classic_Rotate, false)
  168. .Attribute("matches", Scan_Classic_Matches, ScanLogMatches_None)
  169. .Mnemonic("none", "0")
  170. .Mnemonic("unique", "1")
  171. .Mnemonic("all","2")
  172. .End("classic")
  173. .Element("xml")
  174. .Attribute("mode", Scan_XML_Mode, LogOutputMode_None)
  175. .Mnemonic("none", "0")
  176. .Mnemonic("api", "1")
  177. .Mnemonic("file", "2")
  178. .Attribute("rotate", Scan_XML_Rotate, false)
  179. .Attribute("matches", Scan_XML_Matches, ScanLogMatches_None)
  180. .Mnemonic("none", "0")
  181. .Mnemonic("unique", "1")
  182. .Mnemonic("all","2")
  183. .Attribute("performance", Scan_XML_Performance, false)
  184. .Attribute("gbudb", Scan_XML_GBUdb, false)
  185. .End("xml")
  186. .Element("xheaders")
  187. .atStartCall(XHDRSymbolHeadersInitializer)
  188. .Element("output")
  189. .Attribute("mode", XHDROutput_Mode, LogOutputMode_None)
  190. .Mnemonic("none", "0")
  191. .Mnemonic("api", "1")
  192. .Mnemonic("file", "2")
  193. .Mnemonic("inject", "3")
  194. .End("output")
  195. .Element("symbol", XHDRSymbolHeaders.Header, "")
  196. .atEndCall(XHDRSymbolHeaders)
  197. .Attribute("on-off", XHDRSymbolHeaders.OnOff, false)
  198. .Mnemonic("on", "true")
  199. .Mnemonic("off", "false")
  200. .Attribute("n", XHDRSymbolHeaders.Symbol, -1)
  201. .End("symbol")
  202. .Element("version", XHDRVersion_Header, "")
  203. .Attribute("on-off", XHDRVersion_OnOff, false)
  204. .Mnemonic("on", "true")
  205. .Mnemonic("off", "false")
  206. .End("version")
  207. .Element("license", XHDRLicense_Header, "")
  208. .Attribute("on-off", XHDRLicense_OnOff, false)
  209. .Mnemonic("on", "true")
  210. .Mnemonic("off", "false")
  211. .End("license")
  212. .Element("rulebase", XHDRRulebase_Header, "")
  213. .Attribute("on-off", XHDRRulebase_OnOff, false)
  214. .Mnemonic("on", "true")
  215. .Mnemonic("off", "false")
  216. .End("rulebase")
  217. .Element("identifier", XHDRIdentifier_Header, "")
  218. .Attribute("on-off", XHDRIdentifier_OnOff, false)
  219. .Mnemonic("on", "true")
  220. .Mnemonic("off", "false")
  221. .End("identifier")
  222. .Element("gbudb", XHDRGBUdb_Header, "")
  223. .Attribute("on-off", XHDRGBUdb_OnOff, false)
  224. .Mnemonic("on", "true")
  225. .Mnemonic("off", "false")
  226. .End("gbudb")
  227. .Element("result", XHDRResult_Header, "")
  228. .Attribute("on-off", XHDRResult_OnOff, false)
  229. .Mnemonic("on", "true")
  230. .Mnemonic("off", "false")
  231. .End("result")
  232. .Element("matches", XHDRMatches_Header, "")
  233. .Attribute("on-off", XHDRMatches_OnOff, false)
  234. .Mnemonic("on", "true")
  235. .Mnemonic("off", "false")
  236. .End("matches")
  237. .Element("black", XHDRBlack_Header, "")
  238. .Attribute("on-off", XHDRBlack_OnOff, false)
  239. .Mnemonic("on", "true")
  240. .Mnemonic("off", "false")
  241. .End("black")
  242. .Element("white", XHDRWhite_Header, "")
  243. .Attribute("on-off", XHDRWhite_OnOff, false)
  244. .Mnemonic("on", "true")
  245. .Mnemonic("off", "false")
  246. .End("white")
  247. .Element("clean", XHDRClean_Header, "")
  248. .Attribute("on-off", XHDRClean_OnOff, false)
  249. .Mnemonic("on", "true")
  250. .Mnemonic("off", "false")
  251. .End("clean")
  252. .End("xheaders")
  253. .End("scan")
  254. .End("logs")
  255. .Element("network")
  256. .Element("sync")
  257. .Attribute("secs", network_sync_secs, 30)
  258. .Attribute("host", network_sync_host, "sync.messagesniffer.net")
  259. .Attribute("port", network_sync_port, 25)
  260. .End("sync")
  261. .Element("update-script")
  262. .Attribute("on-off", update_script_on_off, false)
  263. .Mnemonic("on", "true")
  264. .Mnemonic("off", "false")
  265. .Attribute("call", update_script_call, "")
  266. .Attribute("guard-time", update_script_guard_time, 180)
  267. .End("update-script")
  268. .End("network")
  269. .Element("xci")
  270. .Attribute("on-off", XCI_OnOff, true)
  271. .Mnemonic("on", "true")
  272. .Mnemonic("off", "false")
  273. .Attribute("port", XCI_Port, 9001)
  274. .End("xci")
  275. .Element("gbudb")
  276. .Element("database")
  277. .Element("condense")
  278. .Attribute("minimum-seconds-between", gbudb_database_condense_minimum_seconds_between, 600)
  279. .Element("time-trigger")
  280. .Attribute("on-off", gbudb_database_condense_time_trigger_on_off, true)
  281. .Mnemonic("on", "true")
  282. .Mnemonic("off", "false")
  283. .Attribute("seconds", gbudb_database_condense_time_trigger_seconds, 84600)
  284. .End("time-trigger")
  285. .Element("posts-trigger")
  286. .Attribute("on-off", gbudb_database_condense_posts_trigger_on_off, false)
  287. .Mnemonic("on", "true")
  288. .Mnemonic("off", "false")
  289. .Attribute("posts", gbudb_database_condense_posts_trigger_posts, 32768)
  290. .End("posts-trigger")
  291. .Element("records-trigger")
  292. .Attribute("on-off", gbudb_database_condense_records_trigger_on_off, false)
  293. .Mnemonic("on", "true")
  294. .Mnemonic("off", "false")
  295. .Attribute("records", gbudb_database_condense_records_trigger_records, 150000)
  296. .End("records-trigger")
  297. .Element("size-trigger")
  298. .Attribute("on-off", gbudb_database_condense_size_trigger_on_off, false)
  299. .Mnemonic("on", "true")
  300. .Mnemonic("off", "false")
  301. .Attribute("megabytes", gbudb_database_condense_size_trigger_megabytes, 150)
  302. .End("size-trigger")
  303. .End("condense")
  304. .Element("checkpoint")
  305. .Attribute("on-off", gbudb_database_checkpoint_on_off, true)
  306. .Mnemonic("on", "true")
  307. .Mnemonic("off", "false")
  308. .Attribute("secs", gbudb_database_checkpoint_secs, 3600)
  309. .End("checkpoint")
  310. .End("database")
  311. .Element("regions")
  312. .Element("white")
  313. .atStartCall(WhiteRangeInitializer)
  314. .Attribute("on-off", WhiteRangeHandler.On_Off, true)
  315. .Mnemonic("on", "true")
  316. .Mnemonic("off", "false")
  317. .Attribute("symbol", WhiteRangeHandler.Symbol, 0)
  318. .Attribute("priority", WhiteRangeHandler.Priority, 1)
  319. .Element("edge")
  320. .atEndCall(WhiteRangeHandler)
  321. .Attribute("probability", WhiteRangeHandler.EdgeInput.Probability, 0.0)
  322. .Attribute("confidence", WhiteRangeHandler.EdgeInput.Confidence, 0.0)
  323. .End("edge")
  324. .Element("panic")
  325. .Attribute("on-off", gbudb_regions_white_panic_on_off, true)
  326. .Mnemonic("on", "true")
  327. .Mnemonic("off", "false")
  328. .Attribute("rule-range", gbudb_regions_white_panic_rule_range, 1000)
  329. .End("panic")
  330. .End("white")
  331. .Element("black")
  332. .atStartCall(BlackRangeInitializer)
  333. .Attribute("on-off", BlackRangeHandler.On_Off, true)
  334. .Mnemonic("on", "true")
  335. .Mnemonic("off", "false")
  336. .Attribute("symbol", BlackRangeHandler.Symbol, 63)
  337. .mapTo(gbudb_regions_black_truncate_symbol, 63)
  338. .Attribute("priority", BlackRangeHandler.Priority, 2)
  339. .Element("edge")
  340. .atEndCall(BlackRangeHandler)
  341. .Attribute("probability", BlackRangeHandler.EdgeInput.Probability, 0.0)
  342. .Attribute("confidence", BlackRangeHandler.EdgeInput.Confidence, 0.0)
  343. .End("edge")
  344. .Element("truncate")
  345. .Attribute("on-off", gbudb_regions_black_truncate_on_off, true)
  346. .Mnemonic("on", "true")
  347. .Mnemonic("off", "false")
  348. .Attribute("probability", gbudb_regions_black_truncate_probability, 0.5)
  349. .Attribute("peek-one-in", gbudb_regions_black_truncate_peek_one_in, 3)
  350. .Attribute("symbol", gbudb_regions_black_truncate_symbol, 63)
  351. .End("truncate")
  352. .Element("sample")
  353. .Attribute("on-off", gbudb_regions_black_sample_on_off, true)
  354. .Mnemonic("on", "true")
  355. .Mnemonic("off", "false")
  356. .Attribute("probability", gbudb_regions_black_sample_probability, 0.5)
  357. .Attribute("grab-one-in", gbudb_regions_black_sample_grab_one_in, 10)
  358. .Attribute("passthrough", gbudb_regions_black_sample_passthrough, false)
  359. .Attribute("passthrough-symbol", gbudb_regions_black_sample_passthrough_symbol, 0)
  360. .End("sample")
  361. .End("black")
  362. .Element("caution")
  363. .atStartCall(CautionRangeInitializer)
  364. .Attribute("on-off", CautionRangeHandler.On_Off, true)
  365. .Mnemonic("on", "true")
  366. .Mnemonic("off", "false")
  367. .Attribute("symbol", CautionRangeHandler.Symbol, 30)
  368. .Attribute("priority", CautionRangeHandler.Priority, 3)
  369. .Element("edge")
  370. .atEndCall(CautionRangeHandler)
  371. .Attribute("probability", CautionRangeHandler.EdgeInput.Probability, 0.0)
  372. .Attribute("confidence", CautionRangeHandler.EdgeInput.Confidence, 0.0)
  373. .End("edge")
  374. .End("caution")
  375. .End("regions")
  376. .Element("training")
  377. .atStartCall(HeaderDirectivesInitializer)
  378. .Attribute("on-off", GBUdbTrainingOn_Off, true)
  379. .Mnemonic("on", "true")
  380. .Mnemonic("off", "false")
  381. .Element("source")
  382. .Element("header")
  383. .atStartCall(HDSourceHeaderInitializer)
  384. .atEndCall(HeaderDirectivesHandler)
  385. .Attribute("name", HeaderDirectivesHandler.DirectiveInput.Header, "\n\n")
  386. .Attribute("received", HeaderDirectivesHandler.ContextInput.Contains, "\n\n")
  387. .Attribute("ordinal", HeaderDirectivesHandler.ContextInput.Ordinal, 0)
  388. .End("header")
  389. .End("source")
  390. .Element("drilldown")
  391. .Element("received")
  392. .atStartCall(HDDrilldownInitializer)
  393. .atEndCall(HeaderDirectivesHandler)
  394. .Attribute("ordinal", HeaderDirectivesHandler.DirectiveInput.Ordinal, 0)
  395. .Attribute("find", HeaderDirectivesHandler.DirectiveInput.Contains, "\n\n")
  396. .End("received")
  397. .End("drilldown")
  398. .Element("bypass")
  399. .atStartCall(TrainingBypassRuleInitializer)
  400. .Element("result")
  401. .atEndCall(TrainingBypassRuleHandler)
  402. .Attribute("code", TrainingBypassRuleHandler.IntegerInput,-1)
  403. .End("result")
  404. .Element("header")
  405. .atStartCall(HDBypassHeaderInitializer)
  406. .atEndCall(HeaderDirectivesHandler)
  407. .Attribute("name", HeaderDirectivesHandler.DirectiveInput.Header, "\n\n")
  408. .Attribute("ordinal", HeaderDirectivesHandler.DirectiveInput.Ordinal, 0)
  409. .Attribute("find", HeaderDirectivesHandler.DirectiveInput.Contains, "\n\n")
  410. .End("header")
  411. .End("bypass")
  412. .Element("white")
  413. .atStartCall(TrainingWhiteRuleInitializer)
  414. .Element("result")
  415. .atEndCall(TrainingWhiteRuleHandler)
  416. .Attribute("code", TrainingWhiteRuleHandler.IntegerInput,-1)
  417. .End("result")
  418. .Element("header")
  419. .atStartCall(HDWhiteHeaderInitializer)
  420. .atEndCall(HeaderDirectivesHandler)
  421. .Attribute("name", HeaderDirectivesHandler.DirectiveInput.Header, "\n\n")
  422. .Attribute("ordinal", HeaderDirectivesHandler.DirectiveInput.Ordinal, 0)
  423. .Attribute("find", HeaderDirectivesHandler.DirectiveInput.Contains, "\n\n")
  424. .End("header")
  425. .End("white")
  426. .End("training")
  427. .End("gbudb")
  428. .Element("rule-panics")
  429. .atStartCall(RulePanicInitializer)
  430. .Element("rule")
  431. .atEndCall(RulePanicHandler)
  432. .Attribute("id", RulePanicHandler.IntegerInput, -1)
  433. .End("rule")
  434. .End("rule-panics")
  435. .Element("platform", PlatformElementContents, "")
  436. .End("platform")
  437. .Element("msg-file")
  438. .Attribute("type", MessageFileTypeCGP_on_off, false)
  439. .Mnemonic("cgp", "true")
  440. .End("msg-file")
  441. .End("node")
  442. .End("snf");
  443. }
  444. void fixPathTermination(string& s) { // Ensure s ends in a / or a \ as needed.
  445. if(0 == s.length()) return; // If the string is empty we do nothing.
  446. // Determine what our path terminator should be by looking to
  447. // see what separator has already been used.
  448. char Terminator; // This will be our terminator.
  449. if(string::npos == s.find('\\')) { // If we're not using a backslash then
  450. Terminator = '/'; // we will use the forward slash.
  451. } else { // If we are using the backslash then
  452. Terminator = '\\'; // we will remain consistent and terminate
  453. } // with a backslash.
  454. // If the path that's given doesn't have a terminator then we will add
  455. // the appropriate separator to the end.
  456. if( // If the string is
  457. '\\' != s.at(s.length()-1) && // not terminated by a backslash nor
  458. '/' != s.at(s.length()-1) // by a forward slash then
  459. ) { // we will append an appropriate
  460. s.append(1,Terminator); // terminator. Otherwise we will
  461. } // leave it as it is.
  462. }
  463. void snfCFGData::initializeFromFile(const char* FileName) { // Initialize from the provided file.
  464. ConfigurationData MyCFGData(FileName); // Create a cfg data object from the file.
  465. if(0 == MyCFGData.Data(0)) throw false; // If we didn't read a config file throw!
  466. MyCFGReader.initialize(); // Initialize to defaults.
  467. MyCFGReader.interpret(MyCFGData); // Interpret the data.
  468. fixPathTermination(paths_log_path); // Automagically fix / or \ termination
  469. fixPathTermination(paths_rulebase_path); // for the paths provided in the
  470. fixPathTermination(paths_workspace_path); // configuration <path/> section.
  471. ConfigFilePath = FileName; // Set the ConfigFilePath for what we read.
  472. }
  473. snfIPRange snfCFGData::RangeEvaluation(GBUdbRecord& R) { // Returns the range for a GBUdbRecord.
  474. if(Good == R.Flag()) { // If the flag on the IP is Good
  475. return White; // then this IP is automatically white.
  476. } else
  477. if(Bad == R.Flag()) { // If the flag on this IP is Bad
  478. if(true == gbudb_regions_black_truncate_on_off) { // and truncate is turned on then
  479. return Truncate; // the IP is automatically in the
  480. } else { // truncate range. If truncate is off
  481. return Black; // then this IP is automatically black.
  482. }
  483. }
  484. // If it's not so simple then get a
  485. RangePoint P(R.Confidence(), R.Probability()); // range point and evaluate it that way.
  486. return RangeEvaluation(P);
  487. }
  488. snfIPRange snfCFGData::RangeEvaluation(RangePoint& p) { // Returns the range for a RangePoint.
  489. if( // If the IP is unknown, indicated
  490. 0.0 == p.Confidence && // by a zero confidence and
  491. 0.0 == p.Probability // a zero probability, then
  492. ) { // the range point cannot be "in"
  493. return New; // any range.
  494. }
  495. if(WhiteRangeHandler.isInWhite(p)) { // If it's in the white range,
  496. return White; // return White.
  497. } else // White has priority over all others.
  498. if(BlackRangeHandler.isInBlack(p)) { // If it's in the black range then
  499. if(p.Probability >= gbudb_regions_black_truncate_probability) { // determine if it's also in the truncate
  500. return Truncate; // range, and if so - send back Truncate.
  501. } else { // If not then we can send back a
  502. return Black; // normal black result.
  503. }
  504. } else // Black takes precedence over caution.
  505. if(CautionRangeHandler.isInBlack(p)) { // If we're in the caution range
  506. return Caution; // then return caution.
  507. } // If none of those ranges matched then
  508. return Normal; // the IP is in the normal range.
  509. }
  510. //// snfCFGmgr /////////////////////////////////////////////////////////////////
  511. void snfCFGmgr::initialize( // Initialize our configuration data.
  512. const char* FileName,
  513. const char* LicenseId,
  514. const char* Authentication) {
  515. // Check for NULLs and assign Init parameters
  516. InitFileName = (NULL==FileName)?"":FileName; // Initilization parameters are reused
  517. InitLicenseId = (NULL==LicenseId)?"":LicenseId; // any time load() is called.
  518. InitAuthentication = (NULL==Authentication)?"":Authentication;
  519. }
  520. //// When the license ID and security string come from an OEM application they
  521. //// may not appear in the configuration files. If that is the case we will assume
  522. //// that they developer wants to keep the security string secret by encrypting it
  523. //// in their application and providing it to SNF at runtime. In that case we will
  524. //// not display the security key in the configuration log.
  525. ////
  526. //// To prevent hacking attempts, if the authentication information appears to be
  527. //// provided by configuration data then we will build the string from that data.
  528. //// that way an attacker can't trick the application into disclosing the true
  529. //// authentication string -- they will only get out what they put in.
  530. string SecurityKeyDisplayString(snfCFGData& D) { // Returns appropriate SecurityKey: data
  531. string ConfigLogSecurityKey = "************************"; // Start with a masked display.
  532. if(0 < D.node_licenseid.length()) { // If auth info is in the config files then
  533. ConfigLogSecurityKey = D.node_licenseid + D.node_authentication; // build up the key from that data so it
  534. } // can be displayed in the config log.
  535. return ConfigLogSecurityKey;
  536. }
  537. void logCFGData(snfCFGData& D) { // Log interpreted cfg data (debug aid).
  538. try {
  539. string CFGLogPath; // Build the snf_cfg log path.
  540. CFGLogPath = D.paths_log_path +
  541. D.node_licenseid + "_snf_engine_cfg.log";
  542. ofstream cfgl(CFGLogPath.c_str(), ios::trunc); // Open and truncate the cfg log file.
  543. cfgl // Report important cfg information.
  544. << "SNF Engine Configuration" << endl
  545. << "____________" << endl
  546. << "Fundamentals" << endl
  547. << " License: " << D.node_licenseid << endl
  548. << " ConfigFilePath: " << D.ConfigFilePath << endl
  549. << " IdentityFilePath: " << D.node_identity << endl
  550. << " SecurityKey: " << SecurityKeyDisplayString(D) << endl
  551. << "_____" << endl
  552. << "Paths" << endl
  553. << " Log Path: " << D.paths_log_path << endl
  554. << " Rulebase Path: " << D.paths_rulebase_path << endl
  555. << " Workspace Path: " << D.paths_workspace_path << endl
  556. << " RuleFilePath: " << D.RuleFilePath << endl
  557. << "____" << endl
  558. << "Logs" << endl
  559. << endl
  560. << " Rotation-Midnight: " << ((D.Logs_Rotation_LocalTime_OnOff)? "Local" : "UTC") << endl
  561. << " ______" << endl
  562. << " Status" << endl
  563. << " PerSecond: "
  564. << ((D.Status_SecondReport_Log_OnOff)? "yes, " : "no, ")
  565. << "Append: "
  566. << ((D.Status_SecondReport_Append_OnOff)? "yes" : "no")
  567. << endl
  568. << " PerMinute: "
  569. << ((D.Status_MinuteReport_Log_OnOff)? "yes, " : "no, ")
  570. << "Append: "
  571. << ((D.Status_MinuteReport_Append_OnOff)? "yes" : "no")
  572. << endl
  573. << " PerHour: "
  574. << ((D.Status_HourReport_Log_OnOff)? "yes, " : "no, ")
  575. << "Append: "
  576. << ((D.Status_HourReport_Append_OnOff)? "yes" : "no")
  577. << endl
  578. << " ____" << endl
  579. << " Scan" << endl
  580. << " Identifier: "
  581. << ((D.Scan_Identifier_Force_Message_Id)? "Force RFC822 Message-ID" : "Use Provided Identifier")
  582. << endl
  583. << " Classic: Output-"
  584. << ((LogOutputMode_None == D.Scan_Classic_Mode)? "None, " :
  585. ((LogOutputMode_API == D.Scan_Classic_Mode)? "API, " :
  586. ((LogOutputMode_File == D.Scan_Classic_Mode)? "File, " : "Error!")))
  587. << ((D.Scan_Classic_Rotate)? "Rotating, ": "Non-Rotating, ")
  588. << ((D.Scan_Classic_Matches == ScanLogMatches_None) ? "No Mathes":
  589. ((D.Scan_Classic_Matches == ScanLogMatches_Unique) ? "Unique Matches":
  590. ((D.Scan_Classic_Matches == ScanLogMatches_All) ? "All Matches" : "Error!")))
  591. << endl
  592. << " XML: Output-"
  593. << ((LogOutputMode_None == D.Scan_XML_Mode)? "None, " :
  594. ((LogOutputMode_API == D.Scan_XML_Mode)? "API, " :
  595. ((LogOutputMode_File == D.Scan_XML_Mode)? "File, " : "Error!")))
  596. << ((D.Scan_XML_Rotate)? "Rotating, ": "Non-Rotating, ")
  597. << ((D.Scan_XML_Matches == ScanLogMatches_None) ? "No Mathes, ":
  598. ((D.Scan_XML_Matches == ScanLogMatches_Unique) ? "Unique Matches, ":
  599. ((D.Scan_XML_Matches == ScanLogMatches_All) ? "All Matches, " : "Match Error! ")))
  600. << ((D.Scan_XML_Performance)? "Performance Metrics, " : "No Performance Metrics, ")
  601. << ((D.Scan_XML_GBUdb)? "GBUdb Data" : "No GBUdb Data")
  602. << endl
  603. << " XHeaders:" << endl
  604. << " Output: "
  605. << ((LogOutputMode_None == D.XHDROutput_Mode) ? "None" :
  606. ((LogOutputMode_API == D.XHDROutput_Mode) ? "API" :
  607. ((LogOutputMode_File == D.XHDROutput_Mode) ? "File" :
  608. ((LogOutputMode_Inject == D.XHDROutput_Mode)? "Inject" : "Error!"))))
  609. << endl
  610. << " Version: "
  611. << ((D.XHDRVersion_OnOff)? "On, " : "Off, ")
  612. << D.XHDRVersion_Header
  613. << endl
  614. << " License: "
  615. << ((D.XHDRLicense_OnOff)? "On, " : "Off, ")
  616. << D.XHDRLicense_Header
  617. << endl
  618. << " Rulebase: "
  619. << ((D.XHDRRulebase_OnOff)? "On, " : "Off, ")
  620. << D.XHDRRulebase_Header
  621. << endl
  622. << " Identifier: "
  623. << ((D.XHDRIdentifier_OnOff)? "On, " : "Off, ")
  624. << D.XHDRIdentifier_Header
  625. << endl
  626. << " GBUdb: "
  627. << ((D.XHDRGBUdb_OnOff)? "On, " : "Off, ")
  628. << D.XHDRGBUdb_Header
  629. << endl
  630. << " Result: "
  631. << ((D.XHDRResult_OnOff)? "On, " : "Off, ")
  632. << D.XHDRResult_Header
  633. << endl
  634. << " Matches: "
  635. << ((D.XHDRMatches_OnOff)? "On, " : "Off, ")
  636. << D.XHDRMatches_Header
  637. << endl
  638. << " Black: "
  639. << ((D.XHDRBlack_OnOff)? "On, " : "Off, ")
  640. << D.XHDRBlack_Header
  641. << endl
  642. << " White: "
  643. << ((D.XHDRWhite_OnOff)? "On, " : "Off, ")
  644. << D.XHDRWhite_Header
  645. << endl
  646. << " Clean: "
  647. << ((D.XHDRClean_OnOff)? "On, " : "Off, ")
  648. << D.XHDRClean_Header
  649. << endl;
  650. for(
  651. set<XHDRSymbol>::iterator iH = D.XHDRSymbolHeaders.SymbolHeaders.begin();
  652. iH != D.XHDRSymbolHeaders.SymbolHeaders.end(); iH++
  653. ) {
  654. cfgl
  655. << " Symbol: "
  656. << (*iH).Symbol << ", "
  657. << (*iH).Header
  658. << endl;
  659. }
  660. cfgl
  661. << "_______" << endl
  662. << "Network" << endl
  663. << " Sync Host: " << D.network_sync_host << endl
  664. << " Sync Port: " << D.network_sync_port << endl
  665. << " Sync Secs: " << D.network_sync_secs << endl
  666. << " _____________" << endl
  667. << " Update-Script" << endl
  668. << " On-Off: " << ((D.update_script_on_off) ? "On" : "Off") << endl
  669. << " Script: " << D.update_script_call << endl
  670. << " Guard-Time: " << D.update_script_guard_time << " seconds" << endl
  671. << "___" << endl
  672. << "XCI" << endl
  673. << " " << ((D.XCI_OnOff)? "Enabled" : "Disabled") << endl
  674. << " Port: " << D.XCI_Port << endl
  675. << "_____" << endl
  676. << "GBUdb" << endl
  677. << " ____________" << endl
  678. << " Condensation" << endl
  679. << " Minimum-Seconds-Between = " << D.gbudb_database_condense_minimum_seconds_between << endl
  680. << " Time-Trigger: "
  681. << ((D.gbudb_database_condense_time_trigger_on_off)? "on, " : "off, ")
  682. << D.gbudb_database_condense_time_trigger_seconds << " seconds" << endl
  683. << " Posts-Trigger: "
  684. << ((D.gbudb_database_condense_posts_trigger_on_off)? "on, " : "off, ")
  685. << D.gbudb_database_condense_posts_trigger_posts << " posts" << endl
  686. << " Records-Trigger: "
  687. << ((D.gbudb_database_condense_records_trigger_on_off) ? "on, " : "off, ")
  688. << D.gbudb_database_condense_records_trigger_records << " records" << endl
  689. << " Size-Trigger: "
  690. << ((D.gbudb_database_condense_size_trigger_on_off) ? "on, " : "off, ")
  691. << D.gbudb_database_condense_size_trigger_megabytes << " megabytes" << endl
  692. << " __________" << endl
  693. << " Checkpoint" << endl
  694. << " Checkpoint: "
  695. << ((D.gbudb_database_checkpoint_on_off) ? "on, " : "off, ")
  696. << D.gbudb_database_checkpoint_secs << " seconds" << endl
  697. << " ______" << endl
  698. << " Ranges" << endl
  699. << " White: "
  700. << ((D.WhiteRangeHandler.On_Off) ? "on, " : "off, ")
  701. << "Symbol " << D.WhiteRangeHandler.Symbol << endl
  702. << " Auto-Panic: "
  703. << ((D.gbudb_regions_white_panic_on_off) ? "on, " : "off, ")
  704. << "Range " << D.gbudb_regions_white_panic_rule_range << endl
  705. << endl
  706. << " Caution: "
  707. << ((D.CautionRangeHandler.On_Off) ? "on, " : "off, ")
  708. << "Symbol " << D.CautionRangeHandler.Symbol << endl
  709. << endl
  710. << " Black: "
  711. << ((D.BlackRangeHandler.On_Off) ? "on, " : "off, ")
  712. << "Symbol " << D.BlackRangeHandler.Symbol << endl
  713. << " Truncate: "
  714. << ((D.gbudb_regions_black_truncate_on_off) ? "on, " : "off, ")
  715. << "Probability " << D.gbudb_regions_black_truncate_probability << ", "
  716. << "Peek-One-In " << D.gbudb_regions_black_truncate_peek_one_in << ", "
  717. << "Symbol " << D.gbudb_regions_black_truncate_symbol << endl
  718. << " Sample: "
  719. << ((D.gbudb_regions_black_sample_on_off) ? "on, " : "off, ")
  720. << "Probability: " << D.gbudb_regions_black_sample_probability << ", "
  721. << "Grab-One-In: " << D.gbudb_regions_black_sample_grab_one_in << ", " << endl
  722. << " Passthrough: "
  723. << ((D.gbudb_regions_black_sample_passthrough) ? "yes, " : "no, ")
  724. << "Passthrough Symbol " << D.gbudb_regions_black_sample_passthrough_symbol << endl
  725. << endl
  726. << " Range Map - [W]hite [B]lack [C]aution [ ]undefined" << endl << endl
  727. << " |-9876543210123456789+|" << endl;
  728. // Output GBUdb Range Map
  729. for(double c = 0; c < 1.01; c+=0.1) { // Run through the confidence
  730. cfgl << " |";
  731. for(double p = -1.0; p < 1.01; p+=0.1) { // and probability ranges.
  732. RangePoint t(c,p); // Test the range point w/ c & p
  733. if(D.WhiteRangeHandler.isInWhite(t)) { // If it's in the white range
  734. cfgl << "W"; // put in a W.
  735. } else
  736. if(D.BlackRangeHandler.isInBlack(t)) { // If it's in the black range
  737. cfgl << "B"; // put in a B.
  738. } else
  739. if(D.CautionRangeHandler.isInBlack(t)) { // If it's in the caution range
  740. cfgl << "C"; // put in a C.
  741. } else {
  742. cfgl << " "; // Otherwise put in a space.
  743. }
  744. }
  745. cfgl << "|" << c << endl;
  746. }
  747. cfgl << " |---------------------|" << endl;
  748. cfgl
  749. << endl
  750. << " ________" << endl
  751. << " Training" << endl
  752. << " GBUdb Updates: "
  753. << ((D.GBUdbTrainingOn_Off)? "Enabled" : "Disabled") << endl
  754. << endl;
  755. cfgl
  756. << " Source Header Directives: " << endl;
  757. for(
  758. HeaderDirectiveSet::iterator iD = D.HeaderDirectivesHandler.HeaderDirectives.begin();
  759. iD != D.HeaderDirectivesHandler.HeaderDirectives.end(); iD++
  760. ) {
  761. const HeaderFinderPattern& Dx = *iD;
  762. if(HeaderDirectiveContext == Dx.Directive) {
  763. cfgl
  764. << " "
  765. << "Context " << Dx.Context << " is a "
  766. << Dx.Header << " header at"
  767. << " Ordinal " << Dx.Ordinal
  768. << " that Contains " << Dx.Contains << endl;
  769. } else
  770. if(HeaderDirectiveSource == Dx.Directive) {
  771. cfgl
  772. << " "
  773. << "Context " << Dx.Context << " Source ip is in "
  774. << Dx.Header << " header at"
  775. << " Ordinal " << Dx.Ordinal << endl;
  776. }
  777. }
  778. cfgl << endl;
  779. cfgl
  780. << " Drilldown Header Directives: " << endl;
  781. for(
  782. HeaderDirectiveSet::iterator iD = D.HeaderDirectivesHandler.HeaderDirectives.begin();
  783. iD != D.HeaderDirectivesHandler.HeaderDirectives.end(); iD++
  784. ) {
  785. const HeaderFinderPattern& Dx = *iD;
  786. if(HeaderDirectiveDrillDown == Dx.Directive) {
  787. cfgl
  788. << " "
  789. << Dx.Header << " header at"
  790. << " Ordinal " << Dx.Ordinal
  791. << " Contains " << Dx.Contains << endl;
  792. }
  793. }
  794. cfgl << endl;
  795. cfgl
  796. << " Bypass Header Directives: " << endl;
  797. for(
  798. HeaderDirectiveSet::iterator iD = D.HeaderDirectivesHandler.HeaderDirectives.begin();
  799. iD != D.HeaderDirectivesHandler.HeaderDirectives.end(); iD++
  800. ) {
  801. const HeaderFinderPattern& Dx = *iD;
  802. if(HeaderDirectiveBypass == Dx.Directive) {
  803. cfgl
  804. << " "
  805. << Dx.Header << " header at"
  806. << " Ordinal " << Dx.Ordinal
  807. << " Contains " << Dx.Contains << endl;
  808. }
  809. }
  810. cfgl << endl;
  811. cfgl
  812. << " White Rule Header Directives: " << endl;
  813. for(
  814. HeaderDirectiveSet::iterator iD = D.HeaderDirectivesHandler.HeaderDirectives.begin();
  815. iD != D.HeaderDirectivesHandler.HeaderDirectives.end(); iD++
  816. ) {
  817. const HeaderFinderPattern& Dx = *iD;
  818. if(HeaderDirectiveWhite == Dx.Directive) {
  819. cfgl
  820. << " "
  821. << Dx.Header << " header at"
  822. << " Ordinal " << Dx.Ordinal
  823. << " Contains " << Dx.Contains << endl;
  824. }
  825. }
  826. cfgl << endl;
  827. cfgl
  828. << " White Rule Symbols: ";
  829. // Output white rule symbols
  830. for(
  831. set<int>::iterator ix = D.TrainingWhiteRuleHandler.IntegerSet.begin();
  832. ix != D.TrainingWhiteRuleHandler.IntegerSet.end();
  833. ix ++) {
  834. if(D.TrainingWhiteRuleHandler.IntegerSet.begin() != ix) {
  835. cfgl << ", ";
  836. }
  837. cfgl << (*ix);
  838. }
  839. cfgl << endl;
  840. // Rule Panics
  841. cfgl
  842. << "___________" << endl
  843. << "Rule-Panics" << endl;
  844. for(
  845. set<int>::iterator ix = D.RulePanicHandler.IntegerSet.begin();
  846. ix != D.RulePanicHandler.IntegerSet.end();
  847. ix ++) {
  848. cfgl << " Rule ID: " << (*ix) << endl;
  849. }
  850. cfgl << endl;
  851. cfgl
  852. << "___________" << endl
  853. << "Integration" << endl
  854. << endl
  855. << " Message Format: "
  856. << ((D.MessageFileTypeCGP_on_off)? "CGP" : "RFC822")
  857. << endl;
  858. #ifdef __BIG_ENDIAN__
  859. cfgl << " Rulebase Conversion: BIG ENDIAN" << endl;
  860. #else
  861. cfgl << " Rulebase Conversion: LITTLE ENDIAN" << endl;
  862. #endif
  863. cfgl
  864. << "________" << endl
  865. << "Platform" << endl
  866. << D.PlatformElementContents
  867. << endl;
  868. cfgl << endl; // End with a new line.
  869. cfgl.close(); // Close the cfg log file.
  870. } catch (...) {} // Ignore any errors.
  871. }
  872. void snfCFGmgr::load() {
  873. // What shall we configure -- the inactive snfCFGData.
  874. snfCFGData& CFGData = InactiveData();
  875. // How shall we configure?
  876. // If FileName ends in .snf then find the .cfg file for details.
  877. // If the FileName ends some other way it _should_ be our cfg file.
  878. int PathLength = InitFileName.length(); // How long is the path?
  879. const int MinimumPathLength = 12; // Must be at least licensid.snf long.
  880. if(MinimumPathLength > PathLength) throw LoadFailure(); // Path length is impossible? throw!
  881. const string SNFExt = ".snf"; // The extension we are looking for.
  882. const string CFGExt = ".xml"; // The default cfg extension.
  883. const int SNFExtLength = SNFExt.length(); // The length of the extension.
  884. int SNFExtPosition = InitFileName.rfind(SNFExt,PathLength); // Find the extension at the end.
  885. bool InitPathIsRulebase = false; // Was the init FileName the Rulebase?
  886. bool InitLicenseIdIsProvided = (0 < InitLicenseId.length()); // Was the init LicenseId provided?
  887. bool InitAuthenticationIsProvided = (0 < InitAuthentication.length()); // Was the authentication provided?
  888. if((PathLength - SNFExtLength) == SNFExtPosition) { // If path ends in .snf then
  889. InitPathIsRulebase = true; // set our flag to keep track then set
  890. ConfigurationPath = InitFileName.substr(0,SNFExtPosition); // our configuration path as the init
  891. ConfigurationPath.append(CFGExt); // file name with the config extension.
  892. } else { // If the init file is not a rulebase
  893. ConfigurationPath = InitFileName; // then it is the config file name.
  894. }
  895. // At this point we know where to read our configuration from.
  896. try { CFGData.initializeFromFile(ConfigurationPath.c_str()); } // Initialize the inactive config.
  897. catch(...) { // If that failed then throw.
  898. throw LoadFailure();
  899. }
  900. // Now that the main config has been read we create the derived cfg data.
  901. // Anything that was provided in Init takes precedence over the config.
  902. //// SecurityKey
  903. //// If an identity path has been provided we must load that data.
  904. if(0 < CFGData.node_identity.length()) { // If an identity path was provided
  905. ConfigurationData Identity(CFGData.node_identity.c_str()); // then get the data from that file.
  906. ConfigurationElement IdentityReader("snf"); // Create an Identity reader and
  907. IdentityReader // configure it.
  908. .Element("identity")
  909. .Attribute("licenseid", CFGData.node_licenseid)
  910. .Attribute("authentication", CFGData.node_authentication)
  911. .End("identity")
  912. .End("snf");
  913. IdentityReader.interpret(Identity); // Then read the data.
  914. }
  915. //// The SecurityKey is built from the licenseID and the Authentication
  916. if(InitLicenseIdIsProvided) { // If the LicenseID has been provided then
  917. CFGData.SecurityKey = InitLicenseId; // the first part of our security key is that.
  918. } else { // If it was not provided then we will get
  919. CFGData.SecurityKey = CFGData.node_licenseid; // the LicenseID from our config file.
  920. }
  921. string LicenseIDToUse = CFGData.SecurityKey; // Grab the License ID we want to use.
  922. if(InitAuthenticationIsProvided) { // If the Authentication has been provided then
  923. CFGData.SecurityKey += InitAuthentication; // we use it for the second part of our
  924. } else { // security key. Otherwise we will get the
  925. CFGData.SecurityKey += CFGData.node_authentication; // Authentication from the config file.
  926. }
  927. //// RuleFilePath
  928. if(InitPathIsRulebase) { // If the Rulebase path was provided
  929. CFGData.RuleFilePath = InitFileName; // then we have our rulebase path.
  930. } else { // If not then we must figure it out...
  931. CFGData.RuleFilePath = // We build the path from the base
  932. CFGData.paths_rulebase_path + // rulebase path concattonated with
  933. LicenseIDToUse + // the license id concattonated with
  934. SNFExt; // the rulebase extension.
  935. }
  936. // Once all of the configuration data is correct we make it active.
  937. swapCFGData(); // Then swap it into the active state.
  938. // Log the configuration data as it was interpreted.
  939. logCFGData(ActiveData());
  940. }