From: Tim Düsterhus Date: Thu, 28 Jul 2022 09:25:01 +0000 (+0200) Subject: Store SHA-256 hashes in `wcf1_package_installation_file_log` X-Git-Tag: 6.0.0_Alpha_1~1096^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=01ec69848a725e649b045f26cd16720581071076;p=GitHub%2FWoltLab%2FWCF.git Store SHA-256 hashes in `wcf1_package_installation_file_log` It is not planned to actively check them anywhere, but having something is often better than needing them. They might ease manual verification of the installation's consistency. --- diff --git a/wcfsetup/install/files/acp/database/update_com.woltlab.wcf_5.6.php b/wcfsetup/install/files/acp/database/update_com.woltlab.wcf_5.6.php index e94541bbf0..71e99b6171 100644 --- a/wcfsetup/install/files/acp/database/update_com.woltlab.wcf_5.6.php +++ b/wcfsetup/install/files/acp/database/update_com.woltlab.wcf_5.6.php @@ -9,8 +9,10 @@ * @package WoltLabSuite\Core */ +use wcf\system\database\table\column\BigintDatabaseTableColumn; use wcf\system\database\table\column\NotNullInt10DatabaseTableColumn; use wcf\system\database\table\column\TinyintDatabaseTableColumn; +use wcf\system\database\table\column\VarbinaryDatabaseTableColumn; use wcf\system\database\table\PartialDatabaseTable; return [ @@ -25,6 +27,12 @@ return [ PartialDatabaseTable::create('wcf1_package_installation_file_log') ->columns([ NotNullInt10DatabaseTableColumn::create('packageID'), + VarbinaryDatabaseTableColumn::create('sha256') + ->length(32) + ->defaultValue(null), + BigintDatabaseTableColumn::create('lastUpdated') + ->length(20) + ->defaultValue(null), ]), PartialDatabaseTable::create('wcf1_package_installation_plugin') ->columns([ diff --git a/wcfsetup/install/files/lib/system/package/FilesFileHandler.class.php b/wcfsetup/install/files/lib/system/package/FilesFileHandler.class.php index 2133591bd0..37f9de5e19 100644 --- a/wcfsetup/install/files/lib/system/package/FilesFileHandler.class.php +++ b/wcfsetup/install/files/lib/system/package/FilesFileHandler.class.php @@ -2,6 +2,7 @@ namespace wcf\system\package; +use wcf\data\application\Application; use wcf\data\package\Package; use wcf\system\database\util\PreparedStatementConditionBuilder; use wcf\system\exception\SystemException; @@ -61,9 +62,13 @@ class FilesFileHandler extends PackageInstallationFileHandler return; } - $sql = "INSERT IGNORE INTO wcf" . WCF_N . "_package_installation_file_log - (packageID, filename, application) - VALUES (?, ?, ?)"; + $baseDirectory = Application::getDirectory($this->application); + + $sql = "INSERT INTO wcf1_package_installation_file_log + (packageID, filename, application, sha256, lastUpdated) + VALUES (?, ?, ?, ?, ?) + ON DUPLICATE KEY UPDATE sha256 = VALUES(sha256), + lastUpdated = VALUES(lastUpdated)"; $statement = WCF::getDB()->prepareStatement($sql); WCF::getDB()->beginTransaction(); @@ -72,6 +77,8 @@ class FilesFileHandler extends PackageInstallationFileHandler $this->packageInstallation->getPackageID(), $file, $this->application, + \hash_file('sha256', $baseDirectory . $file, true), + TIME_NOW, ]); } WCF::getDB()->commitTransaction(); diff --git a/wcfsetup/install/files/lib/system/package/plugin/FilePackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/FilePackageInstallationPlugin.class.php index f72ff426bb..e15d102cd0 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/FilePackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/FilePackageInstallationPlugin.class.php @@ -69,19 +69,21 @@ class FilePackageInstallationPlugin extends AbstractPackageInstallationPlugin im // log files $sql = "INSERT INTO wcf" . WCF_N . "_package_installation_file_log - (packageID, filename, application) - VALUES (?, ?, ?)"; + (packageID, filename, application, sha256, lastUpdated) + VALUES (?, ?, ?, ?, ?)"; $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute([ - $this->installation->getPackageID(), - 'config.inc.php', - Package::getAbbreviation($this->installation->getPackage()->package), - ]); - $statement->execute([ - $this->installation->getPackageID(), + foreach ([ PackageInstallationDispatcher::CONFIG_FILE, - Package::getAbbreviation($this->installation->getPackage()->package), - ]); + 'config.inc.php', + ] as $filename) { + $statement->execute([ + $this->installation->getPackageID(), + $filename, + Package::getAbbreviation($this->installation->getPackage()->package), + \hash_file('sha256', $packageDir . $filename, true), + \TIME_NOW, + ]); + } // load application WCF::loadRuntimeApplication($this->installation->getPackageID()); diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index 8be229875a..07685b4da6 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -956,6 +956,8 @@ CREATE TABLE wcf1_package_installation_file_log ( packageID INT(10) NOT NULL, filename VARBINARY(765) NOT NULL, -- VARBINARY(765) roughly equals VARCHAR(255) application VARCHAR(20) NOT NULL, + sha256 VARBINARY(32) DEFAULT NULL, + lastUpdated BIGINT(20) DEFAULT NULL, UNIQUE KEY applicationFile (application, filename) );