Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

UtilityConfig.cpp 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  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_PATH/getRulebase.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. /// Configuration file command-line input.
  78. const string ConfigFileKey("-config=");
  79. /// License ID command-line input.
  80. const string LicenseIdKey("-id=");
  81. /// Authentication command-line input.
  82. const string AuthenticationKey("-auth=");
  83. /// String that indicates a successful rulebase download.
  84. //
  85. // This string must be in the last line of the getRulebase status
  86. // file. Note: The getRulebase status file is created by the
  87. // getRulebase script, has the name getRulebase.status, and is in the
  88. // same directory as the rulebase files.
  89. const string SuccessKey("Success");
  90. const string LicenseSearchString = "LICENSE_ID=";
  91. const string AuthSearchString = "AUTHENTICATION=";
  92. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  93. // End of configuration. /////////////////////////////////////////////////////////////////////////////////
  94. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  95. UtilityConfig::UtilityConfig() :
  96. LicenseIdIsSpecified(false), AuthenticationIsSpecified(false), ConfigFileExists(true)
  97. {
  98. SetExplain(false);
  99. SetVerbose(false);
  100. SetHelp(false);
  101. }
  102. void
  103. UtilityConfig::CheckAndSetConfigFileName(const std::string DefaultFile[], int NumDefaultFiles) {
  104. string ProvisionalConfigFile = ConfigFileName;
  105. if (ProvisionalConfigFile.length() == 0) {
  106. int i;
  107. vector<string> FoundFile;
  108. for (i = 0; i < NumDefaultFiles; i++) {
  109. if (!FileExists(DefaultFile[i])) {
  110. continue; // File doesn't exist.
  111. }
  112. FoundFile.push_back(DefaultFile[i]); // Update list of found files.
  113. ProvisionalConfigFile = DefaultFile[i]; // Found configuration file.
  114. }
  115. if (0 == FoundFile.size()) { // No default file found.
  116. if (NumDefaultFiles > 0) {
  117. ProvisionalConfigFile = DefaultFile[0]; // Use the first default file.
  118. ConfigFileExists = false;
  119. } else { // No default config file was specified.
  120. ostringstream Temp;
  121. Temp << "Internal error: NumDefaultFiles <= 0 at " << __FILE__ << ":" << __LINE__;
  122. throw runtime_error(Temp.str());
  123. }
  124. } else if (FoundFile.size() > 1) { // Multiple default files found.
  125. string Temp;
  126. Temp = "Configuration file was not specified, and more than one default configuration file was found::\n\n";
  127. for (i = 0; i < FoundFile.size(); i++) {
  128. Temp += " ";
  129. Temp += FoundFile[i] + "\n";
  130. }
  131. throw runtime_error(Temp);
  132. } else {
  133. ConfigFileExists = true; // Config file was found.
  134. }
  135. } else {
  136. ConfigFileExists = FileExists(ProvisionalConfigFile);
  137. }
  138. SetConfigFileName(ProvisionalConfigFile);
  139. }
  140. void
  141. UtilityConfig::CreateDefaultConfigFile(std::string SampleConfigFile) {
  142. std::string File = GetConfigFileName();
  143. if (!ConfigFileExists) {
  144. // Create the config file.
  145. Copy(SampleConfigFile, File);
  146. }
  147. }
  148. void
  149. UtilityConfig::CreateDefaultIdentityFile(std::string SampleIdentityFile) {
  150. std::string File = GetIdentityFileName();
  151. if (!FileExists(File)) {
  152. // Create the config file.
  153. Copy(SampleIdentityFile, File);
  154. }
  155. }
  156. void
  157. UtilityConfig::LoadConfig() {
  158. if (Verbose()) {
  159. cout << "Using configuration file " << GetConfigFileName() << ".\n";
  160. }
  161. // Load the data.
  162. try {
  163. CFGData.initializeFromFile(GetConfigFileName().c_str());
  164. } catch(...) {
  165. string Temp;
  166. Temp = "Error reading configuration file " + GetConfigFileName();
  167. Temp += ".";
  168. throw runtime_error(Temp);
  169. }
  170. if ( (CFGData.paths_workspace_path.length() == 0) ||
  171. (CFGData.paths_rulebase_path.length() == 0) ||
  172. (CFGData.paths_log_path.length() == 0) ||
  173. (CFGData.update_script_call.length() == 0) ||
  174. (CFGData.node_identity.length() == 0) ) {
  175. string Temp;
  176. Temp = "The configuration file " + GetConfigFileName();
  177. Temp += " did not have the necessary specification of one or more paths:\n";
  178. Temp += "\n Workspace path: " + CFGData.paths_workspace_path;
  179. Temp += "\n Rulebase path: " + CFGData.paths_rulebase_path;
  180. Temp += "\n Log path: " + CFGData.paths_log_path;
  181. Temp += "\n Update script: " + CFGData.update_script_call;
  182. Temp += "\n Identity file: " + CFGData.node_identity;
  183. throw runtime_error(Temp);
  184. }
  185. }
  186. string
  187. UtilityConfig::GetPlatformContents(void) {
  188. return CFGData.PlatformElementContents;
  189. }
  190. string
  191. UtilityConfig::GetConfigFileName(void) {
  192. return ConfigFileName;
  193. }
  194. void
  195. UtilityConfig::SetConfigFileName(string Name) {
  196. ConfigFileName = Name;
  197. }
  198. string
  199. UtilityConfig::GetWorkspacePath(void) {
  200. return CFGData.paths_workspace_path;
  201. }
  202. string
  203. UtilityConfig::GetRulebasePath(void) {
  204. return CFGData.paths_rulebase_path;
  205. }
  206. string
  207. UtilityConfig::GetLogPath(void) {
  208. return CFGData.paths_log_path;
  209. }
  210. string
  211. UtilityConfig::GetIdentityFileName(void) {
  212. return CFGData.node_identity;
  213. }
  214. string
  215. UtilityConfig::GetRulebaseScriptName(void) {
  216. return CFGData.update_script_call;
  217. }
  218. string
  219. UtilityConfig::GetIgnoreListFileName(void) {
  220. return GetWorkspacePath() + "GBUdbIgnoreList.txt";
  221. }
  222. string
  223. UtilityConfig::GetRulebaseFileName(void) {
  224. std::string Name;
  225. Name = GetRulebasePath();
  226. Name += LicenseId + ".snf";
  227. return Name;
  228. }
  229. string
  230. UtilityConfig::GetOperatingSystemType(void) {
  231. return OperatingSystemType;
  232. }
  233. void
  234. UtilityConfig::LoadInfo(){
  235. if ("OpenBSD" == OperatingSystemType) {
  236. PostfixMainCfPath = "/usr/local/etc/postfix/main.cf";
  237. PostfixMasterCfPath = "/usr/local/etc/postfix/master.cf";
  238. } else if ("FreeBSD" == OperatingSystemType) {
  239. PostfixMainCfPath = "/etc/postfix/main.cf";
  240. PostfixMasterCfPath = "/etc/postfix/master.cf";
  241. } else if ("Ubuntu" == OperatingSystemType) {
  242. PostfixMainCfPath = "/etc/postfix/main.cf";
  243. PostfixMasterCfPath = "/etc/postfix/master.cf";
  244. } else if ("RedHat" == OperatingSystemType) {
  245. PostfixMainCfPath = "/etc/postfix/main.cf";
  246. PostfixMasterCfPath = "/etc/postfix/master.cf";
  247. } else if ("Suse" == OperatingSystemType) {
  248. PostfixMainCfPath = "/etc/postfix/main.cf";
  249. PostfixMasterCfPath = "/etc/postfix/master.cf";
  250. } else {
  251. ostringstream Temp;
  252. Temp << "Internal error in UtilityConfig::LoadInfo: Invalid value of OperatingSystemType: "
  253. << OperatingSystemType;
  254. throw runtime_error(Temp.str());
  255. }
  256. }
  257. void
  258. UtilityConfig::UpdateIgnoreListFile() {
  259. string IgnoreListFile = GetIgnoreListFileName();
  260. if (!FileExists(IgnoreListFile)) {
  261. Copy(SampleIgnoreListFile, IgnoreListFile);
  262. }
  263. SetMode(IgnoreListFile, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); // Set permissions.
  264. SetOwnerGroup(IgnoreListFile); // Set to sniffer user.
  265. }
  266. void
  267. UtilityConfig::UpdateLogDir() {
  268. string LogDir = GetLogPath();
  269. if (!FileExists(LogDir)) {
  270. MkDir(LogDir);
  271. }
  272. SetMode(LogDir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
  273. SetOwnerGroup(LogDir);
  274. }
  275. bool
  276. UtilityConfig::UpdateCredentialsSpecified() {
  277. return ( (LicenseId.length() > 0) && (Authentication.length() > 0) );
  278. }
  279. void
  280. UtilityConfig::CreateUpdateRulebaseScript() {
  281. std::string File = GetRulebaseScriptName();
  282. if (!FileExists(File)) {
  283. Copy(SampleRulebaseScriptFile, File); // Copy if !Explain().
  284. }
  285. if (UpdateCredentialsSpecified()) {
  286. UpdateRulebaseScriptCredentials();
  287. }
  288. SetMode(File, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); // Set permissions.
  289. }
  290. void
  291. UtilityConfig::UpdateRulebaseScriptCredentials() {
  292. std::string File = GetRulebaseScriptName();
  293. if (Verbose()) {
  294. cout << "Update authentication and license ID in the rulebase download script file " << File << "--\n";
  295. }
  296. ifstream Input;
  297. Input.open(File.c_str()); // Read the contents.
  298. if (!Input) {
  299. string Temp;
  300. Temp = "Error opening rulebase download script file " + File;
  301. Temp += " for reading: ";
  302. Temp += strerror(errno);
  303. throw runtime_error(Temp);
  304. }
  305. string Content;
  306. string Line;
  307. bool FoundLicense = false;
  308. bool FoundAuth = false;
  309. while (getline(Input, Line)) {
  310. if (CheckForString(Line, LicenseSearchString)) { // Check for license line.
  311. if (FoundLicense) { // Second license line found?
  312. string Temp;
  313. Temp = "Rulebase sownload script file " + File;
  314. Temp += " has the wrong format: Found two lines beginning with " + LicenseSearchString;
  315. throw runtime_error(Temp);
  316. }
  317. if (Verbose()) {
  318. cout << " Modify line: '" << Line << "'...\n";
  319. }
  320. FoundLicense = true;
  321. Line = LicenseSearchString + LicenseId; // Add license line.
  322. Line += " # Added by SNFSetup";
  323. }
  324. if (CheckForString(Line, AuthSearchString)) { // Check for authentication line.
  325. if (FoundAuth) { // Second authentication line found?
  326. string Temp;
  327. Temp = "Rulebase download script file " + File;
  328. Temp += " has the wrong format: Found two lines beginning with " + AuthSearchString;
  329. throw runtime_error(Temp);
  330. }
  331. if (Verbose()) {
  332. cout << " Modify line: '" << Line << "'...\n";
  333. }
  334. FoundAuth = true;
  335. Line = AuthSearchString + Authentication; // Add authentication line.
  336. Line += " # Added by SNFSetup";
  337. }
  338. Content += Line + "\n";
  339. }
  340. if (!FoundLicense || !FoundAuth) {
  341. string Temp;
  342. Temp = "Rulebase download script file " + File;
  343. Temp += " has the wrong format: Missing required line beginning with '" + LicenseSearchString;
  344. Temp += "' or '" + AuthSearchString;
  345. Temp += "'";
  346. throw runtime_error(Temp);
  347. }
  348. if (!Input.eof()) { // Should be at end-of-file.
  349. string Temp;
  350. Temp = "Error reading the rulebase download script file " + File;
  351. Temp += ": ";
  352. Temp += strerror(errno);
  353. throw runtime_error(Temp);
  354. }
  355. Input.close();
  356. if (Input.bad()) {
  357. string Temp;
  358. Temp = "Error closing the rulebase download script file " + File;
  359. Temp += " after reading: ";
  360. Temp += strerror(errno);
  361. throw runtime_error(Temp);
  362. }
  363. if (!Explain()) {
  364. ofstream Output; // Write the updated contents.
  365. Output.open(File.c_str(), ios::trunc);
  366. if (!Output) {
  367. string Temp;
  368. Temp = "Error opening rulebase download script file " + File;
  369. Temp += " for writing: ";
  370. Temp += strerror(errno);
  371. throw runtime_error(Temp);
  372. }
  373. Output << Content;
  374. if (!Output) {
  375. string Temp;
  376. Temp = "Error writing the rulebase download script file " + File;
  377. Temp += ": ";
  378. Temp += strerror(errno);
  379. throw runtime_error(Temp);
  380. }
  381. Output.close();
  382. if (!Output) {
  383. string Temp;
  384. Temp = "Error closing the rulebase download script file " + File;
  385. Temp += " after writing: ";
  386. Temp += strerror(errno);
  387. throw runtime_error(Temp);
  388. }
  389. }
  390. OutputVerboseEnd();
  391. }
  392. void
  393. UtilityConfig::DownloadRulebase() {
  394. if (!UpdateCredentialsSpecified()) {
  395. return;
  396. }
  397. if (Verbose()) {
  398. std::cout << "Downloading the rulebase...";
  399. std::cout.flush();
  400. }
  401. std::string Command;
  402. Command = RulebaseDownloadCommand;
  403. std::string::size_type ScriptIndex = Command.find(ScriptNameKey);
  404. if (ScriptIndex != std::string::npos) { // Insert script full path?
  405. Command.replace(ScriptIndex, ScriptNameKey.length(), GetRulebaseScriptName());
  406. }
  407. std::string::size_type SnifferPathIndex = Command.find(SnifferPathKey);
  408. if (SnifferPathIndex != std::string::npos) { // Insert rulebase location?
  409. Command.replace(SnifferPathIndex, SnifferPathKey.length(), GetRulebasePath());
  410. }
  411. std::string StatusFile; // Construct download status file name.
  412. StatusFile = RulebaseDownloadStatusFile;
  413. SnifferPathIndex = StatusFile.find(SnifferPathKey);
  414. if (SnifferPathIndex != std::string::npos) { // Insert rulebase location?
  415. StatusFile.replace(SnifferPathIndex, SnifferPathKey.length(), GetRulebasePath());
  416. }
  417. if (!Explain()) {
  418. if (0 != remove(StatusFile.c_str())) { // Delete the status file.
  419. if (ENOENT != errno) { // No error if the file doesn't exist.
  420. std::ostringstream Temp;
  421. Temp << "Unable to remove rulebase download status file " << StatusFile
  422. << ": " << strerror(errno) << "\n";
  423. throw runtime_error(Temp.str());
  424. }
  425. }
  426. if (std::system(Command.c_str()) != 0) { // Download the rulebase.
  427. string Temp;
  428. Temp = "Error running the command '" + Command;
  429. Temp += "'.";
  430. throw runtime_error(Temp);
  431. }
  432. ifstream Input;
  433. Input.open(StatusFile.c_str()); // Check the status.
  434. if (!Input) {
  435. string Temp;
  436. Temp = "Error opening rulebase download scriptstatus file " + StatusFile;
  437. Temp += ": ";
  438. Temp += strerror(errno);
  439. throw runtime_error(Temp);
  440. }
  441. string Line;
  442. string PrevLine;
  443. string Content;
  444. while (getline(Input, Line)) { // Read the last line.
  445. PrevLine = Line;
  446. Content += Line + "\n";
  447. }
  448. if (PrevLine.find(SuccessKey) == std::string::npos) { // Check the status.
  449. string Temp;
  450. Temp = "Error downloading the rulebase. Rulebase download status:\n\n" + Content;
  451. throw runtime_error(Temp);
  452. }
  453. }
  454. OutputVerboseEnd();
  455. }
  456. void
  457. UtilityConfig::UpdateIdentityFile() {
  458. std::string File = GetIdentityFileName();
  459. if (UpdateCredentialsSpecified()) {
  460. ofstream Output;
  461. if (Verbose()) {
  462. cout << "Create identity file " << File << "...";
  463. }
  464. if (!Explain()) {
  465. Output.open(File.c_str());
  466. if (!Output) {
  467. string Temp;
  468. Temp = "Error opening identity file " + File;
  469. Temp += ": ";
  470. Temp += strerror(errno);
  471. throw runtime_error(Temp);
  472. }
  473. Output << "<!-- License file created by SNFIdentity-->\n"
  474. << "<snf>\n"
  475. << " <identity licenseid='" << LicenseId << "' authentication='"
  476. << Authentication << "'/>\n"
  477. << "</snf>\n";
  478. if (!Output) {
  479. string Temp;
  480. Temp = "Error writing identity file " + File;
  481. Temp += ": ";
  482. Temp += strerror(errno);
  483. throw runtime_error(Temp);
  484. }
  485. Output.close();
  486. if (!Output) {
  487. string Temp;
  488. Temp = "Error closing identity file " + File;
  489. Temp += ": ";
  490. Temp += strerror(errno);
  491. throw runtime_error(Temp);
  492. }
  493. }
  494. OutputVerboseEnd();
  495. }
  496. SetOwnerGroup(File); // Set the user and group.
  497. SetMode(File, S_IRUSR); // Set to readonly by owner.
  498. }
  499. bool
  500. UtilityConfig::ProcessCommandLineItem(std::string OneInput) {
  501. bool ValidCommand = true;
  502. std::string TempString;
  503. if (OneInput == VerboseKey) {
  504. SetVerbose(true);
  505. } else if (OneInput == ExplainKey) {
  506. SetExplain(true);
  507. } else if (OneInput == HelpKey) {
  508. SetHelp(true);
  509. } else if (OneInput == ConfigFileKey) {
  510. SetConfigFileName(OneInput.substr(ConfigFileKey.length()));
  511. } else if (0 == OneInput.find(LicenseIdKey)) {
  512. TempString = Trim(OneInput.substr(LicenseIdKey.length())); // Copy only if not null after trimming.
  513. if (!TempString.empty()) {
  514. LicenseId = TempString;
  515. LicenseIdIsSpecified = true;
  516. } else {
  517. ValidCommand = false;
  518. }
  519. } else if (0 == OneInput.find(AuthenticationKey)) {
  520. Authentication = Trim(OneInput.substr(AuthenticationKey.length()));
  521. AuthenticationIsSpecified = true;
  522. } else {
  523. ValidCommand = false;
  524. }
  525. return ValidCommand;
  526. }
  527. bool
  528. UtilityConfig::CommandLineIsOkay() {
  529. return (AuthenticationIsSpecified == LicenseIdIsSpecified);
  530. }
  531. std::string
  532. UtilityConfig::HelpCommandLine() {
  533. std::string Help;
  534. Help = "[" + ConfigFileKey + "snf-config-file] ";
  535. Help += "[" + LicenseIdKey + "licenseid " + AuthenticationKey + "authentication] ";
  536. Help += "[ " + VerboseKey + " " + ExplainKey + " ]";
  537. return Help;
  538. }
  539. std::string
  540. UtilityConfig::HelpDescription() {
  541. std::string Desc;
  542. Desc = " -config=snf-config-file Specifies the configuration file\n";
  543. Desc += " -id=licenseid Specifies the license ID\n";
  544. Desc += " -auth=authentication Specifies the Authentication\n";
  545. Desc += " -v Provide verbose output\n";
  546. Desc += " -explain Provide an explaination of the actions\n";
  547. Desc += " without executing any commands\n";
  548. return Desc;
  549. }