Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

snfCFGmgr.cpp 58KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  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. //*****************************************************************************
  521. //// IMPORTANT: If the authentication string is provided in the initialize() it
  522. //// MUST NOT be put into D.node_authentication.
  523. //*****************************************************************************
  524. //// When the license ID and security string come from an OEM application they
  525. //// may not appear in the configuration files. If that is the case we will assume
  526. //// that they developer wants to keep the security string secret by encrypting it
  527. //// in their application and providing it to SNF at runtime. In that case we will
  528. //// not display the security key in the configuration log.
  529. ////
  530. //// To prevent hacking attempts, if the authentication information appears to be
  531. //// provided by configuration data then we will build the string from that data.
  532. //// that way an attacker can't trick the application into disclosing the true
  533. //// authentication string -- they will only get out what they put in.
  534. string SecurityKeyDisplayString(snfCFGData& D) { // Returns appropriate SecurityKey: data
  535. string ConfigLogSecurityKey = "************************"; // Start with a masked display.
  536. if(0 < D.node_authentication.length()) { // If auth info is in the config files then
  537. ConfigLogSecurityKey = D.node_licenseid + D.node_authentication; // build up the key from that data so it
  538. } // can be displayed in the config log.
  539. return ConfigLogSecurityKey;
  540. }
  541. void logCFGData(snfCFGData& D) { // Log interpreted cfg data (debug aid).
  542. try {
  543. string CFGLogPath; // Build the snf_cfg log path.
  544. CFGLogPath = D.paths_log_path +
  545. D.node_licenseid + "_snf_engine_cfg.log";
  546. ofstream cfgl(CFGLogPath.c_str(), ios::trunc); // Open and truncate the cfg log file.
  547. cfgl // Report important cfg information.
  548. << "SNF Engine Configuration" << endl
  549. << "____________" << endl
  550. << "Fundamentals" << endl
  551. << " License: " << D.node_licenseid << endl
  552. << " ConfigFilePath: " << D.ConfigFilePath << endl
  553. << " IdentityFilePath: " << D.node_identity << endl
  554. << " SecurityKey: " << SecurityKeyDisplayString(D) << endl
  555. << "_____" << endl
  556. << "Paths" << endl
  557. << " Log Path: " << D.paths_log_path << endl
  558. << " Rulebase Path: " << D.paths_rulebase_path << endl
  559. << " Workspace Path: " << D.paths_workspace_path << endl
  560. << " RuleFilePath: " << D.RuleFilePath << endl
  561. << "____" << endl
  562. << "Logs" << endl
  563. << endl
  564. << " Rotation-Midnight: " << ((D.Logs_Rotation_LocalTime_OnOff)? "Local" : "UTC") << endl
  565. << " ______" << endl
  566. << " Status" << endl
  567. << " PerSecond: "
  568. << ((D.Status_SecondReport_Log_OnOff)? "yes, " : "no, ")
  569. << "Append: "
  570. << ((D.Status_SecondReport_Append_OnOff)? "yes" : "no")
  571. << endl
  572. << " PerMinute: "
  573. << ((D.Status_MinuteReport_Log_OnOff)? "yes, " : "no, ")
  574. << "Append: "
  575. << ((D.Status_MinuteReport_Append_OnOff)? "yes" : "no")
  576. << endl
  577. << " PerHour: "
  578. << ((D.Status_HourReport_Log_OnOff)? "yes, " : "no, ")
  579. << "Append: "
  580. << ((D.Status_HourReport_Append_OnOff)? "yes" : "no")
  581. << endl
  582. << " ____" << endl
  583. << " Scan" << endl
  584. << " Identifier: "
  585. << ((D.Scan_Identifier_Force_Message_Id)? "Force RFC822 Message-ID" : "Use Provided Identifier")
  586. << endl
  587. << " Classic: Output-"
  588. << ((LogOutputMode_None == D.Scan_Classic_Mode)? "None, " :
  589. ((LogOutputMode_API == D.Scan_Classic_Mode)? "API, " :
  590. ((LogOutputMode_File == D.Scan_Classic_Mode)? "File, " : "Error!")))
  591. << ((D.Scan_Classic_Rotate)? "Rotating, ": "Non-Rotating, ")
  592. << ((D.Scan_Classic_Matches == ScanLogMatches_None) ? "No Mathes":
  593. ((D.Scan_Classic_Matches == ScanLogMatches_Unique) ? "Unique Matches":
  594. ((D.Scan_Classic_Matches == ScanLogMatches_All) ? "All Matches" : "Error!")))
  595. << endl
  596. << " XML: Output-"
  597. << ((LogOutputMode_None == D.Scan_XML_Mode)? "None, " :
  598. ((LogOutputMode_API == D.Scan_XML_Mode)? "API, " :
  599. ((LogOutputMode_File == D.Scan_XML_Mode)? "File, " : "Error!")))
  600. << ((D.Scan_XML_Rotate)? "Rotating, ": "Non-Rotating, ")
  601. << ((D.Scan_XML_Matches == ScanLogMatches_None) ? "No Mathes, ":
  602. ((D.Scan_XML_Matches == ScanLogMatches_Unique) ? "Unique Matches, ":
  603. ((D.Scan_XML_Matches == ScanLogMatches_All) ? "All Matches, " : "Match Error! ")))
  604. << ((D.Scan_XML_Performance)? "Performance Metrics, " : "No Performance Metrics, ")
  605. << ((D.Scan_XML_GBUdb)? "GBUdb Data" : "No GBUdb Data")
  606. << endl
  607. << " XHeaders:" << endl
  608. << " Output: "
  609. << ((LogOutputMode_None == D.XHDROutput_Mode) ? "None" :
  610. ((LogOutputMode_API == D.XHDROutput_Mode) ? "API" :
  611. ((LogOutputMode_File == D.XHDROutput_Mode) ? "File" :
  612. ((LogOutputMode_Inject == D.XHDROutput_Mode)? "Inject" : "Error!"))))
  613. << endl
  614. << " Version: "
  615. << ((D.XHDRVersion_OnOff)? "On, " : "Off, ")
  616. << D.XHDRVersion_Header
  617. << endl
  618. << " License: "
  619. << ((D.XHDRLicense_OnOff)? "On, " : "Off, ")
  620. << D.XHDRLicense_Header
  621. << endl
  622. << " Rulebase: "
  623. << ((D.XHDRRulebase_OnOff)? "On, " : "Off, ")
  624. << D.XHDRRulebase_Header
  625. << endl
  626. << " Identifier: "
  627. << ((D.XHDRIdentifier_OnOff)? "On, " : "Off, ")
  628. << D.XHDRIdentifier_Header
  629. << endl
  630. << " GBUdb: "
  631. << ((D.XHDRGBUdb_OnOff)? "On, " : "Off, ")
  632. << D.XHDRGBUdb_Header
  633. << endl
  634. << " Result: "
  635. << ((D.XHDRResult_OnOff)? "On, " : "Off, ")
  636. << D.XHDRResult_Header
  637. << endl
  638. << " Matches: "
  639. << ((D.XHDRMatches_OnOff)? "On, " : "Off, ")
  640. << D.XHDRMatches_Header
  641. << endl
  642. << " Black: "
  643. << ((D.XHDRBlack_OnOff)? "On, " : "Off, ")
  644. << D.XHDRBlack_Header
  645. << endl
  646. << " White: "
  647. << ((D.XHDRWhite_OnOff)? "On, " : "Off, ")
  648. << D.XHDRWhite_Header
  649. << endl
  650. << " Clean: "
  651. << ((D.XHDRClean_OnOff)? "On, " : "Off, ")
  652. << D.XHDRClean_Header
  653. << endl;
  654. for(
  655. set<XHDRSymbol>::iterator iH = D.XHDRSymbolHeaders.SymbolHeaders.begin();
  656. iH != D.XHDRSymbolHeaders.SymbolHeaders.end(); iH++
  657. ) {
  658. cfgl
  659. << " Symbol: "
  660. << (*iH).Symbol << ", "
  661. << (*iH).Header
  662. << endl;
  663. }
  664. cfgl
  665. << "_______" << endl
  666. << "Network" << endl
  667. << " Sync Host: " << D.network_sync_host << endl
  668. << " Sync Port: " << D.network_sync_port << endl
  669. << " Sync Secs: " << D.network_sync_secs << endl
  670. << " _____________" << endl
  671. << " Update-Script" << endl
  672. << " On-Off: " << ((D.update_script_on_off) ? "On" : "Off") << endl
  673. << " Script: " << D.update_script_call << endl
  674. << " Guard-Time: " << D.update_script_guard_time << " seconds" << endl
  675. << "___" << endl
  676. << "XCI" << endl
  677. << " " << ((D.XCI_OnOff)? "Enabled" : "Disabled") << endl
  678. << " Port: " << D.XCI_Port << endl
  679. << "_____" << endl
  680. << "GBUdb" << endl
  681. << " ____________" << endl
  682. << " Condensation" << endl
  683. << " Minimum-Seconds-Between = " << D.gbudb_database_condense_minimum_seconds_between << endl
  684. << " Time-Trigger: "
  685. << ((D.gbudb_database_condense_time_trigger_on_off)? "on, " : "off, ")
  686. << D.gbudb_database_condense_time_trigger_seconds << " seconds" << endl
  687. << " Posts-Trigger: "
  688. << ((D.gbudb_database_condense_posts_trigger_on_off)? "on, " : "off, ")
  689. << D.gbudb_database_condense_posts_trigger_posts << " posts" << endl
  690. << " Records-Trigger: "
  691. << ((D.gbudb_database_condense_records_trigger_on_off) ? "on, " : "off, ")
  692. << D.gbudb_database_condense_records_trigger_records << " records" << endl
  693. << " Size-Trigger: "
  694. << ((D.gbudb_database_condense_size_trigger_on_off) ? "on, " : "off, ")
  695. << D.gbudb_database_condense_size_trigger_megabytes << " megabytes" << endl
  696. << " __________" << endl
  697. << " Checkpoint" << endl
  698. << " Checkpoint: "
  699. << ((D.gbudb_database_checkpoint_on_off) ? "on, " : "off, ")
  700. << D.gbudb_database_checkpoint_secs << " seconds" << endl
  701. << " ______" << endl
  702. << " Ranges" << endl
  703. << " White: "
  704. << ((D.WhiteRangeHandler.On_Off) ? "on, " : "off, ")
  705. << "Symbol " << D.WhiteRangeHandler.Symbol << endl
  706. << " Auto-Panic: "
  707. << ((D.gbudb_regions_white_panic_on_off) ? "on, " : "off, ")
  708. << "Range " << D.gbudb_regions_white_panic_rule_range << endl
  709. << endl
  710. << " Caution: "
  711. << ((D.CautionRangeHandler.On_Off) ? "on, " : "off, ")
  712. << "Symbol " << D.CautionRangeHandler.Symbol << endl
  713. << endl
  714. << " Black: "
  715. << ((D.BlackRangeHandler.On_Off) ? "on, " : "off, ")
  716. << "Symbol " << D.BlackRangeHandler.Symbol << endl
  717. << " Truncate: "
  718. << ((D.gbudb_regions_black_truncate_on_off) ? "on, " : "off, ")
  719. << "Probability " << D.gbudb_regions_black_truncate_probability << ", "
  720. << "Peek-One-In " << D.gbudb_regions_black_truncate_peek_one_in << ", "
  721. << "Symbol " << D.gbudb_regions_black_truncate_symbol << endl
  722. << " Sample: "
  723. << ((D.gbudb_regions_black_sample_on_off) ? "on, " : "off, ")
  724. << "Probability: " << D.gbudb_regions_black_sample_probability << ", "
  725. << "Grab-One-In: " << D.gbudb_regions_black_sample_grab_one_in << ", " << endl
  726. << " Passthrough: "
  727. << ((D.gbudb_regions_black_sample_passthrough) ? "yes, " : "no, ")
  728. << "Passthrough Symbol " << D.gbudb_regions_black_sample_passthrough_symbol << endl
  729. << endl
  730. << " Range Map - [W]hite [B]lack [C]aution [ ]undefined" << endl << endl
  731. << " |-9876543210123456789+|" << endl;
  732. // Output GBUdb Range Map
  733. for(double c = 0; c < 1.01; c+=0.1) { // Run through the confidence
  734. cfgl << " |";
  735. for(double p = -1.0; p < 1.01; p+=0.1) { // and probability ranges.
  736. RangePoint t(c,p); // Test the range point w/ c & p
  737. if(D.WhiteRangeHandler.isInWhite(t)) { // If it's in the white range
  738. cfgl << "W"; // put in a W.
  739. } else
  740. if(D.BlackRangeHandler.isInBlack(t)) { // If it's in the black range
  741. cfgl << "B"; // put in a B.
  742. } else
  743. if(D.CautionRangeHandler.isInBlack(t)) { // If it's in the caution range
  744. cfgl << "C"; // put in a C.
  745. } else {
  746. cfgl << " "; // Otherwise put in a space.
  747. }
  748. }
  749. cfgl << "|" << c << endl;
  750. }
  751. cfgl << " |---------------------|" << endl;
  752. cfgl
  753. << endl
  754. << " ________" << endl
  755. << " Training" << endl
  756. << " GBUdb Updates: "
  757. << ((D.GBUdbTrainingOn_Off)? "Enabled" : "Disabled") << endl
  758. << endl;
  759. cfgl
  760. << " Source Header Directives: " << endl;
  761. for(
  762. HeaderDirectiveSet::iterator iD = D.HeaderDirectivesHandler.HeaderDirectives.begin();
  763. iD != D.HeaderDirectivesHandler.HeaderDirectives.end(); iD++
  764. ) {
  765. const HeaderFinderPattern& Dx = *iD;
  766. if(HeaderDirectiveContext == Dx.Directive) {
  767. cfgl
  768. << " "
  769. << "Context " << Dx.Context << " is a "
  770. << Dx.Header << " header at"
  771. << " Ordinal " << Dx.Ordinal
  772. << " that Contains " << Dx.Contains << endl;
  773. } else
  774. if(HeaderDirectiveSource == Dx.Directive) {
  775. cfgl
  776. << " "
  777. << "Context " << Dx.Context << " Source ip is in "
  778. << Dx.Header << " header at"
  779. << " Ordinal " << Dx.Ordinal << endl;
  780. }
  781. }
  782. cfgl << endl;
  783. cfgl
  784. << " Drilldown Header Directives: " << endl;
  785. for(
  786. HeaderDirectiveSet::iterator iD = D.HeaderDirectivesHandler.HeaderDirectives.begin();
  787. iD != D.HeaderDirectivesHandler.HeaderDirectives.end(); iD++
  788. ) {
  789. const HeaderFinderPattern& Dx = *iD;
  790. if(HeaderDirectiveDrillDown == Dx.Directive) {
  791. cfgl
  792. << " "
  793. << Dx.Header << " header at"
  794. << " Ordinal " << Dx.Ordinal
  795. << " Contains " << Dx.Contains << endl;
  796. }
  797. }
  798. cfgl << endl;
  799. cfgl
  800. << " Bypass Header Directives: " << endl;
  801. for(
  802. HeaderDirectiveSet::iterator iD = D.HeaderDirectivesHandler.HeaderDirectives.begin();
  803. iD != D.HeaderDirectivesHandler.HeaderDirectives.end(); iD++
  804. ) {
  805. const HeaderFinderPattern& Dx = *iD;
  806. if(HeaderDirectiveBypass == Dx.Directive) {
  807. cfgl
  808. << " "
  809. << Dx.Header << " header at"
  810. << " Ordinal " << Dx.Ordinal
  811. << " Contains " << Dx.Contains << endl;
  812. }
  813. }
  814. cfgl << endl;
  815. cfgl
  816. << " White Rule Header Directives: " << endl;
  817. for(
  818. HeaderDirectiveSet::iterator iD = D.HeaderDirectivesHandler.HeaderDirectives.begin();
  819. iD != D.HeaderDirectivesHandler.HeaderDirectives.end(); iD++
  820. ) {
  821. const HeaderFinderPattern& Dx = *iD;
  822. if(HeaderDirectiveWhite == Dx.Directive) {
  823. cfgl
  824. << " "
  825. << Dx.Header << " header at"
  826. << " Ordinal " << Dx.Ordinal
  827. << " Contains " << Dx.Contains << endl;
  828. }
  829. }
  830. cfgl << endl;
  831. cfgl
  832. << " White Rule Symbols: ";
  833. // Output white rule symbols
  834. for(
  835. set<int>::iterator ix = D.TrainingWhiteRuleHandler.IntegerSet.begin();
  836. ix != D.TrainingWhiteRuleHandler.IntegerSet.end();
  837. ix ++) {
  838. if(D.TrainingWhiteRuleHandler.IntegerSet.begin() != ix) {
  839. cfgl << ", ";
  840. }
  841. cfgl << (*ix);
  842. }
  843. cfgl << endl;
  844. // Rule Panics
  845. cfgl
  846. << "___________" << endl
  847. << "Rule-Panics" << endl;
  848. for(
  849. set<int>::iterator ix = D.RulePanicHandler.IntegerSet.begin();
  850. ix != D.RulePanicHandler.IntegerSet.end();
  851. ix ++) {
  852. cfgl << " Rule ID: " << (*ix) << endl;
  853. }
  854. cfgl << endl;
  855. cfgl
  856. << "___________" << endl
  857. << "Integration" << endl
  858. << endl
  859. << " Message Format: "
  860. << ((D.MessageFileTypeCGP_on_off)? "CGP" : "RFC822")
  861. << endl;
  862. #ifdef __BIG_ENDIAN__
  863. cfgl << " Rulebase Conversion: BIG ENDIAN" << endl;
  864. #else
  865. cfgl << " Rulebase Conversion: LITTLE ENDIAN" << endl;
  866. #endif
  867. cfgl
  868. << "________" << endl
  869. << "Platform" << endl
  870. << D.PlatformElementContents
  871. << endl;
  872. cfgl << endl; // End with a new line.
  873. cfgl.close(); // Close the cfg log file.
  874. } catch (...) {} // Ignore any errors.
  875. }
  876. void snfCFGmgr::load() {
  877. // What shall we configure -- the inactive snfCFGData.
  878. snfCFGData& CFGData = InactiveData();
  879. // How shall we configure?
  880. // If FileName ends in .snf then find the .cfg file for details.
  881. // If the FileName ends some other way it _should_ be our cfg file.
  882. int PathLength = InitFileName.length(); // How long is the path?
  883. const int MinimumPathLength = 12; // Must be at least licensid.snf long.
  884. if(MinimumPathLength > PathLength) throw LoadFailure(); // Path length is impossible? throw!
  885. const string SNFExt = ".snf"; // The extension we are looking for.
  886. const string CFGExt = ".xml"; // The default cfg extension.
  887. const int SNFExtLength = SNFExt.length(); // The length of the extension.
  888. int SNFExtPosition = InitFileName.rfind(SNFExt,PathLength); // Find the extension at the end.
  889. bool InitPathIsRulebase = false; // Was the init FileName the Rulebase?
  890. bool InitLicenseIdIsProvided = (0 < InitLicenseId.length()); // Was the init LicenseId provided?
  891. bool InitAuthenticationIsProvided = (0 < InitAuthentication.length()); // Was the authentication provided?
  892. if((PathLength - SNFExtLength) == SNFExtPosition) { // If path ends in .snf then
  893. InitPathIsRulebase = true; // set our flag to keep track then set
  894. ConfigurationPath = InitFileName.substr(0,SNFExtPosition); // our configuration path as the init
  895. ConfigurationPath.append(CFGExt); // file name with the config extension.
  896. } else { // If the init file is not a rulebase
  897. ConfigurationPath = InitFileName; // then it is the config file name.
  898. }
  899. // At this point we know where to read our configuration from.
  900. try { CFGData.initializeFromFile(ConfigurationPath.c_str()); } // Initialize the inactive config.
  901. catch(...) { // If that failed then throw.
  902. throw LoadFailure();
  903. }
  904. // Now that the main config has been read we create the derived cfg data.
  905. // Anything that was provided in Init takes precedence over the config.
  906. //// SecurityKey
  907. //// If an identity path has been provided we must load that data.
  908. if(0 < CFGData.node_identity.length()) { // If an identity path was provided
  909. ConfigurationData Identity(CFGData.node_identity.c_str()); // then get the data from that file.
  910. ConfigurationElement IdentityReader("snf"); // Create an Identity reader and
  911. IdentityReader // configure it.
  912. .Element("identity")
  913. .Attribute("licenseid", CFGData.node_licenseid)
  914. .Attribute("authentication", CFGData.node_authentication)
  915. .End("identity")
  916. .End("snf");
  917. IdentityReader.interpret(Identity); // Then read the data.
  918. }
  919. //// The SecurityKey is built from the licenseID and the Authentication
  920. if(InitLicenseIdIsProvided) { // If the LicenseID is OEM provided then
  921. CFGData.SecurityKey = InitLicenseId; // the first part of our security key is that.
  922. CFGData.node_licenseid = InitLicenseId; // Also override any file-loaded license ID.
  923. } else { // If it was not provided then we will get
  924. CFGData.SecurityKey = CFGData.node_licenseid; // the LicenseID from our config file.
  925. }
  926. string LicenseIDToUse = CFGData.SecurityKey; // Grab the License ID we want to use.
  927. if(InitAuthenticationIsProvided) { // If the Authentication has been provided then
  928. CFGData.SecurityKey += InitAuthentication; // we use it for the second part of our
  929. } else { // security key. Otherwise we will get the
  930. CFGData.SecurityKey += CFGData.node_authentication; // Authentication from the config file.
  931. }
  932. //// RuleFilePath
  933. if(InitPathIsRulebase) { // If the Rulebase path was provided
  934. CFGData.RuleFilePath = InitFileName; // then we have our rulebase path.
  935. } else { // If not then we must figure it out...
  936. CFGData.RuleFilePath = // We build the path from the base
  937. CFGData.paths_rulebase_path + // rulebase path concattonated with
  938. LicenseIDToUse + // the license id concattonated with
  939. SNFExt; // the rulebase extension.
  940. }
  941. // Once all of the configuration data is correct we make it active.
  942. swapCFGData(); // Then swap it into the active state.
  943. // Log the configuration data as it was interpreted.
  944. logCFGData(ActiveData());
  945. }