From de8921b32e5241c82a118e485b7b759397649361 Mon Sep 17 00:00:00 2001 From: Vadim Kurland Date: Tue, 8 Mar 2011 18:15:57 -0800 Subject: [PATCH] * Importer.cpp (addStandardRuleComment): see #2189 Program adds the file name and the line number to comments of policy and nat rules it creates during import. --- doc/ChangeLog | 4 + src/libgui/IPTImporter.cpp | 5 +- src/libgui/Importer.cpp | 14 +- src/libgui/Importer.h | 6 + .../IC_ProgressPage.cpp | 5 +- .../ImporterThread.cpp | 7 +- .../ImporterThread.h | 4 +- src/unit_tests/ImporterTest/test_data/ios.fwb | 34 +-- src/unit_tests/ImporterTest/test_data/ipt.fwb | 258 +++++++++--------- 9 files changed, 184 insertions(+), 153 deletions(-) diff --git a/doc/ChangeLog b/doc/ChangeLog index 8867dd384..9a95913ea 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,5 +1,9 @@ 2011-03-08 vadim + * Importer.cpp (addStandardRuleComment): see #2189 Program adds + the file name and the line number to comments of policy and nat + rules it creates during import. + * IPTImporter.cpp (pushPolicyRule): see #2202 importer for iptables creates Custom Service object to match combination of states it does not recognize. This includes "NEW,ESTABLISHED". diff --git a/src/libgui/IPTImporter.cpp b/src/libgui/IPTImporter.cpp index 231af18ae..888385d38 100644 --- a/src/libgui/IPTImporter.cpp +++ b/src/libgui/IPTImporter.cpp @@ -1258,8 +1258,7 @@ void IPTImporter::pushPolicyRule() processModuleMatches(); - current_rule->setComment(rule_comment); - + current_rule->setComment(addStandardRuleComment(rule_comment)); } current_rule = NULL; @@ -1491,7 +1490,7 @@ void IPTImporter::pushNATRule() // renumber to clean-up rule positions ruleset->renumberRules(); - current_rule->setComment(rule_comment); + current_rule->setComment(addStandardRuleComment(rule_comment)); // RuleSet *nat = RuleSet::cast( // getFirewallObject()->getFirstByType(NAT::TYPENAME)); diff --git a/src/libgui/Importer.cpp b/src/libgui/Importer.cpp index b28375f4e..38da7cd9c 100644 --- a/src/libgui/Importer.cpp +++ b/src/libgui/Importer.cpp @@ -535,7 +535,7 @@ void Importer::pushRule() // then add it to the current ruleset current_ruleset->ruleset->add(current_rule); - current_rule->setComment(rule_comment); + current_rule->setComment(addStandardRuleComment(rule_comment)); // *logger << "Rule: " << action << " " // << protocol << " " @@ -1242,4 +1242,16 @@ void Importer::addMessageToLog(const std::string &msg) *logger << msg + "\n"; } +string Importer::addStandardRuleComment(const string &comment) +{ + string rule_comment = comment; + if (!rule_comment.empty()) rule_comment += "\n"; + QString file_and_line("Created during import of %1 line %2"); + rule_comment += string( + file_and_line + .arg(QString::fromUtf8(input_file_name.c_str())) + .arg(getCurrentLineNumber()).toUtf8().constData()); + return rule_comment; +} + diff --git a/src/libgui/Importer.h b/src/libgui/Importer.h index 1e1766d02..84255bdfb 100644 --- a/src/libgui/Importer.h +++ b/src/libgui/Importer.h @@ -97,6 +97,7 @@ protected: libfwbuilder::FWObject *library; + std::string input_file_name; std::istringstream &input; std::string platform; @@ -272,7 +273,12 @@ public: virtual void run(); + void setFileName(const std::string &fn) { input_file_name = fn; } void setPlatform(const std::string &pl) { platform = pl; } + + // add standard line to rule comment, this adds something like + // "created during import from , line " + std::string addStandardRuleComment(const std::string &comment); int errorCounter() { return error_counter; } diff --git a/src/libgui/importFirewallConfigurationWizard/IC_ProgressPage.cpp b/src/libgui/importFirewallConfigurationWizard/IC_ProgressPage.cpp index 6efb7e6b9..998b6cfec 100644 --- a/src/libgui/importFirewallConfigurationWizard/IC_ProgressPage.cpp +++ b/src/libgui/importFirewallConfigurationWizard/IC_ProgressPage.cpp @@ -138,10 +138,13 @@ void IC_ProgressPage::initializePage() QStringList *buffer = dynamic_cast(wizard())-> getBufferPtr(); + QString fileName = field("fileName").toString(); importer = new ImporterThread(this, mw->getCurrentLib(), - *buffer, platform, firewallName); + *buffer, platform, firewallName, fileName); + + connect(importer, SIGNAL(destroyed(QObject*)), this, SLOT(importerDestroyed(QObject*))); connect(importer, SIGNAL(finished()), diff --git a/src/libgui/importFirewallConfigurationWizard/ImporterThread.cpp b/src/libgui/importFirewallConfigurationWizard/ImporterThread.cpp index 478ed9a1c..180a28221 100644 --- a/src/libgui/importFirewallConfigurationWizard/ImporterThread.cpp +++ b/src/libgui/importFirewallConfigurationWizard/ImporterThread.cpp @@ -45,13 +45,15 @@ ImporterThread::ImporterThread(QWidget *ui, FWObject *lib, const QStringList &buffer, const QString &platform, - const QString &firewallName) + const QString &firewallName, + const QString &fileName) { this->lib = lib; this->ui = ui; this->buffer = buffer; this->platform = platform; this->firewallName = firewallName; + this->fileName = fileName; importer = NULL; stopFlag = false; } @@ -83,6 +85,9 @@ void ImporterThread::run() if (importer) { + + importer->setFileName(fileName.toUtf8().constData()); + try { importer->run(); diff --git a/src/libgui/importFirewallConfigurationWizard/ImporterThread.h b/src/libgui/importFirewallConfigurationWizard/ImporterThread.h index d805e62fa..510478fcb 100644 --- a/src/libgui/importFirewallConfigurationWizard/ImporterThread.h +++ b/src/libgui/importFirewallConfigurationWizard/ImporterThread.h @@ -46,6 +46,7 @@ class ImporterThread : public QThread libfwbuilder::FWObject *lib; Importer *importer; + QString fileName; QStringList buffer; QString firewallName; QString platform; @@ -58,7 +59,8 @@ public: libfwbuilder::FWObject *lib, const QStringList &buffer, const QString &platform, - const QString &firewallName); + const QString &firewallName, + const QString &fileName); virtual ~ImporterThread(); void run(); diff --git a/src/unit_tests/ImporterTest/test_data/ios.fwb b/src/unit_tests/ImporterTest/test_data/ios.fwb index dfb59c6e5..c769afb9a 100644 --- a/src/unit_tests/ImporterTest/test_data/ios.fwb +++ b/src/unit_tests/ImporterTest/test_data/ios.fwb @@ -1,6 +1,6 @@ - + @@ -500,7 +500,7 @@ - + @@ -520,7 +520,7 @@ - + @@ -540,7 +540,7 @@ - + @@ -560,7 +560,7 @@ - + @@ -580,7 +580,7 @@ - + @@ -600,7 +600,7 @@ - + @@ -620,7 +620,7 @@ - + @@ -640,7 +640,7 @@ - + @@ -660,7 +660,7 @@ - + @@ -680,7 +680,7 @@ - + @@ -700,7 +700,7 @@ - + @@ -720,7 +720,7 @@ - + @@ -740,7 +740,7 @@ - + @@ -760,7 +760,7 @@ - + @@ -780,7 +780,7 @@ - + @@ -800,7 +800,7 @@ - + diff --git a/src/unit_tests/ImporterTest/test_data/ipt.fwb b/src/unit_tests/ImporterTest/test_data/ipt.fwb index 477c7534c..430a55c22 100644 --- a/src/unit_tests/ImporterTest/test_data/ipt.fwb +++ b/src/unit_tests/ImporterTest/test_data/ipt.fwb @@ -1,6 +1,6 @@ - + @@ -612,7 +612,7 @@ - + @@ -639,7 +639,7 @@ - + @@ -666,7 +666,7 @@ - + @@ -693,7 +693,7 @@ - + @@ -720,7 +720,7 @@ - + @@ -747,7 +747,7 @@ - + @@ -774,7 +774,7 @@ - + @@ -801,7 +801,7 @@ - + @@ -828,7 +828,7 @@ - + @@ -855,7 +855,7 @@ - + @@ -882,7 +882,7 @@ - + @@ -909,7 +909,7 @@ - + @@ -936,7 +936,7 @@ - + @@ -963,7 +963,7 @@ - + @@ -990,7 +990,7 @@ - + @@ -1017,7 +1017,7 @@ - + @@ -1044,7 +1044,7 @@ - + @@ -1071,7 +1071,7 @@ - + @@ -1098,7 +1098,7 @@ - + @@ -1128,7 +1128,7 @@ - + @@ -1148,7 +1148,7 @@ - + @@ -1168,7 +1168,7 @@ - + @@ -1188,7 +1188,7 @@ - + @@ -1208,7 +1208,7 @@ - + @@ -1230,7 +1230,7 @@ - + @@ -1252,7 +1252,7 @@ - + @@ -1274,7 +1274,7 @@ - + @@ -1294,7 +1294,7 @@ - + @@ -1316,7 +1316,7 @@ - + @@ -1338,7 +1338,7 @@ - + @@ -1360,7 +1360,7 @@ - + @@ -1381,7 +1381,7 @@ - + @@ -1402,7 +1402,7 @@ - + @@ -1423,7 +1423,7 @@ - + @@ -1444,7 +1444,7 @@ - + @@ -1465,7 +1465,7 @@ - + @@ -1486,7 +1486,7 @@ - + @@ -1507,7 +1507,7 @@ - + @@ -1528,7 +1528,7 @@ - + @@ -1549,7 +1549,7 @@ - + @@ -1570,7 +1570,7 @@ - + @@ -1591,7 +1591,7 @@ - + @@ -1612,7 +1612,7 @@ - + @@ -1633,7 +1633,7 @@ - + @@ -1654,7 +1654,7 @@ - + @@ -1675,7 +1675,7 @@ - + @@ -1697,7 +1697,7 @@ - + @@ -1719,7 +1719,7 @@ - + @@ -1741,7 +1741,7 @@ - + @@ -1761,7 +1761,7 @@ - + @@ -1781,7 +1781,7 @@ - + @@ -1801,7 +1801,7 @@ - + @@ -1821,7 +1821,7 @@ - + @@ -1846,7 +1846,7 @@ - + @@ -1868,7 +1868,7 @@ - + @@ -1890,7 +1890,7 @@ - + @@ -1912,7 +1912,7 @@ - + @@ -1934,7 +1934,7 @@ - + @@ -1957,7 +1957,7 @@ - + @@ -1982,7 +1982,7 @@ - + @@ -2007,7 +2007,7 @@ - + @@ -2028,7 +2028,7 @@ - + @@ -2072,7 +2072,7 @@ - + @@ -2092,7 +2092,7 @@ - + @@ -2112,7 +2112,7 @@ - + @@ -2132,7 +2132,7 @@ - + @@ -2152,7 +2152,7 @@ - + @@ -2172,7 +2172,7 @@ - + @@ -2192,7 +2192,7 @@ - + @@ -2212,7 +2212,7 @@ - + @@ -2232,7 +2232,7 @@ - + @@ -2252,7 +2252,7 @@ - + @@ -2272,7 +2272,7 @@ - + @@ -2292,7 +2292,7 @@ - + @@ -2312,7 +2312,7 @@ - + @@ -2332,7 +2332,7 @@ - + @@ -2352,7 +2352,7 @@ - + @@ -2372,7 +2372,7 @@ - + @@ -2392,7 +2392,7 @@ - + @@ -2412,7 +2412,7 @@ - + @@ -2432,7 +2432,7 @@ - + @@ -2452,7 +2452,7 @@ - + @@ -2472,7 +2472,7 @@ - + @@ -2492,7 +2492,7 @@ - + @@ -2512,7 +2512,7 @@ - + @@ -2533,7 +2533,7 @@ - + @@ -2560,7 +2560,7 @@ - + @@ -2580,7 +2580,7 @@ - + @@ -2600,7 +2600,7 @@ - + @@ -2620,7 +2620,7 @@ - + @@ -2640,7 +2640,7 @@ - + @@ -2660,7 +2660,7 @@ - + @@ -2680,7 +2680,7 @@ - + @@ -2700,7 +2700,7 @@ - + @@ -2720,7 +2720,7 @@ - + @@ -2740,7 +2740,7 @@ - + @@ -2760,7 +2760,7 @@ - + @@ -2780,7 +2780,7 @@ - + @@ -2801,7 +2801,7 @@ - + @@ -2822,7 +2822,7 @@ - + @@ -2842,7 +2842,7 @@ - + @@ -2862,7 +2862,7 @@ - + @@ -2882,7 +2882,7 @@ - + @@ -2902,7 +2902,7 @@ - + @@ -2922,7 +2922,7 @@ - + @@ -2944,7 +2944,7 @@ - + @@ -2966,7 +2966,7 @@ - + @@ -2988,7 +2988,7 @@ - + @@ -3010,7 +3010,7 @@ - + @@ -3032,7 +3032,7 @@ - + @@ -3054,7 +3054,7 @@ - + @@ -3077,7 +3077,7 @@ - + @@ -3100,7 +3100,7 @@ - + @@ -3120,7 +3120,7 @@ - + @@ -3215,7 +3215,7 @@ - + @@ -3242,7 +3242,7 @@ - + @@ -3269,7 +3269,7 @@ - + @@ -3296,7 +3296,7 @@ - + @@ -3323,7 +3323,7 @@ - + @@ -3350,7 +3350,7 @@ - + @@ -3377,7 +3377,7 @@ - + @@ -3404,7 +3404,7 @@ - + @@ -3424,7 +3424,7 @@ - + @@ -3444,7 +3444,7 @@ - + @@ -3464,7 +3464,7 @@ - + @@ -3484,7 +3484,7 @@ - + @@ -3504,7 +3504,7 @@ - + @@ -3524,7 +3524,7 @@ - +