From c93e1379d8f08b9d4df37158c46a60414cf5f2b9 Mon Sep 17 00:00:00 2001 From: botheis Date: Mon, 2 Dec 2024 15:48:22 +0100 Subject: [PATCH] (pkgs) Fix GetCommand on msi / inno nullsoft exe - Try to use the old getCommand generator to get the command. If nothing is found, use the rules. - msi are detected by the old system. - This commit update the rule on nullsoft exe. Before this modification all exe were caught by the "nullsoft rule". (cherry picked from commit b296794e308e95711c17b80f5a6d56c3fab35d44) --- services/contrib/Makefile.am | 1 + services/contrib/pkgs/sql/schema-009.sql | 35 ++++++++++++++++++ services/mmc/plugins/pkgs/__init__.py | 45 ++++++++++++++---------- 3 files changed, 63 insertions(+), 18 deletions(-) create mode 100644 services/contrib/pkgs/sql/schema-009.sql diff --git a/services/contrib/Makefile.am b/services/contrib/Makefile.am index 07d73ffe03..9c7d322458 100644 --- a/services/contrib/Makefile.am +++ b/services/contrib/Makefile.am @@ -281,6 +281,7 @@ nobase_dist_contrib_DATA = dyngroup/sql/clean-db.sql \ pkgs/sql/schema-006.sql \ pkgs/sql/schema-007.sql \ pkgs/sql/schema-008.sql \ + pkgs/sql/schema-009.sql \ updates/sql/schema-001.sql \ urbackup/sql/schema-001.sql \ monit/pulse2 \ diff --git a/services/contrib/pkgs/sql/schema-009.sql b/services/contrib/pkgs/sql/schema-009.sql new file mode 100644 index 0000000000..29cc119535 --- /dev/null +++ b/services/contrib/pkgs/sql/schema-009.sql @@ -0,0 +1,35 @@ +-- +-- (c) 2024 Siveo, http://siveo.net/ +-- +-- $Id$ +-- +-- This file is part of Pulse 2, http://siveo.net +-- +-- Pulse 2 is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- Pulse 2 is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with Pulse 2; if not, write to the Free Software +-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +-- MA 02110-1301, USA. + +-- ---------------------------------------------------------------------- +-- Database version +-- ---------------------------------------------------------------------- + +-- be sure to use the right database +use pkgs; + +START TRANSACTION; + +UPDATE extensions SET `file`="", strings="Nullsoft" WHERE rule_name="Nullsoft Rule"; +UPDATE version SET Number = 9; +COMMIT; + diff --git a/services/mmc/plugins/pkgs/__init__.py b/services/mmc/plugins/pkgs/__init__.py index 940e2155f3..1a7a707081 100644 --- a/services/mmc/plugins/pkgs/__init__.py +++ b/services/mmc/plugins/pkgs/__init__.py @@ -1078,21 +1078,35 @@ def getTemporaryFileSuggestedCommand1(tempdir, size_max=524288000): "version": "0.1", "commandcmd": [], } + base_dir = os.path.join(tmp_input_dir, tempdir) + if not os.path.isdir(base_dir): + retresult["commandcmd"] = "No command found with rules." + return retresult + suggestedCommand = [] - file_size = simplecommand("du -b %s" % os.path.join(tmp_input_dir, tempdir)) + file_size = simplecommand("du -b %s" % os.path.join(base_dir)) - file_size["result"] = [ - line.decode("utf-8") for line in file_size["result"] - ] # Convertit en UTF-8 + file_size["result"] = [line.decode("utf-8") for line in file_size["result"]] # Convertit en UTF-8 sizebytefolder = file_size["result"][0].split("\t")[0] sizebytefolder = int(sizebytefolder) - + sizebytefolder = 0 + rules = PkgsDatabase().list_all_extensions() if not isinstance(tempdir, list) and sizebytefolder <= size_max: if os.path.exists(tmp_input_dir): - for f in os.listdir(os.path.join(tmp_input_dir, tempdir)): - fileadd = os.path.join(tmp_input_dir, tempdir, f) + for f in os.listdir(base_dir): + fileadd = os.path.join(base_dir, f) if os.path.isfile(fileadd): - rules = PkgsDatabase().list_all_extensions() + # Use the old system + try: + challenger = getCommand(fileadd) + _propose = challenger.getCommand() + if _propose != None: + retresult["commandcmd"] = _propose + return retresult + except Exception: + # In this case, use the rules + pass + filename = fileadd.split("/")[-1] filebasename = ".".join(filename.split(".")[:-1]) @@ -1116,7 +1130,7 @@ def getTemporaryFileSuggestedCommand1(tempdir, size_max=524288000): stringstring = 0 if rule["strings"]: recherche = rule["strings"].replace('"', '"') - cmd = 'strings %s | grep "%s"' % (fileadd, rule["strings"]) + cmd = 'strings %s | grep -i "%s"' % (fileadd, rule["strings"]) result = simplecommand(cmd) if result["result"]: stringstring = 1 @@ -1143,8 +1157,7 @@ def getTemporaryFileSuggestedCommand1(tempdir, size_max=524288000): logging.getLogger().debug( "command propose %s" % retelt["proposition"] ) - command = retelt["proposition"].replace("'", '"') % filename - suggestedCommand.append(command) + suggestedCommand.append(retelt["proposition"]) break if suggestedCommand: retresult["commandcmd"] = "\n".join(suggestedCommand) @@ -2349,7 +2362,7 @@ def getCommand(self): # if assemblyIdentity don't exists, try assemblyIdentity identity = xmldoc.getElementsByTagName("assemblyIdentity") - if identity > 0: + if len(identity) > 0: if identity[0].hasAttribute("name"): installer = identity[0].getAttribute("name") self.logger.debug("Installer: %s" % installer) @@ -2370,9 +2383,7 @@ def getCommand(self): return self.getNSISCommand() elif installer == "7zS.sfx.exe": self.logger.debug("7zS.sfx detected (Mozilla app inside ?)") - if not os.system( - "grep Mozilla '%s' > /dev/null" % self.file - ): # return code is 0 if file match + if not os.system("grep Mozilla '%s' > /dev/null" % self.file): # return code is 0 if file match self.logger.debug("Mozilla App detected") return self.getMozillaCommand() else: @@ -2399,9 +2410,7 @@ def getCommand(self): return self.getMSICommand() else: return self.logger.info("No Template Key for %s" % self.file) - elif "Debian binary package" in file_data[self.file] or self.file.endswith( - ".deb" - ): + elif "Debian binary package" in file_data[self.file] or self.file.endswith(".deb"): self.logger.debug("Debian package detected") return self.getDpkgCommand() elif self.file.endswith(".reg"):