You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

snfCFGmgr.cpp 58KB

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