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.

UtilityConfig.cpp 42KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619
  1. // UtilityConfig.cpp
  2. //
  3. // Copyright (C) 2011, ARM Research Labs, LLC.
  4. // See www.armresearch.com for the copyright terms.
  5. //
  6. // This file implements the common functionality for the configuration
  7. // utilities.
  8. #include <cerrno>
  9. #include <cstring>
  10. #include <unistd.h>
  11. #include <pwd.h>
  12. #include <sys/types.h>
  13. #include <sys/stat.h>
  14. #include <stdexcept>
  15. #include <sstream>
  16. #include <iostream>
  17. #include <fstream>
  18. #include <vector>
  19. #include "UtilityConfig.hpp"
  20. using namespace std;
  21. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  22. // Configuration. ////////////////////////////////////////////////////////////////////////////////////////
  23. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  24. // Initialize OS-dependent constants.
  25. #ifdef WIN
  26. // Windows OS.
  27. const std::string UtilityConfig::SampleIgnoreListFile("C:\\SNF\\GBUdbIgnoreList.txt.sample");
  28. const std::string UtilityConfig::RulebaseDownloadCommand("FIX THIS");
  29. const std::string UtilityConfig::RulebaseDownloadStatusFile("FIX THIS");
  30. const std::string ScriptNameKey("FIX THIS"); ///< Text to replace with script name.
  31. const std::string SnifferPathKey("FIX THIS"); ///< Text to replace with directory of the rulebase.
  32. const std::string UtilityConfig::SampleRulebaseScriptFile("C:\\SNF\\getRulebase.sample");
  33. const std::string UtilityConfig::OperatingSystemType("Windows");
  34. #else
  35. // *nix OS.
  36. // SCRIPT is replaced with the full path of the script run,
  37. // SNIFFER_PATH is replaced with the path of the rulebase.
  38. const std::string UtilityConfig::RulebaseDownloadCommand
  39. ("(cd SNIFFER_PATH; touch UpdateReady.txt; chown snfuser UpdateReady.txt; su -m snfuser -c SCRIPT)");
  40. const std::string ScriptNameKey("SCRIPT"); ///< Text to replace with script name.
  41. const std::string SnifferPathKey("SNIFFER_PATH"); ///< Text to replace with directory of the rulebase.
  42. // SNIFFER_PATH is replaced with the path of the rulebase.
  43. const std::string UtilityConfig::RulebaseDownloadStatusFile("SNIFFER_PATHgetRulebase.status");
  44. #ifdef DEFAULT_DATA_DIR
  45. // *nix, DEFAULT_DATA_DIR is specified on the compile command line.
  46. const std::string UtilityConfig::SampleIgnoreListFile(DEFAULT_DATA_DIR "/GBUdbIgnoreList.txt.sample");
  47. #else
  48. // Not Windows, and DEFAULT_DATA_DIR is not specified on the compile
  49. // command line. In this case, we don't know the path for the sample
  50. // ignore list file.
  51. #error DEFAULT_DATA_DIR must be defined by -DDEFAULT_DATA_DIR="..." when compiling.
  52. #endif
  53. #ifdef SBIN_DIR
  54. // *nix, SBIN_DIR is specified on the compile command line.
  55. const std::string UtilityConfig::SampleRulebaseScriptFile(SBIN_DIR "/getRulebase.sample");
  56. #else
  57. // Not Windows, and SBIN_DIR is not specified on the compile
  58. // command line. In this case, we don't know the path for the sample
  59. // ignore list file.
  60. #error SBIN_DIR must be defined by -DSBIN_DIR="..." when compiling.
  61. #endif
  62. #ifdef SNF_OSTYPE
  63. // *nix, SNF_OSTYPE is specified on the compile command line.
  64. const std::string UtilityConfig::OperatingSystemType(SNF_OSTYPE);
  65. #else
  66. // Not Windows, and SNF_OSTYPE is not specified on the compile command
  67. // line. In this case, we don't know the operating system.
  68. #error SNF_OSTYPE must be defined by -DSNF_OSTYPE="..." when compiling.
  69. #endif
  70. #endif
  71. /// Verbose command-line input.
  72. const string VerboseKey("-v");
  73. /// Explain command-line input.
  74. const string ExplainKey("-explain");
  75. /// Help command-line input.
  76. const string HelpKey("-h");
  77. /// Setup command-line input.
  78. const string SetupKey("-setup");
  79. /// Repair command-line input.
  80. const string RepairKey("-repair");
  81. /// Start sniffer command-line input.
  82. const string StartSnifferKey("-start");
  83. /// Stop sniffer command-line input.
  84. const string StopSnifferKey("-stop");
  85. /// Configuration file command-line input.
  86. const string ConfigFileKey("-config=");
  87. /// License ID command-line input.
  88. const string LicenseIdKey("-id=");
  89. /// Authentication command-line input.
  90. const string AuthenticationKey("-auth=");
  91. /// String that indicates a successful rulebase download.
  92. //
  93. // This string must be in the last line of the getRulebase status
  94. // file. Note: The getRulebase status file is created by the
  95. // getRulebase script, has the name getRulebase.status, and is in the
  96. // same directory as the rulebase files.
  97. const string SuccessKey("Success");
  98. const string LicenseSearchString = "LICENSE_ID=";
  99. const string AuthSearchString = "AUTHENTICATION=";
  100. const string IdentityElementName = "identity";
  101. const string LicenseAttributeName = "licenseid";
  102. const string AuthenticationAttributeName = "authentication";
  103. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  104. // End of configuration. /////////////////////////////////////////////////////////////////////////////////
  105. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  106. UtilityConfig::UtilityConfig() :
  107. LicenseIdIsSpecified(false), AuthenticationIsSpecified(false)
  108. {
  109. SetExplain(false);
  110. SetVerbose(false);
  111. SetHelp(false);
  112. SetSetupRepair(false);
  113. SetStartSniffer(false);
  114. SetStopSniffer(false);
  115. }
  116. void
  117. UtilityConfig::CreateDefaultConfigFile(std::string SampleConfigFile) {
  118. std::string File = GetConfigFileName();
  119. if (!FileExists(File)) {
  120. if (!Explain()) {
  121. SaveFile.CreateBackupFile(File);
  122. }
  123. // Create the config file.
  124. Copy(SampleConfigFile, File);
  125. }
  126. SetMode(File, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); // Set permissions.
  127. SetOwnerGroup(File); // Set to sniffer user.
  128. }
  129. void
  130. UtilityConfig::LoadConfig() {
  131. if (Verbose()) {
  132. cout << "Using configuration file " << GetConfigFileName() << ".\n";
  133. }
  134. // Load the data.
  135. try {
  136. CFGData.initializeFromFile(GetConfigFileName().c_str());
  137. } catch(...) {
  138. string Temp;
  139. Temp = "Error reading configuration file " + GetConfigFileName();
  140. Temp += ".";
  141. throw std::runtime_error(Temp);
  142. }
  143. if ( (CFGData.paths_workspace_path.length() == 0) ||
  144. (CFGData.paths_rulebase_path.length() == 0) ||
  145. (CFGData.paths_log_path.length() == 0) ||
  146. (CFGData.update_script_call.length() == 0) ||
  147. (CFGData.node_identity.length() == 0) ) {
  148. string Temp;
  149. Temp = "The configuration file " + GetConfigFileName();
  150. Temp += " did not have the necessary specification of one or more paths:\n";
  151. Temp += "\n Workspace path: " + CFGData.paths_workspace_path;
  152. Temp += "\n Rulebase path: " + CFGData.paths_rulebase_path;
  153. Temp += "\n Log path: " + CFGData.paths_log_path;
  154. Temp += "\n Update script: " + CFGData.update_script_call;
  155. Temp += "\n Identity file: " + CFGData.node_identity;
  156. throw std::runtime_error(Temp);
  157. }
  158. }
  159. string
  160. UtilityConfig::GetPlatformContents(void) {
  161. return CFGData.PlatformElementContents;
  162. }
  163. string
  164. UtilityConfig::GetConfigFileName(void) {
  165. return ConfigFileName;
  166. }
  167. void
  168. UtilityConfig::SetConfigFileName(string Name) {
  169. ConfigFileName = Name;
  170. }
  171. string
  172. UtilityConfig::GetWorkspacePath(void) {
  173. return CFGData.paths_workspace_path;
  174. }
  175. string
  176. UtilityConfig::GetRulebasePath(void) {
  177. if (CFGData.paths_rulebase_path.empty())
  178. return "";
  179. // Ensure that there's a trailing "/".
  180. if (CFGData.paths_rulebase_path[CFGData.paths_rulebase_path.length() - 1] ==
  181. '/')
  182. return CFGData.paths_rulebase_path;
  183. return CFGData.paths_rulebase_path + "/";
  184. }
  185. string
  186. UtilityConfig::GetLogPath(void) {
  187. return CFGData.paths_log_path;
  188. }
  189. std::string
  190. UtilityConfig::GetStatusSecondLogFileName(void) {
  191. std::string FileName = CFGData.paths_log_path + CFGData.node_licenseid + ".status.second";
  192. if (CFGData.Status_SecondReport_Append_OnOff) {
  193. AppendDatestampToLogFileName(&FileName);
  194. }
  195. FileName += ".log.xml";
  196. return FileName;
  197. }
  198. std::string
  199. UtilityConfig::GetStatusMinuteLogFileName(void) {
  200. std::string FileName = CFGData.paths_log_path + CFGData.node_licenseid + ".status.minute";
  201. if (CFGData.Status_MinuteReport_Append_OnOff) {
  202. AppendDatestampToLogFileName(&FileName);
  203. }
  204. FileName += ".log.xml";
  205. return FileName;
  206. }
  207. void
  208. UtilityConfig::AppendDatestampToLogFileName(std::string *FileBaseName) {
  209. char TimestampBuffer[20];
  210. tm *BrokenDownTime;
  211. time_t Timestamp;
  212. time(&Timestamp);
  213. if (CFGData.Logs_Rotation_LocalTime_OnOff) {
  214. BrokenDownTime = localtime(&Timestamp);
  215. } else {
  216. BrokenDownTime = gmtime(&Timestamp);
  217. }
  218. snprintf(TimestampBuffer, sizeof TimestampBuffer, "%04d%02d%02d",
  219. BrokenDownTime->tm_year+1900,
  220. BrokenDownTime->tm_mon+1,
  221. BrokenDownTime->tm_mday);
  222. *FileBaseName += ".";
  223. *FileBaseName += TimestampBuffer;
  224. }
  225. string
  226. UtilityConfig::GetIdentityFileName(void) {
  227. return CFGData.node_identity;
  228. }
  229. string
  230. UtilityConfig::GetRulebaseScriptName(void) {
  231. return CFGData.update_script_call;
  232. }
  233. string
  234. UtilityConfig::GetIgnoreListFileName(void) {
  235. return GetWorkspacePath() + "GBUdbIgnoreList.txt";
  236. }
  237. string
  238. UtilityConfig::GetRulebaseFileName(void) {
  239. std::string Name;
  240. Name = GetRulebasePath();
  241. Name += LicenseId + ".snf";
  242. return Name;
  243. }
  244. string
  245. UtilityConfig::GetOperatingSystemType(void) {
  246. return OperatingSystemType;
  247. }
  248. void
  249. UtilityConfig::LoadInfo(){
  250. if ("OpenBSD" == OperatingSystemType) {
  251. PostfixMainCfPath = "/usr/local/etc/postfix/main.cf";
  252. PostfixMasterCfPath = "/usr/local/etc/postfix/master.cf";
  253. SnifferStartScriptDir = "/usr/local/sbin/";
  254. } else if ("FreeBSD" == OperatingSystemType) {
  255. PostfixMainCfPath = "/etc/postfix/main.cf";
  256. PostfixMasterCfPath = "/etc/postfix/master.cf";
  257. SnifferStartScriptDir = "/usr/local/etc/rc.d/";
  258. } else if ("Ubuntu" == OperatingSystemType) {
  259. PostfixMainCfPath = "/etc/postfix/main.cf";
  260. PostfixMasterCfPath = "/etc/postfix/master.cf";
  261. SnifferStartScriptDir = "/etc/init.d/";
  262. } else if ("RedHat" == OperatingSystemType) {
  263. PostfixMainCfPath = "/etc/postfix/main.cf";
  264. PostfixMasterCfPath = "/etc/postfix/master.cf";
  265. SnifferStartScriptDir = "/etc/init.d/";
  266. } else if ("Suse" == OperatingSystemType) {
  267. PostfixMainCfPath = "/etc/postfix/main.cf";
  268. PostfixMasterCfPath = "/etc/postfix/master.cf";
  269. SnifferStartScriptDir = "/etc/init.d/";
  270. } else {
  271. ostringstream Temp;
  272. Temp << "Internal error in UtilityConfig::LoadInfo: Invalid value of OperatingSystemType: "
  273. << OperatingSystemType;
  274. throw std::runtime_error(Temp.str());
  275. }
  276. }
  277. void
  278. UtilityConfig::LoadCredentials(void) {
  279. if(0 < CFGData.node_identity.length()) { // If an identity path was provided
  280. ConfigurationData Identity(CFGData.node_identity.c_str()); // then get the data from that file.
  281. ConfigurationElement IdentityReader("snf"); // Create an Identity reader and
  282. IdentityReader // configure it.
  283. .Element("identity")
  284. .Attribute("licenseid", CFGData.node_licenseid)
  285. .Attribute("authentication", CFGData.node_authentication)
  286. .End("identity")
  287. .End("snf");
  288. IdentityReader.interpret(Identity); // Then read the data.
  289. }
  290. }
  291. UtilityConfig::StatusCheckMethod
  292. UtilityConfig::GetPreferredStatusCheckMethod(void) {
  293. if (CFGData.XCI_OnOff) {
  294. return StatusCheckXci;
  295. }
  296. if (CFGData.Status_SecondReport_Log_OnOff) {
  297. return StatusCheckSecond;
  298. }
  299. if (CFGData.Status_MinuteReport_Log_OnOff) {
  300. return StatusCheckMinute;
  301. }
  302. return StatusCheckNotAvailable;
  303. }
  304. std::string
  305. UtilityConfig::GetSnifferStatusReport() {
  306. std::string StatusReport;
  307. int SleepTime_msec;
  308. int TimeoutTime_msec;
  309. switch (GetPreferredStatusCheckMethod()) {
  310. case StatusCheckXci:
  311. StatusReport = GetReportViaXci();
  312. break;
  313. case StatusCheckSecond:
  314. SleepTime_msec = 1000;
  315. TimeoutTime_msec = 7000;
  316. StatusReport = GetReportViaLogFile(&UtilityConfig::GetStatusSecondLogFileName, SleepTime_msec, TimeoutTime_msec);
  317. break;
  318. case StatusCheckMinute:
  319. SleepTime_msec = 10 * 1000;
  320. TimeoutTime_msec = 70 * 1000;
  321. std::cout << "Getting Sniffer status from status.minute log file (this takes about "
  322. << TimeoutTime_msec / 1000 << " s)...";
  323. std::cout.flush();
  324. StatusReport = GetReportViaLogFile(&UtilityConfig::GetStatusMinuteLogFileName, SleepTime_msec, TimeoutTime_msec);
  325. std::cout << "done." << std::endl;
  326. break;
  327. default:
  328. {
  329. std::string Temp;
  330. Temp = "No method for determining Sniffer status is available. ";
  331. Temp += "Tried XCI, status.second logging, and status.minute logging.";
  332. throw std::runtime_error(Temp);
  333. }
  334. }
  335. return StatusReport;
  336. }
  337. std::string
  338. UtilityConfig::GetReportViaXci() {
  339. if (Verbose()) {
  340. std::cout << "Getting Sniffer status report via XCI...";
  341. std::cout.flush();
  342. }
  343. bool ConnectSuccess = false;
  344. std::string ResultString;
  345. const std::string RequestString("<snf><xci><report><request><status class='second'/></request></report></xci></snf>");
  346. // Code copied from SNFClient.
  347. // Max time in this loop should be (100*50ms) = 5 seconds per try times
  348. // 10 tries = 50 seconds, plus (9*500ms) = 4.5 secs for re-tries. ~ 55 secs.
  349. const int ResultBufferSize = 4096;
  350. char ResultBuffer[ResultBufferSize+1]; // Make an oversize buffer for the answer.
  351. memset(ResultBuffer, 0, sizeof(ResultBuffer)); // Set the entire thing to nulls.
  352. const int Tries = 20; // How many times to try this.
  353. Sleeper SleepAfterAttempt(100); // How long to sleep between attempts.
  354. const int OpenTries = 90; // How many tries at opening.
  355. Sleeper WaitForOpen(10); // How long to wait for an open cycle.
  356. const int ReadTries = 900; // How many tries at reading.
  357. Sleeper SleepBeforeReading(10); // How long to pause before reading.
  358. /*
  359. ** 20 * 100ms = 2 seconds for all tries.
  360. ** 90 * 10ms = 900ms for a failed connection.
  361. ** 900 * 10ms = 9 seconds for a failed read.
  362. **
  363. ** Approximate wait for can't connect = 2.0 + (20 * 0.9) = ~ 20.0 seconds.
  364. ** Maximum impossible wait = 2.0 + (0.9 * 20) + (9.0 * 20) = 200.0 seconds.
  365. */
  366. for(int tryagain = Tries; (0<tryagain) && (!ConnectSuccess); tryagain--) { // Try a few times to get this done.
  367. try {
  368. ResultString = ""; // Clear our result string.
  369. TCPHost SNFServer(9001); // Create connection to server.
  370. SNFServer.makeNonBlocking(); // Make it non-blocking.
  371. for(int tries = OpenTries; 0 < tries; tries--) { // Wait & Watch for a good connection.
  372. try { SNFServer.open(); } catch(...) {} // Try opening the connection.
  373. if(SNFServer.isOpen()) break; // When successful, let's Go!
  374. else WaitForOpen(); // When not successful, pause.
  375. }
  376. if(SNFServer.isOpen()) { // If we have a good connection:
  377. SNFServer.transmit(
  378. RequestString.c_str(), RequestString.length()); // Send the request.
  379. for(int tries = ReadTries; 0 < tries; tries--) { // Try to read the result a few times.
  380. SleepBeforeReading(); // Provide some time for each try.
  381. memset(ResultBuffer, 0, sizeof(ResultBuffer)); // Clear the buffer.
  382. SNFServer.receive(ResultBuffer, ResultBufferSize); // Receive the answer.
  383. ResultString.append(ResultBuffer);
  384. if(string::npos ==
  385. ResultString.rfind("</snf>",ResultString.length())) { // If we don't have the end yet.
  386. continue; // Try again.
  387. } else { // If we got to end of line
  388. ConnectSuccess = true; // Success!
  389. break; // We're done.
  390. }
  391. }
  392. SNFServer.close(); // No need for our connection after that.
  393. }
  394. } catch(...) { } // Ignore errors for now.
  395. if(!ConnectSuccess) SleepAfterAttempt(); // Pause for a moment before trying again..
  396. }
  397. if(!ConnectSuccess) { // If no connection then Sniffer isn't running.
  398. if (Verbose()) {
  399. std::cout << "no response...";
  400. }
  401. return "";
  402. }
  403. // At this point we should have a usable result.
  404. if(Debug()) { cout << ResultString << endl; } // In debug, show the result string.
  405. snf_xci Reader(ResultString); // Interpret the data and check for
  406. if(Reader.bad()) { // a proper read. If it was bad...
  407. std::string Temp;
  408. Temp = "Bad result from Sniffer:\n" + ResultString;
  409. throw std::runtime_error(Temp);
  410. }
  411. if(0 < Reader.xci_error_message.length()) { // If the result was a general error...
  412. std::string Temp;
  413. Temp = "XCI error when determing status of Sniffer: " + Reader.xci_error_message;
  414. throw std::runtime_error(Temp);
  415. }
  416. if (Verbose()) {
  417. std::cout << "response received...";
  418. }
  419. return Reader.report_response;
  420. }
  421. std::string
  422. UtilityConfig::GetReportViaLogFile(GetLogFileName GetLogFileNamePtr, int SleepTime_msec, int TimeoutTime_msec) {
  423. std::string LogFileName;
  424. LogFileName = (this->*GetLogFileNamePtr)();
  425. if (Verbose()) {
  426. cout << "\nGetting Sniffer status report via log file " << LogFileName << "...";
  427. std::cout.flush();
  428. }
  429. std::string InitialContents;
  430. InitialContents = ReadLastPartOfFile(LogFileName, LogFileReportSize); // Read last part of log file.
  431. int ElapsedTime_msec = 0;
  432. while (ElapsedTime_msec < TimeoutTime_msec) {
  433. bool IncreasedTimeoutTime = false; // TimeoutTime_msec can be increased
  434. // only once if the log file name changes.
  435. std::string NewLogFileName;
  436. Sleeper Sleep(SleepTime_msec);
  437. std::string FinalContents;
  438. Sleep();
  439. NewLogFileName = (this->*GetLogFileNamePtr)();
  440. if (!IncreasedTimeoutTime && (NewLogFileName != LogFileName)) { // Filename changes if it contains a
  441. // date stemp and the time is close
  442. // to midnight.
  443. TimeoutTime_msec *= 2;
  444. IncreasedTimeoutTime = true;
  445. if (Verbose()) {
  446. cout << "reading from " << NewLogFileName << "...";
  447. std::cout.flush();
  448. }
  449. }
  450. LogFileName = NewLogFileName;
  451. FinalContents = ReadLastPartOfFile(LogFileName, LogFileReportSize); // Read again.
  452. if ( (FinalContents.length() != 0) && // There is a report, and
  453. (InitialContents != FinalContents) ) { // the contents have changed.
  454. if (Verbose()) {
  455. cout << "report changed...";
  456. }
  457. OutputVerboseEnd();
  458. std::string::size_type StatsStartPos; // Index of start of <stats> element.
  459. std::string::size_type StatsEndPos; // Index of end of <stats> element.
  460. StatsEndPos = FinalContents.rfind("</stats>");
  461. if (std::string::npos == StatsEndPos) {
  462. throw std::runtime_error("Unable to interpret the status report: No '</stats>' closing tag found.");
  463. }
  464. StatsStartPos = FinalContents.rfind("<stats ", StatsEndPos);
  465. if (std::string::npos == StatsStartPos) {
  466. throw std::runtime_error("Unable to interpret the status report: No '<stats>' tag found.");
  467. }
  468. return FinalContents.substr(StatsStartPos); // Return the last <stats> element.
  469. }
  470. ElapsedTime_msec += SleepTime_msec;
  471. }
  472. if (Verbose()) {
  473. cout << "report unchanged...";
  474. }
  475. OutputVerboseEnd();
  476. return "";
  477. }
  478. void
  479. UtilityConfig::CheckSnifferStatusReport(std::string StatusReport, std::string ApplicationName) {
  480. if (Verbose()) {
  481. cout << "Checking Sniffer status report...";
  482. }
  483. ConfigurationElement MyCFGReader("stats"); // Object to parse the XML.
  484. ConfigurationData MyCFGData(StatusReport.c_str(), StatusReport.length()); // Object that contains the XML.
  485. std::string PlatformContent;
  486. MyCFGReader
  487. .Element("version")
  488. .Element("platform", PlatformContent, "")
  489. .End("platform")
  490. .End("version")
  491. .End("stats");
  492. MyCFGReader.initialize();
  493. if (!MyCFGReader.interpret(MyCFGData)) {
  494. std::ostringstream Temp;
  495. Temp << "Error interpreting the Sniffer status report:\n" << StatusReport;
  496. throw std::runtime_error(Temp.str());
  497. }
  498. if (std::string::npos == PlatformContent.find(ApplicationName)) { // Verify correct application.
  499. std::ostringstream Temp;
  500. Temp << "Error--The expected Sniffer application (" << ApplicationName
  501. << ") isn't running. The running application determined from the status report is "
  502. << PlatformContent;
  503. throw std::runtime_error(Temp.str());
  504. }
  505. OutputVerboseEnd();
  506. }
  507. UtilityConfig::SnifferRunningStateEnum
  508. UtilityConfig::GetRunningState(std::string ApplicationName) {
  509. if (Verbose()) {
  510. cout << "Checking whether " << ApplicationName << " is running...";
  511. cout.flush();
  512. }
  513. std::string StatusReport = GetSnifferStatusReport();
  514. OutputVerboseEnd();
  515. if (StatusReport.length() == 0) {
  516. return SnifferIsStopped;
  517. }
  518. CheckSnifferStatusReport(StatusReport, ApplicationName);
  519. return SnifferIsRunning;
  520. }
  521. void
  522. UtilityConfig::SetupRepair(const std::string SampleIdentityFile) {
  523. RestoreMissingConfigFiles(SampleIdentityFile);
  524. SetOwnerPermissionsOfConfigFiles();
  525. }
  526. void
  527. UtilityConfig::RestoreMissingConfigFiles(std::string SampleIdentityFile) {
  528. std::string File;
  529. File = GetIdentityFileName();
  530. if (!FileExists(File)) {
  531. if (!Explain()) {
  532. SaveFile.CreateBackupFile(File);
  533. }
  534. // Create the config file.
  535. Copy(SampleIdentityFile, File);
  536. }
  537. File = GetRulebaseScriptName();
  538. if (!FileExists(File)) {
  539. if (!Explain()) {
  540. SaveFile.CreateBackupFile(File);
  541. }
  542. Copy(SampleRulebaseScriptFile, File); // Copy if !Explain().
  543. }
  544. File = GetIgnoreListFileName();
  545. if (!FileExists(File)) {
  546. if (!Explain()) {
  547. SaveFile.CreateBackupFile(File);
  548. }
  549. Copy(SampleIgnoreListFile, File);
  550. }
  551. std::string LogDir = GetLogPath();
  552. if (!FileExists(LogDir)) {
  553. MkDir(LogDir);
  554. }
  555. }
  556. void
  557. UtilityConfig::SetOwnerPermissionsOfConfigFiles() {
  558. std::string File;
  559. File = GetIdentityFileName();
  560. if (FileExists(File)) {
  561. SetMode(File, S_IRUSR | S_IWUSR | S_IRGRP);
  562. SetOwnerGroup(File);
  563. }
  564. File = GetRulebaseScriptName();
  565. if (FileExists(File)) {
  566. SetMode(File, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
  567. }
  568. File = GetIgnoreListFileName();
  569. if (FileExists(File)) {
  570. SetMode(File, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  571. SetOwnerGroup(File);
  572. }
  573. File = DEFAULT_DATA_DIR;
  574. if (FileExists(File)) {
  575. SetMode(File, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
  576. SetOwnerGroup(File);
  577. }
  578. std::string LogDir = GetLogPath();
  579. if (FileExists(LogDir)) {
  580. SetMode(LogDir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
  581. SetOwnerGroup(LogDir);
  582. }
  583. }
  584. void
  585. UtilityConfig::UpdateRulebaseScriptCredentials() {
  586. std::string File = GetRulebaseScriptName();
  587. if (Verbose()) {
  588. cout << "Update authentication and license ID in the rulebase download script file " << File << "--\n";
  589. }
  590. ifstream Input;
  591. Input.open(File.c_str()); // Read the contents.
  592. if (!Input) {
  593. string Temp;
  594. Temp = "Error opening rulebase download script file " + File;
  595. Temp += " for reading: ";
  596. Temp += strerror(errno);
  597. throw std::runtime_error(Temp);
  598. }
  599. string Content;
  600. string Line;
  601. bool FoundLicense = false;
  602. bool FoundAuth = false;
  603. while (getline(Input, Line)) {
  604. if (CheckForString(Line, LicenseSearchString)) { // Check for license line.
  605. if (FoundLicense) { // Second license line found?
  606. string Temp;
  607. Temp = "Rulebase sownload script file " + File;
  608. Temp += " has the wrong format: Found two lines beginning with " + LicenseSearchString;
  609. throw std::runtime_error(Temp);
  610. }
  611. if (Verbose()) {
  612. cout << " Modify line: '" << Line << "'...\n";
  613. }
  614. FoundLicense = true;
  615. Line = LicenseSearchString + LicenseId; // Add license line.
  616. Line += " # Added by SNFSetup";
  617. }
  618. if (CheckForString(Line, AuthSearchString)) { // Check for authentication line.
  619. if (FoundAuth) { // Second authentication line found?
  620. string Temp;
  621. Temp = "Rulebase download script file " + File;
  622. Temp += " has the wrong format: Found two lines beginning with " + AuthSearchString;
  623. throw std::runtime_error(Temp);
  624. }
  625. if (Verbose()) {
  626. cout << " Modify line: '" << Line << "'...\n";
  627. }
  628. FoundAuth = true;
  629. Line = AuthSearchString + Authentication; // Add authentication line.
  630. Line += " # Added by SNFSetup";
  631. }
  632. Content += Line + "\n";
  633. }
  634. if (!FoundLicense || !FoundAuth) {
  635. string Temp;
  636. Temp = "Rulebase download script file " + File;
  637. Temp += " has the wrong format: Missing required line beginning with '" + LicenseSearchString;
  638. Temp += "' or '" + AuthSearchString;
  639. Temp += "'";
  640. throw std::runtime_error(Temp);
  641. }
  642. if (!Input.eof()) { // Should be at end-of-file.
  643. string Temp;
  644. Temp = "Error reading the rulebase download script file " + File;
  645. Temp += ": ";
  646. Temp += strerror(errno);
  647. throw std::runtime_error(Temp);
  648. }
  649. Input.close();
  650. if (Input.bad()) {
  651. string Temp;
  652. Temp = "Error closing the rulebase download script file " + File;
  653. Temp += " after reading: ";
  654. Temp += strerror(errno);
  655. throw std::runtime_error(Temp);
  656. }
  657. if (!Explain()) {
  658. SaveFile.CreateBackupFile(File);
  659. ofstream Output; // Write the updated contents.
  660. Output.open(File.c_str(), ios::trunc);
  661. if (!Output) {
  662. string Temp;
  663. Temp = "Error opening rulebase download script file " + File;
  664. Temp += " for writing: ";
  665. Temp += strerror(errno);
  666. throw std::runtime_error(Temp);
  667. }
  668. Output << Content;
  669. if (!Output) {
  670. string Temp;
  671. Temp = "Error writing the rulebase download script file " + File;
  672. Temp += ": ";
  673. Temp += strerror(errno);
  674. throw std::runtime_error(Temp);
  675. }
  676. Output.close();
  677. if (!Output) {
  678. string Temp;
  679. Temp = "Error closing the rulebase download script file " + File;
  680. Temp += " after writing: ";
  681. Temp += strerror(errno);
  682. throw std::runtime_error(Temp);
  683. }
  684. }
  685. OutputVerboseEnd();
  686. }
  687. void
  688. UtilityConfig::DownloadRulebase() {
  689. if (Verbose()) {
  690. std::cout << "Downloading the rulebase...";
  691. std::cout.flush();
  692. }
  693. std::string Command;
  694. Command = RulebaseDownloadCommand;
  695. std::string::size_type ScriptIndex = Command.find(ScriptNameKey);
  696. if (ScriptIndex != std::string::npos) { // Insert script full path?
  697. Command.replace(ScriptIndex, ScriptNameKey.length(), GetRulebaseScriptName());
  698. }
  699. std::string::size_type SnifferPathIndex = Command.find(SnifferPathKey);
  700. if (SnifferPathIndex != std::string::npos) { // Insert rulebase location?
  701. Command.replace(SnifferPathIndex, SnifferPathKey.length(), GetRulebasePath());
  702. }
  703. std::string StatusFile; // Construct download status file name.
  704. StatusFile = RulebaseDownloadStatusFile;
  705. SnifferPathIndex = StatusFile.find(SnifferPathKey);
  706. if (SnifferPathIndex != std::string::npos) { // Insert rulebase location?
  707. StatusFile.replace(SnifferPathIndex, SnifferPathKey.length(), GetRulebasePath());
  708. }
  709. if (!Explain()) {
  710. SaveFile.CreateBackupFile(GetRulebaseFileName()); // Save the current rulebase file.
  711. if (0 != remove(StatusFile.c_str())) { // Delete the status file.
  712. if (ENOENT != errno) { // No error if the file doesn't exist.
  713. std::ostringstream Temp;
  714. Temp << "Unable to remove rulebase download status file " << StatusFile
  715. << ": " << strerror(errno);
  716. throw std::runtime_error(Temp.str());
  717. }
  718. }
  719. if (std::system(Command.c_str()) != 0) { // Download the rulebase.
  720. string Temp;
  721. Temp = "Error running the command '" + Command;
  722. Temp += "'.";
  723. throw std::runtime_error(Temp);
  724. }
  725. ifstream Input;
  726. Input.open(StatusFile.c_str()); // Check the status.
  727. if (!Input) {
  728. string Temp;
  729. Temp = "Error opening rulebase download script status file " + StatusFile;
  730. Temp += ": ";
  731. Temp += strerror(errno);
  732. throw std::runtime_error(Temp);
  733. }
  734. string Line;
  735. string PrevLine;
  736. string Content;
  737. while (getline(Input, Line)) { // Read the last line.
  738. PrevLine = Line;
  739. Content += Line + "\n";
  740. }
  741. if (PrevLine.find(SuccessKey) == std::string::npos) { // Check the status.
  742. string Temp;
  743. Temp = "Error downloading the rulebase. Rulebase download status:\n\n" + Content;
  744. throw std::runtime_error(Temp);
  745. }
  746. }
  747. OutputVerboseEnd();
  748. }
  749. void
  750. UtilityConfig::UpdateIdentityFile() {
  751. std::string File = GetIdentityFileName();
  752. if (Verbose()) {
  753. cout << "Update authentication and license ID in the identity file " << File << "--\n";
  754. }
  755. ifstream Input;
  756. Input.open(File.c_str()); // Read the contents.
  757. if (!Input) {
  758. string Temp;
  759. Temp = "Error opening identity file " + File;
  760. Temp += " for reading: ";
  761. Temp += strerror(errno);
  762. throw std::runtime_error(Temp);
  763. }
  764. ostringstream InputContents;
  765. if (!Input.eof()) { // Copy if there are characters.
  766. // Copying an empty file causes
  767. InputContents << Input.rdbuf(); // failbit to be set.
  768. }
  769. if (InputContents.bad() || InputContents.fail()) {
  770. std::string Temp;
  771. Temp = "Error reading identity file " + File;
  772. throw std::runtime_error(Temp);
  773. }
  774. Input.close();
  775. if (Input.bad()) {
  776. string Temp;
  777. Temp = "Error closing the identity file " + File;
  778. Temp += " after reading: ";
  779. Temp += strerror(errno);
  780. throw std::runtime_error(Temp);
  781. }
  782. string Content = InputContents.str();
  783. try {
  784. ReplaceXmlAttribute(&Content, IdentityElementName, LicenseAttributeName, LicenseId);
  785. ReplaceXmlAttribute(&Content, IdentityElementName, AuthenticationAttributeName, Authentication);
  786. } catch (std::exception &e) {
  787. std::string Temp;
  788. Temp = "Error updating credentials for identity file " + File;
  789. Temp += ": ";
  790. Temp += e.what();
  791. throw std::runtime_error(Temp);
  792. }
  793. if (!Explain()) {
  794. SaveFile.CreateBackupFile(File);
  795. ofstream Output;
  796. Output.open(File.c_str(), ios::trunc);
  797. if (!Output) {
  798. string Temp;
  799. Temp = "Error opening identity file " + File;
  800. Temp += " for writing: ";
  801. Temp += strerror(errno);
  802. throw std::runtime_error(Temp);
  803. }
  804. Output << Content;
  805. if (!Output) {
  806. string Temp;
  807. Temp = "Error writing the identity file " + File;
  808. Temp += ": ";
  809. Temp += strerror(errno);
  810. throw std::runtime_error(Temp);
  811. }
  812. Output.close();
  813. if (!Output) {
  814. string Temp;
  815. Temp = "Error closing the identity file " + File;
  816. Temp += " after writing: ";
  817. Temp += strerror(errno);
  818. throw std::runtime_error(Temp);
  819. }
  820. }
  821. OutputVerboseEnd();
  822. }
  823. #if 0
  824. void
  825. UtilityConfig::UpdateIdentityFileOld() {
  826. std::string File = GetIdentityFileName();
  827. ofstream Output;
  828. if (Verbose()) {
  829. cout << "Create identity file " << File << "...";
  830. }
  831. if (!Explain()) {
  832. SaveFile.CreateBackupFile(File);
  833. Output.open(File.c_str());
  834. if (!Output) {
  835. string Temp;
  836. Temp = "Error opening identity file " + File;
  837. Temp += ": ";
  838. Temp += strerror(errno);
  839. throw std::runtime_error(Temp);
  840. }
  841. Output << "<!-- License file created by SNFIdentity-->\n"
  842. << "<snf>\n"
  843. << " <identity licenseid='" << LicenseId << "' authentication='"
  844. << Authentication << "'/>\n"
  845. << "</snf>\n";
  846. if (!Output) {
  847. string Temp;
  848. Temp = "Error writing identity file " + File;
  849. Temp += ": ";
  850. Temp += strerror(errno);
  851. throw std::runtime_error(Temp);
  852. }
  853. Output.close();
  854. if (!Output) {
  855. string Temp;
  856. Temp = "Error closing identity file " + File;
  857. Temp += ": ";
  858. Temp += strerror(errno);
  859. throw std::runtime_error(Temp);
  860. }
  861. }
  862. OutputVerboseEnd();
  863. SetOwnerGroup(File); // Set the user and group.
  864. SetMode(File, S_IRUSR); // Set to readonly by owner.
  865. }
  866. #endif
  867. void
  868. UtilityConfig::StartSniffer(std::string ScriptAndArgs, std::string ApplicationName) {
  869. if (SnifferIsRunning == GetRunningState(ApplicationName)) {
  870. std::cout << ApplicationName << " is already running.\n";
  871. return;
  872. }
  873. std::string Command;
  874. Command = SnifferStartScriptDir + ScriptAndArgs;
  875. if (Verbose()) {
  876. cout << "Starting Sniffer with the command '" << Command << "'...";
  877. cout.flush();
  878. }
  879. if (!Explain()) {
  880. if (std::system(Command.c_str()) == -1) { // Start the sniffer.
  881. string Temp;
  882. Temp = "Error running the command '" + Command;
  883. Temp += "' to start the Sniffer: ";
  884. Temp += strerror(errno);
  885. throw std::runtime_error(Temp);
  886. }
  887. OutputVerboseEnd();
  888. if (SnifferIsRunning != GetRunningState(ApplicationName)) {
  889. std::string Temp;
  890. Temp = "Unable to start " + ApplicationName;
  891. throw std::runtime_error(Temp);
  892. }
  893. } else {
  894. OutputVerboseEnd();
  895. }
  896. }
  897. void
  898. UtilityConfig::StopSniffer(std::string ScriptAndArgs, std::string ApplicationName) {
  899. if (SnifferIsStopped == GetRunningState(ApplicationName)) {
  900. std::cout << ApplicationName << " was not running.\n";
  901. return;
  902. }
  903. std::string Command;
  904. Command = SnifferStartScriptDir + ScriptAndArgs;
  905. if (Verbose()) {
  906. cout << "Stopping Sniffer with the command '" << Command << "'...";
  907. cout.flush();
  908. }
  909. if (!Explain()) {
  910. if (std::system(Command.c_str()) == -1) { // Start the sniffer.
  911. string Temp;
  912. Temp = "Error running the command '" + Command;
  913. Temp += "' to stop the Sniffer: ";
  914. Temp += strerror(errno);
  915. throw std::runtime_error(Temp);
  916. }
  917. OutputVerboseEnd();
  918. if (SnifferIsStopped != GetRunningState(ApplicationName)) {
  919. std::string Temp;
  920. Temp = "Unable to stop " + ApplicationName;
  921. throw std::runtime_error(Temp);
  922. }
  923. } else {
  924. OutputVerboseEnd();
  925. }
  926. }
  927. bool
  928. UtilityConfig::ProcessCommandLineItem(std::string OneInput) {
  929. bool ValidCommand = true;
  930. std::string TempString;
  931. if (OneInput == VerboseKey) {
  932. SetVerbose(true);
  933. } else if (OneInput == ExplainKey) {
  934. SetExplain(true);
  935. } else if (OneInput == HelpKey) {
  936. SetHelp(true);
  937. } else if (OneInput == SetupKey) {
  938. SetSetupRepair(true);
  939. } else if (OneInput == RepairKey) {
  940. SetSetupRepair(true);
  941. } else if (OneInput == StartSnifferKey) {
  942. SetStartSniffer(true);
  943. } else if (OneInput == StopSnifferKey) {
  944. SetStopSniffer(true);
  945. } else if (0 == OneInput.find(ConfigFileKey)) {
  946. TempString = Trim(OneInput.substr(ConfigFileKey.length())); // Copy only if not null after trimming.
  947. SetConfigFileName(TempString);
  948. } else if (0 == OneInput.find(LicenseIdKey)) {
  949. TempString = Trim(OneInput.substr(LicenseIdKey.length())); // Copy only if not null after trimming.
  950. if (!TempString.empty()) {
  951. LicenseId = TempString;
  952. LicenseIdIsSpecified = true;
  953. } else {
  954. ValidCommand = false;
  955. }
  956. } else if (0 == OneInput.find(AuthenticationKey)) {
  957. TempString = Trim(OneInput.substr(AuthenticationKey.length())); // Copy only if not null after trimming.
  958. if (!TempString.empty()) {
  959. Authentication = TempString;
  960. AuthenticationIsSpecified = true;
  961. } else {
  962. ValidCommand = false;
  963. }
  964. } else {
  965. ValidCommand = false;
  966. }
  967. return ValidCommand;
  968. }
  969. bool
  970. UtilityConfig::CommandLineIsOkay() {
  971. return (AuthenticationIsSpecified == LicenseIdIsSpecified);
  972. }
  973. std::string
  974. UtilityConfig::HelpCommandLine(std::string ExclusiveCommandsHelp) {
  975. std::string Help;
  976. Help = SetupKey + " | ";
  977. Help += RepairKey + " | ";
  978. Help += ExclusiveCommandsHelp + " | ";
  979. Help += LicenseIdKey + "licenseid " + AuthenticationKey + "authentication | ";
  980. Help += StartSnifferKey + " | ";
  981. Help += StopSnifferKey + " ";
  982. Help += "[" + ConfigFileKey + "snf-config-file] ";
  983. Help += "[ " + VerboseKey + " " + ExplainKey + " ]";
  984. return Help;
  985. }
  986. std::string
  987. UtilityConfig::HelpDescription(std::string ExclusiveCommandsHelp) {
  988. std::string Desc;
  989. Desc = "creates and updates the configuration files (snf-config-file and\n";
  990. Desc += "the ignore list file), the rulebase download script (default: getRulebase),\n";
  991. Desc += "and the identity file if they don't exist.\n\n";
  992. Desc += " -setup Perform initial setup/replace missing files\n";
  993. Desc += " -repair Perform initial setup/replace missing files\n";
  994. Desc += ExclusiveCommandsHelp;
  995. Desc += " -id=licenseid Specifies the license ID\n";
  996. Desc += " -auth=authentication Specifies the Authentication\n";
  997. Desc += " -start Start the sniffer\n";
  998. Desc += " -stop Stop the sniffer\n";
  999. Desc += " -v Provide verbose output\n";
  1000. Desc += " -explain Provide an explaination of the actions\n";
  1001. Desc += " without executing any commands\n";
  1002. return Desc;
  1003. }
  1004. void
  1005. UtilityConfig::SetSetupRepair(bool Specified) {
  1006. SetupRepairRequested = Specified;
  1007. }
  1008. bool
  1009. UtilityConfig::SetupRepairSpecified() {
  1010. return SetupRepairRequested;
  1011. }
  1012. bool
  1013. UtilityConfig::UpdateCredentialsSpecified() {
  1014. return ( (LicenseId.length() > 0) && (Authentication.length() > 0) );
  1015. }
  1016. void
  1017. UtilityConfig::SetStartSniffer(bool Specified) {
  1018. StartSnifferRequested = Specified;
  1019. }
  1020. bool
  1021. UtilityConfig::StartSnifferSpecified() {
  1022. return StartSnifferRequested;
  1023. }
  1024. void
  1025. UtilityConfig::SetStopSniffer(bool Specified) {
  1026. StopSnifferRequested = Specified;
  1027. }
  1028. bool
  1029. UtilityConfig::StopSnifferSpecified() {
  1030. return StopSnifferRequested;
  1031. }